summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Project/Constant.cpp27
-rw-r--r--Project/Constant.h3
-rw-r--r--Project/ControlElement.cpp42
-rw-r--r--Project/ControlElement.h4
-rw-r--r--Project/Divider.cpp22
-rw-r--r--Project/Divider.h4
-rw-r--r--Project/Element.cpp2
-rw-r--r--Project/Exponential.cpp32
-rw-r--r--Project/Exponential.h7
-rw-r--r--Project/FileHanding.cpp577
-rw-r--r--Project/Gain.cpp26
-rw-r--r--Project/Gain.h5
-rw-r--r--Project/IOControl.cpp27
-rw-r--r--Project/IOControl.h4
-rw-r--r--Project/Limiter.cpp31
-rw-r--r--Project/Limiter.h4
-rw-r--r--Project/MathExpression.cpp12
-rw-r--r--Project/Multiplier.cpp25
-rw-r--r--Project/Multiplier.h4
-rw-r--r--Project/Project.mk2
-rw-r--r--Project/RateLimiter.cpp29
-rw-r--r--Project/RateLimiter.h3
-rw-r--r--Project/Sum.cpp16
-rw-r--r--Project/TransferFunction.cpp43
-rw-r--r--Project/XMLParser.cpp17
-rw-r--r--Project/XMLParser.h17
26 files changed, 383 insertions, 602 deletions
diff --git a/Project/Constant.cpp b/Project/Constant.cpp
index f99eab6..ce50719 100644
--- a/Project/Constant.cpp
+++ b/Project/Constant.cpp
@@ -32,6 +32,7 @@ Constant::~Constant()
{
if(m_glText) delete m_glText;
}
+
void Constant::Draw(wxPoint2DDouble translation, double scale) const
{
glLineWidth(1.0);
@@ -127,3 +128,29 @@ bool Constant::UpdateText()
if(!m_glText->IsTextureOK()) return false;
return true;
}
+
+void Constant::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Constant");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto value = XMLParser::AppendNode(doc, elementNode, "Value");
+ XMLParser::SetNodeValue(doc, value, m_value);
+}
+
+bool Constant::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ double value = XMLParser::GetNodeValueDouble(elementNode, "Value");
+
+ SetPosition(m_position);
+ SetValue(value);
+ return true;
+}
diff --git a/Project/Constant.h b/Project/Constant.h
index b9e9f93..d61e1f0 100644
--- a/Project/Constant.h
+++ b/Project/Constant.h
@@ -48,6 +48,9 @@ class Constant : public ControlElement
virtual double GetValue() const { return m_value; }
virtual void UpdatePoints();
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/ControlElement.cpp b/Project/ControlElement.cpp
index f13836d..f67cef1 100644
--- a/Project/ControlElement.cpp
+++ b/Project/ControlElement.cpp
@@ -141,29 +141,6 @@ void ControlElement::ReplaceNode(Node* oldNode, Node* newNode)
}
}
-void ControlElement::SaveControlNodes(rapidxml::xml_document<>& doc,
- rapidxml::xml_node<>* nodesN,
- std::vector<Node*> nodeList)
-{
- int id = 0;
- for(auto it = nodeList.begin(), itEnd = nodeList.end(); it != itEnd; ++it) {
- Node* node = *it;
- node->SetID(id);
- auto nodeN = XMLParser::AppendNode(doc, nodesN, "Node");
- XMLParser::SetNodeAttribute(doc, nodeN, "ID", id);
- auto nodePosition = XMLParser::AppendNode(doc, nodeN, "Position");
- auto posNodeX = XMLParser::AppendNode(doc, nodePosition, "X");
- XMLParser::SetNodeValue(doc, posNodeX, node->GetPosition().m_x);
- auto posNodeY = XMLParser::AppendNode(doc, nodePosition, "Y");
- XMLParser::SetNodeValue(doc, posNodeY, node->GetPosition().m_y);
- auto angle = XMLParser::AppendNode(doc, nodeN, "Angle");
- XMLParser::SetNodeValue(doc, angle, node->GetAngle());
- auto nodeType = XMLParser::AppendNode(doc, nodeN, "Type");
- XMLParser::SetNodeValue(doc, nodeType, node->GetNodeType());
- id++;
- }
-}
-
ControlElement* ControlElement::GetControlElementFromID(std::vector<ControlElement*> elementList, int id)
{
for(auto it = elementList.begin(), itEnd = elementList.end(); it != itEnd; ++it) {
@@ -173,25 +150,6 @@ ControlElement* ControlElement::GetControlElementFromID(std::vector<ControlEleme
return NULL;
}
-bool ControlElement::OpenControlNodeList(rapidxml::xml_node<>* elementNode, std::vector<Node*>& nodeVector)
-{
- auto nodeList = elementNode->first_node("NodeList");
- if(!nodeList) return false;
- auto nodeN = nodeList->first_node("Node");
- while(nodeN) {
- auto nodePosition = nodeN->first_node("Position");
- double nodePosX = XMLParser::GetNodeValueDouble(nodePosition, "X");
- double nodePosY = XMLParser::GetNodeValueDouble(nodePosition, "Y");
- double nodeAngle = XMLParser::GetNodeValueDouble(nodeN, "Angle");
- Node::NodeType nodeType = static_cast<Node::NodeType>(XMLParser::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");
- }
- return true;
-}
-
void ControlElement::SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementNode)
{
auto nodeList = XMLParser::AppendNode(doc, elementNode, "NodeList");
diff --git a/Project/ControlElement.h b/Project/ControlElement.h
index 84e23b6..6d1593f 100644
--- a/Project/ControlElement.h
+++ b/Project/ControlElement.h
@@ -109,10 +109,6 @@ class ControlElement : public Element
virtual void SetOutput(double output) { m_output = output; }
static ControlElement* GetControlElementFromID(std::vector<ControlElement*> elementList, int id);
-
- // File handling methods
- void SaveControlNodes(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* nodesN, std::vector<Node*> nodeList);
- bool OpenControlNodeList(rapidxml::xml_node<>* elementNode, std::vector<Node*>& nodeVector);
protected:
std::vector<Node*> m_nodeList;
diff --git a/Project/Divider.cpp b/Project/Divider.cpp
index 3f7027d..a19d9c5 100644
--- a/Project/Divider.cpp
+++ b/Project/Divider.cpp
@@ -15,8 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "Divider.h"
#include "ConnectionLine.h"
+#include "Divider.h"
Divider::Divider(int id) : MathOperation(id) {}
Divider::~Divider() {}
@@ -75,3 +75,23 @@ Element* Divider::GetCopy()
*copy = *this;
return copy;
}
+
+void Divider::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Divider");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+}
+
+bool Divider::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ StartMove(m_position);
+ UpdatePoints();
+
+ return true;
+}
diff --git a/Project/Divider.h b/Project/Divider.h
index d31828d..52154f4 100644
--- a/Project/Divider.h
+++ b/Project/Divider.h
@@ -37,6 +37,10 @@ class Divider : public MathOperation
virtual void DrawSymbol() const;
virtual bool Solve(double* input, double timeStep);
+
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
};
diff --git a/Project/Element.cpp b/Project/Element.cpp
index f2458e8..46aaa7d 100644
--- a/Project/Element.cpp
+++ b/Project/Element.cpp
@@ -437,10 +437,10 @@ bool Element::OpenCADProperties(rapidxml::xml_node<>* elementNode)
auto position = cadPropNode->first_node("Position");
double posX = XMLParser::GetNodeValueDouble(position, "X");
double posY = XMLParser::GetNodeValueDouble(position, "Y");
- m_position = wxPoint2DDouble(posX, posY);
auto size = cadPropNode->first_node("Size");
m_width = XMLParser::GetNodeValueDouble(size, "Width");
m_height = XMLParser::GetNodeValueDouble(size, "Height");
m_angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
+ SetPosition(wxPoint2DDouble(posX, posY));
return true;
}
diff --git a/Project/Exponential.cpp b/Project/Exponential.cpp
index a021854..4a04bbe 100644
--- a/Project/Exponential.cpp
+++ b/Project/Exponential.cpp
@@ -131,7 +131,7 @@ void Exponential::SetValues(double aValue, double bValue)
bool Exponential::Solve(double* input, double timeStep)
{
- if(!input){
+ if(!input) {
m_output = 0.0;
return true;
}
@@ -145,3 +145,33 @@ Element* Exponential::GetCopy()
*copy = *this;
return copy;
}
+
+void Exponential::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Exponential");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ auto value = XMLParser::AppendNode(doc, elementNode, "Value");
+ auto aValue = XMLParser::AppendNode(doc, value, "A");
+ XMLParser::SetNodeValue(doc, aValue, m_aValue);
+ auto bValue = XMLParser::AppendNode(doc, value, "B");
+ XMLParser::SetNodeValue(doc, bValue, m_bValue);
+}
+
+bool Exponential::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ auto value = elementNode->first_node("Value");
+ m_aValue = XMLParser::GetNodeValueDouble(value, "A");
+ m_bValue = XMLParser::GetNodeValueDouble(value, "B");
+
+ StartMove(m_position);
+ UpdatePoints();
+ return true;
+}
diff --git a/Project/Exponential.h b/Project/Exponential.h
index f9a65ec..8151b40 100644
--- a/Project/Exponential.h
+++ b/Project/Exponential.h
@@ -45,10 +45,10 @@ class Exponential : public ControlElement
virtual void GetValues(double& aValue, double& bValue);
virtual void SetValues(double aValue, double bValue);
-
+
/**
* @brief Calculates the exponential.
- *
+ *
* <center>\f$ output = A\cdot e^{B\cdot input} \f$</center>
* @param input Input value.
* @param timeStep Time step.
@@ -56,6 +56,9 @@ class Exponential : public ControlElement
*/
virtual bool Solve(double* input, double timeStep);
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/FileHanding.cpp b/Project/FileHanding.cpp
index 6bfbdf0..512fae2 100644
--- a/Project/FileHanding.cpp
+++ b/Project/FileHanding.cpp
@@ -1291,38 +1291,36 @@ bool FileHanding::OpenProject(wxFileName path)
parentNode = parentNode->next_sibling("ParentID");
}
- // Set parents (if have)
- Bus *parent1, *parent2;
- if(parentID[0] == -1) {
- parent1 = new Bus(ptsList[0]);
- line->AddParent(parent1, ptsList[0]);
- } else {
- parent1 = busList[parentID[0]];
- line->AddParent(parent1, ptsList[0]);
- }
- if(parentID[1] == -1) {
- parent2 = new Bus(ptsList[ptsList.size() - 1]);
- line->AddParent(parent2, ptsList[ptsList.size() - 1]);
- } else {
- parent2 = busList[parentID[1]];
- line->AddParent(parent2, ptsList[ptsList.size() - 1]);
+ std::vector<wxPoint2DDouble> nodePtsList; // List of node points
+ nodePtsList.push_back(ptsList[0]); // First point on the list
+ nodePtsList.push_back(ptsList[ptsList.size() - 1]); // Last point on the list
+
+ // List of dummy buses to set not connected nodes properly
+ std::vector<Bus*> dummyBusList;
+ for(unsigned int i = 0; i < nodePtsList.size(); ++i) {
+ if(parentID[i] == -1) // No parent connected
+ {
+ Bus* dummyBus = new Bus(nodePtsList[i]);
+ dummyBusList.push_back(dummyBus);
+ line->AddParent(dummyBus, nodePtsList[i]);
+ } else { // Parent connected (necessarily a bus, get from bus list)
+ line->AddParent(busList[parentID[i]], nodePtsList[i]);
+ }
}
- // Add the others nodes (if have)
+ // Add the others nodes (if exists)
std::vector<wxPoint2DDouble> midPts;
- for(int i = 1; i < (int)ptsList.size() - 1; i++) midPts.push_back(ptsList[i]);
+ for(unsigned int i = 1; i < ptsList.size() - 1; i++) midPts.push_back(ptsList[i]);
std::vector<wxPoint2DDouble> edgesPts = line->GetPointList();
edgesPts.insert(edgesPts.begin() + 2, midPts.begin(), midPts.end());
line->SetPointList(edgesPts);
- if(parentID[0] == -1) {
- line->RemoveParent(parent1);
- delete parent1;
- }
- if(parentID[1] == -1) {
- line->RemoveParent(parent2);
- delete parent2;
+ // Remove dummy buses
+ for(auto it = dummyBusList.begin(), itEnd = dummyBusList.end(); it != itEnd; ++it) {
+ line->RemoveParent(*it);
+ delete *it;
}
+ dummyBusList.clear();
auto electricalProp = lineNode->first_node("ElectricalProperties");
if(!electricalProp) return false;
@@ -1992,279 +1990,58 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc,
auto constsNode = XMLParser::AppendNode(doc, elementsNode, "ConstantList");
auto constList = ctrlContainer->GetConstantList();
for(auto it = constList.begin(), itEnd = constList.end(); it != itEnd; ++it) {
- Constant* constant = *it;
- auto constNode = XMLParser::AppendNode(doc, constsNode, "Constant");
- XMLParser::SetNodeAttribute(doc, constNode, "ID", constant->GetID());
- auto cadProp = XMLParser::AppendNode(doc, constNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, constant->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, constant->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, constant->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, constant->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, constant->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, constNode, "NodeList");
- constant->SaveControlNodes(doc, nodeList, constant->GetNodeList());
-
- // Control properties
- auto value = XMLParser::AppendNode(doc, constNode, "Value");
- XMLParser::SetNodeValue(doc, value, constant->GetValue());
+ (*it)->SaveElement(doc, constsNode);
} //}
//{ Exponential
auto expsNode = XMLParser::AppendNode(doc, elementsNode, "ExponentialList");
auto expList = ctrlContainer->GetExponentialList();
- for(auto it = expList.begin(), itEnd = expList.end(); it != itEnd; ++it) {
- Exponential* exponential = *it;
- auto expNode = XMLParser::AppendNode(doc, expsNode, "Exponential");
- XMLParser::SetNodeAttribute(doc, expNode, "ID", exponential->GetID());
- auto cadProp = XMLParser::AppendNode(doc, expNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, exponential->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, exponential->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, exponential->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, exponential->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, exponential->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, expNode, "NodeList");
- exponential->SaveControlNodes(doc, nodeList, exponential->GetNodeList());
-
- // Control properties
- double a, b;
- exponential->GetValues(a, b);
- auto value = XMLParser::AppendNode(doc, expNode, "Value");
- auto aValue = XMLParser::AppendNode(doc, value, "A");
- XMLParser::SetNodeValue(doc, aValue, a);
- auto bValue = XMLParser::AppendNode(doc, value, "B");
- XMLParser::SetNodeValue(doc, bValue, b);
- } //}
+ for(auto it = expList.begin(), itEnd = expList.end(); it != itEnd; ++it) { (*it)->SaveElement(doc, expsNode); } //}
//{ Gain
auto gainsNode = XMLParser::AppendNode(doc, elementsNode, "GainList");
auto gainList = ctrlContainer->GetGainList();
for(auto it = gainList.begin(), itEnd = gainList.end(); it != itEnd; ++it) {
- Gain* gain = *it;
- auto gainNode = XMLParser::AppendNode(doc, gainsNode, "Gain");
- XMLParser::SetNodeAttribute(doc, gainNode, "ID", gain->GetID());
- auto cadProp = XMLParser::AppendNode(doc, gainNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, gain->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, gain->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, gain->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, gain->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, gain->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, gainNode, "NodeList");
- gain->SaveControlNodes(doc, nodeList, gain->GetNodeList());
-
- // Control properties
- auto value = XMLParser::AppendNode(doc, gainNode, "Value");
- XMLParser::SetNodeValue(doc, value, gain->GetValue());
+ (*it)->SaveElement(doc, gainsNode);
} //}
//{ IO
auto iosNode = XMLParser::AppendNode(doc, elementsNode, "IOList");
auto ioList = ctrlContainer->GetIOControlList();
- for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) {
- IOControl* io = *it;
- auto ioNode = XMLParser::AppendNode(doc, iosNode, "IO");
- XMLParser::SetNodeAttribute(doc, ioNode, "ID", io->GetID());
- auto cadProp = XMLParser::AppendNode(doc, ioNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, io->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, io->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, io->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, io->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, io->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, ioNode, "NodeList");
- io->SaveControlNodes(doc, nodeList, io->GetNodeList());
-
- // Control properties
- auto value = XMLParser::AppendNode(doc, ioNode, "Value");
- XMLParser::SetNodeValue(doc, value, io->GetValue());
- auto ioFlags = XMLParser::AppendNode(doc, ioNode, "IOFlags");
- XMLParser::SetNodeValue(doc, ioFlags, io->GetIOFlags());
- } //}
+ for(auto it = ioList.begin(), itEnd = ioList.end(); it != itEnd; ++it) { (*it)->SaveElement(doc, iosNode); } //}
//{ Limiter
auto limitersNode = XMLParser::AppendNode(doc, elementsNode, "LimiterList");
auto limiterList = ctrlContainer->GetLimiterList();
for(auto it = limiterList.begin(), itEnd = limiterList.end(); it != itEnd; ++it) {
- Limiter* limiter = *it;
- auto limiterNode = XMLParser::AppendNode(doc, limitersNode, "Limiter");
- XMLParser::SetNodeAttribute(doc, limiterNode, "ID", limiter->GetID());
- auto cadProp = XMLParser::AppendNode(doc, limiterNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, limiter->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, limiter->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, limiter->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, limiter->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, limiter->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, limiterNode, "NodeList");
- limiter->SaveControlNodes(doc, nodeList, limiter->GetNodeList());
-
- // Control properties
- auto upLimit = XMLParser::AppendNode(doc, limiterNode, "UpperLimit");
- XMLParser::SetNodeValue(doc, upLimit, limiter->GetUpLimit());
- auto lowLimit = XMLParser::AppendNode(doc, limiterNode, "LowerLimit");
- XMLParser::SetNodeValue(doc, lowLimit, limiter->GetLowLimit());
+ (*it)->SaveElement(doc, limitersNode);
} //}
//{ Multiplier
auto multipliersNode = XMLParser::AppendNode(doc, elementsNode, "MultiplierList");
auto multiplierList = ctrlContainer->GetMultiplierList();
for(auto it = multiplierList.begin(), itEnd = multiplierList.end(); it != itEnd; ++it) {
- Multiplier* multiplier = *it;
- auto multiplierNode = XMLParser::AppendNode(doc, multipliersNode, "Multiplier");
- XMLParser::SetNodeAttribute(doc, multiplierNode, "ID", multiplier->GetID());
- auto cadProp = XMLParser::AppendNode(doc, multiplierNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, multiplier->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, multiplier->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, multiplier->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, multiplier->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, multiplier->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, multiplierNode, "NodeList");
- multiplier->SaveControlNodes(doc, nodeList, multiplier->GetNodeList());
+ (*it)->SaveElement(doc, multipliersNode);
} //}
//{ Divider
auto dividersNode = XMLParser::AppendNode(doc, elementsNode, "DividerList");
auto dividersList = ctrlContainer->GetDividerList();
for(auto it = dividersList.begin(), itEnd = dividersList.end(); it != itEnd; ++it) {
- Divider* divider = *it;
- auto dividerNode = XMLParser::AppendNode(doc, dividersNode, "Divider");
- XMLParser::SetNodeAttribute(doc, dividerNode, "ID", divider->GetID());
- auto cadProp = XMLParser::AppendNode(doc, dividerNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, divider->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, divider->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, divider->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, divider->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, divider->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, dividerNode, "NodeList");
- divider->SaveControlNodes(doc, nodeList, divider->GetNodeList());
+ (*it)->SaveElement(doc, dividersNode);
} //}
//{ Rate limiter
auto rateLimitersNode = XMLParser::AppendNode(doc, elementsNode, "RateLimiterList");
auto rateLimiterList = ctrlContainer->GetRateLimiterList();
for(auto it = rateLimiterList.begin(), itEnd = rateLimiterList.end(); it != itEnd; ++it) {
- RateLimiter* rateLimiter = *it;
- auto rateLimiterNode = XMLParser::AppendNode(doc, rateLimitersNode, "RateLimiter");
- XMLParser::SetNodeAttribute(doc, rateLimiterNode, "ID", rateLimiter->GetID());
- auto cadProp = XMLParser::AppendNode(doc, rateLimiterNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, rateLimiter->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, rateLimiter->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, rateLimiter->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, rateLimiter->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, rateLimiter->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, rateLimiterNode, "NodeList");
- rateLimiter->SaveControlNodes(doc, nodeList, rateLimiter->GetNodeList());
-
- // Control properties
- auto upLimit = XMLParser::AppendNode(doc, rateLimiterNode, "UpperLimit");
- XMLParser::SetNodeValue(doc, upLimit, rateLimiter->GetUpLimit());
- auto lowLimit = XMLParser::AppendNode(doc, rateLimiterNode, "LowerLimit");
- XMLParser::SetNodeValue(doc, lowLimit, rateLimiter->GetLowLimit());
+ (*it)->SaveElement(doc, rateLimitersNode);
} //}
//{ Sum
auto sumsNode = XMLParser::AppendNode(doc, elementsNode, "SumList");
auto sumList = ctrlContainer->GetSumList();
- for(auto it = sumList.begin(), itEnd = sumList.end(); it != itEnd; ++it) {
- Sum* sum = *it;
- auto sumNode = XMLParser::AppendNode(doc, sumsNode, "Sum");
- XMLParser::SetNodeAttribute(doc, sumNode, "ID", sum->GetID());
- auto cadProp = XMLParser::AppendNode(doc, sumNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, sum->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, sum->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, sum->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, sum->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, sum->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, sumNode, "NodeList");
- sum->SaveControlNodes(doc, nodeList, sum->GetNodeList());
-
- // Control properties
- auto signsNode = XMLParser::AppendNode(doc, sumNode, "Signs");
- auto signs = sum->GetSignalList();
- for(int i = 0; i < (int)signs.size(); ++i) {
- auto value = XMLParser::AppendNode(doc, signsNode, "Value");
- XMLParser::SetNodeValue(doc, value, static_cast<int>(signs[i]));
- }
-
- } //}
+ for(auto it = sumList.begin(), itEnd = sumList.end(); it != itEnd; ++it) { (*it)->SaveElement(doc, sumsNode); } //}
//{ Math expression
auto mathExprsNode = XMLParser::AppendNode(doc, elementsNode, "MathExprList");
@@ -2276,42 +2053,7 @@ void FileHanding::SaveControlElements(rapidxml::xml_document<>& doc,
//{ Transfer function
auto tfsNode = XMLParser::AppendNode(doc, elementsNode, "TransferFunctionList");
auto tfList = ctrlContainer->GetTFList();
- for(auto it = tfList.begin(), itEnd = tfList.end(); it != itEnd; ++it) {
- TransferFunction* tf = *it;
- auto tfNode = XMLParser::AppendNode(doc, tfsNode, "TransferFunction");
- XMLParser::SetNodeAttribute(doc, tfNode, "ID", tf->GetID());
- auto cadProp = XMLParser::AppendNode(doc, tfNode, "CADProperties");
- auto position = XMLParser::AppendNode(doc, cadProp, "Position");
- auto posX = XMLParser::AppendNode(doc, position, "X");
- XMLParser::SetNodeValue(doc, posX, tf->GetPosition().m_x);
- auto posY = XMLParser::AppendNode(doc, position, "Y");
- XMLParser::SetNodeValue(doc, posY, tf->GetPosition().m_y);
- auto size = XMLParser::AppendNode(doc, cadProp, "Size");
- auto width = XMLParser::AppendNode(doc, size, "Width");
- XMLParser::SetNodeValue(doc, width, tf->GetWidth());
- auto height = XMLParser::AppendNode(doc, size, "Height");
- XMLParser::SetNodeValue(doc, height, tf->GetHeight());
- auto angle = XMLParser::AppendNode(doc, cadProp, "Angle");
- XMLParser::SetNodeValue(doc, angle, tf->GetAngle());
-
- // Nodes
- auto nodeList = XMLParser::AppendNode(doc, tfNode, "NodeList");
- tf->SaveControlNodes(doc, nodeList, tf->GetNodeList());
-
- // Control properties
- auto numeratorNode = XMLParser::AppendNode(doc, tfNode, "Numerator");
- auto numerator = tf->GetNumerator();
- for(int i = 0; i < (int)numerator.size(); ++i) {
- auto value = XMLParser::AppendNode(doc, numeratorNode, "Value");
- XMLParser::SetNodeValue(doc, value, numerator[i]);
- }
- auto denominatorNode = XMLParser::AppendNode(doc, tfNode, "Denominator");
- auto denominator = tf->GetDenominator();
- for(int i = 0; i < (int)denominator.size(); ++i) {
- auto value = XMLParser::AppendNode(doc, denominatorNode, "Value");
- XMLParser::SetNodeValue(doc, value, denominator[i]);
- }
- } //}
+ for(auto it = tfList.begin(), itEnd = tfList.end(); it != itEnd; ++it) { (*it)->SaveElement(doc, tfsNode); } //}
//{ Connection line
auto cLinesNode = XMLParser::AppendNode(doc, elementsNode, "ConnectionList");
@@ -2365,32 +2107,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(constNode, "ID");
Constant* constant = new Constant(id);
- auto cadPropNode = constNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- double value = XMLParser::GetNodeValueDouble(constNode, "Value");
-
- constant->SetWidth(width);
- constant->SetHeight(height);
- constant->SetAngle(angle);
- constant->SetPosition(wxPoint2DDouble(posX, posY));
- constant->StartMove(constant->GetPosition());
-
- constant->SetValue(value);
-
- std::vector<Node*> nodeVector;
- if(!constant->OpenControlNodeList(constNode, nodeVector)) return false;
-
- constant->SetNodeList(nodeVector);
- constant->UpdatePoints();
+ if(!constant->OpenElement(constNode)) return false;
elementList.push_back(constant);
constNode = constNode->next_sibling("Constant");
@@ -2406,34 +2123,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::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 = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- auto value = expNode->first_node("Value");
- double a = XMLParser::GetNodeValueDouble(value, "A");
- double b = XMLParser::GetNodeValueDouble(value, "B");
-
- exponential->SetWidth(width);
- exponential->SetHeight(height);
- exponential->SetAngle(angle);
- exponential->SetPosition(wxPoint2DDouble(posX, posY));
- exponential->StartMove(exponential->GetPosition());
-
- exponential->SetValues(a, b);
-
- std::vector<Node*> nodeVector;
- if(!exponential->OpenControlNodeList(expNode, nodeVector)) return false;
-
- exponential->SetNodeList(nodeVector);
- exponential->UpdatePoints();
+ if(!exponential->OpenElement(expNode)) return false;
elementList.push_back(exponential);
expNode = expNode->next_sibling("Exponential");
@@ -2449,31 +2139,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(gainNode, "ID");
Gain* gain = new Gain(id);
- auto cadPropNode = gainNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- double value = XMLParser::GetNodeValueDouble(gainNode, "Value");
-
- gain->SetWidth(width);
- gain->SetHeight(height);
- gain->SetAngle(angle);
- gain->SetPosition(wxPoint2DDouble(posX, posY));
- gain->SetValue(value);
- gain->StartMove(gain->GetPosition());
-
- std::vector<Node*> nodeVector;
- if(!gain->OpenControlNodeList(gainNode, nodeVector)) return false;
-
- gain->SetNodeList(nodeVector);
- gain->UpdatePoints();
+ if(!gain->OpenElement(gainNode)) return false;
elementList.push_back(gain);
gainNode = gainNode->next_sibling("Gain");
@@ -2487,34 +2153,11 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
auto ioNode = ioListNode->first_node("IO");
while(ioNode) {
int id = XMLParser::GetAttributeValueInt(ioNode, "ID");
-
- auto cadPropNode = ioNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- IOControl::IOFlags value = static_cast<IOControl::IOFlags>(XMLParser::GetNodeValueInt(ioNode, "Value"));
int ioFlags = XMLParser::GetNodeValueInt(ioNode, "IOFlags");
IOControl* io = new IOControl(ioFlags, id);
- std::vector<Node*> nodeVector;
- if(!io->OpenControlNodeList(ioNode, nodeVector)) return false;
-
- io->SetWidth(width);
- io->SetHeight(height);
- io->SetAngle(angle);
- io->SetPosition(wxPoint2DDouble(posX, posY));
- io->SetValue(value);
- io->StartMove(io->GetPosition());
- io->SetNodeList(nodeVector);
- io->UpdatePoints();
+ if(!io->OpenElement(ioNode)) return false;
elementList.push_back(io);
ioNode = ioNode->next_sibling("IO");
@@ -2530,33 +2173,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(limiterNode, "ID");
Limiter* limiter = new Limiter(id);
- auto cadPropNode = limiterNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- double upLimit = XMLParser::GetNodeValueDouble(limiterNode, "UpperLimit");
- double lowLimit = XMLParser::GetNodeValueDouble(limiterNode, "LowerLimit");
-
- std::vector<Node*> nodeVector;
- if(!limiter->OpenControlNodeList(limiterNode, nodeVector)) return false;
-
- limiter->SetWidth(width);
- limiter->SetHeight(height);
- limiter->SetAngle(angle);
- limiter->SetPosition(wxPoint2DDouble(posX, posY));
- limiter->SetUpLimit(upLimit);
- limiter->SetLowLimit(lowLimit);
-
- limiter->StartMove(limiter->GetPosition());
- limiter->SetNodeList(nodeVector);
- limiter->UpdatePoints();
+ if(!limiter->OpenElement(limiterNode)) return false;
elementList.push_back(limiter);
limiterNode = limiterNode->next_sibling("Limiter");
@@ -2572,28 +2189,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(multiplierNode, "ID");
Multiplier* multiplier = new Multiplier(id);
- auto cadPropNode = multiplierNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- std::vector<Node*> nodeVector;
- if(!multiplier->OpenControlNodeList(multiplierNode, nodeVector)) return false;
-
- multiplier->SetWidth(width);
- multiplier->SetHeight(height);
- multiplier->SetAngle(angle);
- multiplier->SetPosition(wxPoint2DDouble(posX, posY));
-
- multiplier->StartMove(multiplier->GetPosition());
- multiplier->SetNodeList(nodeVector);
- multiplier->UpdatePoints();
+ if(!multiplier->OpenElement(multiplierNode)) return false;
elementList.push_back(multiplier);
multiplierNode = multiplierNode->next_sibling("Multiplier");
@@ -2609,28 +2205,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(dividerNode, "ID");
Divider* divider = new Divider(id);
- auto cadPropNode = dividerNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- std::vector<Node*> nodeVector;
- if(!divider->OpenControlNodeList(dividerNode, nodeVector)) return false;
-
- divider->SetWidth(width);
- divider->SetHeight(height);
- divider->SetAngle(angle);
- divider->SetPosition(wxPoint2DDouble(posX, posY));
-
- divider->StartMove(divider->GetPosition());
- divider->SetNodeList(nodeVector);
- divider->UpdatePoints();
+ if(!divider->OpenElement(dividerNode)) return false;
elementList.push_back(divider);
dividerNode = dividerNode->next_sibling("Divider");
@@ -2646,33 +2221,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(rateLimiterNode, "ID");
RateLimiter* limiter = new RateLimiter(id);
- auto cadPropNode = rateLimiterNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- double upLimit = XMLParser::GetNodeValueDouble(rateLimiterNode, "UpperLimit");
- double lowLimit = XMLParser::GetNodeValueDouble(rateLimiterNode, "LowerLimit");
-
- std::vector<Node*> nodeVector;
- if(!limiter->OpenControlNodeList(rateLimiterNode, nodeVector)) return false;
-
- limiter->SetWidth(width);
- limiter->SetHeight(height);
- limiter->SetAngle(angle);
- limiter->SetPosition(wxPoint2DDouble(posX, posY));
- limiter->SetUpLimit(upLimit);
- limiter->SetLowLimit(lowLimit);
-
- limiter->StartMove(limiter->GetPosition());
- limiter->SetNodeList(nodeVector);
- limiter->UpdatePoints();
+ if(!limiter->OpenElement(rateLimiterNode)) return false;
elementList.push_back(limiter);
rateLimiterNode = rateLimiterNode->next_sibling("RateLimiter");
@@ -2720,51 +2269,7 @@ bool FileHanding::OpenControlElements(rapidxml::xml_document<>& doc,
int id = XMLParser::GetAttributeValueInt(tfNode, "ID");
TransferFunction* tf = new TransferFunction(id);
- auto cadPropNode = tfNode->first_node("CADProperties");
- if(!cadPropNode) return false;
-
- auto position = cadPropNode->first_node("Position");
- double posX = XMLParser::GetNodeValueDouble(position, "X");
- double posY = XMLParser::GetNodeValueDouble(position, "Y");
- auto size = cadPropNode->first_node("Size");
- double width = XMLParser::GetNodeValueDouble(size, "Width");
- double height = XMLParser::GetNodeValueDouble(size, "Height");
- double angle = XMLParser::GetNodeValueDouble(cadPropNode, "Angle");
-
- std::vector<double> numerator, denominator;
- auto numeratorNode = tfNode->first_node("Numerator");
- auto nValue = numeratorNode->first_node("Value");
- while(nValue) {
- double value = 0.0;
- wxString(nValue->value()).ToCDouble(&value);
- numerator.push_back(value);
- nValue = nValue->next_sibling("Value");
- }
- auto denominatorNode = tfNode->first_node("Denominator");
- auto dValue = denominatorNode->first_node("Value");
- while(dValue) {
- double value = 0.0;
- wxString(dValue->value()).ToCDouble(&value);
- denominator.push_back(value);
- dValue = dValue->next_sibling("Value");
- }
-
- std::vector<Node*> nodeVector;
- if(!tf->OpenControlNodeList(tfNode, nodeVector)) return false;
-
- tf->SetWidth(width);
- tf->SetHeight(height);
- tf->SetAngle(angle);
- tf->SetPosition(wxPoint2DDouble(posX, posY));
-
- tf->SetNumerator(numerator);
- tf->SetDenominator(denominator);
-
- tf->StartMove(tf->GetPosition());
- tf->SetNodeList(nodeVector);
-
- tf->UpdateTFText();
-
+ if(!tf->OpenElement(tfNode)) return false;
elementList.push_back(tf);
tfNode = tfNode->next_sibling("TransferFunction");
diff --git a/Project/Gain.cpp b/Project/Gain.cpp
index 95107d8..fd82fba 100644
--- a/Project/Gain.cpp
+++ b/Project/Gain.cpp
@@ -177,7 +177,7 @@ void Gain::Move(wxPoint2DDouble position)
bool Gain::Solve(double* input, double timeStep)
{
- if(!input){
+ if(!input) {
m_output = 0.0;
return true;
}
@@ -199,3 +199,27 @@ bool Gain::UpdateText()
if(!m_glText->IsTextureOK()) return false;
return true;
}
+
+void Gain::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Gain");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto value = XMLParser::AppendNode(doc, elementNode, "Value");
+ XMLParser::SetNodeValue(doc, value, m_value);
+}
+
+bool Gain::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ double value = XMLParser::GetNodeValueDouble(elementNode, "Value");
+ SetValue(value);
+ return true;
+} \ No newline at end of file
diff --git a/Project/Gain.h b/Project/Gain.h
index 4d436f9..c5ed6bd 100644
--- a/Project/Gain.h
+++ b/Project/Gain.h
@@ -50,7 +50,7 @@ class Gain : public ControlElement
virtual void UpdatePoints();
/**
* @brief Multiply the input by a constant
- *
+ *
* <center>\f$ output = K \cdot input \f$</center>
* @param input Input value.
* @param timeStep Time step.
@@ -58,6 +58,9 @@ class Gain : public ControlElement
*/
virtual bool Solve(double* input, double timeStep);
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/IOControl.cpp b/Project/IOControl.cpp
index 193986e..f40232a 100644
--- a/Project/IOControl.cpp
+++ b/Project/IOControl.cpp
@@ -270,3 +270,30 @@ bool IOControl::UpdateText()
if(!m_glText->IsTextureOK()) return false;
return true;
}
+
+void IOControl::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "IO");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto value = XMLParser::AppendNode(doc, elementNode, "Value");
+ XMLParser::SetNodeValue(doc, value, m_value);
+ auto ioFlags = XMLParser::AppendNode(doc, elementNode, "IOFlags");
+ XMLParser::SetNodeValue(doc, ioFlags, m_ioFlags);
+}
+
+bool IOControl::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ IOControl::IOFlags value = static_cast<IOControl::IOFlags>(XMLParser::GetNodeValueInt(elementNode, "Value"));
+ SetValue(value);
+
+ return true;
+}
diff --git a/Project/IOControl.h b/Project/IOControl.h
index a445efb..c580c52 100644
--- a/Project/IOControl.h
+++ b/Project/IOControl.h
@@ -65,6 +65,10 @@ class IOControl : public ControlElement
virtual void SetValue(IOFlags value);
virtual int GetIOFlags() const { return m_ioFlags; }
virtual Node::NodeType GetType() { return m_ioNodeType; }
+
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/Limiter.cpp b/Project/Limiter.cpp
index 2a1d076..7769cb2 100644
--- a/Project/Limiter.cpp
+++ b/Project/Limiter.cpp
@@ -107,7 +107,7 @@ void Limiter::UpdatePoints()
bool Limiter::Solve(double* input, double timeStep)
{
- if(!input){
+ if(!input) {
m_output = 0.0;
return true;
}
@@ -126,3 +126,32 @@ Element* Limiter::GetCopy()
*copy = *this;
return copy;
}
+
+void Limiter::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Limiter");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto upLimit = XMLParser::AppendNode(doc, elementNode, "UpperLimit");
+ XMLParser::SetNodeValue(doc, upLimit, m_upLimit);
+ auto lowLimit = XMLParser::AppendNode(doc, elementNode, "LowerLimit");
+ XMLParser::SetNodeValue(doc, lowLimit, m_lowLimit);
+}
+
+bool Limiter::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ m_upLimit = XMLParser::GetNodeValueDouble(elementNode, "UpperLimit");
+ m_lowLimit = XMLParser::GetNodeValueDouble(elementNode, "LowerLimit");
+
+ StartMove(m_position);
+ UpdatePoints();
+ return true;
+}
diff --git a/Project/Limiter.h b/Project/Limiter.h
index c351eac..e51c14e 100644
--- a/Project/Limiter.h
+++ b/Project/Limiter.h
@@ -48,6 +48,10 @@ class Limiter : public ControlElement
double GetLowLimit() const { return m_lowLimit; }
void SetUpLimit(double upLimit) { m_upLimit = upLimit; }
void SetLowLimit(double lowLimit) { m_lowLimit = lowLimit; }
+
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/MathExpression.cpp b/Project/MathExpression.cpp
index 6ab6c14..ee55732 100644
--- a/Project/MathExpression.cpp
+++ b/Project/MathExpression.cpp
@@ -333,19 +333,19 @@ bool MathExpression::Initialize()
void MathExpression::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
{
- auto mathExprNode = XMLParser::AppendNode(doc, elementListNode, "MathExpr");
- XMLParser::SetNodeAttribute(doc, mathExprNode, "ID", m_elementID);
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "MathExpr");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
- SaveCADProperties(doc, mathExprNode);
- SaveControlNodes(doc, mathExprNode);
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
// Element properties
- auto variablesNode = XMLParser::AppendNode(doc, mathExprNode, "VariableList");
+ auto variablesNode = XMLParser::AppendNode(doc, elementNode, "VariableList");
for(unsigned int i = 0; i < m_variablesVector.size(); ++i) {
auto variable = XMLParser::AppendNode(doc, variablesNode, "Variable");
XMLParser::SetNodeValue(doc, variable, m_variablesVector[i]);
}
- auto mathExprValue = XMLParser::AppendNode(doc, mathExprNode, "MathExprValue");
+ auto mathExprValue = XMLParser::AppendNode(doc, elementNode, "MathExprValue");
XMLParser::SetNodeValue(doc, mathExprValue, m_mathExpression);
}
diff --git a/Project/Multiplier.cpp b/Project/Multiplier.cpp
index b25a406..a32d494 100644
--- a/Project/Multiplier.cpp
+++ b/Project/Multiplier.cpp
@@ -15,8 +15,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include "Multiplier.h"
#include "ConnectionLine.h"
+#include "Multiplier.h"
Multiplier::Multiplier(int id) : MathOperation(id) {}
Multiplier::~Multiplier() {}
@@ -58,9 +58,7 @@ bool Multiplier::Solve(double* input, double timeStep)
}
m_output = 1.0;
- for(unsigned int i = 0; i < inputVector.size(); ++i) {
- m_output *= inputVector[i];
- }
+ for(unsigned int i = 0; i < inputVector.size(); ++i) { m_output *= inputVector[i]; }
return true;
}
@@ -71,3 +69,22 @@ Element* Multiplier::GetCopy()
*copy = *this;
return copy;
}
+
+void Multiplier::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Multiplier");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+}
+
+bool Multiplier::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ StartMove(m_position);
+ UpdatePoints();
+ return true;
+}
diff --git a/Project/Multiplier.h b/Project/Multiplier.h
index 83eb37b..d9df358 100644
--- a/Project/Multiplier.h
+++ b/Project/Multiplier.h
@@ -37,6 +37,10 @@ class Multiplier : public MathOperation
virtual void DrawSymbol() const;
virtual bool Solve(double* input, double timeStep);
+
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
};
diff --git a/Project/Project.mk b/Project/Project.mk
index 9e0545c..7d7b579 100644
--- a/Project/Project.mk
+++ b/Project/Project.mk
@@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=NDSE-69
-Date :=03/01/2018
+Date :=04/01/2018
CodeLitePath :="C:/Program Files/CodeLite"
LinkerName :=C:/TDM-GCC-64/bin/g++.exe
SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC
diff --git a/Project/RateLimiter.cpp b/Project/RateLimiter.cpp
index c8da81d..94e44f5 100644
--- a/Project/RateLimiter.cpp
+++ b/Project/RateLimiter.cpp
@@ -140,3 +140,32 @@ Element* RateLimiter::GetCopy()
*copy = *this;
return copy;
}
+
+void RateLimiter::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "RateLimiter");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto upLimit = XMLParser::AppendNode(doc, elementNode, "UpperLimit");
+ XMLParser::SetNodeValue(doc, upLimit, m_upLimit);
+ auto lowLimit = XMLParser::AppendNode(doc, elementNode, "LowerLimit");
+ XMLParser::SetNodeValue(doc, lowLimit, m_lowLimit);
+}
+
+bool RateLimiter::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ m_upLimit = XMLParser::GetNodeValueDouble(elementNode, "UpperLimit");
+ m_lowLimit = XMLParser::GetNodeValueDouble(elementNode, "LowerLimit");
+
+ StartMove(m_position);
+ UpdatePoints();
+ return true;
+}
diff --git a/Project/RateLimiter.h b/Project/RateLimiter.h
index 91e0b9f..c832aac 100644
--- a/Project/RateLimiter.h
+++ b/Project/RateLimiter.h
@@ -65,6 +65,9 @@ class RateLimiter : public ControlElement
*/
virtual bool Solve(double* input, double timeStep);
+ virtual void SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode);
+ virtual bool OpenElement(rapidxml::xml_node<>* elementNode);
+
virtual Element* GetCopy();
protected:
diff --git a/Project/Sum.cpp b/Project/Sum.cpp
index 10d515f..789380a 100644
--- a/Project/Sum.cpp
+++ b/Project/Sum.cpp
@@ -246,7 +246,21 @@ Element* Sum::GetCopy()
return copy;
}
-void Sum::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode) {}
+void Sum::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Sum");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto signsNode = XMLParser::AppendNode(doc, elementNode, "Signs");
+ for(unsigned int i = 0; i < m_signalList.size(); ++i) {
+ auto value = XMLParser::AppendNode(doc, signsNode, "Value");
+ XMLParser::SetNodeValue(doc, value, static_cast<int>(m_signalList[i]));
+ }
+}
bool Sum::OpenElement(rapidxml::xml_node<>* elementNode)
{
diff --git a/Project/TransferFunction.cpp b/Project/TransferFunction.cpp
index 8ebaddc..d630ea3 100644
--- a/Project/TransferFunction.cpp
+++ b/Project/TransferFunction.cpp
@@ -389,9 +389,52 @@ bool TransferFunction::UpdateText()
void TransferFunction::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "TransferFunction");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ auto numeratorNode = XMLParser::AppendNode(doc, elementNode, "Numerator");
+ for(unsigned int i = 0; i < m_numerator.size(); ++i) {
+ auto value = XMLParser::AppendNode(doc, numeratorNode, "Value");
+ XMLParser::SetNodeValue(doc, value, m_numerator[i]);
+ }
+ auto denominatorNode = XMLParser::AppendNode(doc, elementNode, "Denominator");
+ for(unsigned int i = 0; i < m_denominator.size(); ++i) {
+ auto value = XMLParser::AppendNode(doc, denominatorNode, "Value");
+ XMLParser::SetNodeValue(doc, value, m_denominator[i]);
+ }
}
bool TransferFunction::OpenElement(rapidxml::xml_node<>* elementNode)
{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ std::vector<double> numerator, denominator;
+ m_numerator.clear();
+ m_denominator.clear();
+ auto numeratorNode = elementNode->first_node("Numerator");
+ auto nValue = numeratorNode->first_node("Value");
+ while(nValue) {
+ double value = 0.0;
+ wxString(nValue->value()).ToCDouble(&value);
+ m_numerator.push_back(value);
+ nValue = nValue->next_sibling("Value");
+ }
+ auto denominatorNode = elementNode->first_node("Denominator");
+ auto dValue = denominatorNode->first_node("Value");
+ while(dValue) {
+ double value = 0.0;
+ wxString(dValue->value()).ToCDouble(&value);
+ m_denominator.push_back(value);
+ dValue = dValue->next_sibling("Value");
+ }
+ StartMove(m_position);
+ UpdateTFText();
+
return true;
}
diff --git a/Project/XMLParser.cpp b/Project/XMLParser.cpp
index 09fa2cc..0d1588e 100644
--- a/Project/XMLParser.cpp
+++ b/Project/XMLParser.cpp
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2018 Thales Lima Oliveira <thales@ufu.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#include "XMLParser.h"
XMLParser::XMLParser() {}
diff --git a/Project/XMLParser.h b/Project/XMLParser.h
index 1486394..ee8f5a0 100644
--- a/Project/XMLParser.h
+++ b/Project/XMLParser.h
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2018 Thales Lima Oliveira <thales@ufu.br>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef XMLPARSER_H
#define XMLPARSER_H