summaryrefslogtreecommitdiffstats
path: root/Project/FileHanding.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Project/FileHanding.cpp')
-rw-r--r--Project/FileHanding.cpp159
1 files changed, 154 insertions, 5 deletions
diff --git a/Project/FileHanding.cpp b/Project/FileHanding.cpp
index f049c23..11ba8d9 100644
--- a/Project/FileHanding.cpp
+++ b/Project/FileHanding.cpp
@@ -1722,12 +1722,63 @@ void FileHanding::SaveControl(wxFileName path)
writeXML.close();
}
-bool FileHanding::OpenControl(wxFileName path) {}
+bool FileHanding::OpenControl(wxFileName path) { return false; }
void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode)
{
ControlElementContainer ctrlContainer;
ctrlContainer.FillContainer(m_controlEditor);
+ //{ Connection line
+ auto cLinesNode = AppendNode(doc, elementsNode, "ConnectionList");
+ auto connLineList = ctrlContainer.GetConnectionLineList();
+ for(auto it = connLineList.begin(), itEnd = connLineList.end(); it != itEnd; ++it) {
+ ConnectionLine* cLine = *it;
+ auto cLineNode = AppendNode(doc, cLinesNode, "Connection");
+ SetNodeAttribute(doc, cLineNode, "ID", cLine->GetID());
+
+ // CAD properties
+ auto cadProp = AppendNode(doc, cLineNode, "CADProperties");
+ auto position1 = AppendNode(doc, cadProp, "Position1");
+ auto posX1 = AppendNode(doc, position1, "X");
+ SetNodeValue(doc, posX1, cLine->GetPointList()[0].m_x);
+ auto posY1 = AppendNode(doc, position1, "Y");
+ SetNodeValue(doc, posY1, cLine->GetPointList()[0].m_y);
+ auto position2 = AppendNode(doc, cadProp, "Position2");
+ auto posX2 = AppendNode(doc, position2, "X");
+ SetNodeValue(doc, posX2, cLine->GetPointList()[5].m_x);
+ auto posY2 = AppendNode(doc, position2, "Y");
+ SetNodeValue(doc, posY2, cLine->GetPointList()[5].m_y);
+ auto offset = AppendNode(doc, cadProp, "Offset");
+ SetNodeValue(doc, offset, cLine->GetOffset());
+
+ // Child list
+ auto childsNode = AppendNode(doc, cLineNode, "ChildList");
+ auto childList = cLine->GetLineChildList();
+ for(auto itC = childList.begin(), itCEnd = childList.end(); itC != itCEnd; ++itC) {
+ ConnectionLine* childLine = *itC;
+ auto childNode = AppendNode(doc, childsNode, "Child");
+ SetNodeAttribute(doc, childNode, "ID", childLine->GetID());
+ }
+
+ // Parent list
+ auto parentsNode = AppendNode(doc, cLineNode, "ParentList");
+ auto parentList = cLine->GetParentList();
+ for(auto itP = parentList.begin(), itPEnd = parentList.end(); itP != itPEnd; ++itP) {
+ Element* parent = *itP;
+ auto parentNode = AppendNode(doc, parentsNode, "Parent");
+ SetNodeAttribute(doc, parentNode, "ID", parent->GetID());
+ }
+
+ auto parentLine = AppendNode(doc, cLineNode, "ParentLine");
+ if(cLine->GetParentLine()) {
+ ConnectionLine* parent = cLine->GetParentLine();
+ SetNodeAttribute(doc, parentLine, "ID", parent->GetID());
+ } else {
+ SetNodeAttribute(doc, parentLine, "ID", -1);
+ }
+ } //}
+
+ //{ Constant
auto constsNode = AppendNode(doc, elementsNode, "ConstantList");
auto constList = ctrlContainer.GetConstantList();
for(auto it = constList.begin(), itEnd = constList.end(); it != itEnd; ++it) {
@@ -1747,13 +1798,111 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x
SetNodeValue(doc, height, constant->GetHeight());
auto angle = AppendNode(doc, cadProp, "Angle");
SetNodeValue(doc, angle, constant->GetAngle());
+
+ // Nodes
+ auto nodeList = AppendNode(doc, constNode, "NodeList");
+ SaveControlNodes(doc, nodeList, constant->GetNodeList());
+
+ // Control properties
+ auto value = AppendNode(doc, constNode, "Value");
+ SetNodeValue(doc, value, constant->GetValue());
+ } //}
+
+ //{ Exponential
+ auto expsNode = AppendNode(doc, elementsNode, "ExponentialList");
+ auto expList = ctrlContainer.GetExponentialList();
+ for(auto it = expList.begin(), itEnd = expList.end(); it != itEnd; ++it) {
+ Exponential* exponential = *it;
+ auto expNode = AppendNode(doc, expsNode, "Exponential");
+ SetNodeAttribute(doc, expNode, "ID", exponential->GetID());
+ auto cadProp = AppendNode(doc, expNode, "CADProperties");
+ auto position = AppendNode(doc, cadProp, "Position");
+ auto posX = AppendNode(doc, position, "X");
+ SetNodeValue(doc, posX, exponential->GetPosition().m_x);
+ auto posY = AppendNode(doc, position, "Y");
+ SetNodeValue(doc, posY, exponential->GetPosition().m_y);
+ auto size = AppendNode(doc, cadProp, "Size");
+ auto width = AppendNode(doc, size, "Width");
+ SetNodeValue(doc, width, exponential->GetWidth());
+ auto height = AppendNode(doc, size, "Height");
+ SetNodeValue(doc, height, exponential->GetHeight());
+ auto angle = AppendNode(doc, cadProp, "Angle");
+ SetNodeValue(doc, angle, exponential->GetAngle());
+
+ // Nodes
+ auto nodeList = AppendNode(doc, expNode, "NodeList");
+ SaveControlNodes(doc, nodeList, exponential->GetNodeList());
+
+ // Control properties
+ double a, b;
+ exponential->GetValues(a, b);
+ auto value = AppendNode(doc, expNode, "Value");
+ auto aValue = AppendNode(doc, value, "A");
+ SetNodeValue(doc, aValue, a);
+ auto bValue = AppendNode(doc, value, "B");
+ SetNodeValue(doc, bValue, b);
+ } //}
+
+ //{ Gain
+ auto gainsNode = AppendNode(doc, elementsNode, "GainList");
+ auto gainList = ctrlContainer.GetGainList();
+ for(auto it = gainList.begin(), itEnd = gainList.end(); it != itEnd; ++it) {
+ Gain* gain = *it;
+ auto gainNode = AppendNode(doc, gainsNode, "Gain");
+ SetNodeAttribute(doc, gainNode, "ID", gain->GetID());
+ auto cadProp = AppendNode(doc, gainNode, "CADProperties");
+ auto position = AppendNode(doc, cadProp, "Position");
+ auto posX = AppendNode(doc, position, "X");
+ SetNodeValue(doc, posX, gain->GetPosition().m_x);
+ auto posY = AppendNode(doc, position, "Y");
+ SetNodeValue(doc, posY, gain->GetPosition().m_y);
+ auto size = AppendNode(doc, cadProp, "Size");
+ auto width = AppendNode(doc, size, "Width");
+ SetNodeValue(doc, width, gain->GetWidth());
+ auto height = AppendNode(doc, size, "Height");
+ SetNodeValue(doc, height, gain->GetHeight());
+ auto angle = AppendNode(doc, cadProp, "Angle");
+ SetNodeValue(doc, angle, gain->GetAngle());
+
+ // Nodes
+ auto nodeList = AppendNode(doc, gainNode, "NodeList");
+ SaveControlNodes(doc, nodeList, gain->GetNodeList());
+
+ // Control properties
+ auto value = AppendNode(doc, gainNode, "Value");
+ SetNodeValue(doc, value, gain->GetValue());
+ } //}
+}
+
+void FileHanding::SaveControlNodes(rapidxml::xml_document<>& doc,
+ rapidxml::xml_node<>* nodesN,
+ std::vector<Node*> nodeList)
+{
+ for(auto it = nodeList.begin(), itEnd = nodeList.end(); it != itEnd; ++it) {
+ Node* node = *it;
+ auto nodeN = AppendNode(doc, nodesN, "Node");
+ auto nodePosition = AppendNode(doc, nodeN, "Position");
+ auto posNodeX = AppendNode(doc, nodePosition, "X");
+ SetNodeValue(doc, posNodeX, node->GetPosition().m_x);
+ auto posNodeY = AppendNode(doc, nodePosition, "Y");
+ SetNodeValue(doc, posNodeY, node->GetPosition().m_y);
+ auto angle = AppendNode(doc, nodeN, "Angle");
+ SetNodeValue(doc, angle, node->GetAngle());
+ auto isConnected = AppendNode(doc, nodeN, "IsConnected");
+ SetNodeValue(doc, isConnected, node->IsConnected());
+ auto nodeType = AppendNode(doc, nodeN, "Type");
+ SetNodeValue(doc, nodeType, node->GetNodeType());
}
}
-rapidxml::xml_node<>* FileHanding::AppendNode(rapidxml::xml_document<>& doc,
- rapidxml::xml_node<>* parentNode,
- const char* name,
- rapidxml::node_type nodeType)
+void FileHanding::SaveControlChildren(rapidxml::xml_document<>& doc,
+ rapidxml::xml_node<>* childrenNode,
+ std::vector<Node*> childList)
+
+ rapidxml::xml_node<>* FileHanding::AppendNode(rapidxml::xml_document<>& doc,
+ rapidxml::xml_node<>* parentNode,
+ const char* name,
+ rapidxml::node_type nodeType)
{
rapidxml::xml_node<>* node = doc.allocate_node(nodeType, name);
parentNode->append_node(node);