diff --git a/OpenRoadEd/OpenDrive/ObjectSignal.cpp b/OpenRoadEd/OpenDrive/ObjectSignal.cpp index b71539b99b13a09a2425d2d06b76e17689473219..81db8095651bcd5ed41eb3f3d1afda5b9b5c830c 100644 --- a/OpenRoadEd/OpenDrive/ObjectSignal.cpp +++ b/OpenRoadEd/OpenDrive/ObjectSignal.cpp @@ -17,6 +17,9 @@ Object::Object() mRoll=0.0; mBoundingBox=false; mBoundingCylinder=false; + mParkingAccess="all"; + mParkingRestrictions="none"; + mParkingMarkings.clear(); } Object::Object(std::string &name,std::string &id) @@ -35,6 +38,9 @@ Object::Object(std::string &name,std::string &id) mRoll=0.0; mBoundingBox=false; mBoundingCylinder=false; + mParkingAccess="all"; + mParkingRestrictions="none"; + mParkingMarkings.clear(); } Object::Object(const Object &object) @@ -64,6 +70,9 @@ Object::Object(const Object &object) mBounding.cylinder.radius=object.mBounding.cylinder.radius; mBounding.cylinder.height=object.mBounding.cylinder.height; } + mParkingAccess=object.mParkingAccess; + mParkingRestrictions=object.mParkingRestrictions; + mParkingMarkings=object.mParkingMarkings; } const Object &Object::operator=(const Object &rhs) @@ -185,6 +194,49 @@ bool Object::GetBoundingCylinder(double &radius,double &height) return mBoundingCylinder; } + +std::string Object::GetParkingAccess(void) +{ + if(this->mType=="parkingSpace") + return this->mParkingAccess; + else + return std::string(""); +} + +std::string Object::GetParkingRestrictions(void) +{ + if(this->mType=="parkingSpace") + return this->mParkingRestrictions; + else + return std::string(""); +} + +unsigned int Object::GetNumParkingMarkings(void) +{ + if(this->mType=="parkingSpace") + return this->mParkingMarkings.size(); + else + return 0; +} + +bool Object::GetParkingMarking(unsigned int index,std::string &side, std::string &type, double &width,std::string &color) +{ + if(this->mType=="parkingSpace") + { + if(index>=0 && index<mParkingMarkings.size()) + { + side=mParkingMarkings[index].side; + type=mParkingMarkings[index].type; + width=mParkingMarkings[index].width; + color=mParkingMarkings[index].color; + return true; + } + else + return false; + } + else + return false; +} void Object::SetS(const double s) { @@ -269,6 +321,69 @@ void Object::ClearBounding(void) mBoundingCylinder=false; } +void Object::SetParkingAccess(const std::string &access) +{ + if(mType=="parkingSpace") + mParkingAccess=access; +} + +void Object::SetParkingRestrictions(const std::string &restrictions) +{ + if(mType=="parkingSpace") + mParkingRestrictions=restrictions; +} + +void Object::AddParkingMarking(const std::string &side, const std::string &type, const double width, const std::string &color) +{ + TParkingSpaceMarking new_markings; + + std::vector<TParkingSpaceMarking>::iterator it; + + if(mType=="parkingSpace") + { + for(it=mParkingMarkings.begin();it!=mParkingMarkings.end();it++) + { + if(it->side==side) + { + it->side=side; + it->type=type; + it->width=width; + it->color=color; + return; + } + } + new_markings.side=side; + new_markings.type=type; + new_markings.width=width; + new_markings.color=color; + mParkingMarkings.push_back(new_markings); + } +} + +void Object::RemoveParkingMarking(const std::string &side) +{ + std::vector<TParkingSpaceMarking>::iterator it; + + if(mType=="parkingSpace") + { + for(it=mParkingMarkings.begin();it!=mParkingMarkings.end();it++) + { + if(it->side==side) + { + mParkingMarkings.erase(it); + return; + } + } + } +} + +void Object::ClearParking(void) +{ + mParkingAccess="all"; + mParkingRestrictions="none"; + mParkingMarkings.clear(); +} + Signal::Signal() { mS=0.0; diff --git a/OpenRoadEd/OpenDrive/ObjectSignal.h b/OpenRoadEd/OpenDrive/ObjectSignal.h index 762873fb34cc9666c883b38e9a5a20fdface58d4..6d995ee3faef0b0bcf8352919e2e099893b94f6c 100644 --- a/OpenRoadEd/OpenDrive/ObjectSignal.h +++ b/OpenRoadEd/OpenDrive/ObjectSignal.h @@ -2,7 +2,7 @@ #define OBJECTSIGNAL_H #include <string> - +#include <vector> typedef struct { @@ -23,6 +23,14 @@ typedef union TBoundingCylinder cylinder; }TBounding; +typedef struct +{ + std::string side; + std::string type; + double width; + std::string color; +}TParkingSpaceMarking; + //*********************************************************************************** //Object //*********************************************************************************** @@ -44,6 +52,10 @@ class Object bool mBoundingBox; bool mBoundingCylinder; TBounding mBounding; + // parking space specific attributes + std::string mParkingAccess; + std::string mParkingRestrictions; + std::vector<TParkingSpaceMarking> mParkingMarkings; public: Object(); Object(std::string &name,std::string &id); @@ -68,6 +80,10 @@ class Object bool IsBoundigCylinder(void); TBoundingCylinder GetBoundingCylinder(void); bool GetBoundingCylinder(double &radius,double &height); + std::string GetParkingAccess(void); + std::string GetParkingRestrictions(void); + unsigned int GetNumParkingMarkings(void); + bool GetParkingMarking(unsigned int index,std::string &side, std::string &type, double &width,std::string &color); void SetS(const double s); void SetT(const double t); @@ -84,7 +100,11 @@ class Object void SetBoundingBox(double length,double width,double height); void SetBoundingCylinder(double radius,double height); void ClearBounding(void); - + void SetParkingAccess(const std::string &access); + void SetParkingRestrictions(const std::string &restrictions); + void AddParkingMarking(const std::string &side, const std::string &type, const double width,const std::string &color); + void RemoveParkingMarking(const std::string &side); + void ClearParking(void); }; //---------------------------------------------------------------------------------- diff --git a/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp b/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp index 8c06fa67231a2cbe01086a44a91aead8653e5c76..7488fe0b90485a90fb600511c6b7b9a7b73d48fb 100644 --- a/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp +++ b/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp @@ -10,8 +10,8 @@ using std::endl; * Constructor which saves a reference to OpenDrive structure */ OpenDriveXmlParser::OpenDriveXmlParser (OpenDrive* openDriveObj) -{ - mOpenDrive=openDriveObj; +{ + mOpenDrive=openDriveObj; } /** @@ -20,282 +20,282 @@ OpenDriveXmlParser::OpenDriveXmlParser (OpenDrive* openDriveObj) */ bool OpenDriveXmlParser::ReadHeader(TiXmlElement *node) { - //Read the Header - unsigned short int revMajor; - unsigned short int revMinor; - string name; - float version; - string date; - double north; - double south; - double east; - double west; - - int checker=TIXML_SUCCESS; - checker+=node->QueryValueAttribute<unsigned short int>("revMajor",&revMajor); - checker+=node->QueryValueAttribute<unsigned short int>("revMinor",&revMinor); - checker+=node->QueryStringAttribute("name",&name); - checker+=node->QueryFloatAttribute("version",&version); - checker+=node->QueryStringAttribute("date",&date); - checker+=node->QueryDoubleAttribute("north",&north); - checker+=node->QueryDoubleAttribute("south",&south); - checker+=node->QueryDoubleAttribute("east",&east); - checker+=node->QueryDoubleAttribute("west",&west); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Header attributes"<<endl; - return false; - } - - mOpenDrive->SetHeader(revMajor, revMinor, name, version, date, north, south, east, west); - - return true; + //Read the Header + unsigned short int revMajor; + unsigned short int revMinor; + string name; + float version; + string date; + double north; + double south; + double east; + double west; + + int checker=TIXML_SUCCESS; + checker+=node->QueryValueAttribute<unsigned short int>("revMajor",&revMajor); + checker+=node->QueryValueAttribute<unsigned short int>("revMinor",&revMinor); + checker+=node->QueryStringAttribute("name",&name); + checker+=node->QueryFloatAttribute("version",&version); + checker+=node->QueryStringAttribute("date",&date); + checker+=node->QueryDoubleAttribute("north",&north); + checker+=node->QueryDoubleAttribute("south",&south); + checker+=node->QueryDoubleAttribute("east",&east); + checker+=node->QueryDoubleAttribute("west",&west); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Header attributes"<<endl; + return false; + } + + mOpenDrive->SetHeader(revMajor, revMinor, name, version, date, north, south, east, west); + + return true; } //-------------- bool OpenDriveXmlParser::ReadRoad(TiXmlElement *node) { - //Read road attributes - string name; - double length; - string id; - string junction; - - int checker=TIXML_SUCCESS; - - checker+=node->QueryStringAttribute("name",&name); - checker+=node->QueryDoubleAttribute("length",&length); - checker+=node->QueryStringAttribute("id",&id); - checker+=node->QueryStringAttribute("junction",&junction); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Road attributes"<<endl; - return false; - } - //fill in - mOpenDrive->AddRoad(name, length, id, junction); - Road* road = mOpenDrive->GetLastAddedRoad(); - TiXmlElement* subNode; - - - //Get links - subNode=node->FirstChildElement("link"); - if (subNode) - { - ReadRoadLinks (road,subNode); - } - - //Proceed to road Type - subNode=node->FirstChildElement("type"); - while (subNode) - { - ReadRoadType(road, subNode); - subNode=subNode->NextSiblingElement("type"); - } - - //Proceed to planView - subNode=node->FirstChildElement("planView"); - ReadPlanView(road, subNode); - - //Proceed to ElevationProfile - subNode=node->FirstChildElement("elevationProfile"); - if (subNode) - { - ReadElevationProfile(road, subNode); - } - - //Proceed to LateralProfile - subNode=node->FirstChildElement("lateralProfile"); - if (subNode) - { - ReadLateralProfile(road, subNode); - } - - //Proceed to Lanes - subNode=node->FirstChildElement("lanes"); - ReadLanes(road, subNode); - - //Proceed to Objects - subNode=node->FirstChildElement("objects"); - if (subNode) - { - ReadObjects(road, subNode); - } - - //Proceed to Signals - subNode=node->FirstChildElement("signals"); - if (subNode) - { - ReadSignals(road, subNode); - } - - //Proceed to Surface - subNode=node->FirstChildElement("surface"); - if (subNode) - { - ReadSurface(road, subNode); - } - - return true; + //Read road attributes + string name; + double length; + string id; + string junction; + + int checker=TIXML_SUCCESS; + + checker+=node->QueryStringAttribute("name",&name); + checker+=node->QueryDoubleAttribute("length",&length); + checker+=node->QueryStringAttribute("id",&id); + checker+=node->QueryStringAttribute("junction",&junction); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Road attributes"<<endl; + return false; + } + //fill in + mOpenDrive->AddRoad(name, length, id, junction); + Road* road = mOpenDrive->GetLastAddedRoad(); + TiXmlElement* subNode; + + + //Get links + subNode=node->FirstChildElement("link"); + if (subNode) + { + ReadRoadLinks (road,subNode); + } + + //Proceed to road Type + subNode=node->FirstChildElement("type"); + while (subNode) + { + ReadRoadType(road, subNode); + subNode=subNode->NextSiblingElement("type"); + } + + //Proceed to planView + subNode=node->FirstChildElement("planView"); + ReadPlanView(road, subNode); + + //Proceed to ElevationProfile + subNode=node->FirstChildElement("elevationProfile"); + if (subNode) + { + ReadElevationProfile(road, subNode); + } + + //Proceed to LateralProfile + subNode=node->FirstChildElement("lateralProfile"); + if (subNode) + { + ReadLateralProfile(road, subNode); + } + + //Proceed to Lanes + subNode=node->FirstChildElement("lanes"); + ReadLanes(road, subNode); + + //Proceed to Objects + subNode=node->FirstChildElement("objects"); + if (subNode) + { + ReadObjects(road, subNode); + } + + //Proceed to Signals + subNode=node->FirstChildElement("signals"); + if (subNode) + { + ReadSignals(road, subNode); + } + + //Proceed to Surface + subNode=node->FirstChildElement("surface"); + if (subNode) + { + ReadSurface(road, subNode); + } + + return true; } //-------------- bool OpenDriveXmlParser::ReadRoadLinks (Road* road, TiXmlElement *node) { - TiXmlElement* subNode; - subNode=node->FirstChildElement("predecessor"); - if (subNode) - { - ReadRoadLink(road, subNode,0); - } - - subNode=node->FirstChildElement("successor"); - if (subNode) - { - ReadRoadLink(road, subNode,1); - } - - subNode=node->FirstChildElement("neighbor"); - if (subNode) - { - ReadRoadLink(road, subNode,2); - } - - subNode=node->NextSiblingElement("neighbor"); - if (subNode) - { - ReadRoadLink(road, subNode,2); - } - - return true; + TiXmlElement* subNode; + subNode=node->FirstChildElement("predecessor"); + if (subNode) + { + ReadRoadLink(road, subNode,0); + } + + subNode=node->FirstChildElement("successor"); + if (subNode) + { + ReadRoadLink(road, subNode,1); + } + + subNode=node->FirstChildElement("neighbor"); + if (subNode) + { + ReadRoadLink(road, subNode,2); + } + + subNode=node->NextSiblingElement("neighbor"); + if (subNode) + { + ReadRoadLink(road, subNode,2); + } + + return true; } //-------------- bool OpenDriveXmlParser::ReadRoadLink (Road* road, TiXmlElement *node, short int type) { - //all three types (neighbor, successor or predecessor) have the same number and same types of members, - //but in case this changes in future, load it separately - if (type == 0) - { - string elementType; - string elementId; - string contactPoint; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("elementType",&elementType); - checker+=node->QueryStringAttribute("elementId",&elementId); - checker+=node->QueryStringAttribute("contactPoint",&contactPoint); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": missing element"<<endl; - return false; - } + //all three types (neighbor, successor or predecessor) have the same number and same types of members, + //but in case this changes in future, load it separately + if (type == 0) + { + string elementType; + string elementId; + string contactPoint; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("elementType",&elementType); + checker+=node->QueryStringAttribute("elementId",&elementId); + checker+=node->QueryStringAttribute("contactPoint",&contactPoint); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": missing element"<<endl; + return false; + } else { if(elementType!="road" && elementType!="junction") - { - cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": invalid element type: " << elementType << endl; - return false; - } + { + cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": invalid element type: " << elementType << endl; + return false; + } if(contactPoint!="start" && contactPoint!="end") - { - cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": invalid contact point: " << contactPoint << endl; - return false; - } + { + cout<<"Error parsing Predecessor attributes for road " << road->GetRoadName() << ": invalid contact point: " << contactPoint << endl; + return false; + } + } + road->SetPredecessor(elementType,elementId,contactPoint); + return true; + + } + else if (type == 1) + { + string elementType; + string elementId; + string contactPoint; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("elementType",&elementType); + checker+=node->QueryStringAttribute("elementId",&elementId); + checker+=node->QueryStringAttribute("contactPoint",&contactPoint); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": missing element"<<endl; + return false; } - road->SetPredecessor(elementType,elementId,contactPoint); - return true; - - } - else if (type == 1) - { - string elementType; - string elementId; - string contactPoint; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("elementType",&elementType); - checker+=node->QueryStringAttribute("elementId",&elementId); - checker+=node->QueryStringAttribute("contactPoint",&contactPoint); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": missing element"<<endl; - return false; - } else { if(elementType!="road" && elementType!="junction") - { - cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": invalid element type: " << elementType << endl; - return false; - } + { + cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": invalid element type: " << elementType << endl; + return false; + } if(contactPoint!="start" && contactPoint!="end") - { - cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": invalid contact point: " << contactPoint << endl; - return false; - } + { + cout<<"Error parsing Successor attributes for road " << road->GetRoadName() << ": invalid contact point: " << contactPoint << endl; + return false; + } + } + road->SetSuccessor(elementType,elementId,contactPoint); + return true; + } + + else if (type == 2) + { + string side; + string elementId; + string direction; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("side",&side); + checker+=node->QueryStringAttribute("elementId",&elementId); + checker+=node->QueryStringAttribute("direction",&direction); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Neighbor attributes for road " << road->GetRoadName() << ": missing element" << endl; + return false; } - road->SetSuccessor(elementType,elementId,contactPoint); - return true; - } - - else if (type == 2) - { - string side; - string elementId; - string direction; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("side",&side); - checker+=node->QueryStringAttribute("elementId",&elementId); - checker+=node->QueryStringAttribute("direction",&direction); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Neighbor attributes for road " << road->GetRoadName() << ": missing element" << endl; - return false; - } else { if(side!="left" && side!="right") - { - cout<<"Error parsing Neightbor attributes for road " << road->GetRoadName() << ": invalid side: " << side << endl; - return false; - } + { + cout<<"Error parsing Neightbor attributes for road " << road->GetRoadName() << ": invalid side: " << side << endl; + return false; + } if(direction!="same" && direction!="opposite") - { - cout<<"Error parsing Neightbor attributes for road " << road->GetRoadName() << ": invalid direction: " << direction << endl; - return false; - } + { + cout<<"Error parsing Neightbor attributes for road " << road->GetRoadName() << ": invalid direction: " << direction << endl; + return false; + } } - road->SetNeighbor(side,elementId,direction); - return true; - } + road->SetNeighbor(side,elementId,direction); + return true; + } - return false; - + return false; + } //-------------- bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node) { - double s; - string type; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("s",&s); - checker+=node->QueryStringAttribute("type",&type); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Road Type attributes"<<endl; - return false; - } + double s; + string type; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("s",&s); + checker+=node->QueryStringAttribute("type",&type); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Road Type attributes"<<endl; + return false; + } else { if(type!="unknown" && type!="rural" && type!="motorway" && type!="town" && type!="lowSpeed" && type!="pedestrian" && type!="bicycle" && type!="townExpressway" && type!="townCollector" && @@ -306,359 +306,359 @@ bool OpenDriveXmlParser::ReadRoadType (Road* road, TiXmlElement *node) } } - road->AddRoadType(s,type); - return true; + road->AddRoadType(s,type); + return true; } //-------------- bool OpenDriveXmlParser::ReadPlanView(Road* road, TiXmlElement *node) { - //Get geometry - TiXmlElement* subNode; - TiXmlElement* subNodeType; - subNode=node->FirstChildElement("geometry"); - - while (subNode) - { - subNodeType=subNode->FirstChildElement(); - if (subNodeType->ValueStr().compare("line")==0) - { - ReadGeometryBlock(road, subNode,0); //load a straight block - } - else if (subNodeType->ValueStr().compare("spiral")==0) - { - ReadGeometryBlock(road, subNode,1); //load a turn block - } - else if (subNodeType->ValueStr().compare("poly3")==0) - { - ReadGeometryBlock(road, subNode,2); //load a polynom spline block - } - else if (subNodeType->ValueStr().compare("paramPoly3")==0) - { - ReadGeometryBlock(road, subNode,3); //load a polynom spline block - } + //Get geometry + TiXmlElement* subNode; + TiXmlElement* subNodeType; + subNode=node->FirstChildElement("geometry"); + + while (subNode) + { + subNodeType=subNode->FirstChildElement(); + if (subNodeType->ValueStr().compare("line")==0) + { + ReadGeometryBlock(road, subNode,0); //load a straight block + } + else if (subNodeType->ValueStr().compare("spiral")==0) + { + ReadGeometryBlock(road, subNode,1); //load a turn block + } + else if (subNodeType->ValueStr().compare("poly3")==0) + { + ReadGeometryBlock(road, subNode,2); //load a polynom spline block + } + else if (subNodeType->ValueStr().compare("paramPoly3")==0) + { + ReadGeometryBlock(road, subNode,3); //load a polynom spline block + } else cout<<"Unsupported geometry type for road " << road->GetRoadName() << ": " << subNodeType->ValueStr() << endl; - + - subNode=subNode->NextSiblingElement("geometry"); + subNode=subNode->NextSiblingElement("geometry"); - } - return true; + } + return true; } //-------------- bool OpenDriveXmlParser::ReadGeometryBlock (Road* road, TiXmlElement *&node, short int blockType) { - road->AddGeometryBlock(); - GeometryBlock* geomBlock=road->GetLastAddedGeometryBlock(); - switch (blockType) - { - case 0: - ReadGeometry(geomBlock, node, 0); - break; - case 1: - ReadGeometry(geomBlock, node, 1); - node=node->NextSiblingElement("geometry"); - ReadGeometry(geomBlock, node, 2); - node=node->NextSiblingElement("geometry"); - ReadGeometry(geomBlock, node, 1); - break; - case 2: - ReadGeometry(geomBlock, node, 3); - break; - case 3: - ReadGeometry(geomBlock, node, 4); - break; - } - - return true; - + road->AddGeometryBlock(); + GeometryBlock* geomBlock=road->GetLastAddedGeometryBlock(); + switch (blockType) + { + case 0: + ReadGeometry(geomBlock, node, 0); + break; + case 1: + ReadGeometry(geomBlock, node, 1); + node=node->NextSiblingElement("geometry"); + ReadGeometry(geomBlock, node, 2); + node=node->NextSiblingElement("geometry"); + ReadGeometry(geomBlock, node, 1); + break; + case 2: + ReadGeometry(geomBlock, node, 3); + break; + case 3: + ReadGeometry(geomBlock, node, 4); + break; + } + + return true; + } //-------------- bool OpenDriveXmlParser::ReadGeometry(GeometryBlock* geomBlock, TiXmlElement *node, short int geometryType) { - double s, x, y, hdg, length; - //read the geometry node - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("s",&s); - checker+=node->QueryDoubleAttribute("x",&x); - checker+=node->QueryDoubleAttribute("y",&y); - checker+=node->QueryDoubleAttribute("hdg",&hdg); - checker+=node->QueryDoubleAttribute("length",&length); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Geometry attributes"<<endl; - return false; - } - - TiXmlElement *subNode=node->FirstChildElement(); - - //read the type nodes - switch ( geometryType ) + double s, x, y, hdg, length; + //read the geometry node + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("s",&s); + checker+=node->QueryDoubleAttribute("x",&x); + checker+=node->QueryDoubleAttribute("y",&y); + checker+=node->QueryDoubleAttribute("hdg",&hdg); + checker+=node->QueryDoubleAttribute("length",&length); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Geometry attributes"<<endl; + return false; + } + + TiXmlElement *subNode=node->FirstChildElement(); + + //read the type nodes + switch ( geometryType ) { - case 0: //line - geomBlock->AddGeometryLine(s,x,y,hdg,length); - break; - case 1: //spiral - checker=TIXML_SUCCESS; - double curvatureStart, curvatureEnd; - checker+=subNode->QueryDoubleAttribute("curvStart",&curvatureStart); - checker+=subNode->QueryDoubleAttribute("curvEnd",&curvatureEnd); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing spiral attributes"<<endl; - return false; - } - geomBlock->AddGeometrySpiral(s,x,y,hdg,length,curvatureStart,curvatureEnd); - break; - case 2: //arc - checker=TIXML_SUCCESS; - double curvature; - checker+=subNode->QueryDoubleAttribute("curvature",&curvature); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing arc attributes"<<endl; - return false; - } - geomBlock->AddGeometryArc(s,x,y,hdg,length,curvature); - break; - - - case 3: //poly3 - checker=TIXML_SUCCESS; - double a,b,c,d; - checker+=subNode->QueryDoubleAttribute("a",&a); - checker+=subNode->QueryDoubleAttribute("b",&b); - checker+=subNode->QueryDoubleAttribute("c",&c); - checker+=subNode->QueryDoubleAttribute("d",&d); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing poly3 attributes"<<endl; - return false; - } - - geomBlock->AddGeometryPoly3(s,x,y,hdg,length,a,b,c,d); - break; - - case 4: //parampoly3 - checker=TIXML_SUCCESS; - double au,bu,cu,du; - double av,bv,cv,dv; - checker+=subNode->QueryDoubleAttribute("aU",&au); - checker+=subNode->QueryDoubleAttribute("bU",&bu); - checker+=subNode->QueryDoubleAttribute("cU",&cu); - checker+=subNode->QueryDoubleAttribute("dU",&du); - checker+=subNode->QueryDoubleAttribute("aV",&av); - checker+=subNode->QueryDoubleAttribute("bV",&bv); - checker+=subNode->QueryDoubleAttribute("cV",&cv); - checker+=subNode->QueryDoubleAttribute("dV",&dv); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing paramPoly3 attributes"<<endl; - return false; - } - - geomBlock->AddGeometryParamPoly3(s,x,y,hdg,length,au,bu,cu,du,av,bv,cv,dv); - break; - - } - - return true; + case 0: //line + geomBlock->AddGeometryLine(s,x,y,hdg,length); + break; + case 1: //spiral + checker=TIXML_SUCCESS; + double curvatureStart, curvatureEnd; + checker+=subNode->QueryDoubleAttribute("curvStart",&curvatureStart); + checker+=subNode->QueryDoubleAttribute("curvEnd",&curvatureEnd); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing spiral attributes"<<endl; + return false; + } + geomBlock->AddGeometrySpiral(s,x,y,hdg,length,curvatureStart,curvatureEnd); + break; + case 2: //arc + checker=TIXML_SUCCESS; + double curvature; + checker+=subNode->QueryDoubleAttribute("curvature",&curvature); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing arc attributes"<<endl; + return false; + } + geomBlock->AddGeometryArc(s,x,y,hdg,length,curvature); + break; + + + case 3: //poly3 + checker=TIXML_SUCCESS; + double a,b,c,d; + checker+=subNode->QueryDoubleAttribute("a",&a); + checker+=subNode->QueryDoubleAttribute("b",&b); + checker+=subNode->QueryDoubleAttribute("c",&c); + checker+=subNode->QueryDoubleAttribute("d",&d); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing poly3 attributes"<<endl; + return false; + } + + geomBlock->AddGeometryPoly3(s,x,y,hdg,length,a,b,c,d); + break; + + case 4: //parampoly3 + checker=TIXML_SUCCESS; + double au,bu,cu,du; + double av,bv,cv,dv; + checker+=subNode->QueryDoubleAttribute("aU",&au); + checker+=subNode->QueryDoubleAttribute("bU",&bu); + checker+=subNode->QueryDoubleAttribute("cU",&cu); + checker+=subNode->QueryDoubleAttribute("dU",&du); + checker+=subNode->QueryDoubleAttribute("aV",&av); + checker+=subNode->QueryDoubleAttribute("bV",&bv); + checker+=subNode->QueryDoubleAttribute("cV",&cv); + checker+=subNode->QueryDoubleAttribute("dV",&dv); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing paramPoly3 attributes"<<endl; + return false; + } + + geomBlock->AddGeometryParamPoly3(s,x,y,hdg,length,au,bu,cu,du,av,bv,cv,dv); + break; + + } + + return true; } //-------------- bool OpenDriveXmlParser::ReadElevationProfile (Road* road, TiXmlElement *node) { - TiXmlElement* subNode; - subNode=node->FirstChildElement("elevation"); - double s, a, b, c, d; - while (subNode) - { - int checker=TIXML_SUCCESS; - checker+=subNode->QueryDoubleAttribute("s",&s); - checker+=subNode->QueryDoubleAttribute("a",&a); - checker+=subNode->QueryDoubleAttribute("b",&b); - checker+=subNode->QueryDoubleAttribute("c",&c); - checker+=subNode->QueryDoubleAttribute("d",&d); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Elevation attributes"<<endl; - return false; - } - - road->AddElevation(s,a,b,c,d); - - subNode=subNode->NextSiblingElement("elevation"); - } - return true; + TiXmlElement* subNode; + subNode=node->FirstChildElement("elevation"); + double s, a, b, c, d; + while (subNode) + { + int checker=TIXML_SUCCESS; + checker+=subNode->QueryDoubleAttribute("s",&s); + checker+=subNode->QueryDoubleAttribute("a",&a); + checker+=subNode->QueryDoubleAttribute("b",&b); + checker+=subNode->QueryDoubleAttribute("c",&c); + checker+=subNode->QueryDoubleAttribute("d",&d); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Elevation attributes"<<endl; + return false; + } + + road->AddElevation(s,a,b,c,d); + + subNode=subNode->NextSiblingElement("elevation"); + } + return true; } //-------------- bool OpenDriveXmlParser::ReadLateralProfile (Road* road, TiXmlElement *node) { - TiXmlElement* subNode; - subNode=node->FirstChildElement("superelevation"); - double s, a, b, c, d; - while (subNode) - { - int checker=TIXML_SUCCESS; - checker+=subNode->QueryDoubleAttribute("s",&s); - checker+=subNode->QueryDoubleAttribute("a",&a); - checker+=subNode->QueryDoubleAttribute("b",&b); - checker+=subNode->QueryDoubleAttribute("c",&c); - checker+=subNode->QueryDoubleAttribute("d",&d); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Superelevation attributes"<<endl; - return false; - } - - road->AddSuperElevation(s,a,b,c,d); - - subNode=subNode->NextSiblingElement("superelevation"); - } - - subNode=node->FirstChildElement("crossfall"); - string side; - while (subNode) - { - int checker=TIXML_SUCCESS; - checker+=subNode->QueryStringAttribute("side",&side); - checker+=subNode->QueryDoubleAttribute("s",&s); - checker+=subNode->QueryDoubleAttribute("a",&a); - checker+=subNode->QueryDoubleAttribute("b",&b); - checker+=subNode->QueryDoubleAttribute("c",&c); - checker+=subNode->QueryDoubleAttribute("d",&d); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Crossfall attributes"<<endl; - return false; - } - - road->AddCrossfall(side,s,a,b,c,d); - - subNode=subNode->NextSiblingElement("crossfall"); - } - - return true; + TiXmlElement* subNode; + subNode=node->FirstChildElement("superelevation"); + double s, a, b, c, d; + while (subNode) + { + int checker=TIXML_SUCCESS; + checker+=subNode->QueryDoubleAttribute("s",&s); + checker+=subNode->QueryDoubleAttribute("a",&a); + checker+=subNode->QueryDoubleAttribute("b",&b); + checker+=subNode->QueryDoubleAttribute("c",&c); + checker+=subNode->QueryDoubleAttribute("d",&d); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Superelevation attributes"<<endl; + return false; + } + + road->AddSuperElevation(s,a,b,c,d); + + subNode=subNode->NextSiblingElement("superelevation"); + } + + subNode=node->FirstChildElement("crossfall"); + string side; + while (subNode) + { + int checker=TIXML_SUCCESS; + checker+=subNode->QueryStringAttribute("side",&side); + checker+=subNode->QueryDoubleAttribute("s",&s); + checker+=subNode->QueryDoubleAttribute("a",&a); + checker+=subNode->QueryDoubleAttribute("b",&b); + checker+=subNode->QueryDoubleAttribute("c",&c); + checker+=subNode->QueryDoubleAttribute("d",&d); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Crossfall attributes"<<endl; + return false; + } + + road->AddCrossfall(side,s,a,b,c,d); + + subNode=subNode->NextSiblingElement("crossfall"); + } + + return true; } //-------------- bool OpenDriveXmlParser::ReadLanes (Road* road, TiXmlElement *node) { - TiXmlElement *subNode = node->FirstChildElement("laneSection"); - while (subNode) - { - ReadLaneSections(road, subNode); - subNode=subNode->NextSiblingElement("laneSection"); - } - - return true; + TiXmlElement *subNode = node->FirstChildElement("laneSection"); + while (subNode) + { + ReadLaneSections(road, subNode); + subNode=subNode->NextSiblingElement("laneSection"); + } + + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneSections (Road* road, TiXmlElement *node) { - int checker=TIXML_SUCCESS; - double s; - checker+=node->QueryDoubleAttribute("s",&s); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane Section attributes"<<endl; - return false; - } - - - road->AddLaneSection(s); - LaneSection* laneSection=road->GetLastAddedLaneSection(); - TiXmlElement *subNode=node->FirstChildElement("left"); - if (subNode) - { - subNode=subNode->FirstChildElement("lane"); - while(subNode) - { - - ReadLane(laneSection,subNode,1); //0 for left - subNode=subNode->NextSiblingElement("lane"); - } - - } - - subNode=node->FirstChildElement("center"); - if (subNode) - { - subNode=subNode->FirstChildElement("lane"); - while(subNode) - { - - ReadLane(laneSection,subNode,0); //1 for center - subNode=subNode->NextSiblingElement("lane"); - } - } - - subNode=node->FirstChildElement("right"); - if (subNode) - { - subNode=subNode->FirstChildElement("lane"); - while(subNode) - { - - ReadLane(laneSection,subNode,-1); //2 for right - subNode=subNode->NextSiblingElement("lane"); - } - } - - - //OutputDebugString( "\n") ; - for (unsigned int i=0;i<laneSection->GetLaneVector()->size();i++) - { - int id = static_cast<Lane>(laneSection->GetLaneVector()->at(i)).GetId(); - - /*char* buf; - buf=new char[5]; - itoa(id,buf,10); - - OutputDebugString( buf ) ; - OutputDebugString( " ") ;*/ - } - //OutputDebugString( "\n") ; - - - //sort in descending order - std::sort(laneSection->GetLaneVector()->begin(),laneSection->GetLaneVector()->end()); - std::reverse(laneSection->GetLaneVector()->begin(),laneSection->GetLaneVector()->end()); - return true; + int checker=TIXML_SUCCESS; + double s; + checker+=node->QueryDoubleAttribute("s",&s); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane Section attributes"<<endl; + return false; + } + + + road->AddLaneSection(s); + LaneSection* laneSection=road->GetLastAddedLaneSection(); + TiXmlElement *subNode=node->FirstChildElement("left"); + if (subNode) + { + subNode=subNode->FirstChildElement("lane"); + while(subNode) + { + + ReadLane(laneSection,subNode,1); //0 for left + subNode=subNode->NextSiblingElement("lane"); + } + + } + + subNode=node->FirstChildElement("center"); + if (subNode) + { + subNode=subNode->FirstChildElement("lane"); + while(subNode) + { + + ReadLane(laneSection,subNode,0); //1 for center + subNode=subNode->NextSiblingElement("lane"); + } + } + + subNode=node->FirstChildElement("right"); + if (subNode) + { + subNode=subNode->FirstChildElement("lane"); + while(subNode) + { + + ReadLane(laneSection,subNode,-1); //2 for right + subNode=subNode->NextSiblingElement("lane"); + } + } + + + //OutputDebugString( "\n") ; + for (unsigned int i=0;i<laneSection->GetLaneVector()->size();i++) + { + int id = static_cast<Lane>(laneSection->GetLaneVector()->at(i)).GetId(); + + /*char* buf; + buf=new char[5]; + itoa(id,buf,10); + + OutputDebugString( buf ) ; + OutputDebugString( " ") ;*/ + } + //OutputDebugString( "\n") ; + + + //sort in descending order + std::sort(laneSection->GetLaneVector()->begin(),laneSection->GetLaneVector()->end()); + std::reverse(laneSection->GetLaneVector()->begin(),laneSection->GetLaneVector()->end()); + return true; } //-------------- bool OpenDriveXmlParser::ReadLane (LaneSection* laneSection, TiXmlElement *node, short int laneType) { - //Read Lane attributes - short int side=laneType; - int id; - string type; - string level; - bool boolLevel; - int predecessor; - int successor; - - int checker=TIXML_SUCCESS; - checker+=node->QueryIntAttribute("id",&id); - checker+=node->QueryStringAttribute("type",&type); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane attributes"<<endl; - return false; - } + //Read Lane attributes + short int side=laneType; + int id; + string type; + string level; + bool boolLevel; + int predecessor; + int successor; + + int checker=TIXML_SUCCESS; + checker+=node->QueryIntAttribute("id",&id); + checker+=node->QueryStringAttribute("type",&type); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane attributes"<<endl; + return false; + } else { if(type!="none" && type!="driving" && type!="stop" && type!="shoulder" && type!="biking" && type!="sidewalk" && type!="border" && type!="restricted" && type!="parking" && type!="bidirectional" && @@ -669,157 +669,157 @@ bool OpenDriveXmlParser::ReadLane (LaneSection* laneSection, TiXmlElement *node, return false; } } - //in case "level" is missing, apply default value - checker=node->QueryStringAttribute("level",&level); - if (checker!=TIXML_SUCCESS) - { level="false"; } - - //convert level to bool - - if (level.compare("false")==0 || level.compare("0")==0) - boolLevel=false; - else - boolLevel=true; - - //pointer to the lane - Lane* lane; - //Depending on the laneType, add it to the appropriate vector and get a pointer to it - - laneSection->AddLane(side,id,type,boolLevel,false); - lane=laneSection->GetLastAddedLane(); - - - //Read Link parameters and add them to the lane if available - TiXmlElement *subNode=node->FirstChildElement("link"); - TiXmlElement *subSubNode; - if (subNode) - subSubNode=subNode->FirstChildElement("predecessor"); - if (subSubNode) - { - checker=subSubNode->QueryIntAttribute("id",&predecessor); - if (checker==TIXML_SUCCESS) - lane->SetPredecessor(predecessor); - } - if (subNode) - subSubNode=subNode->FirstChildElement("successor"); - if (subSubNode) - { - checker=subSubNode->QueryIntAttribute("id",&successor); - if (checker==TIXML_SUCCESS) - lane->SetSuccessor(successor); - } + //in case "level" is missing, apply default value + checker=node->QueryStringAttribute("level",&level); + if (checker!=TIXML_SUCCESS) + { level="false"; } + + //convert level to bool + + if (level.compare("false")==0 || level.compare("0")==0) + boolLevel=false; + else + boolLevel=true; + + //pointer to the lane + Lane* lane; + //Depending on the laneType, add it to the appropriate vector and get a pointer to it + + laneSection->AddLane(side,id,type,boolLevel,false); + lane=laneSection->GetLastAddedLane(); + + + //Read Link parameters and add them to the lane if available + TiXmlElement *subNode=node->FirstChildElement("link"); + TiXmlElement *subSubNode; + if (subNode) + subSubNode=subNode->FirstChildElement("predecessor"); + if (subSubNode) + { + checker=subSubNode->QueryIntAttribute("id",&predecessor); + if (checker==TIXML_SUCCESS) + lane->SetPredecessor(predecessor); + } + if (subNode) + subSubNode=subNode->FirstChildElement("successor"); + if (subSubNode) + { + checker=subSubNode->QueryIntAttribute("id",&successor); + if (checker==TIXML_SUCCESS) + lane->SetSuccessor(successor); + } if(side!=0) { - //Proceed to the Road width - subNode=node->FirstChildElement("width"); - while (subNode) - { - ReadLaneWidth(lane, subNode); - subNode=subNode->NextSiblingElement("width"); - } + //Proceed to the Road width + subNode=node->FirstChildElement("width"); + while (subNode) + { + ReadLaneWidth(lane, subNode); + subNode=subNode->NextSiblingElement("width"); + } } - //Proceed to the Road Mark - subNode=node->FirstChildElement("roadMark"); - while (subNode) - { - ReadLaneRoadMark(lane, subNode); - subNode=subNode->NextSiblingElement("roadMark"); - } + //Proceed to the Road Mark + subNode=node->FirstChildElement("roadMark"); + while (subNode) + { + ReadLaneRoadMark(lane, subNode); + subNode=subNode->NextSiblingElement("roadMark"); + } if(side!=0) { - //Proceed to the Lane Material - subNode=node->FirstChildElement("material"); - while (subNode) - { - ReadLaneMaterial(lane, subNode); - subNode=subNode->NextSiblingElement("material"); - } - - //Proceed to the Lane Visibility - subNode=node->FirstChildElement("visibility"); - while (subNode) - { - ReadLaneVisibility(lane, subNode); - subNode=subNode->NextSiblingElement("visibility"); - } - - //Proceed to the Lane speed - subNode=node->FirstChildElement("speed"); - while (subNode) - { - ReadLaneSpeed(lane, subNode); - subNode=subNode->NextSiblingElement("speed"); - } - - //Proceed to the Lane access - subNode=node->FirstChildElement("access"); - while (subNode) - { - ReadLaneAccess(lane, subNode); - subNode=subNode->NextSiblingElement("access"); - } - - //Proceed to the Lane height - subNode=node->FirstChildElement("height"); - while (subNode) - { - ReadLaneHeight(lane, subNode); - subNode=subNode->NextSiblingElement("height"); - } + //Proceed to the Lane Material + subNode=node->FirstChildElement("material"); + while (subNode) + { + ReadLaneMaterial(lane, subNode); + subNode=subNode->NextSiblingElement("material"); + } + + //Proceed to the Lane Visibility + subNode=node->FirstChildElement("visibility"); + while (subNode) + { + ReadLaneVisibility(lane, subNode); + subNode=subNode->NextSiblingElement("visibility"); + } + + //Proceed to the Lane speed + subNode=node->FirstChildElement("speed"); + while (subNode) + { + ReadLaneSpeed(lane, subNode); + subNode=subNode->NextSiblingElement("speed"); + } + + //Proceed to the Lane access + subNode=node->FirstChildElement("access"); + while (subNode) + { + ReadLaneAccess(lane, subNode); + subNode=subNode->NextSiblingElement("access"); + } + + //Proceed to the Lane height + subNode=node->FirstChildElement("height"); + while (subNode) + { + ReadLaneHeight(lane, subNode); + subNode=subNode->NextSiblingElement("height"); + } } - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneWidth(Lane* lane, TiXmlElement *node) { - double sOffset, a, b, c, d; + double sOffset, a, b, c, d; - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryDoubleAttribute("a",&a); - checker+=node->QueryDoubleAttribute("b",&b); - checker+=node->QueryDoubleAttribute("c",&c); - checker+=node->QueryDoubleAttribute("d",&d); + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryDoubleAttribute("a",&a); + checker+=node->QueryDoubleAttribute("b",&b); + checker+=node->QueryDoubleAttribute("c",&c); + checker+=node->QueryDoubleAttribute("d",&d); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane Width attributes"<<endl; - return false; - } + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane Width attributes"<<endl; + return false; + } - lane->AddWidthRecord(sOffset,a,b,c,d); + lane->AddWidthRecord(sOffset,a,b,c,d); - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneRoadMark(Lane* lane, TiXmlElement *node) { - - double sOffset; - string type; - string weight; - string color; - double width; - string laneChange; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryStringAttribute("type",&type); - checker+=node->QueryStringAttribute("weight",&weight); - checker+=node->QueryStringAttribute("color",&color); - - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane road mark attributes"<<endl; - return false; - } + + double sOffset; + string type; + string weight; + string color; + double width; + string laneChange; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryStringAttribute("type",&type); + checker+=node->QueryStringAttribute("weight",&weight); + checker+=node->QueryStringAttribute("color",&color); + + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane road mark attributes"<<endl; + return false; + } else { if(type!="none" && type!="solid" && type!="broken" && type!="solid solid" && type!="solid broken" && type!="broken solid" && type!="broken broken" && type!="botts dots" && type!="grass" && @@ -830,130 +830,130 @@ bool OpenDriveXmlParser::ReadLaneRoadMark(Lane* lane, TiXmlElement *node) } } - checker+=node->QueryDoubleAttribute("width",&width); - if (checker!=TIXML_SUCCESS) - { width=0; } + checker+=node->QueryDoubleAttribute("width",&width); + if (checker!=TIXML_SUCCESS) + { width=0; } - checker=node->QueryStringAttribute("laneChange",&laneChange); - if (checker!=TIXML_SUCCESS) - { laneChange = "both"; } + checker=node->QueryStringAttribute("laneChange",&laneChange); + if (checker!=TIXML_SUCCESS) + { laneChange = "both"; } - lane->AddRoadMarkRecord(sOffset,type,weight,color,width,laneChange); + lane->AddRoadMarkRecord(sOffset,type,weight,color,width,laneChange); - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneMaterial(Lane* lane, TiXmlElement *node) { - double sOffset; - string surface; - double friction; - double roughness; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryStringAttribute("surface",&surface); - checker+=node->QueryDoubleAttribute("friction",&friction); - checker+=node->QueryDoubleAttribute("roughness",&roughness); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane material attributes"<<endl; - return false; - } - - lane->AddMaterialRecord(sOffset,surface,friction,roughness); - - return true; + double sOffset; + string surface; + double friction; + double roughness; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryStringAttribute("surface",&surface); + checker+=node->QueryDoubleAttribute("friction",&friction); + checker+=node->QueryDoubleAttribute("roughness",&roughness); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane material attributes"<<endl; + return false; + } + + lane->AddMaterialRecord(sOffset,surface,friction,roughness); + + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneVisibility(Lane* lane, TiXmlElement *node) { - double sOffset; - double forward; - double back; - double left; - double right; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryDoubleAttribute("forward",&forward); - checker+=node->QueryDoubleAttribute("back",&back); - checker+=node->QueryDoubleAttribute("left",&left); - checker+=node->QueryDoubleAttribute("right",&right); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane visibility attributes"<<endl; - return false; - } - - lane->AddVisibilityRecord(sOffset,forward,back,left,right); - - return true; + double sOffset; + double forward; + double back; + double left; + double right; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryDoubleAttribute("forward",&forward); + checker+=node->QueryDoubleAttribute("back",&back); + checker+=node->QueryDoubleAttribute("left",&left); + checker+=node->QueryDoubleAttribute("right",&right); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane visibility attributes"<<endl; + return false; + } + + lane->AddVisibilityRecord(sOffset,forward,back,left,right); + + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneSpeed(Lane* lane, TiXmlElement *node) -{ - double sOffset; - double max; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryDoubleAttribute("max",&max); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane speed attributes"<<endl; - return false; - } - - lane->AddSpeedRecord(sOffset,max); - - return true; +{ + double sOffset; + double max; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryDoubleAttribute("max",&max); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane speed attributes"<<endl; + return false; + } + + lane->AddSpeedRecord(sOffset,max); + + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneAccess(Lane* lane, TiXmlElement *node) { - double sOffset; - string restriction; + double sOffset; + string restriction; - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryStringAttribute("restriction",&restriction); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane access attributes"<<endl; - return false; - } + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryStringAttribute("restriction",&restriction); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane access attributes"<<endl; + return false; + } - lane->AddAccessRecord(sOffset,restriction); + lane->AddAccessRecord(sOffset,restriction); - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadLaneHeight(Lane* lane, TiXmlElement *node) { - double sOffset; - double inner; - double outer; - - int checker=TIXML_SUCCESS; - checker+=node->QueryDoubleAttribute("sOffset",&sOffset); - checker+=node->QueryDoubleAttribute("inner",&inner); - checker+=node->QueryDoubleAttribute("outer",&outer); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Lane height attributes"<<endl; - return false; - } - - lane->AddHeightRecord(sOffset,inner,outer); - - return true; + double sOffset; + double inner; + double outer; + + int checker=TIXML_SUCCESS; + checker+=node->QueryDoubleAttribute("sOffset",&sOffset); + checker+=node->QueryDoubleAttribute("inner",&inner); + checker+=node->QueryDoubleAttribute("outer",&outer); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Lane height attributes"<<endl; + return false; + } + + lane->AddHeightRecord(sOffset,inner,outer); + + return true; } //-------------- @@ -961,38 +961,38 @@ bool OpenDriveXmlParser::ReadLaneHeight(Lane* lane, TiXmlElement *node) bool OpenDriveXmlParser::ReadObjects (Road* road, TiXmlElement *node) { - double s,t,zOffset,validLength,length,width,height,radius,heading,pitch,roll; - std::string id,name,dynamic,orientation,type,subType; + double s,t,zOffset,validLength,length,width,height,radius,heading,pitch,roll; + std::string id,name,dynamic,orientation,type,subType; Object *object; - int checker=TIXML_SUCCESS; - TiXmlElement *object_node; + int checker=TIXML_SUCCESS; + TiXmlElement *object_node,*parking_node,*parking_marking_node; object_node=node->FirstChildElement("object"); while(object_node!=0) { std::cout << "new object" << std::endl; - checker=TIXML_SUCCESS; - checker+=object_node->QueryDoubleAttribute("s",&s); - checker+=object_node->QueryDoubleAttribute("t",&t); - checker+=object_node->QueryStringAttribute("id",&id); + checker=TIXML_SUCCESS; + checker+=object_node->QueryDoubleAttribute("s",&s); + checker+=object_node->QueryDoubleAttribute("t",&t); + checker+=object_node->QueryStringAttribute("id",&id); checker+=object_node->QueryStringAttribute("name",&name); checker+=object_node->QueryStringAttribute("dynamic",&dynamic); checker+=object_node->QueryStringAttribute("orientation",&orientation); - checker+=object_node->QueryDoubleAttribute("zOffset",&zOffset); - checker+=object_node->QueryDoubleAttribute("validLength",&validLength); + checker+=object_node->QueryDoubleAttribute("zOffset",&zOffset); + checker+=object_node->QueryDoubleAttribute("validLength",&validLength); checker+=object_node->QueryStringAttribute("type",&type); - checker+=object_node->QueryDoubleAttribute("hdg",&heading); - checker+=object_node->QueryDoubleAttribute("pitch",&pitch); - checker+=object_node->QueryDoubleAttribute("roll",&roll); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing road object attributes"<<endl; - return false; - } + checker+=object_node->QueryDoubleAttribute("hdg",&heading); + checker+=object_node->QueryDoubleAttribute("pitch",&pitch); + checker+=object_node->QueryDoubleAttribute("roll",&roll); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing road object attributes"<<endl; + return false; + } else { if(type!="none" && type!="obstacle" && type!="pole" && type!="tree" && type!="vegetation" && type!="barrier" && type!="building" && type!="parkingSpace" && type!="patch" && type!="railing" && - type!="trafficIsland" && type!="crosswalk" && type!="streetLamp" && type!="gantry" && type!="soundBarrier") + type!="trafficIsland" && type!="crosswalk" && type!="streetLamp" && type!="gantry" && type!="soundBarrier") { cout<<"Error parsing road object attributes for road " << road->GetRoadName() << ": invalid type: " << type << endl; return false; @@ -1009,7 +1009,7 @@ bool OpenDriveXmlParser::ReadObjects (Road* road, TiXmlElement *node) } } - road->AddObject(); + road->AddObject(); object=road->GetLastObject(); object->SetS(s); object->SetT(t); @@ -1027,64 +1027,104 @@ bool OpenDriveXmlParser::ReadObjects (Road* road, TiXmlElement *node) object->SetPitch(pitch); object->SetRoll(roll); // read bounding box - checker=TIXML_SUCCESS; - checker+=object_node->QueryDoubleAttribute("length",&length); - checker+=object_node->QueryDoubleAttribute("width",&width); - checker+=object_node->QueryDoubleAttribute("height",&height); - if(checker==TIXML_SUCCESS) + checker=TIXML_SUCCESS; + checker+=object_node->QueryDoubleAttribute("length",&length); + checker+=object_node->QueryDoubleAttribute("width",&width); + checker+=object_node->QueryDoubleAttribute("height",&height); + if(checker==TIXML_SUCCESS) object->SetBoundingBox(length,width,height); else { - checker=TIXML_SUCCESS; - checker+=object_node->QueryDoubleAttribute("radius",&radius); - checker+=object_node->QueryDoubleAttribute("height",&height); - if(checker==TIXML_SUCCESS) + checker=TIXML_SUCCESS; + checker+=object_node->QueryDoubleAttribute("radius",&radius); + checker+=object_node->QueryDoubleAttribute("height",&height); + if(checker==TIXML_SUCCESS) object->SetBoundingCylinder(radius,height); } + if(type=="parkingSpace") + { + std::string access,restrictions,mark_side,mark_type,mark_color; + double mark_width; + + parking_node=object_node->FirstChildElement("parkingSpace"); + if(parking_node!=0) + { + checker=TIXML_SUCCESS; + checker+=parking_node->QueryStringAttribute("access",&access); + checker+=parking_node->QueryStringAttribute("restrictions",&restrictions); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing road object attributes"<<endl; + return false; + } + else + { + object->SetParkingAccess(access); + object->SetParkingRestrictions(restrictions); + parking_marking_node=parking_node->FirstChildElement("marking"); + while(parking_marking_node!=0) + { + checker=TIXML_SUCCESS; + checker+=parking_marking_node->QueryStringAttribute("side",&mark_side); + checker+=parking_marking_node->QueryStringAttribute("type",&mark_type); + checker+=parking_marking_node->QueryDoubleAttribute("width",&mark_width); + checker+=parking_marking_node->QueryStringAttribute("color",&mark_color); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing road object attributes"<<endl; + return false; + } + else + object->AddParkingMarking(mark_side,mark_type,mark_width,mark_color); + parking_marking_node=parking_marking_node->NextSiblingElement("marking"); + } + } + } + } object_node=object_node->NextSiblingElement("object"); } - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadSignals (Road* road, TiXmlElement *node) { - double s,t,zOffset,value,height,width,hOffset,pitch,roll; - std::string id,name,dynamic,orientation,country,countryRevision,type,subType,unit,text; + double s,t,zOffset,value,height,width,hOffset,pitch,roll; + std::string id,name,dynamic,orientation,country,countryRevision,type,subType,unit,text; Signal *signal; - int checker=TIXML_SUCCESS; + int checker=TIXML_SUCCESS; TiXmlElement *signal_node; signal_node=node->FirstChildElement("signal"); while(signal_node!=0) { std::cout << "new signal" << std::endl; - checker=TIXML_SUCCESS; - checker+=signal_node->QueryDoubleAttribute("s",&s); - checker+=signal_node->QueryDoubleAttribute("t",&t); - checker+=signal_node->QueryStringAttribute("id",&id); + checker=TIXML_SUCCESS; + checker+=signal_node->QueryDoubleAttribute("s",&s); + checker+=signal_node->QueryDoubleAttribute("t",&t); + checker+=signal_node->QueryStringAttribute("id",&id); checker+=signal_node->QueryStringAttribute("name",&name); checker+=signal_node->QueryStringAttribute("dynamic",&dynamic); checker+=signal_node->QueryStringAttribute("orientation",&orientation); - checker+=signal_node->QueryDoubleAttribute("zOffset",&zOffset); + checker+=signal_node->QueryDoubleAttribute("zOffset",&zOffset); checker+=signal_node->QueryStringAttribute("country",&country); // checker+=signal_node->QueryStringAttribute("countryRevision",&countryRevision); checker+=signal_node->QueryStringAttribute("type",&type); checker+=signal_node->QueryStringAttribute("subtype",&subType); - checker+=signal_node->QueryDoubleAttribute("value",&value); + checker+=signal_node->QueryDoubleAttribute("value",&value); // checker+=signal_node->QueryStringAttribute("unit",&unit); -// checker+=signal_node->QueryDoubleAttribute("height",&height); -// checker+=signal_node->QueryDoubleAttribute("width",&width); +// checker+=signal_node->QueryDoubleAttribute("height",&height); +// checker+=signal_node->QueryDoubleAttribute("width",&width); // checker+=signal_node->QueryStringAttribute("text",&text); -// checker+=signal_node->QueryDoubleAttribute("hOffset",&hOffset); -// checker+=signal_node->QueryDoubleAttribute("pitch",&pitch); -// checker+=signal_node->QueryDoubleAttribute("roll",&roll); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing road signal attributes"<<endl; - return false; - } +// checker+=signal_node->QueryDoubleAttribute("hOffset",&hOffset); +// checker+=signal_node->QueryDoubleAttribute("pitch",&pitch); +// checker+=signal_node->QueryDoubleAttribute("roll",&roll); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing road signal attributes"<<endl; + return false; + } else { if(dynamic!="yes" && dynamic!="no") @@ -1099,7 +1139,7 @@ bool OpenDriveXmlParser::ReadSignals (Road* road, TiXmlElement *node) } } - road->AddSignal(); + road->AddSignal(); signal=road->GetLastSignal(); signal->SetS(s); signal->SetT(t); @@ -1126,162 +1166,162 @@ bool OpenDriveXmlParser::ReadSignals (Road* road, TiXmlElement *node) signal_node=signal_node->NextSiblingElement("signal"); } - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadSurface (Road* road, TiXmlElement *node) { - return true; + return true; } //-------------- bool OpenDriveXmlParser::ReadController (TiXmlElement *node) -{ return true; } +{ return true; } //-------------- bool OpenDriveXmlParser::ReadJunction (TiXmlElement *node) -{ - string name; - string id; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("name",&name); - checker+=node->QueryStringAttribute("id",&id); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Junction attributes"<<endl; - return false; - } +{ + string name; + string id; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("name",&name); + checker+=node->QueryStringAttribute("id",&id); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Junction attributes"<<endl; + return false; + } - mOpenDrive->AddJunction(name,id); - Junction* junction=mOpenDrive->GetLastJunction(); + mOpenDrive->AddJunction(name,id); + Junction* junction=mOpenDrive->GetLastJunction(); - //Read connection parameters and add them to the lane if available - TiXmlElement *subNode=node->FirstChildElement("connection"); + //Read connection parameters and add them to the lane if available + TiXmlElement *subNode=node->FirstChildElement("connection"); - while (subNode) - { - ReadJunctionConnection(junction, subNode); - subNode=subNode->NextSiblingElement("connection"); - } + while (subNode) + { + ReadJunctionConnection(junction, subNode); + subNode=subNode->NextSiblingElement("connection"); + } - //Read connection parameters and add them to the lane if available - subNode=node->FirstChildElement("priority"); + //Read connection parameters and add them to the lane if available + subNode=node->FirstChildElement("priority"); - while (subNode) - { - ReadJunctionPriority(junction, subNode); - subNode=subNode->NextSiblingElement("priority"); - } + while (subNode) + { + ReadJunctionPriority(junction, subNode); + subNode=subNode->NextSiblingElement("priority"); + } - //Read connection parameters and add them to the lane if available - subNode=node->FirstChildElement("controller"); + //Read connection parameters and add them to the lane if available + subNode=node->FirstChildElement("controller"); - while (subNode) - { - ReadJunctionController(junction, subNode); - subNode=subNode->NextSiblingElement("controller"); - } + while (subNode) + { + ReadJunctionController(junction, subNode); + subNode=subNode->NextSiblingElement("controller"); + } - return true; - + return true; + } //-------------- bool OpenDriveXmlParser::ReadJunctionConnection (Junction* junction, TiXmlElement *node) { - string id; - string incomingRoad; - string connectingRoad; - string contactPoint; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("id",&id); - checker+=node->QueryStringAttribute("incomingRoad",&incomingRoad); - checker+=node->QueryStringAttribute("connectingRoad",&connectingRoad); - checker+=node->QueryStringAttribute("contactPoint",&contactPoint); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Junction Connection attributes"<<endl; - return false; - } + string id; + string incomingRoad; + string connectingRoad; + string contactPoint; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("id",&id); + checker+=node->QueryStringAttribute("incomingRoad",&incomingRoad); + checker+=node->QueryStringAttribute("connectingRoad",&connectingRoad); + checker+=node->QueryStringAttribute("contactPoint",&contactPoint); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Junction Connection attributes"<<endl; + return false; + } else { if(contactPoint!="start" && contactPoint!="end") - { - cout<<"Error parsing junction connection attributes for junction " << junction->GetName() << ": invalid contact point: " << contactPoint << endl; - return false; - } + { + cout<<"Error parsing junction connection attributes for junction " << junction->GetName() << ": invalid contact point: " << contactPoint << endl; + return false; + } } - - junction->AddJunctionConnection(id,incomingRoad,connectingRoad,contactPoint); - JunctionConnection* junctionConnetion = junction->GetLastJunctionConnection(); + + junction->AddJunctionConnection(id,incomingRoad,connectingRoad,contactPoint); + JunctionConnection* junctionConnetion = junction->GetLastJunctionConnection(); - TiXmlElement *subNode=node->FirstChildElement("laneLink"); + TiXmlElement *subNode=node->FirstChildElement("laneLink"); - while (subNode) - { - ReadJunctionConnectionLaneLink(junctionConnetion, subNode); - subNode=subNode->NextSiblingElement("laneLink"); - } + while (subNode) + { + ReadJunctionConnectionLaneLink(junctionConnetion, subNode); + subNode=subNode->NextSiblingElement("laneLink"); + } - return true; + return true; } bool OpenDriveXmlParser::ReadJunctionConnectionLaneLink (JunctionConnection* junctionConnection, TiXmlElement *node) { - int from; - int to; - - int checker=TIXML_SUCCESS; - checker+=node->QueryIntAttribute("from",&from); - checker+=node->QueryIntAttribute("to",&to); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Junction Lane Link attributes"<<endl; - return false; - } - - junctionConnection->AddJunctionLaneLink(from,to); - return true; + int from; + int to; + + int checker=TIXML_SUCCESS; + checker+=node->QueryIntAttribute("from",&from); + checker+=node->QueryIntAttribute("to",&to); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Junction Lane Link attributes"<<endl; + return false; + } + + junctionConnection->AddJunctionLaneLink(from,to); + return true; } bool OpenDriveXmlParser::ReadJunctionPriority (Junction* junction, TiXmlElement *node) { - string high; - string low; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("high",&high); - checker+=node->QueryStringAttribute("low",&low); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Junction Priority attributes"<<endl; - return false; - } - - junction->AddJunctionPriority(high,low); - return true; + string high; + string low; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("high",&high); + checker+=node->QueryStringAttribute("low",&low); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Junction Priority attributes"<<endl; + return false; + } + + junction->AddJunctionPriority(high,low); + return true; } bool OpenDriveXmlParser::ReadJunctionController (Junction* junction, TiXmlElement *node) { - string id; - string type; - - int checker=TIXML_SUCCESS; - checker+=node->QueryStringAttribute("id",&id); - checker+=node->QueryStringAttribute("type",&type); - if (checker!=TIXML_SUCCESS) - { - cout<<"Error parsing Junction Controller attributes"<<endl; - return false; - } - - junction->AddJunctionController(id,type); - return true; + string id; + string type; + + int checker=TIXML_SUCCESS; + checker+=node->QueryStringAttribute("id",&id); + checker+=node->QueryStringAttribute("type",&type); + if (checker!=TIXML_SUCCESS) + { + cout<<"Error parsing Junction Controller attributes"<<endl; + return false; + } + + junction->AddJunctionController(id,type); + return true; } @@ -1291,46 +1331,46 @@ bool OpenDriveXmlParser::ReadJunctionController (Junction* junction, TiXmlElemen */ bool OpenDriveXmlParser::ReadFile(std::string fileName) { - //Read and load File - TiXmlDocument doc( fileName ); - bool loadOkay = doc.LoadFile(); - if (loadOkay) - { - TiXmlElement *rootNode=doc.FirstChildElement(); - //read header - int checker=TIXML_SUCCESS; - TiXmlElement *node=rootNode->FirstChildElement("header"); - ReadHeader(node); - - //read roads - node=rootNode->FirstChildElement("road"); - while (node!=0) - { - ReadRoad(node); - node=node->NextSiblingElement("road"); - } - - //read controllers - node=rootNode->FirstChildElement("controller"); - while (node!=0) - { - ReadController(node); - node=node->NextSiblingElement("controller"); - } - - //read junctions - node=rootNode->FirstChildElement("junction"); - while (node!=0) - { - ReadJunction(node); - node=node->NextSiblingElement("junction"); - } - - return true; - } - - //failed to read the file - cout<<"Could not read file: "<<fileName<<endl; - return false; + //Read and load File + TiXmlDocument doc( fileName ); + bool loadOkay = doc.LoadFile(); + if (loadOkay) + { + TiXmlElement *rootNode=doc.FirstChildElement(); + //read header + int checker=TIXML_SUCCESS; + TiXmlElement *node=rootNode->FirstChildElement("header"); + ReadHeader(node); + + //read roads + node=rootNode->FirstChildElement("road"); + while (node!=0) + { + ReadRoad(node); + node=node->NextSiblingElement("road"); + } + + //read controllers + node=rootNode->FirstChildElement("controller"); + while (node!=0) + { + ReadController(node); + node=node->NextSiblingElement("controller"); + } + + //read junctions + node=rootNode->FirstChildElement("junction"); + while (node!=0) + { + ReadJunction(node); + node=node->NextSiblingElement("junction"); + } + + return true; + } + + //failed to read the file + cout<<"Could not read file: "<<fileName<<endl; + return false; } //-------------- diff --git a/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp b/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp index fc3053d3d764cea53311ef8543f23beaf07d0d78..55897846baa7e32d3f72bf742b164fb5f7c70c83 100644 --- a/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp +++ b/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp @@ -966,6 +966,28 @@ bool OpenDriveXmlWriter::WriteObjects (TiXmlElement *node, Road* road) text << setprecision(16) << setiosflags (ios_base::scientific) << height; object_node->SetAttribute("height",text.str()); } + if(object->GetType()=="parkingSpace") + { + TiXmlElement *parking_node = new TiXmlElement("parkingSpace"); + object_node->LinkEndChild(parking_node); + parking_node->SetAttribute("access",object->GetParkingAccess()); + parking_node->SetAttribute("restrictions",object->GetParkingRestrictions()); + for(unsigned int i=0;i<object->GetNumParkingMarkings();i++) + { + TiXmlElement *parking_marking_node = new TiXmlElement("marking"); + std::string mark_side,mark_type,mark_color; + double mark_width; + + parking_node->LinkEndChild(parking_marking_node); + object->GetParkingMarking(i,mark_side,mark_type,mark_width,mark_color); + parking_marking_node->SetAttribute("side",mark_side); + parking_marking_node->SetAttribute("type",mark_type); + text.str(""); + text << setprecision(16) << setiosflags (ios_base::scientific) << mark_width; + parking_marking_node->SetAttribute("width",text.str()); + parking_marking_node->SetAttribute("color",mark_color); + } + } std::cout << "written object " << object->GetName() << " with id: " << object->GetId() << std::endl; } diff --git a/OpenRoadEd/Osg/OSGMain.cpp b/OpenRoadEd/Osg/OSGMain.cpp index 360c0523433470782f13402a4ba6fffc0e27dbce..ec693b14b1c5c3d08c3449eb10f6f5b6e0b2570b 100644 --- a/OpenRoadEd/Osg/OSGMain.cpp +++ b/OpenRoadEd/Osg/OSGMain.cpp @@ -162,7 +162,27 @@ void OSGMain::ShowScenery(bool show) */ void OSGMain::ShowRecordsHelpers(bool show) { - mRecordsHelpersGroup->setNodeMask(show); + //mRecordsHelpersGroup->setNodeMask(show); + for(unsigned int i=0;i<mRecordsHelpersGroup->getNumChildren();i++) + { + osg::Group *group=mRecordsHelpersGroup->getChild(i)->asGroup(); + for(unsigned int l=0;l<group->getNumChildren();l++) + { + osg::Group *group2=group->getChild(l)->asGroup(); + for(unsigned int j=0;j<group2->getNumChildren();j++) + { + osg::MatrixTransform *transform=(osg::MatrixTransform *)group2->getChild(j)->asGroup(); + for(unsigned int k=0;k<transform->getNumChildren();k++) + { + OSGGeodeNode *geode=(OSGGeodeNode *)transform->getChild(k); + if(geode->GetNodeType()!=PARKING_OBJECT_NODE) + geode->setNodeMask(show); + else + geode->setNodeMask(true); + } + } + } + } mHelpersGroup->setNodeMask(show); } @@ -736,6 +756,7 @@ OSGObjectNode* OSGMain::PickNode(float x, float y) case SUPERELEVATION_NODE: case CROSSFALL_NODE: case OBJECT_NODE: + case PARKING_OBJECT_NODE: case SIGNAL_NODE: { //get the index of the parameter and then the index of the road @@ -1387,6 +1408,7 @@ OSGGeodeNode* OSGMain::FindNode(OSGObjectNode* objToSelect) break; } + case PARKING_OBJECT_NODE: case OBJECT_NODE: { roadParamInd=objToSelect->GetNodeInfoIndex(1); diff --git a/OpenRoadEd/Osg/OSGObjectNode.h b/OpenRoadEd/Osg/OSGObjectNode.h index 2a1457d263b005741908e8ab2f41595646a51207..e868514abb68db80e361bfe54d4f0af8897f9096 100644 --- a/OpenRoadEd/Osg/OSGObjectNode.h +++ b/OpenRoadEd/Osg/OSGObjectNode.h @@ -32,7 +32,8 @@ enum OSGNodeType LANE_HEIGHT_NODE, OBJECT_NODE, SIGNAL_NODE, - JUNCTION_NODE + JUNCTION_NODE, + PARKING_OBJECT_NODE, }; /** diff --git a/OpenRoadEd/Osg/OSGRecordsHelpers.cpp b/OpenRoadEd/Osg/OSGRecordsHelpers.cpp index dc5ea15aa372a22e30fe8ad4b812413749f73033..dc8cc6fcceb187916f63ce2a0616174d815d849e 100644 --- a/OpenRoadEd/Osg/OSGRecordsHelpers.cpp +++ b/OpenRoadEd/Osg/OSGRecordsHelpers.cpp @@ -4,6 +4,7 @@ #include <osg/Geode> #include <osg/MatrixTransform> #include <osg/Geometry> +#include <osg/Material> #include <osgDB/ReadFile> #include <osg/Texture2D> #include <osg/ShapeDrawable> @@ -32,8 +33,8 @@ OSGRecordsHelpers::OSGRecordsHelpers() /** * Create a billboard node */ - CreateBillboard(); - CreateSignalBillboard(); + mBillboard=CreateBillboard(mSize,mSize); + mSignalBillboard=CreateBillboard(mSignalSize,mSignalSize); /** * Create an arrow @@ -258,8 +259,13 @@ void OSGRecordsHelpers::FillHelperGroups (Road *road,unsigned int roadIndex, osg } ////Objects and Signals for (unsigned int i = 0; i<road->GetObjectCount(); i++) - mObjectGroup->addChild(AddObjectHelper(road->GetObject(i)).get()); - + { + if(road->GetObject(i)->GetType()=="parkingSpace") + mObjectGroup->addChild(AddParkingHelper(road->GetObject(i)).get()); + else + mObjectGroup->addChild(AddObjectHelper(road->GetObject(i)).get()); + } + std::cout << "num object items: " << mObjectGroup->getNumChildren() << std::endl; for (unsigned int i = 0; i<road->GetSignalCount(); i++) mSignalGroup->addChild(AddSignalHelper(road->GetSignal(i)).get()); } @@ -471,6 +477,148 @@ osg::ref_ptr<osg::MatrixTransform> OSGRecordsHelpers::AddObjectHelper(Object *ob return matrix; } +osg::ref_ptr<osg::MatrixTransform> OSGRecordsHelpers::AddParkingHelper(Object *object) +{ + osg::ref_ptr<OSGGeodeNode> ShapeGeode = new OSGGeodeNode(); + osg::ref_ptr<osg::ShapeDrawable> Shape = new osg::ShapeDrawable; + osg::ref_ptr<osg::MatrixTransform> matrix = new osg::MatrixTransform; + matrix->setName("RecordMatrix"); + + //Get the coords and the heading for the current record + double x,y,hdg,elevation,s; + s=object->GetS(); + short int resultID=mRoad->GetGeometryCoords(s,x,y,hdg); + + if (resultID==-999) + return matrix; + + elevation=mRoad->GetElevationValue(s); + + double length,width,height,radius; + + object->GetBoundingBox(length,width,height); + //========================================================= + //Now, add a billboard with the texture of the needed type + //========================================================= + osg::ref_ptr<OSGGeodeNode> parkingGeode = new OSGGeodeNode(); + osg::ref_ptr<osg::Geometry> parkingGeom=new osg::Geometry; + parkingGeom->setUseDisplayList( false ); + + parkingGeode->SetNodeType(PARKING_OBJECT_NODE); + + osg::ref_ptr<osg::Vec3Array> parkingVertices = new osg::Vec3Array; + osg::ref_ptr<osg::DrawElementsUInt> parkingTris = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); + osg::ref_ptr<osg::Vec2Array> parkingTexCoords = new osg::Vec2Array; + + parkingVertices->push_back(osg::Vec3(-length/2.0,-width/2.0,0)); + parkingVertices->push_back(osg::Vec3(length/2.0,-width/2.0,0)); + parkingVertices->push_back(osg::Vec3(length/2.0,width/2.0,0)); + parkingVertices->push_back(osg::Vec3(-length/2.0,width/2.0,0)); + parkingTris->push_back(1); + parkingTris->push_back(2); + parkingTris->push_back(3); + parkingTris->push_back(0); + parkingTris->push_back(1); + parkingTris->push_back(3); + parkingTexCoords->push_back(osg::Vec2(0,0)); + parkingTexCoords->push_back(osg::Vec2(1,0)); + parkingTexCoords->push_back(osg::Vec2(1,1)); + parkingTexCoords->push_back(osg::Vec2(0,1)); + + parkingGeode->addDrawable(parkingGeom); + parkingGeom->setVertexArray(parkingVertices.get()); + parkingGeom->setTexCoordArray(0,parkingTexCoords.get()); + parkingGeom->addPrimitiveSet(parkingTris.get()); + + osg::ref_ptr<osg::Material> roadMaterial = new osg::Material(); + //roadMaterial->setEmission(osg::Material::FRONT, osg::Vec4(0.0, 0.0, 0.0, 1.0)); + roadMaterial->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); + + std::string roadTextureFile; + roadTextureFile=":/Billboards/parkingSpace.jpg"; + // create a texture + // load image for texture + osg::Image *roadImage = convert_resource(roadTextureFile); + if (!roadImage) + { + roadImage = convert_resource(":/noTexture.jpg"); + osg::notify(osg::WARN) << "Couldn't load texture." << std::endl; + } + osg::ref_ptr<osg::Texture2D> roadTexture = new osg::Texture2D; + roadTexture->setDataVariance(osg::Object::DYNAMIC); + roadTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); + roadTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT); + roadTexture->setImage(roadImage); + + osg::StateSet* roadStateSet=parkingGeom->getOrCreateStateSet(); + // assign the material and texture + roadStateSet->setAttribute(roadMaterial); + roadStateSet->setTextureAttributeAndModes(0, roadTexture, osg::StateAttribute::ON); + roadStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + roadStateSet->setMode(GL_BLEND,osg::StateAttribute::ON); + roadStateSet->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + + //=========================================================================================== + //in order to translate the helper orthogonally to the heading, compute the cos and sin + //=========================================================================================== + x-=object->GetT()*sin(hdg); + y+=object->GetT()*cos(hdg); + + matrix->setMatrix(osg::Matrix::rotate(osg::inRadians(hdg+object->GetHeading()), osg::Vec3(0.0, 0.0, 1.0)) * + osg::Matrix::translate(osg::Vec3(x,y,elevation+object->GetZOffset())) ); + matrix->addChild(parkingGeode); + + //========================================================= + // Add front mark + //========================================================= + std::string mark_side,mark_type,mark_color; + double mark_width; + + for(unsigned int i=0;i<object->GetNumParkingMarkings();i++) + { + object->GetParkingMarking(i,mark_side,mark_type,mark_width,mark_color); + if(mark_side=="front") + { + osg::ref_ptr<OSGGeodeNode> markGeode = new OSGGeodeNode(); + osg::ref_ptr<osg::Geometry> markGeom=new osg::Geometry; + markGeom->setUseDisplayList( false ); + + markGeode->SetNodeType(PARKING_OBJECT_NODE); + + osg::ref_ptr<osg::Vec3Array> markVertices = new osg::Vec3Array; + osg::ref_ptr<osg::DrawElementsUInt> markTris = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, 0); + + markVertices->push_back(osg::Vec3(-mark_width/2.0+length/2.0,-width/2.0,0)); + markVertices->push_back(osg::Vec3(mark_width/2.0+length/2.0,-width/2.0,0)); + markVertices->push_back(osg::Vec3(mark_width/2.0+length/2.0,width/2.0,0)); + markVertices->push_back(osg::Vec3(-mark_width/2.0+length/2.0,width/2.0,0)); + markTris->push_back(1); + markTris->push_back(2); + markTris->push_back(3); + markTris->push_back(0); + markTris->push_back(1); + markTris->push_back(3); + + markGeode->addDrawable(markGeom); + markGeom->setVertexArray(markVertices.get()); + markGeom->addPrimitiveSet(markTris.get()); + + osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; + markGeom->setColorArray(colors.get()); + markGeom->setColorBinding(osg::Geometry::BIND_OVERALL); + colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); + osg::StateSet* markState=markGeom->getOrCreateStateSet(); + // assign the material and texture + markState->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + markState->setMode(GL_BLEND,osg::StateAttribute::ON); + markState->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + + matrix->addChild(markGeode); + } + } + + return matrix; +} osg::ref_ptr<osg::MatrixTransform> OSGRecordsHelpers::AddSignalHelper(Signal *signal) { osg::ref_ptr<OSGGeodeNode> arrowGeode = new OSGGeodeNode(); @@ -575,66 +723,35 @@ osg::ref_ptr<osg::MatrixTransform> OSGRecordsHelpers::AddSignalHelper(Signal *si } //-------------- -void OSGRecordsHelpers::CreateBillboard() +osg::Geometry *OSGRecordsHelpers::CreateBillboard(double length, double width) { - mBillboard = new osg::Geometry(); + osg::Geometry *geometry = new osg::Geometry(); //arrays for vertices osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; - mBillboard->setVertexArray( vertices.get() ); + geometry->setVertexArray( vertices.get() ); osg::ref_ptr<osg::Vec2Array> texCoords = new osg::Vec2Array; - mBillboard->setTexCoordArray( 0, texCoords.get() ); + geometry->setTexCoordArray( 0, texCoords.get() ); osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1,1,1,1)); - mBillboard->setColorArray( colors.get() ); - mBillboard->setColorBinding(osg::Geometry::BIND_OVERALL); - - double halfSize=mSize/2; + geometry->setColorArray( colors.get() ); + geometry->setColorBinding(osg::Geometry::BIND_OVERALL); - vertices->push_back(osg::Vec3(-halfSize,0,-halfSize)); + vertices->push_back(osg::Vec3(-length/2.0,0,-width/2.0)); texCoords->push_back(osg::Vec2(0,0)); - vertices->push_back(osg::Vec3(halfSize,0,-halfSize)); - texCoords->push_back(osg::Vec2(1,0)); - vertices->push_back(osg::Vec3(halfSize,0,halfSize)); + vertices->push_back(osg::Vec3(length/2.0,0,-width/2.0)); + texCoords->push_back(osg::Vec2(1,0)); + vertices->push_back(osg::Vec3(length/2.0,0,width/2.0)); texCoords->push_back(osg::Vec2(1,1)); - vertices->push_back(osg::Vec3(-halfSize,0,halfSize)); + vertices->push_back(osg::Vec3(-length/2.0,0,width/2.0)); texCoords->push_back(osg::Vec2(0,1)); //lines osg::ref_ptr<osg::DrawArrays> quad = new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, vertices.get()->size()); - mBillboard->addPrimitiveSet(quad.get()); + geometry->addPrimitiveSet(quad.get()); - mBillboard->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); -} - -void OSGRecordsHelpers::CreateSignalBillboard() -{ - mSignalBillboard = new osg::Geometry(); - //arrays for vertices - osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; - mSignalBillboard->setVertexArray( vertices.get() ); - osg::ref_ptr<osg::Vec2Array> texCoords = new osg::Vec2Array; - mSignalBillboard->setTexCoordArray( 0, texCoords.get() ); - osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array; - colors->push_back(osg::Vec4(1,1,1,1)); - mSignalBillboard->setColorArray( colors.get() ); - mSignalBillboard->setColorBinding(osg::Geometry::BIND_OVERALL); - - double halfSize=mSignalSize/2; - - vertices->push_back(osg::Vec3(-halfSize,0,-halfSize)); - texCoords->push_back(osg::Vec2(0,0)); - vertices->push_back(osg::Vec3(halfSize,0,-halfSize)); - texCoords->push_back(osg::Vec2(1,0)); - vertices->push_back(osg::Vec3(halfSize,0,halfSize)); - texCoords->push_back(osg::Vec2(1,1)); - vertices->push_back(osg::Vec3(-halfSize,0,halfSize)); - texCoords->push_back(osg::Vec2(0,1)); - - //lines - osg::ref_ptr<osg::DrawArrays> quad = new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, vertices.get()->size()); - mSignalBillboard->addPrimitiveSet(quad.get()); + geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); - mSignalBillboard->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + return geometry; } void OSGRecordsHelpers::CreateArrow() diff --git a/OpenRoadEd/Osg/OSGRecordsHelpers.h b/OpenRoadEd/Osg/OSGRecordsHelpers.h index 1f59b7010a9cdc27b034c4fa80b3c423c707eac3..a1493049646476f8537ef2a82ac88df011c07c04 100644 --- a/OpenRoadEd/Osg/OSGRecordsHelpers.h +++ b/OpenRoadEd/Osg/OSGRecordsHelpers.h @@ -17,6 +17,7 @@ private: osg::ref_ptr<osg::Geometry> mBillboard; osg::ref_ptr<osg::Geometry> mSignalBillboard; + std::map<std::string,osg::ref_ptr<osg::Geometry>> mParkingBillboards; //these are shared between all the arrows osg::ref_ptr<osg::Vec3Array>mArrowVertices; @@ -32,8 +33,7 @@ private: /** * Create a billboard node */ - void CreateBillboard(); - void CreateSignalBillboard(); + osg::Geometry *CreateBillboard(double length, double width); /** * Create an arrow @@ -52,6 +52,7 @@ private: */ osg::ref_ptr<osg::MatrixTransform> AddRecordHelper(double s, double offsetX,double offsetY,double offsetZ, OSGNodeType type, std::string iconName, double extra_heading=0.0,osg::Vec4* color=NULL); osg::ref_ptr<osg::MatrixTransform> AddObjectHelper(Object *object); + osg::ref_ptr<osg::MatrixTransform> AddParkingHelper(Object *object); osg::ref_ptr<osg::MatrixTransform> AddSignalHelper(Signal *signal); public: OSGRecordsHelpers(); diff --git a/OpenRoadEd/Qt/QOSGWidget.cpp b/OpenRoadEd/Qt/QOSGWidget.cpp index 7010fbcc47938930eabe828f0cbef9e8664e14eb..facf5d2378f05a85d439cf176afcf73767f8cf35 100644 --- a/OpenRoadEd/Qt/QOSGWidget.cpp +++ b/OpenRoadEd/Qt/QOSGWidget.cpp @@ -429,6 +429,7 @@ void QOSGWidget::Pick(QMouseEvent *e) case LANE_HEIGHT_NODE: mRoadTree->SelectLaneHeight(lLastPicked->GetNodeInfoIndex(0),lLastPicked->GetNodeInfoIndex(1),lLastPicked->GetNodeInfoIndex(2),lLastPicked->GetNodeInfoIndex(3)); break; + case PARKING_OBJECT_NODE: case OBJECT_NODE: mRoadTree->SelectObject(lLastPicked->GetNodeInfoIndex(0),lLastPicked->GetNodeInfoIndex(1)); break; diff --git a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp index 71ab21a91dbbb15baff4f4d5fa8b61f857067733..facf9978b7824353648d230a51cbcbab24a081b1 100644 --- a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp +++ b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp @@ -69,6 +69,38 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive) mTypeMap["unknown"]="14"; mHeading = new QLineEdit; + mParkingAccess = new QComboBox; + mParkingAccess->insertItem(0,tr("all")); + mAccessMap["all"]="0"; + mParkingAccess->insertItem(1,tr("car")); + mAccessMap["car"]="1"; + mParkingAccess->insertItem(2,tr("women")); + mAccessMap["women"]="2"; + mParkingAccess->insertItem(3,tr("handicapped")); + mAccessMap["handicapped"]="3"; + mParkingAccess->insertItem(4,tr("bus")); + mAccessMap["bus"]="4"; + mParkingAccess->insertItem(5,tr("truck")); + mAccessMap["truck"]="5"; + mParkingAccess->insertItem(6,tr("residents")); + mAccessMap["residents"]="6"; + mParkingAccess->insertItem(7,tr("electric")); + mAccessMap["electric"]="7"; + mParkingRestrictions = new QComboBox; + mParkingRestrictions->insertItem(0,tr("none")); + mAccessMap["none"]="-1"; + mParkingRestrictions->insertItem(1,tr("2hr_limit")); + mAccessMap["2hr_limit"]="0"; + mParkingFrontMark = new QGroupBox; + mParkingFrontMark->setTitle(tr("ParkingFrontMarking")); + mParkingFrontMark->setCheckable(true); + mParkingFrontMark->setChecked(false); + mParkingFrontWidth = new QLineEdit; + mParkingFrontWidth->setText("0.3"); + QFormLayout *settingsParkingFrontMarkLayout = new QFormLayout; + settingsParkingFrontMarkLayout->addRow(tr("Width:"),mParkingFrontWidth); + mParkingFrontMark->setLayout(settingsParkingFrontMarkLayout); + mBoundingBox = new QGroupBox; mBoundingBox->setTitle(tr("BoundingBox")); mBoundingBox->setCheckable(true); @@ -112,9 +144,12 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive) settingsFormLayout->addRow(tr("validLength:"),mValidLength); settingsFormLayout->addRow(tr("Type:"),mType); settingsFormLayout->addRow(tr("Heading:"),mHeading); + settingsFormLayout->addRow(tr("ParkingAccess:"),mParkingAccess); + settingsFormLayout->addRow(tr("ParkingRestrictions:"),mParkingRestrictions); QVBoxLayout *settingsGroupLayout = new QVBoxLayout; settingsGroupLayout->addLayout(settingsFormLayout); + settingsGroupLayout->addWidget(mParkingFrontMark); settingsGroupLayout->addWidget(mBoundingBox); settingsGroupLayout->addWidget(mBoundingCyl); @@ -137,7 +172,11 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive) "<p><b>zOffset</b> - z offset from track level to bottom edge of the object [meter]</p>" "<p><b>validLength</b> - extent of object's validity along s-axis (0.0 for point object) [meter]</p>" "<p><b>Type</b> - type identifier according to country code. -1 or none for unspecified type</p>" - "<p><b>heading</b> - heading angle of the object relative to road direction</p>" + "<p><b>Heading</b> - heading angle of the object relative to road direction</p>" + "<p><b>ParkingAccess</b> - type of parking. Only for ParkingSpace objects</p>" + "<p><b>ParkingRestrictions</b> - restrictions of the parking space. Only for ParkingSpace objects</p>" + "<p><b>ParkingFrontMark</b> - check if the parking space has a front mark</p>" + "<p><b>Width</b> - Width of the front mark of the parking space</p>" "<p><b>BoundingBox</b> - check if this road has a bounding box</p>" "<p><b>Box length</b> - length of the bounding box</p>" "<p><b>Box width</b> - width of the bounding box</p>" @@ -179,6 +218,10 @@ void SettingsRoadObject::LoadData(Object *object) disconnect(mValidLength, SIGNAL(editingFinished()), this, SLOT(ValidLengthChanged())); disconnect(mType, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(TypeChanged(const QString &))); disconnect(mHeading, SIGNAL(editingFinished()), this, SLOT(HeadingChanged())); + disconnect(mParkingAccess, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(ParkingAccessChanged(const QString &))); + disconnect(mParkingRestrictions, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(ParkingRestrictionsChanged(const QString &))); + disconnect(mParkingFrontMark, SIGNAL(clicked(bool)), this, SLOT(ParkingFrontMarkChanged(bool))); + disconnect(mParkingFrontWidth, SIGNAL(editingFinished()), this, SLOT(ParkingFrontWidthChanged())); disconnect(mBoundingBox, SIGNAL(clicked(bool)), this, SLOT(BoundingBoxChanged(bool))); disconnect(mBoxLength, SIGNAL(editingFinished()), this, SLOT(BoxLengthChanged())); disconnect(mBoxWidth, SIGNAL(editingFinished()), this, SLOT(BoxWidthChanged())); @@ -239,6 +282,52 @@ void SettingsRoadObject::LoadData(Object *object) else mType->setCurrentIndex(15); mHeading->setText(QString("%1").arg(object->GetHeading())); + if(object->GetType()=="parkingSpace") + { + mParkingAccess->setEnabled(true); + if(object->GetParkingAccess()=="all") + mParkingAccess->setCurrentIndex(0); + else if(object->GetParkingAccess()=="car") + mParkingAccess->setCurrentIndex(1); + else if(object->GetParkingAccess()=="women") + mParkingAccess->setCurrentIndex(2); + else if(object->GetParkingAccess()=="handicapped") + mParkingAccess->setCurrentIndex(3); + else if(object->GetParkingAccess()=="bus") + mParkingAccess->setCurrentIndex(4); + else if(object->GetParkingAccess()=="truck") + mParkingAccess->setCurrentIndex(5); + else if(object->GetParkingAccess()=="residents") + mParkingAccess->setCurrentIndex(6); + else if(object->GetParkingAccess()=="electric") + mParkingAccess->setCurrentIndex(7); + mParkingRestrictions->setEnabled(true); + if(object->GetParkingRestrictions()=="none") + mParkingRestrictions->setCurrentIndex(0); + else if(object->GetParkingRestrictions()=="2hr_limit") + mParkingRestrictions->setCurrentIndex(1); + mParkingFrontMark->setEnabled(true); + mParkingFrontMark->setChecked(false); + for(unsigned int i=0;i<object->GetNumParkingMarkings();i++) + { + std::string mark_side,mark_type,mark_color; + double mark_width; + object->GetParkingMarking(i,mark_side,mark_type,mark_width,mark_color); + if(mark_side=="front") + { + mParkingFrontMark->setChecked(true); + mParkingFrontWidth->setEnabled(true); + mParkingFrontWidth->setText(QString("%1").arg(mark_width)); + } + } + } + else + { + mParkingAccess->setDisabled(true); + mParkingRestrictions->setDisabled(true); + mParkingFrontMark->setDisabled(true); + mParkingFrontWidth->setDisabled(true); + } if(object->GetBoundingBox(length,width,height)) { @@ -271,6 +360,10 @@ void SettingsRoadObject::LoadData(Object *object) connect(mValidLength, SIGNAL(editingFinished()), this, SLOT(ValidLengthChanged())); connect(mType, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(TypeChanged(const QString &))); connect(mHeading, SIGNAL(editingFinished()), this, SLOT(HeadingChanged())); + connect(mParkingAccess, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(ParkingAccessChanged(const QString &))); + connect(mParkingRestrictions, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(ParkingRestrictionsChanged(const QString &))); + connect(mParkingFrontMark, SIGNAL(clicked(bool)), this, SLOT(ParkingFrontMarkChanged(bool))); + connect(mParkingFrontWidth, SIGNAL(editingFinished()), this, SLOT(ParkingFrontWidthChanged())); connect(mBoundingBox, SIGNAL(clicked(bool)), this, SLOT(BoundingBoxChanged(bool))); connect(mBoxLength, SIGNAL(editingFinished()), this, SLOT(BoxLengthChanged())); connect(mBoxWidth, SIGNAL(editingFinished()), this, SLOT(BoxWidthChanged())); @@ -332,6 +425,21 @@ void SettingsRoadObject::ValidLengthChanged() void SettingsRoadObject::TypeChanged(const QString & text) { mObject->SetType(text.toStdString()); + if(mObject->GetType()=="parkingSpace") + { + mParkingAccess->setEnabled(true); + mParkingRestrictions->setEnabled(true); + mParkingFrontMark->setEnabled(true); + mBoundingBox->setChecked(true); + mBoundingCyl->setChecked(false); + } + else + { + mParkingAccess->setDisabled(true); + mParkingRestrictions->setDisabled(true); + mParkingFrontMark->setDisabled(true); + mObject->ClearParking(); + } emit RoadGeometryChanged(true); } @@ -341,6 +449,47 @@ void SettingsRoadObject::HeadingChanged() emit RoadGeometryChanged(true); } +void SettingsRoadObject::ParkingAccessChanged(const QString &text) +{ + mObject->SetParkingAccess(text.toStdString()); + emit RoadGeometryChanged(true); +} + +void SettingsRoadObject::ParkingRestrictionsChanged(const QString &text) +{ + mObject->SetParkingRestrictions(text.toStdString()); + emit RoadGeometryChanged(true); +} + +void SettingsRoadObject::ParkingFrontMarkChanged(bool on) +{ + double width; + + if(on) + { + mParkingFrontWidth->setEnabled(true); + width=mParkingFrontWidth->text().toDouble(); + mObject->AddParkingMarking("front","solid",width,"standard"); + } + else + { + mParkingFrontWidth->setDisabled(true); + mObject->RemoveParkingMarking("front"); + } + + emit RoadGeometryChanged(true); +} + +void SettingsRoadObject::ParkingFrontWidthChanged() +{ + double width; + + width=mParkingFrontWidth->text().toDouble(); + mObject->AddParkingMarking("front","solid",width,"standard"); + + emit RoadGeometryChanged(true); +} + void SettingsRoadObject::BoundingBoxChanged(bool on) { double length,width,height; @@ -355,7 +504,10 @@ void SettingsRoadObject::BoundingBoxChanged(bool on) } else { - mObject->ClearBounding(); + if(mObject->GetType()=="parkingSpace") + mBoundingBox->setChecked(true); + else + mObject->ClearBounding(); } emit RoadGeometryChanged(true); diff --git a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h index 393e7df8986183c4db9f22c625894372afa3ca2a..b1abc85d09890eb4e4c97d051974284aa663d232 100644 --- a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h +++ b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h @@ -42,6 +42,8 @@ private: Object *mObject; std::map<std::string,std::string> mTypeMap; + std::map<std::string,std::string> mAccessMap; + std::map<std::string,std::string> mRestrictionsMap; /** * Interface widgets @@ -56,6 +58,10 @@ private: QLineEdit *mValidLength; QComboBox *mType; QLineEdit *mHeading; + QComboBox *mParkingAccess; + QComboBox *mParkingRestrictions; + QGroupBox *mParkingFrontMark; + QLineEdit *mParkingFrontWidth; QGroupBox *mBoundingBox; QLineEdit *mBoxLength; QLineEdit *mBoxWidth; @@ -79,6 +85,10 @@ public slots: void ValidLengthChanged(); void TypeChanged(const QString & text); void HeadingChanged(); + void ParkingAccessChanged(const QString & text); + void ParkingRestrictionsChanged(const QString & text); + void ParkingFrontMarkChanged(bool on); + void ParkingFrontWidthChanged(); void BoundingBoxChanged(bool on); void BoxLengthChanged(); void BoxWidthChanged(); diff --git a/Resources/Billboards/parkingSpace.jpg b/Resources/Billboards/parkingSpace.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c89d8eca0d161cdc34d5086fa0f040bd64ee9de8 Binary files /dev/null and b/Resources/Billboards/parkingSpace.jpg differ diff --git a/Resources/resources.qrc b/Resources/resources.qrc index 5a4c3ed4380d8c90a78abc8775ac2fcdf1bdf2e5..7dd1c347c3feb480102ea179d4f818b9facde727 100644 --- a/Resources/resources.qrc +++ b/Resources/resources.qrc @@ -37,6 +37,7 @@ <file>Billboards/JunctionConnection.jpg</file> <file>Billboards/LaneMaterial.jpg</file> <file>Billboards/Road.jpg</file> + <file>Billboards/parkingSpace.jpg</file> <file>Icons/Expand.png</file> <file>Icons/Collapse.png</file> <file>Icons/Hide.png</file>