mainwindow.cpp 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <iomanip>//不要忘记包含此头文件
  4. #include <QScrollBar>
  5. #include <QFileInfo>
  6. #include <QInputDialog>
  7. #include "gpsimu.pb.h"
  8. #include "gnss_coordinate_convert.h"
  9. #include "ndsdataproc.h"
  10. #define VIEW_WIDTH 10000
  11. #define VIEW_HEIGHT 10000
  12. double glon0 = 117.0866293;
  13. double glat0 = 39.1364713;
  14. double ghdg0 = 360;
  15. MainWindow * gw;
  16. MainWindow::MainWindow(QWidget *parent) :
  17. QMainWindow(parent),
  18. ui(new Ui::MainWindow)
  19. {
  20. gw = this;
  21. ui->setupUi(this);
  22. mnfac = 1;
  23. mnMoveX = VIEW_WIDTH/2;
  24. mnMoveY = VIEW_HEIGHT/2;
  25. mnDefmnfac = mnfac;
  26. mnDefMoveX = mnMoveX;
  27. mnDefMoveY = mnMoveY;
  28. QIcon icon(":/opendrive.png");
  29. setWindowIcon(icon);
  30. //Create View
  31. myview = new MyView(this);
  32. myview->setObjectName(QStringLiteral("graphicsView"));
  33. myview->setGeometry(QRect(30, 30, 600, 600));
  34. connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double)));
  35. image = new QImage(VIEW_WIDTH, VIEW_HEIGHT, QImage::Format_RGB32);//画布的初始化大小设为300*300,使用32位颜色
  36. myview->setCacheMode(myview->CacheBackground);
  37. painter = new QPainter(image);
  38. painter->end();
  39. scene = new QGraphicsScene;
  40. mpscene = new QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
  41. mpscene->setBackgroundBrush(Qt::darkGreen);
  42. //Create Tab
  43. QTabWidget * p = new QTabWidget(ui->centralWidget);
  44. p->setGeometry(30,30,300,300);
  45. mnFontHeight = ui->centralWidget->fontMetrics().height();
  46. CreateTab1View(p);
  47. mpLabel_Status = new QLabel(this);
  48. ui->statusBar->addPermanentWidget(mpLabel_Status);
  49. mTabMain = p;
  50. //Create Timer
  51. QTimer * timer = new QTimer();
  52. connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
  53. timer->start(1000);
  54. //Create File Backup
  55. mpfb = new FileBackup();
  56. mpfb->start();
  57. //Create Draw Dialog
  58. mpdlgdraw = new DialogDrawRoad(&mxodr, this);
  59. connect(mpdlgdraw,SIGNAL(drawnewroad()),this,SLOT(onDrawNewRoad()));
  60. setWindowTitle("Create Map From Lane Info");
  61. // NDSDataProc::ProcNDSData("/home/yuchuli/下载/nds-sync-line.csv","/home/yuchuli/下载/nds-sync-vehicle.csv");
  62. }
  63. MainWindow::~MainWindow()
  64. {
  65. delete mpfb;
  66. delete ui;
  67. }
  68. void MainWindow::resizeEvent(QResizeEvent *event)
  69. {
  70. (void)event;
  71. qDebug("resize");
  72. QSize sizemain = ui->centralWidget->size();
  73. qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
  74. AdjustWPos(sizemain);
  75. }
  76. void MainWindow::AdjustWPos(QSize sizemain)
  77. {
  78. myview->setGeometry(0,30,sizemain.width()-mnFontHeight * 22 - 30,sizemain.height());
  79. mTabMain->setGeometry(sizemain.width()-mnFontHeight * 22,30,mnFontHeight * 22,sizemain.height()-50);
  80. }
  81. void MainWindow::ExecPainter()
  82. {
  83. painter->begin(image);
  84. image->fill(QColor(255, 255, 255));//对画布进行填充
  85. painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
  86. //Set Move
  87. painter->translate(mnMoveX,mnMoveY);
  88. painter->setPen(Qt::black);
  89. painter->drawLine(VIEW_WIDTH/(-2),0,VIEW_WIDTH/2,0);
  90. painter->drawLine(0,VIEW_HEIGHT/(-2),0,VIEW_HEIGHT/2);
  91. int i;
  92. painter->setPen(Qt::blue);
  93. int nfac = mnfac;
  94. (void)nfac;
  95. if(mbClick)
  96. {
  97. painter->setPen(Qt::red);
  98. painter->drawEllipse(QPoint(mClickX ,mClickY),mnMarkSize,mnMarkSize);
  99. painter->setPen(Qt::black);
  100. }
  101. if(mbSetObj)
  102. {
  103. painter->setPen(Qt::green);
  104. painter->drawRect(mfObjX*mnfac-mnMarkSize,mfObjY*mnfac*(-1)-mnMarkSize,mnMarkSize*2,mnMarkSize*2);
  105. painter->setPen(Qt::black);
  106. }
  107. painter->setPen(Qt::green);
  108. double x0,y0;
  109. GaussProjCal(glon0,glat0,&x0,&y0);
  110. painter->setPen(Qt::blue);
  111. int selid = mpCBRoad->currentText().toInt();
  112. for(i=0;i<static_cast<int>( mxodr.GetRoadCount());i++)
  113. {
  114. int j;
  115. Road * pRoad = mxodr.GetRoad(i);
  116. painter->setPen(Qt::blue);
  117. if(selid == atoi(pRoad->GetRoadId().data()))
  118. {
  119. painter->setPen(Qt::red);
  120. }
  121. if(IsHidenRoad(atoi(pRoad->GetRoadId().data())))
  122. {
  123. continue;
  124. }
  125. if(mxodr.GetRoad(i)->GetGeometryBlockCount()>0)
  126. {
  127. GeometryBlock * pgeob = pRoad->GetGeometryBlock(0);
  128. double x,y;
  129. RoadGeometry * pg;
  130. pg = pgeob->GetGeometryAt(0);
  131. x = pg->GetX();
  132. y = pg->GetY();
  133. double endx,endy,endhdg;
  134. GetEndPoint(pRoad,endx,endy,endhdg);
  135. x = (x+endx)/2;
  136. y = (y+endy)/2;
  137. x = x + mfViewMoveX;
  138. y = y + mfViewMoveY;
  139. painter->drawText(x*mnfac,y*mnfac*(-1),mxodr.GetRoad(i)->GetRoadId().data());
  140. }
  141. for(j=0;j<static_cast<int>(mxodr.GetRoad(i)->GetGeometryBlockCount());j++)
  142. {
  143. GeometryBlock * pgeob = pRoad->GetGeometryBlock(j);
  144. double x,y;
  145. double x_center,y_center;
  146. double R;
  147. RoadGeometry * pg;
  148. GeometryArc * parc;
  149. GeometryParamPoly3 * ppp3;
  150. GeometrySpiral *pSpiral;
  151. GeometryPoly3 *ppoly;
  152. double rel_x,rel_y,rel_hdg;
  153. pg = pgeob->GetGeometryAt(0);
  154. x = pg->GetX();
  155. y = pg->GetY();
  156. x = x + mfViewMoveX;
  157. y = y + mfViewMoveY;
  158. if(j== 0)
  159. {
  160. if(selid == atoi(pRoad->GetRoadId().data()))
  161. {
  162. painter->setPen(Qt::green);
  163. painter->drawEllipse(x*mnfac-5,y*mnfac*(-1)-5,10,10);
  164. painter->setPen(Qt::red);
  165. }
  166. }
  167. switch (pg->GetGeomType()) {
  168. case 0:
  169. painter->drawLine(QPoint(x*mnfac,y*mnfac*(-1)),
  170. QPoint((x + pg->GetLength() * cos(pg->GetHdg()))*mnfac,(y + pg->GetLength() * sin(pg->GetHdg()))*mnfac*(-1)));
  171. break;
  172. case 1:
  173. pSpiral = (GeometrySpiral * )pg;
  174. {
  175. int ncount = pSpiral->GetLength() * mnfac;
  176. double sstep = pSpiral->GetLength()/((double)ncount);
  177. int k;
  178. double x0,y0,hdg0,s0;
  179. (void)x0;
  180. (void)y0;
  181. (void)hdg0;
  182. s0 = pSpiral->GetS();
  183. painter->setPen(Qt::red);
  184. for(k=0;k<ncount;k++)
  185. {
  186. pSpiral->GetCoords(s0+sstep*k,rel_x,rel_y,rel_hdg);
  187. x = rel_x;
  188. y = rel_y;
  189. x = x + mfViewMoveX;
  190. y = y + mfViewMoveY;
  191. painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
  192. }
  193. painter->setPen(Qt::blue);
  194. }
  195. break;
  196. case 2:
  197. {
  198. parc = (GeometryArc *)pg;
  199. R = abs(1.0/parc->GetCurvature());
  200. if(parc->GetCurvature() > 0)
  201. {
  202. x_center = pg->GetX() + R *cos(pg->GetHdg() + M_PI/2.0);
  203. y_center = pg->GetY() + R * sin(pg->GetHdg() + M_PI/2.0);
  204. }
  205. else
  206. {
  207. x_center = pg->GetX() + R *cos(pg->GetHdg() -M_PI/2.0);
  208. y_center = pg->GetY() + R * sin(pg->GetHdg() - M_PI/2.0);
  209. }
  210. int k;
  211. int ncount = parc->GetLength() * mnfac ;
  212. double curv = parc->GetCurvature();
  213. double hdgstep;
  214. double hdg0 = parc->GetHdg();
  215. double hdgnow = parc->GetHdg();(void)hdgnow;
  216. if(ncount > 0) hdgstep= (parc->GetLength()/R)/ncount;
  217. for(k=0;k<ncount;k++)
  218. {
  219. double x_draw,y_draw;
  220. if(curv > 0)
  221. {
  222. hdgnow = hdg0 + k*hdgstep;
  223. x_draw = x_center + R *cos(hdgnow - M_PI/2.0);
  224. y_draw = y_center + R * sin(hdgnow - M_PI/2.0);
  225. }
  226. else
  227. {
  228. hdgnow = hdg0 - k * hdgstep;
  229. x_draw = x_center + R *cos(hdgnow + M_PI/2.0);
  230. y_draw = y_center + R * sin(hdgnow + M_PI/2.0);
  231. }
  232. x_draw = x_draw + mfViewMoveX;
  233. y_draw = y_draw + mfViewMoveY;
  234. painter->drawPoint(x_draw * mnfac ,y_draw * mnfac *(-1));
  235. }
  236. }
  237. break;
  238. case 3:
  239. {
  240. ppoly = (GeometryPoly3 *)pg;
  241. x = pg->GetX();
  242. y = pg->GetY();
  243. double A,B,C,D;
  244. A = ppoly->GetA();
  245. B = ppoly->GetB();
  246. C = ppoly->GetC();
  247. D = ppoly->GetD();
  248. const double steplim = 0.1;
  249. double du = steplim;
  250. double u = 0;
  251. double v = 0;
  252. double oldx,oldy;
  253. oldx = x;
  254. oldy = y;
  255. double xstart,ystart;
  256. xstart = x;
  257. ystart = y;
  258. double hdgstart = ppoly->GetHdg();
  259. double flen = 0;
  260. while(flen < ppoly->GetLength())
  261. {
  262. double fdis = 0;
  263. v = A + B*u + C*u*u + D*u*u*u;
  264. x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
  265. y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
  266. fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
  267. oldx = x;
  268. oldy = y;
  269. if(fdis>(steplim*2.0))du = du/2.0;
  270. flen = flen + fdis;
  271. u = u + du;
  272. std::cout<<" x: "<<x<<" y:"<<y<<std::endl;
  273. x = x + mfViewMoveX;
  274. y = y + mfViewMoveY;
  275. painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
  276. }
  277. }
  278. break;
  279. case 4:
  280. {
  281. ppp3 = (GeometryParamPoly3 * )pg;
  282. int ncount = ppp3->GetLength()* mnfac;
  283. double sstep;
  284. bool bNormal = ppp3->GetNormal();
  285. double arclength = ppp3->GetLength();
  286. if(ncount > 0)sstep = ppp3->GetLength()/ncount;
  287. else sstep = 10000.0;
  288. double s = 0;
  289. while(s < ppp3->GetLength())
  290. {
  291. double xtem,ytem;
  292. double pRange =s;
  293. if(bNormal && (arclength>0))pRange = s/arclength;
  294. xtem = ppp3->GetuA() + ppp3->GetuB() * pRange + ppp3->GetuC() * pRange*pRange + ppp3->GetuD() * pRange*pRange*pRange;
  295. ytem = ppp3->GetvA() + ppp3->GetvB() * pRange + ppp3->GetvC() * pRange*pRange + ppp3->GetvD() * pRange*pRange*pRange;
  296. x = xtem*cos(ppp3->GetHdg()) - ytem * sin(ppp3->GetHdg()) + ppp3->GetX();
  297. y = xtem*sin(ppp3->GetHdg()) + ytem * cos(ppp3->GetHdg()) + ppp3->GetY();
  298. x = x + mfViewMoveX;
  299. y = y + mfViewMoveY;
  300. painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
  301. s = s+ sstep;
  302. }
  303. }
  304. break;
  305. default:
  306. break;
  307. }
  308. }
  309. }
  310. for(i=0;i<static_cast<int>( mvectorlp.size());i++)
  311. {
  312. if(!mbShowLane)continue;
  313. if(i == mnMarkLane)
  314. {
  315. painter->setPen(Qt::red);
  316. }
  317. else
  318. {
  319. painter->setPen(Qt::blue);
  320. }
  321. int npsize = mvectorlp[i].mvectorlpleft.size();
  322. int j;
  323. for(j=0;j<npsize;j++)
  324. {
  325. double x,y;
  326. double lon,lat;
  327. lon = mvectorlp[i].mvectorlpleft[j].mfLon;
  328. lat = mvectorlp[i].mvectorlpleft[j].mfLat;
  329. GaussProjCal(lon,lat,&x,&y);
  330. x = x-x0;
  331. y= y-y0;
  332. painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
  333. lon = mvectorlp[i].mvectorlpright[j].mfLon;
  334. lat = mvectorlp[i].mvectorlpright[j].mfLat;
  335. GaussProjCal(lon,lat,&x,&y);
  336. x = x-x0;
  337. y= y-y0;
  338. x = x + mfViewMoveX;
  339. y = y + mfViewMoveY;
  340. painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
  341. }
  342. }
  343. painter->setPen(Qt::green);
  344. painter->end();
  345. }
  346. //刷新
  347. void MainWindow::paintEvent(QPaintEvent *)
  348. {
  349. if(mnViewMode == 1)
  350. {
  351. if(mbRefresh)
  352. {
  353. // UpdateScene();
  354. }
  355. myview->setScene(mpscene);
  356. myview->show();
  357. return;
  358. }
  359. if(mbRefresh)
  360. {
  361. ExecPainter();
  362. // qDebug(" time is %d ",x.elapsed());
  363. mbRefresh = false;
  364. }
  365. scene->clear();
  366. scene->addPixmap(QPixmap::fromImage(*image));
  367. myview->setScene(scene);
  368. myview->show();
  369. if(mbInit == false)
  370. {
  371. myview->horizontalScrollBar()->setValue((mnMoveX - 800));
  372. myview->verticalScrollBar()->setValue((mnMoveY - 500));
  373. mbInit = true;
  374. }
  375. // qDebug(" time 2 is %d ",x.elapsed());
  376. }
  377. void MainWindow::onTimer()
  378. {
  379. }
  380. void MainWindow::CreateTab1View(QTabWidget * p)
  381. {
  382. QGroupBox * pGroup = new QGroupBox();
  383. pGroup->setGeometry(0,0,mnFontHeight * 21,mnFontHeight * 160);
  384. QLabel * pLabel;
  385. QLineEdit * pLE;
  386. QPushButton * pPB;
  387. QSlider * pSlider;
  388. QComboBox * pCB;
  389. int nXPos = 10;
  390. int nYPos = 30;
  391. int i;
  392. (void)i;
  393. int nSpace = mnFontHeight * 65/10;
  394. int nLEWidth = mnFontHeight * 6;
  395. int nLEHeight = mnFontHeight * 3/2;
  396. pLabel = new QLabel(pGroup);
  397. pLabel->setText(tr("View Mode"));
  398. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  399. nXPos = nXPos + nSpace;
  400. pCB = new QComboBox(pGroup);
  401. pCB->addItem(tr("Line"));
  402. pCB->addItem(tr("Scene"));
  403. pCB->setCurrentIndex(0);
  404. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  405. mpCBViewMode = pCB;
  406. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onViewModeChange(int)));
  407. nXPos = 10;
  408. nYPos = nYPos + mnFontHeight * 3;
  409. pLabel = new QLabel(pGroup);
  410. pLabel->setText(tr("Lat0"));
  411. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  412. nXPos = nXPos + nSpace;
  413. pLabel = new QLabel(pGroup);
  414. pLabel->setText(tr("Lon0"));
  415. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  416. nXPos = nXPos + nSpace;
  417. pLabel = new QLabel(pGroup);
  418. pLabel->setText(tr("Head0"));
  419. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  420. // nXPos = nXPos + nSpace;
  421. nXPos = 10;
  422. nYPos = nYPos + mnFontHeight * 2;
  423. pLE = new QLineEdit(pGroup);
  424. pLE->setText(QString::number(glat0,'f',7));
  425. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  426. mpLELat0 = pLE;
  427. nXPos = nXPos + nSpace;
  428. pLE = new QLineEdit(pGroup);
  429. pLE->setText(QString::number(glon0,'f',7));
  430. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  431. mpLELon0 = pLE;
  432. nXPos = nXPos + nSpace;
  433. pLE = new QLineEdit(pGroup);
  434. pLE->setText(QString::number(ghdg0,'f',3));
  435. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  436. mpLEHead0 = pLE;
  437. // nXPos = nXPos + nSpace;
  438. nXPos = 10;
  439. nYPos = nYPos + mnFontHeight * 2;
  440. pLabel = new QLabel(pGroup);
  441. pLabel->setText(tr("ViewMove"));
  442. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  443. nXPos = nXPos + nSpace;
  444. pLE = new QLineEdit(pGroup);
  445. pLE->setText(QString::number(mfViewMoveX,'f',2));
  446. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  447. mpLEViewMoveX = pLE;
  448. nXPos = nXPos + nSpace;
  449. pLE = new QLineEdit(pGroup);
  450. pLE->setText(QString::number(mfViewMoveY,'f',2));
  451. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  452. mpLEViewMoveY = pLE;
  453. // nXPos = nXPos + nSpace;
  454. nXPos = 10;
  455. nYPos = nYPos + mnFontHeight * 4;
  456. pPB = new QPushButton(pGroup);
  457. pPB->setText(tr("Restore Default View"));
  458. pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
  459. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDefView()));
  460. nXPos = nXPos + mnFontHeight * 11;
  461. pPB = new QPushButton(pGroup);
  462. pPB->setText(tr("Zoom One"));
  463. pPB->setGeometry(nXPos,nYPos,mnFontHeight*6,nLEHeight);
  464. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickZoomOne()));
  465. nXPos = 10;
  466. nYPos = nYPos + mnFontHeight * 4;
  467. pLabel = new QLabel(pGroup);
  468. pLabel->setText(tr("Scale"));
  469. pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  470. nXPos = nXPos + mnFontHeight * 4;
  471. pSlider = new QSlider(pGroup);
  472. pSlider->setOrientation(Qt::Horizontal);
  473. pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
  474. pSlider->setRange(1,100);
  475. pSlider->setValue(mnfac);
  476. connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeScale(int)));
  477. mpSlider_Scale = pSlider;
  478. nXPos = nXPos + mnFontHeight*11;
  479. pLE = new QLineEdit(pGroup);
  480. pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  481. pLE->setText(QString::number(pSlider->value()));
  482. mpLE_Scale = pLE;
  483. // nXPos = 10;
  484. // nYPos = nYPos + mnFontHeight * 2;
  485. // pLabel = new QLabel(pGroup);
  486. // pLabel->setText("MoveX");
  487. // pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  488. // nXPos = nXPos + mnFontHeight * 4;
  489. // pSlider = new QSlider(pGroup);
  490. // pSlider->setOrientation(Qt::Horizontal);
  491. // pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
  492. // pSlider->setRange(0,100);
  493. // pSlider->setValue(mnMoveX*100/VIEW_WIDTH);
  494. // connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMoveX(int)));
  495. // mpSlider_MoveX = pSlider;
  496. // nXPos = nXPos + mnFontHeight*11;
  497. // pLE = new QLineEdit(pGroup);
  498. // pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  499. // pLE->setText(QString::number(pSlider->value()));
  500. // mpLE_MoveX = pLE;
  501. // nXPos = 10;
  502. // nYPos = nYPos + mnFontHeight * 2;
  503. // pLabel = new QLabel(pGroup);
  504. // pLabel->setText("MoveY");
  505. // pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  506. // nXPos = nXPos + mnFontHeight * 4;
  507. // pSlider = new QSlider(pGroup);
  508. // pSlider->setOrientation(Qt::Horizontal);
  509. // pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
  510. // pSlider->setRange(0,100);
  511. // pSlider->setValue(mnMoveY*100/VIEW_HEIGHT);
  512. // connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMoveY(int)));
  513. // mpSlider_MoveY = pSlider;
  514. // nXPos = nXPos + mnFontHeight*11;
  515. // pLE = new QLineEdit(pGroup);
  516. // pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  517. // pLE->setText(QString::number(pSlider->value()));
  518. // mpLE_MoveY = pLE;
  519. nXPos = 10;
  520. nYPos = nYPos + mnFontHeight * 4;
  521. pLabel = new QLabel(pGroup);
  522. pLabel->setText(tr("Mark"));
  523. pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  524. nXPos = nXPos + mnFontHeight * 4;
  525. pSlider = new QSlider(pGroup);
  526. pSlider->setOrientation(Qt::Horizontal);
  527. pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
  528. pSlider->setRange(5,100);
  529. pSlider->setValue(mnMarkSize);
  530. connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMark(int)));
  531. mpSlider_Mark = pSlider;
  532. nXPos = nXPos + mnFontHeight*11;
  533. pLE = new QLineEdit(pGroup);
  534. pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
  535. pLE->setText(QString::number(pSlider->value()));
  536. mpLE_Mark = pLE;
  537. nXPos = 10;
  538. nYPos = nYPos + mnFontHeight * 4;
  539. pLabel = new QLabel(pGroup);
  540. pLabel->setText(tr("SelLon"));
  541. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  542. nXPos = nXPos + nSpace;
  543. pLabel = new QLabel(pGroup);
  544. pLabel->setText(tr("SelLat"));
  545. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  546. nXPos = nXPos + nSpace;
  547. (void)nXPos;
  548. nXPos = 10;
  549. nYPos = nYPos + mnFontHeight * 2;
  550. pLE = new QLineEdit(pGroup);
  551. pLE->setText("");
  552. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  553. mpLE_SelX = pLE;
  554. nXPos = nXPos + nSpace;
  555. pLE = new QLineEdit(pGroup);
  556. pLE->setText("");
  557. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  558. mpLE_SelY = pLE;
  559. // nXPos = nXPos + nSpace;
  560. nXPos = 10;
  561. nYPos = nYPos + mnFontHeight * 2;
  562. pLE = new QLineEdit(pGroup);
  563. pLE->setText("");
  564. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  565. mpLE_SelLon = pLE;
  566. nXPos = nXPos + nSpace;
  567. pLE = new QLineEdit(pGroup);
  568. pLE->setText("");
  569. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  570. mpLE_SelLat = pLE;
  571. nXPos = nXPos + nSpace;
  572. pLE = new QLineEdit(pGroup);
  573. pLE->setText("");
  574. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  575. pLE->setText("360");
  576. mpLE_StartHeading = pLE;
  577. nXPos = 10;
  578. nYPos = nYPos + mnFontHeight * 2;
  579. pPB = new QPushButton(pGroup);
  580. pPB->setText(tr("Set Move"));
  581. pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
  582. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetMove()));
  583. nXPos = 30 + mnFontHeight*10;
  584. pPB = new QPushButton(pGroup);
  585. pPB->setText(tr("Reset Move"));
  586. pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
  587. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickReSetMove()));
  588. nXPos = 10;
  589. nYPos = nYPos + mnFontHeight * 4;
  590. pPB = new QPushButton(pGroup);
  591. pPB->setText(tr("Load Lane"));
  592. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  593. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLoadLane()));
  594. nXPos = nXPos + nSpace;
  595. pCB = new QComboBox(pGroup);
  596. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  597. nXPos = nXPos + nSpace;
  598. (void)nXPos;
  599. mpCBLane = pCB;
  600. nXPos = 10;
  601. nYPos = nYPos + mnFontHeight * 2;
  602. pPB = new QPushButton(pGroup);
  603. pPB->setText(tr("Remove"));
  604. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  605. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRemoveLane()));
  606. nXPos = nXPos + nSpace;
  607. pPB = new QPushButton(pGroup);
  608. pPB->setText(tr("Mark"));
  609. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  610. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickMarkLane()));
  611. nXPos = nXPos + nSpace;
  612. pPB = new QPushButton(pGroup);
  613. pPB->setText(tr("Clear Road Lane"));
  614. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  615. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickClearRoadLane()));
  616. nXPos = nXPos + nSpace;
  617. (void)nXPos;
  618. nXPos = 10;
  619. nYPos = nYPos + mnFontHeight * 2;
  620. pPB = new QPushButton(pGroup);
  621. pPB->setText(tr("To Road"));
  622. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  623. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickToRoad()));
  624. nXPos = nXPos + nSpace;
  625. pPB = new QPushButton(pGroup);
  626. pPB->setText(tr("To Opposite"));
  627. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  628. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickToOpposite()));
  629. nXPos = nXPos + nSpace;
  630. pLE = new QLineEdit(pGroup);
  631. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  632. nXPos = nXPos + nSpace; (void)nXPos;
  633. mpLE_RoadName = pLE;
  634. nXPos = 10;
  635. nYPos = nYPos + mnFontHeight * 2;
  636. pCB = new QComboBox(pGroup);
  637. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  638. nXPos = nXPos + nSpace;
  639. mpCBSelLane = pCB;
  640. pCB = new QComboBox(pGroup);
  641. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  642. nXPos = nXPos + nSpace;
  643. mpCBSelOpLane = pCB;
  644. pPB = new QPushButton(pGroup);
  645. pPB->setText(tr("Add Road"));
  646. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  647. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAddRoad()));
  648. nXPos = nXPos + nSpace; (void)nXPos;
  649. nXPos = 10;
  650. nYPos = nYPos + mnFontHeight * 4;
  651. pCB = new QComboBox(pGroup);
  652. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  653. nXPos = nXPos + nSpace;
  654. mpCBRoad = pCB;
  655. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBRoadChange(int)));
  656. pPB = new QPushButton(pGroup);
  657. pPB->setText(tr("Mark"));
  658. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  659. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadMark()));
  660. nXPos = nXPos + nSpace;
  661. pPB = new QPushButton(pGroup);
  662. pPB->setText(tr("Del"));
  663. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  664. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadDel()));
  665. nXPos = nXPos + nSpace; (void)nXPos;
  666. nXPos = 10;
  667. nYPos = nYPos + mnFontHeight * 2;
  668. pLabel = new QLabel(pGroup);
  669. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  670. pLabel->setText(tr("Predecessor:"));
  671. nXPos = nXPos + nSpace;
  672. pLabel = new QLabel(pGroup);
  673. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  674. pLabel->setText(tr("road"));
  675. mpLabelRoadShowPreType1 = pLabel;
  676. nXPos = nXPos + nSpace;
  677. pLabel = new QLabel(pGroup);
  678. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  679. pLabel->setText(tr("10010"));
  680. mpLabelRoadShowPreID = pLabel;
  681. nXPos = nXPos + nSpace; (void)nXPos;
  682. nXPos = 10;
  683. nYPos = nYPos + mnFontHeight * 2;
  684. pLabel = new QLabel(pGroup);
  685. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  686. pLabel->setText(tr("start"));
  687. mpLabelRoadShowPreType2 = pLabel;
  688. nXPos = nXPos + nSpace;
  689. pCB = new QComboBox(pGroup);
  690. pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
  691. mpCBRoadShowPre = pCB;
  692. nXPos = 10;
  693. nYPos = nYPos + mnFontHeight * 2;
  694. pLabel = new QLabel(pGroup);
  695. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  696. pLabel->setText(tr("Successor:"));
  697. nXPos = nXPos + nSpace;
  698. pLabel = new QLabel(pGroup);
  699. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  700. pLabel->setText(tr("road"));
  701. mpLabelRoadShowNxtType1 = pLabel;
  702. nXPos = nXPos + nSpace;
  703. pLabel = new QLabel(pGroup);
  704. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  705. pLabel->setText(tr("10010"));
  706. mpLabelRoadShowNxtID = pLabel;
  707. nXPos = nXPos + nSpace; (void)nXPos;
  708. nXPos = 10;
  709. nYPos = nYPos + mnFontHeight * 2;
  710. pLabel = new QLabel(pGroup);
  711. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  712. pLabel->setText(tr("start"));
  713. mpLabelRoadShowNxtType2 = pLabel;
  714. nXPos = nXPos + nSpace;
  715. pCB = new QComboBox(pGroup);
  716. pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
  717. mpCBRoadShowNext = pCB;
  718. // nXPos = 10;
  719. // nYPos = nYPos + mnFontHeight * 2;
  720. // pCB = new QComboBox(pGroup);
  721. // pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  722. // nXPos = nXPos + nSpace;
  723. // mpCBPreNxtCurLane = pCB;
  724. nXPos = 10;
  725. nYPos = nYPos + mnFontHeight * 2;
  726. pCB = new QComboBox(pGroup);
  727. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  728. nXPos = nXPos + nSpace;
  729. mpCBPreNxtRoad = pCB;
  730. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickPreNxtRoadChange(int)));
  731. pCB = new QComboBox(pGroup);
  732. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  733. nXPos = nXPos + nSpace;
  734. mpCBPreNxtRelLane = pCB;
  735. pCB = new QComboBox(pGroup);
  736. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  737. nXPos = nXPos + nSpace; (void)nXPos;
  738. mpCBPreNxtConatact = pCB;
  739. pCB->addItem(tr("start"));
  740. pCB->addItem(tr("end"));
  741. nXPos = 10;
  742. nYPos = nYPos + mnFontHeight * 2;
  743. pPB = new QPushButton(pGroup);
  744. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  745. nXPos = nXPos + nSpace*15/10;
  746. pPB->setText(tr("Set Predecessor"));
  747. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetRoadPredecessor()));
  748. pPB = new QPushButton(pGroup);
  749. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  750. nXPos = nXPos + nSpace*15/10; (void)nXPos;
  751. pPB->setText(tr("Set Successor"));
  752. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetRoadSuccessor()));
  753. nXPos = 10;
  754. nYPos = nYPos + mnFontHeight * 2;
  755. pPB = new QPushButton(pGroup);
  756. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  757. nXPos = nXPos + nSpace*15/10;
  758. pPB->setText(tr("Del Predecessor"));
  759. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDelRoadPredecessor()));
  760. pPB = new QPushButton(pGroup);
  761. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  762. nXPos = nXPos + nSpace*15/10; (void)nXPos;
  763. pPB->setText(tr("Del Successor"));
  764. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDelRoadSuccessor()));
  765. nXPos = 10;
  766. nYPos = nYPos + mnFontHeight * 4;
  767. pCB = new QComboBox(pGroup);
  768. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  769. nXPos = nXPos + nSpace;
  770. mpCBRoad1 = pCB;
  771. pCB = new QComboBox(pGroup);
  772. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  773. nXPos = nXPos + nSpace;
  774. pCB->addItem(tr("start"));
  775. pCB->addItem(tr("end"));
  776. mpCBRC1 = pCB;
  777. QCheckBox * pCheck = new QCheckBox(pGroup);
  778. pCheck->setText(tr("act"));
  779. pCheck->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  780. mpCheckFromSel = pCheck;
  781. mpCheckFromSel->setChecked(false);
  782. nXPos = 10;
  783. nYPos = nYPos + mnFontHeight * 2;
  784. pCB = new QComboBox(pGroup);
  785. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  786. nXPos = nXPos + nSpace;
  787. mpCBRoad2 = pCB;
  788. pCB = new QComboBox(pGroup);
  789. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  790. nXPos = nXPos + nSpace;
  791. pCB->addItem(tr("start"));
  792. pCB->addItem(tr("end"));
  793. mpCBRC2 = pCB;
  794. pCheck = new QCheckBox(pGroup);
  795. pCheck->setText(tr("act"));
  796. pCheck->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  797. mpCheckToSel = pCheck;
  798. mpCheckToSel->setChecked(false);
  799. nXPos = 10;
  800. nYPos = nYPos + mnFontHeight * 2;
  801. pPB = new QPushButton(pGroup);
  802. pPB->setText(tr("Road Contact"));
  803. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  804. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadContact()));
  805. nXPos = nXPos + nSpace;
  806. pPB = new QPushButton(pGroup);
  807. pPB->setText(tr("Auto Road Contact"));
  808. pPB->setGeometry(nXPos,nYPos,nLEWidth*3/2,nLEHeight);
  809. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAutoRoadContact()));
  810. nXPos = 10;
  811. nYPos = nYPos + mnFontHeight * 4;
  812. pCB = new QComboBox(pGroup);
  813. pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
  814. // nXPos = nXPos + nSpace;
  815. mpCBRoadCon = pCB;
  816. nXPos = 10;
  817. nYPos = nYPos + mnFontHeight * 2;
  818. pCB = new QComboBox(pGroup);
  819. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  820. nXPos = nXPos + nSpace;
  821. mpCBLane1 = pCB;
  822. pCB = new QComboBox(pGroup);
  823. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  824. // nXPos = nXPos + nSpace;
  825. mpCBLane2 = pCB;
  826. nXPos = 10;
  827. nYPos = nYPos + mnFontHeight * 2;
  828. pPB = new QPushButton(pGroup);
  829. pPB->setText(tr("Lane Contact"));
  830. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  831. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLaneContact()));
  832. nXPos = nXPos + nSpace*15/10;
  833. pCB = new QComboBox(pGroup);
  834. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  835. // nXPos = nXPos + nSpace;
  836. mpCBLane1Lane2 = pCB;
  837. nXPos = 10;
  838. nYPos = nYPos + mnFontHeight * 2;
  839. pPB = new QPushButton(pGroup);
  840. pPB->setText(tr("OpLane Contact"));
  841. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  842. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickOpLaneContact()));
  843. nXPos = nXPos + nSpace*15/10;
  844. pCB = new QComboBox(pGroup);
  845. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  846. // nXPos = nXPos + nSpace;
  847. mpCBLane1Lane2op = pCB;
  848. nXPos = 10;
  849. nYPos = nYPos + mnFontHeight * 2;
  850. pPB = new QPushButton(pGroup);
  851. pPB->setText(tr("Clear"));
  852. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  853. nXPos = nXPos + nSpace;
  854. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickClearLaneContact()));
  855. pPB = new QPushButton(pGroup);
  856. pPB->setText(tr("Create Road"));
  857. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  858. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateRoad()));
  859. nXPos = 10;
  860. nYPos = nYPos + mnFontHeight * 2;
  861. pCB = new QComboBox(pGroup);
  862. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  863. nXPos = nXPos + nSpace;
  864. mpCBRoadType = pCB;
  865. pCB->addItem(tr("Turn"));
  866. pCB->addItem(tr("Straight"));
  867. pCB->addItem(tr("U-Turn"));
  868. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onChangeRoadType(int)));
  869. pLabel = new QLabel(pGroup);
  870. pLabel->setText(tr("Radius:"));
  871. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  872. nXPos = nXPos + nSpace;
  873. mpLBRoadType = pLabel;
  874. pLE = new QLineEdit(pGroup);
  875. pLE->setText("6.0");
  876. pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  877. mpLERoadType = pLE;
  878. mpCBStraightType = new QCheckBox(pGroup);
  879. mpCBStraightType->setText(tr("Line Only"));
  880. mpCBStraightType->setChecked(false);
  881. mpCBStraightType->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  882. mpCBStraightType->setVisible(false);
  883. mpCBRoadType->setCurrentIndex(0);
  884. mpLBRoadType->setVisible(true);
  885. mpLERoadType->setVisible(true);
  886. nXPos = 10;
  887. nYPos = nYPos + mnFontHeight * 4;
  888. pPB = new QPushButton(pGroup);
  889. pPB->setText(tr("Create Junction"));
  890. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  891. nXPos = nXPos + nSpace*15/10;
  892. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateJunction()));
  893. pCB = new QComboBox(pGroup);
  894. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  895. nXPos = nXPos + nSpace;
  896. mpCBJunction = pCB;
  897. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionChange(int)));
  898. pCB = new QComboBox(pGroup);
  899. pCB->setGeometry(nXPos,nYPos,nLEWidth*5/10,nLEHeight);
  900. mpCBJunctionConnection = pCB;
  901. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionConnectionChange(int)));
  902. nXPos = 10;
  903. nYPos = nYPos + mnFontHeight * 2;
  904. pLabel = new QLabel(pGroup);
  905. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  906. nXPos = nXPos + nSpace;
  907. mpLabelJunctionIncommingRoad = pLabel;
  908. pLabel = new QLabel(pGroup);
  909. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  910. nXPos = nXPos + nSpace;
  911. mpLabelJunctionContactPoint = pLabel;
  912. pLabel = new QLabel(pGroup);
  913. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  914. // nXPos = nXPos + nSpace;
  915. mpLabelJunctionConnectingRoad = pLabel;
  916. nXPos = 10;
  917. nYPos = nYPos + mnFontHeight * 2;
  918. pCB = new QComboBox(pGroup);
  919. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  920. mpCBJunctionFromTo = pCB;
  921. nXPos = 10;
  922. nYPos = nYPos + mnFontHeight * 2;
  923. pLabel = new QLabel(pGroup);
  924. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  925. nXPos = nXPos + nSpace;
  926. pLabel->setText(tr("Incomming"));
  927. pCB = new QComboBox(pGroup);
  928. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  929. // nXPos = nXPos + nSpace;
  930. mpCBJunctionIncommingRoad = pCB;
  931. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionIncommingChange(int)));
  932. nXPos = 10;
  933. nYPos = nYPos + mnFontHeight * 2;
  934. pLabel = new QLabel(pGroup);
  935. pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  936. nXPos = nXPos + nSpace;
  937. pLabel->setText(tr("Connecting"));
  938. pCB = new QComboBox(pGroup);
  939. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  940. nXPos = nXPos + nSpace;
  941. mpCBJunctionConnectingRoad= pCB;
  942. connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionConnectionroadChange(int)));
  943. pCB = new QComboBox(pGroup);
  944. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  945. // nXPos = nXPos + nSpace;
  946. pCB->addItem(tr("start"));
  947. pCB->addItem(tr("end"));
  948. mpCBJunctionContactPoint = pCB;
  949. nXPos = 10;
  950. nYPos = nYPos + mnFontHeight * 2;
  951. pCB = new QComboBox(pGroup);
  952. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  953. nXPos = nXPos + nSpace;
  954. mpCBJunctionFromLane = pCB;
  955. pCB = new QComboBox(pGroup);
  956. pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  957. // nXPos = nXPos + nSpace;
  958. mpCBJunctionToLane = pCB;
  959. nXPos = 10;
  960. nYPos = nYPos + mnFontHeight * 2;
  961. pPB = new QPushButton(pGroup);
  962. pPB->setText(tr("Create Lane Link"));
  963. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  964. nXPos = nXPos + nSpace*15/10;
  965. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateJunctionLaneLink()));
  966. pPB = new QPushButton(pGroup);
  967. pPB->setText(tr("Delete Lane Link"));
  968. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  969. // nXPos = nXPos + nSpace*15/10;
  970. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDeleteJunctionLaneLink()));
  971. nXPos = 10;
  972. nYPos = nYPos + mnFontHeight * 4;
  973. pPB = new QPushButton(pGroup);
  974. pPB->setText(tr("Auto Connect Road"));
  975. pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
  976. // nXPos = nXPos + nSpace*15/10;
  977. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAutoConnect()));
  978. nXPos = 10;
  979. nYPos = nYPos + mnFontHeight * 4;
  980. pPB = new QPushButton(pGroup);
  981. pPB->setText(tr("Save"));
  982. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  983. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSave()));
  984. nXPos = nXPos + nSpace;
  985. pPB = new QPushButton(pGroup);
  986. pPB->setText(tr("Load"));
  987. pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
  988. connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLoad()));
  989. // nXPos = nXPos + nSpace;
  990. QScrollArea * pScroll = new QScrollArea();
  991. pScroll->setWidget(pGroup);
  992. p->addTab(pScroll,tr("Calculate"));
  993. }
  994. void MainWindow::onClickXY(double x, double y)
  995. {
  996. mClickX = x - mnMoveX;
  997. mClickY = y - mnMoveY;
  998. mbClick = true;
  999. mbRefresh = true;
  1000. double selx,sely;
  1001. double lon,lat;
  1002. selx = mClickX;
  1003. sely = mClickY * (-1);
  1004. if(mnViewMode == 0)
  1005. {
  1006. selx = selx/((double )mnfac);
  1007. sely = sely/((double)mnfac);
  1008. }
  1009. mpLE_SelX->setText(QString::number(selx,'f',3));
  1010. mpLE_SelY->setText(QString::number(sely,'f',3));
  1011. emit CurrentPosition(selx,sely);
  1012. double x0,y0;
  1013. GaussProjCal(glon0,glat0,&x0,&y0);
  1014. GaussProjInvCal(x0+selx,y0+sely,&lon,&lat);
  1015. double rel_x,rel_y;
  1016. rel_x = selx - mfViewMoveX;
  1017. rel_y = sely - mfViewMoveY;
  1018. Road * pRoad = 0;
  1019. GeometryBlock * pgeob;
  1020. double fdis,nearx,neary,hdg;
  1021. double fs;
  1022. int nlane;
  1023. // if(xodrfunc::GetNearPointWithHide2(rel_x,rel_y,&mxodr,&pRoad,fdis,nearx,neary,hdg,50,mvectorhideroadid,&fs,&nlane) == 0)
  1024. if(xodrfunc::GetNearPointWithHide(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,mvectorhideroadid,&fs,&nlane) == 0)
  1025. {
  1026. qDebug("s:%f dis is %f nlane is %d",fs,fdis,nlane);
  1027. char strout[1000];
  1028. snprintf(strout,1000,"Road:%s s:%f dis:%f nlane:%d",pRoad->GetRoadId().data(),fs,fdis,nlane);
  1029. mpLabel_Status->setText(strout);
  1030. ui->statusBar->showMessage(strout,3000);
  1031. int i;
  1032. int nsize = mpCBRoad->count();
  1033. for(i=0;i<nsize;i++)
  1034. {
  1035. if(mpCBRoad->itemText(i).toStdString() == pRoad->GetRoadId())
  1036. {
  1037. break;
  1038. }
  1039. }
  1040. if(i<nsize)
  1041. {
  1042. if(i != mpCBRoad->currentIndex())
  1043. mpCBRoad->setCurrentIndex(i);
  1044. }
  1045. }
  1046. if(mpCheckFromSel->isChecked())
  1047. {
  1048. if(pRoad != 0)ComboToString(pRoad->GetRoadId(),mpCBRoad1);
  1049. mpCheckFromSel->setChecked(false);
  1050. }
  1051. if(mpCheckToSel->isChecked())
  1052. {
  1053. if(pRoad != 0)ComboToString(pRoad->GetRoadId(),mpCBRoad2);
  1054. mpCheckToSel->setChecked(false);
  1055. }
  1056. mpLE_SelLon->setText(QString::number(lon,'f',7));
  1057. mpLE_SelLat->setText(QString::number(lat,'f',7));
  1058. update();
  1059. if(mpCBViewMode->currentIndex() == 1)
  1060. {
  1061. UpdateScene_SelectRoadRefGeo();
  1062. }
  1063. }
  1064. void MainWindow::ComboToString(std::string strroadid,QComboBox * pCB)
  1065. {
  1066. int i;
  1067. int nsize = pCB->count();
  1068. for(i=0;i<nsize;i++)
  1069. {
  1070. if(pCB->itemText(i).toStdString() == strroadid)
  1071. {
  1072. break;
  1073. }
  1074. }
  1075. if(i<nsize)
  1076. {
  1077. if(i != pCB->currentIndex())
  1078. pCB->setCurrentIndex(i);
  1079. }
  1080. }
  1081. void MainWindow::onChangeScale(int scale)
  1082. {
  1083. mnfac = scale;
  1084. mpLE_Scale->setText(QString::number(scale));
  1085. mbRefresh = true;
  1086. update();
  1087. }
  1088. void MainWindow::onChangeMoveX(int scale)
  1089. {
  1090. mnMoveX = VIEW_WIDTH * scale/100;
  1091. mpLE_MoveX->setText(QString::number(scale));
  1092. mbRefresh = true;
  1093. update();
  1094. }
  1095. void MainWindow::onChangeMoveY(int scale)
  1096. {
  1097. mnMoveY = VIEW_HEIGHT * scale/100;
  1098. mpLE_MoveY->setText(QString::number(scale));
  1099. mbRefresh = true;
  1100. update();
  1101. }
  1102. void MainWindow::onChangeMark(int scale)
  1103. {
  1104. mnMarkSize = scale;
  1105. mpLE_Mark->setText(QString::number(scale));
  1106. mbRefresh = true;
  1107. update();
  1108. }
  1109. void MainWindow::onClickDefView()
  1110. {
  1111. mnfac = mnDefmnfac;
  1112. mnMoveX = mnDefMoveX;
  1113. mnMoveY = mnDefMoveY;
  1114. mpSlider_Scale->setValue(mnfac);
  1115. // mpSlider_MoveX->setValue(mnMoveX*100/VIEW_WIDTH);
  1116. // mpSlider_MoveY->setValue(mnMoveY*100/VIEW_HEIGHT);
  1117. // mbRefresh = true;
  1118. update();
  1119. }
  1120. void MainWindow::onClickZoomOne()
  1121. {
  1122. myview->zoomone();
  1123. }
  1124. void MainWindow::onClickAsStart()
  1125. {
  1126. }
  1127. void MainWindow::onClickAsDst()
  1128. {
  1129. double lon,lat;
  1130. lon = mpLE_SelLon->text().toDouble();
  1131. lat = mpLE_SelLat->text().toDouble();
  1132. mpLE_DstLon->setText(QString::number(lon,'f',7));
  1133. mpLE_DstLat->setText(QString::number(lat,'f',7));
  1134. double x,y;
  1135. x = mpLE_SelX->text().toDouble();
  1136. y = mpLE_SelY->text().toDouble();
  1137. mfObjX = x;
  1138. mfObjY = y;
  1139. mbSetObj = true;
  1140. mbRefresh = true;
  1141. update();
  1142. }
  1143. void MainWindow::onClickSetDst()
  1144. {
  1145. }
  1146. void MainWindow::onClickPlan()
  1147. {
  1148. }
  1149. void MainWindow::onClickSetStart()
  1150. {
  1151. }
  1152. /**
  1153. * @brief ADCIntelligentVehicle::UpdateMap
  1154. * @param strdata
  1155. * @param nSize
  1156. * @param index
  1157. * @param dt
  1158. * @param strmemname
  1159. */
  1160. void MainWindow::UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1161. {
  1162. (void)index;
  1163. (void)dt;
  1164. (void)strmemname;
  1165. // std::cout<<"update map "<<std::endl;
  1166. int gpsunitsize = sizeof(iv::GPS_INS);
  1167. int nMapSize = nSize/gpsunitsize;
  1168. // std::cout<<"map size is "<<nMapSize<<std::endl;
  1169. if(nMapSize < 1)return;
  1170. int i;
  1171. mMutexNavi.lock();
  1172. m_navigation_data.clear();
  1173. for(i=0;i<nMapSize;i++)
  1174. {
  1175. iv::GPS_INS x;
  1176. memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
  1177. iv::GPSData data(new iv::GPS_INS);
  1178. *data = x;
  1179. m_navigation_data.push_back(data);
  1180. }
  1181. mMutexNavi.unlock();
  1182. mbRefresh = true;
  1183. update();
  1184. }
  1185. /**
  1186. * @brief MainWindow::UpdateGPSIMU
  1187. * @param strdata
  1188. * @param nSize
  1189. * @param index
  1190. * @param dt
  1191. * @param strmemname
  1192. */
  1193. void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  1194. {
  1195. (void)index;
  1196. (void)dt;
  1197. (void)strmemname;
  1198. iv::gps::gpsimu xgpsimu;
  1199. if(!xgpsimu.ParseFromArray(strdata,nSize))
  1200. {
  1201. // gIvlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
  1202. return;
  1203. }
  1204. double flat,flon,fhead;
  1205. flat = xgpsimu.lat();
  1206. flon = xgpsimu.lon();
  1207. fhead = xgpsimu.heading();
  1208. double x,y;
  1209. GaussProjCal(flon,flat,&x,&y);
  1210. mfNowX = x - mx0;
  1211. mfNowY = y- my0;
  1212. mfNowHdg = (90- fhead)*M_PI/180.0;
  1213. mbGPSUpdate = true;
  1214. mbGPSViewUpdate = true;
  1215. }
  1216. void MainWindow::onClickLoadLane()
  1217. {
  1218. QString str = QFileDialog::getOpenFileName(this,tr("Open Lane Info file"),"",tr("Lane File(*.txt)"));
  1219. if(str.isEmpty())return;
  1220. QFile xFile;
  1221. xFile.setFileName(str);
  1222. QFileInfo fi(str);
  1223. QString filename = fi.fileName();
  1224. double fLastLat = 39;
  1225. double fLastLon = 117;
  1226. if(filename.contains(".txt"))
  1227. {
  1228. filename = filename.left(filename.length() -4);
  1229. }
  1230. if(xFile.open(QIODevice::ReadWrite))
  1231. {
  1232. iv::lpunit lpu;
  1233. strncpy(lpu.strlanename,filename.toLatin1().data(),filename.size());
  1234. QByteArray ba;
  1235. ba = xFile.read(xFile.size());
  1236. QString strdata = ba;
  1237. #ifdef ADCQT6
  1238. QStringList strlinedata= strdata.split("\n",Qt::SplitBehaviorFlags::SkipEmptyParts);
  1239. #else
  1240. QStringList strlinedata= strdata.split("\n",QString::SkipEmptyParts);
  1241. #endif
  1242. int i;
  1243. int nsize = strlinedata.size();
  1244. // qDebug("line is %d",nsize);
  1245. for(i=0;i<nsize;i++)
  1246. {
  1247. QString strline = strlinedata.at(i);
  1248. #ifdef ADCQT6
  1249. QStringList strvaluedata = strline.split(" ",Qt::SplitBehaviorFlags::SkipEmptyParts);
  1250. #else
  1251. QStringList strvaluedata = strline.split(" ",QString::SkipEmptyParts);
  1252. #endif
  1253. // qDebug("%d value size is %d ",i,strvaluedata.size());
  1254. iv::lanepoint lpleft,lpright;
  1255. if(strvaluedata.size() == 12)
  1256. {
  1257. int j;
  1258. QString strx[12];
  1259. for(j=0;j<12;j++)strx[j] = strvaluedata.at(j);
  1260. lpleft.mfLon = strx[0].toDouble();
  1261. lpleft.mfLat = strx[1].toDouble();
  1262. lpleft.mfHeight = strx[2].toDouble();
  1263. lpleft.nLaneType = strx[3].toInt();
  1264. lpleft.mfHeading = strx[4].toDouble();
  1265. lpleft.mfDis = strx[5].toDouble();
  1266. lpright.mfLon = strx[6].toDouble();
  1267. lpright.mfLat = strx[7].toDouble();
  1268. lpright.mfHeight = strx[8].toDouble();
  1269. lpright.nLaneType = strx[9].toInt();
  1270. lpright.mfHeading = strx[10].toDouble();
  1271. lpright.mfDis = strx[11].toDouble();
  1272. lpleft.mfHdg = (90-lpleft.mfHeading) * M_PI/180.0;
  1273. if(lpleft.mfHdg < 0)lpleft.mfHdg = lpleft.mfHdg + 2.0*M_PI;
  1274. lpright.mfHdg = (90-lpright.mfHeading) * M_PI/180.0;
  1275. if(lpright.mfHdg < 0)lpright.mfHdg = lpright.mfHdg + 2.0*M_PI;
  1276. double x,y;
  1277. double xlast,ylast;
  1278. GaussProjCal(lpleft.mfLon,lpleft.mfLat,&x,&y);
  1279. GaussProjCal(fLastLon,fLastLat,&xlast,&ylast);
  1280. if(sqrt(pow(xlast -x ,2)+pow(ylast -y,2))> 0.1)
  1281. {
  1282. lpu.mvectorlpleft.push_back(lpleft);
  1283. lpu.mvectorlpright.push_back(lpright);
  1284. fLastLat = lpleft.mfLat;
  1285. fLastLon = lpleft.mfLon;
  1286. }
  1287. else
  1288. {
  1289. // qDebug("no use this point");
  1290. }
  1291. }
  1292. }
  1293. if((mbSetOrigin == false)&&(lpu.mvectorlpleft.size() > 0))
  1294. {
  1295. glat0 = lpu.mvectorlpleft[0].mfLat;
  1296. glon0 = lpu.mvectorlpright[0].mfLon;
  1297. mpLELat0->setText(QString::number(glat0,'f',7));
  1298. mpLELon0->setText(QString::number(glon0,'f',7));
  1299. mbSetOrigin = true;
  1300. }
  1301. double x0,y0;
  1302. GaussProjCal(glon0,glat0,&x0,&y0);
  1303. int j;
  1304. for(j=0;j<static_cast<int>( lpu.mvectorlpleft.size());j++)
  1305. {
  1306. double x,y;
  1307. GaussProjCal(lpu.mvectorlpleft[j].mfLon,lpu.mvectorlpleft[j].mfLat,&x,&y);
  1308. lpu.mvectorlpleft[j].mfX = x - x0;
  1309. lpu.mvectorlpleft[j].mfY = y- y0;
  1310. GaussProjCal(lpu.mvectorlpright[j].mfLon,lpu.mvectorlpright[j].mfLat,&x,&y);
  1311. lpu.mvectorlpright[j].mfX = x - x0;
  1312. lpu.mvectorlpright[j].mfY = y- y0;
  1313. }
  1314. if(lpu.mvectorlpleft.size() > 0)
  1315. {
  1316. mvectorlp.push_back(lpu);
  1317. mpCBLane->addItem(filename);
  1318. int N = lpu.mvectorlpleft.size();
  1319. VectorXd x_veh(N);
  1320. VectorXd y_veh(N);
  1321. int j;
  1322. int ntype = 0;
  1323. int ntypecount = 1;
  1324. for(j=0;j<N;j++)
  1325. {
  1326. double x,y;
  1327. GaussProjCal(glon0,glat0,&x0,&y0);
  1328. GaussProjCal(lpu.mvectorlpleft[j].mfLon,lpu.mvectorlpleft[j].mfLat,&x,&y);
  1329. x_veh[j] = x - x0;
  1330. y_veh[j] = y - y0;
  1331. if(lpu.mvectorlpright[j].nLaneType != ntype)
  1332. {
  1333. ntype = lpu.mvectorlpright[j].nLaneType;
  1334. ntypecount++;
  1335. }
  1336. }
  1337. // CreateRoad(x_veh,y_veh);
  1338. // auto coeffs = polyfit(x_veh, y_veh, 1);
  1339. // double dismax = 0;
  1340. // for(j=0;j<N;j++)
  1341. // {
  1342. // double A = coeffs[1];
  1343. // double B = -1;
  1344. // double C = coeffs[0];
  1345. // double dis = fabs(A*x_veh[j] + B*y_veh[j] +C )/sqrt(pow(A,2)+pow(B,2));
  1346. // if(dis>dismax)dismax = dis;
  1347. // }
  1348. // int nxxx = coeffs.size();
  1349. }
  1350. }
  1351. xFile.close();
  1352. mbRefresh = true;
  1353. update();
  1354. }
  1355. /**
  1356. * @brief MainWindow::CreateRoad
  1357. * Create Road Geometry
  1358. * @param xvals
  1359. * @param yvals
  1360. * @return
  1361. */
  1362. Road MainWindow::CreateRoad(VectorXd xvals, VectorXd yvals)
  1363. {
  1364. (void)xvals;
  1365. (void)yvals;
  1366. Road x;
  1367. return x;
  1368. }
  1369. void MainWindow::onClickMarkLane()
  1370. {
  1371. mnMarkLane = mpCBLane->currentIndex();
  1372. mbRefresh = true;
  1373. update();
  1374. }
  1375. void MainWindow::onClickRemoveLane()
  1376. {
  1377. int i = mpCBLane->currentIndex();
  1378. if((i>=0) && (i<static_cast<int>( mvectorlp.size())))
  1379. {
  1380. int j;
  1381. for(j=0;j< static_cast<int>(mvectorroadlane.size());j++)
  1382. {
  1383. if(mvectorroadlane[j] == i)
  1384. {
  1385. mvectorroadlane.erase(mvectorroadlane.begin() + j);
  1386. mpCBSelLane->removeItem(j);
  1387. break;
  1388. }
  1389. }
  1390. mvectorlp.erase(mvectorlp.begin() + i);
  1391. mpCBLane->removeItem(i);
  1392. mbRefresh = true;
  1393. update();
  1394. }
  1395. }
  1396. void MainWindow::onClickToRoad()
  1397. {
  1398. int i = mpCBLane->currentIndex();
  1399. if((i>=0) && (i< static_cast<int>(mvectorlp.size())))
  1400. {
  1401. int j;
  1402. bool bHave = false;
  1403. for(j=0;j< static_cast<int>(mvectorroadlane.size());j++)
  1404. {
  1405. if(mvectorroadlane[j] == i)
  1406. {
  1407. bHave = true;
  1408. break;
  1409. }
  1410. }
  1411. if(bHave == false)
  1412. {
  1413. mvectorroadlane.push_back(i);
  1414. mpCBSelLane->addItem(mvectorlp.at(i).strlanename);
  1415. }
  1416. }
  1417. }
  1418. void MainWindow::onClickToOpposite()
  1419. {
  1420. int i = mpCBLane->currentIndex();
  1421. if((i>=0) && (i< static_cast<int>(mvectorlp.size())))
  1422. {
  1423. int j;
  1424. bool bHave = false;
  1425. for(j=0;j<static_cast<int>(mvectorroadopposite.size());j++)
  1426. {
  1427. if(mvectorroadopposite[j] == i)
  1428. {
  1429. bHave = true;
  1430. break;
  1431. }
  1432. }
  1433. if(bHave == false)
  1434. {
  1435. mvectorroadopposite.push_back(i);
  1436. mpCBSelOpLane->addItem(mvectorlp.at(i).strlanename);
  1437. }
  1438. }
  1439. }
  1440. void MainWindow::onClickClearRoadLane()
  1441. {
  1442. mvectorroadlane.clear();
  1443. mvectorroadopposite.clear();
  1444. mpCBSelLane->clear();
  1445. mpCBSelOpLane->clear();
  1446. }
  1447. void MainWindow::onClickAddRoad()
  1448. {
  1449. int nrtn;
  1450. std::string strrtn = " ";
  1451. std::string strroadname = mpLE_RoadName->text().toStdString();
  1452. nrtn = ServiceXODRMake.AddRoadFromeLanePoint(mvectorlp,mvectorroadlane,mvectorroadopposite,glon0,
  1453. glat0,mxodr,strroadname,strrtn);
  1454. (void)nrtn;
  1455. mpCBSelLane->clear();
  1456. mpCBSelOpLane->clear();
  1457. mvectorroadlane.clear();
  1458. mvectorroadopposite.clear();
  1459. updateCBRoad();
  1460. mbRefresh = true;
  1461. update();
  1462. return;
  1463. if(mvectorroadlane.size() < 1)return;
  1464. int nlanesize = mvectorroadlane.size();
  1465. int noplanesize = mvectorroadopposite.size();
  1466. double notlinethresh = 1.0; //When heading change more than this value, is a arc.
  1467. int nsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
  1468. int * pntype = new int[nsize];
  1469. std::shared_ptr<int> ppntype; ppntype.reset(pntype);
  1470. std::vector<iv::lanepoint > * pvectorlp = &(mvectorlp[mvectorroadlane[0]].mvectorlpleft);
  1471. int i;
  1472. //Go throuh point for fit type.
  1473. for(i=0;i<5;i++)pntype[i] = 0;
  1474. for(i=5;i<(nsize-5);i++)
  1475. {
  1476. double s = pvectorlp->at(i).mfDis;
  1477. double head0 = pvectorlp->at(i).mfHeading;
  1478. int j;
  1479. double xcount = 0;
  1480. double headdifftotal = 0;
  1481. double headdiffavg = 0.0;
  1482. for(j=1;j<nsize;j++)
  1483. {
  1484. if((j>1)&&((pvectorlp->at(j).mfDis - s)>1.0))
  1485. {
  1486. break;
  1487. }
  1488. double headdiff = pvectorlp->at(j).mfHeading - head0;
  1489. if(headdiff > 300)headdiff = headdiff - 360;
  1490. if(headdiff < -300)headdiff = headdiff + 360;
  1491. headdifftotal = headdifftotal + headdiff;
  1492. xcount = xcount + 1.0;
  1493. }
  1494. if(xcount > 0)headdiffavg = headdifftotal/xcount;
  1495. if(fabs(headdiffavg) > (notlinethresh*2))
  1496. {
  1497. pntype[i] = 1;
  1498. }
  1499. else
  1500. {
  1501. pntype[i] = 0;
  1502. }
  1503. }
  1504. for(i=(nsize -5);i<nsize;i++)
  1505. {
  1506. pntype[i] = 0;
  1507. }
  1508. for(i=0;i<nsize;i++) //Remove Few Not Line Point.
  1509. {
  1510. if(pntype[i] != 0)
  1511. {
  1512. int j;
  1513. int ncount = 1;
  1514. for(j=(i+1);j<nsize;j++)
  1515. {
  1516. if(pntype[i] != 0)ncount++;
  1517. else break;
  1518. }
  1519. if(ncount < 10)pntype[i] = 0;
  1520. else
  1521. {
  1522. i = i+ ncount;
  1523. }
  1524. }
  1525. }
  1526. for(i=5;i<nsize;i++)
  1527. {
  1528. if(pntype[i] != pntype[i-1])
  1529. {
  1530. int j = i-1;
  1531. double disx = pvectorlp->at(i).mfDis;
  1532. for(j=(i-2);j>5;j--)
  1533. {
  1534. if(pntype[j] == pntype[i-1])
  1535. {
  1536. pntype[j] = 2; //Besel
  1537. }
  1538. if(fabs(pvectorlp->at(j).mfDis - disx)>1) //1 m besel
  1539. {
  1540. break;
  1541. }
  1542. }
  1543. pntype[i-1] = 2;
  1544. }
  1545. }
  1546. //Calc dis to ref line
  1547. double xor0,yor0;
  1548. GaussProjCal(glon0,glat0,&xor0,&yor0);
  1549. std::vector<std::vector<iv::distogeo>> xvectordiss;
  1550. std::vector<std::vector<iv::distogeo>> xvectoropdiss;
  1551. for(i=0;i<static_cast<int>(mvectorroadlane.size());i++)
  1552. {
  1553. std::vector<iv::distogeo> xvectordistogeo;
  1554. int j;
  1555. int nsizepoint = mvectorlp[mvectorroadlane[i]].mvectorlpright.size();
  1556. bool bHaveLast = false;
  1557. int nLast = 0;
  1558. for(j=0;j<nsizepoint;j++)
  1559. {
  1560. double fdismin = 1000;
  1561. double fS = 0;
  1562. int k;
  1563. double x,y;
  1564. double x0,y0;
  1565. iv::distogeo xdistogeo;
  1566. int nLastBig = 0;
  1567. bool bFindDisMin = false;
  1568. x = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfX;
  1569. y = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfY;
  1570. int kstart = 0;
  1571. if(bHaveLast)
  1572. {
  1573. kstart= nLast;
  1574. }
  1575. for(k=kstart;k<static_cast<int>( mvectorlp[mvectorroadlane[0]].mvectorlpleft.size());k++)
  1576. {
  1577. x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
  1578. y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
  1579. double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
  1580. if(fdismin > fdis)
  1581. {
  1582. fdismin = fdis;
  1583. fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
  1584. bFindDisMin = true;
  1585. nLast = k;
  1586. }
  1587. if((bFindDisMin)&&(bHaveLast))
  1588. {
  1589. if(fdis>fdismin)
  1590. {
  1591. nLastBig++;
  1592. }
  1593. else
  1594. {
  1595. nLastBig = 0;
  1596. }
  1597. }
  1598. if(nLastBig > 10)break;
  1599. }
  1600. // std::cout<<" k is "<<k<<std::endl;
  1601. if(bHaveLast == false)
  1602. {
  1603. if(fdismin<10)bHaveLast = true;
  1604. }
  1605. else
  1606. {
  1607. if(fdismin > 10)bHaveLast = false;
  1608. }
  1609. double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
  1610. mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
  1611. double fHdgDiff = fHdg - mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfHdg;
  1612. if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
  1613. if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
  1614. if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 3.2))
  1615. {
  1616. xdistogeo.mfdis = fdismin;
  1617. xdistogeo.mfs = fS;
  1618. mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS = fS;
  1619. }
  1620. else
  1621. {
  1622. xdistogeo.mfs = -1;
  1623. std::cout<<"point extend."<<std::endl;
  1624. mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS = -1;
  1625. }
  1626. xvectordistogeo.push_back(xdistogeo);
  1627. }
  1628. xvectordiss.push_back(xvectordistogeo);
  1629. }
  1630. for(i=1;i<static_cast<int>( mvectorroadlane.size());i++)
  1631. {
  1632. std::vector<iv::distogeo> xvectordistogeo;
  1633. int j;
  1634. int nsizepoint = mvectorlp[mvectorroadlane[i]].mvectorlpleft.size();
  1635. bool bHaveLast = false;
  1636. int nLast = 0;
  1637. for(j=0;j<nsizepoint;j++)
  1638. {
  1639. double fdismin = 1000;
  1640. double fS = 0;
  1641. int k;
  1642. double x,y;
  1643. double x0,y0;
  1644. iv::distogeo xdistogeo;
  1645. int nLastBig = 0;
  1646. bool bFindDisMin = false;
  1647. x = mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfX;
  1648. y = mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfY;
  1649. int kstart = 0;
  1650. if(bHaveLast)
  1651. {
  1652. kstart= nLast;
  1653. }
  1654. for(k=kstart;k<static_cast<int>( mvectorlp[mvectorroadlane[0]].mvectorlpleft.size());k++)
  1655. {
  1656. x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
  1657. y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
  1658. double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
  1659. if(fdismin > fdis)
  1660. {
  1661. fdismin = fdis;
  1662. fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
  1663. bFindDisMin = true;
  1664. nLast = k;
  1665. }
  1666. if((bFindDisMin)&&(bHaveLast))
  1667. {
  1668. if(fdis>fdismin)
  1669. {
  1670. nLastBig++;
  1671. }
  1672. else
  1673. {
  1674. nLastBig = 0;
  1675. }
  1676. }
  1677. if(nLastBig > 10)break;
  1678. }
  1679. // std::cout<<" k is "<<k<<std::endl;
  1680. if(bHaveLast == false)
  1681. {
  1682. if(fdismin<10)bHaveLast = true;
  1683. }
  1684. else
  1685. {
  1686. if(fdismin > 10)bHaveLast = false;
  1687. }
  1688. double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
  1689. mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
  1690. double fHdgDiff = fHdg - mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfHdg;
  1691. if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
  1692. if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
  1693. if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 3.2))
  1694. {
  1695. xdistogeo.mfdis = fdismin;
  1696. xdistogeo.mfs = fS;
  1697. mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfRelS = fS;
  1698. }
  1699. else
  1700. {
  1701. xdistogeo.mfs = -1;
  1702. std::cout<<"point extend."<<std::endl;
  1703. mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfRelS = -1;
  1704. }
  1705. xvectordistogeo.push_back(xdistogeo);
  1706. }
  1707. xvectordiss.push_back(xvectordistogeo);
  1708. }
  1709. for(i=0;i<static_cast<int>(mvectorroadopposite.size());i++)
  1710. {
  1711. std::vector<iv::distogeo> xvectordistogeo;
  1712. int j;
  1713. int nsizepoint = mvectorlp[mvectorroadopposite[i]].mvectorlpleft.size();
  1714. bool bHaveLast = false;
  1715. int nLast = 0;
  1716. for(j=0;j<nsizepoint;j++)
  1717. {
  1718. double fdismin = 1000;
  1719. double fS = 0;
  1720. int k;
  1721. double x,y;
  1722. double x0,y0;
  1723. iv::distogeo xdistogeo;
  1724. int nLastBig = 0;
  1725. bool bFindDisMin = false;
  1726. x = mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfX;
  1727. y = mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfY;
  1728. int nrefsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
  1729. int kstart = nrefsize-1;
  1730. if(bHaveLast)
  1731. {
  1732. kstart= nLast;
  1733. }
  1734. for(k=kstart;k>=0;k--)
  1735. {
  1736. x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
  1737. y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
  1738. double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
  1739. if(fdismin > fdis)
  1740. {
  1741. fdismin = fdis;
  1742. fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
  1743. bFindDisMin = true;
  1744. nLast = k;
  1745. }
  1746. if((bFindDisMin)&&(bHaveLast))
  1747. {
  1748. if(fdis>fdismin)
  1749. {
  1750. nLastBig++;
  1751. }
  1752. else
  1753. {
  1754. nLastBig = 0;
  1755. }
  1756. }
  1757. if(nLastBig > 10)break;
  1758. }
  1759. // std::cout<<" k is "<<k<<std::endl;
  1760. if(bHaveLast == false)
  1761. {
  1762. if(fdismin<10)bHaveLast = true;
  1763. }
  1764. else
  1765. {
  1766. if(fdismin > 10)bHaveLast = false;
  1767. }
  1768. double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
  1769. mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
  1770. double fHdgDiff = fHdg - mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfHdg;
  1771. if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
  1772. if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
  1773. if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 0.5))
  1774. {
  1775. xdistogeo.mfdis = fdismin;
  1776. xdistogeo.mfs = fS;
  1777. mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfRelS = fS;
  1778. }
  1779. else
  1780. {
  1781. xdistogeo.mfs = -1;
  1782. std::cout<<"point extend."<<std::endl;
  1783. mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfRelS = -1;
  1784. }
  1785. xvectordistogeo.push_back(xdistogeo);
  1786. }
  1787. xvectoropdiss.push_back(xvectordistogeo);
  1788. }
  1789. for(i=0;i<static_cast<int>(mvectorroadopposite.size());i++)
  1790. {
  1791. std::vector<iv::distogeo> xvectordistogeo;
  1792. int j;
  1793. int nsizepoint = mvectorlp[mvectorroadopposite[i]].mvectorlpright.size();
  1794. bool bHaveLast = false;
  1795. int nLast = 0;
  1796. for(j=0;j<nsizepoint;j++)
  1797. {
  1798. double fdismin = 1000;
  1799. double fS = 0;
  1800. int k;
  1801. double x,y;
  1802. double x0,y0;
  1803. iv::distogeo xdistogeo;
  1804. int nLastBig = 0;
  1805. bool bFindDisMin = false;
  1806. x = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfX;
  1807. y = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfY;
  1808. int nrefsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
  1809. int kstart = nrefsize-1;
  1810. if(bHaveLast)
  1811. {
  1812. kstart= nLast;
  1813. }
  1814. for(k=kstart;k>=0;k--)
  1815. {
  1816. x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
  1817. y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
  1818. double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
  1819. if(fdismin > fdis)
  1820. {
  1821. fdismin = fdis;
  1822. fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
  1823. bFindDisMin = true;
  1824. nLast = k;
  1825. }
  1826. if((bFindDisMin)&&(bHaveLast))
  1827. {
  1828. if(fdis>fdismin)
  1829. {
  1830. nLastBig++;
  1831. }
  1832. else
  1833. {
  1834. nLastBig = 0;
  1835. }
  1836. }
  1837. if(nLastBig > 10)break;
  1838. }
  1839. // std::cout<<" k is "<<k<<std::endl;
  1840. if(bHaveLast == false)
  1841. {
  1842. if(fdismin<10)bHaveLast = true;
  1843. }
  1844. else
  1845. {
  1846. if(fdismin > 10)bHaveLast = false;
  1847. }
  1848. double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
  1849. mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
  1850. double fHdgDiff = fHdg - mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfHdg;
  1851. if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
  1852. if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
  1853. if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 0.5))
  1854. {
  1855. xdistogeo.mfdis = fdismin;
  1856. xdistogeo.mfs = fS;
  1857. mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS = fS;
  1858. }
  1859. else
  1860. {
  1861. xdistogeo.mfs = -1;
  1862. std::cout<<"point extend."<<std::endl;
  1863. mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS = -1;
  1864. }
  1865. xvectordistogeo.push_back(xdistogeo);
  1866. }
  1867. xvectoropdiss.push_back(xvectordistogeo);
  1868. }
  1869. //Get Lane Type
  1870. std::vector<std::vector<iv::lanetype>> xvevelanetype;
  1871. std::vector<std::vector<iv::lanetype>> xvectoroplanetype;
  1872. for(i=0;i<nlanesize;i++)
  1873. {
  1874. std::vector<iv::lanetype> xvelanetype;
  1875. int j;
  1876. int nlasttype;
  1877. iv::lanetype xlt;
  1878. xlt.s = 0;
  1879. xlt.ntype = 0;
  1880. int nsizelp = mvectorlp[mvectorroadlane[i]].mvectorlpright.size();
  1881. if(nsizelp > 0)
  1882. {
  1883. xlt.ntype = mvectorlp[mvectorroadlane[i]].mvectorlpright[0].nLaneType;
  1884. nlasttype = xlt.ntype;
  1885. }
  1886. for(j=1;j<nsizelp;j++)
  1887. {
  1888. int nlt = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].nLaneType;
  1889. if((nlt != nlasttype)&&(mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS != -1))
  1890. {
  1891. xvelanetype.push_back(xlt);
  1892. xlt.ntype = nlt;
  1893. xlt.s = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS;
  1894. }
  1895. nlasttype = nlt;
  1896. }
  1897. xvelanetype.push_back(xlt);
  1898. xvevelanetype.push_back(xvelanetype);
  1899. }
  1900. for(i=0;i<noplanesize;i++)
  1901. {
  1902. std::vector<iv::lanetype> xvelanetype;
  1903. int j;
  1904. int nlasttype;
  1905. iv::lanetype xlt;
  1906. xlt.s = 0;
  1907. xlt.ntype = 0;
  1908. int nsizelp = mvectorlp[mvectorroadopposite[i]].mvectorlpright.size();
  1909. if(nsizelp > 0)
  1910. {
  1911. xlt.ntype = mvectorlp[mvectorroadopposite[i]].mvectorlpright[nsizelp-1].nLaneType;
  1912. nlasttype = xlt.ntype;
  1913. }
  1914. for(j=(nsizelp-2);j>=0;j--)
  1915. {
  1916. int nlt = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].nLaneType;
  1917. if((nlt != nlasttype)&&(mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS != -1))
  1918. {
  1919. xvelanetype.push_back(xlt);
  1920. xlt.ntype = nlt;
  1921. xlt.s = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS;
  1922. }
  1923. nlasttype = nlt;
  1924. }
  1925. xvelanetype.push_back(xlt);
  1926. xvectoroplanetype.push_back(xvelanetype);
  1927. }
  1928. //Get Lane Mark Width
  1929. std::vector<double> xvectormarkwidth;
  1930. std::vector<double> xvectoravgdis;
  1931. for(i=0;i< static_cast<int>(xvectordiss.size());i++)
  1932. {
  1933. double fdis = 0;
  1934. int j;
  1935. int ncount = 0;
  1936. for(j=0;j<static_cast<int>(xvectordiss[i].size());j++)
  1937. {
  1938. if(xvectordiss[i].at(j).mfs != -1)
  1939. {
  1940. fdis = fdis + xvectordiss[i].at(j).mfdis;
  1941. ncount++;
  1942. }
  1943. }
  1944. if(ncount>0)fdis = fdis/ncount;
  1945. xvectoravgdis.push_back(fdis);
  1946. }
  1947. for(i=1;i<static_cast<int>(mvectorroadlane.size());i++)
  1948. {
  1949. xvectormarkwidth.push_back(xvectoravgdis[mvectorroadlane.size()+i-1] - xvectoravgdis[i-1]);
  1950. }
  1951. std::vector<double> xvectoropmarkwidth;
  1952. std::vector<double> xvectoropavgdis;
  1953. for(i=0;i<static_cast<int>(xvectoropdiss.size());i++)
  1954. {
  1955. double fdis = 0;
  1956. int j;
  1957. int ncount = 0;
  1958. int nsize = xvectoropdiss[i].size();
  1959. for(j=0;j<nsize;j++)
  1960. {
  1961. if(xvectoropdiss[i].at(j).mfs != -1)
  1962. {
  1963. fdis = fdis + xvectoropdiss[i].at(j).mfdis;
  1964. ncount++;
  1965. }
  1966. }
  1967. if(ncount>0)fdis = fdis/ncount;
  1968. xvectoropavgdis.push_back(fdis);
  1969. }
  1970. if(xvectoropavgdis.size()>0)xvectoropmarkwidth.push_back(xvectoropavgdis[0]);
  1971. for(i=1;i<static_cast<int>(mvectorroadopposite.size());i++)
  1972. {
  1973. xvectoropmarkwidth.push_back(xvectoropavgdis[i] - xvectoropavgdis[i+mvectorroadopposite.size()-1]);
  1974. }
  1975. //Get Lane Width
  1976. std::vector<std::vector<iv::distogeo>> xvectorlanewidth;
  1977. std::vector<std::vector<iv::distogeo>> xvectoroplanewidth;
  1978. std::vector<iv::distogeo> xlanewidth;
  1979. xlanewidth.clear();
  1980. int j;
  1981. for(j=0;j<static_cast<int>(xvectordiss[0].size());j++)
  1982. {
  1983. if(xvectordiss[0].at(j).mfs != -1)xlanewidth.push_back(xvectordiss[0].at(j));
  1984. }
  1985. xvectorlanewidth.push_back(xlanewidth);
  1986. for(i=1;i<static_cast<int>(mvectorroadlane.size());i++)
  1987. {
  1988. xlanewidth.clear();
  1989. for(j=0;j<static_cast<int>(xvectordiss[i].size());j++)
  1990. {
  1991. if((xvectordiss[i].at(j).mfs!=-1)&&(xvectordiss[i-1+nlanesize].at(j).mfs!=-1))
  1992. {
  1993. iv::distogeo xdisg;
  1994. xdisg = xvectordiss[i].at(j);
  1995. xdisg.mfdis = xdisg.mfdis - xvectordiss[i-1+nlanesize].at(j).mfdis + xvectormarkwidth[i-1];
  1996. xlanewidth.push_back(xdisg);
  1997. }
  1998. }
  1999. xvectorlanewidth.push_back(xlanewidth);
  2000. }
  2001. xlanewidth.clear();
  2002. if(xvectoropmarkwidth.size()>0)
  2003. {
  2004. if(xvectoropmarkwidth[0] > 0.4)
  2005. {
  2006. int nsize = xvectoropdiss[0].size();
  2007. for(j=0;j<nsize;j++)
  2008. {
  2009. if(xvectoropdiss[0].at(j).mfs != -1)xlanewidth.push_back(xvectoropdiss[0].at(j));
  2010. }
  2011. xvectoroplanewidth.push_back(xlanewidth);
  2012. xlanewidth.clear();
  2013. nsize = xvectoropdiss[noplanesize].size();
  2014. for(j=0;j<nsize;j++)
  2015. {
  2016. if((xvectoropdiss[noplanesize].at(j).mfs!=-1)&&(xvectoropdiss[0].at(j).mfs!=-1))
  2017. {
  2018. iv::distogeo xdisg;
  2019. xdisg = xvectoropdiss[noplanesize].at(j);
  2020. xdisg.mfdis = xdisg.mfdis - xvectoropdiss[0].at(j).mfdis ;
  2021. xlanewidth.push_back(xdisg);
  2022. }
  2023. }
  2024. xvectoroplanewidth.push_back(xlanewidth);
  2025. }
  2026. else
  2027. {
  2028. nsize = xvectoropdiss[noplanesize].size();
  2029. for(j=0;j<nsize;j++)
  2030. {
  2031. if((xvectoropdiss[noplanesize].at(j).mfs!=-1)&&(xvectoropdiss[0].at(j).mfs!=-1))
  2032. {
  2033. iv::distogeo xdisg;
  2034. xdisg = xvectoropdiss[noplanesize].at(j);
  2035. xdisg.mfdis = xdisg.mfdis - xvectoropdiss[0].at(j).mfdis + xvectoropmarkwidth[0];
  2036. xlanewidth.push_back(xdisg);
  2037. }
  2038. }
  2039. xvectoroplanewidth.push_back(xlanewidth);
  2040. }
  2041. for(i=1;i<noplanesize;i++)
  2042. {
  2043. xlanewidth.clear();
  2044. nsize = xvectoropdiss[noplanesize+i].size();
  2045. for(j=0;j<nsize;j++)
  2046. {
  2047. if((xvectoropdiss[noplanesize+i].at(j).mfs != -1)&&(xvectoropdiss[i].at(j).mfs != -1))
  2048. {
  2049. iv::distogeo xdisg;
  2050. xdisg = xvectoropdiss[noplanesize+i].at(j);
  2051. xdisg.mfdis = xdisg.mfdis - xvectoropdiss[i].at(j).mfdis + xvectoropmarkwidth[i];
  2052. xlanewidth.push_back(xdisg);
  2053. }
  2054. }
  2055. xvectoroplanewidth.push_back(xlanewidth);
  2056. }
  2057. }
  2058. std::vector<iv::lanecoff> xvectorlanecoff;
  2059. std::vector<iv::lanecoff> xvectoroplanecoff;
  2060. for(i=0;i<nlanesize;i++)
  2061. {
  2062. int N = xvectorlanewidth[i].size();
  2063. VectorXd x_veh(N);
  2064. VectorXd y_veh(N);
  2065. for(j=0;j<N;j++)
  2066. {
  2067. x_veh[j] = xvectorlanewidth[i].at(j).mfs;
  2068. y_veh[j] =xvectorlanewidth[i].at(j).mfdis;
  2069. }
  2070. VectorXd coeffs = polyfit(x_veh, y_veh, 3);
  2071. iv::lanecoff xlanecoff;
  2072. xlanecoff.A = coeffs[0];
  2073. xlanecoff.B = coeffs[1];
  2074. xlanecoff.C = coeffs[2];
  2075. xlanecoff.D = coeffs[3];
  2076. xvectorlanecoff.push_back(xlanecoff);
  2077. }
  2078. for(i=0;i< static_cast<int>(xvectoroplanewidth.size());i++)
  2079. {
  2080. int N = xvectoroplanewidth[i].size();
  2081. VectorXd x_veh(N);
  2082. VectorXd y_veh(N);
  2083. for(j=0;j<N;j++)
  2084. {
  2085. x_veh[j] = xvectoroplanewidth[i].at(j).mfs;
  2086. y_veh[j] =xvectoroplanewidth[i].at(j).mfdis;
  2087. }
  2088. VectorXd coeffs = polyfit(x_veh, y_veh, 3);
  2089. iv::lanecoff xlanecoff;
  2090. xlanecoff.A = coeffs[0];
  2091. xlanecoff.B = coeffs[1];
  2092. xlanecoff.C = coeffs[2];
  2093. xlanecoff.D = coeffs[3];
  2094. xvectoroplanecoff.push_back(xlanecoff);
  2095. }
  2096. iv::lanecoff xlaneheightcoff;
  2097. int M = mvectorlp[0].mvectorlpleft.size();
  2098. VectorXd x_vehhg(M);
  2099. VectorXd y_vehhg(M);
  2100. for(j=0;j<M;j++)
  2101. {
  2102. x_vehhg[j] = mvectorlp[0].mvectorlpleft.at(j).mfDis;
  2103. y_vehhg[j] =mvectorlp[0].mvectorlpleft.at(j).mfHeight;
  2104. }
  2105. VectorXd coeffs = polyfit(x_vehhg, y_vehhg, 3);
  2106. xlaneheightcoff.A = coeffs[0];
  2107. xlaneheightcoff.B = coeffs[1];
  2108. xlaneheightcoff.C = coeffs[2];
  2109. xlaneheightcoff.D = coeffs[3];
  2110. geofit xgeofit;
  2111. int N = pvectorlp->size();
  2112. VectorXd x_veh(N);
  2113. VectorXd y_veh(N);
  2114. VectorXi t_veh(N);
  2115. double x0,y0;
  2116. GaussProjCal(glon0,glat0,&x0,&y0);
  2117. for(j=0;j<N;j++)
  2118. {
  2119. double x,y;
  2120. GaussProjCal(pvectorlp->at(j).mfLon,pvectorlp->at(j).mfLat,&x,&y);
  2121. x_veh[j] = x - x0;
  2122. y_veh[j] = y - y0;
  2123. t_veh[j] = pntype[j];
  2124. }
  2125. std::vector<geobase> xvectorgeo = xgeofit.getgeo(x_veh,y_veh,t_veh);
  2126. // OpenDrive od;
  2127. // std::string mapx = "map";
  2128. // od.SetHeader(1,1,mapx,1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
  2129. j= 0;
  2130. double xroadlen = 0;
  2131. for(j=0;j<static_cast<int>(xvectorgeo.size());j++)
  2132. {
  2133. xroadlen = xroadlen + xvectorgeo[j].mfLen;
  2134. }
  2135. mxodr.AddRoad(mpLE_RoadName->text().toLatin1().data(),xroadlen, QString::number(CreateRoadID()).toStdString(),"-1");
  2136. Road * p = mxodr.GetRoad(mxodr.GetRoadCount() - 1);
  2137. p->AddElevation(0,xlaneheightcoff.A,xlaneheightcoff.B,xlaneheightcoff.C,xlaneheightcoff.D);
  2138. double s = 0;
  2139. j= 0;
  2140. // for(j=0;j<4;j++)
  2141. for(j=0;j<static_cast<int>( xvectorgeo.size());j++)
  2142. {
  2143. p->AddGeometryBlock();
  2144. GeometryBlock * pgb = p->GetGeometryBlock(j);
  2145. geobase * pline;
  2146. geobase * pbez;
  2147. geobase * parc;
  2148. switch(xvectorgeo[j].mnType)
  2149. {
  2150. case 0:
  2151. pline = &xvectorgeo[j];
  2152. pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
  2153. break;
  2154. case 1:
  2155. parc = &xvectorgeo[j];
  2156. pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
  2157. break;
  2158. case 2:
  2159. pbez = &xvectorgeo[j];
  2160. std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
  2161. pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
  2162. pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
  2163. pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
  2164. pbez->mfv[1],pbez->mfv[2],pbez->mfv[3]);
  2165. break;
  2166. }
  2167. s = s + xvectorgeo[j].mfLen;
  2168. }
  2169. p->AddLaneSection(0);
  2170. LaneSection * pLS = p->GetLaneSection(0);
  2171. Lane * pLL;
  2172. pLS->SetS(0);
  2173. pLS->AddLane(0,0,"none",false);
  2174. pLL = pLS->GetLane(0);
  2175. if(noplanesize != static_cast<int>(xvectoroplanewidth.size()))
  2176. {
  2177. pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  2178. }
  2179. for(i=0;i<nlanesize;i++)
  2180. {
  2181. pLS->AddLane(-1,(i+1)*(-1),"driving",false,false);
  2182. pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
  2183. pLL->AddWidthRecord(0,xvectorlanecoff[i].A,xvectorlanecoff[i].B,
  2184. xvectorlanecoff[i].C,xvectorlanecoff[i].D);
  2185. int j;
  2186. for(j=0;j<static_cast<int>(xvevelanetype[i].size());j++)
  2187. {
  2188. std::string strlanetype = "broken";
  2189. if(xvevelanetype[i].at(j).ntype != 0)
  2190. {
  2191. strlanetype = "solid";
  2192. }
  2193. pLL->AddRoadMarkRecord(xvevelanetype[i].at(j).s,strlanetype,"standard","standard",0.15,"false");
  2194. }
  2195. }
  2196. for(i=0;i<static_cast<int>(xvectoroplanewidth.size());i++)
  2197. {
  2198. pLS->AddLane(1,(i+1)*(1),"driving",false,false);
  2199. pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
  2200. if((i==0)&&(noplanesize != static_cast<int>(xvectoroplanewidth.size())))
  2201. {
  2202. pLL->SetType("shoulder");
  2203. pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  2204. }
  2205. pLL->AddWidthRecord(0,xvectoroplanecoff[i].A,xvectoroplanecoff[i].B,
  2206. xvectoroplanecoff[i].C,xvectoroplanecoff[i].D);
  2207. int j;
  2208. int index = i;
  2209. if((i==0)&&(noplanesize != static_cast<int>(xvectoroplanewidth.size())))
  2210. {
  2211. continue;
  2212. }
  2213. if(noplanesize != static_cast<int>(xvectoroplanewidth.size()))
  2214. {
  2215. index = i-1;
  2216. }
  2217. else
  2218. index = i;
  2219. for(j=0;j<static_cast<int>(xvectoroplanetype[index].size());j++)
  2220. {
  2221. std::string strlanetype = "broken";
  2222. if(xvectoroplanetype[index].at(j).ntype != 0)
  2223. {
  2224. strlanetype = "solid";
  2225. }
  2226. pLL->AddRoadMarkRecord(xvectoroplanetype[index].at(j).s,strlanetype,"standard","standard",0.15,"false");
  2227. }
  2228. }
  2229. mpCBSelLane->clear();
  2230. mpCBSelOpLane->clear();
  2231. mvectorroadlane.clear();
  2232. mvectorroadopposite.clear();
  2233. updateCBRoad();
  2234. mbRefresh = true;
  2235. update();
  2236. }
  2237. int MainWindow::CreateRoadID(int ntype)
  2238. {
  2239. int i;
  2240. bool bUsed = false;
  2241. int nroadidstart = 10000;
  2242. if(ntype == 1) //not create by lane roaid
  2243. {
  2244. nroadidstart = 20000;
  2245. }
  2246. int nroadcount = mxodr.GetRoadCount();
  2247. if(nroadcount == 0)return nroadidstart;
  2248. int * proadid = new int[nroadcount];
  2249. for(i=0;i<nroadcount;i++)
  2250. {
  2251. proadid[i]=atoi(mxodr.GetRoad(i)->GetRoadId().data());
  2252. }
  2253. do
  2254. {
  2255. bUsed = false;
  2256. for(i=0;i<nroadcount;i++)
  2257. {
  2258. if(proadid[i] == nroadidstart)
  2259. {
  2260. nroadidstart++;
  2261. bUsed = true;
  2262. }
  2263. }
  2264. }while(bUsed);
  2265. delete [] proadid;
  2266. return nroadidstart;
  2267. }
  2268. int MainWindow::CreateJunctionID()
  2269. {
  2270. int i;
  2271. bool bUsed = false;
  2272. int njunctionidstart = 800000;
  2273. int njunctioncount = mxodr.GetJunctionCount();
  2274. if(njunctioncount == 0)return njunctionidstart;
  2275. int * pjunctionid = new int[njunctioncount];
  2276. for(i=0;i<njunctioncount;i++)
  2277. {
  2278. pjunctionid[i]=atoi(mxodr.GetJunction(i)->GetId().data());
  2279. }
  2280. do
  2281. {
  2282. bUsed = false;
  2283. for(i=0;i<njunctioncount;i++)
  2284. {
  2285. if(pjunctionid[i] == njunctionidstart)
  2286. {
  2287. njunctionidstart++;
  2288. bUsed = true;
  2289. }
  2290. }
  2291. }while(bUsed);
  2292. delete []pjunctionid;
  2293. return njunctionidstart;
  2294. }
  2295. static bool IsNaN(double dat)
  2296. {
  2297. qint64 & ref=*(qint64 *)&dat;
  2298. return (ref&0x7FF0000000000000) == 0x7FF0000000000000 && (ref&0xfffffffffffff)!=0;
  2299. }
  2300. void MainWindow::onClickLoad()
  2301. {
  2302. QString str = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
  2303. if(str.isEmpty())return;
  2304. mvectorhideroadid.clear();
  2305. QString strfilepath = str;
  2306. QString strbak = str + ".bak";
  2307. QFileInfo fileback(strbak);
  2308. if(fileback.exists())
  2309. {
  2310. QMessageBox::StandardButton button;
  2311. // button=QMessageBox::question(this,tr("恢复备份"),QString(tr("上次为非正常退出,是否从备份文件导入?")),QMessageBox::Yes|QMessageBox::No);
  2312. button=QMessageBox::question(this,tr("Load Backup"),QString(tr("Last time it was an abnormal exit. Did you import it from a backup file?")),QMessageBox::Yes|QMessageBox::No);
  2313. if(button==QMessageBox::No)
  2314. {
  2315. }
  2316. else if(button==QMessageBox::Yes)
  2317. {
  2318. str = strbak;
  2319. }
  2320. }
  2321. OpenDrive * pxodr = new OpenDrive(); //because add to xodr,so don't delete
  2322. OpenDriveXmlParser x(pxodr);
  2323. if(!x.ReadFile(str.toStdString()))
  2324. {
  2325. QMessageBox::warning(this,"warn","Can't load xodr file.");
  2326. return;
  2327. }
  2328. int nroadnum = pxodr->GetRoadCount();
  2329. int i;
  2330. for(i=0;i<nroadnum;i++)
  2331. {
  2332. Road * pRoad = pxodr->GetRoad(i);
  2333. if(IsNaN(pRoad->GetRoadLength()))
  2334. {
  2335. pxodr->DeleteRoad(i);
  2336. i--;
  2337. nroadnum--;
  2338. qDebug("delete road %s because length is NaN",pRoad->GetRoadId().data());
  2339. continue;
  2340. }
  2341. unsigned int j;
  2342. double snow = 0;
  2343. double roadcalclen = 0;
  2344. for(j=0;j<pRoad->GetGeometryBlockCount();j++)
  2345. {
  2346. if(fabs(pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - snow)>0.1)
  2347. {
  2348. std::cout<<"change road "<<pRoad->GetRoadId().data()<<" S"<<std::endl;
  2349. pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(snow);
  2350. }
  2351. snow = snow + pRoad->GetGeometryBlock(j)->GetBlockLength();
  2352. roadcalclen = snow;
  2353. }
  2354. if(fabs(roadcalclen - pRoad->GetRoadLength())>0.1)
  2355. {
  2356. std::cout<<"change road "<<pRoad->GetRoadId().data()<<" Length"<<std::endl;
  2357. pRoad->SetRoadLength(roadcalclen);
  2358. }
  2359. }
  2360. bool bNeedMove = false;
  2361. bool bNeedAjustID = false;
  2362. unsigned short int revMajor,revMinor;
  2363. std::string name,date;
  2364. float version;
  2365. double north,south,east,west,lat0,lon0,hdg0;
  2366. if(pxodr->GetHeader() != 0)
  2367. {
  2368. pxodr->GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
  2369. // mxodr.SetHeader(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
  2370. // std::string strgeoref;
  2371. // std::string struserData;
  2372. // pxodr->GetHeader()->GetgeoReference(strgeoref);
  2373. // pxodr->GetHeader()->GetuserData(struserData);
  2374. // mxodr.GetHeader()->SetgeoReference(strgeoref);
  2375. // mxodr.GetHeader()->SetuserData(struserData);
  2376. }
  2377. else
  2378. {
  2379. lat0 = 39.0;
  2380. lon0 = 119.0;
  2381. }
  2382. double xMoveX = 0;
  2383. double xMoveY = 0;
  2384. bool bAddToNow = false;
  2385. if(mxodr.GetRoadCount() > 0)
  2386. {
  2387. QMessageBox::StandardButton button;
  2388. // button=QMessageBox::question(this,tr("载入模式"),QString(tr("附加到当前地图?")),QMessageBox::Yes|QMessageBox::No);
  2389. button=QMessageBox::question(this,tr("Load Mode"),QString(tr("Add on Current Map?")),QMessageBox::Yes|QMessageBox::No);
  2390. if(button==QMessageBox::No)
  2391. {
  2392. bAddToNow = false;
  2393. }
  2394. else if(button==QMessageBox::Yes)
  2395. {
  2396. bAddToNow = true;
  2397. }
  2398. }
  2399. if(bAddToNow )bNeedAjustID = true;
  2400. if(bAddToNow == false)
  2401. {
  2402. mbSetOrigin = false;
  2403. }
  2404. if(mbSetOrigin == false)
  2405. {
  2406. bNeedMove = false;
  2407. glat0 = lat0;
  2408. glon0 = lon0;
  2409. mpLELon0->setText(QString::number(glon0,'f',7));
  2410. mpLELat0->setText(QString::number(glat0,'f',7));
  2411. mbSetOrigin = true;
  2412. }
  2413. else
  2414. {
  2415. if((glat0 == lat0)&&(glon0 == lon0))
  2416. {
  2417. bNeedMove = false;
  2418. }
  2419. else
  2420. {
  2421. bNeedMove = true;
  2422. double x0,y0,x1,y1;
  2423. GaussProjCal(glon0,glat0,&x0,&y0);
  2424. GaussProjCal(lon0,lat0,&x1,&y1);
  2425. xMoveX = x1 - x0;
  2426. xMoveY = y1 - y0;
  2427. }
  2428. }
  2429. if(bNeedMove)
  2430. {
  2431. MoveXODR(pxodr,xMoveX,xMoveY);
  2432. }
  2433. int noldroadcount = mxodr.GetRoadCount();
  2434. int noldjunctioncount = mxodr.GetJunctionCount();
  2435. int nnewcount = pxodr->GetRoadCount();
  2436. int nnewjunctioncount = pxodr->GetJunctionCount();
  2437. // int i;
  2438. if(bNeedAjustID)
  2439. {
  2440. for(i=0;i<nnewcount;i++)
  2441. {
  2442. int nid = atoi(pxodr->GetRoad(i)->GetRoadId().data());
  2443. int j;
  2444. bool bNeedChange = false;
  2445. for(j=0;j<noldroadcount;j++)
  2446. {
  2447. if(nid == atoi(mxodr.GetRoad(j)->GetRoadId().data()))
  2448. {
  2449. bNeedChange = true;
  2450. break;
  2451. }
  2452. }
  2453. if(bNeedChange)
  2454. {
  2455. int nnewid = FindNewRoadID(&mxodr,pxodr);
  2456. ChangeXODRRoadID(pxodr,i,nnewid);
  2457. }
  2458. }
  2459. for(i=0;i<nnewjunctioncount;i++)
  2460. {
  2461. int nid = atoi(pxodr->GetJunction(i)->GetId().data());
  2462. int j;
  2463. bool bNeedChange = false;
  2464. for(j=0;j<noldjunctioncount;j++)
  2465. {
  2466. if(nid == atoi(mxodr.GetJunction(j)->GetId().data()))
  2467. {
  2468. bNeedChange = true;
  2469. break;
  2470. }
  2471. }
  2472. if(bNeedChange)
  2473. {
  2474. int nnewid = FindNewJunctionID(&mxodr,pxodr);
  2475. ChangeXODRJunctionID(pxodr,i,nnewid);
  2476. }
  2477. }
  2478. }
  2479. if(bAddToNow)
  2480. {
  2481. for(i=0;i<nnewcount;i++)
  2482. {
  2483. mxodr.GetRoadVector()->push_back(pxodr->GetRoadVector()->at(i));
  2484. // OpenDrive * px = &mxodr;
  2485. }
  2486. for(i=0;i<nnewjunctioncount;i++)
  2487. {
  2488. mxodr.GetJunctionVector()->push_back(pxodr->GetJunctionVector()->at(i));
  2489. }
  2490. if((mxodr.GetRoadCount()>0)&&(mxodr.GetHeader() == 0))
  2491. mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
  2492. }
  2493. else
  2494. {
  2495. mxodr = *pxodr;
  2496. }
  2497. updateCBRoad();
  2498. updateJunction();
  2499. mbRefresh = true;
  2500. update();
  2501. if(mpCBViewMode->currentIndex() == 1)
  2502. {
  2503. UpdateScene();
  2504. }
  2505. mpfb->Activate(strfilepath);
  2506. delete pxodr;
  2507. }
  2508. void MainWindow::onClickSave()
  2509. {
  2510. QString str = QFileDialog::getSaveFileName(this,"Save XODR",".","*.xodr");
  2511. if(str.isEmpty())return;
  2512. if(str.indexOf(".xodr")<0)str = str + ".xodr";
  2513. if(mxodr.GetHeader() == NULL)
  2514. {
  2515. mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
  2516. mxodr.GetHeader()->SetVendor("adc");
  2517. }
  2518. else
  2519. {
  2520. mxodr.GetHeader()->SetVendor("adc");
  2521. }
  2522. OpenDriveXmlWriter x(&mxodr);
  2523. x.WriteFile(str.toStdString());
  2524. mnNotSave = 0;
  2525. mpfb->Activate(str);
  2526. }
  2527. void MainWindow::onClickAutoRoadContact()
  2528. {
  2529. int ch1,ch2;
  2530. ch1 = mpCBRoad1->currentIndex();
  2531. ch2 = mpCBRoad2->currentIndex();
  2532. if((ch1 == -1)||(ch2 == -1))
  2533. {
  2534. return;
  2535. }
  2536. // if(ch1 == ch2)
  2537. // {
  2538. // QMessageBox::warning(this,"warn","road same");
  2539. // return;
  2540. // }
  2541. int ntype1,ntype2;
  2542. ntype1 = mpCBRC1->currentIndex();
  2543. ntype2 = mpCBRC2->currentIndex();
  2544. (void)ntype1; (void)ntype2;
  2545. Road * p1 = mxodr.GetRoad(ch1);
  2546. Road * p2 = mxodr.GetRoad(ch2);
  2547. int contactype;
  2548. int turnstraight;
  2549. std::vector<iv::ARC> xARCLane,xARCOpLane;
  2550. int nARCRtn = AutoRoadContact::CalcContact(p1,p2,contactype,turnstraight,xARCLane,xARCOpLane);
  2551. if(nARCRtn < 0)
  2552. {
  2553. QMessageBox::warning(this,"Warning","Auto Road Contact fail",QMessageBox::YesAll);
  2554. return;
  2555. }
  2556. switch (contactype) {
  2557. case 0:
  2558. mpCBRC1->setCurrentIndex(0);
  2559. mpCBRC2->setCurrentIndex(0);
  2560. break;
  2561. case 1:
  2562. mpCBRC1->setCurrentIndex(0);
  2563. mpCBRC2->setCurrentIndex(1);
  2564. break;
  2565. case 2:
  2566. mpCBRC1->setCurrentIndex(1);
  2567. mpCBRC2->setCurrentIndex(0);
  2568. break;
  2569. case 3:
  2570. mpCBRC1->setCurrentIndex(1);
  2571. mpCBRC2->setCurrentIndex(1);
  2572. break;
  2573. default:
  2574. break;
  2575. }
  2576. ntype1 = mpCBRC1->currentIndex();
  2577. ntype2 = mpCBRC2->currentIndex();
  2578. iv::roadcontact rc;
  2579. rc.mnroad1id = atoi(p1->GetRoadId().data());
  2580. rc.mnroad2id = atoi(p2->GetRoadId().data());
  2581. rc.mncon1 = ntype1;
  2582. rc.mncon2 = ntype2;
  2583. char strname[256];
  2584. if(xARCLane.size()>0)
  2585. {
  2586. snprintf(strname,256,"%s_%s_%s_%s",p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data(),
  2587. p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data());
  2588. }
  2589. else
  2590. {
  2591. xARCLane = xARCOpLane;
  2592. xARCOpLane.clear();
  2593. rc.mnroad2id = atoi(p1->GetRoadId().data());
  2594. rc.mnroad1id = atoi(p2->GetRoadId().data());
  2595. rc.mncon2 = ntype1;
  2596. rc.mncon1 = ntype2;
  2597. snprintf(strname,256,"%s_%s_%s_%s",p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data(),
  2598. p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data());
  2599. }
  2600. mpCBRoadCon->clear();
  2601. mpCBRoadCon->addItem(strname);
  2602. mpCBLane1->clear();
  2603. mpCBLane2->clear();
  2604. mpCBLane1Lane2->clear();
  2605. mpCBLane1Lane2op->clear();
  2606. if(p1->GetLaneSectionCount()>0)
  2607. {
  2608. LaneSection * pLS;
  2609. if(ntype1 == 0)
  2610. pLS = p1->GetLaneSection(0);
  2611. else
  2612. pLS = p1->GetLaneSection(p1->GetLaneSectionCount()-1);
  2613. int i;
  2614. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  2615. {
  2616. Lane * pL = pLS->GetLane(i);
  2617. // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
  2618. if(pL->GetId() != 0)
  2619. mpCBLane1->addItem(QString::number(pL->GetId()));
  2620. }
  2621. }
  2622. if(p2->GetLaneSectionCount()>0)
  2623. {
  2624. LaneSection * pLS;
  2625. if(ntype1 == 0)
  2626. pLS = p2->GetLaneSection(0);
  2627. else
  2628. pLS = p2->GetLaneSection(p2->GetLaneSectionCount()-1);
  2629. int i;
  2630. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  2631. {
  2632. Lane * pL = pLS->GetLane(i);
  2633. // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
  2634. if(pL->GetId() != 0)
  2635. mpCBLane2->addItem(QString::number(pL->GetId()));
  2636. }
  2637. }
  2638. mvectorrc.clear();
  2639. mvectorrc.push_back(rc);
  2640. mpCBRoadType->setCurrentIndex(turnstraight);
  2641. unsigned int i;
  2642. for(i=0;i<xARCLane.size();i++)
  2643. {
  2644. iv::lanecontact xlc;
  2645. xlc.ml1 = xARCLane.at(i).from;
  2646. xlc.ml2 = xARCLane.at(i).to;
  2647. if(mvectorrc.size() < 1)break;
  2648. mvectorrc[0].mvectorlc.push_back(xlc);
  2649. char strname[256];
  2650. snprintf(strname,255,"%dto%d",xlc.ml1,xlc.ml2);
  2651. mpCBLane1Lane2->addItem(strname);
  2652. }
  2653. for(i=0;i<xARCOpLane.size();i++)
  2654. {
  2655. iv::lanecontact xlc;
  2656. xlc.ml1 = xARCOpLane.at(i).from;
  2657. xlc.ml2 = xARCOpLane.at(i).to;
  2658. if(mvectorrc.size() < 1)break;
  2659. mvectorrc[0].mvectorlcop.push_back(xlc);
  2660. char strname[256];
  2661. snprintf(strname,255,"%dto%d",xlc.ml1,xlc.ml2);
  2662. mpCBLane1Lane2op->addItem(strname);
  2663. }
  2664. }
  2665. void MainWindow::onClickRoadContact()
  2666. {
  2667. int ch1,ch2;
  2668. ch1 = mpCBRoad1->currentIndex();
  2669. ch2 = mpCBRoad2->currentIndex();
  2670. if((ch1 == -1)||(ch2 == -1))
  2671. {
  2672. return;
  2673. }
  2674. // if(ch1 == ch2)
  2675. // {
  2676. // QMessageBox::warning(this,"warn","road same");
  2677. // return;
  2678. // }
  2679. int ntype1,ntype2;
  2680. ntype1 = mpCBRC1->currentIndex();
  2681. ntype2 = mpCBRC2->currentIndex();
  2682. Road * p1 = mxodr.GetRoad(ch1);
  2683. Road * p2 = mxodr.GetRoad(ch2);
  2684. iv::roadcontact rc;
  2685. rc.mnroad1id = atoi(p1->GetRoadId().data());
  2686. rc.mnroad2id = atoi(p2->GetRoadId().data());
  2687. rc.mncon1 = ntype1;
  2688. rc.mncon2 = ntype2;
  2689. char strname[256];
  2690. snprintf(strname,256,"%s_%s_%s_%s",p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data(),
  2691. p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data());
  2692. mpCBRoadCon->clear();
  2693. mpCBRoadCon->addItem(strname);
  2694. mpCBLane1->clear();
  2695. mpCBLane2->clear();
  2696. mpCBLane1Lane2->clear();
  2697. mpCBLane1Lane2op->clear();
  2698. if(p1->GetLaneSectionCount()>0)
  2699. {
  2700. LaneSection * pLS;
  2701. if(ntype1 == 0)
  2702. pLS = p1->GetLaneSection(0);
  2703. else
  2704. pLS = p1->GetLaneSection(p1->GetLaneSectionCount()-1);
  2705. int i;
  2706. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  2707. {
  2708. Lane * pL = pLS->GetLane(i);
  2709. // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
  2710. if(pL->GetId() != 0)
  2711. mpCBLane1->addItem(QString::number(pL->GetId()));
  2712. }
  2713. }
  2714. if(p2->GetLaneSectionCount()>0)
  2715. {
  2716. LaneSection * pLS;
  2717. if(ntype1 == 0)
  2718. pLS = p2->GetLaneSection(0);
  2719. else
  2720. pLS = p2->GetLaneSection(p2->GetLaneSectionCount()-1);
  2721. int i;
  2722. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  2723. {
  2724. Lane * pL = pLS->GetLane(i);
  2725. // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
  2726. if(pL->GetId() != 0)
  2727. mpCBLane2->addItem(QString::number(pL->GetId()));
  2728. }
  2729. }
  2730. mvectorrc.clear();
  2731. mvectorrc.push_back(rc);
  2732. }
  2733. void MainWindow::onClickLaneContact()
  2734. {
  2735. int n1,n2;
  2736. n1 = mpCBLane1->currentText().toInt();
  2737. n2 = mpCBLane2->currentText().toInt();
  2738. iv::lanecontact xlc;
  2739. xlc.ml1 = n1;
  2740. xlc.ml2 = n2;
  2741. if(mvectorrc.size() < 1)return;
  2742. mvectorrc[0].mvectorlc.push_back(xlc);
  2743. char strname[256];
  2744. snprintf(strname,255,"%dto%d",n1,n2);
  2745. mpCBLane1Lane2->addItem(strname);
  2746. }
  2747. void MainWindow::onClickOpLaneContact()
  2748. {
  2749. int n1,n2;
  2750. n1 = mpCBLane1->currentText().toInt();
  2751. n2 = mpCBLane2->currentText().toInt();
  2752. iv::lanecontact xlc;
  2753. xlc.ml1 = n1;
  2754. xlc.ml2 = n2;
  2755. if(mvectorrc.size() < 1)return;
  2756. mvectorrc[0].mvectorlcop.push_back(xlc);
  2757. char strname[256];
  2758. snprintf(strname,255,"%dto%d",n1,n2);
  2759. mpCBLane1Lane2op->addItem(strname);
  2760. }
  2761. void MainWindow::onClickClearLaneContact()
  2762. {
  2763. mpCBLane1Lane2op->clear();
  2764. mpCBLane1Lane2->clear();
  2765. if(mvectorrc.size()<1)return;
  2766. mvectorrc[0].mvectorlc.clear();
  2767. mvectorrc[0].mvectorlcop.clear();
  2768. }
  2769. void MainWindow::onClickCreateRoad()
  2770. {
  2771. if(mvectorrc.size()<1)return;
  2772. SaveBack();
  2773. Road * p1, *p2;
  2774. int nroad1index;
  2775. int nroad2index;
  2776. // p1 = mvectorrc[0].mp1;
  2777. // p2 = mvectorrc[0].mp2;
  2778. int i;
  2779. bool bhavep1 = false;
  2780. bool bhavep2 = false;
  2781. for(i=0;i<static_cast<int>(mxodr.GetRoadCount());i++)
  2782. {
  2783. if(mvectorrc[0].mnroad1id == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
  2784. {
  2785. bhavep1 = true;
  2786. p1 = mxodr.GetRoad(i);
  2787. nroad1index = i;
  2788. break;
  2789. }
  2790. }
  2791. if(bhavep1 == false)
  2792. {
  2793. QMessageBox::warning(this,tr("Warn"),tr("Road not found."));
  2794. return;
  2795. }
  2796. double off1,off2;
  2797. for(i=0;i<static_cast<int>(mxodr.GetRoadCount());i++)
  2798. {
  2799. if(mvectorrc[0].mnroad2id == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
  2800. {
  2801. bhavep2 = true;
  2802. p2 = mxodr.GetRoad(i);
  2803. nroad2index = i;
  2804. break;
  2805. }
  2806. }
  2807. if(bhavep2 == false)
  2808. {
  2809. QMessageBox::warning(this,tr("Warn"),tr("Road not found."));
  2810. return;
  2811. }
  2812. if(mvectorrc[0].mvectorlc.size()<1)
  2813. {
  2814. QMessageBox::warning(this,tr("Warn"),tr("No Lane Contact."));
  2815. return;
  2816. }
  2817. double startx,starty,starthdg;
  2818. double endx,endy,endhdg;
  2819. double startheight,endheight;
  2820. bool bFromstart,bTostart;
  2821. if(mvectorrc[0].mncon1 == 0)
  2822. {
  2823. bFromstart = true;
  2824. starthdg = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
  2825. off1 = getoff(p1,mvectorrc[0].mvectorlc[0].ml1,true);
  2826. startx = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
  2827. starty = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
  2828. if(p1->GetLaneOffsetCount()>0)
  2829. {
  2830. off1 = off1 - p1->GetLaneOffset(0)->Geta();
  2831. }
  2832. startx = startx + off1 * cos(starthdg -M_PI/2.0);
  2833. starty = starty + off1 * sin(starthdg -M_PI/2.0);
  2834. startheight = 0;
  2835. if(p1->GetElevationCount()>0)
  2836. {
  2837. startheight = p1->GetElevation(0)->GetA();
  2838. }
  2839. // if(mvectorrc[0].mvectorlc[0].ml1<0)
  2840. starthdg = starthdg +M_PI;if(starthdg >=2.0*M_PI)starthdg = starthdg -2.0*M_PI;
  2841. }
  2842. else
  2843. {
  2844. bFromstart = false;
  2845. if(GetEndPoint(p1,startx,starty,starthdg) != 0)
  2846. {
  2847. QMessageBox::warning(this,tr("Warn"),tr("get start error."));
  2848. return;
  2849. }
  2850. off1 = getoff(p1,mvectorrc[0].mvectorlc[0].ml1,false);
  2851. if(p1->GetLaneOffsetCount()>0)
  2852. {
  2853. LaneOffset * pLO = p1->GetLaneOffset(p1->GetLaneOffsetCount()-1);
  2854. double froadlen = p1->GetRoadLength();
  2855. double sdis = froadlen - pLO->GetS();
  2856. double foffset = pLO->Geta() + pLO->Getb()*(sdis) + pLO->Getc() * sdis * sdis
  2857. +pLO->Getd() * sdis * sdis * sdis;
  2858. off1 = off1 - foffset;
  2859. }
  2860. startx = startx + off1 * cos(starthdg -M_PI/2.0);
  2861. starty = starty + off1 * sin(starthdg -M_PI/2.0);
  2862. startheight = 0;
  2863. if(p1->GetElevationCount()>0)
  2864. {
  2865. startheight = p1->GetElevation(0)->GetA()
  2866. +p1->GetElevation(0)->GetB() * pow(p1->GetRoadLength(),1)
  2867. +p1->GetElevation(0)->GetC() * pow(p1->GetRoadLength(),2)
  2868. +p1->GetElevation(0)->GetD() * pow(p1->GetRoadLength(),3);
  2869. }
  2870. }
  2871. if(mvectorrc[0].mncon2 == 0)
  2872. {
  2873. bTostart = true;
  2874. off2 = getoff(p2,mvectorrc[0].mvectorlc[0].ml2,true);
  2875. endx = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
  2876. endy = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
  2877. endhdg = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
  2878. if(p2->GetLaneOffsetCount()>0)
  2879. {
  2880. off2 = off2 - p2->GetLaneOffset(0)->Geta();
  2881. }
  2882. endx = endx + off2 * cos(endhdg -M_PI/2.0);
  2883. endy = endy + off2 * sin(endhdg -M_PI/2.0);
  2884. endheight = 0;
  2885. if(p2->GetElevationCount()>0)
  2886. {
  2887. endheight = p2->GetElevation(0)->GetA();
  2888. }
  2889. }
  2890. else
  2891. {
  2892. bTostart = false;
  2893. off2 = getoff(p2,mvectorrc[0].mvectorlc[0].ml2,false);
  2894. if(GetEndPoint(p2,endx,endy,endhdg) != 0)
  2895. {
  2896. QMessageBox::warning(this,tr("Warn"),tr("get end error."));
  2897. return;
  2898. }
  2899. if(p2->GetLaneOffsetCount()>0)
  2900. {
  2901. LaneOffset * pLO = p2->GetLaneOffset(p2->GetLaneOffsetCount()-1);
  2902. double froadlen = p2->GetRoadLength();
  2903. double sdis = froadlen - pLO->GetS();
  2904. double foffset = pLO->Geta() + pLO->Getb()*(sdis) + pLO->Getc() * sdis * sdis
  2905. +pLO->Getd() * sdis * sdis * sdis;
  2906. off2 = off2 - foffset;
  2907. }
  2908. endx = endx + off2 * cos(endhdg -M_PI/2.0);
  2909. endy = endy + off2 * sin(endhdg -M_PI/2.0);
  2910. endhdg = endhdg +M_PI;if(endhdg >=2.0*M_PI)endhdg = endhdg -2.0*M_PI;
  2911. endheight = 0;
  2912. if(p2->GetElevationCount()>0)
  2913. {
  2914. endheight = p2->GetElevation(0)->GetA()
  2915. +p2->GetElevation(0)->GetB() * pow(p2->GetRoadLength(),1)
  2916. +p2->GetElevation(0)->GetC() * pow(p2->GetRoadLength(),2)
  2917. +p2->GetElevation(0)->GetD() * pow(p2->GetRoadLength(),3);
  2918. }
  2919. }
  2920. //Create Geo
  2921. double R = mpLERoadType->text().toDouble();
  2922. std::vector<geobase> xvectorgeo;
  2923. std::vector<geobase> xvectorgeo1,xvectorgeo2;
  2924. switch(mpCBRoadType->currentIndex())
  2925. {
  2926. case 0:
  2927. xvectorgeo = CreateTurnGeo(startx,starty,starthdg,endx,endy,endhdg,R);
  2928. break;
  2929. case 1:
  2930. {
  2931. double fdis = sqrt(pow(startx - endx,2) +pow(starty -endy,2));
  2932. if((fdis<3) || (starthdg == endhdg) ||(mpCBStraightType->isChecked()))
  2933. {
  2934. xvectorgeo = CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
  2935. }
  2936. else
  2937. {
  2938. xvectorgeo = geofit::CreateBezierGeo(startx,starty,starthdg,endx,endy,endhdg);
  2939. }
  2940. //
  2941. }
  2942. break;
  2943. case 2:
  2944. xvectorgeo = CreateUTurnGeo(startx,starty,starthdg,endx,endy,endhdg,R);
  2945. break;
  2946. default:
  2947. break;
  2948. }
  2949. if(mpCBRoadType->currentIndex() == 2)
  2950. {
  2951. for(i=0;i<static_cast<int>(xvectorgeo.size())/2;i++)
  2952. {
  2953. xvectorgeo1.push_back(xvectorgeo.at(i));
  2954. }
  2955. for(i=static_cast<int>(xvectorgeo.size())/2;i<static_cast<int>(xvectorgeo.size());i++)
  2956. {
  2957. xvectorgeo2.push_back(xvectorgeo.at(i));
  2958. }
  2959. }
  2960. if(xvectorgeo.size() == 0)
  2961. {
  2962. QMessageBox::warning(this,tr("Warn"),tr("Create Road Fail."));
  2963. return;
  2964. }
  2965. double xroadlen = 0;
  2966. if(mpCBRoadType->currentIndex() != 2)
  2967. {
  2968. for(i=0;i<static_cast<int>(xvectorgeo.size());i++)xroadlen = xroadlen + xvectorgeo[i].mfLen;
  2969. mxodr.AddRoad("",xroadlen, QString::number(CreateRoadID()).toStdString(),"-1");
  2970. Road * p = mxodr.GetRoad(mxodr.GetRoadCount() - 1);
  2971. p->AddElevation(0,startheight,(endheight-startheight)/xroadlen,0,0);
  2972. p1 = mxodr.GetRoad(nroad1index);
  2973. p2 = mxodr.GetRoad(nroad2index);
  2974. double s = 0;
  2975. int j = 0;
  2976. for(j=0;j<static_cast<int>(xvectorgeo.size());j++)
  2977. {
  2978. p->AddGeometryBlock();
  2979. GeometryBlock * pgb = p->GetGeometryBlock(j);
  2980. geobase * pline;
  2981. geobase * pbez;
  2982. geobase * parc;
  2983. switch(xvectorgeo[j].mnType)
  2984. {
  2985. case 0:
  2986. pline = &xvectorgeo[j];
  2987. pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
  2988. break;
  2989. case 1:
  2990. parc = &xvectorgeo[j];
  2991. pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
  2992. break;
  2993. case 2:
  2994. pbez = &xvectorgeo[j];
  2995. std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
  2996. pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
  2997. pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
  2998. pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
  2999. pbez->mfv[1],pbez->mfv[2],pbez->mfv[3],false);
  3000. break;
  3001. }
  3002. s = s + xvectorgeo[j].mfLen;
  3003. }
  3004. p->AddLaneSection(0);
  3005. LaneSection * pLS = p->GetLaneSection(0);
  3006. pLS->SetS(0);
  3007. pLS->AddLane(0,0,"none",false);
  3008. double * pswidth,*pewidth;
  3009. std::vector<std::string> strvectorlanetype;
  3010. int nlanecount = mvectorrc[0].mvectorlc.size();
  3011. pswidth = new double[nlanecount];
  3012. pewidth = new double[nlanecount];
  3013. std::shared_ptr<double> ppswidth,ppewidth;
  3014. ppswidth.reset(pswidth);
  3015. ppewidth.reset(pewidth);
  3016. for(i=0;i<nlanecount;i++)
  3017. {
  3018. pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart);
  3019. strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart));
  3020. }
  3021. for(i=0;i<nlanecount;i++)
  3022. {
  3023. pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlc.at(i).ml2,bTostart);
  3024. }
  3025. double * pa,*pb;
  3026. pa = new double[nlanecount];
  3027. pb = new double[nlanecount];
  3028. std::shared_ptr<double> ppa,ppb;
  3029. ppa.reset(pa);
  3030. ppb.reset(pb);
  3031. for(i=0;i<nlanecount;i++)
  3032. {
  3033. pa[i] = pswidth[i];
  3034. pb[i] = (pewidth[i] - pa[i])/xroadlen;
  3035. }
  3036. for(i=0;i<nlanecount;i++)
  3037. {
  3038. pLS->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
  3039. Lane * pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
  3040. pLL->AddWidthRecord(0,pa[i],pb[i],
  3041. 0,0);
  3042. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3043. }
  3044. int noplanecount = mvectorrc[0].mvectorlcop.size();
  3045. if(noplanecount > 0)
  3046. {
  3047. pswidth = new double[noplanecount];
  3048. pewidth = new double[noplanecount];
  3049. ppswidth.reset(pswidth);
  3050. ppewidth.reset(pewidth);
  3051. strvectorlanetype.clear();
  3052. for(i=0;i<noplanecount;i++)
  3053. {
  3054. pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart);
  3055. strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart));
  3056. }
  3057. for(i=0;i<noplanecount;i++)
  3058. {
  3059. pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlcop.at(i).ml2,bTostart);
  3060. }
  3061. pa = new double[noplanecount];
  3062. pb = new double[noplanecount];
  3063. ppa.reset(pa);
  3064. ppb.reset(pb);
  3065. for(i=0;i<noplanecount;i++)
  3066. {
  3067. pa[i] = pswidth[i];
  3068. pb[i] = (pewidth[i] - pa[i])/xroadlen;
  3069. }
  3070. for(i=0;i<noplanecount;i++)
  3071. {
  3072. pLS->AddLane(1,(i+1),strvectorlanetype[i],false,false);
  3073. Lane * pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
  3074. pLL->AddWidthRecord(0,pa[i],pb[i],
  3075. 0,0);
  3076. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3077. }
  3078. }
  3079. }
  3080. else
  3081. {
  3082. double xroadlen1 = 0;
  3083. double xroadlen2 = 0;
  3084. for(i=0;i<static_cast<int>(xvectorgeo1.size());i++)xroadlen1 = xroadlen1 + xvectorgeo1[i].mfLen;
  3085. for(i=0;i<static_cast<int>(xvectorgeo2.size());i++)xroadlen2 = xroadlen2 + xvectorgeo2[i].mfLen;
  3086. int index1 = mxodr.AddRoad("",xroadlen1, QString::number(CreateRoadID()).toStdString(),"-1");
  3087. int index2 = mxodr.AddRoad("",xroadlen2, QString::number(CreateRoadID()).toStdString(),"-1");
  3088. Road * proad2 = mxodr.GetRoad(index2);
  3089. Road * proad1 = mxodr.GetRoad(index1);
  3090. proad1->AddElevation(0,startheight,(endheight-startheight)/(xroadlen1+xroadlen2),0,0);
  3091. proad2->AddElevation(0,startheight+xroadlen1*(endheight-startheight)/(xroadlen1+xroadlen2),
  3092. (endheight-startheight)/(xroadlen1+xroadlen2),
  3093. 0,0);
  3094. p1 = mxodr.GetRoad(nroad1index);
  3095. p2 = mxodr.GetRoad(nroad2index);
  3096. // OpenDrive * px = &mxodr;
  3097. double s = 0;
  3098. int j = 0;
  3099. for(j=0;j<static_cast<int>(xvectorgeo1.size());j++)
  3100. {
  3101. proad1->AddGeometryBlock();
  3102. GeometryBlock * pgb = proad1->GetGeometryBlock(j);
  3103. geobase * pline;
  3104. geobase * pbez;
  3105. geobase * parc;
  3106. switch(xvectorgeo1[j].mnType)
  3107. {
  3108. case 0:
  3109. pline = &xvectorgeo1[j];
  3110. pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
  3111. break;
  3112. case 1:
  3113. parc = &xvectorgeo1[j];
  3114. pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
  3115. break;
  3116. case 2:
  3117. pbez = &xvectorgeo1[j];
  3118. std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
  3119. pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
  3120. pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
  3121. pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
  3122. pbez->mfv[1],pbez->mfv[2],pbez->mfv[3],false);
  3123. break;
  3124. }
  3125. s = s + xvectorgeo1[j].mfLen;
  3126. }
  3127. s=0.0;
  3128. for(j=0;j<static_cast<int>(xvectorgeo2.size());j++)
  3129. {
  3130. proad2->AddGeometryBlock();
  3131. GeometryBlock * pgb = proad2->GetGeometryBlock(j);
  3132. geobase * pline;
  3133. geobase * pbez;
  3134. geobase * parc;
  3135. switch(xvectorgeo2[j].mnType)
  3136. {
  3137. case 0:
  3138. pline = &xvectorgeo2[j];
  3139. pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
  3140. break;
  3141. case 1:
  3142. parc = &xvectorgeo2[j];
  3143. pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
  3144. break;
  3145. case 2:
  3146. pbez = &xvectorgeo2[j];
  3147. std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
  3148. pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
  3149. pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
  3150. pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
  3151. pbez->mfv[1],pbez->mfv[2],pbez->mfv[3]);
  3152. break;
  3153. }
  3154. s = s + xvectorgeo2[j].mfLen;
  3155. }
  3156. proad1->AddLaneSection(0);
  3157. LaneSection * pLS1 = proad1->GetLaneSection(0);
  3158. pLS1->SetS(0);
  3159. pLS1->AddLane(0,0,"none",false);
  3160. proad2->AddLaneSection(0);
  3161. LaneSection * pLS2 = proad2->GetLaneSection(0);
  3162. pLS2->SetS(0);
  3163. pLS2->AddLane(0,0,"none",false);
  3164. double * pswidth,*pewidth;
  3165. int nlanecount = mvectorrc[0].mvectorlc.size();
  3166. std::vector<std::string> strvectorlanetype;
  3167. pswidth = new double[nlanecount];
  3168. pewidth = new double[nlanecount];
  3169. std::shared_ptr<double> ppswidth,ppewidth;
  3170. ppswidth.reset(pswidth);
  3171. ppewidth.reset(pewidth);
  3172. for(i=0;i<nlanecount;i++)
  3173. {
  3174. pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart);
  3175. strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart));
  3176. }
  3177. for(i=0;i<nlanecount;i++)
  3178. {
  3179. pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlc.at(i).ml2,bTostart);
  3180. }
  3181. double * pa,*pb;
  3182. pa = new double[nlanecount];
  3183. pb = new double[nlanecount];
  3184. std::shared_ptr<double> ppa,ppb;
  3185. ppa.reset(pa);
  3186. ppb.reset(pb);
  3187. for(i=0;i<nlanecount;i++)
  3188. {
  3189. pa[i] = pswidth[i];
  3190. pb[i] = (pewidth[i] - pa[i])/(xroadlen1+xroadlen2);
  3191. }
  3192. for(i=0;i<nlanecount;i++)
  3193. {
  3194. pLS1->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
  3195. Lane * pLL = pLS1->GetLane(pLS1->GetLaneCount() - 1);
  3196. pLL->AddWidthRecord(0,pa[i],pb[i],
  3197. 0,0);
  3198. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3199. pLS2->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
  3200. pLL = pLS2->GetLane(pLS2->GetLaneCount() - 1);
  3201. pLL->AddWidthRecord(0,pa[i]+pb[i]*xroadlen1 ,pb[i],
  3202. 0,0);
  3203. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3204. }
  3205. int noplanecount = mvectorrc[0].mvectorlcop.size();
  3206. if(noplanecount > 0)
  3207. {
  3208. pswidth = new double[noplanecount];
  3209. pewidth = new double[noplanecount];
  3210. ppswidth.reset(pswidth);
  3211. ppewidth.reset(pewidth);
  3212. strvectorlanetype.clear();
  3213. for(i=0;i<noplanecount;i++)
  3214. {
  3215. pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart);
  3216. strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart));
  3217. }
  3218. for(i=0;i<noplanecount;i++)
  3219. {
  3220. pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlcop.at(i).ml2,bTostart);
  3221. }
  3222. pa = new double[noplanecount];
  3223. pb = new double[noplanecount];
  3224. ppa.reset(pa);
  3225. ppb.reset(pb);
  3226. for(i=0;i<noplanecount;i++)
  3227. {
  3228. pa[i] = pswidth[i];
  3229. pb[i] = (pewidth[i] - pa[i])/xroadlen;
  3230. }
  3231. for(i=0;i<noplanecount;i++)
  3232. {
  3233. pLS1->AddLane(1,(i+1),strvectorlanetype[i],false,false);
  3234. Lane * pLL = pLS1->GetLane(pLS1->GetLaneCount() - 1);
  3235. pLL->AddWidthRecord(0,pa[i],pb[i],
  3236. 0,0);
  3237. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3238. pLS2->AddLane(1,(i+1),strvectorlanetype[i],false,false);
  3239. pLL = pLS2->GetLane(pLS2->GetLaneCount() - 1);
  3240. pLL->AddWidthRecord(0,pa[i]+pb[i]*xroadlen1 ,pb[i],
  3241. 0,0);
  3242. // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
  3243. }
  3244. }
  3245. }
  3246. updateCBRoad();
  3247. mbRefresh = true;
  3248. update();
  3249. if(mpCBViewMode->currentIndex() == 1)
  3250. {
  3251. UpdateScene();
  3252. }
  3253. mpfb->SetOpenDrive(mxodr);
  3254. }
  3255. int MainWindow::GetEndPoint(Road *proad, double &x, double &y, double &hdg)
  3256. {
  3257. GeometryBlock * pblock = proad->GetLastGeometryBlock();
  3258. RoadGeometry * pgeo = pblock->GetLastGeometry();
  3259. (void)pgeo;
  3260. proad->GetGeometryCoords(proad->GetRoadLength(),x,y,hdg);
  3261. return 0;
  3262. //0-line, 1-arc, 2-spiral 3-poly3 4-parampoly3
  3263. switch (pgeo->GetGeomType()) {
  3264. case 0:
  3265. {
  3266. GeometryLine * pline = (GeometryLine *)pgeo;
  3267. x = pline->GetX() + pline->GetLength() * cos(pline->GetHdg());
  3268. y = pline->GetY() + pline->GetLength() * sin(pline->GetHdg());
  3269. hdg = pline->GetHdg();
  3270. }
  3271. return 0;
  3272. break;
  3273. case 1:
  3274. {
  3275. GeometryArc * parc = (GeometryArc *)pgeo;
  3276. double x_center = parc->GetX() + (1.0/parc->GetCurvature()) * cos(parc->GetHdg() + M_PI/2.0);
  3277. double y_center = parc->GetY() + (1.0/parc->GetCurvature()) * sin(parc->GetHdg()+ M_PI/2.0);
  3278. x = x_center + fabs(1.0/parc->GetCurvature()) * cos(parc->GetHdg() + parc->GetLength() * parc->GetCurvature() - M_PI/2.0);
  3279. y = y_center + fabs(1.0/parc->GetCurvature()) * sin(parc->GetHdg() + parc->GetLength() * parc->GetCurvature() - M_PI/2.0);
  3280. hdg = parc->GetHdg() + parc->GetLength() * parc->GetCurvature();
  3281. return 0;
  3282. }
  3283. break;
  3284. case 2:
  3285. {
  3286. GeometrySpiral * pspiral = (GeometrySpiral *)pgeo;
  3287. pspiral->GetCoords(pspiral->GetS()+pspiral->GetLength(),x,y,hdg);
  3288. return 0;
  3289. }
  3290. break;
  3291. case 3:
  3292. QMessageBox::warning(this,tr("Warn"),tr("type not supported."));
  3293. break;
  3294. case 4:
  3295. {
  3296. double xtem,ytem;
  3297. double xtem1,ytem1,x1,y1;
  3298. GeometryParamPoly3 * ppoly3 = (GeometryParamPoly3* )pgeo;
  3299. double s = ppoly3->GetLength();
  3300. // xtem = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
  3301. // ytem = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
  3302. if(ppoly3->GetNormal())
  3303. {
  3304. xtem = ppoly3->GetuA() + ppoly3->GetuB() + ppoly3->GetuC() + ppoly3->GetuD() ;
  3305. ytem = ppoly3->GetvA() + ppoly3->GetvB() + ppoly3->GetvC() + ppoly3->GetvD() ;
  3306. }
  3307. else
  3308. {
  3309. xtem = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
  3310. ytem = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
  3311. }
  3312. x = xtem*cos(ppoly3->GetHdg()) - ytem * sin(ppoly3->GetHdg()) + ppoly3->GetX();
  3313. y = xtem*sin(ppoly3->GetHdg()) + ytem * cos(ppoly3->GetHdg()) + ppoly3->GetY();
  3314. s = ppoly3->GetLength()*0.99;
  3315. if(s>0)
  3316. {
  3317. double frel = 0.99;
  3318. if(ppoly3->GetNormal() == false)
  3319. {
  3320. xtem1 = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
  3321. ytem1 = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
  3322. }
  3323. else
  3324. {
  3325. xtem1 = ppoly3->GetuA() + ppoly3->GetuB() * frel + ppoly3->GetuC() *frel*frel + ppoly3->GetuD()*frel*frel*frel ;
  3326. ytem1 = ppoly3->GetvA() + ppoly3->GetvB()*frel + ppoly3->GetvC()*frel*frel + ppoly3->GetvD()*frel*frel*frel ;
  3327. }
  3328. x1 = xtem1*cos(ppoly3->GetHdg()) - ytem1 * sin(ppoly3->GetHdg()) + ppoly3->GetX();
  3329. y1 = xtem1*sin(ppoly3->GetHdg()) + ytem1 * cos(ppoly3->GetHdg()) + ppoly3->GetY();
  3330. hdg = geofit::CalcHdg(x1,y1,x,y);
  3331. }
  3332. else
  3333. {
  3334. hdg = 0;
  3335. }
  3336. return 0;
  3337. }
  3338. break;
  3339. default:
  3340. QMessageBox::warning(this,tr("Warn"),tr("type not supported."));
  3341. break;
  3342. }
  3343. return -1;
  3344. }
  3345. void MainWindow::onChangeRoadType(int index)
  3346. {
  3347. if(index == 1)
  3348. {
  3349. mpLBRoadType->setVisible(true);
  3350. mpLERoadType->setVisible(false);
  3351. mpCBStraightType->setVisible(true);
  3352. }
  3353. else
  3354. {
  3355. mpLBRoadType->setVisible(true);
  3356. mpLERoadType->setVisible(true);
  3357. mpCBStraightType->setVisible(false);
  3358. }
  3359. if(index == 0)
  3360. {
  3361. mpLBRoadType->setText("Radius:");
  3362. mpLERoadType->setText("6.0");
  3363. }
  3364. if(index == 1)
  3365. {
  3366. mpLBRoadType->setText("Type:");
  3367. }
  3368. if(index == 2)
  3369. {
  3370. mpLBRoadType->setText("Extend:");
  3371. mpLERoadType->setText("3.0");
  3372. }
  3373. }
  3374. std::vector<geobase> MainWindow::CreateLineGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg)
  3375. {
  3376. (void)starthdg;
  3377. (void)endhdg;
  3378. // std::vector<geobase> xvectorgeo;
  3379. // geobase xgeobezier;
  3380. // int nbtype;
  3381. // double fabc[3],fxy[2],fblen,fbhdg;
  3382. // geofit x;
  3383. // x.CreateBezier(startx,starty,starthdg,
  3384. // endx,endy,endhdg,
  3385. // 0.35,0.35,xgeobezier.mfu,xgeobezier.mfv,xgeobezier.mfLen,
  3386. // nbtype,fabc,&fbhdg,fxy,&fblen);
  3387. // if(nbtype == 2)
  3388. // {
  3389. // xgeobezier.mfHdg = starthdg;
  3390. // xgeobezier.mfX = startx;
  3391. // xgeobezier.mfY = starty;
  3392. // xgeobezier.mnType = 2;
  3393. // }
  3394. // else
  3395. // {
  3396. // xgeobezier.mnType = 0; //Line
  3397. // xgeobezier.mfHdgStart = fbhdg;
  3398. // xgeobezier.mfHdg = fbhdg;
  3399. // xgeobezier.mfX = fxy[0];
  3400. // xgeobezier.mfY = fxy[1];
  3401. // xgeobezier.mfLen = fblen;
  3402. // }
  3403. // xvectorgeo.push_back(xgeobezier);
  3404. // return xvectorgeo;
  3405. geobase linegeo;
  3406. linegeo.mnType = 0;
  3407. linegeo.mfX = startx;
  3408. linegeo.mfY = starty;
  3409. linegeo.mfHdg = geofit::CalcHdg(startx,starty,endx,endy);
  3410. linegeo.mfLen = sqrt(pow(endx - startx,2)+pow(endy - starty,2));
  3411. std::vector<geobase> xvectorgeo;
  3412. xvectorgeo.push_back(linegeo);
  3413. return xvectorgeo;
  3414. }
  3415. std::vector<geobase> MainWindow::CreateTurnGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg,double R)
  3416. {
  3417. std::vector<geobase> xvectorgeo;
  3418. xvectorgeo.clear();
  3419. if(starthdg == endhdg)
  3420. {
  3421. std::cout<<"hdg same use line contact"<<std::endl;
  3422. return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
  3423. }
  3424. double a1,c1,a2,c2;
  3425. double inter_x,inter_y;
  3426. if((starthdg == M_PI/2.0)||(starthdg == 3.0*M_PI/2.0))
  3427. {
  3428. a2 = tan(endhdg) *(-1);
  3429. c2 = 0-a2*endx - endy;
  3430. a1 = 1;
  3431. c1 = startx *(-1);
  3432. (void)a1; (void)c1;
  3433. inter_x = startx;
  3434. inter_y = 0 - a2*inter_x-c2;
  3435. }
  3436. else
  3437. {
  3438. if((endhdg == M_PI/2.0)||(endhdg == 3.0*M_PI/2.0))
  3439. {
  3440. a1 = tan(starthdg) *(-1);
  3441. c1 = 0-a1*startx - starty;
  3442. a2 = 1;
  3443. c2 = endx *(-1);
  3444. (void)a2; (void)c2;
  3445. inter_x = endx;
  3446. inter_y = 0 - a1*inter_x-c1;
  3447. }
  3448. else
  3449. {
  3450. a1 = tan(starthdg) *(-1);
  3451. a2 = tan(endhdg) *(-1);
  3452. c1 = 0-a1*startx - starty;
  3453. c2 = 0-a2*endx - endy;
  3454. inter_x = (c1-c2)/(a2-a1);
  3455. inter_y = 0 - a1*inter_x - c1;
  3456. }
  3457. }
  3458. double dis1,dis2;
  3459. dis1 =sqrt(pow(inter_x - startx,2)+pow(inter_y - starty,2));
  3460. dis2 =sqrt(pow(inter_x - endx,2)+pow(inter_y - endy,2));
  3461. if((dis1<1.0)||(dis2<1.0))
  3462. {
  3463. std::cout<<"use line connect."<<std::endl;
  3464. char strinfo[256];
  3465. snprintf(strinfo,256,"Use Line Connect");
  3466. QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
  3467. return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
  3468. }
  3469. if((R>=dis1 )||(R>=dis2))
  3470. {
  3471. R = dis1 - 0.3;
  3472. if(R>=dis2)
  3473. {
  3474. R = dis2 - 0.3;
  3475. }
  3476. char strinfo[256];
  3477. snprintf(strinfo,256,"Change Radius to %f",R);
  3478. QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
  3479. }
  3480. double hdgdiff = endhdg - starthdg;
  3481. if(hdgdiff >= M_PI)hdgdiff = hdgdiff - 2.0*M_PI;
  3482. if(hdgdiff <= (-M_PI))hdgdiff = hdgdiff + 2.0*M_PI;
  3483. double slen = R*tan(fabs(hdgdiff/2.0));
  3484. if(slen <(R+0.3))
  3485. {
  3486. R = slen - 0.3;
  3487. std::cout<<"Change Radius to "<<R<<std::endl;
  3488. slen = R*tan(fabs(hdgdiff/2.0));
  3489. }
  3490. if((dis1<slen)||(dis2<slen))
  3491. {
  3492. std::cout<<"radius is big. use line."<<std::endl;
  3493. char strinfo[256];
  3494. snprintf(strinfo,256,"Use Line Connect");
  3495. QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
  3496. return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
  3497. }
  3498. double p1_x,p1_y,p2_x,p2_y;
  3499. p1_x = inter_x+ slen * cos(starthdg +M_PI);
  3500. p1_y = inter_y+ slen * sin(starthdg +M_PI);
  3501. p2_x = inter_x+slen*cos(endhdg);
  3502. p2_y = inter_y+slen*sin(endhdg);
  3503. geobase linegeo;
  3504. linegeo.mnType = 0;
  3505. linegeo.mfX = startx;
  3506. linegeo.mfY = starty;
  3507. linegeo.mfHdg = starthdg;
  3508. linegeo.mfLen = sqrt(pow(p1_x - startx,2)+pow(p1_y - starty,2));
  3509. xvectorgeo.push_back(linegeo);
  3510. geobase arcgeo;
  3511. arcgeo.mnType = 1;
  3512. arcgeo.mfX = p1_x;
  3513. arcgeo.mfY = p1_y;
  3514. arcgeo.mfHdg = starthdg;
  3515. arcgeo.mfHdgStart = starthdg;
  3516. arcgeo.mfLen = R*fabs(hdgdiff);
  3517. arcgeo.mR = R*(fabs(hdgdiff)/hdgdiff);
  3518. arcgeo.mfEndX = p2_x;
  3519. arcgeo.mfEndY = p2_y;
  3520. xvectorgeo.push_back(arcgeo);
  3521. linegeo.mnType = 0;
  3522. linegeo.mfX = p2_x;
  3523. linegeo.mfY = p2_y;
  3524. linegeo.mfHdg = endhdg;
  3525. linegeo.mfLen = sqrt(pow(p2_x - endx,2)+pow(p2_y - endy,2));
  3526. xvectorgeo.push_back(linegeo);
  3527. return xvectorgeo;
  3528. }
  3529. std::string MainWindow::getlanetype(Road *p, int nlane, bool bstart)
  3530. {
  3531. Lane * plane = 0;
  3532. int i;
  3533. LaneSection * pLS;
  3534. if(bstart)
  3535. {
  3536. pLS = p->GetLaneSection(0);
  3537. }
  3538. else
  3539. {
  3540. pLS = p->GetLaneSection(p->GetLaneSectionCount() -1);
  3541. }
  3542. int nlanecount = pLS->GetLaneCount();
  3543. for(i=0;i<nlanecount;i++)
  3544. {
  3545. if(nlane == pLS->GetLane(i)->GetId())
  3546. {
  3547. plane = pLS->GetLane(i);
  3548. break;
  3549. }
  3550. }
  3551. if(plane == 0)
  3552. {
  3553. std::cout<<"MainWindow::getlanetype can't find lane : "<<nlane<<std::endl;
  3554. return "driving";
  3555. }
  3556. return plane->GetType();
  3557. }
  3558. double MainWindow::getlanewidth(Road * p, int nlane,bool bstart)
  3559. {
  3560. Lane * plane = 0;
  3561. double a,b,c,d;
  3562. double s;
  3563. if(bstart)
  3564. {
  3565. s = 0;
  3566. (void)s;
  3567. }
  3568. else
  3569. {
  3570. s = p->GetRoadLength();
  3571. (void)s;
  3572. }
  3573. int i;
  3574. LaneSection * pLS;
  3575. if(bstart)
  3576. {
  3577. pLS = p->GetLaneSection(0);
  3578. }
  3579. else
  3580. {
  3581. pLS = p->GetLaneSection(p->GetLaneSectionCount() -1);
  3582. }
  3583. int nlanecount = pLS->GetLaneCount();
  3584. for(i=0;i<nlanecount;i++)
  3585. {
  3586. if(nlane == pLS->GetLane(i)->GetId())
  3587. {
  3588. plane = pLS->GetLane(i);
  3589. break;
  3590. }
  3591. }
  3592. if(plane == 0)
  3593. {
  3594. std::cout<<"MainWindow::getlanewidth can't find lane : "<<nlane<<std::endl;
  3595. return 0;
  3596. }
  3597. if(bstart)
  3598. {
  3599. return plane->GetLaneWidth(0)->GetA();
  3600. }
  3601. else
  3602. {
  3603. s = p->GetRoadLength() - pLS->GetS();
  3604. LaneWidth * pLW = plane->GetLaneWidth(plane->GetLaneWidthCount()-1);
  3605. a = pLW->GetA();b = pLW->GetB();c = pLW->GetC();d = pLW->GetD();
  3606. return a+b*s+c*pow(s,2)+d*pow(s,3);
  3607. }
  3608. }
  3609. double MainWindow::getoff(Road *p, int nlane, bool bstart)
  3610. {
  3611. double off = 0;
  3612. int i;
  3613. if(bstart)
  3614. {
  3615. LaneSection * pLS = p->GetLaneSection(0);
  3616. if(nlane<0)
  3617. {
  3618. if(nlane == -1)return 0;
  3619. else
  3620. {
  3621. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  3622. {
  3623. Lane * pL = pLS->GetLane(i);
  3624. if((pL->GetId()<0)&&(pL->GetId()>nlane))
  3625. {
  3626. off = off + pL->GetLaneWidth(0)->GetA();
  3627. }
  3628. }
  3629. }
  3630. }
  3631. else
  3632. {
  3633. if(nlane == 1)return 0;
  3634. else
  3635. {
  3636. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  3637. {
  3638. Lane * pL = pLS->GetLane(i);
  3639. if((pL->GetId()>0)&&(pL->GetId()<nlane))
  3640. {
  3641. off = off - pL->GetLaneWidth(0)->GetA();
  3642. }
  3643. }
  3644. }
  3645. }
  3646. }
  3647. else
  3648. {
  3649. LaneSection * pLS = p->GetLaneSection(p->GetLaneSectionCount()-1);
  3650. if(nlane<0)
  3651. {
  3652. if(nlane == -1)return 0;
  3653. else
  3654. {
  3655. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  3656. {
  3657. Lane * pL = pLS->GetLane(i);
  3658. if((pL->GetId()<0)&&(pL->GetId()>nlane))
  3659. {
  3660. double a,b,c,d;
  3661. a = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetA();
  3662. b = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetB();
  3663. c = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetC();
  3664. d = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetD();
  3665. double s = p->GetRoadLength();
  3666. off = off + a + b*s +c *s*s + d*s*s*s;
  3667. }
  3668. }
  3669. }
  3670. }
  3671. else
  3672. {
  3673. if(nlane == 1)return 0;
  3674. else
  3675. {
  3676. for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
  3677. {
  3678. Lane * pL = pLS->GetLane(i);
  3679. if((pL->GetId()>0)&&(pL->GetId()<nlane))
  3680. {
  3681. double a,b,c,d;
  3682. a = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetA();
  3683. b = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetB();
  3684. c = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetC();
  3685. d = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetD();
  3686. double s = p->GetRoadLength();
  3687. off = off - a - b*s -c *s*s - d*s*s*s;
  3688. }
  3689. }
  3690. }
  3691. }
  3692. }
  3693. return off;
  3694. }
  3695. std::vector<geobase> MainWindow::CreateUTurnGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg, double fextend)
  3696. {
  3697. std::vector<geobase> xvectorgeo;
  3698. double p1_x,p1_y, p2_x,p2_y,p1_hdg,p2_hdg;
  3699. p1_x = fextend*cos(starthdg) + startx;
  3700. p1_y = fextend*sin(starthdg) + starty;
  3701. p2_x = fextend*cos(endhdg + M_PI) + endx;
  3702. p2_y = fextend*sin(endhdg + M_PI) + endy;
  3703. p1_hdg = starthdg;
  3704. p2_hdg = endhdg;
  3705. if(starthdg == endhdg)
  3706. {
  3707. std::cout<<" hdg is same, can't create u turn."<<std::endl;
  3708. return xvectorgeo;
  3709. }
  3710. double hdgse = geofit::CalcHdg(p1_x,p1_y,p2_x,p2_y);
  3711. double hdgdiff = hdgse - p1_hdg;
  3712. if(hdgdiff < 0)hdgdiff = hdgdiff + 2.0*M_PI;
  3713. bool bPA = true; //Positive
  3714. if(hdgdiff >=M_PI)bPA = false;
  3715. double xdiff;
  3716. if(bPA)xdiff = hdgdiff - M_PI/2.0;
  3717. else xdiff = hdgdiff - 3.0*M_PI/2.0;
  3718. double xdis = sqrt(pow(p1_x-p2_x,2)+pow(p1_y-p2_y,2));
  3719. double R = xdis/(2.0*cos(xdiff));
  3720. double x_center,y_center;
  3721. double xhdgtocenter;
  3722. if(bPA)
  3723. {
  3724. xhdgtocenter = p1_hdg + M_PI/2.0;
  3725. if(xhdgtocenter >= 2.0*M_PI)xhdgtocenter = xhdgtocenter - M_PI*2.0;
  3726. }
  3727. else
  3728. {
  3729. xhdgtocenter = p1_hdg - M_PI/2.0;
  3730. if(xhdgtocenter < 0)xhdgtocenter = xhdgtocenter + 2.0*M_PI;
  3731. }
  3732. x_center = p1_x + R*cos(xhdgtocenter);
  3733. y_center = p1_y + R*sin(xhdgtocenter);
  3734. double xhdgcentertoarc;
  3735. if(bPA)
  3736. {
  3737. xhdgcentertoarc = hdgse - M_PI/2.0;
  3738. if(xhdgcentertoarc <0)xhdgcentertoarc = xhdgcentertoarc + 2.0*M_PI;
  3739. }
  3740. else
  3741. {
  3742. xhdgcentertoarc = hdgse + M_PI/2.0;
  3743. if(xhdgcentertoarc >= M_PI*2.0)xhdgcentertoarc = xhdgcentertoarc - M_PI*2.0;
  3744. }
  3745. double p3_x,p3_y,p3_hdg;
  3746. (void)p3_hdg;
  3747. p3_hdg = hdgse;
  3748. (void)p3_hdg;
  3749. p3_x = x_center + R* cos(xhdgcentertoarc);
  3750. p3_y = y_center + R* sin(xhdgcentertoarc);
  3751. // pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
  3752. geobase c2,c3;
  3753. c2.mfX = p1_x;
  3754. c2.mfY = p1_y;
  3755. c2.mfHdgStart = p1_hdg;
  3756. c3.mfX = p3_x;
  3757. c3.mfY = p3_y;
  3758. c3.mfHdgStart = hdgse;
  3759. c2.mnType = 1;
  3760. c3.mnType = 1;
  3761. if(bPA)
  3762. {
  3763. c2.mfLen = hdgdiff * R;
  3764. c2.mR = R;
  3765. c3.mfLen = c2.mfLen;
  3766. c3.mR = R;
  3767. }
  3768. else
  3769. {
  3770. c2.mfLen = (2.0*M_PI - hdgdiff) * R;
  3771. c2.mR = R*(-1);
  3772. c3.mfLen = c2.mfLen;
  3773. c3.mR = R*(-1);
  3774. }
  3775. geobase l1,l2;
  3776. if(fextend != 0)
  3777. {
  3778. l1.mfX = startx;
  3779. l1.mfY = starty;
  3780. l1.mfHdg = starthdg;
  3781. l1.mfLen = fextend;
  3782. l1.mnType = 0;
  3783. l2.mfX = p2_x;
  3784. l2.mfY = p2_y;
  3785. l2.mfHdg = p2_hdg;
  3786. l2.mfLen = fextend;
  3787. l2.mnType = 0;
  3788. xvectorgeo.push_back(l1);
  3789. }
  3790. xvectorgeo.push_back(c2);
  3791. xvectorgeo.push_back(c3);
  3792. if(fextend != 0)xvectorgeo.push_back(l2);
  3793. return xvectorgeo;
  3794. }
  3795. void MainWindow::ChangeXODRRoadID(OpenDrive *pxodr, int index, int newid)
  3796. {
  3797. Road * proad;
  3798. int nsize = pxodr->GetRoadCount();
  3799. int i;
  3800. if(index<0)return;
  3801. if(index>=nsize)return;
  3802. proad = pxodr->GetRoad(index);
  3803. int noldid = atoi(proad->GetRoadId().data());
  3804. char strid[255];
  3805. snprintf(strid,255,"%d",newid);
  3806. proad->SetRoadId(strid);
  3807. for(i=0;i<nsize;i++)
  3808. {
  3809. Road * proad2 = pxodr->GetRoad(i);
  3810. if(proad2->GetPredecessor()!= 0)
  3811. {
  3812. RoadLink * plink = proad2->GetPredecessor();
  3813. if(strncmp(plink->GetElementType().data(),"road",255)== 0)
  3814. {
  3815. if(atoi(plink->GetElementId().data()) == noldid)
  3816. {
  3817. plink->SetElementId(strid);
  3818. }
  3819. }
  3820. }
  3821. if(proad2->GetSuccessor()!= 0)
  3822. {
  3823. RoadLink * plink = proad2->GetSuccessor();
  3824. if(strncmp(plink->GetElementType().data(),"road",255)== 0)
  3825. {
  3826. if(atoi(plink->GetElementId().data()) == noldid)
  3827. {
  3828. plink->SetElementId(strid);
  3829. }
  3830. }
  3831. }
  3832. }
  3833. nsize = pxodr->GetJunctionCount();
  3834. for(i=0;i<nsize;i++)
  3835. {
  3836. Junction * pjunction = pxodr->GetJunction(i);
  3837. int j;
  3838. for(j=0;j<static_cast<int>(pjunction->GetJunctionConnectionCount());j++)
  3839. {
  3840. JunctionConnection * pjc = pjunction->GetJunctionConnection(j);
  3841. if(atoi(pjc->GetIncomingRoad().data()) == noldid)
  3842. {
  3843. pjc->SetIncomingRoad(strid);
  3844. }
  3845. if(atoi(pjc->GetConnectingRoad().data()) == noldid)
  3846. {
  3847. pjc->SetConnectingRoad(strid);
  3848. }
  3849. }
  3850. }
  3851. }
  3852. void MainWindow::ChangeXODRJunctionID(OpenDrive *pxodr, int index, int newid)
  3853. {
  3854. Junction * pjunction;
  3855. int nsize = pxodr->GetJunctionCount();
  3856. int i;
  3857. if(index<0)return;
  3858. if(index>=nsize)return;
  3859. pjunction = pxodr->GetJunction(index);
  3860. int noldid = atoi(pjunction->GetId().data());
  3861. char strid[255];
  3862. snprintf(strid,255,"%d",newid);
  3863. pjunction->SetId(strid);
  3864. for(i=0;i<(int)(pxodr->GetRoadCount());i++)
  3865. {
  3866. Road * proad2 = pxodr->GetRoad(i);
  3867. if(proad2 == NULL)
  3868. {
  3869. qDebug("Road %d is NULL size is %d",i,nsize);
  3870. continue;
  3871. }
  3872. if(proad2->GetPredecessor()!= 0)
  3873. {
  3874. RoadLink * plink = proad2->GetPredecessor();
  3875. if(strncmp(plink->GetElementType().data(),"junction",255)== 0)
  3876. {
  3877. if(atoi(plink->GetElementId().data()) == noldid)
  3878. {
  3879. plink->SetElementId(strid);
  3880. }
  3881. }
  3882. }
  3883. if(proad2->GetSuccessor()!= 0)
  3884. {
  3885. RoadLink * plink = proad2->GetSuccessor();
  3886. if(strncmp(plink->GetElementType().data(),"junction",255)== 0)
  3887. {
  3888. if(atoi(plink->GetElementId().data()) == noldid)
  3889. {
  3890. plink->SetElementId(strid);
  3891. }
  3892. }
  3893. }
  3894. }
  3895. }
  3896. void MainWindow::MoveXODR(OpenDrive *pxodr, double movex, double movey)
  3897. {
  3898. int nsize = pxodr->GetRoadCount();
  3899. int i;
  3900. for(i=0;i<nsize;i++)
  3901. {
  3902. Road * pRoad = pxodr->GetRoad(i);
  3903. int nblockcount = pRoad->GetGeometryBlockCount();
  3904. int j;
  3905. for(j=0;j<nblockcount;j++)
  3906. {
  3907. GeometryBlock * pgb = pRoad->GetGeometryBlock(j);
  3908. if(pgb != 0)
  3909. {
  3910. pgb->GetGeometryAt(0)->SetX(pgb->GetGeometryAt(0)->GetX() + movex);
  3911. pgb->GetGeometryAt(0)->SetY(pgb->GetGeometryAt(0)->GetY() + movey);
  3912. }
  3913. }
  3914. }
  3915. }
  3916. int MainWindow::FindNewRoadID(OpenDrive *pxodr1, OpenDrive *pxodr2)
  3917. {
  3918. int nroadsize1,nroadsize2;
  3919. nroadsize1 = pxodr1->GetRoadCount();
  3920. nroadsize2 = pxodr2->GetRoadCount();
  3921. int i;
  3922. int * pnid = new int[nroadsize1 + nroadsize2];
  3923. std::shared_ptr<int> ppnid;ppnid.reset(pnid);
  3924. for(i=0;i<nroadsize1;i++)
  3925. {
  3926. pnid[i] = atoi(pxodr1->GetRoad(i)->GetRoadId().data());
  3927. }
  3928. for(i=0;i<nroadsize2;i++)
  3929. {
  3930. pnid[i+nroadsize1] = atoi(pxodr2->GetRoad(i)->GetRoadId().data());
  3931. }
  3932. int nstartid = 40000;
  3933. bool bUsed = true;
  3934. while(bUsed == true)
  3935. {
  3936. bUsed = false;
  3937. for(i=0;i<(nroadsize1 + nroadsize2);i++)
  3938. {
  3939. if(pnid[i] == nstartid)
  3940. {
  3941. bUsed = true;
  3942. break;
  3943. }
  3944. }
  3945. if(bUsed == false)break;
  3946. nstartid++;
  3947. }
  3948. return nstartid;
  3949. }
  3950. int MainWindow::FindNewJunctionID(OpenDrive *pxodr1, OpenDrive *pxodr2)
  3951. {
  3952. int njunctionsize1,njunctionsize2;
  3953. njunctionsize1 = pxodr1->GetJunctionCount();
  3954. njunctionsize2 = pxodr2->GetJunctionCount();
  3955. int i;
  3956. int * pnid = new int[njunctionsize1 + njunctionsize2];
  3957. std::shared_ptr<int> ppnid;ppnid.reset(pnid);
  3958. for(i=0;i<njunctionsize1;i++)
  3959. {
  3960. pnid[i] = atoi(pxodr1->GetJunction(i)->GetId().data());
  3961. }
  3962. for(i=0;i<njunctionsize2;i++)
  3963. {
  3964. pnid[i+njunctionsize1] = atoi(pxodr2->GetJunction(i)->GetId().data());
  3965. }
  3966. int nstartid = 50000;
  3967. bool bUsed = true;
  3968. while(bUsed == true)
  3969. {
  3970. bUsed = false;
  3971. for(i=0;i<(njunctionsize1 + njunctionsize2);i++)
  3972. {
  3973. if(pnid[i] == nstartid)
  3974. {
  3975. bUsed = true;
  3976. break;
  3977. }
  3978. }
  3979. if(bUsed == false)break;
  3980. nstartid++;
  3981. }
  3982. return nstartid;
  3983. }
  3984. void MainWindow::onClickRoadMark()
  3985. {
  3986. mbRefresh = true;
  3987. update();
  3988. }
  3989. void MainWindow::onClickRoadDel()
  3990. {
  3991. if(mpCBRoad->count() == 0)
  3992. {
  3993. QMessageBox::warning(this,"warn","no road to be delete");
  3994. return;
  3995. }
  3996. int nroadid = mpCBRoad->currentText().toInt();
  3997. QMessageBox::StandardButton button;
  3998. button=QMessageBox::question(this,tr("Delete Road"),QString(tr("Delete Road?")),QMessageBox::Yes|QMessageBox::No);
  3999. if(button==QMessageBox::No)
  4000. {
  4001. return;
  4002. }
  4003. else if(button==QMessageBox::Yes)
  4004. {
  4005. }
  4006. Road * pRoad = 0;
  4007. int nroadsize = mxodr.GetRoadCount();
  4008. int i;
  4009. int index;
  4010. for(i=0;i<nroadsize;i++)
  4011. {
  4012. if(nroadid == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
  4013. {
  4014. pRoad = mxodr.GetRoad(i);
  4015. index = i;
  4016. break;
  4017. }
  4018. }
  4019. if(pRoad == 0)
  4020. {
  4021. QMessageBox::warning(this,tr("Warn"),tr("can't find road"));
  4022. return;
  4023. }
  4024. SaveBack();
  4025. mxodr.DeleteRoad(index);
  4026. nroadsize = mxodr.GetRoadCount();
  4027. for(i=0;i<nroadsize;i++)
  4028. {
  4029. pRoad = mxodr.GetRoad(i);
  4030. RoadLink * ppre,* pnext;
  4031. ppre = pRoad->GetPredecessor();
  4032. pnext = pRoad->GetSuccessor();
  4033. if(ppre != 0)
  4034. {
  4035. if(strncmp(ppre->GetElementType().data(),"road",255) == 0)
  4036. {
  4037. if(atoi(ppre->GetElementId().data()) == nroadid)
  4038. {
  4039. pRoad->RemovePredecessor();
  4040. LaneSection * pLS = pRoad->GetLaneSection(0);
  4041. int nlanecount = pLS->GetLaneCount();
  4042. int j;
  4043. for(j=0;j<nlanecount;j++)
  4044. {
  4045. Lane * pLane;
  4046. pLane = pLS->GetLane(j);
  4047. pLane->RemovePredecessor();
  4048. }
  4049. }
  4050. }
  4051. }
  4052. if(pnext != 0)
  4053. {
  4054. if(strncmp(pnext->GetElementType().data(),"road",255) == 0)
  4055. {
  4056. if(atoi(pnext->GetElementId().data()) == nroadid)
  4057. {
  4058. pRoad->RemoveSuccessor();
  4059. LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4060. int nlanecount = pLS->GetLaneCount();
  4061. int j;
  4062. for(j=0;j<nlanecount;j++)
  4063. {
  4064. Lane * pLane;
  4065. pLane = pLS->GetLane(j);
  4066. pLane->RemoveSuccessor();
  4067. }
  4068. }
  4069. }
  4070. }
  4071. }
  4072. //remove juction connection where id = roadid
  4073. int njunctioncount = mxodr.GetJunctionCount();
  4074. Junction * pjunction;
  4075. for(i=0;i<njunctioncount;i++)
  4076. {
  4077. pjunction = mxodr.GetJunction(i);
  4078. int j;
  4079. for(j=0;j<static_cast<int>(pjunction->GetJunctionConnectionCount());j++)
  4080. {
  4081. JunctionConnection * pjc = pjunction->GetJunctionConnection(j);
  4082. int nfromid = atoi(pjc->GetIncomingRoad().data());
  4083. int ntoid = atoi(pjc->GetConnectingRoad().data());
  4084. if((nfromid == nroadid)||(ntoid == nroadid))
  4085. {
  4086. pjunction->DeleteJunctionConnection(j);
  4087. j--;
  4088. }
  4089. }
  4090. }
  4091. updateCBRoad();
  4092. mbRefresh = true;
  4093. update();
  4094. if(mpCBViewMode->currentIndex() == 1)
  4095. {
  4096. UpdateScene();
  4097. }
  4098. mpfb->SetOpenDrive(mxodr);
  4099. }
  4100. void MainWindow::updateCBRoad()
  4101. {
  4102. mpCBRoad->clear();
  4103. mpCBRoad1->clear();
  4104. mpCBRoad2->clear();
  4105. mpCBJunctionIncommingRoad->clear();
  4106. mpCBJunctionConnectingRoad->clear();
  4107. mpCBPreNxtRoad->clear();
  4108. int i;
  4109. int nroadcount = mxodr.GetRoadCount();
  4110. for(i=0;i<nroadcount;i++)
  4111. {
  4112. const char * strname1 = mxodr.GetRoad(i)->GetRoadId().data();
  4113. QString strname(strname1);
  4114. mpCBRoad->addItem(strname);
  4115. mpCBRoad1->addItem(strname);
  4116. mpCBRoad2->addItem(strname);
  4117. mpCBJunctionIncommingRoad->addItem(strname);
  4118. mpCBJunctionConnectingRoad->addItem(strname);
  4119. mpCBPreNxtRoad->addItem(strname);
  4120. }
  4121. }
  4122. void MainWindow::onClickCBRoadChange(int index)
  4123. {
  4124. Road * pRoad = mxodr.GetRoad(index);
  4125. if(pRoad == 0)
  4126. {
  4127. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  4128. return;
  4129. }
  4130. int i;
  4131. mpLabelRoadShowPreID->setText("");
  4132. mpLabelRoadShowPreType2->setText("");
  4133. mpLabelRoadShowPreType1->setText("");
  4134. mpCBRoadShowPre->clear();
  4135. mpLabelRoadShowNxtID->setText("");
  4136. mpLabelRoadShowNxtType2->setText("");
  4137. mpLabelRoadShowNxtType1->setText("");
  4138. mpCBRoadShowNext->clear();
  4139. if(pRoad->GetPredecessor() != 0)
  4140. {
  4141. RoadLink * pRL = pRoad->GetPredecessor();
  4142. mpLabelRoadShowPreID->setText(pRL->GetElementId().data());
  4143. mpLabelRoadShowPreType2->setText(pRL->GetContactPoint().data());
  4144. mpLabelRoadShowPreType1->setText(pRL->GetElementType().data());
  4145. }
  4146. if(pRoad->GetSuccessor() != 0)
  4147. {
  4148. RoadLink * pRL = pRoad->GetSuccessor();
  4149. mpLabelRoadShowNxtID->setText(pRL->GetElementId().data());
  4150. mpLabelRoadShowNxtType2->setText(pRL->GetContactPoint().data());
  4151. mpLabelRoadShowNxtType1->setText(pRL->GetElementType().data());
  4152. }
  4153. LaneSection * pLS = pRoad->GetLaneSection(0);
  4154. if(pLS == 0)
  4155. {
  4156. return;
  4157. }
  4158. int nlanecount = pLS->GetLaneCount();
  4159. for(i=0;i<nlanecount;i++)
  4160. {
  4161. char strout[256];
  4162. char strtem[255];
  4163. Lane * pLane = pLS->GetLane(i);
  4164. snprintf(strout,255,"%d type:%s",pLane->GetId(),pLane->GetType().data());
  4165. if(pLane->IsPredecessorSet())
  4166. {
  4167. snprintf(strtem,255," pre:%d",pLane->GetPredecessor());
  4168. strncat(strout,strtem,255);
  4169. }
  4170. mpCBRoadShowPre->addItem(strout);
  4171. }
  4172. pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4173. nlanecount = pLS->GetLaneCount();
  4174. for(i=0;i<nlanecount;i++)
  4175. {
  4176. char strout[256];
  4177. char strtem[255];
  4178. Lane * pLane = pLS->GetLane(i);
  4179. snprintf(strout,255,"%d type:%s",pLane->GetId(),pLane->GetType().data());
  4180. if(pLane->IsSuccessorSet())
  4181. {
  4182. snprintf(strtem,255," suc:%d",pLane->GetSuccessor());
  4183. strncat(strout,strtem,255);
  4184. }
  4185. mpCBRoadShowNext->addItem(strout);
  4186. }
  4187. if(mpCBRoad->currentText().length()>0)
  4188. {
  4189. int nCurRoadID = mpCBRoad->currentText().toInt();
  4190. emit CurrentRoadChange(nCurRoadID);
  4191. }
  4192. }
  4193. void MainWindow::updateJunction()
  4194. {
  4195. int i;
  4196. int njunctioncount = mxodr.GetJunctionCount();
  4197. mpCBJunction->clear();
  4198. for(i=0;i<njunctioncount;i++)
  4199. {
  4200. Junction * pjunction = mxodr.GetJunction(i);
  4201. mpCBJunction->addItem(pjunction->GetId().data());
  4202. }
  4203. }
  4204. void MainWindow::onClickCBJunctionChange(int index)
  4205. {
  4206. mpCBJunctionConnection->clear();
  4207. Junction * pjunction = mxodr.GetJunction(index);
  4208. if(pjunction == NULL)
  4209. {
  4210. // QMessageBox::warning(this,"warn","MainWindow::onClickCBJunctionChange can't find junction");
  4211. return;
  4212. }
  4213. int nconnectioncount = pjunction->GetJunctionConnectionCount();
  4214. int i;
  4215. for(i=0;i<nconnectioncount;i++)
  4216. {
  4217. JunctionConnection * pJC = pjunction->GetJunctionConnection(i);
  4218. mpCBJunctionConnection->addItem(pJC->GetId().data());
  4219. }
  4220. mpCBJunctionFromTo->clear();
  4221. mpLabelJunctionConnectingRoad->setText("");
  4222. mpLabelJunctionContactPoint->setText("");
  4223. mpLabelJunctionIncommingRoad->setText("");
  4224. if(pjunction->GetJunctionConnectionCount()>0)
  4225. {
  4226. mpCBJunctionConnection->setCurrentIndex(0);
  4227. onClickCBJunctionConnectionChange(0);
  4228. }
  4229. }
  4230. void MainWindow::onClickCBJunctionConnectionChange(int index)
  4231. {
  4232. // mpCBJunctionIncommingRoad->clear();
  4233. // mpCBJunctionConnectingRoad->clear();
  4234. // mpCBJunctionFromLane->clear();
  4235. // mpCBJunctionToLane->clear();
  4236. Junction * pjunction = mxodr.GetJunction(mpCBJunction->currentIndex());
  4237. if(pjunction == NULL)
  4238. {
  4239. std::cout<<"MainWindow::onClickCBJunctionConnectionChange Junction NULL"<<std::endl;
  4240. return;
  4241. }
  4242. if((index<0)||(index>= static_cast<int>(pjunction->GetJunctionConnectionCount())))
  4243. {
  4244. // std::cout<<"MainWindow::onClickCBJunctionConnectionChange out range."<<std::endl;
  4245. return;
  4246. }
  4247. JunctionConnection * pJC = pjunction->GetJunctionConnection(index);
  4248. if(pJC == NULL)
  4249. {
  4250. std::cout<<"MainWindow::onClickCBJunctionConnectionChange Junction Connection NULL"<<std::endl;
  4251. return;
  4252. }
  4253. mpLabelJunctionIncommingRoad->setText(pJC->GetIncomingRoad().data());
  4254. mpLabelJunctionContactPoint->setText(pJC->GetContactPoint().data());
  4255. mpLabelJunctionConnectingRoad->setText(pJC->GetConnectingRoad().data());
  4256. unsigned int i;
  4257. unsigned int njunctionlanelinkcount = pJC->GetJunctionLaneLinkCount();
  4258. mpCBJunctionFromTo->clear();
  4259. for(i=0;i<njunctionlanelinkcount;i++)
  4260. {
  4261. char strout[255];
  4262. JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(i);
  4263. snprintf(strout,255,"%d to %d",pjll->GetFrom(),pjll->GetTo());
  4264. mpCBJunctionFromTo->addItem(strout);
  4265. }
  4266. }
  4267. void MainWindow::onClickCBJunctionIncommingChange(int index)
  4268. {
  4269. int i;
  4270. int ncount = mxodr.GetRoadCount();
  4271. if((index < 0)||(index>=ncount))
  4272. {
  4273. return;
  4274. }
  4275. Road * pRoad = mxodr.GetRoad(index);
  4276. if(pRoad == NULL)
  4277. {
  4278. return;
  4279. }
  4280. LaneSection * pLS;
  4281. if(mpCBJunctionContactPoint->currentIndex() == 0)
  4282. {
  4283. pLS = pRoad->GetLaneSection(0);
  4284. }
  4285. else
  4286. {
  4287. pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4288. }
  4289. if(pLS == 0)
  4290. {
  4291. return;
  4292. }
  4293. int nlanecount = pLS->GetLaneCount();
  4294. mpCBJunctionFromLane->clear();
  4295. for(i=0;i<nlanecount;i++)
  4296. {
  4297. Lane * pLane = pLS->GetLane(i);
  4298. if(pLane->GetId() != 0)
  4299. {
  4300. mpCBJunctionFromLane->addItem(QString::number(pLane->GetId()));
  4301. }
  4302. }
  4303. }
  4304. void MainWindow::onClickCBJunctionConnectionroadChange(int index)
  4305. {
  4306. int i;
  4307. int ncount = mxodr.GetRoadCount();
  4308. if((index < 0)||(index>=ncount))
  4309. {
  4310. return;
  4311. }
  4312. Road * pRoad = mxodr.GetRoad(index);
  4313. if(pRoad == NULL)
  4314. {
  4315. return;
  4316. }
  4317. LaneSection * pLS;
  4318. pLS = pRoad->GetLaneSection(0);
  4319. if(pLS == 0)
  4320. {
  4321. return;
  4322. }
  4323. int nlanecount = pLS->GetLaneCount();
  4324. mpCBJunctionToLane->clear();
  4325. for(i=0;i<nlanecount;i++)
  4326. {
  4327. Lane * pLane = pLS->GetLane(i);
  4328. if(pLane->GetId() != 0)
  4329. {
  4330. mpCBJunctionToLane->addItem(QString::number(pLane->GetId()));
  4331. }
  4332. }
  4333. }
  4334. void MainWindow::onClickCreateJunction()
  4335. {
  4336. mxodr.AddJunction("",QString::number(CreateJunctionID()).toStdString());
  4337. updateJunction();
  4338. }
  4339. void MainWindow::onClickCreateJunctionLaneLink()
  4340. {
  4341. Junction * pJunction= mxodr.GetJunction(mpCBJunction->currentIndex());
  4342. if(pJunction == NULL)
  4343. {
  4344. QMessageBox::warning(this,tr("Warn"),tr("can't find junction"));
  4345. return ;
  4346. }
  4347. Road * pFromRoad = mxodr.GetRoad(mpCBJunctionIncommingRoad->currentIndex());
  4348. if(pFromRoad == NULL)
  4349. {
  4350. QMessageBox::warning(this,tr("Warn"),tr("can't find incomming road."));
  4351. return;
  4352. }
  4353. Road * pToRoad = mxodr.GetRoad(mpCBJunctionConnectingRoad->currentIndex());
  4354. if(pToRoad == NULL)
  4355. {
  4356. QMessageBox::warning(this,tr("Warn"),tr("can't find connecting road."));
  4357. return;
  4358. }
  4359. string contacpoint = mpCBJunctionContactPoint->currentText().toStdString();
  4360. JunctionConnection * pJC = 0;
  4361. int njunctioncount = pJunction->GetJunctionConnectionCount();
  4362. int i;
  4363. for(i=0;i<njunctioncount;i++)
  4364. {
  4365. JunctionConnection * pJunCon = pJunction->GetJunctionConnection(i);
  4366. if((pJunCon->GetIncomingRoad() == pFromRoad->GetRoadId())&&(pJunCon->GetContactPoint() == contacpoint)&&(pJunCon->GetConnectingRoad() == pToRoad->GetRoadId()))
  4367. {
  4368. pJC = pJunCon;
  4369. break;
  4370. }
  4371. }
  4372. bool bNewJC = false;
  4373. if(pJC == 0)
  4374. {
  4375. int nnewJCid = pJunction->GetJunctionConnectionCount();
  4376. int j;
  4377. int njccount = pJunction->GetJunctionConnectionCount();
  4378. bool bNotUse = true;
  4379. do
  4380. {
  4381. for(j=0;j<njccount;j++)
  4382. {
  4383. if(nnewJCid == atoi(pJunction->GetJunctionConnection(j)->GetId().data()))
  4384. {
  4385. bNotUse = false;
  4386. nnewJCid++;
  4387. break;
  4388. }
  4389. }
  4390. }while(bNotUse == false);
  4391. unsigned int addindex = pJunction->AddJunctionConnection(QString::number(nnewJCid).toStdString(),
  4392. pFromRoad->GetRoadId(),
  4393. pToRoad->GetRoadId(),
  4394. contacpoint);
  4395. pJC = pJunction->GetJunctionConnection(addindex);
  4396. bNewJC = true;
  4397. }
  4398. int nfrom = mpCBJunctionFromLane->currentText().toInt();
  4399. int nto = mpCBJunctionToLane->currentText().toInt();
  4400. int njlcount = pJC->GetJunctionLaneLinkCount();
  4401. for(i=0;i<njlcount;i++)
  4402. {
  4403. JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(i);
  4404. if((pjll->GetFrom()== nfrom)&&(pjll->GetTo() == nto))
  4405. {
  4406. QMessageBox::warning(this,tr("Warn"),tr("this lane link exist."));
  4407. return;
  4408. }
  4409. }
  4410. unsigned int nadd = pJC->AddJunctionLaneLink(mpCBJunctionFromLane->currentText().toInt(),
  4411. mpCBJunctionToLane->currentText().toInt());
  4412. char strout[255];
  4413. JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(nadd);
  4414. snprintf(strout,255,"%d to %d",pjll->GetFrom(),pjll->GetTo());
  4415. if(bNewJC)
  4416. {
  4417. mpCBJunctionConnection->addItem(pJC->GetId().data());
  4418. }
  4419. if(strncmp(contacpoint.data(),"start",255) == 0)
  4420. {
  4421. if(nfrom*nto<0)
  4422. {
  4423. pFromRoad->SetPredecessor("junction",pJunction->GetId(),contacpoint);
  4424. }
  4425. else
  4426. {
  4427. pFromRoad->SetSuccessor("junction",pJunction->GetId(),contacpoint);
  4428. }
  4429. }
  4430. else
  4431. {
  4432. if(nfrom*nto <0)
  4433. {
  4434. pFromRoad->SetSuccessor("junction",pJunction->GetId(),contacpoint);
  4435. }
  4436. else
  4437. {
  4438. pFromRoad->SetPredecessor("junction",pJunction->GetId(),contacpoint);
  4439. }
  4440. }
  4441. pToRoad->SetRoadJunction(pJunction->GetId());
  4442. }
  4443. void MainWindow::onClickDeleteJunctionLaneLink()
  4444. {
  4445. Junction * pJunction= mxodr.GetJunction(mpCBJunction->currentIndex());
  4446. if(pJunction == NULL)
  4447. {
  4448. QMessageBox::warning(this,tr("Warn"),tr("can't find junction"));
  4449. return ;
  4450. }
  4451. if(pJunction->GetJunctionConnectionCount() == 0)
  4452. {
  4453. mxodr.DeleteJunction(mpCBJunction->currentIndex());
  4454. updateJunction();
  4455. return;
  4456. }
  4457. JunctionConnection * pJC = pJunction->GetJunctionConnection(mpCBJunctionConnection->currentIndex());
  4458. if(pJC == NULL)
  4459. {
  4460. QMessageBox::warning(this,tr("Warn"),tr("can't find junction connetion."));
  4461. return;
  4462. }
  4463. if(pJC->GetJunctionLaneLinkCount() == 0)
  4464. {
  4465. pJunction->DeleteJunctionConnection(mpCBJunctionConnection->currentIndex());
  4466. if(pJunction->GetJunctionConnectionCount() > 0)
  4467. onClickCBJunctionChange(mpCBJunction->currentIndex());
  4468. else
  4469. {
  4470. mxodr.DeleteJunction(mpCBJunction->currentIndex());
  4471. updateJunction();
  4472. }
  4473. return;
  4474. }
  4475. // std::string strincommingroad = mpLabelJunctionIncommingRoad->text().toStdString();
  4476. // std::string strconnectionroad = mpLabelJunctionConnectingRoad->text().toStdString();
  4477. // std::string strcontact = mpLabelJunctionContactPoint->text().toStdString();
  4478. int nllindex = mpCBJunctionFromTo->currentIndex();
  4479. pJC->DeleteJunctionLaneLink(nllindex);
  4480. onClickCBJunctionConnectionChange(mpCBJunctionConnection->currentIndex());
  4481. }
  4482. void MainWindow::onClickPreNxtRoadChange(int index)
  4483. {
  4484. mpCBPreNxtRelLane->clear();
  4485. Road * pRoad = mxodr.GetRoad(index);
  4486. if(pRoad == NULL)
  4487. {
  4488. return;
  4489. }
  4490. LaneSection * pLS;
  4491. if(strncmp(mpCBPreNxtConatact->currentText().toStdString().data(),"start",255)==0)
  4492. {
  4493. pLS = pRoad->GetLaneSection(0);
  4494. }
  4495. else
  4496. {
  4497. pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4498. }
  4499. if(pLS == NULL)
  4500. {
  4501. std::cout<<"MainWindow::onClickPreNxtRoadChange can't find lanesection"<<std::endl;
  4502. return;
  4503. }
  4504. int nlanecount = pLS->GetLaneCount();
  4505. int i;
  4506. for(i=0;i<nlanecount;i++)
  4507. {
  4508. Lane * pLane = pLS->GetLane(i);
  4509. char strout[255];
  4510. snprintf(strout,255,"%d %s",pLane->GetId(),pLane->GetType().data());
  4511. mpCBPreNxtRelLane->addItem(strout);
  4512. }
  4513. }
  4514. void MainWindow::onClickSetRoadPredecessor()
  4515. {
  4516. Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
  4517. if(pRoad == NULL)
  4518. {
  4519. return;
  4520. }
  4521. Road * pOtherRoad = mxodr.GetRoad(mpCBPreNxtRoad->currentIndex());
  4522. if(pOtherRoad == NULL)
  4523. {
  4524. return;
  4525. }
  4526. std::string strcontact = mpCBPreNxtConatact->currentText().toStdString();
  4527. int curlane = mpCBRoadShowPre->currentIndex();
  4528. int otherlane = mpCBPreNxtRelLane->currentIndex();
  4529. pRoad->SetPredecessor("road",pOtherRoad->GetRoadId(),strcontact);
  4530. LaneSection * pLS = pRoad->GetLaneSection(0);
  4531. Lane * pLane =pLS->GetLane(curlane);
  4532. LaneSection * pLSOther;
  4533. if(strncmp(strcontact.data(),"start",0) == 0)
  4534. {
  4535. pLSOther = pOtherRoad->GetLaneSection(0);
  4536. }
  4537. else
  4538. {
  4539. pLSOther = pOtherRoad->GetLaneSection(pOtherRoad->GetLaneSectionCount()-1);
  4540. }
  4541. Lane * pLaneOther = pLSOther->GetLane(otherlane);
  4542. if(pLaneOther == NULL)
  4543. {
  4544. QMessageBox::warning(this,tr("Warn"),tr("no this lane."));
  4545. return;
  4546. }
  4547. pLane->SetPredecessor(pLaneOther->GetId());
  4548. onClickCBRoadChange(mpCBRoad->currentIndex());
  4549. }
  4550. void MainWindow::onClickSetRoadSuccessor()
  4551. {
  4552. Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
  4553. if(pRoad == NULL)
  4554. {
  4555. return;
  4556. }
  4557. Road * pOtherRoad = mxodr.GetRoad(mpCBPreNxtRoad->currentIndex());
  4558. if(pOtherRoad == NULL)
  4559. {
  4560. return;
  4561. }
  4562. std::string strcontact = mpCBPreNxtConatact->currentText().toStdString();
  4563. int curlane = mpCBRoadShowNext->currentIndex();
  4564. int otherlane = mpCBPreNxtRelLane->currentIndex();
  4565. pRoad->SetSuccessor("road",pOtherRoad->GetRoadId(),strcontact);
  4566. LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4567. Lane * pLane =pLS->GetLane(curlane);
  4568. LaneSection * pLSOther;
  4569. if(strncmp(strcontact.data(),"start",0) == 0)
  4570. {
  4571. pLSOther = pOtherRoad->GetLaneSection(0);
  4572. }
  4573. else
  4574. {
  4575. pLSOther = pOtherRoad->GetLaneSection(pOtherRoad->GetLaneSectionCount()-1);
  4576. }
  4577. Lane * pLaneOther = pLSOther->GetLane(otherlane);
  4578. if(pLaneOther == NULL)
  4579. {
  4580. QMessageBox::warning(this,tr("Warn"),tr("no this lane."));
  4581. return;
  4582. }
  4583. pLane->SetSuccessor(pLaneOther->GetId());
  4584. onClickCBRoadChange(mpCBRoad->currentIndex());
  4585. }
  4586. void MainWindow::onClickDelRoadPredecessor()
  4587. {
  4588. Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
  4589. if(pRoad == NULL)
  4590. {
  4591. return;
  4592. }
  4593. int curlane = mpCBRoadShowPre->currentIndex();
  4594. LaneSection * pLS = pRoad->GetLaneSection(0);
  4595. Lane * pLane =pLS->GetLane(curlane);
  4596. if(pLane == 0)
  4597. {
  4598. return;
  4599. }
  4600. pLane->RemovePredecessor();
  4601. int i;
  4602. int nlanecount = pLS->GetLaneCount();
  4603. bool bAllNotHavePre = true;
  4604. for(i=0;i<nlanecount;i++)
  4605. {
  4606. Lane * pLa= pLS->GetLane(i);
  4607. if(pLa->IsPredecessorSet())
  4608. {
  4609. bAllNotHavePre = false;
  4610. break;
  4611. }
  4612. }
  4613. if(bAllNotHavePre)
  4614. {
  4615. pRoad->RemovePredecessor();
  4616. }
  4617. onClickCBRoadChange(mpCBRoad->currentIndex());
  4618. }
  4619. void MainWindow::onClickDelRoadSuccessor()
  4620. {
  4621. Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
  4622. if(pRoad == NULL)
  4623. {
  4624. return;
  4625. }
  4626. int curlane = mpCBRoadShowNext->currentIndex();
  4627. LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
  4628. Lane * pLane =pLS->GetLane(curlane);
  4629. if(pLane == 0)
  4630. {
  4631. return;
  4632. }
  4633. pLane->RemoveSuccessor();
  4634. int i;
  4635. int nlanecount = pLS->GetLaneCount();
  4636. bool bAllNotHaveNxt = true;
  4637. for(i=0;i<nlanecount;i++)
  4638. {
  4639. Lane * pLa= pLS->GetLane(i);
  4640. if(pLa->IsSuccessorSet())
  4641. {
  4642. bAllNotHaveNxt = false;
  4643. break;
  4644. }
  4645. }
  4646. if(bAllNotHaveNxt)
  4647. {
  4648. pRoad->RemoveSuccessor();
  4649. }
  4650. onClickCBRoadChange(mpCBRoad->currentIndex());
  4651. }
  4652. void MainWindow::onClickAutoConnect()
  4653. {
  4654. if(mxodr.GetRoadCount() <= 0)
  4655. {
  4656. QMessageBox::warning(this,tr("Warning"),tr("OpenDrive Road Count is 0."),QMessageBox::YesAll);
  4657. return;
  4658. }
  4659. AutoConnect pAC(&mxodr);
  4660. pAC.Connect();
  4661. updateJunction();
  4662. }
  4663. void MainWindow::on_actionLoad_triggered()
  4664. {
  4665. onClickLoad();
  4666. }
  4667. void MainWindow::on_actionSave_triggered()
  4668. {
  4669. onClickSave();
  4670. }
  4671. void MainWindow::on_actionAutoConnect_triggered()
  4672. {
  4673. onClickAutoConnect();
  4674. mpfb->SetOpenDrive(mxodr);
  4675. }
  4676. void MainWindow::on_actionSet_Speed_triggered()
  4677. {
  4678. #ifdef OPENDRIVE_EDITONLY
  4679. QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
  4680. return;
  4681. #endif
  4682. std::string strroadid = mpCBRoad->currentText().toStdString();
  4683. SpeedDialog sd(&mxodr,strroadid,this);
  4684. int res = sd.exec();(void)res;
  4685. }
  4686. void MainWindow::closeEvent(QCloseEvent *event)
  4687. {
  4688. if(mxodr.GetRoadCount() == 0)
  4689. {
  4690. event->accept(); // 接受退出信号,程序退出
  4691. return;
  4692. }
  4693. if(mnNotSave == 0)
  4694. {
  4695. event->accept(); // 接受退出信号,程序退出
  4696. return;
  4697. }
  4698. QMessageBox::StandardButton button;
  4699. button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序")),QMessageBox::Yes|QMessageBox::No);
  4700. if(button==QMessageBox::No)
  4701. {
  4702. event->ignore(); // 忽略退出信号,程序继续进行
  4703. }
  4704. else if(button==QMessageBox::Yes)
  4705. {
  4706. event->accept(); // 接受退出信号,程序退出
  4707. }
  4708. }
  4709. void MainWindow::on_actionSet_Traffic_Light_triggered()
  4710. {
  4711. #ifdef OPENDRIVE_EDITONLY
  4712. QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
  4713. return;
  4714. #endif
  4715. std::string strroadid = mpCBRoad->currentText().toStdString();
  4716. TrafficLightDialog td(&mxodr,strroadid,this);
  4717. int res = td.exec();
  4718. (void)res;
  4719. }
  4720. void MainWindow::on_actionEdit_Road_Lane_triggered()
  4721. {
  4722. }
  4723. void MainWindow::on_actionEdit_Road_triggered()
  4724. {
  4725. SaveBack();
  4726. std::string strroadid = mpCBRoad->currentText().toStdString();
  4727. RoadEditDialog rd(&mxodr,strroadid,this);
  4728. int res = rd.exec();
  4729. (void)res;
  4730. updateCBRoad();
  4731. mbRefresh = true;
  4732. update();
  4733. if(mpCBViewMode->currentIndex() == 1)
  4734. {
  4735. UpdateScene();
  4736. }
  4737. mpfb->SetOpenDrive(mxodr);
  4738. }
  4739. void MainWindow::on_actionAdd_Road_From_RTK_triggered()
  4740. {
  4741. #ifdef OPENDRIVE_EDITONLY
  4742. QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
  4743. return;
  4744. #endif
  4745. SaveBack();
  4746. DialogAddRoadFromRTK arfrd(&mxodr,glon0,glat0,this);
  4747. arfrd.exec();
  4748. mpLELat0->setText(QString::number(glat0,'f',7));
  4749. mpLELon0->setText(QString::number(glon0,'f',7));
  4750. updateCBRoad();
  4751. mbRefresh = true;
  4752. update();
  4753. mpfb->SetOpenDrive(mxodr);
  4754. }
  4755. void MainWindow::onClickSetMove()
  4756. {
  4757. double fMoveX = mpLE_SelX->text().toDouble();
  4758. double fMoveY = mpLE_SelY->text().toDouble();
  4759. mfViewMoveX = mfViewMoveX - fMoveX;
  4760. mfViewMoveY = mfViewMoveY - fMoveY;
  4761. mbRefresh = true;
  4762. update();
  4763. mpLEViewMoveX->setText(QString::number(mfViewMoveX,'f',2));
  4764. mpLEViewMoveY->setText(QString::number(mfViewMoveY,'f',2));
  4765. // updateView();
  4766. }
  4767. void MainWindow::onClickReSetMove()
  4768. {
  4769. mfViewMoveX = 0;
  4770. mfViewMoveY = 0;
  4771. mbRefresh = true;
  4772. update();
  4773. mpLEViewMoveX->setText(QString::number(mfViewMoveX,'f',2));
  4774. mpLEViewMoveY->setText(QString::number(mfViewMoveY,'f',2));
  4775. }
  4776. void MainWindow::on_actionSummary_Road_triggered()
  4777. {
  4778. int nroadnum = mxodr.GetRoadCount();
  4779. int i;
  4780. double flen = 0;
  4781. for(i=0;i<nroadnum;i++)
  4782. {
  4783. flen = flen + mxodr.GetRoad(i)->GetRoadLength();
  4784. }
  4785. char strout[256];
  4786. snprintf(strout,256,"Road Count:%d Length Total:%f",nroadnum,flen);
  4787. QMessageBox::information(this,tr("Summary"),QString(strout),QMessageBox::YesAll);
  4788. }
  4789. void MainWindow::on_actionSplit_Road_triggered()
  4790. {
  4791. }
  4792. void MainWindow::UpdateScene()
  4793. {
  4794. int i;
  4795. int nsize = mvectorviewitem.size();
  4796. for(i=0;i<nsize;i++)
  4797. {
  4798. mpscene->removeItem(mvectorviewitem.at(i));
  4799. delete mvectorviewitem.at(i);
  4800. }
  4801. nsize = mvectorgeoitem.size();
  4802. for(i=0;i<nsize;i++)
  4803. {
  4804. mpscene->removeItem(mvectorgeoitem.at(i));
  4805. delete mvectorgeoitem.at(i);
  4806. }
  4807. mvectorviewitem.clear();
  4808. mvectorgeoitem.clear();
  4809. nsize = mxodr.GetRoadCount();
  4810. std::vector<RoadDigit> xvectorrd;
  4811. for(i=0;i<nsize;i++)
  4812. {
  4813. RoadDigit xrd(mxodr.GetRoad(i),5.0);
  4814. xvectorrd.push_back(xrd);
  4815. // UpdateSceneRoad(mxodr.GetRoad(i));
  4816. // qDebug("update road %d",i);
  4817. }
  4818. for(i=0;i<nsize;i++)
  4819. {
  4820. if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
  4821. {
  4822. continue;
  4823. }
  4824. std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&(xvectorrd[i]));
  4825. int j;
  4826. int ncount = xvectorlanepath.size();
  4827. for(j=0;j<ncount;j++)
  4828. {
  4829. QGraphicsPathItem * pitem = xvectorlanepath[j];
  4830. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
  4831. mpscene->addItem(pitem);
  4832. mvectorviewitem.push_back(pitem);
  4833. }
  4834. }
  4835. for(i=0;i<nsize;i++)
  4836. {
  4837. if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
  4838. {
  4839. continue;
  4840. }
  4841. std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&(xvectorrd[i]));
  4842. int j;
  4843. int ncount = xvectormarkpath.size();
  4844. for(j=0;j<ncount;j++)
  4845. {
  4846. QGraphicsPathItem * pitem = xvectormarkpath[j];
  4847. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
  4848. mpscene->addItem(pitem);
  4849. mvectorviewitem.push_back(pitem);
  4850. }
  4851. }
  4852. for(i=0;i<nsize;i++)
  4853. {
  4854. if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
  4855. {
  4856. continue;
  4857. }
  4858. std::vector<QGraphicsTextItem *> xvectortext;
  4859. std::vector<QGraphicsPathItem *> xvectorparkmark;
  4860. std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]),xvectortext,
  4861. xvectorparkmark);
  4862. int j;
  4863. int ncount = xvectorparkpath.size();
  4864. for(j=0;j<ncount;j++)
  4865. {
  4866. QGraphicsPathItem * pitem = xvectorparkpath[j];
  4867. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
  4868. mpscene->addItem(pitem);
  4869. mvectorviewitem.push_back(pitem);
  4870. }
  4871. ncount = xvectortext.size();
  4872. for(j=0;j<ncount;j++)
  4873. {
  4874. QGraphicsTextItem * pitem = xvectortext[j];
  4875. // pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + (-24.0),-mfViewMoveY+VIEW_HEIGHT/2.0+(-102.0));
  4876. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + pitem->pos().x(),-mfViewMoveY+VIEW_HEIGHT/2.0+pitem->pos().y());
  4877. mpscene->addItem(pitem);
  4878. }
  4879. ncount = xvectorparkmark.size();
  4880. for(j=0;j<ncount;j++)
  4881. {
  4882. QGraphicsPathItem * pitem = xvectorparkmark[j];
  4883. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
  4884. mpscene->addItem(pitem);
  4885. mvectorviewitem.push_back(pitem);
  4886. }
  4887. }
  4888. UpdateScene_SelectRoadRefGeo();
  4889. mbRefresh = false;
  4890. // mpscene->addLine(0,0,1000,100);
  4891. }
  4892. void MainWindow::UpdateScene_SelectRoadRefGeo()
  4893. {
  4894. int i;
  4895. int nsize;
  4896. nsize = mvectorgeoitem.size();
  4897. for(i=0;i<nsize;i++)
  4898. {
  4899. mpscene->removeItem(mvectorgeoitem.at(i));
  4900. delete mvectorgeoitem.at(i);
  4901. }
  4902. mvectorgeoitem.clear();
  4903. if(mbHideSelected)return;
  4904. int selid = mpCBRoad->currentText().toInt();
  4905. nsize = mxodr.GetRoadCount();
  4906. for(i=0;i<nsize;i++)
  4907. {
  4908. if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
  4909. {
  4910. continue;
  4911. }
  4912. if(selid == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
  4913. {
  4914. RoadDigit xrd(mxodr.GetRoad(i),5.0);
  4915. std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadRefGeoItem(&(xrd));
  4916. int j;
  4917. int ncount = xvectorlanepath.size();
  4918. for(j=0;j<ncount;j++)
  4919. {
  4920. QGraphicsPathItem * pitem = xvectorlanepath[j];
  4921. pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
  4922. mpscene->addItem(pitem);
  4923. mvectorgeoitem.push_back(pitem);
  4924. }
  4925. }
  4926. }
  4927. }
  4928. void MainWindow::onViewModeChange(int index)
  4929. {
  4930. if(index == 1)
  4931. {
  4932. UpdateScene();
  4933. }
  4934. mnViewMode = index;
  4935. mbRefresh = true;
  4936. update();
  4937. }
  4938. void MainWindow::on_actionCalc_Road_S_triggered()
  4939. {
  4940. DialogCalcS calcs(&mxodr,glon0,glat0,this);
  4941. calcs.exec();
  4942. }
  4943. void MainWindow::on_actionBack_triggered()
  4944. {
  4945. if(mvectorxodrback.size()>0)
  4946. {
  4947. mxodr = mvectorxodrback.at(mvectorxodrback.size() -1);
  4948. updateCBRoad();
  4949. mbRefresh = true;
  4950. update();
  4951. if(mpCBViewMode->currentIndex() == 1)
  4952. {
  4953. UpdateScene();
  4954. }
  4955. mvectorxodrback.erase(mvectorxodrback.begin() + mvectorxodrback.size()-1);
  4956. }
  4957. else
  4958. {
  4959. QMessageBox::warning(this,tr("Warning"),tr("No Back Option"),QMessageBox::YesAll);
  4960. }
  4961. }
  4962. void MainWindow::SaveBack()
  4963. {
  4964. if(mxodr.GetRoadCount() > 0)
  4965. {
  4966. mvectorxodrback.push_back(mxodr);
  4967. if(mvectorxodrback.size() > 10)
  4968. {
  4969. mvectorxodrback.erase(mvectorxodrback.begin());
  4970. }
  4971. }
  4972. mnNotSave++;
  4973. mpfb->SetOpenDrive(mxodr);
  4974. }
  4975. void MainWindow::on_actionEdit_Road_Borrow_triggered()
  4976. {
  4977. #ifdef OPENDRIVE_EDITONLY
  4978. QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
  4979. return;
  4980. #endif
  4981. std::string strroadid = mpCBRoad->currentText().toStdString();
  4982. DialogRoadBorrow rbd(&mxodr,strroadid,this);
  4983. int res = rbd.exec();
  4984. (void)res;
  4985. mpfb->SetOpenDrive(mxodr);
  4986. }
  4987. void MainWindow::on_actionMake_All_Road_Contact_triggered()
  4988. {
  4989. QMessageBox::StandardButton button;
  4990. // button=QMessageBox::question(this,tr("路口道路创建"),QString(tr("是否让软件自动创建所有路口道路?")),QMessageBox::Yes|QMessageBox::No);
  4991. button=QMessageBox::question(this,tr("Junction Create"),QString(tr("Do you want Auto Create Junction?")),QMessageBox::Yes|QMessageBox::No);
  4992. if(button==QMessageBox::No)
  4993. {
  4994. return;
  4995. }
  4996. else if(button==QMessageBox::Yes)
  4997. {
  4998. }
  4999. #ifdef OPENDRIVE_EDITONLY
  5000. QMessageBox::warning(this,"Warnig","This Function is not comlete.Please Wait.",QMessageBox::YesAll);
  5001. return;
  5002. #endif
  5003. on_actionAutoConnect_triggered();
  5004. AutoRoadContact::MakeAllContact(&mxodr);
  5005. updateJunction();
  5006. updateCBRoad();
  5007. mbRefresh = true;
  5008. update();
  5009. if(mpCBViewMode->currentIndex() == 1)
  5010. {
  5011. UpdateScene();
  5012. }
  5013. mpfb->SetOpenDrive(mxodr);
  5014. }
  5015. void MainWindow::on_actionHide_Road_triggered()
  5016. {
  5017. std::string strroadid = mpCBRoad->currentText().toStdString();
  5018. DialogHideRoad hrd(&mxodr,strroadid,&mvectorhideroadid, this);
  5019. int res = hrd.exec();
  5020. if(res == 0){}
  5021. mbRefresh = true;
  5022. update();
  5023. if(mpCBViewMode->currentIndex() == 1)
  5024. {
  5025. UpdateScene();
  5026. }
  5027. }
  5028. bool MainWindow::IsHidenRoad(int nroadid)
  5029. {
  5030. bool bIsHiden = false;
  5031. unsigned int i;
  5032. for(i=0;i<mvectorhideroadid.size();i++)
  5033. {
  5034. if(nroadid == mvectorhideroadid[i])
  5035. {
  5036. bIsHiden = true;
  5037. break;
  5038. }
  5039. }
  5040. return bIsHiden;
  5041. }
  5042. void MainWindow::on_actionHide_Selected_triggered()
  5043. {
  5044. if(mbHideSelected)
  5045. {
  5046. mbHideSelected = false;
  5047. ui->actionHide_Selected->setText(tr("Hide Selected"));
  5048. }
  5049. else
  5050. {
  5051. mbHideSelected = true;
  5052. ui->actionHide_Selected->setText(tr("Show Selected"));
  5053. }
  5054. UpdateScene_SelectRoadRefGeo();
  5055. }
  5056. void MainWindow::on_actionDraw_Road_triggered()
  5057. {
  5058. DialogDrawRoad * pdlgdraw = mpdlgdraw;
  5059. pdlgdraw->setModal(false);
  5060. pdlgdraw->show();
  5061. }
  5062. void MainWindow::onDrawNewRoad()
  5063. {
  5064. updateJunction();
  5065. updateCBRoad();
  5066. mbRefresh = true;
  5067. update();
  5068. if(mpCBViewMode->currentIndex() == 1)
  5069. {
  5070. UpdateScene();
  5071. }
  5072. }
  5073. void MainWindow::on_actionEdit_Road_Noavoid_triggered()
  5074. {
  5075. #ifdef OPENDRIVE_EDITONLY
  5076. QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
  5077. return;
  5078. #endif
  5079. std::string strroadid = mpCBRoad->currentText().toStdString();
  5080. DialogRoadNoavoid rbd(&mxodr,strroadid,this);
  5081. rbd.exec();
  5082. mpfb->SetOpenDrive(mxodr);
  5083. }
  5084. void MainWindow::on_actionAdd_Road_From_NDS_triggered()
  5085. {
  5086. DialogAddRoadFromNDS rnd(&mxodr, this);
  5087. rnd.exec();
  5088. updateJunction();
  5089. updateCBRoad();
  5090. mbRefresh = true;
  5091. update();
  5092. if(mpCBViewMode->currentIndex() == 1)
  5093. {
  5094. UpdateScene();
  5095. }
  5096. }
  5097. void MainWindow::on_CreateBefore_triggered()
  5098. {
  5099. bool ok;
  5100. QString text = QInputDialog::getText(this, tr("Get Road ID"),
  5101. tr("Road ID:"), QLineEdit::Normal,
  5102. mpCBRoad->currentText(), &ok);
  5103. Road * pRoad =NULL;
  5104. if (ok && !text.isEmpty())
  5105. {
  5106. std::string strroadid = text.toStdString();
  5107. int i;
  5108. for(i=0;i<(int)mxodr.GetRoadCount();i++)
  5109. {
  5110. if(mxodr.GetRoad(i)->GetRoadId() == strroadid)
  5111. {
  5112. pRoad = mxodr.GetRoad(i);
  5113. break;
  5114. }
  5115. }
  5116. if(pRoad == NULL)
  5117. {
  5118. QMessageBox::warning(this,tr("Warning"),tr("Road is not exist."),QMessageBox::YesAll);
  5119. return;
  5120. }
  5121. }
  5122. else
  5123. {
  5124. return;
  5125. }
  5126. double fLength = 0.0;
  5127. text = QInputDialog::getText(this, tr("Set Length"),
  5128. tr("Length:"), QLineEdit::Normal,
  5129. "100.0", &ok);
  5130. if (ok && !text.isEmpty())
  5131. {
  5132. fLength = text.toDouble();
  5133. if(fLength<=0)
  5134. {
  5135. QMessageBox::warning(this,tr("Warning"),tr("Road Lenth is negative or zero."),QMessageBox::YesAll);
  5136. return;
  5137. }
  5138. }
  5139. mpfb->SetOpenDrive(mxodr);
  5140. CreateExtendRoad::CreateBeforeRoad(&mxodr,pRoad,fLength);
  5141. std::cout<<"create road."<<std::endl;
  5142. updateJunction();
  5143. updateCBRoad();
  5144. mbRefresh = true;
  5145. update();
  5146. if(mpCBViewMode->currentIndex() == 1)
  5147. {
  5148. UpdateScene();
  5149. }
  5150. }
  5151. void MainWindow::on_CreateAfter_triggered()
  5152. {
  5153. bool ok;
  5154. QString text = QInputDialog::getText(this, tr("Get Road ID"),
  5155. tr("Road ID:"), QLineEdit::Normal,
  5156. mpCBRoad->currentText(), &ok);
  5157. Road * pRoad =NULL;
  5158. if (ok && !text.isEmpty())
  5159. {
  5160. std::string strroadid = text.toStdString();
  5161. int i;
  5162. for(i=0;i<(int)mxodr.GetRoadCount();i++)
  5163. {
  5164. if(mxodr.GetRoad(i)->GetRoadId() == strroadid)
  5165. {
  5166. pRoad = mxodr.GetRoad(i);
  5167. break;
  5168. }
  5169. }
  5170. if(pRoad == NULL)
  5171. {
  5172. QMessageBox::warning(this,tr("Warning"),tr("Road is not exist."),QMessageBox::YesAll);
  5173. return;
  5174. }
  5175. }
  5176. else
  5177. {
  5178. return;
  5179. }
  5180. double fLength = 0.0;
  5181. text = QInputDialog::getText(this, tr("Set Length"),
  5182. tr("Length:"), QLineEdit::Normal,
  5183. "100.0", &ok);
  5184. if (ok && !text.isEmpty())
  5185. {
  5186. fLength = text.toDouble();
  5187. if(fLength<=0)
  5188. {
  5189. QMessageBox::warning(this,tr("Warning"),tr("Road Lenth is negative or zero."),QMessageBox::YesAll);
  5190. return;
  5191. }
  5192. }
  5193. mpfb->SetOpenDrive(mxodr);
  5194. CreateExtendRoad::CreateAfterRoad(&mxodr,pRoad,fLength);
  5195. std::cout<<"create road."<<std::endl;
  5196. updateJunction();
  5197. updateCBRoad();
  5198. mbRefresh = true;
  5199. update();
  5200. if(mpCBViewMode->currentIndex() == 1)
  5201. {
  5202. UpdateScene();
  5203. }
  5204. }
  5205. void MainWindow::on_actionAdd_Road_From_CDA_triggered()
  5206. {
  5207. if(ServiceExcelAPI.IsLoad() == false)
  5208. {
  5209. QMessageBox::warning(this,tr("Warning"),tr("Can't load ivxlnt plugin."),QMessageBox::YesAll);
  5210. return;
  5211. }
  5212. QString str = QFileDialog::getOpenFileName(this,"Load xlsx",".","*.xlsx");
  5213. if(str.isEmpty())return;
  5214. // QString str = "/home/yuchuli/3.xlsx";
  5215. int nrtn = CDAProc::Proc(str.toStdString(),&mxodr);
  5216. if(nrtn<0)
  5217. {
  5218. std::cout<<" CDAProc::Proc return code: "<<nrtn<<std::endl;
  5219. QMessageBox::warning(this,tr("Warning"),tr("CDA Create road fail."),QMessageBox::YesAll);
  5220. }
  5221. AutoConnect pAC(&mxodr);
  5222. pAC.Connect();
  5223. updateJunction();
  5224. updateCBRoad();
  5225. mbRefresh = true;
  5226. update();
  5227. if(mpCBViewMode->currentIndex() == 1)
  5228. {
  5229. UpdateScene();
  5230. }
  5231. }
  5232. void MainWindow::on_actionDraw_Road_From_CDA_triggered()
  5233. {
  5234. DialogAddRoadFromCDA xdlg(&mxodr, this);
  5235. if(xdlg.exec() == QDialog::Accepted)
  5236. {
  5237. }
  5238. else
  5239. {
  5240. return;
  5241. }
  5242. AutoConnect pAC(&mxodr);
  5243. pAC.Connect();
  5244. updateJunction();
  5245. updateCBRoad();
  5246. mbRefresh = true;
  5247. update();
  5248. if(mpCBViewMode->currentIndex() == 1)
  5249. {
  5250. UpdateScene();
  5251. }
  5252. }
  5253. void MainWindow::on_actionAdd_Roads_From_Labels_triggered()
  5254. {
  5255. if(ServiceExcelAPI.IsLoad() == false)
  5256. {
  5257. QMessageBox::warning(this,tr("Warning"),tr("Can't load ivxlnt plugin."),QMessageBox::YesAll);
  5258. return;
  5259. }
  5260. QString str = QFileDialog::getOpenFileName(this,"Load xlsx",".","*.xlsx");
  5261. if(str.isEmpty())return;
  5262. // QString str = "/home/yuchuli/下载/Scenarios(1).xlsx";
  5263. QString strdir = QFileDialog::getExistingDirectory(this,tr("Set Save Directory"),".");
  5264. if(strdir.isNull())return;
  5265. int nrtn = CDAProc::ProcRoads(str.toStdString(),strdir.toStdString());
  5266. if(nrtn == 0)
  5267. {
  5268. QMessageBox::information(this,tr("Info"),tr("Successfully."),QMessageBox::YesAll);
  5269. }
  5270. else
  5271. {
  5272. QMessageBox::warning(this,tr("Warning"),tr("Some Item convert fail. Please Check."),QMessageBox::YesAll);
  5273. }
  5274. }
  5275. void MainWindow::on_actionEdit_Road_Priority_triggered()
  5276. {
  5277. std::string strroadid = mpCBRoad->currentText().toStdString();
  5278. DialogRoadPriority rpd(&mxodr,strroadid,this);
  5279. rpd.exec();
  5280. mpfb->SetOpenDrive(mxodr);
  5281. }
  5282. void MainWindow::on_actionExport_Current_Road_triggered()
  5283. {
  5284. int index = mpCBRoad->currentIndex();
  5285. qDebug("index: %d",index);
  5286. int nroadsize = static_cast<int>(mxodr.GetRoadCount());
  5287. if((index<0)||(index>=nroadsize))
  5288. {
  5289. QMessageBox::warning(this,tr("Warning"),tr("Road Index Error."),QMessageBox::YesAll);
  5290. return;
  5291. }
  5292. QString strsavepath = QFileDialog::getSaveFileName(this,tr("Save Select Road"),getenv("HOME"),"*.xodr");
  5293. if(strsavepath.isEmpty())return;
  5294. if(strsavepath.length()>4)
  5295. {
  5296. if(strsavepath.right(5) == ".xodr" )
  5297. {
  5298. }
  5299. else
  5300. {
  5301. strsavepath.append(".xodr");
  5302. }
  5303. }
  5304. else
  5305. {
  5306. strsavepath.append(".xodr");
  5307. }
  5308. OpenDrive * pxodr = new OpenDrive();
  5309. unsigned short int revMajor,revMinor;
  5310. std::string name,date;
  5311. float version;
  5312. double north,south,east,west,lat0,lon0,hdg0;
  5313. mxodr.GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
  5314. pxodr->SetHeader(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
  5315. pxodr->GetRoadVector()->push_back(mxodr.GetRoadVector()->at(index));
  5316. OpenDriveXmlWriter x(pxodr);
  5317. x.WriteFile(strsavepath.toStdString());
  5318. delete pxodr;
  5319. }
  5320. void MainWindow::on_actionOptimize_Road_triggered()
  5321. {
  5322. QMessageBox::StandardButton button;
  5323. // button=QMessageBox::question(this,tr("优化当前选中的道路"),QString(tr("是否优化当前选中道路?")),QMessageBox::Yes|QMessageBox::No);
  5324. button=QMessageBox::question(this,tr("Optimize Road"),QString(tr("Optimize selected road?")),QMessageBox::Yes|QMessageBox::No);
  5325. if(button==QMessageBox::No)
  5326. {
  5327. return;
  5328. }
  5329. else if(button==QMessageBox::Yes)
  5330. {
  5331. }
  5332. int index = mpCBRoad->currentIndex();
  5333. qDebug("index: %d",index);
  5334. int nroadsize = static_cast<int>(mxodr.GetRoadCount());
  5335. if((index<0)||(index>=nroadsize))
  5336. {
  5337. QMessageBox::warning(this,tr("Warning"),tr("Road Index Error."),QMessageBox::YesAll);
  5338. return;
  5339. }
  5340. SaveBack();
  5341. Road * pRoad = mxodr.GetRoad(index);
  5342. if(pRoad == NULL)return;
  5343. int nrtn = xodrfunc::optimizeroad(pRoad);
  5344. if(nrtn == 1)
  5345. {
  5346. mbRefresh = true;
  5347. update();
  5348. if(mpCBViewMode->currentIndex() == 1)
  5349. {
  5350. UpdateScene();
  5351. }
  5352. }
  5353. else
  5354. {
  5355. std::cout<<" no optimize, so not need update."<<std::endl;
  5356. }
  5357. }
  5358. void MainWindow::on_actionAdd_ParkSpace_triggered()
  5359. {
  5360. int nroadcount = mxodr.GetRoadCount();
  5361. if(nroadcount == 0)return;
  5362. Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
  5363. if(pRoad == 0)return;
  5364. double fLon = mpLE_SelLon->text().toDouble();
  5365. double fLat = mpLE_SelLat->text().toDouble();
  5366. SaveBack();
  5367. DialogParkingFromPoint dlgparkpoint(pRoad,fLon,fLat,this);
  5368. dlgparkpoint.exec();
  5369. mbRefresh = true;
  5370. update();
  5371. if(mpCBViewMode->currentIndex() == 1)
  5372. {
  5373. UpdateScene();
  5374. }
  5375. }