PLCControler.py
changeset 13 69075340d6a9
parent 6 c8cf918ee7ea
child 24 364320323b4d
equal deleted inserted replaced
12:58a65b901719 13:69075340d6a9
   756                     BlockTypes[-1]["list"].append(block_infos)
   756                     BlockTypes[-1]["list"].append(block_infos)
   757 
   757 
   758     # Return Block types checking for recursion
   758     # Return Block types checking for recursion
   759     def GetBlockTypes(self):
   759     def GetBlockTypes(self):
   760         if self.CurrentElementEditing != None:
   760         if self.CurrentElementEditing != None:
   761             current_name = self.ElementsOpened[self.CurrentElementEditing]
   761             if self.Project:
   762             words = current_name.split("::")
   762                 current_name = self.ElementsOpened[self.CurrentElementEditing]
   763             if len(words) == 1:
   763                 words = current_name.split("::")
   764                 name = current_name
   764                 if len(words) == 1:
       
   765                     name = current_name
       
   766                 else:
       
   767                     name = words[1]
       
   768                 type = self.GetPouType(name)
   765             else:
   769             else:
   766                 name = words[1]
   770                 name = ""
   767             blocktypes = [category for category in BlockTypes[:-1]]
   771                 type = None
   768             blocktypes.append({"name" : "User-defined POUs", "list": []})
   772             if type == "function":
       
   773                 blocktypes = []
       
   774                 for category in BlockTypes[:-1]:
       
   775                     cat = {"name" : category["name"], "list" : []}
       
   776                     for block in category["list"]:
       
   777                         if block["type"] == "function":
       
   778                             cat["list"].append(block)
       
   779                     if len(cat["list"]) > 0:
       
   780                         blocktypes.append(cat)
       
   781             else:
       
   782                 blocktypes = [category for category in BlockTypes[:-1]]
   769             if self.Project:
   783             if self.Project:
   770                 pou = self.Project.getPou(name)
   784                 blocktypes.append({"name" : "User-defined POUs", "list": []})
   771                 name = pou.getName()
       
   772                 type = pou.pouType.getValue()
       
   773                 for blocktype in BlockTypes[-1]["list"]:
   785                 for blocktype in BlockTypes[-1]["list"]:
   774                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] == "functionBlock"):
   786                     if blocktype["name"] != name and not self.PouIsUsedBy(name, blocktype["name"]) and not (type == "function" and blocktype["type"] != "function"):
   775                         blocktypes[-1]["list"].append(blocktype)
   787                         blocktypes[-1]["list"].append(blocktype)
   776             return blocktypes
   788             return blocktypes
   777         return []
   789         return []
   778 
   790 
   779     # Return Block types checking for recursion
   791     # Return Block types checking for recursion
   922         return None
   934         return None
   923     
   935     
   924     # Replace the index of current pou editing by the one given
   936     # Replace the index of current pou editing by the one given
   925     def RefreshCurrentElementEditing(self, index):
   937     def RefreshCurrentElementEditing(self, index):
   926         self.CurrentElementEditing = index
   938         self.CurrentElementEditing = index
       
   939 
       
   940     # Return language in which current pou editing is written
       
   941     def GetCurrentElementEditingType(self):
       
   942         if self.CurrentElementEditing != None:
       
   943             name = self.ElementsOpened[self.CurrentElementEditing]
       
   944             words = name.split("::")
       
   945             if len(words) == 1:
       
   946                 return self.GetPouType(name)
       
   947             else:
       
   948                 return self.GetPouType(words[1])
       
   949         return None
   927 
   950 
   928     # Return language in which current pou editing is written
   951     # Return language in which current pou editing is written
   929     def GetCurrentElementEditingBodyType(self):
   952     def GetCurrentElementEditingBodyType(self):
   930         if self.CurrentElementEditing != None:
   953         if self.CurrentElementEditing != None:
   931             name = self.ElementsOpened[self.CurrentElementEditing]
   954             name = self.ElementsOpened[self.CurrentElementEditing]