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
232
233
|
#include "IOControl.h"
#include "IOControlForm.h"
IOControl::IOControl(int ioFlags, int id) : ControlElement(id)
{
m_ioFlags = ioFlags;
Node* node = new Node(m_position, Node::NODE_IN, m_borderSize);
m_nodeList.push_back(node);
if(ioFlags & IN_TERMINAL_VOLTAGE)
SetValue(IN_TERMINAL_VOLTAGE);
else if(ioFlags & IN_VELOCITY)
SetValue(IN_VELOCITY);
node->StartMove(m_position);
}
IOControl::~IOControl() {}
void IOControl::Draw(wxPoint2DDouble translation, double scale) const
{
std::vector<wxPoint2DDouble> pts;
if(m_angle == 0.0) {
pts.push_back(m_rect.GetLeftTop() + wxPoint2DDouble(m_borderSize, m_borderSize));
pts.push_back(m_rect.GetRightTop() + wxPoint2DDouble(-m_borderSize - 10, m_borderSize));
pts.push_back(m_position + wxPoint2DDouble(m_width / 2 - m_borderSize, 0));
pts.push_back(m_rect.GetRightBottom() + wxPoint2DDouble(-m_borderSize - 10, -m_borderSize));
pts.push_back(m_rect.GetLeftBottom() + wxPoint2DDouble(m_borderSize, -m_borderSize));
} else if(m_angle == 90.0) {
pts.push_back(m_rect.GetLeftTop() + wxPoint2DDouble(m_borderSize, m_borderSize));
pts.push_back(m_rect.GetRightTop() + wxPoint2DDouble(-m_borderSize, m_borderSize));
pts.push_back(m_rect.GetRightBottom() + wxPoint2DDouble(-m_borderSize, -m_borderSize - 10));
pts.push_back(m_position + wxPoint2DDouble(0, m_height / 2 - m_borderSize));
pts.push_back(m_rect.GetLeftBottom() + wxPoint2DDouble(m_borderSize, -m_borderSize - 10));
} else if(m_angle == 180.0) {
pts.push_back(m_rect.GetLeftTop() + wxPoint2DDouble(m_borderSize + 10, m_borderSize));
pts.push_back(m_rect.GetRightTop() + wxPoint2DDouble(-m_borderSize, m_borderSize));
pts.push_back(m_rect.GetRightBottom() + wxPoint2DDouble(-m_borderSize, -m_borderSize));
pts.push_back(m_rect.GetLeftBottom() + wxPoint2DDouble(m_borderSize + 10, -m_borderSize));
pts.push_back(m_position + wxPoint2DDouble(-m_width / 2 + m_borderSize, 0));
} else if(m_angle == 270.0) {
pts.push_back(m_position + wxPoint2DDouble(0, -m_height / 2 + m_borderSize));
pts.push_back(m_rect.GetRightTop() + wxPoint2DDouble(-m_borderSize, m_borderSize + 10));
pts.push_back(m_rect.GetRightBottom() + wxPoint2DDouble(-m_borderSize, -m_borderSize));
pts.push_back(m_rect.GetLeftBottom() + wxPoint2DDouble(m_borderSize, -m_borderSize));
pts.push_back(m_rect.GetLeftTop() + wxPoint2DDouble(m_borderSize, m_borderSize + 10));
}
if(m_selected) {
glColor4dv(m_selectionColour.GetRGBA());
double borderSize = (m_borderSize * 2.0 + 1.0) / scale;
std::vector<wxPoint2DDouble> selPts = pts;
if(m_angle == 0.0) {
selPts[0] += wxPoint2DDouble(-borderSize / 2, -borderSize / 2);
selPts[1] += wxPoint2DDouble(borderSize / 2, -borderSize / 2);
selPts[2] += wxPoint2DDouble(1.5 * borderSize / 2, 0);
selPts[3] += wxPoint2DDouble(borderSize / 2, borderSize / 2);
selPts[4] += wxPoint2DDouble(-borderSize / 2, borderSize / 2);
} else if(m_angle == 90.0) {
selPts[0] += wxPoint2DDouble(-borderSize / 2, -borderSize / 2);
selPts[1] += wxPoint2DDouble(borderSize / 2, -borderSize / 2);
selPts[2] += wxPoint2DDouble(borderSize / 2, borderSize / 2);
selPts[3] += wxPoint2DDouble(0, 1.5 * borderSize / 2);
selPts[4] += wxPoint2DDouble(-borderSize / 2, borderSize / 2);
} else if(m_angle == 180.0) {
selPts[0] += wxPoint2DDouble(-borderSize / 2, -borderSize / 2);
selPts[1] += wxPoint2DDouble(borderSize / 2, -borderSize / 2);
selPts[2] += wxPoint2DDouble(borderSize / 2, borderSize / 2);
selPts[3] += wxPoint2DDouble(-borderSize / 2, borderSize / 2);
selPts[4] += wxPoint2DDouble(-1.5 * borderSize / 2, 0);
} else if(m_angle == 270.0) {
selPts[0] += wxPoint2DDouble(0, -1.5 * borderSize / 2);
selPts[1] += wxPoint2DDouble(borderSize / 2, -borderSize / 2);
selPts[2] += wxPoint2DDouble(borderSize / 2, borderSize / 2);
selPts[3] += wxPoint2DDouble(-borderSize / 2, borderSize / 2);
selPts[4] += wxPoint2DDouble(-borderSize / 2, -borderSize / 2);
}
DrawLine(selPts, GL_POLYGON);
}
glLineWidth(1.0);
glColor4d(1.0, 1.0, 1.0, 1.0);
DrawLine(pts, GL_POLYGON);
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawLine(pts, GL_LINE_LOOP);
// Plot number.
glEnable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
m_glStringValue->bind();
if(m_angle == 0.0) {
m_glStringValue->render(m_position.m_x - 5, m_position.m_y);
} else if(m_angle == 90.0) {
m_glStringValue->render(m_position.m_x, m_position.m_y - 5);
} else if(m_angle == 180.0) {
m_glStringValue->render(m_position.m_x + 5, m_position.m_y);
} else if(m_angle == 270.0) {
m_glStringValue->render(m_position.m_x, m_position.m_y + 5);
}
glDisable(GL_TEXTURE_2D);
glColor4d(0.0, 0.0, 0.0, 1.0);
DrawNodes();
}
bool IOControl::ShowForm(wxWindow* parent, Element* element)
{
IOControlForm* form = new IOControlForm(parent, this);
if(form->ShowModal() == wxID_OK) {
form->Destroy();
return true;
}
form->Destroy();
return false;
}
void IOControl::Rotate(bool clockwise)
{
if(clockwise)
m_angle += 90.0;
else
m_angle -= 90.0;
if(m_angle >= 360.0)
m_angle = 0.0;
else if(m_angle < 0)
m_angle = 270.0;
UpdatePoints();
for(auto it = m_nodeList.begin(), itEnd = m_nodeList.end(); it != itEnd; ++it) {
Node* node = *it;
node->Rotate(clockwise);
}
}
wxString IOControl::GenerateText()
{
wxString omega = wxString::FromUTF8("\xCF\x89");
switch(m_value) {
case IN_TERMINAL_VOLTAGE: {
m_ioNodeType = Node::NODE_OUT;
return _("Vt");
} break;
case IN_VELOCITY: {
m_ioNodeType = Node::NODE_OUT;
return omega;
} break;
case IN_ACTIVE_POWER: {
m_ioNodeType = Node::NODE_OUT;
return _("Pe");
} break;
case IN_REACTIVE_POWER: {
m_ioNodeType = Node::NODE_OUT;
return _("Qe");
} break;
case OUT_FIELD_VOLTAGE: {
m_ioNodeType = Node::NODE_IN;
return _("Vf");
} break;
case OUT_MEC_POWER: {
m_ioNodeType = Node::NODE_IN;
return _("Pm");
} break;
}
return "";
}
void IOControl::SetValue(IOFlags value)
{
m_value = value;
wxString text = GenerateText();
wxFont font(m_fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxScreenDC dc;
if(m_glStringValue) {
delete m_glStringValue;
m_glStringValue = NULL;
}
m_glStringValue = new wxGLString(text);
m_glStringValue->setFont(font);
m_glStringValue->consolidate(&dc);
m_width = m_glStringValue->getWidth() + 10 + 2 * m_borderSize;
m_height = m_glStringValue->getheight() + 10 + 2 * m_borderSize;
SetPosition(m_position); // Update rectangle.
UpdatePoints();
}
void IOControl::UpdatePoints()
{
if(m_nodeList.size() != 0) {
Node* node = m_nodeList[0];
if(node->GetNodeType() != m_ioNodeType) {
// Rotate 180 degrees
node->Rotate();
node->Rotate();
}
node->SetNodeType(m_ioNodeType);
if(m_angle == 0.0) {
if(m_ioNodeType == Node::NODE_IN)
node->SetPosition(m_position + wxPoint2DDouble(-m_width / 2, 0));
else
node->SetPosition(m_position + wxPoint2DDouble(m_width / 2 - 2, 0));
} else if(m_angle == 90.0) {
if(m_ioNodeType == Node::NODE_IN)
node->SetPosition(m_position + wxPoint2DDouble(0, -m_height / 2));
else
node->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2 - 2));
} else if(m_angle == 180.0) {
if(m_ioNodeType == Node::NODE_IN)
node->SetPosition(m_position + wxPoint2DDouble(m_width / 2, 0));
else
node->SetPosition(m_position + wxPoint2DDouble(2 - m_width / 2, 0));
} else if(m_angle == 270.0) {
if(m_ioNodeType == Node::NODE_IN)
node->SetPosition(m_position + wxPoint2DDouble(0, m_height / 2));
else
node->SetPosition(m_position + wxPoint2DDouble(0, 2 - m_height / 2));
}
}
}
Element* IOControl::GetCopy()
{
IOControl* copy = new IOControl(m_ioFlags, m_elementID);
*copy = *this;
m_glStringValue = NULL;
SetValue(m_value);
return copy;
}
|