19#include "../../forms/ReactiveShuntElementForm.h"
21Inductor::Inductor() :
Shunt()
23 m_elementType = TYPE_INDUCTOR;
26Inductor::Inductor(wxString name) :
Shunt()
28 m_elementType = TYPE_INDUCTOR;
29 m_electricalData.name = name;
32Inductor::~Inductor() {}
37 m_parentList.push_back(parent);
39 wxPoint2DDouble parentPt =
44 m_position = parentPt + wxPoint2DDouble(0.0, 100.0);
47 m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, m_height);
49 m_pointList.push_back(parentPt);
50 m_pointList.push_back(
GetSwitchPoint(parent, parentPt, m_position));
51 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0 - 10.0));
52 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0));
56 wxRect2DDouble genRect(0, 0, 0, 0);
57 m_switchRect.push_back(genRect);
124void Inductor::DrawDC(wxPoint2DDouble translation,
double scale, wxGraphicsContext* gc)
const
126 wxColour elementColour;
129 elementColour = m_dynamicEventColour;
131 elementColour = m_onlineElementColour;
134 elementColour = m_offlineElementColour;
138 gc->SetPen(wxPen(wxColour(m_selectionColour), 2 + m_borderSize * 2.0));
139 gc->SetBrush(*wxTRANSPARENT_BRUSH);
141 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
146 gc->Translate(m_position.m_x, m_position.m_y);
147 gc->Rotate(wxDegToRad(m_angle));
148 gc->Translate(-m_position.m_x, -m_position.m_y);
150 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), 10, 45, 270, 30, gc);
151 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0), 10, 45, 315, 30, gc);
152 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0), 10, 90, 315, 30, gc);
154 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0), gc);
159 gc->SetPen(*wxTRANSPARENT_PEN);
160 gc->SetBrush(wxBrush(wxColour(m_selectionColour)));
161 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, gc);
164 gc->SetPen(*wxTRANSPARENT_PEN);
165 gc->SetBrush(wxBrush(wxColour(elementColour)));
168 gc->SetPen(wxPen(wxColour(elementColour), 2));
169 gc->SetBrush(*wxTRANSPARENT_BRUSH);
170 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
177 gc->Translate(m_position.m_x, m_position.m_y);
178 gc->Rotate(wxDegToRad(m_angle));
179 gc->Translate(-m_position.m_x, -m_position.m_y);
181 gc->SetPen(wxPen(wxColour(elementColour), 2));
182 gc->SetBrush(*wxTRANSPARENT_BRUSH);
183 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), 10, 45, 270, 10, gc);
184 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0), 10, 45, 315, 10, gc);
185 DrawDCArc(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0), 10, 90, 315, 10, gc);
187 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0), gc);
195 wxColour elementColour;
198 elementColour = m_dynamicEventColour;
200 elementColour = m_onlineElementColour;
203 elementColour = m_offlineElementColour;
205 std::vector<wxPoint> pointListInt;
206 for (
auto& pt : m_pointList) {
207 pointListInt.emplace_back(
static_cast<int>(pt.m_x),
static_cast<int>(pt.m_y));
213 p = m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0);
214 arcPts[0] = RotateAround(p, m_position, m_angle);
215 p = m_position + wxPoint2DDouble(0, -m_height / 2.0 + 25.0);
216 arcPts[1] = RotateAround(p, m_position, m_angle);
217 p = m_position + wxPoint2DDouble(0, -m_height / 2.0 + 40.0);
218 arcPts[2] = RotateAround(p, m_position, m_angle);
221 dc.SetPen(wxPen(wxColour(m_selectionColour), 2 + m_borderSize * 2.0));
222 dc.SetBrush(*wxTRANSPARENT_BRUSH);
224 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
226 DrawDCArc(arcPts[0], 10, 90 - m_angle, 315 - m_angle, dc);
227 DrawDCArc(arcPts[1], 10, 45 - m_angle, 315 - m_angle, dc);
228 DrawDCArc(arcPts[2], 10, 45 - m_angle, 270 - m_angle, dc);
230 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0), dc);
233 dc.SetPen(*wxTRANSPARENT_PEN);
234 dc.SetBrush(wxBrush(wxColour(m_selectionColour)));
235 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, dc);
238 dc.SetPen(*wxTRANSPARENT_PEN);
239 dc.SetBrush(wxBrush(wxColour(elementColour)));
242 dc.SetPen(wxPen(wxColour(elementColour), 2));
243 dc.SetBrush(*wxTRANSPARENT_BRUSH);
244 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
248 dc.SetPen(wxPen(wxColour(elementColour), 2));
249 dc.SetBrush(*wxTRANSPARENT_BRUSH);
250 DrawDCArc(arcPts[0], 10, 90 - m_angle, 315 - m_angle, dc);
251 DrawDCArc(arcPts[1], 10, 45 - m_angle, 315 - m_angle, dc);
252 DrawDCArc(arcPts[2], 10, 45 - m_angle, 270 - m_angle, dc);
254 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 50.0), dc);
260 double rotAngle = m_rotationAngle;
261 if (!clockwise) rotAngle = -m_rotationAngle;
264 if (m_angle >= 360 || m_angle <= -360) m_angle = 0.0;
267 UpdateSwitchesPosition();
274 wxMenu* textMenu =
new wxMenu();
276 textMenu->Append(ID_TXT_NAME, _(
"Name"));
277 textMenu->Append(ID_TXT_REACTIVE_POWER, _(
"Reactive power"));
278 textMenu->SetClientData(menu.GetClientData());
279 menu.AppendSubMenu(textMenu, _(
"Add text"));
288 return m_rect.Contains(ptR);
295 inductorForm.SetTitle(_(
"Inductor"));
296 inductorForm.CenterOnParent();
297 if (inductorForm.ShowModal() == wxID_OK) {
306 switch (data.reactivePowerUnit) {
308 data.reactivePower = data.reactivePower / systemPowerBase;
312 data.reactivePower = (data.reactivePower * 1e3) / systemPowerBase;
316 data.reactivePower = (data.reactivePower * 1e6) / systemPowerBase;
335 wxString tipText = m_electricalData.name;
338 double reactivePower = m_electricalData.reactivePower;
342 std::complex<double> v =
static_cast<Bus*
>(m_parentList[0])->GetElectricalData().voltage;
343 reactivePower *= std::pow(std::abs(v), 2);
346 tipText += _(
"\nQ = ") + wxString::FromDouble(reactivePower, 5);
347 switch (m_electricalData.reactivePowerUnit) {
349 tipText += _(
" p.u.");
352 tipText += _(
" var");
355 tipText += _(
" kvar");
358 tipText += _(
" Mvar");
367rapidxml::xml_node<>* Inductor::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
369 auto elementNode = XMLParser::AppendNode(doc, elementListNode,
"Inductor");
370 XMLParser::SetNodeAttribute(doc, elementNode,
"ID", m_elementID);
372 SaveCADProperties(doc, elementNode);
374 auto electricalProp = XMLParser::AppendNode(doc, elementNode,
"ElectricalProperties");
375 auto isOnline = XMLParser::AppendNode(doc, electricalProp,
"IsOnline");
376 XMLParser::SetNodeValue(doc, isOnline, m_online);
377 auto name = XMLParser::AppendNode(doc, electricalProp,
"Name");
378 XMLParser::SetNodeValue(doc, name, m_electricalData.name);
379 auto reactivePower = XMLParser::AppendNode(doc, electricalProp,
"ReactivePower");
380 XMLParser::SetNodeValue(doc, reactivePower, m_electricalData.reactivePower);
381 XMLParser::SetNodeAttribute(doc, reactivePower,
"UnitID",
static_cast<int>(m_electricalData.reactivePowerUnit));
383 SaveSwitchingData(doc, electricalProp);
388bool Inductor::OpenElement(rapidxml::xml_node<>* elementNode, std::vector<Element*> parentList)
390 if (!OpenCADProperties(elementNode, parentList))
return false;
392 auto electricalProp = elementNode->first_node(
"ElectricalProperties");
393 if (!electricalProp)
return false;
395 SetOnline(XMLParser::GetNodeValueInt(electricalProp,
"IsOnline"));
396 m_electricalData.name = electricalProp->first_node(
"Name")->value();
397 m_electricalData.reactivePower = XMLParser::GetNodeValueDouble(electricalProp,
"ReactivePower");
398 m_electricalData.reactivePowerUnit =
399 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"ReactivePower",
"UnitID"));
401 if (!OpenSwitchingData(electricalProp))
return false;
ElectricalUnit
Electrical units.
Node for power elements. All others power elements are connected through this.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
virtual bool RotatedRectanglesIntersects(wxRect2DDouble rect1, wxRect2DDouble rect2, double angle1, double angle2) const
Check if two roteted rectangles intersect.
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
wxPoint2DDouble GetPosition() const
Get the element position.
double GetAngle() const
Get the element angle.
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
virtual void AddChild(Element *child)
Add a child to the child list.
bool SetOnline(bool online=true)
Set if the element is online or offline.
virtual void DrawDCCircle(wxPoint2DDouble position, double radius, int numSegments, wxGraphicsContext *gc) const
Draw a circle using device context.
Inductor shunt power element.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
virtual Element * GetCopy()
Get a the element copy.
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,...
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
virtual bool ShowForm(wxWindow *parent, Element *element)
Show element data form.
virtual wxString GetTipText() const
Get the tip text.
virtual bool Contains(wxPoint2DDouble position) const
Checks if the element contains a position.
virtual void DrawDC(wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
virtual void SetDynamicEvent(bool dynEvent=true)
Set if the power element have dynamic event.
virtual void DrawDCSwitches(wxGraphicsContext *gc) const
Draw switch.
virtual void UpdateSwitches()
Update the switch position.
virtual wxPoint2DDouble GetSwitchPoint(Element *parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const
Get the correct switch position.
Abstract class for shunt power elements.
std::vector< double > swTime