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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A logging window for the gui
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <cassert>
38 #include <fxkeys.h>
39 #include "GUIMessageWindow.h"
40 
41 
42 // ===========================================================================
43 // static members
44 // ===========================================================================
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 GUIMessageWindow::GUIMessageWindow(FXComposite* parent) :
52  FXText(parent, 0, 0, 0, 0, 0, 0, 50),
53  myStyles(new FXHiliteStyle[7]),
54  myErrorRetriever(0),
55  myMessageRetriever(0),
56  myWarningRetriever(0) {
57  setStyled(true);
58  setEditable(false);
59  const FXColor white = FXRGB(0xff, 0xff, 0xff);
60  const FXColor blue = FXRGB(0x00, 0x00, 0x88);
61  const FXColor green = FXRGB(0x00, 0x88, 0x00);
62  const FXColor red = FXRGB(0x88, 0x00, 0x00);
63  const FXColor yellow = FXRGB(0xe6, 0x98, 0x00);
64  // set separator style
65  myStyles[0].normalForeColor = blue;
66  myStyles[0].normalBackColor = white;
67  myStyles[0].selectForeColor = white;
68  myStyles[0].selectBackColor = blue;
69  myStyles[0].hiliteForeColor = blue;
70  myStyles[0].hiliteBackColor = white;
71  myStyles[0].activeBackColor = white;
72  myStyles[0].style = 0;
73  // set message text style
74  myStyles[1] = myStyles[0];
75  myStyles[1].normalForeColor = green;
76  myStyles[1].selectBackColor = green;
77  myStyles[1].hiliteForeColor = green;
78  myStyles[4] = myStyles[1];
79  myStyles[4].style = STYLE_UNDERLINE;
80  // set error text style
81  myStyles[2] = myStyles[0];
82  myStyles[2].normalForeColor = red;
83  myStyles[2].selectBackColor = red;
84  myStyles[2].hiliteForeColor = red;
85  myStyles[5] = myStyles[2];
86  myStyles[5].style = STYLE_UNDERLINE;
87  // set warning text style
88  myStyles[3] = myStyles[0];
89  myStyles[3].normalForeColor = yellow;
90  myStyles[3].selectBackColor = yellow;
91  myStyles[3].hiliteForeColor = yellow;
92  myStyles[6] = myStyles[3];
93  myStyles[6].style = STYLE_UNDERLINE;
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") {
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 0;
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 = dynamic_cast<GUIGlChildWindow*>(main->getViewByID(viewIDs[0]));
144  const FXString text = getText();
145  const GUIGlObject* const glObj = getActiveStringObject(text, pos, lineStart(pos), lineEnd(pos));
146  if (glObj != 0) {
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) {
165  case EVENT_ERROR_OCCURED:
166  // color: red
167  style = 2;
168  break;
170  // color: yellow
171  style = 3;
172  break;
174  // color: green
175  style = 1;
176  break;
177  default:
178  assert(false);
179  }
180  FXString text(msg.c_str());
181  if (myLocateLinks) {
182  FXint pos = text.find("'");
183  while (pos >= 0) {
184  const GUIGlObject* const glObj = getActiveStringObject(text, pos + 1, 0, text.length());
185  if (glObj != 0) {
187  FXString insText = text.left(pos + 1);
188  FXText::appendStyledText(insText, style + 1);
189  text.erase(0, pos + 1);
190  pos = text.find("'");
191  insText = text.left(pos);
192  FXText::appendStyledText(insText, style + 4);
193  text.erase(0, pos);
194  }
195  pos = text.find("'", pos + 1);
196  }
197  }
198  // insert rest of the message
199  FXText::appendStyledText(text, style + 1, true);
200  FXText::setCursorPos(getLength() - 1);
201  FXText::setBottomLine(getLength() - 1);
202  if (isEnabled()) {
203  layout();
204  update();
205  }
206 }
207 
208 
209 void
211  std::string msg = "----------------------------------------------------------------------------------------\n";
212  FXText::appendStyledText(msg.c_str(), (FXint) msg.length(), 1, true);
213  FXText::setCursorPos(getLength() - 1);
214  FXText::setBottomLine(getLength() - 1);
215  if (isEnabled()) {
216  layout();
217  update();
218  }
219 }
220 
221 
222 void
224  if (getLength() == 0) {
225  return;
226  }
227  FXText::removeText(0, getLength() - 1, true);
228  if (isEnabled()) {
229  layout();
230  update();
231  }
232 }
233 
234 
235 void
237  if (myMessageRetriever == 0) {
238  // initialize only if registration is requested
242  }
246 }
247 
248 
249 void
254 }
255 
256 
257 /****************************************************************************/
258 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:66
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
void appendMsg(GUIEventType eType, const std::string &msg)
Adds new text to the window.
send when a message occured
Definition: GUIEvent.h:49
void toggleSelection(GUIGlID id)
Toggles selection of an object.
void registerMsgHandlers()
register and unregister message handlers
T MAX2(T a, T b)
Definition: StdDefs.h:73
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:156
~GUIMessageWindow()
Destructor.
std::vector< std::string > getViewIDs() const
void addSeparator()
Adds a a separator to this log window.
FXHiliteStyle * myStyles
The text colors used.
virtual void setCursorPos(FXint pos, FXbool notify=FALSE)
static GUIMainWindow * getInstance()
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:170
GUIMessageWindow(FXComposite *parent)
Constructor.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:57
send when a error occured
Definition: GUIEvent.h:55
GUIEventType
Definition: GUIEvent.h:41
OutputDevice * myMessageRetriever
void setView(GUIGlID id)
Centers the view onto the given artifact.
FXMDIChild * getViewByID(const std::string &id) const
static bool myLocateLinks
whether messages are linked to the GUI elements
send when a warning occured
Definition: GUIEvent.h:52
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
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[])