Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNENetDiffTool.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// Netdiff tool used in netedit
19/****************************************************************************/
20
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.h>
28#include <utils/xml/XMLSubSys.h>
29
30#include "GNENetDiffTool.h"
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
36GNENetDiffTool::GNENetDiffTool(GNEApplicationWindow* GNEApp, const std::string& toolPath, FXMenuPane* menu) :
37 GNEPythonTool(GNEApp, toolPath, "", menu) {
38 // fill options
41}
42
43
45
46
47void
50 // obtain curren network folder
51 const auto networkPath = OptionsCont::getOptions().getString("net-file");
52 if (networkPath.empty()) {
53 myPythonToolsOptions.set("outprefix", "");
54 } else {
55 myPythonToolsOptions.set("outprefix", FileHelpers::getFilePath(networkPath) + "diff");
56 }
57}
58
59
60void
62 // first check if there is a network
63 if (myGNEApp->getViewNet()) {
64 // get selector operator modul from selector frame
66 // select elements
67 if (myPythonToolsOptions.getBool("select-modified")) {
68 selectorModul->loadFromFile(myPythonToolsOptions.getString("outprefix") + ".changed.sel.txt");
69 }
70 if (myPythonToolsOptions.getBool("select-added")) {
71 selectorModul->loadFromFile(myPythonToolsOptions.getString("outprefix") + ".created.sel.txt");
72 }
73 if (myPythonToolsOptions.getBool("select-deleted")) {
74 selectorModul->loadFromFile(myPythonToolsOptions.getString("outprefix") + ".deleted.sel.txt");
75 }
76 // load shapes
77 if (myPythonToolsOptions.getBool("load-shapes-modified")) {
78 loadShapes(myPythonToolsOptions.getString("outprefix") + ".changed.shape.xml");
79 }
80 if (myPythonToolsOptions.getBool("load-shapes-added")) {
81 loadShapes(myPythonToolsOptions.getString("outprefix") + ".created.shape.xml");
82 }
83 if (myPythonToolsOptions.getBool("load-shapes-deleted")) {
84 loadShapes(myPythonToolsOptions.getString("outprefix") + ".deleted.shape.xml");
85 }
86 }
87}
88
89
90std::string
92 std::string arguments;
93 // add arguments
94 arguments += "\"" + myPythonToolsOptions.getString("original-net") + "\" ";
95 arguments += "\"" + myPythonToolsOptions.getString("modified-net") + "\" ";
96 arguments += "\"" + myPythonToolsOptions.getString("outprefix") + "\" ";
97 // check if save selection
98 if (myPythonToolsOptions.getBool("select-modified") ||
99 myPythonToolsOptions.getBool("select-added") ||
100 myPythonToolsOptions.getBool("select-deleted")) {
101 arguments += "--write-selections ";
102 }
103 // check if save shapes
104 if (myPythonToolsOptions.getBool("load-shapes-modified") ||
105 myPythonToolsOptions.getBool("load-shapes-added") ||
106 myPythonToolsOptions.getBool("load-shapes-deleted")) {
107 arguments += "--write-shapes ";
108 }
109 return getCommandPath() + " " + arguments;
110}
111
112
113void
115 // build custom options for netdiff
116 options.addOptionSubTopic("input");
117 options.addOptionSubTopic("output");
118 options.doRegister("original-net", new Option_Network(""));
119 options.addDescription("original-net", "input", TL("Original network"));
120
121 options.doRegister("modified-net", new Option_Network(""));
122 options.addDescription("modified-net", "input", TL("Modified network"));
123
124 options.doRegister("outprefix", new Option_FileName());
125 options.addDescription("outprefix", "output", TL("Output prefix network"));
126
127 options.addOptionSubTopic("Select");
128 options.doRegister("select-modified", new Option_Bool(false));
129 options.addDescription("select-modified", "Select", TL("Select modified elements"));
130
131 options.doRegister("select-added", new Option_Bool(false));
132 options.addDescription("select-added", "Select", TL("Select added elements"));
133
134 options.doRegister("select-deleted", new Option_Bool(false));
135 options.addDescription("select-deleted", "Select", TL("Select deleted elements"));
136
137 options.addOptionSubTopic("Load");
138 options.doRegister("load-shapes-modified", new Option_Bool(false));
139 options.addDescription("load-shapes-modified", "Load", TL("Load shapes for elements"));
140
141 options.doRegister("load-shapes-added", new Option_Bool(false));
142 options.addDescription("load-shapes-added", "Load", TL("Load shapes for added"));
143
144 options.doRegister("load-shapes-deleted", new Option_Bool(false));
145 options.addDescription("load-shapes-deleted", "Load", TL("Load shapes for deleted elements"));
146}
147
148
149void
150GNENetDiffTool::loadShapes(const std::string& file) {
151 // get undo list
152 auto undoList = myGNEApp->getUndoList();
153 // disable validation for additionals
154 XMLSubSys::setValidation("never", "auto", "auto");
155 // Create additional handler
156 GNEGeneralHandler generalHandler(myGNEApp->getViewNet()->getNet(), file, true, true);
157 // begin undoList operation
158 undoList->begin(Supermode::NETWORK, GUIIcon::SUPERMODENETWORK, TL("load shapes from '") + file + "'");
159 // Run parser
160 if (!generalHandler.parse()) {
161 // write error
162 WRITE_ERROR(TL("Loading of shape file failed: ") + file);
163 } else {
164 // write info
165 WRITE_MESSAGE(TL("Loading of shape file successfully: ") + file);
166 }
167 // end undoList operation
168 undoList->end();
169 // restore validation for additionals
170 XMLSubSys::setValidation("auto", "auto", "auto");
171 // update view
172 myGNEApp->getViewNet()->update();
173}
174
175/****************************************************************************/
@ NETWORK
Network mode (Edges, junctions, etc..)
@ SUPERMODENETWORK
#define WRITE_MESSAGE(msg)
Definition MsgHandler.h:297
#define WRITE_ERROR(msg)
Definition MsgHandler.h:304
#define TL(string)
Definition MsgHandler.h:315
static std::string getFilePath(const std::string &path)
Removes the file information from the given path.
The main window of Netedit.
GNEUndoList * getUndoList()
get pointer to undoList
GNEViewNet * getViewNet()
get pointer to viewNet
std::string getCommand() const
get command (python + script + arguments)
void loadShapes(const std::string &file)
load shapes
void postProcessing()
execute post processing
~GNENetDiffTool()
destructor
void setCurrentValues()
set current values (used for set values like current folder and similar)
void fillNetDiffOptions(OptionsCont &options)
fill netDiff options
GNENetDiffTool(GNEApplicationWindow *GNEApp, const std::string &toolPath, FXMenuPane *menu)
Constructor.
OptionsCont myPythonToolsOptionsOriginal
original tools options
GNEApplicationWindow * myGNEApp
pointer to GNEApplicationWindow
std::string getCommandPath() const
get command (python + script)
OptionsCont myPythonToolsOptions
tools options
void loadFromFile(const std::string &file) const
load from file
GNESelectorFrame::SelectionOperation * getSelectionOperationModul() const
get selection operation modul
GNENet * getNet() const
get the net object
GNEViewParent * getViewParent() const
get the net object
GNESelectorFrame * getSelectorFrame() const
get frame for select elements
bool parse()
parse
A storage for options typed value containers)
Definition OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool set(const std::string &name, const std::string &value, const bool append=false)
Sets the given value for the named option.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void resetWritable()
Resets all options to be writeable.
static OptionsCont & getOptions()
Retrieves the options.
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme, const std::string &routeValidationScheme)
Enables or disables validation.
Definition XMLSubSys.cpp:83