From: NATHALIE GORE Date: Wed, 21 Aug 2019 08:41:33 +0000 (+0200) Subject: Update pour separator X-Git-Tag: V9_4_0a2~7^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a5f2a6e1e09c90ba9f638a04e31115313617e129;p=modules%2Fshaper.git Update pour separator --- diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py index c8e5fed48..0f2189c1e 100644 --- a/src/PythonAddons/macros/compoundVertices/feature.py +++ b/src/PythonAddons/macros/compoundVertices/feature.py @@ -26,6 +26,11 @@ class compoundVertices(model.Feature): """Returns ID of the file select parameter.""" return "file_path" + @staticmethod + def SEPARATOR_ID(): + """Returns ID of the separator parameter.""" + return "separator" + def getKind(self): """Override Feature.getKind()""" return compoundVertices.ID() @@ -37,6 +42,11 @@ class compoundVertices(model.Feature): """Override Feature.initAttributes()""" # Creating the input argument of the feature self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId()) + self.data().addAttribute(self.SEPARATOR_ID(), ModelAPI.ModelAPI_AttributeString_typeId()) + + self.lfeatures = [] + self.folder = None + self.separator = " " # Execution of the Import @@ -44,33 +54,39 @@ class compoundVertices(model.Feature): """F.execute() -- execute the Feature""" # Retrieving the user input apath = self.string(self.FILE_ID()) + aseparator = self.string(self.SEPARATOR_ID()).value() + if aseparator: + self.separator = aseparator + filepath = apath.value() - print("filepath : ", filepath) if filepath != "" : - + part = model.activeDocument() + if self.lfeatures : + for feature in self.lfeatures: + part.removeFeature(feature.feature()) + self.lfeatures = [] + #part.removeFeature(self.folder.feature()) + from os.path import basename filename = basename(filepath) - print("filename : ", filename) + nameRes = "Points_" + filename # Creating the construction points in the current document - part = model.activeDocument() lVertices = [] - startPoint = None - with open(filepath) as file: for line in file: - coord = line.split(' ') + coord = line.split(self.separator) x = float(coord[0]); y = float(coord[1]); z = float(coord[2]); - point = model.addPoint(part, x,y,z); point.execute(True) - if startPoint == None : startPoint = point - vertex = model.addVertex(part, [point.result()]); vertex.execute(True) + point = model.addPoint(part, x,y,z); point.execute(True); self.lfeatures.append(point) + vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex) lVertices.append(vertex.result()) file.close() compound = model.addCompound(part, lVertices) - compound.execute(True) - folder = model.addFolder(part, startPoint, compound) - folder.setName(filename) + compound.execute(True); self.lfeatures.append(compound) + compound.result().setName(nameRes) + self.folder = model.addFolder(part, self.lfeatures[0], compound) + self.folder.setName(nameRes) return setError("The file does not exist") @@ -82,4 +98,4 @@ class compoundVertices(model.Feature): compoundVertices feature is macro: removes itself on the creation transaction finish. """ - return True + return True diff --git a/src/PythonAddons/macros/compoundVertices/widget.xml b/src/PythonAddons/macros/compoundVertices/widget.xml index e8e2f2e88..2fa559776 100644 --- a/src/PythonAddons/macros/compoundVertices/widget.xml +++ b/src/PythonAddons/macros/compoundVertices/widget.xml @@ -5,6 +5,8 @@ + + diff --git a/src/PythonAddons/macros/importParameters/feature.py b/src/PythonAddons/macros/importParameters/feature.py index 7f2f15055..6abd0ddf3 100644 --- a/src/PythonAddons/macros/importParameters/feature.py +++ b/src/PythonAddons/macros/importParameters/feature.py @@ -58,6 +58,8 @@ class importParameters(model.Feature): model.addParameter(part, defParameters[0], defParameters[1]) file.close() return + + setError("The file does not exist") def isMacro(self): """Override Feature.initAttributes(). @@ -67,6 +69,5 @@ class importParameters(model.Feature): finish. """ return True - - setError("The file does not exist") +