19#include "../../forms/ReactiveShuntElementForm.h"
21Capacitor::Capacitor() :
Shunt() {
22 m_elementType = TYPE_CAPACITOR;
25Capacitor::Capacitor(wxString name) :
Shunt() {
26 m_elementType = TYPE_CAPACITOR;
27 m_electricalData.name = name;
30Capacitor::~Capacitor() {}
35 m_parentList.push_back(parent);
37 wxPoint2DDouble parentPt =
42 m_position = parentPt + wxPoint2DDouble(0.0, 100.0);
45 m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, m_height);
47 m_pointList.push_back(parentPt);
48 m_pointList.push_back(
GetSwitchPoint(parent, parentPt, m_position));
49 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0 - 10.0));
50 m_pointList.push_back(m_position + wxPoint2DDouble(0.0, -m_height / 2.0));
54 wxRect2DDouble genRect(0, 0, 0, 0);
55 m_switchRect.push_back(genRect);
126 wxColour elementColour;
131 elementColour = guiColour->enabled;
134 elementColour = guiColour->disable;
137 std::vector<wxPoint2DDouble> capPts;
138 capPts.push_back(wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0));
139 capPts.push_back(wxPoint2DDouble(m_position.m_x + m_width / 2.0, m_position.m_y - m_height / 2.0));
140 capPts.push_back(wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0 + 10.0));
141 capPts.push_back(wxPoint2DDouble(m_position.m_x + m_width / 2.0, m_position.m_y - m_height / 2.0 + 10.0));
144 gc->SetPen(wxPen(guiColour->selection, 2 + m_borderSize * 2.0));
145 gc->SetBrush(*wxTRANSPARENT_BRUSH);
147 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
152 gc->Translate(m_position.m_x, m_position.m_y);
153 gc->Rotate(wxDegToRad(m_angle));
154 gc->Translate(-m_position.m_x, -m_position.m_y);
156 gc->StrokeLines(2, &capPts[0]);
157 gc->StrokeLines(2, &capPts[2]);
159 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), gc);
164 gc->SetPen(*wxTRANSPARENT_PEN);
165 gc->SetBrush(wxBrush(guiColour->selection));
166 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, gc);
170 gc->SetPen(*wxTRANSPARENT_PEN);
171 gc->SetBrush(wxBrush(elementColour));
174 gc->SetPen(wxPen(elementColour, 2));
175 gc->SetBrush(*wxTRANSPARENT_BRUSH);
176 gc->StrokeLines(m_pointList.size(), &m_pointList[0]);
183 gc->Translate(m_position.m_x, m_position.m_y);
184 gc->Rotate(wxDegToRad(m_angle));
185 gc->Translate(-m_position.m_x, -m_position.m_y);
187 gc->SetPen(wxPen(elementColour, 2));
188 gc->SetBrush(*wxTRANSPARENT_BRUSH);
189 gc->StrokeLines(2, &capPts[0]);
190 gc->StrokeLines(2, &capPts[2]);
192 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), gc);
197 DrawStabilityEventGC(gc, translation, scale, guiColour);
204 wxColour elementColour;
207 elementColour = guiColour->eventElement;
209 elementColour = guiColour->enabled;
212 elementColour = guiColour->disable;
217 p = wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0);
218 capPts[0] = RotateAround(p, m_position, m_angle);
220 p = wxPoint2DDouble(m_position.m_x + m_width / 2.0, m_position.m_y - m_height / 2.0);
221 capPts[1] = RotateAround(p, m_position, m_angle);
223 p = wxPoint2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0 + 10.0);
224 capPts[2] = RotateAround(p, m_position, m_angle);
225 p = wxPoint2DDouble(m_position.m_x + m_width / 2.0, m_position.m_y - m_height / 2.0 + 10.0);
226 capPts[3] = RotateAround(p, m_position, m_angle);
228 std::vector<wxPoint> pointListInt;
229 for (
auto& pt : m_pointList) {
230 pointListInt.emplace_back(
static_cast<int>(pt.m_x),
static_cast<int>(pt.m_y));
234 dc.SetPen(wxPen(guiColour->selection, 2 + m_borderSize * 2.0));
235 dc.SetBrush(*wxTRANSPARENT_BRUSH);
237 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
240 dc.DrawLines(2, &capPts[0]);
241 dc.DrawLines(2, &capPts[2]);
243 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), dc);
246 dc.SetPen(*wxTRANSPARENT_PEN);
247 dc.SetBrush(wxBrush(guiColour->selection));
248 DrawDCCircle(m_pointList[0], 5.0 + m_borderSize / scale, dc);
252 dc.SetPen(*wxTRANSPARENT_PEN);
253 dc.SetBrush(wxBrush(elementColour));
256 dc.SetPen(wxPen(elementColour, 2));
257 dc.SetBrush(*wxTRANSPARENT_BRUSH);
258 dc.DrawLines(pointListInt.size(), &pointListInt[0]);
262 dc.SetPen(wxPen(elementColour, 2));
263 dc.SetBrush(*wxTRANSPARENT_BRUSH);
264 dc.DrawLines(2, &capPts[0]);
265 dc.DrawLines(2, &capPts[2]);
267 DrawDCGround(m_position + wxPoint2DDouble(0, -m_height / 2.0 + 10.0), dc);
273 double rotAngle = m_rotationAngle;
274 if (!clockwise) rotAngle = -m_rotationAngle;
277 if (m_angle >= 360 || m_angle <= -360) m_angle = 0.0;
280 UpdateSwitchesPosition();
287 wxMenu* textMenu =
new wxMenu();
289 textMenu->Append(ID_TXT_NAME, _(
"Name"));
290 textMenu->Append(ID_TXT_REACTIVE_POWER, _(
"Reactive power"));
291 textMenu->SetClientData(menu.GetClientData());
292 menu.AppendSubMenu(textMenu, _(
"Add text"));
301 return m_rect.Contains(ptR);
312 capacitorForm.SetTitle(_(
"Capacitor"));
313 capacitorForm.CenterOnParent();
314 if (capacitorForm.ShowModal() == wxID_OK) {
323 switch (data.reactivePowerUnit) {
324 case ElectricalUnit::UNIT_var: {
325 data.reactivePower = data.reactivePower / systemPowerBase;
326 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
328 case ElectricalUnit::UNIT_kvar: {
329 data.reactivePower = (data.reactivePower * 1e3) / systemPowerBase;
330 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
332 case ElectricalUnit::UNIT_Mvar: {
333 data.reactivePower = (data.reactivePower * 1e6) / systemPowerBase;
334 data.reactivePowerUnit = ElectricalUnit::UNIT_PU;
352 wxString tipText = m_electricalData.name;
355 double reactivePower = m_electricalData.reactivePower;
359 std::complex<double> v =
static_cast<Bus*
>(m_parentList[0])->GetElectricalData().voltage;
360 reactivePower *= std::pow(std::abs(v), 2);
363 tipText += _(
"\nQ = ") + wxString::FromDouble(reactivePower, 5);
364 switch (m_electricalData.reactivePowerUnit) {
365 case ElectricalUnit::UNIT_PU: {
366 tipText += _(
" p.u.");
368 case ElectricalUnit::UNIT_var: {
369 tipText += _(
" var");
371 case ElectricalUnit::UNIT_kvar: {
372 tipText += _(
" kvar");
374 case ElectricalUnit::UNIT_Mvar: {
375 tipText += _(
" Mvar");
384rapidxml::xml_node<>* Capacitor::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
386 auto elementNode = XMLParser::AppendNode(doc, elementListNode,
"Capacitor");
387 XMLParser::SetNodeAttribute(doc, elementNode,
"ID", m_elementID);
389 SaveCADProperties(doc, elementNode);
391 auto electricalProp = XMLParser::AppendNode(doc, elementNode,
"ElectricalProperties");
392 auto isOnline = XMLParser::AppendNode(doc, electricalProp,
"IsOnline");
393 XMLParser::SetNodeValue(doc, isOnline, m_online);
394 auto name = XMLParser::AppendNode(doc, electricalProp,
"Name");
395 XMLParser::SetNodeValue(doc, name, m_electricalData.name);
396 auto reactivePower = XMLParser::AppendNode(doc, electricalProp,
"ReactivePower");
397 XMLParser::SetNodeValue(doc, reactivePower, m_electricalData.reactivePower);
398 XMLParser::SetNodeAttribute(doc, reactivePower,
"UnitID",
static_cast<int>(m_electricalData.reactivePowerUnit));
400 SaveSwitchingData(doc, electricalProp);
405bool Capacitor::OpenElement(rapidxml::xml_node<>* elementNode, std::vector<Element*> parentList)
407 if (!OpenCADProperties(elementNode, parentList))
return false;
409 auto electricalProp = elementNode->first_node(
"ElectricalProperties");
410 if (!electricalProp)
return false;
412 SetOnline(XMLParser::GetNodeValueInt(electricalProp,
"IsOnline"));
413 m_electricalData.name = electricalProp->first_node(
"Name")->value();
414 m_electricalData.reactivePower = XMLParser::GetNodeValueDouble(electricalProp,
"ReactivePower");
415 m_electricalData.reactivePowerUnit =
416 static_cast<ElectricalUnit
>(XMLParser::GetAttributeValueInt(electricalProp,
"ReactivePower",
"UnitID"));
418 if (!OpenSwitchingData(electricalProp))
return false;
Node for power elements. All others power elements are connected through this.
Shunt capactior power element.
virtual wxString GetTipText() const
Get the tip text.
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual Element * GetCopy()
Get a the element copy.
virtual bool Intersects(wxRect2DDouble rect) const
Check if the element's rect intersects other rect.
virtual bool Contains(wxPoint2DDouble position) const
Checks if the element contains a position.
virtual bool AddParent(Element *parent, wxPoint2DDouble position, bool isOpening=false)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
virtual bool ShowForm(wxWindow *parent, Element *element, wxWindow *workspace=nullptr)
Show element data form.
virtual void DrawDC(GUIColour *guiColour, wxPoint2DDouble translation, double scale, wxGraphicsContext *gc) const
Draw the element using GDI+.
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.
virtual void SetDynamicEvent(bool dynEvent=true)
Set if the power element have dynamic event.
virtual void UpdateSwitches()
Update the switch position.
virtual void DrawDCSwitches(GUIColour *guiColour, wxGraphicsContext *gc) const
Draw switch.
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