blobshapetrans.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "blobshapetrans.h"
  2. #include "ui_blobshapetrans.h"
  3. #include "../ToolDialog.h"
  4. class ToolDialogImpl;
  5. BolbShapeTrans::BolbShapeTrans(QWidget *parent , ToolDialogImpl* p) : ToolInterface(parent), ui(new Ui::BolbShapeTrans)
  6. {
  7. ui->setupUi(this);
  8. m_pToolDialogImpl = p;
  9. ui->comboBox_index->setView(new QListView());
  10. ui->comboBox->setView(new QListView());
  11. if(m_pToolDialogImpl->m_LinkProcess.size() > 0)
  12. {
  13. ui->comboBox_index->setVisible(true);
  14. ui->label_index->setVisible(true);
  15. }
  16. else
  17. {
  18. ui->comboBox_index->setVisible(false);
  19. ui->label_index->setVisible(false);
  20. }
  21. for(int i = 0; i < m_pToolDialogImpl->m_LinkProcess.size(); i++)
  22. {
  23. ui->comboBox_index->addItem(QString::number(i));
  24. }
  25. }
  26. BolbShapeTrans::~BolbShapeTrans()
  27. {
  28. delete ui;
  29. }
  30. bool BolbShapeTrans::Serialized(QDataStream& ar, bool bIsOut)
  31. {
  32. int paranum;//参数数量
  33. if (bIsOut)//保存参数流程
  34. {
  35. paranum = 2;
  36. ar << paranum;//先保存参数数量
  37. ar << (int)1 << ui->comboBox_index->currentIndex();
  38. ar << (int)2 << ui->comboBox->currentIndex();
  39. }
  40. else//加载参数流程,参数加载顺序一定要跟保存顺序一致
  41. {
  42. int nCurrentIndex1 = 0;
  43. int nCurrentIndex2 = 0;
  44. int para;
  45. ar >> paranum;//读取参数数量
  46. for (int i = 0; i < paranum; i++)
  47. {
  48. ar >> para;
  49. switch (para)
  50. {
  51. case 1: ar >> nCurrentIndex1; break;
  52. case 2: ar >> nCurrentIndex2; break;
  53. default:
  54. {
  55. qWarning() << "Serialized(In) Error";
  56. return false;
  57. }
  58. break;
  59. }
  60. }
  61. {
  62. ui->comboBox_index->setCurrentIndex(nCurrentIndex1);
  63. ui->comboBox->setCurrentIndex(nCurrentIndex2);
  64. emit updateParameter(ShowParameter());
  65. }
  66. }
  67. return true;
  68. }
  69. QString BolbShapeTrans::ShowParameter()
  70. {
  71. QString str;
  72. str = ui->comboBox->currentText();
  73. return str;
  74. }
  75. int BolbShapeTrans::Execute()
  76. {
  77. int result = 1;
  78. int m_nType = ui->comboBox->currentIndex();
  79. try
  80. {
  81. if(ui->comboBox_index->currentIndex() == 0)
  82. {
  83. if(m_nType == 0)
  84. {
  85. ShapeTrans (m_InImage, &m_OutImage, "convex");
  86. }
  87. if(m_nType == 1)
  88. {
  89. ShapeTrans (m_InImage, &m_OutImage, "ellipse");
  90. }
  91. if(m_nType == 2)
  92. {
  93. ShapeTrans (m_InImage, &m_OutImage, "outer_circle");
  94. }
  95. if(m_nType == 3)
  96. {
  97. ShapeTrans (m_InImage, &m_OutImage, "inner_circle");
  98. }
  99. if(m_nType == 4)
  100. {
  101. ShapeTrans (m_InImage, &m_OutImage, "rectangle1");
  102. }
  103. if(m_nType == 5)
  104. {
  105. ShapeTrans (m_InImage, &m_OutImage, "rectangle2");
  106. }
  107. if(m_nType == 6)
  108. {
  109. ShapeTrans (m_InImage, &m_OutImage, "inner_rectangle1");
  110. }
  111. }
  112. else
  113. {
  114. int index = ui->comboBox_index->currentIndex() - 1;
  115. HObject inputimage = m_pToolDialogImpl->m_LinkProcess[index].p_dlg->GetResult();
  116. if(m_nType == 0)
  117. {
  118. ShapeTrans (inputimage, &m_OutImage, "convex");
  119. }
  120. if(m_nType == 1)
  121. {
  122. ShapeTrans (inputimage, &m_OutImage, "ellipse");
  123. }
  124. if(m_nType == 2)
  125. {
  126. ShapeTrans (inputimage, &m_OutImage, "outer_circle");
  127. }
  128. if(m_nType == 3)
  129. {
  130. ShapeTrans (inputimage, &m_OutImage, "inner_circle");
  131. }
  132. if(m_nType == 4)
  133. {
  134. ShapeTrans (inputimage, &m_OutImage, "rectangle1");
  135. }
  136. if(m_nType == 5)
  137. {
  138. ShapeTrans (inputimage, &m_OutImage, "rectangle2");
  139. }
  140. if(m_nType == 6)
  141. {
  142. ShapeTrans (inputimage, &m_OutImage, "inner_rectangle1");
  143. }
  144. }
  145. }
  146. catch(...)
  147. {
  148. }
  149. return result;
  150. }
  151. void BolbShapeTrans::on_comboBox_currentIndexChanged(int index)
  152. {
  153. emit updateParameter(ShowParameter());
  154. }
  155. void BolbShapeTrans::on_comboBox_index_currentIndexChanged(int index)
  156. {
  157. if(index > 0)
  158. {
  159. emit updateParameterIndex(QString::number(index - 1));
  160. }
  161. emit updateParameter(ShowParameter());
  162. }