Eclipse SUMO - Simulation of Urban MObility
GUIMessageWindow.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // A logging window for the gui
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <cassert>
32 #include <fxkeys.h>
33 #include "GUIMessageWindow.h"
34 
35 
36 // ===========================================================================
37 // static members
38 // ===========================================================================
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 GUIMessageWindow::GUIMessageWindow(FXComposite* parent) :
46  FXText(parent, nullptr, 0, 0, 0, 0, 0, 50),
47  myStyles(new FXHiliteStyle[8]),
48  myErrorRetriever(nullptr),
49  myMessageRetriever(nullptr),
50  myWarningRetriever(nullptr) {
51  setStyled(true);
52  setEditable(false);
53  const FXColor white = FXRGB(0xff, 0xff, 0xff);
54  const FXColor blue = FXRGB(0x00, 0x00, 0x88);
55  const FXColor green = FXRGB(0x00, 0x88, 0x00);
56  const FXColor red = FXRGB(0x88, 0x00, 0x00);
57  const FXColor yellow = FXRGB(0xe6, 0x98, 0x00);
58  const FXColor fuchsia = FXRGB(0x88, 0x00, 0x88);
59  // set separator style
60  myStyles[0].normalForeColor = blue;
61  myStyles[0].normalBackColor = white;
62  myStyles[0].selectForeColor = white;
63  myStyles[0].selectBackColor = blue;
64  myStyles[0].hiliteForeColor = blue;
65  myStyles[0].hiliteBackColor = white;
66  myStyles[0].activeBackColor = white;
67  myStyles[0].style = 0;
68  // set message text style
69  myStyles[1] = myStyles[0];
70  myStyles[1].normalForeColor = green;
71  myStyles[1].selectBackColor = green;
72  myStyles[1].hiliteForeColor = green;
73  myStyles[4] = myStyles[1];
74  myStyles[4].style = STYLE_UNDERLINE;
75  // set error text style
76  myStyles[2] = myStyles[0];
77  myStyles[2].normalForeColor = red;
78  myStyles[2].selectBackColor = red;
79  myStyles[2].hiliteForeColor = red;
80  myStyles[5] = myStyles[2];
81  myStyles[5].style = STYLE_UNDERLINE;
82  // set warning text style
83  myStyles[3] = myStyles[0];
84  myStyles[3].normalForeColor = yellow;
85  myStyles[3].selectBackColor = yellow;
86  myStyles[3].hiliteForeColor = yellow;
87  myStyles[6] = myStyles[3];
88  myStyles[6].style = STYLE_UNDERLINE;
89  // set GLDebug text style
90  myStyles[7] = myStyles[0];
91  myStyles[7].normalForeColor = fuchsia;
92  myStyles[7].selectBackColor = fuchsia;
93  myStyles[7].hiliteForeColor = fuchsia;
94  //
95  setHiliteStyles(myStyles);
96 }
97 
98 
100  delete[] myStyles;
101  delete myMessageRetriever;
102  delete myErrorRetriever;
103  delete myWarningRetriever;
104 }
105 
106 
107 const GUIGlObject*
108 GUIMessageWindow::getActiveStringObject(const FXString& text, const FXint pos, const FXint lineS, const FXint lineE) const {
109  const FXint idS = MAX2(text.rfind(" '", pos), text.rfind("='", pos));
110  const FXint idE = text.find("'", pos);
111  if (idS >= 0 && idE >= 0 && idS >= lineS && idE <= lineE) {
112  const FXint typeS = text.rfind(" ", idS - 1);
113  if (typeS >= 0) {
114  std::string type(text.mid(typeS + 1, idS - typeS - 1).lower().text());
115  if (type == "tllogic") {
116  type = "tlLogic"; // see GUIGlObject.cpp
117  } else if (type == "busstop" || type == "trainstop") {
118  type = "busStop";
119  } else if (type == "containerstop") {
120  type = "containerStop";
121  } else if (type == "chargingstation") {
122  type = "chargingStation";
123  } else if (type == "parkingarea") {
124  type = "parkingArea";
125  }
126  const std::string id(text.mid(idS + 2, idE - idS - 2).text());
127  return GUIGlObjectStorage::gIDStorage.getObjectBlocking(type + ":" + id);
128  }
129  }
130  return nullptr;
131 }
132 
133 
134 void
135 GUIMessageWindow::setCursorPos(FXint pos, FXbool notify) {
136  FXText::setCursorPos(pos, notify);
137  if (myLocateLinks) {
139  std::vector<std::string> viewIDs = main->getViewIDs();
140  if (viewIDs.empty()) {
141  return;
142  }
143  GUIGlChildWindow* const child = main->getViewByID(viewIDs[0]);
144  const FXString text = getText();
145  const GUIGlObject* const glObj = getActiveStringObject(text, pos, lineStart(pos), lineEnd(pos));
146  if (glObj != nullptr) {
147  child->setView(glObj->getGlID());
149  if (getApp()->getKeyState(KEY_Control_L)) {
151  }
152  }
153  }
154 }
155 
156 
157 void
158 GUIMessageWindow::appendMsg(GUIEventType eType, const std::string& msg) {
159  if (!isEnabled()) {
160  show();
161  }
162  // build the styled message
163  FXint style = 1;
164  switch (eType) {
166  // color: blue
167  style = 0;
168  break;
170  // color: fuchsia
171  style = 7;
172  break;
174  // color: red
175  style = 2;
176  break;
178  // color: yellow
179  style = 3;
180  break;
182  // color: green
183  style = 1;
184  break;
185  default:
186  assert(false);
187  }
188  FXString text(msg.c_str());
189  if (myLocateLinks) {
190  FXint pos = text.find("'");
191  while (pos >= 0) {
192  const GUIGlObject* const glObj = getActiveStringObject(text, pos + 1, 0, text.length());
193  if (glObj != nullptr) {
195  FXString insText = text.left(pos + 1);
196  FXText::appendStyledText(insText, style + 1);
197  text.erase(0, pos + 1);
198  pos = text.find("'");
199  insText = text.left(pos);
200  FXText::appendStyledText(insText, style + 4);
201  text.erase(0, pos);
202  }
203  pos = text.find("'", pos + 1);
204  }
205  }
206  // insert rest of the message
207  FXText::appendStyledText(text, style + 1, true);
208  FXText::setCursorPos(getLength() - 1);
209  FXText::setBottomLine(getLength() - 1);
210  if (isEnabled()) {
211  layout();
212  update();
213  }
214 }
215 
216 
217 void
219  std::string msg = "----------------------------------------------------------------------------------------\n";
220  FXText::appendStyledText(msg.c_str(), (FXint) msg.length(), 1, true);
221  FXText::setCursorPos(getLength() - 1);
222  FXText::setBottomLine(getLength() - 1);
223  if (isEnabled()) {
224  layout();
225  update();
226  }
227 }
228 
229 
230 void
232  if (getLength() == 0) {
233  return;
234  }
235  FXText::removeText(0, getLength() - 1, true);
236  if (isEnabled()) {
237  layout();
238  update();
239  }
240 }
241 
242 
243 void
245  if (myMessageRetriever == nullptr) {
246  // initialize only if registration is requested
252  }
258 }
259 
260 
261 void
268 }
269 
270 
271 /****************************************************************************/
272 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:72
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
send when a warning occured
Definition: GUIEvent.h:46
void appendMsg(GUIEventType eType, const std::string &msg)
Adds new text to the window.
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
Definition: MsgHandler.cpp:99
OutputDevice * myGLDebugRetriever
void toggleSelection(GUIGlID id)
Toggles selection of an object.
void registerMsgHandlers()
register message handlers
send when a debug occured
Definition: GUIEvent.h:52
T MAX2(T a, T b)
Definition: StdDefs.h:80
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:166
void unregisterMsgHandlers()
unregister message handlers
~GUIMessageWindow()
Destructor.
std::vector< std::string > getViewIDs() const
void addSeparator()
Adds a a separator to this log window.
OutputDevice * myDebugRetriever
FXHiliteStyle * myStyles
The text colors used.
virtual void setCursorPos(FXint pos, FXbool notify=FALSE)
set cursor position over a certain line
static GUIMainWindow * getInstance()
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
Definition: MsgHandler.cpp:90
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:174
GUIMessageWindow(FXComposite *parent)
Constructor.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:59
GUIEventType
Definition: GUIEvent.h:35
OutputDevice * myMessageRetriever
void setView(GUIGlID id)
Centers the view onto the given artifact.
send when a gldebug occured
Definition: GUIEvent.h:55
send when a message occured
Definition: GUIEvent.h:43
static bool myLocateLinks
whether messages are linked to the GUI elements
send when a error occured
Definition: GUIEvent.h:49
GUIGlID getGlID() const
Returns the numerical id of the object.
const GUIGlObject * getActiveStringObject(const FXString &text, const FXint pos, const FXint lineS, const FXint lineE) const
get active string object
GUIGlChildWindow * getViewByID(const std::string &id) const
void unblockObject(GUIGlID id)
Marks an object as unblocked.
void clear()
Clears the window.
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations.
GUISelectedStorage gSelected
A global holder of selected objects.
OutputDevice * myWarningRetriever
int main(int argc, char *argv[])