1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <iomanip>//不要忘记包含此头文件
- #include <QScrollBar>
- #include <QFileInfo>
- #include <QInputDialog>
- #include "gpsimu.pb.h"
- #include "gnss_coordinate_convert.h"
- #include "ndsdataproc.h"
- #define VIEW_WIDTH 10000
- #define VIEW_HEIGHT 10000
- double glon0 = 117.0866293;
- double glat0 = 39.1364713;
- double ghdg0 = 360;
- MainWindow * gw;
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- gw = this;
- ui->setupUi(this);
- mnfac = 1;
- mnMoveX = VIEW_WIDTH/2;
- mnMoveY = VIEW_HEIGHT/2;
- mnDefmnfac = mnfac;
- mnDefMoveX = mnMoveX;
- mnDefMoveY = mnMoveY;
- QIcon icon(":/opendrive.png");
- setWindowIcon(icon);
- //Create View
- myview = new MyView(this);
- myview->setObjectName(QStringLiteral("graphicsView"));
- myview->setGeometry(QRect(30, 30, 600, 600));
- connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double)));
- image = new QImage(VIEW_WIDTH, VIEW_HEIGHT, QImage::Format_RGB32);//画布的初始化大小设为300*300,使用32位颜色
- myview->setCacheMode(myview->CacheBackground);
- painter = new QPainter(image);
- painter->end();
- scene = new QGraphicsScene;
- mpscene = new QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
- mpscene->setBackgroundBrush(Qt::darkGreen);
- //Create Tab
- QTabWidget * p = new QTabWidget(ui->centralWidget);
- p->setGeometry(30,30,300,300);
- mnFontHeight = ui->centralWidget->fontMetrics().height();
- CreateTab1View(p);
- mpLabel_Status = new QLabel(this);
- ui->statusBar->addPermanentWidget(mpLabel_Status);
- mTabMain = p;
- //Create Timer
- QTimer * timer = new QTimer();
- connect(timer,SIGNAL(timeout()),this,SLOT(onTimer()));
- timer->start(1000);
- //Create File Backup
- mpfb = new FileBackup();
- mpfb->start();
- //Create Draw Dialog
- mpdlgdraw = new DialogDrawRoad(&mxodr, this);
- connect(mpdlgdraw,SIGNAL(drawnewroad()),this,SLOT(onDrawNewRoad()));
- setWindowTitle("Create Map From Lane Info");
- // NDSDataProc::ProcNDSData("/home/yuchuli/下载/nds-sync-line.csv","/home/yuchuli/下载/nds-sync-vehicle.csv");
- }
- MainWindow::~MainWindow()
- {
- delete mpfb;
- delete ui;
- }
- void MainWindow::resizeEvent(QResizeEvent *event)
- {
- (void)event;
- qDebug("resize");
- QSize sizemain = ui->centralWidget->size();
- qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
- AdjustWPos(sizemain);
- }
- void MainWindow::AdjustWPos(QSize sizemain)
- {
- myview->setGeometry(0,30,sizemain.width()-mnFontHeight * 22 - 30,sizemain.height());
- mTabMain->setGeometry(sizemain.width()-mnFontHeight * 22,30,mnFontHeight * 22,sizemain.height()-50);
- }
- void MainWindow::ExecPainter()
- {
- painter->begin(image);
- image->fill(QColor(255, 255, 255));//对画布进行填充
- painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
- //Set Move
- painter->translate(mnMoveX,mnMoveY);
- painter->setPen(Qt::black);
- painter->drawLine(VIEW_WIDTH/(-2),0,VIEW_WIDTH/2,0);
- painter->drawLine(0,VIEW_HEIGHT/(-2),0,VIEW_HEIGHT/2);
- int i;
- painter->setPen(Qt::blue);
- int nfac = mnfac;
- (void)nfac;
- if(mbClick)
- {
- painter->setPen(Qt::red);
- painter->drawEllipse(QPoint(mClickX ,mClickY),mnMarkSize,mnMarkSize);
- painter->setPen(Qt::black);
- }
- if(mbSetObj)
- {
- painter->setPen(Qt::green);
- painter->drawRect(mfObjX*mnfac-mnMarkSize,mfObjY*mnfac*(-1)-mnMarkSize,mnMarkSize*2,mnMarkSize*2);
- painter->setPen(Qt::black);
- }
- painter->setPen(Qt::green);
- double x0,y0;
- GaussProjCal(glon0,glat0,&x0,&y0);
- painter->setPen(Qt::blue);
- int selid = mpCBRoad->currentText().toInt();
- for(i=0;i<static_cast<int>( mxodr.GetRoadCount());i++)
- {
- int j;
- Road * pRoad = mxodr.GetRoad(i);
- painter->setPen(Qt::blue);
- if(selid == atoi(pRoad->GetRoadId().data()))
- {
- painter->setPen(Qt::red);
- }
- if(IsHidenRoad(atoi(pRoad->GetRoadId().data())))
- {
- continue;
- }
- if(mxodr.GetRoad(i)->GetGeometryBlockCount()>0)
- {
- GeometryBlock * pgeob = pRoad->GetGeometryBlock(0);
- double x,y;
- RoadGeometry * pg;
- pg = pgeob->GetGeometryAt(0);
- x = pg->GetX();
- y = pg->GetY();
- double endx,endy,endhdg;
- GetEndPoint(pRoad,endx,endy,endhdg);
- x = (x+endx)/2;
- y = (y+endy)/2;
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- painter->drawText(x*mnfac,y*mnfac*(-1),mxodr.GetRoad(i)->GetRoadId().data());
- }
- for(j=0;j<static_cast<int>(mxodr.GetRoad(i)->GetGeometryBlockCount());j++)
- {
- GeometryBlock * pgeob = pRoad->GetGeometryBlock(j);
- double x,y;
- double x_center,y_center;
- double R;
- RoadGeometry * pg;
- GeometryArc * parc;
- GeometryParamPoly3 * ppp3;
- GeometrySpiral *pSpiral;
- GeometryPoly3 *ppoly;
- double rel_x,rel_y,rel_hdg;
- pg = pgeob->GetGeometryAt(0);
- x = pg->GetX();
- y = pg->GetY();
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- if(j== 0)
- {
- if(selid == atoi(pRoad->GetRoadId().data()))
- {
- painter->setPen(Qt::green);
- painter->drawEllipse(x*mnfac-5,y*mnfac*(-1)-5,10,10);
- painter->setPen(Qt::red);
- }
- }
- switch (pg->GetGeomType()) {
- case 0:
- painter->drawLine(QPoint(x*mnfac,y*mnfac*(-1)),
- QPoint((x + pg->GetLength() * cos(pg->GetHdg()))*mnfac,(y + pg->GetLength() * sin(pg->GetHdg()))*mnfac*(-1)));
- break;
- case 1:
- pSpiral = (GeometrySpiral * )pg;
- {
- int ncount = pSpiral->GetLength() * mnfac;
- double sstep = pSpiral->GetLength()/((double)ncount);
- int k;
- double x0,y0,hdg0,s0;
- (void)x0;
- (void)y0;
- (void)hdg0;
- s0 = pSpiral->GetS();
- painter->setPen(Qt::red);
- for(k=0;k<ncount;k++)
- {
- pSpiral->GetCoords(s0+sstep*k,rel_x,rel_y,rel_hdg);
- x = rel_x;
- y = rel_y;
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
- }
- painter->setPen(Qt::blue);
- }
- break;
- case 2:
- {
- parc = (GeometryArc *)pg;
- R = abs(1.0/parc->GetCurvature());
- if(parc->GetCurvature() > 0)
- {
- x_center = pg->GetX() + R *cos(pg->GetHdg() + M_PI/2.0);
- y_center = pg->GetY() + R * sin(pg->GetHdg() + M_PI/2.0);
- }
- else
- {
- x_center = pg->GetX() + R *cos(pg->GetHdg() -M_PI/2.0);
- y_center = pg->GetY() + R * sin(pg->GetHdg() - M_PI/2.0);
- }
- int k;
- int ncount = parc->GetLength() * mnfac ;
- double curv = parc->GetCurvature();
- double hdgstep;
- double hdg0 = parc->GetHdg();
- double hdgnow = parc->GetHdg();(void)hdgnow;
- if(ncount > 0) hdgstep= (parc->GetLength()/R)/ncount;
- for(k=0;k<ncount;k++)
- {
- double x_draw,y_draw;
- if(curv > 0)
- {
- hdgnow = hdg0 + k*hdgstep;
- x_draw = x_center + R *cos(hdgnow - M_PI/2.0);
- y_draw = y_center + R * sin(hdgnow - M_PI/2.0);
- }
- else
- {
- hdgnow = hdg0 - k * hdgstep;
- x_draw = x_center + R *cos(hdgnow + M_PI/2.0);
- y_draw = y_center + R * sin(hdgnow + M_PI/2.0);
- }
- x_draw = x_draw + mfViewMoveX;
- y_draw = y_draw + mfViewMoveY;
- painter->drawPoint(x_draw * mnfac ,y_draw * mnfac *(-1));
- }
- }
- break;
- case 3:
- {
- ppoly = (GeometryPoly3 *)pg;
- x = pg->GetX();
- y = pg->GetY();
- double A,B,C,D;
- A = ppoly->GetA();
- B = ppoly->GetB();
- C = ppoly->GetC();
- D = ppoly->GetD();
- const double steplim = 0.1;
- double du = steplim;
- double u = 0;
- double v = 0;
- double oldx,oldy;
- oldx = x;
- oldy = y;
- double xstart,ystart;
- xstart = x;
- ystart = y;
- double hdgstart = ppoly->GetHdg();
- double flen = 0;
- while(flen < ppoly->GetLength())
- {
- double fdis = 0;
- v = A + B*u + C*u*u + D*u*u*u;
- x = xstart + u*cos(hdgstart) - v*sin(hdgstart);
- y = ystart + u*sin(hdgstart) + v*cos(hdgstart);
- fdis = sqrt(pow(x- oldx,2)+pow(y-oldy,2));
- oldx = x;
- oldy = y;
- if(fdis>(steplim*2.0))du = du/2.0;
- flen = flen + fdis;
- u = u + du;
- std::cout<<" x: "<<x<<" y:"<<y<<std::endl;
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
- }
- }
- break;
- case 4:
- {
- ppp3 = (GeometryParamPoly3 * )pg;
- int ncount = ppp3->GetLength()* mnfac;
- double sstep;
- bool bNormal = ppp3->GetNormal();
- double arclength = ppp3->GetLength();
- if(ncount > 0)sstep = ppp3->GetLength()/ncount;
- else sstep = 10000.0;
- double s = 0;
- while(s < ppp3->GetLength())
- {
- double xtem,ytem;
- double pRange =s;
- if(bNormal && (arclength>0))pRange = s/arclength;
- xtem = ppp3->GetuA() + ppp3->GetuB() * pRange + ppp3->GetuC() * pRange*pRange + ppp3->GetuD() * pRange*pRange*pRange;
- ytem = ppp3->GetvA() + ppp3->GetvB() * pRange + ppp3->GetvC() * pRange*pRange + ppp3->GetvD() * pRange*pRange*pRange;
- x = xtem*cos(ppp3->GetHdg()) - ytem * sin(ppp3->GetHdg()) + ppp3->GetX();
- y = xtem*sin(ppp3->GetHdg()) + ytem * cos(ppp3->GetHdg()) + ppp3->GetY();
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
- s = s+ sstep;
- }
- }
- break;
- default:
- break;
- }
- }
- }
- for(i=0;i<static_cast<int>( mvectorlp.size());i++)
- {
- if(!mbShowLane)continue;
- if(i == mnMarkLane)
- {
- painter->setPen(Qt::red);
- }
- else
- {
- painter->setPen(Qt::blue);
- }
- int npsize = mvectorlp[i].mvectorlpleft.size();
- int j;
- for(j=0;j<npsize;j++)
- {
- double x,y;
- double lon,lat;
- lon = mvectorlp[i].mvectorlpleft[j].mfLon;
- lat = mvectorlp[i].mvectorlpleft[j].mfLat;
- GaussProjCal(lon,lat,&x,&y);
- x = x-x0;
- y= y-y0;
- painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
- lon = mvectorlp[i].mvectorlpright[j].mfLon;
- lat = mvectorlp[i].mvectorlpright[j].mfLat;
- GaussProjCal(lon,lat,&x,&y);
- x = x-x0;
- y= y-y0;
- x = x + mfViewMoveX;
- y = y + mfViewMoveY;
- painter->drawPoint((int)(x*mnfac),(int)(y*(-1.0*mnfac)));
- }
- }
- painter->setPen(Qt::green);
- painter->end();
- }
- //刷新
- void MainWindow::paintEvent(QPaintEvent *)
- {
- if(mnViewMode == 1)
- {
- if(mbRefresh)
- {
- // UpdateScene();
- }
- myview->setScene(mpscene);
- myview->show();
- return;
- }
- if(mbRefresh)
- {
- ExecPainter();
- // qDebug(" time is %d ",x.elapsed());
- mbRefresh = false;
- }
- scene->clear();
- scene->addPixmap(QPixmap::fromImage(*image));
- myview->setScene(scene);
- myview->show();
- if(mbInit == false)
- {
- myview->horizontalScrollBar()->setValue((mnMoveX - 800));
- myview->verticalScrollBar()->setValue((mnMoveY - 500));
- mbInit = true;
- }
- // qDebug(" time 2 is %d ",x.elapsed());
- }
- void MainWindow::onTimer()
- {
- }
- void MainWindow::CreateTab1View(QTabWidget * p)
- {
- QGroupBox * pGroup = new QGroupBox();
- pGroup->setGeometry(0,0,mnFontHeight * 21,mnFontHeight * 160);
- QLabel * pLabel;
- QLineEdit * pLE;
- QPushButton * pPB;
- QSlider * pSlider;
- QComboBox * pCB;
- int nXPos = 10;
- int nYPos = 30;
- int i;
- (void)i;
- int nSpace = mnFontHeight * 65/10;
- int nLEWidth = mnFontHeight * 6;
- int nLEHeight = mnFontHeight * 3/2;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("View Mode"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pCB = new QComboBox(pGroup);
- pCB->addItem(tr("Line"));
- pCB->addItem(tr("Scene"));
- pCB->setCurrentIndex(0);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpCBViewMode = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onViewModeChange(int)));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 3;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Lat0"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Lon0"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Head0"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLE = new QLineEdit(pGroup);
- pLE->setText(QString::number(glat0,'f',7));
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLELat0 = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText(QString::number(glon0,'f',7));
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLELon0 = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText(QString::number(ghdg0,'f',3));
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLEHead0 = pLE;
- // nXPos = nXPos + nSpace;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("ViewMove"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText(QString::number(mfViewMoveX,'f',2));
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLEViewMoveX = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText(QString::number(mfViewMoveY,'f',2));
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLEViewMoveY = pLE;
- // nXPos = nXPos + nSpace;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Restore Default View"));
- pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDefView()));
- nXPos = nXPos + mnFontHeight * 11;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Zoom One"));
- pPB->setGeometry(nXPos,nYPos,mnFontHeight*6,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickZoomOne()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Scale"));
- pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- nXPos = nXPos + mnFontHeight * 4;
- pSlider = new QSlider(pGroup);
- pSlider->setOrientation(Qt::Horizontal);
- pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
- pSlider->setRange(1,100);
- pSlider->setValue(mnfac);
- connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeScale(int)));
- mpSlider_Scale = pSlider;
- nXPos = nXPos + mnFontHeight*11;
- pLE = new QLineEdit(pGroup);
- pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- pLE->setText(QString::number(pSlider->value()));
- mpLE_Scale = pLE;
- // nXPos = 10;
- // nYPos = nYPos + mnFontHeight * 2;
- // pLabel = new QLabel(pGroup);
- // pLabel->setText("MoveX");
- // pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- // nXPos = nXPos + mnFontHeight * 4;
- // pSlider = new QSlider(pGroup);
- // pSlider->setOrientation(Qt::Horizontal);
- // pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
- // pSlider->setRange(0,100);
- // pSlider->setValue(mnMoveX*100/VIEW_WIDTH);
- // connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMoveX(int)));
- // mpSlider_MoveX = pSlider;
- // nXPos = nXPos + mnFontHeight*11;
- // pLE = new QLineEdit(pGroup);
- // pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- // pLE->setText(QString::number(pSlider->value()));
- // mpLE_MoveX = pLE;
- // nXPos = 10;
- // nYPos = nYPos + mnFontHeight * 2;
- // pLabel = new QLabel(pGroup);
- // pLabel->setText("MoveY");
- // pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- // nXPos = nXPos + mnFontHeight * 4;
- // pSlider = new QSlider(pGroup);
- // pSlider->setOrientation(Qt::Horizontal);
- // pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
- // pSlider->setRange(0,100);
- // pSlider->setValue(mnMoveY*100/VIEW_HEIGHT);
- // connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMoveY(int)));
- // mpSlider_MoveY = pSlider;
- // nXPos = nXPos + mnFontHeight*11;
- // pLE = new QLineEdit(pGroup);
- // pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- // pLE->setText(QString::number(pSlider->value()));
- // mpLE_MoveY = pLE;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Mark"));
- pLabel->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- nXPos = nXPos + mnFontHeight * 4;
- pSlider = new QSlider(pGroup);
- pSlider->setOrientation(Qt::Horizontal);
- pSlider->setGeometry(nXPos,nYPos,mnFontHeight * 10,nLEHeight);
- pSlider->setRange(5,100);
- pSlider->setValue(mnMarkSize);
- connect(pSlider,SIGNAL(valueChanged(int)),this,SLOT(onChangeMark(int)));
- mpSlider_Mark = pSlider;
- nXPos = nXPos + mnFontHeight*11;
- pLE = new QLineEdit(pGroup);
- pLE->setGeometry(nXPos,nYPos,mnFontHeight*3,nLEHeight);
- pLE->setText(QString::number(pSlider->value()));
- mpLE_Mark = pLE;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("SelLon"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("SelLat"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLE = new QLineEdit(pGroup);
- pLE->setText("");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLE_SelX = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText("");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLE_SelY = pLE;
- // nXPos = nXPos + nSpace;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLE = new QLineEdit(pGroup);
- pLE->setText("");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLE_SelLon = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText("");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLE_SelLat = pLE;
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setText("");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLE->setText("360");
- mpLE_StartHeading = pLE;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Set Move"));
- pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetMove()));
- nXPos = 30 + mnFontHeight*10;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Reset Move"));
- pPB->setGeometry(nXPos,nYPos,mnFontHeight*10,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickReSetMove()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Load Lane"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLoadLane()));
- nXPos = nXPos + nSpace;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- (void)nXPos;
- mpCBLane = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Remove"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRemoveLane()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Mark"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickMarkLane()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Clear Road Lane"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickClearRoadLane()));
- nXPos = nXPos + nSpace;
- (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("To Road"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickToRoad()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("To Opposite"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickToOpposite()));
- nXPos = nXPos + nSpace;
- pLE = new QLineEdit(pGroup);
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace; (void)nXPos;
- mpLE_RoadName = pLE;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBSelLane = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBSelOpLane = pCB;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Add Road"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAddRoad()));
- nXPos = nXPos + nSpace; (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBRoad = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBRoadChange(int)));
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Mark"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadMark()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Del"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadDel()));
- nXPos = nXPos + nSpace; (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("Predecessor:"));
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("road"));
- mpLabelRoadShowPreType1 = pLabel;
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("10010"));
- mpLabelRoadShowPreID = pLabel;
- nXPos = nXPos + nSpace; (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("start"));
- mpLabelRoadShowPreType2 = pLabel;
- nXPos = nXPos + nSpace;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
- mpCBRoadShowPre = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("Successor:"));
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("road"));
- mpLabelRoadShowNxtType1 = pLabel;
- nXPos = nXPos + nSpace;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("10010"));
- mpLabelRoadShowNxtID = pLabel;
- nXPos = nXPos + nSpace; (void)nXPos;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- pLabel->setText(tr("start"));
- mpLabelRoadShowNxtType2 = pLabel;
- nXPos = nXPos + nSpace;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
- mpCBRoadShowNext = pCB;
- // nXPos = 10;
- // nYPos = nYPos + mnFontHeight * 2;
- // pCB = new QComboBox(pGroup);
- // pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- // mpCBPreNxtCurLane = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBPreNxtRoad = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickPreNxtRoadChange(int)));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBPreNxtRelLane = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace; (void)nXPos;
- mpCBPreNxtConatact = pCB;
- pCB->addItem(tr("start"));
- pCB->addItem(tr("end"));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10;
- pPB->setText(tr("Set Predecessor"));
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetRoadPredecessor()));
- pPB = new QPushButton(pGroup);
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10; (void)nXPos;
- pPB->setText(tr("Set Successor"));
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSetRoadSuccessor()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10;
- pPB->setText(tr("Del Predecessor"));
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDelRoadPredecessor()));
- pPB = new QPushButton(pGroup);
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10; (void)nXPos;
- pPB->setText(tr("Del Successor"));
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDelRoadSuccessor()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBRoad1 = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pCB->addItem(tr("start"));
- pCB->addItem(tr("end"));
- mpCBRC1 = pCB;
- QCheckBox * pCheck = new QCheckBox(pGroup);
- pCheck->setText(tr("act"));
- pCheck->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpCheckFromSel = pCheck;
- mpCheckFromSel->setChecked(false);
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBRoad2 = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pCB->addItem(tr("start"));
- pCB->addItem(tr("end"));
- mpCBRC2 = pCB;
- pCheck = new QCheckBox(pGroup);
- pCheck->setText(tr("act"));
- pCheck->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpCheckToSel = pCheck;
- mpCheckToSel->setChecked(false);
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Road Contact"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickRoadContact()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Auto Road Contact"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*3/2,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAutoRoadContact()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth*2,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBRoadCon = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBLane1 = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBLane2 = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Lane Contact"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLaneContact()));
- nXPos = nXPos + nSpace*15/10;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBLane1Lane2 = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("OpLane Contact"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickOpLaneContact()));
- nXPos = nXPos + nSpace*15/10;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBLane1Lane2op = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Clear"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickClearLaneContact()));
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Create Road"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateRoad()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBRoadType = pCB;
- pCB->addItem(tr("Turn"));
- pCB->addItem(tr("Straight"));
- pCB->addItem(tr("U-Turn"));
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onChangeRoadType(int)));
- pLabel = new QLabel(pGroup);
- pLabel->setText(tr("Radius:"));
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpLBRoadType = pLabel;
- pLE = new QLineEdit(pGroup);
- pLE->setText("6.0");
- pLE->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpLERoadType = pLE;
- mpCBStraightType = new QCheckBox(pGroup);
- mpCBStraightType->setText(tr("Line Only"));
- mpCBStraightType->setChecked(false);
- mpCBStraightType->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpCBStraightType->setVisible(false);
- mpCBRoadType->setCurrentIndex(0);
- mpLBRoadType->setVisible(true);
- mpLERoadType->setVisible(true);
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Create Junction"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10;
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateJunction()));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBJunction = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionChange(int)));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth*5/10,nLEHeight);
- mpCBJunctionConnection = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionConnectionChange(int)));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpLabelJunctionIncommingRoad = pLabel;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpLabelJunctionContactPoint = pLabel;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpLabelJunctionConnectingRoad = pLabel;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- mpCBJunctionFromTo = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLabel->setText(tr("Incomming"));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBJunctionIncommingRoad = pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionIncommingChange(int)));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pLabel = new QLabel(pGroup);
- pLabel->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- pLabel->setText(tr("Connecting"));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBJunctionConnectingRoad= pCB;
- connect(pCB,SIGNAL(currentIndexChanged(int)),this,SLOT(onClickCBJunctionConnectionroadChange(int)));
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- pCB->addItem(tr("start"));
- pCB->addItem(tr("end"));
- mpCBJunctionContactPoint = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- nXPos = nXPos + nSpace;
- mpCBJunctionFromLane = pCB;
- pCB = new QComboBox(pGroup);
- pCB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- // nXPos = nXPos + nSpace;
- mpCBJunctionToLane = pCB;
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 2;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Create Lane Link"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- nXPos = nXPos + nSpace*15/10;
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickCreateJunctionLaneLink()));
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Delete Lane Link"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- // nXPos = nXPos + nSpace*15/10;
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickDeleteJunctionLaneLink()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Auto Connect Road"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth*15/10,nLEHeight);
- // nXPos = nXPos + nSpace*15/10;
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickAutoConnect()));
- nXPos = 10;
- nYPos = nYPos + mnFontHeight * 4;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Save"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickSave()));
- nXPos = nXPos + nSpace;
- pPB = new QPushButton(pGroup);
- pPB->setText(tr("Load"));
- pPB->setGeometry(nXPos,nYPos,nLEWidth,nLEHeight);
- connect(pPB,SIGNAL(clicked(bool)),this,SLOT(onClickLoad()));
- // nXPos = nXPos + nSpace;
- QScrollArea * pScroll = new QScrollArea();
- pScroll->setWidget(pGroup);
- p->addTab(pScroll,tr("Calculate"));
- }
- void MainWindow::onClickXY(double x, double y)
- {
- mClickX = x - mnMoveX;
- mClickY = y - mnMoveY;
- mbClick = true;
- mbRefresh = true;
- double selx,sely;
- double lon,lat;
- selx = mClickX;
- sely = mClickY * (-1);
- if(mnViewMode == 0)
- {
- selx = selx/((double )mnfac);
- sely = sely/((double)mnfac);
- }
- mpLE_SelX->setText(QString::number(selx,'f',3));
- mpLE_SelY->setText(QString::number(sely,'f',3));
- emit CurrentPosition(selx,sely);
- double x0,y0;
- GaussProjCal(glon0,glat0,&x0,&y0);
- GaussProjInvCal(x0+selx,y0+sely,&lon,&lat);
- double rel_x,rel_y;
- rel_x = selx - mfViewMoveX;
- rel_y = sely - mfViewMoveY;
- Road * pRoad = 0;
- GeometryBlock * pgeob;
- double fdis,nearx,neary,hdg;
- double fs;
- int nlane;
- // if(xodrfunc::GetNearPointWithHide2(rel_x,rel_y,&mxodr,&pRoad,fdis,nearx,neary,hdg,50,mvectorhideroadid,&fs,&nlane) == 0)
- if(xodrfunc::GetNearPointWithHide(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,mvectorhideroadid,&fs,&nlane) == 0)
- {
- qDebug("s:%f dis is %f nlane is %d",fs,fdis,nlane);
- char strout[1000];
- snprintf(strout,1000,"Road:%s s:%f dis:%f nlane:%d",pRoad->GetRoadId().data(),fs,fdis,nlane);
- mpLabel_Status->setText(strout);
- ui->statusBar->showMessage(strout,3000);
- int i;
- int nsize = mpCBRoad->count();
- for(i=0;i<nsize;i++)
- {
- if(mpCBRoad->itemText(i).toStdString() == pRoad->GetRoadId())
- {
- break;
- }
- }
- if(i<nsize)
- {
- if(i != mpCBRoad->currentIndex())
- mpCBRoad->setCurrentIndex(i);
- }
- }
- if(mpCheckFromSel->isChecked())
- {
- if(pRoad != 0)ComboToString(pRoad->GetRoadId(),mpCBRoad1);
- mpCheckFromSel->setChecked(false);
- }
- if(mpCheckToSel->isChecked())
- {
- if(pRoad != 0)ComboToString(pRoad->GetRoadId(),mpCBRoad2);
- mpCheckToSel->setChecked(false);
- }
- mpLE_SelLon->setText(QString::number(lon,'f',7));
- mpLE_SelLat->setText(QString::number(lat,'f',7));
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene_SelectRoadRefGeo();
- }
- }
- void MainWindow::ComboToString(std::string strroadid,QComboBox * pCB)
- {
- int i;
- int nsize = pCB->count();
- for(i=0;i<nsize;i++)
- {
- if(pCB->itemText(i).toStdString() == strroadid)
- {
- break;
- }
- }
- if(i<nsize)
- {
- if(i != pCB->currentIndex())
- pCB->setCurrentIndex(i);
- }
- }
- void MainWindow::onChangeScale(int scale)
- {
- mnfac = scale;
- mpLE_Scale->setText(QString::number(scale));
- mbRefresh = true;
- update();
- }
- void MainWindow::onChangeMoveX(int scale)
- {
- mnMoveX = VIEW_WIDTH * scale/100;
- mpLE_MoveX->setText(QString::number(scale));
- mbRefresh = true;
- update();
- }
- void MainWindow::onChangeMoveY(int scale)
- {
- mnMoveY = VIEW_HEIGHT * scale/100;
- mpLE_MoveY->setText(QString::number(scale));
- mbRefresh = true;
- update();
- }
- void MainWindow::onChangeMark(int scale)
- {
- mnMarkSize = scale;
- mpLE_Mark->setText(QString::number(scale));
- mbRefresh = true;
- update();
- }
- void MainWindow::onClickDefView()
- {
- mnfac = mnDefmnfac;
- mnMoveX = mnDefMoveX;
- mnMoveY = mnDefMoveY;
- mpSlider_Scale->setValue(mnfac);
- // mpSlider_MoveX->setValue(mnMoveX*100/VIEW_WIDTH);
- // mpSlider_MoveY->setValue(mnMoveY*100/VIEW_HEIGHT);
- // mbRefresh = true;
- update();
- }
- void MainWindow::onClickZoomOne()
- {
- myview->zoomone();
- }
- void MainWindow::onClickAsStart()
- {
- }
- void MainWindow::onClickAsDst()
- {
- double lon,lat;
- lon = mpLE_SelLon->text().toDouble();
- lat = mpLE_SelLat->text().toDouble();
- mpLE_DstLon->setText(QString::number(lon,'f',7));
- mpLE_DstLat->setText(QString::number(lat,'f',7));
- double x,y;
- x = mpLE_SelX->text().toDouble();
- y = mpLE_SelY->text().toDouble();
- mfObjX = x;
- mfObjY = y;
- mbSetObj = true;
- mbRefresh = true;
- update();
- }
- void MainWindow::onClickSetDst()
- {
- }
- void MainWindow::onClickPlan()
- {
- }
- void MainWindow::onClickSetStart()
- {
- }
- /**
- * @brief ADCIntelligentVehicle::UpdateMap
- * @param strdata
- * @param nSize
- * @param index
- * @param dt
- * @param strmemname
- */
- void MainWindow::UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- // std::cout<<"update map "<<std::endl;
- int gpsunitsize = sizeof(iv::GPS_INS);
- int nMapSize = nSize/gpsunitsize;
- // std::cout<<"map size is "<<nMapSize<<std::endl;
- if(nMapSize < 1)return;
- int i;
- mMutexNavi.lock();
- m_navigation_data.clear();
- for(i=0;i<nMapSize;i++)
- {
- iv::GPS_INS x;
- memcpy(&x,strdata + i*gpsunitsize,gpsunitsize);
- iv::GPSData data(new iv::GPS_INS);
- *data = x;
- m_navigation_data.push_back(data);
- }
- mMutexNavi.unlock();
- mbRefresh = true;
- update();
- }
- /**
- * @brief MainWindow::UpdateGPSIMU
- * @param strdata
- * @param nSize
- * @param index
- * @param dt
- * @param strmemname
- */
- void MainWindow::UpdateGPSIMU(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- iv::gps::gpsimu xgpsimu;
- if(!xgpsimu.ParseFromArray(strdata,nSize))
- {
- // gIvlog->warn("ADCIntelligentVehicle::UpdateGPSIMU parse error. nSize is %d",nSize);
- return;
- }
- double flat,flon,fhead;
- flat = xgpsimu.lat();
- flon = xgpsimu.lon();
- fhead = xgpsimu.heading();
- double x,y;
- GaussProjCal(flon,flat,&x,&y);
- mfNowX = x - mx0;
- mfNowY = y- my0;
- mfNowHdg = (90- fhead)*M_PI/180.0;
- mbGPSUpdate = true;
- mbGPSViewUpdate = true;
- }
- void MainWindow::onClickLoadLane()
- {
- QString str = QFileDialog::getOpenFileName(this,tr("Open Lane Info file"),"",tr("Lane File(*.txt)"));
- if(str.isEmpty())return;
- QFile xFile;
- xFile.setFileName(str);
- QFileInfo fi(str);
- QString filename = fi.fileName();
- double fLastLat = 39;
- double fLastLon = 117;
- if(filename.contains(".txt"))
- {
- filename = filename.left(filename.length() -4);
- }
- if(xFile.open(QIODevice::ReadWrite))
- {
- iv::lpunit lpu;
- strncpy(lpu.strlanename,filename.toLatin1().data(),filename.size());
- QByteArray ba;
- ba = xFile.read(xFile.size());
- QString strdata = ba;
- #ifdef ADCQT6
- QStringList strlinedata= strdata.split("\n",Qt::SplitBehaviorFlags::SkipEmptyParts);
- #else
- QStringList strlinedata= strdata.split("\n",QString::SkipEmptyParts);
- #endif
- int i;
- int nsize = strlinedata.size();
- // qDebug("line is %d",nsize);
- for(i=0;i<nsize;i++)
- {
- QString strline = strlinedata.at(i);
- #ifdef ADCQT6
- QStringList strvaluedata = strline.split(" ",Qt::SplitBehaviorFlags::SkipEmptyParts);
- #else
- QStringList strvaluedata = strline.split(" ",QString::SkipEmptyParts);
- #endif
- // qDebug("%d value size is %d ",i,strvaluedata.size());
- iv::lanepoint lpleft,lpright;
- if(strvaluedata.size() == 12)
- {
- int j;
- QString strx[12];
- for(j=0;j<12;j++)strx[j] = strvaluedata.at(j);
- lpleft.mfLon = strx[0].toDouble();
- lpleft.mfLat = strx[1].toDouble();
- lpleft.mfHeight = strx[2].toDouble();
- lpleft.nLaneType = strx[3].toInt();
- lpleft.mfHeading = strx[4].toDouble();
- lpleft.mfDis = strx[5].toDouble();
- lpright.mfLon = strx[6].toDouble();
- lpright.mfLat = strx[7].toDouble();
- lpright.mfHeight = strx[8].toDouble();
- lpright.nLaneType = strx[9].toInt();
- lpright.mfHeading = strx[10].toDouble();
- lpright.mfDis = strx[11].toDouble();
- lpleft.mfHdg = (90-lpleft.mfHeading) * M_PI/180.0;
- if(lpleft.mfHdg < 0)lpleft.mfHdg = lpleft.mfHdg + 2.0*M_PI;
- lpright.mfHdg = (90-lpright.mfHeading) * M_PI/180.0;
- if(lpright.mfHdg < 0)lpright.mfHdg = lpright.mfHdg + 2.0*M_PI;
- double x,y;
- double xlast,ylast;
- GaussProjCal(lpleft.mfLon,lpleft.mfLat,&x,&y);
- GaussProjCal(fLastLon,fLastLat,&xlast,&ylast);
- if(sqrt(pow(xlast -x ,2)+pow(ylast -y,2))> 0.1)
- {
- lpu.mvectorlpleft.push_back(lpleft);
- lpu.mvectorlpright.push_back(lpright);
- fLastLat = lpleft.mfLat;
- fLastLon = lpleft.mfLon;
- }
- else
- {
- // qDebug("no use this point");
- }
- }
- }
- if((mbSetOrigin == false)&&(lpu.mvectorlpleft.size() > 0))
- {
- glat0 = lpu.mvectorlpleft[0].mfLat;
- glon0 = lpu.mvectorlpright[0].mfLon;
- mpLELat0->setText(QString::number(glat0,'f',7));
- mpLELon0->setText(QString::number(glon0,'f',7));
- mbSetOrigin = true;
- }
- double x0,y0;
- GaussProjCal(glon0,glat0,&x0,&y0);
- int j;
- for(j=0;j<static_cast<int>( lpu.mvectorlpleft.size());j++)
- {
- double x,y;
- GaussProjCal(lpu.mvectorlpleft[j].mfLon,lpu.mvectorlpleft[j].mfLat,&x,&y);
- lpu.mvectorlpleft[j].mfX = x - x0;
- lpu.mvectorlpleft[j].mfY = y- y0;
- GaussProjCal(lpu.mvectorlpright[j].mfLon,lpu.mvectorlpright[j].mfLat,&x,&y);
- lpu.mvectorlpright[j].mfX = x - x0;
- lpu.mvectorlpright[j].mfY = y- y0;
- }
- if(lpu.mvectorlpleft.size() > 0)
- {
- mvectorlp.push_back(lpu);
- mpCBLane->addItem(filename);
- int N = lpu.mvectorlpleft.size();
- VectorXd x_veh(N);
- VectorXd y_veh(N);
- int j;
- int ntype = 0;
- int ntypecount = 1;
- for(j=0;j<N;j++)
- {
- double x,y;
- GaussProjCal(glon0,glat0,&x0,&y0);
- GaussProjCal(lpu.mvectorlpleft[j].mfLon,lpu.mvectorlpleft[j].mfLat,&x,&y);
- x_veh[j] = x - x0;
- y_veh[j] = y - y0;
- if(lpu.mvectorlpright[j].nLaneType != ntype)
- {
- ntype = lpu.mvectorlpright[j].nLaneType;
- ntypecount++;
- }
- }
- // CreateRoad(x_veh,y_veh);
- // auto coeffs = polyfit(x_veh, y_veh, 1);
- // double dismax = 0;
- // for(j=0;j<N;j++)
- // {
- // double A = coeffs[1];
- // double B = -1;
- // double C = coeffs[0];
- // double dis = fabs(A*x_veh[j] + B*y_veh[j] +C )/sqrt(pow(A,2)+pow(B,2));
- // if(dis>dismax)dismax = dis;
- // }
- // int nxxx = coeffs.size();
- }
- }
- xFile.close();
- mbRefresh = true;
- update();
- }
- /**
- * @brief MainWindow::CreateRoad
- * Create Road Geometry
- * @param xvals
- * @param yvals
- * @return
- */
- Road MainWindow::CreateRoad(VectorXd xvals, VectorXd yvals)
- {
- (void)xvals;
- (void)yvals;
- Road x;
- return x;
- }
- void MainWindow::onClickMarkLane()
- {
- mnMarkLane = mpCBLane->currentIndex();
- mbRefresh = true;
- update();
- }
- void MainWindow::onClickRemoveLane()
- {
- int i = mpCBLane->currentIndex();
- if((i>=0) && (i<static_cast<int>( mvectorlp.size())))
- {
- int j;
- for(j=0;j< static_cast<int>(mvectorroadlane.size());j++)
- {
- if(mvectorroadlane[j] == i)
- {
- mvectorroadlane.erase(mvectorroadlane.begin() + j);
- mpCBSelLane->removeItem(j);
- break;
- }
- }
- mvectorlp.erase(mvectorlp.begin() + i);
- mpCBLane->removeItem(i);
- mbRefresh = true;
- update();
- }
- }
- void MainWindow::onClickToRoad()
- {
- int i = mpCBLane->currentIndex();
- if((i>=0) && (i< static_cast<int>(mvectorlp.size())))
- {
- int j;
- bool bHave = false;
- for(j=0;j< static_cast<int>(mvectorroadlane.size());j++)
- {
- if(mvectorroadlane[j] == i)
- {
- bHave = true;
- break;
- }
- }
- if(bHave == false)
- {
- mvectorroadlane.push_back(i);
- mpCBSelLane->addItem(mvectorlp.at(i).strlanename);
- }
- }
- }
- void MainWindow::onClickToOpposite()
- {
- int i = mpCBLane->currentIndex();
- if((i>=0) && (i< static_cast<int>(mvectorlp.size())))
- {
- int j;
- bool bHave = false;
- for(j=0;j<static_cast<int>(mvectorroadopposite.size());j++)
- {
- if(mvectorroadopposite[j] == i)
- {
- bHave = true;
- break;
- }
- }
- if(bHave == false)
- {
- mvectorroadopposite.push_back(i);
- mpCBSelOpLane->addItem(mvectorlp.at(i).strlanename);
- }
- }
- }
- void MainWindow::onClickClearRoadLane()
- {
- mvectorroadlane.clear();
- mvectorroadopposite.clear();
- mpCBSelLane->clear();
- mpCBSelOpLane->clear();
- }
- void MainWindow::onClickAddRoad()
- {
- int nrtn;
- std::string strrtn = " ";
- std::string strroadname = mpLE_RoadName->text().toStdString();
- nrtn = ServiceXODRMake.AddRoadFromeLanePoint(mvectorlp,mvectorroadlane,mvectorroadopposite,glon0,
- glat0,mxodr,strroadname,strrtn);
- (void)nrtn;
- mpCBSelLane->clear();
- mpCBSelOpLane->clear();
- mvectorroadlane.clear();
- mvectorroadopposite.clear();
- updateCBRoad();
- mbRefresh = true;
- update();
- return;
- if(mvectorroadlane.size() < 1)return;
- int nlanesize = mvectorroadlane.size();
- int noplanesize = mvectorroadopposite.size();
- double notlinethresh = 1.0; //When heading change more than this value, is a arc.
- int nsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
- int * pntype = new int[nsize];
- std::shared_ptr<int> ppntype; ppntype.reset(pntype);
- std::vector<iv::lanepoint > * pvectorlp = &(mvectorlp[mvectorroadlane[0]].mvectorlpleft);
- int i;
- //Go throuh point for fit type.
- for(i=0;i<5;i++)pntype[i] = 0;
- for(i=5;i<(nsize-5);i++)
- {
- double s = pvectorlp->at(i).mfDis;
- double head0 = pvectorlp->at(i).mfHeading;
- int j;
- double xcount = 0;
- double headdifftotal = 0;
- double headdiffavg = 0.0;
- for(j=1;j<nsize;j++)
- {
- if((j>1)&&((pvectorlp->at(j).mfDis - s)>1.0))
- {
- break;
- }
- double headdiff = pvectorlp->at(j).mfHeading - head0;
- if(headdiff > 300)headdiff = headdiff - 360;
- if(headdiff < -300)headdiff = headdiff + 360;
- headdifftotal = headdifftotal + headdiff;
- xcount = xcount + 1.0;
- }
- if(xcount > 0)headdiffavg = headdifftotal/xcount;
- if(fabs(headdiffavg) > (notlinethresh*2))
- {
- pntype[i] = 1;
- }
- else
- {
- pntype[i] = 0;
- }
- }
- for(i=(nsize -5);i<nsize;i++)
- {
- pntype[i] = 0;
- }
- for(i=0;i<nsize;i++) //Remove Few Not Line Point.
- {
- if(pntype[i] != 0)
- {
- int j;
- int ncount = 1;
- for(j=(i+1);j<nsize;j++)
- {
- if(pntype[i] != 0)ncount++;
- else break;
- }
- if(ncount < 10)pntype[i] = 0;
- else
- {
- i = i+ ncount;
- }
- }
- }
- for(i=5;i<nsize;i++)
- {
- if(pntype[i] != pntype[i-1])
- {
- int j = i-1;
- double disx = pvectorlp->at(i).mfDis;
- for(j=(i-2);j>5;j--)
- {
- if(pntype[j] == pntype[i-1])
- {
- pntype[j] = 2; //Besel
- }
- if(fabs(pvectorlp->at(j).mfDis - disx)>1) //1 m besel
- {
- break;
- }
- }
- pntype[i-1] = 2;
- }
- }
- //Calc dis to ref line
- double xor0,yor0;
- GaussProjCal(glon0,glat0,&xor0,&yor0);
- std::vector<std::vector<iv::distogeo>> xvectordiss;
- std::vector<std::vector<iv::distogeo>> xvectoropdiss;
- for(i=0;i<static_cast<int>(mvectorroadlane.size());i++)
- {
- std::vector<iv::distogeo> xvectordistogeo;
- int j;
- int nsizepoint = mvectorlp[mvectorroadlane[i]].mvectorlpright.size();
- bool bHaveLast = false;
- int nLast = 0;
- for(j=0;j<nsizepoint;j++)
- {
- double fdismin = 1000;
- double fS = 0;
- int k;
- double x,y;
- double x0,y0;
- iv::distogeo xdistogeo;
- int nLastBig = 0;
- bool bFindDisMin = false;
- x = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfX;
- y = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfY;
- int kstart = 0;
- if(bHaveLast)
- {
- kstart= nLast;
- }
- for(k=kstart;k<static_cast<int>( mvectorlp[mvectorroadlane[0]].mvectorlpleft.size());k++)
- {
- x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
- y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
- double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
- if(fdismin > fdis)
- {
- fdismin = fdis;
- fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
- bFindDisMin = true;
- nLast = k;
- }
- if((bFindDisMin)&&(bHaveLast))
- {
- if(fdis>fdismin)
- {
- nLastBig++;
- }
- else
- {
- nLastBig = 0;
- }
- }
- if(nLastBig > 10)break;
- }
- // std::cout<<" k is "<<k<<std::endl;
- if(bHaveLast == false)
- {
- if(fdismin<10)bHaveLast = true;
- }
- else
- {
- if(fdismin > 10)bHaveLast = false;
- }
- double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
- mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
- double fHdgDiff = fHdg - mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfHdg;
- if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
- if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
- if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 3.2))
- {
- xdistogeo.mfdis = fdismin;
- xdistogeo.mfs = fS;
- mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS = fS;
- }
- else
- {
- xdistogeo.mfs = -1;
- std::cout<<"point extend."<<std::endl;
- mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS = -1;
- }
- xvectordistogeo.push_back(xdistogeo);
- }
- xvectordiss.push_back(xvectordistogeo);
- }
- for(i=1;i<static_cast<int>( mvectorroadlane.size());i++)
- {
- std::vector<iv::distogeo> xvectordistogeo;
- int j;
- int nsizepoint = mvectorlp[mvectorroadlane[i]].mvectorlpleft.size();
- bool bHaveLast = false;
- int nLast = 0;
- for(j=0;j<nsizepoint;j++)
- {
- double fdismin = 1000;
- double fS = 0;
- int k;
- double x,y;
- double x0,y0;
- iv::distogeo xdistogeo;
- int nLastBig = 0;
- bool bFindDisMin = false;
- x = mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfX;
- y = mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfY;
- int kstart = 0;
- if(bHaveLast)
- {
- kstart= nLast;
- }
- for(k=kstart;k<static_cast<int>( mvectorlp[mvectorroadlane[0]].mvectorlpleft.size());k++)
- {
- x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
- y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
- double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
- if(fdismin > fdis)
- {
- fdismin = fdis;
- fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
- bFindDisMin = true;
- nLast = k;
- }
- if((bFindDisMin)&&(bHaveLast))
- {
- if(fdis>fdismin)
- {
- nLastBig++;
- }
- else
- {
- nLastBig = 0;
- }
- }
- if(nLastBig > 10)break;
- }
- // std::cout<<" k is "<<k<<std::endl;
- if(bHaveLast == false)
- {
- if(fdismin<10)bHaveLast = true;
- }
- else
- {
- if(fdismin > 10)bHaveLast = false;
- }
- double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
- mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
- double fHdgDiff = fHdg - mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfHdg;
- if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
- if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
- if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 3.2))
- {
- xdistogeo.mfdis = fdismin;
- xdistogeo.mfs = fS;
- mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfRelS = fS;
- }
- else
- {
- xdistogeo.mfs = -1;
- std::cout<<"point extend."<<std::endl;
- mvectorlp[mvectorroadlane[i]].mvectorlpleft[j].mfRelS = -1;
- }
- xvectordistogeo.push_back(xdistogeo);
- }
- xvectordiss.push_back(xvectordistogeo);
- }
- for(i=0;i<static_cast<int>(mvectorroadopposite.size());i++)
- {
- std::vector<iv::distogeo> xvectordistogeo;
- int j;
- int nsizepoint = mvectorlp[mvectorroadopposite[i]].mvectorlpleft.size();
- bool bHaveLast = false;
- int nLast = 0;
- for(j=0;j<nsizepoint;j++)
- {
- double fdismin = 1000;
- double fS = 0;
- int k;
- double x,y;
- double x0,y0;
- iv::distogeo xdistogeo;
- int nLastBig = 0;
- bool bFindDisMin = false;
- x = mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfX;
- y = mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfY;
- int nrefsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
- int kstart = nrefsize-1;
- if(bHaveLast)
- {
- kstart= nLast;
- }
- for(k=kstart;k>=0;k--)
- {
- x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
- y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
- double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
- if(fdismin > fdis)
- {
- fdismin = fdis;
- fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
- bFindDisMin = true;
- nLast = k;
- }
- if((bFindDisMin)&&(bHaveLast))
- {
- if(fdis>fdismin)
- {
- nLastBig++;
- }
- else
- {
- nLastBig = 0;
- }
- }
- if(nLastBig > 10)break;
- }
- // std::cout<<" k is "<<k<<std::endl;
- if(bHaveLast == false)
- {
- if(fdismin<10)bHaveLast = true;
- }
- else
- {
- if(fdismin > 10)bHaveLast = false;
- }
- double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
- mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
- double fHdgDiff = fHdg - mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfHdg;
- if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
- if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
- if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 0.5))
- {
- xdistogeo.mfdis = fdismin;
- xdistogeo.mfs = fS;
- mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfRelS = fS;
- }
- else
- {
- xdistogeo.mfs = -1;
- std::cout<<"point extend."<<std::endl;
- mvectorlp[mvectorroadopposite[i]].mvectorlpleft[j].mfRelS = -1;
- }
- xvectordistogeo.push_back(xdistogeo);
- }
- xvectoropdiss.push_back(xvectordistogeo);
- }
- for(i=0;i<static_cast<int>(mvectorroadopposite.size());i++)
- {
- std::vector<iv::distogeo> xvectordistogeo;
- int j;
- int nsizepoint = mvectorlp[mvectorroadopposite[i]].mvectorlpright.size();
- bool bHaveLast = false;
- int nLast = 0;
- for(j=0;j<nsizepoint;j++)
- {
- double fdismin = 1000;
- double fS = 0;
- int k;
- double x,y;
- double x0,y0;
- iv::distogeo xdistogeo;
- int nLastBig = 0;
- bool bFindDisMin = false;
- x = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfX;
- y = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfY;
- int nrefsize = mvectorlp[mvectorroadlane[0]].mvectorlpleft.size();
- int kstart = nrefsize-1;
- if(bHaveLast)
- {
- kstart= nLast;
- }
- for(k=kstart;k>=0;k--)
- {
- x0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfX;
- y0 = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfY;
- double fdis = sqrt(pow(x-x0,2)+pow(y-y0,2));
- if(fdismin > fdis)
- {
- fdismin = fdis;
- fS = mvectorlp[mvectorroadlane[0]].mvectorlpleft[k].mfDis;
- bFindDisMin = true;
- nLast = k;
- }
- if((bFindDisMin)&&(bHaveLast))
- {
- if(fdis>fdismin)
- {
- nLastBig++;
- }
- else
- {
- nLastBig = 0;
- }
- }
- if(nLastBig > 10)break;
- }
- // std::cout<<" k is "<<k<<std::endl;
- if(bHaveLast == false)
- {
- if(fdismin<10)bHaveLast = true;
- }
- else
- {
- if(fdismin > 10)bHaveLast = false;
- }
- double fHdg = geofit::CalcHdg(x,y,mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfX,
- mvectorlp[mvectorroadlane[0]].mvectorlpleft[nLast].mfY);
- double fHdgDiff = fHdg - mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfHdg;
- if(fHdgDiff < 0)fHdgDiff = fHdgDiff + 2.0*M_PI;
- if(fHdgDiff >= 2.0*M_PI)fHdgDiff = fHdgDiff - 2.0*M_PI;
- if(((fHdgDiff>(M_PI/2.0-0.3))&&(fHdgDiff<(M_PI/2.0+0.3)))||(fdismin < 0.5))
- {
- xdistogeo.mfdis = fdismin;
- xdistogeo.mfs = fS;
- mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS = fS;
- }
- else
- {
- xdistogeo.mfs = -1;
- std::cout<<"point extend."<<std::endl;
- mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS = -1;
- }
- xvectordistogeo.push_back(xdistogeo);
- }
- xvectoropdiss.push_back(xvectordistogeo);
- }
- //Get Lane Type
- std::vector<std::vector<iv::lanetype>> xvevelanetype;
- std::vector<std::vector<iv::lanetype>> xvectoroplanetype;
- for(i=0;i<nlanesize;i++)
- {
- std::vector<iv::lanetype> xvelanetype;
- int j;
- int nlasttype;
- iv::lanetype xlt;
- xlt.s = 0;
- xlt.ntype = 0;
- int nsizelp = mvectorlp[mvectorroadlane[i]].mvectorlpright.size();
- if(nsizelp > 0)
- {
- xlt.ntype = mvectorlp[mvectorroadlane[i]].mvectorlpright[0].nLaneType;
- nlasttype = xlt.ntype;
- }
- for(j=1;j<nsizelp;j++)
- {
- int nlt = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].nLaneType;
- if((nlt != nlasttype)&&(mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS != -1))
- {
- xvelanetype.push_back(xlt);
- xlt.ntype = nlt;
- xlt.s = mvectorlp[mvectorroadlane[i]].mvectorlpright[j].mfRelS;
- }
- nlasttype = nlt;
- }
- xvelanetype.push_back(xlt);
- xvevelanetype.push_back(xvelanetype);
- }
- for(i=0;i<noplanesize;i++)
- {
- std::vector<iv::lanetype> xvelanetype;
- int j;
- int nlasttype;
- iv::lanetype xlt;
- xlt.s = 0;
- xlt.ntype = 0;
- int nsizelp = mvectorlp[mvectorroadopposite[i]].mvectorlpright.size();
- if(nsizelp > 0)
- {
- xlt.ntype = mvectorlp[mvectorroadopposite[i]].mvectorlpright[nsizelp-1].nLaneType;
- nlasttype = xlt.ntype;
- }
- for(j=(nsizelp-2);j>=0;j--)
- {
- int nlt = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].nLaneType;
- if((nlt != nlasttype)&&(mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS != -1))
- {
- xvelanetype.push_back(xlt);
- xlt.ntype = nlt;
- xlt.s = mvectorlp[mvectorroadopposite[i]].mvectorlpright[j].mfRelS;
- }
- nlasttype = nlt;
- }
- xvelanetype.push_back(xlt);
- xvectoroplanetype.push_back(xvelanetype);
- }
- //Get Lane Mark Width
- std::vector<double> xvectormarkwidth;
- std::vector<double> xvectoravgdis;
- for(i=0;i< static_cast<int>(xvectordiss.size());i++)
- {
- double fdis = 0;
- int j;
- int ncount = 0;
- for(j=0;j<static_cast<int>(xvectordiss[i].size());j++)
- {
- if(xvectordiss[i].at(j).mfs != -1)
- {
- fdis = fdis + xvectordiss[i].at(j).mfdis;
- ncount++;
- }
- }
- if(ncount>0)fdis = fdis/ncount;
- xvectoravgdis.push_back(fdis);
- }
- for(i=1;i<static_cast<int>(mvectorroadlane.size());i++)
- {
- xvectormarkwidth.push_back(xvectoravgdis[mvectorroadlane.size()+i-1] - xvectoravgdis[i-1]);
- }
- std::vector<double> xvectoropmarkwidth;
- std::vector<double> xvectoropavgdis;
- for(i=0;i<static_cast<int>(xvectoropdiss.size());i++)
- {
- double fdis = 0;
- int j;
- int ncount = 0;
- int nsize = xvectoropdiss[i].size();
- for(j=0;j<nsize;j++)
- {
- if(xvectoropdiss[i].at(j).mfs != -1)
- {
- fdis = fdis + xvectoropdiss[i].at(j).mfdis;
- ncount++;
- }
- }
- if(ncount>0)fdis = fdis/ncount;
- xvectoropavgdis.push_back(fdis);
- }
- if(xvectoropavgdis.size()>0)xvectoropmarkwidth.push_back(xvectoropavgdis[0]);
- for(i=1;i<static_cast<int>(mvectorroadopposite.size());i++)
- {
- xvectoropmarkwidth.push_back(xvectoropavgdis[i] - xvectoropavgdis[i+mvectorroadopposite.size()-1]);
- }
- //Get Lane Width
- std::vector<std::vector<iv::distogeo>> xvectorlanewidth;
- std::vector<std::vector<iv::distogeo>> xvectoroplanewidth;
- std::vector<iv::distogeo> xlanewidth;
- xlanewidth.clear();
- int j;
- for(j=0;j<static_cast<int>(xvectordiss[0].size());j++)
- {
- if(xvectordiss[0].at(j).mfs != -1)xlanewidth.push_back(xvectordiss[0].at(j));
- }
- xvectorlanewidth.push_back(xlanewidth);
- for(i=1;i<static_cast<int>(mvectorroadlane.size());i++)
- {
- xlanewidth.clear();
- for(j=0;j<static_cast<int>(xvectordiss[i].size());j++)
- {
- if((xvectordiss[i].at(j).mfs!=-1)&&(xvectordiss[i-1+nlanesize].at(j).mfs!=-1))
- {
- iv::distogeo xdisg;
- xdisg = xvectordiss[i].at(j);
- xdisg.mfdis = xdisg.mfdis - xvectordiss[i-1+nlanesize].at(j).mfdis + xvectormarkwidth[i-1];
- xlanewidth.push_back(xdisg);
- }
- }
- xvectorlanewidth.push_back(xlanewidth);
- }
- xlanewidth.clear();
- if(xvectoropmarkwidth.size()>0)
- {
- if(xvectoropmarkwidth[0] > 0.4)
- {
- int nsize = xvectoropdiss[0].size();
- for(j=0;j<nsize;j++)
- {
- if(xvectoropdiss[0].at(j).mfs != -1)xlanewidth.push_back(xvectoropdiss[0].at(j));
- }
- xvectoroplanewidth.push_back(xlanewidth);
- xlanewidth.clear();
- nsize = xvectoropdiss[noplanesize].size();
- for(j=0;j<nsize;j++)
- {
- if((xvectoropdiss[noplanesize].at(j).mfs!=-1)&&(xvectoropdiss[0].at(j).mfs!=-1))
- {
- iv::distogeo xdisg;
- xdisg = xvectoropdiss[noplanesize].at(j);
- xdisg.mfdis = xdisg.mfdis - xvectoropdiss[0].at(j).mfdis ;
- xlanewidth.push_back(xdisg);
- }
- }
- xvectoroplanewidth.push_back(xlanewidth);
- }
- else
- {
- nsize = xvectoropdiss[noplanesize].size();
- for(j=0;j<nsize;j++)
- {
- if((xvectoropdiss[noplanesize].at(j).mfs!=-1)&&(xvectoropdiss[0].at(j).mfs!=-1))
- {
- iv::distogeo xdisg;
- xdisg = xvectoropdiss[noplanesize].at(j);
- xdisg.mfdis = xdisg.mfdis - xvectoropdiss[0].at(j).mfdis + xvectoropmarkwidth[0];
- xlanewidth.push_back(xdisg);
- }
- }
- xvectoroplanewidth.push_back(xlanewidth);
- }
- for(i=1;i<noplanesize;i++)
- {
- xlanewidth.clear();
- nsize = xvectoropdiss[noplanesize+i].size();
- for(j=0;j<nsize;j++)
- {
- if((xvectoropdiss[noplanesize+i].at(j).mfs != -1)&&(xvectoropdiss[i].at(j).mfs != -1))
- {
- iv::distogeo xdisg;
- xdisg = xvectoropdiss[noplanesize+i].at(j);
- xdisg.mfdis = xdisg.mfdis - xvectoropdiss[i].at(j).mfdis + xvectoropmarkwidth[i];
- xlanewidth.push_back(xdisg);
- }
- }
- xvectoroplanewidth.push_back(xlanewidth);
- }
- }
- std::vector<iv::lanecoff> xvectorlanecoff;
- std::vector<iv::lanecoff> xvectoroplanecoff;
- for(i=0;i<nlanesize;i++)
- {
- int N = xvectorlanewidth[i].size();
- VectorXd x_veh(N);
- VectorXd y_veh(N);
- for(j=0;j<N;j++)
- {
- x_veh[j] = xvectorlanewidth[i].at(j).mfs;
- y_veh[j] =xvectorlanewidth[i].at(j).mfdis;
- }
- VectorXd coeffs = polyfit(x_veh, y_veh, 3);
- iv::lanecoff xlanecoff;
- xlanecoff.A = coeffs[0];
- xlanecoff.B = coeffs[1];
- xlanecoff.C = coeffs[2];
- xlanecoff.D = coeffs[3];
- xvectorlanecoff.push_back(xlanecoff);
- }
- for(i=0;i< static_cast<int>(xvectoroplanewidth.size());i++)
- {
- int N = xvectoroplanewidth[i].size();
- VectorXd x_veh(N);
- VectorXd y_veh(N);
- for(j=0;j<N;j++)
- {
- x_veh[j] = xvectoroplanewidth[i].at(j).mfs;
- y_veh[j] =xvectoroplanewidth[i].at(j).mfdis;
- }
- VectorXd coeffs = polyfit(x_veh, y_veh, 3);
- iv::lanecoff xlanecoff;
- xlanecoff.A = coeffs[0];
- xlanecoff.B = coeffs[1];
- xlanecoff.C = coeffs[2];
- xlanecoff.D = coeffs[3];
- xvectoroplanecoff.push_back(xlanecoff);
- }
- iv::lanecoff xlaneheightcoff;
- int M = mvectorlp[0].mvectorlpleft.size();
- VectorXd x_vehhg(M);
- VectorXd y_vehhg(M);
- for(j=0;j<M;j++)
- {
- x_vehhg[j] = mvectorlp[0].mvectorlpleft.at(j).mfDis;
- y_vehhg[j] =mvectorlp[0].mvectorlpleft.at(j).mfHeight;
- }
- VectorXd coeffs = polyfit(x_vehhg, y_vehhg, 3);
- xlaneheightcoff.A = coeffs[0];
- xlaneheightcoff.B = coeffs[1];
- xlaneheightcoff.C = coeffs[2];
- xlaneheightcoff.D = coeffs[3];
- geofit xgeofit;
- int N = pvectorlp->size();
- VectorXd x_veh(N);
- VectorXd y_veh(N);
- VectorXi t_veh(N);
- double x0,y0;
- GaussProjCal(glon0,glat0,&x0,&y0);
- for(j=0;j<N;j++)
- {
- double x,y;
- GaussProjCal(pvectorlp->at(j).mfLon,pvectorlp->at(j).mfLat,&x,&y);
- x_veh[j] = x - x0;
- y_veh[j] = y - y0;
- t_veh[j] = pntype[j];
- }
- std::vector<geobase> xvectorgeo = xgeofit.getgeo(x_veh,y_veh,t_veh);
- // OpenDrive od;
- // std::string mapx = "map";
- // od.SetHeader(1,1,mapx,1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
- j= 0;
- double xroadlen = 0;
- for(j=0;j<static_cast<int>(xvectorgeo.size());j++)
- {
- xroadlen = xroadlen + xvectorgeo[j].mfLen;
- }
- mxodr.AddRoad(mpLE_RoadName->text().toLatin1().data(),xroadlen, QString::number(CreateRoadID()).toStdString(),"-1");
- Road * p = mxodr.GetRoad(mxodr.GetRoadCount() - 1);
- p->AddElevation(0,xlaneheightcoff.A,xlaneheightcoff.B,xlaneheightcoff.C,xlaneheightcoff.D);
- double s = 0;
- j= 0;
- // for(j=0;j<4;j++)
- for(j=0;j<static_cast<int>( xvectorgeo.size());j++)
- {
- p->AddGeometryBlock();
- GeometryBlock * pgb = p->GetGeometryBlock(j);
- geobase * pline;
- geobase * pbez;
- geobase * parc;
- switch(xvectorgeo[j].mnType)
- {
- case 0:
- pline = &xvectorgeo[j];
- pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
- break;
- case 1:
- parc = &xvectorgeo[j];
- pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
- break;
- case 2:
- pbez = &xvectorgeo[j];
- std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
- pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
- pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
- pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
- pbez->mfv[1],pbez->mfv[2],pbez->mfv[3]);
- break;
- }
- s = s + xvectorgeo[j].mfLen;
- }
- p->AddLaneSection(0);
- LaneSection * pLS = p->GetLaneSection(0);
- Lane * pLL;
- pLS->SetS(0);
- pLS->AddLane(0,0,"none",false);
- pLL = pLS->GetLane(0);
- if(noplanesize != static_cast<int>(xvectoroplanewidth.size()))
- {
- pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- for(i=0;i<nlanesize;i++)
- {
- pLS->AddLane(-1,(i+1)*(-1),"driving",false,false);
- pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,xvectorlanecoff[i].A,xvectorlanecoff[i].B,
- xvectorlanecoff[i].C,xvectorlanecoff[i].D);
- int j;
- for(j=0;j<static_cast<int>(xvevelanetype[i].size());j++)
- {
- std::string strlanetype = "broken";
- if(xvevelanetype[i].at(j).ntype != 0)
- {
- strlanetype = "solid";
- }
- pLL->AddRoadMarkRecord(xvevelanetype[i].at(j).s,strlanetype,"standard","standard",0.15,"false");
- }
- }
- for(i=0;i<static_cast<int>(xvectoroplanewidth.size());i++)
- {
- pLS->AddLane(1,(i+1)*(1),"driving",false,false);
- pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
- if((i==0)&&(noplanesize != static_cast<int>(xvectoroplanewidth.size())))
- {
- pLL->SetType("shoulder");
- pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- pLL->AddWidthRecord(0,xvectoroplanecoff[i].A,xvectoroplanecoff[i].B,
- xvectoroplanecoff[i].C,xvectoroplanecoff[i].D);
- int j;
- int index = i;
- if((i==0)&&(noplanesize != static_cast<int>(xvectoroplanewidth.size())))
- {
- continue;
- }
- if(noplanesize != static_cast<int>(xvectoroplanewidth.size()))
- {
- index = i-1;
- }
- else
- index = i;
- for(j=0;j<static_cast<int>(xvectoroplanetype[index].size());j++)
- {
- std::string strlanetype = "broken";
- if(xvectoroplanetype[index].at(j).ntype != 0)
- {
- strlanetype = "solid";
- }
- pLL->AddRoadMarkRecord(xvectoroplanetype[index].at(j).s,strlanetype,"standard","standard",0.15,"false");
- }
- }
- mpCBSelLane->clear();
- mpCBSelOpLane->clear();
- mvectorroadlane.clear();
- mvectorroadopposite.clear();
- updateCBRoad();
- mbRefresh = true;
- update();
- }
- int MainWindow::CreateRoadID(int ntype)
- {
- int i;
- bool bUsed = false;
- int nroadidstart = 10000;
- if(ntype == 1) //not create by lane roaid
- {
- nroadidstart = 20000;
- }
- int nroadcount = mxodr.GetRoadCount();
- if(nroadcount == 0)return nroadidstart;
- int * proadid = new int[nroadcount];
- for(i=0;i<nroadcount;i++)
- {
- proadid[i]=atoi(mxodr.GetRoad(i)->GetRoadId().data());
- }
- do
- {
- bUsed = false;
- for(i=0;i<nroadcount;i++)
- {
- if(proadid[i] == nroadidstart)
- {
- nroadidstart++;
- bUsed = true;
- }
- }
- }while(bUsed);
- delete [] proadid;
- return nroadidstart;
- }
- int MainWindow::CreateJunctionID()
- {
- int i;
- bool bUsed = false;
- int njunctionidstart = 800000;
- int njunctioncount = mxodr.GetJunctionCount();
- if(njunctioncount == 0)return njunctionidstart;
- int * pjunctionid = new int[njunctioncount];
- for(i=0;i<njunctioncount;i++)
- {
- pjunctionid[i]=atoi(mxodr.GetJunction(i)->GetId().data());
- }
- do
- {
- bUsed = false;
- for(i=0;i<njunctioncount;i++)
- {
- if(pjunctionid[i] == njunctionidstart)
- {
- njunctionidstart++;
- bUsed = true;
- }
- }
- }while(bUsed);
- delete []pjunctionid;
- return njunctionidstart;
- }
- static bool IsNaN(double dat)
- {
- qint64 & ref=*(qint64 *)&dat;
- return (ref&0x7FF0000000000000) == 0x7FF0000000000000 && (ref&0xfffffffffffff)!=0;
- }
- void MainWindow::onClickLoad()
- {
- QString str = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
- if(str.isEmpty())return;
- mvectorhideroadid.clear();
- QString strfilepath = str;
- QString strbak = str + ".bak";
- QFileInfo fileback(strbak);
- if(fileback.exists())
- {
- QMessageBox::StandardButton button;
- // button=QMessageBox::question(this,tr("恢复备份"),QString(tr("上次为非正常退出,是否从备份文件导入?")),QMessageBox::Yes|QMessageBox::No);
- 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);
- if(button==QMessageBox::No)
- {
- }
- else if(button==QMessageBox::Yes)
- {
- str = strbak;
- }
- }
- OpenDrive * pxodr = new OpenDrive(); //because add to xodr,so don't delete
- OpenDriveXmlParser x(pxodr);
- if(!x.ReadFile(str.toStdString()))
- {
- QMessageBox::warning(this,"warn","Can't load xodr file.");
- return;
- }
- int nroadnum = pxodr->GetRoadCount();
- int i;
- for(i=0;i<nroadnum;i++)
- {
- Road * pRoad = pxodr->GetRoad(i);
- if(IsNaN(pRoad->GetRoadLength()))
- {
- pxodr->DeleteRoad(i);
- i--;
- nroadnum--;
- qDebug("delete road %s because length is NaN",pRoad->GetRoadId().data());
- continue;
- }
- unsigned int j;
- double snow = 0;
- double roadcalclen = 0;
- for(j=0;j<pRoad->GetGeometryBlockCount();j++)
- {
- if(fabs(pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->GetS() - snow)>0.1)
- {
- std::cout<<"change road "<<pRoad->GetRoadId().data()<<" S"<<std::endl;
- pRoad->GetGeometryBlock(j)->GetGeometryAt(0)->SetS(snow);
- }
- snow = snow + pRoad->GetGeometryBlock(j)->GetBlockLength();
- roadcalclen = snow;
- }
- if(fabs(roadcalclen - pRoad->GetRoadLength())>0.1)
- {
- std::cout<<"change road "<<pRoad->GetRoadId().data()<<" Length"<<std::endl;
- pRoad->SetRoadLength(roadcalclen);
- }
- }
- bool bNeedMove = false;
- bool bNeedAjustID = false;
- unsigned short int revMajor,revMinor;
- std::string name,date;
- float version;
- double north,south,east,west,lat0,lon0,hdg0;
- if(pxodr->GetHeader() != 0)
- {
- pxodr->GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
- // mxodr.SetHeader(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
- // std::string strgeoref;
- // std::string struserData;
- // pxodr->GetHeader()->GetgeoReference(strgeoref);
- // pxodr->GetHeader()->GetuserData(struserData);
- // mxodr.GetHeader()->SetgeoReference(strgeoref);
- // mxodr.GetHeader()->SetuserData(struserData);
- }
- else
- {
- lat0 = 39.0;
- lon0 = 119.0;
- }
- double xMoveX = 0;
- double xMoveY = 0;
- bool bAddToNow = false;
- if(mxodr.GetRoadCount() > 0)
- {
- QMessageBox::StandardButton button;
- // button=QMessageBox::question(this,tr("载入模式"),QString(tr("附加到当前地图?")),QMessageBox::Yes|QMessageBox::No);
- button=QMessageBox::question(this,tr("Load Mode"),QString(tr("Add on Current Map?")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- bAddToNow = false;
- }
- else if(button==QMessageBox::Yes)
- {
- bAddToNow = true;
- }
- }
- if(bAddToNow )bNeedAjustID = true;
- if(bAddToNow == false)
- {
- mbSetOrigin = false;
- }
- if(mbSetOrigin == false)
- {
- bNeedMove = false;
- glat0 = lat0;
- glon0 = lon0;
- mpLELon0->setText(QString::number(glon0,'f',7));
- mpLELat0->setText(QString::number(glat0,'f',7));
- mbSetOrigin = true;
- }
- else
- {
- if((glat0 == lat0)&&(glon0 == lon0))
- {
- bNeedMove = false;
- }
- else
- {
- bNeedMove = true;
- double x0,y0,x1,y1;
- GaussProjCal(glon0,glat0,&x0,&y0);
- GaussProjCal(lon0,lat0,&x1,&y1);
- xMoveX = x1 - x0;
- xMoveY = y1 - y0;
- }
- }
- if(bNeedMove)
- {
- MoveXODR(pxodr,xMoveX,xMoveY);
- }
- int noldroadcount = mxodr.GetRoadCount();
- int noldjunctioncount = mxodr.GetJunctionCount();
- int nnewcount = pxodr->GetRoadCount();
- int nnewjunctioncount = pxodr->GetJunctionCount();
- // int i;
- if(bNeedAjustID)
- {
- for(i=0;i<nnewcount;i++)
- {
- int nid = atoi(pxodr->GetRoad(i)->GetRoadId().data());
- int j;
- bool bNeedChange = false;
- for(j=0;j<noldroadcount;j++)
- {
- if(nid == atoi(mxodr.GetRoad(j)->GetRoadId().data()))
- {
- bNeedChange = true;
- break;
- }
- }
- if(bNeedChange)
- {
- int nnewid = FindNewRoadID(&mxodr,pxodr);
- ChangeXODRRoadID(pxodr,i,nnewid);
- }
- }
- for(i=0;i<nnewjunctioncount;i++)
- {
- int nid = atoi(pxodr->GetJunction(i)->GetId().data());
- int j;
- bool bNeedChange = false;
- for(j=0;j<noldjunctioncount;j++)
- {
- if(nid == atoi(mxodr.GetJunction(j)->GetId().data()))
- {
- bNeedChange = true;
- break;
- }
- }
- if(bNeedChange)
- {
- int nnewid = FindNewJunctionID(&mxodr,pxodr);
- ChangeXODRJunctionID(pxodr,i,nnewid);
- }
- }
- }
- if(bAddToNow)
- {
- for(i=0;i<nnewcount;i++)
- {
- mxodr.GetRoadVector()->push_back(pxodr->GetRoadVector()->at(i));
- // OpenDrive * px = &mxodr;
- }
- for(i=0;i<nnewjunctioncount;i++)
- {
- mxodr.GetJunctionVector()->push_back(pxodr->GetJunctionVector()->at(i));
- }
- if((mxodr.GetRoadCount()>0)&&(mxodr.GetHeader() == 0))
- mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
- }
- else
- {
- mxodr = *pxodr;
- }
- updateCBRoad();
- updateJunction();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mpfb->Activate(strfilepath);
- delete pxodr;
- }
- void MainWindow::onClickSave()
- {
- QString str = QFileDialog::getSaveFileName(this,"Save XODR",".","*.xodr");
- if(str.isEmpty())return;
- if(str.indexOf(".xodr")<0)str = str + ".xodr";
- if(mxodr.GetHeader() == NULL)
- {
- mxodr.SetHeader(1,1,"adcmap",1.1,QDateTime::currentDateTime().toString("yyyy-MM-dd").toLatin1().data(),0,0,0,0,glat0,glon0,ghdg0);
- mxodr.GetHeader()->SetVendor("adc");
- }
- else
- {
- mxodr.GetHeader()->SetVendor("adc");
- }
- OpenDriveXmlWriter x(&mxodr);
- x.WriteFile(str.toStdString());
- mnNotSave = 0;
- mpfb->Activate(str);
- }
- void MainWindow::onClickAutoRoadContact()
- {
- int ch1,ch2;
- ch1 = mpCBRoad1->currentIndex();
- ch2 = mpCBRoad2->currentIndex();
- if((ch1 == -1)||(ch2 == -1))
- {
- return;
- }
- // if(ch1 == ch2)
- // {
- // QMessageBox::warning(this,"warn","road same");
- // return;
- // }
- int ntype1,ntype2;
- ntype1 = mpCBRC1->currentIndex();
- ntype2 = mpCBRC2->currentIndex();
- (void)ntype1; (void)ntype2;
- Road * p1 = mxodr.GetRoad(ch1);
- Road * p2 = mxodr.GetRoad(ch2);
- int contactype;
- int turnstraight;
- std::vector<iv::ARC> xARCLane,xARCOpLane;
- int nARCRtn = AutoRoadContact::CalcContact(p1,p2,contactype,turnstraight,xARCLane,xARCOpLane);
- if(nARCRtn < 0)
- {
- QMessageBox::warning(this,"Warning","Auto Road Contact fail",QMessageBox::YesAll);
- return;
- }
- switch (contactype) {
- case 0:
- mpCBRC1->setCurrentIndex(0);
- mpCBRC2->setCurrentIndex(0);
- break;
- case 1:
- mpCBRC1->setCurrentIndex(0);
- mpCBRC2->setCurrentIndex(1);
- break;
- case 2:
- mpCBRC1->setCurrentIndex(1);
- mpCBRC2->setCurrentIndex(0);
- break;
- case 3:
- mpCBRC1->setCurrentIndex(1);
- mpCBRC2->setCurrentIndex(1);
- break;
- default:
- break;
- }
- ntype1 = mpCBRC1->currentIndex();
- ntype2 = mpCBRC2->currentIndex();
- iv::roadcontact rc;
- rc.mnroad1id = atoi(p1->GetRoadId().data());
- rc.mnroad2id = atoi(p2->GetRoadId().data());
- rc.mncon1 = ntype1;
- rc.mncon2 = ntype2;
- char strname[256];
- if(xARCLane.size()>0)
- {
- snprintf(strname,256,"%s_%s_%s_%s",p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data(),
- p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data());
- }
- else
- {
- xARCLane = xARCOpLane;
- xARCOpLane.clear();
- rc.mnroad2id = atoi(p1->GetRoadId().data());
- rc.mnroad1id = atoi(p2->GetRoadId().data());
- rc.mncon2 = ntype1;
- rc.mncon1 = ntype2;
- snprintf(strname,256,"%s_%s_%s_%s",p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data(),
- p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data());
- }
- mpCBRoadCon->clear();
- mpCBRoadCon->addItem(strname);
- mpCBLane1->clear();
- mpCBLane2->clear();
- mpCBLane1Lane2->clear();
- mpCBLane1Lane2op->clear();
- if(p1->GetLaneSectionCount()>0)
- {
- LaneSection * pLS;
- if(ntype1 == 0)
- pLS = p1->GetLaneSection(0);
- else
- pLS = p1->GetLaneSection(p1->GetLaneSectionCount()-1);
- int i;
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
- if(pL->GetId() != 0)
- mpCBLane1->addItem(QString::number(pL->GetId()));
- }
- }
- if(p2->GetLaneSectionCount()>0)
- {
- LaneSection * pLS;
- if(ntype1 == 0)
- pLS = p2->GetLaneSection(0);
- else
- pLS = p2->GetLaneSection(p2->GetLaneSectionCount()-1);
- int i;
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
- if(pL->GetId() != 0)
- mpCBLane2->addItem(QString::number(pL->GetId()));
- }
- }
- mvectorrc.clear();
- mvectorrc.push_back(rc);
- mpCBRoadType->setCurrentIndex(turnstraight);
- unsigned int i;
- for(i=0;i<xARCLane.size();i++)
- {
- iv::lanecontact xlc;
- xlc.ml1 = xARCLane.at(i).from;
- xlc.ml2 = xARCLane.at(i).to;
- if(mvectorrc.size() < 1)break;
- mvectorrc[0].mvectorlc.push_back(xlc);
- char strname[256];
- snprintf(strname,255,"%dto%d",xlc.ml1,xlc.ml2);
- mpCBLane1Lane2->addItem(strname);
- }
- for(i=0;i<xARCOpLane.size();i++)
- {
- iv::lanecontact xlc;
- xlc.ml1 = xARCOpLane.at(i).from;
- xlc.ml2 = xARCOpLane.at(i).to;
- if(mvectorrc.size() < 1)break;
- mvectorrc[0].mvectorlcop.push_back(xlc);
- char strname[256];
- snprintf(strname,255,"%dto%d",xlc.ml1,xlc.ml2);
- mpCBLane1Lane2op->addItem(strname);
- }
- }
- void MainWindow::onClickRoadContact()
- {
- int ch1,ch2;
- ch1 = mpCBRoad1->currentIndex();
- ch2 = mpCBRoad2->currentIndex();
- if((ch1 == -1)||(ch2 == -1))
- {
- return;
- }
- // if(ch1 == ch2)
- // {
- // QMessageBox::warning(this,"warn","road same");
- // return;
- // }
- int ntype1,ntype2;
- ntype1 = mpCBRC1->currentIndex();
- ntype2 = mpCBRC2->currentIndex();
- Road * p1 = mxodr.GetRoad(ch1);
- Road * p2 = mxodr.GetRoad(ch2);
- iv::roadcontact rc;
- rc.mnroad1id = atoi(p1->GetRoadId().data());
- rc.mnroad2id = atoi(p2->GetRoadId().data());
- rc.mncon1 = ntype1;
- rc.mncon2 = ntype2;
- char strname[256];
- snprintf(strname,256,"%s_%s_%s_%s",p1->GetRoadId().data(),mpCBRC1->currentText().toLatin1().data(),
- p2->GetRoadId().data(),mpCBRC2->currentText().toLatin1().data());
- mpCBRoadCon->clear();
- mpCBRoadCon->addItem(strname);
- mpCBLane1->clear();
- mpCBLane2->clear();
- mpCBLane1Lane2->clear();
- mpCBLane1Lane2op->clear();
- if(p1->GetLaneSectionCount()>0)
- {
- LaneSection * pLS;
- if(ntype1 == 0)
- pLS = p1->GetLaneSection(0);
- else
- pLS = p1->GetLaneSection(p1->GetLaneSectionCount()-1);
- int i;
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
- if(pL->GetId() != 0)
- mpCBLane1->addItem(QString::number(pL->GetId()));
- }
- }
- if(p2->GetLaneSectionCount()>0)
- {
- LaneSection * pLS;
- if(ntype1 == 0)
- pLS = p2->GetLaneSection(0);
- else
- pLS = p2->GetLaneSection(p2->GetLaneSectionCount()-1);
- int i;
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- // if((pL->GetId() != 0)&&(strncmp(pL->GetType().data(),"driving",255)==0))
- if(pL->GetId() != 0)
- mpCBLane2->addItem(QString::number(pL->GetId()));
- }
- }
- mvectorrc.clear();
- mvectorrc.push_back(rc);
- }
- void MainWindow::onClickLaneContact()
- {
- int n1,n2;
- n1 = mpCBLane1->currentText().toInt();
- n2 = mpCBLane2->currentText().toInt();
- iv::lanecontact xlc;
- xlc.ml1 = n1;
- xlc.ml2 = n2;
- if(mvectorrc.size() < 1)return;
- mvectorrc[0].mvectorlc.push_back(xlc);
- char strname[256];
- snprintf(strname,255,"%dto%d",n1,n2);
- mpCBLane1Lane2->addItem(strname);
- }
- void MainWindow::onClickOpLaneContact()
- {
- int n1,n2;
- n1 = mpCBLane1->currentText().toInt();
- n2 = mpCBLane2->currentText().toInt();
- iv::lanecontact xlc;
- xlc.ml1 = n1;
- xlc.ml2 = n2;
- if(mvectorrc.size() < 1)return;
- mvectorrc[0].mvectorlcop.push_back(xlc);
- char strname[256];
- snprintf(strname,255,"%dto%d",n1,n2);
- mpCBLane1Lane2op->addItem(strname);
- }
- void MainWindow::onClickClearLaneContact()
- {
- mpCBLane1Lane2op->clear();
- mpCBLane1Lane2->clear();
- if(mvectorrc.size()<1)return;
- mvectorrc[0].mvectorlc.clear();
- mvectorrc[0].mvectorlcop.clear();
- }
- void MainWindow::onClickCreateRoad()
- {
- if(mvectorrc.size()<1)return;
- SaveBack();
- Road * p1, *p2;
- int nroad1index;
- int nroad2index;
- // p1 = mvectorrc[0].mp1;
- // p2 = mvectorrc[0].mp2;
- int i;
- bool bhavep1 = false;
- bool bhavep2 = false;
- for(i=0;i<static_cast<int>(mxodr.GetRoadCount());i++)
- {
- if(mvectorrc[0].mnroad1id == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
- {
- bhavep1 = true;
- p1 = mxodr.GetRoad(i);
- nroad1index = i;
- break;
- }
- }
- if(bhavep1 == false)
- {
- QMessageBox::warning(this,tr("Warn"),tr("Road not found."));
- return;
- }
- double off1,off2;
- for(i=0;i<static_cast<int>(mxodr.GetRoadCount());i++)
- {
- if(mvectorrc[0].mnroad2id == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
- {
- bhavep2 = true;
- p2 = mxodr.GetRoad(i);
- nroad2index = i;
- break;
- }
- }
- if(bhavep2 == false)
- {
- QMessageBox::warning(this,tr("Warn"),tr("Road not found."));
- return;
- }
- if(mvectorrc[0].mvectorlc.size()<1)
- {
- QMessageBox::warning(this,tr("Warn"),tr("No Lane Contact."));
- return;
- }
- double startx,starty,starthdg;
- double endx,endy,endhdg;
- double startheight,endheight;
- bool bFromstart,bTostart;
- if(mvectorrc[0].mncon1 == 0)
- {
- bFromstart = true;
- starthdg = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
- off1 = getoff(p1,mvectorrc[0].mvectorlc[0].ml1,true);
- startx = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
- starty = p1->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
- if(p1->GetLaneOffsetCount()>0)
- {
- off1 = off1 - p1->GetLaneOffset(0)->Geta();
- }
- startx = startx + off1 * cos(starthdg -M_PI/2.0);
- starty = starty + off1 * sin(starthdg -M_PI/2.0);
- startheight = 0;
- if(p1->GetElevationCount()>0)
- {
- startheight = p1->GetElevation(0)->GetA();
- }
- // if(mvectorrc[0].mvectorlc[0].ml1<0)
- starthdg = starthdg +M_PI;if(starthdg >=2.0*M_PI)starthdg = starthdg -2.0*M_PI;
- }
- else
- {
- bFromstart = false;
- if(GetEndPoint(p1,startx,starty,starthdg) != 0)
- {
- QMessageBox::warning(this,tr("Warn"),tr("get start error."));
- return;
- }
- off1 = getoff(p1,mvectorrc[0].mvectorlc[0].ml1,false);
- if(p1->GetLaneOffsetCount()>0)
- {
- LaneOffset * pLO = p1->GetLaneOffset(p1->GetLaneOffsetCount()-1);
- double froadlen = p1->GetRoadLength();
- double sdis = froadlen - pLO->GetS();
- double foffset = pLO->Geta() + pLO->Getb()*(sdis) + pLO->Getc() * sdis * sdis
- +pLO->Getd() * sdis * sdis * sdis;
- off1 = off1 - foffset;
- }
- startx = startx + off1 * cos(starthdg -M_PI/2.0);
- starty = starty + off1 * sin(starthdg -M_PI/2.0);
- startheight = 0;
- if(p1->GetElevationCount()>0)
- {
- startheight = p1->GetElevation(0)->GetA()
- +p1->GetElevation(0)->GetB() * pow(p1->GetRoadLength(),1)
- +p1->GetElevation(0)->GetC() * pow(p1->GetRoadLength(),2)
- +p1->GetElevation(0)->GetD() * pow(p1->GetRoadLength(),3);
- }
- }
- if(mvectorrc[0].mncon2 == 0)
- {
- bTostart = true;
- off2 = getoff(p2,mvectorrc[0].mvectorlc[0].ml2,true);
- endx = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
- endy = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
- endhdg = p2->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
- if(p2->GetLaneOffsetCount()>0)
- {
- off2 = off2 - p2->GetLaneOffset(0)->Geta();
- }
- endx = endx + off2 * cos(endhdg -M_PI/2.0);
- endy = endy + off2 * sin(endhdg -M_PI/2.0);
- endheight = 0;
- if(p2->GetElevationCount()>0)
- {
- endheight = p2->GetElevation(0)->GetA();
- }
- }
- else
- {
- bTostart = false;
- off2 = getoff(p2,mvectorrc[0].mvectorlc[0].ml2,false);
- if(GetEndPoint(p2,endx,endy,endhdg) != 0)
- {
- QMessageBox::warning(this,tr("Warn"),tr("get end error."));
- return;
- }
- if(p2->GetLaneOffsetCount()>0)
- {
- LaneOffset * pLO = p2->GetLaneOffset(p2->GetLaneOffsetCount()-1);
- double froadlen = p2->GetRoadLength();
- double sdis = froadlen - pLO->GetS();
- double foffset = pLO->Geta() + pLO->Getb()*(sdis) + pLO->Getc() * sdis * sdis
- +pLO->Getd() * sdis * sdis * sdis;
- off2 = off2 - foffset;
- }
- endx = endx + off2 * cos(endhdg -M_PI/2.0);
- endy = endy + off2 * sin(endhdg -M_PI/2.0);
- endhdg = endhdg +M_PI;if(endhdg >=2.0*M_PI)endhdg = endhdg -2.0*M_PI;
- endheight = 0;
- if(p2->GetElevationCount()>0)
- {
- endheight = p2->GetElevation(0)->GetA()
- +p2->GetElevation(0)->GetB() * pow(p2->GetRoadLength(),1)
- +p2->GetElevation(0)->GetC() * pow(p2->GetRoadLength(),2)
- +p2->GetElevation(0)->GetD() * pow(p2->GetRoadLength(),3);
- }
- }
- //Create Geo
- double R = mpLERoadType->text().toDouble();
- std::vector<geobase> xvectorgeo;
- std::vector<geobase> xvectorgeo1,xvectorgeo2;
- switch(mpCBRoadType->currentIndex())
- {
- case 0:
- xvectorgeo = CreateTurnGeo(startx,starty,starthdg,endx,endy,endhdg,R);
- break;
- case 1:
- {
- double fdis = sqrt(pow(startx - endx,2) +pow(starty -endy,2));
- if((fdis<3) || (starthdg == endhdg) ||(mpCBStraightType->isChecked()))
- {
- xvectorgeo = CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
- }
- else
- {
- xvectorgeo = geofit::CreateBezierGeo(startx,starty,starthdg,endx,endy,endhdg);
- }
- //
- }
- break;
- case 2:
- xvectorgeo = CreateUTurnGeo(startx,starty,starthdg,endx,endy,endhdg,R);
- break;
- default:
- break;
- }
- if(mpCBRoadType->currentIndex() == 2)
- {
- for(i=0;i<static_cast<int>(xvectorgeo.size())/2;i++)
- {
- xvectorgeo1.push_back(xvectorgeo.at(i));
- }
- for(i=static_cast<int>(xvectorgeo.size())/2;i<static_cast<int>(xvectorgeo.size());i++)
- {
- xvectorgeo2.push_back(xvectorgeo.at(i));
- }
- }
- if(xvectorgeo.size() == 0)
- {
- QMessageBox::warning(this,tr("Warn"),tr("Create Road Fail."));
- return;
- }
- double xroadlen = 0;
- if(mpCBRoadType->currentIndex() != 2)
- {
- for(i=0;i<static_cast<int>(xvectorgeo.size());i++)xroadlen = xroadlen + xvectorgeo[i].mfLen;
- mxodr.AddRoad("",xroadlen, QString::number(CreateRoadID()).toStdString(),"-1");
- Road * p = mxodr.GetRoad(mxodr.GetRoadCount() - 1);
- p->AddElevation(0,startheight,(endheight-startheight)/xroadlen,0,0);
- p1 = mxodr.GetRoad(nroad1index);
- p2 = mxodr.GetRoad(nroad2index);
- double s = 0;
- int j = 0;
- for(j=0;j<static_cast<int>(xvectorgeo.size());j++)
- {
- p->AddGeometryBlock();
- GeometryBlock * pgb = p->GetGeometryBlock(j);
- geobase * pline;
- geobase * pbez;
- geobase * parc;
- switch(xvectorgeo[j].mnType)
- {
- case 0:
- pline = &xvectorgeo[j];
- pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
- break;
- case 1:
- parc = &xvectorgeo[j];
- pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
- break;
- case 2:
- pbez = &xvectorgeo[j];
- std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
- pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
- pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
- pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
- pbez->mfv[1],pbez->mfv[2],pbez->mfv[3],false);
- break;
- }
- s = s + xvectorgeo[j].mfLen;
- }
- p->AddLaneSection(0);
- LaneSection * pLS = p->GetLaneSection(0);
- pLS->SetS(0);
- pLS->AddLane(0,0,"none",false);
- double * pswidth,*pewidth;
- std::vector<std::string> strvectorlanetype;
- int nlanecount = mvectorrc[0].mvectorlc.size();
- pswidth = new double[nlanecount];
- pewidth = new double[nlanecount];
- std::shared_ptr<double> ppswidth,ppewidth;
- ppswidth.reset(pswidth);
- ppewidth.reset(pewidth);
- for(i=0;i<nlanecount;i++)
- {
- pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart);
- strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart));
- }
- for(i=0;i<nlanecount;i++)
- {
- pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlc.at(i).ml2,bTostart);
- }
- double * pa,*pb;
- pa = new double[nlanecount];
- pb = new double[nlanecount];
- std::shared_ptr<double> ppa,ppb;
- ppa.reset(pa);
- ppb.reset(pb);
- for(i=0;i<nlanecount;i++)
- {
- pa[i] = pswidth[i];
- pb[i] = (pewidth[i] - pa[i])/xroadlen;
- }
- for(i=0;i<nlanecount;i++)
- {
- pLS->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
- Lane * pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i],pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- int noplanecount = mvectorrc[0].mvectorlcop.size();
- if(noplanecount > 0)
- {
- pswidth = new double[noplanecount];
- pewidth = new double[noplanecount];
- ppswidth.reset(pswidth);
- ppewidth.reset(pewidth);
- strvectorlanetype.clear();
- for(i=0;i<noplanecount;i++)
- {
- pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart);
- strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart));
- }
- for(i=0;i<noplanecount;i++)
- {
- pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlcop.at(i).ml2,bTostart);
- }
- pa = new double[noplanecount];
- pb = new double[noplanecount];
- ppa.reset(pa);
- ppb.reset(pb);
- for(i=0;i<noplanecount;i++)
- {
- pa[i] = pswidth[i];
- pb[i] = (pewidth[i] - pa[i])/xroadlen;
- }
- for(i=0;i<noplanecount;i++)
- {
- pLS->AddLane(1,(i+1),strvectorlanetype[i],false,false);
- Lane * pLL = pLS->GetLane(pLS->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i],pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- }
- }
- else
- {
- double xroadlen1 = 0;
- double xroadlen2 = 0;
- for(i=0;i<static_cast<int>(xvectorgeo1.size());i++)xroadlen1 = xroadlen1 + xvectorgeo1[i].mfLen;
- for(i=0;i<static_cast<int>(xvectorgeo2.size());i++)xroadlen2 = xroadlen2 + xvectorgeo2[i].mfLen;
- int index1 = mxodr.AddRoad("",xroadlen1, QString::number(CreateRoadID()).toStdString(),"-1");
- int index2 = mxodr.AddRoad("",xroadlen2, QString::number(CreateRoadID()).toStdString(),"-1");
- Road * proad2 = mxodr.GetRoad(index2);
- Road * proad1 = mxodr.GetRoad(index1);
- proad1->AddElevation(0,startheight,(endheight-startheight)/(xroadlen1+xroadlen2),0,0);
- proad2->AddElevation(0,startheight+xroadlen1*(endheight-startheight)/(xroadlen1+xroadlen2),
- (endheight-startheight)/(xroadlen1+xroadlen2),
- 0,0);
- p1 = mxodr.GetRoad(nroad1index);
- p2 = mxodr.GetRoad(nroad2index);
- // OpenDrive * px = &mxodr;
- double s = 0;
- int j = 0;
- for(j=0;j<static_cast<int>(xvectorgeo1.size());j++)
- {
- proad1->AddGeometryBlock();
- GeometryBlock * pgb = proad1->GetGeometryBlock(j);
- geobase * pline;
- geobase * pbez;
- geobase * parc;
- switch(xvectorgeo1[j].mnType)
- {
- case 0:
- pline = &xvectorgeo1[j];
- pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
- break;
- case 1:
- parc = &xvectorgeo1[j];
- pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
- break;
- case 2:
- pbez = &xvectorgeo1[j];
- std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
- pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
- pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
- pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
- pbez->mfv[1],pbez->mfv[2],pbez->mfv[3],false);
- break;
- }
- s = s + xvectorgeo1[j].mfLen;
- }
- s=0.0;
- for(j=0;j<static_cast<int>(xvectorgeo2.size());j++)
- {
- proad2->AddGeometryBlock();
- GeometryBlock * pgb = proad2->GetGeometryBlock(j);
- geobase * pline;
- geobase * pbez;
- geobase * parc;
- switch(xvectorgeo2[j].mnType)
- {
- case 0:
- pline = &xvectorgeo2[j];
- pgb->AddGeometryLine(s,pline->mfX,pline->mfY,pline->mfHdg,pline->mfLen);
- break;
- case 1:
- parc = &xvectorgeo2[j];
- pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
- break;
- case 2:
- pbez = &xvectorgeo2[j];
- std::cout<<"u0:"<<pbez->mfu[0]<<std::endl;
- pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
- pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
- pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
- pbez->mfv[1],pbez->mfv[2],pbez->mfv[3]);
- break;
- }
- s = s + xvectorgeo2[j].mfLen;
- }
- proad1->AddLaneSection(0);
- LaneSection * pLS1 = proad1->GetLaneSection(0);
- pLS1->SetS(0);
- pLS1->AddLane(0,0,"none",false);
- proad2->AddLaneSection(0);
- LaneSection * pLS2 = proad2->GetLaneSection(0);
- pLS2->SetS(0);
- pLS2->AddLane(0,0,"none",false);
- double * pswidth,*pewidth;
- int nlanecount = mvectorrc[0].mvectorlc.size();
- std::vector<std::string> strvectorlanetype;
- pswidth = new double[nlanecount];
- pewidth = new double[nlanecount];
- std::shared_ptr<double> ppswidth,ppewidth;
- ppswidth.reset(pswidth);
- ppewidth.reset(pewidth);
- for(i=0;i<nlanecount;i++)
- {
- pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart);
- strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlc.at(i).ml1,bFromstart));
- }
- for(i=0;i<nlanecount;i++)
- {
- pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlc.at(i).ml2,bTostart);
- }
- double * pa,*pb;
- pa = new double[nlanecount];
- pb = new double[nlanecount];
- std::shared_ptr<double> ppa,ppb;
- ppa.reset(pa);
- ppb.reset(pb);
- for(i=0;i<nlanecount;i++)
- {
- pa[i] = pswidth[i];
- pb[i] = (pewidth[i] - pa[i])/(xroadlen1+xroadlen2);
- }
- for(i=0;i<nlanecount;i++)
- {
- pLS1->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
- Lane * pLL = pLS1->GetLane(pLS1->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i],pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- pLS2->AddLane(-1,(i+1)*(-1),strvectorlanetype[i],false,false);
- pLL = pLS2->GetLane(pLS2->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i]+pb[i]*xroadlen1 ,pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- int noplanecount = mvectorrc[0].mvectorlcop.size();
- if(noplanecount > 0)
- {
- pswidth = new double[noplanecount];
- pewidth = new double[noplanecount];
- ppswidth.reset(pswidth);
- ppewidth.reset(pewidth);
- strvectorlanetype.clear();
- for(i=0;i<noplanecount;i++)
- {
- pswidth[i] = getlanewidth(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart);
- strvectorlanetype.push_back(getlanetype(p1,mvectorrc[0].mvectorlcop.at(i).ml1,bFromstart));
- }
- for(i=0;i<noplanecount;i++)
- {
- pewidth[i] = getlanewidth(p2,mvectorrc[0].mvectorlcop.at(i).ml2,bTostart);
- }
- pa = new double[noplanecount];
- pb = new double[noplanecount];
- ppa.reset(pa);
- ppb.reset(pb);
- for(i=0;i<noplanecount;i++)
- {
- pa[i] = pswidth[i];
- pb[i] = (pewidth[i] - pa[i])/xroadlen;
- }
- for(i=0;i<noplanecount;i++)
- {
- pLS1->AddLane(1,(i+1),strvectorlanetype[i],false,false);
- Lane * pLL = pLS1->GetLane(pLS1->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i],pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- pLS2->AddLane(1,(i+1),strvectorlanetype[i],false,false);
- pLL = pLS2->GetLane(pLS2->GetLaneCount() - 1);
- pLL->AddWidthRecord(0,pa[i]+pb[i]*xroadlen1 ,pb[i],
- 0,0);
- // pLL->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"false");
- }
- }
- }
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mpfb->SetOpenDrive(mxodr);
- }
- int MainWindow::GetEndPoint(Road *proad, double &x, double &y, double &hdg)
- {
- GeometryBlock * pblock = proad->GetLastGeometryBlock();
- RoadGeometry * pgeo = pblock->GetLastGeometry();
- (void)pgeo;
- proad->GetGeometryCoords(proad->GetRoadLength(),x,y,hdg);
- return 0;
- //0-line, 1-arc, 2-spiral 3-poly3 4-parampoly3
- switch (pgeo->GetGeomType()) {
- case 0:
- {
- GeometryLine * pline = (GeometryLine *)pgeo;
- x = pline->GetX() + pline->GetLength() * cos(pline->GetHdg());
- y = pline->GetY() + pline->GetLength() * sin(pline->GetHdg());
- hdg = pline->GetHdg();
- }
- return 0;
- break;
- case 1:
- {
- GeometryArc * parc = (GeometryArc *)pgeo;
- double x_center = parc->GetX() + (1.0/parc->GetCurvature()) * cos(parc->GetHdg() + M_PI/2.0);
- double y_center = parc->GetY() + (1.0/parc->GetCurvature()) * sin(parc->GetHdg()+ M_PI/2.0);
- x = x_center + fabs(1.0/parc->GetCurvature()) * cos(parc->GetHdg() + parc->GetLength() * parc->GetCurvature() - M_PI/2.0);
- y = y_center + fabs(1.0/parc->GetCurvature()) * sin(parc->GetHdg() + parc->GetLength() * parc->GetCurvature() - M_PI/2.0);
- hdg = parc->GetHdg() + parc->GetLength() * parc->GetCurvature();
- return 0;
- }
- break;
- case 2:
- {
- GeometrySpiral * pspiral = (GeometrySpiral *)pgeo;
- pspiral->GetCoords(pspiral->GetS()+pspiral->GetLength(),x,y,hdg);
- return 0;
- }
- break;
- case 3:
- QMessageBox::warning(this,tr("Warn"),tr("type not supported."));
- break;
- case 4:
- {
- double xtem,ytem;
- double xtem1,ytem1,x1,y1;
- GeometryParamPoly3 * ppoly3 = (GeometryParamPoly3* )pgeo;
- double s = ppoly3->GetLength();
- // xtem = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
- // ytem = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
- if(ppoly3->GetNormal())
- {
- xtem = ppoly3->GetuA() + ppoly3->GetuB() + ppoly3->GetuC() + ppoly3->GetuD() ;
- ytem = ppoly3->GetvA() + ppoly3->GetvB() + ppoly3->GetvC() + ppoly3->GetvD() ;
- }
- else
- {
- xtem = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
- ytem = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
- }
- x = xtem*cos(ppoly3->GetHdg()) - ytem * sin(ppoly3->GetHdg()) + ppoly3->GetX();
- y = xtem*sin(ppoly3->GetHdg()) + ytem * cos(ppoly3->GetHdg()) + ppoly3->GetY();
- s = ppoly3->GetLength()*0.99;
- if(s>0)
- {
- double frel = 0.99;
- if(ppoly3->GetNormal() == false)
- {
- xtem1 = ppoly3->GetuA() + ppoly3->GetuB() * s + ppoly3->GetuC() * s*s + ppoly3->GetuD() * s*s*s ;
- ytem1 = ppoly3->GetvA() + ppoly3->GetvB() * s + ppoly3->GetvC() * s*s + ppoly3->GetvD() * s*s*s ;
- }
- else
- {
- xtem1 = ppoly3->GetuA() + ppoly3->GetuB() * frel + ppoly3->GetuC() *frel*frel + ppoly3->GetuD()*frel*frel*frel ;
- ytem1 = ppoly3->GetvA() + ppoly3->GetvB()*frel + ppoly3->GetvC()*frel*frel + ppoly3->GetvD()*frel*frel*frel ;
- }
- x1 = xtem1*cos(ppoly3->GetHdg()) - ytem1 * sin(ppoly3->GetHdg()) + ppoly3->GetX();
- y1 = xtem1*sin(ppoly3->GetHdg()) + ytem1 * cos(ppoly3->GetHdg()) + ppoly3->GetY();
- hdg = geofit::CalcHdg(x1,y1,x,y);
- }
- else
- {
- hdg = 0;
- }
- return 0;
- }
- break;
- default:
- QMessageBox::warning(this,tr("Warn"),tr("type not supported."));
- break;
- }
- return -1;
- }
- void MainWindow::onChangeRoadType(int index)
- {
- if(index == 1)
- {
- mpLBRoadType->setVisible(true);
- mpLERoadType->setVisible(false);
- mpCBStraightType->setVisible(true);
- }
- else
- {
- mpLBRoadType->setVisible(true);
- mpLERoadType->setVisible(true);
- mpCBStraightType->setVisible(false);
- }
- if(index == 0)
- {
- mpLBRoadType->setText("Radius:");
- mpLERoadType->setText("6.0");
- }
- if(index == 1)
- {
- mpLBRoadType->setText("Type:");
- }
- if(index == 2)
- {
- mpLBRoadType->setText("Extend:");
- mpLERoadType->setText("3.0");
- }
- }
- std::vector<geobase> MainWindow::CreateLineGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg)
- {
- (void)starthdg;
- (void)endhdg;
- // std::vector<geobase> xvectorgeo;
- // geobase xgeobezier;
- // int nbtype;
- // double fabc[3],fxy[2],fblen,fbhdg;
- // geofit x;
- // x.CreateBezier(startx,starty,starthdg,
- // endx,endy,endhdg,
- // 0.35,0.35,xgeobezier.mfu,xgeobezier.mfv,xgeobezier.mfLen,
- // nbtype,fabc,&fbhdg,fxy,&fblen);
- // if(nbtype == 2)
- // {
- // xgeobezier.mfHdg = starthdg;
- // xgeobezier.mfX = startx;
- // xgeobezier.mfY = starty;
- // xgeobezier.mnType = 2;
- // }
- // else
- // {
- // xgeobezier.mnType = 0; //Line
- // xgeobezier.mfHdgStart = fbhdg;
- // xgeobezier.mfHdg = fbhdg;
- // xgeobezier.mfX = fxy[0];
- // xgeobezier.mfY = fxy[1];
- // xgeobezier.mfLen = fblen;
- // }
- // xvectorgeo.push_back(xgeobezier);
- // return xvectorgeo;
- geobase linegeo;
- linegeo.mnType = 0;
- linegeo.mfX = startx;
- linegeo.mfY = starty;
- linegeo.mfHdg = geofit::CalcHdg(startx,starty,endx,endy);
- linegeo.mfLen = sqrt(pow(endx - startx,2)+pow(endy - starty,2));
- std::vector<geobase> xvectorgeo;
- xvectorgeo.push_back(linegeo);
- return xvectorgeo;
- }
- std::vector<geobase> MainWindow::CreateTurnGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg,double R)
- {
- std::vector<geobase> xvectorgeo;
- xvectorgeo.clear();
- if(starthdg == endhdg)
- {
- std::cout<<"hdg same use line contact"<<std::endl;
- return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
- }
- double a1,c1,a2,c2;
- double inter_x,inter_y;
- if((starthdg == M_PI/2.0)||(starthdg == 3.0*M_PI/2.0))
- {
- a2 = tan(endhdg) *(-1);
- c2 = 0-a2*endx - endy;
- a1 = 1;
- c1 = startx *(-1);
- (void)a1; (void)c1;
- inter_x = startx;
- inter_y = 0 - a2*inter_x-c2;
- }
- else
- {
- if((endhdg == M_PI/2.0)||(endhdg == 3.0*M_PI/2.0))
- {
- a1 = tan(starthdg) *(-1);
- c1 = 0-a1*startx - starty;
- a2 = 1;
- c2 = endx *(-1);
- (void)a2; (void)c2;
- inter_x = endx;
- inter_y = 0 - a1*inter_x-c1;
- }
- else
- {
- a1 = tan(starthdg) *(-1);
- a2 = tan(endhdg) *(-1);
- c1 = 0-a1*startx - starty;
- c2 = 0-a2*endx - endy;
- inter_x = (c1-c2)/(a2-a1);
- inter_y = 0 - a1*inter_x - c1;
- }
- }
- double dis1,dis2;
- dis1 =sqrt(pow(inter_x - startx,2)+pow(inter_y - starty,2));
- dis2 =sqrt(pow(inter_x - endx,2)+pow(inter_y - endy,2));
- if((dis1<1.0)||(dis2<1.0))
- {
- std::cout<<"use line connect."<<std::endl;
- char strinfo[256];
- snprintf(strinfo,256,"Use Line Connect");
- QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
- return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
- }
- if((R>=dis1 )||(R>=dis2))
- {
- R = dis1 - 0.3;
- if(R>=dis2)
- {
- R = dis2 - 0.3;
- }
- char strinfo[256];
- snprintf(strinfo,256,"Change Radius to %f",R);
- QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
- }
- double hdgdiff = endhdg - starthdg;
- if(hdgdiff >= M_PI)hdgdiff = hdgdiff - 2.0*M_PI;
- if(hdgdiff <= (-M_PI))hdgdiff = hdgdiff + 2.0*M_PI;
- double slen = R*tan(fabs(hdgdiff/2.0));
- if(slen <(R+0.3))
- {
- R = slen - 0.3;
- std::cout<<"Change Radius to "<<R<<std::endl;
- slen = R*tan(fabs(hdgdiff/2.0));
- }
- if((dis1<slen)||(dis2<slen))
- {
- std::cout<<"radius is big. use line."<<std::endl;
- char strinfo[256];
- snprintf(strinfo,256,"Use Line Connect");
- QMessageBox::information(this,"Info",strinfo,QMessageBox::YesAll);
- return CreateLineGeo(startx,starty,starthdg,endx,endy,endhdg);
- }
- double p1_x,p1_y,p2_x,p2_y;
- p1_x = inter_x+ slen * cos(starthdg +M_PI);
- p1_y = inter_y+ slen * sin(starthdg +M_PI);
- p2_x = inter_x+slen*cos(endhdg);
- p2_y = inter_y+slen*sin(endhdg);
- geobase linegeo;
- linegeo.mnType = 0;
- linegeo.mfX = startx;
- linegeo.mfY = starty;
- linegeo.mfHdg = starthdg;
- linegeo.mfLen = sqrt(pow(p1_x - startx,2)+pow(p1_y - starty,2));
- xvectorgeo.push_back(linegeo);
- geobase arcgeo;
- arcgeo.mnType = 1;
- arcgeo.mfX = p1_x;
- arcgeo.mfY = p1_y;
- arcgeo.mfHdg = starthdg;
- arcgeo.mfHdgStart = starthdg;
- arcgeo.mfLen = R*fabs(hdgdiff);
- arcgeo.mR = R*(fabs(hdgdiff)/hdgdiff);
- arcgeo.mfEndX = p2_x;
- arcgeo.mfEndY = p2_y;
- xvectorgeo.push_back(arcgeo);
- linegeo.mnType = 0;
- linegeo.mfX = p2_x;
- linegeo.mfY = p2_y;
- linegeo.mfHdg = endhdg;
- linegeo.mfLen = sqrt(pow(p2_x - endx,2)+pow(p2_y - endy,2));
- xvectorgeo.push_back(linegeo);
- return xvectorgeo;
- }
- std::string MainWindow::getlanetype(Road *p, int nlane, bool bstart)
- {
- Lane * plane = 0;
- int i;
- LaneSection * pLS;
- if(bstart)
- {
- pLS = p->GetLaneSection(0);
- }
- else
- {
- pLS = p->GetLaneSection(p->GetLaneSectionCount() -1);
- }
- int nlanecount = pLS->GetLaneCount();
- for(i=0;i<nlanecount;i++)
- {
- if(nlane == pLS->GetLane(i)->GetId())
- {
- plane = pLS->GetLane(i);
- break;
- }
- }
- if(plane == 0)
- {
- std::cout<<"MainWindow::getlanetype can't find lane : "<<nlane<<std::endl;
- return "driving";
- }
- return plane->GetType();
- }
- double MainWindow::getlanewidth(Road * p, int nlane,bool bstart)
- {
- Lane * plane = 0;
- double a,b,c,d;
- double s;
- if(bstart)
- {
- s = 0;
- (void)s;
- }
- else
- {
- s = p->GetRoadLength();
- (void)s;
- }
- int i;
- LaneSection * pLS;
- if(bstart)
- {
- pLS = p->GetLaneSection(0);
- }
- else
- {
- pLS = p->GetLaneSection(p->GetLaneSectionCount() -1);
- }
- int nlanecount = pLS->GetLaneCount();
- for(i=0;i<nlanecount;i++)
- {
- if(nlane == pLS->GetLane(i)->GetId())
- {
- plane = pLS->GetLane(i);
- break;
- }
- }
- if(plane == 0)
- {
- std::cout<<"MainWindow::getlanewidth can't find lane : "<<nlane<<std::endl;
- return 0;
- }
- if(bstart)
- {
- return plane->GetLaneWidth(0)->GetA();
- }
- else
- {
- s = p->GetRoadLength() - pLS->GetS();
- LaneWidth * pLW = plane->GetLaneWidth(plane->GetLaneWidthCount()-1);
- a = pLW->GetA();b = pLW->GetB();c = pLW->GetC();d = pLW->GetD();
- return a+b*s+c*pow(s,2)+d*pow(s,3);
- }
- }
- double MainWindow::getoff(Road *p, int nlane, bool bstart)
- {
- double off = 0;
- int i;
- if(bstart)
- {
- LaneSection * pLS = p->GetLaneSection(0);
- if(nlane<0)
- {
- if(nlane == -1)return 0;
- else
- {
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- if((pL->GetId()<0)&&(pL->GetId()>nlane))
- {
- off = off + pL->GetLaneWidth(0)->GetA();
- }
- }
- }
- }
- else
- {
- if(nlane == 1)return 0;
- else
- {
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- if((pL->GetId()>0)&&(pL->GetId()<nlane))
- {
- off = off - pL->GetLaneWidth(0)->GetA();
- }
- }
- }
- }
- }
- else
- {
- LaneSection * pLS = p->GetLaneSection(p->GetLaneSectionCount()-1);
- if(nlane<0)
- {
- if(nlane == -1)return 0;
- else
- {
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- if((pL->GetId()<0)&&(pL->GetId()>nlane))
- {
- double a,b,c,d;
- a = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetA();
- b = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetB();
- c = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetC();
- d = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetD();
- double s = p->GetRoadLength();
- off = off + a + b*s +c *s*s + d*s*s*s;
- }
- }
- }
- }
- else
- {
- if(nlane == 1)return 0;
- else
- {
- for(i=0;i<static_cast<int>(pLS->GetLaneCount());i++)
- {
- Lane * pL = pLS->GetLane(i);
- if((pL->GetId()>0)&&(pL->GetId()<nlane))
- {
- double a,b,c,d;
- a = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetA();
- b = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetB();
- c = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetC();
- d = pL->GetLaneWidth(pL->GetLaneWidthCount()-1)->GetD();
- double s = p->GetRoadLength();
- off = off - a - b*s -c *s*s - d*s*s*s;
- }
- }
- }
- }
- }
- return off;
- }
- std::vector<geobase> MainWindow::CreateUTurnGeo(double startx, double starty, double starthdg, double endx, double endy, double endhdg, double fextend)
- {
- std::vector<geobase> xvectorgeo;
- double p1_x,p1_y, p2_x,p2_y,p1_hdg,p2_hdg;
- p1_x = fextend*cos(starthdg) + startx;
- p1_y = fextend*sin(starthdg) + starty;
- p2_x = fextend*cos(endhdg + M_PI) + endx;
- p2_y = fextend*sin(endhdg + M_PI) + endy;
- p1_hdg = starthdg;
- p2_hdg = endhdg;
- if(starthdg == endhdg)
- {
- std::cout<<" hdg is same, can't create u turn."<<std::endl;
- return xvectorgeo;
- }
- double hdgse = geofit::CalcHdg(p1_x,p1_y,p2_x,p2_y);
- double hdgdiff = hdgse - p1_hdg;
- if(hdgdiff < 0)hdgdiff = hdgdiff + 2.0*M_PI;
- bool bPA = true; //Positive
- if(hdgdiff >=M_PI)bPA = false;
- double xdiff;
- if(bPA)xdiff = hdgdiff - M_PI/2.0;
- else xdiff = hdgdiff - 3.0*M_PI/2.0;
- double xdis = sqrt(pow(p1_x-p2_x,2)+pow(p1_y-p2_y,2));
- double R = xdis/(2.0*cos(xdiff));
- double x_center,y_center;
- double xhdgtocenter;
- if(bPA)
- {
- xhdgtocenter = p1_hdg + M_PI/2.0;
- if(xhdgtocenter >= 2.0*M_PI)xhdgtocenter = xhdgtocenter - M_PI*2.0;
- }
- else
- {
- xhdgtocenter = p1_hdg - M_PI/2.0;
- if(xhdgtocenter < 0)xhdgtocenter = xhdgtocenter + 2.0*M_PI;
- }
- x_center = p1_x + R*cos(xhdgtocenter);
- y_center = p1_y + R*sin(xhdgtocenter);
- double xhdgcentertoarc;
- if(bPA)
- {
- xhdgcentertoarc = hdgse - M_PI/2.0;
- if(xhdgcentertoarc <0)xhdgcentertoarc = xhdgcentertoarc + 2.0*M_PI;
- }
- else
- {
- xhdgcentertoarc = hdgse + M_PI/2.0;
- if(xhdgcentertoarc >= M_PI*2.0)xhdgcentertoarc = xhdgcentertoarc - M_PI*2.0;
- }
- double p3_x,p3_y,p3_hdg;
- (void)p3_hdg;
- p3_hdg = hdgse;
- (void)p3_hdg;
- p3_x = x_center + R* cos(xhdgcentertoarc);
- p3_y = y_center + R* sin(xhdgcentertoarc);
- // pgb->AddGeometryArc(s,parc->mfX,parc->mfY,parc->mfHdgStart,parc->mfLen,1.0/parc->mR);
- geobase c2,c3;
- c2.mfX = p1_x;
- c2.mfY = p1_y;
- c2.mfHdgStart = p1_hdg;
- c3.mfX = p3_x;
- c3.mfY = p3_y;
- c3.mfHdgStart = hdgse;
- c2.mnType = 1;
- c3.mnType = 1;
- if(bPA)
- {
- c2.mfLen = hdgdiff * R;
- c2.mR = R;
- c3.mfLen = c2.mfLen;
- c3.mR = R;
- }
- else
- {
- c2.mfLen = (2.0*M_PI - hdgdiff) * R;
- c2.mR = R*(-1);
- c3.mfLen = c2.mfLen;
- c3.mR = R*(-1);
- }
- geobase l1,l2;
- if(fextend != 0)
- {
- l1.mfX = startx;
- l1.mfY = starty;
- l1.mfHdg = starthdg;
- l1.mfLen = fextend;
- l1.mnType = 0;
- l2.mfX = p2_x;
- l2.mfY = p2_y;
- l2.mfHdg = p2_hdg;
- l2.mfLen = fextend;
- l2.mnType = 0;
- xvectorgeo.push_back(l1);
- }
- xvectorgeo.push_back(c2);
- xvectorgeo.push_back(c3);
- if(fextend != 0)xvectorgeo.push_back(l2);
- return xvectorgeo;
- }
- void MainWindow::ChangeXODRRoadID(OpenDrive *pxodr, int index, int newid)
- {
- Road * proad;
- int nsize = pxodr->GetRoadCount();
- int i;
- if(index<0)return;
- if(index>=nsize)return;
- proad = pxodr->GetRoad(index);
- int noldid = atoi(proad->GetRoadId().data());
- char strid[255];
- snprintf(strid,255,"%d",newid);
- proad->SetRoadId(strid);
- for(i=0;i<nsize;i++)
- {
- Road * proad2 = pxodr->GetRoad(i);
- if(proad2->GetPredecessor()!= 0)
- {
- RoadLink * plink = proad2->GetPredecessor();
- if(strncmp(plink->GetElementType().data(),"road",255)== 0)
- {
- if(atoi(plink->GetElementId().data()) == noldid)
- {
- plink->SetElementId(strid);
- }
- }
- }
- if(proad2->GetSuccessor()!= 0)
- {
- RoadLink * plink = proad2->GetSuccessor();
- if(strncmp(plink->GetElementType().data(),"road",255)== 0)
- {
- if(atoi(plink->GetElementId().data()) == noldid)
- {
- plink->SetElementId(strid);
- }
- }
- }
- }
- nsize = pxodr->GetJunctionCount();
- for(i=0;i<nsize;i++)
- {
- Junction * pjunction = pxodr->GetJunction(i);
- int j;
- for(j=0;j<static_cast<int>(pjunction->GetJunctionConnectionCount());j++)
- {
- JunctionConnection * pjc = pjunction->GetJunctionConnection(j);
- if(atoi(pjc->GetIncomingRoad().data()) == noldid)
- {
- pjc->SetIncomingRoad(strid);
- }
- if(atoi(pjc->GetConnectingRoad().data()) == noldid)
- {
- pjc->SetConnectingRoad(strid);
- }
- }
- }
- }
- void MainWindow::ChangeXODRJunctionID(OpenDrive *pxodr, int index, int newid)
- {
- Junction * pjunction;
- int nsize = pxodr->GetJunctionCount();
- int i;
- if(index<0)return;
- if(index>=nsize)return;
- pjunction = pxodr->GetJunction(index);
- int noldid = atoi(pjunction->GetId().data());
- char strid[255];
- snprintf(strid,255,"%d",newid);
- pjunction->SetId(strid);
- for(i=0;i<(int)(pxodr->GetRoadCount());i++)
- {
- Road * proad2 = pxodr->GetRoad(i);
- if(proad2 == NULL)
- {
- qDebug("Road %d is NULL size is %d",i,nsize);
- continue;
- }
- if(proad2->GetPredecessor()!= 0)
- {
- RoadLink * plink = proad2->GetPredecessor();
- if(strncmp(plink->GetElementType().data(),"junction",255)== 0)
- {
- if(atoi(plink->GetElementId().data()) == noldid)
- {
- plink->SetElementId(strid);
- }
- }
- }
- if(proad2->GetSuccessor()!= 0)
- {
- RoadLink * plink = proad2->GetSuccessor();
- if(strncmp(plink->GetElementType().data(),"junction",255)== 0)
- {
- if(atoi(plink->GetElementId().data()) == noldid)
- {
- plink->SetElementId(strid);
- }
- }
- }
- }
- }
- void MainWindow::MoveXODR(OpenDrive *pxodr, double movex, double movey)
- {
- int nsize = pxodr->GetRoadCount();
- int i;
- for(i=0;i<nsize;i++)
- {
- Road * pRoad = pxodr->GetRoad(i);
- int nblockcount = pRoad->GetGeometryBlockCount();
- int j;
- for(j=0;j<nblockcount;j++)
- {
- GeometryBlock * pgb = pRoad->GetGeometryBlock(j);
- if(pgb != 0)
- {
- pgb->GetGeometryAt(0)->SetX(pgb->GetGeometryAt(0)->GetX() + movex);
- pgb->GetGeometryAt(0)->SetY(pgb->GetGeometryAt(0)->GetY() + movey);
- }
- }
- }
- }
- int MainWindow::FindNewRoadID(OpenDrive *pxodr1, OpenDrive *pxodr2)
- {
- int nroadsize1,nroadsize2;
- nroadsize1 = pxodr1->GetRoadCount();
- nroadsize2 = pxodr2->GetRoadCount();
- int i;
- int * pnid = new int[nroadsize1 + nroadsize2];
- std::shared_ptr<int> ppnid;ppnid.reset(pnid);
- for(i=0;i<nroadsize1;i++)
- {
- pnid[i] = atoi(pxodr1->GetRoad(i)->GetRoadId().data());
- }
- for(i=0;i<nroadsize2;i++)
- {
- pnid[i+nroadsize1] = atoi(pxodr2->GetRoad(i)->GetRoadId().data());
- }
- int nstartid = 40000;
- bool bUsed = true;
- while(bUsed == true)
- {
- bUsed = false;
- for(i=0;i<(nroadsize1 + nroadsize2);i++)
- {
- if(pnid[i] == nstartid)
- {
- bUsed = true;
- break;
- }
- }
- if(bUsed == false)break;
- nstartid++;
- }
- return nstartid;
- }
- int MainWindow::FindNewJunctionID(OpenDrive *pxodr1, OpenDrive *pxodr2)
- {
- int njunctionsize1,njunctionsize2;
- njunctionsize1 = pxodr1->GetJunctionCount();
- njunctionsize2 = pxodr2->GetJunctionCount();
- int i;
- int * pnid = new int[njunctionsize1 + njunctionsize2];
- std::shared_ptr<int> ppnid;ppnid.reset(pnid);
- for(i=0;i<njunctionsize1;i++)
- {
- pnid[i] = atoi(pxodr1->GetJunction(i)->GetId().data());
- }
- for(i=0;i<njunctionsize2;i++)
- {
- pnid[i+njunctionsize1] = atoi(pxodr2->GetJunction(i)->GetId().data());
- }
- int nstartid = 50000;
- bool bUsed = true;
- while(bUsed == true)
- {
- bUsed = false;
- for(i=0;i<(njunctionsize1 + njunctionsize2);i++)
- {
- if(pnid[i] == nstartid)
- {
- bUsed = true;
- break;
- }
- }
- if(bUsed == false)break;
- nstartid++;
- }
- return nstartid;
- }
- void MainWindow::onClickRoadMark()
- {
- mbRefresh = true;
- update();
- }
- void MainWindow::onClickRoadDel()
- {
- if(mpCBRoad->count() == 0)
- {
- QMessageBox::warning(this,"warn","no road to be delete");
- return;
- }
- int nroadid = mpCBRoad->currentText().toInt();
- QMessageBox::StandardButton button;
- button=QMessageBox::question(this,tr("Delete Road"),QString(tr("Delete Road?")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- return;
- }
- else if(button==QMessageBox::Yes)
- {
- }
- Road * pRoad = 0;
- int nroadsize = mxodr.GetRoadCount();
- int i;
- int index;
- for(i=0;i<nroadsize;i++)
- {
- if(nroadid == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
- {
- pRoad = mxodr.GetRoad(i);
- index = i;
- break;
- }
- }
- if(pRoad == 0)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find road"));
- return;
- }
- SaveBack();
- mxodr.DeleteRoad(index);
- nroadsize = mxodr.GetRoadCount();
- for(i=0;i<nroadsize;i++)
- {
- pRoad = mxodr.GetRoad(i);
- RoadLink * ppre,* pnext;
- ppre = pRoad->GetPredecessor();
- pnext = pRoad->GetSuccessor();
- if(ppre != 0)
- {
- if(strncmp(ppre->GetElementType().data(),"road",255) == 0)
- {
- if(atoi(ppre->GetElementId().data()) == nroadid)
- {
- pRoad->RemovePredecessor();
- LaneSection * pLS = pRoad->GetLaneSection(0);
- int nlanecount = pLS->GetLaneCount();
- int j;
- for(j=0;j<nlanecount;j++)
- {
- Lane * pLane;
- pLane = pLS->GetLane(j);
- pLane->RemovePredecessor();
- }
- }
- }
- }
- if(pnext != 0)
- {
- if(strncmp(pnext->GetElementType().data(),"road",255) == 0)
- {
- if(atoi(pnext->GetElementId().data()) == nroadid)
- {
- pRoad->RemoveSuccessor();
- LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- int nlanecount = pLS->GetLaneCount();
- int j;
- for(j=0;j<nlanecount;j++)
- {
- Lane * pLane;
- pLane = pLS->GetLane(j);
- pLane->RemoveSuccessor();
- }
- }
- }
- }
- }
- //remove juction connection where id = roadid
- int njunctioncount = mxodr.GetJunctionCount();
- Junction * pjunction;
- for(i=0;i<njunctioncount;i++)
- {
- pjunction = mxodr.GetJunction(i);
- int j;
- for(j=0;j<static_cast<int>(pjunction->GetJunctionConnectionCount());j++)
- {
- JunctionConnection * pjc = pjunction->GetJunctionConnection(j);
- int nfromid = atoi(pjc->GetIncomingRoad().data());
- int ntoid = atoi(pjc->GetConnectingRoad().data());
- if((nfromid == nroadid)||(ntoid == nroadid))
- {
- pjunction->DeleteJunctionConnection(j);
- j--;
- }
- }
- }
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::updateCBRoad()
- {
- mpCBRoad->clear();
- mpCBRoad1->clear();
- mpCBRoad2->clear();
- mpCBJunctionIncommingRoad->clear();
- mpCBJunctionConnectingRoad->clear();
- mpCBPreNxtRoad->clear();
- int i;
- int nroadcount = mxodr.GetRoadCount();
- for(i=0;i<nroadcount;i++)
- {
- const char * strname1 = mxodr.GetRoad(i)->GetRoadId().data();
- QString strname(strname1);
- mpCBRoad->addItem(strname);
- mpCBRoad1->addItem(strname);
- mpCBRoad2->addItem(strname);
- mpCBJunctionIncommingRoad->addItem(strname);
- mpCBJunctionConnectingRoad->addItem(strname);
- mpCBPreNxtRoad->addItem(strname);
- }
- }
- void MainWindow::onClickCBRoadChange(int index)
- {
- Road * pRoad = mxodr.GetRoad(index);
- if(pRoad == 0)
- {
- // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
- return;
- }
- int i;
- mpLabelRoadShowPreID->setText("");
- mpLabelRoadShowPreType2->setText("");
- mpLabelRoadShowPreType1->setText("");
- mpCBRoadShowPre->clear();
- mpLabelRoadShowNxtID->setText("");
- mpLabelRoadShowNxtType2->setText("");
- mpLabelRoadShowNxtType1->setText("");
- mpCBRoadShowNext->clear();
- if(pRoad->GetPredecessor() != 0)
- {
- RoadLink * pRL = pRoad->GetPredecessor();
- mpLabelRoadShowPreID->setText(pRL->GetElementId().data());
- mpLabelRoadShowPreType2->setText(pRL->GetContactPoint().data());
- mpLabelRoadShowPreType1->setText(pRL->GetElementType().data());
- }
- if(pRoad->GetSuccessor() != 0)
- {
- RoadLink * pRL = pRoad->GetSuccessor();
- mpLabelRoadShowNxtID->setText(pRL->GetElementId().data());
- mpLabelRoadShowNxtType2->setText(pRL->GetContactPoint().data());
- mpLabelRoadShowNxtType1->setText(pRL->GetElementType().data());
- }
- LaneSection * pLS = pRoad->GetLaneSection(0);
- if(pLS == 0)
- {
- return;
- }
- int nlanecount = pLS->GetLaneCount();
- for(i=0;i<nlanecount;i++)
- {
- char strout[256];
- char strtem[255];
- Lane * pLane = pLS->GetLane(i);
- snprintf(strout,255,"%d type:%s",pLane->GetId(),pLane->GetType().data());
- if(pLane->IsPredecessorSet())
- {
- snprintf(strtem,255," pre:%d",pLane->GetPredecessor());
- strncat(strout,strtem,255);
- }
- mpCBRoadShowPre->addItem(strout);
- }
- pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- nlanecount = pLS->GetLaneCount();
- for(i=0;i<nlanecount;i++)
- {
- char strout[256];
- char strtem[255];
- Lane * pLane = pLS->GetLane(i);
- snprintf(strout,255,"%d type:%s",pLane->GetId(),pLane->GetType().data());
- if(pLane->IsSuccessorSet())
- {
- snprintf(strtem,255," suc:%d",pLane->GetSuccessor());
- strncat(strout,strtem,255);
- }
- mpCBRoadShowNext->addItem(strout);
- }
- if(mpCBRoad->currentText().length()>0)
- {
- int nCurRoadID = mpCBRoad->currentText().toInt();
- emit CurrentRoadChange(nCurRoadID);
- }
- }
- void MainWindow::updateJunction()
- {
- int i;
- int njunctioncount = mxodr.GetJunctionCount();
- mpCBJunction->clear();
- for(i=0;i<njunctioncount;i++)
- {
- Junction * pjunction = mxodr.GetJunction(i);
- mpCBJunction->addItem(pjunction->GetId().data());
- }
- }
- void MainWindow::onClickCBJunctionChange(int index)
- {
- mpCBJunctionConnection->clear();
- Junction * pjunction = mxodr.GetJunction(index);
- if(pjunction == NULL)
- {
- // QMessageBox::warning(this,"warn","MainWindow::onClickCBJunctionChange can't find junction");
- return;
- }
- int nconnectioncount = pjunction->GetJunctionConnectionCount();
- int i;
- for(i=0;i<nconnectioncount;i++)
- {
- JunctionConnection * pJC = pjunction->GetJunctionConnection(i);
- mpCBJunctionConnection->addItem(pJC->GetId().data());
- }
- mpCBJunctionFromTo->clear();
- mpLabelJunctionConnectingRoad->setText("");
- mpLabelJunctionContactPoint->setText("");
- mpLabelJunctionIncommingRoad->setText("");
- if(pjunction->GetJunctionConnectionCount()>0)
- {
- mpCBJunctionConnection->setCurrentIndex(0);
- onClickCBJunctionConnectionChange(0);
- }
- }
- void MainWindow::onClickCBJunctionConnectionChange(int index)
- {
- // mpCBJunctionIncommingRoad->clear();
- // mpCBJunctionConnectingRoad->clear();
- // mpCBJunctionFromLane->clear();
- // mpCBJunctionToLane->clear();
- Junction * pjunction = mxodr.GetJunction(mpCBJunction->currentIndex());
- if(pjunction == NULL)
- {
- std::cout<<"MainWindow::onClickCBJunctionConnectionChange Junction NULL"<<std::endl;
- return;
- }
- if((index<0)||(index>= static_cast<int>(pjunction->GetJunctionConnectionCount())))
- {
- // std::cout<<"MainWindow::onClickCBJunctionConnectionChange out range."<<std::endl;
- return;
- }
- JunctionConnection * pJC = pjunction->GetJunctionConnection(index);
- if(pJC == NULL)
- {
- std::cout<<"MainWindow::onClickCBJunctionConnectionChange Junction Connection NULL"<<std::endl;
- return;
- }
- mpLabelJunctionIncommingRoad->setText(pJC->GetIncomingRoad().data());
- mpLabelJunctionContactPoint->setText(pJC->GetContactPoint().data());
- mpLabelJunctionConnectingRoad->setText(pJC->GetConnectingRoad().data());
- unsigned int i;
- unsigned int njunctionlanelinkcount = pJC->GetJunctionLaneLinkCount();
- mpCBJunctionFromTo->clear();
- for(i=0;i<njunctionlanelinkcount;i++)
- {
- char strout[255];
- JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(i);
- snprintf(strout,255,"%d to %d",pjll->GetFrom(),pjll->GetTo());
- mpCBJunctionFromTo->addItem(strout);
- }
- }
- void MainWindow::onClickCBJunctionIncommingChange(int index)
- {
- int i;
- int ncount = mxodr.GetRoadCount();
- if((index < 0)||(index>=ncount))
- {
- return;
- }
- Road * pRoad = mxodr.GetRoad(index);
- if(pRoad == NULL)
- {
- return;
- }
- LaneSection * pLS;
- if(mpCBJunctionContactPoint->currentIndex() == 0)
- {
- pLS = pRoad->GetLaneSection(0);
- }
- else
- {
- pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- }
- if(pLS == 0)
- {
- return;
- }
- int nlanecount = pLS->GetLaneCount();
- mpCBJunctionFromLane->clear();
- for(i=0;i<nlanecount;i++)
- {
- Lane * pLane = pLS->GetLane(i);
- if(pLane->GetId() != 0)
- {
- mpCBJunctionFromLane->addItem(QString::number(pLane->GetId()));
- }
- }
- }
- void MainWindow::onClickCBJunctionConnectionroadChange(int index)
- {
- int i;
- int ncount = mxodr.GetRoadCount();
- if((index < 0)||(index>=ncount))
- {
- return;
- }
- Road * pRoad = mxodr.GetRoad(index);
- if(pRoad == NULL)
- {
- return;
- }
- LaneSection * pLS;
- pLS = pRoad->GetLaneSection(0);
- if(pLS == 0)
- {
- return;
- }
- int nlanecount = pLS->GetLaneCount();
- mpCBJunctionToLane->clear();
- for(i=0;i<nlanecount;i++)
- {
- Lane * pLane = pLS->GetLane(i);
- if(pLane->GetId() != 0)
- {
- mpCBJunctionToLane->addItem(QString::number(pLane->GetId()));
- }
- }
- }
- void MainWindow::onClickCreateJunction()
- {
- mxodr.AddJunction("",QString::number(CreateJunctionID()).toStdString());
- updateJunction();
- }
- void MainWindow::onClickCreateJunctionLaneLink()
- {
- Junction * pJunction= mxodr.GetJunction(mpCBJunction->currentIndex());
- if(pJunction == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find junction"));
- return ;
- }
- Road * pFromRoad = mxodr.GetRoad(mpCBJunctionIncommingRoad->currentIndex());
- if(pFromRoad == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find incomming road."));
- return;
- }
- Road * pToRoad = mxodr.GetRoad(mpCBJunctionConnectingRoad->currentIndex());
- if(pToRoad == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find connecting road."));
- return;
- }
- string contacpoint = mpCBJunctionContactPoint->currentText().toStdString();
- JunctionConnection * pJC = 0;
- int njunctioncount = pJunction->GetJunctionConnectionCount();
- int i;
- for(i=0;i<njunctioncount;i++)
- {
- JunctionConnection * pJunCon = pJunction->GetJunctionConnection(i);
- if((pJunCon->GetIncomingRoad() == pFromRoad->GetRoadId())&&(pJunCon->GetContactPoint() == contacpoint)&&(pJunCon->GetConnectingRoad() == pToRoad->GetRoadId()))
- {
- pJC = pJunCon;
- break;
- }
- }
- bool bNewJC = false;
- if(pJC == 0)
- {
- int nnewJCid = pJunction->GetJunctionConnectionCount();
- int j;
- int njccount = pJunction->GetJunctionConnectionCount();
- bool bNotUse = true;
- do
- {
- for(j=0;j<njccount;j++)
- {
- if(nnewJCid == atoi(pJunction->GetJunctionConnection(j)->GetId().data()))
- {
- bNotUse = false;
- nnewJCid++;
- break;
- }
- }
- }while(bNotUse == false);
- unsigned int addindex = pJunction->AddJunctionConnection(QString::number(nnewJCid).toStdString(),
- pFromRoad->GetRoadId(),
- pToRoad->GetRoadId(),
- contacpoint);
- pJC = pJunction->GetJunctionConnection(addindex);
- bNewJC = true;
- }
- int nfrom = mpCBJunctionFromLane->currentText().toInt();
- int nto = mpCBJunctionToLane->currentText().toInt();
- int njlcount = pJC->GetJunctionLaneLinkCount();
- for(i=0;i<njlcount;i++)
- {
- JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(i);
- if((pjll->GetFrom()== nfrom)&&(pjll->GetTo() == nto))
- {
- QMessageBox::warning(this,tr("Warn"),tr("this lane link exist."));
- return;
- }
- }
- unsigned int nadd = pJC->AddJunctionLaneLink(mpCBJunctionFromLane->currentText().toInt(),
- mpCBJunctionToLane->currentText().toInt());
- char strout[255];
- JunctionLaneLink * pjll = pJC->GetJunctionLaneLink(nadd);
- snprintf(strout,255,"%d to %d",pjll->GetFrom(),pjll->GetTo());
- if(bNewJC)
- {
- mpCBJunctionConnection->addItem(pJC->GetId().data());
- }
- if(strncmp(contacpoint.data(),"start",255) == 0)
- {
- if(nfrom*nto<0)
- {
- pFromRoad->SetPredecessor("junction",pJunction->GetId(),contacpoint);
- }
- else
- {
- pFromRoad->SetSuccessor("junction",pJunction->GetId(),contacpoint);
- }
- }
- else
- {
- if(nfrom*nto <0)
- {
- pFromRoad->SetSuccessor("junction",pJunction->GetId(),contacpoint);
- }
- else
- {
- pFromRoad->SetPredecessor("junction",pJunction->GetId(),contacpoint);
- }
- }
- pToRoad->SetRoadJunction(pJunction->GetId());
- }
- void MainWindow::onClickDeleteJunctionLaneLink()
- {
- Junction * pJunction= mxodr.GetJunction(mpCBJunction->currentIndex());
- if(pJunction == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find junction"));
- return ;
- }
- if(pJunction->GetJunctionConnectionCount() == 0)
- {
- mxodr.DeleteJunction(mpCBJunction->currentIndex());
- updateJunction();
- return;
- }
- JunctionConnection * pJC = pJunction->GetJunctionConnection(mpCBJunctionConnection->currentIndex());
- if(pJC == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("can't find junction connetion."));
- return;
- }
- if(pJC->GetJunctionLaneLinkCount() == 0)
- {
- pJunction->DeleteJunctionConnection(mpCBJunctionConnection->currentIndex());
- if(pJunction->GetJunctionConnectionCount() > 0)
- onClickCBJunctionChange(mpCBJunction->currentIndex());
- else
- {
- mxodr.DeleteJunction(mpCBJunction->currentIndex());
- updateJunction();
- }
- return;
- }
- // std::string strincommingroad = mpLabelJunctionIncommingRoad->text().toStdString();
- // std::string strconnectionroad = mpLabelJunctionConnectingRoad->text().toStdString();
- // std::string strcontact = mpLabelJunctionContactPoint->text().toStdString();
- int nllindex = mpCBJunctionFromTo->currentIndex();
- pJC->DeleteJunctionLaneLink(nllindex);
- onClickCBJunctionConnectionChange(mpCBJunctionConnection->currentIndex());
- }
- void MainWindow::onClickPreNxtRoadChange(int index)
- {
- mpCBPreNxtRelLane->clear();
- Road * pRoad = mxodr.GetRoad(index);
- if(pRoad == NULL)
- {
- return;
- }
- LaneSection * pLS;
- if(strncmp(mpCBPreNxtConatact->currentText().toStdString().data(),"start",255)==0)
- {
- pLS = pRoad->GetLaneSection(0);
- }
- else
- {
- pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- }
- if(pLS == NULL)
- {
- std::cout<<"MainWindow::onClickPreNxtRoadChange can't find lanesection"<<std::endl;
- return;
- }
- int nlanecount = pLS->GetLaneCount();
- int i;
- for(i=0;i<nlanecount;i++)
- {
- Lane * pLane = pLS->GetLane(i);
- char strout[255];
- snprintf(strout,255,"%d %s",pLane->GetId(),pLane->GetType().data());
- mpCBPreNxtRelLane->addItem(strout);
- }
- }
- void MainWindow::onClickSetRoadPredecessor()
- {
- Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
- if(pRoad == NULL)
- {
- return;
- }
- Road * pOtherRoad = mxodr.GetRoad(mpCBPreNxtRoad->currentIndex());
- if(pOtherRoad == NULL)
- {
- return;
- }
- std::string strcontact = mpCBPreNxtConatact->currentText().toStdString();
- int curlane = mpCBRoadShowPre->currentIndex();
- int otherlane = mpCBPreNxtRelLane->currentIndex();
- pRoad->SetPredecessor("road",pOtherRoad->GetRoadId(),strcontact);
- LaneSection * pLS = pRoad->GetLaneSection(0);
- Lane * pLane =pLS->GetLane(curlane);
- LaneSection * pLSOther;
- if(strncmp(strcontact.data(),"start",0) == 0)
- {
- pLSOther = pOtherRoad->GetLaneSection(0);
- }
- else
- {
- pLSOther = pOtherRoad->GetLaneSection(pOtherRoad->GetLaneSectionCount()-1);
- }
- Lane * pLaneOther = pLSOther->GetLane(otherlane);
- if(pLaneOther == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("no this lane."));
- return;
- }
- pLane->SetPredecessor(pLaneOther->GetId());
- onClickCBRoadChange(mpCBRoad->currentIndex());
- }
- void MainWindow::onClickSetRoadSuccessor()
- {
- Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
- if(pRoad == NULL)
- {
- return;
- }
- Road * pOtherRoad = mxodr.GetRoad(mpCBPreNxtRoad->currentIndex());
- if(pOtherRoad == NULL)
- {
- return;
- }
- std::string strcontact = mpCBPreNxtConatact->currentText().toStdString();
- int curlane = mpCBRoadShowNext->currentIndex();
- int otherlane = mpCBPreNxtRelLane->currentIndex();
- pRoad->SetSuccessor("road",pOtherRoad->GetRoadId(),strcontact);
- LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- Lane * pLane =pLS->GetLane(curlane);
- LaneSection * pLSOther;
- if(strncmp(strcontact.data(),"start",0) == 0)
- {
- pLSOther = pOtherRoad->GetLaneSection(0);
- }
- else
- {
- pLSOther = pOtherRoad->GetLaneSection(pOtherRoad->GetLaneSectionCount()-1);
- }
- Lane * pLaneOther = pLSOther->GetLane(otherlane);
- if(pLaneOther == NULL)
- {
- QMessageBox::warning(this,tr("Warn"),tr("no this lane."));
- return;
- }
- pLane->SetSuccessor(pLaneOther->GetId());
- onClickCBRoadChange(mpCBRoad->currentIndex());
- }
- void MainWindow::onClickDelRoadPredecessor()
- {
- Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
- if(pRoad == NULL)
- {
- return;
- }
- int curlane = mpCBRoadShowPre->currentIndex();
- LaneSection * pLS = pRoad->GetLaneSection(0);
- Lane * pLane =pLS->GetLane(curlane);
- if(pLane == 0)
- {
- return;
- }
- pLane->RemovePredecessor();
- int i;
- int nlanecount = pLS->GetLaneCount();
- bool bAllNotHavePre = true;
- for(i=0;i<nlanecount;i++)
- {
- Lane * pLa= pLS->GetLane(i);
- if(pLa->IsPredecessorSet())
- {
- bAllNotHavePre = false;
- break;
- }
- }
- if(bAllNotHavePre)
- {
- pRoad->RemovePredecessor();
- }
- onClickCBRoadChange(mpCBRoad->currentIndex());
- }
- void MainWindow::onClickDelRoadSuccessor()
- {
- Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
- if(pRoad == NULL)
- {
- return;
- }
- int curlane = mpCBRoadShowNext->currentIndex();
- LaneSection * pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
- Lane * pLane =pLS->GetLane(curlane);
- if(pLane == 0)
- {
- return;
- }
- pLane->RemoveSuccessor();
- int i;
- int nlanecount = pLS->GetLaneCount();
- bool bAllNotHaveNxt = true;
- for(i=0;i<nlanecount;i++)
- {
- Lane * pLa= pLS->GetLane(i);
- if(pLa->IsSuccessorSet())
- {
- bAllNotHaveNxt = false;
- break;
- }
- }
- if(bAllNotHaveNxt)
- {
- pRoad->RemoveSuccessor();
- }
- onClickCBRoadChange(mpCBRoad->currentIndex());
- }
- void MainWindow::onClickAutoConnect()
- {
- if(mxodr.GetRoadCount() <= 0)
- {
- QMessageBox::warning(this,tr("Warning"),tr("OpenDrive Road Count is 0."),QMessageBox::YesAll);
- return;
- }
- AutoConnect pAC(&mxodr);
- pAC.Connect();
- updateJunction();
- }
- void MainWindow::on_actionLoad_triggered()
- {
- onClickLoad();
- }
- void MainWindow::on_actionSave_triggered()
- {
- onClickSave();
- }
- void MainWindow::on_actionAutoConnect_triggered()
- {
- onClickAutoConnect();
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionSet_Speed_triggered()
- {
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
- return;
- #endif
- std::string strroadid = mpCBRoad->currentText().toStdString();
- SpeedDialog sd(&mxodr,strroadid,this);
- int res = sd.exec();(void)res;
- }
- void MainWindow::closeEvent(QCloseEvent *event)
- {
- if(mxodr.GetRoadCount() == 0)
- {
- event->accept(); // 接受退出信号,程序退出
- return;
- }
- if(mnNotSave == 0)
- {
- event->accept(); // 接受退出信号,程序退出
- return;
- }
- QMessageBox::StandardButton button;
- button=QMessageBox::question(this,tr("退出程序"),QString(tr("确认退出程序")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- event->ignore(); // 忽略退出信号,程序继续进行
- }
- else if(button==QMessageBox::Yes)
- {
- event->accept(); // 接受退出信号,程序退出
- }
- }
- void MainWindow::on_actionSet_Traffic_Light_triggered()
- {
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
- return;
- #endif
- std::string strroadid = mpCBRoad->currentText().toStdString();
- TrafficLightDialog td(&mxodr,strroadid,this);
- int res = td.exec();
- (void)res;
- }
- void MainWindow::on_actionEdit_Road_Lane_triggered()
- {
- }
- void MainWindow::on_actionEdit_Road_triggered()
- {
- SaveBack();
- std::string strroadid = mpCBRoad->currentText().toStdString();
- RoadEditDialog rd(&mxodr,strroadid,this);
- int res = rd.exec();
- (void)res;
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionAdd_Road_From_RTK_triggered()
- {
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
- return;
- #endif
- SaveBack();
- DialogAddRoadFromRTK arfrd(&mxodr,glon0,glat0,this);
- arfrd.exec();
- mpLELat0->setText(QString::number(glat0,'f',7));
- mpLELon0->setText(QString::number(glon0,'f',7));
- updateCBRoad();
- mbRefresh = true;
- update();
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::onClickSetMove()
- {
- double fMoveX = mpLE_SelX->text().toDouble();
- double fMoveY = mpLE_SelY->text().toDouble();
- mfViewMoveX = mfViewMoveX - fMoveX;
- mfViewMoveY = mfViewMoveY - fMoveY;
- mbRefresh = true;
- update();
- mpLEViewMoveX->setText(QString::number(mfViewMoveX,'f',2));
- mpLEViewMoveY->setText(QString::number(mfViewMoveY,'f',2));
- // updateView();
- }
- void MainWindow::onClickReSetMove()
- {
- mfViewMoveX = 0;
- mfViewMoveY = 0;
- mbRefresh = true;
- update();
- mpLEViewMoveX->setText(QString::number(mfViewMoveX,'f',2));
- mpLEViewMoveY->setText(QString::number(mfViewMoveY,'f',2));
- }
- void MainWindow::on_actionSummary_Road_triggered()
- {
- int nroadnum = mxodr.GetRoadCount();
- int i;
- double flen = 0;
- for(i=0;i<nroadnum;i++)
- {
- flen = flen + mxodr.GetRoad(i)->GetRoadLength();
- }
- char strout[256];
- snprintf(strout,256,"Road Count:%d Length Total:%f",nroadnum,flen);
- QMessageBox::information(this,tr("Summary"),QString(strout),QMessageBox::YesAll);
- }
- void MainWindow::on_actionSplit_Road_triggered()
- {
- }
- void MainWindow::UpdateScene()
- {
- int i;
- int nsize = mvectorviewitem.size();
- for(i=0;i<nsize;i++)
- {
- mpscene->removeItem(mvectorviewitem.at(i));
- delete mvectorviewitem.at(i);
- }
- nsize = mvectorgeoitem.size();
- for(i=0;i<nsize;i++)
- {
- mpscene->removeItem(mvectorgeoitem.at(i));
- delete mvectorgeoitem.at(i);
- }
- mvectorviewitem.clear();
- mvectorgeoitem.clear();
- nsize = mxodr.GetRoadCount();
- std::vector<RoadDigit> xvectorrd;
- for(i=0;i<nsize;i++)
- {
- RoadDigit xrd(mxodr.GetRoad(i),5.0);
- xvectorrd.push_back(xrd);
- // UpdateSceneRoad(mxodr.GetRoad(i));
- // qDebug("update road %d",i);
- }
- for(i=0;i<nsize;i++)
- {
- if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
- {
- continue;
- }
- std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&(xvectorrd[i]));
- int j;
- int ncount = xvectorlanepath.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsPathItem * pitem = xvectorlanepath[j];
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
- mpscene->addItem(pitem);
- mvectorviewitem.push_back(pitem);
- }
- }
- for(i=0;i<nsize;i++)
- {
- if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
- {
- continue;
- }
- std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&(xvectorrd[i]));
- int j;
- int ncount = xvectormarkpath.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsPathItem * pitem = xvectormarkpath[j];
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
- mpscene->addItem(pitem);
- mvectorviewitem.push_back(pitem);
- }
- }
- for(i=0;i<nsize;i++)
- {
- if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
- {
- continue;
- }
- std::vector<QGraphicsTextItem *> xvectortext;
- std::vector<QGraphicsPathItem *> xvectorparkmark;
- std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]),xvectortext,
- xvectorparkmark);
- int j;
- int ncount = xvectorparkpath.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsPathItem * pitem = xvectorparkpath[j];
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
- mpscene->addItem(pitem);
- mvectorviewitem.push_back(pitem);
- }
- ncount = xvectortext.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsTextItem * pitem = xvectortext[j];
- // pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + (-24.0),-mfViewMoveY+VIEW_HEIGHT/2.0+(-102.0));
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + pitem->pos().x(),-mfViewMoveY+VIEW_HEIGHT/2.0+pitem->pos().y());
- mpscene->addItem(pitem);
- }
- ncount = xvectorparkmark.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsPathItem * pitem = xvectorparkmark[j];
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
- mpscene->addItem(pitem);
- mvectorviewitem.push_back(pitem);
- }
- }
- UpdateScene_SelectRoadRefGeo();
- mbRefresh = false;
- // mpscene->addLine(0,0,1000,100);
- }
- void MainWindow::UpdateScene_SelectRoadRefGeo()
- {
- int i;
- int nsize;
- nsize = mvectorgeoitem.size();
- for(i=0;i<nsize;i++)
- {
- mpscene->removeItem(mvectorgeoitem.at(i));
- delete mvectorgeoitem.at(i);
- }
- mvectorgeoitem.clear();
- if(mbHideSelected)return;
- int selid = mpCBRoad->currentText().toInt();
- nsize = mxodr.GetRoadCount();
- for(i=0;i<nsize;i++)
- {
- if(IsHidenRoad(atoi(mxodr.GetRoad(i)->GetRoadId().data())))
- {
- continue;
- }
- if(selid == atoi(mxodr.GetRoad(i)->GetRoadId().data()))
- {
- RoadDigit xrd(mxodr.GetRoad(i),5.0);
- std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadRefGeoItem(&(xrd));
- int j;
- int ncount = xvectorlanepath.size();
- for(j=0;j<ncount;j++)
- {
- QGraphicsPathItem * pitem = xvectorlanepath[j];
- pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
- mpscene->addItem(pitem);
- mvectorgeoitem.push_back(pitem);
- }
- }
- }
- }
- void MainWindow::onViewModeChange(int index)
- {
- if(index == 1)
- {
- UpdateScene();
- }
- mnViewMode = index;
- mbRefresh = true;
- update();
- }
- void MainWindow::on_actionCalc_Road_S_triggered()
- {
- DialogCalcS calcs(&mxodr,glon0,glat0,this);
- calcs.exec();
- }
- void MainWindow::on_actionBack_triggered()
- {
- if(mvectorxodrback.size()>0)
- {
- mxodr = mvectorxodrback.at(mvectorxodrback.size() -1);
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mvectorxodrback.erase(mvectorxodrback.begin() + mvectorxodrback.size()-1);
- }
- else
- {
- QMessageBox::warning(this,tr("Warning"),tr("No Back Option"),QMessageBox::YesAll);
- }
- }
- void MainWindow::SaveBack()
- {
- if(mxodr.GetRoadCount() > 0)
- {
- mvectorxodrback.push_back(mxodr);
- if(mvectorxodrback.size() > 10)
- {
- mvectorxodrback.erase(mvectorxodrback.begin());
- }
- }
- mnNotSave++;
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionEdit_Road_Borrow_triggered()
- {
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
- return;
- #endif
- std::string strroadid = mpCBRoad->currentText().toStdString();
- DialogRoadBorrow rbd(&mxodr,strroadid,this);
- int res = rbd.exec();
- (void)res;
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionMake_All_Road_Contact_triggered()
- {
- QMessageBox::StandardButton button;
- // button=QMessageBox::question(this,tr("路口道路创建"),QString(tr("是否让软件自动创建所有路口道路?")),QMessageBox::Yes|QMessageBox::No);
- button=QMessageBox::question(this,tr("Junction Create"),QString(tr("Do you want Auto Create Junction?")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- return;
- }
- else if(button==QMessageBox::Yes)
- {
- }
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warnig","This Function is not comlete.Please Wait.",QMessageBox::YesAll);
- return;
- #endif
- on_actionAutoConnect_triggered();
- AutoRoadContact::MakeAllContact(&mxodr);
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionHide_Road_triggered()
- {
- std::string strroadid = mpCBRoad->currentText().toStdString();
- DialogHideRoad hrd(&mxodr,strroadid,&mvectorhideroadid, this);
- int res = hrd.exec();
- if(res == 0){}
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- bool MainWindow::IsHidenRoad(int nroadid)
- {
- bool bIsHiden = false;
- unsigned int i;
- for(i=0;i<mvectorhideroadid.size();i++)
- {
- if(nroadid == mvectorhideroadid[i])
- {
- bIsHiden = true;
- break;
- }
- }
- return bIsHiden;
- }
- void MainWindow::on_actionHide_Selected_triggered()
- {
- if(mbHideSelected)
- {
- mbHideSelected = false;
- ui->actionHide_Selected->setText(tr("Hide Selected"));
- }
- else
- {
- mbHideSelected = true;
- ui->actionHide_Selected->setText(tr("Show Selected"));
- }
- UpdateScene_SelectRoadRefGeo();
- }
- void MainWindow::on_actionDraw_Road_triggered()
- {
- DialogDrawRoad * pdlgdraw = mpdlgdraw;
- pdlgdraw->setModal(false);
- pdlgdraw->show();
- }
- void MainWindow::onDrawNewRoad()
- {
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_actionEdit_Road_Noavoid_triggered()
- {
- #ifdef OPENDRIVE_EDITONLY
- QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
- return;
- #endif
- std::string strroadid = mpCBRoad->currentText().toStdString();
- DialogRoadNoavoid rbd(&mxodr,strroadid,this);
- rbd.exec();
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionAdd_Road_From_NDS_triggered()
- {
- DialogAddRoadFromNDS rnd(&mxodr, this);
- rnd.exec();
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_CreateBefore_triggered()
- {
- bool ok;
- QString text = QInputDialog::getText(this, tr("Get Road ID"),
- tr("Road ID:"), QLineEdit::Normal,
- mpCBRoad->currentText(), &ok);
- Road * pRoad =NULL;
- if (ok && !text.isEmpty())
- {
- std::string strroadid = text.toStdString();
- int i;
- for(i=0;i<(int)mxodr.GetRoadCount();i++)
- {
- if(mxodr.GetRoad(i)->GetRoadId() == strroadid)
- {
- pRoad = mxodr.GetRoad(i);
- break;
- }
- }
- if(pRoad == NULL)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road is not exist."),QMessageBox::YesAll);
- return;
- }
- }
- else
- {
- return;
- }
- double fLength = 0.0;
- text = QInputDialog::getText(this, tr("Set Length"),
- tr("Length:"), QLineEdit::Normal,
- "100.0", &ok);
- if (ok && !text.isEmpty())
- {
- fLength = text.toDouble();
- if(fLength<=0)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road Lenth is negative or zero."),QMessageBox::YesAll);
- return;
- }
- }
- mpfb->SetOpenDrive(mxodr);
- CreateExtendRoad::CreateBeforeRoad(&mxodr,pRoad,fLength);
- std::cout<<"create road."<<std::endl;
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_CreateAfter_triggered()
- {
- bool ok;
- QString text = QInputDialog::getText(this, tr("Get Road ID"),
- tr("Road ID:"), QLineEdit::Normal,
- mpCBRoad->currentText(), &ok);
- Road * pRoad =NULL;
- if (ok && !text.isEmpty())
- {
- std::string strroadid = text.toStdString();
- int i;
- for(i=0;i<(int)mxodr.GetRoadCount();i++)
- {
- if(mxodr.GetRoad(i)->GetRoadId() == strroadid)
- {
- pRoad = mxodr.GetRoad(i);
- break;
- }
- }
- if(pRoad == NULL)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road is not exist."),QMessageBox::YesAll);
- return;
- }
- }
- else
- {
- return;
- }
- double fLength = 0.0;
- text = QInputDialog::getText(this, tr("Set Length"),
- tr("Length:"), QLineEdit::Normal,
- "100.0", &ok);
- if (ok && !text.isEmpty())
- {
- fLength = text.toDouble();
- if(fLength<=0)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road Lenth is negative or zero."),QMessageBox::YesAll);
- return;
- }
- }
- mpfb->SetOpenDrive(mxodr);
- CreateExtendRoad::CreateAfterRoad(&mxodr,pRoad,fLength);
- std::cout<<"create road."<<std::endl;
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_actionAdd_Road_From_CDA_triggered()
- {
- if(ServiceExcelAPI.IsLoad() == false)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Can't load ivxlnt plugin."),QMessageBox::YesAll);
- return;
- }
- QString str = QFileDialog::getOpenFileName(this,"Load xlsx",".","*.xlsx");
- if(str.isEmpty())return;
- // QString str = "/home/yuchuli/3.xlsx";
- int nrtn = CDAProc::Proc(str.toStdString(),&mxodr);
- if(nrtn<0)
- {
- std::cout<<" CDAProc::Proc return code: "<<nrtn<<std::endl;
- QMessageBox::warning(this,tr("Warning"),tr("CDA Create road fail."),QMessageBox::YesAll);
- }
- AutoConnect pAC(&mxodr);
- pAC.Connect();
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_actionDraw_Road_From_CDA_triggered()
- {
- DialogAddRoadFromCDA xdlg(&mxodr, this);
- if(xdlg.exec() == QDialog::Accepted)
- {
- }
- else
- {
- return;
- }
- AutoConnect pAC(&mxodr);
- pAC.Connect();
- updateJunction();
- updateCBRoad();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- void MainWindow::on_actionAdd_Roads_From_Labels_triggered()
- {
- if(ServiceExcelAPI.IsLoad() == false)
- {
- QMessageBox::warning(this,tr("Warning"),tr("Can't load ivxlnt plugin."),QMessageBox::YesAll);
- return;
- }
- QString str = QFileDialog::getOpenFileName(this,"Load xlsx",".","*.xlsx");
- if(str.isEmpty())return;
- // QString str = "/home/yuchuli/下载/Scenarios(1).xlsx";
- QString strdir = QFileDialog::getExistingDirectory(this,tr("Set Save Directory"),".");
- if(strdir.isNull())return;
- int nrtn = CDAProc::ProcRoads(str.toStdString(),strdir.toStdString());
- if(nrtn == 0)
- {
- QMessageBox::information(this,tr("Info"),tr("Successfully."),QMessageBox::YesAll);
- }
- else
- {
- QMessageBox::warning(this,tr("Warning"),tr("Some Item convert fail. Please Check."),QMessageBox::YesAll);
- }
- }
- void MainWindow::on_actionEdit_Road_Priority_triggered()
- {
- std::string strroadid = mpCBRoad->currentText().toStdString();
- DialogRoadPriority rpd(&mxodr,strroadid,this);
- rpd.exec();
- mpfb->SetOpenDrive(mxodr);
- }
- void MainWindow::on_actionExport_Current_Road_triggered()
- {
- int index = mpCBRoad->currentIndex();
- qDebug("index: %d",index);
- int nroadsize = static_cast<int>(mxodr.GetRoadCount());
- if((index<0)||(index>=nroadsize))
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road Index Error."),QMessageBox::YesAll);
- return;
- }
- QString strsavepath = QFileDialog::getSaveFileName(this,tr("Save Select Road"),getenv("HOME"),"*.xodr");
- if(strsavepath.isEmpty())return;
- if(strsavepath.length()>4)
- {
- if(strsavepath.right(5) == ".xodr" )
- {
- }
- else
- {
- strsavepath.append(".xodr");
- }
- }
- else
- {
- strsavepath.append(".xodr");
- }
- OpenDrive * pxodr = new OpenDrive();
- unsigned short int revMajor,revMinor;
- std::string name,date;
- float version;
- double north,south,east,west,lat0,lon0,hdg0;
- mxodr.GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
- pxodr->SetHeader(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
- pxodr->GetRoadVector()->push_back(mxodr.GetRoadVector()->at(index));
- OpenDriveXmlWriter x(pxodr);
- x.WriteFile(strsavepath.toStdString());
- delete pxodr;
- }
- void MainWindow::on_actionOptimize_Road_triggered()
- {
- QMessageBox::StandardButton button;
- // button=QMessageBox::question(this,tr("优化当前选中的道路"),QString(tr("是否优化当前选中道路?")),QMessageBox::Yes|QMessageBox::No);
- button=QMessageBox::question(this,tr("Optimize Road"),QString(tr("Optimize selected road?")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- return;
- }
- else if(button==QMessageBox::Yes)
- {
- }
- int index = mpCBRoad->currentIndex();
- qDebug("index: %d",index);
- int nroadsize = static_cast<int>(mxodr.GetRoadCount());
- if((index<0)||(index>=nroadsize))
- {
- QMessageBox::warning(this,tr("Warning"),tr("Road Index Error."),QMessageBox::YesAll);
- return;
- }
- SaveBack();
- Road * pRoad = mxodr.GetRoad(index);
- if(pRoad == NULL)return;
- int nrtn = xodrfunc::optimizeroad(pRoad);
- if(nrtn == 1)
- {
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
- else
- {
- std::cout<<" no optimize, so not need update."<<std::endl;
- }
- }
- void MainWindow::on_actionAdd_ParkSpace_triggered()
- {
- int nroadcount = mxodr.GetRoadCount();
- if(nroadcount == 0)return;
- Road * pRoad = mxodr.GetRoad(mpCBRoad->currentIndex());
- if(pRoad == 0)return;
- double fLon = mpLE_SelLon->text().toDouble();
- double fLat = mpLE_SelLat->text().toDouble();
- SaveBack();
- DialogParkingFromPoint dlgparkpoint(pRoad,fLon,fLat,this);
- dlgparkpoint.exec();
- mbRefresh = true;
- update();
- if(mpCBViewMode->currentIndex() == 1)
- {
- UpdateScene();
- }
- }
|