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