diff --git a/.gitignore b/.gitignore index 00b34e444e0f477bc77fcb8bac8cbd6e8da3fdb1..56a89b0ed85ad17d78ebd0ad367ffbffa3e8c682 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ Makefile bin/ ui_* +.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index b781b1436fc37579e571cfef9ddff5a3c23c4cbe..2640d0bce3baf655ee22f7853c0bf97a294f9108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,25 @@ # Change Log All notable changes to this project will be documented in this file. +## v0.8.1 [Unreleased] -## v0.8.0 [Unreleased] +### Added + +### Changed + +### Bugs fixed + + Heap error when using undo/redo while drawing + +### Bugs + + Several heap errors + Autosave not working properly + DXF-Import restricted + +## v0.8.0 [05.03.2016] ### Added -#### JPSEDITOR - 1.2.16 Undo/Redo when Line was edited - 1.2.16 Change Info Text - 1.2.16 Load HLines @@ -23,103 +37,4 @@ All notable changes to this project will be documented in this file. - Length of line is displayed - Show origin - ... -- Room and door declarations -# Change Log -All notable changes to this project will be documented in this file. - - -## v0.8.0 [Unreleased] - - -### Added -#### JPSCORE -- CI with travis and Gitlab CI -- Compilation checked on Visual Studio 12 2013 -- Added more validation tests -- Added statistics (calculate exit usage) for all exits -- Added voronoi based algorithm for inserting agents coming from the source or from matsim -- New option for the quickest path router. Sample options are: - `````` - `````` - ``` -``` -- New model with the generic name `Tordeux2015` and `id=3`. For use check the ini-files in the Utest-validation tests. -- Tests are sorted in `rimea_tests`, `juelich_tests` and `validation_tests`. -- Periodic boundary conditions with the option `1`.Works only with model 3. -- Added Floorfield to all exits, providing direction to target, direction to closest wall and cost estimates. Parameter to control wall-avoidance included. - -#### JPSVIS -- Added option to load vtk files. Need to add the line ``` -``` in the header of the trajectory file. Alternatively drag and drop a vtk file on JPSvis. - -- Fixed error displaying the total number of frames when using the scroolbar - -#### JPSREPORT -- Added geometry information while plotting the voronoi cells -- Added option to disable plotting -- Issue a warning when the voronoi cell cannot be calculated -- Fixed error where all trajectories were colinear - -#### JPSEDITOR - - -## v0.7.0 [2015-07-15] - -### New Module -- JuPedSim: Editor for the geometry - -### Added - -- Risk tolerance factor (value in [0 1]) for pedestrian. Pedestrians with high values are likely to take more risks. -- Added pre-movement time of the agents. Only after this time, the concerned agents will start moving. -- Sources for generating agents at runtime. Parameter are frequency (agents per seconds) and maximum number -- Option to color the pedestrians by group, spotlight, velocity, group, knowledge, router, final\_goal, intermediate\_goal. Usage: ( -``` ```) -- More control over the triangulation specially to avoid skinny triangles. Usage: `````` -- Improved statistics. The flow curve for the different exits can be computed at runtime. -- Changelog file -- Rimea testcases -- Unit tests are now based on the Boost testing engine -#### JPSVIS -- Display the geometry structure individual room/subroom. -- Now build on OSX/Linux/Windows - -### Changed -- -- - -### Fixed -- Visiblity in 3D -- Numerous geometrical operations - - -## v0.6.0 - 2015-01-31 -### Added -- Steering the simulation with predefined events (closing or opening doors during the simulation) -- Information sharing between the pedestrians. The agents now share their knowledge about closed doors. -- Pre evacuation time for groups of agents. -- Adjustable velocities on stairs and even terrain for group of agents. -- Stability and performance improvement. The simulation is approx 40% faster for larger scenarios and you will notice it -- New route choice model, cognitive map, giving agents the possibility to explore the environment and discover doors for instance. -- Different sensors for improving the navigation of pedestrians (smoke/jam sensor). -- New verification and validation tests. -- General statistics over the evacuation (for instance areas egress time and door usage) -- Support for Visual Studio and Xcode compilers. - - -### Changed -- refactor NumCPU and ExitCrossingStrategy tags to `num_threads and exit_crossing_strategy` - - - -## v0.5.0 - 2014-08-05 -First release of the the Juelich Pedestrian Simulator. Most noteworthy features: - -- Simulate pedestrians movement in a space continuous geometry -- Forces based models for describing the pedestrians interactions -- Shortest and quickest path route choice strategies -- Loading and visualizing trajectories and geometries -- Easy to use visualization interface -- Making high quality videos directly from the visualization interface or generating png sequences -- XML based input files \ No newline at end of file +- Room and door declarations \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 826e5f377680c321dc981c722870d22d15024309..56a94c3ca69524673b598ad9285ac366a2599177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,11 +107,12 @@ set( SRCS src/widgetsettings.cpp src/jpsyahpointer.cpp src/jpsconnection.cpp - src/UndoFramework/action.cpp - src/UndoFramework/lineaction.cpp - src/UndoFramework/actionstack.cpp + src/jpsregion.cpp dxflib/src/dl_writer_ascii.cpp dxflib/src/dl_dxf.cpp + src/UndoFramework/action.cpp + src/UndoFramework/actionstack.cpp + src/UndoFramework/lineaction.cpp ) # all header files that should be treated with moc set( HDR @@ -131,9 +132,7 @@ set( HDR src/widgetsettings.h src/jpsyahpointer.h src/jpsconnection.h - src/UndoFramework/action.h - src/UndoFramework/lineaction.h - src/UndoFramework/actionstack.h + src/jpsregion.h dxflib/src/dl_writer_ascii.h dxflib/src/dl_writer.h dxflib/src/dl_global.h @@ -145,6 +144,9 @@ set( HDR dxflib/src/dl_creationadapter.h dxflib/src/dl_codes.h dxflib/src/dl_attributes.h + src/UndoFramework/action.h + src/UndoFramework/actionstack.h + src/UndoFramework/lineaction.h ) @@ -458,6 +460,7 @@ if(APPLE OR WIN32) if(${QT4_INSTALLED}) include(DeployQt4) install_qt4_executable("${EXECUTABLE}" "qsqlite") + elseif(${QT5_INSTALLED}) include(DeployQt5) install_qt5_executable("${EXECUTABLE}" "qsqlite") diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..f03a93d2de677c170f0e2c17e11ecda311c9a8d1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +#------------------------------------------------------------- +# - build: +# docker build -t jupedsim/jpseditor . +# - run: +# 1. socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" +# 2. docker -it -e DISPLAY= jupedsim/jpseditor +#------------------------------------------------------------- + +FROM ubuntu:14.04 + +MAINTAINER Erik Andresen + +# install required packages +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + g++ \ + git \ + lcov \ + doxygen \ + qt5-default qttools5-dev-tools \ + # python \ + # python-dev \ + # python-pip \ + && apt-get clean + +# set environment +ENV HOME /home/jupedsim + +# add user +RUN groupadd -r -g 1000 jupedsim && useradd -r -g jupedsim -u 1000 -m jupedsim +USER jupedsim + +# install jpscore +RUN mkdir -p /home/jupedsim/workspace +RUN cd /home/jupedsim/workspace \ + && git clone --depth=5 https://cst.version.fz-juelich.de/jupedsim/jpseditor.git \ + && cd jpseditor \ + && mkdir -p build \ + && cd build \ + && cmake -D DESIRED_QT_VERSION=5 ..\ + && make + + +# by default /bin/bash is executed +CMD $HOME/workspace/jpseditor/bin/JPSeditor \ No newline at end of file diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 8e958db5b2b19cc3e39355d4ea2f6bbcec0dad6c..dc0fbe3e7cabd940c7ae588b2df74f5659e0298a 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -33,9 +33,10 @@ + - + @@ -55,6 +56,7 @@ + @@ -67,6 +69,8 @@ + + @@ -560,6 +564,47 @@ true + + + false + + + + :/filesave.png:/filesave.png + + + Save CognitiveMap + + + Save CognitiveMap + + + false + + + + + + :/open.png:/open.png + + + Load Cognitive Map + + + Load Cognitive Map + + + false + + + + + Copy + + + Ctrl+C + + diff --git a/forms/widgetlandmark.ui b/forms/widgetlandmark.ui index 26c035e00f95c621baed39a5ddf66141c9f7e395..9b5f6b1e5488b8b2797dcc5f801d2fa765c363d4 100644 --- a/forms/widgetlandmark.ui +++ b/forms/widgetlandmark.ui @@ -16,56 +16,255 @@ 0 - + - Landmark + Cognitive Map - + - 30 - 30 - 191 + 10 + 70 + 291 + 161 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.8pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">The purpose of this widget is to create one or multiple cognitive maps. The maps can be used as a representation of the agents' knowledge degree in JuPedSim. Use tabs Landmarks/Connections/Regions to make your specifications. If you need help have a look at the tutorial on our YouTube-Channel. (coming soon)</p></body></html> + + + + + + 10 + 20 + 241 31 - 12 + 14 + + 6 + - Landmark: + Cognitive Map + + + Qt::AutoText - + + + + -10 + 250 + 341 + 20 + + + + Qt::Horizontal + + + + + + 10 + 280 + 241 + 31 + + + + + 10 + + + + 6 + + + Save the current map + + + Qt::AutoText + + + + + + 20 + 390 + 241 + 31 + + + + + 10 + + + + 6 + + + Save the current and x similar maps + + + Qt::AutoText + + + + + + 20 + 330 + 93 + 28 + + + + Save + + + + + + -10 + 540 + 341 + 20 + + + + Qt::Horizontal + + + - false + true + + + + 110 + 570 + 93 + 28 + + + + Close + + + + + + 170 + 440 + 61 + 31 + + + + 100000000 + + + + + + 10 + 440 + 151 + 31 + + + + + 8 + + + + 6 + + + How many maps in total? + + + Qt::AutoText + + + + + + -10 + 370 + 341 + 20 + + + + Qt::Horizontal + + 20 - 470 - 291 + 500 + 93 + 28 + + + + Make it fuzzy! + + + + + + Landmarks + + + + + 40 + 20 + 191 31 + + + 12 + + - Press Add and throw rect! + Landmark: - + - false + true 10 - 360 + 440 291 - 91 + 31 + + Press Set and throw rect! + @@ -74,7 +273,7 @@ 110 - 560 + 570 93 28 @@ -85,18 +284,18 @@ - false + true - 30 - 510 + 20 + 480 112 34 - Add + Set true @@ -104,12 +303,12 @@ - false + true 170 - 510 + 480 112 34 @@ -120,12 +319,12 @@ - false + true - 10 - 310 + 20 + 290 191 31 @@ -143,7 +342,7 @@ 80 - 150 + 120 113 22 @@ -153,7 +352,7 @@ 20 - 150 + 120 51 16 @@ -171,7 +370,7 @@ 210 - 150 + 120 81 21 @@ -184,7 +383,7 @@ -10 - 200 + 210 341 20 @@ -196,8 +395,8 @@ - 30 - 80 + 40 + 70 201 31 @@ -207,7 +406,7 @@ -10 - 290 + 270 341 20 @@ -218,12 +417,12 @@ - false + true - 130 - 250 + 80 + 240 101 21 @@ -231,12 +430,12 @@ - false + true - 50 - 240 + 10 + 230 61 41 @@ -250,6 +449,369 @@ is in: + + + true + + + + 10 + 410 + 271 + 31 + + + + + 12 + + + + Set Position in Cognitive Map: + + + + + + -10 + 390 + 341 + 20 + + + + Qt::Horizontal + + + + + + 10 + 520 + 291 + 21 + + + + + + + + + + -10 + 540 + 341 + 20 + + + + Qt::Horizontal + + + + + + 210 + 10 + 93 + 28 + + + + Show/Hide + + + + + + 20 + 330 + 171 + 51 + + + + + + true + + + + 210 + 350 + 81 + 21 + + + + New + + + true + + + + + + -10 + 150 + 341 + 20 + + + + Qt::Horizontal + + + + + true + + + + 30 + 170 + 61 + 41 + + + + + 12 + + + + Type: + + + + + true + + + + 100 + 180 + 101 + 21 + + + + + + true + + + + 200 + 240 + 101 + 21 + + + + + + + Connections + + + + + -10 + 530 + 341 + 20 + + + + Qt::Horizontal + + + + + true + + + + 110 + 560 + 93 + 28 + + + + Close + + + + + + 20 + 20 + 191 + 31 + + + + + 12 + + + + Connections: + + + + + true + + + + 30 + 320 + 101 + 31 + + + + New + + + true + + + + + true + + + + 180 + 320 + 101 + 31 + + + + Remove + + + false + + + + + + 15 + 80 + 281 + 192 + + + + + + + Regions + + + + + 10 + 80 + 281 + 192 + + + + + + + 30 + 310 + 93 + 28 + + + + Add + + + + + + 180 + 310 + 93 + 28 + + + + Remove + + + + + + 30 + 30 + 111 + 31 + + + + + 12 + + + + Regions: + + + + + + -10 + 540 + 341 + 20 + + + + Qt::Horizontal + + + + + true + + + + 110 + 570 + 93 + 28 + + + + Close + + + + + + 200 + 20 + 93 + 28 + + + + Show/Hide + + diff --git a/jpseditor.pro b/jpseditor.pro index 7186b31fc7d00e9c9b258e45714fb0c87b6dbdcf..b1ba056c8775fb1fb31bb660e9f683da7d9064a8 100644 --- a/jpseditor.pro +++ b/jpseditor.pro @@ -60,7 +60,8 @@ HEADERS += \ src/jpsconnection.h \ src/UndoFramework/actionstack.h \ src/UndoFramework/action.h \ - src/UndoFramework/lineaction.h + src/UndoFramework/lineaction.h \ + src/jpsregion.h SOURCES += \ @@ -85,7 +86,8 @@ SOURCES += \ src/jpsconnection.cpp \ src/UndoFramework/actionstack.cpp \ src/UndoFramework/action.cpp \ - src/UndoFramework/lineaction.cpp + src/UndoFramework/lineaction.cpp \ + src/jpsregion.cpp RESOURCES += forms/Ressource.qrc diff --git a/src/GraphicView.cpp b/src/GraphicView.cpp index dcb7784c91e0ad0cb0834c9e844eebb7ac414065..1a79ff4e90a52ed60b583e1d7261202f773cc9d1 100644 --- a/src/GraphicView.cpp +++ b/src/GraphicView.cpp @@ -1,7 +1,7 @@ /** * \file GraphicView.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -32,12 +32,13 @@ #include #include #include +#include "datamanager.h" -jpsGraphicsView::jpsGraphicsView(QWidget* parent):QGraphicsView(parent) +jpsGraphicsView::jpsGraphicsView(QWidget* parent, jpsDatamanager *datamanager):QGraphicsView(parent) { - + _datamanager=datamanager; current_line=nullptr; _currentVLine=nullptr; current_caption=nullptr; @@ -66,18 +67,22 @@ jpsGraphicsView::jpsGraphicsView(QWidget* parent):QGraphicsView(parent) statDoor=false; statExit=false; _statHLine=false; + _statCopy=0; statLandmark=false; markedLandmark=nullptr; currentLandmarkRect=nullptr; currentPen.setColor(Qt::black); currentPen.setCosmetic(true); + currentPen.setWidth(2); this->scale(1/gl_scale_f,-1/gl_scale_f); _currentTrackedPoint=nullptr; _statLineEdit=false; intersection_point=nullptr; + _statDefConnections=0; lines_collided=false; - _assoDef=false; + _posDef=false; + _regionDef=false; //m_graphView->setFixedSize(1600, 900); @@ -112,6 +117,31 @@ jpsGraphicsView::~jpsGraphicsView() delete Scene; } +QGraphicsScene *jpsGraphicsView::GetScene() +{ + return Scene; +} + +const qreal &jpsGraphicsView::GetTranslationX() const +{ + return translation_x; +} + +const qreal &jpsGraphicsView::GetTranslationY() const +{ + return translation_y; +} + +const qreal &jpsGraphicsView::GetScaleF() const +{ + return gl_scale_f; +} + +void jpsGraphicsView::SetDatamanager(jpsDatamanager *datamanager) +{ + _datamanager=datamanager; +} + void jpsGraphicsView::mouseMoveEvent(QMouseEvent *mouseEvent) { @@ -182,6 +212,10 @@ void jpsGraphicsView::mouseMoveEvent(QMouseEvent *mouseEvent) //{ //emit set_focus_textedit(); current_line->setLine(current_line->line().x1(),current_line->line().y1(),translated_pos.x(),translated_pos.y()); + if (current_line->line().isNull()) + current_line->setVisible(false); + else + current_line->setVisible(true); //} //As line length has changed @@ -223,7 +257,9 @@ void jpsGraphicsView::mousePressEvent(QMouseEvent *mouseEvent) emit no_drawing(); } else + { drawLine(); + } } else if (statLandmark==true) { @@ -231,13 +267,27 @@ void jpsGraphicsView::mousePressEvent(QMouseEvent *mouseEvent) } else { + if (_statDefConnections==1) + { + emit DefConnection1Completed(); + } //LineEdit - if (_currentTrackedPoint!=nullptr && line_tracked==1) + else if (_currentTrackedPoint!=nullptr && line_tracked==1 && _statCopy==0) { EditLine(_currentTrackedPoint); _currentTrackedPoint=nullptr; line_tracked=-1; } + else if (_statCopy!=0) + { + if (_statCopy==1) + { + _copyOrigin=return_Pos(); + _statCopy += 1; + } + else + Copy_lines(return_Pos()-_copyOrigin); + } else { //Select_mode @@ -274,10 +324,13 @@ void jpsGraphicsView::mouseDoubleClickEvent(QMouseEvent *event) void jpsGraphicsView::unmark_all_lines() { + QPen pen = QPen(Qt::black,2); + pen.setCosmetic(true); for (int i=0; iget_line()->setPen(QPen(QColor(marked_lines[i]->get_defaultColor()),0)); + pen.setColor(QColor(marked_lines[i]->get_defaultColor())); + marked_lines[i]->get_line()->setPen(pen); } marked_lines.clear(); } @@ -292,15 +345,53 @@ void jpsGraphicsView::addLandmark() +pixmap.height()/1000.)); pixmapItem->setTransform(QTransform::fromScale(1,-1),true); pixmapItem->setTransform(QTransform::fromTranslate(translation_x,-translation_y), true); - QString name="Landmark"+QString::number(LLandmarks.size()); + QString name="Landmark"+QString::number(_datamanager->GetLandmarkCounter()); jpsLandmark* landmark = new jpsLandmark(pixmapItem,name,pixmapItem->scenePos()); + //text immediately under the pixmap + QGraphicsTextItem* text = Scene->addText(name); + text->setPos(QPointF(landmark->GetPos().x(), + landmark->GetPos().y()+0.2));// landmark->GetPos().x()+translation_x,landmark->GetPos().y()+translation_y); + //text->setScale(gl_scale_f); - LLandmarks.push_back(landmark); + text->setData(0,0.01); + text->setTransform(QTransform::fromScale(0.01,-0.01),true); - emit landmark_added(); + + landmark->SetPixMapText(text); + + _datamanager->new_landmark(landmark); } +void jpsGraphicsView::addLandmark(const QPointF &pos) +{ + QPixmap pixmap("../jupedsim/forms/statue.jpg"); + + QGraphicsPixmapItem* pixmapItem = Scene->addPixmap(pixmap); + pixmapItem->setScale(0.002); + pixmapItem->setTransform(QTransform::fromTranslate(pos.x()-pixmap.width()/1000.,pos.y() + +pixmap.height()/1000.)); + pixmapItem->setTransform(QTransform::fromScale(1,-1),true); + pixmapItem->setTransform(QTransform::fromTranslate(translation_x,-translation_y), true); + QString name="Landmark"+QString::number(_datamanager->GetLandmarkCounter()); + jpsLandmark* landmark = new jpsLandmark(pixmapItem,name,pos); + //text immediately under the pixmap + QGraphicsTextItem* text = Scene->addText(name); + text->setPos(QPointF(landmark->GetPos().x(), + landmark->GetPos().y()+0.2));// landmark->GetPos().x()+translation_x,landmark->GetPos().y()+translation_y); + //text->setScale(gl_scale_f); + + text->setTransform(QTransform::fromTranslate(translation_x,-translation_y), true); + text->setData(0,0.01); + text->setTransform(QTransform::fromScale(0.01,-0.01),true); + + + landmark->SetPixMapText(text); + + _datamanager->new_landmark(landmark); +} + + void jpsGraphicsView::unmarkLandmark() { @@ -313,37 +404,19 @@ void jpsGraphicsView::unmarkLandmark() } -QList jpsGraphicsView::get_landmarks() -{ - return LLandmarks; -} + QGraphicsRectItem *jpsGraphicsView::GetCurrentSelectRect() { return currentSelectRect; } -void jpsGraphicsView::ShowWaypoints(QList waypoints) +void jpsGraphicsView::SetStatDefConnections(const int &stat) { - ClearWaypoints(); - - for (ptrWaypoint waypoint:waypoints) - { - QGraphicsEllipseItem* ellipse = Scene->addEllipse(waypoint->GetRect(),QPen(Qt::blue,0)); - ellipse->setTransform(QTransform::fromTranslate(translation_x,translation_y), true); - QString string = waypoint->GetType() + "\n" + waypoint->GetCaption()+ "\n" + waypoint->GetText(); - QGraphicsTextItem* text = Scene->addText(string); - text->setPos(waypoint->GetPos().x()+translation_x,waypoint->GetPos().y()+translation_y); - //text->setScale(gl_scale_f); - text->setData(0,gl_scale_f); - text->setTransform(QTransform::fromScale(gl_scale_f,-gl_scale_f),true); - _waypoints.push_back(ellipse); - _waypointLabels.push_back(text); - } - - + _statDefConnections=stat; } + void jpsGraphicsView::ShowYAHPointer(const QPointF &pos, const qreal &dir) { for (QGraphicsLineItem* lineItem:_yahPointer) @@ -364,21 +437,13 @@ void jpsGraphicsView::ShowYAHPointer(const QPointF &pos, const qreal &dir) } -void jpsGraphicsView::ClearWaypointLabels() -{ - for (QGraphicsTextItem* label:_waypointLabels) - { - delete label; - } - _waypointLabels.clear(); -} void jpsGraphicsView::ShowConnections(QList cons) { ClearConnections(); for (ptrConnection con:cons) { - QGraphicsLineItem* line = Scene->addLine(QLineF(con->GetWaypoints().first->GetPos(),con->GetWaypoints().second->GetPos()),QPen(Qt::blue,0)); + QGraphicsLineItem* line = Scene->addLine(QLineF(con->GetLandmarks().first->GetPos(),con->GetLandmarks().second->GetPos()),QPen(Qt::blue,0)); _connections.push_back(line); @@ -399,19 +464,6 @@ void jpsGraphicsView::ClearConnections() -void jpsGraphicsView::ClearWaypoints() -{ - - //Waypoints - for (QGraphicsEllipseItem* old_waypoint:_waypoints) - { - delete old_waypoint; - } - _waypoints.clear(); - - ClearWaypointLabels(); - -} void jpsGraphicsView::ActivateLineGrid() { @@ -445,13 +497,23 @@ void jpsGraphicsView::mouseReleaseEvent(QMouseEvent *event) { leftbutton_hold=false; - if (currentSelectRect!=nullptr) + //for connection setting + if (_statDefConnections==2) + { + emit DefConnection2Completed(); + } + else if (currentSelectRect!=nullptr) { - if (_assoDef) + if (_posDef) { - //Waypoint definition - emit AssoDefCompleted(); - _assoDef=false; + //Landmark position definition + emit PositionDefCompleted(); + _posDef=false; + } + else if (_regionDef) + { + emit RegionDefCompleted(); + _regionDef=false; } else { @@ -483,13 +545,16 @@ void jpsGraphicsView::mouseReleaseEvent(QMouseEvent *event) -QPointF jpsGraphicsView::return_Pos() +const QPointF &jpsGraphicsView::return_Pos() const { return translated_pos; } void jpsGraphicsView::delete_all(bool final) { + unmark_all_lines(); + unmarkLandmark(); + if (!final) { int ret = QMessageBox::warning(this,"Delete?", "Do you really want to delete all elements?", QMessageBox::Yes | QMessageBox::No); @@ -523,19 +588,13 @@ void jpsGraphicsView::delete_all(bool final) } - for (jpsLandmark* landmark:LLandmarks) - { - delete landmark->get_pixmap(); - delete landmark; - } - for (QGraphicsEllipseItem* waypoint:_waypoints) - { - delete waypoint; - } + //delete landmarks + + _datamanager->remove_all_landmarks(); + intersect_point_vector.clear(); marked_lines.clear(); - LLandmarks.clear(); if (current_line!=nullptr) @@ -782,6 +841,7 @@ void jpsGraphicsView::drawLine() // all two points of the line are inited with the cursorcoordinates current_line = Scene->addLine(translated_pos.x(),translated_pos.y(),translated_pos.x(),translated_pos.y(),currentPen); + current_line->setVisible(false); //current_line->translate(translation_x,translation_y); current_line->setTransform(QTransform::fromTranslate(translation_x,translation_y), true); emit set_focus_textedit(); @@ -837,13 +897,17 @@ void jpsGraphicsView::select_line(jpsLineItem *mline) if (!marked_lines.contains(mline)) { - mline->get_line()->setPen(QPen(Qt::red,0)); + QPen pen = QPen(Qt::red,2); + pen.setCosmetic(true); + mline->get_line()->setPen(pen); marked_lines.push_back(mline); line_tracked=1; } else { - mline->get_line()->setPen(QPen(Qt::black,0)); + QPen pen = QPen(Qt::black,2); + pen.setCosmetic(true); + mline->get_line()->setPen(pen); marked_lines.removeOne(mline); } } @@ -856,6 +920,8 @@ void jpsGraphicsView::disable_drawing() statExit=false; statLandmark=false; _statLineEdit=false; + _statHLine=false; + _statCopy=0; // if drawing was canceled by pushing ESC if (current_line!=nullptr) { @@ -874,8 +940,10 @@ void jpsGraphicsView::disable_drawing() jpsLineItem* jpsGraphicsView::addLineItem(const qreal &x1,const qreal &y1,const qreal &x2,const qreal &y2,const QString &type) { + QPen pen = QPen(Qt::black,2); + pen.setCosmetic(true); - current_line=Scene->addLine(x1,y1,x2,y2); + current_line=Scene->addLine(x1,y1,x2,y2,pen); current_line->setTransform(QTransform::fromTranslate(translation_x,translation_y), true); jpsLineItem* newLine = new jpsLineItem(current_line); newLine->set_id(id_counter); @@ -898,7 +966,8 @@ jpsLineItem* jpsGraphicsView::addLineItem(const qreal &x1,const qreal &y1,const newLine->set_Wall(); } - current_line->setPen(QPen(QColor(newLine->get_defaultColor()),0)); + pen.setColor(newLine->get_defaultColor()); + newLine->get_line()->setPen(pen); // if line has already been added before (from another room) for (int i=0; iget_landmarks()) { - landmark->get_pixmap()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); + } if (currentLandmarkRect!=nullptr) @@ -1296,20 +1369,51 @@ void jpsGraphicsView::translations(QPointF old_pos) { gridmap->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); } - for (QGraphicsEllipseItem* ellipse:_waypoints) - { - ellipse->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); - } for (QGraphicsLineItem* lineItem:_yahPointer) { lineItem->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); } - for (QGraphicsTextItem* item:_waypointLabels) + for (jpsLandmark* landmark:_datamanager->get_landmarks()) + { + if (landmark->GetTextItem()!=nullptr) + { + qreal scalef = landmark->GetTextItem()->data(0).toReal(); + landmark->GetTextItem()->setTransform(QTransform::fromScale(1.0/scalef,1.0/scalef),true); // without this line translations won't work + landmark->GetTextItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); + landmark->GetTextItem()->setTransform(QTransform::fromScale(scalef,scalef),true); + } + + if (landmark->GetPixmapTextItem()!=nullptr) + { + qreal scalef = landmark->GetPixmapTextItem()->data(0).toReal(); + landmark->GetPixmapTextItem()->setTransform(QTransform::fromScale(1.0/scalef,1.0/scalef),true); // without this line translations won't work + landmark->GetPixmapTextItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); + landmark->GetPixmapTextItem()->setTransform(QTransform::fromScale(scalef,scalef),true); + } + + landmark->GetPixmap()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); + + if (landmark->GetEllipseItem()!=nullptr) + landmark->GetEllipseItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); + } + + for (jpsConnection* connection:_datamanager->GetAllConnections()) { - qreal scalef = item->data(0).toReal(); - item->setTransform(QTransform::fromScale(1.0/scalef,1.0/scalef),true); // without this line translations won't work - item->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); - item->setTransform(QTransform::fromScale(scalef,scalef),true); + connection->GetLineItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); + } + + for (jpsRegion* region:_datamanager->GetRegions()) + { + if (region->GetTextItem()!=nullptr) + { + qreal scalef = region->GetTextItem()->data(0).toReal(); + region->GetTextItem()->setTransform(QTransform::fromScale(1.0/scalef,1.0/scalef),true); // without this line translations won't work + region->GetTextItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),-pos.y()+old_pos.y()), true); + region->GetTextItem()->setTransform(QTransform::fromScale(scalef,scalef),true); + } + + if (region->GetEllipseItem()!=nullptr) + region->GetEllipseItem()->setTransform(QTransform::fromTranslate(pos.x()-old_pos.x(),pos.y()-old_pos.y()), true); } for (QGraphicsLineItem* lineItem:_connections) @@ -1454,9 +1558,14 @@ void jpsGraphicsView::ShowOrigin() } } -void jpsGraphicsView::StatAssoDef() +void jpsGraphicsView::StatPositionDef() { - _assoDef=!_assoDef; + _posDef=!_posDef; +} + +void jpsGraphicsView::ChangeRegionStatDef() +{ + _regionDef=!_regionDef; } @@ -1579,9 +1688,7 @@ void jpsGraphicsView::delete_landmark() { if (markedLandmark!=nullptr) { - LLandmarks.removeOne(markedLandmark); - delete markedLandmark->get_pixmap(); - delete markedLandmark; + _datamanager->remove_landmark(markedLandmark); markedLandmark=nullptr; delete currentLandmarkRect; currentLandmarkRect=nullptr; @@ -1593,10 +1700,10 @@ void jpsGraphicsView::catch_landmark() { if (currentSelectRect!=nullptr) { - for (jpsLandmark* landmark:LLandmarks) + for (jpsLandmark* landmark:_datamanager->get_landmarks()) { - if (currentSelectRect->contains(QPointF(landmark->get_pixmap()->scenePos().x()-translation_x, - landmark->get_pixmap()->scenePos().y()-translation_y))) + if (currentSelectRect->contains(QPointF(landmark->GetPixmap()->scenePos().x()-translation_x, + landmark->GetPixmap()->scenePos().y()-translation_y))) { select_landmark(landmark); return; @@ -1607,8 +1714,9 @@ void jpsGraphicsView::catch_landmark() void jpsGraphicsView::select_landmark(jpsLandmark* landmark) { + unmarkLandmark(); currentLandmarkRect=Scene->addRect( - landmark->get_pixmap()->mapRectToScene(landmark->get_pixmap()->pixmap().rect()),QPen(Qt::red,0)); + landmark->GetPixmap()->mapRectToScene(landmark->GetPixmap()->pixmap().rect()),QPen(Qt::red,0)); markedLandmark=landmark; } @@ -1766,6 +1874,7 @@ void jpsGraphicsView::en_disableHLine() statDoor=false; statWall=false; statLandmark=false; + _statCopy=0; if (_statHLine==false) { emit no_drawing(); @@ -1787,6 +1896,7 @@ void jpsGraphicsView::en_disableLandmark() statDoor=false; statWall=false; statExit=false; + _statCopy=0; if (statLandmark==false) { emit no_drawing(); @@ -1798,13 +1908,20 @@ bool jpsGraphicsView::statusExit() return statExit; } +void jpsGraphicsView::start_Copy_function() +{ + _statCopy=1; +} - - - - - - - - - +void jpsGraphicsView::Copy_lines(const QPointF& delta) +{ + for (jpsLineItem* line:marked_lines) + { + addLineItem(line->get_line()->line().p1().x()+delta.x(), + line->get_line()->line().p1().y()+delta.y(), + line->get_line()->line().p2().x()+delta.x(), + line->get_line()->line().p2().y()+delta.y(), + line->GetType()); + } + _statCopy=0; +} diff --git a/src/GraphicView.h b/src/GraphicView.h index e72eb847602aab6192ae783019ae7e2f6bd3adc2..227e78a8c4aaa7f9da822bf6f32b9106898fcfc7 100644 --- a/src/GraphicView.h +++ b/src/GraphicView.h @@ -1,7 +1,7 @@ /** * \file GraphicView.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -39,6 +39,9 @@ #include "./UndoFramework/actionstack.h" using ptrConnection = std::shared_ptr; +using ptrLandmark = std::shared_ptr; + +class jpsDatamanager; class jpsGraphicsView: public QGraphicsView { @@ -46,11 +49,22 @@ class jpsGraphicsView: public QGraphicsView { public: //Constructor - jpsGraphicsView(QWidget* parent = nullptr); + jpsGraphicsView(QWidget* parent = nullptr, jpsDatamanager* datamanager=nullptr); //Destructor ~jpsGraphicsView(); + QGraphicsScene* GetScene(); + const qreal& GetTranslationX() const; + const qreal& GetTranslationY() const; + const qreal& GetScaleF() const; + + //Pos + const QPointF& return_Pos() const; + + + void SetDatamanager(jpsDatamanager* datamanager); + //Change modes void change_stat_anglesnap(); bool get_stat_anglesnap(); @@ -82,8 +96,6 @@ public: qreal CalcGridSize(); void ShowOrigin(); - //Pos - QPointF return_Pos(); //Catch lines, points and intersections void catch_points(); @@ -111,20 +123,22 @@ public: void SetVLine(); void EditLine(QPointF* point); qreal ReturnLineLength(); + void start_Copy_function(); + void Copy_lines(const QPointF& delta); // Landmark void delete_landmark(); void catch_landmark(); void select_landmark(jpsLandmark *landmark); void addLandmark(); + void addLandmark(const QPointF& pos); // unmark Landmarks see slots - QList get_landmarks(); - //Waypoints/Connections and YAHPointer + //Connections and YAHPointer QGraphicsRectItem* GetCurrentSelectRect(); - void ShowWaypoints(QList waypoints); + void SetStatDefConnections(const int& stat); + void ShowYAHPointer(const QPointF& pos, const qreal& dir); - void ClearWaypointLabels(); void ShowConnections(QList cons); void ClearConnections(); @@ -138,9 +152,9 @@ public: void RedoLineEdit(const int &lineID, const QLineF &old_line); public slots: - //Waypoints - void StatAssoDef(); - void ClearWaypoints(); + //Landmarks/Regions + void StatPositionDef(); + void ChangeRegionStatDef(); //GridSettings void ActivateLineGrid(); void ActivatePointGrid(); @@ -162,6 +176,7 @@ protected: virtual void mouseReleaseEvent(QMouseEvent *event); private: + jpsDatamanager* _datamanager; QGraphicsLineItem* current_line; QPolygonF polygon; //std::vector line_vector; @@ -184,6 +199,8 @@ private: bool statExit; bool statLandmark; bool _statHLine; + int _statCopy; + QPointF _copyOrigin; qreal catch_radius; qreal _scaleFactor; qreal gl_scale_f; @@ -202,20 +219,20 @@ private: int id_counter; //Landmark and waypoints - QList LLandmarks; jpsLandmark* markedLandmark; QGraphicsRectItem* currentLandmarkRect; - QList _waypoints; QList _connections; QList _yahPointer; QList _waypointLabels; + int _statDefConnections; + bool _regionDef; + bool _posDef; QGraphicsLineItem* _currentVLine; QPointF* _currentTrackedPoint; QGraphicsPixmapItem* gridmap; bool _statLineEdit; bool lines_collided; - bool _assoDef; bool _gridmode; //Undo/Redo @@ -230,9 +247,11 @@ signals: void no_drawing(); void remove_marked_lines(); void remove_all(); - void landmark_added(); - void AssoDefCompleted(); + void PositionDefCompleted(); void LineLengthChanged(); + void DefConnection1Completed(); + void DefConnection2Completed(); + void RegionDefCompleted(); //void DoubleClick(); }; diff --git a/src/UndoFramework/action.cpp b/src/UndoFramework/action.cpp index 43f7b4b86daceabedd951e097a3391515c11540e..2c4754b52039d2728ddc2dcdf8d5feb18a60c901 100644 --- a/src/UndoFramework/action.cpp +++ b/src/UndoFramework/action.cpp @@ -1,3 +1,27 @@ +/** + * \file action.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "action.h" Action::Action() diff --git a/src/UndoFramework/action.h b/src/UndoFramework/action.h index c38c6d649bc3da7b7707ca97e90d286101bb3690..575c3535bec1dec7ea5ee3b36bcfad3cb36cf30e 100644 --- a/src/UndoFramework/action.h +++ b/src/UndoFramework/action.h @@ -1,3 +1,27 @@ +/** + * \file action.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef ACTION_H #define ACTION_H #include diff --git a/src/UndoFramework/actionstack.cpp b/src/UndoFramework/actionstack.cpp index 84bf454ecd7b7bbc29aff7f8f815ff91ce5128b6..0ffbc9a590dbd7389f2eb66d499eecbb0ea92d31 100644 --- a/src/UndoFramework/actionstack.cpp +++ b/src/UndoFramework/actionstack.cpp @@ -1,3 +1,27 @@ +/** + * \file actionstack.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "actionstack.h" ActionStack::ActionStack() diff --git a/src/UndoFramework/actionstack.h b/src/UndoFramework/actionstack.h index 364f7f54a387b69922347766693d9fc435cba5ca..7454ad8e5b444bfc7a03018a521612559751640a 100644 --- a/src/UndoFramework/actionstack.h +++ b/src/UndoFramework/actionstack.h @@ -1,3 +1,27 @@ +/** + * \file actionstack.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef ACTIONSTACK_H #define ACTIONSTACK_H diff --git a/src/UndoFramework/lineaction.cpp b/src/UndoFramework/lineaction.cpp index 9bc9523366ea8e8bd70a7b7a4b6885badb11ae32..0418545c40a1a785d7b557c4e2b5e376465c26e7 100644 --- a/src/UndoFramework/lineaction.cpp +++ b/src/UndoFramework/lineaction.cpp @@ -1,3 +1,27 @@ +/** + * \file lineaction.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "lineaction.h" LineAction::LineAction() diff --git a/src/UndoFramework/lineaction.h b/src/UndoFramework/lineaction.h index e61f2662b3c6bc7ab3e94df87814e36f379961da..e43d2c7217d7ec621cd8e0a38a775188766b580f 100644 --- a/src/UndoFramework/lineaction.h +++ b/src/UndoFramework/lineaction.h @@ -1,3 +1,27 @@ +/** + * \file lineaction.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef LINEACTION_H #define LINEACTION_H diff --git a/src/datamanager.cpp b/src/datamanager.cpp index 5f35521d7145a2f24208b139da9da88ccfd25599..a75b9278d8f5eaf0492bb996f5a2195a79d878d2 100644 --- a/src/datamanager.cpp +++ b/src/datamanager.cpp @@ -1,7 +1,7 @@ /** * \file datamanager.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -30,23 +30,27 @@ #include "datamanager.h" #include #include - - +#include +#include +#include jpsDatamanager::jpsDatamanager(QWidget *parent, jpsGraphicsView *view) { parent_widget=parent; - mView=view; + _mView=view; room_id_counter=0; obs_id_counter=0; _yahPointer=nullptr; _frameRate=0; + _landmarkCounter=0; + _regionCounter=0; } jpsDatamanager::~jpsDatamanager() { //remove_all(); vmiew->delete_all() does this work + remove_all(); } void jpsDatamanager::new_room() @@ -228,33 +232,123 @@ void jpsDatamanager::remove_all_exits() QList jpsDatamanager::get_landmarks() { - return landmarks; + return _landmarks; } void jpsDatamanager::new_landmark(jpsLandmark *newlandmark) { - landmarks.push_back(newlandmark); + newlandmark->SetId(_landmarkCounter); + _landmarkCounter++; + _landmarks.push_back(newlandmark); } void jpsDatamanager::remove_landmark(jpsLandmark *landmark) { - landmarks.removeOne(landmark); + _landmarks.removeOne(landmark); + for (jpsConnection* connection:landmark->GetConnections()) + { + RemoveConnection(connection); + } + delete landmark; + _landmarkCounter++; } void jpsDatamanager::change_LandmarkName(jpsLandmark *landmark, QString name) { - landmark->set_name(name); + landmark->SetCaption(name); } void jpsDatamanager::remove_all_landmarks() { - landmarks.clear(); + for (jpsLandmark* landmark:_landmarks) + { + delete landmark; + } + _landmarks.clear(); +} + +const int &jpsDatamanager::GetLandmarkCounter() const +{ + return _landmarkCounter; +} + +const QList &jpsDatamanager::GetAllConnections() const +{ + return _landmarkConnections; +} + +void jpsDatamanager::NewConnection(jpsConnection *newConnection) +{ + _landmarkConnections.push_back(newConnection); +} + +void jpsDatamanager::RemoveConnection(jpsConnection *connection) +{ + _landmarkConnections.removeOne(connection); + connection->GetLandmarks().first->RemoveConnection(connection); + connection->GetLandmarks().second->RemoveConnection(connection); + delete connection->GetLineItem(); + delete connection; +} + +void jpsDatamanager::RemoveAllConnections() +{ + for (jpsConnection* connection:_landmarkConnections) + { + delete connection->GetLineItem(); + delete connection; + + //remove also from _ConnectionsAfterLandmarkLoose + if (_ConnectionsAfterLandmarkLoose.contains(connection)) + { + _ConnectionsAfterLandmarkLoose.removeOne(connection); + } + } + _landmarkConnections.clear(); + + for (jpsConnection* connection:_ConnectionsAfterLandmarkLoose) + { + delete connection; + } + _ConnectionsAfterLandmarkLoose.clear(); +} + +const QList &jpsDatamanager::GetRegions() const +{ + return _regions; +} + +void jpsDatamanager::NewRegion(jpsRegion *region) +{ + _regions.push_back(region); + _regionCounter++; +} + +void jpsDatamanager::RemoveRegion(jpsRegion *region) +{ + _regions.removeOne(region); + delete region; + +} + +void jpsDatamanager::RemoveAllRegions() +{ + for (jpsRegion* region:_regions) + { + delete region; + } + _regions.clear(); +} + +const int &jpsDatamanager::GetRegionCounter() const +{ + return _regionCounter; } void jpsDatamanager::writeXML(QFile &file) { QXmlStreamWriter* stream = new QXmlStreamWriter(&file); - QList lines = mView->get_line_vector(); + QList lines = _mView->get_line_vector(); writeHeader(stream); stream->writeStartElement("rooms"); @@ -266,10 +360,6 @@ void jpsDatamanager::writeXML(QFile &file) exitList.clear(); stream->writeEndElement();//transitions - stream->writeStartElement("landmarks"); - writeLandmarks(stream,landmarks); - stream->writeEndElement();//landmarks - stream->writeEndElement();//geometry stream->writeEndDocument(); @@ -282,7 +372,7 @@ void jpsDatamanager::writeRoutingXML(QFile &file) // Construction side QXmlStreamWriter* stream = new QXmlStreamWriter(&file); QList hLines; - for (jpsLineItem* line:mView->get_line_vector()) + for (jpsLineItem* line:_mView->get_line_vector()) { if (line->IsHLine()) { @@ -303,10 +393,86 @@ void jpsDatamanager::writeRoutingXML(QFile &file) // Construction side } +void jpsDatamanager::WriteCognitiveMapXML(QFile &file, bool fuzzy) +{ + QXmlStreamWriter* stream = new QXmlStreamWriter(&file); + WriteCognitiveMapHeader(stream); + + //write regions incl. their landmarks and connections + stream->writeStartElement("regions"); + WriteRegions(stream,fuzzy); + stream->writeEndElement();//regions + + stream->writeEndElement();//cognitiveMap + + stream->writeEndDocument(); + + delete stream; +} + +void jpsDatamanager::WriteCognitiveMapHeader(QXmlStreamWriter *stream) +{ + stream->setAutoFormatting(true); + stream->writeStartDocument("1.0",true); + + stream->writeStartElement("cognitiveMap"); + stream->writeAttribute("version", "0.81"); + stream->writeAttribute("caption","cogMap"); + stream->writeAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); + stream->writeAttribute("xsi:noNamespaceSchemaLocation","http://xsd.jupedsim.org/jps_geometry.xsd"); + stream->writeAttribute("unit","m"); +} + +void jpsDatamanager::WriteRegions(QXmlStreamWriter *stream, bool fuzzy) +{ + for (jpsRegion* region:_regions) + { + stream->writeStartElement("region"); + + int id = region->GetId(); + QString caption = region->GetCaption(); + qreal px = region->GetPos().x(); + qreal py = region->GetPos().y(); + qreal a = region->GetA(); + qreal b = region->GetB(); + + if (fuzzy) + { + px = MakeItFuzzy(px,a/2.0); + py = MakeItFuzzy(py,b/2.0); + a = MakeItFuzzy(a,a/2.0); + if (a<0.5) + a=0.5; + b= MakeItFuzzy(b,b/2.0); + if (b<0.5) + b=0.5; + } + + + stream->writeAttribute("id",QString::number(id)); + stream->writeAttribute("caption",caption); + stream->writeAttribute("px",QString::number(px)); + stream->writeAttribute("py",QString::number(py)); + stream->writeAttribute("a",QString::number(a)); + stream->writeAttribute("b",QString::number(b)); + + + stream->writeStartElement("landmarks"); + WriteLandmarks(region,stream,fuzzy); + stream->writeEndElement();//landmarks + + stream->writeStartElement("connections"); + WriteConnections(region,stream); + stream->writeEndElement();//connections + + stream->writeEndElement();//region + } +} + void jpsDatamanager::AutoSaveXML(QFile &file) { QXmlStreamWriter* stream = new QXmlStreamWriter(&file); - QList lines = mView->get_line_vector(); + QList lines = _mView->get_line_vector(); writeHeader(stream); stream->writeStartElement("rooms"); @@ -319,9 +485,9 @@ void jpsDatamanager::AutoSaveXML(QFile &file) exitList.clear(); stream->writeEndElement();//transitions - stream->writeStartElement("landmarks"); - writeLandmarks(stream,landmarks); - stream->writeEndElement();//landmarks +// stream->writeStartElement("landmarks"); +// writeLandmarks(stream,landmarks); +// stream->writeEndElement();//landmarks stream->writeEndElement();//geometry @@ -368,7 +534,7 @@ void jpsDatamanager::writeHLines(QXmlStreamWriter *stream, QList QString rid = RoomIDHLine(lineItem); if (rid.contains("Warning")) { - QMessageBox::critical(mView, + QMessageBox::critical(_mView, "WriteHLines", rid, QMessageBox::Ok); @@ -760,46 +926,263 @@ void jpsDatamanager::writeNotAssignedExits(QXmlStreamWriter *stream, QList &landmarks) +void jpsDatamanager::WriteLandmarks(jpsRegion* cRegion, QXmlStreamWriter *stream, bool fuzzy) +{ + + //cut some landmarks and/or their connections + _ConnectionsAfterLandmarkLoose=_landmarkConnections; + _landmarksAfterLoose=_landmarks; + if (fuzzy) + CutOutLandmarks(); + + for (jpsLandmark* landmark:_landmarksAfterLoose) + { + if (landmark->GetRegion()==cRegion) + { + int id = landmark->GetId(); + QString caption = landmark->GetCaption(); + QString type = landmark->GetType(); + if (type=="Main Target") + type="main"; + int id_subroom; + if (landmark->GetRoom()!=nullptr) + id_subroom = landmark->GetRoom()->get_id(); + else + id_subroom = -1; + qreal pxreal = landmark->GetRealPos().x(); + qreal pyreal = landmark->GetRealPos().y(); + qreal px = landmark->GetPos().x(); + qreal py = landmark->GetPos().y(); + qreal a = landmark->GetA(); + qreal b = landmark->GetB(); + + if (fuzzy) + { + px = MakeItFuzzy(px,a/5.0); + py = MakeItFuzzy(py,b/5.0); + a = MakeItFuzzy(a,a/3.0); + if (a<0.5) + a=0.5; + b = MakeItFuzzy(b,b/3.0); + if (b<0.5) + b=0.5; + } + + + stream->writeStartElement("landmark"); + + stream->writeAttribute("id",QString::number(id)); + stream->writeAttribute("caption",caption); + stream->writeAttribute("type",type); + stream->writeAttribute("room1_id","0"); + if (landmark->GetRoom()!=nullptr) + stream->writeAttribute("subroom1_id",QString::number(id_subroom)); + else + stream->writeAttribute("subroom1_id","NaN"); + stream->writeAttribute("pxreal",QString::number(pxreal)); + stream->writeAttribute("pyreal",QString::number(pyreal)); + stream->writeAttribute("px",QString::number(px)); + stream->writeAttribute("py",QString::number(py)); + stream->writeAttribute("a",QString::number(a)); + stream->writeAttribute("b",QString::number(b)); + + stream->writeStartElement("associations"); + // + stream->writeEndElement();//associations + stream->writeEndElement();//landmark + } + + } + + +} + +void jpsDatamanager::CutOutLandmarks() { - int m=0; + using myClock = std::chrono::high_resolution_clock; + + int numberMainTargets = GetNumberOfMainTargets(); + int statcutMainTarget= numberMainTargets; + + int number; int n=0; - for (jpsLandmark* landmark:landmarks) + for (jpsLandmark* landmark:_landmarksAfterLoose) { - stream->writeStartElement("landmark"); + // at least one main target will be kept + if (landmark->GetType()=="main" || landmark->GetType()=="Main Target") + { + if (numberMainTargets==1) + continue; + else if (statcutMainTarget==1) + continue; + } - stream->writeAttribute("id",QString::number(n)); - stream->writeAttribute("caption",landmark->get_name()); - stream->writeAttribute("type","NaN"); - stream->writeAttribute("room1_id","0"); - if (landmark->get_room()!=nullptr) - stream->writeAttribute("subroom1_id",QString::number(landmark->get_room()->get_id())); - else - stream->writeAttribute("subroom1_id","NaN"); - stream->writeAttribute("px",QString::number(landmark->get_pos().x())); - stream->writeAttribute("py",QString::number(landmark->get_pos().y())); - stream->writeStartElement("associations"); + myClock::duration d = myClock::now().time_since_epoch(); + + auto seed = d.count()+n; + + std::default_random_engine generator(seed); + + std::discrete_distribution distribution({ 30,70 }); + + number = distribution(generator); - for (ptrWaypoint waypoint:landmark->GetWaypoints()) + if (!number) { - stream->writeStartElement("association"); - stream->writeAttribute("id",QString::number(m)); - stream->writeAttribute("caption","Waypoint"); - stream->writeAttribute("type","NaN"); - stream->writeAttribute("px",QString::number(waypoint->GetPos().x())); - stream->writeAttribute("py",QString::number(waypoint->GetPos().y())); - stream->writeAttribute("a",QString::number(waypoint->GetA())); - stream->writeAttribute("b",QString::number(waypoint->GetB())); - stream->writeEndElement();//association - m++; + if (landmark->GetType()=="main" || landmark->GetType()=="Main Target") + statcutMainTarget--; + _landmarksAfterLoose.removeOne(landmark); + BridgeLostLandmark(landmark); } - stream->writeEndElement();//associations - stream->writeEndElement();//landmark n++; + } } +void jpsDatamanager::BridgeLostLandmark(jpsLandmark *landmark) +{ + // if landmark was removed from the landmarknetwork adjacent connected + // landmarks will be connected with each other (if random engine returns 1) + + using myClock = std::chrono::high_resolution_clock; + + QList connectedLandmarks; + QList connections = landmark->GetConnections(); + + int n=0; + + for (jpsConnection* connection:connections) + { + _ConnectionsAfterLandmarkLoose.removeOne(connection); + + myClock::duration d = myClock::now().time_since_epoch(); + + auto seed = d.count()+n; + + std::default_random_engine generator(seed); + + std::discrete_distribution distribution({ 20, 80 }); + + int number = distribution(generator); + + if (number) + { + std::pair lPair = connection->GetLandmarks(); + if (lPair.first!=landmark) + connectedLandmarks.push_back(lPair.first); + else + connectedLandmarks.push_back(lPair.second); + } + n++; + } + + for (jpsLandmark* connectedLandmark:connectedLandmarks) + { + for (jpsLandmark* connectedLandmark2:connectedLandmarks) + { + if (connectedLandmark!=connectedLandmark2) + { + bool status=false; + jpsConnection* newConnection = new jpsConnection(connectedLandmark,connectedLandmark2); + for (jpsConnection* connection:_ConnectionsAfterLandmarkLoose) + { + if (*connection==*newConnection) + { + status=true; + } + } + if (!status) + _ConnectionsAfterLandmarkLoose.push_back(newConnection); + } + } + } + +} + +void jpsDatamanager::WriteConnections(jpsRegion* cRegion, QXmlStreamWriter *stream) +{ + int n=0; + for (jpsConnection* connection:_ConnectionsAfterLandmarkLoose) + { + // only write connection if adjacent landmark is still there + if (_landmarksAfterLoose.contains(connection->GetLandmarks().first) && _landmarksAfterLoose.contains(connection->GetLandmarks().second)) + { + if (connection->GetLandmarks().first->GetRegion()==cRegion) + { + stream->writeStartElement("connection"); + + stream->writeAttribute("id",QString::number(n)); + stream->writeAttribute("caption","Connection "+QString::number(n)); + stream->writeAttribute("type","Not specified"); + stream->writeAttribute("landmark1_id",QString::number(connection->GetLandmarks().first->GetId())); + stream->writeAttribute("landmark2_id",QString::number(connection->GetLandmarks().second->GetId())); + + stream->writeEndElement();//connection + n++; + } + } + + } +} + +void jpsDatamanager::CreateAndSaveASimilarCogMap(const int& id) +{ + //Filename of first cognitivemap + QString filename; + if (id==0) + { + _currentCogMapFileName = QFileDialog::getSaveFileName(this->parent_widget,QFileDialog::tr("Save CognitiveMap XML"),"",QFileDialog::tr("XML-Files (*.xml)")); + if (_currentCogMapFileName.isEmpty()) return; + _currentCogMapFileName.remove(".xml"); + filename=_currentCogMapFileName+QString::number(id)+".xml"; + } + else + { + filename=_currentCogMapFileName+QString::number(id)+".xml"; + } + QFile file(filename); + + + if(file.open(QIODevice::WriteOnly|QIODevice::Text)) + { + if (id==0) + WriteCognitiveMapXML(file,false); + else + WriteCognitiveMapXML(file,true); + + } + +} + +qreal jpsDatamanager::MakeItFuzzy(const qreal& mean, const qreal &std) +{ + using myClock = std::chrono::high_resolution_clock; + myClock::duration d = myClock::now().time_since_epoch(); + + auto seed = d.count(); + + std::default_random_engine generator(seed); + std::normal_distribution distribution(mean,std); + + double number = distribution(generator); + + return number; +} + +int jpsDatamanager::GetNumberOfMainTargets() const +{ + int counter=0; + for (jpsLandmark* landmark:_landmarks) + { + if (landmark->GetType()=="main" || landmark->GetType()=="Main Target") + { + counter++; + } + } + return counter; +} + void jpsDatamanager::remove_all() { remove_all_crossings(); @@ -807,6 +1190,8 @@ void jpsDatamanager::remove_all() remove_all_obstacles(); remove_all_rooms(); remove_all_landmarks(); + RemoveAllConnections(); + RemoveAllRegions(); room_id_counter=0; obs_id_counter=0; @@ -814,7 +1199,7 @@ void jpsDatamanager::remove_all() void jpsDatamanager::remove_marked_lines() { - QList marked_lines = mView->get_markedLines(); + QList marked_lines = _mView->get_markedLines(); for (int i=0; iis_Wall()==true) @@ -852,12 +1237,12 @@ void jpsDatamanager::remove_marked_lines() void jpsDatamanager::set_view(jpsGraphicsView *view) { - mView=view; + _mView=view; } jpsGraphicsView * jpsDatamanager::get_view() { - return mView; + return _mView; } //void jpsDatamanager::AutoAssignCrossings() @@ -1024,7 +1409,7 @@ bool jpsDatamanager::readXML(QFile &file) /* Error handling. */ if(xmlReader.hasError()) { - QMessageBox::critical(mView, + QMessageBox::critical(_mView, "QXSRExample::parseXML", xmlReader.errorString(), QMessageBox::Ok); @@ -1077,7 +1462,7 @@ bool jpsDatamanager::readRoutingXML(QFile &file) /* Error handling. */ if(xmlReader.hasError()) { - QMessageBox::critical(mView, + QMessageBox::critical(_mView, "QXSRExample::parseXML", xmlReader.errorString(), QMessageBox::Ok); @@ -1114,7 +1499,7 @@ void jpsDatamanager::parseHline(QXmlStreamReader &xmlReader) qreal x2=xmlReader.attributes().value("px").toString().toFloat(); qreal y2=xmlReader.attributes().value("py").toString().toFloat(); // add Line to graphview - mView->addLineItem(x1,y1,x2,y2,"HLine"); + _mView->addLineItem(x1,y1,x2,y2,"HLine"); } } @@ -1133,7 +1518,6 @@ void jpsDatamanager::parseSubRoom(QXmlStreamReader &xmlReader) /* We'll add it to the room. */ roomlist.last()->change_name(attributes.value("caption").toString()); - if(attributes.hasAttribute("class")) { if (attributes.value("class").toString()=="subroom") @@ -1187,7 +1571,7 @@ void jpsDatamanager::parseWalls(QXmlStreamReader &xmlReader, jpsRoom *room) qreal x2=xmlReader.attributes().value("px").toString().toFloat(); qreal y2=xmlReader.attributes().value("py").toString().toFloat(); // add Line to graphview - jpsLineItem* lineItem = mView->addLineItem(x1,y1,x2,y2,"Wall"); + jpsLineItem* lineItem = _mView->addLineItem(x1,y1,x2,y2,"Wall"); room->addWall(lineItem); @@ -1227,7 +1611,7 @@ void jpsDatamanager::parseWalls(QXmlStreamReader &xmlReader, jpsObstacle *room) qreal x2=xmlReader.attributes().value("px").toString().toFloat(); qreal y2=xmlReader.attributes().value("py").toString().toFloat(); // add Line to graphview - jpsLineItem* lineItem = mView->addLineItem(x1,y1,x2,y2,"Wall"); + jpsLineItem* lineItem = _mView->addLineItem(x1,y1,x2,y2,"Wall"); room->addWall(lineItem); @@ -1259,7 +1643,7 @@ void jpsDatamanager::parseCrossings(QXmlStreamReader &xmlReader) qreal x2=xmlReader.attributes().value("px").toString().toFloat(); qreal y2=xmlReader.attributes().value("py").toString().toFloat(); - jpsLineItem* lineItem = mView->addLineItem(x1,y1,x2,y2,"Door"); + jpsLineItem* lineItem = _mView->addLineItem(x1,y1,x2,y2,"Door"); if (id!=-2) { @@ -1314,7 +1698,7 @@ void jpsDatamanager::parseTransitions(QXmlStreamReader &xmlReader) qreal x2=xmlReader.attributes().value("px").toString().toFloat(); qreal y2=xmlReader.attributes().value("py").toString().toFloat(); - jpsLineItem* lineItem = mView->addLineItem(x1,y1,x2,y2,"Exit"); + jpsLineItem* lineItem = _mView->addLineItem(x1,y1,x2,y2,"Exit"); if (id!=-2) { jpsCrossing* exit = new jpsCrossing(lineItem); @@ -1376,7 +1760,7 @@ bool jpsDatamanager::readDXF(std::string filename) else { ///AutoZoom to contents (items of Scene) - mView->AutoZoom(); + _mView->AutoZoom(); return true; } @@ -1388,11 +1772,11 @@ void jpsDatamanager::addLine(const DL_LineData &d) std::string layername = attributes.getLayer(); std::transform(layername.begin(), layername.end(), layername.begin(), ::tolower); if (layername=="wall") - mView->addLineItem(d.x1,d.y1,d.x2,d.y2,"Wall"); + _mView->addLineItem(d.x1,d.y1,d.x2,d.y2,"Wall"); else if (layername=="door") - mView->addLineItem(d.x1,d.y1,d.x2,d.y2,"Door"); + _mView->addLineItem(d.x1,d.y1,d.x2,d.y2,"Door"); else - mView->addLineItem(d.x1,d.y1,d.x2,d.y2); + _mView->addLineItem(d.x1,d.y1,d.x2,d.y2); } @@ -1573,7 +1957,7 @@ void jpsDatamanager::writeDXFEntities(DL_Dxf *dxf, DL_WriterA *dw) //DL_Attributes("mainlayer", 256, 256, -1, "BYLAYER")); - QList lines = mView->get_line_vector(); + QList lines = _mView->get_line_vector(); DL_Attributes attribute("mainlayer", 256, 256, -1, "BYLAYER"); @@ -1653,6 +2037,7 @@ QString jpsDatamanager::check_printAbility() bool jpsDatamanager::ParseCogMap(QFile &file) { QXmlStreamReader xmlReader(&file); + jpsRegion* actRegion=nullptr; while(!xmlReader.atEnd() && !xmlReader.hasError()) { @@ -1672,24 +2057,42 @@ bool jpsDatamanager::ParseCogMap(QFile &file) { continue; } - if(xmlReader.name() == "header") +// if(xmlReader.name() == "header") +// { +// continue; +// } + if(xmlReader.name() == "regions") + { + continue; + } + if (xmlReader.name()=="region") + { + actRegion=ParseRegion(xmlReader); + } + if(xmlReader.name() == "landmarks") { continue; } - if(xmlReader.name() == "frameRate") + if(xmlReader.name() == "landmark") { - _frameRate=xmlReader.readElementText().toFloat(); + if (actRegion!=nullptr) + ParseLandmark(actRegion,xmlReader); } - if(xmlReader.name() == "frame") + if(xmlReader.name() == "connections") { - ParseFrames(xmlReader); + continue; + } + if(xmlReader.name() == "connection") + { + if (actRegion!=nullptr) + ParseConnection(actRegion,xmlReader); } } } /* Error handling. */ if(xmlReader.hasError()) { - QMessageBox::critical(mView, + QMessageBox::critical(_mView, "QXSRExample::parseXML", xmlReader.errorString(), QMessageBox::Ok); @@ -1703,215 +2106,196 @@ bool jpsDatamanager::ParseCogMap(QFile &file) return true; } -void jpsDatamanager::ParseFrames(QXmlStreamReader &xmlReader) +void jpsDatamanager::ParseLandmark(jpsRegion *actRegion, QXmlStreamReader &xmlReader) { - int frameID= xmlReader.attributes().value("ID").toString().toInt(); + int id = xmlReader.attributes().value("id").toString().toInt(); + QString caption = xmlReader.attributes().value("caption").toString(); + QString type = xmlReader.attributes().value("type").toString(); + //int roomId = xmlReader.attributes().value("room1_id").toString().toInt(); + int subroomId = xmlReader.attributes().value("subroom1_id").toString().toInt(); + qreal real_x = xmlReader.attributes().value("pxreal").toString().toFloat(); + qreal real_y = xmlReader.attributes().value("pyreal").toString().toFloat(); + qreal x = xmlReader.attributes().value("px").toString().toFloat(); + qreal y = xmlReader.attributes().value("py").toString().toFloat(); + qreal rA = xmlReader.attributes().value("a").toString().toFloat(); + qreal rB = xmlReader.attributes().value("b").toString().toFloat(); - while(!(xmlReader.tokenType() == QXmlStreamReader::EndElement && - xmlReader.name() == "frame")) + + //create landmark incl. pixmap + _mView->addLandmark(QPointF(real_x,real_y)); + + _landmarks.back()->SetId(id); + _landmarks.back()->SetCaption(caption); + _landmarks.back()->SetType(type); + + for (jpsRoom* room:roomlist) { - if (xmlReader.tokenType()==QXmlStreamReader::StartElement && - xmlReader.name() == "YAHPointer") - { - ParseYAHPointer(xmlReader, frameID); - } - else if (xmlReader.tokenType()==QXmlStreamReader::StartElement && - xmlReader.name() == "landmark") - { - ParseLandmarksInCMap(xmlReader, frameID); - } - else if (xmlReader.tokenType()==QXmlStreamReader::StartElement && - xmlReader.name() == "waypoint") - { - ParseWaypointInCMap(xmlReader, frameID); - } - else if (xmlReader.tokenType()==QXmlStreamReader::StartElement && - xmlReader.name() == "connection") + if (room->get_id()==subroomId) { - ParseConnectionsInCMap(xmlReader, frameID); + _landmarks.back()->SetRoom(room); + break; } - xmlReader.readNext(); } + _landmarks.back()->SetRect(QRectF(QPointF(x-rA,y+rB),QPointF(x+rA,y-rB))); - _lastCMapFrame=frameID; -} + // Ellipse + // show ellipse and text in graphics view + QPen pen = QPen(Qt::blue,2); + pen.setCosmetic(true); + QGraphicsEllipseItem* ellipse = _mView->GetScene()->addEllipse(_landmarks.back()->GetRect(),pen); + ellipse->setTransform(QTransform::fromTranslate(_mView->GetTranslationX(),_mView->GetTranslationY()), true); + QGraphicsTextItem* text = _mView->GetScene()->addText(_landmarks.back()->GetCaption()); + text->setPos(_landmarks.back()->GetPos().x()+_mView->GetTranslationX(),_landmarks.back()->GetPos().y()+_mView->GetTranslationY()); + //text->setScale(gl_scale_f); + text->setData(0,_mView->GetScaleF()); + text->setTransform(QTransform::fromScale(_mView->GetScaleF(),-_mView->GetScaleF()),true); + _landmarks.back()->SetEllipseItem(ellipse); + _landmarks.back()->SetTextItem(text); -void jpsDatamanager::ParseYAHPointer(QXmlStreamReader &xmlReader, const int& frame) -{ - qreal x = xmlReader.attributes().value("x").toString().toFloat(); - qreal y = xmlReader.attributes().value("y").toString().toFloat(); - qreal angle = xmlReader.attributes().value("dir").toString().toFloat(); - if (_yahPointer==nullptr) - { - _yahPointer = new jpsYAHPointer(x,y,angle); - _yahPointer->SetFirstFrame(frame); - _yahPointer->SetLastFrame(frame); - } - else - { - _yahPointer->SetPos(QPointF(x,y)); - _yahPointer->SetDirection(angle); - _yahPointer->SetLastFrame(frame); - } + //register region and landmark (vice versa) + actRegion->AddLandmark(_landmarks.back()); + _landmarks.back()->SetRegion(actRegion); } -void jpsDatamanager::ParseLandmarksInCMap(QXmlStreamReader &xmlReader, const int& frame) +void jpsDatamanager::ParseConnection(jpsRegion *actRegion, QXmlStreamReader &xmlReader) { + //int id = xmlReader.attributes().value("id").toInt(); + //QString caption = xmlReader.attributes().value("caption").toString(); + //QString type = xmlReader.attributes().value("type").toString(); + int idLandmark1 = xmlReader.attributes().value("landmark1_id").toString().toInt(); + int idLandmark2 = xmlReader.attributes().value("landmark2_id").toString().toInt(); - bool wayPInList=false; - - int id = xmlReader.attributes().value("ID").toString().toInt(); - qreal x = xmlReader.attributes().value("x").toString().toFloat(); - qreal y = xmlReader.attributes().value("y").toString().toFloat(); - qreal rA = xmlReader.attributes().value("rA").toString().toFloat(); - qreal rB = xmlReader.attributes().value("rB").toString().toFloat(); - QString caption = xmlReader.attributes().value("caption").toString(); + jpsLandmark* landmark1 = nullptr; + jpsLandmark* landmark2 = nullptr; - for (ptrWaypoint waypoint:_waypointsInCMap) + for (jpsLandmark* landmark:actRegion->GetLandmarks()) { - if (waypoint->GetId()==id && waypoint->GetType()=="Landmark") - { - wayPInList = true; - waypoint->SetLastFrame(frame); - } + if (landmark->GetId()==idLandmark1) + landmark1=landmark; + else if (landmark->GetId()==idLandmark2) + landmark2=landmark; } - if (!wayPInList) - { - _waypointsInCMap.push_back(std::make_shared(QPointF(x,y),rA,rB,id,"Landmark")); - _waypointsInCMap.back()->SetFirstFrame(frame); - _waypointsInCMap.back()->SetLastFrame(frame); - _waypointsInCMap.back()->SetCaption(caption); - } + jpsConnection* currentConnection =new jpsConnection(landmark1,landmark2); + landmark1->NewConnection(currentConnection); + landmark2->NewConnection(currentConnection); + + QLineF line = QLineF(landmark1->GetPos(),landmark2->GetPos()); + QPen pen = QPen(Qt::blue,2); + pen.setCosmetic(true); + QGraphicsLineItem* lineItem = _mView->GetScene()->addLine(line,pen); + lineItem->setTransform(QTransform::fromTranslate(_mView->GetTranslationX(),_mView->GetTranslationY()), true); + currentConnection->SetLineItem(lineItem); + + NewConnection(currentConnection); } -void jpsDatamanager::ParseWaypointInCMap(QXmlStreamReader &xmlReader, const int& frame) +jpsRegion* jpsDatamanager::ParseRegion(QXmlStreamReader &xmlReader) { - bool wayPInList=false; - - int id = xmlReader.attributes().value("ID").toString().toInt(); - qreal x = xmlReader.attributes().value("x").toString().toFloat(); - qreal y = xmlReader.attributes().value("y").toString().toFloat(); - qreal rA = xmlReader.attributes().value("rA").toString().toFloat(); - qreal rB = xmlReader.attributes().value("rB").toString().toFloat(); + int id = xmlReader.attributes().value("id").toString().toInt(); QString caption = xmlReader.attributes().value("caption").toString(); - bool current = xmlReader.attributes().value("current").toString().toInt(); + qreal x = xmlReader.attributes().value("px").toString().toFloat(); + qreal y = xmlReader.attributes().value("py").toString().toFloat(); + qreal rA = xmlReader.attributes().value("a").toString().toFloat(); + qreal rB = xmlReader.attributes().value("b").toString().toFloat(); - for (ptrWaypoint waypoint:_waypointsInCMap) - { - if (waypoint->GetId()==id && waypoint->GetType()=="Waypoint") - { - wayPInList = true; - waypoint->SetLastFrame(frame); - - if (current!=waypoint->IsCurrent()) - { - waypoint->ChangeCurrentness(frame); - - } - - } - } + QPen pen = QPen(Qt::darkGreen,2); + pen.setCosmetic(true); + QRectF rect = QRectF(QPointF(x-rA,y+rB),QPointF(x+rA,y-rB)); + QGraphicsEllipseItem* ellipse = _mView->GetScene()->addEllipse(rect,pen); + ellipse->setTransform(QTransform::fromTranslate(_mView->GetTranslationX(),_mView->GetTranslationY()), true); - if (!wayPInList) - { - _waypointsInCMap.push_back(std::make_shared(QPointF(x,y),rA,rB,id,"Waypoint")); - _waypointsInCMap.back()->SetFirstFrame(frame); - _waypointsInCMap.back()->SetLastFrame(frame); - _waypointsInCMap.back()->SetCurrentness(current,frame); - _waypointsInCMap.back()->SetCaption(caption); - } + // create region + jpsRegion* actRegion = new jpsRegion(id,caption, + rect.center(),std::fabs(rect.width()/2.0),std::fabs(rect.height()/2.0)); -} + QGraphicsTextItem* text = _mView->GetScene()->addText(actRegion->GetCaption()); + text->setPos(rect.center().x()+_mView->GetTranslationX(),rect.center().y()+_mView->GetTranslationY()); + //text->setScale(gl_scale_f); + text->setData(0,_mView->GetScaleF()); + text->setTransform(QTransform::fromScale(_mView->GetScaleF(),-_mView->GetScaleF()),true); -void jpsDatamanager::ParseConnectionsInCMap(QXmlStreamReader &xmlReader, const int &frame) -{ - int id1 = xmlReader.attributes().value("Landmark_WaypointID1").toString().toInt(); - int id2 = xmlReader.attributes().value("Landmark_WaypointID2").toString().toInt(); - std::shared_ptr waypoint1 = nullptr; - std::shared_ptr waypoint2 = nullptr; + actRegion->SetTextItem(text); + actRegion->SetEllipse(ellipse); + NewRegion(actRegion); - for (ptrWaypoint waypoint:_waypointsInCMap) - { - if (waypoint->GetId()==id1) - { - waypoint1=waypoint; + return actRegion; - } - else if (waypoint->GetId()==id2) - { - waypoint2=waypoint; +} - } - } - ptrConnection con = std::make_shared(waypoint1,waypoint2,frame); - if (waypoint1!=nullptr && waypoint2!=nullptr) - { - for (ptrConnection conInMap : _connectionsInCMap) - { - if (con->operator ==(conInMap)) - { - conInMap->SetLastFrame(frame); +//void jpsDatamanager::ParseYAHPointer(QXmlStreamReader &xmlReader, const int& frame) +//{ +// qreal x = xmlReader.attributes().value("x").toString().toFloat(); +// qreal y = xmlReader.attributes().value("y").toString().toFloat(); +// qreal angle = xmlReader.attributes().value("dir").toString().toFloat(); +// if (_yahPointer==nullptr) +// { +// _yahPointer = new jpsYAHPointer(x,y,angle); +// _yahPointer->SetFirstFrame(frame); +// _yahPointer->SetLastFrame(frame); +// } +// else +// { +// _yahPointer->SetPos(QPointF(x,y)); +// _yahPointer->SetDirection(angle); +// _yahPointer->SetLastFrame(frame); +// } - return; - } - } +//} - _connectionsInCMap.push_back(con); - } -} +//} -void jpsDatamanager::ShowCMapFrame(const int& frame) const -{ - mView->ShowYAHPointer(_yahPointer->GetPosWhenFrame(frame),_yahPointer->GetDirWhenFrame(frame)); +//void jpsDatamanager::ShowCMapFrame(const int& frame) const +//{ +// mView->ShowYAHPointer(_yahPointer->GetPosWhenFrame(frame),_yahPointer->GetDirWhenFrame(frame)); - QList wayPCandidates; +// QList wayPCandidates; - for (ptrWaypoint waypoint:_waypointsInCMap) - { - if (waypoint->OccursInFrame(frame)) - { - wayPCandidates.push_back(waypoint); +// for (ptrWaypoint waypoint:_waypointsInCMap) +// { +// if (waypoint->OccursInFrame(frame)) +// { +// wayPCandidates.push_back(waypoint); - if (waypoint->IsCurrentInFrame(frame)) - waypoint->SetText("Next target"); - else if (waypoint->Visited(frame)) - waypoint->SetText("Already visited"); - else - waypoint->SetText(""); - } - } - QList conCandidates; - for (ptrConnection connection:_connectionsInCMap) - { - if (connection->OccursInFrame(frame)) - { - conCandidates.push_back(connection); - } - } +// if (waypoint->IsCurrentInFrame(frame)) +// waypoint->SetText("Next target"); +// else if (waypoint->Visited(frame)) +// waypoint->SetText("Already visited"); +// else +// waypoint->SetText(""); +// } +// } +// QList conCandidates; +// for (ptrConnection connection:_connectionsInCMap) +// { +// if (connection->OccursInFrame(frame)) +// { +// conCandidates.push_back(connection); +// } +// } - mView->ShowConnections(conCandidates); - mView->ShowWaypoints(wayPCandidates); +// mView->ShowConnections(conCandidates); +// mView->ShowWaypoints(wayPCandidates); -} +//} -const double &jpsDatamanager::GetCMapFrameRate() const -{ - return _frameRate; -} +//const double &jpsDatamanager::GetCMapFrameRate() const +//{ +// return _frameRate; +//} -const int &jpsDatamanager::GetLastCMapFrame() const -{ - return _lastCMapFrame; -} +//const int &jpsDatamanager::GetLastCMapFrame() const +//{ +// return _lastCMapFrame; +//} diff --git a/src/datamanager.h b/src/datamanager.h index d1a14caeb0a78f9ada46fcf292c35d549ff941f3..b17572c6b363ab04c6a785482b81f56b7ed9a73f 100644 --- a/src/datamanager.h +++ b/src/datamanager.h @@ -1,7 +1,7 @@ /** * \file datamanager.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -42,6 +42,7 @@ #include "GraphicView.h" #include "jpsyahpointer.h" #include "jpsconnection.h" +#include "jpsregion.h" #include "../dxflib/src/dl_creationadapter.h" @@ -49,7 +50,7 @@ using ptrConnection = std::shared_ptr; -using ptrWaypoint = std::shared_ptr; + class jpsDatamanager: public DL_CreationAdapter @@ -89,6 +90,18 @@ public: void remove_landmark(jpsLandmark* landmark); void change_LandmarkName(jpsLandmark* landmark, QString name); void remove_all_landmarks(); + const int& GetLandmarkCounter() const; + //Connection + const QList& GetAllConnections() const; + void NewConnection(jpsConnection* newConnection); + void RemoveConnection(jpsConnection* connection); + void RemoveAllConnections(); + //Regions + const QList& GetRegions() const; + void NewRegion(jpsRegion* region); + void RemoveRegion(jpsRegion* region); + void RemoveAllRegions(); + const int& GetRegionCounter() const; // void remove_all(); void remove_marked_lines(); @@ -115,6 +128,7 @@ public: // Write XML void writeXML(QFile &file); void writeRoutingXML(QFile &file); + void AutoSaveXML(QFile &file); void writeHeader(QXmlStreamWriter *stream); void writeRoutingHeader(QXmlStreamWriter *stream); @@ -128,7 +142,19 @@ public: void writeNotAssignedWalls(QXmlStreamWriter *stream, QList& lines); void writeNotAssignedDoors(QXmlStreamWriter *stream, QList& lines); void writeNotAssignedExits(QXmlStreamWriter *stream, QList& lines); - void writeLandmarks(QXmlStreamWriter *stream, QList &landmarks); + + + //Write Cognitive Map XML + void WriteCognitiveMapXML(QFile &file, bool fuzzy=false); + void WriteCognitiveMapHeader(QXmlStreamWriter *stream); + void WriteRegions(QXmlStreamWriter *stream, bool fuzzy=false); + void WriteLandmarks(jpsRegion *cRegion, QXmlStreamWriter *stream, bool fuzzy=false); + void CutOutLandmarks(); + void BridgeLostLandmark(jpsLandmark* landmark); + void WriteConnections(jpsRegion *cRegion, QXmlStreamWriter *stream); + void CreateAndSaveASimilarCogMap(const int &id); + qreal MakeItFuzzy(const qreal &mean, const qreal& std); + int GetNumberOfMainTargets() const; // Read DXF bool readDXF(std::string filename); @@ -145,16 +171,15 @@ public: //Parse Cognitive Map bool ParseCogMap(QFile &file); - void ParseFrames(QXmlStreamReader &xmlReader); + jpsRegion* ParseRegion(QXmlStreamReader &xmlReader); void ParseYAHPointer(QXmlStreamReader &xmlReader, const int &frame); - void ParseLandmarksInCMap(QXmlStreamReader &xmlReader, const int &frame); - void ParseWaypointInCMap(QXmlStreamReader &xmlReader, const int &frame); - void ParseConnectionsInCMap(QXmlStreamReader &xmlReader, const int &frame); + void ParseLandmark(jpsRegion* actRegion, QXmlStreamReader &xmlReader); + void ParseConnection(jpsRegion* actRegion, QXmlStreamReader &xmlReader); - //Show Cognitive Map - void ShowCMapFrame(const int& frame) const; - const double& GetCMapFrameRate() const; - const int& GetLastCMapFrame() const; +// //Show Cognitive Map +// void ShowCMapFrame(const int& frame) const; +// const double& GetCMapFrameRate() const; +// const int& GetLastCMapFrame() const; private: //Geometry @@ -162,20 +187,28 @@ private: QList obstaclelist; QList crossingList; QList exitList; - QList landmarks; + QList _landmarks; + QList _landmarkConnections; + QList _landmarksAfterLoose; + QList _ConnectionsAfterLandmarkLoose; + QList _regions; int room_id_counter; int obs_id_counter; QWidget* parent_widget; - jpsGraphicsView* mView; + jpsGraphicsView* _mView; //CognitiveMap - QList _landmarksInCMap; - QList _waypointsInCMap; - QList _connectionsInCMap; + //QList _landmarksInCMap; + //QList _connectionsInCMap; jpsYAHPointer* _yahPointer; double _frameRate; int _lastCMapFrame; + int _landmarkCounter; + int _regionCounter; + + QString _currentCogMapFileName; + }; diff --git a/src/graphicscene.cpp b/src/graphicscene.cpp index 3600b99d405bd32570bc2f05f8a7f1f96cde71de..f7e834cde1bd978c7bdf40cdeef9936190c38599 100644 --- a/src/graphicscene.cpp +++ b/src/graphicscene.cpp @@ -1,3 +1,27 @@ +/** + * \file graphicscene.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "graphicscene.h" #include #include diff --git a/src/graphicscene.h b/src/graphicscene.h index 91da5da9edb7a1666791a577e8160c9443a09c16..9c0ca118692a7f80e07833559df311fa01b66876 100644 --- a/src/graphicscene.h +++ b/src/graphicscene.h @@ -1,3 +1,27 @@ +/** + * \file graphicscene.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef GRAPHICSCENE_H #define GRAPHICSCENE_H diff --git a/src/jpsLineItem.cpp b/src/jpsLineItem.cpp index 10301c4c61e13948777e2414b343e857512581e9..63ced3e159f80ca86513b7ad042ef2088372eae4 100644 --- a/src/jpsLineItem.cpp +++ b/src/jpsLineItem.cpp @@ -1,7 +1,7 @@ /** * \file jpsLineItem.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsLineItem.h b/src/jpsLineItem.h index 3ebb525d7841de23f98c52f2d54836b78721e623..63edd632da4ab3aef667796e070ab4a351458a09 100644 --- a/src/jpsLineItem.h +++ b/src/jpsLineItem.h @@ -1,7 +1,7 @@ /** * \file jpsLineItem.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsconnection.cpp b/src/jpsconnection.cpp index a2ccecc224dd51d448dc2de213c8a5e54e297e27..5006ae75f9ce8871a7ce5e742036951845bbe3c8 100644 --- a/src/jpsconnection.cpp +++ b/src/jpsconnection.cpp @@ -1,11 +1,36 @@ +/** + * \file jpsconnection.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "jpsconnection.h" -jpsConnection::jpsConnection(ptrWaypoint waypoint1, ptrWaypoint waypoint2, const int &frameID) +jpsConnection::jpsConnection(jpsLandmark* landmark1, jpsLandmark* landmark2, QGraphicsLineItem *lineItem, const int &frameID) { - _waypoint1=waypoint1; - _waypoint2=waypoint2; + _landmark1=landmark1; + _landmark2=landmark2; _firstFrame=frameID; _lastFrame=frameID; + _lineItem=lineItem; } jpsConnection::~jpsConnection() @@ -13,14 +38,45 @@ jpsConnection::~jpsConnection() } -std::pair jpsConnection::GetWaypoints() const +std::pair jpsConnection::GetLandmarks() const { - return std::make_pair(_waypoint1,_waypoint2); + return std::make_pair(_landmark1,_landmark2); } -bool jpsConnection::OccursInFrame(const int& frameID) const +//bool jpsConnection::OccursInFrame(const int& frameID) const +//{ +// if (frameID>=_firstFrame && frameID<=_lastFrame) +// { +// return true; +// } +// else +// return false; +//} + +//void jpsConnection::SetFirstFrame(const int &frameID) +//{ +// _firstFrame=frameID; +//} + +//void jpsConnection::SetLastFrame(const int &frameID) +//{ +// _lastFrame=frameID; +//} + +//const int &jpsConnection::GetFirstFrame() const +//{ +// return _firstFrame; +//} + +//const int &jpsConnection::GetLastFrame() const +//{ +// return _lastFrame; +//} + +bool jpsConnection::operator == (const jpsConnection& con2) const { - if (frameID>=_firstFrame && frameID<=_lastFrame) + if ((con2.GetLandmarks().first==_landmark1 && con2.GetLandmarks().second==_landmark2) + || (con2.GetLandmarks().second==_landmark1 && con2.GetLandmarks().first==_landmark2)) { return true; } @@ -28,34 +84,25 @@ bool jpsConnection::OccursInFrame(const int& frameID) const return false; } -void jpsConnection::SetFirstFrame(const int &frameID) +void jpsConnection::SetLineItem(QGraphicsLineItem *lineItem) { - _firstFrame=frameID; + _lineItem=lineItem; } -void jpsConnection::SetLastFrame(const int &frameID) +QGraphicsLineItem *jpsConnection::GetLineItem() { - _lastFrame=frameID; + return _lineItem; } -const int &jpsConnection::GetFirstFrame() const +void jpsConnection::SetFirstLandmark(jpsLandmark* landmark) { - return _firstFrame; + _landmark1=landmark; } -const int &jpsConnection::GetLastFrame() const +void jpsConnection::SetSecondLandmark(jpsLandmark* landmark) { - return _lastFrame; + _landmark2=landmark; } -bool jpsConnection::operator == (const ptrConnection con2) const -{ - if ((con2->GetWaypoints().first==_waypoint1 && con2->GetWaypoints().second==_waypoint2) - || (con2->GetWaypoints().second==_waypoint1 && con2->GetWaypoints().first==_waypoint2)) - { - return true; - } - else - return false; -} + diff --git a/src/jpsconnection.h b/src/jpsconnection.h index 8359d4e3969343a6c81e56a6e2b5e99c4b76fd91..c81436605b46e8f80b92c551ea845abff62983c3 100644 --- a/src/jpsconnection.h +++ b/src/jpsconnection.h @@ -1,33 +1,66 @@ +/** + * \file jpsconnection.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef JPSCONNECTION_H #define JPSCONNECTION_H #include #include -#include "jpswaypoint.h" +#include "jpslandmark.h" + -using ptrWaypoint = std::shared_ptr; class jpsConnection { -using ptrConnection = std::shared_ptr; + public: - jpsConnection(ptrWaypoint waypoint1, ptrWaypoint waypoint2, const int& frameID=-1); + jpsConnection(jpsLandmark* landmark1=nullptr, jpsLandmark* landmark2=nullptr, QGraphicsLineItem* lineItem=nullptr, const int& frameID=-1); ~jpsConnection(); - std::pair GetWaypoints() const; + std::pair GetLandmarks() const; + + void SetLineItem(QGraphicsLineItem* lineItem); + QGraphicsLineItem* GetLineItem(); + + void SetFirstLandmark(jpsLandmark* landmark); + void SetSecondLandmark(jpsLandmark* landmark); //Occurence - bool OccursInFrame(const int &frameID) const; - void SetFirstFrame(const int &frameID); - void SetLastFrame(const int &frameID); - const int& GetFirstFrame() const; - const int& GetLastFrame() const; +// bool OccursInFrame(const int &frameID) const; +// void SetFirstFrame(const int &frameID); +// void SetLastFrame(const int &frameID); +// const int& GetFirstFrame() const; +// const int& GetLastFrame() const; // Operator overload - bool operator ==(const ptrConnection con2) const; + bool operator ==(const jpsConnection& con2) const; private: - ptrWaypoint _waypoint1; - ptrWaypoint _waypoint2; + jpsLandmark* _landmark1; + jpsLandmark* _landmark2; + QGraphicsLineItem* _lineItem; int _firstFrame; int _lastFrame; + + }; #endif // JPSCONNECTION_H diff --git a/src/jpscrossing.cpp b/src/jpscrossing.cpp index a5f7e9a7a3278b54092e4a86786249c86fc30084..5fb2c72922b20253199360899895688bdc9c332a 100644 --- a/src/jpscrossing.cpp +++ b/src/jpscrossing.cpp @@ -1,7 +1,7 @@ /** * \file jpscrossing.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpscrossing.h b/src/jpscrossing.h index 0784431a41339b482e0ecded04cc58e0d0c37c4a..5c45d7a0fb56aeb2099c0b2e6ea76a3ced7c3456 100644 --- a/src/jpscrossing.h +++ b/src/jpscrossing.h @@ -1,7 +1,7 @@ /** * \file jpscrossing.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsexit.cpp b/src/jpsexit.cpp index 0725b708677bc87479d83c9176c337831a9c63df..7e60f21d0a9d812dde7adab74aa88f34575e4c0e 100644 --- a/src/jpsexit.cpp +++ b/src/jpsexit.cpp @@ -1,7 +1,7 @@ /** * \file jpsexit.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsexit.h b/src/jpsexit.h index 0a903713f4fc251b7acadc59e830126ed3857391..f8ab0f33d485675b96a09a6a324677e4e04c0146 100644 --- a/src/jpsexit.h +++ b/src/jpsexit.h @@ -1,7 +1,7 @@ /** * \file jpsexit.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpslandmark.cpp b/src/jpslandmark.cpp index b109cf397a928c3fcea29ea2139922e1d830b3cf..b94bde7d22288fe62a50c752332636640f8d0b7f 100644 --- a/src/jpslandmark.cpp +++ b/src/jpslandmark.cpp @@ -1,7 +1,7 @@ /** * \file jpslandmark.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,106 +22,219 @@ * * \section Description * This class is representing a landmark in the building which could be set by the user. - * The usage of landmarks is not enabled in v0.7. + * The usage of landmarks is not enabled in v0.8.1. * **/ #include "jpslandmark.h" +#include jpsLandmark::jpsLandmark() { } -jpsLandmark::jpsLandmark(QGraphicsPixmapItem* pixmap, QString name, QPointF point) +jpsLandmark::jpsLandmark(QGraphicsPixmapItem *pixmap, const QString &caption, const QPointF &realPos, const qreal &rA, const qreal &rB, const int &id, const QString &type) { - _name=name; - _pos=point; + _caption=caption; + _realPos=realPos; + _pos=realPos; _room=nullptr; _visibility=0; _pixmapItem=pixmap; - + _a=rA; + _b=rB; + _id=id; + _type=type; + _rect=QRectF(realPos.x()-rA,realPos.y()-rB,rA*2,rB*2); + _textItem=nullptr; + _pixmapText=nullptr; + _ellipseItem=nullptr; + _region=nullptr; } jpsLandmark::~jpsLandmark() { - RemoveAllWaypoints(); + delete _pixmapItem; + delete _ellipseItem; + delete _textItem; + delete _pixmapText; } -void jpsLandmark::set_pixmap(QGraphicsPixmapItem *pixmap) +void jpsLandmark::SetPixmap(QGraphicsPixmapItem *pixmap) { _pixmapItem=pixmap; } -void jpsLandmark::set_name(QString name) + + +void jpsLandmark::SetRoom(jpsRoom *room) { - _name=name; + _room=room; +} +void jpsLandmark::SetVisibility(int visibility) +{ + _visibility=visibility; } -void jpsLandmark::set_pos(QPointF pos) +QGraphicsPixmapItem* jpsLandmark::GetPixmap() const { - _pos=pos; + return _pixmapItem; } -void jpsLandmark::set_room(jpsRoom *room) + + +jpsRoom *jpsLandmark::GetRoom() const { - _room=room; + return _room; } -void jpsLandmark::set_visibility(int visibility) +int jpsLandmark::GetVisibility() const { - _visibility=visibility; + return _visibility; } -QGraphicsPixmapItem* jpsLandmark::get_pixmap() + +const QPointF &jpsLandmark::GetPos() const { - return _pixmapItem; + return _pos; + } -QString jpsLandmark::get_name() +const QPointF &jpsLandmark::GetRealPos() const { - return _name; + return _realPos; } -const QPointF &jpsLandmark::get_pos() +const QRectF &jpsLandmark::GetRect() const { - return _pos; + return _rect; } -jpsRoom *jpsLandmark::get_room() +const double& jpsLandmark::GetA() const { - return _room; + return _a; } -int jpsLandmark::get_visibility() +const double& jpsLandmark::GetB() const { - return _visibility; + return _b; +} + +const int &jpsLandmark::GetId() const +{ + return _id; } -void jpsLandmark::AddWaypoint(ptrWaypoint waypoint) +QGraphicsEllipseItem *jpsLandmark::GetEllipseItem() const { - _waypoints.push_back(waypoint); + return _ellipseItem; } -void jpsLandmark::RemoveWaypoint(ptrWaypoint waypoint) +const QString &jpsLandmark::GetCaption() const { - delete waypoint.get(); - _waypoints.removeOne(waypoint); + return _caption; } -QList jpsLandmark::GetWaypoints() +const QString &jpsLandmark::GetType() const { - return _waypoints; + return _type; } -void jpsLandmark::RemoveAllWaypoints() +QGraphicsTextItem *jpsLandmark::GetTextItem() const { - for (ptrWaypoint waypoint:_waypoints) + return _textItem; +} + +QGraphicsTextItem *jpsLandmark::GetPixmapTextItem() const +{ + return _pixmapText; +} + +const QList &jpsLandmark::GetConnections() const +{ + return _connections; +} + + +void jpsLandmark::SetPos(const QPointF& point) +{ + _pos=point; + _rect.setRect(point.x(),point.y(),_rect.width(),_rect.height()); +} + +void jpsLandmark::SetRealPos(const QPointF &point) +{ + _realPos=point; +} + +void jpsLandmark::SetRect(const QRectF& rect) +{ + _rect=rect; + _a=std::fabs(_rect.width()/2.0); + _b=std::fabs(_rect.height()/2.0); + _pos=_rect.center(); +} + +void jpsLandmark::SetEllipseItem(QGraphicsEllipseItem *ellipseItem) +{ + _ellipseItem=ellipseItem; +} + +void jpsLandmark::SetId(const int &id) +{ + _id=id; +} + +void jpsLandmark::SetCaption(const QString &string) +{ + _caption=string; + if (_textItem!=nullptr) + _textItem->setPlainText(_caption); + + if (_pixmapText!=nullptr) + _pixmapText->setPlainText(_caption); +} + +void jpsLandmark::SetType(const QString &type) +{ + _type=type; +} + +void jpsLandmark::SetTextItem(QGraphicsTextItem *textItem) +{ + _textItem=textItem; +} + +void jpsLandmark::SetPixMapText(QGraphicsTextItem *textItem) +{ + _pixmapText=textItem; +} + +void jpsLandmark::NewConnection(jpsConnection *newConnection) +{ + _connections.push_back(newConnection); +} + +void jpsLandmark::RemoveConnection(jpsConnection *connection) +{ + if (_connections.contains(connection)) { - delete waypoint.get(); + _connections.removeOne(connection); } - _waypoints.clear(); } +void jpsLandmark::SetRegion(jpsRegion *region) +{ + _region=region; +} + +jpsRegion *jpsLandmark::GetRegion() const +{ + return _region; +} + + + diff --git a/src/jpslandmark.h b/src/jpslandmark.h index 8bbf20fdf0e6f245a588ecc1c27857d9d7e9969c..35b9602056320db4093c3564a4da306841efa7b3 100644 --- a/src/jpslandmark.h +++ b/src/jpslandmark.h @@ -1,7 +1,7 @@ /** * \file jpslandmark.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,51 +22,106 @@ * * \section Description * This class is representing a landmark in the building which could be set by the user. - * The usage of landmarks is not enabled in v0.7. + * The usage of landmarks is not enabled in v0.8.1. * **/ #ifndef JPSLANDMARK_H #define JPSLANDMARK_H #include +#include #include #include "rooms.h" -#include "jpswaypoint.h" -using ptrWaypoint = std::shared_ptr; +class jpsConnection; +class jpsRegion; + class jpsLandmark { public: jpsLandmark(); - jpsLandmark(QGraphicsPixmapItem* pixmap, QString name, QPointF point); + jpsLandmark(QGraphicsPixmapItem* pixmap,const QString& caption, const QPointF& realPos,const qreal& rA=0, const qreal& rB=0, const int& id=0, const QString& type="Landmark"); ~jpsLandmark(); //Setter - void set_pixmap(QGraphicsPixmapItem* pixmap); - void set_name(QString name); - void set_pos(QPointF pos); - void set_room(jpsRoom* room); - void set_visibility(int visibility); + //Getter - QGraphicsPixmapItem* get_pixmap(); - QString get_name(); - const QPointF& get_pos(); - jpsRoom *get_room(); - int get_visibility(); - //Waypoint handling - void AddWaypoint(ptrWaypoint waypoint); - void RemoveWaypoint(ptrWaypoint waypoint); - QList GetWaypoints(); - void RemoveAllWaypoints(); + QGraphicsPixmapItem* GetPixmap() const; + jpsRoom *GetRoom() const; + int GetVisibility() const; + const QPointF& GetPos() const; + const QPointF& GetRealPos() const; + const QRectF &GetRect() const; + const double& GetA() const; + const double& GetB() const; + const int& GetId() const; + QGraphicsEllipseItem* GetEllipseItem() const; + const QString& GetCaption() const; + const QString& GetType() const; + QGraphicsTextItem* GetTextItem() const; + QGraphicsTextItem* GetPixmapTextItem() const; + const QList& GetConnections() const; + + //Setter + void SetPixmap(QGraphicsPixmapItem* pixmap); + void SetRoom(jpsRoom* room); + void SetVisibility(int visibility); + void SetPos(const QPointF& point); + void SetRealPos(const QPointF& point); + void SetRect(const QRectF &rect); + void SetEllipseItem(QGraphicsEllipseItem* ellipseItem); + void SetId(const int& id); + void SetCaption(const QString& string); + void SetType(const QString& type); + void SetTextItem(QGraphicsTextItem* textItem); + void SetPixMapText(QGraphicsTextItem* textItem); + + //Connections + void NewConnection(jpsConnection* newConnection); + void RemoveConnection(jpsConnection* connection); + + //Region + void SetRegion(jpsRegion* region); + jpsRegion* GetRegion() const; + + +// //Occurence +// const int& GetFirstFrame() const; +// const int& GetLastFrame() const; +// void SetFirstFrame(const int& frame); +// void SetLastFrame(const int& frame); +// bool OccursInFrame(const int& frame) const; + +// //Currency +// bool IsCurrent() const; +// bool IsCurrentInFrame(const int& frameID); +// void SetCurrentness(bool stat, const int &frameID=1); +// const int& GetFirstFrameCurrent() const; +// const int& GetLastFrameCurrent() const; +// void ChangeCurrentness(const int& frameID); +// const QString& GetText(); +// void SetText(const QString& text); + +// bool Visited(const int& frameID) const; private: - QString _name; + QString _caption; + qreal _a; + qreal _b; + int _id; + QString _type; QPointF _pos; + QPointF _realPos; jpsRoom* _room; int _visibility; QGraphicsPixmapItem* _pixmapItem; - QList _waypoints; + QRectF _rect; + QGraphicsEllipseItem* _ellipseItem; + QGraphicsTextItem* _textItem; + QGraphicsTextItem* _pixmapText; + QList _connections; + jpsRegion* _region; }; diff --git a/src/jpsobstacle.cpp b/src/jpsobstacle.cpp index 2b8b52ec122dd6b18c6be76017a1738949074ff5..8f1778917bd3a16272c8921866e34aa1a8a184d8 100644 --- a/src/jpsobstacle.cpp +++ b/src/jpsobstacle.cpp @@ -1,7 +1,7 @@ /** * \file jpsObstacle.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsobstacle.h b/src/jpsobstacle.h index 14efc584fda6644059324da3fb20f97093922ec2..469d200f992ac9cdc5e63e91a7a4446bf2a52888 100644 --- a/src/jpsobstacle.h +++ b/src/jpsobstacle.h @@ -1,7 +1,7 @@ /** * \file jpsObstacle.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/jpsregion.cpp b/src/jpsregion.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82fab3159e566a6ced1bbb944ea3c6ec93a39dc3 --- /dev/null +++ b/src/jpsregion.cpp @@ -0,0 +1,95 @@ +#include "jpsregion.h" + +jpsRegion::jpsRegion(const int &id, const QString &caption, const QPointF &pos, const qreal &a, const qreal &b, const QString &type, const int &floor) +{ + _id=id; + _caption=caption; + _pos=pos; + _a=a; + _b=b; + _type=type; + _ellipseItem=nullptr; + _textItem=nullptr; + _floor=floor; +} + +jpsRegion::jpsRegion(const int &id, const QString &caption, QGraphicsEllipseItem *ellipse, QGraphicsTextItem* text, const QString &type, const int &floor) +{ + _id=id; + _caption=caption; + _ellipseItem=ellipse; + _type=type; + _pos=_ellipseItem->pos(); + _a=_ellipseItem->rect().width()/2.0; + _b=_ellipseItem->rect().height()/2.0; + _textItem=text; + _floor=floor; +} + +jpsRegion::~jpsRegion() +{ + delete _ellipseItem; + delete _textItem; + +} + +void jpsRegion::AddLandmark(jpsLandmark *landmark) +{ + _landmarks.push_back(landmark); +} + +void jpsRegion::RemoveLandmark(jpsLandmark *landmark) +{ + _landmarks.removeOne(landmark); +} + +const int &jpsRegion::GetId() const +{ + return _id; +} + +const QPointF &jpsRegion::GetPos() const +{ + return _pos; +} + +const QString &jpsRegion::GetCaption() const +{ + return _caption; +} + +QGraphicsTextItem *jpsRegion::GetTextItem() const +{ + return _textItem; +} + +QGraphicsEllipseItem *jpsRegion::GetEllipseItem() const +{ + return _ellipseItem; +} + +QList jpsRegion::GetLandmarks() const +{ + return _landmarks; +} + +const qreal &jpsRegion::GetA() const +{ + return _a; +} + +const qreal &jpsRegion::GetB() const +{ + return _b; +} + +void jpsRegion::SetTextItem(QGraphicsTextItem *textItem) +{ + _textItem=textItem; +} + +void jpsRegion::SetEllipse(QGraphicsEllipseItem *ellipseItem) +{ + _ellipseItem=ellipseItem; +} + diff --git a/src/jpsregion.h b/src/jpsregion.h new file mode 100644 index 0000000000000000000000000000000000000000..c4e1f73539d6724e7077f1071b6cd119eeb97c05 --- /dev/null +++ b/src/jpsregion.h @@ -0,0 +1,45 @@ +#ifndef JPSREGION_H +#define JPSREGION_H +#include "jpslandmark.h" + +class jpsRegion +{ +public: + jpsRegion(const int& id, const QString& caption, const QPointF& pos, const qreal& a, const qreal& b, const QString& type="Region", const int& floor=0); + jpsRegion(const int& id, const QString& caption, QGraphicsEllipseItem* ellipse, QGraphicsTextItem* text=nullptr, const QString& type="Region", const int& floor=0); + ~jpsRegion(); + + void AddLandmark(jpsLandmark* landmark); + void RemoveLandmark(jpsLandmark* landmark); + + //Getter + const int& GetId() const; + const QPointF& GetPos() const; + const QString& GetCaption() const; + QGraphicsTextItem* GetTextItem() const; + QGraphicsEllipseItem* GetEllipseItem() const; + QList GetLandmarks() const; + const qreal& GetA() const; + const qreal& GetB() const; + + //Setter + + void SetTextItem(QGraphicsTextItem* textItem); + void SetEllipse(QGraphicsEllipseItem* ellipseItem); + +private: + QString _caption; + qreal _a; + qreal _b; + int _id; + QString _type; + QPointF _pos; + QGraphicsEllipseItem* _ellipseItem; + QGraphicsTextItem* _textItem; + int _floor; + + //Landmarks + QList _landmarks; +}; + +#endif // JPSREGION_H diff --git a/src/jpswaypoint.cpp b/src/jpswaypoint.cpp index 109c26b9be11a6c01804d5398b13e2ff9a58cbad..4414ee08c97abf05fb7cbbf3bab1967ee7a8864e 100644 --- a/src/jpswaypoint.cpp +++ b/src/jpswaypoint.cpp @@ -1,7 +1,7 @@ /** * \file jpswaypoint.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,7 +22,7 @@ * * \section Description * This class is representing an spatial association which rely on a certain landmark. - * jpswaypoint is not enabled in v0.7. + * jpswaypoint is not enabled in v0.8.1. * **/ diff --git a/src/jpswaypoint.h b/src/jpswaypoint.h index 39bb917d03af58315a4a115488497f6d5bbc4b1d..2038024bdbc50b5b25fc1452f0ec2668a5c4a04b 100644 --- a/src/jpswaypoint.h +++ b/src/jpswaypoint.h @@ -1,7 +1,7 @@ /** * \file jpswaypoint.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,7 +22,7 @@ * * \section Description * This class is representing an spatial association which rely on a certain landmark. - * jpswaypoint is not enabled in v0.7. + * jpswaypoint is not enabled in v0.8.1. * **/ diff --git a/src/jpsyahpointer.cpp b/src/jpsyahpointer.cpp index 4c0b90f6d3926f4eef6ffe3eb33dc58c931d62dd..eff16c56022413e66e8b6b9020960b44fbd5891c 100644 --- a/src/jpsyahpointer.cpp +++ b/src/jpsyahpointer.cpp @@ -1,3 +1,27 @@ +/** + * \file jpsyahpointer.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "jpsyahpointer.h" jpsYAHPointer::jpsYAHPointer(const QPointF &point, const qreal &angle) diff --git a/src/jpsyahpointer.h b/src/jpsyahpointer.h index ef1e00296ad02c3be6801c3b5110568eae25311b..c3ba55d3cf6b91ca26b64d9f5c368c79d08a0a8d 100644 --- a/src/jpsyahpointer.h +++ b/src/jpsyahpointer.h @@ -1,3 +1,27 @@ +/** + * \file jpsyahpointer.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef JPSYAHPOINTER_H #define JPSYAHPOINTER_H #include diff --git a/src/main.cpp b/src/main.cpp index b76ab5838b195095b0e9ec1c132ac3ecd1742886..3a022c601e4b775b5f1b5bc88f7a024a593cd8af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ /** * \file main.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -27,7 +27,7 @@ //main.cpp -/* for compiling a standalone windows exe with VS + //for compiling a standalone windows exe with VS #ifdef _MSC_VER # ifdef NDEBUG # pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") @@ -35,7 +35,7 @@ # pragma comment(linker, "/SUBSYSTEM:CONSOLE") # endif #endif -*/ + #include "mainWindow.h" diff --git a/src/mainWindow.cpp b/src/mainWindow.cpp index 39293e93eb1ec6cc00464e8d5e967e7745663d06..00d0e5cf500daf9b58f23f6abf5f17c6f53819c7 100644 --- a/src/mainWindow.cpp +++ b/src/mainWindow.cpp @@ -1,7 +1,7 @@ /** * \file mainWindow.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -47,6 +47,7 @@ MWindow :: MWindow() { mview = new jpsGraphicsView(this); dmanager = new jpsDatamanager(this,mview); + mview->SetDatamanager(dmanager); //Roomwidget rwidget=nullptr; @@ -94,10 +95,11 @@ MWindow :: MWindow() { connect(actionBeenden, SIGNAL(triggered(bool)),this,SLOT(close())); connect(action_ffnen,SIGNAL(triggered(bool)),this,SLOT(openFile())); connect(action_ffnen_xml,SIGNAL(triggered(bool)),this,SLOT(openFileXML())); + connect(action_ffnen_cogmap,SIGNAL(triggered(bool)),this,SLOT(openFileCogMap())); connect(actionSpeichern,SIGNAL(triggered(bool)),this,SLOT(saveFile())); connect(actionSpeichern_dxf,SIGNAL(triggered(bool)),this,SLOT(saveAsDXF())); connect(actionSettings,SIGNAL(triggered(bool)),this,SLOT(Settings())); - connect(action_ffnen_CogMap,SIGNAL(triggered(bool)),this,SLOT(openFileCMap())); + //connect(action_ffnen_CogMap,SIGNAL(triggered(bool)),this,SLOT(openFileCMap())); // Tab Help connect(action_ber,SIGNAL(triggered(bool)),this,SLOT(info())); // Tab Tools @@ -126,7 +128,6 @@ MWindow :: MWindow() { connect(mview,SIGNAL(remove_all()),this,SLOT(remove_all_lines())); connect(mview,SIGNAL(set_focus_textedit()),length_edit,SLOT(setFocus())); connect(mview,SIGNAL(mouse_moved()),this,SLOT(show_coords())); - connect(mview,SIGNAL(landmark_added()),this,SLOT(add_landmark())); connect(mview,SIGNAL(LineLengthChanged()),this,SLOT(ShowLineLength())); // Mark all lines QAction *str_a = new QAction(this); @@ -142,11 +143,13 @@ MWindow :: MWindow() { // Landmark specifications connect(actionLandmarkWidget,SIGNAL(triggered(bool)),this,SLOT(define_landmark())); //CMap - connect(actionRun_visualisation,SIGNAL(triggered(bool)),this,SLOT(RunCMap())); - connect(_cMapTimer,SIGNAL(timeout()),this,SLOT(UpdateCMap())); +// connect(actionRun_visualisation,SIGNAL(triggered(bool)),this,SLOT(RunCMap())); +// connect(_cMapTimer,SIGNAL(timeout()),this,SLOT(UpdateCMap())); +// connect(actionSpeichern_cogmap,SIGNAL(triggered()),this,SLOT(SaveCogMapXML())); //Undo Redo connect(actionUndo,SIGNAL(triggered(bool)),mview,SLOT(Undo())); connect(actionRedo,SIGNAL(triggered(bool)),mview,SLOT(Redo())); + } MWindow::~MWindow() @@ -193,37 +196,33 @@ void MWindow::AutoSave() } } -void MWindow::RunCMap() -{ - double frameRate = dmanager->GetCMapFrameRate(); - _cMapFrame=1; - if (frameRate==0) - { - statusBar()->showMessage(tr("No cognitive map has been loaded!"),10000); - return; - } - _cMapTimer->setInterval(1/frameRate*1000); - _cMapTimer->start(); -} +//void MWindow::RunCMap() +//{ -void MWindow::UpdateCMap() -{ - _cMapFrame++; - if (_cMapFrame>dmanager->GetLastCMapFrame()) - { - _cMapTimer->stop(); - dmanager->ShowCMapFrame(1); - return; - } - dmanager->ShowCMapFrame(_cMapFrame); -} +// double frameRate = dmanager->GetCMapFrameRate(); +// _cMapFrame=1; +// if (frameRate==0) +// { +// statusBar()->showMessage(tr("No cognitive map has been loaded!"),10000); +// return; +// } +// _cMapTimer->setInterval(1/frameRate*1000); +// _cMapTimer->start(); +//} + +//void MWindow::UpdateCMap() +//{ +// _cMapFrame++; +// if (_cMapFrame>dmanager->GetLastCMapFrame()) +// { +// _cMapTimer->stop(); +// dmanager->ShowCMapFrame(1); +// return; +// } +// dmanager->ShowCMapFrame(_cMapFrame); +//} -void MWindow::add_landmark() -{ - jpsLandmark* landmark = mview->get_landmarks().last(); - dmanager->new_landmark(landmark); -} void MWindow::Settings() { @@ -281,12 +280,14 @@ void MWindow::openFileXML() //RoutingFile QString fileNameRouting= fileName.split(".").first()+"_routing.xml"; QFile fileRouting(fileNameRouting); + bool statusFileRouting=true; if (!fileRouting.open(QIODevice::ReadOnly | QIODevice::Text)) { - return; + statusFileRouting=false; + } - if (!dmanager->readXML(file) || !dmanager->readRoutingXML(fileRouting)) + if (!dmanager->readXML(file)) { QMessageBox::critical(this, "OpenFileXML", @@ -295,8 +296,14 @@ void MWindow::openFileXML() statusBar()->showMessage("XML-File could not be parsed!",10000); } + + else { + //optional: load routing file + if (statusFileRouting==true) + dmanager->readRoutingXML(fileRouting); + //AutoZoom to drawing mview->AutoZoom(); statusBar()->showMessage("XML-File successfully loaded!",10000); @@ -304,7 +311,7 @@ void MWindow::openFileXML() } -void MWindow::openFileCMap() +void MWindow::openFileCogMap() { QString fileName=QFileDialog::getOpenFileName(this,tr("Open XML"),"",tr("XML-Files (*.xml)")); QFile file(fileName); @@ -327,7 +334,6 @@ void MWindow::openFileCMap() { statusBar()->showMessage("Cognitive map successfully loaded!",10000); - dmanager->ShowCMapFrame(1); } } @@ -381,6 +387,20 @@ void MWindow::saveAsDXF() } } +void MWindow::SaveCogMapXML() +{ + QString fileName = QFileDialog::getSaveFileName(this,tr("Save CognitiveMap XML"),"",tr("XML-Files (*.xml)")); + if (fileName.isEmpty()) return; + QFile file(fileName); + + if(file.open(QIODevice::WriteOnly|QIODevice::Text)) + { + dmanager->WriteCognitiveMapXML(file); + //file.write(coord_string.toUtf8());//textEdit->toPlainText().toUtf8()); + statusBar()->showMessage(tr("XML-File successfully saved!"),10000); + } +} + void MWindow::info(){ @@ -455,6 +475,7 @@ void MWindow::disableDrawing() this->actionExit->setChecked(false); this->actionLandmark->setChecked(false); this->actionHLine->setChecked(false); + this->actionCopy->setChecked(false); } void MWindow::objectsnap() @@ -527,7 +548,6 @@ void MWindow::define_landmark() else { lwidget->close(); - mview->ClearWaypoints(); lwidget=nullptr; actionLandmarkWidget->setChecked(false); } @@ -543,6 +563,7 @@ void MWindow::en_selectMode() actionExit->setChecked(false); actionHLine->setChecked(false); actionLandmark->setChecked(false); + actionCopy->setChecked(false); length_edit->clearFocus(); } @@ -594,14 +615,8 @@ void MWindow::closeEvent(QCloseEvent *event) } - - - - - - - - - - - +void MWindow::on_actionCopy_triggered() +{ + actionCopy->setChecked(true); + mview->start_Copy_function(); +} diff --git a/src/mainWindow.h b/src/mainWindow.h index 75e99c3cb7251d480db65446c970d74d3e65877b..603b63f199f3bc4ca80e401ec7ee18ffbdcc7bce 100644 --- a/src/mainWindow.h +++ b/src/mainWindow.h @@ -1,7 +1,7 @@ /** * \file mainWindow.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -75,9 +75,12 @@ protected slots: //parseFiles void openFile(); void openFileXML(); - void openFileCMap(); + void openFileCogMap(); void saveFile(); void saveAsDXF(); + + //cogmap + void SaveCogMapXML(); //about void info(); @@ -106,7 +109,6 @@ protected slots: //Room and landmark def void define_room(); void define_landmark(); - void add_landmark(); //view options void gridmode(); @@ -116,15 +118,18 @@ protected slots: //autosave void AutoSave(); - + + //CMap - void RunCMap(); - void UpdateCMap(); + //void RunCMap(); + //void UpdateCMap(); //quit void closeEvent(QCloseEvent *event); +private slots: + void on_actionCopy_triggered(); }; diff --git a/src/rooms.cpp b/src/rooms.cpp index 146555edcd3223e658a6619e550c8e71da355454..3b4b2f42ae72a5e4e71b9a63e1f657370aff30f7 100644 --- a/src/rooms.cpp +++ b/src/rooms.cpp @@ -1,7 +1,7 @@ /** * \file rooms.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/rooms.h b/src/rooms.h index 88f2be036c9f90bdb6586b5c7a70e96919f08a5e..9cfdd3f2c26821ed451cf15959d59589f75c96ae 100644 --- a/src/rooms.h +++ b/src/rooms.h @@ -1,7 +1,7 @@ /** * \file rooms.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/roomwidget.cpp b/src/roomwidget.cpp index 2b705cdbf74dfec94406ea961c76c3cc5ec6e737..c0f15506a247aec54f81e0bb71784fa240124d54 100644 --- a/src/roomwidget.cpp +++ b/src/roomwidget.cpp @@ -1,7 +1,7 @@ /** * \file roomwidget.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/roomwidget.h b/src/roomwidget.h index ba1365866b45b771ea273080885ccd7094db050a..a8b5361ad3081f9a8b038d6e2a28d5389c392bed 100644 --- a/src/roomwidget.h +++ b/src/roomwidget.h @@ -1,7 +1,7 @@ /** * \file roomwidget.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License diff --git a/src/widgetlandmark.cpp b/src/widgetlandmark.cpp index 6e2ce7508518cd5eb6d6218f05bcd636828d5709..4b23a05eb5a4c57c2b3e307eb5fc8fdde4b2bda5 100644 --- a/src/widgetlandmark.cpp +++ b/src/widgetlandmark.cpp @@ -1,7 +1,7 @@ /** * \file widgetlandmark.cpp * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,7 +22,7 @@ * * \section Description * With the help of this class the user is able to handle landmarks and set associations (waypoints) relying on a certain landmark. - * widgetlandmark is not enabled in v0.7. + * widgetlandmark is not enabled in v0.8.1. * * **/ @@ -30,8 +30,9 @@ #include "widgetlandmark.h" #include "ui_widgetlandmark.h" -#include +#include +#include widgetLandmark::widgetLandmark(QWidget *parent, jpsDatamanager *dmanager, jpsGraphicsView *gview): QTabWidget(parent), @@ -40,19 +41,46 @@ widgetLandmark::widgetLandmark(QWidget *parent, jpsDatamanager *dmanager, jpsGra ui->setupUi(this); _dmanager=dmanager; _gview=gview; - _waypointIDCounter=0; - show_landmarks(); + //Landmark type + ui->Box_landmarkType->addItem("Landmark"); + ui->Box_landmarkType->addItem("Main Target"); + show_landmarks(); + connect(ui->apply_name_button,SIGNAL(clicked(bool)),this,SLOT(change_name())); connect(ui->closeButton,SIGNAL(clicked(bool)),this->parentWidget(),SLOT(define_landmark())); + connect(ui->closeButton_2,SIGNAL(clicked(bool)),this->parentWidget(),SLOT(define_landmark())); + connect(ui->closeButton_regions,SIGNAL(clicked(bool)),this->parentWidget(),SLOT(define_landmark())); + connect(ui->cogmap_closeButton,SIGNAL(clicked(bool)),this->parentWidget(),SLOT(define_landmark())); connect(ui->list_landmarks,SIGNAL(activated(int)),this,SLOT(enable_room_selection())); + connect(ui->list_landmarks,SIGNAL(activated(int)),this,SLOT(ShowLandmarkType())); connect(ui->list_landmarks,SIGNAL(currentIndexChanged(int)),_gview,SLOT(unmarkLandmark())); connect(ui->roomBox_landmarks,SIGNAL(activated(int)),this,SLOT(add_room_to_landmark())); - connect(ui->add_button,SIGNAL(clicked(bool)),_gview,SLOT(StatAssoDef())); - connect(_gview,SIGNAL(AssoDefCompleted()),this,SLOT(AddAssociation())); + connect(ui->add_button,SIGNAL(clicked(bool)),_gview,SLOT(StatPositionDef())); + connect(_gview,SIGNAL(PositionDefCompleted()),this,SLOT(SetPosInCMap())); connect(ui->remove_button,SIGNAL(clicked(bool)),this,SLOT(RemoveAssociation())); + connect(ui->button_showhide,SIGNAL(clicked(bool)),this,SLOT(ShowHideLandmark())); + connect(ui->Box_landmarkType,SIGNAL(activated(int)),this,SLOT(SetLandmarkType())); + + //connectionDef + connect(ui->add_button_connections,SIGNAL(clicked(bool)),this,SLOT(NewConnection())); + connect(_gview,SIGNAL(DefConnection1Completed()),this,SLOT(AskForSecondLandmark())); + connect(_gview,SIGNAL(DefConnection2Completed()),this,SLOT(SetLandmarksToConnection())); + connect(ui->remove_button_connections,SIGNAL(clicked(bool)),this,SLOT(RemoveConnection())); + + //Region Def + connect(ui->add_button_regions,SIGNAL(clicked(bool)),_gview,SLOT(ChangeRegionStatDef())); + connect(_gview,SIGNAL(RegionDefCompleted()),this,SLOT(NewRegion())); + connect(ui->remove_button_regions,SIGNAL(clicked(bool)),this,SLOT(RemoveRegion())); + connect(ui->box_regions,SIGNAL(activated(int)),this,SLOT(SetLandmarkToRegion())); + connect(ui->button_showhide_region,SIGNAL(clicked(bool)),this,SLOT(ShowHideRegion())); + + //saveCogMap + connect(ui->save_button_cogmap,SIGNAL(clicked(bool)),this->parentWidget(),SLOT(SaveCogMapXML())); + connect(ui->save_button_multiple_maps,SIGNAL(clicked(bool)),this,SLOT(CreateSimilarMaps())); + } widgetLandmark::~widgetLandmark() @@ -66,8 +94,13 @@ void widgetLandmark::show_landmarks() QList landmarks=_dmanager->get_landmarks(); for (jpsLandmark* landmark:landmarks) { - ui->list_landmarks->addItem(landmark->get_name()); + ui->list_landmarks->addItem(landmark->GetCaption()); } + if (!landmarks.empty()) + enable_room_selection(); + ShowLandmarkType(); + ShowRegionBox(); + ShowRegions(); } @@ -79,7 +112,7 @@ void widgetLandmark::add_room_to_landmark() int cRoomRow=ui->roomBox_landmarks->currentIndex(); if (cRoomRow!=-1) { - _dmanager->get_landmarks()[cLanRow]->set_room(_dmanager->get_roomlist()[cRoomRow]); + _dmanager->get_landmarks()[cLanRow]->SetRoom(_dmanager->get_roomlist()[cRoomRow]); } } } @@ -91,9 +124,6 @@ void widgetLandmark::enable_room_selection() ui->roomBox_landmarks->setEnabled(true); ui->is_in->setEnabled(true); ui->roomBox_landmarks->clear(); - ui->label_Waypoints->setEnabled(true); - ui->label_Waypoints2->setEnabled(true); - ui->listWaypoints->setEnabled(true); ui->add_button->setEnabled(true); ui->remove_button->setEnabled(true); @@ -110,7 +140,7 @@ void widgetLandmark::enable_room_selection() int cLanRow=ui->list_landmarks->currentIndex(); if (cLanRow!=-1) { - jpsRoom* cRoom = _dmanager->get_landmarks()[cLanRow]->get_room(); + jpsRoom* cRoom = _dmanager->get_landmarks()[cLanRow]->GetRoom(); if (cRoom!=nullptr) { int index = _dmanager->get_roomlist().indexOf(cRoom); @@ -123,10 +153,9 @@ void widgetLandmark::enable_room_selection() } - ///mark Landmark + //mark Landmark _gview->select_landmark(_dmanager->get_landmarks()[cLanRow]); - ShowAssociations(); } else @@ -141,70 +170,387 @@ void widgetLandmark::disable_room_selection() ui->is_in->setEnabled(false); ui->label_Waypoints->setEnabled(false); ui->label_Waypoints2->setEnabled(false); - ui->listWaypoints->setEnabled(false); ui->add_button->setEnabled(false); ui->remove_button->setEnabled(false); } void widgetLandmark::change_name() +{ + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) + { + landmark->SetCaption(ui->chname_edit->text()); + int row = ui->list_landmarks->currentIndex(); + this->show_landmarks(); + ui->list_landmarks->setCurrentIndex(row); + } + +} + +void widgetLandmark::SetPosInCMap() { - if (ui->list_landmarks->currentIndex()!=-1) + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) { - int crow=ui->list_landmarks->currentIndex(); + landmark->SetRect(_gview->GetCurrentSelectRect()->rect()); + QString string = "Ellipse: x: "+QString::number(landmark->GetRect().center().x()) + + " y: "+QString::number(landmark->GetRect().center().y())+" rA: "+QString::number(landmark->GetA()) + + " rB: "+QString::number(landmark->GetB()); + ui->ellipse_label->setText(string); + ui->add_button->setChecked(false); - _dmanager->get_landmarks()[crow]->set_name(ui->chname_edit->text()); + // show ellipse and text in graphics view + QPen pen = QPen(Qt::blue,2); + pen.setCosmetic(true); + QGraphicsEllipseItem* ellipse = _gview->GetScene()->addEllipse(landmark->GetRect(),pen); + ellipse->setTransform(QTransform::fromTranslate(_gview->GetTranslationX(),_gview->GetTranslationY()), true); + QGraphicsTextItem* text = _gview->GetScene()->addText(landmark->GetCaption()); + text->setPos(landmark->GetPos().x()+_gview->GetTranslationX(),landmark->GetPos().y()+_gview->GetTranslationY()); + //text->setScale(gl_scale_f); + text->setData(0,_gview->GetScaleF()); + text->setTransform(QTransform::fromScale(_gview->GetScaleF(),-_gview->GetScaleF()),true); + landmark->SetEllipseItem(ellipse); + landmark->SetTextItem(text); + } - this->show_landmarks(); +} + +void widgetLandmark::ShowLandmarkType() +{ + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) + { + if (landmark->GetType()=="Landmark") + ui->Box_landmarkType->setCurrentIndex(0); + else + ui->Box_landmarkType->setCurrentIndex(1); + } +} + +void widgetLandmark::SetLandmarkType() +{ + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) + { + landmark->SetType(ui->Box_landmarkType->currentText()); } } -void widgetLandmark::AddAssociation() +void widgetLandmark::ShowRegionBox() { - if (ui->list_landmarks->currentIndex()!=-1) + if (_dmanager->GetRegions().empty()) + return; + + for (jpsRegion* region:_dmanager->GetRegions()) { - int cLanRow=ui->list_landmarks->currentIndex(); + ui->box_regions->addItem(region->GetCaption()); + } - _dmanager->get_landmarks()[cLanRow]->AddWaypoint(std::make_shared(_gview->GetCurrentSelectRect()->rect(),_waypointIDCounter)); + jpsLandmark* landmark = GetCurrentLandmark(); + QString cRegion; + if (landmark!=nullptr) + { + if (landmark->GetRegion()!=nullptr) - ShowAssociations(); - _waypointIDCounter++; - ui->add_button->setChecked(false); + cRegion = landmark->GetRegion()->GetCaption(); + for (int i=0; ibox_regions->count(); ++i) + { + if (ui->box_regions->itemText(i)==cRegion) + { + ui->box_regions->setCurrentIndex(i); + break; + } + } } } -void widgetLandmark::ShowAssociations() + + +void widgetLandmark::AddAssociation() { - ui->listWaypoints->clear(); - if (ui->list_landmarks->currentIndex()!=-1) +// if (ui->list_landmarks->currentIndex()!=-1) +// { +// int cLanRow=ui->list_landmarks->currentIndex(); + +// _dmanager->get_landmarks()[cLanRow]->AddWaypoint(std::make_shared(_gview->GetCurrentSelectRect()->rect(),_waypointIDCounter)); + +// ShowAssociations(); +// _waypointIDCounter++; +// ui->add_button->setChecked(false); +// } +} + +void widgetLandmark::ShowHideLandmark() +{ + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) { - int cLanRow=ui->list_landmarks->currentIndex(); - QList waypoints = _dmanager->get_landmarks()[cLanRow]->GetWaypoints(); + if (landmark->GetEllipseItem()==nullptr && landmark->GetPixmap()->isVisible()) + { + landmark->GetPixmap()->setVisible(false); + landmark->GetPixmapTextItem()->setVisible(false); + } + else if (landmark->GetEllipseItem()==nullptr && !landmark->GetPixmap()->isVisible()) + { + landmark->GetPixmap()->setVisible(true); + landmark->GetPixmapTextItem()->setVisible(true); + } + else if (!landmark->GetEllipseItem()->isVisible()) + { + landmark->GetPixmap()->setVisible(true); + landmark->GetPixmapTextItem()->setVisible(true); + landmark->GetEllipseItem()->setVisible(true); + landmark->GetTextItem()->setVisible(true); + } + else + { + landmark->GetPixmap()->setVisible(false); + landmark->GetPixmapTextItem()->setVisible(false); + landmark->GetEllipseItem()->setVisible(false); + landmark->GetTextItem()->setVisible(false); + } - for (ptrWaypoint waypoint:waypoints) + } +} + +void widgetLandmark::NewConnection() +{ + jpsConnection* connection = new jpsConnection(); + _dmanager->NewConnection(connection); + _currentConnection=connection; + AskForFirstLandmark(); +} + +void widgetLandmark::AskForFirstLandmark() +{ + _gview->SetStatDefConnections(1); +} + +void widgetLandmark::AskForSecondLandmark() +{ + // if mousePressed: if mousepos in landmark: first landmark set in connection + QPointF mousePos = _gview->return_Pos(); + for (jpsLandmark* landmark:_dmanager->get_landmarks()) + { + if (landmark->GetEllipseItem()!=nullptr) { - QPointF pos = waypoint->GetPos(); - QString name = "Waypoint: x: "+QString::number(pos.x())+"y: "+QString::number(pos.y()); - ui->listWaypoints->addItem(name); + if (landmark->GetEllipseItem()->boundingRect().contains(mousePos)) + { + _currentConnection->SetFirstLandmark(landmark); + landmark->NewConnection(_currentConnection); + _gview->SetStatDefConnections(2); + return; + } + } + } +} +void widgetLandmark::SetLandmarksToConnection() +{ + // if mousePressed: if mousepos in landmark: first landmark set in connection + QPointF mousePos = _gview->return_Pos(); + for (jpsLandmark* landmark:_dmanager->get_landmarks()) + { + if (landmark->GetEllipseItem()!=nullptr) + { + if (landmark->GetEllipseItem()->boundingRect().contains(mousePos)) + { + _currentConnection->SetSecondLandmark(landmark); + landmark->NewConnection(_currentConnection); + _gview->SetStatDefConnections(0); + AddConnectionsToWidget(); + SetLineItemAsConnection(); + ui->add_button_connections->setChecked(false); + return; + } } - _gview->ShowWaypoints(waypoints); } + ui->add_button_connections->setChecked(false); + } -void widgetLandmark::RemoveAssociation() +void widgetLandmark::SetLineItemAsConnection() { - if (ui->list_landmarks->currentIndex()!=-1) + QLineF line = QLineF(_currentConnection->GetLandmarks().first->GetPos(),_currentConnection->GetLandmarks().second->GetPos()); + QPen pen = QPen(Qt::blue,2); + pen.setCosmetic(true); + QGraphicsLineItem* lineItem = _gview->GetScene()->addLine(line,pen); + lineItem->setTransform(QTransform::fromTranslate(_gview->GetTranslationX(),_gview->GetTranslationY()), true); + _currentConnection->SetLineItem(lineItem); + _currentConnection=nullptr; +} + +void widgetLandmark::AddConnectionsToWidget() +{ + QString string = _currentConnection->GetLandmarks().first->GetCaption()+" <-> "+_currentConnection->GetLandmarks().second->GetCaption(); + ui->listWidgetConnections->addItem(string); + +} + +void widgetLandmark::RemoveConnection() +{ + if (ui->listWidgetConnections->currentRow()!=-1) { + int currentRow = ui->listWidgetConnections->currentRow(); + QListWidgetItem* item = ui->listWidgetConnections->takeItem(currentRow); + delete item; + _dmanager->RemoveConnection(_dmanager->GetAllConnections()[currentRow]); + } +} - int cLanRow=ui->list_landmarks->currentIndex(); +void widgetLandmark::NewRegion() +{ + ui->add_button->setChecked(false); + // show ellipse and text in graphics view + QPen pen = QPen(Qt::darkGreen,2); + pen.setCosmetic(true); + QRectF rect = _gview->GetCurrentSelectRect()->rect(); + QGraphicsEllipseItem* ellipse = _gview->GetScene()->addEllipse(rect,pen); + ellipse->setTransform(QTransform::fromTranslate(_gview->GetTranslationX(),_gview->GetTranslationY()), true); + + + // create region + jpsRegion* region = new jpsRegion(_dmanager->GetRegionCounter(),"Region"+QString::number(_dmanager->GetRegionCounter()), + rect.center(),std::fabs(rect.width()/2.0),std::fabs(rect.height()/2.0)); + + + QGraphicsTextItem* text = _gview->GetScene()->addText(region->GetCaption()); + text->setPos(rect.center().x()+_gview->GetTranslationX(),rect.center().y()+_gview->GetTranslationY()); + //text->setScale(gl_scale_f); + text->setData(0,_gview->GetScaleF()); + text->setTransform(QTransform::fromScale(_gview->GetScaleF(),-_gview->GetScaleF()),true); - if (ui->listWaypoints->currentItem()!=nullptr) + region->SetTextItem(text); + region->SetEllipse(ellipse); + _dmanager->NewRegion(region); + + //show Region in listwidget + ShowRegions(); +} + +void widgetLandmark::RemoveRegion() +{ + int row = ui->listWidgetRegions->currentRow(); + if (row!=-1) + { + _dmanager->RemoveRegion(_dmanager->GetRegions()[row]); + QListWidgetItem* item = ui->listWidgetRegions->takeItem(row); + delete item; + } +} + +void widgetLandmark::SetLandmarkToRegion() +{ + jpsLandmark* landmark = GetCurrentLandmark(); + + if (landmark!=nullptr) + { + int row = ui->box_regions->currentIndex(); + + if (row!=-1) { - int cWayRow=ui->listWaypoints->currentRow(); + for (jpsRegion* region:_dmanager->GetRegions()) + { + region->RemoveLandmark(landmark); + } + jpsRegion* cRegion = _dmanager->GetRegions()[row]; + landmark->SetRegion(cRegion); + cRegion->AddLandmark(landmark); + } + } + +} + +void widgetLandmark::ShowHideRegion() +{ + jpsRegion* region = GetCurrentRegion(); - _dmanager->get_landmarks()[cLanRow]->RemoveWaypoint(_dmanager->get_landmarks()[cLanRow]->GetWaypoints()[cWayRow]); - ShowAssociations(); + if (region!=nullptr) + { + if (region->GetEllipseItem()->isVisible()) + { + region->GetEllipseItem()->setVisible(false); + region->GetTextItem()->setVisible(false); + } + else + { + region->GetEllipseItem()->setVisible(true); + region->GetTextItem()->setVisible(true); } + } +} + +void widgetLandmark::ShowRegions() +{ + ui->listWidgetRegions->clear(); + for (jpsRegion* region:_dmanager->GetRegions()) + { + + QString string = "x: "+QString::number(region->GetPos().x()) + + " y: "+QString::number(region->GetPos().y())+" rA: "+QString::number(region->GetA()) + + " rB: "+QString::number(region->GetB()); + ui->listWidgetRegions->addItem(string); + } +} + +void widgetLandmark::CreateSimilarMaps() +{ + int numberMaps = ui->spinBox_numberMaps->value(); + for (int i=0; iCreateAndSaveASimilarCogMap(i); } + //ui->progressBar->setVisible(false); +} + + + + + +void widgetLandmark::RemoveAssociation() +{ +// if (ui->list_landmarks->currentIndex()!=-1) +// { + +// int cLanRow=ui->list_landmarks->currentIndex(); + +// if (ui->listWaypoints->currentItem()!=nullptr) +// { +// int cWayRow=ui->listWaypoints->currentRow(); + +// _dmanager->get_landmarks()[cLanRow]->RemoveWaypoint(_dmanager->get_landmarks()[cLanRow]->GetWaypoints()[cWayRow]); +// ShowAssociations(); +// } + +// } +} + +jpsLandmark* widgetLandmark::GetCurrentLandmark() const +{ + if (ui->list_landmarks->currentIndex()!=-1) + { + int crow=ui->list_landmarks->currentIndex(); + + return _dmanager->get_landmarks()[crow]; + } + else + return nullptr; +} + +jpsRegion *widgetLandmark::GetCurrentRegion() const +{ + if (ui->listWidgetRegions->currentRow()!=-1) + { + int crow=ui->listWidgetRegions->currentRow(); + + return _dmanager->GetRegions()[crow]; + } + else + return nullptr; } diff --git a/src/widgetlandmark.h b/src/widgetlandmark.h index 71369c74d65b91802011a8b4ccd009238cced51a..9e62c7cc317e91384d66b763652453094c61e74e 100644 --- a/src/widgetlandmark.h +++ b/src/widgetlandmark.h @@ -1,7 +1,7 @@ /** * \file widgetlandmark.h * \date Jun 26, 2015 - * \version v0.7 + * \version v0.8.1 * \copyright <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved. * * \section License @@ -22,7 +22,7 @@ * * \section Description * With the help of this class the user is able to handle landmarks and set associations (waypoints) relying on a certain landmark. - * widgetlandmark is not enabled in v0.7. + * widgetlandmark is not enabled in v0.8.1. * * **/ @@ -33,6 +33,10 @@ #include #include "datamanager.h" #include "GraphicView.h" +#include + +using ptrLandmark = std::shared_ptr; + namespace Ui { class widgetLandmark; @@ -52,15 +56,40 @@ protected slots: void enable_room_selection(); void disable_room_selection(); void change_name(); + void SetPosInCMap(); + void ShowLandmarkType(); + void SetLandmarkType(); + void ShowRegionBox(); + //associated landmarks void AddAssociation(); - void ShowAssociations(); void RemoveAssociation(); + //Show or hide landmark picture and ellipse in graphicsview + void ShowHideLandmark(); + //connections + void NewConnection(); + void AskForFirstLandmark(); + void AskForSecondLandmark(); + void SetLandmarksToConnection(); + void SetLineItemAsConnection(); + void AddConnectionsToWidget(); + void RemoveConnection(); + //regions + void NewRegion(); + void RemoveRegion(); + void SetLandmarkToRegion(); + void ShowHideRegion(); + void ShowRegions(); + + void CreateSimilarMaps(); private: + jpsLandmark *GetCurrentLandmark() const; + jpsRegion* GetCurrentRegion() const; Ui::widgetLandmark *ui; jpsDatamanager* _dmanager; jpsGraphicsView* _gview; - int _waypointIDCounter; + jpsConnection* _currentConnection; + }; #endif // WIDGETLANDMARK_H diff --git a/src/widgetsettings.cpp b/src/widgetsettings.cpp index 7c556e9d304a4bef3e0db318fd5f77c03ea0dbe0..925cf6d090b82e8a41f5e538bb7383fffd225a72 100644 --- a/src/widgetsettings.cpp +++ b/src/widgetsettings.cpp @@ -1,3 +1,27 @@ +/** + * \file widgetsettings.cpp + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #include "widgetsettings.h" #include "ui_widgetsettings.h" diff --git a/src/widgetsettings.h b/src/widgetsettings.h index 604d8cf417194146b6c9a8ec12ffdee3cccb9175..a7c5eb8e5822dbf0e1ebc6fdf4b3ba070c2de034 100644 --- a/src/widgetsettings.h +++ b/src/widgetsettings.h @@ -1,3 +1,27 @@ +/** + * \file widgetsettings.h + * \date Mar 07, 2016 + * \version v0.8.1 + * \copyright <2009-2016> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ + + #ifndef WIDGETSETTINGS_H #define WIDGETSETTINGS_H diff --git a/update_version.sh b/update_version.sh new file mode 100755 index 0000000000000000000000000000000000000000..031d9c1800dbe7ba7603c0d818c3185257e13ea1 --- /dev/null +++ b/update_version.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# ----------------- change these parameter --------- +old_version='v0.7' +new_version='v0.8.1' +# -------------------------------------------------- + +Date=`date +"%b %d, %Y"` +Year=`date +"%Y"` +header=" + * \\date $Date + * \\version ${new_version} + * \\copyright <2009-$Year> Forschungszentrum Jülich GmbH. All rights reserved. + * + * \\section License + * This file is part of JuPedSim. + * + * JuPedSim is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * JuPedSim is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JuPedSim. If not, see . + **/ +" + +for f in $(find . -path ./dxflib -prune -name '*.cpp' -or -name '*.h' ); # exclude dxflib +do + +#file uptodate +if grep -R -q "$new_version" $f; then + echo "File $f is uptodate" + continue +fi + +if grep -R -q "\version $old_version" $f; then + echo "Processing $f $old_version ---> $new_version" + sed -i -e "s/${old_version}/${new_version}/g" $f +else + echo "File $f does not contain a version number. Adding header.." + VAR="/** + * \\file `basename $f` $header + " + ed -s "$f" << EOF +0a +$VAR +. +w +EOF +fi +done +