summaryrefslogtreecommitdiffstats
path: root/Project/MathExpression.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2018-01-08 20:09:35 -0200
committerGitHub <noreply@github.com>2018-01-08 20:09:35 -0200
commit29af4e28898f44df444fef5534134c6b6000418d (patch)
tree13fd8f4449f2cfeed8a6185e96a6889f9529285d /Project/MathExpression.cpp
parent0c0280cfcf540f943fd2dbfdf7ac0304ea96a465 (diff)
parentc11a42ee83fcf535557d4f2cc259efae2da1b7ff (diff)
downloadPSP.git-29af4e28898f44df444fef5534134c6b6000418d.tar.gz
PSP.git-29af4e28898f44df444fef5534134c6b6000418d.tar.xz
PSP.git-29af4e28898f44df444fef5534134c6b6000418d.zip
Merge pull request #44 from Thales1330/org/file-handling-and-ctrl-init
Org file handling and ctrl init
Diffstat (limited to 'Project/MathExpression.cpp')
-rw-r--r--Project/MathExpression.cpp54
1 files changed, 51 insertions, 3 deletions
diff --git a/Project/MathExpression.cpp b/Project/MathExpression.cpp
index f8be598..f22b828 100644
--- a/Project/MathExpression.cpp
+++ b/Project/MathExpression.cpp
@@ -159,9 +159,9 @@ bool MathExpression::Solve(double* input, double timeStep)
return true;
}
// Get the input vector from connection lines (can't use default (one) input argument)
- m_inputValues[0] = input[1]; // Current time
+ m_inputValues[0] = input[1]; // Current time
m_inputValues[1] = timeStep;
- m_inputValues[2] = input[2]; // Switch status
+ m_inputValues[2] = input[2]; // Switch status
int i = 3;
for(auto itN = m_nodeList.begin(), itNEnd = m_nodeList.end(); itN != itNEnd; ++itN) {
Node* node = *itN;
@@ -325,8 +325,56 @@ bool MathExpression::Initialize()
if(m_inputValues) delete m_inputValues;
m_inputValues = new double[m_variablesVector.size() + 3]; // Custom variables + time + step + switch
-
+
// Optimize only once to gain performance.
m_fparser.Optimize();
+
+ m_solved = false;
+ m_output = 0.0;
+ return true;
+}
+
+rapidxml::xml_node<>* MathExpression::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
+{
+ auto elementNode = XMLParser::AppendNode(doc, elementListNode, "MathExpr");
+ XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
+
+ SaveCADProperties(doc, elementNode);
+ SaveControlNodes(doc, elementNode);
+
+ // Element properties
+ 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, elementNode, "MathExprValue");
+ XMLParser::SetNodeValue(doc, mathExprValue, m_mathExpression);
+
+ return elementNode;
+}
+
+bool MathExpression::OpenElement(rapidxml::xml_node<>* elementNode)
+{
+ if(!OpenCADProperties(elementNode)) return false;
+ if(!OpenControlNodes(elementNode)) return false;
+
+ // Element properties
+ std::vector<wxString> variables;
+ auto variablesNode = elementNode->first_node("VariableList");
+ auto variable = variablesNode->first_node("Variable");
+ while(variable) {
+ variables.push_back(variable->value());
+ variable = variable->next_sibling("Variable");
+ }
+ SetVariables(variables);
+
+ auto mathExprValueNode = elementNode->first_node("MathExprValue");
+ m_mathExpression = mathExprValueNode->value();
+
+ // Init opened properties
+ StartMove(m_position);
+ UpdatePoints();
+
return true;
}