# HG changeset patch # User lbessard # Date 1192636227 -7200 # Node ID 9aa1fdfb7cb229eded697eecadfe94eebba0eebc # Parent 255eada206887c645d7c487b90c3b1eea48e865b A lots of bugs fixed diff -r 255eada20688 -r 9aa1fdfb7cb2 Dialogs.py --- a/Dialogs.py Fri Oct 05 18:11:51 2007 +0200 +++ b/Dialogs.py Wed Oct 17 17:50:27 2007 +0200 @@ -1473,7 +1473,8 @@ name='Inline', parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) self.Bind(wx.EVT_TEXT, self.OnInlineChanged, id=ID_TRANSITIONCONTENTDIALOGINLINE) - + self.Inline.Enable(False) + self.radioButton3 = wx.RadioButton(id=ID_TRANSITIONCONTENTDIALOGRADIOBUTTON3, label='Connection', name='radioButton3', parent=self, pos=wx.Point(0, 0), size=wx.Size(0, 24), style=0) @@ -1599,6 +1600,7 @@ self.Reference.Enable(False) self.Inline.Enable(False) self.Element.SetType("connection") + self.Priority.SetValue(values["priority"]) self.Element.SetPriority(values["priority"]) self.RefreshPreview() @@ -2062,6 +2064,7 @@ self.Bind(wx.EVT_BUTTON, self.OnDownButton, id=ID_ACTIONBLOCKDIALOGDOWNBUTTON) self.ButtonSizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE) + self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.ButtonSizer.GetAffirmativeButton().GetId()) self._init_sizers() @@ -2079,6 +2082,10 @@ self.Table.ResetView(self.ActionsGrid) + def OnOK(self, event): + self.ActionsGrid.SetGridCursor(0, 0) + self.EndModal(wx.ID_OK) + def OnAddButton(self, event): self.Table.AppendRow(self.DefaultValue.copy()) self.Table.ResetView(self.ActionsGrid) diff -r 255eada20688 -r 9aa1fdfb7cb2 PLCControler.py --- a/PLCControler.py Fri Oct 05 18:11:51 2007 +0200 +++ b/PLCControler.py Wed Oct 17 17:50:27 2007 +0200 @@ -515,6 +515,7 @@ if old_computedname in self.ElementsOpened: idx = self.ElementsOpened.index(old_computedname) self.ElementsOpened[idx] = new_computedname + pou.updateElementName(old_name, new_name) self.BufferProject() # Change the name of a pou action @@ -529,6 +530,7 @@ if old_computedname in self.ElementsOpened: idx = self.ElementsOpened.index(old_computedname) self.ElementsOpened[idx] = new_computedname + pou.updateElementName(old_name, new_name) self.BufferProject() # Change the name of a pou variable diff -r 255eada20688 -r 9aa1fdfb7cb2 PLCGenerator.py --- a/PLCGenerator.py Fri Oct 05 18:11:51 2007 +0200 +++ b/PLCGenerator.py Wed Oct 17 17:50:27 2007 +0200 @@ -268,8 +268,6 @@ self.SFCNetworks["Steps"][self.InitialSteps[0]]["actions"].append(action_infos) self.SFCNetworks["Actions"][action_name] = ReIndentText(self.SFCComputedBlocks, 4) self.Program = "" - else: - raise Exception for initialstep in self.InitialSteps: self.ComputeSFCStep(initialstep) diff -r 255eada20688 -r 9aa1fdfb7cb2 PLCOpenEditor.py --- a/PLCOpenEditor.py Fri Oct 05 18:11:51 2007 +0200 +++ b/PLCOpenEditor.py Wed Oct 17 17:50:27 2007 +0200 @@ -804,7 +804,7 @@ self.RefreshEditorNames(itemtype, old_name, new_name) self.RefreshTabsOpenedTitles() elif itemtype == ITEM_TRANSITION: - parent = self.ProjectTree.GetItemParent(selected) + parent = self.ProjectTree.GetItemParent(item) parent_type = self.ProjectTree.GetPyData(parent) while parent_type != ITEM_POU: parent = self.ProjectTree.GetItemParent(parent) @@ -820,7 +820,7 @@ self.RefreshEditorNames(itemtype, old_name, new_name) self.RefreshTabsOpenedTitles() elif itemtype == ITEM_ACTION: - parent = self.ProjectTree.GetItemParent(selected) + parent = self.ProjectTree.GetItemParent(item) parent_type = self.ProjectTree.GetPyData(parent) while parent_type != ITEM_POU: parent = self.ProjectTree.GetItemParent(parent) @@ -855,7 +855,7 @@ self.RefreshEditorNames(itemtype, old_name, new_name) self.RefreshTabsOpenedTitles() elif itemtype == ITEM_RESOURCE: - parent = self.ProjectTree.GetItemParent(selected) + parent = self.ProjectTree.GetItemParent(item) parent_type = self.ProjectTree.GetPyData(parent) while parent_type != ITEM_CONFIGURATION: parent = self.ProjectTree.GetItemParent(parent) @@ -889,6 +889,8 @@ event.Veto() else: wx.CallAfter(self.RefreshProjectTree) + window = self.TabsOpened.GetCurrentPage() + window.RefreshView() event.Skip() def OnProjectTreeItemBeginEdit(self, event): diff -r 255eada20688 -r 9aa1fdfb7cb2 Viewer.py --- a/Viewer.py Fri Oct 05 18:11:51 2007 +0200 +++ b/Viewer.py Wed Oct 17 17:50:27 2007 +0200 @@ -53,6 +53,7 @@ self.ParentWindow = parent def OnDropText(self, x, y, data): + x, y = self.ParentWindow.CalcUnscrolledPosition(x, y) values = eval(data) if values[1] == "program": message = wx.MessageDialog(self.ParentWindow, "Programs can't be used by other POUs!", "Error", wx.OK|wx.ICON_ERROR) @@ -1286,6 +1287,46 @@ self.Refresh(False) dialog.Destroy() + def AddNewJump(self, bbox): + choices = [] + for block in self.Blocks: + if isinstance(block, SFC_Step): + choices.append(block.GetName()) + dialog = wx.SingleChoiceDialog(self.ParentWindow, "Add a new jump", "Please choose a target", choices, wx.OK|wx.CANCEL) + if dialog.ShowModal() == wx.ID_OK: + id = self.GetNewId() + value = dialog.GetStringSelection() + jump = SFC_Jump(self, value, id) + jump.SetPosition(bbox.x, bbox.y) + min_width, min_height = jump.GetMinSize() + jump.SetSize(max(bbox.width, min_width), max(bbox.height, min_height)) + self.AddBlock(jump) + self.Controler.AddCurrentElementEditingJump(id) + self.RefreshJumpModel(jump) + self.RefreshBuffer() + self.RefreshScrollBars() + self.Refresh() + dialog.Destroy() + + def AddNewActionBlock(self, bbox): + dialog = ActionBlockDialog(self.ParentWindow) + dialog.SetQualifierList(self.Controler.GetQualifierTypes()) + dialog.SetActionList(self.Controler.GetCurrentElementEditingActions()) + dialog.SetVariableList(self.Controler.GetCurrentElementEditingInterfaceVars()) + if dialog.ShowModal() == wx.ID_OK: + actions = dialog.GetValues() + id = self.GetNewId() + actionblock = SFC_ActionBlock(self, actions, id) + actionblock.SetPosition(bbox.x, bbox.y) + min_width, min_height = actionblock.GetMinSize() + actionblock.SetSize(max(bbox.width, min_width), max(bbox.height, min_height)) + self.AddBlock(actionblock) + self.Controler.AddCurrentElementEditingActionBlock(id) + self.RefreshActionBlockModel(actionblock) + self.RefreshBuffer() + self.RefreshScrollBars() + self.Refresh() + dialog.Destroy() #------------------------------------------------------------------------------- # Edit element content functions @@ -1716,9 +1757,9 @@ for element in connector.GetConnectedBlocks(): if element not in elements: elements.append(element) - powerrrail.Clean() - self.RemoveBlock(powerrrail) - self.Controler.RemoveCurrentElementEditingInstance(powerrrail.GetId()) + powerrail.Clean() + self.RemoveBlock(powerrail) + self.Controler.RemoveCurrentElementEditingInstance(powerrail.GetId()) for element in elements: element.RefreshModel() diff -r 255eada20688 -r 9aa1fdfb7cb2 graphics/GraphicCommons.py --- a/graphics/GraphicCommons.py Fri Oct 05 18:11:51 2007 +0200 +++ b/graphics/GraphicCommons.py Wed Oct 17 17:50:27 2007 +0200 @@ -497,7 +497,7 @@ height += movey # Verify that new size is not lesser than minimum min_width, min_height = self.GetMinSize() - if width >= min_width and height >= min_height: + if width >= min_width and height >= min_height or width >= self.Size[0] and height >= self.Size[1]: self.Resize(x, y, width, height) # If it is a move handle, Move this element elif handle_type == HANDLE_MOVE: @@ -1103,8 +1103,8 @@ maxx, maxbbxx = max(maxx, self.Points[-1].x), max(maxbbxx, self.Points[-1].x + end_radius) miny, minbbxy = min(miny, self.Points[-1].y), min(minbbxy, self.Points[-1].y - end_radius) maxy, maxbbxy = max(maxy, self.Points[-1].y), max(maxbbxy, self.Points[-1].y + end_radius) - self.Pos = wx.Point(minx, miny) - self.Size = wx.Size(maxx -minx + 1, maxy - miny + 1) + self.Pos.x, self.Pos.y = minx, miny + self.Size = wx.Size(maxx - minx + 1, maxy - miny + 1) self.BoundingBox = wx.Rect(minbbxx, minbbxy, maxbbxx - minbbxx + 1, maxbbxy - minbbxy + 1) # Refresh the realpoints that permits to keep the proportionality in wire during resizing diff -r 255eada20688 -r 9aa1fdfb7cb2 graphics/SFC_Objects.py --- a/graphics/SFC_Objects.py Fri Oct 05 18:11:51 2007 +0200 +++ b/graphics/SFC_Objects.py Wed Oct 17 17:50:27 2007 +0200 @@ -52,7 +52,7 @@ self.Size = wx.Size(SFC_STEP_DEFAULT_SIZE[0], SFC_STEP_DEFAULT_SIZE[1]) # Create an input and output connector if not self.Initial: - self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) else: self.Input = None self.Output = None @@ -80,7 +80,7 @@ # Add output connector to step def AddInput(self): if not self.Input: - self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) self.RefreshBoundingBox() # Remove output connector from step @@ -93,7 +93,7 @@ # Add output connector to step def AddOutput(self): if not self.Output: - self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) + self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) self.RefreshBoundingBox() # Remove output connector from step @@ -106,7 +106,7 @@ # Add action connector to step def AddAction(self): if not self.Action: - self.Action = Connector(self, "", "ANY", wx.Point(self.Size[0], self.Size[1] / 2), EAST) + self.Action = Connector(self, "", None, wx.Point(self.Size[0], self.Size[1] / 2), EAST) self.RefreshBoundingBox() # Remove action connector from step @@ -199,6 +199,9 @@ # Test output connector if self.Output and self.Output.TestPoint(pt, exclude): return self.Output + # Test action connector + if self.Action and self.Action.TestPoint(pt, exclude): + return self.Action return None # Changes the step name @@ -262,7 +265,10 @@ diffy = height - self.Size.GetHeight() self.Move(diffx, 0) Graphic_Element.SetSize(self, width, height) - self.RefreshOutputPosition((0, diffy)) + if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: + self.RefreshConnected() + else: + self.RefreshOutputPosition((0, diffy)) # Align input element with this step def RefreshInputPosition(self): @@ -443,8 +449,8 @@ self.Priority = 0 self.Size = wx.Size(SFC_TRANSITION_SIZE[0], SFC_TRANSITION_SIZE[1]) # Create an input and output connector - self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH) - self.Output = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) + self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH) self.SetType(type, condition) self.SetPriority(priority) @@ -776,15 +782,15 @@ self.Size = wx.Size((number - 1) * SFC_DEFAULT_SEQUENCE_INTERVAL, 3) # Create an input and output connector if self.Type in [SELECTION_DIVERGENCE, SIMULTANEOUS_DIVERGENCE]: - self.Inputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH)] + self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)] self.Outputs = [] for i in xrange(number): - self.Outputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)) + self.Outputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH)) elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: self.Inputs = [] for i in xrange(number): - self.Inputs.append(Connector(self, "", "ANY", wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)) - self.Outputs = [Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)] + self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)) + self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH)] # Destructor def __del__(self): @@ -818,7 +824,7 @@ for output in self.Outputs: pos = output.GetRelPosition() maxx = max(maxx, pos.x) - connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH) + connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, self.Size[1]), SOUTH) self.Outputs.append(connector) self.MoveConnector(connector, 0) elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]: @@ -826,7 +832,7 @@ for input in self.Inputs: pos = input.GetRelPosition() maxx = max(maxx, pos.x) - connector = Connector(self, "", "ANY", wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH) + connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH) self.Inputs.append(connector) self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL) @@ -1149,7 +1155,7 @@ self.Id = id self.Size = wx.Size(SFC_JUMP_SIZE[0], SFC_JUMP_SIZE[1]) # Create an input and output connector - self.Input = Connector(self, "", "ANY", wx.Point(self.Size[0] / 2, 0), NORTH) + self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH) # Destructor def __del__(self): @@ -1318,8 +1324,9 @@ Graphic_Element.__init__(self, parent) self.Id = id self.Size = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) + self.MinSize = wx.Size(SFC_ACTION_MIN_SIZE[0], SFC_ACTION_MIN_SIZE[1]) # Create an input and output connector - self.Input = Connector(self, "", "ANY", wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST) + self.Input = Connector(self, "", None, wx.Point(0, SFC_ACTION_MIN_SIZE[1] / 2), WEST) self.SetActions(actions) # Destructor @@ -1331,7 +1338,7 @@ return len(self.Actions) def GetLineSize(self): - if len(self.Actions) > 1: + if len(self.Actions) > 0: return self.Size[1] / len(self.Actions) else: return SFC_ACTION_MIN_SIZE[1] @@ -1376,30 +1383,40 @@ dc = wx.ClientDC(self.Parent) self.Actions = actions self.ColSize = [0, 0, 0] + min_height = 0 for action in self.Actions: width, height = dc.GetTextExtent(action["qualifier"]) self.ColSize[0] = max(self.ColSize[0], width + 10) + row_height = height if "duration" in action: width, height = dc.GetTextExtent(action["duration"]) + row_height = max(row_height, height) self.ColSize[0] = max(self.ColSize[0], width + 10) width, height = dc.GetTextExtent(action["value"]) + row_height = max(row_height, height) self.ColSize[1] = max(self.ColSize[1], width + 10) if "indicator" in action and action["indicator"] != "": width, height = dc.GetTextExtent(action["indicator"]) + row_height = max(row_height, height) self.ColSize[2] = max(self.ColSize[2], width + 10) + min_height += row_height + 5 if self.Parent.GetDrawingMode() == FREEDRAWING_MODE: - line_size = self.GetLineSize() - self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], len(self.Actions) * line_size) + self.Size = wx.Size(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], max(min_height, SFC_ACTION_MIN_SIZE[1], self.Size[1])) + self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], + SFC_ACTION_MIN_SIZE[0]), max(SFC_ACTION_MIN_SIZE[1], min_height) + self.RefreshBoundingBox() else: self.Size = wx.Size(max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1]) - self.RefreshBoundingBox() - if self.Input: - wires = self.Input.GetWires() - if len(wires) == 1: - input_block = wires[0][0].EndConnected.GetParentBlock() - input_block.RefreshOutputPosition() - input_block.RefreshOutputModel(True) + self.MinSize = max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], + SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] + self.RefreshBoundingBox() + if self.Input: + wires = self.Input.GetWires() + if len(wires) == 1: + input_block = wires[0][0].EndConnected.GetParentBlock() + input_block.RefreshOutputPosition() + input_block.RefreshOutputModel(True) # Returns the action block actions def GetActions(self): @@ -1407,8 +1424,7 @@ # Returns the action block minimum size def GetMinSize(self): - return max(self.ColSize[0] + self.ColSize[1] + self.ColSize[2], - SFC_ACTION_MIN_SIZE[0]), len(self.Actions) * SFC_ACTION_MIN_SIZE[1] + return self.MinSize # Method called when a LeftDClick event have been generated def OnLeftDClick(self, event, dc, scaling): diff -r 255eada20688 -r 9aa1fdfb7cb2 plcopen/plcopen.py --- a/plcopen/plcopen.py Fri Oct 05 18:11:51 2007 +0200 +++ b/plcopen/plcopen.py Wed Oct 17 17:50:27 2007 +0200 @@ -1090,6 +1090,8 @@ for action in self.action: params = {} params["qualifier"] = action.getQualifierValue() + if params["qualifier"] is None: + params["qualifier"] = "N" if action.getReference(): params["type"] = "reference" params["value"] = action.getReferenceName() diff -r 255eada20688 -r 9aa1fdfb7cb2 plcopen/structures.py --- a/plcopen/structures.py Fri Oct 05 18:11:51 2007 +0200 +++ b/plcopen/structures.py Wed Oct 17 17:50:27 2007 +0200 @@ -44,7 +44,7 @@ for variable in block.inputVariables.getVariable(): connections = variable.connectionPointIn.getConnections() if connections and len(connections) == 1: - if body_type == "FBD": + if body_type == "FBD" or body_type == "SFC": value = generator.ComputeFBDExpression(body, connections[0]) elif body_type == "LD": paths = generator.GenerateLDPaths(variable.connectionPointIn.getConnections(), body) @@ -63,7 +63,7 @@ connections = variable.connectionPointIn.getConnections() if connections and len(connections) == 1: parameter = variable.getFormalParameter() - if body_type == "FBD": + if body_type == "FBD" or body_type == "SFC": value = generator.ComputeFBDExpression(body, connections[0]) vars.append("%s := %s"%(parameter, generator.ExtractModifier(variable, value))) elif body_type == "LD":