dialogroadobject.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. #include "dialogroadobject.h"
  2. #include "ui_dialogroadobject.h"
  3. #include <QMessageBox>
  4. static std::string strobjecttypelist[] ={"none","obstacle","car","pole",
  5. "tree","vegetation","barrier","building","parkingSpace","patch",
  6. "railing","trafficIsland","crosswalk","streetLamp","gantry",
  7. "soundBarrier","van","bus","trailer","bike","motorbike",
  8. "tram","train","pedestrian","wind","roadMark"};
  9. const static int objectlistcount = 26;
  10. DialogRoadObject::DialogRoadObject(Road * pRoad,QWidget *parent) :
  11. QDialog(parent),
  12. ui(new Ui::DialogRoadObject)
  13. {
  14. ui->setupUi(this);
  15. mpRoad = pRoad;
  16. if(pRoad == 0)
  17. {
  18. ui->pushButton_add->setEnabled(false);
  19. ui->pushButton_change->setEnabled(false);
  20. ui->pushButton_delete->setEnabled(false);
  21. }
  22. else
  23. {
  24. ui->lineEdit_RoadID->setText(pRoad->GetRoadId().data());
  25. ui->lineEdit_RoadLen->setText(QString::number(pRoad->GetRoadLength()));
  26. }
  27. CreateView();
  28. int i;
  29. for(i=0;i<objectlistcount;i++)
  30. {
  31. mpCBtype->addItem(strobjecttypelist[i].data());
  32. }
  33. mpCBtype->setCurrentIndex(8);
  34. mpCBdynamic->addItem("no");
  35. mpCBdynamic->addItem("yes");
  36. mpCBdynamic->addItem("undefined");
  37. mpCBdynamic->setCurrentIndex(2);
  38. mpCBorientation->addItem("+");
  39. mpCBorientation->addItem("-");
  40. mpCBorientation->addItem("none");
  41. mpCBorientation->addItem("undefined");
  42. mpCBorientation->setCurrentIndex(3);
  43. int nobjectcount = pRoad->GetObjectCount();
  44. for(i=0;i<nobjectcount;i++)
  45. {
  46. Object * pObject = pRoad->GetObject(i);
  47. ui->comboBox_Object->addItem("Object s:"+QString::number(pObject->Gets()));
  48. }
  49. setWindowTitle("Edit Road Object");
  50. }
  51. DialogRoadObject::~DialogRoadObject()
  52. {
  53. delete ui;
  54. }
  55. void DialogRoadObject::CreateView()
  56. {
  57. int startpos_x = 30;
  58. int startpos_y = 150;
  59. int nSpace = 300;
  60. int nLabelWidth = 100;
  61. int nLEWidth = 150;
  62. int nHeight = 30;
  63. int nVSpace = 50;
  64. int nVIndex = 0;
  65. mpLEt = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"t",this);
  66. mpLEzOffset = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"zOffset",this);
  67. mpCBtype = ViewCreate::CreateCB(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"type",this);
  68. nVIndex++;
  69. mpLEvalidLength = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"validLength",this);
  70. mpCBorientation = ViewCreate::CreateCB(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"orientation",this);
  71. mpLEsubtype = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"subtype",this);
  72. nVIndex++;
  73. mpCBdynamic = ViewCreate::CreateCB(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"dynamic",this);
  74. mpLEhdg = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"hdg",this);
  75. mpLEname = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"name",this);
  76. nVIndex++;
  77. mpLEpitch = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"pitch",this);
  78. mpLEid = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"id",this);
  79. mpLEroll = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"roll",this);
  80. nVIndex++;
  81. mpLEheight = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"height",this);
  82. mpLEs = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"s",this);
  83. mpLElength = ViewCreate::CreateLE(startpos_x+2*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"length",this);
  84. nVIndex++;
  85. mpLEwidth = ViewCreate::CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"width",this);
  86. mpLEradius = ViewCreate::CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"radius",this);
  87. int nPBSpace = 200;
  88. int nPBWidth = 150;
  89. nVIndex++;
  90. mpPBmaterial = ViewCreate::CreatePB(startpos_x+0*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"material",this);
  91. mpPBrepeat = ViewCreate::CreatePB(startpos_x+1*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"repeat",this);
  92. mpPBparkingspace = ViewCreate::CreatePB(startpos_x+2*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"parkingspace",this);
  93. mpPBoutlines = ViewCreate::CreatePB(startpos_x+3*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"outlines",this);
  94. nVIndex++;
  95. mpPBoutline = ViewCreate::CreatePB(startpos_x+0*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"outline",this);
  96. mpPBmarkings = ViewCreate::CreatePB(startpos_x+1*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"markings",this);
  97. mpPBborders = ViewCreate::CreatePB(startpos_x+2*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"borders",this);
  98. mpPBvalidity = ViewCreate::CreatePB(startpos_x+3*nPBSpace,startpos_y+nVIndex*nVSpace,nPBWidth,nHeight,"validity",this);
  99. connect(mpPBmaterial,SIGNAL(clicked(bool)),this,SLOT(onClickMaterial()));
  100. connect(mpPBrepeat,SIGNAL(clicked(bool)),this,SLOT(onClickRepeat()));
  101. connect(mpPBparkingspace,SIGNAL(clicked(bool)),this,SLOT(onClickParkingSpace()));
  102. }
  103. void DialogRoadObject::on_pushButton_add_clicked()
  104. {
  105. Road * pRoad = mpRoad;
  106. if(ViewCreate::CheckLE(mpLEid,"id",true,this) == false)return;
  107. string id = mpLEid->text().toStdString();
  108. if(ViewCreate::CheckLE(mpLEt,"t",true,this) == false)return;
  109. double t = mpLEt->text().toDouble();
  110. if(ViewCreate::CheckLE(mpLEs,"s",true,this) == false)return;
  111. double s = mpLEs->text().toDouble();
  112. if(ViewCreate::CheckLE(mpLEzOffset,"zOffset",true,this) == false)return;
  113. double zOffset = mpLEzOffset->text().toDouble();
  114. double length,width,hdg;
  115. if(mpCBtype->currentText() == "parkingSpace")
  116. {
  117. if(ViewCreate::CheckLE(mpLElength,"length",true,this) == false)return;
  118. length = mpLElength->text().toDouble();
  119. if(ViewCreate::CheckLE(mpLEwidth,"width",true,this) == false)return;
  120. width = mpLEwidth->text().toDouble();
  121. if(ViewCreate::CheckLE(mpLEhdg,"hdg",true,this) == false)return;
  122. hdg = mpLEhdg->text().toDouble();
  123. }
  124. pRoad->AddObject(id,s,t,zOffset);
  125. Object * pObject = pRoad->GetLastAddedObject();
  126. pObject->Settype(mpCBtype->currentText().toStdString());
  127. if(ViewCreate::CheckLE(mpLEvalidLength,"validLength",false,this))
  128. {
  129. pObject->SetvalidLength(mpLEvalidLength->text().toDouble());
  130. }
  131. if(mpCBorientation->currentIndex() != 3)
  132. {
  133. pObject->Setorientation(mpCBorientation->currentText().toStdString());
  134. }
  135. if(ViewCreate::CheckLE(mpLEsubtype,"subtype",false,this))
  136. {
  137. pObject->Setsubtype(mpLEsubtype->text().toStdString());
  138. }
  139. if(mpCBdynamic->currentIndex()!= 2)
  140. {
  141. pObject->Setdynamic(mpCBdynamic->currentText().toStdString());
  142. }
  143. if(ViewCreate::CheckLE(mpLEname,"name",false,this))
  144. {
  145. pObject->Setname(mpLEname->text().toStdString());
  146. }
  147. if(ViewCreate::CheckLE(mpLEhdg,"hdg",false,this))
  148. {
  149. pObject->Sethdg(mpLEhdg->text().toDouble());
  150. }
  151. if(ViewCreate::CheckLE(mpLEpitch,"pitch",false,this))
  152. {
  153. pObject->Setpitch(mpLEpitch->text().toDouble());
  154. }
  155. if(ViewCreate::CheckLE(mpLEroll,"roll",false,this))
  156. {
  157. pObject->Setroll(mpLEroll->text().toDouble());
  158. }
  159. if(ViewCreate::CheckLE(mpLEheight,"height",false,this))
  160. {
  161. pObject->Setheight(mpLEheight->text().toDouble());
  162. }
  163. if(ViewCreate::CheckLE(mpLElength,"length",false,this))
  164. {
  165. pObject->Setlength(mpLElength->text().toDouble());
  166. }
  167. if(ViewCreate::CheckLE(mpLEwidth,"width",false,this))
  168. {
  169. pObject->Setwidth(mpLEwidth->text().toDouble());
  170. }
  171. if(ViewCreate::CheckLE(mpLEradius,"radius",false,this))
  172. {
  173. pObject->Setradius(mpLEradius->text().toDouble());
  174. }
  175. ui->comboBox_Object->addItem("Object s:"+QString::number(pObject->Gets()));
  176. }
  177. void DialogRoadObject::on_comboBox_Object_currentIndexChanged(int index)
  178. {
  179. Road * pRoad = mpRoad;
  180. if(pRoad == 0)return;
  181. if(index < 0)return;
  182. if(index >= mpRoad->GetObjectCount())
  183. {
  184. return;
  185. }
  186. Object * pObject = mpRoad->GetObject(index);
  187. if(pObject == 0)return;
  188. mpLEt->setText(QString::number(pObject->Gett()));
  189. mpLEzOffset->setText(QString::number(pObject->GetzOffset()));
  190. string type = pObject->Gettype();
  191. int i;
  192. for(i=0;i<objectlistcount;i++)
  193. {
  194. if(strobjecttypelist[i] == type)break;
  195. }
  196. if(i<objectlistcount)mpCBtype->setCurrentIndex(i);
  197. double validLength;
  198. if(pObject->GetvalidLength(validLength) == 1)
  199. {
  200. mpLEvalidLength->setText(QString::number(validLength));
  201. }
  202. else
  203. mpLEvalidLength->setText("");
  204. string strorientation = pObject->Getorientation();
  205. if(strorientation == "")
  206. {
  207. mpCBorientation->setCurrentIndex(3);
  208. }
  209. else
  210. {
  211. if(strorientation == "+")mpCBorientation->setCurrentIndex(0);
  212. else
  213. {
  214. if(strorientation == "-")mpCBorientation->setCurrentIndex(1);
  215. else mpCBorientation->setCurrentIndex(2);
  216. }
  217. }
  218. string strtype = pObject->Getsubtype();
  219. if(strtype != "")pObject->Setsubtype(strtype);
  220. string strdynamic = pObject->Getdynamic();
  221. if(strdynamic == "")
  222. {
  223. mpCBdynamic->setCurrentIndex(2);
  224. }
  225. else
  226. {
  227. if(strdynamic == "no")mpCBdynamic->setCurrentIndex(0);
  228. else mpCBdynamic->setCurrentIndex(1);
  229. }
  230. double hdg;
  231. if(pObject->Gethdg(hdg) == 1)mpLEhdg->setText(QString::number(hdg));
  232. else mpLEhdg->setText("");
  233. mpLEname->setText(pObject->Getname().data());
  234. double pitch;
  235. if(pObject->Getpitch(pitch) == 1)mpLEpitch->setText(QString::number(pitch));
  236. else mpLEpitch->setText("");
  237. mpLEid->setText(pObject->Getid().data());
  238. double roll;
  239. if(pObject->Getroll(roll) == 1)mpLEroll->setText(QString::number(roll));
  240. else mpLEroll->setText("");
  241. double height;
  242. if(pObject->Getheight(height) == 1)mpLEheight->setText(QString::number(height));
  243. else mpLEheight->setText("");
  244. mpLEs->setText(QString::number(pObject->Gets()));
  245. double length;
  246. if(pObject->Getlength(length) == 1)mpLElength->setText(QString::number(length));
  247. else mpLElength->setText("");
  248. double width;
  249. if(pObject->Getwidth(width) == 1)mpLEwidth->setText(QString::number(width));
  250. else mpLEwidth->setText("");
  251. double radius;
  252. if(pObject->Getradius(radius) == 1)mpLEradius->setText(QString::number(radius));
  253. else mpLEradius->setText("");
  254. }
  255. void DialogRoadObject::on_pushButton_delete_clicked()
  256. {
  257. if(mpRoad == 0)return;
  258. Road * pRoad = mpRoad;
  259. if(pRoad->GetObjectCount() == 0)
  260. {
  261. QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
  262. return;
  263. }
  264. int index = ui->comboBox_Object->currentIndex();
  265. if(index<0)return;
  266. if(index >= mpRoad->GetObjectCount())return;
  267. pRoad->DeleteObject(index);
  268. ui->comboBox_Object->removeItem(index);
  269. }
  270. void DialogRoadObject::on_pushButton_change_clicked()
  271. {
  272. if(mpRoad == 0)return;
  273. Road * pRoad = mpRoad;
  274. if(pRoad->GetObjectCount() == 0)
  275. {
  276. QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
  277. return;
  278. }
  279. int index = ui->comboBox_Object->currentIndex();
  280. if(index<0)return;
  281. if(index >= mpRoad->GetObjectCount())return;
  282. Object * pObject = mpRoad->GetObject(index);
  283. if(pObject == 0)
  284. {
  285. QMessageBox::warning(this,"Warning","Can't found Object.",QMessageBox::YesAll);
  286. return;
  287. }
  288. if(ViewCreate::CheckLE(mpLEid,"id",true,this) == false)return;
  289. string id = mpLEid->text().toStdString();
  290. if(ViewCreate::CheckLE(mpLEt,"t",true,this) == false)return;
  291. double t = mpLEt->text().toDouble();
  292. if(ViewCreate::CheckLE(mpLEs,"s",true,this) == false)return;
  293. double s = mpLEs->text().toDouble();
  294. if(ViewCreate::CheckLE(mpLEzOffset,"zOffset",true,this) == false)return;
  295. double zOffset = mpLEzOffset->text().toDouble();
  296. double length,width,hdg;
  297. if(mpCBtype->currentText() == "parkingSpace")
  298. {
  299. if(ViewCreate::CheckLE(mpLElength,"length",true,this) == false)return;
  300. length = mpLElength->text().toDouble();
  301. if(ViewCreate::CheckLE(mpLEwidth,"width",true,this) == false)return;
  302. width = mpLEwidth->text().toDouble();
  303. if(ViewCreate::CheckLE(mpLEhdg,"hdg",true,this) == false)return;
  304. hdg = mpLEhdg->text().toDouble();
  305. }
  306. pObject->Setid(id);
  307. pObject->Sets(s);
  308. pObject->Sett(t);
  309. pObject->SetzOffset(zOffset);
  310. pObject->Settype(mpCBtype->currentText().toStdString());
  311. if(ViewCreate::CheckLE(mpLEvalidLength,"validLength",false,this))
  312. {
  313. pObject->SetvalidLength(mpLEvalidLength->text().toDouble());
  314. }
  315. if(mpCBorientation->currentIndex() != 3)
  316. {
  317. pObject->Setorientation(mpCBorientation->currentText().toStdString());
  318. }
  319. if(ViewCreate::CheckLE(mpLEsubtype,"subtype",false,this))
  320. {
  321. pObject->Setsubtype(mpLEsubtype->text().toStdString());
  322. }
  323. if(mpCBdynamic->currentIndex()!= 2)
  324. {
  325. pObject->Setdynamic(mpCBdynamic->currentText().toStdString());
  326. }
  327. if(ViewCreate::CheckLE(mpLEhdg,"hdg",false,this))
  328. {
  329. pObject->Sethdg(mpLEhdg->text().toDouble());
  330. }
  331. if(ViewCreate::CheckLE(mpLEname,"name",false,this))
  332. {
  333. pObject->Setname(mpLEname->text().toStdString());
  334. }
  335. if(ViewCreate::CheckLE(mpLEpitch,"pitch",false,this))
  336. {
  337. pObject->Setpitch(mpLEpitch->text().toDouble());
  338. }
  339. if(ViewCreate::CheckLE(mpLEroll,"roll",false,this))
  340. {
  341. pObject->Setroll(mpLEroll->text().toDouble());
  342. }
  343. if(ViewCreate::CheckLE(mpLEheight,"height",false,this))
  344. {
  345. pObject->Setheight(mpLEheight->text().toDouble());
  346. }
  347. if(ViewCreate::CheckLE(mpLElength,"length",false,this))
  348. {
  349. pObject->Setlength(mpLElength->text().toDouble());
  350. }
  351. if(ViewCreate::CheckLE(mpLEwidth,"width",false,this))
  352. {
  353. pObject->Setwidth(mpLEwidth->text().toDouble());
  354. }
  355. if(ViewCreate::CheckLE(mpLEradius,"radius",false,this))
  356. {
  357. pObject->Setradius(mpLEradius->text().toDouble());
  358. }
  359. QMessageBox::information(this,"Info","Change Object Successfull.",QMessageBox::YesAll);
  360. }
  361. void DialogRoadObject::onClickMaterial()
  362. {
  363. if(mpRoad == 0)return;
  364. Road * pRoad = mpRoad;
  365. if(pRoad->GetObjectCount() == 0)
  366. {
  367. QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
  368. return;
  369. }
  370. int index = ui->comboBox_Object->currentIndex();
  371. if(index<0)return;
  372. if(index >= mpRoad->GetObjectCount())return;
  373. Object * pObject = mpRoad->GetObject(index);
  374. if(pObject == 0)
  375. {
  376. QMessageBox::warning(this,"Warning","Can't found Object.",QMessageBox::YesAll);
  377. return;
  378. }
  379. DialogRoadObject_material dlgmaterail(pObject);
  380. dlgmaterail.exec();
  381. }
  382. void DialogRoadObject::onClickRepeat()
  383. {
  384. if(mpRoad == 0)return;
  385. Road * pRoad = mpRoad;
  386. if(pRoad->GetObjectCount() == 0)
  387. {
  388. QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
  389. return;
  390. }
  391. int index = ui->comboBox_Object->currentIndex();
  392. if(index<0)return;
  393. if(index >= mpRoad->GetObjectCount())return;
  394. Object * pObject = mpRoad->GetObject(index);
  395. if(pObject == 0)
  396. {
  397. QMessageBox::warning(this,"Warning","Can't found Object.",QMessageBox::YesAll);
  398. return;
  399. }
  400. DialogRoadObject_repeat dlgrepeat(pObject);
  401. dlgrepeat.exec();
  402. }
  403. void DialogRoadObject::onClickParkingSpace()
  404. {
  405. if(mpRoad == 0)return;
  406. Road * pRoad = mpRoad;
  407. if(pRoad->GetObjectCount() == 0)
  408. {
  409. QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
  410. return;
  411. }
  412. int index = ui->comboBox_Object->currentIndex();
  413. if(index<0)return;
  414. if(index >= mpRoad->GetObjectCount())return;
  415. Object * pObject = mpRoad->GetObject(index);
  416. if(pObject == 0)
  417. {
  418. QMessageBox::warning(this,"Warning","Can't found Object.",QMessageBox::YesAll);
  419. return;
  420. }
  421. DialogRoadObject_parkingSpace dlgparkingspace(pObject);
  422. dlgparkingspace.exec();
  423. }