314 self.PageSize = None |
314 self.PageSize = None |
315 self.PagePen = wx.TRANSPARENT_PEN |
315 self.PagePen = wx.TRANSPARENT_PEN |
316 self.DrawingWire = False |
316 self.DrawingWire = False |
317 self.current_id = 0 |
317 self.current_id = 0 |
318 self.TagName = tagname |
318 self.TagName = tagname |
|
319 self.Errors = [] |
319 |
320 |
320 # Initialize Block, Wire and Comment numbers |
321 # Initialize Block, Wire and Comment numbers |
321 self.block_id = self.wire_id = self.comment_id = 0 |
322 self.block_id = self.wire_id = self.comment_id = 0 |
322 |
323 |
323 # Initialize Viewer mode to Selection mode |
324 # Initialize Viewer mode to Selection mode |
821 end_connector.Connect((wire, -1), False) |
823 end_connector.Connect((wire, -1), False) |
822 wire.ConnectStartPoint(None, start_connector) |
824 wire.ConnectStartPoint(None, start_connector) |
823 wire.ConnectEndPoint(None, end_connector) |
825 wire.ConnectEndPoint(None, end_connector) |
824 self.AddWire(wire) |
826 self.AddWire(wire) |
825 |
827 |
|
828 def IsOfType(self, type, reference): |
|
829 return self.Controler.IsOfType(type, reference) |
|
830 |
|
831 def IsEndType(self, type): |
|
832 return self.Controler.IsEndType(type) |
|
833 |
|
834 def GetBlockType(self, type, inputs = None): |
|
835 return self.Controler.GetBlockType(type, inputs) |
|
836 |
826 #------------------------------------------------------------------------------- |
837 #------------------------------------------------------------------------------- |
827 # Search Element functions |
838 # Search Element functions |
828 #------------------------------------------------------------------------------- |
839 #------------------------------------------------------------------------------- |
829 |
840 |
830 def FindBlock(self, pos): |
841 def FindBlock(self, pos): |
1415 width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0] |
1426 width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0] |
1416 height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1] |
1427 height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1] |
1417 return width, height |
1428 return width, height |
1418 |
1429 |
1419 def AddNewBlock(self, bbox): |
1430 def AddNewBlock(self, bbox): |
1420 dialog = BlockPropertiesDialog(self.ParentWindow) |
1431 dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler) |
1421 dialog.SetPreviewFont(self.GetFont()) |
1432 dialog.SetPreviewFont(self.GetFont()) |
1422 dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName)) |
1433 dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName)) |
1423 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1434 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1424 dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName)) |
1435 dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName)) |
1425 dialog.SetMinBlockSize((bbox.width, bbox.height)) |
1436 dialog.SetMinBlockSize((bbox.width, bbox.height)) |
1440 self.ParentWindow.RefreshVariablePanel(self.TagName) |
1451 self.ParentWindow.RefreshVariablePanel(self.TagName) |
1441 block.Refresh() |
1452 block.Refresh() |
1442 dialog.Destroy() |
1453 dialog.Destroy() |
1443 |
1454 |
1444 def AddNewVariable(self, bbox): |
1455 def AddNewVariable(self, bbox): |
1445 dialog = VariablePropertiesDialog(self.ParentWindow) |
1456 dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler) |
1446 dialog.SetPreviewFont(self.GetFont()) |
1457 dialog.SetPreviewFont(self.GetFont()) |
1447 dialog.SetMinVariableSize((bbox.width, bbox.height)) |
1458 dialog.SetMinVariableSize((bbox.width, bbox.height)) |
1448 varlist = [] |
1459 varlist = [] |
1449 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1460 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1450 if vars: |
1461 if vars: |
1468 self.RefreshScrollBars() |
1479 self.RefreshScrollBars() |
1469 variable.Refresh() |
1480 variable.Refresh() |
1470 dialog.Destroy() |
1481 dialog.Destroy() |
1471 |
1482 |
1472 def AddNewConnection(self, bbox): |
1483 def AddNewConnection(self, bbox): |
1473 dialog = ConnectionPropertiesDialog(self.ParentWindow) |
1484 dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler) |
1474 dialog.SetPreviewFont(self.GetFont()) |
1485 dialog.SetPreviewFont(self.GetFont()) |
1475 dialog.SetMinConnectionSize((bbox.width, bbox.height)) |
1486 dialog.SetMinConnectionSize((bbox.width, bbox.height)) |
1476 if dialog.ShowModal() == wx.ID_OK: |
1487 if dialog.ShowModal() == wx.ID_OK: |
1477 id = self.GetNewId() |
1488 id = self.GetNewId() |
1478 values = dialog.GetValues() |
1489 values = dialog.GetValues() |
1506 self.RefreshScrollBars() |
1517 self.RefreshScrollBars() |
1507 comment.Refresh() |
1518 comment.Refresh() |
1508 dialog.Destroy() |
1519 dialog.Destroy() |
1509 |
1520 |
1510 def AddNewContact(self, bbox): |
1521 def AddNewContact(self, bbox): |
1511 dialog = LDElementDialog(self.ParentWindow, "contact") |
1522 dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact") |
1512 dialog.SetPreviewFont(self.GetFont()) |
1523 dialog.SetPreviewFont(self.GetFont()) |
1513 varlist = [] |
1524 varlist = [] |
1514 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1525 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1515 if vars: |
1526 if vars: |
1516 for var in vars: |
1527 for var in vars: |
1532 self.RefreshScrollBars() |
1543 self.RefreshScrollBars() |
1533 contact.Refresh() |
1544 contact.Refresh() |
1534 dialog.Destroy() |
1545 dialog.Destroy() |
1535 |
1546 |
1536 def AddNewCoil(self, bbox): |
1547 def AddNewCoil(self, bbox): |
1537 dialog = LDElementDialog(self.ParentWindow, "coil") |
1548 dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil") |
1538 dialog.SetPreviewFont(self.GetFont()) |
1549 dialog.SetPreviewFont(self.GetFont()) |
1539 varlist = [] |
1550 varlist = [] |
1540 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1551 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1541 if vars: |
1552 if vars: |
1542 for var in vars: |
1553 for var in vars: |
1561 self.RefreshScrollBars() |
1572 self.RefreshScrollBars() |
1562 coil.Refresh() |
1573 coil.Refresh() |
1563 dialog.Destroy() |
1574 dialog.Destroy() |
1564 |
1575 |
1565 def AddNewPowerRail(self, bbox): |
1576 def AddNewPowerRail(self, bbox): |
1566 dialog = LDPowerRailDialog(self.ParentWindow) |
1577 dialog = LDPowerRailDialog(self.ParentWindow, self.Controler) |
1567 dialog.SetPreviewFont(self.GetFont()) |
1578 dialog.SetPreviewFont(self.GetFont()) |
1568 dialog.SetMinSize((bbox.width, bbox.height)) |
1579 dialog.SetMinSize((bbox.width, bbox.height)) |
1569 if dialog.ShowModal() == wx.ID_OK: |
1580 if dialog.ShowModal() == wx.ID_OK: |
1570 id = self.GetNewId() |
1581 id = self.GetNewId() |
1571 values = dialog.GetValues() |
1582 values = dialog.GetValues() |
1579 self.RefreshScrollBars() |
1590 self.RefreshScrollBars() |
1580 powerrail.Refresh() |
1591 powerrail.Refresh() |
1581 dialog.Destroy() |
1592 dialog.Destroy() |
1582 |
1593 |
1583 def AddNewStep(self, bbox, initial = False): |
1594 def AddNewStep(self, bbox, initial = False): |
1584 dialog = StepContentDialog(self.ParentWindow, initial) |
1595 dialog = StepContentDialog(self.ParentWindow, self.Controler, initial) |
1585 dialog.SetPreviewFont(self.GetFont()) |
1596 dialog.SetPreviewFont(self.GetFont()) |
1586 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1597 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1587 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
1598 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
1588 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
1599 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)]) |
1589 dialog.SetMinStepSize((bbox.width, bbox.height)) |
1600 dialog.SetMinStepSize((bbox.width, bbox.height)) |
1613 self.RefreshScrollBars() |
1624 self.RefreshScrollBars() |
1614 step.Refresh() |
1625 step.Refresh() |
1615 dialog.Destroy() |
1626 dialog.Destroy() |
1616 |
1627 |
1617 def AddNewTransition(self, bbox): |
1628 def AddNewTransition(self, bbox): |
1618 dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE) |
1629 dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE) |
1619 dialog.SetPreviewFont(self.GetFont()) |
1630 dialog.SetPreviewFont(self.GetFont()) |
1620 dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName)) |
1631 dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName)) |
1621 if dialog.ShowModal() == wx.ID_OK: |
1632 if dialog.ShowModal() == wx.ID_OK: |
1622 id = self.GetNewId() |
1633 id = self.GetNewId() |
1623 values = dialog.GetValues() |
1634 values = dialog.GetValues() |
1632 self.RefreshScrollBars() |
1643 self.RefreshScrollBars() |
1633 transition.Refresh() |
1644 transition.Refresh() |
1634 dialog.Destroy() |
1645 dialog.Destroy() |
1635 |
1646 |
1636 def AddNewDivergence(self, bbox): |
1647 def AddNewDivergence(self, bbox): |
1637 dialog = DivergenceCreateDialog(self.ParentWindow) |
1648 dialog = DivergenceCreateDialog(self.ParentWindow, self.Controler) |
1638 dialog.SetPreviewFont(self.GetFont()) |
1649 dialog.SetPreviewFont(self.GetFont()) |
1639 dialog.SetMinSize((bbox.width, bbox.height)) |
1650 dialog.SetMinSize((bbox.width, bbox.height)) |
1640 if dialog.ShowModal() == wx.ID_OK: |
1651 if dialog.ShowModal() == wx.ID_OK: |
1641 id = self.GetNewId() |
1652 id = self.GetNewId() |
1642 values = dialog.GetValues() |
1653 values = dialog.GetValues() |
1696 #------------------------------------------------------------------------------- |
1707 #------------------------------------------------------------------------------- |
1697 # Edit element content functions |
1708 # Edit element content functions |
1698 #------------------------------------------------------------------------------- |
1709 #------------------------------------------------------------------------------- |
1699 |
1710 |
1700 def EditBlockContent(self, block): |
1711 def EditBlockContent(self, block): |
1701 dialog = BlockPropertiesDialog(self.ParentWindow) |
1712 dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler) |
1702 dialog.SetPreviewFont(self.GetFont()) |
1713 dialog.SetPreviewFont(self.GetFont()) |
1703 dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName)) |
1714 dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName)) |
1704 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1715 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1705 variable_names = self.Controler.GetEditedElementVariables(self.TagName) |
1716 variable_names = self.Controler.GetEditedElementVariables(self.TagName) |
1706 if block.GetName() != "": |
1717 if block.GetName() != "": |
1729 self.ParentWindow.RefreshVariablePanel(self.TagName) |
1740 self.ParentWindow.RefreshVariablePanel(self.TagName) |
1730 block.Refresh(rect) |
1741 block.Refresh(rect) |
1731 dialog.Destroy() |
1742 dialog.Destroy() |
1732 |
1743 |
1733 def EditVariableContent(self, variable): |
1744 def EditVariableContent(self, variable): |
1734 dialog = VariablePropertiesDialog(self.ParentWindow) |
1745 dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler) |
1735 dialog.SetPreviewFont(self.GetFont()) |
1746 dialog.SetPreviewFont(self.GetFont()) |
1736 dialog.SetMinVariableSize(variable.GetSize()) |
1747 dialog.SetMinVariableSize(variable.GetSize()) |
1737 varlist = [] |
1748 varlist = [] |
1738 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1749 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1739 if vars: |
1750 if vars: |
1766 self.RefreshScrollBars() |
1777 self.RefreshScrollBars() |
1767 variable.Refresh(rect) |
1778 variable.Refresh(rect) |
1768 dialog.Destroy() |
1779 dialog.Destroy() |
1769 |
1780 |
1770 def EditConnectionContent(self, connection): |
1781 def EditConnectionContent(self, connection): |
1771 dialog = ConnectionPropertiesDialog(self.ParentWindow) |
1782 dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler) |
1772 dialog.SetPreviewFont(self.GetFont()) |
1783 dialog.SetPreviewFont(self.GetFont()) |
1773 dialog.SetMinConnectionSize(connection.GetSize()) |
1784 dialog.SetMinConnectionSize(connection.GetSize()) |
1774 values = {"name" : connection.GetName(), "type" : connection.GetType()} |
1785 values = {"name" : connection.GetName(), "type" : connection.GetType()} |
1775 dialog.SetValues(values) |
1786 dialog.SetValues(values) |
1776 if dialog.ShowModal() == wx.ID_OK: |
1787 if dialog.ShowModal() == wx.ID_OK: |
1790 self.RefreshScrollBars() |
1801 self.RefreshScrollBars() |
1791 connection.Refresh(rect) |
1802 connection.Refresh(rect) |
1792 dialog.Destroy() |
1803 dialog.Destroy() |
1793 |
1804 |
1794 def EditContactContent(self, contact): |
1805 def EditContactContent(self, contact): |
1795 dialog = LDElementDialog(self.ParentWindow, "contact") |
1806 dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact") |
1796 dialog.SetPreviewFont(self.GetFont()) |
1807 dialog.SetPreviewFont(self.GetFont()) |
1797 varlist = [] |
1808 varlist = [] |
1798 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1809 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1799 if vars: |
1810 if vars: |
1800 for var in vars: |
1811 for var in vars: |
1816 self.RefreshScrollBars() |
1827 self.RefreshScrollBars() |
1817 contact.Refresh(rect) |
1828 contact.Refresh(rect) |
1818 dialog.Destroy() |
1829 dialog.Destroy() |
1819 |
1830 |
1820 def EditCoilContent(self, coil): |
1831 def EditCoilContent(self, coil): |
1821 dialog = LDElementDialog(self.ParentWindow, "coil") |
1832 dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil") |
1822 dialog.SetPreviewFont(self.GetFont()) |
1833 dialog.SetPreviewFont(self.GetFont()) |
1823 varlist = [] |
1834 varlist = [] |
1824 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1835 vars = self.Controler.GetEditedElementInterfaceVars(self.TagName) |
1825 if vars: |
1836 if vars: |
1826 for var in vars: |
1837 for var in vars: |
1845 self.RefreshScrollBars() |
1856 self.RefreshScrollBars() |
1846 coil.Refresh(rect) |
1857 coil.Refresh(rect) |
1847 dialog.Destroy() |
1858 dialog.Destroy() |
1848 |
1859 |
1849 def EditPowerRailContent(self, powerrail): |
1860 def EditPowerRailContent(self, powerrail): |
1850 dialog = LDPowerRailDialog(self.ParentWindow, powerrail.GetType(), len(powerrail.GetConnectors())) |
1861 dialog = LDPowerRailDialog(self.ParentWindow, self.Controler, powerrail.GetType(), len(powerrail.GetConnectors())) |
1851 dialog.SetPreviewFont(self.GetFont()) |
1862 dialog.SetPreviewFont(self.GetFont()) |
1852 dialog.SetMinSize(powerrail.GetSize()) |
1863 dialog.SetMinSize(powerrail.GetSize()) |
1853 if dialog.ShowModal() == wx.ID_OK: |
1864 if dialog.ShowModal() == wx.ID_OK: |
1854 old_type = powerrail.GetType() |
1865 old_type = powerrail.GetType() |
1855 values = dialog.GetValues() |
1866 values = dialog.GetValues() |
1866 self.RefreshScrollBars() |
1877 self.RefreshScrollBars() |
1867 powerrail.Refresh(rect) |
1878 powerrail.Refresh(rect) |
1868 dialog.Destroy() |
1879 dialog.Destroy() |
1869 |
1880 |
1870 def EditStepContent(self, step): |
1881 def EditStepContent(self, step): |
1871 dialog = StepContentDialog(self.ParentWindow, step.GetInitial()) |
1882 dialog = StepContentDialog(self.ParentWindow, self.Controler, step.GetInitial()) |
1872 dialog.SetPreviewFont(self.GetFont()) |
1883 dialog.SetPreviewFont(self.GetFont()) |
1873 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1884 dialog.SetPouNames(self.Controler.GetProjectPouNames()) |
1874 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
1885 dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName)) |
1875 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
1886 dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()]) |
1876 dialog.SetMinStepSize(step.GetSize()) |
1887 dialog.SetMinStepSize(step.GetSize()) |
1902 self.RefreshBuffer() |
1913 self.RefreshBuffer() |
1903 self.RefreshScrollBars() |
1914 self.RefreshScrollBars() |
1904 step.Refresh(rect) |
1915 step.Refresh(rect) |
1905 |
1916 |
1906 def EditTransitionContent(self, transition): |
1917 def EditTransitionContent(self, transition): |
1907 dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE) |
1918 dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE) |
1908 dialog.SetPreviewFont(self.GetFont()) |
1919 dialog.SetPreviewFont(self.GetFont()) |
1909 dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName)) |
1920 dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName)) |
1910 dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()}) |
1921 dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()}) |
1911 dialog.SetElementSize(transition.GetSize()) |
1922 dialog.SetElementSize(transition.GetSize()) |
1912 if dialog.ShowModal() == wx.ID_OK: |
1923 if dialog.ShowModal() == wx.ID_OK: |
2326 self.RefreshJumpModel(block) |
2337 self.RefreshJumpModel(block) |
2327 elif isinstance(block, SFC_ActionBlock): |
2338 elif isinstance(block, SFC_ActionBlock): |
2328 self.Controler.AddEditedElementActionBlock(self.TagName, id) |
2339 self.Controler.AddEditedElementActionBlock(self.TagName, id) |
2329 self.RefreshActionBlockModel(block) |
2340 self.RefreshActionBlockModel(block) |
2330 return block |
2341 return block |
2331 |
2342 |
2332 |
2343 |
|
2344 #------------------------------------------------------------------------------- |
|
2345 # Errors showing functions |
|
2346 #------------------------------------------------------------------------------- |
|
2347 |
|
2348 def ClearErrors(self): |
|
2349 self.Errors = [] |
|
2350 self.RefreshView() |
|
2351 |
|
2352 def AddShownError(self, infos, start, end): |
|
2353 self.Errors.append((infos, start, end)) |
|
2354 |
|
2355 def ShowErrors(self): |
|
2356 for infos, start, end in self.Errors: |
|
2357 if infos[0] in ["io_variable", "block", "coil", "contact", "transition", "step", "action_block"]: |
|
2358 block = self.FindElementById(infos[1]) |
|
2359 if block is not None: |
|
2360 block.AddError(infos[2:], start, end) |
|
2361 |
2333 #------------------------------------------------------------------------------- |
2362 #------------------------------------------------------------------------------- |
2334 # Drawing functions |
2363 # Drawing functions |
2335 #------------------------------------------------------------------------------- |
2364 #------------------------------------------------------------------------------- |
2336 |
2365 |
2337 def OnMoveWindow(self, event): |
2366 def OnMoveWindow(self, event): |