77FXDEFMAP(GUIOSGView) GUIOSGView_Map[] = {
79 FXMAPFUNC(SEL_CHORE,
MID_CHORE, GUIOSGView::onIdle),
85operator<<(std::ostream& os,
const osg::Vec3d& v) {
86 return os << v.x() <<
"," << v.y() <<
"," << v.z();
93GUIOSGView::Command_TLSChange::Command_TLSChange(
const MSLink*
const link, osg::Switch* switchNode)
99GUIOSGView::Command_TLSChange::~Command_TLSChange() {}
103GUIOSGView::Command_TLSChange::execute() {
104 switch (myLink->getState()) {
107 mySwitch->setSingleChildOn(0);
111 mySwitch->setSingleChildOn(1);
115 mySwitch->setSingleChildOn(2);
118 mySwitch->setSingleChildOn(3);
122 mySwitch->setSingleChildOn(3);
125 mySwitch->setAllChildrenOff();
127 myLastState = myLink->getState();
134GUIOSGView::GUIOSGView(
138 GUINet& net, FXGLVisual* glVis,
141 myTracked(0), myCameraManipulator(new GUIOSGManipulator(this)), myLastUpdate(-1),
142 myOSGNormalizedCursorX(0.), myOSGNormalizedCursorY(0.) {
143 if (myChanger !=
nullptr) {
148 myAdapter =
new FXOSGAdapter(
this,
new FXCursor(parent->getApp(), CURSOR_CROSS));
149 myViewer =
new osgViewer::Viewer();
151 const char* sumoPath = getenv(
"SUMO_HOME");
153 std::string newPath = std::string(sumoPath) +
"/data/3D";
155 osgDB::FilePathList path = osgDB::Registry::instance()->getDataFilePathList();
156 path.push_back(newPath);
157 osgDB::Registry::instance()->setDataFilePathList(path);
161 myGreenLight = osgDB::readNodeFile(
"tlg.obj");
162 myYellowLight = osgDB::readNodeFile(
"tly.obj");
163 myRedLight = osgDB::readNodeFile(
"tlr.obj");
164 myRedYellowLight = osgDB::readNodeFile(
"tlu.obj");
165 myPoleBase = osgDB::readNodeFile(
"poleBase.obj");
166 if (myGreenLight == 0 || myYellowLight == 0 || myRedLight == 0 || myRedYellowLight == 0 || myPoleBase == 0) {
170 double left, right, bottom, top, zNear, zFar;
171 myViewer->getCamera()->getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar);
172 myRoot = GUIOSGBuilder::buildOSGScene(myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase);
173 myPlane =
new osg::MatrixTransform();
174 myPlane->setCullCallback(
new ExcludeFromNearFarComputationCallback());
175 myPlane->addChild(GUIOSGBuilder::buildPlane((
float)(zFar - zNear)));
176 myPlane->addUpdateCallback(
new PlaneMoverCallback(myViewer->getCamera()));
177 myRoot->addChild(myPlane);
179 osgViewer::StatsHandler* statsHandler =
new osgViewer::StatsHandler();
180 statsHandler->setKeyEventTogglesOnScreenStats(osgGA::GUIEventAdapter::KEY_I);
181 myViewer->addEventHandler(statsHandler);
182 myViewer->setSceneData(myRoot);
183 myViewer->setCameraManipulator(myCameraManipulator);
185 myViewer->setKeyEventSetsDone(0);
186 myViewer->getCamera()->setGraphicsContext(myAdapter);
187 myViewer->getCamera()->setViewport(0, 0, w, h);
188 myViewer->getCamera()->setNearFarRatio(0.005);
189 myViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
190 myViewer->addEventHandler(
new PickHandler(
this));
191 osg::Vec3d lookFrom, lookAt, up;
192 myCameraManipulator->getHomePosition(lookFrom, lookAt, up);
193 lookFrom = lookAt + osg::Z_AXIS;
195 myCameraManipulator->setHomePosition(lookFrom, lookAt, up);
200 myTextNode =
new osg::Geode();
201 myText =
new osgText::Text;
202 myText->setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
203 myText->setShaderTechnique(osgText::NO_TEXT_SHADER);
204 osgText::Font* font = osgText::readFontFile(
"arial.ttf");
205 if (font !=
nullptr) {
206 myText->setFont(font);
208 myText->setCharacterSize(16.f);
209 myTextNode->addDrawable(myText);
210 myText->setAlignment(osgText::TextBase::AlignmentType::LEFT_TOP);
211 myText->setDrawMode(osgText::TextBase::DrawModeMask::FILLEDBOUNDINGBOX | osgText::TextBase::DrawModeMask::TEXT);
212 myText->setBoundingBoxColor(osg::Vec4(0.0f, 0.0f, 0.2f, 0.5f));
213 myText->setBoundingBoxMargin(2.0f);
215 myHUD =
new osg::Camera;
216 myHUD->setProjectionMatrixAsOrtho2D(0, 800, 0, 800);
217 myHUD->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
218 myHUD->setViewMatrix(osg::Matrix::identity());
219 myHUD->setClearMask(GL_DEPTH_BUFFER_BIT);
220 myHUD->setRenderOrder(osg::Camera::POST_RENDER);
221 myHUD->setAllowEventFocus(
false);
222 myHUD->setGraphicsContext(myAdapter);
223 myHUD->addChild(myTextNode);
224 myHUD->setViewport(0, 0, w, h);
225 myViewer->addSlave(myHUD,
false);
226 myCameraManipulator->updateHUDText();
230 osgUtil::Optimizer optimizer;
231 optimizer.optimize(myRoot);
235GUIOSGView::~GUIOSGView() {
237 myViewer->setDone(
true);
241 myCameraManipulator = 0;
248 myRedYellowLight = 0;
254GUIOSGView::adoptViewSettings() {
256 osg::Light* globalLight = myViewer->getLight();
257 globalLight->setAmbient(toOSGColorVector(myVisualizationSettings->ambient3DLight));
258 globalLight->setDiffuse(toOSGColorVector(myVisualizationSettings->diffuse3DLight));
259 myViewer->getCamera()->setClearColor(toOSGColorVector(myVisualizationSettings->skyColor));
262 osg::Geode* planeGeode =
dynamic_cast<osg::Geode*
>(myPlane->getChild(0));
263 osg::Geometry* planeGeom =
dynamic_cast<osg::Geometry*
>(planeGeode->getChild(0));
264 osg::Vec4ubArray* colors =
dynamic_cast<osg::Vec4ubArray*
>(planeGeom->getColorArray());
265 (*colors)[0].set(myVisualizationSettings->backgroundColor.red(),
266 myVisualizationSettings->backgroundColor.green(),
267 myVisualizationSettings->backgroundColor.blue(),
268 myVisualizationSettings->backgroundColor.alpha());
269 planeGeom->setColorArray(colors);
272 unsigned int cullMask = 0xFFFFFFFF;
273 if (!myVisualizationSettings->show3DTLSDomes) {
274 cullMask &= ~(
unsigned int)NODESET_TLSDOMES;
276 if (!myVisualizationSettings->show3DTLSLinkMarkers) {
277 cullMask &= ~(
unsigned int)NODESET_TLSLINKMARKERS;
279 if (!myVisualizationSettings->generate3DTLSModels) {
280 cullMask &= ~(
unsigned int)NODESET_TLSMODELS;
282 myViewer->getCamera()->setCullMask(cullMask);
283 unsigned int hudCullMask = (myVisualizationSettings->show3DHeadUpDisplay) ? 0xFFFFFFFF : 0;
284 myHUD->setCullMask(hudCullMask);
289GUIOSGView::getPositionInformation()
const {
291 getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos);
297GUIOSGView::is3DView()
const {
307 for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) {
309 if ((*i) == myVisualizationSettings->name) {
316 "Locate Junction",
"Locate a junction within the network.",
"",
321 "Locate Street",
"Locate a street within the network.",
"",
326 "Locate Vehicle",
"Locate a vehicle within the network.",
"",
331 "Locate Person",
"Locate a person within the network.",
"",
336 "Locate Container",
"Locate a container within the network.",
"",
341 "Locate TLS",
"Locate a tls within the network.",
"",
346 "Locate Additional",
"Locate an additional structure within the network.",
"",
351 "Locate POI",
"Locate a POI within the network.",
"",
356 "Locate Polygon",
"Locate a Polygon within the network.",
"",
363GUIOSGView::resize(
int w,
int h) {
364 GUISUMOAbstractView::resize(w, h);
365 updateHUDPosition(w, h);
370GUIOSGView::position(
int x,
int y,
int w,
int h) {
371 GUISUMOAbstractView::position(x, y, w, h);
372 updateHUDPosition(w, h);
377GUIOSGView::updateHUDPosition(
int w,
int h) {
379 myHUD->setProjectionMatrixAsOrtho2D(0, w, 0, h);
380 myText->setPosition(osg::Vec3d(0.,
static_cast<double>(height), 0.));
385GUIOSGView::updateHUDText(
const std::string text) {
386 myText->setText(text, osgText::String::ENCODING_UTF8);
391GUIOSGView::recenterView() {
393 Position center = myGrid->getCenter();
394 double radius = std::max(myGrid->xmax() - myGrid->xmin(), myGrid->ymax() - myGrid->ymin());
395 myChanger->centerTo(center, radius);
400GUIOSGView::setColorScheme(
const std::string& name) {
404 if (myGUIDialogViewSettings != 0) {
405 if (myGUIDialogViewSettings->getCurrentScheme() != name) {
406 myGUIDialogViewSettings->setCurrentScheme(name);
410 myVisualizationSettings->
gaming = myApp->isGaming();
418GUIOSGView::onPaint(FXObject*, FXSelector,
void*) {
422 myDecalsLockMutex.lock();
424 if (!d.initialised && d.filename.length() > 0) {
425 if (d.filename.length() == 6 && d.filename.substr(0, 5) ==
"light") {
426 GUIOSGBuilder::buildLight(d, *myRoot);
427 }
else if (d.filename.length() > 3 && d.filename.substr(0, 3) ==
"tl:") {
428 const int linkStringIdx = (int)d.filename.find(
':', 3);
431 const std::string tlLogic = d.filename.substr(3, linkStringIdx - 3);
434 if (linkIdx < 0 || linkIdx >=
static_cast<int>(vars.
getActive()->
getLinks().size())) {
438 osg::Group* tlNode = GUIOSGBuilder::getTrafficLight(d, vars, link, myGreenLight, myYellowLight, myRedLight, myRedYellowLight, myPoleBase,
true, 0.5);
439 tlNode->setName(
"tlLogic:" + tlLogic);
440 myRoot->addChild(tlNode);
447 GUIOSGBuilder::buildDecal(d, *myRoot);
449 d.initialised =
true;
452 myDecalsLockMutex.unlock();
455 for (
auto& item : myVehicles) {
456 item.second.active =
false;
461 for (
const MSEdge* e : net->getEdgeControl().getEdges()) {
462 for (
const MSLane* l : e->getLanes()) {
469 auto itVeh = myVehicles.find(veh);
470 if (itVeh == myVehicles.end()) {
471 myVehicles[veh] = GUIOSGBuilder::buildMovable(veh->
getVehicleType());
472 myRoot->addChild(myVehicles[veh].pos);
473 myVehicles[veh].pos->setName(
"vehicle:" + veh->
getID());
474 veh->setNode(myVehicles[veh].pos);
476 itVeh->second.active =
true;
478 osg::PositionAttitudeTransform* n = myVehicles[veh].pos;
481 const double slope = -veh->
getSlope();
482 n->setAttitude(osg::Quat(osg::DegreesToRadians(slope), osg::Vec3(1, 0, 0),
483 0, osg::Vec3(0, 1, 0),
484 dir, osg::Vec3(0, 0, 1)));
499 col = myVisualizationSettings->vehicleColorer.getScheme().getColor(veh->
getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
501 myVehicles[veh].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.
red() / 255., col.
green() / 255., col.
blue() / 255., col.
alpha() / 255.));
506 l->releaseVehicles();
510 for (
auto veh = myVehicles.begin(); veh != myVehicles.end();) {
511 if (!veh->second.active) {
512 removeVeh((veh++)->first);
519 if (now != myLastUpdate || (myGUIDialogViewSettings != 0 && myGUIDialogViewSettings->shown())) {
522 if (now != myLastUpdate && myTracked != 0) {
523 osg::Vec3d lookFrom, lookAt, up;
524 lookAt[0] = myTracked->getPosition().x();
525 lookAt[1] = myTracked->getPosition().y();
526 lookAt[2] = myTracked->getPosition().z();
527 const double angle = myTracked->getAngle();
528 lookFrom[0] = lookAt[0] + 50. * cos(angle);
529 lookFrom[1] = lookAt[1] + 50. * sin(angle);
530 lookFrom[2] = lookAt[2] + 10.;
532 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
533 myViewer->getCameraManipulator()->setByInverseMatrix(m);
537 for (
auto& item : myPersons) {
538 item.second.active =
false;
541 for (
const MSEdge* e : net->getEdgeControl().getEdges()) {
543 const std::set<MSTransportable*, ComparatorNumericalIdLess>& persons = ge->
getPersonsSecure();
544 for (
auto person : persons) {
545 if (person->hasArrived() || !person->hasDeparted()) {
549 auto itPers = myPersons.find(person);
550 if (itPers == myPersons.end()) {
551 myPersons[person] = GUIOSGBuilder::buildMovable(person->getVehicleType());
552 myRoot->addChild(myPersons[person].pos);
554 itPers->second.active =
true;
556 osg::PositionAttitudeTransform* n = myPersons[person].pos;
557 const Position pos = person->getPosition();
558 n->setPosition(osg::Vec3d(pos.
x(), pos.
y(), pos.
z()));
559 const double dir = person->getAngle() +
M_PI / 2.;
560 n->setAttitude(osg::Quat(dir, osg::Vec3d(0, 0, 1)));
565 col = myVisualizationSettings->personColorer.getScheme().getColor(actualPerson->
getColorValue(*myVisualizationSettings, myVisualizationSettings->vehicleColorer.getActive()));
567 myPersons[person].mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4d(col.
red() / 255., col.
green() / 255., col.
blue() / 255., col.
alpha() / 255.));
573 for (
auto person = myPersons.begin(); person != myPersons.end();) {
574 if (!person->second.active) {
575 removeTransportable((person++)->first);
581 if (myAdapter->makeCurrent()) {
592 if (myTracked == veh) {
595 std::map<MSVehicle*, OSGMovable>::iterator i = myVehicles.find(veh);
596 if (i != myVehicles.end()) {
597 myRoot->removeChild(i->second.pos);
605 std::map<MSTransportable*, OSGMovable>::iterator i = myPersons.find(t);
606 if (i != myPersons.end()) {
607 myRoot->removeChild(i->second.pos);
613void GUIOSGView::updateViewportValues() {
614 osg::Vec3d lookFrom, lookAt, up;
615 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
616 myGUIDialogEditViewport->setValues(
Position(lookFrom[0], lookFrom[1], lookFrom[2]),
617 Position(lookAt[0], lookAt[1], lookAt[2]), calculateRotation(lookFrom, lookAt, up));
622GUIOSGView::showViewportEditor() {
624 osg::Vec3d lookFrom, lookAt, up;
625 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
626 Position from(lookFrom[0], lookFrom[1], lookFrom[2]), at(lookAt[0], lookAt[1], lookAt[2]);
627 myGUIDialogEditViewport->setOldValues(from, at, calculateRotation(lookFrom, lookAt, up));
628 myGUIDialogEditViewport->setZoomValue(100);
629 myGUIDialogEditViewport->show();
634GUIOSGView::setViewportFromToRot(
const Position& lookFrom,
const Position& lookAt,
double rotation) {
635 osg::Vec3d lookFromOSG, lookAtOSG, up;
636 lookFromOSG[0] = lookFrom.
x();
637 lookFromOSG[1] = lookFrom.
y();
638 lookFromOSG[2] = lookFrom.
z();
639 lookAtOSG[0] = lookAt.
x();
640 lookAtOSG[1] = lookAt.
y();
641 lookAtOSG[2] = lookAt.
z();
643 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
644 viewAxis = lookFromOSG - lookAtOSG;
645 viewAxis.normalize();
646 viewUp = (viewAxis[0] + viewAxis[1] == 0.) ? osg::Vec3d(0., 1., 0.) : osg::Vec3d(0., 0., 1.);
647 orthogonal = viewUp ^ viewAxis;
648 orthogonal.normalize();
649 normal = viewAxis ^ orthogonal;
651 rotation = std::fmod(rotation, 360.);
655 myChanger->setRotation(rotation);
656 double angle =
DEG2RAD(rotation);
657 up = normal * cos(angle) - orthogonal * sin(angle);
660 double zoom = (myGUIDialogEditViewport !=
nullptr) ? myGUIDialogEditViewport->getZoomValue() : 100.;
661 lookFromOSG = lookFromOSG + viewAxis * (100. - zoom);
662 lookAtOSG = lookFromOSG - viewAxis;
663 myViewer->getCameraManipulator()->setHomePosition(lookFromOSG, lookAtOSG, up);
670 osg::Vec3d lookFrom, lookAt, up;
671 myViewer->getCameraManipulator()->getHomePosition(lookFrom, lookAt, up);
673 Position(lookAt[0], lookAt[1], lookAt[2]), 0);
678GUIOSGView::startTrack(
int id) {
679 if (myTracked == 0 || (
int)myTracked->getGlID() !=
id) {
684 if ((
int)veh->getGlID() ==
id) {
685 if (!veh->
isOnRoad() || myVehicles.find(veh) == myVehicles.end()) {
692 if (myTracked != 0) {
693 osg::Vec3d lookFrom, lookAt, up;
695 lookAt[1] = myTracked->getPosition().y();
696 lookAt[2] = myTracked->getPosition().z();
697 lookFrom[0] = lookAt[0] + 50.;
698 lookFrom[1] = lookAt[1] + 50.;
699 lookFrom[2] = lookAt[2] + 10.;
701 m.makeLookAt(lookFrom, lookAt, osg::Z_AXIS);
702 myViewer->getCameraManipulator()->setByInverseMatrix(m);
709GUIOSGView::stopTrack() {
715GUIOSGView::getTrackedID()
const {
721GUIOSGView::onGamingClick(
Position pos) {
724 double minDist = std::numeric_limits<double>::infinity();
729 if (lanes.size() > 0) {
730 const Position& endPos = lanes[0]->getShape().back();
740 const std::vector<MSTrafficLightLogic*> logics = vars.
getAllLogics();
741 if (logics.size() > 1) {
743 for (
int i = 0; i < (int)logics.size() - 1; i++) {
744 if (minTll->
getProgramID() == logics[i]->getProgramID()) {
749 if (l == logics[0]) {
760GUIOSGView::getCurrentTimeStep()
const {
765long GUIOSGView::onConfigure(FXObject* sender, FXSelector sel,
void* ptr) {
767 const int w = getWidth();
768 const int h = getHeight();
769 if (w > 0 && h > 0) {
770 myAdapter->getEventQueue()->windowResize(0, 0, w, h);
771 myAdapter->resized(0, 0, w, h);
772 updateHUDPosition(w, h);
774 return FXGLCanvas::onConfigure(sender, sel, ptr);
778long GUIOSGView::onKeyPress(FXObject* sender, FXSelector sel,
void* ptr) {
779 int key = ((FXEvent*)ptr)->code;
780 myAdapter->getEventQueue()->keyPress(key);
782 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
785 return FXGLCanvas::onKeyPress(sender, sel, ptr);
789long GUIOSGView::onKeyRelease(FXObject* sender, FXSelector sel,
void* ptr) {
790 int key = ((FXEvent*)ptr)->code;
791 myAdapter->getEventQueue()->keyRelease(key);
793 if (key == FX::KEY_f || key == FX::KEY_Left || key == FX::KEY_Right || key == FX::KEY_Up || key == FX::KEY_Down) {
796 return FXGLCanvas::onKeyRelease(sender, sel, ptr);
800long GUIOSGView::onLeftBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
801 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
803 FXEvent*
event = (FXEvent*)ptr;
804 myAdapter->getEventQueue()->mouseButtonPress((
float)
event->click_x, (float)event->click_y, 1);
805 if (myApp->isGaming()) {
806 onGamingClick(getPositionInformation());
809 return FXGLCanvas::onLeftBtnPress(sender, sel, ptr);
813long GUIOSGView::onLeftBtnRelease(FXObject* sender, FXSelector sel,
void* ptr) {
814 FXEvent*
event = (FXEvent*)ptr;
815 myAdapter->getEventQueue()->mouseButtonRelease((
float)
event->click_x, (float)event->click_y, 1);
816 myChanger->onLeftBtnRelease(ptr);
817 return FXGLCanvas::onLeftBtnRelease(sender, sel, ptr);
821long GUIOSGView::onMiddleBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
822 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
824 FXEvent*
event = (FXEvent*)ptr;
825 myAdapter->getEventQueue()->mouseButtonPress((
float)
event->click_x, (float)event->click_y, 2);
827 return FXGLCanvas::onMiddleBtnPress(sender, sel, ptr);
831long GUIOSGView::onMiddleBtnRelease(FXObject* sender, FXSelector sel,
void* ptr) {
832 FXEvent*
event = (FXEvent*)ptr;
833 myAdapter->getEventQueue()->mouseButtonRelease((
float)
event->click_x, (float)event->click_y, 2);
834 myChanger->onMiddleBtnRelease(ptr);
835 return FXGLCanvas::onMiddleBtnRelease(sender, sel, ptr);
839long GUIOSGView::onRightBtnPress(FXObject* sender, FXSelector sel,
void* ptr) {
840 handle(
this, FXSEL(SEL_FOCUS_SELF, 0), ptr);
842 FXEvent*
event = (FXEvent*)ptr;
843 myAdapter->getEventQueue()->mouseButtonPress((
float)
event->click_x, (float)event->click_y, 3);
845 return FXGLCanvas::onRightBtnPress(sender, sel, ptr);
849long GUIOSGView::onRightBtnRelease(FXObject* sender, FXSelector sel,
void* ptr) {
850 FXEvent*
event = (FXEvent*)ptr;
851 myAdapter->getEventQueue()->mouseButtonRelease((
float)
event->click_x, (float)event->click_y, 3);
852 myChanger->onRightBtnRelease(ptr);
853 return FXGLCanvas::onRightBtnRelease(sender, sel, ptr);
858GUIOSGView::onMouseMove(FXObject* sender, FXSelector sel,
void* ptr) {
860 if (myPopup && !myPopup->shown()) {
864 FXEvent*
event = (FXEvent*)ptr;
865 osgGA::GUIEventAdapter* ea = myAdapter->getEventQueue()->mouseMotion((
float)
event->win_x, (float)event->win_y);
866 setWindowCursorPosition(ea->getXnormalized(), ea->getYnormalized());
867 if (myGUIDialogEditViewport !=
nullptr && myGUIDialogEditViewport->shown()) {
868 updateViewportValues();
870 updatePositionInformation();
871 return FXGLCanvas::onMotion(sender, sel, ptr);
876GUIOSGView::onIdle(FXObject* , FXSelector ,
void*) {
885GUIOSGView::onCmdCloseLane(FXObject*, FXSelector,
void*) {
886 GUILane* lane = getLaneUnderCursor();
887 if (lane !=
nullptr) {
898GUIOSGView::onCmdCloseEdge(FXObject*, FXSelector,
void*) {
899 GUILane* lane = getLaneUnderCursor();
900 if (lane !=
nullptr) {
911GUIOSGView::onCmdAddRerouter(FXObject*, FXSelector,
void*) {
912 GUILane* lane = getLaneUnderCursor();
913 if (lane !=
nullptr) {
923GUIOSGView::onCmdShowReachability(FXObject* menu, FXSelector selector,
void*) {
924 GUILane* lane = getLaneUnderCursor();
925 if (lane !=
nullptr) {
929 if (myVisualizationSettings->laneColorer.getActive() != 36) {
930 myVisualizationSettings->laneColorer.setActive(1);
940GUIOSGView::onVisualizationChange(FXObject*, FXSelector,
void*) {
947GUIOSGView::setWindowCursorPosition(
float x,
float y) {
948 myOSGNormalizedCursorX = x;
949 myOSGNormalizedCursorY = y;
954GUIOSGView::calculateRotation(
const osg::Vec3d& lookFrom,
const osg::Vec3d& lookAt,
const osg::Vec3d& up) {
955 osg::Vec3d viewAxis, viewUp, orthogonal, normal;
956 viewAxis = lookFrom - lookAt;
957 viewAxis.normalize();
958 viewUp = (abs(viewAxis[0]) + abs(viewAxis[1]) == 0.) ? osg::Y_AXIS : osg::Z_AXIS;
959 orthogonal = viewUp ^ viewAxis;
960 orthogonal.normalize();
961 normal = viewAxis ^ orthogonal;
962 double angle = atan2((normal ^ up).length() / (normal.length() * up.length()), (normal * up) / (normal.length() * up.length()));
971GUIOSGView::updatePositionInformation()
const {
973 if (getPositionAtCursor(myOSGNormalizedCursorX, myOSGNormalizedCursorY, pos)) {
974 myApp->getCartesianLabel()->setText((
"x:" +
toString(pos.
x()) +
", y:" +
toString(pos.
y())).c_str());
980 myApp->getGeoLabel()->setText(
TL(
"(No projection defined)"));
984 myApp->getCartesianLabel()->setText(
TL(
"N/A"));
985 myApp->getGeoLabel()->setText(
TL(
"N/A"));
991GUIOSGView::getPositionAtCursor(
float xNorm,
float yNorm,
Position& pos)
const {
993 osg::Vec3d lookFrom, lookAt, up, viewAxis;
994 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFrom, lookAt, up);
995 if ((lookAt - lookFrom).z() >= 0.) {
1000 osg::Matrixd iVP = osg::Matrixd::inverse(myViewer->getCamera()->getViewMatrix() * myViewer->getCamera()->getProjectionMatrix());
1001 osg::Vec3 nearPoint = osg::Vec3(xNorm, yNorm, 0.0f) * iVP;
1002 osg::Vec3 farPoint = osg::Vec3(xNorm, yNorm, 1.0f) * iVP;
1003 osg::Vec3 ray = farPoint - nearPoint;
1004 osg::Vec3 groundPos = nearPoint - ray * nearPoint.z() / ray.z();
1005 pos.
setx(groundPos.x());
1006 pos.
sety(groundPos.y());
1012std::vector<GUIGlObject*>
1013GUIOSGView::getGUIGlObjectsUnderCursor() {
1014 std::vector<GUIGlObject*> result;
1015 osgUtil::LineSegmentIntersector::Intersections intersections;
1016 if (myViewer->computeIntersections(myViewer->getCamera(), osgUtil::Intersector::CoordinateFrame::PROJECTION, myOSGNormalizedCursorX, myOSGNormalizedCursorY, intersections)) {
1017 for (
auto intersection : intersections) {
1018 if (!intersection.nodePath.empty()) {
1020 for (osg::Node* currentNode : intersection.nodePath) {
1021 if (currentNode->getName().length() > 0 && currentNode->getName().find(
":") != std::string::npos) {
1022 const std::string objID = currentNode->getName();
1032 result.push_back(o);
1045GUIOSGView::getLaneUnderCursor() {
1046 std::vector<GUIGlObject*> objects = getGUIGlObjectsUnderCursor();
1047 if (objects.size() > 0) {
1048 return dynamic_cast<GUILane*
>(objects[0]);
1056 osg::Vec3d lookFromOSG, lookAtOSG, viewAxis, up;
1057 myViewer->getCameraManipulator()->getInverseMatrix().getLookAt(lookFromOSG, lookAtOSG, up);
1058 lookFromOSG[0] = camera.
x();
1059 lookFromOSG[1] = camera.
y();
1060 lookFromOSG[2] = camera.
z();
1061 lookAtOSG[0] = lookAt.
x();
1062 lookAtOSG[1] = lookAt.
y();
1063 lookAtOSG[2] = lookAt.
z();
1064 viewAxis = lookAtOSG - lookFromOSG;
1065 viewAxis.normalize();
1068 osg::Vec3d cameraUpdate = lookFromOSG + viewAxis * (zoom - 100.);
1069 osg::Vec3d lookAtUpdate = cameraUpdate + viewAxis;
1071 myViewer->getCameraManipulator()->setHomePosition(cameraUpdate, lookAtUpdate, up);
1077GUIOSGView::toOSGColorVector(
RGBColor c,
bool useAlpha) {
1078 return osg::Vec4d(c.
red() / 255., c.
green() / 255., c.
blue() / 255., (useAlpha) ? c.
alpha() / 255. : 1.);
1083 : myParent(parent), myOldCursor(cursor) {
1084 _traits =
new GraphicsContext::Traits();
1087 _traits->width = parent->getWidth();
1088 _traits->height = parent->getHeight();
1089 _traits->windowDecoration =
false;
1090 _traits->doubleBuffer =
true;
1091 _traits->sharedContext = 0;
1093 setState(
new osg::State());
1094 getState()->setGraphicsContext(
this);
1095#ifdef DEBUG_GLERRORS
1096 getState()->setCheckForGLErrors(osg::State::ONCE_PER_ATTRIBUTE);
1097 std::cout <<
"OSG getCheckForGLErrors " << getState()->getCheckForGLErrors() << std::endl;
1099 if (_traits.valid() && _traits->sharedContext != 0) {
1100 getState()->setContextID(_traits->sharedContext->getState()->getContextID());
1101 incrementContextIDUsageCount(getState()->getContextID());
1103 getState()->setContextID(createNewContextID());
1109GUIOSGView::FXOSGAdapter::~FXOSGAdapter() {
1115GUIOSGView::FXOSGAdapter::grabFocus() {
1117 myParent->setFocus();
1122GUIOSGView::FXOSGAdapter::useCursor(
bool cursorOn) {
1124 myParent->setDefaultCursor(myOldCursor);
1126 myParent->setDefaultCursor(NULL);
1132GUIOSGView::FXOSGAdapter::makeCurrentImplementation() {
1133 myParent->makeCurrent();
1139GUIOSGView::FXOSGAdapter::releaseContext() {
1140 myParent->makeNonCurrent();
1146GUIOSGView::FXOSGAdapter::swapBuffersImplementation() {
1147 myParent->swapBuffers();
1152GUIOSGView::PickHandler::handle(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& ) {
1153 if (ea.getEventType() == osgGA::GUIEventAdapter::DRAG) {
1155 }
else if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE && ea.getButton() == osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON) {
1157 if (myParent->makeCurrent()) {
1158 std::vector<GUIGlObject*> objects = myParent->getGUIGlObjectsUnderCursor();
1159 if (objects.size() > 0) {
1160 myParent->openObjectDialog(objects);
1162 myParent->makeNonCurrent();
@ MID_HOTKEY_SHIFT_O_LOCATEPOI
Locate poi - button.
@ MID_HOTKEY_SHIFT_A_LOCATEADDITIONAL
Locate additional structure - button.
@ MID_HOTKEY_SHIFT_C_LOCATECONTAINER
Locate container - button.
@ MID_HOTKEY_SHIFT_V_LOCATEVEHICLE
Locate vehicle - button.
@ MID_HOTKEY_SHIFT_L_LOCATEPOLY
Locate polygons - button.
@ MID_HOTKEY_SHIFT_E_LOCATEEDGE
Locate edge - button.
@ MID_HOTKEY_SHIFT_P_LOCATEPERSON
Locate person - button.
@ MID_HOTKEY_SHIFT_J_LOCATEJUNCTION
Locate junction - button.
@ MID_HOTKEY_SHIFT_T_LOCATETLS
Locate TLS - button.
GUICompleteSchemeStorage gSchemeStorage
#define GUIDesignButtonPopup
checkable button placed in popup (for example, locate buttons)
FXDEFMAP(GUIDialog_AppSettings) GUIDialog_AppSettingsMap[]
std::ostream & operator<<(std::ostream &out, MSDevice_SSM::EncounterType type)
Nicer output for EncounterType enum.
#define WRITE_ERRORF(...)
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static bool isReadable(std::string path)
Checks whether the given file is readable.
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
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
A road/street connecting two junctions (gui-version)
void releasePersons() const
Allows to use the container for microsimulation again.
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersonsSecure() const
Returns this edge's persons set; locks it for microsimulation.
MFXComboBoxIcon * getColoringSchemesCombo()
return combobox with the current coloring schemes (standard, fastest standard, real world....
FXPopup * getLocatorPopup()
@ brief return a pointer to locator popup
static const GUIGlID INVALID_ID
GUIGlID getGlID() const
Returns the numerical id of the object.
void unblockObject(GUIGlID id)
Marks an object as unblocked.
GUIGlObject * getObjectBlocking(GUIGlID id) const
Returns the object from the container locking it.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Representation of a lane in the micro simulation (gui-version)
void closeTraffic(bool rebuildAllowed=true)
close this lane for traffic
A MSNet extended by some values for usage within the gui.
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const override
gets the color value according to the current scheme index
static bool setFunctionalColor(int activeScheme, const MSPerson *person, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
A single child window which contains a view of the simulation area.
A MSVehicle extended by some values for usage within the gui.
double getAngle() const
Return current angle.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
static long showLaneReachability(GUILane *lane, FXObject *, FXSelector)
bool gaming
whether the application is in gaming mode or not
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
long setCurrentItem(const FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXint getNumItems() const
Return the number of items in the list.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
bool isParking() const
Returns whether the vehicle is parking.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
A road/street connecting two junctions.
Representation of a lane in the micro simulation.
std::vector< MSVehicle * > VehCont
Container for vehicles.
MSEdge & getEdge() const
Returns the lane's edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
SUMOTime duration
The duration of the phase.
A fixed traffic light logic.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
Storage for all programs of a single tls.
std::vector< MSTrafficLightLogic * > getAllLogics() const
MSTrafficLightLogic * getActive() const
A class that stores and controls tls and switching of their programs.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
The parent class for traffic light logics.
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
const std::string & getProgramID() const
Returns this tl-logic's id.
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
bool wasRemoteControlled(SUMOTime lookBack=DELTA_T) const
Returns the information whether the vehicle is fully controlled via TraCI within the lookBack time.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
bool signalSet(int which) const
Returns whether the given signal is on.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
@ VEH_SIGNAL_BLINKER_RIGHT
Right blinker lights are switched on.
@ VEH_SIGNAL_BRAKELIGHT
The brake lights are on.
@ VEH_SIGNAL_BLINKER_LEFT
Left blinker lights are switched on.
@ VEH_SIGNAL_BLINKER_EMERGENCY
Blinker lights on both sides are switched on.
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
const std::string & getID() const
Returns the id.
A point in 2D or 3D with translation and scaling methods.
void setx(double x)
set position x
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
double x() const
Returns the x-position.
void setz(double z)
set position z
double z() const
Returns the z-position.
void sety(double y)
set position y
double y() const
Returns the y-position.
unsigned char red() const
Returns the red-amount of the color.
unsigned char alpha() const
Returns the alpha-amount of the color.
unsigned char green() const
Returns the green-amount of the color.
unsigned char blue() const
Returns the blue-amount of the color.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
@ key
the parser read a key of a value in an object
A decal (an image) that can be shown.