Skip to content

Commit

Permalink
Updated GUIDialog_GLObjChooser. Refs eclipse-sumo#6916
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Oct 16, 2020
1 parent fbb42d8 commit c666b53
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 55 deletions.
102 changes: 98 additions & 4 deletions src/gui/GUISUMOViewParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,38 @@ GUISUMOViewParent::setToolBarVisibility(const bool value) {
}


void
GUISUMOViewParent::eraseGLObjChooser(GUIDialog_GLObjChooser* GLObjChooser) {
if (GLObjChooser == nullptr) {
throw ProcessError("ChooserDialog already deleted");
} else if (GLObjChooser == myGLObjChooser.ACChooserJunction) {
myGLObjChooser.ACChooserJunction = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserEdges) {
myGLObjChooser.ACChooserEdges = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserVehicles) {
myGLObjChooser.ACChooserVehicles = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserPersons) {
myGLObjChooser.ACChooserPersons = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserRoutes) {
myGLObjChooser.ACChooserRoutes = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserStops) {
myGLObjChooser.ACChooserStops = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserTLS) {
myGLObjChooser.ACChooserTLS = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserAdditional) {
myGLObjChooser.ACChooserAdditional = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserPOI) {
myGLObjChooser.ACChooserPOI = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserPolygon) {
myGLObjChooser.ACChooserPolygon = nullptr;
} else if (GLObjChooser == myGLObjChooser.ACChooserProhibition) {
myGLObjChooser.ACChooserProhibition = nullptr;
} else {
throw ProcessError("Unregistered chooserDialog");
}
}


long
GUISUMOViewParent::onCmdMakeSnapshot(FXObject* sender, FXSelector, void*) {
MFXCheckableButton* button = dynamic_cast<MFXCheckableButton*>(sender);
Expand Down Expand Up @@ -191,9 +223,17 @@ GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
std::string chooserTitle;
switch (FXSELID(sel)) {
case MID_LOCATEJUNCTION:
ids = static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal());
icon = GUIIcon::LOCATEJUNCTION;
chooserTitle = "Junction Chooser";
if (myGLObjChooser.ACChooserJunction) {
// restore focus in the existent chooser dialog
myGLObjChooser.ACChooserJunction->restore();
myGLObjChooser.ACChooserJunction->setFocus();
} else {
myGLObjChooser.ACChooserJunction = new GUIDialog_GLObjChooser(this, nullptr,
GUIIconSubSys::getIcon(GUIIcon::LOCATEJUNCTION),
"Junction Chooser",
static_cast<GUINet*>(GUINet::getInstance())->getJunctionIDs(myParent->listInternal()),
GUIGlObjectStorage::gIDStorage);
}
break;
case MID_LOCATEEDGE:
ids = GUIEdge::getIDs(myParent->listInternal());
Expand Down Expand Up @@ -246,7 +286,6 @@ GUISUMOViewParent::onCmdLocate(FXObject*, FXSelector sel, void*) {
myLocatorPopup->popdown();
myLocatorButton->killFocus();
myLocatorPopup->update();
new GUIDialog_GLObjChooser(this, GUIIconSubSys::getIcon(icon), chooserTitle.c_str(), ids, GUIGlObjectStorage::gIDStorage);
return 1;
}

Expand Down Expand Up @@ -361,5 +400,60 @@ GUISUMOViewParent::onUpdSpeedFactor(FXObject* sender, FXSelector, void* ptr) {
return 1;
}

// ===========================================================================
// private
// ===========================================================================

GUISUMOViewParent::GLObjChooser::GLObjChooser() :
ACChooserJunction(nullptr),
ACChooserEdges(nullptr),
ACChooserVehicles(nullptr),
ACChooserPersons(nullptr),
ACChooserRoutes(nullptr),
ACChooserStops(nullptr),
ACChooserTLS(nullptr),
ACChooserAdditional(nullptr),
ACChooserPOI(nullptr),
ACChooserPolygon(nullptr),
ACChooserProhibition(nullptr) {
}


GUISUMOViewParent::GLObjChooser::~GLObjChooser() {
// remove all dialogs if are active
if (ACChooserJunction) {
delete ACChooserJunction;
}
if (ACChooserEdges) {
delete ACChooserEdges;
}
if (ACChooserRoutes) {
delete ACChooserRoutes;
}
if (ACChooserStops) {
delete ACChooserStops;
}
if (ACChooserVehicles) {
delete ACChooserVehicles;
}
if (ACChooserPersons) {
delete ACChooserPersons;
}
if (ACChooserTLS) {
delete ACChooserTLS;
}
if (ACChooserAdditional) {
delete ACChooserAdditional;
}
if (ACChooserPOI) {
delete ACChooserPOI;
}
if (ACChooserPolygon) {
delete ACChooserPolygon;
}
if (ACChooserProhibition) {
delete ACChooserProhibition;
}
}

/****************************************************************************/
68 changes: 60 additions & 8 deletions src/gui/GUISUMOViewParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class GUISUMOViewParent : public GUIGlChildWindow {
VIEW_3D_OSG
};


/** @brief Constructor
* @param[in] p The MDI-pane this window is shown within
* @param[in] mdimenu The MDI-menu for alignment
Expand All @@ -92,21 +91,19 @@ class GUISUMOViewParent : public GUIGlChildWindow {
*/
virtual GUISUMOAbstractView* init(FXGLCanvas* share, GUINet& net, ViewType type);


/// @brief Destructor
~GUISUMOViewParent();


/// @brief Called if the user wants to make a snapshot (screenshot)
long onCmdMakeSnapshot(FXObject* sender, FXSelector, void*);

/// @brief Called on a simulation step
long onSimStep(FXObject* sender, FXSelector, void*);

/// @brief locator-callback
/// @brief locator-callback
long onCmdLocate(FXObject*, FXSelector, void*);

/// @brief speedFactor-callback
/// @brief speedFactor-callback
long onCmdSpeedFactor(FXObject*, FXSelector, void*);
long onUpdSpeedFactor(FXObject*, FXSelector, void*);

Expand All @@ -117,18 +114,73 @@ class GUISUMOViewParent : public GUIGlChildWindow {
/// @brief true if the object is selected (may include extra logic besides calling gSelected)
bool isSelected(GUIGlObject* o) const;

/// @notify about toggled gaming status
/// @brief about toggled gaming status
void setToolBarVisibility(const bool value);

/// @brief erase GLObjChooser
void eraseGLObjChooser(GUIDialog_GLObjChooser* GLObjChooser);

protected:
/// @brief fox need this
FOX_CONSTRUCTOR(GUISUMOViewParent)

/// @brief build speed control toolbar
void buildSpeedControlToolbar();

/// @brief toolbar shell for speed
FXToolBarShell* myToolBarDragSpeed = nullptr;

/// @brief toolbar for speed
FXToolBar* myToolBarSpeed = nullptr;

/// @brief slider for speedfactor
FXSlider* mySpeedFactorSlider = nullptr;

private:
/// @brief struct for GLObjChooser dialog
class GLObjChooser {

protected:
FOX_CONSTRUCTOR(GUISUMOViewParent)
public:
/// @brief constructor
GLObjChooser();

/// @brief destructor
~GLObjChooser();

/// @brief pointer to ACChooser dialog used for locate junctions
GUIDialog_GLObjChooser* ACChooserJunction;

/// @brief pointer to ACChooser dialog used for locate edges
GUIDialog_GLObjChooser* ACChooserEdges;

/// @brief pointer to ACChooser dialog used for locate vehicles
GUIDialog_GLObjChooser* ACChooserVehicles;

/// @brief pointer to ACChooser dialog used for locate persons
GUIDialog_GLObjChooser* ACChooserPersons;

/// @brief pointer to ACChooser dialog used for locate routes
GUIDialog_GLObjChooser* ACChooserRoutes;

/// @brief pointer to ACChooser dialog used for locate stops
GUIDialog_GLObjChooser* ACChooserStops;

/// @brief pointer to ACChooser dialog used for locate TLSs
GUIDialog_GLObjChooser* ACChooserTLS;

/// @brief pointer to ACChooser dialog used for locate additional
GUIDialog_GLObjChooser* ACChooserAdditional;

/// @brief pointer to ACChooser dialog used for locate POIs
GUIDialog_GLObjChooser* ACChooserPOI;

/// @brief pointer to ACChooser dialog used for locate Polygons
GUIDialog_GLObjChooser* ACChooserPolygon;

/// @brief pointer to ACChooser dialog used for locate Prohibitions
GUIDialog_GLObjChooser* ACChooserProhibition;
};

/// @brief GLObjChooser
GLObjChooser myGLObjChooser;
};
2 changes: 1 addition & 1 deletion src/netedit/dialogs/GNEDialogACChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// ===========================================================================

GNEDialogACChooser::GNEDialogACChooser(GNEViewParent* viewParent, FXIcon* icon, const std::string& title, const std::vector<GNEAttributeCarrier*>& ACs):
GUIDialog_GLObjChooser(viewParent, icon, title.c_str(), std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
GUIDialog_GLObjChooser(nullptr, viewParent, icon, title.c_str(), std::vector<GUIGlID>(), GUIGlObjectStorage::gIDStorage),
myACs(ACs),
myFilteredACs(ACs),
myViewParent(viewParent),
Expand Down
79 changes: 56 additions & 23 deletions src/utils/gui/windows/GUIDialog_GLObjChooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,26 @@
#include <utils/gui/div/GUIGlobalSelection.h>
#include <utils/gui/div/GUIDesigns.h>
#include <utils/gui/globjects/GUIGlObject_AbstractAdd.h>
#include <gui/GUISUMOViewParent.h>
#include <netedit/GNEViewParent.h>

#include "GUIDialog_GLObjChooser.h"


// ===========================================================================
// FOX callback mapping
// ===========================================================================
FXDEFMAP(GUIDialog_GLObjChooser) GUIDialog_GLObjChooserMap[] = {
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TRACK, GUIDialog_GLObjChooser::onCmdTrack),
FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLObjChooser::onCmdClose),
FXMAPFUNC(SEL_CHANGED, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onChgText),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onCmdText),
FXMAPFUNC(SEL_KEYPRESS, MID_CHOOSER_LIST, GUIDialog_GLObjChooser::onListKeyPress),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_FILTER, GUIDialog_GLObjChooser::onCmdFilter),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_FILTER_SUBSTR, GUIDialog_GLObjChooser::onCmdFilterSubstr),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_INVERT, GUIDialog_GLObjChooser::onCmdToggleSelection),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_NAME, GUIDialog_GLObjChooser::onCmdLocateByName),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_CENTER, GUIDialog_GLObjChooser::onCmdCenter),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TRACK, GUIDialog_GLObjChooser::onCmdTrack),
FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GUIDialog_GLObjChooser::onCmdClose),
FXMAPFUNC(SEL_CHANGED, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onChgText),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_TEXT, GUIDialog_GLObjChooser::onCmdText),
FXMAPFUNC(SEL_KEYPRESS, MID_CHOOSER_LIST, GUIDialog_GLObjChooser::onListKeyPress),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_FILTER, GUIDialog_GLObjChooser::onCmdFilter),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSER_FILTER_SUBSTR, GUIDialog_GLObjChooser::onCmdFilterSubstr),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_INVERT, GUIDialog_GLObjChooser::onCmdToggleSelection),
FXMAPFUNC(SEL_COMMAND, MID_CHOOSEN_NAME, GUIDialog_GLObjChooser::onCmdLocateByName),
};

FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARRAYNUMBER(GUIDialog_GLObjChooserMap))
Expand All @@ -58,9 +61,11 @@ FXIMPLEMENT(GUIDialog_GLObjChooser, FXMainWindow, GUIDialog_GLObjChooserMap, ARR
// ===========================================================================
// method definitions
// ===========================================================================
GUIDialog_GLObjChooser::GUIDialog_GLObjChooser(GUIGlChildWindow* parent, FXIcon* icon, const FXString& title, const std::vector<GUIGlID>& ids, GUIGlObjectStorage& /*glStorage*/) :
FXMainWindow(parent->getApp(), title, icon, nullptr, GUIDesignChooserDialog),
myParent(parent),
GUIDialog_GLObjChooser::GUIDialog_GLObjChooser(GUISUMOViewParent* SUMOViewParent, GNEViewParent* viewParent,
FXIcon* icon, const FXString& title, const std::vector<GUIGlID>& ids, GUIGlObjectStorage& /*glStorage*/) :
FXMainWindow(SUMOViewParent? SUMOViewParent->getApp() : viewParent->getApp(), title, icon, nullptr, GUIDesignChooserDialog),
mySUMOViewParent(SUMOViewParent),
myGNEViewParent(viewParent),
myLocateByName(false),
myHaveFilteredSubstring(false) {
FXHorizontalFrame* hbox = new FXHorizontalFrame(this, GUIDesignAuxiliarFrame);
Expand All @@ -86,16 +91,25 @@ GUIDialog_GLObjChooser::GUIDialog_GLObjChooser(GUIGlChildWindow* parent, FXIcon*
new FXButton(layoutRight, "By &Name\tLocate item by name\t", nullptr, this, MID_CHOOSEN_NAME, GUIDesignChooserButtons);
new FXHorizontalSeparator(layoutRight, GUIDesignHorizontalSeparator);
new FXButton(layoutRight, "&Close\t\t", GUIIconSubSys::getIcon(GUIIcon::NO), this, MID_CANCEL, GUIDesignChooserButtons);

myParent->getParent()->addChild(this);
// add child ind viewNet
SUMOViewParent? SUMOViewParent->getParent()->addChild(this) : viewParent->getParent()->addChild(this);
// create and show dialog
create();
show();
}


GUIDialog_GLObjChooser::~GUIDialog_GLObjChooser() {
myParent->getParent()->removeChild(this);
if (mySUMOViewParent) {
//mySUMOViewParent->eraseGLObjChooser(this);
mySUMOViewParent->getParent()->removeChild(this);
}
}


GUIGlObject*
GUIDialog_GLObjChooser::getObject() const {
return static_cast<GUIGlObject*>(mySelected);
}


Expand All @@ -110,8 +124,11 @@ long
GUIDialog_GLObjChooser::onCmdCenter(FXObject*, FXSelector, void*) {
int selected = myList->getCurrentItem();
if (selected >= 0) {
myParent->getView()->stopTrack();
myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
if (mySUMOViewParent) {
mySUMOViewParent->getView()->stopTrack();
} else {
myGNEViewParent->getView()->stopTrack();
}
}
return 1;
}
Expand All @@ -121,11 +138,19 @@ long
GUIDialog_GLObjChooser::onCmdTrack(FXObject*, FXSelector, void*) {
int selected = myList->getCurrentItem();
if (selected >= 0) {
myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
if (mySUMOViewParent) {
mySUMOViewParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
} else {
myGNEViewParent->setView(*static_cast<GUIGlID*>(myList->getItemData(selected)));
}
GUIGlID id = *static_cast<GUIGlID*>(myList->getItemData(selected));
GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(id);
if (o->getType() == GLO_VEHICLE) {
myParent->getView()->startTrack(o->getGlID());
if (mySUMOViewParent) {
mySUMOViewParent->getView()->startTrack(o->getGlID());
} else {
myGNEViewParent->getView()->startTrack(o->getGlID());
}
}
GUIGlObjectStorage::gIDStorage.unblockObject(id);
}
Expand Down Expand Up @@ -178,7 +203,11 @@ long
GUIDialog_GLObjChooser::onCmdText(FXObject*, FXSelector, void*) {
int current = myList->getCurrentItem();
if (current >= 0 && myList->isItemSelected(current)) {
myParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
if (mySUMOViewParent) {
mySUMOViewParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
} else {
myGNEViewParent->setView(*static_cast<GUIGlID*>(myList->getItemData(current)));
}
}
return 1;
}
Expand Down Expand Up @@ -253,7 +282,7 @@ GUIDialog_GLObjChooser::refreshList(const std::vector<GUIGlID>& ids) {
continue;
}
const std::string& name = getObjectName(o);
bool selected = myParent->isSelected(o);
bool selected = mySUMOViewParent? mySUMOViewParent->isSelected(o) : myGNEViewParent->isSelected(o);
FXIcon* icon = selected ? GUIIconSubSys::getIcon(GUIIcon::FLAG) : nullptr;
myIDs.insert(o->getGlID());
myList->appendItem(name.c_str(), icon, (void*) & (*myIDs.find(o->getGlID())));
Expand All @@ -276,7 +305,11 @@ GUIDialog_GLObjChooser::onCmdToggleSelection(FXObject*, FXSelector, void*) {
}
}
myList->update();
myParent->getView()->update();
if (mySUMOViewParent) {
mySUMOViewParent->getView()->update();
} else {
myGNEViewParent->getView()->update();
}
return 1;
}

Expand Down
Loading

0 comments on commit c666b53

Please sign in to comment.