Power System Platform  2026w23a-beta
Loading...
Searching...
No Matches
RateLimiter Class Reference

Limits the rising and/or falling rate.
More...

#include <RateLimiter.h>

Inheritance diagram for RateLimiter:
Collaboration diagram for RateLimiter:

Public Member Functions

 RateLimiter (int id)
 
virtual void DrawDC (GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
 Draw the element using GDI+.
 
virtual bool Contains (wxPoint2DDouble position) const
 Checks if the element contains a position.
 
virtual bool Intersects (wxRect2DDouble rect) const
 Check if the element's rect intersects other rect.
 
virtual bool ShowForm (wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
 Show element data form.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
virtual void UpdatePoints ()
 
double GetUpLimit () const
 
double GetLowLimit () const
 
void SetUpLimit (double upLimit)
 
void SetLowLimit (double lowLimit)
 
virtual bool Solve (double *input, double timeStep)
 Calculate the rate and limits it if exceeds.

 
virtual rapidxml::xml_node * SaveElement (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementListNode)
 
virtual bool OpenElement (rapidxml::xml_node<> *elementNode)
 
virtual ElementGetCopy ()
 Get a the element copy.
 
- Public Member Functions inherited from ControlElement
 ControlElement (int id)
 
virtual void StartMove (wxPoint2DDouble position)
 Update the element attributes related to the movement.
 
virtual void Move (wxPoint2DDouble position)
 Move the element other position.
 
virtual void SetFont (wxFont &font)
 
void SetNodeList (std::vector< Node * > nodeList)
 
std::vector< Node * > GetNodeList () const
 
virtual void DrawDCNodes (wxGraphicsContext *gc) const
 
virtual void ReplaceNode (Node *oldNode, Node *newNode)
 
virtual bool UpdateText ()
 Update the OpenGL text in the element (if present).
 
virtual bool IsSolved () const
 
virtual void SetSolved (bool solved=true)
 
virtual bool Initialize ()
 
virtual double GetOutput () const
 
virtual void SetOutput (double output)
 
- Public Member Functions inherited from Element
 Element ()
 Constructor.
 
virtual ~Element ()
 Destructor.
 
void SetDragging (bool dragging=true)
 Set if the element are being dragged.
 
void SetHeight (double height)
 Set element height.
 
void SetPosition (const wxPoint2DDouble position)
 Set the element position and update the rectangle.
 
void SetSelected (bool selected=true)
 Set element selection.
 
void SetWidth (double width)
 Set element width.
 
void SetAngle (double angle)
 Set element angle.
 
void ShowPickbox (bool showPickbox=true)
 Set if the pickbox is shown.
 
void SetBorderSize (double borderSize)
 Set the size of the border (shown in selected elements).
 
bool SetOnline (bool online=true)
 Set if the element is online or offline.
 
virtual void SetPointList (std::vector< wxPoint2DDouble > pointList)
 Set the list of points that connect the element to the bus.
 
ElementType GetElementType ()
 
wxRect2DDouble GetRect () const
 Get the element rectangle.
 
wxPoint2DDouble GetPosition () const
 Get the element position.
 
bool IsDragging () const
 Checks if the element is being dragged.
 
double GetHeight () const
 Get the element height.
 
bool IsSelected () const
 Checks if the element is selected.
 
double GetWidth () const
 Get the element width.
 
double GetAngle () const
 Get the element angle.
 
double GetRotationAngle () const
 Get the angle of rotation.
 
bool IsPickboxShown () const
 Checks if the pickbox is shown.
 
bool IsOnline () const
 Checks if the element is online or offline.
 
virtual std::vector< wxPoint2DDouble > GetPointList () const
 Get the list of points that connect the element to bus.
 
virtual bool AddParent (Element *parent, wxPoint2DDouble position)
 Add a parent to the element. This method must be used on power elements that connect to a bus, so the parent must be a bus. The element basic points are calculated in this method, so apply this when the element is being inserted.
 
virtual void AddParent (Element *parent)
 Add a parent to the element.
 
virtual void SetID (int id)
 Set the element ID.
 
virtual int GetID () const
 Get the element ID.
 
virtual void AddChild (Element *child)
 Add a child to the child list.
 
virtual void RemoveChild (Element *child)
 Remove a child from the list.
 
virtual void ReplaceChild (Element *oldChild, Element *newChild)
 Replace a child from the list.
 
virtual wxString GetTipText () const
 Get the tip text.
 
virtual void DrawDC (GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxDC &dc) const
 Draw the element using wxDC.
 
virtual bool GetContextMenu (wxMenu &menu)
 Get the element contex menu.
 
virtual void AddPoint (wxPoint2DDouble point)
 Add point to the list of points that connect the element to the bus.
 
virtual void MoveNode (Element *parent, wxPoint2DDouble position)
 Move a node. StartMove(wxPoint2DDouble position) before start moving.
 
virtual bool NodeContains (wxPoint2DDouble position)
 Check if a node contains a point. If contains, set the attributes related to node movement.
 
virtual void UpdateNodes ()
 Update the nodes according to the parents. If a parent is removed, use this method.
 
void SetParent (Element *parent, int num)
 
void SetChild (Element *child, int num)
 
virtual bool SetNodeParent (Element *parent)
 Set a perent to the node. If all conditions are met, a new parent are added to the element and the points related to the nodes will be calculated.
 
virtual void RemoveParent (Element *parent)
 Remove a parent.
 
virtual void ReplaceParent (Element *oldParent, Element *newParent)
 Replace a parent.
 
virtual void RotateNode (Element *parent, bool clockwise=true)
 Rotate a node.
 
virtual bool PickboxContains (wxPoint2DDouble position)
 Check if a pickbox contains a point. If contains the attributes related to pickbox movement will be calculated.
 
virtual void MovePickbox (wxPoint2DDouble position)
 Move the pickbox.
 
virtual wxCursor GetBestPickboxCursor () const
 Get the best cursor to shown to the user when the mouse is above a pickbox.
 
virtual void ResetPickboxes ()
 Remove the pickboxes.
 
virtual void ResetNodes ()
 Remove the active nodes.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert the element position to screen position.
 
virtual wxPoint2DDouble WorldToScreen (wxPoint2DDouble position, wxPoint2DDouble translation, double scale, double offsetX=0.0, double offsetY=0.0) const
 Convert a generic position to screen position.
 
virtual bool RotatedRectanglesIntersects (wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
 Check if two roteted rectangles intersect.
 
virtual void DrawDCRectangle (wxPoint2DDouble position, double width, double height, double angle, wxDC &dc) const
 Draw a circle.
 
virtual void DrawDCRoundedRectRotated (wxDC &dc, const wxPoint2DDouble &center, double width, double height, double radius, double angleDeg, int arcSegments=8) const
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
 Draw a circle using device context.
 
virtual void DrawDCCircle (wxPoint2DDouble position, double radius, wxDC &dc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, int numSegments, wxGraphicsContext *gc) const
 
virtual void DrawDCArc (wxPoint2DDouble position, double radius, double initAngle, double finalAngle, wxDC &dc) const
 
virtual void DrawDCTriangle (std::vector< wxPoint2DDouble > points, wxGraphicsContext *gc) const
 Draw rectangle.
 
virtual void DrawDCTriangle (std::vector< wxPoint > points, wxDC &dc) const
 
virtual void DrawDCPickbox (wxPoint2DDouble position, wxGraphicsContext *gc) const
 Draw a point.
 
virtual wxPoint2DDouble RotateAtPosition (wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
 Rotate a point as element position being the origin.
 
virtual wxPoint2DDouble RotateLocal (wxPoint2DDouble local, double angleDeg) const
 
virtual wxPoint RotateAround (const wxPoint2DDouble &p, const wxPoint2DDouble &center, double angleDeg) const
 
virtual std::vector< Element * > GetParentList () const
 Get the parent list.
 
virtual std::vector< Element * > GetChildList () const
 Get the Child list.
 
virtual void CalculateBoundaries (wxPoint2DDouble &leftUp, wxPoint2DDouble &rightBottom) const
 Calculate the element boundaries.
 
virtual void GeneralMenuItens (wxMenu &menu)
 Insert general itens to context menu.
 
virtual double PointToLineDistance (wxPoint2DDouble point, int *segmentNumber=nullptr) const
 Calculate the distance between a line (formed by point list) and a point.
 
bool IsInserted () const
 Check if the element is properly inserted in the workspace.
 
void SetInserted (bool inserted=true)
 Set if the element is properly inserted in the workspace.
 
void SaveCADProperties (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenCADProperties (rapidxml::xml_node<> *elementNode)
 

Protected Attributes

double m_upLimit = 5.0
 
double m_lowLimit = -5.0
 
- Protected Attributes inherited from ControlElement
std::vector< Node * > m_nodeList
 
bool m_solved = false
 
double m_output = 0.0
 
- Protected Attributes inherited from Element
ElementType m_elementType = ElementType::TYPE_NONE
 
int m_elementID = 0
 
std::vector< Element * > m_parentList
 
std::vector< Element * > m_childList
 
wxRect2DDouble m_rect
 
wxPoint2DDouble m_position
 
double m_width = 0.0
 
double m_height = 0.0
 
double m_angle = 0.0
 
double m_borderSize = 2.0
 
double m_rotationAngle = 45.0
 
double m_switchSize = 10.0
 
std::vector< wxRect2DDouble > m_switchRect
 
bool m_selected = false
 
bool m_dragging = false
 
bool m_showPickbox = false
 
bool m_inserted = false
 
int m_activePickboxID = ID_PB_NONE
 
int m_activeNodeID = 0
 
std::vector< wxPoint2DDouble > m_pointList
 
std::vector< wxPoint2DDouble > m_movePts
 
wxPoint2DDouble m_moveStartPt
 
wxPoint2DDouble m_movePos
 
bool m_online = true
 

Additional Inherited Members

- Static Public Member Functions inherited from ControlElement
static ControlElementGetControlElementFromID (std::vector< std::shared_ptr< ControlElement > > elementList, int id)
 
- Static Public Member Functions inherited from Element
static bool DoubleFromString (wxWindow *parent, wxString strValue, double &value, wxString errorMsg)
 Get a double value from a string. Show a error message if the conversion fail.
 
static bool IntFromString (wxWindow *parent, wxString strValue, int &value, wxString errorMsg)
 Convert a string to int. Show a error message if the conversion fail.
 
static wxString StringFromDouble (double value, int minDecimal=1, int maxDecimals=13)
 Convert a double value to string.
 
- Protected Member Functions inherited from ControlElement
void SaveControlNodes (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenControlNodes (rapidxml::xml_node<> *elementNode)
 

Detailed Description

Limits the rising and/or falling rate.

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

Definition at line 32 of file RateLimiter.h.

Constructor & Destructor Documentation

◆ RateLimiter()

RateLimiter::RateLimiter ( int  id)

Definition at line 23 of file RateLimiter.cpp.

23 : ControlElement(id)
24{
25 m_width = m_height = 36.0;
26 Node* nodeIn = new Node(m_position + wxPoint2DDouble(-18, 0), Node::NodeType::NODE_IN, m_borderSize);
27 nodeIn->StartMove(m_position);
28 Node* nodeOut = new Node(m_position + wxPoint2DDouble(18, 0), Node::NodeType::NODE_OUT, m_borderSize);
29 nodeOut->SetAngle(180.0);
30 nodeOut->StartMove(m_position);
31 m_nodeList.push_back(nodeIn);
32 m_nodeList.push_back(nodeOut);
33}
Node of a control element. This class manages the user interaction with the connection and control el...

◆ ~RateLimiter()

RateLimiter::~RateLimiter ( )

Definition at line 35 of file RateLimiter.cpp.

36{
37 for (auto& node : m_nodeList) if (node) delete node;
38 m_nodeList.clear();
39}

Member Function Documentation

◆ Contains()

virtual bool RateLimiter::Contains ( wxPoint2DDouble  position) const
inlinevirtual

Checks if the element contains a position.

Parameters
positionPosition to be checked.

Implements Element.

Definition at line 40 of file RateLimiter.h.

40{ return m_rect.Contains(position); }

◆ DrawDC()

void RateLimiter::DrawDC ( GUIColour guiColour,
wxPoint2DDouble  translation,
double  scale,
wxGraphicsContext *  gc 
) const
virtual

Draw the element using GDI+.

Parameters
guiColourColours of the system defined in properties.
translationTranslation of the system.
scaleScale of the system.
gcGraphics context

Reimplemented from Element.

Definition at line 41 of file RateLimiter.cpp.

42{
43 if (m_selected) {
44 gc->SetPen(*wxTRANSPARENT_PEN);
45 gc->SetBrush(guiColour->selection);
46 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
47 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);
48 }
49 gc->SetPen(guiColour->enabled);
50 gc->SetBrush(guiColour->background);
51 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
52
53 // Plot symbol.
54 gc->SetBrush(*wxTRANSPARENT_BRUSH);
55 wxPoint2DDouble axis[4];
56 axis[0] = m_position + wxPoint2DDouble(-13, 0);
57 axis[1] = m_position + wxPoint2DDouble(13, 0);
58 axis[2] = m_position + wxPoint2DDouble(0, -13);
59 axis[3] = m_position + wxPoint2DDouble(0, 13);
60 gc->StrokeLines(2, &axis[0]);
61 gc->StrokeLines(2, &axis[2]);
62
63 gc->SetPen(wxPen(guiColour->bus, 2));
64 wxPoint2DDouble limSymbol[2];
65 limSymbol[0] = m_position + wxPoint2DDouble(10, -10);
66 limSymbol[1] = m_position + wxPoint2DDouble(-10, 10);
67 gc->StrokeLines(2, limSymbol);
68
69 gc->SetPen(*wxTRANSPARENT_PEN);
70 gc->SetBrush(guiColour->enabled);
71 DrawDCNodes(gc);
72}

◆ GetCopy()

Element * RateLimiter::GetCopy ( )
virtual

Get a the element copy.

Returns
Copy of the element.

Reimplemented from Element.

Definition at line 148 of file RateLimiter.cpp.

149{
150 RateLimiter* copy = new RateLimiter(*this);
151 return copy;
152}
Limits the rising and/or falling rate.
Definition RateLimiter.h:33

◆ GetLowLimit()

double RateLimiter::GetLowLimit ( ) const
inline

Definition at line 48 of file RateLimiter.h.

48{ return m_lowLimit; }

◆ GetUpLimit()

double RateLimiter::GetUpLimit ( ) const
inline

Definition at line 47 of file RateLimiter.h.

47{ return m_upLimit; }

◆ Intersects()

virtual bool RateLimiter::Intersects ( wxRect2DDouble  rect) const
inlinevirtual

Check if the element's rect intersects other rect.

Parameters
rectRect to check intersection.

Implements Element.

Definition at line 41 of file RateLimiter.h.

41{ return m_rect.Intersects(rect); }

◆ OpenElement()

bool RateLimiter::OpenElement ( rapidxml::xml_node<> *  elementNode)
virtual

Reimplemented from Element.

Definition at line 171 of file RateLimiter.cpp.

172{
173 if (!OpenCADProperties(elementNode)) return false;
174 if (!OpenControlNodes(elementNode)) return false;
175
176 // Element properties
177 m_upLimit = XMLParser::GetNodeValueDouble(elementNode, "UpperLimit");
178 m_lowLimit = XMLParser::GetNodeValueDouble(elementNode, "LowerLimit");
179
180 StartMove(m_position);
181 UpdatePoints();
182 return true;
183}
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.

◆ Rotate()

void RateLimiter::Rotate ( bool  clockwise = true)
virtual

Rotate the element.

Parameters
clockwiseTrue to rotate clockwise, false to rotate counter-clockwise.

Reimplemented from Element.

Definition at line 84 of file RateLimiter.cpp.

85{
86 if (clockwise)
87 m_angle += 90.0;
88 else
89 m_angle -= 90.0;
90 if (m_angle >= 360.0)
91 m_angle = 0.0;
92 else if (m_angle < 0)
93 m_angle = 270.0;
94
95 UpdatePoints();
96
97 for (auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
98 Node* node = *it;
99 node->Rotate(clockwise);
100 }
101}

◆ SaveElement()

rapidxml::xml_node * RateLimiter::SaveElement ( rapidxml::xml_document<> &  doc,
rapidxml::xml_node<> *  elementListNode 
)
virtual

Reimplemented from Element.

Definition at line 154 of file RateLimiter.cpp.

155{
156 auto elementNode = XMLParser::AppendNode(doc, elementListNode, "RateLimiter");
157 XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
158
159 SaveCADProperties(doc, elementNode);
160 SaveControlNodes(doc, elementNode);
161
162 // Element properties
163 auto upLimit = XMLParser::AppendNode(doc, elementNode, "UpperLimit");
164 XMLParser::SetNodeValue(doc, upLimit, m_upLimit);
165 auto lowLimit = XMLParser::AppendNode(doc, elementNode, "LowerLimit");
166 XMLParser::SetNodeValue(doc, lowLimit, m_lowLimit);
167
168 return elementNode;
169}

◆ SetLowLimit()

void RateLimiter::SetLowLimit ( double  lowLimit)
inline

Definition at line 50 of file RateLimiter.h.

50{ m_lowLimit = lowLimit; }

◆ SetUpLimit()

void RateLimiter::SetUpLimit ( double  upLimit)
inline

Definition at line 49 of file RateLimiter.h.

49{ m_upLimit = upLimit; }

◆ ShowForm()

bool RateLimiter::ShowForm ( wxWindow *  parent,
Element element,
wxWindow *  workspace = nullptr 
)
virtual

Show element data form.

Parameters
parentForm parent
elementElement that will be edited.
Returns
True if the form is shown, false otherwise.

Reimplemented from Element.

Definition at line 74 of file RateLimiter.cpp.

75{
76 RateLimiterForm form(parent, this);
77 form.CenterOnParent();
78 if (form.ShowModal() == wxID_OK) {
79 return true;
80 }
81 return false;
82}
Form to edit the rate limit control data.

◆ Solve()

bool RateLimiter::Solve ( double *  input,
double  timeStep 
)
virtual

Calculate the rate and limits it if exceeds.

The rate is calculated by:

\( rate = \frac{x(i) - y(i-1)}{\Delta t} \)

Where, \( x(i) \) is the current input and \( y(i-1) \) is the previous output.

If the \(rate\) is greater than rising rate ( \( R \)), the output will be:

\( output = \Delta t \cdot R + y(i-1)\)

If the \(rate\) is lower than falling rate ( \( F \)), the output will be:

\( output = \Delta t \cdot F + y(i-1) \)

Otherwise:

\( output = input \)

.

Parameters
inputInput value.
timeStepTime step.
Returns
Always true.

Reimplemented from ControlElement.

Definition at line 123 of file RateLimiter.cpp.

124{
125 if (!input) {
126 m_output = 0.0;
127 return true;
128 }
129 double rate = (input[0] - m_output) / timeStep;
130
131 bool reachLimit = false;
132 if (rate > m_upLimit) {
133 rate = m_upLimit;
134 reachLimit = true;
135 }
136 else if (rate < m_lowLimit) {
137 rate = m_lowLimit;
138 reachLimit = true;
139 }
140
141 if (reachLimit)
142 m_output += rate * timeStep;
143 else
144 m_output = input[0];
145 return true;
146}

◆ UpdatePoints()

void RateLimiter::UpdatePoints ( )
virtual

Definition at line 103 of file RateLimiter.cpp.

104{
105 if (m_angle == 0.0) {
106 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-18, 0));
107 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(18, 0));
108 }
109 else if (m_angle == 90.0) {
110 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -18));
111 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, 18));
112 }
113 else if (m_angle == 180.0) {
114 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(18, 0));
115 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-18, 0));
116 }
117 else if (m_angle == 270.0) {
118 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, 18));
119 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, -18));
120 }
121}

Member Data Documentation

◆ m_lowLimit

double RateLimiter::m_lowLimit = -5.0
protected

Definition at line 76 of file RateLimiter.h.

◆ m_upLimit

double RateLimiter::m_upLimit = 5.0
protected

Definition at line 75 of file RateLimiter.h.


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