Power System Platform  2026w34a-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
31void Multiplier::DrawDCSymbol(GUIColour* guiColour, wxGraphicsContext* gc) const
32{
33 // Plot x.
34 gc->SetPen(wxPen(guiColour->bus, 2));
35 gc->SetBrush(*wxTRANSPARENT_BRUSH);
36 wxPoint2DDouble xSymbol[4];
37 xSymbol[0] = m_position + wxPoint2DDouble(-5, -5);
38 xSymbol[1] = m_position + wxPoint2DDouble(5, 5);
39 xSymbol[2] = m_position + wxPoint2DDouble(-5, 5);
40 xSymbol[3] = m_position + wxPoint2DDouble(5, -5);
41 gc->StrokeLines(2, &xSymbol[0]);
42 gc->StrokeLines(2, &xSymbol[2]);
43}
44
45bool Multiplier::Solve(double* input, double timeStep)
46{
47 std::vector<double> inputVector;
48 for(auto itN = m_nodeList.begin(), itNEnd = m_nodeList.end(); itN != itNEnd; ++itN) {
49 Node* node = *itN;
50 if(node->GetNodeType() != Node::NodeType::NODE_OUT) {
51 if(!node->IsConnected()) {
52 inputVector.push_back(1.0);
53 } else {
54 for(auto itC = m_childList.begin(), itCEnd = m_childList.end(); itC != itCEnd; ++itC) {
55 ConnectionLine* cLine = static_cast<ConnectionLine*>(*itC);
56 auto nodeList = cLine->GetNodeList();
57 for(auto itCN = nodeList.begin(), itCNEnd = nodeList.end(); itCN != itCNEnd; ++itCN) {
58 Node* childNode = *itCN;
59 if(childNode == node) {
60 inputVector.push_back(cLine->GetValue());
61 break;
62 }
63 }
64 }
65 }
66 }
67 }
68
69 m_output = 1.0;
70 for(unsigned int i = 0; i < inputVector.size(); ++i) { m_output *= inputVector[i]; }
71
72 return true;
73}
74
76{
77 Multiplier* copy = new Multiplier(*this);
78 return copy;
79}
80
81rapidxml::xml_node<>* Multiplier::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
82{
83 auto elementNode = XMLParser::AppendNode(doc, elementListNode, "Multiplier");
84 XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
85
86 SaveCADProperties(doc, elementNode);
87 SaveControlNodes(doc, elementNode);
88
89 return elementNode;
90}
91
92bool Multiplier::OpenElement(rapidxml::xml_node<>* elementNode)
93{
94 if(!OpenCADProperties(elementNode)) return false;
95 if(!OpenControlNodes(elementNode)) return false;
96
97 StartMove(m_position);
98 UpdatePoints();
99 return true;
100}
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Element()
Constructor.
Definition Element.cpp:28
Abstract class that define the general behavior of math operation control block.
virtual Element * GetCopy()
Get a the element copy.