]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PythonAddons/macros/importParameters/feature.py
Salome HOME
updated copyright message
[modules/shaper.git] / src / PythonAddons / macros / importParameters / feature.py
old mode 100644 (file)
new mode 100755 (executable)
index 7f2f150..19581ee
@@ -1,3 +1,22 @@
+# Copyright (C) 2016-2023  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
 """importParameters
 Author: Nathalie Gore
 """
@@ -5,6 +24,7 @@ Author: Nathalie Gore
 from salome.shaper import model
 from salome.shaper import geom
 import ModelAPI
+import ParametersAPI
 
 class importParameters(model.Feature):
     """Import of Construction points
@@ -36,7 +56,23 @@ class importParameters(model.Feature):
     def initAttributes(self):
         """Override Feature.initAttributes()"""
         # Creating the input argument of the feature
-        self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId())
+        self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString.typeId())
+
+
+# Get existing parameters names
+
+    def existingParameters(self):
+        """ Returns list of already existing parameters names"""
+        aDoc = model.activeDocument()
+        aNbFeatures = aDoc.numInternalFeatures();
+        aNames = []
+        for i in range(aNbFeatures):
+            aParamFeature = aDoc.internalFeature(i);
+            if aParamFeature is not None:
+                if aParamFeature.getKind() == ParametersAPI.ParametersAPI_Parameter.ID():
+                    aNames.append(aParamFeature.name())
+        return aNames
+
 
 # Execution of the Import
 
@@ -50,15 +86,20 @@ class importParameters(model.Feature):
 
             # Creating the parameters in the current document
             part = model.activeDocument()
+            aNames = self.existingParameters()
 
             with open(filepath) as file:
                 for line in file:
                     defParameters = line.replace("\n","").split(' ')
                     if len(defParameters) == 2 :
-                        model.addParameter(part, defParameters[0], defParameters[1])
+                        if defParameters[0] not in aNames:
+                            model.addParameter(part, defParameters[0], defParameters[1])
+                            aNames.append(defParameters[0])
                 file.close()
                 return
 
+            setError("The file does not exist")
+
     def isMacro(self):
         """Override Feature.initAttributes().
         F.isMacro() -> True
@@ -67,6 +108,3 @@ class importParameters(model.Feature):
         finish.
         """
         return True
-        
-            setError("The file does not exist")
-