1 # Copyright (C) 2016-2023 CEA, EDF
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 from salome.shaper import model
25 from salome.shaper import geom
29 class importParameters(model.Feature):
30 """Import of Construction points
33 # Feature initializations
36 """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
37 model.Feature.__init__(self)
41 """Return Id of the Feature."""
42 return "importParameters"
46 """Returns ID of the file select parameter."""
50 """Override Feature.getKind()"""
51 return importParameters.ID()
54 # Initialization of the dialog panel
56 def initAttributes(self):
57 """Override Feature.initAttributes()"""
58 # Creating the input argument of the feature
59 self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString.typeId())
62 # Get existing parameters names
64 def existingParameters(self):
65 """ Returns list of already existing parameters names"""
66 aDoc = model.activeDocument()
67 aNbFeatures = aDoc.numInternalFeatures();
69 for i in range(aNbFeatures):
70 aParamFeature = aDoc.internalFeature(i);
71 if aParamFeature is not None:
72 if aParamFeature.getKind() == ParametersAPI.ParametersAPI_Parameter.ID():
73 aNames.append(aParamFeature.name())
77 # Execution of the Import
80 """F.execute() -- execute the Feature"""
81 # Retrieving the user input
82 apath = self.string(self.FILE_ID())
83 filepath = apath.value()
84 #print("filepath : ", filepath)
87 # Creating the parameters in the current document
88 part = model.activeDocument()
89 aNames = self.existingParameters()
91 with open(filepath) as file:
93 defParameters = line.replace("\n","").split(' ')
94 if len(defParameters) == 2 :
95 if defParameters[0] not in aNames:
96 model.addParameter(part, defParameters[0], defParameters[1])
97 aNames.append(defParameters[0])
101 setError("The file does not exist")
104 """Override Feature.initAttributes().
107 importParameters feature is macro: removes itself on the creation transaction