summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Project/ControlElementContainer.cpp7
-rw-r--r--Project/ControlElementContainer.h8
-rw-r--r--Project/FileHanding.cpp227
-rw-r--r--Project/FileHanding.h4
-rw-r--r--Project/Project.mk2
5 files changed, 145 insertions, 103 deletions
diff --git a/Project/ControlElementContainer.cpp b/Project/ControlElementContainer.cpp
index 0e0e9d4..f5372a8 100644
--- a/Project/ControlElementContainer.cpp
+++ b/Project/ControlElementContainer.cpp
@@ -7,6 +7,7 @@ ControlElementContainer::~ControlElementContainer() {}
void ControlElementContainer::FillContainer(ControlEditor* editor)
{
ClearContainer();
+ m_ctrlElementsList = editor->GetControlElementList();
m_cLineList = editor->GetConnectionLineList();
auto cElementList = editor->GetControlElementList();
for(auto it = cElementList.begin(), itEnd = cElementList.end(); it != itEnd; ++it) {
@@ -45,3 +46,9 @@ void ControlElementContainer::ClearContainer()
m_sumList.clear();
m_tfList.clear();
}
+
+void ControlElementContainer::FillContainer(std::vector<ControlElement*> controlElementList, std::vector<ConnectionLine*> connectionLineList)
+{
+ m_ctrlElementsList = controlElementList;
+ m_cLineList = connectionLineList;
+}
diff --git a/Project/ControlElementContainer.h b/Project/ControlElementContainer.h
index 5ff218f..119ba82 100644
--- a/Project/ControlElementContainer.h
+++ b/Project/ControlElementContainer.h
@@ -24,8 +24,10 @@ class ControlElementContainer
~ControlElementContainer();
virtual void FillContainer(ControlEditor* editor);
+ virtual void FillContainer(std::vector<ControlElement*> controlElementList, std::vector<ConnectionLine*> connectionLineList);
virtual void ClearContainer();
-
+
+ std::vector<ControlElement*> GetControlElementsList() const { return m_ctrlElementsList; }
std::vector<ConnectionLine*> GetConnectionLineList() const { return m_cLineList; }
std::vector<Constant*> GetConstantList() const { return m_constantList; }
std::vector<Exponential*> GetExponentialList() const { return m_exponentialList; }
@@ -37,8 +39,10 @@ class ControlElementContainer
std::vector<Sum*> GetSumList() const { return m_sumList; }
std::vector<TransferFunction*> GetTFList() const { return m_tfList; }
protected:
- std::vector<ConnectionLine*> m_cLineList;
+ std::vector<ControlElement*> m_ctrlElementsList;
std::vector<Constant*> m_constantList;
+
+ std::vector<ConnectionLine*> m_cLineList;
std::vector<Exponential*> m_exponentialList;
std::vector<Gain*> m_gainList;
std::vector<IOControl*> m_ioControlList;
diff --git a/Project/FileHanding.cpp b/Project/FileHanding.cpp
index 15a0dcf..7698fb6 100644
--- a/Project/FileHanding.cpp
+++ b/Project/FileHanding.cpp
@@ -1722,7 +1722,9 @@ void FileHanding::SaveControl(wxFileName path)
writeXML.close();
}
-bool FileHanding::OpenControl(wxFileName path, std::vector<ControlElement*>& ctrlElementList, std::vector<ConnectionLine*>& ctrlConnectionList)
+bool FileHanding::OpenControl(wxFileName path,
+ std::vector<ControlElement*>& ctrlElementList,
+ std::vector<ConnectionLine*>& ctrlConnectionList)
{
rapidxml::xml_document<> doc;
rapidxml::file<> xmlFile(path.GetFullPath());
@@ -1739,107 +1741,26 @@ bool FileHanding::OpenControl(wxFileName path, std::vector<ControlElement*>& ctr
auto elementsNode = projectNode->first_node("ControlElements");
if(!elementsNode) return false;
- std::vector<ControlElement*> elementList;
- std::vector<ConnectionLine*> connectionList;
-
- auto expListNode = elementsNode->first_node("ExponentialList");
- if(!expListNode) return false;
- auto expNode = expListNode->first_node("Exponential");
- while(expNode) {
- int id = GetAttributeValueInt(expNode, "ID");
- Exponential* exponential = new Exponential(id);
-
- auto cadPropNode = expNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = GetNodeValueDouble(position, "X");
- double posY = GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = GetNodeValueDouble(size, "Width");
- double height = GetNodeValueDouble(size, "Height");
- double angle = GetNodeValueDouble(cadPropNode, "Angle");
-
- exponential->SetWidth(width);
- exponential->SetHeight(height);
- exponential->SetAngle(angle);
- exponential->SetPosition(wxPoint2DDouble(posX, posY));
- exponential->StartMove(exponential->GetPosition());
-
- auto nodeList = expNode->first_node("NodeList");
- if(!nodeList) return false;
- auto nodeN = nodeList->first_node("Node");
- std::vector<Node*> nodeVector;
- while(nodeN) {
- auto nodePosition = nodeN->first_node("Position");
- double nodePosX = GetNodeValueDouble(nodePosition, "X");
- double nodePosY = GetNodeValueDouble(nodePosition, "Y");
- double nodeAngle = GetNodeValueDouble(nodeN, "Angle");
- Node::NodeType nodeType = (Node::NodeType)GetNodeValueInt(nodeN, "Type");
- Node* node = new Node(wxPoint2DDouble(nodePosX, nodePosY), nodeType, 2.0);
- node->SetAngle(nodeAngle);
- nodeVector.push_back(node);
- nodeN = nodeN->next_sibling("Node");
- }
- exponential->SetNodeList(nodeVector);
- exponential->UpdatePoints();
- elementList.push_back(exponential);
-
- expNode = expNode->next_sibling("Exponential");
- }
-
- //Connection line
- auto connectionListNode = elementsNode->first_node("ConnectionList");
- if(!connectionListNode) return false;
- auto connNode = connectionListNode->first_node("Connection");
- while(connNode) {
- ConnectionLine* cLine = NULL;
- int id = GetAttributeValueInt(connNode, "ID");
-
- auto cadPropNode = connNode->first_node("CADProperties");
- if(!cadPropNode) return false;
- double offset = GetNodeValueDouble(cadPropNode, "Offset");
-
- auto parentList = connNode->first_node("ParentList");
- if(!parentList) return false;
- auto parentNode = parentList->first_node("Parent");
- bool firstNode = true;
- while(parentNode) {
- int elementID = GetNodeValueInt(parentNode, "ElementID");
- int nodeID = GetNodeValueInt(parentNode, "NodeID");
-
- ControlElement* element = GetControlElementFromID(elementList, elementID);
- Node* node = element->GetNodeList()[nodeID];
-
- if(firstNode)
- cLine = new ConnectionLine(node, id);
- cLine->AddParent(element);
- element->AddChild(cLine);
- if(!firstNode)
- cLine->AppendNode(node, element);
-
- if(firstNode) firstNode = false;
- parentNode = parentNode->next_sibling("Parent");
- }
- cLine->SetOffset(offset);
- cLine->UpdatePoints();
- connectionList.push_back(cLine);
- connNode = connectionListNode->next_sibling("Connection");
- }
-
- ctrlElementList = elementList;
- ctrlConnectionList = connectionList;
+ // auto elementsNode = AppendNode(doc, rootNode, "ControlElements");
+ ControlElementContainer* ctrlElementContainer = new ControlElementContainer();
+ if(!OpenControlElements(doc, elementsNode, ctrlElementContainer)) return false;
+ ctrlElementList = ctrlElementContainer->GetControlElementsList();
+ ctrlConnectionList = ctrlElementContainer->GetConnectionLineList();
return true;
}
-void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode)
+void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc,
+ rapidxml::xml_node<>* elementsNode,
+ ControlElementContainer* ctrlContainer)
{
- ControlElementContainer ctrlContainer;
- ctrlContainer.FillContainer(m_controlEditor);
+ if(!ctrlContainer) {
+ ctrlContainer = new ControlElementContainer();
+ ctrlContainer->FillContainer(m_controlEditor);
+ }
//{ Constant
auto constsNode = AppendNode(doc, elementsNode, "ConstantList");
- auto constList = ctrlContainer.GetConstantList();
+ auto constList = ctrlContainer->GetConstantList();
for(auto it = constList.begin(), itEnd = constList.end(); it != itEnd; ++it) {
Constant* constant = *it;
auto constNode = AppendNode(doc, constsNode, "Constant");
@@ -1869,7 +1790,7 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x
//{ Exponential
auto expsNode = AppendNode(doc, elementsNode, "ExponentialList");
- auto expList = ctrlContainer.GetExponentialList();
+ auto expList = ctrlContainer->GetExponentialList();
for(auto it = expList.begin(), itEnd = expList.end(); it != itEnd; ++it) {
Exponential* exponential = *it;
auto expNode = AppendNode(doc, expsNode, "Exponential");
@@ -1904,7 +1825,7 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x
//{ Gain
auto gainsNode = AppendNode(doc, elementsNode, "GainList");
- auto gainList = ctrlContainer.GetGainList();
+ auto gainList = ctrlContainer->GetGainList();
for(auto it = gainList.begin(), itEnd = gainList.end(); it != itEnd; ++it) {
Gain* gain = *it;
auto gainNode = AppendNode(doc, gainsNode, "Gain");
@@ -1934,7 +1855,7 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x
//{ Connection line
auto cLinesNode = AppendNode(doc, elementsNode, "ConnectionList");
- auto connLineList = ctrlContainer.GetConnectionLineList();
+ auto connLineList = ctrlContainer->GetConnectionLineList();
for(auto it = connLineList.begin(), itEnd = connLineList.end(); it != itEnd; ++it) {
ConnectionLine* cLine = *it;
auto cLineNode = AppendNode(doc, cLinesNode, "Connection");
@@ -1969,6 +1890,114 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::x
} //}
}
+bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
+ rapidxml::xml_node<>* elementsNode,
+ ControlElementContainer* ctrlContainer)
+{
+ std::vector<ControlElement*> elementList;
+ std::vector<ConnectionLine*> connectionList;
+
+ auto expListNode = elementsNode->first_node("ExponentialList");
+ if(!expListNode) return false;
+ auto expNode = expListNode->first_node("Exponential");
+ while(expNode) {
+ int id = GetAttributeValueInt(expNode, "ID");
+ Exponential* exponential = new Exponential(id);
+
+ auto cadPropNode = expNode->first_node("CADProperties");
+ if(!cadPropNode) return false;
+
+ auto position = cadPropNode->first_node("Position");
+ double posX = GetNodeValueDouble(position, "X");
+ double posY = GetNodeValueDouble(position, "Y");
+ auto size = cadPropNode->first_node("Size");
+ double width = GetNodeValueDouble(size, "Width");
+ double height = GetNodeValueDouble(size, "Height");
+ double angle = GetNodeValueDouble(cadPropNode, "Angle");
+
+ exponential->SetWidth(width);
+ exponential->SetHeight(height);
+ exponential->SetAngle(angle);
+ exponential->SetPosition(wxPoint2DDouble(posX, posY));
+ exponential->StartMove(exponential->GetPosition());
+
+ auto nodeList = expNode->first_node("NodeList");
+ if(!nodeList) return false;
+ auto nodeN = nodeList->first_node("Node");
+ std::vector<Node*> nodeVector;
+ while(nodeN) {
+ auto nodePosition = nodeN->first_node("Position");
+ double nodePosX = GetNodeValueDouble(nodePosition, "X");
+ double nodePosY = GetNodeValueDouble(nodePosition, "Y");
+ double nodeAngle = GetNodeValueDouble(nodeN, "Angle");
+ Node::NodeType nodeType = (Node::NodeType)GetNodeValueInt(nodeN, "Type");
+ Node* node = new Node(wxPoint2DDouble(nodePosX, nodePosY), nodeType, 2.0);
+ node->SetAngle(nodeAngle);
+ nodeVector.push_back(node);
+ nodeN = nodeN->next_sibling("Node");
+ }
+ exponential->SetNodeList(nodeVector);
+ exponential->UpdatePoints();
+ elementList.push_back(exponential);
+
+ expNode = expNode->next_sibling("Exponential");
+ }
+
+ // Connection line
+ auto connectionListNode = elementsNode->first_node("ConnectionList");
+ if(!connectionListNode) return false;
+ auto connNode = connectionListNode->first_node("Connection");
+ while(connNode) {
+ ConnectionLine* cLine = NULL;
+ int id = GetAttributeValueInt(connNode, "ID");
+
+ auto cadPropNode = connNode->first_node("CADProperties");
+ if(!cadPropNode) return false;
+ double offset = GetNodeValueDouble(cadPropNode, "Offset");
+
+ auto parentList = connNode->first_node("ParentList");
+ if(!parentList) return false;
+
+ auto parentNode = parentList->first_node("Parent");
+ bool firstNode = true;
+ while(parentNode) {
+ int elementID = GetNodeValueInt(parentNode, "ElementID");
+ int nodeID = GetNodeValueInt(parentNode, "NodeID");
+
+ ControlElement* element = GetControlElementFromID(elementList, elementID);
+ Node* node = element->GetNodeList()[nodeID];
+
+ if(firstNode) cLine = new ConnectionLine(node, id);
+ cLine->AddParent(element);
+ element->AddChild(cLine);
+ if(!firstNode) cLine->AppendNode(node, element);
+
+ if(firstNode) firstNode = false;
+ parentNode = parentNode->next_sibling("Parent");
+ }
+
+ auto parentLine = connNode->first_node("ParentLine");
+ if(!parentLine) return false;
+ int parentLineID = GetAttributeValueInt(parentLine, "ID");
+ if(parentLineID != -1) {
+ for(auto it = connectionList.begin(), itEnd = connectionList.end(); it != itEnd; ++it) {
+ ConnectionLine* parent = *it;
+ if(parent->GetID() == parentLineID) {
+ cLine->SetParentLine(parent);
+ parent->AddChild(cLine);
+ }
+ }
+ }
+
+ cLine->SetOffset(offset);
+ cLine->UpdatePoints();
+ connectionList.push_back(cLine);
+ connNode = connNode->next_sibling("Connection");
+ }
+ ctrlContainer->FillContainer(elementList, connectionList);
+ return true;
+}
+
void FileHanding::SaveControlNodes(rapidxml::xml_document<>& doc,
rapidxml::xml_node<>* nodesN,
std::vector<Node*> nodeList)
@@ -2091,4 +2120,4 @@ int FileHanding::GetAttributeValueInt(rapidxml::xml_node<>* node, const char* at
if(!atr) return false;
wxString(atr->value()).ToCLong(&intValue);
return (int)intValue;
-} \ No newline at end of file
+}
diff --git a/Project/FileHanding.h b/Project/FileHanding.h
index 28efa83..e072cbf 100644
--- a/Project/FileHanding.h
+++ b/Project/FileHanding.h
@@ -32,6 +32,9 @@ public:
void SaveControl(wxFileName path);
bool OpenControl(wxFileName path, std::vector<ControlElement*>& ctrlElementList, std::vector<ConnectionLine*>& ctrlConnectionList);
+
+ void SaveControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode, ControlElementContainer* ctrlContainer = NULL);
+ bool OpenControlElements(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementsNode, ControlElementContainer* ctrlContainer = NULL);
protected:
Workspace* m_workspace = NULL;
@@ -52,7 +55,6 @@ protected:
int GetAttributeValueInt(rapidxml::xml_node<>* parent, const char* nodeName, const char* atrName);
int GetAttributeValueInt(rapidxml::xml_node<>* node, 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);
ControlElement* GetControlElementFromID(std::vector<ControlElement*> elementList, int id);
};
diff --git a/Project/Project.mk b/Project/Project.mk
index b26a453..b2aab3f 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=NDSE-69
-Date :=17/04/2017
+Date :=18/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