180 self.ProjectBuffer = None |
180 self.ProjectBuffer = None |
181 self.Buffering = False |
181 self.Buffering = False |
182 self.FilePath = "" |
182 self.FilePath = "" |
183 self.FileName = "" |
183 self.FileName = "" |
184 self.ProgramChunks = [] |
184 self.ProgramChunks = [] |
|
185 self.NextCompiledProject = None |
185 self.CurrentCompiledProject = None |
186 self.CurrentCompiledProject = None |
186 self.PluginTypes = [] |
187 self.PluginTypes = [] |
187 self.ProgramFilePath = "" |
188 self.ProgramFilePath = "" |
188 |
189 |
189 def GetQualifierTypes(self): |
190 def GetQualifierTypes(self): |
212 self.Project.setcontentHeader(properties) |
213 self.Project.setcontentHeader(properties) |
213 self.SetFilePath("") |
214 self.SetFilePath("") |
214 # Initialize the project buffer |
215 # Initialize the project buffer |
215 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False) |
216 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), False) |
216 self.ProgramChunks = [] |
217 self.ProgramChunks = [] |
|
218 self.NextCompiledProject = self.Copy(self.Project) |
217 self.CurrentCompiledProject = None |
219 self.CurrentCompiledProject = None |
218 self.Buffering = False |
220 self.Buffering = False |
219 |
221 |
220 # Return project data type names |
222 # Return project data type names |
221 def GetProjectDataTypeNames(self, debug = False): |
223 def GetProjectDataTypeNames(self, debug = False): |
498 |
500 |
499 def GenerateProgram(self, filepath): |
501 def GenerateProgram(self, filepath): |
500 if self.Project is not None: |
502 if self.Project is not None: |
501 try: |
503 try: |
502 self.ProgramChunks = GenerateCurrentProgram(self, self.Project) |
504 self.ProgramChunks = GenerateCurrentProgram(self, self.Project) |
503 self.CurrentCompiledProject = self.Copy(self.Project) |
505 self.NextCompiledProject = self.Copy(self.Project) |
504 program_text = "".join([item[0] for item in self.ProgramChunks]) |
506 program_text = "".join([item[0] for item in self.ProgramChunks]) |
505 programfile = open(filepath, "w") |
507 programfile = open(filepath, "w") |
506 programfile.write(program_text) |
508 programfile.write(program_text) |
507 programfile.close() |
509 programfile.close() |
508 self.ProgramFilePath = filepath |
510 self.ProgramFilePath = filepath |
509 return None |
511 return None |
510 except PLCGenException, e: |
512 except PLCGenException, e: |
511 return e.message |
513 return e.message |
512 return "No project opened" |
514 return "No project opened" |
|
515 |
|
516 def ProgramTransferred(self): |
|
517 self.CurrentCompiledProject = self.NextCompiledProject |
513 |
518 |
514 def GetChunkInfos(self, from_location, to_location): |
519 def GetChunkInfos(self, from_location, to_location): |
515 row = col = 1 |
520 row = col = 1 |
516 infos = [] |
521 infos = [] |
517 for chunk, chunk_infos in self.ProgramChunks: |
522 for chunk, chunk_infos in self.ProgramChunks: |
1084 return None |
1089 return None |
1085 |
1090 |
1086 # Return Block types checking for recursion |
1091 # Return Block types checking for recursion |
1087 def GetBlockTypes(self, tagname = "", debug = False): |
1092 def GetBlockTypes(self, tagname = "", debug = False): |
1088 type = None |
1093 type = None |
|
1094 words = tagname.split("::") |
1089 if self.Project: |
1095 if self.Project: |
1090 name = "" |
1096 name = "" |
1091 words = tagname.split("::") |
|
1092 if words[0] in ["P","T","A"]: |
1097 if words[0] in ["P","T","A"]: |
1093 name = words[1] |
1098 name = words[1] |
1094 type = self.GetPouType(name, debug) |
1099 type = self.GetPouType(name, debug) |
1095 if type == "function": |
1100 if type == "function" or words[0] == "T": |
1096 blocktypes = [] |
1101 blocktypes = [] |
1097 for category in BlockTypes + self.PluginTypes: |
1102 for category in BlockTypes + self.PluginTypes: |
1098 cat = {"name" : category["name"], "list" : []} |
1103 cat = {"name" : category["name"], "list" : []} |
1099 for block in category["list"]: |
1104 for block in category["list"]: |
1100 if block["type"] == "function": |
1105 if block["type"] == "function": |
1103 blocktypes.append(cat) |
1108 blocktypes.append(cat) |
1104 else: |
1109 else: |
1105 blocktypes = [category for category in BlockTypes + self.PluginTypes] |
1110 blocktypes = [category for category in BlockTypes + self.PluginTypes] |
1106 project = self.GetProject(debug) |
1111 project = self.GetProject(debug) |
1107 if project is not None: |
1112 if project is not None: |
1108 blocktypes.append({"name" : "User-defined POUs", "list": project.GetCustomBlockTypes(name)}) |
1113 blocktypes.append({"name" : "User-defined POUs", "list": project.GetCustomBlockTypes(name, type == "function" or words[0] == "T")}) |
1109 return blocktypes |
1114 return blocktypes |
1110 |
1115 |
1111 # Return Function Block types checking for recursion |
1116 # Return Function Block types checking for recursion |
1112 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1117 def GetFunctionBlockTypes(self, tagname = "", debug = False): |
1113 blocktypes = [] |
1118 blocktypes = [] |
2533 self.Project.RefreshElementUsingTree() |
2538 self.Project.RefreshElementUsingTree() |
2534 self.Project.RefreshDataTypeHierarchy() |
2539 self.Project.RefreshDataTypeHierarchy() |
2535 self.Project.RefreshCustomBlockTypes() |
2540 self.Project.RefreshCustomBlockTypes() |
2536 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True) |
2541 self.ProjectBuffer = UndoBuffer(self.Copy(self.Project), True) |
2537 self.ProgramChunks = [] |
2542 self.ProgramChunks = [] |
|
2543 self.NextCompiledProject = self.Copy(self.Project) |
2538 self.CurrentCompiledProject = None |
2544 self.CurrentCompiledProject = None |
2539 self.Buffering = False |
2545 self.Buffering = False |
2540 self.CurrentElementEditing = None |
2546 self.CurrentElementEditing = None |
2541 return None |
2547 return None |
2542 return "No PLC project found" |
2548 return "No PLC project found" |