180 text += pri_vars |
180 text += pri_vars |
181 |
181 |
182 text += "IMPLEMENT_APP_NO_MAIN(SVGViewApp);\n" |
182 text += "IMPLEMENT_APP_NO_MAIN(SVGViewApp);\n" |
183 text += "IMPLEMENT_WX_THEME_SUPPORT;\n" |
183 text += "IMPLEMENT_WX_THEME_SUPPORT;\n" |
184 text += "SVGViewApp *myapp = NULL;\n" |
184 text += "SVGViewApp *myapp = NULL;\n" |
185 text += "pthread_t wxMainLoop,automate;\n" |
185 text += "pthread_t wxMainLoop;\n" |
|
186 # text += "pthread_t wxMainLoop,automate;\n" |
186 text += "int myargc = 0;\n" |
187 text += "int myargc = 0;\n" |
187 text += "char** myargv = NULL;\n\n" |
188 text += "char** myargv = NULL;\n\n" |
188 |
189 |
189 text += "#define UNCHANGED 1 \n" |
190 text += "#define UNCHANGED 1 \n" |
190 text += "#define PLC_BUSY 2 \n" |
191 text += "#define PLC_BUSY 2 \n" |
205 # text += " sleep(1);\n" |
206 # text += " sleep(1);\n" |
206 # text += " }\n" |
207 # text += " }\n" |
207 # text += " return args;\n" |
208 # text += " return args;\n" |
208 # text += "}\n\n" |
209 # text += "}\n\n" |
209 |
210 |
210 if (self.SVGUIRootElement): |
211 # if (self.SVGUIRootElement): |
211 width = self.SVGUIRootElement.GetBBox().GetWidth() |
212 # width = self.SVGUIRootElement.GetBBox().GetWidth() |
212 height = self.SVGUIRootElement.GetBBox().GetHeight() |
213 # height = self.SVGUIRootElement.GetBBox().GetHeight() |
213 else : |
214 # else : |
214 width = 250 |
215 # width = 250 |
215 height = 350 |
216 # height = 350 |
216 text += "bool SVGViewApp::OnInit()\n{\n" |
217 text += "bool SVGViewApp::OnInit()\n{\n" |
217 text += " #ifndef __WXMSW__\n" |
218 text += " #ifndef __WXMSW__\n" |
218 text += " setlocale(LC_NUMERIC, \"C\");\n" |
219 text += " setlocale(LC_NUMERIC, \"C\");\n" |
219 text += " #endif\n" |
220 text += " #endif\n" |
220 text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize((int)"+str(width)+", (int)"+str(height)+"));\n" |
221 #text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize((int)"+str(width)+", (int)"+str(height)+"));\n" |
|
222 text += " frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxDefaultSize);\n" |
221 text += " myapp = this;\n" |
223 text += " myapp = this;\n" |
222 # text += " pthread_create(&automate, NULL, SimulAutomate, NULL);\n" |
224 # text += " pthread_create(&automate, NULL, SimulAutomate, NULL);\n" |
223 text += " return true;\n" |
225 text += " return true;\n" |
224 text += "}\n\n" |
226 text += "}\n\n" |
225 |
227 |
226 text += "int __init_"+self.BusNumber+"(int argc, char** argv)\n{\n" |
228 text += "int __init_"+self.BusNumber+"(int argc, char** argv)\n{\n" |
227 text += " myargc = argc;\n" |
229 text += " myargc = argc;\n" |
228 text += " myargv = argv;\n" |
230 text += " myargv = argv;\n" |
229 text += " pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);\n" |
231 text += " pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);\n" |
230 text += " pause();\n" |
232 text += "}\n\n" |
|
233 |
|
234 text += "int __cleanup_"+self.BusNumber+"()\n{\n" |
231 text += "}\n\n" |
235 text += "}\n\n" |
232 |
236 |
233 text += "int __retrive_"+self.BusNumber+"()\n{\n" |
237 text += "int __retrive_"+self.BusNumber+"()\n{\n" |
234 text += " if(myapp){" |
238 text += " if(myapp){" |
235 text += " myapp->Retrive()" |
239 text += " myapp->Retrive()" |
319 infos = element.getElementAttributes() |
323 infos = element.getElementAttributes() |
320 for info in infos: |
324 for info in infos: |
321 if info["name"] == "id": |
325 if info["name"] == "id": |
322 element_id = str(info["value"]) |
326 element_id = str(info["value"]) |
323 text += " out_state_"+element_id+" = UNCHANGED;\n" |
327 text += " out_state_"+element_id+" = UNCHANGED;\n" |
|
328 text += " in_state_"+element_id+" = UNCHANGED;\n" |
324 text += "}\n\n" |
329 text += "}\n\n" |
325 return text |
330 return text |
326 |
331 |
327 def GenerateProgramEventFunctions(self): |
332 def GenerateProgramEventFunctions(self): |
328 fct="" |
333 fct="" |
751 return fct |
756 return fct |
752 |
757 |
753 def PlugGenerate_C(self, buildpath, locations, logger): |
758 def PlugGenerate_C(self, buildpath, locations, logger): |
754 current_location = self.GetCurrentLocation() |
759 current_location = self.GetCurrentLocation() |
755 self.BusNumber = "_".join(map(lambda x:str(x), current_location)) |
760 self.BusNumber = "_".join(map(lambda x:str(x), current_location)) |
756 self.GenerateProgram(buildpath) |
761 progname = self.BusNumber + "_SVGUI" |
757 Gen_C_file = os.path.join(buildpath, "program.cpp" ) |
762 self.GenerateProgram(buildpath, progname) |
|
763 Gen_C_file = os.path.join(buildpath, progname+".cpp" ) |
758 return [(Gen_C_file,"")],"" |
764 return [(Gen_C_file,"")],"" |
759 |
765 |
760 def BlockTypesFactory(self): |
766 def BlockTypesFactory(self): |
761 def generate_svgui_block(generator, block, body, link): |
767 def generate_svgui_block(generator, block, body, link): |
762 name = block.getInstanceName() |
768 name = block.getInstanceName() |
768 current_location = ".".join(map(str, self.GetCurrentLocation())) |
774 current_location = ".".join(map(str, self.GetCurrentLocation())) |
769 if not generator.ComputedBlocks.get(name, False): |
775 if not generator.ComputedBlocks.get(name, False): |
770 for num, variable in enumerate(block.inputVariables.getVariable()): |
776 for num, variable in enumerate(block.inputVariables.getVariable()): |
771 connections = variable.connectionPointIn.getConnections() |
777 connections = variable.connectionPointIn.getConnections() |
772 if connections and len(connections) == 1: |
778 if connections and len(connections) == 1: |
773 parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num) |
779 parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num+1) |
774 value = generator.ComputeFBDExpression(body, connections[0]) |
780 value = generator.ComputeFBDExpression(body, connections[0]) |
775 generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
781 generator.Program += (" %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value))) |
776 generator.ComputedBlocks[name] = True |
782 generator.ComputedBlocks[name] = True |
777 if link: |
783 if link: |
778 connectionPoint = link.getPosition()[-1] |
784 connectionPoint = link.getPosition()[-1] |
779 for num, variable in enumerate(block.outputVariables.getVariable()): |
785 for num, variable in enumerate(block.outputVariables.getVariable()): |
780 blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
786 blockPointx, blockPointy = variable.connectionPointOut.getRelPosition() |
781 if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
787 if block.getX() + blockPointx == connectionPoint.getX() and block.getY() + blockPointy == connectionPoint.getY(): |
782 return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num) |
788 return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1) |
783 raise ValueError, "No output variable found" |
789 raise ValueError, "No output variable found" |
784 else: |
790 else: |
785 return None |
791 return None |
786 |
792 |
787 def initialise_block(type, name): |
793 def initialise_block(type, name): |
790 raise ValueError, "No corresponding block found" |
796 raise ValueError, "No corresponding block found" |
791 block_infos = self.GetBlockType(type) |
797 block_infos = self.GetBlockType(type) |
792 current_location = ".".join(map(str, self.GetCurrentLocation())) |
798 current_location = ".".join(map(str, self.GetCurrentLocation())) |
793 variables = [] |
799 variables = [] |
794 for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]): |
800 for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]): |
795 variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None)) |
801 variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None)) |
796 for num, (output_name, output_type, output_modifier) in enumerate(block_infos["outputs"]): |
802 for num, (output_name, output_type, output_modifier) in enumerate(block_infos["outputs"]): |
797 variables.append((output_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num), None)) |
803 variables.append((output_type, None, "%sI%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None)) |
798 return variables |
804 return variables |
799 |
805 |
800 return [{"name" : "SVGUI function blocks", "list" : |
806 return [{"name" : "SVGUI function blocks", "list" : |
801 [{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
807 [{"name" : "Container", "type" : "functionBlock", "extensible" : False, |
802 "inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], |
808 "inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], |