1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#include "TextForm.h"
#include "Text.h"
#include "ElectricCalculation.h"
#include "Bus.h"
#include "Line.h"
#include "Transformer.h"
#include "SyncGenerator.h"
#include "IndMotor.h"
#include "SyncMotor.h"
#include "Load.h"
#include "Inductor.h"
#include "Capacitor.h"
Text::Text()
: Element()
{
SetText(m_text);
}
Text::Text(wxPoint2DDouble position)
: Element()
{
SetText(m_text);
SetPosition(position);
}
Text::~Text() {}
bool Text::Contains(wxPoint2DDouble position) const
{
wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle);
return m_rect.Contains(ptR);
}
void Text::Draw(wxPoint2DDouble translation, double scale)
{
wxScreenDC dc;
// Draw selection rectangle
// Push the current matrix on stack.
glPushMatrix();
// Rotate the matrix around the object position.
glTranslated(m_position.m_x, m_position.m_y, 0.0);
glRotated(m_angle, 0.0, 0.0, 1.0);
glTranslated(-m_position.m_x, -m_position.m_y, 0.0);
if(m_selected) {
glColor4d(0.0, 0.5, 1.0, 0.5);
DrawRectangle(
m_position + wxPoint2DDouble(m_borderSize / 2.0, m_borderSize / 2.0), m_rect.m_width, m_rect.m_height);
}
// Draw text (layer 2)
glColor4d(0.0, 0.0, 0.0, 1.0);
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();
}
bool Text::Intersects(wxRect2DDouble rect) const
{
if(m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect);
return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0);
}
void Text::SetText(wxString text)
{
m_text = text;
// Creating a glString to get the text size.
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);
}
void Text::Rotate(bool clockwise)
{
double rotAngle = m_rotationAngle;
if(!clockwise) rotAngle = -m_rotationAngle;
m_angle += rotAngle;
if(m_angle >= 360.0) m_angle = 0.0;
}
bool Text::ShowForm(wxWindow* parent, std::vector<Element*> elementList)
{
TextForm* textForm = new TextForm(parent, this, elementList);
if(textForm->ShowModal() == wxID_OK) {
textForm->Destroy();
return true;
}
textForm->Destroy();
return false;
}
void Text::UpdateText(double systemPowerBase)
{
switch(m_elementType) {
case TYPE_NONE:
break;
case TYPE_BUS: {
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 voltage = std::abs(data.voltage);
switch(m_unit) {
case UNIT_PU: {
SetText(wxString::FromDouble(voltage, m_decimalPlaces) + " p.u.");
} break;
case UNIT_V: {
SetText(wxString::FromDouble(voltage * baseVoltage, m_decimalPlaces) + " V");
} break;
case UNIT_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;
case TYPE_SYNC_GENERATOR: {
} break;
case TYPE_LINE: {
} break;
case TYPE_TRANSFORMER: {
} break;
case TYPE_LOAD: {
} break;
case TYPE_SYNC_MOTOR: {
} break;
case TYPE_IND_MOTOR: {
} break;
case TYPE_CAPACITOR: {
} break;
case TYPE_INDUCTOR: {
} break;
}
}
|