plugins/svgui/svgui.py
author etisserant
Wed, 11 Mar 2009 10:41:55 +0100
changeset 320 76492675c3ed
parent 272 9cce83526487
permissions -rw-r--r--
Restored splash with new lolitech logo
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
260
038eff285e00 add docutils in svgui plugins to launch inkscape
greg
parents: 259
diff changeset
     6
import wx, subprocess
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     7
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
     8
from SVGUIGenerator import *
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
     9
from SVGUIControler import *
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    10
from SVGUIEditor import *
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    11
from FBD_Objects import *
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
    12
from PLCGenerator import PLCGenException
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
    13
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    14
from wxPopen import ProcessLogger
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
    15
from wx.wxsvg import SVGDocument
260
038eff285e00 add docutils in svgui plugins to launch inkscape
greg
parents: 259
diff changeset
    16
from docutils import *
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    17
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    18
[ID_SVGUIEDITORFBDPANEL, 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    19
] = [wx.NewId() for _init_ctrls in range(1)]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    20
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    21
SVGUIFB_Types = {ITEM_CONTAINER : "Container",
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    22
                 ITEM_BUTTON : "Button", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    23
                 ITEM_TEXT : "TextCtrl", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    24
                 ITEM_SCROLLBAR : "ScrollBar", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    25
                 ITEM_ROTATING : "RotatingCtrl", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    26
                 ITEM_NOTEBOOK : "NoteBook", 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    27
                 ITEM_TRANSFORM : "Transform"}
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    28
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    29
class _SVGUIEditor(SVGUIEditor):
37
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
    This Class add IEC specific features to the SVGUIEditor :
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    32
        - FDB preview
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    33
        - FBD begin drag 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    34
    """
137
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_coll_EditorGridSizer_Items(self, parent):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    37
        SVGUIEditor._init_coll_EditorGridSizer_Items(self, parent)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    38
        parent.AddWindow(self.FBDPanel, 0, border=0, flag=wx.GROW)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    39
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    40
    def _init_ctrls(self, prnt):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    41
        SVGUIEditor._init_ctrls(self, prnt, False)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    42
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    43
        self.FBDPanel = wx.Panel(id=ID_SVGUIEDITORFBDPANEL, 
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    44
                  name='FBDPanel', parent=self.EditorPanel, pos=wx.Point(0, 0),
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    45
                  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
    46
        self.FBDPanel.SetBackgroundColour(wx.WHITE)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    47
        self.FBDPanel.Bind(wx.EVT_LEFT_DOWN, self.OnFBDPanelClick)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    48
        self.FBDPanel.Bind(wx.EVT_PAINT, self.OnPaintFBDPanel)
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
        setattr(self.FBDPanel, "GetScaling", lambda: None) 
252
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    51
        setattr(self.FBDPanel, "IsOfType", self.IsOfType) 
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    52
        setattr(self.FBDPanel, "GetBlockType", self.GetBlockType) 
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    53
        
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    54
        self._init_sizers()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    55
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    56
    def __init__(self, parent, controler = None, fileOpen = None):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    57
        SVGUIEditor.__init__(self, parent, controler, fileOpen)
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
        self.FBDBlock = None
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    60
    
252
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    61
    def IsOfType(self, type, reference):
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    62
        return self.Controler.GetPlugRoot().IsOfType(type, reference)
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    63
    
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    64
    def GetBlockType(self, type, inputs = None):
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    65
        return self.Controler.GetPlugRoot().GetBlockType(type, inputs)
5c8167203f6e Bug with FBDPanel fixed
lbessard
parents: 241
diff changeset
    66
    
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    67
    def RefreshView(self, select_id = None):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    68
        SVGUIEditor.RefreshView(self, select_id)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    69
        self.FBDPanel.Refresh()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    70
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    71
    def OnPaintFBDPanel(self,event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    72
        dc = wx.ClientDC(self.FBDPanel)
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    73
        dc.Clear()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    74
        selected = self.GetSelected()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    75
        if selected is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    76
            selected_type = self.Controler.GetElementType(selected)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    77
            if selected_type is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    78
                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
    79
                width, height = self.FBDBlock.GetMinSize()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    80
                self.FBDBlock.SetSize(width,height)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    81
                clientsize = self.FBDPanel.GetClientSize()
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    82
                x = (clientsize.width - width) / 2
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    83
                y = (clientsize.height - height) / 2
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    84
                self.FBDBlock.SetPosition(x, y)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    85
                self.FBDBlock.Draw(dc)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    86
        else:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    87
            self.FBDBlock = None
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    88
        event.Skip()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    89
        
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    90
    def OnFBDPanelClick(self, event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    91
        if self.FBDBlock:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    92
            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
    93
            DropSrc = wx.DropSource(self.FBDPanel)
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    94
            DropSrc.SetData(data)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
    95
            DropSrc.DoDragDrop()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    96
        event.Skip()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    97
    
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    98
    def OnInterfaceTreeItemSelected(self, event):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
    99
        self.FBDPanel.Refresh()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   100
        SVGUIEditor.OnInterfaceTreeItemSelected(self, event)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   101
    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   102
    def OnGenerate(self,event):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   103
        self.SaveProject()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   104
        self.Controler.PlugGenerate_C(sys.path[0],(0,0,4,5),None)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   105
        event.Skip()    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   106
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   107
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   108
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   109
    "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
   110
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   111
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
   112
CPRINTTYPECONVERSION = {"BOOL" : "d", "UINT" : "d", "STRING" : "s", "REAL" : "f"}
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   113
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   114
class RootClass(SVGUIControler):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   115
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   116
    def __init__(self):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   117
        SVGUIControler.__init__(self)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   118
        filepath = os.path.join(self.PlugPath(), "gui.xml")
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   119
        
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   120
        if os.path.isfile(filepath):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   121
            svgfile = os.path.join(self.PlugPath(), "gui.svg")
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   122
            if os.path.isfile(svgfile):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   123
                self.SvgFilepath = svgfile
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   124
            self.OpenXMLFile(filepath)
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   125
        else:
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   126
            self.CreateNewInterface()
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   127
            self.SetFilePath(filepath)
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   128
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   129
    def GetElementIdFromName(self, name):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   130
        element = self.GetElementByName(name)
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   131
        if element is not None:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   132
            return element.getid()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   133
        return None
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   134
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   135
    _View = None
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   136
    def _OpenView(self):
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   137
        if not self._View:
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   138
            def _onclose():
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   139
                self._View = None
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   140
            def _onsave():
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   141
                self.GetPlugRoot().SaveProject()
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   142
            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
   143
            self._View._onclose = _onclose
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   144
            self._View._onsave = _onsave
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   145
            self._View.Show()
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   146
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   147
    def _ImportSVG(self):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   148
        if not self._View:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   149
            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
   150
            if dialog.ShowModal() == wx.ID_OK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   151
                svgpath = dialog.GetPath()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   152
                if os.path.isfile(svgpath):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   153
                    shutil.copy(svgpath, os.path.join(self.PlugPath(), "gui.svg"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   154
                else:
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   155
                    self.logger.write_error("No such SVG file: %s\n"%svgpath)
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   156
            dialog.Destroy()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   157
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   158
    def _ImportXML(self):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   159
        if not self._View:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   160
            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
   161
            if dialog.ShowModal() == wx.ID_OK:
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   162
                xmlpath = dialog.GetPath()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   163
                if os.path.isfile(xmlpath):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   164
                    shutil.copy(xmlpath, os.path.join(self.PlugPath(), "gui.xml"))
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   165
                else:
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   166
                    self.logger.write_error("No such XML file: %s\n"%xmlpath)
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   167
            dialog.Destroy()
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   168
233
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   169
    def _StartInkscape(self):
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   170
        svgfile = os.path.join(self.PlugPath(), "gui.svg")		
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   171
        if not os.path.isfile(svgfile):
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   172
            svgfile = None
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   173
        open_svg(svgfile)
233
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   174
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   175
    PluginMethods = [
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   176
        {"bitmap" : os.path.join("images","HMIEditor"),
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   177
         "name" : "HMI Editor",
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   178
         "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
   179
         "method" : "_OpenView"},
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   180
        {"bitmap" : os.path.join("images","ImportSVG"),
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   181
         "name" : "Import SVG",
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   182
         "tooltip" : "Import SVG",
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   183
         "method" : "_ImportSVG"},
82
d7b4dd1f543f Beremiz layout improved for wx2.8 by inserting all control in TreeCtrl
lbessard
parents: 73
diff changeset
   184
        {"bitmap" : os.path.join("images","ImportDEF"),
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   185
         "name" : "Import XML",
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   186
         "tooltip" : "Import XML",
139
09923f7ee87e fixed typo in svgui.py
greg
parents: 138
diff changeset
   187
         "method" : "_ImportXML"},
233
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   188
         {"bitmap" : os.path.join("images","ImportSVG"),
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   189
         "name" : "Inkscape",
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   190
         "tooltip" : "Create HMI",
95b5aa098c4a add start inkscape methods for svgui plugin
greg
parents: 229
diff changeset
   191
         "method" : "_StartInkscape"},
65
e55d6faee9d1 Adding icons in Beremiz GUI
lbessard
parents: 55
diff changeset
   192
    ]
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   193
    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   194
    def OnPlugSave(self):
198
cf99e75b6dda Bug while while changing name of SVGUI plugin node fixed
lbessard
parents: 192
diff changeset
   195
        self.SaveXMLFile(os.path.join(self.PlugPath(), "gui.xml"))
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   196
        return True
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   197
    
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   198
    def PlugGenerate_C(self, buildpath, locations):
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   199
        progname = "SVGUI_%s"%"_".join(map(str, self.GetCurrentLocation()))
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   200
        
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   201
        doc = SVGDocument(self.GetSVGFilePath())
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   202
        root_element = doc.GetRootElement()
191
5b1fa0e06284 Bug with float window size fixed
lbessard
parents: 189
diff changeset
   203
        window_size = (int(float(root_element.GetAttribute("width"))),
5b1fa0e06284 Bug with float window size fixed
lbessard
parents: 189
diff changeset
   204
                       int(float(root_element.GetAttribute("height"))))
5b1fa0e06284 Bug with float window size fixed
lbessard
parents: 189
diff changeset
   205
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   206
#        svgfilepath = self.GetSVGFilePath()
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   207
#        xmlfilepath = self.GetFilePath()
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   208
#        shutil.copy(svgfilepath, buildpath)
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   209
#        shutil.copy(xmlfilepath, buildpath)
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   210
        
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   211
        SVGFilePath = self.GetSVGFilePath()
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   212
        SVGFileBaseName = os.path.split(SVGFilePath)[1]
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   213
        FilePath = self.GetFilePath()
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   214
        FileBaseName = os.path.split(FilePath)[1]
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   215
        
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   216
        generator = _SVGUICGenerator(self, self.GetElementsByType(), 
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   217
                                     os.path.split(self.GetSVGFilePath())[1], 
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   218
                                     os.path.split(self.GetFilePath())[1], 
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   219
                                     self.GetCurrentLocation())
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   220
        generator.GenerateProgram(window_size, buildpath, progname)
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   221
        Gen_C_file = os.path.join(buildpath, progname+".cpp" )
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   222
        
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   223
        if wx.Platform == '__WXMSW__':
259
f527d1c3f630 changes CXXFLAGS LDFLAGS for svgui plugin on win32 platform
greg
parents: 256
diff changeset
   224
            cxx_flags = "-I..\\lib\\wx\\include\\msw-unicode-release-2.8 -I..\\include\\wx-2.8 -I..\\..\\matiec\\lib -DWXUSINGDLL -D__WXMSW__ -mthreads"
f527d1c3f630 changes CXXFLAGS LDFLAGS for svgui plugin on win32 platform
greg
parents: 256
diff changeset
   225
            libs = "\"..\\lib\\libwxsvg.a\" \"..\\lib\\libwxsvg_agg.a\" \"..\\lib\\libagg.a\" \"..\\lib\\libaggplatformwin32.a\" \"..\\lib\\libaggfontwin32tt.a\" -L..\\lib -mwindows -mthreads -Wl,--subsystem,windows -mwindows -lwx_mswu_richtext-2.8 -lwx_mswu_aui-2.8 -lwx_mswu_xrc-2.8 -lwx_mswu_qa-2.8 -lwx_mswu_html-2.8 -lwx_mswu_adv-2.8 -lwx_mswu_core-2.8 -lwx_baseu_xml-2.8 -lwx_baseu_net-2.8 -lwx_baseu-2.8"
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   226
        else:
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   227
            status, result, err_result = ProcessLogger(self.logger, "wx-config --cxxflags", no_stdout=True).spin()
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   228
            if status:
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   229
                self.logger.write_error("Unable to get wx cxxflags\n")
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   230
            cxx_flags = result.strip() + " -I../matiec/lib"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   231
            
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   232
            status, result, err_result = ProcessLogger(self.logger, "wx-config --libs", no_stdout=True).spin()
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   233
            if status:
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   234
                self.logger.write_error("Unable to get wx libs\n")
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   235
            libs = result.strip() + " -lwxsvg"
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   236
        
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   237
        return [(Gen_C_file, cxx_flags)],libs,True,(SVGFileBaseName, file(SVGFilePath, "rb")), (FileBaseName, file(FilePath, "rb"))
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   238
    
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   239
    def BlockTypesFactory(self):
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   240
        
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   241
        SVGUIBlock_Types = []
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   242
        
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   243
        def GetSVGUIBlockType(type):
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   244
            for category in SVGUIBlock_Types:
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   245
                for blocktype in category["list"]:
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   246
                    if blocktype["name"] == type:
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   247
                        return blocktype
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   248
        setattr(self, "GetSVGUIBlockType", GetSVGUIBlockType)
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   249
        
73
5e1e3d46c0c9 Adding support for execution order code generation
lbessard
parents: 65
diff changeset
   250
        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
   251
            name = block.getinstanceName()
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   252
            block_id = self.GetElementIdFromName(name)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   253
            if block_id == None:
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   254
                raise PLCGenException, "Undefined SVGUI Block \"%s\""%name
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   255
            type = block.gettypeName()
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   256
            block_infos = GetSVGUIBlockType(type)
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   257
            current_location = ".".join(map(str, self.GetCurrentLocation()))
186
ed2a408d79b6 Various bugs fixed
lbessard
parents: 181
diff changeset
   258
            if not generator.ComputedBlocks.get(block, False) and not order:
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   259
                generator.ComputedBlocks[block] = True
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   260
                for num, variable in enumerate(block.inputVariables.getvariable()):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   261
                    connections = variable.connectionPointIn.getconnections()
241
3475e76e0672 Problem with multi-connection on block in LD fixed
lbessard
parents: 240
diff changeset
   262
                    if connections is not None:
3475e76e0672 Problem with multi-connection on block in LD fixed
lbessard
parents: 240
diff changeset
   263
                        input_info = (generator.TagName, "block", block.getlocalId(), "input", num)
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   264
                        parameter = "%sQ%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["inputs"][num][1]], current_location, block_id, num+1)
241
3475e76e0672 Problem with multi-connection on block in LD fixed
lbessard
parents: 240
diff changeset
   265
                        value = generator.ComputeExpression(body, connections)
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   266
                        generator.Program += [(generator.CurrentIndent, ()),
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   267
                                              (parameter, input_info),
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   268
                                              (" := ", ())]
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   269
                        generator.Program += generator.ExtractModifier(variable, value, input_info)
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   270
                        generator.Program += [(";\n", ())]
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   271
            if link:
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   272
                connectionPoint = link.getposition()[-1]
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   273
                for num, variable in enumerate(block.outputVariables.getvariable()):
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   274
                    blockPointx, blockPointy = variable.connectionPointOut.getrelPositionXY()
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   275
                    output_info = (generator.TagName, "block", block.getlocalId(), "output", num)
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   276
                    parameter = "%sI%s%s.%d.%d"%("%", TYPECONVERSION[block_infos["outputs"][num][1]], current_location, block_id, num+1)
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   277
                    if block.getx() + blockPointx == connectionPoint.getx() and block.gety() + blockPointy == connectionPoint.gety():
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   278
                        return generator.ExtractModifier(variable, [(parameter, output_info)], output_info)
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   279
                raise PLCGenException, "No corresponding output variable found on SVGUI Block \"%s\""%name
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   280
            else:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   281
                return None
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   282
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   283
        def initialise_block(type, name, block = None):
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   284
            block_id = self.GetElementIdFromName(name)
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   285
            if block_id == None:
272
9cce83526487 Bug on Exception handling fixed
greg
parents: 260
diff changeset
   286
                raise PLCGenException, "Undefined SVGUI Block \"%s\""%name
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   287
            block_infos = GetSVGUIBlockType(type)
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   288
            current_location = ".".join(map(str, self.GetCurrentLocation()))
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   289
            variables = []
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   290
            if block is not None:
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   291
                input_variables = block.inputVariables.getvariable()
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   292
                output_variables = block.outputVariables.getvariable()
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   293
            else:
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   294
                input_variables = None
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   295
                output_variables = None
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   296
            for num, (input_name, input_type, input_modifier) in enumerate(block_infos["inputs"]):
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   297
                if input_variables is not None and num < len(input_variables):
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   298
                    connections = input_variables[num].connectionPointIn.getconnections()
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   299
                if input_variables is None or connections and len(connections) == 1:
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   300
                    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
   301
            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
   302
                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
   303
            return variables
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   304
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   305
        SVGUIBlock_Types.extend([{"name" : "SVGUI function blocks", "list" :
137
187a4e2412e5 Modifying svgui plugin for following new SVGUIEditor version
lbessard
parents: 105
diff changeset
   306
                [{"name" : "Container", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   307
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   308
                    "outputs" : [],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   309
                    "comment" : "SVGUI Container",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   310
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   311
                {"name" : "Button", "type" : "functionBlock", "extensible" : False, 
186
ed2a408d79b6 Various bugs fixed
lbessard
parents: 181
diff changeset
   312
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("Value","BOOL","none")], 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   313
                    "outputs" : [("State","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   314
                    "comment" : "SVGUI Button",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   315
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   316
                {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   317
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("SetText","STRING","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   318
                    "outputs" : [("Text","STRING","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   319
                    "comment" : "SVGUI Text Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   320
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   321
                {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   322
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("SetThumb","UINT","none"),("SetRange","UINT","none"),("SetPosition","UINT","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   323
                    "outputs" : [("Position","UINT","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   324
                    "comment" : "SVGUI ScrollBar",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   325
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   326
                {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   327
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("SetSelected","BOOL","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   328
                    "outputs" : [("Selected","UINT","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   329
                    "comment" : "SVGUI Notebook",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   330
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   331
                {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   332
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("SetAngle","REAL","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   333
                    "outputs" : [("Angle","REAL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   334
                    "comment" : "SVGUI Rotating Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   335
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   336
                {"name" : "Transform", "type" : "functionBlock", "extensible" : False, 
138
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   337
                    "inputs" : [("Show","BOOL","none"),("Enable","BOOL","none"),("SetX","REAL","none"),("SetY","REAL","none"),("SetXScale","REAL","none"),("SetYScale","REAL","none"),("SetAngle","REAL","none")], 
3a6ebb01760a Changing SVGUI FunctionBlocks interface
lbessard
parents: 137
diff changeset
   338
                    "outputs" : [("X","REAL","none"),("Y","REAL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   339
                    "comment" : "SVGUI Transform",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   340
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   341
               ]}
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   342
        ])
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   343
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   344
        return SVGUIBlock_Types
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   345
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   346
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   347
class _SVGUICGenerator(SVGUICGenerator):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   348
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   349
    def __init__(self, controler, elements, svgfile, xmlfile, current_location):
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   350
        SVGUICGenerator.__init__(self, elements, svgfile, xmlfile)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   351
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   352
        self.CurrentLocation = current_location
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   353
        self.Controler = controler
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   354
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   355
    def GenerateProgramHeadersPublicVars(self):
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   356
        text = """
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   357
    void OnPlcOutEvent(wxEvent& event);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   358
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   359
    void Retrieve();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   360
    void Publish();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   361
    void Initialize();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   362
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   363
#        text += "    void Print();\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   364
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   365
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   366
    def GenerateIECVars(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   367
        text = ""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   368
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   369
            text += "STATE_TYPE out_state_%d;\n"%element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   370
            text += "STATE_TYPE in_state_%d;\n"%element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   371
        text +="\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   372
        current_location = "_".join(map(str, self.CurrentLocation))
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   373
        #Declaration des variables
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   374
        for element in self.Elements:
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   375
            block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)])
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   376
            block_id = element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   377
            for i, input in enumerate(block_infos["inputs"]):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   378
                element_c_type = CTYPECONVERSION[input[1]]
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   379
                variable = "__Q%s%s_%d_%d"%(TYPECONVERSION[input[1]], current_location, block_id, i + 1)
165
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   380
                text += "%s beremiz%s;\n"%(element_c_type, variable)
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   381
                text += "%s* %s = &beremiz%s;\n"%(element_c_type, variable, variable)
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   382
                text += "%s _copy%s;\n"%(element_c_type, variable)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   383
            for i, output in enumerate(block_infos["outputs"]):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   384
                element_c_type = CTYPECONVERSION[output[1]]
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   385
                variable = "__I%s%s_%d_%d"%(TYPECONVERSION[output[1]], current_location, block_id, i + 1)
165
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   386
                text += "%s beremiz%s;\n"%(element_c_type, variable)
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   387
                text += "%s* %s = &beremiz%s;\n"%(element_c_type, variable, variable)
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   388
                text += "%s _copy%s;\n"%(element_c_type, variable)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   389
            text +="\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   390
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   391
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   392
    def GenerateGlobalVarsAndFuncs(self, size):
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   393
        text = """#include "iec_types.h"
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   394
#ifdef __WXMSW__
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   395
#define COMPARE_AND_SWAP_VAL(Destination, comparand, exchange) InterlockedCompareExchange(Destination, exchange, comparand)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   396
#define THREAD_RETURN_TYPE DWORD WINAPI
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   397
#define STATE_TYPE long int
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   398
#else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   399
#define COMPARE_AND_SWAP_VAL(Destination, comparand, exchange) __sync_val_compare_and_swap(Destination, comparand, exchange)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   400
#define THREAD_RETURN_TYPE void*
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   401
#define STATE_TYPE volatile int
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   402
#endif
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   403
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   404
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   405
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   406
        text += self.GenerateIECVars()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   407
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   408
        text += """IMPLEMENT_APP_NO_MAIN(SVGViewApp);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   409
SVGViewApp *myapp = NULL;
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   410
wxSemaphore MyInitSem;
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   411
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   412
#ifdef __WXMSW__
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   413
HANDLE wxMainLoop;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   414
DWORD wxMainLoopId;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   415
#else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   416
pthread_t wxMainLoop;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   417
#endif
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   418
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   419
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   420
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   421
        text += """int myargc = 0;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   422
char** myargv = NULL;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   423
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   424
#define UNCHANGED 1
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   425
#define PLC_BUSY 2
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   426
#define CHANGED 3
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   427
#define GUI_BUSY 4
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   428
#ifdef __WXMSW__
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   429
#else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   430
#endif
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   431
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   432
bool refresh = false;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   433
bool refreshing = false;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   434
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   435
THREAD_RETURN_TYPE InitWxEntry(void* args)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   436
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   437
  wxEntry(myargc,myargv);
240
992ae3f46fa1 fixed : bug when stop plc and previously svguiapp closed
greg
parents: 233
diff changeset
   438
  myapp = NULL;
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   439
  MyInitSem.Post();
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   440
  return 0;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   441
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   442
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   443
"""
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   444
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   445
        text += """
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   446
bool SVGViewApp::OnInit()
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   447
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   448
  #ifndef __WXMSW__
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   449
    setlocale(LC_NUMERIC, "C");
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   450
  #endif
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   451
"""
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   452
        
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   453
        text += """  frame = new MainFrame(NULL, wxT("Program"),wxDefaultPosition, wxSize(%d, %d));
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   454
  frame->Show();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   455
  myapp = this;
189
48ba1ae12ffd Adding support for calculate window size while C generating
lbessard
parents: 186
diff changeset
   456
"""%size
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   457
        text += """  return true;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   458
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   459
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   460
extern "C" {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   461
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   462
int __init_%(location)s(int argc, char** argv)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   463
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   464
  myargc = argc;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   465
  myargv = argv;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   466
#ifdef __WXMSW__
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   467
  wxMainLoop = CreateThread(NULL, 0, InitWxEntry, 0, 0, &wxMainLoopId);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   468
#else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   469
  pthread_create(&wxMainLoop, NULL, InitWxEntry, NULL);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   470
#endif
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   471
  MyInitSem.Wait();
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   472
  return 0;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   473
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   474
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   475
void __cleanup_%(location)s()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   476
{
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   477
  if(myapp){
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   478
      wxCloseEvent event(wxEVT_CLOSE_WINDOW);
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   479
      myapp->frame->AddPendingEvent(event);
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   480
      myapp = NULL;
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   481
  }
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   482
  MyInitSem.Wait();
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   483
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   484
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   485
void __retrieve_%(location)s()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   486
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   487
  if(myapp){
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   488
    myapp->frame->m_svgCtrl->Retrieve();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   489
  }        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   490
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   491
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   492
void __publish_%(location)s()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   493
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   494
  if(myapp){
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   495
    myapp->frame->m_svgCtrl->Publish();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   496
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   497
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   498
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   499
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   500
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   501
IEC_STRING wxStringToIEC_STRING(wxString s)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   502
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   503
  IEC_STRING res = {0,""};
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   504
  int i;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   505
  for(i = 0; i<s.Length() && i<STR_MAX_LEN; i++)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   506
    res.body[i] = s.GetChar(i);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   507
  res.len = i;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   508
  return res;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   509
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   510
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   511
"""%{"location" : "_".join(map(str, self.CurrentLocation))}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   512
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   513
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   514
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   515
    def GenerateProgramEventTable(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   516
        text = """BEGIN_DECLARE_EVENT_TYPES()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   517
DECLARE_LOCAL_EVENT_TYPE( EVT_PLC, wxNewEventType() )
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   518
END_DECLARE_EVENT_TYPES()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   519
         
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   520
DEFINE_LOCAL_EVENT_TYPE( EVT_PLC )
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   521
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   522
"""     
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   523
        #Event Table Declaration
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   524
        text += "BEGIN_EVENT_TABLE(Program, SVGUIWindow)\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   525
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   526
            element_type = GetElementType(element)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   527
            element_name = element.getname()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   528
            if element_type == ITEM_BUTTON:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   529
                text += "  EVT_BUTTON (SVGUIID(\"%s\"), Program::On%sClick)\n"%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   530
            elif element_type in [ITEM_SCROLLBAR, ITEM_ROTATING, ITEM_TRANSFORM]:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   531
                text += "  EVT_COMMAND_SCROLL_THUMBTRACK (SVGUIID(\"%s\"), Program::On%sChanging)\n"%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   532
            elif element_type == ITEM_NOTEBOOK:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   533
                text += "  EVT_NOTEBOOK_PAGE_CHANGED (SVGUIID(\"%s\"), Program::On%sTabChanged)\n"%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   534
        text += "  EVT_CUSTOM(EVT_PLC, wxID_ANY, Program::OnPlcOutEvent)\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   535
        text += "END_EVENT_TABLE()\n\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   536
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   537
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   538
    def GenerateProgramInitFrame(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   539
        text = """MainFrame::MainFrame(wxWindow *parent, const wxString& title, const wxPoint& pos,const wxSize& size, long style): wxFrame(parent, wxID_ANY, title, pos, size, style)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   540
{
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   541
  wxFileName svgfilepath(wxTheApp->argv[1], wxT("%s"));
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   542
  wxFileName xmlfilepath(wxTheApp->argv[1], wxT("%s"));
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   543
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   544
  m_svgCtrl = new Program(this);
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   545
  if (m_svgCtrl->LoadFiles(svgfilepath.GetFullPath(), xmlfilepath.GetFullPath()))
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   546
  {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   547
    Show(true);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   548
    m_svgCtrl->SetFocus();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   549
    m_svgCtrl->SetFitToFrame(true);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   550
    m_svgCtrl->InitScrollBars();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   551
    m_svgCtrl->Initialize();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   552
    m_svgCtrl->Update();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   553
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   554
  else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   555
  {
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   556
    printf("Error while opening SVGUI files\\n");
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   557
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   558
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   559
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   560
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   561
"""%(self.SVGFilePath, self.XMLFilePath)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   562
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   563
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   564
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   565
    def GenerateProgramInitProgram(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   566
        text = "Program::Program(wxWindow* parent):SVGUIWindow(parent)\n{\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   567
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   568
            text += "    out_state_%d = UNCHANGED;\n"%element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   569
            text += "    in_state_%d = UNCHANGED;\n"%element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   570
        text += "}\n\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   571
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   572
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   573
    def GenerateProgramEventFunctions(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   574
        text = ""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   575
        current_location = "_".join(map(str, self.CurrentLocation))
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   576
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   577
            element_type = GetElementType(element)
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   578
            element_lock = """
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   579
  if (COMPARE_AND_SWAP_VAL(&in_state_%d, CHANGED, GUI_BUSY) == CHANGED ||
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   580
      COMPARE_AND_SWAP_VAL(&in_state_%d, UNCHANGED, GUI_BUSY) == UNCHANGED) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   581
"""%(element.getid(), element.getid())
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   582
            element_unlock = """
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   583
    COMPARE_AND_SWAP_VAL(&in_state_%d, GUI_BUSY, CHANGED);
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   584
    event.Skip();
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   585
  }else{
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   586
      /* re post event for idle */
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   587
      AddPendingEvent(event);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   588
  }
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   589
}
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   590
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   591
"""%element.getid()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   592
            element_name = element.getname()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   593
                
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   594
            if element_type == ITEM_BUTTON:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   595
                text += """void Program::On%sClick(wxCommandEvent& event)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   596
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   597
  SVGUIButton* button = (SVGUIButton*)GetElementByName(wxT("%s"));\n"""%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   598
                text += element_lock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   599
                text += "    _copy__IX%s_%d_1 = button->GetToggle();\n"%(current_location, element.getid())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   600
                text += element_unlock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   601
            elif element_type == ITEM_ROTATING:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   602
                text += """void Program::On%sChanging(wxScrollEvent& event)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   603
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   604
  SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementByName(wxT("%s"));
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   605
"""%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   606
                text += element_lock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   607
                text += "    _copy__ID%s_%d_1 = rotating->GetAngle();\n"%(current_location, element.getid())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   608
                text += element_unlock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   609
            elif element_type == ITEM_NOTEBOOK:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   610
                text += """void Program::On%sTabChanged(wxNotebookEvent& event)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   611
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   612
  SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementByName(wxT("%s"));
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   613
"""%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   614
                text += element_lock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   615
                text += "    _copy__IB%s_%d_1 = notebook->GetCurrentPage();\n"%(current_location, element.getid())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   616
                text += element_unlock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   617
            elif element_type == ITEM_TRANSFORM:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   618
                text += """void Program::On%sChanging(wxScrollEvent& event)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   619
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   620
  SVGUITransform* transform = (SVGUITransform*)GetElementByName(wxT("%s"));
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   621
"""%(element_name, element_name)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   622
                text += element_lock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   623
                text += "    _copy__ID%s_%d_1 = transform->GetX();\n"%(current_location, element.getid())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   624
                text += "    _copy__ID%s_%d_2 = transform->GetY();\n"%(current_location, element.getid())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   625
                text += element_unlock
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   626
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   627
        text += "/* OnPlcOutEvent update GUI with provided IEC __Q* PLC output variables */\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   628
        text += """void Program::OnPlcOutEvent(wxEvent& event)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   629
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   630
  SVGUIElement* element;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   631
  
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   632
  refreshing = true;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   633
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   634
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   635
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   636
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   637
            element_type = GetElementType(element)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   638
            texts = {"location" : current_location, "id" : element.getid()}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   639
            
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   640
            text += """  if (COMPARE_AND_SWAP_VAL(&out_state_%(id)d, CHANGED, GUI_BUSY) == CHANGED)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   641
  {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   642
    element = (SVGUIElement*)GetElementById(wxT("%(id)d"));
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   643
            
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   644
    if (_copy__QX%(location)s_%(id)d_1 != element->IsVisible()) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   645
      if (_copy__QX%(location)s_%(id)d_1)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   646
        element->Show();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   647
      else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   648
        element->Hide();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   649
    }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   650
    if (_copy__QX%(location)s_%(id)d_2 != element->IsEnabled()) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   651
      if (_copy__QX%(location)s_%(id)d_2)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   652
        element->Enable();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   653
      else
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   654
        element->Disable();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   655
    }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   656
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   657
            if element_type == ITEM_BUTTON:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   658
                text += """    if (_copy__QX%(location)s_%(id)d_3 != ((SVGUIButton*)element)->GetToggle())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   659
      ((SVGUIButton*)element)->SetToggle(_copy__QX%(location)s_%(id)d_3);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   660
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   661
            elif element_type == ITEM_TEXT:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   662
                text += """    if (((SVGUITextCtrl*)element)->GetValue().compare(_copy__QX%(location)s_%(id)d_3))
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   663
    {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   664
      wxString str = wxString::FromAscii(_copy__QB%(location)s_%(id)d_3);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   665
      ((SVGUITextCtrl*)element)->SetText(str);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   666
    }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   667
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   668
            elif  element_type == ITEM_SCROLLBAR:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   669
                text += """    if (_copy__QW%(location)s_%(id)d_3 != ((SVGUIScrollBar*)element)->GetThumbPosition() ||
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   670
        _copy__QW%(location)s_%(id)d_4 != ((SVGUIScrollBar*)element)->GetThumbSize() ||
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   671
        _copy__QW%(location)s_%(id)d_5 != ((SVGUIScrollBar*)element)->GetRange())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   672
      ((SVGUIScrollBar*)element)->Init_ScrollBar(_copy__QW%(location)s_%(id)d_3, _copy__QW%(location)s_%(id)d_4, _copy__QW%(location)s_%(id)d_5);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   673
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   674
            elif element_type == ITEM_ROTATING:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   675
                text += """    if (_copy__QD%(location)s_%(id)d_3 != ((SVGUIRotatingCtrl*)element)->GetAngle())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   676
      ((SVGUIRotatingCtrl*)element)->SetAngle(_copy__QD%(location)s_%(id)d_3);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   677
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   678
            elif element_type == ITEM_NOTEBOOK:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   679
                text += """    if (_copy__QB%(location)s_%(id)d_3 != ((SVGUINoteBook*)element)->GetCurrentPage())
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   680
      ((SVGUINoteBook*)element)->SetCurrentPage(_copy__QB%(location)s_%(id)d_3);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   681
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   682
            elif element_type == ITEM_TRANSFORM:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   683
                text += """    if (_copy__QD%(location)s_%(id)d_3 != ((SVGUITransform*)element)->GetX() ||
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   684
        _copy__QD%(location)s_%(id)d_4 != ((SVGUITransform*)element)->GetY())
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   685
      ((SVGUITransform*)element)->Move(_copy__QD%(location)s_%(id)d_3, _copy__QD%(location)s_%(id)d_4);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   686
    if (_copy__QD%(location)s_%(id)d_5 != ((SVGUITransform*)element)->GetXScale() ||
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   687
        _copy__QD%(location)s_%(id)d_6 != ((SVGUITransform*)element)->GetYScale())
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   688
      ((SVGUITransform*)element)->Scale(_copy__QD%(location)s_%(id)d_5, _copy__QD%(location)s_%(id)d_6);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   689
    if (_copy__QD%(location)s_%(id)d_7 != ((SVGUITransform*)element)->GetAngle())
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   690
      ((SVGUITransform*)element)->Rotate(_copy__QD%(location)s_%(id)d_7);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   691
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   692
            text += "    COMPARE_AND_SWAP_VAL(&out_state_%(id)d, GUI_BUSY, UNCHANGED);\n  }\n"%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   693
            
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   694
        text += """
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   695
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   696
  refreshing = false;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   697
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   698
  event.Skip();
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   699
}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   700
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   701
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   702
        return text
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   703
    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   704
    def GenerateProgramPrivateFunctions(self):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   705
        current_location = "_".join(map(str, self.CurrentLocation))
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   706
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   707
        text = "void Program::Retrieve()\n{\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   708
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   709
            element_type = GetElementType(element)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   710
            texts = {"location" : current_location, "id" : element.getid()}
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   711
            block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)])
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   712
            if len(block_infos["outputs"]) > 0:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   713
                text += """  if (COMPARE_AND_SWAP_VAL(&in_state_%(id)d, CHANGED, PLC_BUSY) == CHANGED) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   714
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   715
                for i, output in enumerate(block_infos["outputs"]):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   716
                    texts["type"] = TYPECONVERSION[output[1]]
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   717
                    texts["pin"] = i + 1
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   718
                    
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   719
                    variable = "__I%(type)s%(location)s_%(id)d_%(pin)d"%texts
165
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   720
                    text +="    beremiz%s = _copy%s;\n"%(variable, variable)
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   721
                
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   722
                text += """    COMPARE_AND_SWAP_VAL(&in_state_%(id)d, PLC_BUSY, UNCHANGED);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   723
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   724
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   725
        text += "}\n\n" 
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   726
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   727
        text += "void Program::Publish()\n{\n  STATE_TYPE new_state;\n\n"
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   728
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   729
            element_type = GetElementType(element)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   730
            texts = {"location" : current_location, "id" : element.getid()}
201
520d2416ff4d Adding support for highlighing compiling errors into PLCOpenEditor
lbessard
parents: 198
diff changeset
   731
            block_infos = self.Controler.GetSVGUIBlockType(SVGUIFB_Types[GetElementType(element)])
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   732
            
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   733
            text += """  if ((new_state = COMPARE_AND_SWAP_VAL(&out_state_%(id)d, UNCHANGED, PLC_BUSY)) == UNCHANGED ||
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   734
       (new_state = COMPARE_AND_SWAP_VAL(&out_state_%(id)d, CHANGED, PLC_BUSY)) == CHANGED) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   735
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   736
            for i, input in enumerate(block_infos["inputs"]):
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   737
                texts["type"] = TYPECONVERSION[input[1]]
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   738
                texts["pin"] = i + 1
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   739
                variable = "__Q%(type)s%(location)s_%(id)d_%(pin)d"%texts
165
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   740
                text += "    if (_copy%s != beremiz%s) {\n"%(variable, variable)
f9c6c9e36725 Support for extern pointer for located variables
lbessard
parents: 158
diff changeset
   741
                text += "      _copy%s = beremiz%s;\n"%(variable, variable)
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   742
                text += "      new_state = CHANGED;\n    }\n"%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   743
            text += """    COMPARE_AND_SWAP_VAL(&out_state_%(id)d, PLC_BUSY, new_state);
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   744
    refresh |= new_state == CHANGED;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   745
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   746
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   747
        
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   748
        text += """  /* Replace this with determinist signal if called from RT */
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   749
  if (refresh && !refreshing) {
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   750
    wxCommandEvent event( EVT_PLC );
203
cb9901076a21 Added concepts :
etisserant
parents: 201
diff changeset
   751
    AddPendingEvent(event);
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   752
    refresh = false;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   753
  }
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   754
};
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   755
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   756
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   757
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   758
        text += """void Program::Initialize()
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   759
{
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   760
  SVGUIElement* element;
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   761
"""
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   762
        for element in self.Elements:
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   763
            element_type = GetElementType(element)
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   764
            texts = {"location" : current_location, "id" : element.getid()}
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   765
            
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   766
            text += """
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   767
  element = (SVGUIElement*)GetElementById(wxT("%(id)d"));
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   768
  beremiz__QX%(location)s_%(id)d_1 = _copy__QX%(location)s_%(id)d_1 = element->IsVisible();
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   769
  beremiz__QX%(location)s_%(id)d_2 = _copy__QX%(location)s_%(id)d_2 = element->IsEnabled();
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   770
"""%texts
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   771
            if element_type == ITEM_BUTTON:
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   772
                text += "  beremiz__QX%(location)s_%(id)d_3 = _copy__QX%(location)s_%(id)d_3 = ((SVGUIButton*)element)->GetToggle();\n"%texts
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   773
                text += "  beremiz__IX%(location)s_%(id)d_1 = _copy__IX%(location)s_%(id)d_1 = ((SVGUIButton*)element)->GetToggle();\n"%texts
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   774
            elif element_type == ITEM_TEXT:
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   775
                text += "  beremiz__QB%(location)s_%(id)d_3 = _copy__QB%(location)s_%(id)d_3 = ((SVGUITextCtrl*)element)->GetValue();\n"%texts
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   776
                text += "  beremiz__IB%(location)s_%(id)d_1 = _copy__IB%(location)s_%(id)d_1 = ((SVGUITextCtrl*)element)->GetValue();\n"%texts
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   777
            elif element_type == ITEM_SCROLLBAR:
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   778
                text += "  beremiz__QW%(location)s_%(id)d_3 = _copy__QW%(location)s_%(id)d_3 = ((SVGUIScrollBar*)element)->GetThumbSize();\n"%texts
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   779
                text += "  beremiz__QW%(location)s_%(id)d_4 = _copy__QW%(location)s_%(id)d_4 = ((SVGUIScrollBar*)element)->GetRange();\n"%texts
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   780
                text += "  beremiz__QW%(location)s_%(id)d_5 = _copy__QW%(location)s_%(id)d_5 = ((SVGUIScrollBar*)element)->GetThumbPosition();\n"%texts
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   781
                text += "  beremiz__IW%(location)s_%(id)d_1 = _copy__IW%(location)s_%(id)d_1 = ((SVGUIScrollBar*)element)->GetThumbPosition();\n"%texts
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   782
            elif element_type == ITEM_ROTATING:
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   783
                text += "  beremiz__QD%(location)s_%(id)d_3 = _copy__QD%(location)s_%(id)d_3 = ((SVGUIRotatingCtrl*)element)->GetAngle();\n"%texts
186
ed2a408d79b6 Various bugs fixed
lbessard
parents: 181
diff changeset
   784
                text += "  beremiz__ID%(location)s_%(id)d_1 = _copy__ID%(location)s_%(id)d_1 = ((SVGUIRotatingCtrl*)element)->GetAngle();\n"%texts
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   785
            elif element_type == ITEM_NOTEBOOK:
192
f0482f1ae901 Problem with files when launching created program from another directory fixed
lbessard
parents: 191
diff changeset
   786
                text += "  beremiz__QB%(location)s_%(id)d_3 = _copy__QB%(location)s_%(id)d_3 = ((SVGUINoteBook*)element)->GetCurrentPage();\n"%texts
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   787
                text += "  beremiz__IB%(location)s_%(id)d_1 = _copy__IB%(location)s_%(id)d_1 = ((SVGUINoteBook*)element)->GetCurrentPage();\n"%texts
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   788
            elif element_type == ITEM_TRANSFORM:
181
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   789
                text += "  beremiz__QD%(location)s_%(id)d_3 = _copy__QD%(location)s_%(id)d_3 = ((SVGUITransform*)element)->GetX();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   790
                text += "  beremiz__QD%(location)s_%(id)d_4 = _copy__QD%(location)s_%(id)d_4 = ((SVGUITransform*)element)->GetY();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   791
                text += "  beremiz__QD%(location)s_%(id)d_5 = _copy__QD%(location)s_%(id)d_5 = ((SVGUITransform*)element)->GetXScale();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   792
                text += "  beremiz__QD%(location)s_%(id)d_6 = _copy__QD%(location)s_%(id)d_6 = ((SVGUITransform*)element)->GetYScale();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   793
                text += "  beremiz__QD%(location)s_%(id)d_7 = _copy__QD%(location)s_%(id)d_7 = ((SVGUITransform*)element)->GetAngle();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   794
                text += "  beremiz__ID%(location)s_%(id)d_1 = _copy__ID%(location)s_%(id)d_1 = ((SVGUITransform*)element)->GetX();\n"%texts
f01bcc3c9157 Better SCGUITransform value initialization. Added semaphore as a mainloop init barrier
etisserant
parents: 165
diff changeset
   795
                text += "  beremiz__ID%(location)s_%(id)d_2 = _copy__ID%(location)s_%(id)d_2 = ((SVGUITransform*)element)->GetY();\n"%texts
186
ed2a408d79b6 Various bugs fixed
lbessard
parents: 181
diff changeset
   796
        
ed2a408d79b6 Various bugs fixed
lbessard
parents: 181
diff changeset
   797
        text += "\n  MyInitSem.Post();\n}\n\n"
147
ccc5e683583d Improve svgui plugin for following SVGUIEditor modifications
lbessard
parents: 142
diff changeset
   798
        return text