From 227076b6870bcc1345b2364da55bd67a8ebbef24 Mon Sep 17 00:00:00 2001 From: NATHALIE GORE Date: Wed, 16 Oct 2019 11:06:54 +0200 Subject: [PATCH] Update for macros NGO --- src/PythonAddons/CMakeLists.txt | 2 + src/PythonAddons/Test/TestcompoundVertices.py | 52 +++++++++++++++++++ src/PythonAddons/Test/TestimportParameters.py | 47 +++++++++++++++++ .../compoundVertices/compoundVertices.txt | 18 +++++++ .../macros/compoundVertices/feature.py | 4 +- .../importParameters/importParameters.txt | 4 ++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/PythonAddons/Test/TestcompoundVertices.py create mode 100644 src/PythonAddons/Test/TestimportParameters.py create mode 100644 src/PythonAddons/macros/compoundVertices/compoundVertices.txt create mode 100644 src/PythonAddons/macros/importParameters/importParameters.txt diff --git a/src/PythonAddons/CMakeLists.txt b/src/PythonAddons/CMakeLists.txt index 3597646b3..5a3cbb565 100644 --- a/src/PythonAddons/CMakeLists.txt +++ b/src/PythonAddons/CMakeLists.txt @@ -47,4 +47,6 @@ INCLUDE(UnitTest) ADD_UNIT_TESTS( TestRectangle.py + TestcompoundVertices.py + TestimportParameters.py ) diff --git a/src/PythonAddons/Test/TestcompoundVertices.py b/src/PythonAddons/Test/TestcompoundVertices.py new file mode 100644 index 000000000..72fc0c961 --- /dev/null +++ b/src/PythonAddons/Test/TestcompoundVertices.py @@ -0,0 +1,52 @@ +# Copyright (C) 2014-2019 CEA/DEN, EDF R&D +# +# 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 +# + +from salome.shaper import model +from salome.shaper import geom +from ModelAPI import * + +import os + +aSession = ModelAPI_Session.get() + +def getFilePath(fileName): + path = os.path.join(os.getenv("SHAPER_ROOT_DIR"), "bin", "salome", "macros", "compoundVertices") + return os.path.join(path, fileName) + +theFile = getFilePath("compoundVertices.txt") + +aSession.startOperation("Create part for import") +aPartFeature = aSession.moduleDocument().addFeature("Part") +aSession.finishOperation() +aPart = aSession.activeDocument() + +aSession.startOperation("Import file") +aFeatureKind = "compoundVertices" +anImportFeature = aPart.addFeature(aFeatureKind) + +aFieldName = "file_path" +file = anImportFeature.string(aFieldName) +file.setValue(theFile) + +aSeparatorName = "separator" +separator = anImportFeature.string(aSeparatorName) +separator.setValue(" ") +aSession.finishOperation() + +assert(model.checkPythonDump()) diff --git a/src/PythonAddons/Test/TestimportParameters.py b/src/PythonAddons/Test/TestimportParameters.py new file mode 100644 index 000000000..3054c9b29 --- /dev/null +++ b/src/PythonAddons/Test/TestimportParameters.py @@ -0,0 +1,47 @@ +# Copyright (C) 2014-2019 CEA/DEN, EDF R&D +# +# 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 +# + +from salome.shaper import model +from salome.shaper import geom +from ModelAPI import * + +import os + +aSession = ModelAPI_Session.get() + +def getFilePath(fileName): + path = os.path.join(os.getenv("SHAPER_ROOT_DIR"), "bin", "salome", "macros", "importParameters") + return os.path.join(path, fileName) + +theFile = getFilePath("importParameters.txt") + +aSession.startOperation("Create part for import") +aPartFeature = aSession.moduleDocument().addFeature("Part") +aSession.finishOperation() +aPart = aSession.activeDocument() + +aSession.startOperation("Import file") +aFeatureKind = "importParameters" +anImportFeature = aPart.addFeature(aFeatureKind) +aFieldName = "file_path" +file = anImportFeature.string(aFieldName) +file.setValue(theFile) +aSession.finishOperation() + +assert(model.checkPythonDump()) diff --git a/src/PythonAddons/macros/compoundVertices/compoundVertices.txt b/src/PythonAddons/macros/compoundVertices/compoundVertices.txt new file mode 100644 index 000000000..114b8bd4f --- /dev/null +++ b/src/PythonAddons/macros/compoundVertices/compoundVertices.txt @@ -0,0 +1,18 @@ +21 16 224.00000000000003 +33 21 224.00000000000003 +35 38 224.00000000000003 +40 43 224.00000000000003 +53 43 224.00000000000003 +69 29 224.00000000000003 +97 58 224.00000000000003 +97 100 224.00000000000003 +80 127 224.00000000000003 +69 128 224.00000000000003 +63 116 224.00000000000003 +51 121 224.00000000000003 +44 137 224.00000000000003 +30 155 224.00000000000003 +23 158 224.00000000000003 +14 154 224.00000000000003 +18 76 224.00000000000003 +16 21 224.00000000000003 diff --git a/src/PythonAddons/macros/compoundVertices/feature.py b/src/PythonAddons/macros/compoundVertices/feature.py index 492594c4a..d089f7434 100644 --- a/src/PythonAddons/macros/compoundVertices/feature.py +++ b/src/PythonAddons/macros/compoundVertices/feature.py @@ -83,8 +83,8 @@ class compoundVertices(model.Feature): return x = float(coord[0]); y = float(coord[1]); z = float(coord[2]); 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()) + #vertex = model.addVertex(part, [point.result()]); vertex.execute(True); self.lfeatures.append(vertex) + lVertices.append(point.result()) file.close() compound = model.addCompound(part, lVertices) compound.execute(True); self.lfeatures.append(compound) diff --git a/src/PythonAddons/macros/importParameters/importParameters.txt b/src/PythonAddons/macros/importParameters/importParameters.txt new file mode 100644 index 000000000..c5babe823 --- /dev/null +++ b/src/PythonAddons/macros/importParameters/importParameters.txt @@ -0,0 +1,4 @@ +a 10 +b 12 +c 15 + -- 2.39.2