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

Calculates the time response by a frequency domain transfer function. More...

#include <TransferFunction.h>

Inheritance diagram for TransferFunction:
Collaboration diagram for TransferFunction:

Classes

struct  SpaceState
 

Public Member Functions

 TransferFunction (int id)
 
virtual void DrawDC (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)
 Show element data form.
 
virtual void Rotate (bool clockwise=true)
 Rotate the element.
 
virtual std::vector< double > GetNumerator () const
 
virtual std::vector< double > GetDenominator () const
 
virtual void SetNumerator (std::vector< double > numerator)
 
virtual void SetDenominator (std::vector< double > denominator)
 
virtual void UpdateTFText ()
 
virtual bool UpdateText ()
 Update the OpenGL text in the element (if present).
 
virtual SpaceState GetSpaceState ()
 
virtual void CalculateSpaceState (int maxIteration=100, double error=1e-3)
 Convert the transfer function to space state on controllable canonical form (CCF).
 
virtual bool Solve (double *input, double timeStep)
 Calculates the time response by the space state form of transfer function.
 
virtual void GetTFString (wxString &numerator, wxString &denominator)
 
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.
 
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 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 (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 Member Functions

virtual void SetText (wxString numerator, wxString denominator)
 
virtual wxString GetSuperscriptNumber (int number)
 
- Protected Member Functions inherited from ControlElement
void SaveControlNodes (rapidxml::xml_document<> &doc, rapidxml::xml_node<> *elementNode)
 
bool OpenControlNodes (rapidxml::xml_node<> *elementNode)
 

Protected Attributes

wchar_t m_supNumber [10]
 
GCTextm_gcTextNum = nullptr
 
GCTextm_gcTextDen = nullptr
 
int m_fontSize = 10
 
std::vector< double > m_numerator
 
std::vector< double > m_denominator
 
SpaceState m_ss
 
std::vector< double > m_x
 
std::vector< double > m_dx
 
double m_error = 1e-3
 
int m_maxIteration = 100
 
- 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
 
wxColour m_selectionColour
 

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.
 

Detailed Description

Calculates the time response by a frequency domain transfer function.

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

Definition at line 36 of file TransferFunction.h.

Constructor & Destructor Documentation

◆ TransferFunction()

TransferFunction::TransferFunction ( int  id)

Definition at line 21 of file TransferFunction.cpp.

21 : ControlElement(id)
22{
23 // Superscript unicode numbers
24 m_supNumber[0] = L'\u2070';
25 m_supNumber[1] = L'\u00B9';
26 m_supNumber[2] = L'\u00B2';
27 m_supNumber[3] = L'\u00B3';
28 m_supNumber[4] = L'\u2074';
29 m_supNumber[5] = L'\u2075';
30 m_supNumber[6] = L'\u2076';
31 m_supNumber[7] = L'\u2077';
32 m_supNumber[8] = L'\u2078';
33 m_supNumber[9] = L'\u2079';
34
35 m_numerator.clear();
36 m_numerator.push_back(1);
37 m_denominator.clear();
38 m_denominator.push_back(1);
39 m_denominator.push_back(1);
40 UpdateTFText();
41
42 Node* node1 = new Node(m_position + wxPoint2DDouble(-m_width / 2, 0), Node::NodeType::NODE_IN, m_borderSize);
43 node1->StartMove(m_position);
44 Node* node2 = new Node(m_position + wxPoint2DDouble(m_width / 2, 0), Node::NodeType::NODE_OUT, m_borderSize);
45 node2->SetAngle(180.0);
46 node2->StartMove(m_position);
47 m_nodeList.push_back(node1);
48 m_nodeList.push_back(node2);
49}
Node of a control element. This class manages the user interaction with the connection and control el...

◆ ~TransferFunction()

TransferFunction::~TransferFunction ( )

Definition at line 51 of file TransferFunction.cpp.

52{
53 //if (m_glTextDen) delete m_glTextDen;
54 if (m_gcTextDen) delete m_gcTextDen;
55 if (m_gcTextNum) delete m_gcTextNum;
56 //if (m_glTextNum) delete m_glTextNum;
57 for (auto& node : m_nodeList) if (node) delete node;
58 m_nodeList.clear();
59}

Member Function Documentation

◆ CalculateSpaceState()

void TransferFunction::CalculateSpaceState ( int  maxIteration = 100,
double  error = 1e-3 
)
virtual

Convert the transfer function to space state on controllable canonical form (CCF).

Parameters
maxIterationMax number of solution iteration.
errorTolerance for calculation.

Definition at line 305 of file TransferFunction.cpp.

306{
307 m_maxIteration = maxIteration;
308 m_error = error;
309
310 int order = static_cast<int>(m_denominator.size());
311 std::vector<double> denominator = m_denominator;
312 std::vector<double> numerator;
313
314 //[Ref.] http://lpsa.swarthmore.edu/Representations/SysRepTransformations/TF2SS.html
315 int k = order;
316 for (int i = 0; i < order; i++) {
317 int numIndex = i - (order - static_cast<int>(m_numerator.size()));
318 if (numIndex < 0)
319 numerator.push_back(0.0);
320 else
321 numerator.push_back(m_numerator[numIndex]);
322 k--;
323 }
324
325 SpaceState ss;
326 for (int i = 0; i < (order - 1); i++) {
327 std::vector<double> lineA;
328 for (int j = 0; j < (order - 1); j++) {
329 if (j == i + 1)
330 lineA.push_back(1.0);
331 else
332 lineA.push_back(0.0);
333 }
334 ss.A.push_back(lineA);
335 ss.B.push_back(0.0);
336 ss.C.push_back(0.0);
337 }
338 for (int i = 0; i < order - 1; i++) {
339 ss.A[order - 2][i] = -(denominator[order - 1 - i] / denominator[0]);
340 ss.C[i] = numerator[order - 1 - i] / denominator[0] -
341 (denominator[order - 1 - i] / denominator[0]) * (numerator[0] / denominator[0]);
342 }
343 ss.B[order - 2] = 1.0;
344 ss.D = numerator[0] / denominator[0];
345
346 m_ss = ss;
347
348 // Reset state
349 m_x.clear();
350 m_dx.clear();
351
352 for (unsigned int i = 0; i < m_denominator.size(); ++i) {
353 m_x.push_back(0.0);
354 m_dx.push_back(0.0);
355 }
356}

◆ Contains()

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

Checks if the element contains a position.

Parameters
positionPosition to be checked.

Implements Element.

Definition at line 51 of file TransferFunction.h.

51{ return m_rect.Contains(position); }

◆ DrawDC()

void TransferFunction::DrawDC ( wxPoint2DDouble  translation,
double  scale,
wxGraphicsContext *  gc 
) const
virtual

Draw the element using GDI+.

Parameters
translationTranslation of the system.
scaleScale of the system.
gcGraphics context

Reimplemented from Element.

Definition at line 86 of file TransferFunction.cpp.

87{
88 if (m_selected) {
89 gc->SetPen(*wxTRANSPARENT_PEN);
90 gc->SetBrush(wxBrush(m_selectionColour));
91 double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
92 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);
93 }
94 gc->SetPen(*wxBLACK_PEN);
95 gc->SetBrush(*wxWHITE_BRUSH);
96 gc->DrawRectangle(m_position.m_x - m_width / 2, m_position.m_y - m_height / 2, m_width, m_height);
97
98 wxPoint2DDouble linePts[2];
99 linePts[0] = wxPoint2DDouble(m_position.m_x - m_width / 2 + 5 + m_borderSize, m_position.m_y);
100 linePts[1] = wxPoint2DDouble(m_position.m_x + m_width / 2 - 5 - m_borderSize, m_position.m_y);
101 gc->StrokeLines(2, linePts);
102
103 gc->SetPen(*wxTRANSPARENT_PEN);
104 gc->SetBrush(*wxBLACK_BRUSH);
105 DrawDCNodes(gc);
106
107 //glColor4d(0.0, 0.0, 0.0, 1.0);
108 m_gcTextNum->Draw(m_position + wxPoint2DDouble(-m_gcTextNum->GetWidth() / 2, -m_height / 4 - m_gcTextNum->GetHeight() / 2), gc);
109 m_gcTextDen->Draw(m_position + wxPoint2DDouble(-m_gcTextDen->GetWidth() / 2, m_height / 4 - m_gcTextDen->GetHeight() / 2), gc);
110}
virtual void Draw(wxPoint2DDouble position, wxGraphicsContext *gc, double angle=0.0, wxColour colour= *wxBLACK) const
Draw the text in wxGraphicsContext.
Definition GCText.cpp:35
Here is the call graph for this function:

◆ GetCopy()

Element * TransferFunction::GetCopy ( )
virtual

Get a the element copy.

Returns
Copy of the element.

Reimplemented from Element.

Definition at line 420 of file TransferFunction.cpp.

421{
422 TransferFunction* copy = new TransferFunction(m_elementID);
423 *copy = *this;
424 copy->m_gcTextNum = m_gcTextNum->GetCopy();
425 copy->m_gcTextDen = m_gcTextDen->GetCopy();
426 return copy;
427}
virtual GCText * GetCopy()
Get a deep text copy.
Definition GCText.cpp:161
Calculates the time response by a frequency domain transfer function.
Here is the call graph for this function:

◆ GetDenominator()

virtual std::vector< double > TransferFunction::GetDenominator ( ) const
inlinevirtual

Definition at line 57 of file TransferFunction.h.

57{ return m_denominator; }

◆ GetNumerator()

virtual std::vector< double > TransferFunction::GetNumerator ( ) const
inlinevirtual

Definition at line 56 of file TransferFunction.h.

56{ return m_numerator; }

◆ GetSpaceState()

virtual SpaceState TransferFunction::GetSpaceState ( )
inlinevirtual

Definition at line 62 of file TransferFunction.h.

62{ return m_ss; }

◆ GetSuperscriptNumber()

wxString TransferFunction::GetSuperscriptNumber ( int  number)
protectedvirtual

Definition at line 132 of file TransferFunction.cpp.

133{
134 wxString strNumber = wxString::Format("%d", number);
135 wxString superscriptStr = "";
136 for (int i = 0; i < (int)strNumber.length(); ++i) {
137 wxString digitStr = strNumber[i];
138 long digit = 0;
139 digitStr.ToLong(&digit);
140 superscriptStr += wxString(m_supNumber[digit]);
141 }
142 return superscriptStr;
143}

◆ GetTFString()

void TransferFunction::GetTFString ( wxString &  numerator,
wxString &  denominator 
)
virtual

Definition at line 145 of file TransferFunction.cpp.

146{
147 numerator = "";
148 denominator = "";
149 int index = static_cast<int>(m_numerator.size()) - 1;
150 for (auto it = m_numerator.begin(), itEnd = m_numerator.end(); it != itEnd; ++it) {
151 double value = *it;
152 if (value != 0.0) {
153 wxString signal;
154 if (index == static_cast<int>(m_numerator.size()) - 1) {
155 if (value >= 0.0)
156 signal += "";
157 else
158 signal += "-";
159 }
160 else {
161 if (value >= 0.0)
162 signal += "+ ";
163 else
164 signal += "- ";
165 }
166
167 if (index == 0) {
168 numerator += signal + StringFromDouble(std::abs(value), 0);
169 break;
170 }
171 else if (index == 1) {
172 if (value == 1.0) {
173 numerator += signal + "s";
174 }
175 else {
176 numerator += signal + StringFromDouble(std::abs(value), 0) + "s";
177 }
178 }
179 else {
180 if (value == 1.0) {
181 numerator += signal + "s" + GetSuperscriptNumber(index);
182 }
183 else {
184 numerator += signal + StringFromDouble(std::abs(value), 0) + "s" + GetSuperscriptNumber(index);
185 }
186 }
187 numerator += " ";
188 }
189 --index;
190 }
191
192 index = static_cast<int>(m_denominator.size()) - 1;
193 for (auto it = m_denominator.begin(), itEnd = m_denominator.end(); it != itEnd; ++it) {
194 double value = *it;
195 if (value != 0.0) {
196 wxString signal;
197 if (index == static_cast<int>(m_denominator.size()) - 1) {
198 if (value >= 0.0)
199 signal += "";
200 else
201 signal += "-";
202 }
203 else {
204 if (value >= 0.0)
205 signal += "+ ";
206 else
207 signal += "- ";
208 }
209
210 if (index == 0) {
211 denominator += signal + StringFromDouble(std::abs(value), 0);
212 break;
213 }
214 else if (index == 1) {
215 if (value == 1.0) {
216 denominator += signal + "s";
217 }
218 else {
219 denominator += signal + StringFromDouble(std::abs(value), 0) + "s";
220 }
221 }
222 else {
223 if (value == 1.0) {
224 denominator += signal + "s" + GetSuperscriptNumber(index);
225 }
226 else {
227 denominator += signal + StringFromDouble(std::abs(value), 0) + "s" + GetSuperscriptNumber(index);
228 }
229 }
230 denominator += " ";
231 }
232 --index;
233 }
234}
static wxString StringFromDouble(double value, int minDecimal=1, int maxDecimals=13)
Convert a double value to string.
Definition Element.cpp:533

◆ Intersects()

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

Check if the element's rect intersects other rect.

Parameters
rectRect to check intersection.

Implements Element.

Definition at line 52 of file TransferFunction.h.

52{ return m_rect.Intersects(rect); }

◆ OpenElement()

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

Reimplemented from Element.

Definition at line 461 of file TransferFunction.cpp.

462{
463 if (!OpenCADProperties(elementNode)) return false;
464 if (!OpenControlNodes(elementNode)) return false;
465
466 // Element properties
467 std::vector<double> numerator, denominator;
468 m_numerator.clear();
469 m_denominator.clear();
470 auto numeratorNode = elementNode->first_node("Numerator");
471 auto nValue = numeratorNode->first_node("Value");
472 while (nValue) {
473 double value = 0.0;
474 wxString(nValue->value()).ToCDouble(&value);
475 m_numerator.push_back(value);
476 nValue = nValue->next_sibling("Value");
477 }
478 auto denominatorNode = elementNode->first_node("Denominator");
479 auto dValue = denominatorNode->first_node("Value");
480 while (dValue) {
481 double value = 0.0;
482 wxString(dValue->value()).ToCDouble(&value);
483 m_denominator.push_back(value);
484 dValue = dValue->next_sibling("Value");
485 }
486 StartMove(m_position);
487 UpdateTFText();
488
489 return true;
490}
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.

◆ Rotate()

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

Rotate the element.

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

Reimplemented from Element.

Definition at line 271 of file TransferFunction.cpp.

272{
273 if (clockwise)
274 m_angle += 90.0;
275 else
276 m_angle -= 90.0;
277 if (m_angle >= 360.0)
278 m_angle = 0.0;
279 else if (m_angle < 0)
280 m_angle = 270.0;
281
282 if (m_angle == 0.0) {
283 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
284 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
285 }
286 else if (m_angle == 90.0) {
287 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
288 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
289 }
290 else if (m_angle == 180.0) {
291 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
292 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
293 }
294 else if (m_angle == 270.0) {
295 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
296 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
297 }
298
299 for (auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
300 Node* node = *it;
301 node->Rotate(clockwise);
302 }
303}

◆ SaveElement()

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

Reimplemented from Element.

Definition at line 437 of file TransferFunction.cpp.

439{
440 auto elementNode = XMLParser::AppendNode(doc, elementListNode, "TransferFunction");
441 XMLParser::SetNodeAttribute(doc, elementNode, "ID", m_elementID);
442
443 SaveCADProperties(doc, elementNode);
444 SaveControlNodes(doc, elementNode);
445
446 // Element properties
447 auto numeratorNode = XMLParser::AppendNode(doc, elementNode, "Numerator");
448 for (unsigned int i = 0; i < m_numerator.size(); ++i) {
449 auto value = XMLParser::AppendNode(doc, numeratorNode, "Value");
450 XMLParser::SetNodeValue(doc, value, m_numerator[i]);
451 }
452 auto denominatorNode = XMLParser::AppendNode(doc, elementNode, "Denominator");
453 for (unsigned int i = 0; i < m_denominator.size(); ++i) {
454 auto value = XMLParser::AppendNode(doc, denominatorNode, "Value");
455 XMLParser::SetNodeValue(doc, value, m_denominator[i]);
456 }
457
458 return elementNode;
459}

◆ SetDenominator()

virtual void TransferFunction::SetDenominator ( std::vector< double >  denominator)
inlinevirtual

Definition at line 59 of file TransferFunction.h.

59{ m_denominator = denominator; }

◆ SetNumerator()

virtual void TransferFunction::SetNumerator ( std::vector< double >  numerator)
inlinevirtual

Definition at line 58 of file TransferFunction.h.

58{ m_numerator = numerator; }

◆ SetText()

void TransferFunction::SetText ( wxString  numerator,
wxString  denominator 
)
protectedvirtual

Definition at line 112 of file TransferFunction.cpp.

113{
114 if (m_gcTextNum)
115 m_gcTextNum->SetText(numerator);
116 else
117 m_gcTextNum = new GCText(numerator);
118
119 if (m_gcTextDen)
120 m_gcTextDen->SetText(denominator);
121 else
122 m_gcTextDen = new GCText(denominator);
123
124 double nWidth = static_cast<double>(m_gcTextNum->GetWidth()) + 5 + m_borderSize;
125 double dWidth = static_cast<double>(m_gcTextDen->GetWidth()) + 5 + m_borderSize;
126
127 m_width = nWidth > dWidth ? nWidth : dWidth;
128 m_height = static_cast<double>(m_gcTextNum->GetHeight()) + static_cast<double>(m_gcTextDen->GetHeight()) + 2 * m_borderSize;
129 SetPosition(m_position); // Update rect properly.
130}
void SetPosition(const wxPoint2DDouble position)
Set the element position and update the rectangle.
Definition Element.cpp:27
Class to draw text on Graphics Context using wxWidgets.
Definition GCText.h:32
virtual void SetText(wxString text)
Set correctly a new text string.
Definition GCText.cpp:68

◆ ShowForm()

bool TransferFunction::ShowForm ( wxWindow *  parent,
Element element 
)
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 261 of file TransferFunction.cpp.

262{
263 TransferFunctionForm tfForm(parent, this);
264 tfForm.CenterOnParent();
265 if (tfForm.ShowModal() == wxID_OK) {
266 return true;
267 }
268 return false;
269}
Form to edit the transfer function control data.

◆ Solve()

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

Calculates the time response by the space state form of transfer function.

Uses the implicit trapezoidal rule to solve:

\( y_{n+1}=y_n+\frac{1}{2}h(y'_n+y'_{n+1}) \)
Parameters
inputInput value.
timeStepTime step.
Returns
true if the calculation converges, false otherwise.

Reimplemented from ControlElement.

Definition at line 358 of file TransferFunction.cpp.

359{
360 if (!input) {
361 m_output = 0.0;
362 return true;
363 }
364
365 int order = static_cast<int>(m_ss.A.size());
366
367 std::vector<double> x;
368 std::vector<double> oldx;
369 std::vector<double> dx;
370 std::vector<double> olddx;
371 for (int i = 0; i < order; i++) {
372 x.push_back(m_x[i]);
373 oldx.push_back(m_x[i]);
374
375 dx.push_back(m_dx[i]);
376 olddx.push_back(m_dx[i]);
377 }
378
379 bool exit = false;
380 int iter = 0;
381 while (!exit) {
382 double xError = 0.0;
383 double dxError = 0.0;
384 for (int i = 0; i < order; i++) {
385 // Trapezoidal method
386 x[i] = m_x[i] + 0.5 * timeStep * (m_dx[i] + dx[i]);
387
388 if (std::abs(x[i] - oldx[i]) > xError) xError = std::abs(x[i] - oldx[i]);
389
390 oldx[i] = x[i];
391 }
392 for (int i = 0; i < order; i++) {
393 // x' = Ax + Bu
394 dx[i] = 0.0;
395 for (int j = 0; j < order; j++) dx[i] += m_ss.A[i][j] * x[j];
396 dx[i] += m_ss.B[i] * input[0];
397
398 if (std::abs(dx[i] - olddx[i]) > dxError) dxError = std::abs(dx[i] - olddx[i]);
399
400 olddx[i] = dx[i];
401 }
402 if (std::max(xError, dxError) < m_error) exit = true;
403
404 iter++;
405 if (iter >= m_maxIteration) return false;
406 }
407
408 m_output = 0.0;
409 for (int i = 0; i < order; i++) {
410 m_output += m_ss.C[i] * x[i];
411 m_x[i] = x[i];
412 m_dx[i] = dx[i];
413 }
414
415 m_output += m_ss.D * input[0];
416
417 return true;
418}

◆ UpdateText()

bool TransferFunction::UpdateText ( )
virtual

Update the OpenGL text in the element (if present).

Returns
true if OpenGLText is ok, false otherwise.

Reimplemented from ControlElement.

Definition at line 429 of file TransferFunction.cpp.

430{
431 UpdateTFText();
432 //if (!m_glTextDen->IsTextureOK()) return false;
433 //if (!m_glTextNum->IsTextureOK()) return false;
434 return true;
435}

◆ UpdateTFText()

void TransferFunction::UpdateTFText ( )
virtual

Definition at line 236 of file TransferFunction.cpp.

237{
238 wxString num, den;
239 GetTFString(num, den);
240 SetText(num, den);
241 if (m_nodeList.size() == 2) {
242 if (m_angle == 0.0) {
243 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
244 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
245 }
246 else if (m_angle == 90.0) {
247 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
248 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
249 }
250 else if (m_angle == 180.0) {
251 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
252 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
253 }
254 else if (m_angle == 270.0) {
255 m_nodeList[0]->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
256 m_nodeList[1]->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
257 }
258 }
259}

Member Data Documentation

◆ m_denominator

std::vector<double> TransferFunction::m_denominator
protected

Definition at line 99 of file TransferFunction.h.

◆ m_dx

std::vector<double> TransferFunction::m_dx
protected

Definition at line 103 of file TransferFunction.h.

◆ m_error

double TransferFunction::m_error = 1e-3
protected

Definition at line 104 of file TransferFunction.h.

◆ m_fontSize

int TransferFunction::m_fontSize = 10
protected

Definition at line 96 of file TransferFunction.h.

◆ m_gcTextDen

GCText* TransferFunction::m_gcTextDen = nullptr
protected

Definition at line 95 of file TransferFunction.h.

◆ m_gcTextNum

GCText* TransferFunction::m_gcTextNum = nullptr
protected

Definition at line 94 of file TransferFunction.h.

◆ m_maxIteration

int TransferFunction::m_maxIteration = 100
protected

Definition at line 105 of file TransferFunction.h.

◆ m_numerator

std::vector<double> TransferFunction::m_numerator
protected

Definition at line 98 of file TransferFunction.h.

◆ m_ss

SpaceState TransferFunction::m_ss
protected

Definition at line 100 of file TransferFunction.h.

◆ m_supNumber

wchar_t TransferFunction::m_supNumber[10]
protected

Definition at line 90 of file TransferFunction.h.

◆ m_x

std::vector<double> TransferFunction::m_x
protected

Definition at line 102 of file TransferFunction.h.


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