summaryrefslogtreecommitdiffstats
path: root/Project/Element.cpp
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2016-10-28 17:46:43 -0200
committerThales1330 <thaleslima.ufu@gmail.com>2016-10-28 17:46:43 -0200
commit468ba7581675a23567746628d6777ca411b150d3 (patch)
tree1c52dc5d0f530a04c03ab76d71e6134df18a4816 /Project/Element.cpp
parent02c5a1d22a078c132aca40ea14b95800dd8257e9 (diff)
downloadPSP.git-468ba7581675a23567746628d6777ca411b150d3.tar.gz
PSP.git-468ba7581675a23567746628d6777ca411b150d3.tar.xz
PSP.git-468ba7581675a23567746628d6777ca411b150d3.zip
Power flow arrow under implementation
Diffstat (limited to 'Project/Element.cpp')
-rw-r--r--Project/Element.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/Project/Element.cpp b/Project/Element.cpp
index 7c69e18..3f6e111 100644
--- a/Project/Element.cpp
+++ b/Project/Element.cpp
@@ -387,3 +387,47 @@ wxString Element::StringFromDouble(double value, int minDecimal)
return formatedStr;
}
+
+void Element::CalculatePowerFlowPts(std::vector<wxPoint2DDouble> edges)
+{
+ if(edges.size() < 2) return;
+
+ // Clear all power flow points
+ for(int i = 0; i < (int)m_powerFlowArrow.size(); i++) m_powerFlowArrow[i].clear();
+ m_powerFlowArrow.clear();
+
+ for(int i = 1; i < (int)edges.size(); i++) {
+ wxPoint2DDouble pt1 = edges[i - 1];
+ 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);
+ }
+ m_powerFlowArrow.push_back(triPts);
+ }
+}
+
+void Element::DrawPowerFlowPts() const
+{
+ glColor4d(1.0, 0.55, 0.0, 1.0);
+ for(int i = 0; i < (int)m_powerFlowArrow.size(); i++) {
+ DrawTriangle(m_powerFlowArrow[i]);
+ }
+}