18#include "../../forms/SyncMachineForm.h"
23 m_elementType = TYPE_SYNC_MOTOR;
26SyncMotor::SyncMotor(wxString name) :
Machines()
28 m_elementType = TYPE_SYNC_MOTOR;
29 m_electricalData.name = name;
32SyncMotor::~SyncMotor() {}
35void SyncMotor::DrawDCSymbol(wxGraphicsContext* gc)
const
37 DrawDCArc(m_position, 12, 30, 330, 10, gc);
40void SyncMotor::DrawDCSymbol(wxDC& dc)
const
42 DrawDCArc(m_position, 12, 30, 330, dc);
49 wxMenu* textMenu =
new wxMenu();
51 textMenu->Append(ID_TXT_NAME, _(
"Name"));
52 textMenu->Append(ID_TXT_ACTIVE_POWER, _(
"Active power"));
53 textMenu->Append(ID_TXT_REACTIVE_POWER, _(
"Reactive power"));
54 textMenu->SetClientData(menu.GetClientData());
55 menu.AppendSubMenu(textMenu, _(
"Add text"));
65 syncMotorForm.SetTitle(_(
"Synchronous Condenser"));
66 syncMotorForm.CenterOnParent();
67 if (syncMotorForm.ShowModal() == wxID_OK) {
76 double machineBasePower = 1.0;
77 if (data.useMachineBase) { machineBasePower = GetValueFromUnit(data.nominalPower, data.nominalPowerUnit); }
80 double activePower = GetValueFromUnit(data.activePower, data.activePowerUnit);
81 if (!m_online) activePower = 0.0;
83 if (data.useMachineBase) data.activePower = (activePower * machineBasePower) / systemPowerBase;
86 data.activePower = activePower / systemPowerBase;
91 double reactivePower = GetValueFromUnit(data.reactivePower, data.reactivePowerUnit);
92 if (!m_online) reactivePower = 0.0;
94 if (data.useMachineBase) data.reactivePower = (reactivePower * machineBasePower) / systemPowerBase;
97 data.reactivePower = reactivePower / systemPowerBase;
102 double maxReactive = GetValueFromUnit(data.maxReactive, data.maxReactiveUnit);
104 if (data.useMachineBase) data.maxReactive = (maxReactive * machineBasePower) / systemPowerBase;
107 data.maxReactive = maxReactive / systemPowerBase;
112 double minReactive = GetValueFromUnit(data.minReactive, data.minReactiveUnit);
114 if (data.useMachineBase) data.minReactive = (minReactive * machineBasePower) / systemPowerBase;
117 data.minReactive = minReactive / systemPowerBase;
121 double baseVoltage = GetValueFromUnit(data.nominalVoltage, data.nominalVoltageUnit);
122 double systemBaseImpedance = (baseVoltage * baseVoltage) / systemPowerBase;
123 double machineBaseImpedance = (baseVoltage * baseVoltage) / machineBasePower;
126 if (data.useMachineBase) {
127 data.positiveResistance = (data.positiveResistance * machineBaseImpedance) / systemBaseImpedance;
128 data.positiveReactance = (data.positiveReactance * machineBaseImpedance) / systemBaseImpedance;
129 data.negativeResistance = (data.negativeResistance * machineBaseImpedance) / systemBaseImpedance;
130 data.negativeReactance = (data.negativeReactance * machineBaseImpedance) / systemBaseImpedance;
131 data.zeroResistance = (data.zeroResistance * machineBaseImpedance) / systemBaseImpedance;
132 data.zeroReactance = (data.zeroReactance * machineBaseImpedance) / systemBaseImpedance;
133 data.groundResistance = (data.groundResistance * machineBaseImpedance) / systemBaseImpedance;
134 data.groundReactance = (data.groundReactance * machineBaseImpedance) / systemBaseImpedance;
138 data.faultCurrent[0] = std::complex<double>(0, 0);
139 data.faultCurrent[1] = std::complex<double>(0, 0);
140 data.faultCurrent[2] = std::complex<double>(0, 0);
148 if (nominalVoltage.size() > 0) {
149 m_electricalData.nominalVoltage = nominalVoltage[0];
150 m_electricalData.nominalVoltageUnit = nominalVoltageUnit[0];
163 wxString tipText = m_electricalData.name;
165 double activePower = m_electricalData.activePower;
166 if (!m_online) activePower = 0.0;
167 tipText += _(
"\nP = ") + wxString::FromDouble(activePower, 5);
168 switch (m_electricalData.activePowerUnit) {
170 tipText += _(
" p.u.");
184 double reactivePower = m_electricalData.reactivePower;
185 if (!m_online) reactivePower = 0.0;
186 tipText += _(
"\nQ = ") + wxString::FromDouble(reactivePower, 5);
187 switch (m_electricalData.reactivePowerUnit) {
189 tipText += _(
" p.u.");
192 tipText += _(
" var");
195 tipText += _(
" kvar");
198 tipText += _(
" Mvar");
207rapidxml::xml_node<>* SyncMotor::SaveElement(rapidxml::xml_document<>& doc, rapidxml::xml_node<>* elementListNode)
209 auto elementNode = XMLParser::AppendNode(doc, elementListNode,
"SyncMotor");
210 XMLParser::SetNodeAttribute(doc, elementNode,
"ID", m_elementID);
212 SaveCADProperties(doc, elementNode);
214 auto electricalProp = XMLParser::AppendNode(doc, elementNode,
"ElectricalProperties");
215 auto isOnline = XMLParser::AppendNode(doc, electricalProp,
"IsOnline");
216 XMLParser::SetNodeValue(doc, isOnline, m_online);
217 auto name = XMLParser::AppendNode(doc, electricalProp,
"Name");
218 XMLParser::SetNodeValue(doc, name, m_electricalData.name);
219 auto nominalPower = XMLParser::AppendNode(doc, electricalProp,
"NominalPower");
220 XMLParser::SetNodeValue(doc, nominalPower, m_electricalData.nominalPower);
221 XMLParser::SetNodeAttribute(doc, nominalPower,
"UnitID",
static_cast<int>(m_electricalData.nominalPowerUnit));
222 auto activePower = XMLParser::AppendNode(doc, electricalProp,
"ActivePower");
223 XMLParser::SetNodeValue(doc, activePower, m_electricalData.activePower);
224 XMLParser::SetNodeAttribute(doc, activePower,
"UnitID",
static_cast<int>(m_electricalData.activePowerUnit));
225 auto reactivePower = XMLParser::AppendNode(doc, electricalProp,
"ReactivePower");
226 XMLParser::SetNodeValue(doc, reactivePower, m_electricalData.reactivePower);
227 XMLParser::SetNodeAttribute(doc, reactivePower,
"UnitID",
static_cast<int>(m_electricalData.reactivePowerUnit));
228 auto haveMaxReactive = XMLParser::AppendNode(doc, electricalProp,
"HaveMaxReactive");
229 XMLParser::SetNodeValue(doc, haveMaxReactive, m_electricalData.haveMaxReactive);
230 auto maxReactive = XMLParser::AppendNode(doc, electricalProp,
"MaxReactive");
231 XMLParser::SetNodeValue(doc, maxReactive, m_electricalData.maxReactive);
232 XMLParser::SetNodeAttribute(doc, maxReactive,
"UnitID",
static_cast<int>(m_electricalData.maxReactiveUnit));
233 auto haveMinReactive = XMLParser::AppendNode(doc, electricalProp,
"HaveMinReactive");
234 XMLParser::SetNodeValue(doc, haveMinReactive, m_electricalData.haveMinReactive);
235 auto minReactive = XMLParser::AppendNode(doc, electricalProp,
"MinReactive");
236 XMLParser::SetNodeValue(doc, minReactive, m_electricalData.minReactive);
237 XMLParser::SetNodeAttribute(doc, minReactive,
"UnitID",
static_cast<int>(m_electricalData.minReactiveUnit));
238 auto useMachineBase = XMLParser::AppendNode(doc, electricalProp,
"UseMachineBase");
239 XMLParser::SetNodeValue(doc, useMachineBase, m_electricalData.useMachineBase);
241 auto fault = XMLParser::AppendNode(doc, electricalProp,
"Fault");
242 auto positiveResistance = XMLParser::AppendNode(doc, fault,
"PositiveResistance");
243 XMLParser::SetNodeValue(doc, positiveResistance, m_electricalData.positiveResistance);
244 auto positiveReactance = XMLParser::AppendNode(doc, fault,
"PositiveReactance");
245 XMLParser::SetNodeValue(doc, positiveReactance, m_electricalData.positiveReactance);
246 auto negativeResistance = XMLParser::AppendNode(doc, fault,
"NegativeResistance");
247 XMLParser::SetNodeValue(doc, negativeResistance, m_electricalData.negativeResistance);
248 auto negativeReactance = XMLParser::AppendNode(doc, fault,
"NegativeReactance");
249 XMLParser::SetNodeValue(doc, negativeReactance, m_electricalData.negativeReactance);
250 auto zeroResistance = XMLParser::AppendNode(doc, fault,
"ZeroResistance");
251 XMLParser::SetNodeValue(doc, zeroResistance, m_electricalData.zeroResistance);
252 auto zeroReactance = XMLParser::AppendNode(doc, fault,
"ZeroReactance");
253 XMLParser::SetNodeValue(doc, zeroReactance, m_electricalData.zeroReactance);
254 auto groundResistance = XMLParser::AppendNode(doc, fault,
"GroundResistance");
255 XMLParser::SetNodeValue(doc, groundResistance, m_electricalData.groundResistance);
256 auto groundReactance = XMLParser::AppendNode(doc, fault,
"GroundReactance");
257 XMLParser::SetNodeValue(doc, groundReactance, m_electricalData.groundReactance);
258 auto groundNeutral = XMLParser::AppendNode(doc, fault,
"GroundNeutral");
259 XMLParser::SetNodeValue(doc, groundNeutral, m_electricalData.groundNeutral);
264bool SyncMotor::OpenElement(rapidxml::xml_node<>* elementNode, std::vector<Element*> parentList)
266 if (!OpenCADProperties(elementNode, parentList))
return false;
268 auto electricalProp = elementNode->first_node(
"ElectricalProperties");
269 if (!electricalProp)
return false;
271 SetOnline(XMLParser::GetNodeValueInt(electricalProp,
"IsOnline"));
272 m_electricalData.name = electricalProp->first_node(
"Name")->value();
273 m_electricalData.nominalPower = XMLParser::GetNodeValueDouble(electricalProp,
"NominalPower");
274 m_electricalData.nominalPowerUnit =
275 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"NominalPower",
"UnitID"));
276 m_electricalData.activePower = XMLParser::GetNodeValueDouble(electricalProp,
"ActivePower");
277 m_electricalData.activePowerUnit =
278 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"ActivePower",
"UnitID"));
279 m_electricalData.reactivePower = XMLParser::GetNodeValueDouble(electricalProp,
"ReactivePower");
280 m_electricalData.reactivePowerUnit =
281 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"ReactivePower",
"UnitID"));
282 m_electricalData.haveMaxReactive = XMLParser::GetNodeValueInt(electricalProp,
"HaveMaxReactive");
283 m_electricalData.maxReactive = XMLParser::GetNodeValueDouble(electricalProp,
"MaxReactive");
284 m_electricalData.maxReactiveUnit =
285 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"MaxReactive",
"UnitID"));
286 m_electricalData.haveMinReactive = XMLParser::GetNodeValueInt(electricalProp,
"HaveMinReactive");
287 m_electricalData.minReactive = XMLParser::GetNodeValueDouble(electricalProp,
"MinReactive");
288 m_electricalData.minReactiveUnit =
289 static_cast<ElectricalUnit>(XMLParser::GetAttributeValueInt(electricalProp,
"MinReactive",
"UnitID"));
290 m_electricalData.useMachineBase = XMLParser::GetNodeValueInt(electricalProp,
"UseMachineBase");
292 auto fault = electricalProp->first_node(
"Fault");
293 if (!fault)
return false;
294 m_electricalData.positiveResistance = XMLParser::GetNodeValueDouble(fault,
"PositiveResistance");
295 m_electricalData.positiveReactance = XMLParser::GetNodeValueDouble(fault,
"PositiveReactance");
296 m_electricalData.negativeResistance = XMLParser::GetNodeValueDouble(fault,
"NegativeResistance");
297 m_electricalData.negativeReactance = XMLParser::GetNodeValueDouble(fault,
"NegativeReactance");
298 m_electricalData.zeroResistance = XMLParser::GetNodeValueDouble(fault,
"ZeroResistance");
299 m_electricalData.zeroReactance = XMLParser::GetNodeValueDouble(fault,
"ZeroReactance");
300 m_electricalData.groundResistance = XMLParser::GetNodeValueDouble(fault,
"GroundResistance");
301 m_electricalData.groundReactance = XMLParser::GetNodeValueDouble(fault,
"GroundReactance");
302 m_electricalData.groundNeutral = XMLParser::GetNodeValueInt(fault,
"GroundNeutral");
ElectricalUnit
Electrical units.
Base class of all elements of the program. This class is responsible for manage graphical and his dat...
virtual void GeneralMenuItens(wxMenu &menu)
Insert general itens to context menu.
bool SetOnline(bool online=true)
Set if the element is online or offline.
Abstract class for rotary machines power elements.
Synchronous motor (synchronous compensator) power element.
virtual Element * GetCopy()
Get a the element copy.
virtual void SetNominalVoltage(std::vector< double > nominalVoltage, std::vector< ElectricalUnit > nominalVoltageUnit)
Set nominal voltage of the element.
virtual wxString GetTipText() const
Get the tip text.
virtual bool ShowForm(wxWindow *parent, Element *element)
Show element data form.
virtual bool GetContextMenu(wxMenu &menu)
Get the element contex menu.