author | etisserant |
Thu, 13 Sep 2007 10:23:44 +0200 | |
changeset 37 | 625f52bba682 |
parent 20 | d3cb5020997b |
child 38 | 8cb20bc13a91 |
permissions | -rw-r--r-- |
20 | 1 |
import os, sys |
2 |
base_folder = os.path.split(sys.path[0])[0] |
|
3 |
sys.path.append(os.path.join(base_folder, "wxsvg", "defeditor")) |
|
4 |
||
37 | 5 |
from DEFControler import * |
6 |
from defeditor import * |
|
7 |
from FBD_Objects import * |
|
11 | 8 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
9 |
class _EditorFramePlug(EditorFrame): |
37 | 10 |
""" |
11 |
This Class add IEC specific features to the SVGUI DEFEditor : |
|
12 |
- FDB preview |
|
13 |
- FBD begin drag |
|
14 |
""" |
|
15 |
def __init__(self,controller): |
|
16 |
EditorFrame.__init__(self,controller) |
|
17 |
self.FbdWindow = wx.Panel(name='fbdwindow',parent=self.EditorPanel, |
|
18 |
pos=wx.Point(300, 355),size=wx.Size(240, 240), |
|
19 |
style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER) |
|
20 |
self.FbdWindow.SetBackgroundColour(wxColour(255,255,255)) |
|
21 |
self.FbdWindow.Bind(wx.EVT_LEFT_DOWN, self.OnFbdClick) |
|
22 |
wx.EVT_PAINT(self.FbdWindow,self.OnPaintFBD) |
|
23 |
||
24 |
self.FbdData = None |
|
25 |
self.RefreshProjectTree() |
|
26 |
if (controller.SvgFilepath): |
|
27 |
self.OpenSVGFile(controller.filepath) |
|
28 |
self.mySVGctrl.Refresh() |
|
29 |
self.OnNewFile() |
|
30 |
self.RefreshFBD() |
|
31 |
||
32 |
def SetFbdDragData(self,selected_type): |
|
33 |
self.FbdBlock = FBD_Block(parent=self.FbdWindow,type=selected_type,name='') |
|
34 |
name = self.Controler.GetSelectedElementName() |
|
35 |
self.FbdData = str((selected_type,"functionBlock", name)) |
|
36 |
||
37 |
def RefreshFBD(self): |
|
38 |
dc = wx.ClientDC(self.FbdWindow) |
|
39 |
dc.Clear() |
|
40 |
if self.Controler.HasOpenedProject(): |
|
41 |
selected_type = self.Controler.GetSelectedElementType() |
|
42 |
if selected_type: |
|
43 |
self.SetFbdDragData(selected_type) |
|
44 |
self.FbdBlock = FBD_Block(parent=self.FbdWindow,type=selected_type,name='') |
|
45 |
width,height = self.FbdBlock.GetMinSize() |
|
46 |
self.FbdBlock.SetSize(width,height) |
|
47 |
clientsize = self.FbdWindow.GetClientSize() |
|
48 |
x = (clientsize.width - width) / 2 |
|
49 |
y = (clientsize.height - height) / 2 |
|
50 |
self.FbdBlock.SetPosition(x, y) |
|
51 |
self.FbdBlock.Draw(dc) |
|
52 |
||
53 |
def OnPaintFBD(self,event): |
|
54 |
self.RefreshFBD() |
|
55 |
event.Skip() |
|
56 |
||
57 |
def OnFbdClick(self,event): |
|
58 |
if self.FbdData: |
|
59 |
data = wx.TextDataObject(self.FbdData) |
|
60 |
DropSrc = wx.DropSource(self.FbdWindow) |
|
61 |
DropSrc.SetData(data) |
|
62 |
DropSrc.DoDragDrop() |
|
63 |
||
64 |
def OnProjectTreeItemSelected(self,event): |
|
65 |
EditorFrame.OnProjectTreeItemSelected(self,event) |
|
66 |
self.RefreshFBD() |
|
67 |
||
68 |
def OnNew(self,event): |
|
69 |
EditorFrame.OnNew(self,event) |
|
70 |
self.RefreshFBD() |
|
71 |
||
72 |
def OnOpen(self,event): |
|
73 |
EditorFrame.OnOpen(self,event) |
|
74 |
self.RefreshFBD() |
|
75 |
||
76 |
def OnGenerate(self,event): |
|
77 |
self.SaveProject() |
|
78 |
self.Controler.PlugGenerate_C(sys.path[0],(0,0,4,5),None) |
|
79 |
event.Skip() |
|
80 |
||
12 | 81 |
def OnClose(self, event): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
82 |
self.OnPlugClose() |
12 | 83 |
event.Skip() |
37 | 84 |
|
85 |
""" |
|
86 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
|
87 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L", |
|
88 |
"STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"} |
|
89 |
""" |
|
90 |
TYPECONVERSION = {"BOOL" : "X", "UINT" : "W","REAL" : "D","STRING" : "B"} |
|
91 |
CTYPECONVERSION = {"BOOL" : "bool", "UINT" : "unsigned int", "STRING" : "char*", "REAL" : "float"} |
|
92 |
CPRINTTYPECONVERSION = {"BOOL" : "d", "UINT" : "d", "STRING" : "s", "REAL" : "f"} |
|
93 |
class RootClass(DEFControler): |
|
94 |
||
12 | 95 |
def __init__(self, buspath): |
37 | 96 |
DEFControler.__init__(self) |
97 |
filepath = os.path.join(self.PlugPath(), "gui.def") |
|
98 |
||
12 | 99 |
if os.path.isfile(filepath): |
37 | 100 |
svgfile = os.path.join(self.PlugPath(), "gui.svg") |
101 |
if os.path.isfile(svgfile): |
|
102 |
self.SvgFilepath = svgfile |
|
12 | 103 |
self.OpenXMLFile(filepath) |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
104 |
else: |
12 | 105 |
self.CreateRootElement() |
106 |
self.SetFilePath(filepath) |
|
107 |
||
37 | 108 |
def OnPlugSave(self): |
12 | 109 |
self.SaveXMLFile() |
110 |
return True |
|
37 | 111 |
|
112 |
def GenerateProgramHeadersPublicVars(self): |
|
113 |
fct = "" |
|
114 |
fct += " void OnPlcOutEvent(wxEvent& event);\n\n" |
|
115 |
fct += " void IN_"+self.BusNumber+"();\n" |
|
116 |
fct += " void OUT_"+self.BusNumber+"();\n" |
|
117 |
fct += " void Initialize();\n" |
|
118 |
fct += " void SetNoChanges();\n" |
|
119 |
fct += " void Print();\n" |
|
120 |
return fct |
|
121 |
||
122 |
def GenerateProgramHeadersPrivateVars(self): |
|
123 |
text = "" |
|
124 |
elementsTab = self.GetElementsTab() |
|
125 |
for element in elementsTab: |
|
126 |
infos = element.getElementAttributes() |
|
127 |
for info in infos: |
|
128 |
if info["name"] == "id": |
|
129 |
element_id = str(info["value"]) |
|
130 |
text += " bool flag_"+element_id+";\n" |
|
131 |
text += " volatile int step_"+element_id+";\n" |
|
132 |
text +="\n" |
|
133 |
#Declaration des variables |
|
134 |
for element in elementsTab: |
|
135 |
infos = element.getElementAttributes() |
|
136 |
for info in infos: |
|
137 |
if info["name"] == "id": |
|
138 |
element_id = str(info["value"]) |
|
139 |
type = element.GetElementInfos()["type"] |
|
140 |
FbdBlock = self.GetBlockType(type) |
|
141 |
element_num_patte = 1 |
|
142 |
for input in FbdBlock["inputs"]: |
|
143 |
element_type = TYPECONVERSION[input[1]] |
|
144 |
element_c_type = CTYPECONVERSION[input[1]] |
|
145 |
line = "__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)+";\n" |
|
146 |
text += " "+element_c_type+" "+line |
|
147 |
text += " "+element_c_type+" _copy"+line |
|
148 |
element_num_patte +=1 |
|
149 |
element_num_patte = 1 |
|
150 |
for output in FbdBlock["outputs"]: |
|
151 |
element_type = TYPECONVERSION[output[1]] |
|
152 |
element_c_type = CTYPECONVERSION[output[1]] |
|
153 |
||
154 |
line = "__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)+";\n" |
|
155 |
text += " "+element_c_type+" "+line |
|
156 |
text += " "+element_c_type+" _copy"+line |
|
157 |
element_num_patte +=1 |
|
158 |
text +="\n" |
|
159 |
return text |
|
160 |
||
161 |
def GenerateGlobalVarsAndFuncs(self): |
|
162 |
text = "" |
|
163 |
text += "IMPLEMENT_APP_NO_MAIN(SVGViewApp);\n" |
|
164 |
text += "IMPLEMENT_WX_THEME_SUPPORT;\n" |
|
165 |
text += "SVGViewApp *myapp;\n" |
|
166 |
text += "pthread_t wxMainLoop,automate;\n" |
|
167 |
text += "int myargc;\n" |
|
168 |
text += "char** myargv;\n\n" |
|
169 |
||
170 |
text += "#define FREE_AND_NO_CHANGES 1 \n" |
|
171 |
text += "#define PLC_BUSY 2 \n" |
|
172 |
text += "#define FREE_AND_CHANGES 3 \n" |
|
173 |
text += "#define PLC_OUT_BUSY 4 \n\n" |
|
174 |
||
175 |
||
176 |
text += "void* InitWxEntry(void* args)\n{\n" |
|
177 |
text += " wxEntry(myargc,myargv);\n" |
|
178 |
text += " return args;\n" |
|
179 |
text += "}\n\n" |
|
180 |
||
181 |
text += "void* SimulAutomate(void* args)\n{\n" |
|
182 |
text += " while(1){\n" |
|
183 |
text += " myapp->frame->m_svgCtrl->IN_"+self.BusNumber+"();\n" |
|
184 |
text += " //printf(\"AUTOMATE\\n\");\n" |
|
185 |
text += " myapp->frame->m_svgCtrl->OUT_"+self.BusNumber+"();\n" |
|
186 |
text += " sleep(1);\n" |
|
187 |
text += " }\n" |
|
188 |
text += " return args;\n" |
|
189 |
text += "}\n\n" |
|
190 |
||
191 |
if (self.SVGUIRootElement): |
|
192 |
width = self.SVGUIRootElement.GetBBox().GetWidth() |
|
193 |
height = self.SVGUIRootElement.GetBBox().GetHeight() |
|
194 |
else : |
|
195 |
width = 250 |
|
196 |
height = 350 |
|
197 |
text += "bool SVGViewApp::OnInit()\n{\n" |
|
198 |
text += " #ifndef __WXMSW__\n" |
|
199 |
text += " setlocale(LC_NUMERIC, \"C\");\n" |
|
200 |
text += " #endif\n" |
|
201 |
text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize((int)"+str(width)+", (int)"+str(height)+"));\n" |
|
202 |
text += " myapp = this;\n" |
|
203 |
text += " pthread_create(&automate, NULL, SimulAutomate, NULL);\n" |
|
204 |
text += " return true;\n" |
|
205 |
text += "}\n\n" |
|
206 |
||
207 |
text += "int main(int argc, char** argv)\n{\n" |
|
208 |
text += " myargc = argc;\n" |
|
209 |
text += " myargv = argv;\n" |
|
210 |
text += " pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);\n" |
|
211 |
text += " pause();\n" |
|
212 |
text += "}\n\n" |
|
213 |
||
214 |
return text |
|
215 |
||
216 |
def GenerateProgramEventTable(self): |
|
217 |
evt = "" |
|
218 |
elementsTab = self.GetElementsTab() |
|
219 |
#evt += "wxEVT_PLCOUT = wxNewEventType();\n\n"; |
|
220 |
evt += "BEGIN_DECLARE_EVENT_TYPES()\n" |
|
221 |
evt += "DECLARE_LOCAL_EVENT_TYPE( EVT_PLC, wxNewEventType() )\n" |
|
222 |
evt += "END_DECLARE_EVENT_TYPES()\n\n" |
|
223 |
||
224 |
evt += "DEFINE_LOCAL_EVENT_TYPE( EVT_PLC )\n\n" |
|
225 |
#Event Table Declaration |
|
226 |
evt += "BEGIN_EVENT_TABLE(Program, SVGUIWindow)\n" |
|
227 |
for element in elementsTab: |
|
228 |
infos = element.getElementAttributes() |
|
229 |
for info in infos: |
|
230 |
if info["name"] == "id": |
|
231 |
element_id = str(info["value"]) |
|
232 |
if info["name"] == "name": |
|
233 |
element_name = str(info["value"]) |
|
234 |
type = element.GetElementInfos()["type"] |
|
235 |
if type == "Button": |
|
236 |
evt += " EVT_BUTTON (SVGUIID(\""+element_id+"\"), Program::On"+element_name+"Click)\n" |
|
237 |
elif type == "ScrollBar": |
|
238 |
pass |
|
239 |
#evt += " EVT_LEFT_UP (Program::OnClick)\n" |
|
240 |
#evt += " EVT_COMMAND_SCROLL_THUMBTRACK (SVGUIID(\""+element_id+"\"), Program::On"+element_name+"Changed)\n" |
|
241 |
elif type == "RotatingCtrl": |
|
242 |
evt += " EVT_COMMAND_SCROLL_THUMBTRACK (SVGUIID(\""+element_id+"\"), Program::On"+element_name+"Changed)\n" |
|
243 |
elif type == "NoteBook": |
|
244 |
evt += " EVT_NOTEBOOK_PAGE_CHANGED (SVGUIID(\""+element_id+"\"), Program::On"+element_name+"TabChanged)\n" |
|
245 |
elif type == "Container" or type == "Transform": |
|
246 |
evt += " EVT_PAINT(Program::On"+element_name+"Paint)\n" |
|
247 |
evt += " EVT_LEFT_UP (Program::OnClick)\n" |
|
248 |
evt += " EVT_CUSTOM( EVT_PLC, wxID_ANY, Program::OnPlcOutEvent )\n" |
|
249 |
evt += "END_EVENT_TABLE()\n\n" |
|
250 |
return evt |
|
251 |
||
252 |
def GenerateProgramInitFrame(self): |
|
253 |
text = "MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,const wxSize& size, long style): wxFrame(parent, wxID_ANY, title, pos, size, style)\n{\n" |
|
254 |
text += " m_svgCtrl = new Program(this);\n" |
|
255 |
text += " if (m_svgCtrl->LoadFiles(wxT(\""+self.SvgFilepath+"\"), wxT(\""+self.filepath+"\")))\n" |
|
256 |
text += " {\n" |
|
257 |
text += " Show(true);\n" |
|
258 |
text += " m_svgCtrl->SetFocus();\n" |
|
259 |
text += " m_svgCtrl->SetFitToFrame(true);\n" |
|
260 |
text += " m_svgCtrl->RefreshScale();\n" |
|
261 |
text += " m_svgCtrl->InitScrollBars();\n" |
|
262 |
text += " m_svgCtrl->Initialize();\n" |
|
263 |
text += " m_svgCtrl->Update();\n" |
|
264 |
text += " //m_svgCtrl->Print();\n" |
|
265 |
text += " }\n" |
|
266 |
text += " else\n" |
|
267 |
text += " {\n" |
|
268 |
text += " printf(\"Error while opening files\\n\");\n" |
|
269 |
text += " exit(0);\n" |
|
270 |
text += " }\n" |
|
271 |
text += "}\n\n\n" |
|
272 |
return text |
|
273 |
||
274 |
def GenerateProgramInitProgram(self): |
|
275 |
elementsTab = self.GetElementsTab() |
|
276 |
text = "Program::Program(wxWindow* parent):SVGUIWindow(parent)\n{\n" |
|
277 |
for element in elementsTab: |
|
278 |
infos = element.getElementAttributes() |
|
279 |
for info in infos: |
|
280 |
if info["name"] == "id": |
|
281 |
element_id = str(info["value"]) |
|
282 |
text += " flag_"+element_id+" = true;\n" |
|
283 |
text += " step_"+element_id+" = FREE_AND_NO_CHANGES;\n" |
|
284 |
text += "}\n\n" |
|
285 |
return text |
|
286 |
||
287 |
def GenerateProgramEventFunctions(self): |
|
288 |
fct="" |
|
289 |
elementsTab = self.GetElementsTab() |
|
290 |
for element in elementsTab: |
|
291 |
infos = element.getElementAttributes() |
|
292 |
for info in infos: |
|
293 |
if info["name"] == "id": |
|
294 |
element_id = str(info["value"]) |
|
295 |
if info["name"] == "name": |
|
296 |
element_name = str(info["value"]) |
|
297 |
type = element.GetElementInfos()["type"] |
|
298 |
FbdBlock = self.GetBlockType(type) |
|
299 |
if type == "Button": |
|
300 |
fct += "void Program::On"+element_name+"Click(wxCommandEvent& event)\n{\n" |
|
301 |
fct += " if (flag_"+element_id+")\n {\n" |
|
302 |
fct += " flag_"+element_id+" = false;\n" |
|
303 |
element_num_patte = 1 |
|
304 |
for output in FbdBlock["outputs"]: |
|
305 |
element_type = TYPECONVERSION[output[1]] |
|
306 |
fct += " _copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)+" = true;\n" |
|
307 |
element_num_patte +=1 |
|
308 |
fct += " flag_"+element_id+" = true;\n" |
|
309 |
fct += " }\n" |
|
310 |
fct += " event.Skip();\n" |
|
311 |
fct += "}\n\n" |
|
312 |
||
313 |
elif type == "RotatingCtrl": |
|
314 |
fct += "void Program::On"+element_name+"Changed(wxScrollEvent& event)\n{\n" |
|
315 |
fct += " SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
316 |
fct += " rotating->SendScrollEvent(event);\n" |
|
317 |
fct += " double angle = rotating->GetAngle();\n" |
|
318 |
fct += " if (flag_"+element_id+")\n {\n" |
|
319 |
fct += " flag_"+element_id+" = false;\n" |
|
320 |
element_num_patte = 1 |
|
321 |
for output in FbdBlock["outputs"]: |
|
322 |
element_type = TYPECONVERSION[output[1]] |
|
323 |
||
324 |
if element_num_patte == 1: |
|
325 |
value = "angle" |
|
326 |
elif element_num_patte == 2: |
|
327 |
value = "true" |
|
328 |
fct += " _copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)+" = "+value+";\n" |
|
329 |
element_num_patte +=1 |
|
330 |
fct += " flag_"+element_id+" = true;\n" |
|
331 |
fct += " }\n" |
|
332 |
fct += "}\n\n" |
|
333 |
elif type == "NoteBook": |
|
334 |
fct += "void Program::On"+element_name+"TabChanged(wxNotebookEvent& event)\n{\n" |
|
335 |
fct += " SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
336 |
fct += " notebook->SendNotebookEvent(event);\n" |
|
337 |
fct += " unsigned int selected = notebook->GetCurrentPage();\n" |
|
338 |
fct += " if (flag_"+element_id+")\n {\n" |
|
339 |
fct += " flag_"+element_id+" = false;\n" |
|
340 |
element_num_patte = 1 |
|
341 |
for output in FbdBlock["outputs"]: |
|
342 |
element_type = TYPECONVERSION[output[1]] |
|
343 |
||
344 |
if element_num_patte == 1: |
|
345 |
value = "selected" |
|
346 |
elif element_num_patte == 2: |
|
347 |
value = "true" |
|
348 |
fct += " _copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)+" = "+value+";\n" |
|
349 |
element_num_patte +=1 |
|
350 |
fct += " flag_"+element_id+" = true;\n" |
|
351 |
fct += " }\n" |
|
352 |
fct += "}\n\n" |
|
353 |
elif type == "Transform": |
|
354 |
fct += "void Program::On"+element_name+"Paint(wxPaintEvent& event)\n{\n" |
|
355 |
fct += " SVGUITransform* transform = (SVGUITransform*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
356 |
fct += " if (flag_"+element_id+")\n {\n" |
|
357 |
fct += " flag_"+element_id+" = false;\n" |
|
358 |
element_num_patte = 1 |
|
359 |
for output in FbdBlock["outputs"]: |
|
360 |
if element_num_patte == 1: |
|
361 |
fct += " if (transform->GetX() != _copy__QD"+self.BusNumber+"_"+element_id+"_1)\n" |
|
362 |
fct += " {\n" |
|
363 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_1 = transform->GetX();\n" |
|
364 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n" |
|
365 |
fct += " }\n" |
|
366 |
elif element_num_patte == 2: |
|
367 |
fct += " if (transform->GetY() != _copy__QD"+self.BusNumber+"_"+element_id+"_2)\n" |
|
368 |
fct += " {\n" |
|
369 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_2 = transform->GetY();\n" |
|
370 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n" |
|
371 |
fct += " }\n" |
|
372 |
elif element_num_patte == 3: |
|
373 |
fct += " if (transform->GetXScale() != _copy__QD"+self.BusNumber+"_"+element_id+"_3)\n" |
|
374 |
fct += " {\n" |
|
375 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_3 = transform->GetXScale();\n" |
|
376 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n" |
|
377 |
fct += " }\n" |
|
378 |
elif element_num_patte == 4: |
|
379 |
fct += " if (transform->GetYScale() != _copy__QD"+self.BusNumber+"_"+element_id+"_4)\n" |
|
380 |
fct += " {\n" |
|
381 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_4 = transform->GetYScale();\n" |
|
382 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n" |
|
383 |
fct += " }\n" |
|
384 |
elif element_num_patte == 5: |
|
385 |
fct += " if (transform->GetAngle() != _copy__QD"+self.BusNumber+"_"+element_id+"_5)\n" |
|
386 |
fct += " {\n" |
|
387 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_5 = transform->GetAngle();\n" |
|
388 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n" |
|
389 |
fct += " }\n" |
|
390 |
element_num_patte +=1 |
|
391 |
fct += " flag_"+element_id+" = true;\n" |
|
392 |
fct += " }\n" |
|
393 |
fct += " event.Skip();\n" |
|
394 |
fct += "}\n\n" |
|
395 |
elif type == "Container": |
|
396 |
fct += "void Program::On"+element_name+"Paint(wxPaintEvent& event)\n{\n" |
|
397 |
fct += " SVGUIContainer* container = (SVGUIContainer*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
398 |
fct += " if (container->IsVisible() != _copy__QX"+self.BusNumber+"_"+element_id+"_1 && flag_"+element_id+")\n" |
|
399 |
fct += " {\n" |
|
400 |
fct += " flag_"+element_id+" = false;\n" |
|
401 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_1 = container->IsVisible();\n" |
|
402 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n" |
|
403 |
fct += " flag_"+element_id+" = true;\n" |
|
404 |
fct += " }\n" |
|
405 |
fct += " event.Skip();\n" |
|
406 |
fct += "}\n\n" |
|
407 |
||
408 |
fct += "void Program::OnChar(wxKeyEvent& event)\n{\n" |
|
409 |
fct += " SVGUIContainer* container = GetSVGUIRootElement();\n" |
|
410 |
fct += " if (container->GetFocusedElementName() == wxT(\"TextCtrl\"))\n" |
|
411 |
fct += " {\n" |
|
412 |
fct += " wxString focusedId = container->GetFocusedElement();\n" |
|
413 |
fct += " SVGUITextCtrl* text = (SVGUITextCtrl*)GetElementById(container->GetFocusedElement());\n" |
|
414 |
fct += " text->SendKeyEvent(event);\n" |
|
415 |
for element in elementsTab: |
|
416 |
infos = element.getElementAttributes() |
|
417 |
for info in infos: |
|
418 |
if info["name"] == "id": |
|
419 |
element_id = str(info["value"]) |
|
420 |
type = element.GetElementInfos()["type"] |
|
421 |
FbdBlock = self.GetBlockType(type) |
|
422 |
if type == "TextCtrl": |
|
423 |
fct += " if (focusedId == wxT(\""+element_id+"\") && flag_"+element_id+")\n" |
|
424 |
fct += " {\n" |
|
425 |
fct += " flag_"+element_id+" = false;\n" |
|
426 |
fct += " _copy__QB"+self.BusNumber+"_"+element_id+"_1 = wxStringToStr(text->GetValue());\n" |
|
427 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n" |
|
428 |
fct += " flag_"+element_id+" = true;\n" |
|
429 |
fct += " }\n" |
|
430 |
fct += " }\n" |
|
431 |
fct += "}\n" |
|
432 |
||
433 |
||
434 |
||
435 |
fct += "void Program::OnClick(wxMouseEvent& event)\n{\n" |
|
436 |
fct += " SVGUIContainer* container = GetSVGUIRootElement();\n" |
|
437 |
fct += " if (container->GetFocusedElementName() == wxT(\"ScrollBar\"))\n" |
|
438 |
fct += " {\n" |
|
439 |
fct += " wxString focusedId = container->GetFocusedElement();\n" |
|
440 |
fct += " SVGUIScrollBar* scrollbar = (SVGUIScrollBar*)GetElementById(focusedId);\n" |
|
441 |
fct += " scrollbar->SendMouseEvent(event);\n" |
|
442 |
for element in elementsTab: |
|
443 |
infos = element.getElementAttributes() |
|
444 |
for info in infos: |
|
445 |
if info["name"] == "id": |
|
446 |
element_id = str(info["value"]) |
|
447 |
type = element.GetElementInfos()["type"] |
|
448 |
FbdBlock = self.GetBlockType(type) |
|
449 |
if type == "ScrollBar": |
|
450 |
fct += " if (focusedId == wxT(\""+element_id+"\") && flag_"+element_id+")\n" |
|
451 |
fct += " {\n" |
|
452 |
fct += " flag_"+element_id+" = false;\n" |
|
453 |
fct += " unsigned int scrollPos = scrollbar->GetThumbPosition();\n" |
|
454 |
fct += " _copy__QW"+self.BusNumber+"_"+element_id+"_1 = scrollPos;\n" |
|
455 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n" |
|
456 |
fct += " flag_"+element_id+" = true;\n" |
|
457 |
fct += " }\n" |
|
458 |
fct += " }\n" |
|
459 |
fct += " event.Skip();\n" |
|
460 |
fct += "}\n" |
|
461 |
||
462 |
||
463 |
||
464 |
||
465 |
fct += "void Program::OnPlcOutEvent(wxEvent& event)\n{\n" |
|
466 |
fct += " int old_state;\n" |
|
467 |
for element in elementsTab: |
|
468 |
infos = element.getElementAttributes() |
|
469 |
for info in infos: |
|
470 |
if info["name"] == "id": |
|
471 |
element_id = str(info["value"]) |
|
472 |
type = element.GetElementInfos()["type"] |
|
473 |
FbdBlock = self.GetBlockType(type) |
|
474 |
if type == "Button": |
|
475 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
476 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
477 |
fct += " {\n" |
|
478 |
fct += " flag_"+element_id+" = false;\n" |
|
479 |
fct += " SVGUIButton* button = (SVGUIButton*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
480 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_1)\n" |
|
481 |
fct += " button->Show();\n" |
|
482 |
fct += " else\n" |
|
483 |
fct += " button->Hide();\n" |
|
484 |
fct += " flag_"+element_id+" = true;\n" |
|
485 |
fct += " }\n" |
|
486 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
487 |
elif type == "Container": |
|
488 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
489 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
490 |
fct += " {\n" |
|
491 |
fct += " flag_"+element_id+" = false;\n" |
|
492 |
fct += " SVGUIContainer* container = (SVGUIContainer*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
493 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_1)\n" |
|
494 |
fct += " container->Show();\n" |
|
495 |
fct += " else\n" |
|
496 |
fct += " container->Hide();\n" |
|
497 |
fct += " flag_"+element_id+" = true;\n" |
|
498 |
fct += " }\n" |
|
499 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
500 |
elif type == "TextCtrl": |
|
501 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
502 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
503 |
fct += " {\n" |
|
504 |
fct += " flag_"+element_id+" = false;\n" |
|
505 |
fct += " SVGUITextCtrl* text = (SVGUITextCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
506 |
fct += " wxString str = wxString::FromAscii(_copy__IB"+self.BusNumber+"_"+element_id+"_1);\n" |
|
507 |
fct += " text->SetText(str);\n" |
|
508 |
fct += " flag_"+element_id+" = true;\n" |
|
509 |
fct += " }\n" |
|
510 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
511 |
elif type == "ScrollBar": |
|
512 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
513 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
514 |
fct += " {\n" |
|
515 |
fct += " flag_"+element_id+" = false;\n" |
|
516 |
fct += " SVGUIScrollBar* scrollbar = (SVGUIScrollBar*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
517 |
fct += " scrollbar->SetThumbPosition(_copy__IW"+self.BusNumber+"_"+element_id+"_1);\n" |
|
518 |
fct += " flag_"+element_id+" = true;\n" |
|
519 |
fct += " }\n" |
|
520 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
521 |
elif type == "RotatingCtrl": |
|
522 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
523 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
524 |
fct += " {\n" |
|
525 |
fct += " flag_"+element_id+" = false;\n" |
|
526 |
fct += " SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
527 |
fct += " rotating->SetAngle(_copy__ID"+self.BusNumber+"_"+element_id+"_1);\n" |
|
528 |
fct += " flag_"+element_id+" = true;\n" |
|
529 |
fct += " }\n" |
|
530 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
531 |
elif type == "NoteBook": |
|
532 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
533 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_2 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
534 |
fct += " {\n" |
|
535 |
fct += " flag_"+element_id+" = false;\n" |
|
536 |
fct += " SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
537 |
fct += " notebook->SetCurrentPage(_copy__IB"+self.BusNumber+"_"+element_id+"_1);\n" |
|
538 |
fct += " flag_"+element_id+" = true;\n" |
|
539 |
fct += " }\n" |
|
540 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
541 |
elif type == "Transform": |
|
542 |
fct += " old_state = __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_CHANGES, PLC_OUT_BUSY);\n" |
|
543 |
fct += " if (_copy__IX"+self.BusNumber+"_"+element_id+"_6 && flag_"+element_id+" && old_state == FREE_AND_CHANGES)\n" |
|
544 |
fct += " {\n" |
|
545 |
fct += " flag_"+element_id+" = false;\n" |
|
546 |
fct += " SVGUITransform* transform = (SVGUITransform*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
547 |
fct += " transform->Move(_copy__ID"+self.BusNumber+"_"+element_id+"_1,_copy__ID"+self.BusNumber+"_"+element_id+"_2);\n" |
|
548 |
fct += " transform->Scale(_copy__ID"+self.BusNumber+"_"+element_id+"_3,_copy__ID"+self.BusNumber+"_"+element_id+"_4);\n" |
|
549 |
fct += " transform->Rotate(_copy__ID"+self.BusNumber+"_"+element_id+"_5);\n" |
|
550 |
fct += " flag_"+element_id+" = true;\n" |
|
551 |
fct += " }\n" |
|
552 |
fct += " __sync_val_compare_and_swap (&step_"+element_id+", PLC_OUT_BUSY, FREE_AND_NO_CHANGES);\n" |
|
553 |
fct += " Update_Elements();\n" |
|
554 |
fct += " Refresh();\n" |
|
555 |
fct += " event.Skip();\n" |
|
556 |
fct += "}\n\n" |
|
557 |
return fct |
|
558 |
||
559 |
def GenerateProgramPrivateFunctions(self): |
|
560 |
elementsTab = self.GetElementsTab() |
|
561 |
fct = "void Program::OUT_"+self.BusNumber+"()\n{\n" |
|
562 |
for element in elementsTab: |
|
563 |
infos = element.getElementAttributes() |
|
564 |
for info in infos: |
|
565 |
if info["name"] == "id": |
|
566 |
element_id = str(info["value"]) |
|
567 |
type = element.GetElementInfos()["type"] |
|
568 |
FbdBlock = self.GetBlockType(type) |
|
569 |
fct += " if ( flag_"+element_id+" && __sync_val_compare_and_swap (&step_"+element_id+", PLC_BUSY, FREE_AND_CHANGES) == PLC_BUSY){\n" |
|
570 |
#fct += " if ( flag_"+element_id+" ){\n" |
|
571 |
fct += " flag_"+element_id+" = false;\n" |
|
572 |
element_num_patte = 1 |
|
573 |
for input in FbdBlock["inputs"]: |
|
574 |
element_type = TYPECONVERSION[input[1]] |
|
575 |
var = "__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
|
576 |
fct +=" _copy"+var+ " = "+var+";\n" |
|
577 |
element_num_patte +=1 |
|
578 |
fct += " flag_"+element_id+" = true;\n" |
|
579 |
fct += " }\n" |
|
580 |
fct +=" wxCommandEvent event( EVT_PLC );\n" |
|
581 |
fct +=" ProcessEvent(event);\n" |
|
582 |
fct +="};\n\n" |
|
583 |
||
584 |
fct += "void Program::IN_"+self.BusNumber+"()\n{\n" |
|
585 |
||
586 |
for element in elementsTab: |
|
587 |
infos = element.getElementAttributes() |
|
588 |
for info in infos: |
|
589 |
if info["name"] == "id": |
|
590 |
element_id = str(info["value"]) |
|
591 |
type = element.GetElementInfos()["type"] |
|
592 |
FbdBlock = self.GetBlockType(type) |
|
593 |
fct += " if ( flag_"+element_id+" && __sync_val_compare_and_swap (&step_"+element_id+", FREE_AND_NO_CHANGES, PLC_BUSY) == FREE_AND_NO_CHANGES){\n" |
|
594 |
fct += " flag_"+element_id+" = false;\n" |
|
595 |
element_num_patte = 1 |
|
596 |
for output in FbdBlock["outputs"]: |
|
597 |
element_type = TYPECONVERSION[output[1]] |
|
598 |
var = "__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
|
599 |
fct +=" "+var+ " = _copy"+var+";\n" |
|
600 |
element_num_patte +=1 |
|
601 |
fct += " flag_"+element_id+" = true;\n" |
|
602 |
fct += " }\n" |
|
603 |
fct += " SetNoChanges();\n" |
|
604 |
fct +="};\n\n" |
|
605 |
||
606 |
fct += "void Program::Initialize()\n{\n" |
|
607 |
button = False |
|
608 |
container = False |
|
609 |
textctrl = False |
|
610 |
scrollbar = False |
|
611 |
rotatingctrl = False |
|
612 |
notebook = False |
|
613 |
transform = False |
|
614 |
for element in elementsTab: |
|
615 |
infos = element.getElementAttributes() |
|
616 |
for info in infos: |
|
617 |
if info["name"] == "id": |
|
618 |
element_id = str(info["value"]) |
|
619 |
type = element.GetElementInfos()["type"] |
|
620 |
FbdBlock = self.GetBlockType(type) |
|
621 |
if type == "Button": |
|
622 |
if (not button): |
|
623 |
fct += " SVGUIButton* button;\n" |
|
624 |
fct += " button = (SVGUIButton*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
625 |
fct += " if (button->IsVisible())\n" |
|
626 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_1 = true;\n" |
|
627 |
fct += " else\n" |
|
628 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_1 = false;\n" |
|
629 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
630 |
button = True |
|
631 |
elif type == "Container": |
|
632 |
if (not container): |
|
633 |
fct += " SVGUIContainer* container;\n" |
|
634 |
fct += " container = (SVGUIContainer*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
635 |
fct += " if (container->IsVisible())\n" |
|
636 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_1 = true;\n" |
|
637 |
fct += " else\n" |
|
638 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_1 = false;\n" |
|
639 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
640 |
container = True |
|
641 |
elif type == "TextCtrl": |
|
642 |
if (not textctrl): |
|
643 |
fct += " SVGUITextCtrl* text;\n" |
|
644 |
fct += " text = (SVGUITextCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
645 |
fct += " _copy__QB"+self.BusNumber+"_"+element_id+"_1 = wxStringToStr(text->GetValue());\n" |
|
646 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
647 |
textctrl = True |
|
648 |
elif type == "ScrollBar": |
|
649 |
if (not scrollbar): |
|
650 |
fct += " SVGUIScrollBar* scrollbar;\n" |
|
651 |
fct += " scrollbar = (SVGUIScrollBar*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
652 |
fct += " _copy__QW"+self.BusNumber+"_"+element_id+"_1 = scrollbar->GetThumbPosition();\n" |
|
653 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
654 |
scrollbar = True |
|
655 |
elif type == "RotatingCtrl": |
|
656 |
if (not rotatingctrl): |
|
657 |
fct += " SVGUIRotatingCtrl* rotating;\n" |
|
658 |
fct += " rotating = (SVGUIRotatingCtrl*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
659 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_1 = rotating->GetAngle();\n" |
|
660 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
661 |
rotatingctrl = True |
|
662 |
elif type == "NoteBook": |
|
663 |
if (not notebook): |
|
664 |
fct += " SVGUINoteBook* notebook;\n" |
|
665 |
fct += " notebook = (SVGUINoteBook*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
666 |
fct += " _copy__QB"+self.BusNumber+"_"+element_id+"_1 = notebook->GetCurrentPage();\n" |
|
667 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n" |
|
668 |
notebook = True |
|
669 |
elif type == "Transform": |
|
670 |
if (not transform): |
|
671 |
fct += " SVGUITransform* transform;\n" |
|
672 |
fct += " transform = (SVGUITransform*)GetElementById(wxT(\""+element_id+"\"));\n" |
|
673 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_1 = transform->GetX();\n" |
|
674 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_2 = transform->GetY();\n" |
|
675 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_3 = transform->GetXScale();\n" |
|
676 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_4 = transform->GetYScale();\n" |
|
677 |
fct += " _copy__QD"+self.BusNumber+"_"+element_id+"_5 = transform->GetAngle();\n" |
|
678 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = true;\n\n" |
|
679 |
transform = True |
|
680 |
fct += "}\n\n" |
|
681 |
||
682 |
fct += "void Program::SetNoChanges()\n{\n" |
|
683 |
for element in elementsTab: |
|
684 |
infos = element.getElementAttributes() |
|
685 |
for info in infos: |
|
686 |
if info["name"] == "id": |
|
687 |
element_id = str(info["value"]) |
|
688 |
type = element.GetElementInfos()["type"] |
|
689 |
FbdBlock = self.GetBlockType(type) |
|
690 |
if type == "Button": |
|
691 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
692 |
elif type == "Container": |
|
693 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
694 |
elif type == "TextCtrl": |
|
695 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
696 |
elif type == "ScrollBar": |
|
697 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
698 |
elif type == "RotatingCtrl": |
|
699 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
700 |
elif type == "NoteBook": |
|
701 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_2 = false;\n" |
|
702 |
elif type == "Transform": |
|
703 |
fct += " _copy__QX"+self.BusNumber+"_"+element_id+"_6 = false;\n" |
|
704 |
fct += "}\n\n" |
|
705 |
||
706 |
#DEBUG Fonction d'affichage |
|
707 |
fct += "void Program::Print()\n{\n" |
|
708 |
for element in elementsTab: |
|
709 |
infos = element.getElementAttributes() |
|
710 |
for info in infos: |
|
711 |
if info["name"] == "id": |
|
712 |
element_id = str(info["value"]) |
|
713 |
type = element.GetElementInfos()["type"] |
|
714 |
FbdBlock = self.GetBlockType(type) |
|
715 |
element_num_patte = 1 |
|
716 |
for input in FbdBlock["inputs"]: |
|
717 |
element_type = TYPECONVERSION[input[1]] |
|
718 |
c_type = CPRINTTYPECONVERSION[input[1]] |
|
719 |
var = "_copy__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
|
720 |
fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
|
721 |
element_num_patte +=1 |
|
722 |
element_num_patte = 1 |
|
723 |
for output in FbdBlock["outputs"]: |
|
724 |
element_type = TYPECONVERSION[output[1]] |
|
725 |
c_type = CPRINTTYPECONVERSION[output[1]] |
|
726 |
var = "_copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte) |
|
727 |
fct +=" printf(\""+var+": %"+c_type+"\\n\","+var+");\n" |
|
728 |
element_num_patte +=1 |
|
729 |
#fct +=" wxPostEvent(Program,wxEVT_PLCOUT);\n" |
|
730 |
fct +="};\n\n" |
|
731 |
return fct |
|
732 |
||
733 |
def PlugGenerate_C(self, buildpath, locations, logger): |
|
734 |
current_location = self.GetCurrentLocation() |
|
735 |
self.BusNumber = "_".join(map(lambda x:str(x), current_location)) |
|
736 |
self.GenerateProgram(buildpath) |
|
737 |
Gen_C_file = os.path.join(buildpath, "program.cpp" ) |
|
738 |
return [(Gen_C_file,"")],"" |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
739 |
|
12 | 740 |
def BlockTypesFactory(self): |
741 |
def generate_svgui_block(generator, block, body, link): |
|
742 |
controller = generator.GetController() |
|
743 |
name = block.getInstanceName() |
|
744 |
type = block.getTypeName() |
|
37 | 745 |
block_infos = self.GetBlockType(type) |
12 | 746 |
bus_id, name = [word for word in name.split("_") if word != ""] |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
747 |
block_id = self.PlugChilds[bus_id].GetElementIdFromName(name) |
12 | 748 |
if block_id == None: |
749 |
raise ValueError, "No corresponding block found" |
|
750 |
if not generator.ComputedBlocks.get(name, False): |
|
751 |
for num, variable in enumerate(block.inputVariables.getVariable()): |
|
752 |
connections = variable.connectionPointIn.getConnections() |
|
753 |
if connections and len(connections) == 1: |
|
754 |
parameter = "__I%s%d_%d_%d"%(TYPECONVERSION[block_infos["inputs"][num][1]], bus_id, block_id, num) |
|
755 |
value = generator.ComputeFBDExpression(body, connections[0]) |
|
756 |
generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
|
757 |
generator.ComputedBlocks[name] = True |
|
758 |
if link: |
|
759 |
connectionPoint = link.getPosition()[-1] |
|
760 |
for num, variable in enumerate(block.outputVariables.getVariable()): |
|
761 |
blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
|
762 |
if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
|
763 |
return "__Q%s%d_%d_%d"%(TYPECONVERSION[block_infos["outputs"][num][1]], bus_id, block_id, num) |
|
764 |
raise ValueError, "No output variable found" |
|
765 |
else: |
|
766 |
return None |
|
11 | 767 |
|
12 | 768 |
return [{"name" : "SVGUI function blocks", "list" : |
769 |
[{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
|
37 | 770 |
"inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], |
771 |
"outputs" : [("Show","BOOL","none"),("State Changed","BOOL","none")], |
|
772 |
"comment" : "SVGUI Container"}, |
|
773 |
{"name" : "Button", "type" : "functionBlock", "extensible" : False, |
|
774 |
"inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], |
|
775 |
"outputs" : [("Visible","BOOL","none"),("State","BOOL","none")], |
|
776 |
"comment" : "SVGUI Button"}, |
|
777 |
{"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, |
|
778 |
"inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], |
|
779 |
"outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")], |
|
780 |
"comment" : "SVGUI Text Control"}, |
|
781 |
{"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, |
|
782 |
"inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], |
|
783 |
"outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")], |
|
784 |
"comment" : "SVGUI ScrollBar"}, |
|
785 |
{"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, |
|
786 |
"inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], |
|
787 |
"outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")], |
|
788 |
"comment" : "SVGUI Notebook"}, |
|
789 |
{"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, |
|
790 |
"inputs" : [("Angle","REAL","none"),("Set Angle","BOOL","none")], |
|
791 |
"outputs" : [("Angle","REAL","none"),("Angle changed","BOOL","none")], |
|
792 |
"comment" : "SVGUI Rotating Control"}, |
|
793 |
{"name" : "Transform", "type" : "functionBlock", "extensible" : False, |
|
794 |
"inputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Set","BOOL","none")], |
|
795 |
"outputs" : [("X","REAL","none"),("Y","REAL","none"),("Scale X","REAL","none"),("Scale Y","REAL","none"),("Angle","REAL","none"),("Changed","BOOL","none")], |
|
796 |
"comment" : "SVGUI Transform"}, |
|
797 |
]} |
|
798 |
] |
|
799 |
||
800 |
def GetBlockType(self,type): |
|
801 |
for category in self.BlockTypesFactory(): |
|
802 |
for blocktype in category["list"]: |
|
803 |
if blocktype["name"] == type: |
|
804 |
return blocktype |
|
805 |
return None |
|
806 |
||
807 |
#DEBUG |
|
808 |
if __name__ == '__main__': |
|
809 |
app = wxPySimpleApp() |
|
810 |
wxInitAllImageHandlers() |
|
811 |
||
812 |
# Install a exception handle for bug reports |
|
813 |
#wxAddExceptHook(os.getcwd(),__version__) |
|
814 |
||
815 |
cont = RootClass(sys.path[0]) |
|
816 |
frame = _EditorFramePlug(cont) |
|
817 |
||
818 |
frame.Show() |
|
819 |
app.MainLoop() |
|
820 |
#DEBUG |
|
821 |
||
822 |
||
823 |
||
824 |
||
825 |