1872 setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
1872 setattr(cls, "filterConnections", _connectionsFunctions["filter"][connectionPointInType]) |
1873 setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
1873 setattr(cls, "updateConnectionsId", _connectionsFunctions["update"][connectionPointInType]) |
1874 setattr(cls, "Search", _SearchInElement) |
1874 setattr(cls, "Search", _SearchInElement) |
1875 return cls |
1875 return cls |
1876 |
1876 |
1877 def _getexecutionOrder(instance, specific_values): |
|
1878 executionOrder = instance.getexecutionOrderId() |
|
1879 if executionOrder is None: |
|
1880 executionOrder = 0 |
|
1881 specific_values["executionOrder"] = executionOrder |
|
1882 |
|
1883 def _getdefaultmodifiers(instance, infos): |
|
1884 infos["negated"] = instance.getnegated() |
|
1885 infos["edge"] = instance.getedge() |
|
1886 |
|
1887 def _getinputmodifiers(instance, infos): |
|
1888 infos["negated"] = instance.getnegatedIn() |
|
1889 infos["edge"] = instance.getedgeIn() |
|
1890 |
|
1891 def _getoutputmodifiers(instance, infos): |
|
1892 infos["negated"] = instance.getnegatedOut() |
|
1893 infos["edge"] = instance.getedgeOut() |
|
1894 |
|
1895 MODIFIERS_FUNCTIONS = {"default": _getdefaultmodifiers, |
|
1896 "input": _getinputmodifiers, |
|
1897 "output": _getoutputmodifiers} |
|
1898 |
|
1899 def _getconnectioninfos(instance, connection, links=False, modifiers=None, parameter=False): |
|
1900 infos = {"position": connection.getrelPositionXY()} |
|
1901 if parameter: |
|
1902 infos["name"] = instance.getformalParameter() |
|
1903 MODIFIERS_FUNCTIONS.get(modifiers, lambda x, y: None)(instance, infos) |
|
1904 if links: |
|
1905 infos["links"] = [] |
|
1906 connections = connection.getconnections() |
|
1907 if connections is not None: |
|
1908 for link in connections: |
|
1909 dic = {"refLocalId": link.getrefLocalId(), |
|
1910 "points": link.getpoints(), |
|
1911 "formalParameter": link.getformalParameter()} |
|
1912 infos["links"].append(dic) |
|
1913 return infos |
|
1914 |
|
1915 def _getelementinfos(instance): |
|
1916 return {"id": instance.getlocalId(), |
|
1917 "x": instance.getx(), |
|
1918 "y": instance.gety(), |
|
1919 "height": instance.getheight(), |
|
1920 "width": instance.getwidth(), |
|
1921 "specific_values": {}, |
|
1922 "inputs": [], |
|
1923 "outputs": []} |
|
1924 |
|
1925 def _getvariableinfosFunction(type, input, output): |
|
1926 def getvariableinfos(self): |
|
1927 infos = _getelementinfos(self) |
|
1928 infos["type"] = type |
|
1929 specific_values = infos["specific_values"] |
|
1930 specific_values["name"] = self.getexpression() |
|
1931 _getexecutionOrder(self, specific_values) |
|
1932 if input and output: |
|
1933 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "input")) |
|
1934 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "output")) |
|
1935 elif input: |
|
1936 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True, "default")) |
|
1937 elif output: |
|
1938 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut, False, "default")) |
|
1939 return infos |
|
1940 return getvariableinfos |
|
1941 |
|
1942 def _getconnectorinfosFunction(type): |
|
1943 def getconnectorinfos(self): |
|
1944 infos = _getelementinfos(self) |
|
1945 infos["type"] = type |
|
1946 infos["specific_values"]["name"] = self.getname() |
|
1947 if type == "connector": |
|
1948 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
1949 elif type == "continuation": |
|
1950 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
1951 return infos |
|
1952 return getconnectorinfos |
|
1953 |
|
1954 def _getpowerrailinfosFunction(type): |
|
1955 def getpowerrailinfos(self): |
|
1956 infos = _getelementinfos(self) |
|
1957 infos["type"] = type |
|
1958 if type == "rightPowerRail": |
|
1959 for connectionPointIn in self.getconnectionPointIn(): |
|
1960 infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
|
1961 infos["specific_values"]["connectors"] = len(infos["inputs"]) |
|
1962 elif type == "leftPowerRail": |
|
1963 for connectionPointOut in self.getconnectionPointOut(): |
|
1964 infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
|
1965 infos["specific_values"]["connectors"] = len(infos["outputs"]) |
|
1966 return infos |
|
1967 return getpowerrailinfos |
|
1968 |
|
1969 def _getldelementinfosFunction(ld_element_type): |
|
1970 def getldelementinfos(self): |
|
1971 infos = _getelementinfos(self) |
|
1972 infos["type"] = ld_element_type |
|
1973 specific_values = infos["specific_values"] |
|
1974 specific_values["name"] = self.getvariable() |
|
1975 _getexecutionOrder(self, specific_values) |
|
1976 specific_values["negated"] = self.getnegated() |
|
1977 specific_values["edge"] = self.getedge() |
|
1978 if ld_element_type == "coil": |
|
1979 specific_values["storage"] = self.getstorage() |
|
1980 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
1981 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
1982 return infos |
|
1983 return getldelementinfos |
|
1984 |
|
1985 DIVERGENCE_TYPES = {(True, True): "simultaneousDivergence", |
|
1986 (True, False): "selectionDivergence", |
|
1987 (False, True): "simultaneousConvergence", |
|
1988 (False, False): "selectionConvergence"} |
|
1989 |
|
1990 def _getdivergenceinfosFunction(divergence, simultaneous): |
|
1991 def getdivergenceinfos(self): |
|
1992 infos = _getelementinfos(self) |
|
1993 infos["type"] = DIVERGENCE_TYPES[(divergence, simultaneous)] |
|
1994 if divergence: |
|
1995 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
1996 for connectionPointOut in self.getconnectionPointOut(): |
|
1997 infos["outputs"].append(_getconnectioninfos(self, connectionPointOut)) |
|
1998 infos["specific_values"]["connectors"] = len(infos["outputs"]) |
|
1999 else: |
|
2000 for connectionPointIn in self.getconnectionPointIn(): |
|
2001 infos["inputs"].append(_getconnectioninfos(self, connectionPointIn, True)) |
|
2002 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2003 infos["specific_values"]["connectors"] = len(infos["inputs"]) |
|
2004 return infos |
|
2005 return getdivergenceinfos |
|
2006 |
|
2007 cls = _initElementClass("comment", "commonObjects") |
1877 cls = _initElementClass("comment", "commonObjects") |
2008 if cls: |
1878 if cls: |
2009 def getinfos(self): |
|
2010 infos = _getelementinfos(self) |
|
2011 infos["type"] = "comment" |
|
2012 infos["specific_values"]["content"] = self.getcontentText() |
|
2013 return infos |
|
2014 setattr(cls, "getinfos", getinfos) |
|
2015 |
|
2016 def setcontentText(self, text): |
1879 def setcontentText(self, text): |
2017 self.content.setanyText(text) |
1880 self.content.setanyText(text) |
2018 setattr(cls, "setcontentText", setcontentText) |
1881 setattr(cls, "setcontentText", setcontentText) |
2019 |
1882 |
2020 def getcontentText(self): |
1883 def getcontentText(self): |
2039 bbox = _getBoundingBox(self) |
1902 bbox = _getBoundingBox(self) |
2040 for input in self.inputVariables.getvariable(): |
1903 for input in self.inputVariables.getvariable(): |
2041 bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
1904 bbox.union(_getConnectionsBoundingBox(input.connectionPointIn)) |
2042 return bbox |
1905 return bbox |
2043 setattr(cls, "getBoundingBox", getBoundingBox) |
1906 setattr(cls, "getBoundingBox", getBoundingBox) |
2044 |
|
2045 def getinfos(self): |
|
2046 infos = _getelementinfos(self) |
|
2047 infos["type"] = self.gettypeName() |
|
2048 specific_values = infos["specific_values"] |
|
2049 specific_values["name"] = self.getinstanceName() |
|
2050 _getexecutionOrder(self, specific_values) |
|
2051 for variable in self.inputVariables.getvariable(): |
|
2052 infos["inputs"].append(_getconnectioninfos(variable, variable.connectionPointIn, True, "default", True)) |
|
2053 for variable in self.outputVariables.getvariable(): |
|
2054 infos["outputs"].append(_getconnectioninfos(variable, variable.connectionPointOut, False, "default", True)) |
|
2055 return infos |
|
2056 setattr(cls, "getinfos", getinfos) |
|
2057 |
1907 |
2058 def updateElementName(self, old_name, new_name): |
1908 def updateElementName(self, old_name, new_name): |
2059 if self.typeName == old_name: |
1909 if self.typeName == old_name: |
2060 self.typeName = new_name |
1910 self.typeName = new_name |
2061 setattr(cls, "updateElementName", updateElementName) |
1911 setattr(cls, "updateElementName", updateElementName) |
2112 return _Search([("reference", self.variable)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) |
1954 return _Search([("reference", self.variable)], criteria, parent_infos + [ld_element_type, self.getlocalId()]) |
2113 return SearchInLDElement |
1955 return SearchInLDElement |
2114 |
1956 |
2115 cls = _initElementClass("contact", "ldObjects", "single") |
1957 cls = _initElementClass("contact", "ldObjects", "single") |
2116 if cls: |
1958 if cls: |
2117 setattr(cls, "getinfos", _getldelementinfosFunction("contact")) |
|
2118 setattr(cls, "updateElementName", _UpdateLDElementName) |
1959 setattr(cls, "updateElementName", _UpdateLDElementName) |
2119 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
1960 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2120 setattr(cls, "Search", _getSearchInLDElement("contact")) |
1961 setattr(cls, "Search", _getSearchInLDElement("contact")) |
2121 |
1962 |
2122 cls = _initElementClass("coil", "ldObjects", "single") |
1963 cls = _initElementClass("coil", "ldObjects", "single") |
2123 if cls: |
1964 if cls: |
2124 setattr(cls, "getinfos", _getldelementinfosFunction("coil")) |
|
2125 setattr(cls, "updateElementName", _UpdateLDElementName) |
1965 setattr(cls, "updateElementName", _UpdateLDElementName) |
2126 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
1966 setattr(cls, "updateElementAddress", _UpdateLDElementAddress) |
2127 setattr(cls, "Search", _getSearchInLDElement("coil")) |
1967 setattr(cls, "Search", _getSearchInLDElement("coil")) |
2128 |
1968 |
2129 cls = _initElementClass("step", "sfcObjects", "single") |
1969 cls = _initElementClass("step", "sfcObjects", "single") |
2130 if cls: |
1970 if cls: |
2131 def getinfos(self): |
|
2132 infos = _getelementinfos(self) |
|
2133 infos["type"] = "step" |
|
2134 specific_values = infos["specific_values"] |
|
2135 specific_values["name"] = self.getname() |
|
2136 specific_values["initial"] = self.getinitialStep() |
|
2137 if self.connectionPointIn is not None: |
|
2138 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2139 if self.connectionPointOut is not None: |
|
2140 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2141 if self.connectionPointOutAction is not None: |
|
2142 specific_values["action"] = _getconnectioninfos(self, self.connectionPointOutAction) |
|
2143 return infos |
|
2144 setattr(cls, "getinfos", getinfos) |
|
2145 |
|
2146 def Search(self, criteria, parent_infos=[]): |
1971 def Search(self, criteria, parent_infos=[]): |
2147 return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
1972 return _Search([("name", self.getname())], criteria, parent_infos + ["step", self.getlocalId()]) |
2148 setattr(cls, "Search", Search) |
1973 setattr(cls, "Search", Search) |
2149 |
1974 |
2150 cls = _initElementClass("transition", "sfcObjects") |
1975 cls = _initElementClass("transition", "sfcObjects") |
2151 if cls: |
1976 if cls: |
2152 def getinfos(self): |
|
2153 infos = _getelementinfos(self) |
|
2154 infos["type"] = "transition" |
|
2155 specific_values = infos["specific_values"] |
|
2156 priority = self.getpriority() |
|
2157 if priority is None: |
|
2158 priority = 0 |
|
2159 specific_values["priority"] = priority |
|
2160 condition = self.getconditionContent() |
|
2161 specific_values["condition_type"] = condition["type"] |
|
2162 if specific_values["condition_type"] == "connection": |
|
2163 specific_values["connection"] = _getconnectioninfos(self, condition["value"], True) |
|
2164 else: |
|
2165 specific_values["condition"] = condition["value"] |
|
2166 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2167 infos["outputs"].append(_getconnectioninfos(self, self.connectionPointOut)) |
|
2168 return infos |
|
2169 setattr(cls, "getinfos", getinfos) |
|
2170 |
|
2171 def setconditionContent(self, condition_type, value): |
1977 def setconditionContent(self, condition_type, value): |
2172 if self.condition is None: |
1978 if self.condition is None: |
2173 self.addcondition() |
1979 self.addcondition() |
2174 if condition_type == "connection": |
1980 if condition_type == "connection": |
2175 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
1981 condition = PLCOpenParser.CreateElement("connectionPointIn", "condition") |
2276 elif content_name == "inline": |
2082 elif content_name == "inline": |
2277 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2083 search_result.extend(content.Search(criteria, parent_infos + ["inline"])) |
2278 return search_result |
2084 return search_result |
2279 setattr(cls, "Search", Search) |
2085 setattr(cls, "Search", Search) |
2280 |
2086 |
2281 cls = _initElementClass("selectionDivergence", "sfcObjects", "single") |
|
2282 if cls: |
|
2283 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, False)) |
|
2284 |
|
2285 cls = _initElementClass("selectionConvergence", "sfcObjects", "multiple") |
|
2286 if cls: |
|
2287 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, False)) |
|
2288 |
|
2289 cls = _initElementClass("simultaneousDivergence", "sfcObjects", "single") |
|
2290 if cls: |
|
2291 setattr(cls, "getinfos", _getdivergenceinfosFunction(True, True)) |
|
2292 |
|
2293 cls = _initElementClass("simultaneousConvergence", "sfcObjects", "multiple") |
|
2294 if cls: |
|
2295 setattr(cls, "getinfos", _getdivergenceinfosFunction(False, True)) |
|
2296 |
|
2297 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2087 cls = _initElementClass("jumpStep", "sfcObjects", "single") |
2298 if cls: |
2088 if cls: |
2299 def getinfos(self): |
|
2300 infos = _getelementinfos(self) |
|
2301 infos["type"] = "jump" |
|
2302 infos["specific_values"]["target"] = self.gettargetName() |
|
2303 infos["inputs"].append(_getconnectioninfos(self, self.connectionPointIn, True)) |
|
2304 return infos |
|
2305 setattr(cls, "getinfos", getinfos) |
|
2306 |
|
2307 def Search(self, criteria, parent_infos): |
2089 def Search(self, criteria, parent_infos): |
2308 return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
2090 return _Search([("target", self.gettargetName())], criteria, parent_infos + ["jump", self.getlocalId()]) |
2309 setattr(cls, "Search", Search) |
2091 setattr(cls, "Search", Search) |
2310 |
2092 |
2311 cls = PLCOpenParser.GetElementClass("action", "actionBlock") |
2093 cls = PLCOpenParser.GetElementClass("action", "actionBlock") |
2438 def _UpdateIOElementAddress(self, old_name, new_name): |
2212 def _UpdateIOElementAddress(self, old_name, new_name): |
2439 self.expression = update_address(self.expression, address_model, new_leading) |
2213 self.expression = update_address(self.expression, address_model, new_leading) |
2440 |
2214 |
2441 cls = _initElementClass("inVariable", "fbdObjects") |
2215 cls = _initElementClass("inVariable", "fbdObjects") |
2442 if cls: |
2216 if cls: |
2443 setattr(cls, "getinfos", _getvariableinfosFunction("input", False, True)) |
|
2444 setattr(cls, "updateElementName", _UpdateIOElementName) |
2217 setattr(cls, "updateElementName", _UpdateIOElementName) |
2445 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2218 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2446 setattr(cls, "Search", _SearchInIOVariable) |
2219 setattr(cls, "Search", _SearchInIOVariable) |
2447 |
2220 |
2448 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2221 cls = _initElementClass("outVariable", "fbdObjects", "single") |
2449 if cls: |
2222 if cls: |
2450 setattr(cls, "getinfos", _getvariableinfosFunction("output", True, False)) |
|
2451 setattr(cls, "updateElementName", _UpdateIOElementName) |
2223 setattr(cls, "updateElementName", _UpdateIOElementName) |
2452 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2224 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2453 setattr(cls, "Search", _SearchInIOVariable) |
2225 setattr(cls, "Search", _SearchInIOVariable) |
2454 |
2226 |
2455 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2227 cls = _initElementClass("inOutVariable", "fbdObjects", "single") |
2456 if cls: |
2228 if cls: |
2457 setattr(cls, "getinfos", _getvariableinfosFunction("inout", True, True)) |
|
2458 setattr(cls, "updateElementName", _UpdateIOElementName) |
2229 setattr(cls, "updateElementName", _UpdateIOElementName) |
2459 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2230 setattr(cls, "updateElementAddress", _UpdateIOElementAddress) |
2460 setattr(cls, "Search", _SearchInIOVariable) |
2231 setattr(cls, "Search", _SearchInIOVariable) |
2461 |
2232 |
2462 |
2233 |
2463 def _SearchInConnector(self, criteria, parent_infos=[]): |
2234 def _SearchInConnector(self, criteria, parent_infos=[]): |
2464 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2235 return _Search([("name", self.getname())], criteria, parent_infos + ["connector", self.getlocalId()]) |
2465 |
2236 |
2466 cls = _initElementClass("continuation", "commonObjects") |
2237 cls = _initElementClass("continuation", "commonObjects") |
2467 if cls: |
2238 if cls: |
2468 setattr(cls, "getinfos", _getconnectorinfosFunction("continuation")) |
|
2469 setattr(cls, "Search", _SearchInConnector) |
2239 setattr(cls, "Search", _SearchInConnector) |
2470 |
2240 |
2471 def updateElementName(self, old_name, new_name): |
2241 def updateElementName(self, old_name, new_name): |
2472 if self.name == old_name: |
2242 if self.name == old_name: |
2473 self.name = new_name |
2243 self.name = new_name |
2474 setattr(cls, "updateElementName", updateElementName) |
2244 setattr(cls, "updateElementName", updateElementName) |
2475 |
2245 |
2476 cls = _initElementClass("connector", "commonObjects", "single") |
2246 cls = _initElementClass("connector", "commonObjects", "single") |
2477 if cls: |
2247 if cls: |
2478 setattr(cls, "getinfos", _getconnectorinfosFunction("connector")) |
|
2479 setattr(cls, "Search", _SearchInConnector) |
2248 setattr(cls, "Search", _SearchInConnector) |
2480 |
2249 |
2481 def updateElementName(self, old_name, new_name): |
2250 def updateElementName(self, old_name, new_name): |
2482 if self.name == old_name: |
2251 if self.name == old_name: |
2483 self.name = new_name |
2252 self.name = new_name |