Power System Platform  2026w10a-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//void MathOperation::Draw(wxPoint2DDouble translation, double scale) const
40//{
41// glLineWidth(1.0);
42// if(m_selected) {
43// glColor4dv(m_selectionColour.GetRGBA());
44// double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
45// DrawRectangle(m_position, m_width + borderSize, m_height + borderSize);
46// }
47// glColor4d(1.0, 1.0, 1.0, 1.0);
48// DrawRectangle(m_position, m_width, m_height);
49// glColor4d(0.0, 0.0, 0.0, 1.0);
50// DrawRectangle(m_position, m_width, m_height, GL_LINE_LOOP);
51//
52// // Draw personalized element symbol.
53// DrawSymbol();
54//
55// glColor4d(0.0, 0.0, 0.0, 1.0);
56// DrawNodes();
57//}
58
59void MathOperation::DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext* gc) const
60{
61 if (m_selected) {
62 gc->SetPen(*wxTRANSPARENT_PEN);
63 gc->SetBrush(wxBrush(m_selectionColour));
64 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
65 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);
66 }
67 gc->SetPen(*wxBLACK_PEN);
68 gc->SetBrush(*wxWHITE_BRUSH);
69 //DrawRectangle(m_position, m_width, m_height);
70 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
71
72 // Draw personalized element symbol.
73 DrawDCSymbol(gc);
74
75 gc->SetPen(*wxTRANSPARENT_PEN);
76 gc->SetBrush(*wxBLACK_BRUSH);
77 DrawDCNodes(gc);
78}
79
80void MathOperation::Rotate(bool clockwise)
81{
82 if(clockwise)
83 m_angle += 90.0;
84 else
85 m_angle -= 90.0;
86 if(m_angle >= 360.0)
87 m_angle = 0.0;
88 else if(m_angle < 0)
89 m_angle = 270.0;
90
91 UpdatePoints();
92
93 for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
94 Node* node = *it;
95 node->Rotate(clockwise);
96 }
97}
98
99void MathOperation::UpdatePoints()
100{
101 if(m_angle == 0.0) {
102 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-18, -9));
103 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-18, 9));
104 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(18, 0));
105 } else if(m_angle == 90.0) {
106 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(9, -18));
107 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-9, -18));
108 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(0, 18));
109 } else if(m_angle == 180.0) {
110 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(18, 9));
111 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(18, -9));
112 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(-18, 0));
113 } else if(m_angle == 270.0) {
114 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-9, 18));
115 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(9, 18));
116 m_nodeList[2]->SetPosition(m_position + wxPoint2DDouble(0, -18));
117 }
118}
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual void DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
Node of a control element. This class manages the user interaction with the connection and control el...