diff options
author | Thales Lima Oliveira <thaleslima.ufu@gmail.com> | 2017-04-24 17:39:03 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-24 17:39:03 -0300 |
commit | 7804c1bd2c0bd2a5f135c30b20991e8187581cc6 (patch) | |
tree | 725e524253d6fd714460402194b408cb33b80b3f /Project/Sum.cpp | |
parent | 69131a727782090ffd7cb467f449e8f26d3d2949 (diff) | |
parent | 9529a6ed44645842adc6f938478acc1dfa17a284 (diff) | |
download | PSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.tar.gz PSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.tar.xz PSP.git-7804c1bd2c0bd2a5f135c30b20991e8187581cc6.zip |
Merge pull request #28 from Thales1330/wip/generic-controllers
Wip generic controllers. Chart view implementation required, creating new branch....
Diffstat (limited to 'Project/Sum.cpp')
-rw-r--r-- | Project/Sum.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/Project/Sum.cpp b/Project/Sum.cpp new file mode 100644 index 0000000..606b367 --- /dev/null +++ b/Project/Sum.cpp @@ -0,0 +1,183 @@ +#include "Sum.h" +#include "SumForm.h" + +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); + nodeIn1->StartMove(m_position); + Node* nodeIn2 = + new Node(m_position + wxPoint2DDouble(-m_width / 2, 27 - m_height / 2), Node::NODE_IN, m_borderSize); + nodeIn2->StartMove(m_position); + Node* nodeOut = new Node(m_position + wxPoint2DDouble(m_width / 2, 0), Node::NODE_OUT, m_borderSize); + nodeOut->SetAngle(180.0); + nodeOut->StartMove(m_position); + m_nodeList.push_back(nodeIn1); + m_nodeList.push_back(nodeIn2); + m_nodeList.push_back(nodeOut); + m_signalList.push_back(SIGNAL_POSITIVE); + m_signalList.push_back(SIGNAL_NEGATIVE); + + UpdatePoints(); +} + +Sum::~Sum() {} + +void Sum::Draw(wxPoint2DDouble translation, double scale) const +{ + glLineWidth(1.0); + if(m_selected) { + glColor4dv(m_selectionColour.GetRGBA()); + double borderSize = (m_borderSize * 2.0 + 1.0) / scale; + DrawRectangle(m_position, m_width + borderSize, m_height + borderSize); + } + glColor4d(1.0, 1.0, 1.0, 1.0); + DrawRectangle(m_position, m_width, m_height); + glColor4d(0.0, 0.0, 0.0, 1.0); + DrawRectangle(m_position, m_width, m_height, GL_LINE_LOOP); + + // Plot signals. + glLineWidth(2.0); + wxPoint2DDouble signalOffset[4]; + wxPoint2DDouble sigmaOffset; + if(m_angle == 0.0) { + signalOffset[0] = wxPoint2DDouble(6, 0); + signalOffset[1] = wxPoint2DDouble(12, 0); + signalOffset[2] = wxPoint2DDouble(9, -3); + signalOffset[3] = wxPoint2DDouble(9, 3); + sigmaOffset = wxPoint2DDouble(6, 0); + } else if(m_angle == 90.0) { + signalOffset[0] = wxPoint2DDouble(-3, 9); + signalOffset[1] = wxPoint2DDouble(3, 9); + signalOffset[2] = wxPoint2DDouble(0, 6); + signalOffset[3] = wxPoint2DDouble(0, 12); + sigmaOffset = wxPoint2DDouble(0, 6); + } else if(m_angle == 180.0) { + signalOffset[0] = wxPoint2DDouble(-6, 0); + signalOffset[1] = wxPoint2DDouble(-12, 0); + signalOffset[2] = wxPoint2DDouble(-9, -3); + signalOffset[3] = wxPoint2DDouble(-9, 3); + sigmaOffset = wxPoint2DDouble(-6, 0); + } else if(m_angle == 270.0) { + signalOffset[0] = wxPoint2DDouble(-3, -9); + signalOffset[1] = wxPoint2DDouble(3, -9); + signalOffset[2] = wxPoint2DDouble(0, -6); + signalOffset[3] = wxPoint2DDouble(0, -12); + sigmaOffset = wxPoint2DDouble(0, -6); + } + for(int i = 0; i < (int)m_nodeList.size() - 1; ++i) { + std::vector<wxPoint2DDouble> hLine; + hLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[0]); + hLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[1]); + DrawLine(hLine); + if(m_signalList[i] == SIGNAL_POSITIVE) { + std::vector<wxPoint2DDouble> vLine; + vLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[2]); + vLine.push_back(m_nodeList[i]->GetPosition() + signalOffset[3]); + DrawLine(vLine); + } + } + + // Plot sigma. + std::vector<wxPoint2DDouble> sigma; + sigma.push_back(m_position + wxPoint2DDouble(4, 9) + sigmaOffset); + sigma.push_back(m_position + wxPoint2DDouble(-6, 9) + sigmaOffset); + sigma.push_back(m_position + wxPoint2DDouble(0, 0) + sigmaOffset); + sigma.push_back(m_position + wxPoint2DDouble(-6, -9) + sigmaOffset); + sigma.push_back(m_position + wxPoint2DDouble(4, -9) + sigmaOffset); + glColor4d(0.0, 0.3, 1.0, 1.0); + DrawLine(sigma); + + glColor4d(0.0, 0.0, 0.0, 1.0); + DrawNodes(); +} + +bool Sum::ShowForm(wxWindow* parent, Element* element) +{ + SumForm* sumForm = new SumForm(parent, this); + if(sumForm->ShowModal() == wxID_OK) { + sumForm->Destroy(); + return true; + } + sumForm->Destroy(); + return false; +} + +void Sum::UpdatePoints() +{ + if(m_angle == 0.0 || m_angle == 180.0) { + m_height = 18.0 * (m_nodeList.size() - 1); + m_width = 36.0; + } else { + m_width = 18.0 * (m_nodeList.size() - 1); + m_height = 42.0; + } + + for(int i = 0; i < (int)m_nodeList.size() - 1; ++i) { + if(m_angle == 0.0) + m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 9 + 18 * i - m_height / 2)); + else if(m_angle == 90.0) + m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(m_width / 2 - 9 - 18 * i, -m_height / 2)); + else if(m_angle == 180.0) + m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, m_height / 2 - 9 - 18 * i)); + else if(m_angle == 270.0) + m_nodeList[i]->SetPosition(m_position + wxPoint2DDouble(9 + 18 * i - m_width / 2, m_height / 2)); + } + if(m_angle == 0.0) + m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0)); + else if(m_angle == 90.0) + m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2)); + else if(m_angle == 180.0) + m_nodeList[m_nodeList.size() - 1]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0)); + 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. +} + +void Sum::AddInNode() +{ + Node* newNode = new Node(wxPoint2DDouble(0, 0), Node::NODE_IN, m_borderSize); + m_nodeList.insert(m_nodeList.end() - 1, newNode); +} + +void Sum::RemoveInNode() +{ + Node* nodeToRemove = *(m_nodeList.end() - 2); + bool foundChild = false; + for(auto it = m_childList.begin(), itEnd = m_childList.end(); it != itEnd; ++it) { + ControlElement* child = static_cast<ControlElement*>(*it); + auto childNodeList = child->GetNodeList(); + for(auto itN = childNodeList.begin(), itEndN = childNodeList.end(); itN != itEndN; ++itN) { + Node* node = *itN; + if(node == nodeToRemove) { + child->RemoveParent(this); + RemoveChild(child); + foundChild = true; + break; + } + } + if(foundChild) break; + } + m_nodeList.erase(m_nodeList.end() - 2); +} + +void Sum::Rotate(bool clockwise) +{ + if(clockwise) + m_angle += 90.0; + else + m_angle -= 90.0; + if(m_angle >= 360.0) + m_angle = 0.0; + else if(m_angle < 0) + m_angle = 270.0; + + UpdatePoints(); + + for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) { + Node* node = *it; + node->Rotate(clockwise); + } +} |