Automatically increment IEC-location address if copy of the variable is created
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 29 Jun 2018 17:53:57 +0300
changeset 2240 e684aed23407
parent 2239 813792f22527
child 2241 e762e234181d
Automatically increment IEC-location address if copy of the variable is created
controls/VariablePanel.py
--- a/controls/VariablePanel.py	Fri Jun 29 15:36:34 2018 +0300
+++ b/controls/VariablePanel.py	Fri Jun 29 17:53:57 2018 +0300
@@ -105,6 +105,7 @@
 }
 
 LOCATION_MODEL = re.compile("((?:%[IQM](?:\*|(?:[XBWLD]?[0-9]+(?:\.[0-9]+)*)))?)$")
+LOCATION_MODEL_SET = re.compile("((?:%[IQM](?:[XBWLD]?[0-9]+(?:\.[0-9]+)*))?)$")
 
 
 # -------------------------------------------------------------------------------
@@ -597,6 +598,15 @@
                 old_name = self.Values[new_row-1].Name
                 row_content.Name = self.Controler.GenerateNewName(
                     self.TagName, old_name, old_name+'%d')
+
+                # increment location address
+                if row_content.Location != "" and LOCATION_MODEL_SET.match(row_content.Location):
+                    old_location = row_content.Location
+                    model = re.compile("%[IQM][XBWLD]?(.*\.|)")
+                    prefix = model.match(old_location).group(0)
+                    addr = int(re.split(model, old_location)[-1]) + 1
+                    row_content.Location = prefix + unicode(addr)
+
             if not row_content.Class:
                 row_content.Class = self.DefaultTypes.get(self.Filter, self.Filter)