From: Christophe Bourcier Date: Tue, 19 Nov 2024 13:33:11 +0000 (+0100) Subject: Fix gradation: X-Git-Tag: V9_14_0a2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9aa34f3fca9bbeb99f16d552aa33dfb91c8c0f52;p=plugins%2Fhybridplugin.git Fix gradation: - could not set decimal values in GUI (locale language was used) - could not set gradation in python --- diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx index 314f693..e99cdd9 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis.cxx @@ -23,6 +23,7 @@ // Author : Edward AGAPOV (eap) //============================================================================= // +#include #include "HYBRIDPlugin_Hypothesis.hxx" #include @@ -1430,7 +1431,7 @@ bool HYBRIDPlugin_Hypothesis::DefaultToRemoveCentralPoint() double HYBRIDPlugin_Hypothesis::DefaultGradation() { - return 1.05; + return 2; } //======================================================================= @@ -2418,7 +2419,13 @@ double HYBRIDPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk ) if ( str.empty() ) throw std::invalid_argument("Empty value provided"); char * endPtr; + // Save locale setting + const std::string oldLocale=std::setlocale(LC_NUMERIC, nullptr); + // Force '.' as the radix point, otherwise it is comma in French and "1.2" will result to 1 + std::setlocale(LC_NUMERIC,"C"); double val = strtod(&str[0], &endPtr); + // Restore locale setting + std::setlocale(LC_NUMERIC, oldLocale.c_str()); bool ok = (&str[0] != endPtr); if ( isOk ) *isOk = ok; diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx index 818bd6e..0299b3a 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_Hypothesis_i.cxx @@ -853,7 +853,7 @@ char* HYBRIDPlugin_Hypothesis_i::GetAdvancedOption() } //======================================================================= -//function : SetToRemoveCentralPoint +//function : SetGradation //======================================================================= void HYBRIDPlugin_Hypothesis_i::SetGradation(CORBA::Double gradation) @@ -861,14 +861,14 @@ void HYBRIDPlugin_Hypothesis_i::SetGradation(CORBA::Double gradation) if (gradation <= 1) THROW_SALOME_CORBA_EXCEPTION( "The volumic gradation must be > 1",SALOME::BAD_PARAM ); ASSERT(myBaseImpl); - if (gradation != GetGradation()) { - this->GetImpl()->SetGradation(gradation); + this->GetImpl()->SetGradation(gradation); + if (gradation != this->GetImpl()->DefaultGradation()) { SMESH::TPythonDump() << _this() << ".SetGradation( " << gradation << " )"; } } //======================================================================= -//function : GetToRemoveCentralPoint +//function : GetGradation //======================================================================= CORBA::Double HYBRIDPlugin_Hypothesis_i::GetGradation() diff --git a/tests/gradation.py b/tests/gradation.py new file mode 100644 index 0000000..544c072 --- /dev/null +++ b/tests/gradation.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python + +import sys +import salome + +salome.salome_init() + +### +### SHAPER component +### + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() + +### Create Part +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +model.addParameter(Part_1_doc, "c", '1') +model.addParameter(Part_1_doc, "r", '2') + +### Create Box +Box_1 = model.addBox(Part_1_doc, "c", "c", "c") + +### Create Translation +Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], vector = ["-c/2", "-c/2", "-c/2"], keepSubResults = True) + +### Create Sphere +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), "r") + +### Create Cut +Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Sphere_1_1")], [model.selection("SOLID", "Translation_1_1")], keepSubResults = True) + +### Create Group +Group_1_objects = [model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Left"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Front"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Top"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Bottom"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Back"), + model.selection("FACE", "Translation_1_1/MF:Translated&Box_1_1/Right")] +Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects) +Group_1.setName("box_faces") +Group_1.result().setName("box_faces") + +### Create Group +Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Sphere_1_1/Face_1")]) +Group_2.setName("sphere_face") +Group_2.result().setName("sphere_face") + +model.end() + +### +### SHAPERSTUDY component +### + +model.publishToShaperStudy() +import SHAPERSTUDY +Cut_1_1, box_faces, sphere_face, = SHAPERSTUDY.shape(model.featureStringId(Cut_1)) +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New() + +Mesh_1 = smesh.Mesh(Cut_1_1,'Mesh_1') + +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +Regular_1D = Mesh_1.Segment(geom=box_faces) +Number_of_Segments_1 = Regular_1D.NumberOfSegments(10) +Quadrangle_2D = Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE,geom=box_faces) +MG_Hybrid = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_1 = MG_Hybrid.Parameters() +isDone = Mesh_1.Compute() +Mesh_1.CheckCompute() + +box_faces_1 = Mesh_1.GroupOnGeom(box_faces,'box_faces',SMESH.FACE) +sphere_face_1 = Mesh_1.GroupOnGeom(sphere_face,'sphere_face',SMESH.FACE) + +nb_vol = Mesh_1.NbVolumes() +print("nb_vol: ", nb_vol) + +# in 9.13 +#nb_vol: 6533 + +# change gradation (default is 2) +MG_Hybrid_Parameters_1.SetGradation( 1.05 ) +isDone = Mesh_1.Compute() +Mesh_1.CheckCompute() + +# should now have more elements +#nb_vol: 17760 + +new_nb_vol = Mesh_1.NbVolumes() +print("new_nb_vol: ", new_nb_vol) + +assert new_nb_vol > 2*nb_vol, "SetGradation has failed" + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser() diff --git a/tests/tests.set b/tests/tests.set index 7f87c93..0b49bec 100644 --- a/tests/tests.set +++ b/tests/tests.set @@ -25,4 +25,5 @@ SET(TEST_NAMES layers_with_snapping mg_hybrid_pyramids advanced_text_option + gradation )