Commit e12509a1 authored by Tao Zhong's avatar Tao Zhong

Write goals in inifile

parent 2548ac2b
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);
......@@ -2925,7 +2926,7 @@ void jpsDatamanager::writeSourceHeader(QXmlStreamWriter *stream)
void jpsDatamanager::writeGoalXML(QFile &file)
{
QXmlStreamWriter* stream = new QXmlStreamWriter(&file);
auto *stream = new QXmlStreamWriter(&file);
stream->setAutoFormatting(true);
......@@ -2985,8 +2986,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
}
}
......@@ -3033,7 +3036,12 @@ void jpsDatamanager::writeTransitionXML(QFile &file)
stream = nullptr;
}
const QList<JPSGoal *> &jpsDatamanager::getGoallist()
{
goallist.clear();
goallist = _mView->getGoals();
return goallist;
}
......
......@@ -202,6 +202,8 @@ public:
// read line file
bool ReadLineFile(QFile &file);
const QList<JPSGoal *> &getGoallist();
// //Show Cognitive Map
// void ShowCMapFrame(const int& frame) const;
// const double& GetCMapFrameRate() const;
......
......@@ -1016,7 +1016,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!";
}
......
......@@ -7,12 +7,14 @@
#include "ui_inifilewidget.h"
#include "src/tinyxml/tinyxml.h"
InifileWidget::InifileWidget(QWidget *parent) :
InifileWidget::InifileWidget(QWidget *parent, jpsDatamanager *dmanager) :
QWidget(parent),
ui(new Ui::InifileWidget)
{
ui->setupUi(this);
dataManager = dmanager;
// set InifileWidget as a Window
setWindowFlag(Qt::Dialog);
......@@ -45,6 +47,8 @@ InifileWidget::InifileWidget(QWidget *parent) :
// Set goals invisivle
// ui->tabWidget->removeTab(4);
//signals and slots connection
}
InifileWidget::~InifileWidget()
......@@ -267,7 +271,7 @@ bool InifileWidget::CheckTrafficData()
bool InifileWidget::CheckRoutingData()
{
//TODO: Fix for goal
return true;
}
bool InifileWidget::CheckAgentData()
......@@ -803,35 +807,35 @@ QString InifileWidget::WriteHeaderData()
QString head_line_3 = "\t<!-- header -->\n";
QString head_line_4 = "\t<header>\n";
// QString head_line_4 = "\t<header>\n";
QString head_line_5 = "\t\t<!-- number of cores used -->\n";
QString head_line_5 = "\t<!-- number of cores used -->\n";
QString head_line_6 = "\t\t<num_threads>" +
QString head_line_6 = "\t<num_threads>" +
ui->lineEdit_general_03->text() +
"</num_threads>\n\n";
QString head_line_7 = "\t\t<!-- seed used for initialising random generator -->\n";
QString head_line_7 = "\t<!-- seed used for initialising random generator -->\n";
QString head_line_8 = "\t\t<seed>" +
QString head_line_8 = "\t<seed>" +
ui->lineEdit_general_05->text() +
"</seed>\n\n";
QString head_line_9 = "\t\t<!-- simulationtime -->\n";
QString head_line_9 = "\t<!-- simulationtime -->\n";
QString head_line_10 = "\t\t<max_sim_time>" +
QString head_line_10 = "\t<max_sim_time>" +
ui->lineEdit_general_06->text() +
"</max_sim_time>\n\n";
QString head_line_11 = "\t\t<!-- geometry file -->\n";
QString head_line_11 = "\t<!-- geometry file -->\n";
QString head_line_12 = "\t\t<geometry>" +
QString head_line_12 = "\t<geometry>" +
ui->lineEdit_general_07->text() +
"</geometry>\n\n";
QString head_line_13 = "\t\t<!-- trajectories file and format -->\n";
QString head_line_13 = "\t<!-- trajectories file and format -->\n";
QString head_line_14 = "\t\t<trajectories format=\"" +
QString head_line_14 = "\t<trajectories format=\"" +
ui->comboBox_general_02->currentText() +
"\" fps=\"" +
ui->lineEdit_general_10->text() +
......@@ -839,31 +843,30 @@ QString InifileWidget::WriteHeaderData()
ui->comboBox_general_03->currentText() +
"\">\n";
QString head_line_15 = "\t\t\t<file location=\""
QString head_line_15 = "\t\t<file location=\""
+ ui->lineEdit_general_12->text() +
"\" />\n";
QString head_line_16 = "\t\t</trajectories>\n\n";
QString head_line_16 = "\t</trajectories>\n\n";
QString head_line_17 = "\t\t<!-- savepath logfile -->\n";
QString head_line_17 = "\t<!-- savepath logfile -->\n";
QString head_line_18 = "\t\t<logfile>" +
QString head_line_18 = "\t<logfile>" +
ui->lineEdit_general_08->text() +
"</logfile>\n\n";
QString head_line_19 = "\t\t<!-- statistics -->\n";
QString head_line_19 = "\t<!-- statistics -->\n";
QString head_line_20 = "\t\t<show_statistics>" +
QString head_line_20 = "\t<show_statistics>" +
ui->comboBox_general_01->currentText() +
"</show_statistics>\n";
QString head_line_21 = "\t</header>\n\n";
// QString head_line_21 = "\t</header>\n\n";
QString head_lines = head_line_1 + head_line_2 + head_line_3 + head_line_4 + head_line_5 +
QString head_lines = head_line_1 + head_line_2 + head_line_3 + head_line_5 +
head_line_6 + head_line_7 + head_line_8 + head_line_9 + head_line_10 +
head_line_11 + head_line_12 + head_line_13 + head_line_14 + head_line_15 +
head_line_16 + head_line_17 + head_line_18 + head_line_19 + head_line_20 +
head_line_21;
head_line_16 + head_line_17 + head_line_18 + head_line_19 + head_line_20;
return head_lines;
}
......@@ -915,9 +918,28 @@ QString InifileWidget::WriteTrafficData()
return traf_lines;
}
QString InifileWidget::WriteRoutingData()
void InifileWidget::WriteRoutingData(QFile &file)
{
//TODO: Fix for Goal
auto *stream = new QXmlStreamWriter(&file);
stream->setAutoFormatting(true);
stream->writeComment("routing");
stream->writeStartElement("routing");
stream->writeStartElement("goals");
QList<JPSGoal *> goallist = dataManager->getGoallist();
dataManager->writeGoals(stream, goallist);
auto goal_FileName = "goals.xml";
stream->writeStartElement("file");
stream->writeCharacters(goal_FileName);
stream->writeEndElement(); //end files
stream->writeEndElement(); //end goals
stream->writeEndDocument();
delete stream;
stream = nullptr;
}
QString InifileWidget::WriteAgentData()
......@@ -1785,17 +1807,22 @@ void InifileWidget::on_pushButton_write_clicked()
QString file_name = QFileDialog::getSaveFileName(this,tr("Create ini"),"",tr("XML-Files (*.xml)"));
QFile file(file_name);
if (file.open(QIODevice::WriteOnly|QIODevice::Text))
{
file.write(head_lines.toUtf8() +
traf_lines.toUtf8() +
agen_lines.toUtf8() +
traf_lines.toUtf8());
WriteRoutingData(file);
file.write(agen_lines.toUtf8() +
gcfm_lines.toUtf8() +
gomp_lines.toUtf8() +
tord_lines.toUtf8() +
grad_lines.toUtf8() +
krau_lines.toUtf8() +
choi_lines.toUtf8());
}
file.close();
}
......@@ -3588,5 +3615,4 @@ void InifileWidget::on_pushButton_read_clicked()
//route_choice_models
ReadRouteChoiceData(JuPedSim);
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@
#include <QWidget>
#include "src/tinyxml/tinyxml.h"
#include "src/datamanager.h"
namespace Ui {
class InifileWidget;
......@@ -13,9 +14,10 @@ class InifileWidget : public QWidget
Q_OBJECT
public:
explicit InifileWidget(QWidget *parent = nullptr);
explicit InifileWidget(QWidget *parent = nullptr, jpsDatamanager* dmanager = nullptr);
~InifileWidget();
void writeRouting(QFile &file);
private slots:
......@@ -41,10 +43,11 @@ private slots:
void on_spinBox_constraints_1_valueChanged(int);
void on_spinBox_constraints_2_valueChanged(int);
private:
Ui::InifileWidget *ui;
jpsDatamanager *dataManager;
bool CheckHeaderData();
bool CheckTrafficData();
bool CheckRoutingData();
......@@ -63,7 +66,7 @@ private:
QString WriteHeaderData();
QString WriteTrafficData();
QString WriteRoutingData();
void WriteRoutingData(QFile &file);
QString WriteAgentData();
QString WriteModelGcfmData();
QString WriteModelGompData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment