plugins/svgui/svgui.py
author lbessard
Mon, 31 Mar 2008 18:33:35 +0200
changeset 137 187a4e2412e5
parent 105 434aed8dc58d
child 138 3a6ebb01760a
permissions -rw-r--r--
Modifying svgui plugin for following new SVGUIEditor version
Changing 'retrive' to 'retrieve' for any file
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     1
import os, shutil, sys
20
d3cb5020997b Beremiz plugins definitions.
etisserant
parents: 13
diff changeset
     2
base_folder = os.path.split(sys.path[0])[0]
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     3
sys.path.append(os.path.join(base_folder, "wxsvg", "SVGUIEditor"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     4
sys.path.append(os.path.join(base_folder, "plcopeneditor", "graphics"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     5
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     6
import wx
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     7
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     8
from SVGUIControler import *
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     9
from SVGUIEditor import *
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    10
from FBD_Objects import *
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    11
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    12
from wxPopen import ProcessLogger
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    13
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    14
[ID_SVGUIEDITORFBDPANEL, 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    15
] = [wx.NewId() for _init_ctrls in range(1)]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    16
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    17
SVGUIFB_Types = {ITEM_CONTAINER : "Container",
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    18
                 ITEM_BUTTON : "Button", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    19
                 ITEM_TEXT : "TextCtrl", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    20
                 ITEM_SCROLLBAR : "ScrollBar", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    21
                 ITEM_ROTATING : "RotatingCtrl", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    22
                 ITEM_NOTEBOOK : "NoteBook", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    23
                 ITEM_TRANSFORM : "Transform"}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    24
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    25
class _SVGUIEditor(SVGUIEditor):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    26
    """
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    27
    This Class add IEC specific features to the SVGUIEditor :
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    28
        - FDB preview
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    29
        - FBD begin drag 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    30
    """
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    31
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    32
    def _init_coll_EditorGridSizer_Items(self, parent):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    33
        SVGUIEditor._init_coll_EditorGridSizer_Items(self, parent)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    34
        parent.AddWindow(self.FBDPanel, 0, border=0, flag=wx.GROW)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    35
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    36
    def _init_ctrls(self, prnt):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    37
        SVGUIEditor._init_ctrls(self, prnt, False)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    38
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    39
        self.FBDPanel = wx.Panel(id=ID_SVGUIEDITORFBDPANEL, 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    40
                  name='FBDPanel', parent=self.EditorPanel, pos=wx.Point(0, 0),
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    41
                  size=wx.Size(0, 0), style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    42
        self.FBDPanel.SetBackgroundColour(wx.WHITE)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    43
        self.FBDPanel.Bind(wx.EVT_LEFT_DOWN, self.OnFBDPanelClick)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    44
        self.FBDPanel.Bind(wx.EVT_PAINT, self.OnPaintFBDPanel)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    45
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    46
        setattr(self.FBDPanel, "GetScaling", lambda: None) 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    47
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    48
        self._init_sizers()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    49
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    50
    def __init__(self, parent, controler = None, fileOpen = None):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    51
        SVGUIEditor.__init__(self, parent, controler, fileOpen)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    52
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    53
        self.FBDBlock = None
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    54
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    55
    def RefreshView(self, select_id = None):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    56
        SVGUIEditor.RefreshView(self, select_id)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    57
        self.FBDPanel.Refresh()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    58
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    59
    def OnPaintFBDPanel(self,event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    60
        dc = wx.ClientDC(self.FBDPanel)
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    61
        dc.Clear()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    62
        selected = self.GetSelected()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    63
        if selected is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    64
            selected_type = self.Controler.GetElementType(selected)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    65
            if selected_type is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    66
                self.FBDBlock = FBD_Block(parent=self.FBDPanel,type=SVGUIFB_Types[selected_type],name=self.Controler.GetElementName(selected))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    67
                width, height = self.FBDBlock.GetMinSize()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    68
                self.FBDBlock.SetSize(width,height)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    69
                clientsize = self.FBDPanel.GetClientSize()
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    70
                x = (clientsize.width - width) / 2
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    71
                y = (clientsize.height - height) / 2
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    72
                self.FBDBlock.SetPosition(x, y)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    73
                self.FBDBlock.Draw(dc)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    74
        else:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    75
            self.FBDBlock = None
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    76
        event.Skip()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    77
        
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    78
    def OnFBDPanelClick(self, event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    79
        if self.FBDBlock:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    80
            data = wx.TextDataObject(str((self.FBDBlock.GetType(), "functionBlock", self.FBDBlock.GetName())))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    81
            DropSrc = wx.DropSource(self.FBDPanel)
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    82
            DropSrc.SetData(data)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    83
            DropSrc.DoDragDrop()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    84
        event.Skip()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    85
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    86
    def OnInterfaceTreeItemSelected(self, event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    87
        self.FBDPanel.Refresh()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    88
        SVGUIEditor.OnInterfaceTreeItemSelected(self, event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    89
    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    90
    def OnGenerate(self,event):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    91
        self.SaveProject()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    92
        self.Controler.PlugGenerate_C(sys.path[0],(0,0,4,5),None)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    93
        event.Skip()    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    94
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    95
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    96
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    97
    "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    98
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
    99
CTYPECONVERSION = {"BOOL" : "IEC_BOOL", "UINT" : "IEC_UINT", "STRING" : "IEC_STRING", "REAL" : "IEC_REAL"}
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   100
CPRINTTYPECONVERSION = {"BOOL" : "d", "UINT" : "d", "STRING" : "s", "REAL" : "f"}
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   101
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   102
class RootClass(SVGUIControler):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   103
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   104
    def __init__(self):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   105
        SVGUIControler.__init__(self)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   106
        filepath = os.path.join(self.PlugPath(), "gui.xml")
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   107
        
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   108
        if os.path.isfile(filepath):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   109
            svgfile = os.path.join(self.PlugPath(), "gui.svg")
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   110
            if os.path.isfile(svgfile):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   111
                self.SvgFilepath = svgfile
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   112
            self.OpenXMLFile(filepath)
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   113
        else:
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   114
            self.CreateNewInterface()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   115
            self.SetFilePath(filepath)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   116
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   117
    def GetElementIdFromName(self, name):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   118
        element = self.GetElementByName(name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   119
        if element is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   120
            return element.getid()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   121
        return None
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   122
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   123
    _View = None
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   124
    def _OpenView(self, logger):
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   125
        if not self._View:
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   126
            def _onclose():
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   127
                self._View = None
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   128
            def _onsave():
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   129
                self.GetPlugRoot().SaveProject()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   130
            self._View = _SVGUIEditor(self.GetPlugRoot().AppFrame, self)
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   131
            self._View._onclose = _onclose
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   132
            self._View._onsave = _onsave
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   133
            self._View.Show()
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   134
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   135
    def _ImportSVG(self, logger):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   136
        if not self._View:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   137
            dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a SVG file", os.getcwd(), "",  "SVG files (*.svg)|*.svg|All files|*.*", wx.OPEN)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   138
            if dialog.ShowModal() == wx.ID_OK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   139
                svgpath = dialog.GetPath()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   140
                if os.path.isfile(svgpath):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   141
                    shutil.copy(svgpath, os.path.join(self.PlugPath(), "gui.svg"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   142
                else:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   143
                    logger.write_error("No such SVG file: %s\n"%svgpath)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   144
            dialog.Destroy()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   145
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   146
    def _ImportXML(self, logger):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   147
        if not self._View:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   148
            dialog = wx.FileDialog(self.GetPlugRoot().AppFrame, "Choose a XML file", os.getcwd(), "",  "XML files (*.xml)|*.xml|All files|*.*", wx.OPEN)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   149
            if dialog.ShowModal() == wx.ID_OK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   150
                xmlpath = dialog.GetPath()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   151
                if os.path.isfile(xmlpath):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   152
                    shutil.copy(xmlpath, os.path.join(self.PlugPath(), "gui.xml"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   153
                else:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   154
                    logger.write_error("No such XML file: %s\n"%xmlpath)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   155
            dialog.Destroy()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   156
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   157
    PluginMethods = [
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   158
        {"bitmap" : os.path.join("images","HMIEditor"),
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   159
         "name" : "HMI Editor",
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   160
         "tooltip" : "HMI Editor",
105
434aed8dc58d Added ability to override plugin methods with arbitrary python code (methods.py) when loading plugins
etisserant
parents: 82
diff changeset
   161
         "method" : "_OpenView"},
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   162
        {"bitmap" : os.path.join("images","ImportSVG"),
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   163
         "name" : "Import SVG",
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   164
         "tooltip" : "Import SVG",
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   165
         "method" : "_ImportSVG"},
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   166
        {"bitmap" : os.path.join("images","ImportDEF"),
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   167
         "name" : "Import XML",
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   168
         "tooltip" : "Import XML",
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   169
         "method" : "_InportXML"},
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   170
    ]
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   171
    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   172
    def OnPlugSave(self):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   173
        self.SaveXMLFile()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   174
        return True
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   175
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   176
    def GenerateProgramHeadersPublicVars(self, elements):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   177
        text = """    void OnPlcOutEvent(wxEvent& event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   178
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   179
    void Retrieve();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   180
    void Publish();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   181
    void Initialize();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   182
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   183
#        text += "    void Print();\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   184
        return text
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   185
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   186
    def GenerateIECVars(self, elements):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   187
        text = ""
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   188
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   189
            text += "volatile int out_state_%d;\n"%element.getid()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   190
            text += "volatile int in_state_%d;\n"%element.getid()
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   191
        text +="\n"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   192
        current_location = "_".join(map(str, self.GetCurrentLocation()))
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   193
        #Declaration des variables
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   194
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   195
            block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   196
            block_id = element.getid()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   197
            for i, input in enumerate(block_infos["inputs"]):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   198
                element_c_type = CTYPECONVERSION[input[1]]
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   199
                variable = "__Q%s%s_%d_%d"%(TYPECONVERSION[input[1]], current_location, block_id, i + 1)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   200
                text += "%s %s;\n"%(element_c_type, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   201
                text += "%s _copy%s;\n"%(element_c_type, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   202
            for i, output in enumerate(block_infos["outputs"]):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   203
                element_c_type = CTYPECONVERSION[output[1]]
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   204
                variable = "__I%s%s_%d_%d"%(TYPECONVERSION[output[1]], current_location, block_id, i + 1)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   205
                text += "%s %s;\n"%(element_c_type, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   206
                text += "%s _copy%s;\n"%(element_c_type, variable)
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   207
            text +="\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   208
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   209
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   210
    def GenerateGlobalVarsAndFuncs(self, elements, size):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   211
        text = "#include \"iec_std_lib.h\"\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   212
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   213
        text += self.GenerateIECVars(elements)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   214
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   215
        text += """IMPLEMENT_APP_NO_MAIN(SVGViewApp);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   216
IMPLEMENT_WX_THEME_SUPPORT;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   217
SVGViewApp *myapp = NULL;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   218
pthread_t wxMainLoop;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   219
"""
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   220
#        text += "pthread_t wxMainLoop,automate;\n"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   221
        text += """int myargc = 0;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   222
char** myargv = NULL;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   223
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   224
#define UNCHANGED 1
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   225
#define PLC_BUSY 2
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   226
#define CHANGED 3
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   227
#define GUI_BUSY 4
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   228
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   229
void* InitWxEntry(void* args)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   230
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   231
  wxEntry(myargc,myargv);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   232
  return args;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   233
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   234
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   235
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   236
#        text += """void* SimulAutomate(void* args)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   237
#{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   238
#  while(1){
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   239
#    myapp->frame->m_svgCtrl->IN_"+self.BusNumber+"();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   240
#    //printf(\"AUTOMATE\\n\");
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   241
#    myapp->frame->m_svgCtrl->OUT_"+self.BusNumber+"();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   242
#    sleep(1);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   243
#  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   244
#  return args;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   245
#}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   246
#
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   247
#"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   248
      
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   249
        text += """bool SVGViewApp::OnInit()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   250
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   251
  #ifndef __WXMSW__
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   252
    setlocale(LC_NUMERIC, "C");
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   253
  #endif
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   254
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   255
        #text += "  frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxSize(%d, %d));\n"%size
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   256
        text += """  frame = new MainFrame(NULL, wxT("Program"),wxDefaultPosition, wxDefaultSize);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   257
  myapp = this;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   258
"""
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   259
#        text += "  pthread_create(&automate, NULL, SimulAutomate, NULL);\n"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   260
        text += """  return true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   261
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   262
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   263
extern "C" {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   264
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   265
int __init_%(location)s(int argc, char** argv)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   266
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   267
  myargc = argc;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   268
  myargv = argv;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   269
  pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   270
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   271
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   272
void __cleanup_%(location)s()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   273
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   274
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   275
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   276
void __retrieve_%(location)s()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   277
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   278
  if(myapp){
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   279
    myapp->frame->m_svgCtrl->Retrieve();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   280
  }        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   281
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   282
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   283
void __publish_%(location)s()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   284
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   285
  if(myapp){
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   286
    myapp->frame->m_svgCtrl->Publish();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   287
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   288
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   289
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   290
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   291
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   292
IEC_STRING wxStringToIEC_STRING(wxString s)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   293
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   294
  STRING res = {0,""};
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   295
  int i;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   296
  for(i = 0; i<s.Length() && i<STR_MAX_LEN; i++)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   297
    res.body[i] = s.GetChar(i);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   298
  res.len = i;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   299
  return res;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   300
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   301
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   302
"""%{"location" : "_".join(map(str, self.GetCurrentLocation()))}
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   303
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   304
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   305
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   306
    def GenerateProgramEventTable(self, elements):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   307
        text = ""        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   308
        #text += "wxEVT_PLCOUT = wxNewEventType();\n\n";
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   309
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   310
        text += """BEGIN_DECLARE_EVENT_TYPES()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   311
DECLARE_LOCAL_EVENT_TYPE( EVT_PLC, wxNewEventType() )
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   312
END_DECLARE_EVENT_TYPES()
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   313
         
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   314
DEFINE_LOCAL_EVENT_TYPE( EVT_PLC )
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   315
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   316
"""     
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   317
        #Event Table Declaration
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   318
        text += "BEGIN_EVENT_TABLE(Program, SVGUIWindow)\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   319
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   320
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   321
            element_name = element.getname()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   322
            if element_type == ITEM_BUTTON:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   323
                text += "  EVT_BUTTON (SVGUIID(\"%s\"), Program::On%sClick)\n"%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   324
            elif element_type in [ITEM_SCROLLBAR, ITEM_ROTATING]:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   325
                text += "  EVT_COMMAND_SCROLL_THUMBTRACK (SVGUIID(\"%s\"), Program::On%sChanged)\n"%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   326
            elif element_type == ITEM_NOTEBOOK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   327
                text += "  EVT_NOTEBOOK_PAGE_CHANGED (SVGUIID(\"%s\"), Program::On%sTabChanged)\n"%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   328
##            elif element_type in [ITEM_CONTAINER, ITEM_TRANSFORM]:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   329
##                text += "  EVT_PAINT(Program::On%sPaint)\n"%element_name
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   330
        text += "  EVT_LEFT_UP (Program::OnClick)\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   331
        text += "  EVT_CUSTOM( EVT_PLC, wxID_ANY, Program::OnPlcOutEvent )\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   332
        text += "END_EVENT_TABLE()\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   333
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   334
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   335
    def GenerateProgramInitFrame(self, elements):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   336
        text = """MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,const wxSize& size, long style): wxFrame(parent, wxID_ANY, title, pos, size, style)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   337
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   338
  m_svgCtrl = new Program(this);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   339
  if (m_svgCtrl->LoadFiles(wxT("%s"), wxT("%s")))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   340
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   341
    Show(true);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   342
    m_svgCtrl->SetFocus();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   343
    m_svgCtrl->SetFitToFrame(true);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   344
    m_svgCtrl->RefreshScale();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   345
    m_svgCtrl->InitScrollBars();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   346
    m_svgCtrl->Initialize();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   347
    m_svgCtrl->Update();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   348
    //m_svgCtrl->Print();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   349
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   350
  else
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   351
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   352
    printf("Error while opening files\\n");
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   353
    exit(0);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   354
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   355
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   356
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   357
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   358
"""%(self.GetSVGFilePath(), self.GetFilePath())
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   359
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   360
        return text
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   361
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   362
    def GenerateProgramInitProgram(self, elements):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   363
        text = "Program::Program(wxWindow* parent):SVGUIWindow(parent)\n{\n"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   364
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   365
            text += "    out_state_%d = UNCHANGED;\n"%element.getid()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   366
            text += "    in_state_%d = UNCHANGED;\n"%element.getid()
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   367
        text += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   368
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   369
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   370
    def GenerateProgramEventFunctions(self, elements):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   371
        text = ""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   372
        current_location = "_".join(map(str, self.GetCurrentLocation()))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   373
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   374
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   375
            element_state = "  in_state_%d = %s;\n"%(element.getid(), "%s")
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   376
            element_name = element.getname()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   377
                
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   378
            block_infos = GetBlockType(SVGUIFB_Types[element_type])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   379
            if element_type == ITEM_BUTTON:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   380
                text += """void Program::On%sClick(wxCommandEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   381
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   382
  SVGUIButton* button = (SVGUIButton*)GetElementByName(wxT("%s"));\n"""%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   383
                text += element_state%"GUI_BUSY"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   384
                for i, output in enumerate(block_infos["outputs"]):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   385
                    element_type = TYPECONVERSION[output[1]]
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   386
                    if i == 0:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   387
                        value = "button->IsVisible()"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   388
                    elif i == 1:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   389
                        value = "button->GetToggle()"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   390
                    else:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   391
                        value = "0"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   392
                    text += "  _copy__I%s%s_%d_%d = %s;\n"%(TYPECONVERSION[output[1]], current_location, element.getid(), i + 1, value)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   393
                text += element_state%"CHANGED"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   394
                text += "  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   395
            elif element_type == ITEM_ROTATING:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   396
                text += """void Program::On%sChanged(wxScrollEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   397
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   398
  SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementByName(wxT("%s"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   399
  rotating->SendScrollEvent(event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   400
  double angle = rotating->GetAngle();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   401
"""%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   402
                text += element_state%"GUI_BUSY"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   403
                for i, output in enumerate(block_infos["outputs"]):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   404
                    text += "  _copy__I%s%s_%d_%d = %s;\n"%(TYPECONVERSION[output[1]], current_location, element.getid(), i + 1, ["angle", "true"][value])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   405
                text += element_state%"CHANGED"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   406
                text += "  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   407
            elif element_type == ITEM_NOTEBOOK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   408
                text += """void Program::On%sTabChanged(wxNotebookEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   409
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   410
  SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementByName(wxT("%s"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   411
  notebook->SendNotebookEvent(event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   412
  unsigned int selected = notebook->GetCurrentPage();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   413
"""%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   414
                text += element_state%"GUI_BUSY"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   415
                for i, output in enumerate(block_infos["outputs"]):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   416
                    text += "  _copy__I%s%s_%d_%d = %s;\n"%(TYPECONVERSION[output[1]], current_location, element.getid(), i + 1, ["selected", "true"][value])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   417
                text += element_state%"CHANGED"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   418
                text += "  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   419
            elif element_type == ITEM_TRANSFORM:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   420
                text += """void Program::On%sPaint(wxPaintEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   421
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   422
  SVGUITransform* transform = (SVGUITransform*)GetElementByName(wxT("%s"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   423
"""%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   424
                text += element_state%"GUI_BUSY"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   425
                for i, output in enumerate(block_infos["outputs"]):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   426
                    if i < 5:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   427
                        texts = {"location" : current_location, "id" : element.getid(), 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   428
                                 "pin" : i + 1, "param" : ["X", "Y", "XScale", "YScale", "Angle"][i]}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   429
                    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   430
                        text += """  if (transform->Get%(param)s() != _copy__ID%(location)s_%(id)d_%(pin)d)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   431
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   432
    _copy__ID%(location)s_%(id)d_%(pin)d = transform->Get%(param)s();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   433
    _copy__IX%(location)s_%(id)d_6 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   434
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   435
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   436
                text += element_state%"CHANGED"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   437
                text += "  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   438
            elif element_type == ITEM_CONTAINER:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   439
                text += """void Program::On%sPaint(wxPaintEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   440
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   441
  SVGUIContainer* container = (SVGUIContainer*)GetElementByName(wxT("%s"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   442
  bool isvisible = container->IsVisible();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   443
"""%(element_name, element_name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   444
                text += element_state%"GUI_BUSY"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   445
                texts = {"location" : current_location, "id" : element.getid()}
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   446
                
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   447
                text += """  if (isvisible != _copy__IX%(location)s_%(id)d_1)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   448
  {    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   449
    _copy__IX%(location)s_%(id)d_1 = container->IsVisible();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   450
    _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   451
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   452
                text += "  %s  }\n  else {\n  %s  }\n"%(element_state%"CHANGED", element_state%"UNCHANGED")
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   453
                text += "  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   454
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   455
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   456
        text += """void Program::OnChar(wxKeyEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   457
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   458
  SVGUIContainer* container = GetSVGUIRootElement();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   459
  if (container->GetFocusedElementName() == wxT("TextCtrl"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   460
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   461
    wxString focusedId = container->GetFocusedElement();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   462
    SVGUITextCtrl* text = (SVGUITextCtrl*)GetElementById(focusedId);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   463
    text->SendKeyEvent(event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   464
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   465
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   466
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   467
            if element_type == ITEM_TEXT:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   468
                texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   469
                
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   470
                text += """    if (focusedId == wxT("%(id)d"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   471
    {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   472
      in_state_%(id)d = GUI_BUSY;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   473
      _copy__IB%(location)s_%(id)d_1 = wxStringToIEC_STRING(text->GetValue());
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   474
      _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   475
      in_state_%(id)d = CHANGED;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   476
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   477
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   478
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   479
        text += "  }\n  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   480
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   481
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   482
        text += """void Program::OnClick(wxMouseEvent& event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   483
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   484
  SVGUIContainer* container = GetSVGUIRootElement();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   485
  if (container->GetFocusedElementName() == wxT("ScrollBar"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   486
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   487
    wxString focusedId = container->GetFocusedElement();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   488
    SVGUIScrollBar* scrollbar = (SVGUIScrollBar*)GetElementById(focusedId);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   489
    scrollbar->SendMouseEvent(event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   490
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   491
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   492
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   493
            if element_type == ITEM_SCROLLBAR:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   494
                texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   495
                
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   496
                text += """    if (focusedId == wxT("%(id)d"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   497
    {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   498
      unsigned int scrollPos = scrollbar->GetThumbPosition();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   499
      _copy__IW%(location)s_%(id)d_1 = scrollPos;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   500
      _copy__IX%(location)s_%(id)d_2 = true;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   501
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   502
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   503
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   504
        text += "  }\n  event.Skip();\n}\n\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   505
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   506
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   507
        text += "/* OnPlcOutEvent update GUI with provided IEC __Q* PLC output variables */\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   508
        text += "void Program::OnPlcOutEvent(wxEvent& event)\n{\n  wxMutexGuiEnter();"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   509
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   510
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   511
            texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   512
            
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   513
            element_lock = "  if (__sync_val_compare_and_swap (&out_state_%(id)d, CHANGED, GUI_BUSY) == CHANGED)\n  {\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   514
            element_unlock = "    __sync_val_compare_and_swap (&out_state_%(id)d, GUI_BUSY, UNCHANGED);\n  }\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   515
            if element_type == ITEM_BUTTON:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   516
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   517
                text += """    SVGUIButton* button = (SVGUIButton*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   518
    //if (_copy__QX%(location)s_%(id)d_1)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   519
    //  button->Show();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   520
    //else
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   521
    //  button->Hide();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   522
    if (_copy__QX%(location)s_%(id)d_2 != button->GetToggle()) {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   523
      button->SetToggle(_copy__QX%(location)s_%(id)d_2);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   524
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   525
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   526
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   527
            elif element_type == ITEM_CONTAINER:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   528
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   529
                text += """  if (_copy__QX%(location)s_%(id)d_2)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   530
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   531
    SVGUIContainer* container = (SVGUIContainer*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   532
    //if (_copy__QX%(location)s_%(id)d_1)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   533
    //  container->Show();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   534
    //else
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   535
    //  container->Hide();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   536
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   537
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   538
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   539
            elif element_type == ITEM_TEXT:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   540
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   541
                text += """  if (_copy__QX%(location)s_%(id)d_2)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   542
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   543
    SVGUITextCtrl* text = (SVGUITextCtrl*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   544
    wxString str = wxString::FromAscii(_copy__QB%(location)s_%(id)d_1);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   545
    text->SetText(str);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   546
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   547
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   548
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   549
            elif  element_type == ITEM_SCROLLBAR:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   550
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   551
                text += """  if (_copy__QX%(location)s_%(id)d_2)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   552
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   553
    SVGUIScrollBar* scrollbar = (SVGUIScrollBar*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   554
    scrollbar->SetThumbPosition(_copy__QW%(location)s_%(id)d_1);\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   555
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   556
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   557
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   558
            elif element_type == ITEM_ROTATING:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   559
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   560
                text += """  if (_copy__QX%(location)s_%(id)d_2)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   561
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   562
    SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   563
    rotating->SetAngle(_copy__QD%(location)s_%(id)d_1);\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   564
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   565
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   566
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   567
            elif elment_type == ITEM_NOTEBOOK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   568
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   569
                text += """  if (copy__QX%(location)s_%(id)d_2)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   570
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   571
    SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   572
    notebook->SetCurrentPage(_copy__QB%(location)s_%(id)d_1);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   573
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   574
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   575
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   576
            elif elment_type == ITEM_TRANSFORM:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   577
                text += element_lock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   578
                text += """  if (copy__QX%(location)s_%(id)d_6)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   579
  {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   580
    SVGUITransform* transform = (SVGUITransform*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   581
    transform->Move(_copy__QD%(location)s_%(id)d_1, _copy__QD%(location)s_%(id)d_2);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   582
    transform->Scale(_copy__QD%(location)s_%(id)d_3, _copy__QD%(location)s_%(id)d_4);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   583
    transform->Rotate(_copy__QD%(location)s_%(id)d_5);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   584
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   585
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   586
                text += element_unlock
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   587
        text += """  wxMutexGuiLeave();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   588
  event.Skip();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   589
}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   590
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   591
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   592
        return text
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   593
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   594
    def GenerateProgramPrivateFunctions(self, elements):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   595
        current_location = "_".join(map(str, self.GetCurrentLocation()))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   596
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   597
        text = "void Program::Retrieve()\n{\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   598
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   599
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   600
            texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   601
            block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   602
            
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   603
            text += """  do{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   604
    if ( __sync_val_compare_and_swap (&in_state_%(id)d, CHANGED, PLC_BUSY) == CHANGED){
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   605
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   606
            for i, output in enumerate(block_infos["outputs"]):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   607
                texts["type"] = TYPECONVERSION[output[1]]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   608
                texts["pin"] = i + 1
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   609
                
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   610
                variable = "__I%(type)s%(location)s_%(id)d_%(pin)d"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   611
                text +="      %s = _copy%s;\n"%(variable, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   612
            
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   613
            text += "      /* reset change status pin */\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   614
            if element_type in [ITEM_BUTTON, ITEM_CONTAINER, ITEM_TEXT, ITEM_SCROLLBAR, ITEM_ROTATING, ITEM_NOTEBOOK]:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   615
                text += "      _copy__IX%(location)s_%(id)d_2 = false;\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   616
            elif element_type == ITEM_TRANSFORM:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   617
                text += "      _copy__IX%(location)s_%(id)d_6 = false;\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   618
            text += """    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   619
    else {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   620
      break;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   621
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   622
"""
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   623
            #If GUI did change data while publishing, do it again (in real-time this should be avoided with priority stuff)
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   624
            text += "  }while(__sync_val_compare_and_swap (&in_state_%(id)s, PLC_BUSY, UNCHANGED) != PLC_BUSY);\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   625
        text += "}\n\n" 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   626
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   627
        text += """void Program::Publish()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   628
{
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   629
  bool refresh = false;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   630
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   631
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   632
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   633
            texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   634
            block_infos = GetBlockType(SVGUIFB_Types[GetElementType(element)])
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   635
            
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   636
            text += """  if ( __sync_bool_compare_and_swap (&out_state_%(id)d, UNCHANGED, PLC_BUSY) ||
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   637
       __sync_bool_compare_and_swap (&out_state_%(id)d, CHANGED, PLC_BUSY)) {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   638
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   639
            for i, input in enumerate(block_infos["inputs"]):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   640
                texts["type"] = TYPECONVERSION[input[1]]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   641
                texts["pin"] = i + 1
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   642
                variable = "__Q%(type)s%(location)s_%(id)d_%(pin)d"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   643
                text += "    if (_copy%s != %s) {\n"%(variable, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   644
                text += "      _copy%s = %s;\n"%(variable, variable)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   645
                text += "      out_state_%(id)d = CHANGED;\n    }\n"%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   646
            text += """    if (out_state_%(id)d == CHANGED) {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   647
      refresh = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   648
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   649
    else {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   650
      out_state_%(id)d = UNCHANGED;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   651
    }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   652
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   653
"""%texts
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   654
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   655
        text += """  /*Replace this with determinist signal if called from RT*/;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   656
  if (refresh) {
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   657
    wxCommandEvent event( EVT_PLC );
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   658
    ProcessEvent(event);
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   659
  }
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   660
};
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   661
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   662
"""
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   663
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   664
        text += "void Program::Initialize()\n{\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   665
        button = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   666
        container = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   667
        textctrl = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   668
        scrollbar = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   669
        rotatingctrl = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   670
        notebook = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   671
        transform = False
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   672
        for element in elements:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   673
            element_type = GetElementType(element)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   674
            texts = {"location" : current_location, "id" : element.getid()}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   675
            
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   676
            if element_type == ITEM_BUTTON:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   677
                if (not button):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   678
                    text += "  SVGUIButton* button;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   679
                text += """  button = (SVGUIButton*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   680
  if (button->IsVisible())
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   681
    _copy__IX%(location)s_%(id)d_1 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   682
  else
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   683
    _copy__IX%(location)s_%(id)d_1 = false;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   684
  _copy__IX%(location)s_%(id)d_2 = false;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   685
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   686
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   687
                button = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   688
            elif element_type == ITEM_CONTAINER:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   689
                if (not container):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   690
                    text += "  SVGUIContainer* container;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   691
                text += """  container = (SVGUIContainer*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   692
  if (container->IsVisible())
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   693
    _copy__IX%(location)s_%(id)d_1 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   694
  else
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   695
    _copy__IX%(location)s_%(id)d_1 = false;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   696
  _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   697
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   698
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   699
                container = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   700
            elif element_type == ITEM_TEXT:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   701
                if (not textctrl):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   702
                    text += "  SVGUITextCtrl* text;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   703
                text += """  text = (SVGUITextCtrl*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   704
  _copy__IB%(location)s_%(id)d_1 = wxStringToIEC_STRING(text->GetValue());
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   705
  _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   706
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   707
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   708
                textctrl = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   709
            elif element_type == ITEM_SCROLLBAR:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   710
                if (not scrollbar):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   711
                    text += "  SVGUIScrollBar* scrollbar;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   712
                text += """  scrollbar = (SVGUIScrollBar*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   713
  _copy__IW%(location)s_%(id)d_1 = scrollbar->GetThumbPosition();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   714
  _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   715
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   716
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   717
                scrollbar = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   718
            elif element_type == ITEM_ROTATING:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   719
                if (not rotatingctrl):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   720
                    text += "  SVGUIRotatingCtrl* rotating;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   721
                text += """  rotating = (SVGUIRotatingCtrl*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   722
  _copy__ID%(location)s_%(id)d_1 = rotating->GetAngle();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   723
  _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   724
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   725
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   726
                rotatingctrl = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   727
            elif element_type == ITEM_NOTEBOOK:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   728
                if (not notebook):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   729
                    text += "  SVGUINoteBook* notebook;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   730
                text += """  notebook = (SVGUINoteBook*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   731
  _copy__IB%(location)s_%(id)d_1 = notebook->GetCurrentPage();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   732
  _copy__IX%(location)s_%(id)d_2 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   733
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   734
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   735
                notebook = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   736
            elif element_type == ITEM_TRANSFORM:
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   737
                if (not transform):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   738
                    text += "  SVGUITransform* transform;\n"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   739
                text += """  transform = (SVGUITransform*)GetElementById(wxT("%(id)d"));
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   740
  _copy__ID%(location)s_%(id)d_1 = transform->GetX();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   741
  _copy__ID%(location)s_%(id)d_2 = transform->GetY();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   742
  _copy__ID%(location)s_%(id)d_3 = transform->GetXScale();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   743
  _copy__ID%(location)s_%(id)d_4 = transform->GetYScale();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   744
  _copy__ID%(location)s_%(id)d_5 = transform->GetAngle();
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   745
  _copy__IX%(location)s_%(id)d_6 = true;
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   746
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   747
"""%texts
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   748
                transform = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   749
        text += "}\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   750
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   751
        #DEBUG Fonction d'affichage
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   752
#        fct += "void Program::Print()\n{\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   753
#        for element in elementsTab:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   754
#            infos = element.getElementAttributes()
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   755
#            for info in infos:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   756
#                if info["name"] == "id":
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   757
#                    element_id = str(info["value"])
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   758
#            type = element.GetElementInfos()["type"]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   759
#            FbdBlock = self.GetBlockType(type)
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   760
#            element_num_patte = 1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   761
#            for input in FbdBlock["inputs"]:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   762
#                element_type = TYPECONVERSION[input[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   763
#                c_type = CPRINTTYPECONVERSION[input[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   764
#                var = "_copy__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   765
#                fct +="  printf(\""+var+": %"+c_type+"\\n\","+var+");\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   766
#                element_num_patte +=1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   767
#            element_num_patte = 1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   768
#            for output in FbdBlock["outputs"]:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   769
#                element_type = TYPECONVERSION[output[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   770
#                c_type = CPRINTTYPECONVERSION[output[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   771
#                var = "_copy__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   772
#                fct +="  printf(\""+var+": %"+c_type+"\\n\","+var+");\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   773
#                element_num_patte +=1
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   774
        #fct +="    wxPostEvent(Program,wxEVT_PLCOUT);\n"
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   775
#        fct +="};\n\n"    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   776
        return text
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   777
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   778
    def PlugGenerate_C(self, buildpath, locations, logger):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   779
        progname = "SVGUI_%s"%"_".join(map(str, self.GetCurrentLocation()))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   780
        self.GenerateProgram((0, 0), buildpath, progname)
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   781
        Gen_C_file = os.path.join(buildpath, progname+".cpp" )
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   782
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   783
        status, result, err_result = ProcessLogger(logger, "wx-config --cxxflags", no_stdout=True).spin()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   784
        if status:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   785
            logger.write_error("Unable to get wx cxxflags\n")
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   786
        cxx_flags = result.strip() + " -I../matiec/lib"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   787
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   788
        status, result, err_result = ProcessLogger(logger, "wx-config --libs", no_stdout=True).spin()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   789
        if status:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   790
            logger.write_error("Unable to get wx libs\n")
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   791
        libs = result.strip() + " -lwxsvg"
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   792
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   793
        return [(Gen_C_file, cxx_flags)],libs,True
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   794
    
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   795
    def BlockTypesFactory(self):
73
5e1e3d46c0c9 Adding support for execution order code generation
lbessard
parents: 65
diff changeset
   796
        def generate_svgui_block(generator, block, body, link, order=False):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   797
            name = block.getinstanceName()
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   798
            block_id = self.GetElementIdFromName(name)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   799
            if block_id == None:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   800
                raise ValueError, "No corresponding block found"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   801
            type = block.gettypeName()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   802
            block_infos = GetBlockType(type)
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   803
            current_location = ".".join(map(str, self.GetCurrentLocation()))
73
5e1e3d46c0c9 Adding support for execution order code generation
lbessard
parents: 65
diff changeset
   804
            if not generator.ComputedBlocks.get(name, False) and not order:
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   805
                for num, variable in enumerate(block.inputVariables.getvariable()):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   806
                    connections = variable.connectionPointIn.getconnections()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   807
                    if connections and len(connections) == 1:
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   808
                        parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num+1)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   809
                        value = generator.ComputeFBDExpression(body, connections[0])
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   810
                        generator.Program += ("  %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
73
5e1e3d46c0c9 Adding support for execution order code generation
lbessard
parents: 65
diff changeset
   811
                generator.ComputedBlocks[block] = True
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   812
            if link:
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   813
                connectionPoint = link.getposition()[-1]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   814
                for num, variable in enumerate(block.outputVariables.getvariable()):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   815
                    blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   816
                    if block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety():
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   817
                        return "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   818
                raise ValueError, "No output variable found"
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   819
            else:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   820
                return None
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   821
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   822
        def initialise_block(type, name):
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   823
            block_id = self.GetElementIdFromName(name)
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   824
            if block_id == None:
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   825
                raise ValueError, "No corresponding block found"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   826
            block_infos = GetBlockType(type)
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   827
            current_location = ".".join(map(str, self.GetCurrentLocation()))
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   828
            variables = []
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   829
            for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]):
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   830
                variables.append((input_type, None, "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None))
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   831
            for num, (output_name, output_type, output_modifier) in enumerate(block_infos["outputs"]):
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   832
                variables.append((output_type, None, "%sI%s%s.%d.%d"%("%", TYPECONVERSION[input_type], current_location, block_id, num+1), None))
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   833
            return variables
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   834
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   835
        return [{"name" : "SVGUI function blocks", "list" :
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   836
                [{"name" : "Container", "type" : "functionBlock", "extensible" : False, 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   837
                    "inputs" : [("Show","BOOL","none"),("SetState","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   838
                    "outputs" : [("Visible","BOOL","none"),("StateChanged","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   839
                    "comment" : "SVGUI Container",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   840
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   841
                {"name" : "Button", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   842
                    "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   843
                    "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   844
                    "comment" : "SVGUI Button",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   845
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   846
                {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   847
                    "inputs" : [("Text","STRING","none"),("SetText","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   848
                    "outputs" : [("Text","STRING","none"),("TextChanged","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   849
                    "comment" : "SVGUI Text Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   850
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   851
                {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   852
                    "inputs" : [("Position","UINT","none"),("SetPosition","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   853
                    "outputs" : [("Position","UINT","none"),("PositionChanged","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   854
                    "comment" : "SVGUI ScrollBar",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   855
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   856
                {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   857
                    "inputs" : [("Selected","UINT","none"),("SetSelected","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   858
                    "outputs" : [("Selected","UINT","none"),("SelectedChanged","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   859
                    "comment" : "SVGUI Notebook",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   860
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   861
                {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   862
                    "inputs" : [("Angle","REAL","none"),("SetAngle","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   863
                    "outputs" : [("Angle","REAL","none"),("AngleChanged","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   864
                    "comment" : "SVGUI Rotating Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   865
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   866
                {"name" : "Transform", "type" : "functionBlock", "extensible" : False, 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   867
                    "inputs" : [("X","REAL","none"),("Y","REAL","none"),("XScale","REAL","none"),("YScale","REAL","none"),("Angle","REAL","none"),("Set","BOOL","none")], 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   868
                    "outputs" : [("X","REAL","none"),("Y","REAL","none"),("XScale","REAL","none"),("YScale","REAL","none"),("Angle","REAL","none"),("Changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   869
                    "comment" : "SVGUI Transform",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   870
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   871
               ]}
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   872
        ]
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   873