editors/Viewer.py
changeset 1734 750eeb7230a1
parent 1730 64d8f52bc8c8
child 1736 7e61baa047f0
equal deleted inserted replaced
1733:dea107dce0c4 1734:750eeb7230a1
   229         scaling = self.ParentWindow.Scaling
   229         scaling = self.ParentWindow.Scaling
   230         message = None
   230         message = None
   231         try:
   231         try:
   232             values = eval(data)
   232             values = eval(data)
   233         except:
   233         except:
   234             message = _("Invalid value \"%s\" for viewer block")%data
   234             message = _("Invalid value \"%s\" for viewer block") % data
   235             values = None
   235             values = None
   236         if not isinstance(values, TupleType):
   236         if not isinstance(values, TupleType):
   237             message = _("Invalid value \"%s\" for viewer block")%data
   237             message = _("Invalid value \"%s\" for viewer block") % data
   238             values = None
   238             values = None
   239         if values is not None:
   239         if values is not None:
   240             if values[1] == "debug":
   240             if values[1] == "debug":
   241                 pass
   241                 pass
   242             elif values[1] == "program":
   242             elif values[1] == "program":
   243                 message = _("Programs can't be used by other POUs!")
   243                 message = _("Programs can't be used by other POUs!")
   244             elif values[1] in ["function", "functionBlock"]:
   244             elif values[1] in ["function", "functionBlock"]:
   245                 words = tagname.split("::")
   245                 words = tagname.split("::")
   246                 if pou_name == values[0]:
   246                 if pou_name == values[0]:
   247                     message = _("\"%s\" can't use itself!")%pou_name
   247                     message = _("\"%s\" can't use itself!") % pou_name
   248                 elif pou_type == "function" and values[1] != "function":
   248                 elif pou_type == "function" and values[1] != "function":
   249                     message = _("Function Blocks can't be used in Functions!")
   249                     message = _("Function Blocks can't be used in Functions!")
   250                 elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug):
   250                 elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug):
   251                     message = _("\"{a1}\" is already used by \"{a2}\"!").format(a1 = pou_name, a2 = values[0])
   251                     message = _("\"{a1}\" is already used by \"{a2}\"!").format(a1 = pou_name, a2 = values[0])
   252                 else:
   252                 else:
   256                     else:
   256                     else:
   257                         blockinputs = None
   257                         blockinputs = None
   258                     if values[1] != "function" and blockname == "":
   258                     if values[1] != "function" and blockname == "":
   259                         blockname = self.ParentWindow.GenerateNewName(blocktype=values[0])
   259                         blockname = self.ParentWindow.GenerateNewName(blocktype=values[0])
   260                     if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   260                     if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   261                         message = _("\"%s\" pou already exists!")%blockname
   261                         message = _("\"%s\" pou already exists!") % blockname
   262                     elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   262                     elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   263                         message = _("\"%s\" element for this pou already exists!")%blockname
   263                         message = _("\"%s\" element for this pou already exists!") % blockname
   264                     else:
   264                     else:
   265                         id = self.ParentWindow.GetNewId()
   265                         id = self.ParentWindow.GetNewId()
   266                         block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
   266                         block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
   267                         width, height = block.GetMinSize()
   267                         width, height = block.GetMinSize()
   268                         if scaling is not None:
   268                         if scaling is not None:
   311                     var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   311                     var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   312                     dlg.Destroy()
   312                     dlg.Destroy()
   313                     if var_name is None:
   313                     if var_name is None:
   314                         return
   314                         return
   315                     elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   315                     elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   316                         message = _("\"%s\" pou already exists!")%var_name
   316                         message = _("\"%s\" pou already exists!") % var_name
   317                     elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   317                     elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   318                         if location[1] == "Q":
   318                         if location[1] == "Q":
   319                             var_class = OUTPUT
   319                             var_class = OUTPUT
   320                         else:
   320                         else:
   321                             var_class = INPUT
   321                             var_class = INPUT
   326                         self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, location=location, description=values[4])
   326                         self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, location=location, description=values[4])
   327                         self.ParentWindow.RefreshVariablePanel()
   327                         self.ParentWindow.RefreshVariablePanel()
   328                         self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   328                         self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   329                         self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
   329                         self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
   330                     else:
   330                     else:
   331                         message = _("\"%s\" element for this pou already exists!")%var_name
   331                         message = _("\"%s\" element for this pou already exists!") % var_name
   332             elif values[1] == "NamedConstant":
   332             elif values[1] == "NamedConstant":
   333                 if pou_type == "program":
   333                 if pou_type == "program":
   334                     initval = values[0]
   334                     initval = values[0]
   335                     var_name = values[3]
   335                     var_name = values[3]
   336                     dlg = wx.TextEntryDialog(
   336                     dlg = wx.TextEntryDialog(
   341                     var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   341                     var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   342                     dlg.Destroy()
   342                     dlg.Destroy()
   343                     if var_name is None:
   343                     if var_name is None:
   344                         return
   344                         return
   345                     elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   345                     elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   346                         message = _("\"%s\" pou already exists!")%var_name
   346                         message = _("\"%s\" pou already exists!") % var_name
   347                     elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   347                     elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   348                         var_class = INPUT
   348                         var_class = INPUT
   349                         var_type = values[2]
   349                         var_type = values[2]
   350                         self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, description=values[4], initval=initval)
   350                         self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, description=values[4], initval=initval)
   351                         self.ParentWindow.RefreshVariablePanel()
   351                         self.ParentWindow.RefreshVariablePanel()
   352                         self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   352                         self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   353                         self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
   353                         self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
   354                     else:
   354                     else:
   355                         message = _("\"%s\" element for this pou already exists!")%var_name
   355                         message = _("\"%s\" element for this pou already exists!") % var_name
   356             elif values[1] == "Global":
   356             elif values[1] == "Global":
   357                 var_name = values[0]
   357                 var_name = values[0]
   358                 dlg = wx.TextEntryDialog(
   358                 dlg = wx.TextEntryDialog(
   359                     self.ParentWindow.ParentWindow,
   359                     self.ParentWindow.ParentWindow,
   360                     _("Confirm or change variable name"),
   360                     _("Confirm or change variable name"),
   363                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   363                 var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
   364                 dlg.Destroy()
   364                 dlg.Destroy()
   365                 if var_name is None:
   365                 if var_name is None:
   366                     return
   366                     return
   367                 elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   367                 elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
   368                     message = _("\"%s\" pou already exists!")%var_name
   368                     message = _("\"%s\" pou already exists!") % var_name
   369                 elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   369                 elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
   370                     self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name)
   370                     self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name)
   371                     self.ParentWindow.RefreshVariablePanel()
   371                     self.ParentWindow.RefreshVariablePanel()
   372                     self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   372                     self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
   373                     self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2])
   373                     self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2])
   374                 else:
   374                 else:
   375                     message = _("\"%s\" element for this pou already exists!")%var_name
   375                     message = _("\"%s\" element for this pou already exists!") % var_name
   376             elif values[1] == "Constant":
   376             elif values[1] == "Constant":
   377                 self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, values[0], None)
   377                 self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, values[0], None)
   378             elif values[3] == tagname:
   378             elif values[3] == tagname:
   379                 if values[1] == "Output":
   379                 if values[1] == "Output":
   380                     var_class = OUTPUT
   380                     var_class = OUTPUT
   989             block = element.GetParentBlock()
   989             block = element.GetParentBlock()
   990             if isinstance(block, FBD_Block):
   990             if isinstance(block, FBD_Block):
   991                 blockname = block.GetName()
   991                 blockname = block.GetName()
   992                 connectorname = element.GetName()
   992                 connectorname = element.GetName()
   993                 if blockname != "":
   993                 if blockname != "":
   994                     iec_path = "%s.%s.%s"%(instance_path, blockname, connectorname)
   994                     iec_path = "%s.%s.%s" % (instance_path, blockname, connectorname)
   995                 else:
   995                 else:
   996                     if connectorname == "":
   996                     if connectorname == "":
   997                         iec_path = "%s.%s%d"%(instance_path, block.GetType(), block.GetId())
   997                         iec_path = "%s.%s%d" % (instance_path, block.GetType(), block.GetId())
   998                     else:
   998                     else:
   999                         iec_path = "%s.%s%d_%s"%(instance_path, block.GetType(), block.GetId(), connectorname)
   999                         iec_path = "%s.%s%d_%s" % (instance_path, block.GetType(), block.GetId(), connectorname)
  1000             elif isinstance(block, FBD_Variable):
  1000             elif isinstance(block, FBD_Variable):
  1001                 iec_path = "%s.%s"%(instance_path, block.GetName())
  1001                 iec_path = "%s.%s" % (instance_path, block.GetName())
  1002             elif isinstance(block, FBD_Connector):
  1002             elif isinstance(block, FBD_Connector):
  1003                 connection = self.GetConnectorByName(block.GetName())
  1003                 connection = self.GetConnectorByName(block.GetName())
  1004                 if connection is not None:
  1004                 if connection is not None:
  1005                     connector = connection.GetConnector()
  1005                     connector = connection.GetConnector()
  1006                     if len(connector.Wires) == 1:
  1006                     if len(connector.Wires) == 1:
  1007                         iec_path = self.GetElementIECPath(connector.Wires[0][0])
  1007                         iec_path = self.GetElementIECPath(connector.Wires[0][0])
  1008         elif isinstance(element, LD_Contact):
  1008         elif isinstance(element, LD_Contact):
  1009             iec_path = "%s.%s"%(instance_path, element.GetName())
  1009             iec_path = "%s.%s" % (instance_path, element.GetName())
  1010         elif isinstance(element, SFC_Step):
  1010         elif isinstance(element, SFC_Step):
  1011             iec_path = "%s.%s.X"%(instance_path, element.GetName())
  1011             iec_path = "%s.%s.X" % (instance_path, element.GetName())
  1012         elif isinstance(element, SFC_Transition):
  1012         elif isinstance(element, SFC_Transition):
  1013             connectors = element.GetConnectors()
  1013             connectors = element.GetConnectors()
  1014             previous_steps = self.GetPreviousSteps(connectors["inputs"])
  1014             previous_steps = self.GetPreviousSteps(connectors["inputs"])
  1015             next_steps = self.GetNextSteps(connectors["outputs"])
  1015             next_steps = self.GetNextSteps(connectors["outputs"])
  1016             iec_path = "%s.%s->%s"%(instance_path, ",".join(previous_steps), ",".join(next_steps))
  1016             iec_path = "%s.%s->%s" % (instance_path, ",".join(previous_steps), ",".join(next_steps))
  1017         return iec_path
  1017         return iec_path
  1018 
  1018 
  1019     def GetWireModifier(self, wire):
  1019     def GetWireModifier(self, wire):
  1020         connector = wire.EndConnected
  1020         connector = wire.EndConnected
  1021         block = connector.GetParentBlock()
  1021         block = connector.GetParentBlock()
  1881         if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
  1881         if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
  1882             self.RemoveDivergenceBranch(self.SelectedElement)
  1882             self.RemoveDivergenceBranch(self.SelectedElement)
  1883 
  1883 
  1884     def OnEditBlockMenu(self, event):
  1884     def OnEditBlockMenu(self, event):
  1885         if self.SelectedElement is not None:
  1885         if self.SelectedElement is not None:
  1886             self.ParentWindow.EditProjectElement(ITEM_POU, "P::%s"%self.SelectedElement.GetType())
  1886             self.ParentWindow.EditProjectElement(ITEM_POU, "P::%s" % self.SelectedElement.GetType())
  1887 
  1887 
  1888     def OnAdjustBlockSizeMenu(self, event):
  1888     def OnAdjustBlockSizeMenu(self, event):
  1889         if self.SelectedElement is not None:
  1889         if self.SelectedElement is not None:
  1890             movex, movey = self.SelectedElement.SetBestSize(self.Scaling)
  1890             movex, movey = self.SelectedElement.SetBestSize(self.Scaling)
  1891             self.SelectedElement.RefreshModel(True)
  1891             self.SelectedElement.RefreshModel(True)
  2236                             "program": ITEM_PROGRAM,
  2236                             "program": ITEM_PROGRAM,
  2237                             "functionBlock": ITEM_FUNCTIONBLOCK,
  2237                             "functionBlock": ITEM_FUNCTIONBLOCK,
  2238                         }.get(self.Controler.GetPouType(instance_type))
  2238                         }.get(self.Controler.GetPouType(instance_type))
  2239                         if pou_type is not None and instance_type in self.Controler.GetProjectPouNames(self.Debug):
  2239                         if pou_type is not None and instance_type in self.Controler.GetProjectPouNames(self.Debug):
  2240                             self.ParentWindow.OpenDebugViewer(pou_type,
  2240                             self.ParentWindow.OpenDebugViewer(pou_type,
  2241                                 "%s.%s"%(self.GetInstancePath(True), self.SelectedElement.GetName()),
  2241                                 "%s.%s" % (self.GetInstancePath(True), self.SelectedElement.GetName()),
  2242                                 self.Controler.ComputePouName(instance_type))
  2242                                 self.Controler.ComputePouName(instance_type))
  2243                 else:
  2243                 else:
  2244                     iec_path = self.GetElementIECPath(self.SelectedElement)
  2244                     iec_path = self.GetElementIECPath(self.SelectedElement)
  2245                     if iec_path is not None:
  2245                     if iec_path is not None:
  2246                         if isinstance(self.SelectedElement, Wire):
  2246                         if isinstance(self.SelectedElement, Wire):