152 # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS |
152 # Generate plugins [(Cfiles, CFLAGS)], LDFLAGS |
153 PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, current_location, locations, logger) |
153 PlugCFilesAndCFLAGS, PlugLDFLAGS = self.PlugGenerate_C(buildpath, current_location, locations, logger) |
154 # recurse through all childs, and stack their results |
154 # recurse through all childs, and stack their results |
155 for PlugChild in self.IterChilds(): |
155 for PlugChild in self.IterChilds(): |
156 # Compute child's IEC location |
156 # Compute child's IEC location |
157 new_location = current_location + (self.BaseParams.getIEC_Channel()) |
157 if current_location: |
|
158 new_location = current_location + (self.BaseParams.getIEC_Channel()) |
|
159 else: |
|
160 # root |
|
161 new_location = () |
158 # Get childs [(Cfiles, CFLAGS)], LDFLAGS |
162 # Get childs [(Cfiles, CFLAGS)], LDFLAGS |
159 CFilesAndCFLAGS, LDFLAGS = \ |
163 CFilesAndCFLAGS, LDFLAGS = \ |
160 PlugChild._Generate_C( |
164 PlugChild._Generate_C( |
161 #keep the same path |
165 #keep the same path |
162 buildpath, |
166 buildpath, |
201 return self._GetChildBySomething('.',"Name", Name) |
205 return self._GetChildBySomething('.',"Name", Name) |
202 |
206 |
203 def GetChildByIECLocation(self, Location): |
207 def GetChildByIECLocation(self, Location): |
204 return self._GetChildBySomething('_',"IEC_Channel", Name) |
208 return self._GetChildBySomething('_',"IEC_Channel", Name) |
205 |
209 |
|
210 def GetCurrentLocation(self): |
|
211 return self.PlugParent.GetCurrentLocation() + (self.BaseParams.getIEC_Channel(),) |
|
212 |
|
213 def GetPlugRoot(self): |
|
214 return self.PlugParent.GetPlugRoot() |
|
215 |
206 def GetPlugInfos(self): |
216 def GetPlugInfos(self): |
207 childs = [] |
217 childs = [] |
208 for child in self.IterChilds(): |
218 for child in self.IterChilds(): |
209 childs.append(child.GetPlugInfos()) |
219 childs.append(child.GetPlugInfos()) |
210 return {"name" : self.BaseParams.getName(), "type" : None, "values" : childs} |
220 return {"name" : self.BaseParams.getName(), "type" : None, "values" : childs} |
350 def LoadChilds(self): |
360 def LoadChilds(self): |
351 # Iterate over all PlugName@PlugType in plugin directory, and try to open them |
361 # Iterate over all PlugName@PlugType in plugin directory, and try to open them |
352 for PlugDir in os.listdir(self.PlugPath()): |
362 for PlugDir in os.listdir(self.PlugPath()): |
353 if os.path.isdir(os.path.join(self.PlugPath(), PlugDir)) and \ |
363 if os.path.isdir(os.path.join(self.PlugPath(), PlugDir)) and \ |
354 PlugDir.count(NameTypeSeparator) == 1: |
364 PlugDir.count(NameTypeSeparator) == 1: |
355 try: |
365 #try: |
356 self.PlugAddChild(*PlugDir.split(NameTypeSeparator)) |
366 self.PlugAddChild(*PlugDir.split(NameTypeSeparator)) |
357 except Exception, e: |
367 #except Exception, e: |
358 print e |
368 # print e |
359 |
369 |
360 def _GetClassFunction(name): |
370 def _GetClassFunction(name): |
361 def GetRootClass(): |
371 def GetRootClass(): |
362 return getattr(__import__("plugins." + name), name).RootClass |
372 return getattr(__import__("plugins." + name), name).RootClass |
363 return GetRootClass |
373 return GetRootClass |
462 This method are not called here... but in NewProject and OpenProject |
472 This method are not called here... but in NewProject and OpenProject |
463 self._AddParamsMembers() |
473 self._AddParamsMembers() |
464 self.PluggedChilds = {} |
474 self.PluggedChilds = {} |
465 """ |
475 """ |
466 |
476 |
467 # self is the parent |
477 # root have no parent |
468 self.PlugParent = None |
478 self.PlugParent = None |
469 # Keep track of the plugin type name |
479 # Keep track of the plugin type name |
470 self.PlugType = "Beremiz" |
480 self.PlugType = "Beremiz" |
471 |
481 |
472 # After __init__ root plugin is not valid |
482 # After __init__ root plugin is not valid |
477 def HasProjectOpened(self): |
487 def HasProjectOpened(self): |
478 """ |
488 """ |
479 Return if a project is actually opened |
489 Return if a project is actually opened |
480 """ |
490 """ |
481 return self.ProjectPath != None |
491 return self.ProjectPath != None |
|
492 |
|
493 def GetPlugRoot(self): |
|
494 return self |
|
495 |
|
496 def GetCurrentLocation(self): |
|
497 return () |
482 |
498 |
483 def GetProjectPath(self): |
499 def GetProjectPath(self): |
484 return self.ProjectPath |
500 return self.ProjectPath |
485 |
501 |
486 def GetPlugInfos(self): |
502 def GetPlugInfos(self): |
607 C_files = result.splitlines() |
623 C_files = result.splitlines() |
608 # remove those that are not to be compiled because included by others |
624 # remove those that are not to be compiled because included by others |
609 C_files.remove("POUS.c") |
625 C_files.remove("POUS.c") |
610 C_files.remove("LOCATED_VARIABLES.h") |
626 C_files.remove("LOCATED_VARIABLES.h") |
611 # transform those base names to full names with path |
627 # transform those base names to full names with path |
612 C_files = map(lambda filename:os.path.join(self.TargetDir, filename), C_files) |
628 C_files = map(lambda filename:os.path.join(buildpath, filename), C_files) |
613 logger.write("Extracting Located Variables...\n") |
629 logger.write("Extracting Located Variables...\n") |
614 # IEC2CC compiler generate a list of located variables : LOCATED_VARIABLES.h |
630 # IEC2CC compiler generate a list of located variables : LOCATED_VARIABLES.h |
615 location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h")) |
631 location_file = open(os.path.join(buildpath,"LOCATED_VARIABLES.h")) |
616 locations = [] |
632 locations = [] |
617 # each line of LOCATED_VARIABLES.h declares a located variable |
633 # each line of LOCATED_VARIABLES.h declares a located variable |
655 return False |
671 return False |
656 |
672 |
657 logger.write("SoftPLC code generation successfull\n") |
673 logger.write("SoftPLC code generation successfull\n") |
658 |
674 |
659 # Generate C code and compilation params from plugin hierarchy |
675 # Generate C code and compilation params from plugin hierarchy |
660 try: |
676 #try: |
661 CFilesAndCFLAGS, LDFLAGS = self._Generate_C( |
677 CFilesAndCFLAGS, LDFLAGS = self._Generate_C( |
662 buildpath, |
678 buildpath, |
663 (), |
679 None, #root has no location |
664 self.PLCGeneratedLocatedVars, |
680 self.PLCGeneratedLocatedVars, |
665 logger) |
681 logger) |
666 except Exception, msg: |
682 #except Exception, msg: |
667 logger.write_error("Plugins code generation Failed !\n") |
683 # logger.write_error("Plugins code generation Failed !\n") |
668 logger.write_error(str(msg)) |
684 # logger.write_error(str(msg)) |
669 return False |
685 # return False |
670 |
686 |
671 logger.write("Plugins code generation successfull\n") |
687 logger.write("Plugins code generation successfull\n") |
672 |
688 |
673 # Compile the resulting code into object files. |
689 # Compile the resulting code into object files. |
674 for CFile, CFLAG in CFilesAndCFLAGS: |
690 for CFile, CFLAG in CFilesAndCFLAGS: |