diff -r 31e63e25b4cc -r 64beb9e9c749 plcopen/plcopen.py
--- a/plcopen/plcopen.py Mon Aug 21 20:17:19 2017 +0000
+++ b/plcopen/plcopen.py Mon Aug 21 23:22:58 2017 +0300
@@ -25,7 +25,8 @@
from xmlclass import *
from types import *
-import os, re
+import os
+import re
from lxml import etree
from collections import OrderedDict
import util.paths as paths
@@ -33,30 +34,39 @@
"""
Dictionary that makes the relation between var names in plcopen and displayed values
"""
-VarTypes = {"Local" : "localVars", "Temp" : "tempVars", "Input" : "inputVars",
- "Output" : "outputVars", "InOut" : "inOutVars", "External" : "externalVars",
- "Global" : "globalVars", "Access" : "accessVars"}
+VarTypes = {
+ "Local": "localVars",
+ "Temp": "tempVars",
+ "Input": "inputVars",
+ "Output": "outputVars",
+ "InOut": "inOutVars",
+ "External": "externalVars",
+ "Global": "globalVars",
+ "Access": "accessVars"
+}
searchResultVarTypes = {
- "inputVars": "var_input",
+ "inputVars": "var_input",
"outputVars": "var_output",
- "inOutVars": "var_inout"
+ "inOutVars": "var_inout"
}
"""
Define in which order var types must be displayed
"""
-VarOrder = ["Local","Temp","Input","Output","InOut","External","Global","Access"]
+VarOrder = ["Local", "Temp", "Input", "Output", "InOut", "External", "Global", "Access"]
"""
-Define which action qualifier must be associated with a duration
+Define which action qualifier must be associated with a duration
"""
-QualifierList = OrderedDict([("N", False), ("R", False), ("S", False),
- ("L", True), ("D", True), ("P", False), ("P0", False),
+QualifierList = OrderedDict([
+ ("N", False), ("R", False), ("S", False),
+ ("L", True), ("D", True), ("P", False), ("P0", False),
("P1", False), ("SD", True), ("DS", True), ("SL", True)])
-FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)"
+FILTER_ADDRESS_MODEL = "(%%[IQM](?:[XBWDL])?)(%s)((?:\.[0-9]+)*)"
+
def update_address(address, address_model, new_leading):
result = address_model.match(address)
@@ -65,6 +75,7 @@
groups = result.groups()
return groups[0] + new_leading + groups[2]
+
def _init_and_compare(function, v1, v2):
if v1 is None:
return v2
@@ -72,11 +83,12 @@
return function(v1, v2)
return v1
-"""
-Helper class for bounding_box calculation
-"""
+
class rect:
-
+ """
+ Helper class for bounding_box calculation
+ """
+
def __init__(self, x=None, y=None, width=None, height=None):
self.x_min = x
self.x_max = None
@@ -86,19 +98,19 @@
self.x_max = x + width
if height is not None and y is not None:
self.y_max = y + height
-
+
def update(self, x, y):
self.x_min = _init_and_compare(min, self.x_min, x)
self.x_max = _init_and_compare(max, self.x_max, x)
self.y_min = _init_and_compare(min, self.y_min, y)
self.y_max = _init_and_compare(max, self.y_max, y)
-
+
def union(self, rect):
self.x_min = _init_and_compare(min, self.x_min, rect.x_min)
self.x_max = _init_and_compare(max, self.x_max, rect.x_max)
self.y_min = _init_and_compare(min, self.y_min, rect.y_min)
self.y_max = _init_and_compare(max, self.y_max, rect.y_max)
-
+
def bounding_box(self):
width = height = None
if self.x_min is not None and self.x_max is not None:
@@ -107,12 +119,14 @@
height = self.y_max - self.y_min
return self.x_min, self.y_min, width, height
+
def TextLenInRowColumn(text):
if text == "":
return (0, 0)
lines = text.split("\n")
return len(lines) - 1, len(lines[-1])
+
def CompilePattern(criteria):
flag = 0 if criteria["case_sensitive"] else re.IGNORECASE
find_pattern = criteria["find_pattern"]
@@ -120,32 +134,39 @@
find_pattern = re.escape(find_pattern)
criteria["pattern"] = re.compile(find_pattern, flag)
+
def TestTextElement(text, criteria):
lines = text.splitlines()
test_result = []
result = criteria["pattern"].search(text)
while result is not None:
- prev_pos=result.endpos
+ prev_pos = result.endpos
start = TextLenInRowColumn(text[:result.start()])
end = TextLenInRowColumn(text[:result.end() - 1])
test_result.append((start, end, "\n".join(lines[start[0]:end[0] + 1])))
result = criteria["pattern"].search(text, result.end())
- if result is not None and prev_pos==result.endpos:
+ if result is not None and prev_pos == result.endpos:
break
return test_result
+
def TextMatched(str1, str2):
return str1 and str2 and (str1.upper() == str2.upper())
+
PLCOpenParser = GenerateParserFromXSD(paths.AbsNeighbourFile(__file__, "tc6_xml_v201.xsd"))
-PLCOpen_XPath = lambda xpath: etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
+
+
+def PLCOpen_XPath(xpath):
+ return etree.XPath(xpath, namespaces=PLCOpenParser.NSMAP)
+
LOAD_POU_PROJECT_TEMPLATE = """
-
-
@@ -164,6 +185,7 @@
"""
+
def LOAD_POU_INSTANCES_PROJECT_TEMPLATE(body_type):
return LOAD_POU_PROJECT_TEMPLATE % """
@@ -172,12 +194,13 @@