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