123 result = criteria["pattern"].search(text, result.end()) |
123 result = criteria["pattern"].search(text, result.end()) |
124 return test_result |
124 return test_result |
125 |
125 |
126 PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
126 PLCOpenParser = GenerateParserFromXSD(os.path.join(os.path.split(__file__)[0], "tc6_xml_v201.xsd")) |
127 |
127 |
|
128 LOAD_POU_PROJECT_TEMPLATE = """ |
|
129 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" |
|
130 xmlns:xhtml="http://www.w3.org/1999/xhtml" |
|
131 xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
|
132 xmlns="http://www.plcopen.org/xml/tc6_0201"> |
|
133 <fileHeader companyName="" productName="" productVersion="" |
|
134 creationDateTime="1970-01-01T00:00:00"/> |
|
135 <contentHeader name="paste_project"> |
|
136 <coordinateInfo> |
|
137 <fbd><scaling x="0" y="0"/></fbd> |
|
138 <ld><scaling x="0" y="0"/></ld> |
|
139 <sfc><scaling x="0" y="0"/></sfc> |
|
140 </coordinateInfo> |
|
141 </contentHeader> |
|
142 <types> |
|
143 <dataTypes/> |
|
144 <pous>%s</pous> |
|
145 </types> |
|
146 <instances> |
|
147 <configurations/> |
|
148 </instances> |
|
149 </project> |
|
150 """ |
|
151 |
|
152 def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type): |
|
153 return LOAD_POU_PROJECT_TEMPLATE % """ |
|
154 <pou name="paste_pou" pouType="program"> |
|
155 <body> |
|
156 <%(body_type)s>%%s</%(body_type)s> |
|
157 </body> |
|
158 </pou>""" % locals() |
|
159 |
128 def LoadProject(filepath): |
160 def LoadProject(filepath): |
129 project_file = open(filepath) |
161 project_file = open(filepath) |
130 project_xml = project_file.read().replace( |
162 project_xml = project_file.read().replace( |
131 "http://www.plcopen.org/xml/tc6.xsd", |
163 "http://www.plcopen.org/xml/tc6.xsd", |
132 "http://www.plcopen.org/xml/tc6_0201") |
164 "http://www.plcopen.org/xml/tc6_0201") |
135 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
167 (re.compile("(?:]]>)(?!</xhtml:p>)"), "]]></xhtml:p>")]: |
136 project_xml = cre.sub(repl, project_xml) |
168 project_xml = cre.sub(repl, project_xml) |
137 project_file.close() |
169 project_file.close() |
138 |
170 |
139 return etree.fromstring(project_xml, PLCOpenParser) |
171 return etree.fromstring(project_xml, PLCOpenParser) |
|
172 |
|
173 def LoadPou(xml_string): |
|
174 root = etree.fromstring( |
|
175 LOAD_POU_PROJECT_TEMPLATE % xml_string, |
|
176 PLCOpenParser) |
|
177 return root.xpath( |
|
178 "/ppx:project/ppx:types/ppx:pous/ppx:pou", |
|
179 namespaces=PLCOpenParser.NSMAP)[0] |
|
180 |
|
181 def LoadPouInstances(xml_string, body_type): |
|
182 root = etree.fromstring( |
|
183 LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type) % xml_string, |
|
184 PLCOpenParser) |
|
185 return root.xpath( |
|
186 "/ppx:project/ppx:types/ppx:pous/ppx:pou[@name='paste_pou']/ppx:body/ppx:%s/*" % body_type, |
|
187 namespaces=PLCOpenParser.NSMAP) |
140 |
188 |
141 def SaveProject(project, filepath): |
189 def SaveProject(project, filepath): |
142 project_file = open(filepath, 'w') |
190 project_file = open(filepath, 'w') |
143 project_file.write(etree.tostring( |
191 project_file.write(etree.tostring( |
144 project, |
192 project, |
2407 setattr(cls, "getconditionContent", getconditionContent) |
2455 setattr(cls, "getconditionContent", getconditionContent) |
2408 |
2456 |
2409 def getconditionConnection(self): |
2457 def getconditionConnection(self): |
2410 if self.condition is not None: |
2458 if self.condition is not None: |
2411 content = self.condition.getcontent() |
2459 content = self.condition.getcontent() |
2412 if content.getLocalTag() == "connection": |
2460 if content.getLocalTag() == "connectionPointIn": |
2413 return content |
2461 return content |
2414 return None |
2462 return None |
2415 setattr(cls, "getconditionConnection", getconditionConnection) |
2463 setattr(cls, "getconditionConnection", getconditionConnection) |
2416 |
2464 |
2417 def getBoundingBox(self): |
2465 def getBoundingBox(self): |
2423 setattr(cls, "getBoundingBox", getBoundingBox) |
2471 setattr(cls, "getBoundingBox", getBoundingBox) |
2424 |
2472 |
2425 def translate(self, dx, dy): |
2473 def translate(self, dx, dy): |
2426 _translateSingle(self, dx, dy) |
2474 _translateSingle(self, dx, dy) |
2427 condition_connection = self.getconditionConnection() |
2475 condition_connection = self.getconditionConnection() |
2428 if condition_connection: |
2476 if condition_connection is not None: |
2429 _translateConnections(condition_connection, dx, dy) |
2477 _translateConnections(condition_connection, dx, dy) |
2430 setattr(cls, "translate", translate) |
2478 setattr(cls, "translate", translate) |
2431 |
2479 |
2432 def filterConnections(self, connections): |
2480 def filterConnections(self, connections): |
2433 _filterConnectionsSingle(self, connections) |
2481 _filterConnectionsSingle(self, connections) |