diff options
Diffstat (limited to 'Project')
-rw-r--r-- | Project/ConnectionLine.h | 22 | ||||
-rw-r--r-- | Project/ControlEditor.cpp | 3 | ||||
-rw-r--r-- | Project/FileHanding.cpp | 159 | ||||
-rw-r--r-- | Project/FileHanding.h | 2 | ||||
-rw-r--r-- | Project/Project.mk | 2 |
5 files changed, 169 insertions, 19 deletions
diff --git a/Project/ConnectionLine.h b/Project/ConnectionLine.h index a0df142..30e0d6a 100644 --- a/Project/ConnectionLine.h +++ b/Project/ConnectionLine.h @@ -5,14 +5,11 @@ class ConnectionLine : public ControlElement { -public: - enum ConnectionLineType { - ELEMENT_ELEMENT = 0, - ELEMENT_LINE - }; + public: + enum ConnectionLineType { ELEMENT_ELEMENT = 0, ELEMENT_LINE }; ConnectionLine(Node* firstNode, int id); ~ConnectionLine(); - + virtual void Draw(wxPoint2DDouble translation, double scale) const; virtual bool Contains(wxPoint2DDouble position) const; virtual bool Intersects(wxRect2DDouble rect) const; @@ -23,23 +20,22 @@ public: virtual void UpdatePoints(); virtual void SetTemporarySecondPoint(wxPoint2DDouble point) { m_tmpSndPt = point; } virtual wxPoint2DDouble GetMidPoint() const; - + virtual double GetOffset() const { return m_lineOffset; } virtual ConnectionLineType GetType() const { return m_type; } virtual void SetType(ConnectionLineType newType) { m_type = newType; } - virtual ConnectionLine* GetParentLine() const { return m_parentLine; } virtual bool SetParentLine(ConnectionLine* parent); - + virtual std::vector<ConnectionLine*> GetLineChildList() const; - -protected: + + protected: double m_lineOffset = 0.0; double m_moveStartPtY = 0.0; double m_moveStartOffset = 0.0; wxPoint2DDouble m_tmpSndPt; - + ConnectionLineType m_type = ELEMENT_ELEMENT; ConnectionLine* m_parentLine = NULL; }; -#endif // CONNECTIONLINE_H +#endif // CONNECTIONLINE_H diff --git a/Project/ControlEditor.cpp b/Project/ControlEditor.cpp index e9e95f1..4fedfa3 100644 --- a/Project/ControlEditor.cpp +++ b/Project/ControlEditor.cpp @@ -584,6 +584,7 @@ void ControlEditor::OnScroll(wxMouseEvent& event) Redraw(); } + void ControlEditor::OnIdle(wxIdleEvent& event) { // Solve wxGLString bug. @@ -596,6 +597,7 @@ void ControlEditor::OnIdle(wxIdleEvent& event) m_firstDraw = false; } } + void ControlEditor::OnKeyDown(wxKeyEvent& event) { char key = event.GetUnicodeKey(); @@ -704,6 +706,7 @@ void ControlEditor::CheckConnections() } } } + void ControlEditor::OnExportClick(wxCommandEvent& event) { FileHanding fileHandling(this); 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); diff --git a/Project/FileHanding.h b/Project/FileHanding.h index 1954876..a00d929 100644 --- a/Project/FileHanding.h +++ b/Project/FileHanding.h @@ -52,6 +52,8 @@ protected: int GetAttributeValueInt(rapidxml::xml_node<>* parent, const char* nodeName, const char* atrName); void SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode); + void SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* nodesN, std::vector<Node*> nodeList); + void SaveControlChildren(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* childrenNode, std::vector<Node*> childList); }; #endif // FILEHANDING_H diff --git a/Project/Project.mk b/Project/Project.mk index 977e057..3dc3138 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=NDSE-69 -Date :=08/04/2017 +Date :=10/04/2017 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC |