This repository was archived by the owner on May 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphprovider.cpp
167 lines (135 loc) · 5.52 KB
/
graphprovider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <QDomDocument>
#include <QFile>
#include "graphprovider.h"
#include "pertgraph.h"
#include "step.h"
#include "scriptstep.h"
GraphProvider::GraphProvider(){}
bool GraphProvider::readGraph(PertGraph *pert, Script *script, const QString &fileName)
{
if (fileName.isEmpty()) return false;
QFile file(fileName);
QString errorStr;
int errorLine;
int errorColumn;
// Load file XML vao QDomDocument
QDomDocument doc;
if (!doc.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
return false;
// Duyet qua du lieu XML de tao ra _node va _edge
QDomElement root = doc.documentElement();
if (root.tagName() != "graph")
return false;
ScriptStep *step = new ScriptStep();
QDomElement element = root.firstChildElement();
while (!element.isNull()){
if (element.tagName() == "node"){
QString id = element.attribute("id","0");
QString x = element.attribute("x","0");
QString y = element.attribute("y","0");
Node *nodetemp = new Node(x.toFloat(), y.toFloat(), id);
pert->setNode(nodetemp);
step->setInfoNode(nodetemp->state(), nodetemp->earlyDate(), nodetemp->lateDate());
} else if (element.tagName() == "edge"){
QString id = element.attribute("id","");
QString weight = element.attribute("weight","0");
QString start = element.attribute("start","0");
QString end = element.attribute("end","0");
Node *startNode = pert->node(start.toInt());
Node *endNode = pert->node(end.toInt());
Task *tasktemp;
if (id == "")
tasktemp = new Task(Task::TaskFictive, startNode, endNode, id, weight.toInt());
else
tasktemp = new Task(Task::TaskNormal, startNode, endNode, id, weight.toInt());
pert->setTask(tasktemp);
step->setInfoTask(tasktemp->state());
}
element = element.nextSiblingElement();
}
step->setOutputText("");
script->setStep(step);
return true;
}
bool GraphProvider::readResultStep(PertGraph *pert, const QString &fileName)
{
if (fileName.isEmpty()) return false;
QFile file(fileName);
QString errorStr;
int errorLine;
int errorColumn;
// Load file XML vao QDomDocument
QDomDocument doc;
if (!doc.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
return false;
// Duyet qua du lieu XML de tao ra _node va _edge
QDomElement root = doc.documentElement();
if (root.tagName() != "ResultPert")
return false;
QDomNodeList node = root.elementsByTagName("Step");
// Lay day cac Aller
int len = pert->lengthTaskList();
for (int i = 0; i < len; i++)
{
QString isChanged = node.at(i).toElement().attribute("isChanged","0");
QString earlyDate = node.at(i).toElement().attribute("earlyDate","0");
QString lateDate = node.at(i).toElement().attribute("lateDate","0");
QString id = node.at(i).toElement().attribute("id","0");
QString idName = node.at(i).toElement().attribute("idName","0");
Step *step = new Step(Step::Mark, Step::Aller, earlyDate, lateDate, id, idName);
pert->setStep(step);
if (isChanged == "1")
step = new Step(Step::Change, Step::Aller, earlyDate, lateDate, id, idName);
else if (isChanged == "0")
step = new Step(Step::NoChange, Step::Aller, earlyDate, lateDate, id, idName);
pert->setStep(step);
}
// Lay day cac Retour
for (int i = (len + 1); i < (2 * len + 1); i++)
{
QString isChanged = node.at(i).toElement().attribute("isChanged","0");
QString earlyDate = node.at(i).toElement().attribute("earlyDate","0");
QString lateDate = node.at(i).toElement().attribute("lateDate","0");
QString id = node.at(i).toElement().attribute("id","0");
QString idName = node.at(i).toElement().attribute("idName","0");
Step *step = new Step(Step::Mark, Step::Retour, earlyDate, lateDate, id, idName);
pert->setStep(step);
if (isChanged == "1")
step = new Step(Step::Change, Step::Retour, earlyDate, lateDate, id, idName);
else if (isChanged == "0")
step = new Step(Step::NoChange, Step::Retour, earlyDate, lateDate, id, idName);
pert->setStep(step);
}
Step *step = new Step(Step::Fin, Step::Retour, "0", "0", "0", "0");
pert->setStep(step);
return true;
}
bool GraphProvider::readResult(PertGraph *pert, const QString &fileName)
{
if (fileName.isEmpty()) return false;
QFile file(fileName);
QString errorStr;
int errorLine;
int errorColumn;
// Load file XML vao QDomDocument
QDomDocument doc;
if (!doc.setContent(&file, true, &errorStr, &errorLine, &errorColumn))
return false;
// Duyet qua du lieu XML de tao ra _node va _edge
QDomElement root = doc.documentElement();
if (root.tagName() != "ResultPert")
return false;
QDomNodeList node = root.elementsByTagName("Node");
// Lay day cac Aller
for (uint i = 0; i < node.length(); i++)
{
QString id = node.at(i).toElement().attribute("id","0");
QString slack = node.at(i).toElement().attribute("slack","0");
QString critique = node.at(i).toElement().attribute("isCritique","0");
bool isCritique = false;
if (critique == "1") isCritique = true;
pert->task(id.toInt())->setSlack(slack);
pert->task(id.toInt())->setCritique(isCritique);
}
return true;
}