22 #License along with this library; if not, write to the Free Software |
22 #License along with this library; if not, write to the Free Software |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
24 |
24 |
25 import wx |
25 import wx |
26 |
26 |
27 from GraphicCommons import * |
27 from graphics.GraphicCommons import * |
|
28 from graphics.DebugDataConsumer import DebugDataConsumer |
28 from plcopen.structures import * |
29 from plcopen.structures import * |
29 |
30 |
30 def GetWireSize(block): |
31 def GetWireSize(block): |
31 if isinstance(block, SFC_Step): |
32 if isinstance(block, SFC_Step): |
32 return SFC_WIRE_MIN_SIZE + block.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
33 return SFC_WIRE_MIN_SIZE + block.GetActionExtraLineNumber() * SFC_ACTION_MIN_SIZE[1] |
1357 output_block.Move(move[0], move[1], self.Parent.Wires) |
1358 output_block.Move(move[0], move[1], self.Parent.Wires) |
1358 output_block.RefreshOutputPosition(move) |
1359 output_block.RefreshOutputPosition(move) |
1359 |
1360 |
1360 # Method called when a LeftDown event have been generated |
1361 # Method called when a LeftDown event have been generated |
1361 def OnLeftDown(self, event, dc, scaling): |
1362 def OnLeftDown(self, event, dc, scaling): |
1362 connector = None |
1363 self.RealConnectors = {"Inputs":[],"Outputs":[]} |
1363 if event.ControlDown(): |
1364 for input in self.Inputs: |
1364 pos = GetScaledEventPosition(event, dc, scaling) |
1365 position = input.GetRelPosition() |
1365 # Test if a connector have been handled |
1366 self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
1366 connector = self.TestConnector(pos, exclude=False) |
1367 for output in self.Outputs: |
|
1368 position = output.GetRelPosition() |
|
1369 self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
1370 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1371 |
|
1372 # Method called when a LeftUp event have been generated |
|
1373 def OnLeftUp(self, event, dc, scaling): |
|
1374 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
|
1375 self.RealConnectors = None |
|
1376 |
|
1377 # Method called when a RightDown event have been generated |
|
1378 def OnRightDown(self, event, dc, scaling): |
|
1379 pos = GetScaledEventPosition(event, dc, scaling) |
|
1380 # Test if a connector have been handled |
|
1381 connector = self.TestConnector(pos, exclude=False) |
1367 if connector: |
1382 if connector: |
1368 self.Handle = (HANDLE_CONNECTOR, connector) |
1383 self.Handle = (HANDLE_CONNECTOR, connector) |
1369 wx.CallAfter(self.Parent.SetCurrentCursor, 1) |
1384 wx.CallAfter(self.Parent.SetCurrentCursor, 1) |
1370 self.Selected = False |
1385 self.Selected = False |
1371 # Initializes the last position |
1386 # Initializes the last position |
1372 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
1387 self.oldPos = GetScaledEventPosition(event, dc, scaling) |
1373 else: |
1388 else: |
1374 self.RealConnectors = {"Inputs":[],"Outputs":[]} |
1389 Graphic_Element.OnRightDown(self, event, dc, scaling) |
1375 for input in self.Inputs: |
1390 |
1376 position = input.GetRelPosition() |
1391 # Method called when a RightUp event have been generated |
1377 self.RealConnectors["Inputs"].append(float(position.x)/float(self.Size[0])) |
1392 def OnRightUp(self, event, dc, scaling): |
1378 for output in self.Outputs: |
1393 pos = GetScaledEventPosition(event, dc, scaling) |
1379 position = output.GetRelPosition() |
|
1380 self.RealConnectors["Outputs"].append(float(position.x)/float(self.Size[0])) |
|
1381 Graphic_Element.OnLeftDown(self, event, dc, scaling) |
|
1382 |
|
1383 # Method called when a LeftUp event have been generated |
|
1384 def OnLeftUp(self, event, dc, scaling): |
|
1385 handle_type, handle = self.Handle |
1394 handle_type, handle = self.Handle |
1386 if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos: |
1395 if handle_type == HANDLE_CONNECTOR and self.Dragging and self.oldPos: |
1387 wires = handle.GetWires() |
1396 wires = handle.GetWires() |
1388 if len(wires) == 1: |
1397 if len(wires) == 1: |
1389 block = wires[0][0].GetOtherConnected(handle).GetParentBlock() |
1398 block = wires[0][0].GetOtherConnected(handle).GetParentBlock() |
1391 if not isinstance(block, SFC_Divergence): |
1400 if not isinstance(block, SFC_Divergence): |
1392 if handle in self.Inputs: |
1401 if handle in self.Inputs: |
1393 block.RefreshInputModel() |
1402 block.RefreshInputModel() |
1394 else: |
1403 else: |
1395 block.RefreshOutputModel() |
1404 block.RefreshOutputModel() |
1396 Graphic_Element.OnLeftUp(self, event, dc, scaling) |
1405 Graphic_Element.OnRightUp(self, event, dc, scaling) |
1397 self.RealConnectors = None |
1406 else: |
1398 |
1407 # Popup the menu with special items for a block and a connector if one is handled |
1399 # Method called when a RightUp event have been generated |
1408 connector = self.TestConnector(pos, exclude=False) |
1400 def OnRightUp(self, event, dc, scaling): |
1409 if connector: |
1401 pos = GetScaledEventPosition(event, dc, scaling) |
1410 self.Handle = (HANDLE_CONNECTOR, connector) |
1402 # Popup the menu with special items for a block and a connector if one is handled |
1411 self.Parent.PopupDivergenceMenu(True) |
1403 connector = self.TestConnector(pos, exclude=False) |
1412 else: |
1404 if connector: |
1413 # Popup the divergence menu without delete branch |
1405 self.Handle = (HANDLE_CONNECTOR, connector) |
1414 self.Parent.PopupDivergenceMenu(False) |
1406 self.Parent.PopupDivergenceMenu(True) |
1415 |
1407 else: |
|
1408 # Popup the divergence menu without delete branch |
|
1409 self.Parent.PopupDivergenceMenu(False) |
|
1410 |
|
1411 # Refreshes the divergence state according to move defined and handle selected |
1416 # Refreshes the divergence state according to move defined and handle selected |
1412 def ProcessDragging(self, movex, movey, event, scaling): |
1417 def ProcessDragging(self, movex, movey, event, scaling): |
1413 handle_type, handle = self.Handle |
1418 handle_type, handle = self.Handle |
1414 # A connector has been handled |
1419 # A connector has been handled |
1415 if handle_type == HANDLE_CONNECTOR: |
1420 if handle_type == HANDLE_CONNECTOR: |