diff options
Diffstat (limited to 'Project')
36 files changed, 364 insertions, 125 deletions
diff --git a/Project/Element.cpp b/Project/Element.cpp index 3f6e111..91ed61f 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -390,6 +390,8 @@ wxString Element::StringFromDouble(double value, int minDecimal) void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges) { + double arrowRate = 100.0; // One arrow to each "arrowRate" distance in pixels. + if(edges.size() < 2) return; // Clear all power flow points @@ -401,26 +403,32 @@ void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges) wxPoint2DDouble pt2 = edges[i]; double angle = std::atan2(pt2.m_y - pt1.m_y, pt2.m_x - pt1.m_x); - - //wxLogMessage(wxString::Format("(%f, %f) (%f, %f)"), pt1.m_x, pt1.m_y, pt2.m_x, pt2.m_y); wxPoint2DDouble rotPt2( std::cos(-angle) * (pt2.m_x - pt1.m_x) - std::sin(-angle) * (pt2.m_y - pt1.m_y) + pt1.m_x, std::sin(-angle) * (pt2.m_x - pt1.m_x) + std::cos(-angle) * (pt2.m_y - pt1.m_y) + pt1.m_y); - wxPoint2DDouble mid((rotPt2.m_x + pt1.m_x) / 2.0, (rotPt2.m_y + pt1.m_y) / 2.0); // test - std::vector<wxPoint2DDouble> triPts; - triPts.push_back(mid + wxPoint2DDouble(5.0, 0.0)); - triPts.push_back(mid + wxPoint2DDouble(-5.0, 5.0)); - triPts.push_back(mid + wxPoint2DDouble(-5.0, -5.0)); - - // Rotate back. - for(int i = 0; i < 3; i++) { - triPts[i] = wxPoint2DDouble( - std::cos(angle) * (triPts[i].m_x - pt1.m_x) - std::sin(angle) * (triPts[i].m_y - pt1.m_y) + pt1.m_x, - std::sin(angle) * (triPts[i].m_x - pt1.m_x) + std::cos(angle) * (triPts[i].m_y - pt1.m_y) + pt1.m_y); + int numArrows = std::abs(pt1.m_x - rotPt2.m_x) / arrowRate; + if(numArrows == 0) numArrows = 1; + + for(int i = 0; i < numArrows; i++) { + wxPoint2DDouble arrowCenter(pt1.m_x + ((rotPt2.m_x - pt1.m_x) / double(numArrows + 1)) * double(i + 1), + pt1.m_y + ((rotPt2.m_y - pt1.m_y) / double(numArrows + 1)) * double(i + 1)); + + std::vector<wxPoint2DDouble> triPts; + triPts.push_back(arrowCenter + wxPoint2DDouble(5.0, 0.0)); + triPts.push_back(arrowCenter + wxPoint2DDouble(-5.0, 5.0)); + triPts.push_back(arrowCenter + wxPoint2DDouble(-5.0, -5.0)); + + // Rotate back. + for(int i = 0; i < 3; i++) { + triPts[i] = wxPoint2DDouble( + std::cos(angle) * (triPts[i].m_x - pt1.m_x) - std::sin(angle) * (triPts[i].m_y - pt1.m_y) + pt1.m_x, + std::sin(angle) * (triPts[i].m_x - pt1.m_x) + std::cos(angle) * (triPts[i].m_y - pt1.m_y) + + pt1.m_y); + } + m_powerFlowArrow.push_back(triPts); } - m_powerFlowArrow.push_back(triPts); } } diff --git a/Project/Element.h b/Project/Element.h index ec18ccd..672723f 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -81,6 +81,15 @@ enum SwitchingType SW_REMOVE }; +enum PowerFlowDirection +{ + PF_NONE = 0, + PF_TO_BUS, + PF_TO_ELEMENT, + PF_BUS1_TO_BUS2, + PF_BUS2_TO_BUS1 +}; + struct SwitchingData { std::vector<SwitchingType> swType; @@ -192,6 +201,8 @@ class Element virtual void SetNominalVoltage(std::vector<double> nominalVoltage, std::vector<ElectricalUnit> nominalVoltageUnit) {} virtual void SetSwitchingData(SwitchingData data) { m_swData = data; } virtual SwitchingData GetSwitchingData() { return m_swData; } + virtual void SetPowerFlowDirection(PowerFlowDirection pfDirection) { m_pfDirection = pfDirection; } + virtual PowerFlowDirection GetPowerFlowDirection() const { return m_pfDirection; } //Static methods static wxString StringFromDouble(double value, int minDecimal = 1); @@ -209,7 +220,9 @@ class Element double m_switchSize = 10.0; std::vector<wxRect2DDouble> m_switchRect; + std::vector< std::vector<wxPoint2DDouble> > m_powerFlowArrow; + PowerFlowDirection m_pfDirection = PF_NONE; bool m_selected = false; bool m_dragging = false; diff --git a/Project/IndMotor.cpp b/Project/IndMotor.cpp index 26d19e9..1c3b252 100644 --- a/Project/IndMotor.cpp +++ b/Project/IndMotor.cpp @@ -1,8 +1,11 @@ #include "IndMotorForm.h" #include "IndMotor.h" -IndMotor::IndMotor() : Machines() {} -IndMotor::IndMotor(wxString name) : Machines() { m_electricalData.name = name; } +IndMotor::IndMotor() : Machines() { } +IndMotor::IndMotor(wxString name) : Machines() +{ + m_electricalData.name = name; +} IndMotor::~IndMotor() {} void IndMotor::DrawSymbol() const { diff --git a/Project/Line.cpp b/Project/Line.cpp index 20edb2e..a473562 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -43,7 +43,10 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const glColor4d(0.2, 0.2, 0.2, 1.0); DrawLine(pointList); - if(m_inserted) DrawSwitches(); + if(m_inserted){ + DrawSwitches(); + DrawPowerFlowPts(); + } // Draw nodes. if(pointList.size() > 0) { @@ -72,10 +75,12 @@ void Line::Move(wxPoint2DDouble position) if(!m_parentList[0]) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } if(!m_parentList[1]) { m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } if(!m_parentList[0] && !m_parentList[1]) { @@ -144,6 +149,7 @@ bool Line::AddParent(Element* parent, wxPoint2DDouble position) UpdateSwitches(); m_inserted = true; + UpdatePowerFlowArrowsPosition(); return true; } } @@ -164,6 +170,7 @@ void Line::MovePickbox(wxPoint2DDouble position) if(m_activePickboxID == i) { m_pointList[i] = m_movePts[i] + position - m_moveStartPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } } } @@ -224,6 +231,7 @@ void Line::MoveNode(Element* parent, wxPoint2DDouble position) // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } double Line::PointToLineDistance(wxPoint2DDouble point, int* segmentNumber) const @@ -284,6 +292,7 @@ void Line::RemoveNode(wxPoint2DDouble point) } } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Line::AddNode(wxPoint2DDouble point) @@ -294,6 +303,7 @@ void Line::AddNode(wxPoint2DDouble point) m_pointList.insert(m_pointList.begin() + segmentNumber + 1, point); } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Line::CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom) const @@ -381,6 +391,7 @@ bool Line::SetNodeParent(Element* parent) m_pointList[0] = parentPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); return true; } if(m_activeNodeID == 2) { @@ -398,6 +409,7 @@ bool Line::SetNodeParent(Element* parent) m_pointList[m_pointList.size() - 1] = parentPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); return true; } } else { @@ -407,3 +419,43 @@ bool Line::SetNodeParent(Element* parent) } return false; } + +void Line::UpdatePowerFlowArrowsPosition() +{ + std::vector<wxPoint2DDouble> edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_BUS1_TO_BUS2: { + for(int i = 1; i < (int)m_pointList.size() - 1; i++) { + edges.push_back(m_pointList[i]); + } + } break; + case PF_BUS2_TO_BUS1: { + for(int i = (int)m_pointList.size() - 2; i > 0; i--) { + edges.push_back(m_pointList[i]); + } + } break; + default: + break; + } + CalculatePowerFlowPts(edges); +} + +void Line::RotateNode(Element* parent, bool clockwise) +{ + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); + } + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle); + } + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); +} diff --git a/Project/Line.h b/Project/Line.h index afabb17..2310126 100644 --- a/Project/Line.h +++ b/Project/Line.h @@ -50,6 +50,7 @@ class Line : public Branch virtual bool GetContextMenu(wxMenu& menu); virtual void RemoveNode(wxPoint2DDouble point); virtual void AddNode(wxPoint2DDouble point); + virtual void RotateNode(Element* parent, bool clockwise = true); virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom) const; virtual bool ShowForm(wxWindow* parent, Element* element); virtual LineElectricalData GetElectricalData() const { return m_electricaData; } @@ -58,6 +59,7 @@ class Line : public Branch protected: double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = NULL) const; + void UpdatePowerFlowArrowsPosition(); LineElectricalData m_electricaData; }; diff --git a/Project/Load.cpp b/Project/Load.cpp index 25793b1..ec2297b 100644 --- a/Project/Load.cpp +++ b/Project/Load.cpp @@ -30,6 +30,8 @@ bool Load::AddParent(Element* parent, wxPoint2DDouble position) wxRect2DDouble genRect(0, 0, 0, 0); m_switchRect.push_back(genRect); // Push a general rectangle. UpdateSwitches(); + m_pfDirection = PF_TO_ELEMENT; + UpdatePowerFlowArrowsPosition(); return true; } @@ -73,6 +75,7 @@ void Load::Draw(wxPoint2DDouble translation, double scale) const DrawLine(m_pointList); DrawSwitches(); + DrawPowerFlowPts(); std::vector<wxPoint2DDouble> triangPts; for(int i = 0; i < 3; i++) { @@ -97,6 +100,7 @@ void Load::Rotate(bool clockwise) m_pointList[2] = RotateAtPosition(m_pointList[2], rotAngle); m_pointList[3] = RotateAtPosition(m_pointList[3], rotAngle); UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } bool Load::GetContextMenu(wxMenu& menu) diff --git a/Project/Machines.cpp b/Project/Machines.cpp index c86f7b7..0f2dc43 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -24,6 +24,7 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) wxRect2DDouble genRect(0,0,0,0); m_switchRect.push_back(genRect); // Push a general rectangle. UpdateSwitches(); + UpdatePowerFlowArrowsPosition(); return true; } return false; @@ -90,12 +91,7 @@ void Machines::Move(wxPoint2DDouble position) m_pointList[0] = m_movePts[0] + position - m_moveStartPt; } UpdateSwitchesPosition(); - - //Power flow arrows - std::vector<wxPoint2DDouble> edges; - edges.push_back(m_pointList[1]); - edges.push_back(m_pointList[2]); - CalculatePowerFlowPts(edges); + UpdatePowerFlowArrowsPosition(); } void Machines::MoveNode(Element* element, wxPoint2DDouble position) @@ -110,12 +106,14 @@ void Machines::MoveNode(Element* element, wxPoint2DDouble position) if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; } } // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Machines::StartMove(wxPoint2DDouble position) @@ -140,7 +138,9 @@ void Machines::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } } @@ -175,11 +175,13 @@ bool Machines::SetNodeParent(Element* parent) m_pointList[0] = parentPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); return true; } else { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; } } @@ -194,8 +196,10 @@ void Machines::UpdateNodes() if(!m_parentList[0]->Intersects(nodeRect)) { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } } } @@ -208,4 +212,27 @@ void Machines::Rotate(bool clockwise) m_pointList[2] = RotateAtPosition(m_pointList[2], rotAngle); m_pointList[3] = RotateAtPosition(m_pointList[3], rotAngle); UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); +} + +void Machines::UpdatePowerFlowArrowsPosition() +{ + std::vector<wxPoint2DDouble> edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_TO_BUS: { + edges.push_back(m_pointList[2]); + edges.push_back(m_pointList[1]); + } break; + case PF_TO_ELEMENT: { + edges.push_back(m_pointList[1]); + edges.push_back(m_pointList[2]); + } break; + default: + break; + } + + CalculatePowerFlowPts(edges); } diff --git a/Project/Machines.h b/Project/Machines.h index 8c60631..b296f99 100644 --- a/Project/Machines.h +++ b/Project/Machines.h @@ -26,6 +26,7 @@ public: protected: void UpdateSwitchesPosition(); + void UpdatePowerFlowArrowsPosition(); bool m_inserted = false; }; diff --git a/Project/Project.mk b/Project/Project.mk index b53fbf5..e46ae7a 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=28/10/2016 +Date :=29/10/2016 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC diff --git a/Project/Release/Branch.cpp.o b/Project/Release/Branch.cpp.o Binary files differindex 9d35f07..098ca04 100644 --- a/Project/Release/Branch.cpp.o +++ b/Project/Release/Branch.cpp.o diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o Binary files differindex 050e9af..ddced0e 100644 --- a/Project/Release/Bus.cpp.o +++ b/Project/Release/Bus.cpp.o diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o Binary files differindex 8e2aa6b..15a25e0 100644 --- a/Project/Release/BusForm.cpp.o +++ b/Project/Release/BusForm.cpp.o diff --git a/Project/Release/Capacitor.cpp.o b/Project/Release/Capacitor.cpp.o Binary files differindex b7b887a..b109288 100644 --- a/Project/Release/Capacitor.cpp.o +++ b/Project/Release/Capacitor.cpp.o diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o Binary files differindex 54cb60c..6833467 100644 --- a/Project/Release/Element.cpp.o +++ b/Project/Release/Element.cpp.o diff --git a/Project/Release/GeneratorStabForm.cpp.o b/Project/Release/GeneratorStabForm.cpp.o Binary files differindex c0ee1ba..b38d859 100644 --- a/Project/Release/GeneratorStabForm.cpp.o +++ b/Project/Release/GeneratorStabForm.cpp.o diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o Binary files differindex bd75e9a..f4bdf37 100644 --- a/Project/Release/IndMotor.cpp.o +++ b/Project/Release/IndMotor.cpp.o diff --git a/Project/Release/IndMotorForm.cpp.o b/Project/Release/IndMotorForm.cpp.o Binary files differindex aa7071b..36b0724 100644 --- a/Project/Release/IndMotorForm.cpp.o +++ b/Project/Release/IndMotorForm.cpp.o diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o Binary files differindex b666ec7..31aa9ea 100644 --- a/Project/Release/Inductor.cpp.o +++ b/Project/Release/Inductor.cpp.o diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o Binary files differindex dd750f9..bd3ca4f 100644 --- a/Project/Release/Line.cpp.o +++ b/Project/Release/Line.cpp.o diff --git a/Project/Release/LineForm.cpp.o b/Project/Release/LineForm.cpp.o Binary files differindex b0762e5..170955e 100644 --- a/Project/Release/LineForm.cpp.o +++ b/Project/Release/LineForm.cpp.o diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o Binary files differindex 18e6d63..081c266 100644 --- a/Project/Release/Load.cpp.o +++ b/Project/Release/Load.cpp.o diff --git a/Project/Release/Machines.cpp.o b/Project/Release/Machines.cpp.o Binary files differindex 9db50de..306a204 100644 --- a/Project/Release/Machines.cpp.o +++ b/Project/Release/Machines.cpp.o diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o Binary files differindex 51effa4..6a99d6d 100644 --- a/Project/Release/MainFrame.cpp.o +++ b/Project/Release/MainFrame.cpp.o diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe Binary files differindex 775cb72..704c0f9 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe diff --git a/Project/Release/ReactiveShuntElementForm.cpp.o b/Project/Release/ReactiveShuntElementForm.cpp.o Binary files differindex dd57691..2535b1c 100644 --- a/Project/Release/ReactiveShuntElementForm.cpp.o +++ b/Project/Release/ReactiveShuntElementForm.cpp.o diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o Binary files differindex a0985c1..475aad5 100644 --- a/Project/Release/Shunt.cpp.o +++ b/Project/Release/Shunt.cpp.o diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o Binary files differindex 1e5282d..8d3af19 100644 --- a/Project/Release/SyncGenerator.cpp.o +++ b/Project/Release/SyncGenerator.cpp.o diff --git a/Project/Release/SyncMachineForm.cpp.o b/Project/Release/SyncMachineForm.cpp.o Binary files differindex 00e1157..928bce0 100644 --- a/Project/Release/SyncMachineForm.cpp.o +++ b/Project/Release/SyncMachineForm.cpp.o diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o Binary files differindex ecb3f5c..47c24b1 100644 --- a/Project/Release/SyncMotor.cpp.o +++ b/Project/Release/SyncMotor.cpp.o diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o Binary files differindex 52e3555..ea4649a 100644 --- a/Project/Release/Transformer.cpp.o +++ b/Project/Release/Transformer.cpp.o diff --git a/Project/Release/TransformerForm.cpp.o b/Project/Release/TransformerForm.cpp.o Binary files differindex 0388483..8707099 100644 --- a/Project/Release/TransformerForm.cpp.o +++ b/Project/Release/TransformerForm.cpp.o diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o Binary files differindex b04b8ca..7b283eb 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 7df5330..d932abd 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -1,55 +1,47 @@ #include "Shunt.h" -Shunt::Shunt() : Element() -{ -} - -Shunt::~Shunt() -{ -} - +Shunt::Shunt() : Element() {} +Shunt::~Shunt() {} void Shunt::UpdateSwitchesPosition() { if(m_parentList[0]) { - m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); - } - else - { - m_pointList[1] = m_pointList[0]; - } - UpdateSwitches(); + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); + } else { + m_pointList[1] = m_pointList[0]; + } + UpdateSwitches(); } void Shunt::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); for(int i = 2; i < (int)m_pointList.size(); i++) { - m_pointList[i] = m_movePts[i] + position - m_moveStartPt; - } - if(!m_parentList[0]) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - } + m_pointList[i] = m_movePts[i] + position - m_moveStartPt; + } + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Shunt::MoveNode(Element* element, wxPoint2DDouble position) { if(element) { - if(element == m_parentList[0]) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - } - } - else - { - if(m_activeNodeID == 1) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; - } - } + if(element == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + } else { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + m_parentList[0] = NULL; + m_online = false; + } + } // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Shunt::StartMove(wxPoint2DDouble position) @@ -62,10 +54,11 @@ void Shunt::StartMove(wxPoint2DDouble position) void Shunt::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { - m_parentList[0] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } + m_parentList[0] = NULL; + m_online = false; + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } } bool Shunt::NodeContains(wxPoint2DDouble position) @@ -74,9 +67,9 @@ bool Shunt::NodeContains(wxPoint2DDouble position) 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); if(nodeRect.Contains(position)) { - m_activeNodeID = 1; - return true; - } + m_activeNodeID = 1; + return true; + } m_activeNodeID = 0; return false; @@ -85,68 +78,89 @@ bool Shunt::NodeContains(wxPoint2DDouble position) bool Shunt::SetNodeParent(Element* parent) { if(parent && m_activeNodeID != 0) { - wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - - if(parent->Intersects(nodeRect)) { - m_parentList[0] = parent; - - // Centralize the node on bus. - wxPoint2DDouble parentPt = parent->RotateAtPosition( - m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position. - parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. - parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); - m_pointList[0] = parentPt; - - UpdateSwitchesPosition(); - return true; - } - else - { - m_parentList[0] = NULL; - m_online = false; - } - } + wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + + if(parent->Intersects(nodeRect)) { + m_parentList[0] = parent; + + // Centralize the node on bus. + wxPoint2DDouble parentPt = + parent->RotateAtPosition(m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position. + parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); + m_pointList[0] = parentPt; + + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + return true; + } else { + m_parentList[0] = NULL; + m_online = false; + } + } return false; } void Shunt::UpdateNodes() { if(m_parentList[0]) { - wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - - if(!m_parentList[0]->Intersects(nodeRect)) { - m_parentList[0] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } - } + wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + + if(!m_parentList[0]->Intersects(nodeRect)) { + m_parentList[0] = NULL; + m_online = false; + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } + } } void Shunt::RotateNode(Element* parent, bool clockwise) { - double rotAngle = m_rotationAngle; - if(!clockwise) rotAngle = -m_rotationAngle; - + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + if(parent == m_parentList[0]) { - m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); - UpdateSwitchesPosition(); - } + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } } void Shunt::DrawGround(wxPoint2DDouble position) const { - std::vector<wxPoint2DDouble> groundPts; - groundPts.push_back(position); - groundPts.push_back(position + wxPoint2DDouble(0, 10)); - groundPts.push_back(position + wxPoint2DDouble(-10, 10)); - groundPts.push_back(position + wxPoint2DDouble(10, 10)); - groundPts.push_back(position + wxPoint2DDouble(-6, 15)); - groundPts.push_back(position + wxPoint2DDouble(6, 15)); - groundPts.push_back(position + wxPoint2DDouble(-3, 20)); - groundPts.push_back(position + wxPoint2DDouble(3, 20)); - - DrawLine(groundPts, GL_LINES); + std::vector<wxPoint2DDouble> groundPts; + groundPts.push_back(position); + groundPts.push_back(position + wxPoint2DDouble(0, 10)); + groundPts.push_back(position + wxPoint2DDouble(-10, 10)); + groundPts.push_back(position + wxPoint2DDouble(10, 10)); + groundPts.push_back(position + wxPoint2DDouble(-6, 15)); + groundPts.push_back(position + wxPoint2DDouble(6, 15)); + groundPts.push_back(position + wxPoint2DDouble(-3, 20)); + groundPts.push_back(position + wxPoint2DDouble(3, 20)); + + DrawLine(groundPts, GL_LINES); } +void Shunt::UpdatePowerFlowArrowsPosition() +{ + std::vector<wxPoint2DDouble> edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_TO_BUS: { + edges.push_back(m_pointList[2]); + edges.push_back(m_pointList[1]); + } break; + case PF_TO_ELEMENT: { + edges.push_back(m_pointList[1]); + edges.push_back(m_pointList[2]); + } break; + default: + break; + } + CalculatePowerFlowPts(edges); +}
\ No newline at end of file diff --git a/Project/Shunt.h b/Project/Shunt.h index e44f735..cf1681d 100644 --- a/Project/Shunt.h +++ b/Project/Shunt.h @@ -22,6 +22,7 @@ public: protected: void UpdateSwitchesPosition(); + void UpdatePowerFlowArrowsPosition(); void DrawGround(wxPoint2DDouble position) const; bool m_inserted = false; diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 57614bb..8ebf4f3 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -59,6 +59,7 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) wxRect2DDouble genRect(0, 0, 0, 0); m_switchRect.push_back(genRect); UpdateSwitches(); + UpdatePowerFlowArrowsPosition(); return true; } @@ -119,6 +120,7 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const } DrawSwitches(); + DrawPowerFlowPts(); // Push the current matrix on stack. glPushMatrix(); @@ -159,6 +161,8 @@ void Transformer::Rotate(bool clockwise) for(int i = 2; i < (int)m_pointList.size() - 2; i++) { m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle); } + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::Move(wxPoint2DDouble position) @@ -178,6 +182,7 @@ void Transformer::Move(wxPoint2DDouble position) } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) @@ -205,6 +210,7 @@ void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::StartMove(wxPoint2DDouble position) @@ -244,3 +250,110 @@ void Transformer::SetNominalVoltage(std::vector<double> nominalVoltage, std::vec m_electricalData.secondaryNominalVoltageUnit = nominalVoltageUnit[1]; } } + +void Transformer::UpdatePowerFlowArrowsPosition() +{ + std::vector<wxPoint2DDouble> edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_BUS1_TO_BUS2: { + for(int i = 1; i < (int)m_pointList.size() - 1; i++) { + edges.push_back(m_pointList[i]); + } + } break; + case PF_BUS2_TO_BUS1: { + for(int i = (int)m_pointList.size() - 2; i > 0; i--) { + edges.push_back(m_pointList[i]); + } + } break; + default: + break; + } + CalculatePowerFlowPts(edges); +} + +void Transformer::RotateNode(Element* parent, bool clockwise) +{ + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); + } + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle); + } + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); +} + +bool Transformer::SetNodeParent(Element* parent) +{ + if(m_activeNodeID == 1 && parent == m_parentList[0]) return false; + if(m_activeNodeID == 2 && parent == m_parentList[1]) return false; + + if(parent && m_activeNodeID != 0) { + wxRect2DDouble nodeRect(0, 0, 0, 0); + if(m_activeNodeID == 1) { + nodeRect = + wxRect2DDouble(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + } + if(m_activeNodeID == 2) { + nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, + m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + } + + if(parent->Intersects(nodeRect)) { + if(m_activeNodeID == 1) { + // Check if the user is trying to connect the same bus. + if(m_parentList[1] == parent) { + m_activeNodeID = 0; + return false; + } + + m_parentList[0] = parent; + + // Centralize the node on bus. + wxPoint2DDouble parentPt = parent->RotateAtPosition( + m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position. + parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); + m_pointList[0] = parentPt; + + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + return true; + } + if(m_activeNodeID == 2) { + if(m_parentList[0] == parent) { + m_activeNodeID = 0; + return false; + } + + m_parentList[1] = parent; + + wxPoint2DDouble parentPt = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], -parent->GetAngle()); + parentPt.m_y = parent->GetPosition().m_y; + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); + m_pointList[m_pointList.size() - 1] = parentPt; + + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + return true; + } + } + else + { + if(m_activeNodeID == 1) m_parentList[0] = NULL; + if(m_activeNodeID == 2) m_parentList[1] = NULL; + } + } + return false; +} diff --git a/Project/Transformer.h b/Project/Transformer.h index 86d4cf7..cf9393f 100644 --- a/Project/Transformer.h +++ b/Project/Transformer.h @@ -5,8 +5,7 @@ class TransformerForm; -enum TransformerConnection -{ +enum TransformerConnection { GWYE_GWYE = 0, WYE_GWYE, GWYE_WYE, @@ -18,8 +17,7 @@ enum TransformerConnection DELTA_DELTA }; -struct TransformerElectricalData -{ +struct TransformerElectricalData { // General wxString name = ""; double primaryNominalVoltage = 138.0; @@ -49,26 +47,29 @@ struct TransformerElectricalData class Transformer : public Branch { -public: - Transformer(); - Transformer(wxString name); + public: + Transformer(); + Transformer(wxString name); virtual ~Transformer(); - + virtual bool AddParent(Element* parent, wxPoint2DDouble position); virtual bool Contains(wxPoint2DDouble position) const; virtual void Draw(wxPoint2DDouble translation, double scale) const; virtual bool Intersects(wxRect2DDouble rect) const; virtual void Rotate(bool clockwise = true); - virtual void Move(wxPoint2DDouble position); - virtual void MoveNode(Element* parent, wxPoint2DDouble position); - virtual void StartMove(wxPoint2DDouble position); - virtual bool GetContextMenu(wxMenu& menu); + virtual void Move(wxPoint2DDouble position); + virtual void MoveNode(Element* parent, wxPoint2DDouble position); + virtual void StartMove(wxPoint2DDouble position); + virtual bool GetContextMenu(wxMenu& menu); + virtual void RotateNode(Element* parent, bool clockwise); + virtual bool SetNodeParent(Element* parent); virtual bool ShowForm(wxWindow* parent, Element* element); virtual TransformerElectricalData GetElectricalData() { return m_electricalData; } virtual void SetElectricaData(TransformerElectricalData electricalData) { m_electricalData = electricalData; } virtual void SetNominalVoltage(std::vector<double> nominalVoltage, std::vector<ElectricalUnit> nominalVoltageUnit); - -protected: + + protected: + void UpdatePowerFlowArrowsPosition(); TransformerElectricalData m_electricalData; }; |