Eclipse SUMO - Simulation of Urban MObility
GNEFrame.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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 titel 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 frame for contents
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
110 myFrameHeaderLabel->setFocus();
111}
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 MARGING)
135 myScrollWindowsContents->setWidth(newWidth - GUIDesignFrameAreaMarging - DEFAULT_SPACING - 1);
136 // calculate new contentWidth
137 int contentWidth = (newWidth - GUIDesignFrameAreaMarging - 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*
163 return myFrameHeaderLabel;
164}
165
166
167FXFont*
169 return myFrameHeaderFont;
170}
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, ("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, "Attribute");
196 myTable->setColumnText(1, "Description");
197 myTable->setColumnText(2, "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 // set header
220 FXHeader* header = myTable->getColumnHeader();
221 header->setItemJustify(0, JUSTIFY_CENTER_X);
222 header->setItemSize(0, 120);
223 header->setItemJustify(1, JUSTIFY_CENTER_X);
224 header->setItemSize(1, sizeColumnDescription * 7);
225 header->setItemJustify(2, JUSTIFY_CENTER_X);
226 header->setItemSize(2, sizeColumnDefinitions * 6);
227 // Create horizontal separator
228 new FXHorizontalSeparator(attributesHelpDialog, GUIDesignHorizontalSeparator);
229 // Create frame for OK Button
230 FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(attributesHelpDialog, GUIDesignAuxiliarHorizontalFrame);
231 // Create Button Close (And two more horizontal frames to center it)
232 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
233 new FXButton(myHorizontalFrameOKButton, TL("OK\t\tclose"), GUIIconSubSys::getIcon(GUIIcon::ACCEPT), attributesHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
234 new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
235 // Write Warning in console if we're in testing mode
236 WRITE_DEBUG("Opening HelpAttributes dialog for tag '" + AC->getTagProperty().getTagStr() + "' showing " + toString(AC->getTagProperty().getNumberOfAttributes()) + " attributes");
237 // create Dialog
238 attributesHelpDialog->create();
239 // show in the given position
240 attributesHelpDialog->show(PLACEMENT_CURSOR);
241 // refresh APP
242 getApp()->refresh();
243 // open as modal dialog (will block all windows until stop() or stopModal() is called)
244 getApp()->runModalFor(attributesHelpDialog);
245 // Write Warning in console if we're in testing mode
246 WRITE_DEBUG("Closing HelpAttributes dialog for tag '" + AC->getTagProperty().getTagStr() + "'");
247}
248
249
250void
252 // this function has to be reimplemente in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
253}
254
255
256void
258 // this function can be reimplemente in all child frames
259}
260
261// ---------------------------------------------------------------------------
262// GNEFrame - protected methods
263// ---------------------------------------------------------------------------
264
265void
267 // this function has to be reimplemente in all child frames that uses a GNETagSelector modul
268}
269
270
271void
273 // this function has to be reimplemente in all child frames that uses a DemandElementSelector
274}
275
276
277bool
279 // this function has to be reimplemente in all child frames that needs to draw a polygon (for example, GNEFrame or GNETAZFrame)
280 return false;
281}
282
283
284void
286 // this function has to be reimplemente in all child frames that uses a GNETagSelector modul
287}
288
289
290void
292 // this function has to be reimplemente in all child frames that uses a GNEAttributesCreator editor with extended attributes
293}
294
295
296void
298 // this function has to be reimplemente in all child frames that uses a GNEOverlappedInspection
299}
300
301
302bool
303GNEFrame::createPath(const bool /*useLastRoute*/) {
304 // this function has to be reimplemente in all child frames that uses a path or consecutiveLanePath
305 return false;
306}
307
308
309const std::vector<std::string>&
311 return myPredefinedTagsMML;
312}
313
314
315FXLabel*
316GNEFrame::buildRainbow(FXComposite* parent) {
317 // create label for color information
318 FXLabel* label = new FXLabel(parent, "Scale: Min -> Max", nullptr, GUIDesignLabelCenterThick);
319 // create frame for color scale
320 FXHorizontalFrame* horizontalFrameColors = new FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame);
321 for (const auto& color : GNEViewNetHelper::getRainbowScaledColors()) {
322 FXLabel* colorLabel = new FXLabel(horizontalFrameColors, "", nullptr, GUIDesignLabelLeft);
323 colorLabel->setBackColor(MFXUtils::getFXColor(color));
324 }
325 return label;
326 // for whatever reason, sonar complains in the next line that horizontalFrameColors may leak, but fox does the cleanup
327} // NOSONAR
328
329/****************************************************************************/
@ MID_TABLE
The Table.
Definition: GUIAppEnum.h:530
#define GUIDesignTableNotEditable
design for table extended over frame that cannot be edited
Definition: GUIDesigns.h:610
#define GUIDesignLabelLeft
Definition: GUIDesigns.h:217
#define GUIDesignDialogBoxResizable
design for standard dialog box (for example, about dialog)
Definition: GUIDesigns.h:593
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignFrameAreaMarging
rigth marging for frame area
Definition: GUIDesigns.h:43
#define GUIDesignButtonOK
Definition: GUIDesigns.h:142
#define GUIDesignLabelCenterThick
label extended over frame with thick and with text justify to center
Definition: GUIDesigns.h:235
#define GUIDesignContentsGNEFrame
design for the GNEFrame
Definition: GUIDesigns.h:391
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:452
#define GUIDesignContentsScrollWindow
design for the content scroll of every frame
Definition: GUIDesigns.h:379
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions
Definition: GUIDesigns.h:394
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:271
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:282
@ SUMO_ATTR_NOTHING
invalid attribute
T MAX2(T a, T b)
Definition: StdDefs.h:77
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
virtual void attributeUpdated()
function called after set a valid attribute in AttributeCreator/AttributeEditor/ParametersEditor/....
Definition: GNEFrame.cpp:285
int getScrollBarWidth() const
get scrollBar width (zero if is hidden)
Definition: GNEFrame.cpp:174
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:251
virtual void attributesEditorExtendedDialogOpened()
open GNEAttributesCreator extended dialog
Definition: GNEFrame.cpp:291
static FXLabel * buildRainbow(FXComposite *parent)
build rainbow in frame modul
Definition: GNEFrame.cpp:316
virtual void tagSelected()
Tag selected in GNETagSelector.
Definition: GNEFrame.cpp:266
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:272
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:297
virtual void frameWidthUpdated()
function called after setting new width in current frame (can be reimplemented in frame children)
Definition: GNEFrame.cpp:257
virtual bool shapeDrawed()
build a shaped element using the drawed shape
Definition: GNEFrame.cpp:278
virtual bool createPath(const bool useLastRoute)
create path between two elements
Definition: GNEFrame.cpp:303
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:310
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.
Definition: GNEViewParent.h:84
void hideFramesArea()
hide frames area if all GNEFrames are hidden
void showFramesArea()
show frames area if at least a GNEFrame is showed
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 StringBijection< int >::Entry attrs[]
The names of SUMO-XML attributes (for passing to GenericSAXHandler)
static const std::vector< RGBColor > & getRainbowScaledColors()
get scaled rainbow colors