From a41af814d1339a03a7891ee5c84f49006fac58e5 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Wed, 7 Dec 2016 20:09:13 -0200 Subject: Multiline text implemented text update still under implementation --- .codelite/.tern-port | 2 +- .codelite/PSP.session | 48 +++++++++----- .codelite/PSP.tags | Bin 84313088 -> 84322304 bytes .codelite/compilation.db | Bin 63488 -> 63488 bytes .codelite/refactoring.db | Bin 2219008 -> 2255872 bytes Project/Bus.h | 14 ++-- Project/Project.mk | 2 +- Project/Release/Bus.cpp.o | Bin 40981 -> 41853 bytes Project/Release/BusForm.cpp.o | Bin 113688 -> 119004 bytes Project/Release/ElectricCalculation.cpp.o | Bin 67499 -> 71739 bytes Project/Release/Line.cpp.o | Bin 160820 -> 162676 bytes Project/Release/MainFrame.cpp.o | Bin 141269 -> 141269 bytes Project/Release/PSP-UFU.exe | Bin 4211221 -> 4232274 bytes Project/Release/PowerFlow.cpp.o | Bin 42558 -> 43132 bytes Project/Release/Text.cpp.o | Bin 47041 -> 53898 bytes Project/Release/TextForm.cpp.o | Bin 165811 -> 166463 bytes Project/Release/Workspace.cpp.o | Bin 206375 -> 210077 bytes Project/Text.cpp | 103 ++++++++++++++++++++++++------ Project/Text.h | 2 + 19 files changed, 129 insertions(+), 42 deletions(-) diff --git a/.codelite/.tern-port b/.codelite/.tern-port index 2a0f5c7..4dfdd5b 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -53784 \ No newline at end of file +54807 \ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index bd4fc99..6777ae1 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -1,12 +1,12 @@ - + - - + + @@ -33,8 +33,8 @@ - - + + @@ -47,22 +47,15 @@ - - + + - - - - - - - - - + + @@ -76,7 +69,28 @@ - + + + + + + + + + + + + + + + + + + + + + + diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags index c287d0c..ab2e805 100644 Binary files a/.codelite/PSP.tags and b/.codelite/PSP.tags differ diff --git a/.codelite/compilation.db b/.codelite/compilation.db index 1015797..b9d6d94 100644 Binary files a/.codelite/compilation.db and b/.codelite/compilation.db differ diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db index 2e7ba05..9e1852f 100644 Binary files a/.codelite/refactoring.db and b/.codelite/refactoring.db differ diff --git a/Project/Bus.h b/Project/Bus.h index 836d2f7..470d4cb 100644 --- a/Project/Bus.h +++ b/Project/Bus.h @@ -11,7 +11,7 @@ struct BusElectricalData { ElectricalUnit nominalVoltageUnit = UNIT_kV; bool isVoltageControlled = false; double controlledVoltage = 1.0; - int controlledVoltageUnitChoice = 0; // 0 = p.u., 1 = same as nominalVoltageUnit (UNIT_V or UNIT_kV). + int controlledVoltageUnitChoice = 0; // 0 = p.u., 1 = same as nominalVoltageUnit (UNIT_V or UNIT_kV). bool slackBus = false; // Power flow (p.u.) @@ -21,8 +21,14 @@ struct BusElectricalData { bool hasFault = false; FaultData faultType = FAULT_THREEPHASE; FaultData faultLocation = FAULT_LINE_A; + // p.u. fault data double faultResistance = 0.0; double faultReactance = 0.0; + std::complex faultCurrent[3] = { std::complex(0.0, 0.0), std::complex(0.0, 0.0), + std::complex(0.0, 0.0) }; + std::complex faultVoltage[3] = { std::complex(0.0, 0.0), std::complex(0.0, 0.0), + std::complex(0.0, 0.0) }; + double scPower = 0.0; // Stability bool plotBus = false; @@ -35,7 +41,7 @@ struct BusElectricalData { class Bus : public Element { - public: +public: Bus(); Bus(wxPoint2DDouble position); Bus(wxPoint2DDouble position, wxString name); @@ -53,8 +59,8 @@ class Bus : public Element virtual void SetElectricalData(BusElectricalData electricalData) { m_electricalData = electricalData; } virtual bool ShowForm(wxWindow* parent, Element* element); - protected: +protected: BusElectricalData m_electricalData; }; -#endif // BUS_H +#endif // BUS_H diff --git a/Project/Project.mk b/Project/Project.mk index 8fed411..8ab3b2c 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=06/12/2016 +Date :=07/12/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/Bus.cpp.o b/Project/Release/Bus.cpp.o index a0baa28..444c5dc 100644 Binary files a/Project/Release/Bus.cpp.o and b/Project/Release/Bus.cpp.o differ diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o index 1644878..3aff5ba 100644 Binary files a/Project/Release/BusForm.cpp.o and b/Project/Release/BusForm.cpp.o differ diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o index 79d5b45..7dc5f55 100644 Binary files a/Project/Release/ElectricCalculation.cpp.o and b/Project/Release/ElectricCalculation.cpp.o differ diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o index 8467f11..1bc1c62 100644 Binary files a/Project/Release/Line.cpp.o and b/Project/Release/Line.cpp.o differ diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o index 0ce9351..07fd41c 100644 Binary files a/Project/Release/MainFrame.cpp.o and b/Project/Release/MainFrame.cpp.o differ diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe index c863055..d591cb9 100644 Binary files a/Project/Release/PSP-UFU.exe and b/Project/Release/PSP-UFU.exe differ diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o index e284cdc..1abafea 100644 Binary files a/Project/Release/PowerFlow.cpp.o and b/Project/Release/PowerFlow.cpp.o differ diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o index 3734ca0..9911071 100644 Binary files a/Project/Release/Text.cpp.o and b/Project/Release/Text.cpp.o differ diff --git a/Project/Release/TextForm.cpp.o b/Project/Release/TextForm.cpp.o index 09a81f7..cc9a9ca 100644 Binary files a/Project/Release/TextForm.cpp.o and b/Project/Release/TextForm.cpp.o differ diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o index ccb9bf6..1200399 100644 Binary files a/Project/Release/Workspace.cpp.o and b/Project/Release/Workspace.cpp.o differ diff --git a/Project/Text.cpp b/Project/Text.cpp index 7082e17..eb94de0 100644 --- a/Project/Text.cpp +++ b/Project/Text.cpp @@ -51,13 +51,26 @@ void Text::Draw(wxPoint2DDouble translation, double scale) } // Draw text (layer 2) - glColor4d(0.0, 0.0, 0.0, 1.0); - wxGLString glString(m_text); - glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - glString.consolidate(&dc); - glString.bind(); - glString.render(m_position.m_x, m_position.m_y); + if(!m_isMultlineText) { // Only one line + wxGLString glString(m_text); + glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + glString.consolidate(&dc); + glString.bind(); + glString.render(m_position.m_x, m_position.m_y); + } else { // Multiples lines + wxGLStringArray glStringArray; + // Fill the string array. + for(int i = 0; i < (int)m_multlineText.size(); i++) glStringArray.addString(m_multlineText[i]); + glStringArray.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + glStringArray.consolidate(&dc); + glStringArray.bind(); + // The text will be printed centralized. + for(int i = 0; i < (int)m_multlineText.size(); i++) { + glStringArray.get(i).render(m_position.m_x, m_position.m_y - m_height / 2.0 + + glStringArray.get(i).getheight() * double(i) + glStringArray.get(i).getheight() / 2.0); + } + } glPopMatrix(); } @@ -73,14 +86,40 @@ void Text::SetText(wxString text) m_text = text; // Creating a glString to get the text size. - wxGLString glString(m_text); - glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); - wxScreenDC dc; - glString.consolidate(&dc); - glString.bind(); - - m_width = glString.getWidth(); - m_height = glString.getheight(); + int numberOfLines = m_text.Freq('\n') + 1; + if(numberOfLines == 1) { // Only one line + m_isMultlineText = false; + wxGLString glString(m_text); + glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + wxScreenDC dc; + glString.consolidate(&dc); + glString.bind(); + + m_width = glString.getWidth(); + m_height = glString.getheight(); + } else { + m_isMultlineText = true; + m_multlineText.clear(); + wxString text = m_text; + double w = 0.0, h = 0.0; + for(int i = 0; i < numberOfLines; ++i) { + wxString nextLine; + wxString currentLine = text.BeforeFirst('\n', &nextLine); + text = nextLine; + m_multlineText.push_back(currentLine); + + wxGLString glString(currentLine); + glString.setFont(wxFont(m_fontSize, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)); + wxScreenDC dc; + glString.consolidate(&dc); + glString.bind(); + + if(w < glString.getWidth()) w = glString.getWidth(); // Get the major width. + h = glString.getheight(); + } + m_width = w; + m_height = h * (double)numberOfLines; + } // Update text rectangle. SetPosition(m_position); @@ -115,26 +154,52 @@ void Text::UpdateText(double systemPowerBase) Bus* bus = (Bus*)m_element; if(bus) { BusElectricalData data = bus->GetEletricalData(); + double baseVoltage = data.nominalVoltage; + if(data.nominalVoltageUnit == UNIT_kV) baseVoltage *= 1e3; + double baseCurrent = systemPowerBase / (std::sqrt(3.0) * baseVoltage); + switch(m_dataType) { case DATA_NAME: { SetText(bus->GetEletricalData().name); } break; case DATA_VOLTAGE: { - double baseVoltage = data.nominalVoltage; - if(data.nominalVoltageUnit == UNIT_kV) baseVoltage *= 1e3; double voltage = std::abs(data.voltage); switch(m_unit) { case UNIT_PU: { - SetText(wxString::FromDouble(voltage, m_decimalPlaces) + _(" p.u.")); + SetText(wxString::FromDouble(voltage, m_decimalPlaces) + " p.u."); } break; case UNIT_V: { - SetText(wxString::FromDouble(voltage * baseVoltage, m_decimalPlaces) + _(" V")); + SetText(wxString::FromDouble(voltage * baseVoltage, m_decimalPlaces) + " V"); } break; case UNIT_kV: { - SetText(wxString::FromDouble(voltage * baseVoltage / 1e3, m_decimalPlaces) + _(" kV")); + SetText(wxString::FromDouble(voltage * baseVoltage / 1e3, m_decimalPlaces) + " kV"); } break; } } break; + case DATA_ANGLE: { + double angle = std::arg(data.voltage); + switch(m_unit) { + case UNIT_RADIAN: { + SetText(wxString::FromDouble(angle, m_decimalPlaces) + " rad"); + } break; + case UNIT_DEGREE: { + SetText(wxString::FromDouble(wxRadToDeg(angle), m_decimalPlaces) + "°"); + } break; + } + } break; + case DATA_SC_CURRENT: { + double faultCurrent[3] = { std::abs(data.faultCurrent[0]), std::abs(data.faultCurrent[1]), + std::abs(data.faultCurrent[2]) }; + switch(m_unit) { + case UNIT_PU: { + wxString str = + "Ia = " + wxString::FromDouble(faultCurrent[0], m_decimalPlaces) + " p.u."; + str += "\nIb = " + wxString::FromDouble(faultCurrent[1], m_decimalPlaces) + " p.u."; + str += "\nIc = " + wxString::FromDouble(faultCurrent[2], m_decimalPlaces) + " p.u."; + SetText(str); + } break; + } + } } } } break; diff --git a/Project/Text.h b/Project/Text.h index 98aeb65..80f35fa 100644 --- a/Project/Text.h +++ b/Project/Text.h @@ -80,6 +80,8 @@ class Text : public Element protected: wxString m_text = _("Text"); + std::vector m_multlineText; + bool m_isMultlineText = false; int m_fontSize = 10; Element* m_element = NULL; -- cgit