Commit 5cbc2092 authored by Tao Zhong's avatar Tao Zhong

Save traffic as a external xml

parent b08ffbac
......@@ -375,6 +375,18 @@
</item>
<item>
<widget class="QPushButton" name="auto_assign_doors">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>75</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Assign Door to room&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
......
......@@ -2871,7 +2871,6 @@ void jpsDatamanager::writeSources(QXmlStreamWriter *stream, QList<JPSSource *> &
stream->writeAttribute("y_max",QString::number(source->getY_max()));
stream->writeEndElement();
}
}
}
......@@ -3044,11 +3043,73 @@ const QList<JPSGoal *> &jpsDatamanager::getGoallist()
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");
writeTraffics(stream, doorlist);
doorlist.clear();
stream->writeEndElement(); //end traffic_constrains
stream->writeEndDocument();
delete stream;
stream = nullptr;
}
void jpsDatamanager::writeTraffics(QXmlStreamWriter *stream, QList<jpsCrossing *> const &doorlist)
{
for(jpsCrossing* door:doorlist)
{
stream->writeStartElement("doors");
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");
stream->writeAttribute("outflow", door->getOutflow());
stream->writeAttribute("max_agents", door->getMaxAgents());
stream->writeEndElement(); //end doors and door
}
}
......@@ -114,6 +114,10 @@ public:
void writeGoalXML(QFile &file);
void writeGoals(QXmlStreamWriter *stream, QList<JPSGoal *>& goallist);
//Traffic
void writeTrafficXML(QFile &file);
void writeTraffics(QXmlStreamWriter *stream, QList<jpsCrossing *> const &doorlist);
void remove_all();
void remove_marked_lines();
void set_view(jpsGraphicsView* view);
......
......@@ -630,6 +630,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);
......
......@@ -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");
......@@ -1224,7 +1219,7 @@ void roomWidget::showLayersInfo()
/*
Since v0.8.8
Save crossing data
Save crossing data into datamanager
*/
void roomWidget::applyCrossing()
{
......
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