Commit 8c91f4e1 authored by Tao Zhong's avatar Tao Zhong

Merge branch '#issue127' into version088

parents 47462bca d5a030d6
Pipeline #19747 passed with stages
in 25 seconds
This diff is collapsed.
This diff is collapsed.
......@@ -179,9 +179,6 @@ public:
void SetGrid(QString grid);
void ChangeGridSize(const qreal& factor);
QList<JPSSource *> getSources();
QList<JPSGoal *> getGoals();
public slots:
//Landmarks/Regions
void StatPositionDef();
......@@ -204,6 +201,9 @@ public slots:
void deleteGoal(int index);
void seleteGoal(const QModelIndex &index);
QList<JPSSource *> getSources();
QList<JPSGoal *> getGoals();
protected:
//Mouse events
void mouseMoveEvent(QMouseEvent * mouseEvent) override;
......
......@@ -55,6 +55,7 @@ jpsDatamanager::jpsDatamanager(QWidget *parent, jpsGraphicsView *view)
roomlist= QList<jpsRoom *> ();
sourcelist = _mView->getSources();
goallist = _mView->getGoals();
}
jpsDatamanager::~jpsDatamanager()
......@@ -435,7 +436,7 @@ const int &jpsDatamanager::GetRegionCounter() const
void jpsDatamanager::writeXML(QFile &file)
{
qDebug(">> Enter jpsDatamanager::writeXML");
QXmlStreamWriter* stream = new QXmlStreamWriter(&file);
auto *stream = new QXmlStreamWriter(&file);
QList<jpsLineItem* > lines = _mView->get_line_vector();
writeHeader(stream);
......@@ -660,7 +661,7 @@ void jpsDatamanager::AutoSaveXML(QFile &file)
void jpsDatamanager::writeHeader(QXmlStreamWriter *stream)
{
qDebug("Enter jpsDatamanager::writeHeader");
qDebug("Enter jpsDatamanager::writeHeader");
stream->setAutoFormatting(true);
stream->writeStartDocument("1.0",true);
......@@ -675,7 +676,7 @@ void jpsDatamanager::writeHeader(QXmlStreamWriter *stream)
void jpsDatamanager::writeRoutingHeader(QXmlStreamWriter *stream)
{
qDebug("Enter jpsDatamanager::writeRoutingHeader");
qDebug("Enter jpsDatamanager::writeRoutingHeader");
stream->setAutoFormatting(true);
stream->writeStartDocument("1.0",true);
......@@ -941,11 +942,12 @@ void jpsDatamanager::AutoSaveRooms(QXmlStreamWriter *stream, QList<jpsLineItem *
void jpsDatamanager::writeCrossings(QXmlStreamWriter *stream, QList<jpsLineItem *> &lines)
{
qDebug("Enter jpsDatamanager::writeCrossings");
qDebug("Enter jpsDatamanager::writeCrossings");
stream->writeStartElement("crossings");
for (int i=0; i<crossingList.size(); i++)
{
if (crossingList[i]->IsExit()==false && crossingList[i]->get_roomList()[0]->get_type()!="Stair" && crossingList[i]->get_roomList()[1]->get_type()!="Stair")
if (!crossingList[i]->IsExit() && crossingList[i]->get_roomList()[0]->get_type()!="Stair" &&
crossingList[i]->get_roomList()[1]->get_type()!="Stair")
{
stream->writeStartElement("crossing");
stream->writeAttribute("id",QString::number(i));
......@@ -2199,9 +2201,10 @@ void jpsDatamanager::parseTransitions(QXmlStreamReader &xmlReader)
qreal y2=xmlReader.attributes().value("py").toString().toFloat();
qDebug("\t x1 = %.2f, y1 = %.2f, x2 = %.2f y2 = %.2f", x1, y1, x2, y2);
jpsLineItem* lineItem = _mView->addLineItem(x1,y1,x2,y2,"Exit");
if (id!=-2)
{
jpsCrossing* exit = new jpsCrossing(lineItem);
jpsCrossing *exit = new jpsCrossing(lineItem);
exit->set_id(id);
exit->change_name(caption);
//exit->set_type(type);
......@@ -2844,6 +2847,9 @@ bool LineIsEqual(const QLineF& line1, const QLineF& line2, double eps)
*/
void jpsDatamanager::writeSources(QXmlStreamWriter *stream, QList<JPSSource *> &sourcelist) {
sourcelist.clear();
sourcelist = _mView->getSources();
for(JPSSource* source:sourcelist)
{
if(source->isBeSaved())
......@@ -2951,7 +2957,7 @@ void jpsDatamanager::writeSourceHeader(QXmlStreamWriter *stream)
void jpsDatamanager::writeGoalXML(QFile &file)
{
QXmlStreamWriter* stream = new QXmlStreamWriter(&file);
auto *stream = new QXmlStreamWriter(&file);
stream->setAutoFormatting(true);
......@@ -2962,8 +2968,6 @@ void jpsDatamanager::writeGoalXML(QFile &file)
stream->writeAttribute("version", "0.8");
stream->writeStartElement("goals");
goallist.clear();
goallist = _mView->getGoals();
writeGoals(stream, goallist);
stream->writeEndElement(); //end goals
......@@ -2975,6 +2979,9 @@ void jpsDatamanager::writeGoalXML(QFile &file)
void jpsDatamanager::writeGoals(QXmlStreamWriter *stream, QList<JPSGoal *> &goallist)
{
goallist.clear();
goallist = _mView->getGoals();
for(JPSGoal* goal:goallist)
{
if(goal->getBeSaved() == "true")
......@@ -3015,8 +3022,10 @@ void jpsDatamanager::writeGoals(QXmlStreamWriter *stream, QList<JPSGoal *> &goal
stream->writeAttribute("py", QString::number(goal->rect().topLeft().y()));
stream->writeEndElement();
stream->writeEndElement();
stream->writeEndElement();//end goal
}
stream->writeEndElement();//end goals
}
}
......@@ -3063,13 +3072,140 @@ void jpsDatamanager::writeTransitionXML(QFile &file)
stream = nullptr;
}
const QList<JPSGoal *> &jpsDatamanager::getGoallist()
{
goallist.clear();
goallist = _mView->getGoals();
return goallist;
}
/*
Since v0.8.8
Write traffic (doors) as a external xml file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JPScore project="JPS-Project" version="0.8">
<traffic_constraints>
<doors> <!-- doors states are: close or open -->
<door trans_id="2" caption="NaN" state="open" />
<door trans_id="6" caption="NaN" state="open" outflow="1.0" max_agents="20"/>
</doors>
</traffic_constraints>
</JPScore>
*/
void jpsDatamanager::writeTrafficXML(QFile &file)
{
QXmlStreamWriter *stream = new QXmlStreamWriter(&file);
QList<jpsCrossing *> crossings =get_crossingList();
QList<jpsCrossing *> doorlist;
for(jpsCrossing *crossing:crossings)
{
if(crossing->IsExit())
doorlist.append(crossing);
}
stream->setAutoFormatting(true);
stream->writeStartDocument("1.0",true);
stream->setCodec("UTF-8");
stream->writeStartElement("JPScore");
stream->writeAttribute("project","JPS-Project");
stream->writeAttribute("version", "0.8");
stream->writeStartElement("traffic_constrains");
stream->writeStartElement("doors");
writeTraffics(stream, doorlist);
doorlist.clear();
stream->writeEndElement(); //end doors
stream->writeEndDocument();
delete stream;
stream = nullptr;
}
void jpsDatamanager::writeTraffics(QXmlStreamWriter *stream, QList<jpsCrossing *> const &doorlist)
{
for(jpsCrossing* door:doorlist)
{
stream->writeStartElement("door");
stream->writeAttribute("trans_id", QString::number(door->get_id()));
stream->writeAttribute("caption", "NaN");
if(door->isState())
stream->writeAttribute("state", "open");
else
stream->writeAttribute("state", "close");
if(!door->getOutflow().isEmpty())
stream->writeAttribute("outflow", door->getOutflow());
if(!door->getMaxAgents().isEmpty())
stream->writeAttribute("max_agents", door->getMaxAgents());
stream->writeEndElement(); //end door
}
}
bool jpsDatamanager::readTrafficXML(QFile &file)
{
QXmlStreamReader xmlReader(&file);
xmlReader.readNext(); // read first token
while (!xmlReader.atEnd())
{
if(xmlReader.isStartElement() && xmlReader.name() == QLatin1String("doors"))
{
readDoor(xmlReader);
} else
{
xmlReader.readNext();
}
}
return true;
}
void jpsDatamanager::readDoor(QXmlStreamReader &xmlReader)
{
bool state;
QString max_agents;
QString outflow;
int id;
while (xmlReader.readNextStartElement())
{
if(xmlReader.name() == QLatin1String("door"))
{
state = xmlReader.attributes().value("state") == "open" ? true : false;
max_agents = xmlReader.attributes().value("max_agents").toString();
outflow = xmlReader.attributes().value("outflow").toString();
id = xmlReader.attributes().value("trans_id").toInt();
for(jpsCrossing *door : crossingList)
{
if(door->get_id() == id && door->IsExit())
{
door->setState(state);
door->setMaxAgents(max_agents);
door->setOutflow(outflow);
}
}
// now token is end element, readNextStartElement() will return false. Have to use readNext
// to go to next start element.
xmlReader.readNext();
}
}
}
const QList<JPSSource *> &jpsDatamanager::getSourcelist() const {
return sourcelist;
}
......@@ -108,11 +108,20 @@ public:
void writeSourceXML(QFile &file);
void writeSourceHeader(QXmlStreamWriter *stream);
void writeSources(QXmlStreamWriter *stream, QList<JPSSource *>& sourcelist);
const QList<JPSSource *> &getSourcelist() const;
//Goals TODO: write goals by a writer class
void writeGoalXML(QFile &file);
void writeGoals(QXmlStreamWriter *stream, QList<JPSGoal *>& goallist);
const QList<JPSGoal *> &getGoallist();
//Traffic
void writeTrafficXML(QFile &file);
void writeTraffics(QXmlStreamWriter *stream, QList<jpsCrossing *> const &doorlist);
bool readTrafficXML(QFile &file);
void readDoor(QXmlStreamReader &xmlReader);
void remove_all();
void remove_marked_lines();
......@@ -202,6 +211,8 @@ public:
// read line file
bool ReadLineFile(QFile &file);
// //Show Cognitive Map
// void ShowCMapFrame(const int& frame) const;
// const double& GetCMapFrameRate() const;
......
......@@ -30,7 +30,6 @@
#include <iostream>
#include <QDebug>
jpsCrossing::jpsCrossing(jpsLineItem *line)
{
cLine=line;
......@@ -68,16 +67,40 @@ void jpsCrossing::change_name(QString name)
cName=name;
}
bool jpsCrossing::isState() const {
return state;
}
void jpsCrossing::setState(bool state) {
jpsCrossing::state = state;
}
QString jpsCrossing::getMaxAgents() const {
return max_agents;
}
void jpsCrossing::setMaxAgents(QString maxAgents) {
max_agents = maxAgents;
}
QString jpsCrossing::getOutflow() const {
return outflow;
}
void jpsCrossing::setOutflow(QString outflow) {
jpsCrossing::outflow = outflow;
}
void jpsCrossing::add_rooms(jpsRoom *room1, jpsRoom *room2)
{
qDebug("Enter jpsCrossing::add_rooms");
qDebug("\t room1 = <%s> of type <%s>",
room1->get_name().toStdString().c_str(),
room1->get_type().toStdString().c_str()
);
room1->get_type().toStdString().c_str());
roomList.clear();
roomList.push_back(room1);
room1->AddDoor(this);
if(room1->get_type().toUpper() != "STAIR") // assuming a crossing can
// not separate two stairs
this->set_elevation(room1->get_elevation());
......@@ -86,12 +109,11 @@ void jpsCrossing::add_rooms(jpsRoom *room1, jpsRoom *room2)
{
qDebug("\t room2 = <%s> of type <%s>",
room2->get_name().toStdString().c_str(),
room2->get_type().toStdString().c_str()
);
room2->get_type().toStdString().c_str());
if(room2->get_type().toUpper() != "STAIR")
this->set_elevation(room2->get_elevation());
roomList.push_back(room2);
room2->AddDoor(this);
room2->AddDoor(this);
}
qDebug("Leave jpsCrossing::add_rooms");
}
......
......@@ -34,6 +34,9 @@ class jpsCrossing
{
public:
jpsCrossing(jpsLineItem *line);
jpsCrossing(jpsLineItem *cLine, bool isExit, float elevation);
~jpsCrossing(){}
QList<jpsRoom *> get_roomList();
QString get_name();
......@@ -49,6 +52,18 @@ public:
float get_elevation();
void set_elevation(float elevation);
QString getMaxAgents() const;
void setMaxAgents(QString maxAgents);
QString getOutflow() const;
void setOutflow(QString outflow);
bool isState() const;
void setState(bool state);
private:
QList<jpsRoom *> roomList;
......@@ -57,6 +72,9 @@ private:
int cId;
bool _isExit;
float _elevation;
bool state;
QString max_agents;
QString outflow;
};
#endif // JPSCROSSING_H
......@@ -21,8 +21,8 @@
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* \section Description
* This class is representing an exit to the outside. This class will vanish in the nearer future since the class
* jpscrossing will overtake the objectives of this class.
* This class is representing an exit to the outside.
* This class will vanish in the nearer future since the class jpscrossing will overtake the objectives of this class.
*
**/
......
......@@ -115,7 +115,7 @@ MWindow :: MWindow()
//Timer needed for autosaving function
// timer will trigger autosave every 5th minute
timer = new QTimer(this);
timer->setInterval(60000);
timer->setInterval(600000);
timer->start();
_cMapTimer = new QTimer(this);
......@@ -408,6 +408,8 @@ void MWindow::openFileXML()
openSource(fileName);
openTraffic(fileName);
//AutoZoom to drawing
mview->AutoZoom();
}
......@@ -630,6 +632,12 @@ void MWindow::saveAsXML(){
if(goalsFile.open(QIODevice::WriteOnly|QIODevice::Text))
dmanager->writeGoalXML(goalsFile);
//Save traffic
QString fileNameTraffic = fileName.split(".").first()+"_traffic.xml";
QFile trafficFile(fileNameTraffic);
if(trafficFile.open(QIODevice::WriteOnly|QIODevice::Text))
dmanager->writeTrafficXML(trafficFile);
//Save transitions
QString fileNameTransition=fileName.split(".").first()+"_transitions.xml";
QFile transitionFile(fileNameTransition);
......@@ -1016,7 +1024,7 @@ QMap<QString, QString> MWindow::loadSettings()
void MWindow::on_actionNew_Inifile_triggered()
{
inifileWidget = new InifileWidget(this);
inifileWidget = new InifileWidget(this, dmanager);
inifileWidget->show();
qDebug()<< "MWindow::on_actionNew_Inifile_triggered(): inifile widget is showed!";
}
......@@ -1095,3 +1103,37 @@ void MWindow::goalButtionClicked()
goalWidget = nullptr;
}
}
/*
Since v0.8.8
Open traffic file
*/
void MWindow::openTraffic(QString fileName)
{
QString fileNameTraffic = fileName.split(".").first() + "_traffic.xml";
QFile fileTraffic(fileNameTraffic);
if(fileNameTraffic.isEmpty())
return;
if (!fileTraffic.open(QIODevice::ReadOnly | QIODevice::Text))
{
QMessageBox::warning(this, tr("Read traffic XML"),
tr("Cannot read file %1:\n%2.")
.arg(QDir::toNativeSeparators(fileName),
fileTraffic.errorString()));
return;
}
if(!dmanager->readTrafficXML(fileTraffic))
{
QMessageBox::critical(this,
"Prase traffic XML",
"Cannot prase XML-file",
QMessageBox::Ok);
} else
{
}
}
......@@ -110,6 +110,7 @@ protected slots:
void openRouting(QString fileName);
void openSource(QString fileName);
void openGoal(QString fileName);
void openTraffic(QString fileName);
void openFileCogMap();
void OpenLineFile();
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
#include <QWidget>
#include "src/tinyxml/tinyxml.h"
#include "src/datamanager.h"
namespace Ui {
class InifileWidget;
......@@ -13,19 +14,15 @@ class InifileWidget : public QWidget
Q_OBJECT
public:
explicit InifileWidget(QWidget *parent = nullptr);
explicit InifileWidget(QWidget *parent = nullptr, jpsDatamanager* dmanager = nullptr);
~InifileWidget();
private slots:
public slots:
//Inside Inifilewidget
void on_pushButton_write_clicked();
void on_pushButton_read_clicked();
//Inside Tab General
void on_checkBox_general_1_clicked();
void on_checkBox_general_2_clicked();
//Inside Tab Groups
void on_spinBox_groups_1_valueChanged(int);
......@@ -38,19 +35,22 @@ private slots:
void on_spinBox_agents_gradnav_1_valueChanged(int);
void on_spinBox_agents_krausz_1_valueChanged(int);
//Inside Tab Constraints
void on_spinBox_constraints_1_valueChanged(int);
void on_spinBox_constraints_2_valueChanged(int);
//Inside Tab Goals
void on_spinBox_goals_1_valueChanged(int);
//External file
void pushButton_GeomeryClicked();
void pushButton_GoalClicked();
void pushButton_SourceClicked();
void pushButton_TrafficClicked();
void pushButton_RoutingClicked();
private:
Ui::InifileWidget *ui;
jpsDatamanager *dataManager;
bool CheckHeaderData();
bool CheckTrafficData();
bool CheckRoutingData();
bool CheckSourceData();
bool CheckAgentData();
bool CheckModelGcfmData();
bool CheckAgentGcfmData();
......@@ -64,24 +64,26 @@ private:
bool CheckAgentKrauData();
bool CheckRouteChoiceData();
QString WriteHeaderData();
QString WriteTrafficData();
QString WriteRoutingData();
QString WriteAgentData();
QString WriteModelGcfmData();
QString WriteModelGompData();
QString WriteModelTordData();
QString WriteModelGradData();
QString WriteModelKrauData();
QString WriteRouteChoiceData();
void writeHeaderData(QXmlStreamWriter *stream, QFile &file);
void writeRoutingData(QXmlStreamWriter *stream, QFile &file);
void writeFFGlobalShortestModel(QXmlStreamWriter *stream, QFile &file);
void writeGlobalShortestModel(QXmlStreamWriter *stream, QFile &file);
void writeCognitiveMap(QXmlStreamWriter *stream, QFile &file);
void writeTrafficData(QXmlStreamWriter *stream, QFile &file);
void writeAgentData(QXmlStreamWriter *stream, QFile &file);
void writeModelGcfmData(QXmlStreamWriter *stream, QFile &file);
void writeModelGompData(QXmlStreamWriter *stream, QFile &file);
void writeModelTordData(QXmlStreamWriter *stream, QFile &file);
void writeModelGradData(QXmlStreamWriter *stream, QFile &file);
void writeModelKrauData(QXmlStreamWriter *stream, QFile &file);
void writeRouteChoiceData(QXmlStreamWriter *stream, QFile &file);
void ReadJuPedSimData(TiXmlElement* JuPedSim);
void ReadHeaderData(TiXmlElement* JuPedSim);
void ReadTrafficData(TiXmlElement* JuPedSim);
void ReadRoutingData(TiXmlElement* JuPedSim);
void ReadAgentData(TiXmlElement* JuPedSim);
void ReadModelData(TiXmlElement* JuPedSim);
void ReadRouteChoiceData(TiXmlElement* JuPedSim);
void readTrafficFile(QFile &file);
};
#endif // INIFILEWIDGET_H
......@@ -53,11 +53,6 @@ roomWidget::roomWidget(QWidget *parent, jpsDatamanager *dmanager, jpsGraphicsVie
show_obstacles();
showLayersInfo();
//temporary uncommented
ui->auto_assign_doors->setVisible(false);
//ui->auto_assign_exits->setVisible(false);
// roomClasses
ui->classBox->addItem("Not specified");
ui->classBox->addItem("Corridor");
......@@ -89,7 +84,9 @@ roomWidget::roomWidget(QWidget *parent, jpsDatamanager *dmanager, jpsGraphicsVie
//connect(ui->highlight,SIGNAL(clicked(bool)),this,SLOT(highlight_room()));
connect(ui->classBox,SIGNAL(activated(int)),this,SLOT(ChangeRoomType()));
connect(ui->classBox,SIGNAL(currentIndexChanged(int)),this,SLOT(ChangeRoomType()));
//tab crossing
connect(ui->pushButton_apply, SIGNAL(clicked(bool)), this, SLOT(applyCrossing()));
connect(ui->addCrossingButton,SIGNAL(clicked(bool)),this,SLOT(new_crossing()));
connect(ui->crossingList,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(enable_roomSelectionCrossings()));
connect(ui->roomBox_from,SIGNAL(activated(int)),this,SLOT(add_rooms_to_crossing()));
......@@ -97,6 +94,7 @@ roomWidget::roomWidget(QWidget *parent, jpsDatamanager *dmanager, jpsGraphicsVie
connect(ui->deleteCrossingButton,SIGNAL(clicked(bool)),this,SLOT(delete_crossing()));
connect(ui->crossingList,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(select_crossing()));
//connect(ui->auto_assign_doors,SIGNAL(clicked(bool)),this,SLOT(autoAssignDoors()));
//tab exit
// connect(ui->addExitButton,SIGNAL(clicked(bool)),this,SLOT(new_exit()));
// connect(ui->exitList,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(enable_roomSelectionExits()));
......@@ -390,7 +388,7 @@ void roomWidget::new_crossing()
void roomWidget::enable_roomSelectionCrossings()
{
qDebug("Enter roomWidget::enable_roomSelectionCrossings");
qDebug("Enter roomWidget::enable_roomSelectionCrossings");
if (datamanager->get_crossingList().size()>0)
{
ui->roomBox_from->setEnabled(true);
......@@ -435,6 +433,16 @@ void roomWidget::enable_roomSelectionCrossings()
{
add_rooms_to_crossing();
}
//show parameters
if(datamanager->get_crossingList()[cCrossingRow]->isState())
ui->stateComboBox->setCurrentIndex(0);
else
ui->stateComboBox->setCurrentIndex(1);
ui->maxAgentsLineEdit->setText(datamanager->get_crossingList()[cCrossingRow]->getMaxAgents());
ui->outflowLineEdit->setText(datamanager->get_crossingList()[cCrossingRow]->getOutflow());