114 self.OpenXMLFile(filepath) |
114 self.OpenXMLFile(filepath) |
115 else: |
115 else: |
116 self.CreateNewInterface() |
116 self.CreateNewInterface() |
117 self.SetFilePath(filepath) |
117 self.SetFilePath(filepath) |
118 |
118 |
119 def IsGUIPlugin(self): |
|
120 return True |
|
121 |
|
122 def GetElementIdFromName(self, name): |
119 def GetElementIdFromName(self, name): |
123 element = self.GetElementByName(name) |
120 element = self.GetElementByName(name) |
124 if element is not None: |
121 if element is not None: |
125 return element.getid() |
122 return element.getid() |
126 return None |
123 return None |
127 |
124 |
128 _View = None |
125 _View = None |
129 def _OpenView(self, logger): |
126 def _OpenView(self): |
130 if not self._View: |
127 if not self._View: |
131 def _onclose(): |
128 def _onclose(): |
132 self._View = None |
129 self._View = None |
133 def _onsave(): |
130 def _onsave(): |
134 self.GetPlugRoot().SaveProject() |
131 self.GetPlugRoot().SaveProject() |
135 self._View = _SVGUIEditor(self.GetPlugRoot().AppFrame, self) |
132 self._View = _SVGUIEditor(self.GetPlugRoot().AppFrame, self) |
136 self._View._onclose = _onclose |
133 self._View._onclose = _onclose |
137 self._View._onsave = _onsave |
134 self._View._onsave = _onsave |
138 self._View.Show() |
135 self._View.Show() |
139 |
136 |
140 def _ImportSVG(self, logger): |
137 def _ImportSVG(self): |
141 if not self._View: |
138 if not self._View: |
142 dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a SVG file", os.getcwd(), "", "SVG files (*.svg)|*.svg|All files|*.*", wx.OPEN) |
139 dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a SVG file", os.getcwd(), "", "SVG files (*.svg)|*.svg|All files|*.*", wx.OPEN) |
143 if dialog.ShowModal() == wx.ID_OK: |
140 if dialog.ShowModal() == wx.ID_OK: |
144 svgpath = dialog.GetPath() |
141 svgpath = dialog.GetPath() |
145 if os.path.isfile(svgpath): |
142 if os.path.isfile(svgpath): |
146 shutil.copy(svgpath, os.path.join(self.PlugPath(), "gui.svg")) |
143 shutil.copy(svgpath, os.path.join(self.PlugPath(), "gui.svg")) |
147 else: |
144 else: |
148 logger.write_error("No such SVG file: %s\n"%svgpath) |
145 self.logger.write_error("No such SVG file: %s\n"%svgpath) |
149 dialog.Destroy() |
146 dialog.Destroy() |
150 |
147 |
151 def _ImportXML(self, logger): |
148 def _ImportXML(self): |
152 if not self._View: |
149 if not self._View: |
153 dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a XML file", os.getcwd(), "", "XML files (*.xml)|*.xml|All files|*.*", wx.OPEN) |
150 dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a XML file", os.getcwd(), "", "XML files (*.xml)|*.xml|All files|*.*", wx.OPEN) |
154 if dialog.ShowModal() == wx.ID_OK: |
151 if dialog.ShowModal() == wx.ID_OK: |
155 xmlpath = dialog.GetPath() |
152 xmlpath = dialog.GetPath() |
156 if os.path.isfile(xmlpath): |
153 if os.path.isfile(xmlpath): |
157 shutil.copy(xmlpath, os.path.join(self.PlugPath(), "gui.xml")) |
154 shutil.copy(xmlpath, os.path.join(self.PlugPath(), "gui.xml")) |
158 else: |
155 else: |
159 logger.write_error("No such XML file: %s\n"%xmlpath) |
156 self.logger.write_error("No such XML file: %s\n"%xmlpath) |
160 dialog.Destroy() |
157 dialog.Destroy() |
161 |
158 |
162 PluginMethods = [ |
159 PluginMethods = [ |
163 {"bitmap" : os.path.join("images","HMIEditor"), |
160 {"bitmap" : os.path.join("images","HMIEditor"), |
164 "name" : "HMI Editor", |
161 "name" : "HMI Editor", |
176 |
173 |
177 def OnPlugSave(self): |
174 def OnPlugSave(self): |
178 self.SaveXMLFile(os.path.join(self.PlugPath(), "gui.xml")) |
175 self.SaveXMLFile(os.path.join(self.PlugPath(), "gui.xml")) |
179 return True |
176 return True |
180 |
177 |
181 def PlugGenerate_C(self, buildpath, locations, logger): |
178 def PlugGenerate_C(self, buildpath, locations): |
182 progname = "SVGUI_%s"%"_".join(map(str, self.GetCurrentLocation())) |
179 progname = "SVGUI_%s"%"_".join(map(str, self.GetCurrentLocation())) |
183 |
180 |
184 doc = SVGDocument(self.GetSVGFilePath()) |
181 doc = SVGDocument(self.GetSVGFilePath()) |
185 root_element = doc.GetRootElement() |
182 root_element = doc.GetRootElement() |
186 window_size = (int(float(root_element.GetAttribute("width"))), |
183 window_size = (int(float(root_element.GetAttribute("width"))), |
187 int(float(root_element.GetAttribute("height")))) |
184 int(float(root_element.GetAttribute("height")))) |
188 |
185 |
189 svgfilepath = self.GetSVGFilePath() |
186 # svgfilepath = self.GetSVGFilePath() |
190 xmlfilepath = self.GetFilePath() |
187 # xmlfilepath = self.GetFilePath() |
191 shutil.copy(svgfilepath, buildpath) |
188 # shutil.copy(svgfilepath, buildpath) |
192 shutil.copy(xmlfilepath, buildpath) |
189 # shutil.copy(xmlfilepath, buildpath) |
|
190 |
|
191 SVGFilePath = self.GetSVGFilePath() |
|
192 SVGFileBaseName = os.path.split(SVGFilePath)[1] |
|
193 FilePath = self.GetFilePath() |
|
194 FileBaseName = os.path.split(FilePath)[1] |
193 |
195 |
194 generator = _SVGUICGenerator(self, self.GetElementsByType(), |
196 generator = _SVGUICGenerator(self, self.GetElementsByType(), |
195 os.path.split(self.GetSVGFilePath())[1], |
197 os.path.split(self.GetSVGFilePath())[1], |
196 os.path.split(self.GetFilePath())[1], |
198 os.path.split(self.GetFilePath())[1], |
197 self.GetCurrentLocation()) |
199 self.GetCurrentLocation()) |
200 |
202 |
201 if wx.Platform == '__WXMSW__': |
203 if wx.Platform == '__WXMSW__': |
202 cxx_flags = "-I..\\..\\wxPython-src-2.8.7.1\\bld\\lib\\wx\\include\\msw-unicode-release-2.8 -I..\\..\\wxPython-src-2.8.7.1\\include -I..\\..\\wxPython-src-2.8.7.1\\contrib\\include -I..\\..\\matiec\\lib -DWXUSINGDLL -D__WXMSW__ -mthreads" |
204 cxx_flags = "-I..\\..\\wxPython-src-2.8.7.1\\bld\\lib\\wx\\include\\msw-unicode-release-2.8 -I..\\..\\wxPython-src-2.8.7.1\\include -I..\\..\\wxPython-src-2.8.7.1\\contrib\\include -I..\\..\\matiec\\lib -DWXUSINGDLL -D__WXMSW__ -mthreads" |
203 libs = "\"..\\lib\\libwxsvg.a\" \"..\\lib\\libwxsvg_agg.a\" \"..\\lib\\libagg.a\" \"..\\lib\\libaggplatformwin32.a\" \"..\\lib\\libaggfontwin32tt.a\" -L..\\..\\wxPython-src-2.8.7.1\\bld\\lib -mno-cygwin -mwindows -mthreads -mno-cygwin -mwindows -Wl,--subsystem,windows -mwindows -lwx_mswu_richtext-2.8 -lwx_mswu_aui-2.8 -lwx_mswu_xrc-2.8 -lwx_mswu_qa-2.8 -lwx_mswu_html-2.8 -lwx_mswu_adv-2.8 -lwx_mswu_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8" |
205 libs = "\"..\\lib\\libwxsvg.a\" \"..\\lib\\libwxsvg_agg.a\" \"..\\lib\\libagg.a\" \"..\\lib\\libaggplatformwin32.a\" \"..\\lib\\libaggfontwin32tt.a\" -L..\\..\\wxPython-src-2.8.7.1\\bld\\lib -mno-cygwin -mwindows -mthreads -mno-cygwin -mwindows -Wl,--subsystem,windows -mwindows -lwx_mswu_richtext-2.8 -lwx_mswu_aui-2.8 -lwx_mswu_xrc-2.8 -lwx_mswu_qa-2.8 -lwx_mswu_html-2.8 -lwx_mswu_adv-2.8 -lwx_mswu_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8" |
204 else: |
206 else: |
205 status, result, err_result = ProcessLogger(logger, "wx-config --cxxflags", no_stdout=True).spin() |
207 status, result, err_result = ProcessLogger(self.logger, "wx-config --cxxflags", no_stdout=True).spin() |
206 if status: |
208 if status: |
207 logger.write_error("Unable to get wx cxxflags\n") |
209 self.logger.write_error("Unable to get wx cxxflags\n") |
208 cxx_flags = result.strip() + " -I../matiec/lib" |
210 cxx_flags = result.strip() + " -I../matiec/lib" |
209 |
211 |
210 status, result, err_result = ProcessLogger(logger, "wx-config --libs", no_stdout=True).spin() |
212 status, result, err_result = ProcessLogger(self.logger, "wx-config --libs", no_stdout=True).spin() |
211 if status: |
213 if status: |
212 logger.write_error("Unable to get wx libs\n") |
214 self.logger.write_error("Unable to get wx libs\n") |
213 libs = result.strip() + " -lwxsvg" |
215 libs = result.strip() + " -lwxsvg" |
214 |
216 |
215 return [(Gen_C_file, cxx_flags)],libs,True |
217 return [(Gen_C_file, cxx_flags)],libs,True,(SVGFileBaseName, file(SVGFilePath, "rb")), (FileBaseName, file(FilePath, "rb")) |
216 |
218 |
217 def BlockTypesFactory(self): |
219 def BlockTypesFactory(self): |
218 |
220 |
219 SVGUIBlock_Types = [] |
221 SVGUIBlock_Types = [] |
220 |
222 |
504 return text |
514 return text |
505 |
515 |
506 def GenerateProgramInitFrame(self): |
516 def GenerateProgramInitFrame(self): |
507 text = """MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,const wxSize& size, long style): wxFrame(parent, wxID_ANY, title, pos, size, style) |
517 text = """MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,const wxSize& size, long style): wxFrame(parent, wxID_ANY, title, pos, size, style) |
508 { |
518 { |
509 wxFileName apppath(wxTheApp->argv[0]); |
519 wxFileName svgfilepath(wxTheApp->argv[1], wxT("%s")); |
510 wxFileName svgfilepath(apppath.GetPath(), wxT("%s")); |
520 wxFileName xmlfilepath(wxTheApp->argv[1], wxT("%s")); |
511 wxFileName xmlfilepath(apppath.GetPath(), wxT("%s")); |
|
512 |
521 |
513 m_svgCtrl = new Program(this); |
522 m_svgCtrl = new Program(this); |
514 if (m_svgCtrl->LoadFiles(svgfilepath.GetFullPath(), xmlfilepath.GetFullPath())) |
523 if (m_svgCtrl->LoadFiles(svgfilepath.GetFullPath(), xmlfilepath.GetFullPath())) |
515 { |
524 { |
516 Show(true); |
525 Show(true); |
543 def GenerateProgramEventFunctions(self): |
551 def GenerateProgramEventFunctions(self): |
544 text = "" |
552 text = "" |
545 current_location = "_".join(map(str, self.CurrentLocation)) |
553 current_location = "_".join(map(str, self.CurrentLocation)) |
546 for element in self.Elements: |
554 for element in self.Elements: |
547 element_type = GetElementType(element) |
555 element_type = GetElementType(element) |
548 element_lock = """ if (COMPARE_AND_SWAP_VAL(&in_state_%d, CHANGED, GUI_BUSY) == CHANGED || |
556 element_lock = """ |
|
557 if (COMPARE_AND_SWAP_VAL(&in_state_%d, CHANGED, GUI_BUSY) == CHANGED || |
549 COMPARE_AND_SWAP_VAL(&in_state_%d, UNCHANGED, GUI_BUSY) == UNCHANGED) { |
558 COMPARE_AND_SWAP_VAL(&in_state_%d, UNCHANGED, GUI_BUSY) == UNCHANGED) { |
550 """%(element.getid(), element.getid()) |
559 """%(element.getid(), element.getid()) |
551 element_unlock = """ COMPARE_AND_SWAP_VAL(&in_state_%d, GUI_BUSY, CHANGED); |
560 element_unlock = """ |
|
561 COMPARE_AND_SWAP_VAL(&in_state_%d, GUI_BUSY, CHANGED); |
|
562 event.Skip(); |
|
563 }else{ |
|
564 /* re post event for idle */ |
|
565 AddPendingEvent(event); |
552 } |
566 } |
553 else |
567 } |
554 ProcessEvent(event); |
568 |
555 """%element.getid() |
569 """%element.getid() |
556 element_name = element.getname() |
570 element_name = element.getname() |
557 |
571 |
558 if element_type == ITEM_BUTTON: |
572 if element_type == ITEM_BUTTON: |
559 text += """void Program::On%sClick(wxCommandEvent& event) |
573 text += """void Program::On%sClick(wxCommandEvent& event) |
560 { |
574 { |
561 SVGUIButton* button = (SVGUIButton*)GetElementByName(wxT("%s"));\n"""%(element_name, element_name) |
575 SVGUIButton* button = (SVGUIButton*)GetElementByName(wxT("%s"));\n"""%(element_name, element_name) |
562 text += element_lock |
576 text += element_lock |
563 text += " _copy__IX%s_%d_1 = button->GetToggle();\n"%(current_location, element.getid()) |
577 text += " _copy__IX%s_%d_1 = button->GetToggle();\n"%(current_location, element.getid()) |
564 text += element_unlock |
578 text += element_unlock |
565 text += " event.Skip();\n}\n\n" |
|
566 elif element_type == ITEM_ROTATING: |
579 elif element_type == ITEM_ROTATING: |
567 text += """void Program::On%sChanging(wxScrollEvent& event) |
580 text += """void Program::On%sChanging(wxScrollEvent& event) |
568 { |
581 { |
569 SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementByName(wxT("%s")); |
582 SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementByName(wxT("%s")); |
570 """%(element_name, element_name) |
583 """%(element_name, element_name) |
571 text += element_lock |
584 text += element_lock |
572 text += " _copy__ID%s_%d_1 = rotating->GetAngle();\n"%(current_location, element.getid()) |
585 text += " _copy__ID%s_%d_1 = rotating->GetAngle();\n"%(current_location, element.getid()) |
573 text += element_unlock |
586 text += element_unlock |
574 text += " event.Skip();\n}\n\n" |
|
575 elif element_type == ITEM_NOTEBOOK: |
587 elif element_type == ITEM_NOTEBOOK: |
576 text += """void Program::On%sTabChanged(wxNotebookEvent& event) |
588 text += """void Program::On%sTabChanged(wxNotebookEvent& event) |
577 { |
589 { |
578 SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementByName(wxT("%s")); |
590 SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementByName(wxT("%s")); |
579 """%(element_name, element_name) |
591 """%(element_name, element_name) |
580 text += element_lock |
592 text += element_lock |
581 text += " _copy__IB%s_%d_1 = notebook->GetCurrentPage();\n"%(current_location, element.getid()) |
593 text += " _copy__IB%s_%d_1 = notebook->GetCurrentPage();\n"%(current_location, element.getid()) |
582 text += element_unlock |
594 text += element_unlock |
583 text += " event.Skip();\n}\n\n" |
|
584 elif element_type == ITEM_TRANSFORM: |
595 elif element_type == ITEM_TRANSFORM: |
585 text += """void Program::On%sChanging(wxScrollEvent& event) |
596 text += """void Program::On%sChanging(wxScrollEvent& event) |
586 { |
597 { |
587 SVGUITransform* transform = (SVGUITransform*)GetElementByName(wxT("%s")); |
598 SVGUITransform* transform = (SVGUITransform*)GetElementByName(wxT("%s")); |
588 """%(element_name, element_name) |
599 """%(element_name, element_name) |
589 text += element_lock |
600 text += element_lock |
590 text += " _copy__ID%s_%d_1 = transform->GetX();\n"%(current_location, element.getid()) |
601 text += " _copy__ID%s_%d_1 = transform->GetX();\n"%(current_location, element.getid()) |
591 text += " _copy__ID%s_%d_2 = transform->GetY();\n"%(current_location, element.getid()) |
602 text += " _copy__ID%s_%d_2 = transform->GetY();\n"%(current_location, element.getid()) |
592 text += element_unlock |
603 text += element_unlock |
593 text += " event.Skip();\n}\n\n" |
|
594 |
604 |
595 text += "/* OnPlcOutEvent update GUI with provided IEC __Q* PLC output variables */\n" |
605 text += "/* OnPlcOutEvent update GUI with provided IEC __Q* PLC output variables */\n" |
596 text += """void Program::OnPlcOutEvent(wxEvent& event) |
606 text += """void Program::OnPlcOutEvent(wxEvent& event) |
597 { |
607 { |
598 SVGUIElement* element; |
608 SVGUIElement* element; |
599 |
609 |
600 refreshing = true; |
610 refreshing = true; |
601 |
611 |
602 wxMutexGuiEnter(); |
612 |
603 """ |
613 """ |
604 for element in self.Elements: |
614 for element in self.Elements: |
605 element_type = GetElementType(element) |
615 element_type = GetElementType(element) |
606 texts = {"location" : current_location, "id" : element.getid()} |
616 texts = {"location" : current_location, "id" : element.getid()} |
607 |
617 |