Viewer.py
changeset 409 34c9f624c2fe
parent 407 0a324a874981
child 431 c1c92d068ac5
equal deleted inserted replaced
408:0e389fa5b160 409:34c9f624c2fe
    31     USE_AUI = False
    31     USE_AUI = False
    32 
    32 
    33 from plcopen.structures import *
    33 from plcopen.structures import *
    34 from PLCControler import ITEM_POU
    34 from PLCControler import ITEM_POU
    35 
    35 
    36 from Dialogs import *
    36 from dialogs import *
       
    37 from graphics import *
    37 
    38 
    38 from types import TupleType
    39 from types import TupleType
    39 
    40 
    40 SCROLLBAR_UNIT = 10
    41 SCROLLBAR_UNIT = 10
    41 WINDOW_BORDER = 10
    42 WINDOW_BORDER = 10
  1710             width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0]
  1711             width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0]
  1711             height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
  1712             height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
  1712         return width, height
  1713         return width, height
  1713     
  1714     
  1714     def AddNewBlock(self, bbox):
  1715     def AddNewBlock(self, bbox):
  1715         dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler)
  1716         dialog = FBDBlockDialog(self.ParentWindow, self.Controler)
  1716         dialog.SetPreviewFont(self.GetFont())
  1717         dialog.SetPreviewFont(self.GetFont())
  1717         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
  1718         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
  1718         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1719         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1719         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  1720         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  1720         dialog.SetMinBlockSize((bbox.width, bbox.height))
  1721         dialog.SetMinBlockSize((bbox.width, bbox.height))
  1740         dialog.Destroy()
  1741         dialog.Destroy()
  1741     
  1742     
  1742     def AddNewVariable(self, bbox):
  1743     def AddNewVariable(self, bbox):
  1743         words = self.TagName.split("::")
  1744         words = self.TagName.split("::")
  1744         if words[0] == "T":
  1745         if words[0] == "T":
  1745             dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler, words[2])
  1746             dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2])
  1746         else:
  1747         else:
  1747             dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler)
  1748             dialog = FBDVariableDialog(self.ParentWindow, self.Controler)
  1748         dialog.SetPreviewFont(self.GetFont())
  1749         dialog.SetPreviewFont(self.GetFont())
  1749         dialog.SetMinVariableSize((bbox.width, bbox.height))
  1750         dialog.SetMinVariableSize((bbox.width, bbox.height))
  1750         varlist = []
  1751         varlist = []
  1751         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
  1752         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
  1752         if vars:
  1753         if vars:
  1771             self.RefreshVisibleElements()
  1772             self.RefreshVisibleElements()
  1772             variable.Refresh()
  1773             variable.Refresh()
  1773         dialog.Destroy()
  1774         dialog.Destroy()
  1774 
  1775 
  1775     def AddNewConnection(self, bbox):
  1776     def AddNewConnection(self, bbox):
  1776         dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
  1777         dialog = ConnectionDialog(self.ParentWindow, self.Controler)
  1777         dialog.SetPreviewFont(self.GetFont())
  1778         dialog.SetPreviewFont(self.GetFont())
  1778         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1779         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1779         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  1780         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  1780         dialog.SetMinConnectionSize((bbox.width, bbox.height))
  1781         dialog.SetMinConnectionSize((bbox.width, bbox.height))
  1781         if dialog.ShowModal() == wx.ID_OK:
  1782         if dialog.ShowModal() == wx.ID_OK:
  1889             self.RefreshVisibleElements()
  1890             self.RefreshVisibleElements()
  1890             powerrail.Refresh()
  1891             powerrail.Refresh()
  1891         dialog.Destroy()
  1892         dialog.Destroy()
  1892 
  1893 
  1893     def AddNewStep(self, bbox, initial = False):
  1894     def AddNewStep(self, bbox, initial = False):
  1894         dialog = StepContentDialog(self.ParentWindow, self.Controler, initial)
  1895         dialog = SFCStepDialog(self.ParentWindow, self.Controler, initial)
  1895         dialog.SetPreviewFont(self.GetFont())
  1896         dialog.SetPreviewFont(self.GetFont())
  1896         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1897         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  1897         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  1898         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  1898         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step)])
  1899         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step)])
  1899         dialog.SetMinStepSize((bbox.width, bbox.height))
  1900         dialog.SetMinStepSize((bbox.width, bbox.height))
  1924             self.RefreshVisibleElements()
  1925             self.RefreshVisibleElements()
  1925             step.Refresh()
  1926             step.Refresh()
  1926         dialog.Destroy()
  1927         dialog.Destroy()
  1927 
  1928 
  1928     def AddNewTransition(self, bbox):
  1929     def AddNewTransition(self, bbox):
  1929         dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
  1930         dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
  1930         dialog.SetPreviewFont(self.GetFont())
  1931         dialog.SetPreviewFont(self.GetFont())
  1931         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
  1932         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
  1932         if dialog.ShowModal() == wx.ID_OK:
  1933         if dialog.ShowModal() == wx.ID_OK:
  1933             id = self.GetNewId()
  1934             id = self.GetNewId()
  1934             values = dialog.GetValues()
  1935             values = dialog.GetValues()
  1944             self.RefreshVisibleElements()
  1945             self.RefreshVisibleElements()
  1945             transition.Refresh()
  1946             transition.Refresh()
  1946         dialog.Destroy()
  1947         dialog.Destroy()
  1947 
  1948 
  1948     def AddNewDivergence(self, bbox):
  1949     def AddNewDivergence(self, bbox):
  1949         dialog = DivergenceCreateDialog(self.ParentWindow, self.Controler)
  1950         dialog = SFCDivergenceDialog(self.ParentWindow, self.Controler)
  1950         dialog.SetPreviewFont(self.GetFont())
  1951         dialog.SetPreviewFont(self.GetFont())
  1951         dialog.SetMinSize((bbox.width, bbox.height))
  1952         dialog.SetMinSize((bbox.width, bbox.height))
  1952         if dialog.ShowModal() == wx.ID_OK:
  1953         if dialog.ShowModal() == wx.ID_OK:
  1953             id = self.GetNewId()
  1954             id = self.GetNewId()
  1954             values = dialog.GetValues()
  1955             values = dialog.GetValues()
  2011 #-------------------------------------------------------------------------------
  2012 #-------------------------------------------------------------------------------
  2012 #                          Edit element content functions
  2013 #                          Edit element content functions
  2013 #-------------------------------------------------------------------------------
  2014 #-------------------------------------------------------------------------------
  2014 
  2015 
  2015     def EditBlockContent(self, block):
  2016     def EditBlockContent(self, block):
  2016         dialog = BlockPropertiesDialog(self.ParentWindow, self.Controler)
  2017         dialog = FBDBlockDialog(self.ParentWindow, self.Controler)
  2017         dialog.SetPreviewFont(self.GetFont())
  2018         dialog.SetPreviewFont(self.GetFont())
  2018         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
  2019         dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
  2019         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2020         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2020         variable_names = self.Controler.GetEditedElementVariables(self.TagName, self.Debug)
  2021         variable_names = self.Controler.GetEditedElementVariables(self.TagName, self.Debug)
  2021         if block.GetName() != "":
  2022         if block.GetName() != "":
  2053         dialog.Destroy()
  2054         dialog.Destroy()
  2054 
  2055 
  2055     def EditVariableContent(self, variable):
  2056     def EditVariableContent(self, variable):
  2056         words = self.TagName.split("::")
  2057         words = self.TagName.split("::")
  2057         if words[0] == "T":
  2058         if words[0] == "T":
  2058             dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler, words[2])
  2059             dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2])
  2059         else:
  2060         else:
  2060             dialog = VariablePropertiesDialog(self.ParentWindow, self.Controler)
  2061             dialog = FBDVariableDialog(self.ParentWindow, self.Controler)
  2061         dialog.SetPreviewFont(self.GetFont())
  2062         dialog.SetPreviewFont(self.GetFont())
  2062         dialog.SetMinVariableSize(variable.GetSize())
  2063         dialog.SetMinVariableSize(variable.GetSize())
  2063         varlist = []
  2064         varlist = []
  2064         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
  2065         vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
  2065         if vars:
  2066         if vars:
  2093             self.RefreshScrollBars()
  2094             self.RefreshScrollBars()
  2094             variable.Refresh(rect)
  2095             variable.Refresh(rect)
  2095         dialog.Destroy()
  2096         dialog.Destroy()
  2096 
  2097 
  2097     def EditConnectionContent(self, connection):
  2098     def EditConnectionContent(self, connection):
  2098         dialog = ConnectionPropertiesDialog(self.ParentWindow, self.Controler)
  2099         dialog = ConnectionDialog(self.ParentWindow, self.Controler)
  2099         dialog.SetPreviewFont(self.GetFont())
  2100         dialog.SetPreviewFont(self.GetFont())
  2100         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2101         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2101         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  2102         dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
  2102         dialog.SetMinConnectionSize(connection.GetSize())
  2103         dialog.SetMinConnectionSize(connection.GetSize())
  2103         values = {"name" : connection.GetName(), "type" : connection.GetType()}
  2104         values = {"name" : connection.GetName(), "type" : connection.GetType()}
  2199             self.RefreshVisibleElements()
  2200             self.RefreshVisibleElements()
  2200             powerrail.Refresh(rect)
  2201             powerrail.Refresh(rect)
  2201         dialog.Destroy()
  2202         dialog.Destroy()
  2202 
  2203 
  2203     def EditStepContent(self, step):
  2204     def EditStepContent(self, step):
  2204         dialog = StepContentDialog(self.ParentWindow, self.Controler, step.GetInitial())
  2205         dialog = SFCStepDialog(self.ParentWindow, self.Controler, step.GetInitial())
  2205         dialog.SetPreviewFont(self.GetFont())
  2206         dialog.SetPreviewFont(self.GetFont())
  2206         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2207         dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
  2207         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  2208         dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
  2208         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  2209         dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
  2209         dialog.SetMinStepSize(step.GetSize())
  2210         dialog.SetMinStepSize(step.GetSize())
  2236             self.RefreshScrollBars()
  2237             self.RefreshScrollBars()
  2237             self.RefreshVisibleElements()
  2238             self.RefreshVisibleElements()
  2238             step.Refresh(rect)
  2239             step.Refresh(rect)
  2239         
  2240         
  2240     def EditTransitionContent(self, transition):
  2241     def EditTransitionContent(self, transition):
  2241         dialog = TransitionContentDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
  2242         dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
  2242         dialog.SetPreviewFont(self.GetFont())
  2243         dialog.SetPreviewFont(self.GetFont())
  2243         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
  2244         dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
  2244         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
  2245         dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
  2245         dialog.SetElementSize(transition.GetSize())
  2246         dialog.SetElementSize(transition.GetSize())
  2246         if dialog.ShowModal() == wx.ID_OK:
  2247         if dialog.ShowModal() == wx.ID_OK: