Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNEFrame.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// The Widget for add additional elements
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNEViewNet.h>
27
28#include "GNEFrame.h"
29
30
31#define PADDINGFRAME 10 // (5+5)
32#define VERTICALSCROLLBARWIDTH 15
33
34// ===========================================================================
35// static members
36// ===========================================================================
37
38FXFont* GNEFrame::myFrameHeaderFont = nullptr;
39
40// ===========================================================================
41// method definitions
42// ===========================================================================
43
44GNEFrame::GNEFrame(GNEViewParent* viewParent, GNEViewNet* viewNet, const std::string& frameLabel) :
45 FXVerticalFrame(viewParent->getFramesArea(), GUIDesignAuxiliarFrame),
46 myViewNet(viewNet) {
47
48 // fill myPredefinedTagsMML (to avoid repeating this fill during every element creation)
49 int i = 0;
51 int key = SUMOXMLDefinitions::attrs[i].key;
52 assert(key >= 0);
53 while (key >= (int)myPredefinedTagsMML.size()) {
54 myPredefinedTagsMML.push_back("");
55 }
57 i++;
58 }
59
60 // Create font only one time
61 if (myFrameHeaderFont == nullptr) {
62 myFrameHeaderFont = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
63 }
64
65 // Create frame for header
66 myHeaderFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
67
68 // Create frame for left elements of header (By default unused)
70 myHeaderLeftFrame->hide();
71
72 // Create title frame
73 myFrameHeaderLabel = new FXLabel(myHeaderFrame, frameLabel.c_str(), nullptr, GUIDesignLabelFrameInformation);
74
75 // Create frame for right elements of header (By default unused)
77 myHeaderRightFrame->hide();
78
79 // Add separator
80 new FXHorizontalSeparator(this, GUIDesignHorizontalSeparator);
81
82 // Create scroll windows with fixed width for contents
83 myScrollWindowsContents = new FXScrollWindow(this, GUIDesignScrollWindowFixed);
84
85 // Create frame for contents (in which GroupBox will be placed)
87
88 // Set font of header
90
91 // set initial width (will be changed in the first update
92 setWidth(10);
93
94 // Hide Frame
95 FXVerticalFrame::hide();
96}
97
98
100 // delete frame header only one time
101 if (myFrameHeaderFont) {
102 delete myFrameHeaderFont;
103 myFrameHeaderFont = nullptr;
104 }
105}
106
107
108void
112
113
114void
116 // show scroll window
117 FXVerticalFrame::show();
118 // Show and update Frame Area in which this GNEFrame is placed
120}
121
122
123void
125 // hide scroll window
126 FXVerticalFrame::hide();
127 // Hide Frame Area in which this GNEFrame is placed
129}
130
131
132void
133GNEFrame::setFrameWidth(const int newWidth) {
134 // set scroll windows size (minus MARGIN)
135 myScrollWindowsContents->setWidth(newWidth - GUIDesignFrameAreaMargin - DEFAULT_SPACING - 1);
136 // calculate new contentWidth
137 int contentWidth = (newWidth - GUIDesignFrameAreaMargin - DEFAULT_SPACING - 1 - 15);
138 // adjust contents frame
139 myContentFrame->setWidth(contentWidth);
140 // set size of all contents frame children
141 for (auto child = myContentFrame->getFirst(); child != nullptr; child = child->getNext()) {
142 child->setWidth(contentWidth);
143 }
144 // call frame width updated
146}
147
148
151 return myViewNet;
152}
153
154
155FXVerticalFrame*
157 return myContentFrame;
158}
159
160
161FXLabel*
165
166
167FXFont*
171
172
173int
175 if (myScrollWindowsContents->verticalScrollBar()->shown()) {
176 return myScrollWindowsContents->verticalScrollBar()->getWidth();
177 } else {
178 return 0;
179 }
180}
181
182
183void
185 FXDialogBox* attributesHelpDialog = new FXDialogBox(myScrollWindowsContents, (TL("Parameters of ") + AC->getTagStr()).c_str(), GUIDesignDialogBoxResizable, 0, 0, 0, 0, 10, 10, 10, 38, 4, 4);
186 // Create FXTable
187 FXTable* myTable = new FXTable(attributesHelpDialog, attributesHelpDialog, MID_TABLE, GUIDesignTableNotEditable);
188 attributesHelpDialog->setIcon(GUIIconSubSys::getIcon(GUIIcon::MODEINSPECT));
189 int sizeColumnDescription = 0;
190 int sizeColumnDefinitions = 0;
191 myTable->setVisibleRows((FXint)(AC->getTagProperty().getNumberOfAttributes()));
192 myTable->setVisibleColumns(3);
193 myTable->setTableSize((FXint)(AC->getTagProperty().getNumberOfAttributes()), 3);
194 myTable->setBackColor(FXRGB(255, 255, 255));
195 myTable->setColumnText(0, TL("Attribute"));
196 myTable->setColumnText(1, TL("Description"));
197 myTable->setColumnText(2, TL("Definition"));
198 myTable->getRowHeader()->setWidth(0);
199 // Iterate over vector of additional parameters
200 int itemIndex = 0;
201 for (const auto& tagProperty : AC->getTagProperty()) {
202 // Set attribute
203 FXTableItem* attribute = new FXTableItem(tagProperty.getAttrStr().c_str());
204 attribute->setJustify(FXTableItem::CENTER_X);
205 myTable->setItem(itemIndex, 0, attribute);
206 // Set description of element
207 FXTableItem* type = new FXTableItem("");
208 type->setText(tagProperty.getDescription().c_str());
209 sizeColumnDescription = MAX2(sizeColumnDescription, (int)tagProperty.getDescription().size());
210 type->setJustify(FXTableItem::CENTER_X);
211 myTable->setItem(itemIndex, 1, type);
212 // Set definition
213 FXTableItem* definition = new FXTableItem(tagProperty.getDefinition().c_str());
214 definition->setJustify(FXTableItem::LEFT);
215 myTable->setItem(itemIndex, 2, definition);
216 sizeColumnDefinitions = MAX2(sizeColumnDefinitions, (int)tagProperty.getDefinition().size());
217 itemIndex++;
218 }
219 myTable->fitRowsToContents(0, itemIndex);
220 // set header
221 FXHeader* header = myTable->getColumnHeader();
222 header->setItemJustify(0, JUSTIFY_CENTER_X);
223 header->setItemSize(0, 120);
224 header->setItemJustify(1, JUSTIFY_CENTER_X);
225 header->setItemSize(1, sizeColumnDescription * 7);
226 header->setItemJustify(2, JUSTIFY_CENTER_X);
227 header->setItemSize(2, sizeColumnDefinitions * 6);
228 // Create horizontal separator
229 new FXHorizontalSeparator(attributesHelpDialog, GUIDesignHorizontalSeparator);
230 // Create frame for OK Button
231 FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(attributesHelpDialog, GUIDesignAuxiliarHorizontalFrame);
232 // Create Button Close (And two more horizontal frames to center it)
233 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
234 GUIDesigns::buildFXButton(myHorizontalFrameOKButton, TL("OK"), "", TL("close"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), attributesHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
235 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
236 // Write Warning in console if we're in testing mode
237 WRITE_DEBUG(TLF("Opening HelpAttributes dialog for tag '%' showing % attributes", AC->getTagProperty().getTagStr(), toString(AC->getTagProperty().getNumberOfAttributes())));
238 // create Dialog
239 attributesHelpDialog->create();
240 // show in the given position
241 attributesHelpDialog->show(PLACEMENT_CURSOR);
242 // refresh APP
243 getApp()->refresh();
244 // open as modal dialog (will block all windows until stop() or stopModal() is called)
245 getApp()->runModalFor(attributesHelpDialog);
246 // Write Warning in console if we're in testing mode
247 WRITE_DEBUG(TL("Closing HelpAttributes dialog for tag '") + AC->getTagProperty().getTagStr() + "'");
248}
249
250
251void
253 // this function has to be reimplemented in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
254}
255
256
257void
259 // this function can be reimplemented in all child frames
260}
261
262// ---------------------------------------------------------------------------
263// GNEFrame - protected methods
264// ---------------------------------------------------------------------------
265
266void
268 // this function has to be reimplemented in all child frames that uses a GNETagSelector module
269}
270
271
272void
274 // this function has to be reimplemented in all child frames that uses a DemandElementSelector
275}
276
277
278bool
280 // this function has to be reimplemented in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
281 return false;
282}
283
284
285void
287 // this function has to be reimplemented in all child frames that uses a AttributeEditor module
288}
289
290
291void
293 // this function has to be reimplemented in all child frames that uses a GNEAttributesCreator editor with extended attributes
294}
295
296
297void
299 // this function has to be reimplemented in all child frames that uses a GNEOverlappedInspection
300}
301
302
303bool
304GNEFrame::createPath(const bool /*useLastRoute*/) {
305 // this function has to be reimplemented in all child frames that uses a path or consecutiveLanePath
306 return false;
307}
308
309
310const std::vector<std::string>&
314
315
316FXLabel*
317GNEFrame::buildRainbow(FXComposite* parent) {
318 // create label for color information
319 FXLabel* label = new FXLabel(parent, TL("Scale: Min -> Max"), nullptr, GUIDesignLabelThick(JUSTIFY_NORMAL));
320 // create frame for color scale
321 FXHorizontalFrame* horizontalFrameColors = new FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame);
322 for (const auto& color : GNEViewNetHelper::getRainbowScaledColors()) {
323 FXLabel* colorLabel = new FXLabel(horizontalFrameColors, "", nullptr, GUIDesignLabel(JUSTIFY_LEFT));
324 colorLabel->setBackColor(MFXUtils::getFXColor(color));
325 }
326 return label;
327 // for whatever reason, sonar complains in the next line that horizontalFrameColors may leak, but fox does the cleanup
328} // NOSONAR
329
330/****************************************************************************/
@ MID_TABLE
The Table.
Definition GUIAppEnum.h:539
#define GUIDesignTableNotEditable
design for table extended over frame that cannot be edited
Definition GUIDesigns.h:631
#define GUIDesignDialogBoxResizable
design for standard dialog box (for example, about dialog)
Definition GUIDesigns.h:611
#define GUIDesignFrameAreaMargin
right margin for frame area
Definition GUIDesigns.h:41
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignLabel(justify)
Definition GUIDesigns.h:249
#define GUIDesignAuxiliarFrameFixedWidth(width)
design for auxiliar (Without borders) frame with fixed width and extended height
Definition GUIDesigns.h:402
#define GUIDesignButtonOK
Definition GUIDesigns.h:159
#define GUIDesignScrollWindowFixed
design for scroll windows extended over Y and fix width
Definition GUIDesigns.h:384
#define GUIDesignLabelThick(justify)
label extended over frame with thick and with text justify to left
Definition GUIDesigns.h:255
#define GUIDesignHorizontalSeparator
Definition GUIDesigns.h:466
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:396
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_NOTHING
invalid attribute, must be the last one
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
FXHorizontalFrame * myHeaderRightFrame
fame for right header elements
Definition GNEFrame.h:129
int getScrollBarWidth() const
get scrollBar width (zero if is hidden)
Definition GNEFrame.cpp:174
virtual void attributeUpdated(SumoXMLAttr attribute)
function called after set a valid attribute in AttributeCreator/AttributeEditor/ParametersEditor/....
Definition GNEFrame.cpp:286
void setFrameWidth(const int newWidth)
set width of GNEFrame
Definition GNEFrame.cpp:133
void focusUpperElement()
focus upper element of frame
Definition GNEFrame.cpp:109
virtual void updateFrameAfterUndoRedo()
function called after undo/redo in the current frame (can be reimplemented in frame children)
Definition GNEFrame.cpp:252
virtual void attributesEditorExtendedDialogOpened()
open GNEAttributesCreator extended dialog
Definition GNEFrame.cpp:292
static FXLabel * buildRainbow(FXComposite *parent)
build rainbow in frame modul
Definition GNEFrame.cpp:317
virtual void tagSelected()
Tag selected in GNETagSelector.
Definition GNEFrame.cpp:267
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
FXLabel * getFrameHeaderLabel() const
get the label for the frame's header
Definition GNEFrame.cpp:162
FXScrollWindow * myScrollWindowsContents
scroll windows that holds the content frame
Definition GNEFrame.h:139
virtual void demandElementSelected()
selected demand element in DemandElementSelector
Definition GNEFrame.cpp:273
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:117
FXFont * getFrameHeaderFont() const
get font of the header's frame
Definition GNEFrame.cpp:168
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition GNEFrame.h:120
FXHorizontalFrame * myHeaderFrame
fame for header elements
Definition GNEFrame.h:123
~GNEFrame()
destructor
Definition GNEFrame.cpp:99
virtual void show()
show Frame
Definition GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition GNEFrame.cpp:124
GNEFrame(GNEViewParent *viewParent, GNEViewNet *viewNet, const std::string &frameLabel)
Constructor.
Definition GNEFrame.cpp:44
virtual void selectedOverlappedElement(GNEAttributeCarrier *AC)
open GNEAttributesCreator extended dialog
Definition GNEFrame.cpp:298
virtual void frameWidthUpdated()
function called after setting new width in current frame (can be reimplemented in frame children)
Definition GNEFrame.cpp:258
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition GNEFrame.cpp:279
virtual bool createPath(const bool useLastRoute)
create path between two elements
Definition GNEFrame.cpp:304
void openHelpAttributesDialog(const GNEAttributeCarrier *AC) const
Open help attributes dialog.
Definition GNEFrame.cpp:184
std::vector< std::string > myPredefinedTagsMML
Map of attribute ids to their (readable) string-representation (needed for SUMOSAXAttributesImpl_Cach...
Definition GNEFrame.h:148
FXLabel * myFrameHeaderLabel
the label for the frame's header
Definition GNEFrame.h:145
static FXFont * myFrameHeaderFont
static Font for the Header (it's common for all headers, then create only one time)
Definition GNEFrame.h:142
const std::vector< std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition GNEFrame.cpp:311
FXVerticalFrame * getContentFrame() const
get vertical frame that holds all widgets of frame
Definition GNEFrame.cpp:156
FXHorizontalFrame * myHeaderLeftFrame
fame for left header elements
Definition GNEFrame.h:126
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
int getNumberOfAttributes() const
get number of attributes
GNEViewParent * getViewParent() const
get the net object
A single child window which contains a view of the simulation area.
void hideFramesArea()
hide frames area if all GNEFrames are hidden
void showFramesArea()
show frames area if at least a GNEFrame is showed
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition MFXUtils.cpp:112
static SequentialStringBijection::Entry attrs[]
The names of SUMO-XML attributes (for passing to GenericSAXHandler)
static const std::vector< RGBColor > & getRainbowScaledColors()
get scaled rainbow colors
int key
const char * str