dialogroadobject_repeat.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #include "dialogroadobject_repeat.h"
  2. #include "ui_dialogroadobject_repeat.h"
  3. static std::string stritemname[] = {"s","length","distance","tStart","tEnd","heightStart","heightEnd",
  4. "zOffsetStart","zOffsetEnd","widthStart","widthEnd","lengthStart",
  5. "lendthEnd","radiusStart","radiusEnd"};
  6. DialogRoadObject_repeat::DialogRoadObject_repeat(Object * pObject,QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::DialogRoadObject_repeat)
  9. {
  10. ui->setupUi(this);
  11. mpObject = pObject;
  12. CreateView();
  13. UpdateList();
  14. setWindowTitle("Edit Road Object Repeat");
  15. }
  16. DialogRoadObject_repeat::~DialogRoadObject_repeat()
  17. {
  18. delete ui;
  19. }
  20. void DialogRoadObject_repeat::UpdateList()
  21. {
  22. ui->comboBox_repeat->clear();
  23. unsigned int i;
  24. for(i=0;i<15;i++)
  25. {
  26. mpLE[i]->setText("");
  27. }
  28. Object * pObject = mpObject;
  29. if(pObject == 0)return;
  30. if(pObject->GetObjectrepeatCount() == 0)return;
  31. for(i=0;i<pObject->GetObjectrepeatCount();i++)
  32. {
  33. Object_repeat * pObject_repeat = pObject->GetObjectrepeat(i);
  34. if(pObject_repeat == 0)return;
  35. ui->comboBox_repeat->addItem("repeat "+QString::number(i));
  36. }
  37. }
  38. void DialogRoadObject_repeat::CreateView()
  39. {
  40. int startpos_x = 30;
  41. int startpos_y = 150;
  42. int nSpace = 260;
  43. int nLabelWidth = 80;
  44. int nLEWidth = 150;
  45. int nHeight = 35;
  46. int nVSpace = 60;
  47. int nVIndex = 0;
  48. mpLEs = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"s",this);
  49. mpLElength = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"length",this);
  50. mpLEdistance = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"distance",this);
  51. nVIndex++;
  52. mpLEtStart = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"tStart",this);
  53. mpLEtEnd = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"tEnd",this);
  54. mpLEheightStart = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"heightStart",this);
  55. nVIndex++;
  56. mpLEheightEnd = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"heightEnd",this);
  57. mpLEzOffsetStart = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"zOffsetStart",this);
  58. mpLEzOffsetEnd = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"zOffsetEnd",this);
  59. nVIndex++;
  60. mpLEwidthStart = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"widthStart",this);
  61. mpLEwidthEnd = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"widthEnd",this);
  62. mpLElengthStart = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"lengthStart",this);
  63. nVIndex++;
  64. mpLElengthEnd = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"lengthEnd",this);
  65. mpLEradiusStart = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"radiusStart",this);
  66. mpLEradiusEnd = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"radiusEnd",this);
  67. nVIndex++;
  68. mpLE[0] = mpLEs;
  69. mpLE[1] = mpLElength;
  70. mpLE[2] = mpLEdistance;
  71. mpLE[3] = mpLEtStart;
  72. mpLE[4] = mpLEtEnd;
  73. mpLE[5] = mpLEheightStart;
  74. mpLE[6] = mpLEheightEnd;
  75. mpLE[7] = mpLEzOffsetStart;
  76. mpLE[8] = mpLEzOffsetEnd;
  77. mpLE[9] = mpLEwidthStart;
  78. mpLE[10] = mpLEwidthEnd;
  79. mpLE[11] = mpLElengthStart;
  80. mpLE[12] = mpLElengthEnd;
  81. mpLE[13] = mpLEradiusStart;
  82. mpLE[14] = mpLEradiusEnd;
  83. int nPBSpace = 300;
  84. int nPBWidth = 150;
  85. mpPBAdd = ViewCreate::CreatePB(startpos_x+0*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"Add",this);
  86. mpPBDel = ViewCreate::CreatePB(startpos_x+1*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"Delete",this);
  87. mpPBChange = ViewCreate::CreatePB(startpos_x+2*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"Change",this);
  88. connect(mpPBAdd,SIGNAL(clicked(bool)),this,SLOT(onClickAdd()));
  89. connect(mpPBDel,SIGNAL(clicked(bool)),this,SLOT(onCLickDel()));
  90. connect(mpPBChange,SIGNAL(clicked(bool)),this,SLOT(onClickChange()));
  91. }
  92. void DialogRoadObject_repeat::on_comboBox_repeat_currentIndexChanged(int index)
  93. {
  94. if(index < 0)return;
  95. Object * pObject = mpObject;
  96. if(pObject == 0)return;
  97. if(index > ((int)pObject->GetObjectrepeatCount()))
  98. {
  99. return;
  100. }
  101. Object_repeat * pObject_repeat = pObject->GetObjectrepeat(index);
  102. if(pObject_repeat == 0)
  103. {
  104. return;
  105. }
  106. mpLEs->setText(QString::number(pObject_repeat->Gets()));
  107. mpLElength->setText(QString::number(pObject_repeat->Getlength()));
  108. mpLEdistance->setText(QString::number(pObject_repeat->Getdistance()));
  109. mpLEtStart->setText(QString::number(pObject_repeat->GettStart()));
  110. mpLEtEnd->setText(QString::number(pObject_repeat->GettEnd()));
  111. mpLEheightStart->setText(QString::number(pObject_repeat->GetheightStart()));
  112. mpLEheightEnd->setText(QString::number(pObject_repeat->GetheightEnd()));
  113. mpLEzOffsetStart->setText(QString::number(pObject_repeat->GetzOffsetStart()));
  114. mpLEzOffsetEnd->setText(QString::number(pObject_repeat->GetzOffsetEnd()));
  115. double widthStart,widthEnd,lengthStart,lengthEnd,radiusStart,radiusEnd;
  116. if(pObject_repeat->GetwidthStart(widthStart) == 1)
  117. {
  118. mpLEwidthStart->setText(QString::number(widthStart));
  119. }
  120. if(pObject_repeat->GetwidthEnd(widthEnd) == 1)
  121. {
  122. mpLEwidthEnd->setText(QString::number(widthEnd));
  123. }
  124. if(pObject_repeat->GetlengthStart(lengthStart) == 1)
  125. {
  126. mpLElengthStart->setText(QString::number(lengthStart));
  127. }
  128. if(pObject_repeat->GetlengthEnd(lengthEnd) == 1)
  129. {
  130. mpLElengthEnd->setText(QString::number(lengthEnd));
  131. }
  132. if(pObject_repeat->GetradiusStart(radiusStart) == 1)
  133. {
  134. mpLEradiusStart->setText(QString::number(radiusStart));
  135. }
  136. if(pObject_repeat->GetradiusEnd(radiusEnd) == 1)
  137. {
  138. mpLEradiusEnd->setText(QString::number(radiusEnd));
  139. }
  140. }
  141. void DialogRoadObject_repeat::onClickAdd()
  142. {
  143. if(mpObject == 0)
  144. {
  145. QMessageBox::warning(this,"Warning","Object is NULL.",QMessageBox::YesAll);
  146. return;
  147. }
  148. Object * pObject = mpObject;
  149. unsigned int i;
  150. for(i=0;i<9;i++)
  151. {
  152. if(false == ViewCreate::CheckLE(mpLE[i],stritemname[i].data(),true,this))
  153. {
  154. return;
  155. }
  156. }
  157. double s,length,distance,tStart,tEnd,heightStart,heightEnd,zOffsetStart,zOffsetEnd;
  158. s = mpLEs->text().toDouble();
  159. length = mpLElength->text().toDouble();
  160. distance = mpLEdistance->text().toDouble();
  161. tStart = mpLEtStart->text().toDouble();
  162. tEnd = mpLEtEnd->text().toDouble();
  163. heightStart = mpLEheightStart->text().toDouble();
  164. heightEnd = mpLEheightEnd->text().toDouble();
  165. zOffsetStart = mpLEzOffsetStart->text().toDouble();
  166. zOffsetEnd = mpLEzOffsetEnd->text().toDouble();
  167. pObject->AddObjectrepeat(s,length,distance,tStart,tEnd,heightStart,heightEnd,zOffsetStart,zOffsetEnd);
  168. Object_repeat * pObject_repeat = pObject->GetLastAddedObjectrepeat();
  169. if(pObject_repeat == 0)return;
  170. if(ViewCreate::CheckLE(mpLEwidthStart,"widthStart",false,this) == true)
  171. {
  172. pObject_repeat->SetwidthStart(mpLEwidthStart->text().toDouble());
  173. }
  174. if(ViewCreate::CheckLE(mpLEwidthEnd,"widthEnd",false,this) == true)
  175. {
  176. pObject_repeat->SetwidthEnd(mpLEwidthEnd->text().toDouble());
  177. }
  178. if(ViewCreate::CheckLE(mpLElengthStart,"lengthStart",false,this) == true)
  179. {
  180. pObject_repeat->SetlengthStart(mpLElengthStart->text().toDouble());
  181. }
  182. if(ViewCreate::CheckLE(mpLElengthEnd,"lengthEnd",false,this) == true)
  183. {
  184. pObject_repeat->SetlengthEnd(mpLElengthEnd->text().toDouble());
  185. }
  186. if(ViewCreate::CheckLE(mpLEradiusStart,"radiusStart",false,this) == true)
  187. {
  188. pObject_repeat->SetradiusStart(mpLEradiusStart->text().toDouble());
  189. }
  190. if(ViewCreate::CheckLE(mpLEradiusEnd,"radiusEnd",false,this) == true)
  191. {
  192. pObject_repeat->SetradiusEnd(mpLEradiusEnd->text().toDouble());
  193. }
  194. UpdateList();
  195. }
  196. void DialogRoadObject_repeat::onCLickDel()
  197. {
  198. if(mpObject == 0)
  199. {
  200. QMessageBox::warning(this,"Warning","Object is NULL.",QMessageBox::YesAll);
  201. return;
  202. }
  203. Object * pObject = mpObject;
  204. if(pObject->GetObjectrepeatCount() == 0)
  205. {
  206. QMessageBox::information(this,"Info","No repeat",QMessageBox::YesAll);
  207. return;
  208. }
  209. int index = ui->comboBox_repeat->currentIndex();
  210. pObject->DeleteObjectmaterial(index);
  211. UpdateList();
  212. }
  213. void DialogRoadObject_repeat::onClickChange()
  214. {
  215. if(mpObject == 0)
  216. {
  217. QMessageBox::warning(this,"Warning","Object is NULL.",QMessageBox::YesAll);
  218. return;
  219. }
  220. Object * pObject = mpObject;
  221. if(pObject->GetObjectrepeatCount() == 0)
  222. {
  223. QMessageBox::warning(this,"Warning","No repeat",QMessageBox::YesAll);
  224. return;
  225. }
  226. int index = ui->comboBox_repeat->currentIndex();
  227. Object_repeat * pObject_repeat = pObject->GetObjectrepeat(index);
  228. if(pObject_repeat == 0)return;
  229. unsigned int i;
  230. for(i=0;i<9;i++)
  231. {
  232. if(false == ViewCreate::CheckLE(mpLE[i],stritemname[i].data(),true,this))
  233. {
  234. return;
  235. }
  236. }
  237. pObject_repeat->Sets(mpLEs->text().toDouble());
  238. pObject_repeat->Setlength(mpLElength->text().toDouble());
  239. pObject_repeat->Setdistance(mpLEdistance->text().toDouble());
  240. pObject_repeat->SettStart(mpLEtStart->text().toDouble());
  241. pObject_repeat->SettEnd(mpLEtEnd->text().toDouble());
  242. pObject_repeat->SetheightStart(mpLEheightStart->text().toDouble());
  243. pObject_repeat->SetheightEnd(mpLEheightEnd->text().toDouble());
  244. pObject_repeat->SetzOffsetStart(mpLEzOffsetStart->text().toDouble());
  245. pObject_repeat->SetzOffsetEnd(mpLEzOffsetEnd->text().toDouble());
  246. if(ViewCreate::CheckLE(mpLEwidthStart,"widthStart",false,this) == true)
  247. {
  248. pObject_repeat->SetwidthStart(mpLEwidthStart->text().toDouble());
  249. }
  250. else
  251. {
  252. pObject_repeat->DeletewidthStart();
  253. }
  254. if(ViewCreate::CheckLE(mpLEwidthEnd,"widthEnd",false,this) == true)
  255. {
  256. pObject_repeat->SetwidthEnd(mpLEwidthEnd->text().toDouble());
  257. }
  258. else
  259. {
  260. pObject_repeat->DeletewidthEnd();
  261. }
  262. if(ViewCreate::CheckLE(mpLElengthStart,"lengthStart",false,this) == true)
  263. {
  264. pObject_repeat->SetlengthStart(mpLElengthStart->text().toDouble());
  265. }
  266. else
  267. {
  268. pObject_repeat->DeletelengthStart();
  269. }
  270. if(ViewCreate::CheckLE(mpLElengthEnd,"lengthEnd",false,this) == true)
  271. {
  272. pObject_repeat->SetlengthEnd(mpLElengthEnd->text().toDouble());
  273. }
  274. else
  275. {
  276. pObject_repeat->DeletelengthEnd();
  277. }
  278. if(ViewCreate::CheckLE(mpLEradiusStart,"radiusStart",false,this) == true)
  279. {
  280. pObject_repeat->SetradiusStart(mpLEradiusStart->text().toDouble());
  281. }
  282. else
  283. {
  284. pObject_repeat->DeleteradiusStart();
  285. }
  286. if(ViewCreate::CheckLE(mpLEradiusEnd,"radiusEnd",false,this) == true)
  287. {
  288. pObject_repeat->SetradiusEnd(mpLEradiusEnd->text().toDouble());
  289. }
  290. else
  291. {
  292. pObject_repeat->DeleteradiusEnd();
  293. }
  294. UpdateList();
  295. }