summaryrefslogtreecommitdiffstats
path: root/Project/Sum.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-05-08 21:43:17 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-05-08 21:43:17 -0300
commit9fb33a91aa22fbce6d0b74529e07af9f7781b916 (patch)
tree2cd9f042977cf598949e7b29745886abfe1bf342 /Project/Sum.cpp
parent74d795cb074b6ae9aa93bcfacee8995d7e6d5945 (diff)
downloadPSP.git-9fb33a91aa22fbce6d0b74529e07af9f7781b916.tar.gz
PSP.git-9fb33a91aa22fbce6d0b74529e07af9f7781b916.tar.xz
PSP.git-9fb33a91aa22fbce6d0b74529e07af9f7781b916.zip
Secondary branch, TF and limiter solution
much work, such results
Diffstat (limited to 'Project/Sum.cpp')
-rw-r--r--Project/Sum.cpp43
1 files changed, 39 insertions, 4 deletions
diff --git a/Project/Sum.cpp b/Project/Sum.cpp
index 606b367..bd35966 100644
--- a/Project/Sum.cpp
+++ b/Project/Sum.cpp
@@ -1,8 +1,8 @@
#include "Sum.h"
#include "SumForm.h"
+#include "ConnectionLine.h"
-Sum::Sum(int id)
- : ControlElement(id)
+Sum::Sum(int id) : ControlElement(id)
{
m_width = m_height = 36.0;
Node* nodeIn1 = new Node(m_position + wxPoint2DDouble(-m_width / 2, 9 - m_height / 2), Node::NODE_IN, m_borderSize);
@@ -23,7 +23,6 @@ Sum::Sum(int id)
}
Sum::~Sum() {}
-
void Sum::Draw(wxPoint2DDouble translation, double scale) const
{
glLineWidth(1.0);
@@ -133,7 +132,7 @@ void Sum::UpdatePoints()
else if(m_angle == 270.0)
m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
- SetPosition(m_position); // Update rect.
+ SetPosition(m_position); // Update rect.
}
void Sum::AddInNode()
@@ -181,3 +180,39 @@ void Sum::Rotate(bool clockwise)
node->Rotate(clockwise);
}
}
+
+bool Sum::Solve(double input)
+{
+ std::vector<double> inputVector;
+ for(auto itN = m_nodeList.begin(), itNEnd = m_nodeList.end(); itN != itNEnd; ++itN) {
+ Node* node = *itN;
+ if(node->GetNodeType() != Node::NODE_OUT) {
+ if(!node->IsConnected()) {
+ inputVector.push_back(0.0);
+ } else {
+ for(auto itC = m_childList.begin(), itCEnd = m_childList.end(); itC != itCEnd; ++itC) {
+ ConnectionLine* cLine = static_cast<ConnectionLine*>(*itC);
+ auto nodeList = cLine->GetNodeList();
+ for(auto itCN = nodeList.begin(), itCNEnd = nodeList.end(); itCN != itCNEnd; ++itCN) {
+ Node* childNode = *itCN;
+ if(childNode == node) {
+ inputVector.push_back(cLine->GetValue());
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(m_signalList.size() != inputVector.size()) return false;
+
+ m_output = 0.0;
+ for(unsigned int i = 0; i < m_signalList.size(); ++i) {
+ if(m_signalList[i] == SIGNAL_POSITIVE)
+ m_output += inputVector[i];
+ else if(m_signalList[i] == SIGNAL_NEGATIVE)
+ m_output -= inputVector[i];
+ }
+ return true;
+}