55FXApp* GUI::myApp =
nullptr;
61std::vector<std::string>
64 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
73 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
80GUI::getZoom(
const std::string& viewID) {
81 return getView(viewID)->getChanger().getZoom();
86GUI::getAngle(
const std::string& viewID) {
87 return getView(viewID)->getChanger().getRotation();
92GUI::getOffset(
const std::string& viewID) {
102GUI::getSchema(
const std::string& viewID) {
103 return getView(viewID)->getVisualisationSettings().name;
108GUI::getBoundary(
const std::string& viewID) {
109 const Boundary& b = getView(viewID)->getVisibleBoundary();
110 TraCIPositionVector tb;
119 tb.value.push_back(minV);
120 tb.value.push_back(maxV);
126GUI::setZoom(
const std::string& viewID,
double zoom) {
129 const Position p(off.x(), off.y(), 0);
135GUI::setAngle(
const std::string& viewID,
double angle) {
138 const Position p(off.x(), off.y(), 0);
144GUI::setOffset(
const std::string& viewID,
double x,
double y) {
153GUI::setSchema(
const std::string& viewID,
const std::string& schemeName) {
154 getView(viewID)->setColorScheme(schemeName);
159GUI::addView(
const std::string& viewID,
const std::string& schemeName,
bool in3D) {
162 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
171GUI::removeView(
const std::string& viewID) {
174 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
183GUI::setBoundary(
const std::string& viewID,
double xmin,
double ymin,
double xmax,
double ymax) {
184 getView(viewID)->centerTo(
Boundary(xmin, ymin, xmax, ymax));
189GUI::screenshot(
const std::string& viewID,
const std::string& filename,
const int width,
const int height) {
190 getView(viewID)->addSnapshot(
SIMSTEP, filename, width, height);
195GUI::trackVehicle(
const std::string& viewID,
const std::string& vehID) {
202 if (veh !=
nullptr) {
203 glID =
static_cast<GUIVehicle*
>(veh)->getGlID();
206 if (person !=
nullptr) {
207 glID =
static_cast<GUIPerson*
>(person)->getGlID();
210 if (container !=
nullptr) {
211 glID =
static_cast<GUIContainer*
>(container)->getGlID();
213 throw TraCIException(
"Could not find vehicle or person '" + vehID +
"'.");
225GUI::hasView(
const std::string& viewID) {
228 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
235GUI::getTrackedVehicle(
const std::string& viewID) {
242 const std::string result = tracked ==
nullptr ?
"" : tracked->
getMicrosimID();
251GUI::track(
const std::string& objID,
const std::string& viewID) {
252 trackVehicle(viewID, objID);
257GUI::isSelected(
const std::string& objID,
const std::string& objType) {
258 const std::string fullName = objType +
":" + objID;
260 if (obj ==
nullptr) {
262 throw TraCIException(
"The " + objType +
" " + objID +
" is not known.");
271GUI::toggleSelection(
const std::string& objID,
const std::string& objType) {
272 const std::string fullName = objType +
":" + objID;
274 if (obj ==
nullptr) {
276 throw TraCIException(
"The " + objType +
" " + objID +
" is not known.");
284GUI::getParameter(
const std::string& ,
const std::string& ) {
290GUI::setParameter(
const std::string& ,
const std::string& ,
const std::string& ) {
299GUI::start(
const std::vector<std::string>& cmd) {
300 if (cmd[0].find(
"sumo-gui") == std::string::npos && std::getenv(
"LIBSUMO_GUI") ==
nullptr) {
304 WRITE_WARNING(
TL(
"Libsumo on Windows does not work with GUI, falling back to plain libsumo."));
308 if (!GUI::close(
"Libsumo started new instance.")) {
311 bool needStart =
false;
312 if (std::getenv(
"LIBSUMO_GUI") !=
nullptr) {
314 for (
const std::string& a : cmd) {
315 if (a ==
"-S" || a ==
"--start") {
320 int origArgc = (int)cmd.size();
325 char** argv =
new char* [argc];
327 for (i = 0; i < origArgc; i++) {
328 argv[i] =
new char[cmd[i].size() + 1];
329 std::strcpy(argv[i], cmd[i].c_str());
332 argv[i++] = (
char*)
"-S";
343 myApp =
new FXApp(
"SUMO GUI",
"sumo-gui");
344 myApp->init(argc, argv);
346 if (!FXGLVisual::supported(myApp, major, minor)) {
347 throw ProcessError(
"This system has no OpenGL support. Exiting.");
353 myWindow->dependentBuild(
true);
355 myWindow->getRunner()->enableLibsumo();
358 myWindow->loadOnStartup(
true);
361 throw TraCIException(e.what());
369GUI::load(
const std::vector<std::string>& ) {
370 if (myWindow !=
nullptr) {
371 WRITE_ERROR(
TL(
"libsumo.load is not implemented for the GUI."));
380 return myWindow !=
nullptr;
386 if (myWindow !=
nullptr) {
391 myWindow->getRunner()->tryStep();
400GUI::close(
const std::string& ) {
401 if (myWindow !=
nullptr) {
414GUI::getView(
const std::string&
id) {
418 throw TraCIException(
"GUI is not running, command not implemented in command line sumo");
422 throw TraCIException(
"View '" +
id +
"' is not known");
428std::shared_ptr<VariableWrapper>
430 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
435GUI::handleVariable(
const std::string& objID,
const int variable, VariableWrapper* wrapper,
tcpip::Storage* ) {
438 return wrapper->wrapStringList(objID, variable, getIDList());
440 return wrapper->wrapInt(objID, variable, getIDCount());
442 return wrapper->wrapDouble(objID, variable, getZoom(objID));
444 return wrapper->wrapPosition(objID, variable, getOffset(objID));
446 return wrapper->wrapString(objID, variable, getSchema(objID));
448 return wrapper->wrapDouble(objID, variable, getAngle(objID));
450 return wrapper->wrapPositionVector(objID, variable, getBoundary(objID));
452 return wrapper->wrapInt(objID, variable, hasView(objID) ? 1 : 0);
454 return wrapper->wrapString(objID, variable, getTrackedVehicle(objID));
GUICompleteSchemeStorage gSchemeStorage
GUISelectedStorage gSelected
A global holder of selected objects.
#define WRITE_WARNING(msg)
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
A class that stores a 2D geometrical boundary.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
double zmin() const
Returns minimum z-coordinate.
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
double zmax() const
Returns maximum z-coordinate.
The main window of the SUMO-gui.
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
GUISUMOAbstractView * getView() const
return GUISUMOAbstractView
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
static const GUIGlID INVALID_ID
GUIGlID getGlID() const
Returns the numerical id of the object.
void unblockObject(GUIGlID id)
Marks an object as unblocked.
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
C++ TraCI client API implementation.
GUIGlChildWindow * getViewByID(const std::string &id) const
get specific view by ID
std::vector< std::string > getViewIDs() const
get view IDs
static GUIMainWindow * getInstance()
get instance
virtual void sendBlockingEvent(GUIEvent *event)
Sends an event from the application thread to the GUI and waits until it is handled.
virtual double zoom2ZPos(double zoom) const =0
Returns the camera height at which the given zoom level is reached.
virtual double getRotation() const =0
Returns the rotation of the canvas stored in this changer.
virtual double getXPos() const =0
Returns the x-offset of the field to show stored in this changer.
virtual double getYPos() const =0
Returns the y-offset of the field to show stored in this changer.
virtual double getZPos() const =0
Returns the camera height corresponding to the current zoom factor.
GUIPerspectiveChanger & getChanger() const
get changer
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
virtual void stopTrack()
stop track
virtual void startTrack(int)
star track
virtual GUIGlID getTrackedID() const
get tracked id
void toggleSelection(GUIGlID id)
Toggles selection of an object.
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
A MSVehicle extended by some values for usage within the gui.
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual MSTransportableControl & getContainerControl()
Returns the container control.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
static void setFactory(Factory func)
Sets the factory function to use for new MsgHandlers.
static MsgHandler * create(MsgType type)
static OptionsCont & getOptions()
Retrieves the options.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
A point in 2D or 3D with translation and scaling methods.
Representation of a vehicle.
static void close()
Closes all of an applications subsystems.
static void init()
Initialises the xml-subsystem.
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_VIEW_BOUNDARY
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_VIEW_OFFSET
TRACI_CONST int VAR_VIEW_SCHEMA
TRACI_CONST int VAR_VIEW_ZOOM
TRACI_CONST int VAR_TRACK_VEHICLE
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
TRACI_CONST int VAR_HAS_VIEW