From: mpv Date: Fri, 14 Feb 2020 12:53:55 +0000 (+0300) Subject: Added unit-tests for SHAPERSTUDY and SMESH check X-Git-Tag: V9_5_0a1~17^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Focc%2Fshaper2smesh;p=modules%2Fshaper.git Added unit-tests for SHAPERSTUDY and SMESH check --- diff --git a/src/ConnectorAPI/Test/TestShaperStudy2.py b/src/ConnectorAPI/Test/TestShaperStudy2.py new file mode 100644 index 000000000..6b370491a --- /dev/null +++ b/src/ConnectorAPI/Test/TestShaperStudy2.py @@ -0,0 +1,116 @@ +# 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 +# + +import os +import sys +import salome + +salome.salome_init() + +#========================================================================= +# A function to get the XAO file path +#========================================================================= +def getPath(path): + shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes") + return os.path.join(shapes_dir, path) + +### +### SHAPER component +### + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(147.3929660820667, 79.1580464539047, 58.09363834643254, 79.1580464539047) +SketchLine_2 = Sketch_1.addLine(58.09363834643254, 79.1580464539047, 58.09363834643254, 8.969712804393431) +SketchLine_3 = Sketch_1.addLine(58.09363834643254, 8.969712804393431, 147.3929660820667, 8.969712804393431) +SketchLine_4 = Sketch_1.addLine(147.3929660820667, 8.969712804393431, 147.3929660820667, 79.1580464539047) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), 150, 0) +Extrusion_1.setName("Box") +Extrusion_1.result().setName("Box") +Group_1 = model.addGroup(Part_1_doc, "Vertices", [model.selection("VERTEX", "[Box/Generated_Face&Sketch_1/SketchLine_1][Box/Generated_Face&Sketch_1/SketchLine_2][Box/To_Face]"), model.selection("VERTEX", "[Box/Generated_Face&Sketch_1/SketchLine_3][Box/Generated_Face&Sketch_1/SketchLine_4][Box/To_Face]")]) +Group_1.setName("VerticesGroup") +Group_1.result().setName("VerticesGroup") +Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box/Generated_Face&Sketch_1/SketchLine_4"), model.selection("FACE", "Box/Generated_Face&Sketch_1/SketchLine_3")]) +Group_2.setName("FacesGroup") +Group_2.result().setName("FacesGroup") +Field_1 = model.addField(Part_1_doc, 1, "DOUBLE", 3, ["Comp 1", "Comp 2", "Comp 3"], [model.selection("EDGE", "[Box/Generated_Face&Sketch_1/SketchLine_2][Box/Generated_Face&Sketch_1/SketchLine_3]")]) +Field_1.setName("MyField") +Field_1.result().setName("MyField") +Field_1.addStep(0, 0, [[0, 0, 0], [1, 1.5, 37.2]]) + +model.end() + +### +### SHAPERSTUDY component +### + +if 'model' in globals(): + model.publishToShaperStudy() +import SHAPERSTUDY +Box, VerticesGroup, FacesGroup, MyField, = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1)) +Box_1, VerticesGroup_1, FacesGroup_1, MyField_1, = SHAPERSTUDY.archive(Box, getPath("Xao/TestShaperStudy2.xao")) +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New() +#smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: + # multiples meshes built in parallel, complex and numerous mesh edition (performance) + +Mesh_1 = smesh.Mesh(Box) +Regular_1D = Mesh_1.Segment() +Number_of_Segments_1 = Regular_1D.NumberOfSegments(4) +MEFISTO_2D = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO) +Length_From_Edges_1 = MEFISTO_2D.LengthFromEdges() +MEFISTO_2D_1 = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO,geom=FacesGroup) +Max_Element_Area_1 = MEFISTO_2D_1.MaxElementArea(2) +Mesh_1.Compute() +Mesh_1.GetMesh().ReplaceShape( Box_1 ) +SHAPERSTUDY.breakLinkForSubElements(salome.ObjectToSObject(Mesh_1.GetMesh()), Box_1) +Mesh_1.Clear() +Sub_mesh_1 = MEFISTO_2D_1.GetSubMesh() + + +## Set names of Mesh objects +smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D') +smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D') +smesh.SetName(Number_of_Segments_1, 'Number of Segments_1') +smesh.SetName(Max_Element_Area_1, 'Max. Element Area_1') +smesh.SetName(Length_From_Edges_1, 'Length From Edges_1') +smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') +smesh.SetName(Sub_mesh_1, 'Sub-mesh_1') + +assert(Mesh_1.Compute()) diff --git a/src/ConnectorAPI/Test/TestShaperStudy3.py b/src/ConnectorAPI/Test/TestShaperStudy3.py new file mode 100644 index 000000000..991c333b6 --- /dev/null +++ b/src/ConnectorAPI/Test/TestShaperStudy3.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python + +### +### This file is generated automatically by SALOME v9.4.0 with dump python functionality +### + +import os +import sys +import salome + +salome.salome_init() + +#========================================================================= +# A function to get the XAO file path +#========================================================================= +def getPath(path): + shapes_dir = os.path.join(os.getenv("DATA_DIR"), "Shapes") + return os.path.join(shapes_dir, path) + +### +### SHAPER component +### + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Param_H = model.addParameter(Part_1_doc, "h", "20") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchLine_1 = Sketch_1.addLine(75.09305815883349, 77.46634028730745, 23.30071943952229, 77.46634028730745) +SketchLine_2 = Sketch_1.addLine(23.30071943952229, 77.46634028730745, 23.30071943952229, 23.93663846925804) +SketchLine_3 = Sketch_1.addLine(23.30071943952229, 23.93663846925804, 75.09305815883349, 23.93663846925804) +SketchLine_4 = Sketch_1.addLine(75.09305815883349, 23.93663846925804, 75.09305815883349, 77.46634028730745) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f")], model.selection(), "h", 0) + +model.end() + +### +### SHAPERSTUDY component +### + +if 'model' in globals(): + model.publishToShaperStudy() +import SHAPERSTUDY +Extrusion_1_1, = SHAPERSTUDY.shape(model.featureStringId(Extrusion_1)) +Extrusion_1_1_1, = SHAPERSTUDY.archive(Extrusion_1_1, getPath("Xao/TestShaperStudy2.xao")) +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New() +#smesh.SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations: + # multiples meshes built in parallel, complex and numerous mesh edition (performance) + +Mesh_1 = smesh.Mesh(Extrusion_1_1) +Cartesian_3D = Mesh_1.BodyFitted() +Body_Fitting_Parameters_1 = Cartesian_3D.SetGrid([ [ '7.71225' ], [ 0, 1 ]],[ [ '7.71225' ], [ 0, 1 ]],[ [ '7.71225' ], [ 0, 1 ]],4,0) +Body_Fitting_Parameters_1.SetFixedPoint( SMESH.PointStruct ( 0, 0, 0 ), 1 ) +Body_Fitting_Parameters_1.SetAxesDirs( SMESH.DirStruct( SMESH.PointStruct ( 1, 0, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 1, 0 )), SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 1 )) ) +isDone = Mesh_1.Compute() +Mesh_2 = smesh.Mesh(Extrusion_1_1) +Regular_1D = Mesh_2.Segment() +Number_of_Segments_1 = Regular_1D.NumberOfSegments(7) +MEFISTO_2D = Mesh_2.Triangle(algo=smeshBuilder.MEFISTO) +Max_Element_Area_1 = MEFISTO_2D.MaxElementArea(20) +SHAPERSTUDY.breakLinkForSubElements(salome.ObjectToSObject(Mesh_2.GetMesh()), Extrusion_1_1_1) +Mesh_2.GetMesh().ReplaceShape( Extrusion_1_1_1 ) +isDone = Mesh_2.Compute() + + +## Set names of Mesh objects +smesh.SetName(Cartesian_3D.GetAlgorithm(), 'Cartesian_3D') +smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D') +smesh.SetName(MEFISTO_2D.GetAlgorithm(), 'MEFISTO_2D') +smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') +smesh.SetName(Mesh_2.GetMesh(), 'Mesh_2') +smesh.SetName(Max_Element_Area_1, 'Max. Element Area_1') +smesh.SetName(Body_Fitting_Parameters_1, 'Body Fitting Parameters_1') +smesh.SetName(Number_of_Segments_1, 'Number of Segments_1') + +# check on update of the initial box Mesh_1 computed on it is changed, Mesh_2 on dead shape is unchanged +aNb1 = Mesh_1.NbElements() +aNb2 = Mesh_2.NbElements() +model.begin() +Param_H.setValue(50) +model.end() +model.publishToShaperStudy() +assert(Mesh_1.Compute()) +assert(Mesh_1.NbElements() > aNb1) +assert(Mesh_2.Compute()) +assert(Mesh_2.NbElements() == aNb2) diff --git a/src/ConnectorAPI/Test/tests.set b/src/ConnectorAPI/Test/tests.set index 65561a4e3..fcd2f7f1c 100644 --- a/src/ConnectorAPI/Test/tests.set +++ b/src/ConnectorAPI/Test/tests.set @@ -26,4 +26,6 @@ SET(TEST_NAMES Test2882 Test17917 TestShaperStudy1 + TestShaperStudy2 + TestShaperStudy3 )