CodeFileTreeNode.py
author Laurent Bessard
Wed, 08 May 2013 18:33:49 +0200
changeset 1095 a73fde048749
parent 1061 c_ext/c_ext.py@02f371f3e063
child 1096 c9ace6a881c9
permissions -rw-r--r--
Move C_ext file for merging with py_ext
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
     1
import os
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
     2
from xml.dom import minidom
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
     3
import cPickle
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
     4
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
     5
from xmlclass import *
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
     6
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
     7
from CFileEditor import CFileEditor
729
25054c592dc4 refactoring - c_ext stripped first stage
Edouard Tisserant
parents: 725
diff changeset
     8
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT 
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 610
diff changeset
     9
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 610
diff changeset
    10
CFileClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "cext_xsd.xsd"))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    11
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    12
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    13
    "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", "REAL" : "D", "LREAL" : "L",
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    14
    "STRING" : "B", "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L", "WSTRING" : "W"}
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    15
729
25054c592dc4 refactoring - c_ext stripped first stage
Edouard Tisserant
parents: 725
diff changeset
    16
class CFile:
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    17
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    18
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    19
      <xsd:element name="CExtension">
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    20
        <xsd:complexType>
45
00acf2162135 Now, C extension plugin do handle multiple files
etisserant
parents: 31
diff changeset
    21
          <xsd:attribute name="CFLAGS" type="xsd:string" use="required"/>
00acf2162135 Now, C extension plugin do handle multiple files
etisserant
parents: 31
diff changeset
    22
          <xsd:attribute name="LDFLAGS" type="xsd:string" use="required"/>
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    23
        </xsd:complexType>
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    24
      </xsd:element>
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    25
    </xsd:schema>
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    26
    """
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 651
diff changeset
    27
    EditorType = CFileEditor
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 651
diff changeset
    28
    
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
    29
    def __init__(self):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    30
        filepath = self.CFileName()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    31
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    32
        self.CFile = CFileClasses["CFile"]()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    33
        if os.path.isfile(filepath):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    34
            xmlfile = open(filepath, 'r')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    35
            tree = minidom.parse(xmlfile)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    36
            xmlfile.close()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    37
            
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    38
            for child in tree.childNodes:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    39
                if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "CFile":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    40
                    self.CFile.loadXMLTree(child, ["xmlns", "xmlns:xsi", "xsi:schemaLocation"])
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
    41
                    self.CreateCFileBuffer(True)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    42
        else:
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
    43
            self.CreateCFileBuffer(False)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    44
            self.OnCTNSave()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    45
781
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
    46
    def GetIconName(self):
cdc6393705ce Adding support using plcopeneditor bitmap library for icon request
laurent
parents: 742
diff changeset
    47
        return "Cfile"
738
413946c04c87 refactoring
laurent
parents: 734
diff changeset
    48
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    49
    def CFileName(self):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    50
        return os.path.join(self.CTNPath(), "cfile.xml")
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    51
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    52
    def GetBaseTypes(self):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    53
        return self.GetCTRoot().GetBaseTypes()
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    54
610
00df5b1db283 Disabling definition of enumerated and structure variables for interfacing with PLC in c_ext plug-in
laurent
parents: 603
diff changeset
    55
    def GetDataTypes(self, basetypes = False, only_locatables = False):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    56
        return self.GetCTRoot().GetDataTypes(basetypes=basetypes, only_locatables=only_locatables)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    57
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    58
    def GetSizeOfType(self, type):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    59
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    60
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    61
    def SetVariables(self, variables):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    62
        self.CFile.variables.setvariable([])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    63
        for var in variables:
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    64
            variable = CFileClasses["variables_variable"]()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    65
            variable.setname(var["Name"])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    66
            variable.settype(var["Type"])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    67
            variable.setclass(var["Class"])
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    68
            self.CFile.variables.appendvariable(variable)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    69
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    70
    def GetVariables(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    71
        datas = []
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    72
        for var in self.CFile.variables.getvariable():
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    73
            datas.append({"Name" : var.getname(), "Type" : var.gettype(), "Class" : var.getclass()})
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    74
        return datas
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    75
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    76
    def SetPartText(self, name, text):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    77
        if name == "Includes":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    78
            self.CFile.includes.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    79
        elif name == "Globals":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    80
            self.CFile.globals.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    81
        elif name == "Init":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    82
            self.CFile.initFunction.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    83
        elif name == "CleanUp":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    84
            self.CFile.cleanUpFunction.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    85
        elif name == "Retrieve":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    86
            self.CFile.retrieveFunction.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    87
        elif name == "Publish":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    88
            self.CFile.publishFunction.settext(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    89
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    90
    def GetPartText(self, name):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    91
        if name == "Includes":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    92
            return self.CFile.includes.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    93
        elif name == "Globals":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    94
            return self.CFile.globals.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    95
        elif name == "Init":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    96
            return self.CFile.initFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    97
        elif name == "CleanUp":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    98
            return self.CFile.cleanUpFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
    99
        elif name == "Retrieve":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   100
            return self.CFile.retrieveFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   101
        elif name == "Publish":
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   102
            return self.CFile.publishFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   103
        return ""
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 610
diff changeset
   104
                
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   105
    def CTNTestModified(self):
630
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 610
diff changeset
   106
        return self.ChangesToSave or not self.CFileIsSaved()    
91b2ae63ea3d Including external tools for editing plugin informations into Beremiz window
laurent
parents: 610
diff changeset
   107
1061
02f371f3e063 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 953
diff changeset
   108
    def OnCTNSave(self, from_project_path=None):
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   109
        filepath = self.CFileName()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   110
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   111
        text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   112
        extras = {"xmlns":"http://www.w3.org/2001/XMLSchema",
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   113
                  "xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   114
                  "xsi:schemaLocation" : "cext_xsd.xsd"}
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   115
        text += self.CFile.generateXMLText("CFile", 0, extras)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   116
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   117
        xmlfile = open(filepath,"w")
430
5981ad8547f5 Allowing unicode characters to be used in comments
laurent
parents: 427
diff changeset
   118
        xmlfile.write(text.encode("utf-8"))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   119
        xmlfile.close()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   120
        
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   121
        self.MarkCFileAsSaved()
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   122
        return True
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   123
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   124
    def CTNGlobalInstances(self):
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   125
        current_location = self.GetCurrentLocation()
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   126
        return [("%s_%s" % (
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   127
                    variable.getname(),"_".join(map(str, current_location))),
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   128
                 variable.gettype())
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   129
                for variable in self.CFile.variables.variable]
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   130
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   131
    def CTNGenerate_C(self, buildpath, locations):
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   132
        """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   133
        Generate C code
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 675
diff changeset
   134
        @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
31
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   135
        @param locations: List of complete variables locations \
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   136
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   137
            "NAME" : name of the variable (generally "__IW0_1_2" style)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   138
            "DIR" : direction "Q","I" or "M"
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   139
            "SIZE" : size "X", "B", "W", "D", "L"
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   140
            "LOC" : tuple of interger for IEC location (0,1,2,...)
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   141
            }, ...]
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   142
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   143
        """
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   144
        current_location = self.GetCurrentLocation()
33b38700d0db added basic C Code extention plugin
etisserant
parents:
diff changeset
   145
        # define a unique name for the generated C file
401
8106a853a7c7 Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents: 361
diff changeset
   146
        location_str = "_".join(map(str, current_location))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   147
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 675
diff changeset
   148
        text = "/* Code generated by Beremiz c_ext confnode */\n\n"
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   149
        text += "#include <stdio.h>"
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   150
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   151
        # Adding includes
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   152
        text += "/* User includes */\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   153
        text += self.CFile.includes.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   154
        text += "\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   155
        
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   156
        text += '#include "iec_types_all.h"'
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   157
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   158
        # Adding variables
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   159
        base_types = self.GetCTRoot().GetBaseTypes()
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   160
        config = self.GetCTRoot().GetProjectConfigNames()[0]
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   161
        text += "/* User variables reference */\n"
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   162
        for variable in self.CFile.variables.variable:
1095
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   163
            var_infos = {
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   164
                "name": variable.getname(),
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   165
                "global": "%s__%s_%s" % (config.upper(),
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   166
                                         variable.getname().upper(), 
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   167
                                         location_str),
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   168
                "type": "__IEC_%s_t" % variable.gettype()}
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   169
            text += "extern %(type)s %(global)s;\n" % var_infos
a73fde048749 Move C_ext file for merging with py_ext
Laurent Bessard
parents: 1061
diff changeset
   170
            text += "#define %(name)s %(global)s.value\n" % var_infos
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   171
        text += "\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   172
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   173
        # Adding user global variables and routines
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   174
        text += "/* User internal user variables and routines */\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   175
        text += self.CFile.globals.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   176
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 675
diff changeset
   177
        # Adding Beremiz confnode functions
1c23952dbde1 refactoring
Edouard Tisserant
parents: 675
diff changeset
   178
        text += "/* Beremiz confnode functions */\n"
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   179
        text += "int __init_%s(int argc,char **argv)\n{\n"%location_str
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   180
        text += self.CFile.initFunction.gettext()
180
f7dc9acda79e Various fixes in c_ext, now, located vars are pointed.
etisserant
parents: 146
diff changeset
   181
        text += "  return 0;\n"
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   182
        text += "\n}\n\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   183
        
419
1cdae505be9e Warning in c_ext compiling fixed
laurent
parents: 402
diff changeset
   184
        text += "void __cleanup_%s(void)\n{\n"%location_str
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   185
        text += self.CFile.cleanUpFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   186
        text += "\n}\n\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   187
        
419
1cdae505be9e Warning in c_ext compiling fixed
laurent
parents: 402
diff changeset
   188
        text += "void __retrieve_%s(void)\n{\n"%location_str
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   189
        text += self.CFile.retrieveFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   190
        text += "\n}\n\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   191
        
419
1cdae505be9e Warning in c_ext compiling fixed
laurent
parents: 402
diff changeset
   192
        text += "void __publish_%s(void)\n{\n"%location_str
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   193
        text += self.CFile.publishFunction.gettext()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   194
        text += "\n}\n\n"
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   195
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   196
        Gen_Cfile_path = os.path.join(buildpath, "CFile_%s.c"%location_str)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   197
        cfile = open(Gen_Cfile_path,'w')
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   198
        cfile.write(text)
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   199
        cfile.close()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   200
        
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   201
        matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath())
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   202
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   203
        return [(Gen_Cfile_path, str(self.CExtension.getCFLAGS() + matiec_flags))],str(self.CExtension.getLDFLAGS()),True
656
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 651
diff changeset
   204
c1792dfc8c7e Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents: 651
diff changeset
   205
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   206
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   207
#                      Current Buffering Management Functions
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   208
#-------------------------------------------------------------------------------
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   209
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   210
    """
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   211
    Return a copy of the cfile model
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   212
    """
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   213
    def Copy(self, model):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   214
        return cPickle.loads(cPickle.dumps(model))
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   215
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   216
    def CreateCFileBuffer(self, saved):
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   217
        self.Buffering = False
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   218
        self.CFileBuffer = UndoBuffer(cPickle.dumps(self.CFile), saved)
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   219
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   220
    def BufferCFile(self):
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   221
        self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   222
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   223
    def StartBuffering(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   224
        self.Buffering = True
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   225
        
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   226
    def EndBuffering(self):
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   227
        if self.Buffering:
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   228
            self.CFileBuffer.Buffering(cPickle.dumps(self.CFile))
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   229
            self.Buffering = False
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   230
    
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   231
    def MarkCFileAsSaved(self):
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   232
        self.EndBuffering()
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   233
        self.CFileBuffer.CurrentSaved()
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   234
    
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   235
    def CFileIsSaved(self):
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   236
        return self.CFileBuffer.IsCurrentSaved() and not self.Buffering
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   237
        
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   238
    def LoadPrevious(self):
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   239
        self.EndBuffering()
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   240
        self.CFile = cPickle.loads(self.CFileBuffer.Previous())
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   241
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   242
    def LoadNext(self):
651
cbeb769b0a56 Adding support for unifying grid table control elements
laurent
parents: 630
diff changeset
   243
        self.CFile = cPickle.loads(self.CFileBuffer.Next())
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   244
    
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   245
    def GetBufferState(self):
658
94417ab25510 Fixing some issues in c_ext plugin
laurent
parents: 656
diff changeset
   246
        first = self.CFileBuffer.IsFirst() and not self.Buffering
145
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   247
        last = self.CFileBuffer.IsLast()
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   248
        return not first, not last
94855f7b08a9 Improving c_ext plugin by adding an XML file format for saving C files and an graphical interface for editing this file
lbessard
parents: 137
diff changeset
   249