--- a/graphics/SFC_Objects.py Fri Jan 04 17:49:17 2008 +0100
+++ b/graphics/SFC_Objects.py Fri Jan 11 17:51:56 2008 +0100
@@ -125,7 +125,7 @@
# Add output connector to step
def AddOutput(self):
if not self.Output:
- self.Output = Connector(self, "", None, 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, onlyone = True)
self.RefreshBoundingBox()
# Remove output connector from step
@@ -138,7 +138,7 @@
# Add action connector to step
def AddAction(self):
if not self.Action:
- self.Action = Connector(self, "", None, 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, onlyone = True)
self.RefreshBoundingBox()
# Remove action connector from step
@@ -171,15 +171,21 @@
# Refresh the positions of the step connectors
def RefreshConnectors(self):
+ scaling = self.Parent.GetScaling()
+ horizontal_pos = self.Size[0] / 2
+ vertical_pos = self.Size[1] / 2
+ if scaling is not None:
+ horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
+ vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
# Update input position if it exists
if self.Input:
- self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
+ self.Input.SetPosition(wx.Point(horizontal_pos, 0))
# Update output position
if self.Output:
- self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1]))
+ self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1]))
# Update action position if it exists
if self.Action:
- self.Action.SetPosition(wx.Point(self.Size[0], self.Size[1] / 2))
+ self.Action.SetPosition(wx.Point(self.Size[0], vertical_pos))
self.RefreshConnected()
# Refresh the position of wires connected to step
@@ -253,7 +259,7 @@
if self.Input:
wires = self.Input.GetWires()
if len(wires) == 1:
- return wires[0][0].EndConnected
+ return wires[0][0].GetOtherConnected(self.Input)
return None
# Returns the connector connected to output
@@ -261,7 +267,7 @@
if self.Output:
wires = self.Output.GetWires()
if len(wires) == 1:
- return wires[0][0].StartConnected
+ return wires[0][0].GetOtherConnected(self.Output)
return None
# Returns the connector connected to action
@@ -269,7 +275,7 @@
if self.Action:
wires = self.Action.GetWires()
if len(wires) == 1:
- return wires[0][0].StartConnected
+ return wires[0][0].GetOtherConnected(self.Action)
return None
# Returns the number of action line
@@ -278,7 +284,7 @@
wires = self.Action.GetWires()
if len(wires) != 1:
return 0
- action_block = wires[0][0].StartConnected.GetParentBlock()
+ action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock()
return max(0, action_block.GetLineNumber() - 1)
return 0
@@ -326,7 +332,7 @@
if len(wires) != 1:
return
current_pos = self.Output.GetPosition(False)
- output = wires[0][0].StartConnected
+ output = wires[0][0].GetOtherConnected(self.Output)
output_pos = output.GetPosition(False)
diffx = current_pos.x - output_pos.x
output_block = output.GetParentBlock()
@@ -365,7 +371,7 @@
wires = self.Action.GetWires()
if len(wires) != 1:
return
- action_block = wires[0][0].StartConnected.GetParentBlock()
+ action_block = wires[0][0].GetOtherConnected(self.Action).GetParentBlock()
action_block.Move(move[0], move[1], self.Parent.Wires)
wires[0][0].Move(move[0], move[1], True)
@@ -387,11 +393,14 @@
self.Parent.PopupDefaultMenu()
# Refreshes the step state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
handle_type, handle = self.Handle
if handle_type == HANDLE_MOVE:
movex = max(-self.BoundingBox.x, movex)
movey = max(-self.BoundingBox.y, movey)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
+ movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y
action_block = None
if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
self.Move(movex, movey)
@@ -409,7 +418,7 @@
self.RefreshOutputPosition()
return movex, 0
else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
# Refresh input element model
def RefreshInputModel(self):
@@ -487,8 +496,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, "", 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.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
+ self.Output = Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)
self.SetType(type, condition)
self.SetPriority(priority)
@@ -582,24 +591,30 @@
def GetPreviousConnector(self):
wires = self.Input.GetWires()
if len(wires) == 1:
- return wires[0][0].EndConnected
+ return wires[0][0].GetOtherConnected(self.Input)
return None
# Returns the connector connected to output
def GetNextConnector(self):
wires = self.Output.GetWires()
if len(wires) == 1:
- return wires[0][0].StartConnected
+ return wires[0][0].GetOtherConnected(self.Output)
return None
# Refresh the positions of the transition connectors
def RefreshConnectors(self):
+ scaling = self.Parent.GetScaling()
+ horizontal_pos = self.Size[0] / 2
+ vertical_pos = self.Size[1] / 2
+ if scaling is not None:
+ horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
+ vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
# Update input position
- self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
+ self.Input.SetPosition(wx.Point(horizontal_pos, 0))
# Update output position
- self.Output.SetPosition(wx.Point(self.Size[0] / 2, self.Size[1]))
+ self.Output.SetPosition(wx.Point(horizontal_pos, self.Size[1]))
if self.Type == "connection":
- self.Condition.SetPosition(wx.Point(0, self.Size[1] / 2))
+ self.Condition.SetPosition(wx.Point(0, vertical_pos))
self.RefreshConnected()
# Refresh the position of the wires connected to transition
@@ -722,7 +737,7 @@
if len(wires) != 1:
return
current_pos = self.Output.GetPosition(False)
- output = wires[0][0].StartConnected
+ output = wires[0][0].GetOtherConnected(self.Output)
output_pos = output.GetPosition(False)
diffx = current_pos.x - output_pos.x
output_block = output.GetParentBlock()
@@ -754,15 +769,17 @@
self.Parent.PopupDefaultMenu()
# Refreshes the transition state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = max(-self.BoundingBox.x, movex)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
self.Move(movex, 0)
self.RefreshInputPosition()
self.RefreshOutputPosition()
return movex, 0
else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
# Refresh input element model
def RefreshInputModel(self):
@@ -845,15 +862,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, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)]
+ self.Inputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)]
self.Outputs = []
for i in xrange(number):
- self.Outputs.append(Connector(self, "", None, 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, onlyone = True))
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
self.Inputs = []
for i in xrange(number):
- 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)]
+ self.Inputs.append(Connector(self, "", None, wx.Point(i * SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True))
+ self.Outputs = [Connector(self, "", None, wx.Point(self.Size[0] / 2, self.Size[1]), SOUTH, onlyone = True)]
# Destructor
def __del__(self):
@@ -909,7 +926,7 @@
for output in self.Outputs:
pos = output.GetRelPosition()
maxx = max(maxx, pos.x)
- connector = Connector(self, "", None, 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, onlyone = True)
self.Outputs.append(connector)
self.MoveConnector(connector, 0)
elif self.Type in [SELECTION_CONVERGENCE, SIMULTANEOUS_CONVERGENCE]:
@@ -917,7 +934,7 @@
for input in self.Inputs:
pos = input.GetRelPosition()
maxx = max(maxx, pos.x)
- connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH)
+ connector = Connector(self, "", None, wx.Point(maxx + SFC_DEFAULT_SEQUENCE_INTERVAL, 0), NORTH, onlyone = True)
self.Inputs.append(connector)
self.MoveConnector(connector, SFC_DEFAULT_SEQUENCE_INTERVAL)
@@ -954,11 +971,11 @@
# Refresh the divergence bounding box
def RefreshBoundingBox(self):
if self.Type in [SELECTION_DIVERGENCE, SELECTION_CONVERGENCE]:
- self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y - 2,
- self.Size[0] + 1, self.Size[1] + 5)
+ self.BoundingBox = wx.Rect(self.Pos.x, self.Pos.y,
+ self.Size[0] + 1, self.Size[1] + 1)
elif self.Type in [SIMULTANEOUS_DIVERGENCE, SIMULTANEOUS_CONVERGENCE]:
- self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y - 2,
- self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 5)
+ self.BoundingBox = wx.Rect(self.Pos.x - SFC_SIMULTANEOUS_SEQUENCE_EXTRA, self.Pos.y,
+ self.Size[0] + 2 * SFC_SIMULTANEOUS_SEQUENCE_EXTRA + 1, self.Size[1] + 1)
# Refresh the position of wires connected to divergence
def RefreshConnected(self, exclude = []):
@@ -1073,10 +1090,7 @@
if len(wires) != 1:
return
current_pos = connector.GetPosition(False)
- if connector in self.Inputs:
- next = wires[0][0].EndConnected
- else:
- next = wires[0][0].StartConnected
+ next = wires[0][0].GetOtherConnected(connector)
next_pos = next.GetPosition(False)
diffx = current_pos.x - next_pos.x
next_block = next.GetParentBlock()
@@ -1096,7 +1110,7 @@
wires = input.GetWires()
if len(wires) != 1:
return
- previous = wires[0][0].EndConnected
+ previous = wires[0][0].GetOtherConnected(input)
previous_pos = previous.GetPosition(False)
y = max(y, previous_pos.y + GetWireSize(previous.GetParentBlock()))
diffy = y - self.Pos.y
@@ -1114,7 +1128,7 @@
if len(wires) != 1:
return
current_pos = output_connector.GetPosition(False)
- output = wires[0][0].StartConnected
+ output = wires[0][0].GetOtherConnected(self.Output)
output_pos = output.GetPosition(False)
diffx = current_pos.x - output_pos.x
output_block = output.GetParentBlock()
@@ -1127,6 +1141,22 @@
# Method called when a LeftDown event have been generated
def OnLeftDown(self, event, dc, scaling):
+ self.RealConnectors = {"Inputs":[],"Outputs":[]}
+ for input in self.Inputs:
+ position = input.GetRelPosition()
+ self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
+ for output in self.Outputs:
+ position = output.GetRelPosition()
+ self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
+ Graphic_Element.OnLeftDown(self, event, dc, scaling)
+
+ # Method called when a LeftUp event have been generated
+ def OnLeftUp(self, event, dc, scaling):
+ Graphic_Element.OnLeftUp(self, event, dc, scaling)
+ self.RealConnectors = None
+
+ # Method called when a RightDown event have been generated
+ def OnRightDown(self, event, dc, scaling):
pos = GetScaledEventPosition(event, dc, scaling)
# Test if a connector have been handled
connector = self.TestConnector(pos, False)
@@ -1137,59 +1167,48 @@
# Initializes the last position
self.oldPos = GetScaledEventPosition(event, dc, scaling)
else:
- self.RealConnectors = {"Inputs":[],"Outputs":[]}
- for input in self.Inputs:
- position = input.GetRelPosition()
- self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0]))
- for output in self.Outputs:
- position = output.GetRelPosition()
- self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0]))
- Graphic_Element.OnLeftDown(self, event, dc, scaling)
-
- # Method called when a LeftUp event have been generated
- def OnLeftUp(self, event, dc, scaling):
- self.RealConnectors = None
+ Graphic_Element.OnRightDown(self, event, dc, scaling)
+
+ # Method called when a RightUp event have been generated
+ def OnRightUp(self, event, dc, scaling):
handle_type, handle = self.Handle
if handle_type == HANDLE_CONNECTOR:
wires = handle.GetWires()
if len(wires) != 1:
return
- if handle in self.Inputs:
- block = wires[0][0].EndConnected.GetParentBlock()
- else:
- block = wires[0][0].StartConnected.GetParentBlock()
+ block = wires[0][0].GetOtherConnected(handle).GetParentBlock()
block.RefreshModel(False)
if not isinstance(block, SFC_Divergence):
if handle in self.Inputs:
block.RefreshInputModel()
else:
block.RefreshOutputModel()
- Graphic_Element.OnLeftUp(self, event, dc, scaling)
-
- # Method called when a RightUp event have been generated
- def OnRightUp(self, event, dc, scaling):
- pos = GetScaledEventPosition(event, dc, scaling)
- # Popup the menu with special items for a block and a connector if one is handled
- connector = self.TestConnector(pos, False)
- if connector:
- self.Handle = (HANDLE_CONNECTOR, connector)
- self.Parent.PopupDivergenceMenu(True)
- else:
- # Popup the divergence menu without delete branch
- self.Parent.PopupDivergenceMenu(False)
+ Graphic_Element.OnRightUp(self, event, dc, scaling)
+ else:
+ pos = GetScaledEventPosition(event, dc, scaling)
+ # Popup the menu with special items for a block and a connector if one is handled
+ connector = self.TestConnector(pos, False)
+ if connector:
+ self.Handle = (HANDLE_CONNECTOR, connector)
+ self.Parent.PopupDivergenceMenu(True)
+ else:
+ # Popup the divergence menu without delete branch
+ self.Parent.PopupDivergenceMenu(False)
# Refreshes the divergence state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
handle_type, handle = self.Handle
# A connector has been handled
if handle_type == HANDLE_CONNECTOR:
movex = max(-self.BoundingBox.x, movex)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
self.MoveConnector(handle, movex)
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
self.RefreshConnectedPosition(handle)
return movex, 0
elif self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
return 0, 0
# Refresh output element model
@@ -1199,7 +1218,7 @@
wires = output.GetWires()
if len(wires) != 1:
return
- output_block = wires[0][0].StartConnected.GetParentBlock()
+ output_block = wires[0][0].GetOtherConnected(output).GetParentBlock()
output_block.RefreshModel(False)
if not isinstance(output_block, SFC_Divergence) or move:
output_block.RefreshOutputModel(move)
@@ -1266,7 +1285,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, "", None, wx.Point(self.Size[0] / 2, 0), NORTH)
+ self.Input = Connector(self, "", None, wx.Point(self.Size[0] / 2, 0), NORTH, onlyone = True)
# Destructor
def __del__(self):
@@ -1321,12 +1340,16 @@
def GetPreviousConnector(self):
wires = self.Input.GetWires()
if len(wires) == 1:
- return wires[0][0].EndConnected
+ return wires[0][0].GetOtherConnected(self.Input)
return None
# Refresh the element connectors position
def RefreshConnectors(self):
- self.Input.SetPosition(wx.Point(self.Size[0] / 2, 0))
+ scaling = self.Parent.GetScaling()
+ horizontal_pos = self.Size[0] / 2
+ if scaling is not None:
+ horizontal_pos = round(float(self.Pos.x + horizontal_pos) / float(scaling[0])) * scaling[0] - self.Pos.x
+ self.Input.SetPosition(wx.Point(horizontal_pos, 0))
self.RefreshConnected()
# Refresh the position of wires connected to jump
@@ -1390,14 +1413,16 @@
self.Parent.PopupDefaultMenu()
# Refreshes the jump state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
movex = max(-self.BoundingBox.x, movex)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
self.Move(movex, 0)
self.RefreshInputPosition()
return movex, 0
else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
# Refresh input element model
def RefreshInputModel(self):
@@ -1468,7 +1493,7 @@
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, "", None, 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, onlyone = True)
self.SetActions(actions)
# Destructor
@@ -1539,6 +1564,15 @@
return self.Input
return None
+ # Refresh the element connectors position
+ def RefreshConnectors(self):
+ scaling = self.Parent.GetScaling()
+ vertical_pos = SFC_ACTION_MIN_SIZE[1] / 2
+ if scaling is not None:
+ vertical_pos = round(float(self.Pos.y + vertical_pos) / float(scaling[1])) * scaling[1] - self.Pos.y
+ self.Input.SetPosition(wx.Point(0, vertical_pos))
+ self.RefreshConnected()
+
# Changes the action block actions
def SetActions(self, actions):
dc = wx.ClientDC(self.Parent)
@@ -1575,7 +1609,7 @@
if self.Input:
wires = self.Input.GetWires()
if len(wires) == 1:
- input_block = wires[0][0].EndConnected.GetParentBlock()
+ input_block = wires[0][0].GetOtherConnected(self.Input).GetParentBlock()
input_block.RefreshOutputPosition()
input_block.RefreshOutputModel(True)
@@ -1598,22 +1632,24 @@
self.Parent.PopupDefaultMenu()
# Refreshes the action block state according to move defined and handle selected
- def ProcessDragging(self, movex, movey):
+ def ProcessDragging(self, movex, movey, scaling):
if self.Parent.GetDrawingMode() != FREEDRAWING_MODE:
handle_type, handle = self.Handle
if handle_type == HANDLE_MOVE:
movex = max(-self.BoundingBox.x, movex)
+ if scaling is not None:
+ movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x
wires = self.Input.GetWires()
if len(wires) == 1:
- input_pos = wires[0][0].EndConnected.GetPosition(False)
+ input_pos = wires[0][0].GetOtherConnected(self.Input).GetPosition(False)
if self.Pos.x - input_pos.x + movex >= SFC_WIRE_MIN_SIZE:
self.Move(movex, 0)
return movex, 0
return 0, 0
else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
- else:
- return Graphic_Element.ProcessDragging(self, movex, movey)
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
+ else:
+ return Graphic_Element.ProcessDragging(self, movex, movey, scaling)
# Refreshes the action block model