34 myFilename(filename) {
52 const std::string key = attrs.
get<std::string>(
SUMO_ATTR_KEY,
nullptr, parsedOk);
56 if ((SumoBaseObjectParent ==
nullptr) || (SumoBaseObjectParent->getTag() ==
SUMO_TAG_ROOTFILE)) {
57 writeError(
TL(
"Parameters must be defined within an object"));
59 writeError(
TL(
"Parameters cannot be defined within another parameter."));
60 }
else if ((SumoBaseObjectParent->getTag() !=
SUMO_TAG_ERROR) && parsedOk) {
62 const std::string parentTagStr =
toString(SumoBaseObjectParent->getTag());
67 writeError(
TLF(
"Error parsing key from % generic parameter. Key cannot be empty", parentTagStr));
69 writeError(
TLF(
"Error parsing key from % generic parameter. Key contains invalid characters", parentTagStr));
72 SumoBaseObjectParent->addParameter(key, value);
92 if (parentTags.size() > 0) {
94 for (
auto it = parentTags.begin(); it != parentTags.end(); it++) {
96 if ((it + 1) != parentTags.end()) {
97 if ((it + 2) != parentTags.end()) {
100 tagsStr.append(
" or ");
106 if (parent ==
nullptr) {
107 ok =
writeError(
TLF(
"'%' must be defined within the definition of a %.",
toString(currentTag), tagsStr));
108 }
else if ((parent->
getTag() !=
SUMO_TAG_ERROR) && std::find(parentTags.begin(), parentTags.end(), parent->
getTag()) == parentTags.end()) {
110 ok =
writeError(
TLF(
"'%' must be defined within the definition of a '%' (found % '%').",
toString(currentTag), tagsStr,
113 ok =
writeError(
TLF(
"'%' must be defined within the definition of a '%' (found %).",
toString(currentTag), tagsStr,
123 for (
const auto& vTypeID : vTypeIDs) {
125 return writeError(
TLF(
"Could not build % with ID '%' in netedit; '%' ist not a valid vType ID.",
toString(tag),
id, vTypeID));
148 if (obj ==
nullptr) {
160 if (hasRoute && hasEmbeddedRoute) {
161 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Cannot have an external route and an embedded route in the same definition.",
toString(tag),
id));
163 if ((overEdges + overJunctions + overTAZs) > 1) {
164 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Cannot have multiple from-to attributes.",
toString(tag),
id));
166 if ((hasRoute + hasEmbeddedRoute + overEdges + overJunctions + overTAZs) > 1) {
167 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Cannot have from-to attributes and route attributes in the same definition.",
toString(tag),
id));
169 if ((hasRoute + hasEmbeddedRoute + overEdges + overJunctions + overTAZs) == 0) {
170 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Requires either a route or an embedded route or a from-to attribute (Edges, junctions or TAZs).",
toString(tag),
id));
180 if (parent ==
nullptr) {
182 }
else if (!parent->wasCreated()) {
195 if (parent ==
nullptr) {
197 }
else if (!parent->wasCreated()) {
210 if (parent ==
nullptr) {
212 }
else if (!parent->wasCreated()) {
235 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Attribute % must be greather than zero.",
toString(tag),
id,
toString(attribute)));
294 return writeError(
TLF(
"Could not build % with ID '%' in netedit; ID contains invalid characters.",
toString(tag), value));
306 return writeError(
TLF(
"Could not build % with ID '%' in netedit; detector ID contains invalid characters.",
toString(tag), value));
318 return writeError(
TLF(
"Could not build % with ID '%' in netedit; ID contains invalid characters.",
toString(tag), value));
333 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Found another % with the same ID.",
toString(tag),
id,
toString(checkedTag)));
347 return writeError(
TLF(
"Could not build % with ID '%' in netedit; Invalid position over lane.",
toString(tag),
id));
353 return writeError(
TLF(
"Could not build % with ID '%' in netedit; List of edges cannot be empty.",
toString(tag),
id));
359 return writeError(
TLF(
"Could not build % with ID '%' in netedit; List of lanes isn't valid.",
toString(tag),
id));
365 return writeError(
TLF(
"Could not build % with ID '%' in netedit; % parent with ID '%' doesn't exist.",
toString(tag),
id,
toString(parentTag), parentID));
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ROOTFILE
root file
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ SUMO_TAG_PARAM
parameter associated to a certain key
@ SUMO_TAG_ERROR
tag used for indicate that there is an error (usually loading elements in handlers)
@ SUMO_TAG_TRIP
a single trip definition (used by router)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FROM_JUNCTION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
bool checkStopParents(CommonXMLStructure::SumoBaseObject *obj)
check stop parents
CommonXMLStructure::SumoBaseObject * getEmbeddedRoute(const CommonXMLStructure::SumoBaseObject *sumoBaseObject) const
get embedded route from children
virtual ~CommonHandler()
Destructor.
void checkParsedParent(const SumoXMLTag currentTag, const std::vector< SumoXMLTag > &parentTags, bool &ok)
check parsed parents
bool checkContainerPlanParents(CommonXMLStructure::SumoBaseObject *obj)
check container plan parents
bool writeError(const std::string &error)
write error and enable error creating element
bool myErrorCreatingElement
flag for mark if a element wasn't created
CommonHandler()=delete
invalidate default onstructor
bool checkValidDetectorID(const SumoXMLTag tag, const std::string &value)
check if the given detector ID is valid
bool writeErrorInvalidParent(const SumoXMLTag tag, const std::string &id, const SumoXMLTag parentTag, const std::string &parentID)
write error "invalid parent element" giving ids of current and parent element
bool checkListOfVehicleTypes(const SumoXMLTag tag, const std::string &id, const std::vector< std::string > &vTypeIDs)
check list of IDs
void parseParameters(const SUMOSAXAttributes &attrs)
parse generic parameters
bool writeWarningDuplicated(const SumoXMLTag tag, const std::string &id, const SumoXMLTag checkedTag)
write warning duplicated element
void writeWarningOverwritting(const SumoXMLTag tag, const std::string &id)
write warning overwritting element
bool writeErrorEmptyEdges(const SumoXMLTag tag, const std::string &id)
write error "empty edges"
bool checkWithinDistribution(CommonXMLStructure::SumoBaseObject *obj)
check if the given object is within a distribution (VType or routes)
bool checkValidAdditionalID(const SumoXMLTag tag, const std::string &value)
check if the given additional ID is valid
bool checkFileName(const SumoXMLTag tag, const std::string &id, const SumoXMLAttr attribute, const std::string &value)
check if the given filename is valid
bool writeErrorInvalidPosition(const SumoXMLTag tag, const std::string &id)
write error "invalid position"
CommonXMLStructure myCommonXMLStructure
common XML Structure
bool writeErrorInvalidLanes(const SumoXMLTag tag, const std::string &id)
write error "invalid list of lanes"
bool checkVehicleParents(CommonXMLStructure::SumoBaseObject *obj)
check vehicle parents
bool checkNegative(const SumoXMLTag tag, const std::string &id, const SumoXMLAttr attribute, const int value, const bool canBeZero)
check if the given int value is NOT negative
bool checkValidDemandElementID(const SumoXMLTag tag, const std::string &value)
check if the given demand elmement ID is valid
bool isErrorCreatingElement() const
get flag for mark if a element wasn't created
bool checkPersonPlanParents(CommonXMLStructure::SumoBaseObject *obj)
check person plan parents
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
SumoBaseObject * getParentSumoBaseObject() const
get pointer to mySumoBaseObjectParent SumoBaseObject (if is null, then is the root)
SumoXMLTag getTag() const
get XML myTag
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const std::vector< SumoBaseObject * > & getSumoBaseObjectChildren() const
get SumoBaseObject children
CommonXMLStructure::SumoBaseObject * getCurrentSumoBaseObject() const
get current editedSumoBaseObject
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
static bool isValidTypeID(const std::string &value)
whether the given string is a valid id for an edge or vehicle type
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidDetectorID(const std::string &value)
whether the given string is a valid id for an detector
static bool isValidParameterKey(const std::string &value)
whether the given string is a valid key for a parameter