plugins/svgui/svgui.py
author etisserant
Mon, 24 Sep 2007 17:07:42 +0200
changeset 52 eaffcd0a2f03
parent 49 45dc6a944ab6
child 55 9c26e67c041a
permissions -rw-r--r--
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
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
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   122
    PluginMethods = [("HMI Editor",_OpenView), ("Import SVG",_OpenView), ("Import DEF",_OpenView)]
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   123
    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   124
    def OnPlugSave(self):
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   125
        self.SaveXMLFile()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   126
        return True
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   127
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   128
    def GenerateProgramHeadersPublicVars(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   129
        fct = ""
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   130
        fct += "    void OnPlcOutEvent(wxEvent& event);\n\n"
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   131
        fct += "    void Retrive();\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   132
        fct += "    void Publish();\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   133
        fct += "    void Initialize();\n"
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   134
#        fct += "    void Print();\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   135
        return fct
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   136
    
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   137
    def GenerateIECVars(self):
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   138
        text = ""
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   139
        elementsTab = self.GetElementsTab()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   140
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   141
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   142
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   143
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   144
                    element_id = str(info["value"])
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   145
            text += "volatile int out_state_"+element_id+";\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   146
            text += "volatile int in_state_"+element_id+";\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   147
        text +="\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   148
        #Declaration des variables
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   149
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   150
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   151
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   152
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   153
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   154
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   155
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   156
            element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   157
            for input in FbdBlock["inputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   158
                element_type = TYPECONVERSION[input[1]]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   159
                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
   160
                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
   161
                text += element_c_type+" "+line
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   162
                text += element_c_type+" _copy"+line
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   163
                element_num_patte +=1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   164
            element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   165
            for output in FbdBlock["outputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   166
                element_type = TYPECONVERSION[output[1]]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   167
                element_c_type = CTYPECONVERSION[output[1]]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   168
                    
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   169
                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
   170
                text += element_c_type+" "+line
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   171
                text += element_c_type+" _copy"+line
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   172
                element_num_patte +=1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   173
            text +="\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   174
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   175
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   176
    def GenerateGlobalVarsAndFuncs(self):
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   177
        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
   178
        pri_vars = self.GenerateIECVars()
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   179
        if (pri_vars):
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   180
            text += pri_vars
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   181
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   182
        text += "IMPLEMENT_APP_NO_MAIN(SVGViewApp);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   183
        text += "IMPLEMENT_WX_THEME_SUPPORT;\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   184
        text += "SVGViewApp *myapp = NULL;\n"
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   185
        text += "pthread_t wxMainLoop;\n"
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   186
#        text += "pthread_t wxMainLoop,automate;\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   187
        text += "int myargc = 0;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   188
        text += "char** myargv = NULL;\n\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   189
        
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   190
        text += "#define UNCHANGED 1 \n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   191
        text += "#define PLC_BUSY 2 \n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   192
        text += "#define CHANGED 3 \n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   193
        text += "#define GUI_BUSY 4 \n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   194
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   195
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   196
        text += "void* InitWxEntry(void* args)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   197
        text += "  wxEntry(myargc,myargv);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   198
        text += "  return args;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   199
        text += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   200
        
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   201
#        text += "void* SimulAutomate(void* args)\n{\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   202
#        text += "  while(1){\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   203
#        text += "    myapp->frame->m_svgCtrl->IN_"+self.BusNumber+"();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   204
#        text += "    //printf(\"AUTOMATE\\n\");\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   205
#        text += "    myapp->frame->m_svgCtrl->OUT_"+self.BusNumber+"();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   206
#        text += "    sleep(1);\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   207
#        text += "  }\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   208
#        text += "  return args;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   209
#        text += "}\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   210
        
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   211
#        if (self.SVGUIRootElement):
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   212
#            width = self.SVGUIRootElement.GetBBox().GetWidth()
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   213
#            height = self.SVGUIRootElement.GetBBox().GetHeight()
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   214
#        else :
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   215
#            width = 250
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   216
#            height = 350
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   217
        text += "bool SVGViewApp::OnInit()\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   218
        text += "  #ifndef __WXMSW__\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   219
        text += "    setlocale(LC_NUMERIC, \"C\");\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   220
        text += "  #endif\n"
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   221
        #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
   222
        text += "  frame = new MainFrame(NULL, wxT(\"Program\"),wxDefaultPosition, wxDefaultSize);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   223
        text += "  myapp = this;\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   224
#        text += "  pthread_create(&automate, NULL, SimulAutomate, NULL);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   225
        text += "  return true;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   226
        text += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   227
        
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   228
        text += "int __init_"+self.BusNumber+"(int argc, char** argv)\n{\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   229
        text += "  myargc = argc;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   230
        text += "  myargv = argv;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   231
        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
   232
        text += "}\n\n"
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   233
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   234
        text += "int __cleanup_"+self.BusNumber+"()\n{\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   235
        text += "}\n\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   236
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   237
        text += "int __retrive_"+self.BusNumber+"()\n{\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   238
        text += "  if(myapp){"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   239
        text += "    myapp->Retrive()"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   240
        text += "  }"        
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   241
        text += "}\n\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   242
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   243
        text += "int __publish_"+self.BusNumber+"()\n{\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   244
        text += "  if(myapp){"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   245
        text += "    myapp->Publish()"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   246
        text += "  }"        
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   247
        text += "}\n\n"
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   248
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   249
        text += "IEC_STRING wxStringToIEC_STRING(wxString s)\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   250
        text += "{\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   251
        text += "  STRING res = {0,""};\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   252
        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
   253
        text += "    res.body[i] = s.GetChar(i);\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   254
        text += "  res.len = i;\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   255
        text += "  return res;\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   256
        text += "}\n\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   257
        
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   258
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   259
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   260
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   261
    def GenerateProgramEventTable(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   262
        evt = ""        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   263
        elementsTab = self.GetElementsTab()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   264
        #evt += "wxEVT_PLCOUT = wxNewEventType();\n\n";
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   265
        evt += "BEGIN_DECLARE_EVENT_TYPES()\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   266
        evt += "DECLARE_LOCAL_EVENT_TYPE( EVT_PLC, wxNewEventType() )\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   267
        evt += "END_DECLARE_EVENT_TYPES()\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   268
         
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   269
        evt += "DEFINE_LOCAL_EVENT_TYPE( EVT_PLC )\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   270
        #Event Table Declaration
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   271
        evt += "BEGIN_EVENT_TABLE(Program, SVGUIWindow)\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   272
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   273
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   274
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   275
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   276
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   277
                if info["name"] == "name":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   278
                    element_name = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   279
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   280
            if type == "Button":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   281
                evt += "  EVT_BUTTON (SVGUIID(\""+element_id+"\"), Program::On"+element_name+"Click)\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   282
            elif type == "ScrollBar":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   283
                pass
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   284
                #evt += "  EVT_LEFT_UP (Program::OnClick)\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   285
                #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
   286
            elif type == "RotatingCtrl":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   287
                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
   288
            elif type == "NoteBook":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   289
                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
   290
            elif type == "Container" or type == "Transform":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   291
                evt += "  EVT_PAINT(Program::On"+element_name+"Paint)\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   292
        evt += "  EVT_LEFT_UP (Program::OnClick)\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   293
        evt += "  EVT_CUSTOM( EVT_PLC, wxID_ANY, Program::OnPlcOutEvent )\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   294
        evt += "END_EVENT_TABLE()\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   295
        return evt
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   296
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   297
    def GenerateProgramInitFrame(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   298
        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
   299
        text += "  m_svgCtrl = new Program(this);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   300
        text += "  if (m_svgCtrl->LoadFiles(wxT(\""+self.SvgFilepath+"\"), wxT(\""+self.filepath+"\")))\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   301
        text += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   302
        text += "    Show(true);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   303
        text += "    m_svgCtrl->SetFocus();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   304
        text += "    m_svgCtrl->SetFitToFrame(true);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   305
        text += "    m_svgCtrl->RefreshScale();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   306
        text += "    m_svgCtrl->InitScrollBars();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   307
        text += "    m_svgCtrl->Initialize();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   308
        text += "    m_svgCtrl->Update();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   309
        text += "    //m_svgCtrl->Print();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   310
        text += "  }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   311
        text += "  else\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   312
        text += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   313
        text += "    printf(\"Error while opening files\\n\");\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   314
        text += "    exit(0);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   315
        text += "  }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   316
        text += "}\n\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   317
        return text
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   318
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   319
    def GenerateProgramInitProgram(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   320
        elementsTab = self.GetElementsTab()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   321
        text = "Program::Program(wxWindow* parent):SVGUIWindow(parent)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   322
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   323
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   324
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   325
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   326
                    element_id = str(info["value"])
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   327
            text += "    out_state_"+element_id+" = UNCHANGED;\n"
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   328
            text += "    in_state_"+element_id+" = UNCHANGED;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   329
        text += "}\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 GenerateProgramEventFunctions(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   333
        fct=""
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   334
        elementsTab = self.GetElementsTab()
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
                    _lock   = "  in_state_"+element_id+" = GUI_BUSY;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   341
                    _unlock = "  in_state_"+element_id+" = CHANGED;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   342
                if info["name"] == "name":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   343
                    element_name = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   344
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   345
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   346
            if type == "Button":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   347
                fct += "void Program::On"+element_name+"Click(wxCommandEvent& event)\n{\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   348
                fct += _lock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   349
                element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   350
                for output in FbdBlock["outputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   351
                    element_type = TYPECONVERSION[output[1]]
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   352
                    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
   353
                    element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   354
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   355
                fct += "  event.Skip();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   356
                fct += "}\n\n"               
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   357
                
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   358
            elif type == "RotatingCtrl":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   359
                fct += "void Program::On"+element_name+"Changed(wxScrollEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   360
                fct += "  SVGUIRotatingCtrl* rotating = (SVGUIRotatingCtrl*)GetElementById(wxT(\""+element_id+"\"));\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   361
                fct += "  rotating->SendScrollEvent(event);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   362
                fct += "  double angle = rotating->GetAngle();\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   363
                fct += _lock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   364
                element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   365
                for output in FbdBlock["outputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   366
                    element_type = TYPECONVERSION[output[1]]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   367
                    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   368
                    if element_num_patte == 1:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   369
                        value = "angle"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   370
                    elif element_num_patte == 2:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   371
                        value = "true"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   372
                    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
   373
                    element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   374
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   375
                fct += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   376
            elif type == "NoteBook":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   377
                fct += "void Program::On"+element_name+"TabChanged(wxNotebookEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   378
                fct += "  SVGUINoteBook* notebook = (SVGUINoteBook*)GetElementById(wxT(\""+element_id+"\"));\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   379
                fct += "  notebook->SendNotebookEvent(event);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   380
                fct += "  unsigned int selected = notebook->GetCurrentPage();\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   381
                fct += _lock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   382
                element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   383
                for output in FbdBlock["outputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   384
                    element_type = TYPECONVERSION[output[1]]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   385
                    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   386
                    if element_num_patte == 1:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   387
                        value = "selected"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   388
                    elif element_num_patte == 2:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   389
                        value = "true"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   390
                    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
   391
                    element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   392
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   393
                fct += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   394
            elif type == "Transform":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   395
                fct += "void Program::On"+element_name+"Paint(wxPaintEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   396
                fct += "  SVGUITransform* transform = (SVGUITransform*)GetElementById(wxT(\""+element_id+"\"));\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   397
                fct += _lock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   398
                element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   399
                for output in FbdBlock["outputs"]:                    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   400
                    if element_num_patte == 1:
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   401
                        fct += "  if (transform->GetX() != _copy__ID"+self.BusNumber+"_"+element_id+"_1)\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   402
                        fct += "  {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   403
                        fct += "    _copy__ID"+self.BusNumber+"_"+element_id+"_1 = transform->GetX();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   404
                        fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   405
                        fct += "  }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   406
                    elif element_num_patte == 2:
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   407
                        fct += "  if (transform->GetY() != _copy__ID"+self.BusNumber+"_"+element_id+"_2)\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   408
                        fct += "  {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   409
                        fct += "    _copy__ID"+self.BusNumber+"_"+element_id+"_2 = transform->GetY();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   410
                        fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   411
                        fct += "  }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   412
                    elif element_num_patte == 3:
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   413
                        fct += "  if (transform->GetXScale() != _copy__ID"+self.BusNumber+"_"+element_id+"_3)\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   414
                        fct += "  {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   415
                        fct += "    _copy__ID"+self.BusNumber+"_"+element_id+"_3 = transform->GetXScale();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   416
                        fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   417
                        fct += "  }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   418
                    elif element_num_patte == 4:
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   419
                        fct += "  if (transform->GetYScale() != _copy__ID"+self.BusNumber+"_"+element_id+"_4)\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   420
                        fct += "  {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   421
                        fct += "    _copy__ID"+self.BusNumber+"_"+element_id+"_4 = transform->GetYScale();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   422
                        fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   423
                        fct += "  }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   424
                    elif element_num_patte == 5:
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   425
                        fct += "  if (transform->GetAngle() != _copy__ID"+self.BusNumber+"_"+element_id+"_5)\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   426
                        fct += "  {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   427
                        fct += "    _copy__ID"+self.BusNumber+"_"+element_id+"_5 = transform->GetAngle();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   428
                        fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   429
                        fct += "  }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   430
                    element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   431
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   432
                fct += "  event.Skip();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   433
                fct += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   434
            elif type == "Container":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   435
                fct += "void Program::On"+element_name+"Paint(wxPaintEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   436
                fct += "  SVGUIContainer* container = (SVGUIContainer*)GetElementById(wxT(\""+element_id+"\"));\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   437
                fct += "  bool isvisible = container->IsVisible();\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   438
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   439
                fct += "  if (isvisible != _copy__IX"+self.BusNumber+"_"+element_id+"_1)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   440
                fct += "  {\n"
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   441
                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
   442
                fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   443
                fct += "  }\n"
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
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   448
        fct += "void Program::OnChar(wxKeyEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   449
        fct += "  SVGUIContainer* container = GetSVGUIRootElement();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   450
        fct += "  if (container->GetFocusedElementName() == wxT(\"TextCtrl\"))\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   451
        fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   452
        fct += "    wxString focusedId = container->GetFocusedElement();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   453
        fct += "    SVGUITextCtrl* text = (SVGUITextCtrl*)GetElementById(container->GetFocusedElement());\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   454
        fct += "    text->SendKeyEvent(event);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   455
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   456
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   457
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   458
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   459
                    element_id = str(info["value"])
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   460
                    _lock   = "      in_state_"+element_id+" = GUI_BUSY;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   461
                    _unlock = "      in_state_"+element_id+" = CHANGED;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   462
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   463
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   464
            if type == "TextCtrl":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   465
                fct += "    if (focusedId == wxT(\""+element_id+"\"))\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   466
                fct += "    {\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   467
                fct += _lock
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   468
                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
   469
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   470
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   471
                fct += "    }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   472
        fct += "  }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   473
        fct += "}\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   474
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   475
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   476
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   477
        fct += "void Program::OnClick(wxMouseEvent& event)\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   478
        fct += "  SVGUIContainer* container = GetSVGUIRootElement();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   479
        fct += "  if (container->GetFocusedElementName() == wxT(\"ScrollBar\"))\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   480
        fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   481
        fct += "    wxString focusedId = container->GetFocusedElement();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   482
        fct += "    SVGUIScrollBar* scrollbar = (SVGUIScrollBar*)GetElementById(focusedId);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   483
        fct += "    scrollbar->SendMouseEvent(event);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   484
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   485
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   486
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   487
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   488
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   489
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   490
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   491
            if type == "ScrollBar":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   492
                fct += "    if (focusedId == wxT(\""+element_id+"\"))\n"
37
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 += "      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
   495
                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
   496
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   497
                fct += "    }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   498
        fct += "  }\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   499
        fct += "  event.Skip();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   500
        fct += "}\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   501
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   502
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   503
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   504
        
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   505
        fct += "/* OnPlcOutEvent updatde GUI with provided IEC __Q* PLC output variables */\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   506
        fct += "void Program::OnPlcOutEvent(wxEvent& event)\n{\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   507
        for element in elementsTab:
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   508
            infos = element.getElementAttributes()
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   509
            for info in infos:
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   510
                if info["name"] == "id":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   511
                    element_id = str(info["value"])
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   512
            _lock =   " if (__sync_val_compare_and_swap (&out_state_"+element_id+", CHANGED, GUI_BUSY) == CHANGED)"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   513
            _lock +=  " {\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   514
            _unlock = "  __sync_val_compare_and_swap (&out_state_"+element_id+", GUI_BUSY, UNCHANGED);\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   515
            _unlock +=" }\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   516
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   517
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   518
            if type == "Button":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   519
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   520
                fct += "  if (_copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   521
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   522
                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
   523
                fct += "    if (_copy__QX"+self.BusNumber+"_"+element_id+"_1)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   524
                fct += "      button->Show();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   525
                fct += "    else\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   526
                fct += "      button->Hide();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   527
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   528
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   529
            elif type == "Container":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   530
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   531
                fct += "  if (_copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   532
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   533
                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
   534
                fct += "    if (_copy__QX"+self.BusNumber+"_"+element_id+"_1)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   535
                fct += "      container->Show();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   536
                fct += "    else\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   537
                fct += "      container->Hide();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   538
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   539
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   540
            elif type == "TextCtrl":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   541
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   542
                fct += "  if (_copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   543
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   544
                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
   545
                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
   546
                fct += "    text->SetText(str);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   547
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   548
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   549
            elif type == "ScrollBar":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   550
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   551
                fct += "  if (_copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   552
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   553
                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
   554
                fct += "    scrollbar->SetThumbPosition(_copy__QW"+self.BusNumber+"_"+element_id+"_1);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   555
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   556
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   557
            elif type == "RotatingCtrl":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   558
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   559
                fct += "  if (_copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   560
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   561
                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
   562
                fct += "    rotating->SetAngle(_copy__QD"+self.BusNumber+"_"+element_id+"_1);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   563
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   564
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   565
            elif type == "NoteBook":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   566
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   567
                fct += "  if (copy__QX"+self.BusNumber+"_"+element_id+"_2)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   568
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   569
                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
   570
                fct += "    notebook->SetCurrentPage(_copy__QB"+self.BusNumber+"_"+element_id+"_1);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   571
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   572
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   573
            elif type == "Transform":
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   574
                fct += _lock
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   575
                fct += "  if (copy__QX"+self.BusNumber+"_"+element_id+"_6)\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   576
                fct += "  {\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   577
                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
   578
                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
   579
                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
   580
                fct += "    transform->Rotate(_copy__QD"+self.BusNumber+"_"+element_id+"_5);\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   581
                fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   582
                fct += _unlock
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   583
        fct += "  Update_Elements();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   584
        fct += "  Refresh();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   585
        fct += "  event.Skip();\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   586
        fct += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   587
        return fct
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   588
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   589
    def GenerateProgramPrivateFunctions(self):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   590
        elementsTab = self.GetElementsTab()
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   591
        fct = "void Program::Retrive()\n{\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   592
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   593
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   594
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   595
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   596
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   597
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   598
            FbdBlock = self.GetBlockType(type)
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   599
            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
   600
            fct += "       __sync_val_compare_and_swap (&out_state_"+element_id+", CHANGED, PLC_BUSY) == CHANGED){\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   601
            fct += "    bool diff = False;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   602
            element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   603
            for input in FbdBlock["inputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   604
                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
   605
                var = "__Q"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   606
                fct +="    diff |= _copy"+var+ " != "+var+";\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   607
                fct +="    _copy"+var+ " = "+var+";\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   608
                element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   609
            fct += "    if(diff) out_state_"+element_id+" = CHANGED;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   610
            fct += "  }\n"
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   611
        fct +="  /*Replace this with determinist signal if called from RT*/;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   612
        fct +="  wxCommandEvent event( EVT_PLC );\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   613
        fct +="  ProcessEvent(event);\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   614
        fct +="};\n\n" 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   615
        
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   616
        fct += "void Program::Publish()\n{\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   617
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   618
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   619
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   620
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   621
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   622
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   623
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   624
            FbdBlock = self.GetBlockType(type)
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   625
            fct += "  do{\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   626
            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
   627
            element_num_patte = 1
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   628
            for output in FbdBlock["outputs"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   629
                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
   630
                var = "__I"+element_type+self.BusNumber+"_"+element_id+"_"+str(element_num_patte)
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   631
                fct +="      "+var+ " = _copy"+var+";\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   632
                element_num_patte +=1
39
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   633
            fct += "      /* reset change status pin */\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   634
            if type == "Button":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   635
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   636
            elif type == "Container":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   637
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   638
            elif type == "TextCtrl":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   639
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   640
            elif type == "ScrollBar":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   641
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   642
            elif type == "RotatingCtrl":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   643
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   644
            elif type == "NoteBook":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   645
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_2 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   646
            elif type == "Transform":
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   647
                fct += "      _copy__IX"+self.BusNumber+"_"+element_id+"_6 = false;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   648
            fct += "    }else{\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   649
            fct += "      break;\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   650
            fct += "    }\n"
243ff39fef11 Improoved SVGUI support
etisserant
parents: 38
diff changeset
   651
            #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
   652
            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
   653
        fct +="};\n\n" 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   654
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   655
        fct += "void Program::Initialize()\n{\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   656
        button = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   657
        container = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   658
        textctrl = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   659
        scrollbar = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   660
        rotatingctrl = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   661
        notebook = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   662
        transform = False
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   663
        for element in elementsTab:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   664
            infos = element.getElementAttributes()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   665
            for info in infos:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   666
                if info["name"] == "id":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   667
                    element_id = str(info["value"])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   668
            type = element.GetElementInfos()["type"]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   669
            FbdBlock = self.GetBlockType(type)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   670
            if type == "Button":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   671
                if (not button):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   672
                    fct += "  SVGUIButton* button;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   673
                fct += "  button = (SVGUIButton*)GetElementById(wxT(\""+element_id+"\"));\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   674
                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
   675
                fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_1 = true;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   676
                fct += "  else\n"
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   677
                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
   678
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   679
                button = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   680
            elif type == "Container":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   681
                if (not container):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   682
                    fct += "  SVGUIContainer* container;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   683
                fct += "  container = (SVGUIContainer*)GetElementById(wxT(\""+element_id+"\"));\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   684
                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
   685
                fct += "    _copy__IX"+self.BusNumber+"_"+element_id+"_1 = true;\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   686
                fct += "  else\n"
38
8cb20bc13a91 SVGUI's DefEditor now runs and generate C code. Swapped __I with __Q
etisserant
parents: 37
diff changeset
   687
                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
   688
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   689
                container = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   690
            elif type == "TextCtrl":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   691
                if (not textctrl):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   692
                    fct += "  SVGUITextCtrl* text;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   693
                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
   694
                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
   695
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   696
                textctrl = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   697
            elif type == "ScrollBar":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   698
                if (not scrollbar):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   699
                    fct += "  SVGUIScrollBar* scrollbar;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   700
                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
   701
                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
   702
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   703
                scrollbar = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   704
            elif type == "RotatingCtrl":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   705
                if (not rotatingctrl):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   706
                    fct += "  SVGUIRotatingCtrl* rotating;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   707
                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
   708
                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
   709
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   710
                rotatingctrl = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   711
            elif type == "NoteBook":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   712
                if (not notebook):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   713
                    fct += "  SVGUINoteBook* notebook;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   714
                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
   715
                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
   716
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_2 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   717
                notebook = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   718
            elif type == "Transform":
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   719
                if (not transform):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   720
                    fct += "  SVGUITransform* transform;\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   721
                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
   722
                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
   723
                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
   724
                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
   725
                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
   726
                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
   727
                fct += "  _copy__IX"+self.BusNumber+"_"+element_id+"_6 = true;\n\n"
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   728
                transform = True
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   729
        fct += "}\n\n"
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   730
        
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   731
        #DEBUG Fonction d'affichage
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   732
#        fct += "void Program::Print()\n{\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   733
#        for element in elementsTab:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   734
#            infos = element.getElementAttributes()
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   735
#            for info in infos:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   736
#                if info["name"] == "id":
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   737
#                    element_id = str(info["value"])
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   738
#            type = element.GetElementInfos()["type"]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   739
#            FbdBlock = self.GetBlockType(type)
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   740
#            element_num_patte = 1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   741
#            for input in FbdBlock["inputs"]:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   742
#                element_type = TYPECONVERSION[input[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   743
#                c_type = CPRINTTYPECONVERSION[input[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   744
#                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
   745
#                fct +="  printf(\""+var+": %"+c_type+"\\n\","+var+");\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   746
#                element_num_patte +=1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   747
#            element_num_patte = 1
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   748
#            for output in FbdBlock["outputs"]:
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   749
#                element_type = TYPECONVERSION[output[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   750
#                c_type = CPRINTTYPECONVERSION[output[1]]
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   751
#                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
   752
#                fct +="  printf(\""+var+": %"+c_type+"\\n\","+var+");\n"
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   753
#                element_num_patte +=1
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   754
        #fct +="    wxPostEvent(Program,wxEVT_PLCOUT);\n"
44
1f5407c0263f Various changes to make SVGUI plugin generated code eventually compile
etisserant
parents: 43
diff changeset
   755
#        fct +="};\n\n"    
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   756
        return fct
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   757
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   758
    def PlugGenerate_C(self, buildpath, locations, logger):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   759
        current_location = self.GetCurrentLocation()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   760
        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
   761
        progname = "SVGUI_" + self.BusNumber
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   762
        self.GenerateProgram(buildpath, progname)
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   763
        Gen_C_file = os.path.join(buildpath, progname+".cpp" )
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   764
        return [(Gen_C_file,"")],""
13
f1f0edbeb313 More precise design for plugins.... to be continued...
etisserant
parents: 12
diff changeset
   765
    
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   766
    def BlockTypesFactory(self):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   767
        def generate_svgui_block(generator, block, body, link):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   768
            name = block.getInstanceName()
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   769
            block_id = self.GetElementIdFromName(name)
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   770
            if block_id == None:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   771
                raise ValueError, "No corresponding block found"
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   772
            type = block.getTypeName()
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   773
            block_infos = self.GetBlockType(type)
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   774
            current_location = ".".join(map(str, self.GetCurrentLocation()))
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   775
            if not generator.ComputedBlocks.get(name, False):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   776
                for num, variable in enumerate(block.inputVariables.getVariable()):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   777
                    connections = variable.connectionPointIn.getConnections()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   778
                    if connections and len(connections) == 1:
47
fd45c291fed0 PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents: 44
diff changeset
   779
                        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
   780
                        value = generator.ComputeFBDExpression(body, connections[0])
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   781
                        generator.Program += ("  %s := %s;\n"%(parameter, generator.ExtractModifier(variable, value)))
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   782
                generator.ComputedBlocks[name] = True
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   783
            if link:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   784
                connectionPoint = link.getPosition()[-1]
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   785
                for num, variable in enumerate(block.outputVariables.getVariable()):
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   786
                    blockPointx, blockPointy = variable.connectionPointOut.getRelPosition()
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   787
                    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
   788
                        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
   789
                raise ValueError, "No output variable found"
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   790
            else:
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   791
                return None
11
75ae893d5eed Adding plugin support in Beremiz
lbessard
parents:
diff changeset
   792
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   793
        def initialise_block(type, name):
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   794
            block_id = self.GetElementIdFromName(name)
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   795
            if block_id == None:
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   796
                raise ValueError, "No corresponding block found"
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   797
            block_infos = self.GetBlockType(type)
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   798
            current_location = ".".join(map(str, self.GetCurrentLocation()))
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   799
            variables = []
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   800
            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
   801
                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
   802
            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
   803
                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
   804
            return variables
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   805
12
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   806
        return [{"name" : "SVGUI function blocks", "list" :
a1f9e514f708 plugin framework organization being defined
etisserant
parents: 11
diff changeset
   807
           [{"name" : "Container", "type" : "functionBlock", "extensible" : False, 
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   808
                    "inputs" : [("Show","BOOL","none"),("Set State","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   809
                    "outputs" : [("Show","BOOL","none"),("State Changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   810
                    "comment" : "SVGUI Container",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   811
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   812
                {"name" : "Button", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   813
                    "inputs" : [("Show","BOOL","none"),("Toggle","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   814
                    "outputs" : [("Visible","BOOL","none"),("State","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   815
                    "comment" : "SVGUI Button",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   816
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   817
                {"name" : "TextCtrl", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   818
                    "inputs" : [("Text","STRING","none"),("Set Text","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   819
                    "outputs" : [("Text","STRING","none"),("Text Changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   820
                    "comment" : "SVGUI Text Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   821
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   822
                {"name" : "ScrollBar", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   823
                    "inputs" : [("Position","UINT","none"),("Set Position","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   824
                    "outputs" : [("Position","UINT","none"),("Position Changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   825
                    "comment" : "SVGUI ScrollBar",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   826
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   827
                {"name" : "NoteBook", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   828
                    "inputs" : [("Selected","UINT","none"),("Set Selected","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   829
                    "outputs" : [("Selected","UINT","none"),("Selected Changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   830
                    "comment" : "SVGUI Notebook",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   831
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   832
                {"name" : "RotatingCtrl", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   833
                    "inputs" : [("Angle","REAL","none"),("Set Angle","BOOL","none")], 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   834
                    "outputs" : [("Angle","REAL","none"),("Angle changed","BOOL","none")],
42
2bff00eb6cd0 Correct bugs on svgui plugin code generation
lbessard
parents: 39
diff changeset
   835
                    "comment" : "SVGUI Rotating Control",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   836
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   837
                {"name" : "Transform", "type" : "functionBlock", "extensible" : False, 
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   838
                    "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
   839
                    "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
   840
                    "comment" : "SVGUI Transform",
43
937640beb464 Adding support for svgui block code generation
lbessard
parents: 42
diff changeset
   841
                    "generate" : generate_svgui_block, "initialise" : initialise_block},
37
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   842
               ]}
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   843
        ]
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   844
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   845
    def GetBlockType(self,type):
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   846
        for category in self.BlockTypesFactory():
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   847
            for blocktype in category["list"]:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   848
                if blocktype["name"] == type:
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   849
                    return blocktype
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   850
        return None
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   851
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   852
#DEBUG
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   853
if __name__ == '__main__':
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   854
    app = wxPySimpleApp()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   855
    wxInitAllImageHandlers()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   856
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   857
    # Install a exception handle for bug reports
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   858
    #wxAddExceptHook(os.getcwd(),__version__)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   859
    
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   860
    cont = RootClass(sys.path[0])
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   861
    frame = _EditorFramePlug(cont)
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   862
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   863
    frame.Show()
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   864
    app.MainLoop()
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
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   867
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   868
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   869
625f52bba682 Primary svgui plugin inherited - broken
etisserant
parents: 20
diff changeset
   870