Viewer.py
changeset 165 e464a4e4e06d
parent 162 e746ff4aa8be
child 169 393193e7590a
equal deleted inserted replaced
164:0fb64076d3f5 165:e464a4e4e06d
   313         self.Controler = controler
   313         self.Controler = controler
   314         
   314         
   315         self.SetDropTarget(ViewerDropTarget(self))
   315         self.SetDropTarget(ViewerDropTarget(self))
   316         
   316         
   317         dc = wx.ClientDC(self)
   317         dc = wx.ClientDC(self)
   318         self.Font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   318         font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   319         dc.SetFont(self.Font)
   319         dc.SetFont(font)
   320         width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   320         width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   321         while width > 260:
   321         while width > 260:
   322             faces["size"] -= 1
   322             faces["size"] -= 1
   323             self.Font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   323             font = wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
   324             dc.SetFont(self.Font)
   324             dc.SetFont(font)
   325             width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
   325             width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
       
   326         self.SetFont(font)
   326         
   327         
   327         # Link Viewer event to corresponding methods
   328         # Link Viewer event to corresponding methods
   328         self.Bind(wx.EVT_PAINT, self.OnPaint)
   329         self.Bind(wx.EVT_PAINT, self.OnPaint)
   329         self.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown)
   330         self.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown)
   330         self.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp)
   331         self.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp)
   365     def GetLogicalDC(self, buffered=False):
   366     def GetLogicalDC(self, buffered=False):
   366         if buffered:
   367         if buffered:
   367             dc = wx.BufferedPaintDC(self)
   368             dc = wx.BufferedPaintDC(self)
   368         else:
   369         else:
   369             dc = wx.ClientDC(self)
   370             dc = wx.ClientDC(self)
   370         dc.SetFont(self.Font)
   371         dc.SetFont(self.GetFont())
   371         if wx.VERSION >= (2, 6, 0):
   372         if wx.VERSION >= (2, 6, 0):
   372             self.DoPrepareDC(dc)
   373             self.DoPrepareDC(dc)
   373         else:
   374         else:
   374             self.PrepareDC(dc)
   375             self.PrepareDC(dc)
   375         return dc
   376         return dc
  1103                         wire = Wire(self, [wx.Point(pos.x, pos.y), EAST], [wx.Point(pos.x, pos.y), WEST])
  1104                         wire = Wire(self, [wx.Point(pos.x, pos.y), EAST], [wx.Point(pos.x, pos.y), WEST])
  1104                     else:
  1105                     else:
  1105                         wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(pos.x, pos.y), EAST])
  1106                         wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(pos.x, pos.y), EAST])
  1106                     wire.oldPos = pos
  1107                     wire.oldPos = pos
  1107                     wire.Handle = (HANDLE_POINT, 0)
  1108                     wire.Handle = (HANDLE_POINT, 0)
  1108                     wire.ProcessDragging(0, 0, self.Scaling)
  1109                     wire.ProcessDragging(0, 0, False, self.Scaling)
  1109                     wire.Handle = (HANDLE_POINT, 1)
  1110                     wire.Handle = (HANDLE_POINT, 1)
  1110                     self.AddWire(wire)
  1111                     self.AddWire(wire)
  1111                     if self.SelectedElement:
  1112                     if self.SelectedElement:
  1112                         self.SelectedElement.SetSelected(False)
  1113                         self.SelectedElement.SetSelected(False)
  1113                     self.SelectedElement = wire
  1114                     self.SelectedElement = wire
  1379             height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
  1380             height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
  1380         return width, height
  1381         return width, height
  1381 
  1382 
  1382     def AddNewBlock(self, bbox):
  1383     def AddNewBlock(self, bbox):
  1383         dialog = BlockPropertiesDialog(self.ParentWindow)
  1384         dialog = BlockPropertiesDialog(self.ParentWindow)
       
  1385         dialog.SetPreviewFont(self.GetFont())
  1384         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
  1386         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
  1385         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1387         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1386         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName))
  1388         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName))
  1387         dialog.SetMinBlockSize((bbox.width, bbox.height))
  1389         dialog.SetMinBlockSize((bbox.width, bbox.height))
  1388         if dialog.ShowModal() == wx.ID_OK:
  1390         if dialog.ShowModal() == wx.ID_OK:
  1403             block.Refresh()
  1405             block.Refresh()
  1404         dialog.Destroy()
  1406         dialog.Destroy()
  1405     
  1407     
  1406     def AddNewVariable(self, bbox):
  1408     def AddNewVariable(self, bbox):
  1407         dialog = VariablePropertiesDialog(self.ParentWindow)
  1409         dialog = VariablePropertiesDialog(self.ParentWindow)
       
  1410         dialog.SetPreviewFont(self.GetFont())
  1408         dialog.SetMinVariableSize((bbox.width, bbox.height))
  1411         dialog.SetMinVariableSize((bbox.width, bbox.height))
  1409         varlist = []
  1412         varlist = []
  1410         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1413         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1411         if vars:
  1414         if vars:
  1412             for var in vars:
  1415             for var in vars:
  1430             variable.Refresh()
  1433             variable.Refresh()
  1431         dialog.Destroy()
  1434         dialog.Destroy()
  1432 
  1435 
  1433     def AddNewConnection(self, bbox):
  1436     def AddNewConnection(self, bbox):
  1434         dialog = ConnectionPropertiesDialog(self.ParentWindow)
  1437         dialog = ConnectionPropertiesDialog(self.ParentWindow)
       
  1438         dialog.SetPreviewFont(self.GetFont())
  1435         dialog.SetMinConnectionSize((bbox.width, bbox.height))
  1439         dialog.SetMinConnectionSize((bbox.width, bbox.height))
  1436         if dialog.ShowModal() == wx.ID_OK:
  1440         if dialog.ShowModal() == wx.ID_OK:
  1437             id = self.GetNewId()
  1441             id = self.GetNewId()
  1438             values = dialog.GetValues()
  1442             values = dialog.GetValues()
  1439             connection = FBD_Connector(self, values["type"], values["name"], id)
  1443             connection = FBD_Connector(self, values["type"], values["name"], id)
  1467             comment.Refresh()
  1471             comment.Refresh()
  1468         dialog.Destroy()
  1472         dialog.Destroy()
  1469 
  1473 
  1470     def AddNewContact(self, bbox):
  1474     def AddNewContact(self, bbox):
  1471         dialog = LDElementDialog(self.ParentWindow, "contact")
  1475         dialog = LDElementDialog(self.ParentWindow, "contact")
       
  1476         dialog.SetPreviewFont(self.GetFont())
  1472         varlist = []
  1477         varlist = []
  1473         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1478         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1474         if vars:
  1479         if vars:
  1475             for var in vars:
  1480             for var in vars:
  1476                 if var["Class"] != "Output" and var["Type"] == "BOOL":
  1481                 if var["Class"] != "Output" and var["Type"] == "BOOL":
  1492             contact.Refresh()
  1497             contact.Refresh()
  1493         dialog.Destroy()
  1498         dialog.Destroy()
  1494 
  1499 
  1495     def AddNewCoil(self, bbox):
  1500     def AddNewCoil(self, bbox):
  1496         dialog = LDElementDialog(self.ParentWindow, "coil")
  1501         dialog = LDElementDialog(self.ParentWindow, "coil")
       
  1502         dialog.SetPreviewFont(self.GetFont())
  1497         varlist = []
  1503         varlist = []
  1498         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1504         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1499         if vars:
  1505         if vars:
  1500             for var in vars:
  1506             for var in vars:
  1501                 if var["Class"] != "Input" and var["Type"] == "BOOL":
  1507                 if var["Class"] != "Input" and var["Type"] == "BOOL":
  1520             coil.Refresh()
  1526             coil.Refresh()
  1521         dialog.Destroy()
  1527         dialog.Destroy()
  1522 
  1528 
  1523     def AddNewPowerRail(self, bbox):
  1529     def AddNewPowerRail(self, bbox):
  1524         dialog = LDPowerRailDialog(self.ParentWindow)
  1530         dialog = LDPowerRailDialog(self.ParentWindow)
       
  1531         dialog.SetPreviewFont(self.GetFont())
  1525         dialog.SetMinSize((bbox.width, bbox.height))
  1532         dialog.SetMinSize((bbox.width, bbox.height))
  1526         if dialog.ShowModal() == wx.ID_OK:
  1533         if dialog.ShowModal() == wx.ID_OK:
  1527             id = self.GetNewId()
  1534             id = self.GetNewId()
  1528             values = dialog.GetValues()
  1535             values = dialog.GetValues()
  1529             powerrail = LD_PowerRail(self, values["type"], id, [True for i in xrange(values["number"])])
  1536             powerrail = LD_PowerRail(self, values["type"], id, [True for i in xrange(values["number"])])
  1537             powerrail.Refresh()
  1544             powerrail.Refresh()
  1538         dialog.Destroy()
  1545         dialog.Destroy()
  1539 
  1546 
  1540     def AddNewStep(self, bbox, initial = False):
  1547     def AddNewStep(self, bbox, initial = False):
  1541         dialog = StepContentDialog(self.ParentWindow, initial)
  1548         dialog = StepContentDialog(self.ParentWindow, initial)
       
  1549         dialog.SetPreviewFont(self.GetFont())
  1542         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1550         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1543         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
  1551         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
  1544         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
  1552         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step)])
  1545         dialog.SetMinStepSize((bbox.width, bbox.height))
  1553         dialog.SetMinStepSize((bbox.width, bbox.height))
  1546         if dialog.ShowModal() == wx.ID_OK:
  1554         if dialog.ShowModal() == wx.ID_OK:
  1570             step.Refresh()
  1578             step.Refresh()
  1571         dialog.Destroy()
  1579         dialog.Destroy()
  1572 
  1580 
  1573     def AddNewTransition(self, bbox):
  1581     def AddNewTransition(self, bbox):
  1574         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
  1582         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
       
  1583         dialog.SetPreviewFont(self.GetFont())
  1575         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
  1584         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
  1576         if dialog.ShowModal() == wx.ID_OK:
  1585         if dialog.ShowModal() == wx.ID_OK:
  1577             id = self.GetNewId()
  1586             id = self.GetNewId()
  1578             values = dialog.GetValues()
  1587             values = dialog.GetValues()
  1579             transition = SFC_Transition(self, values["type"], values["value"], values["priority"], id)
  1588             transition = SFC_Transition(self, values["type"], values["value"], values["priority"], id)
  1588             transition.Refresh()
  1597             transition.Refresh()
  1589         dialog.Destroy()
  1598         dialog.Destroy()
  1590 
  1599 
  1591     def AddNewDivergence(self, bbox):
  1600     def AddNewDivergence(self, bbox):
  1592         dialog = DivergenceCreateDialog(self.ParentWindow)
  1601         dialog = DivergenceCreateDialog(self.ParentWindow)
       
  1602         dialog.SetPreviewFont(self.GetFont())
  1593         dialog.SetMinSize((bbox.width, bbox.height))
  1603         dialog.SetMinSize((bbox.width, bbox.height))
  1594         if dialog.ShowModal() == wx.ID_OK:
  1604         if dialog.ShowModal() == wx.ID_OK:
  1595             id = self.GetNewId()
  1605             id = self.GetNewId()
  1596             values = dialog.GetValues()
  1606             values = dialog.GetValues()
  1597             divergence = SFC_Divergence(self, values["type"], values["number"], id)
  1607             divergence = SFC_Divergence(self, values["type"], values["number"], id)
  1651 #                          Edit element content functions
  1661 #                          Edit element content functions
  1652 #-------------------------------------------------------------------------------
  1662 #-------------------------------------------------------------------------------
  1653 
  1663 
  1654     def EditBlockContent(self, block):
  1664     def EditBlockContent(self, block):
  1655         dialog = BlockPropertiesDialog(self.ParentWindow)
  1665         dialog = BlockPropertiesDialog(self.ParentWindow)
       
  1666         dialog.SetPreviewFont(self.GetFont())
  1656         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
  1667         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName))
  1657         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1668         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1658         variable_names = self.Controler.GetEditedElementVariables(self.TagName)
  1669         variable_names = self.Controler.GetEditedElementVariables(self.TagName)
  1659         if block.GetName() != "":
  1670         if block.GetName() != "":
  1660             variable_names.remove(block.GetName())
  1671             variable_names.remove(block.GetName())
  1683             block.Refresh(rect)
  1694             block.Refresh(rect)
  1684         dialog.Destroy()
  1695         dialog.Destroy()
  1685 
  1696 
  1686     def EditVariableContent(self, variable):
  1697     def EditVariableContent(self, variable):
  1687         dialog = VariablePropertiesDialog(self.ParentWindow)
  1698         dialog = VariablePropertiesDialog(self.ParentWindow)
       
  1699         dialog.SetPreviewFont(self.GetFont())
  1688         dialog.SetMinVariableSize(variable.GetSize())
  1700         dialog.SetMinVariableSize(variable.GetSize())
  1689         varlist = []
  1701         varlist = []
  1690         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1702         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1691         if vars:
  1703         if vars:
  1692             for var in vars:
  1704             for var in vars:
  1719             variable.Refresh(rect)
  1731             variable.Refresh(rect)
  1720         dialog.Destroy()
  1732         dialog.Destroy()
  1721 
  1733 
  1722     def EditConnectionContent(self, connection):
  1734     def EditConnectionContent(self, connection):
  1723         dialog = ConnectionPropertiesDialog(self.ParentWindow)
  1735         dialog = ConnectionPropertiesDialog(self.ParentWindow)
       
  1736         dialog.SetPreviewFont(self.GetFont())
  1724         dialog.SetMinConnectionSize(connection.GetSize())
  1737         dialog.SetMinConnectionSize(connection.GetSize())
  1725         values = {"name" : connection.GetName(), "type" : connection.GetType()}
  1738         values = {"name" : connection.GetName(), "type" : connection.GetType()}
  1726         dialog.SetValues(values)
  1739         dialog.SetValues(values)
  1727         if dialog.ShowModal() == wx.ID_OK:
  1740         if dialog.ShowModal() == wx.ID_OK:
  1728             old_type = connection.GetType()
  1741             old_type = connection.GetType()
  1742             connection.Refresh(rect)
  1755             connection.Refresh(rect)
  1743         dialog.Destroy()
  1756         dialog.Destroy()
  1744 
  1757 
  1745     def EditContactContent(self, contact):
  1758     def EditContactContent(self, contact):
  1746         dialog = LDElementDialog(self.ParentWindow, "contact")
  1759         dialog = LDElementDialog(self.ParentWindow, "contact")
       
  1760         dialog.SetPreviewFont(self.GetFont())
  1747         varlist = []
  1761         varlist = []
  1748         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1762         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1749         if vars:
  1763         if vars:
  1750             for var in vars:
  1764             for var in vars:
  1751                 if var["Class"] != "Output" and var["Type"] == "BOOL":
  1765                 if var["Class"] != "Output" and var["Type"] == "BOOL":
  1767             contact.Refresh(rect)
  1781             contact.Refresh(rect)
  1768         dialog.Destroy()
  1782         dialog.Destroy()
  1769 
  1783 
  1770     def EditCoilContent(self, coil):
  1784     def EditCoilContent(self, coil):
  1771         dialog = LDElementDialog(self.ParentWindow, "coil")
  1785         dialog = LDElementDialog(self.ParentWindow, "coil")
       
  1786         dialog.SetPreviewFont(self.GetFont())
  1772         varlist = []
  1787         varlist = []
  1773         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1788         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName)
  1774         if vars:
  1789         if vars:
  1775             for var in vars:
  1790             for var in vars:
  1776                 if var["Class"] != "Input" and var["Type"] == "BOOL":
  1791                 if var["Class"] != "Input" and var["Type"] == "BOOL":
  1795             coil.Refresh(rect)
  1810             coil.Refresh(rect)
  1796         dialog.Destroy()
  1811         dialog.Destroy()
  1797 
  1812 
  1798     def EditPowerRailContent(self, powerrail):
  1813     def EditPowerRailContent(self, powerrail):
  1799         dialog = LDPowerRailDialog(self.ParentWindow, powerrail.GetType(), len(powerrail.GetConnectors()))
  1814         dialog = LDPowerRailDialog(self.ParentWindow, powerrail.GetType(), len(powerrail.GetConnectors()))
       
  1815         dialog.SetPreviewFont(self.GetFont())
  1800         dialog.SetMinSize(powerrail.GetSize())
  1816         dialog.SetMinSize(powerrail.GetSize())
  1801         if dialog.ShowModal() == wx.ID_OK:
  1817         if dialog.ShowModal() == wx.ID_OK:
  1802             old_type = powerrail.GetType()
  1818             old_type = powerrail.GetType()
  1803             values = dialog.GetValues()
  1819             values = dialog.GetValues()
  1804             rect = powerrail.GetRedrawRect(1, 1)
  1820             rect = powerrail.GetRedrawRect(1, 1)
  1815             powerrail.Refresh(rect)
  1831             powerrail.Refresh(rect)
  1816         dialog.Destroy()
  1832         dialog.Destroy()
  1817 
  1833 
  1818     def EditStepContent(self, step):
  1834     def EditStepContent(self, step):
  1819         dialog = StepContentDialog(self.ParentWindow, step.GetInitial())
  1835         dialog = StepContentDialog(self.ParentWindow, step.GetInitial())
       
  1836         dialog.SetPreviewFont(self.GetFont())
  1820         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1837         dialog.SetPouNames(self.Controler.GetProjectPouNames())
  1821         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
  1838         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName))
  1822         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  1839         dialog.SetStepNames([block.GetName() for block in self.Blocks if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  1823         dialog.SetMinStepSize(step.GetSize())
  1840         dialog.SetMinStepSize(step.GetSize())
  1824         values = {"name" : step.GetName()}
  1841         values = {"name" : step.GetName()}
  1850             self.RefreshScrollBars()
  1867             self.RefreshScrollBars()
  1851             step.Refresh(rect)
  1868             step.Refresh(rect)
  1852         
  1869         
  1853     def EditTransitionContent(self, transition):
  1870     def EditTransitionContent(self, transition):
  1854         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
  1871         dialog = TransitionContentDialog(self.ParentWindow, self.GetDrawingMode() == FREEDRAWING_MODE)
       
  1872         dialog.SetPreviewFont(self.GetFont())
  1855         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
  1873         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName))
  1856         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
  1874         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
  1857         dialog.SetElementSize(transition.GetSize())
  1875         dialog.SetElementSize(transition.GetSize())
  1858         if dialog.ShowModal() == wx.ID_OK:
  1876         if dialog.ShowModal() == wx.ID_OK:
  1859             values = dialog.GetValues()
  1877             values = dialog.GetValues()