Power System Platform  2026w11a-beta
Loading...
Searching...
No Matches
Multiplier.cpp
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "ConnectionLine.h"
19#include "Multiplier.h"
20#include <wx/pen.h>
21#include <wx/brush.h>
22
23Multiplier::Multiplier(int id) : MathOperation(id) {}
24
25Multiplier::~Multiplier()
26{
27 for (auto& node : m_nodeList) if (node) delete node;
28 m_nodeList.clear();
29}
30
31//void Multiplier::DrawSymbol() const
32//{
33// // Plot x.
34// glLineWidth(2.0);
35// std::vector<wxPoint2DDouble> xSymbol;
36// xSymbol.push_back(m_position + wxPoint2DDouble(-5, -5));
37// xSymbol.push_back(m_position + wxPoint2DDouble(5, 5));
38// xSymbol.push_back(m_position + wxPoint2DDouble(-5, 5));
39// xSymbol.push_back(m_position + wxPoint2DDouble(5, -5));
40// glColor4d(0.0, 0.3, 1.0, 1.0);
41// DrawLine(xSymbol, GL_LINES);
42//}
43
44void Multiplier::DrawDCSymbol(wxGraphicsContext* gc) const
45{
46 // Plot x.
47 gc->SetPen(wxPen(wxColour(0, 77, 255, 255), 2));
48 gc->SetBrush(*wxTRANSPARENT_BRUSH);
49 wxPoint2DDouble xSymbol[4];
50 xSymbol[0] = m_position + wxPoint2DDouble(-5, -5);
51 xSymbol[1] = m_position + wxPoint2DDouble(5, 5);
52 xSymbol[2] = m_position + wxPoint2DDouble(-5, 5);
53 xSymbol[3] = m_position + wxPoint2DDouble(5, -5);
54 gc->StrokeLines(2, &xSymbol[0]);
55 gc->StrokeLines(2, &xSymbol[2]);
56}
57
58bool Multiplier::Solve(double* input, double timeStep)
59{
60 std::vector<double> inputVector;
61 for(auto itN = m_nodeList.begin(), itNEnd = m_nodeList.end(); itN != itNEnd; ++itN) {
62 Node* node = *itN;
63 if(node->GetNodeType() != Node::NodeType::NODE_OUT) {
64 if(!node->IsConnected()) {
65 inputVector.push_back(1.0);
66 } else {
67 for(auto itC = m_childList.begin(), itCEnd = m_childList.end(); itC != itCEnd; ++itC) {
68 ConnectionLine* cLine = static_cast<ConnectionLine*>(*itC);
69 auto nodeList = cLine->GetNodeList();
70 for(auto itCN = nodeList.begin(), itCNEnd = nodeList.end(); itCN != itCNEnd; ++itCN) {
71 Node* childNode = *itCN;
72 if(childNode == node) {
73 inputVector.push_back(cLine->GetValue());
74 break;
75 }
76 }
77 }
78 }
79 }
80 }
81
82 m_output = 1.0;
83 for(unsigned int i = 0; i < inputVector.size(); ++i) { m_output *= inputVector[i]; }
84
85 return true;
86}
87
89{
90 Multiplier* copy = new Multiplier(*this);
91 return copy;
92}
93
94rapidxml::xml_node<>* Multiplier::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
95{
96 auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Multiplier");
97 XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
98
99 SaveCADProperties(doc, elementNode);
100 SaveControlNodes(doc, elementNode);
101
102 return elementNode;
103}
104
105bool Multiplier::OpenElement(rapidxml::xml_node<>* elementNode)
106{
107 if(!OpenCADProperties(elementNode)) return false;
108 if(!OpenControlNodes(elementNode)) return false;
109
110 StartMove(m_position);
111 UpdatePoints();
112 return true;
113}
Connection between two control elements or other connection line and an element.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
Definition Element.h:112
Abstract class that define the general behavior of math operation control block.
Multiplies two inputs.
Definition Multiplier.h:33
virtual Element * GetCopy()
Get a the element copy.
Node of a control element. This class manages the user interaction with the connection and control el...