LPCBeremiz.py
changeset 444 8eb1186fc9cf
parent 442 f971de6d274f
child 445 1b1dc8ad2498
equal deleted inserted replaced
443:34c9788bd933 444:8eb1186fc9cf
   379         return target
   379         return target
   380      
   380      
   381     def SetProjectName(self, name):
   381     def SetProjectName(self, name):
   382         return self.Project.setname(name)
   382         return self.Project.setname(name)
   383 
   383 
       
   384     # Update a PLCOpenEditor Pou variable name
       
   385     def UpdateProjectVariableName(self, old_name, new_name):
       
   386         self.Project.updateElementName(old_name, new_name)
       
   387         self.BufferProject()
       
   388 
       
   389     def RemoveProjectVariableByAddress(self, address):
       
   390         self.Project.removeVariableByAddress(address)
       
   391         self.BufferProject()
       
   392 
       
   393     def RemoveProjectVariableByFilter(self, leading):
       
   394         self.Project.removeVariableByFilter(leading)
       
   395         self.BufferProject()
       
   396 
   384     def LoadProject(self, ProjectPath, BuildPath=None):
   397     def LoadProject(self, ProjectPath, BuildPath=None):
   385         """
   398         """
   386         Load a project XML file
   399         Load a project XML file
   387         @param ProjectPath: path of the project xml file
   400         @param ProjectPath: path of the project xml file
   388         """
   401         """
   735             beremiz_thread.start()
   748             beremiz_thread.start()
   736         
   749         
   737         def Refresh(self):
   750         def Refresh(self):
   738             global frame
   751             global frame
   739             if frame is not None:
   752             if frame is not None:
       
   753                 wx.CallAfter(frame._Refresh, TITLE, INSTANCESTREE, FILEMENU, EDITMENU)
       
   754                 wx.CallAfter(frame.RefreshEditor)
   740                 wx.CallAfter(frame.RefreshAll)
   755                 wx.CallAfter(frame.RefreshAll)
   741         
   756         
   742         def Close(self):
   757         def Close(self):
   743             global frame
   758             global frame
   744             
   759             
   783             if bus is None:
   798             if bus is None:
   784                 return "Error: No bus found"
   799                 return "Error: No bus found"
   785             for child in self.PluginRoot.IterChilds():
   800             for child in self.PluginRoot.IterChilds():
   786                 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
   801                 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
   787                     return "Error: A bus with IEC_channel %d already exists" % new_iec_channel
   802                     return "Error: A bus with IEC_channel %d already exists" % new_iec_channel
       
   803             self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), str(new_iec_channel))
   788             bus.BaseParams.setIEC_Channel(new_iec_channel)
   804             bus.BaseParams.setIEC_Channel(new_iec_channel)
   789             self.RestartTimer()
   805             self.RestartTimer()
   790         
   806         
   791         def RemoveBus(self, iec_channel):
   807         def RemoveBus(self, iec_channel):
   792             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
   808             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
   793             if bus is None:
   809             if bus is None:
   794                 return "Error: No bus found"
   810                 return "Error: No bus found"
       
   811             self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
   795             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
   812             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
   796             self.RestartTimer()
   813             self.RestartTimer()
   797     
   814     
   798         def AddModule(self, parent, iec_channel, name, icon=None):
   815         def AddModule(self, parent, iec_channel, name, icon=None):
   799             module = self.PluginRoot.GetChildByIECLocation(parent)
   816             module = self.PluginRoot.GetChildByIECLocation(parent)
   834                 return "Error: No module found"
   851                 return "Error: No module found"
   835             if module["IEC_Channel"] != new_iec_channel:
   852             if module["IEC_Channel"] != new_iec_channel:
   836                 for child in _GetModuleChildren(parent):
   853                 for child in _GetModuleChildren(parent):
   837                     if child["IEC_Channel"] == new_iec_channel:
   854                     if child["IEC_Channel"] == new_iec_channel:
   838                         return "Error: A module with IEC_channel %d already exists" % new_iec_channel
   855                         return "Error: A module with IEC_channel %d already exists" % new_iec_channel
       
   856             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
   839             module["IEC_Channel"] = new_iec_channel
   857             module["IEC_Channel"] = new_iec_channel
   840             self.RestartTimer()
   858             self.RestartTimer()
   841     
   859     
   842         def RemoveModule(self, parent, iec_channel):
   860         def RemoveModule(self, parent, iec_channel):
   843             module = self.PluginRoot.GetChildByIECLocation(parent)
   861             module = self.PluginRoot.GetChildByIECLocation(parent)
   844             if module is None:
   862             if module is None:
   845                 return "Error: No parent found"
   863                 return "Error: No parent found"
   846             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
   864             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
   847             if child is None:
   865             if child is None:
   848                 return "Error: No module found"
   866                 return "Error: No module found"
       
   867             self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
   849             _RemoveModuleChild(module, child)
   868             _RemoveModuleChild(module, child)
   850             self.RestartTimer()
   869             self.RestartTimer()
   851         
   870         
   852         def StartGroup(self, parent, name, icon=None):
   871         def StartGroup(self, parent, name, icon=None):
   853             module = self.PluginRoot.GetChildByIECLocation(parent)
   872             module = self.PluginRoot.GetChildByIECLocation(parent)
   891                     variable = child
   910                     variable = child
   892                 elif child["name"] == new_name:
   911                 elif child["name"] == new_name:
   893                     return "Error: A variable named %s already exists" % new_name
   912                     return "Error: A variable named %s already exists" % new_name
   894             if variable is None:
   913             if variable is None:
   895                 return "Error: No variable found"
   914                 return "Error: No variable found"
   896             variable["name"] = new_name
   915             if variable["name"] != new_name:
       
   916                 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
       
   917                 variable["name"] = new_name
   897             variable["type"] = LOCATION_TYPES[new_direction]
   918             variable["type"] = LOCATION_TYPES[new_direction]
   898             variable["IEC_type"] = new_type
   919             variable["IEC_type"] = new_type
   899             variable["declare"] = new_dcode
   920             variable["declare"] = new_dcode
   900             variable["retrieve"] = new_rcode
   921             variable["retrieve"] = new_rcode
   901             variable["publish"] = new_pcode
   922             variable["publish"] = new_pcode
   908             if module is None:
   929             if module is None:
   909                 return "Error: No parent found"
   930                 return "Error: No parent found"
   910             child = _GetModuleVariable(module, location)
   931             child = _GetModuleVariable(module, location)
   911             if child is None:
   932             if child is None:
   912                 return "Error: No variable found"
   933                 return "Error: No variable found"
       
   934             size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]
       
   935             address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
       
   936             self.PluginRoot.RemoveProjectVariableByAddress(address)
   913             _RemoveModuleChild(module, child)
   937             _RemoveModuleChild(module, child)
   914             self.RestartTimer()
   938             self.RestartTimer()
   915         
   939         
   916     def location(loc):
   940     def location(loc):
   917         return tuple(map(int, loc.split(".")))
   941         return tuple(map(int, loc.split(".")))
   976                                        "AddModule": ([location, int, str, str], 1), 
  1000                                        "AddModule": ([location, int, str, str], 1), 
   977                                        "RenameModule": ([location, str], 0),
  1001                                        "RenameModule": ([location, str], 0),
   978                                        "ChangeModuleIECChannel": ([location, int], 0),
  1002                                        "ChangeModuleIECChannel": ([location, int], 0),
   979                                        "RemoveModule": ([location, int], 0),
  1003                                        "RemoveModule": ([location, int], 0),
   980                                        "StartGroup": ([location, str, str], 1),
  1004                                        "StartGroup": ([location, str, str], 1),
   981                                        "AddVariable": ([location, location, str, str, str, str, str, str], 1),
  1005                                        "AddVariable": ([location, location, str, str, str, str, str, str, str], 1),
   982                                        "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str, str], 1),
  1006                                        "ChangeVariableParams": ([location, location, str, str, str, str, str, str, str], 1),
   983                                        "RemoveVariable": ([location, location], 0)}.iteritems():
  1007                                        "RemoveVariable": ([location, location], 0)}.iteritems():
   984         
  1008         
   985         setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
  1009         setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
   986     
  1010     
   987     lpcberemiz_cmd = LPCBeremiz_Cmd(projectOpen, buildpath)
  1011     lpcberemiz_cmd = LPCBeremiz_Cmd(projectOpen, buildpath)