Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
MathOperation.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 "MathOperation.h"
19#include "ConnectionLine.h"
20#include <wx/pen.h>
21#include <wx/brush.h>
22
23MathOperation::MathOperation(int id) : ControlElement(id)
24{
25 m_width = m_height = 36.0;
26 Node* nodeIn1 = new Node(m_position + wxPoint2DDouble(-18, -9), Node::NodeType::NODE_IN, m_borderSize);
27 nodeIn1->StartMove(m_position);
28 Node* nodeIn2 = new Node(m_position + wxPoint2DDouble(-18, 9), Node::NodeType::NODE_IN, m_borderSize);
29 nodeIn2->StartMove(m_position);
30 Node* nodeOut = new Node(m_position + wxPoint2DDouble(18, 0), Node::NodeType::NODE_OUT, m_borderSize);
31 nodeOut->SetAngle(180.0);
32 nodeOut->StartMove(m_position);
33 m_nodeList.push_back(nodeIn1);
34 m_nodeList.push_back(nodeIn2);
35 m_nodeList.push_back(nodeOut);
36}
37
38MathOperation::~MathOperation() {}
39
40void MathOperation::DrawDC(GUIColour* guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const
41{
42 if (m_selected) {
43 gc->SetPen(*wxTRANSPARENT_PEN);
44 gc->SetBrush(wxBrush(guiColour->selection));
45 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
46 gc->DrawRectangle(m_position.m_x - m_width / 2 - borderSize / 2, m_position.m_y - m_height / 2 - borderSize / 2, m_width + borderSize, m_height + borderSize);
47 }
48 gc->SetPen(guiColour->enabled);
49 gc->SetBrush(guiColour->background);
50 //DrawRectangle(m_position, m_width, m_height);
51 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
52
53 // Draw personalized element symbol.
54 DrawDCSymbol(guiColour, gc);
55
56 gc->SetPen(*wxTRANSPARENT_PEN);
57 gc->SetBrush(guiColour->enabled);
58 DrawDCNodes(gc);
59}
60
61void MathOperation::Rotate(bool clockwise)
62{
63 if(clockwise)
64 m_angle += 90.0;
65 else
66 m_angle -= 90.0;
67 if(m_angle >= 360.0)
68 m_angle = 0.0;
69 else if(m_angle < 0)
70 m_angle = 270.0;
71
72 UpdatePoints();
73
74 for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
75 Node* node = *it;
76 node->Rotate(clockwise);
77 }
78}
79
80void MathOperation::UpdatePoints()
81{
82 if(m_angle == 0.0) {
83 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-18, -9));
84 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-18, 9));
85 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(18, 0));
86 } else if(m_angle == 90.0) {
87 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(9, -18));
88 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-9, -18));
89 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(0, 18));
90 } else if(m_angle == 180.0) {
91 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(18, 9));
92 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(18, -9));
93 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(-18, 0));
94 } else if(m_angle == 270.0) {
95 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-9, 18));
96 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(9, 18));
97 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(0, -18));
98 }
99}
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual void Rotate(bool clockwise=true)
Rotate the element.
Node of a control element. This class manages the user interaction with the connection and control el...