438 (ID_ALIGN_TOP, wx.ITEM_NORMAL, _(u'Top'), '', self.OnAlignTopMenu), |
438 (ID_ALIGN_TOP, wx.ITEM_NORMAL, _(u'Top'), '', self.OnAlignTopMenu), |
439 (ID_ALIGN_MIDDLE, wx.ITEM_NORMAL, _(u'Middle'), '', self.OnAlignMiddleMenu), |
439 (ID_ALIGN_MIDDLE, wx.ITEM_NORMAL, _(u'Middle'), '', self.OnAlignMiddleMenu), |
440 (ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)]) |
440 (ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)]) |
441 |
441 |
442 # Add Wire Menu items to the given menu |
442 # Add Wire Menu items to the given menu |
443 def AddWireMenuItems(self, menu, delete=False): |
443 def AddWireMenuItems(self, menu, delete=False, replace=False): |
444 [ID_ADD_SEGMENT, ID_DELETE_SEGMENT] = [wx.NewId() for i in xrange(2)] |
444 [ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE, |
|
445 ] = [wx.NewId() for i in xrange(3)] |
445 |
446 |
446 # Create menu items |
447 # Create menu items |
447 self.AddMenuItems(menu, [ |
448 self.AddMenuItems(menu, [ |
448 (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu), |
449 (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu), |
449 (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu)]) |
450 (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu), |
450 |
451 (ID_REPLACE_WIRE, wx.ITEM_NORMAL, _(u'Replace Wire by connections'), '', self.OnReplaceWireMenu)]) |
|
452 |
451 menu.Enable(ID_DELETE_SEGMENT, delete) |
453 menu.Enable(ID_DELETE_SEGMENT, delete) |
|
454 menu.Enable(ID_REPLACE_WIRE, replace) |
452 |
455 |
453 # Add Divergence Menu items to the given menu |
456 # Add Divergence Menu items to the given menu |
454 def AddDivergenceMenuItems(self, menu, delete=False): |
457 def AddDivergenceMenuItems(self, menu, delete=False): |
455 [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for i in xrange(2)] |
458 [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for i in xrange(2)] |
456 |
459 |
1503 self.Editor.PopupMenu(menu) |
1506 self.Editor.PopupMenu(menu) |
1504 menu.Destroy() |
1507 menu.Destroy() |
1505 |
1508 |
1506 def PopupWireMenu(self, delete=True): |
1509 def PopupWireMenu(self, delete=True): |
1507 menu = wx.Menu(title='') |
1510 menu = wx.Menu(title='') |
1508 self.AddWireMenuItems(menu, delete) |
1511 |
|
1512 # If Check that wire can be replace by connections or abort |
|
1513 connected = self.SelectedElement.GetConnected() |
|
1514 start_connector = ( |
|
1515 self.SelectedElement.GetEndConnected() |
|
1516 if self.SelectedElement.GetStartConnected() in connected |
|
1517 else self.SelectedElement.GetStartConnected()) |
|
1518 |
|
1519 self.AddWireMenuItems(menu, delete, |
|
1520 start_connector.GetDirection() == EAST and |
|
1521 not isinstance(start_connector.GetParentBlock(), SFC_Step)) |
|
1522 |
1509 menu.AppendSeparator() |
1523 menu.AppendSeparator() |
1510 self.AddDefaultMenuItems(menu, block=True) |
1524 self.AddDefaultMenuItems(menu, block=True) |
1511 self.Editor.PopupMenu(menu) |
1525 self.Editor.PopupMenu(menu) |
1512 menu.Destroy() |
1526 menu.Destroy() |
1513 |
1527 |
1606 |
1620 |
1607 def OnDeleteSegmentMenu(self, event): |
1621 def OnDeleteSegmentMenu(self, event): |
1608 if self.SelectedElement is not None and self.IsWire(self.SelectedElement): |
1622 if self.SelectedElement is not None and self.IsWire(self.SelectedElement): |
1609 self.SelectedElement.DeleteSegment() |
1623 self.SelectedElement.DeleteSegment() |
1610 self.SelectedElement.Refresh() |
1624 self.SelectedElement.Refresh() |
1611 |
1625 |
|
1626 def OnReplaceWireMenu(self, event): |
|
1627 # Check that selected element is a wire before applying replace |
|
1628 if (self.SelectedElement is not None and |
|
1629 self.IsWire(self.SelectedElement)): |
|
1630 |
|
1631 # Get wire redraw bbox to erase it from screen |
|
1632 wire = self.SelectedElement |
|
1633 redraw_rect = wire.GetRedrawRect() |
|
1634 |
|
1635 # Get connector at both ends of wire |
|
1636 connected = wire.GetConnected() |
|
1637 if wire.GetStartConnected() in connected: |
|
1638 start_connector = wire.GetEndConnected() |
|
1639 end_connector = wire.GetStartConnected() |
|
1640 wire.UnConnectStartPoint() |
|
1641 point_to_connect = 0 |
|
1642 else: |
|
1643 start_connector = wire.GetStartConnected() |
|
1644 end_connector = wire.GetEndConnected() |
|
1645 wire.UnConnectEndPoint() |
|
1646 point_to_connect = -1 |
|
1647 |
|
1648 # Get a new default connection name |
|
1649 connection_name = self.Controler.GenerateNewName( |
|
1650 self.TagName, None, "Connection%d", 0) |
|
1651 |
|
1652 # Create a connector to connect to wire |
|
1653 id = self.GetNewId() |
|
1654 connection = FBD_Connector(self, CONNECTOR, connection_name, id) |
|
1655 connection.SetSize(*self.GetScaledSize(*connection.GetMinSize())) |
|
1656 |
|
1657 # Calculate position of connector at the right of start connector |
|
1658 connector = connection.GetConnectors()["inputs"][0] |
|
1659 rel_pos = connector.GetRelPosition() |
|
1660 direction = connector.GetDirection() |
|
1661 start_point = start_connector.GetPosition(False) |
|
1662 end_point = (start_point[0] + LD_WIRE_SIZE, start_point[1]) |
|
1663 connection.SetPosition(end_point[0] - rel_pos[0], |
|
1664 end_point[1] - rel_pos[1]) |
|
1665 |
|
1666 # Connect connector to wire |
|
1667 connector.Connect((wire, point_to_connect)) |
|
1668 if point_to_connect == 0: |
|
1669 wire.SetPoints([end_point, start_point]) |
|
1670 else: |
|
1671 wire.SetPoints([start_point, end_point]) |
|
1672 # Update redraw bbox with new wire trace so that it will be redraw |
|
1673 # on screen |
|
1674 redraw_rect.Union(wire.GetRedrawRect()) |
|
1675 |
|
1676 # Add connector to Viewer and model |
|
1677 self.AddBlock(connection) |
|
1678 self.Controler.AddEditedElementConnection(self.TagName, id, |
|
1679 CONNECTOR) |
|
1680 connection.RefreshModel() |
|
1681 # Update redraw bbox with new connector bbox so that it will be |
|
1682 # drawn on screen |
|
1683 redraw_rect.Union(connection.GetRedrawRect()) |
|
1684 |
|
1685 # Add new continuation |
|
1686 id = self.GetNewId() |
|
1687 connection = FBD_Connector(self, CONTINUATION, connection_name, id) |
|
1688 connection.SetSize(*self.GetScaledSize(*connection.GetMinSize())) |
|
1689 |
|
1690 # Calculate position of connection at the left of end connector |
|
1691 connector = connection.GetConnectors()["outputs"][0] |
|
1692 rel_pos = connector.GetRelPosition() |
|
1693 direction = connector.GetDirection() |
|
1694 end_point = end_connector.GetPosition(False) |
|
1695 start_point = (end_point[0] - LD_WIRE_SIZE, end_point[1]) |
|
1696 connection.SetPosition(start_point[0] - rel_pos[0], |
|
1697 start_point[1] - rel_pos[1]) |
|
1698 |
|
1699 # Add Wire to Viewer and connect it to blocks |
|
1700 new_wire = Wire(self, |
|
1701 [wx.Point(*start_point), connector.GetDirection()], |
|
1702 [wx.Point(*end_point), end_connector.GetDirection()]) |
|
1703 self.AddWire(new_wire) |
|
1704 connector.Connect((new_wire, 0), False) |
|
1705 end_connector.Connect((new_wire, -1), False) |
|
1706 new_wire.ConnectStartPoint(None, connector) |
|
1707 new_wire.ConnectEndPoint(None, end_connector) |
|
1708 # Update redraw bbox with new wire bbox so that it will be drawn on |
|
1709 # screen |
|
1710 redraw_rect.Union(new_wire.GetRedrawRect()) |
|
1711 |
|
1712 # Add connection to Viewer and model |
|
1713 self.AddBlock(connection) |
|
1714 self.Controler.AddEditedElementConnection(self.TagName, id, |
|
1715 CONTINUATION) |
|
1716 connection.RefreshModel() |
|
1717 # Update redraw bbox with new connection bbox so that it will be |
|
1718 # drawn on screen |
|
1719 redraw_rect.Union(connection.GetRedrawRect()) |
|
1720 |
|
1721 # Refresh model for new wire |
|
1722 end_connector.RefreshParentBlock() |
|
1723 |
|
1724 # Redraw |
|
1725 self.RefreshBuffer() |
|
1726 self.RefreshScrollBars() |
|
1727 self.RefreshVisibleElements() |
|
1728 self.RefreshRect(self.GetScrolledRect(redraw_rect), False) |
|
1729 |
1612 def OnAddBranchMenu(self, event): |
1730 def OnAddBranchMenu(self, event): |
1613 if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
1731 if self.SelectedElement is not None and self.IsBlock(self.SelectedElement): |
1614 self.AddDivergenceBranch(self.SelectedElement) |
1732 self.AddDivergenceBranch(self.SelectedElement) |
1615 |
1733 |
1616 def OnDeleteBranchMenu(self, event): |
1734 def OnDeleteBranchMenu(self, event): |