--- a/editors/Viewer.py Thu Oct 18 12:05:45 2012 +0200
+++ b/editors/Viewer.py Thu Oct 18 16:30:12 2012 +0200
@@ -1378,6 +1378,16 @@
self.ReleaseDataValue(iec_path)
return ReleaseVariableFunction
+ def GetChangeVariableTypeMenuFunction(self, type): + def ChangeVariableTypeMenu(event): + self.ChangeVariableType(self.SelectedElement, type) + return ChangeVariableTypeMenu + def GetChangeConnectionTypeMenuFunction(self, type): + def ChangeConnectionTypeMenu(event): + self.ChangeConnectionType(self.SelectedElement, type) + return ChangeConnectionTypeMenu def PopupForceMenu(self):
iec_path = self.GetElementIECPath(self.SelectedElement)
@@ -1405,6 +1415,37 @@
self.Editor.PopupMenu(menu)
+ def PopupVariableMenu(self): + menu = wx.Menu(title='') + variable_type = self.SelectedElement.GetType() + for type_label, type in [(_("Input"), INPUT), + AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label) + self.Bind(wx.EVT_MENU, self.GetChangeVariableTypeMenuFunction(type), id=new_id) + if type == variable_type: + menu.Check(new_id, True) + self.AddDefaultMenuItems(menu, block=True) + self.Editor.PopupMenu(menu) + def PopupConnectionMenu(self): + menu = wx.Menu(title='') + connection_type = self.SelectedElement.GetType() + for type_label, type in [(_("Connector"), CONNECTOR), + (_("Continuation"), CONTINUATION)]: + AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_RADIO, text=type_label) + self.Bind(wx.EVT_MENU, self.GetChangeConnectionTypeMenuFunction(type), id=new_id) + if type == connection_type: + menu.Check(new_id, True) + self.AddDefaultMenuItems(menu, block=True) + self.Editor.PopupMenu(menu) def PopupWireMenu(self, delete=True):
self.AddWireMenuItems(menu, delete)
@@ -1846,7 +1887,7 @@
self.ParentWindow.OpenGraphicViewer(iec_path)
elif event.ControlDown() and not event.ShiftDown():
- if not isinstance(self.SelectedElement, Group_Element):
+ if not isinstance(self.SelectedElement, Graphic_Group): instance_type = self.SelectedElement.GetType()
if self.IsBlock(self.SelectedElement) and instance_type in self.Controler.GetProjectPouNames(self.Debug):
self.ParentWindow.EditProjectElement(ITEM_POU,
@@ -1855,9 +1896,9 @@
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
elif event.ControlDown() and event.ShiftDown():
movex, movey = self.SelectedElement.SetBestSize(self.Scaling)
- self.SelectedElement.RefreshModel()
if movex != 0 or movey != 0:
+ self.SelectedElement.RefreshModel() self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
@@ -2704,6 +2745,20 @@
infos["connectors"] = block.GetConnectors()
self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
+ def ChangeVariableType(self, variable, new_type): + old_type = variable.GetType() + rect = variable.GetRedrawRect(1, 1) + if old_type != new_type: + variable.SetType(new_type, variable.GetValueType()) + self.Controler.RemoveEditedElementInstance(self.TagName, id) + self.Controler.AddEditedElementVariable(self.TagName, id, new_type) + self.RefreshVariableModel(variable) + self.RefreshVisibleElements() + self.RefreshScrollBars() + variable.Refresh(rect.Union(variable.GetRedrawRect())) def RefreshVariableModel(self, variable):
variableid = variable.GetId()
@@ -2715,6 +2770,20 @@
infos["connectors"] = variable.GetConnectors()
self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos)
+ def ChangeConnectionType(self, connection, new_type): + old_type = connection.GetType() + rect = connection.GetRedrawRect(1, 1) + if old_type != new_type: + connection.SetType(new_type) + id = connection.GetId() + self.Controler.RemoveEditedElementInstance(self.TagName, id) + self.Controler.AddEditedElementConnection(self.TagName, id, new_type) + self.RefreshConnectionModel(connection) + self.RefreshScrollBars() + self.RefreshVisibleElements() + connection.Refresh(rect.Union(connection.GetRedrawRect())) def RefreshConnectionModel(self, connection):
connectionid = connection.GetId()
--- a/graphics/FBD_Objects.py Thu Oct 18 12:05:45 2012 +0200
+++ b/graphics/FBD_Objects.py Thu Oct 18 16:30:12 2012 +0200
@@ -652,26 +652,34 @@
def SetType(self, type, value_type):
# Create an input or output connector according to variable type
- self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True)
+ self.Input = Connector(self, "", value_type, wx.Point(0, 0), WEST, onlyone = True) + self.Input.UnConnect(delete = True) - self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST)
+ if self.Output is None: + self.Output = Connector(self, "", value_type, wx.Point(0, 0), EAST) + self.Output.UnConnect(delete = True) elif value_type != self.ValueType:
self.Input.SetType(value_type)
self.Output.SetType(value_type)
- self.RefreshConnectors()
# Returns the variable type
+ # Returns the variable value type + def GetValueType(self): # Changes the variable name
@@ -705,12 +713,18 @@
# Method called when a LeftDClick event have been generated
def OnLeftDClick(self, event, dc, scaling):
- # Edit the variable properties
- self.Parent.EditVariableContent(self)
+ if event.ControlDown(): + types = [INPUT, OUTPUT, INOUT] + self.Parent.ChangeVariableType(self, + types[(types.index(self.Type) + 1) % len(types)]) + # Edit the variable properties + self.Parent.EditVariableContent(self) # Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
- self.Parent.PopupDefaultMenu()
+ self.Parent.PopupVariableMenu() # Refreshes the variable model
def RefreshModel(self, move=True):
@@ -927,13 +941,20 @@
# Method called when a LeftDClick event have been generated
def OnLeftDClick(self, event, dc, scaling):
- # Edit the connection properties
- self.Parent.EditConnectionContent(self)
+ if event.ControlDown(): + # Change connection type + if self.Type == CONNECTOR: + self.Parent.ChangeConnectionType(self, CONTINUATION) + self.Parent.ChangeConnectionType(self, CONNECTOR) + # Edit the connection properties + self.Parent.EditConnectionContent(self) # Method called when a RightUp event have been generated
def OnRightUp(self, event, dc, scaling):
- self.Parent.PopupDefaultMenu()
+ self.Parent.PopupConnectionMenu() # Refreshes the connection model
def RefreshModel(self, move=True):
--- a/graphics/GraphicCommons.py Thu Oct 18 12:05:45 2012 +0200
+++ b/graphics/GraphicCommons.py Thu Oct 18 16:30:12 2012 +0200
@@ -1667,8 +1667,9 @@
# If no wire defined, unconnect all wires
- self.ParentBlock.RefreshModel(False)
+ self.ParentBlock.RefreshModel(False) # Returns if connector has one or more wire connected