author | Laurent Bessard |
Thu, 16 May 2013 00:01:09 +0200 | |
changeset 1151 | 38d6aaad8ffd |
parent 1124 | b1705000eba1 |
child 1315 | ff14a66bbd12 |
permissions | -rw-r--r-- |
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
1 |
|
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
|
2 |
import os |
401
8106a853a7c7
Adding support for displaying plugins available variable into Beremiz plugin tree
laurent
parents:
361
diff
changeset
|
3 |
|
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
|
4 |
from CFileEditor import CFileEditor |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
5 |
from CodeFileTreeNode import CodeFile |
630
91b2ae63ea3d
Including external tools for editing plugin informations into Beremiz window
laurent
parents:
610
diff
changeset
|
6 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
7 |
class CFile(CodeFile): |
31 | 8 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
9 |
<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
|
10 |
<xsd:element name="CExtension"> |
31 | 11 |
<xsd:complexType> |
45 | 12 |
<xsd:attribute name="CFLAGS" type="xsd:string" use="required"/> |
13 |
<xsd:attribute name="LDFLAGS" type="xsd:string" use="required"/> |
|
31 | 14 |
</xsd:complexType> |
15 |
</xsd:element> |
|
16 |
</xsd:schema> |
|
17 |
""" |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
18 |
CODEFILE_NAME = "CFile" |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
19 |
SECTIONS_NAMES = [ |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
20 |
"includes", |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
21 |
"globals", |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
22 |
"initFunction", |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
23 |
"cleanUpFunction", |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
24 |
"retrieveFunction", |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
25 |
"publishFunction"] |
656
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
651
diff
changeset
|
26 |
EditorType = CFileEditor |
c1792dfc8c7e
Fixing bug integrated plugin editors not closed when removing corresponding plugin
laurent
parents:
651
diff
changeset
|
27 |
|
1124
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
28 |
def GenerateClassesFromXSDstring(self, xsd_string): |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
29 |
return GenerateClassesFromXSDstring(xsd_string) |
b1705000eba1
Fixed support for defining python runtime code using sections like in c_ext
Laurent Bessard
parents:
1119
diff
changeset
|
30 |
|
781
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
742
diff
changeset
|
31 |
def GetIconName(self): |
cdc6393705ce
Adding support using plcopeneditor bitmap library for icon request
laurent
parents:
742
diff
changeset
|
32 |
return "Cfile" |
738 | 33 |
|
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
34 |
def CodeFileName(self): |
718 | 35 |
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
|
36 |
|
718 | 37 |
def CTNGenerate_C(self, buildpath, locations): |
31 | 38 |
""" |
39 |
Generate C code |
|
717 | 40 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
31 | 41 |
@param locations: List of complete variables locations \ |
42 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
|
43 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
44 |
"DIR" : direction "Q","I" or "M" |
|
45 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
46 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
47 |
}, ...] |
|
48 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
49 |
""" |
|
50 |
current_location = self.GetCurrentLocation() |
|
51 |
# 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
|
52 |
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
|
53 |
|
717 | 54 |
text = "/* Code generated by Beremiz c_ext confnode */\n\n" |
1114 | 55 |
text += "#include <stdio.h>\n\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
|
56 |
|
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 |
# 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
|
58 |
text += "/* User includes */\n" |
1119 | 59 |
text += self.CodeFile.includes.gettext().strip() |
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 |
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
|
61 |
|
1114 | 62 |
text += '#include "iec_types_all.h"\n\n' |
63 |
||
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
|
64 |
# Adding variables |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
65 |
config = self.GetCTRoot().GetProjectConfigNames()[0] |
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
|
66 |
text += "/* User variables reference */\n" |
1096
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
67 |
for variable in self.CodeFile.variables.variable: |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
68 |
var_infos = { |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
69 |
"name": variable.getname(), |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
70 |
"global": "%s__%s" % (config.upper(), |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
71 |
variable.getname().upper()), |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
72 |
"type": "__IEC_%s_t" % variable.gettype()} |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
73 |
text += "extern %(type)s %(global)s;\n" % var_infos |
c9ace6a881c9
Fixed CFileEditor replacing folding panels by variable panel and STC
Laurent Bessard
parents:
1061
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
|
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 |
# 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
|
78 |
text += "/* User internal user variables and routines */\n" |
1119 | 79 |
text += self.CodeFile.globals.gettext().strip() |
1114 | 80 |
text += "\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
|
81 |
|
717 | 82 |
# Adding Beremiz confnode functions |
83 |
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
|
84 |
text += "int __init_%s(int argc,char **argv)\n{\n"%location_str |
1119 | 85 |
text += self.CodeFile.initFunction.gettext().strip() |
86 |
text += " return 0;\n}\n\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
|
87 |
|
419 | 88 |
text += "void __cleanup_%s(void)\n{\n"%location_str |
1119 | 89 |
text += self.CodeFile.cleanUpFunction.gettext().strip() |
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
|
90 |
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
|
91 |
|
419 | 92 |
text += "void __retrieve_%s(void)\n{\n"%location_str |
1119 | 93 |
text += self.CodeFile.retrieveFunction.gettext().strip() |
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
|
94 |
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
|
95 |
|
419 | 96 |
text += "void __publish_%s(void)\n{\n"%location_str |
1119 | 97 |
text += self.CodeFile.publishFunction.gettext().strip() |
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
|
98 |
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
|
99 |
|
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 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
|
718 | 105 |
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
|
106 |
|
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
|
107 |
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
|
108 |