From eb1fd738b4975723d9ac678e53c7c88b89f70629 Mon Sep 17 00:00:00 2001 From: NATHALIE GORE Date: Fri, 9 Aug 2019 15:30:16 +0200 Subject: [PATCH] Fix compoundVertices and adding list of parameters --- src/PythonAddons/addons_Features.xml.in | 1 + .../macros/compoundVertices/feature.py | 6 +- .../macros/compoundVertices/widget.xml | 1 - .../macros/importParameters/__init__.py | 0 .../macros/importParameters/feature.py | 63 +++++++++++++++++++ .../macros/importParameters/widget.xml | 12 ++++ 6 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 src/PythonAddons/macros/importParameters/__init__.py create mode 100644 src/PythonAddons/macros/importParameters/feature.py create mode 100644 src/PythonAddons/macros/importParameters/widget.xml diff --git a/src/PythonAddons/addons_Features.xml.in b/src/PythonAddons/addons_Features.xml.in index 958ef4511..1bbec0675 100644 --- a/src/PythonAddons/addons_Features.xml.in +++ b/src/PythonAddons/addons_Features.xml.in @@ -1,5 +1,6 @@ + diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py index 141b35bb0..91bc6017f 100644 --- a/src/PythonAddons/macros/compoundVertices/feature.py +++ b/src/PythonAddons/macros/compoundVertices/feature.py @@ -56,13 +56,11 @@ class compoundVertices(model.Feature): for line in file: coord = line.split(' ') x = float(coord[0]); y = float(coord[1]); z = float(coord[2]); - print(line) point = model.addPoint(part, x,y,z) - print(line) vertex = model.addVertex(part, [point.result()]) - print(line) - #lVertices.append(vertex) + lVertices.append(vertex.result()) file.close() + Compound_1 = model.addCompound(part, lVertices) return setError("The file does not exist") diff --git a/src/PythonAddons/macros/compoundVertices/widget.xml b/src/PythonAddons/macros/compoundVertices/widget.xml index d7901cf22..e8e2f2e88 100644 --- a/src/PythonAddons/macros/compoundVertices/widget.xml +++ b/src/PythonAddons/macros/compoundVertices/widget.xml @@ -4,7 +4,6 @@ - diff --git a/src/PythonAddons/macros/importParameters/__init__.py b/src/PythonAddons/macros/importParameters/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/PythonAddons/macros/importParameters/feature.py b/src/PythonAddons/macros/importParameters/feature.py new file mode 100644 index 000000000..440eca6e1 --- /dev/null +++ b/src/PythonAddons/macros/importParameters/feature.py @@ -0,0 +1,63 @@ +"""importParameters +Author: Nathalie Gore +""" + +from salome.shaper import model +from salome.shaper import geom +import ModelAPI + +class importParameters(model.Feature): + """Import of Construction points + """ + +# Feature initializations + + def __init__(self): + """x.__init__(...) initializes x; see x.__class__.__doc__ for signature""" + model.Feature.__init__(self) + + @staticmethod + def ID(): + """Return Id of the Feature.""" + return "importParameters" + + @staticmethod + def FILE_ID(): + """Returns ID of the file select parameter.""" + return "file_path" + + def getKind(self): + """Override Feature.getKind()""" + return importParameters.ID() + + +# Initialization of the dialog panel + + def initAttributes(self): + """Override Feature.initAttributes()""" + # Creating the input argument of the feature + self.data().addAttribute(self.FILE_ID(), ModelAPI.ModelAPI_AttributeString_typeId()) + +# Execution of the Import + + def execute(self): + """F.execute() -- execute the Feature""" + # Retrieving the user input + apath = self.string(self.FILE_ID()) + filepath = apath.value() + #print("filepath : ", filepath) + if filepath != "" : + + # Creating the parameters in the current document + part = model.activeDocument() + + 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]) + file.close() + return + + setError("The file does not exist") + diff --git a/src/PythonAddons/macros/importParameters/widget.xml b/src/PythonAddons/macros/importParameters/widget.xml new file mode 100644 index 000000000..e43b86afe --- /dev/null +++ b/src/PythonAddons/macros/importParameters/widget.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + -- 2.30.2