Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
Node Class Reference

Node of a control element. This class manages the user interaction with the connection and control elements. More...

#include <ControlElement.h>

Public Types

enum class  NodeType { NODE_IN = 0 , NODE_OUT }
 

Public Member Functions

 Node (wxPoint2DDouble position=wxPoint2DDouble(0, 0), NodeType nodeType=NodeType::NODE_IN, double borderSize=0.0)
 
wxRect2DDouble GetRect () const
 
void SetRect (wxRect2DDouble rect)
 
wxPoint2DDouble GetPosition () const
 
void SetPosition (wxPoint2DDouble position)
 
NodeType GetNodeType () const
 
void SetNodeType (NodeType nodeType)
 
double GetRadius () const
 
std::vector< wxPoint2DDouble > GetInTrianglePts () const
 
double GetAngle () const
 
void SetAngle (double angle)
 
void Rotate (bool clockwise=true)
 
void RotateTriPt (double angle)
 
void StartMove (wxPoint2DDouble position)
 
void Move (wxPoint2DDouble position)
 
bool Contains (wxPoint2DDouble position) const
 
bool IsConnected () const
 
void SetConnected (bool connected=true)
 
int GetID () const
 
void SetID (int id)
 
NodeGetCopy () const
 

Protected Attributes

int m_id = -1
 
wxRect2DDouble m_rect
 
NodeType m_nodeType
 
bool m_connected = false
 
wxPoint2DDouble m_moveStartPt
 
wxPoint2DDouble m_movePos
 
double m_radius = 3.0
 
std::vector< wxPoint2DDouble > m_triPts
 
double m_angle = 0.0
 

Detailed Description

Node of a control element. This class manages the user interaction with the connection and control elements.

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
05/10/2017

Definition at line 30 of file ControlElement.h.

Member Enumeration Documentation

◆ NodeType

enum class Node::NodeType
strong

Definition at line 33 of file ControlElement.h.

33{ NODE_IN = 0, NODE_OUT };

Constructor & Destructor Documentation

◆ Node()

Node::Node ( wxPoint2DDouble  position = wxPoint2DDouble(0, 0),
NodeType  nodeType = NodeType::NODE_IN,
double  borderSize = 0.0 
)

Definition at line 23 of file ControlElement.cpp.

24{
25 double totalRadius = m_radius + borderSize;
26 m_rect = wxRect2DDouble(position.m_x - totalRadius, position.m_y - totalRadius, totalRadius * 2, totalRadius * 2);
27 m_nodeType = nodeType;
28
29 m_triPts.push_back(GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, m_radius));
30 m_triPts.push_back(GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, -m_radius));
31 m_triPts.push_back(GetPosition() + wxPoint2DDouble(-m_radius + 1, 0));
32}

◆ ~Node()

Node::~Node ( )

Definition at line 34 of file ControlElement.cpp.

34{}

Member Function Documentation

◆ Contains()

bool Node::Contains ( wxPoint2DDouble  position) const

Definition at line 98 of file ControlElement.cpp.

99{
100 if (m_connected) return false;
101 return m_rect.Contains(position);
102}

◆ GetAngle()

double Node::GetAngle ( ) const
inline

Definition at line 47 of file ControlElement.h.

47{ return m_angle; }

◆ GetCopy()

Node * Node::GetCopy ( ) const

Definition at line 104 of file ControlElement.cpp.

105{
106 Node* copy = new Node();
107 *copy = *this;
108 return copy;
109}
Node of a control element. This class manages the user interaction with the connection and control el...

◆ GetID()

int Node::GetID ( ) const
inline

Definition at line 59 of file ControlElement.h.

59{ return m_id; }

◆ GetInTrianglePts()

std::vector< wxPoint2DDouble > Node::GetInTrianglePts ( ) const
inline

Definition at line 46 of file ControlElement.h.

46{ return m_triPts; }

◆ GetNodeType()

NodeType Node::GetNodeType ( ) const
inline

Definition at line 43 of file ControlElement.h.

43{ return m_nodeType; }

◆ GetPosition()

wxPoint2DDouble Node::GetPosition ( ) const

Definition at line 54 of file ControlElement.cpp.

55{
56 return m_rect.GetPosition() + wxPoint2DDouble(m_rect.GetSize().GetWidth() / 2, m_rect.GetSize().GetHeight() / 2);
57}

◆ GetRadius()

double Node::GetRadius ( ) const
inline

Definition at line 45 of file ControlElement.h.

45{ return m_radius; }

◆ GetRect()

wxRect2DDouble Node::GetRect ( ) const
inline

Definition at line 38 of file ControlElement.h.

38{ return m_rect; }

◆ IsConnected()

bool Node::IsConnected ( ) const
inline

Definition at line 57 of file ControlElement.h.

57{ return m_connected; }

◆ Move()

void Node::Move ( wxPoint2DDouble  position)

Definition at line 53 of file ControlElement.cpp.

53{ SetPosition(m_movePos + position - m_moveStartPt); }

◆ Rotate()

void Node::Rotate ( bool  clockwise = true)

Definition at line 78 of file ControlElement.cpp.

79{
80 if (clockwise)
81 m_angle += 90.0;
82 else
83 m_angle -= 90.0;
84 if (m_angle >= 360.0)
85 m_angle = 0.0;
86 else if (m_angle < 0)
87 m_angle = 270.0;
88
89 // Update input triangle points.
90 m_triPts[0] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, m_radius);
91 m_triPts[1] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, -m_radius);
92 m_triPts[2] = GetPosition() + wxPoint2DDouble(-m_radius + 1, 0);
93
94 // Rotate according to the angle (node rect center as reference)
95 if (m_angle != 0.0) RotateTriPt(m_angle);
96}

◆ RotateTriPt()

void Node::RotateTriPt ( double  angle)

Definition at line 59 of file ControlElement.cpp.

60{
61 double radAngle = wxDegToRad(angle);
62 wxPoint2DDouble rectCenter =
63 m_rect.GetPosition() + wxPoint2DDouble(m_rect.GetSize().GetWidth() / 2.0, m_rect.GetSize().GetHeight() / 2.0);
64 m_triPts[0] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[0].m_x - rectCenter.m_x) -
65 std::sin(radAngle) * (m_triPts[0].m_y - rectCenter.m_y) + rectCenter.m_x,
66 std::sin(radAngle) * (m_triPts[0].m_x - rectCenter.m_x) +
67 std::cos(radAngle) * (m_triPts[0].m_y - rectCenter.m_y) + rectCenter.m_y);
68 m_triPts[1] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[1].m_x - rectCenter.m_x) -
69 std::sin(radAngle) * (m_triPts[1].m_y - rectCenter.m_y) + rectCenter.m_x,
70 std::sin(radAngle) * (m_triPts[1].m_x - rectCenter.m_x) +
71 std::cos(radAngle) * (m_triPts[1].m_y - rectCenter.m_y) + rectCenter.m_y);
72 m_triPts[2] = wxPoint2DDouble(std::cos(radAngle) * (m_triPts[2].m_x - rectCenter.m_x) -
73 std::sin(radAngle) * (m_triPts[2].m_y - rectCenter.m_y) + rectCenter.m_x,
74 std::sin(radAngle) * (m_triPts[2].m_x - rectCenter.m_x) +
75 std::cos(radAngle) * (m_triPts[2].m_y - rectCenter.m_y) + rectCenter.m_y);
76}

◆ SetAngle()

void Node::SetAngle ( double  angle)
inline

Definition at line 48 of file ControlElement.h.

48{ m_angle = angle; }

◆ SetConnected()

void Node::SetConnected ( bool  connected = true)
inline

Definition at line 58 of file ControlElement.h.

58{ m_connected = connected; }

◆ SetID()

void Node::SetID ( int  id)
inline

Definition at line 60 of file ControlElement.h.

60{ m_id = id; }

◆ SetNodeType()

void Node::SetNodeType ( NodeType  nodeType)
inline

Definition at line 44 of file ControlElement.h.

44{ m_nodeType = nodeType; }

◆ SetPosition()

void Node::SetPosition ( wxPoint2DDouble  position)

Definition at line 35 of file ControlElement.cpp.

36{
37 m_rect = wxRect2DDouble(position.m_x - m_rect.m_width / 2, position.m_y - m_rect.m_height / 2, m_rect.m_width,
38 m_rect.m_height);
39 m_triPts[0] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, m_radius);
40 m_triPts[1] = GetPosition() + wxPoint2DDouble(-m_radius - m_rect.GetSize().GetWidth() / 2, -m_radius);
41 m_triPts[2] = GetPosition() + wxPoint2DDouble(-m_radius + 1, 0);
42
43 // Rotate according to the angle (node rect center as reference)
44 if (m_angle != 0.0) RotateTriPt(m_angle);
45}

◆ SetRect()

void Node::SetRect ( wxRect2DDouble  rect)
inline

Definition at line 39 of file ControlElement.h.

39{ m_rect = rect; }

◆ StartMove()

void Node::StartMove ( wxPoint2DDouble  position)

Definition at line 47 of file ControlElement.cpp.

48{
49 m_moveStartPt = position;
50 m_movePos = m_rect.GetPosition() - wxPoint2DDouble(-m_rect.m_width / 2, -m_rect.m_height / 2);
51}

Member Data Documentation

◆ m_angle

double Node::m_angle = 0.0
protected

Definition at line 76 of file ControlElement.h.

◆ m_connected

bool Node::m_connected = false
protected

Definition at line 69 of file ControlElement.h.

◆ m_id

int Node::m_id = -1
protected

Definition at line 64 of file ControlElement.h.

◆ m_movePos

wxPoint2DDouble Node::m_movePos
protected

Definition at line 72 of file ControlElement.h.

◆ m_moveStartPt

wxPoint2DDouble Node::m_moveStartPt
protected

Definition at line 71 of file ControlElement.h.

◆ m_nodeType

NodeType Node::m_nodeType
protected

Definition at line 67 of file ControlElement.h.

◆ m_radius

double Node::m_radius = 3.0
protected

Definition at line 74 of file ControlElement.h.

◆ m_rect

wxRect2DDouble Node::m_rect
protected

Definition at line 66 of file ControlElement.h.

◆ m_triPts

std::vector<wxPoint2DDouble> Node::m_triPts
protected

Definition at line 75 of file ControlElement.h.


The documentation for this class was generated from the following files: