Skip to content

Commit

Permalink
option prefix is now also supported by netconvert
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed May 17, 2018
1 parent 20a9fc9 commit 9babde6
Show file tree
Hide file tree
Showing 25 changed files with 996 additions and 707 deletions.
18 changes: 16 additions & 2 deletions src/netbuild/NBEdgeCont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <utils/common/ToString.h>
#include <utils/common/TplConvert.h>
#include <utils/common/IDSupplier.h>
#include <utils/common/StringUtils.h>
#include <utils/common/StringTokenizer.h>
#include <utils/common/UtilExceptions.h>
#include <utils/iodevices/OutputDevice.h>
Expand Down Expand Up @@ -1157,7 +1158,7 @@ NBEdgeCont::guessSidewalks(double width, double minSpeed, double maxSpeed, bool


int
NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix) {
std::vector<std::string> avoid = getAllNames();
std::set<std::string> reserve;
if (reservedIDs) {
Expand Down Expand Up @@ -1188,7 +1189,20 @@ NBEdgeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
edge->setID(idSupplier.getNext());
myEdges[edge->getID()] = edge;
}
return (int)toChange.size();
if (prefix.empty()) {
return (int)toChange.size();
} else {
int renamed = 0;
// make a copy because we will modify the map
auto oldEdges = myEdges;
for (auto item : oldEdges) {
if (!StringUtils::startsWith(item.first, prefix)) {
rename(item.second, prefix + item.first);
renamed++;
}
}
return renamed;
}
}


Expand Down
2 changes: 1 addition & 1 deletion src/netbuild/NBEdgeCont.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ class NBEdgeCont {
bool ignoreFilterMatch(NBEdge* edge);

/// @brief remap node IDs accoring to options --numerical-ids and --reserved-ids
int remapIDs(bool numericaIDs, bool reservedIDs);
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);

/// @brief check whether edges overlap
void checkOverlap(double threshold, double zThreshold) const;
Expand Down
4 changes: 2 additions & 2 deletions src/netbuild/NBNetBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ NBNetBuilder::compute(OptionsCont& oc, const std::set<std::string>& explicitTurn
myEdgeCont.recheckPostProcessConnections();

// remap ids if wished
int numChangedEdges = myEdgeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
int numChangedNodes = myNodeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"));
int numChangedEdges = myEdgeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"), oc.getString("prefix"));
int numChangedNodes = myNodeCont.remapIDs(oc.getBool("numerical-ids"), oc.isSet("reserved-ids"), oc.getString("prefix"));
if (numChangedEdges + numChangedNodes > 0) {
WRITE_MESSAGE("Remapped " + toString(numChangedEdges) + " edge IDs and " + toString(numChangedNodes) + " node IDs.");
}
Expand Down
18 changes: 16 additions & 2 deletions src/netbuild/NBNodeCont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <utils/common/MsgHandler.h>
#include <utils/common/UtilExceptions.h>
#include <utils/common/StringTokenizer.h>
#include <utils/common/StringUtils.h>
#include <utils/common/StdDefs.h>
#include <utils/common/ToString.h>
#include <utils/common/TplConvert.h>
Expand Down Expand Up @@ -1499,7 +1500,7 @@ NBNodeCont::discardTrafficLights(NBTrafficLightLogicCont& tlc, bool geometryLike


int
NBNodeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
NBNodeCont::remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix) {
std::vector<std::string> avoid = getAllNames();
std::set<std::string> reserve;
if (reservedIDs) {
Expand Down Expand Up @@ -1530,7 +1531,20 @@ NBNodeCont::remapIDs(bool numericaIDs, bool reservedIDs) {
node->setID(idSupplier.getNext());
myNodes[node->getID()] = node;
}
return (int)toChange.size();
if (prefix.empty()) {
return (int)toChange.size();
} else {
int renamed = 0;
// make a copy because we will modify the map
auto oldNodes = myNodes;
for (auto item : oldNodes) {
if (!StringUtils::startsWith(item.first, prefix)) {
rename(item.second, prefix + item.first);
renamed++;
}
}
return renamed;
}
}

/****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/netbuild/NBNodeCont.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class NBNodeCont {
}

/// @brief remap node IDs accoring to options --numerical-ids and --reserved-ids
int remapIDs(bool numericaIDs, bool reservedIDs);
int remapIDs(bool numericaIDs, bool reservedIDs, const std::string& prefix);

private:
/// @brief Definition of a node cluster container
Expand Down
4 changes: 0 additions & 4 deletions src/netgen/NGFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
void
NGFrame::fillOptions() {
OptionsCont& oc = OptionsCont::getOptions();
// register output options
oc.doRegister("prefix", new Option_String(""));
oc.addDescription("prefix", "Output", "Defines the prefix for edge and junction names");

oc.doRegister("alphanumerical-ids", new Option_Bool(true));
oc.addDescription("alphanumerical-ids", "Output", "The Ids of generated nodes use an alphanumerical code for easier readability when possible");

Expand Down
15 changes: 7 additions & 8 deletions src/netgen/NGNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
// ===========================================================================
NGNet::NGNet(NBNetBuilder& nb) :
myLastID(0),
myIDPrefix(OptionsCont::getOptions().getString("prefix")),
myAlphaIDs(OptionsCont::getOptions().getBool("alphanumerical-ids")),
myNetBuilder(nb)
{
Expand All @@ -68,7 +67,7 @@ NGNet::~NGNet() {

std::string
NGNet::getNextFreeID() {
return myIDPrefix + toString<int>(++myLastID);
return toString<int>(++myLastID);
}


Expand Down Expand Up @@ -99,7 +98,7 @@ void
NGNet::createChequerBoard(int numX, int numY, double spaceX, double spaceY, double attachLength) {

for (int ix = 0; ix < numX; ix++) {
const std::string nodeIDStart = myIDPrefix + (myAlphaIDs ? alphabeticalCode(ix, numX) : toString<int>(ix) + "/");
const std::string nodeIDStart = (myAlphaIDs ? alphabeticalCode(ix, numX) : toString<int>(ix) + "/");
for (int iy = 0; iy < numY; iy++) {
// create Node
NGNode* node = new NGNode(nodeIDStart + toString(iy), ix, iy);
Expand All @@ -118,8 +117,8 @@ NGNet::createChequerBoard(int numX, int numY, double spaceX, double spaceY, doub
if (attachLength > 0.0) {
for (int ix = 0; ix < numX; ix++) {
// create nodes
NGNode* topNode = new NGNode(myIDPrefix + "top" + toString<int>(ix), ix, numY);
NGNode* bottomNode = new NGNode(myIDPrefix + "bottom" + toString<int>(ix), ix, numY + 1);
NGNode* topNode = new NGNode("top" + toString<int>(ix), ix, numY);
NGNode* bottomNode = new NGNode("bottom" + toString<int>(ix), ix, numY + 1);
topNode->setX(ix * spaceX + attachLength);
bottomNode->setX(ix * spaceX + attachLength);
topNode->setY((numY - 1) * spaceY + 2 * attachLength);
Expand All @@ -132,8 +131,8 @@ NGNet::createChequerBoard(int numX, int numY, double spaceX, double spaceY, doub
}
for (int iy = 0; iy < numY; iy++) {
// create nodes
NGNode* leftNode = new NGNode(myIDPrefix + "left" + toString<int>(iy), numX, iy);
NGNode* rightNode = new NGNode(myIDPrefix + "right" + toString<int>(iy), numX + 1, iy);
NGNode* leftNode = new NGNode("left" + toString<int>(iy), numX, iy);
NGNode* rightNode = new NGNode("right" + toString<int>(iy), numX + 1, iy);
leftNode->setX(0);
rightNode->setX((numX - 1) * spaceX + 2 * attachLength);
leftNode->setY(iy * spaceY + attachLength);
Expand Down Expand Up @@ -173,7 +172,7 @@ NGNet::createSpiderWeb(int numRadDiv, int numCircles, double spaceRad, bool hasC
double angle = (double)(2 * M_PI / numRadDiv); // angle between radial divisions
NGNode* Node;
for (ic = 1; ic < numCircles + 1; ic++) {
const std::string nodeIDStart = myIDPrefix + alphabeticalCode(ic, numCircles);
const std::string nodeIDStart = alphabeticalCode(ic, numCircles);
for (ir = 1; ir < numRadDiv + 1; ir++) {
// create Node
const std::string nodeID = (myAlphaIDs ?
Expand Down
3 changes: 0 additions & 3 deletions src/netgen/NGNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ class NGNet {
/// @brief The last ID given to node or link
int myLastID;

/// @brief The ID prefix
const std::string myIDPrefix;

/// @brief Whether to use alphanumericalIDs
const bool myAlphaIDs;

Expand Down
3 changes: 3 additions & 0 deletions src/netwrite/NWFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ NWFrame::fillOptions(bool forNetgen) {
oc.addDescription("junctions.join-output", "Output",
"Writes information about joined junctions to FILE (can be loaded as additional node-file to reproduce joins");

oc.doRegister("prefix", new Option_String(""));
oc.addDescription("prefix", "Output", "Defines a prefix for edge and junction names");

#ifdef HAVE_PROJ
if (!forNetgen) {
oc.doRegister("proj.plain-geo", new Option_Bool(false));
Expand Down
Empty file.
37 changes: 37 additions & 0 deletions tests/netconvert/function/prefix/input_edges.edg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on Wed 29 Jan 2014 03:30:12 PM CET by Netedit Version dev-SVN-r15523
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netedit.exeConfiguration.xsd">
<input>
<sumo-net-file value="net4a.net.xml"/>
</input>
<output>
<output-file value="net4a.net.xml"/>
<plain-output-prefix value="/scr1/erdm_ja/sip-svn-trunk/projects/colombo/prototype4/plain4a"/>
</output>
<processing>
<no-turnarounds value="true"/>
<offset.disable-normalization value="true"/>
</processing>
</configuration>
-->

<edges version="0.13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/edges_file.xsd">
<edge id="CE" from="C" to="E" priority="2" numLanes="2" speed="13.89"/>
<edge id="CN" from="C" to="N" priority="2" numLanes="2" speed="13.89"/>
<edge id="CS" from="C" to="S" priority="2" numLanes="2" speed="13.89"/>
<edge id="CW" from="C" to="W" priority="2" numLanes="2" speed="13.89"/>
<edge id="EC" from="E" to="C" priority="2" numLanes="2" speed="13.89"/>
<edge id="NC" from="N" to="C" priority="2" numLanes="2" speed="13.89"/>
<edge id="SC" from="S" to="C" priority="2" numLanes="2" speed="13.89"/>
<edge id="WC" from="W" to="C" priority="2" numLanes="2" speed="13.89"/>
</edges>
36 changes: 36 additions & 0 deletions tests/netconvert/function/prefix/input_nodes.nod.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on Wed 29 Jan 2014 03:30:12 PM CET by Netedit Version dev-SVN-r15523
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v20.html
SPDX-License-Identifier: EPL-2.0
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netedit.exeConfiguration.xsd">
<input>
<sumo-net-file value="net4a.net.xml"/>
</input>
<output>
<output-file value="net4a.net.xml"/>
<plain-output-prefix value="/scr1/erdm_ja/sip-svn-trunk/projects/colombo/prototype4/plain4a"/>
</output>
<processing>
<no-turnarounds value="true"/>
<offset.disable-normalization value="true"/>
</processing>
</configuration>
-->

<nodes version="0.13" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/nodes_file.xsd">
<location netOffset="100.00,100.00" convBoundary="0.00,0.00,200.00,200.00" origBoundary="-10000000000.00,-10000000000.00,10000000000.00,10000000000.00" projParameter="!"/>

<node id="C" x="100.00" y="100.00" type="traffic_light" tl="C"/>
<node id="E" x="200.00" y="100.00" type="priority"/>
<node id="N" x="100.00" y="200.00" type="dead_end"/>
<node id="S" x="100.00" y="0.00" type="priority"/>
<node id="W" x="0.00" y="100.00" type="dead_end"/>
</nodes>
Loading

0 comments on commit 9babde6

Please sign in to comment.