Commit 68abd3c9 by Christophe Geuzaine

Added new option Geometry.OCCTargetUnit to choose the target unit length when…

Added new option Geometry.OCCTargetUnit to choose the target unit length when importing step and iges files.

Set it to meter ("M") by default.

Warning: this changes the old behavior, which was to convert in millimeters (the OpenCASCADE default).
parent 8a0c1449
Pipeline #933 failed with stage
in 41 minutes 32 seconds
......@@ -78,6 +78,7 @@ struct contextGeometryOptions {
int occAutoFix, occFixDegenerated, occFixSmallEdges, occFixSmallFaces;
int occSewFaces, occParallel, occBooleanPreserveNumbering;
double occScaling;
std::string occTargetUnit;
int copyMeshingMethod, exactExtrusion;
int matchGeomAndMesh;
int orientedPhysicals, doubleClickedEntityTag;
......
......@@ -144,6 +144,11 @@ StringXString GeometryOptions_String[] = {
{ F|O, "DoubleClickedVolumeCommand" , opt_geometry_double_clicked_volume_command, "" ,
"Command parsed when double-clicking on a volume" },
{ F|O, "OCCTargetUnit" , opt_geometry_occ_target_unit , "M" ,
"Length unit to which coordinates from STEP and IGES files are converted to when "
"imported by OpenCASCADE (leave empty to keep the unit defined in the STEP and "
"IGES file)"},
{ 0, 0 , 0 , "" , 0 }
} ;
......
......@@ -1376,6 +1376,13 @@ std::string opt_geometry_double_clicked_volume_command(OPT_ARGS_STR)
return CTX::instance()->geom.doubleClickedVolumeCommand;
}
std::string opt_geometry_occ_target_unit(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->geom.occTargetUnit = val;
return CTX::instance()->geom.occTargetUnit;
}
std::string opt_solver_socket_name(OPT_ARGS_STR)
{
if(action & GMSH_SET)
......
......@@ -64,6 +64,7 @@ std::string opt_geometry_double_clicked_point_command(OPT_ARGS_STR);
std::string opt_geometry_double_clicked_line_command(OPT_ARGS_STR);
std::string opt_geometry_double_clicked_surface_command(OPT_ARGS_STR);
std::string opt_geometry_double_clicked_volume_command(OPT_ARGS_STR);
std::string opt_geometry_occ_target_unit(OPT_ARGS_STR);
std::string opt_solver_socket_name(OPT_ARGS_STR);
std::string opt_solver_name(OPT_ARGS_STR);
std::string opt_solver_name0(OPT_ARGS_STR);
......
......@@ -111,12 +111,6 @@ OCC_Internals::OCC_Internals()
for(int i = 0; i < 6; i++) _maxTag[i] = 0;
_changed = true;
_meshAttributes = new OCCMeshAttributesRTree(CTX::instance()->geom.tolerance);
// FIXME: check how we can change the handling of units in STEP, IGES and BREP
// files; by default I think we should convert to meters.
//Interface_Static::Init("XSTEP","xstep.cascade.unit",'&',"eval UIN");
//Interface_Static::SetCVal("xstep.cascade.unit", "M");
//Interface_Static::SetIVal ("read.scale.unit", 1);
}
OCC_Internals::~OCC_Internals()
......@@ -2631,6 +2625,13 @@ bool OCC_Internals::remove(const std::vector<std::pair<int, int> > &dimTags,
return ret;
}
static void setTargetUnit(std::string unit)
{
if(unit.empty()) return; // use unit specified in the file
if(!Interface_Static::SetCVal("xstep.cascade.unit", unit.c_str()))
Msg::Error("Could not set OpenCASCADE target unit '%s'", unit.c_str());
}
bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnly,
std::vector<std::pair<int, int> > &outDimTags,
const std::string &format)
......@@ -2659,6 +2660,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl
}
dummy_app->NewDocument("STEP-XCAF", step_doc);
STEPCAFControl_Reader reader;
setTargetUnit(CTX::instance()->geom.occTargetUnit);
if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not read file '%s'", fileName.c_str());
return false;
......@@ -2698,6 +2700,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl
result = step_shape_contents->GetShape(step_shapes.Value(1));
#else
STEPControl_Reader reader;
setTargetUnit(CTX::instance()->geom.occTargetUnit);
if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not read file '%s'", fileName.c_str());
return false;
......@@ -2711,6 +2714,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl
split[2] == ".iges" || split[2] == ".igs" ||
split[2] == ".IGES" || split[2] == ".IGS"){
IGESControl_Reader reader;
setTargetUnit(CTX::instance()->geom.occTargetUnit);
if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not read file '%s'", fileName.c_str());
return false;
......@@ -2782,6 +2786,7 @@ bool OCC_Internals::exportShapes(const std::string &fileName,
split[2] == ".step" || split[2] == ".stp" ||
split[2] == ".STEP" || split[2] == ".STP"){
STEPControl_Writer writer;
setTargetUnit(CTX::instance()->geom.occTargetUnit);
if(writer.Transfer(c, STEPControl_AsIs) == IFSelect_RetDone){
if(writer.Write(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not create file '%s'", fileName.c_str());
......
Geometry.OCCTargetUnit = "MM";
Merge "Kurbelwelle.stp";
Mesh.MinimumCirclePoints = 25;
Characteristic Length {23,34,22,42,40,41,58,63,7,4,61,69,71,73,3,6,38,39,24,28,29,35,36,37,78,80,88,86,77,74,90,85,82,19,12,10,1,25,27,92,18,17,54,57,53,32,65,66,55,11,94,60,67,2,8,64,33,52,59,56,5,9,15,16,93,30,51,13,14,84,83,91,76,75,81,79,87,89,44,45,31,46,20,26,50,49,72,70,68,62,47,48,21,43} = 2;
Geometry.OCCTargetUnit = "MM";
Merge "Zylkopf.stp";
Characteristic Length {1 ... 1000} = 1;
Characteristic Length {87,86,194,193,83,88,85,82,191,84,192,79,81,189,78,188,80,190,159,232,147,63,15,77,231,18,62,230,17,16,163,148,157,158,156,56,162,228,55,240,54,239,227,160,19,52,59,151,152,252,251,12,250,53,263,149,10,57,117,161,114,213,150,154,262,153,51,155,226,14,237,116,225,261,265,58,224,223,135,134,260,138,61,259,60,258,129,130,128,136,127,137,133,50,144,13,131,143,11,145,49,146,142,9,132,139,44,48,43,140,40,141,46,45,110,47,42,111,41} = .3;
......
Geometry.OCCTargetUnit = "MM";
Merge "linkrods.step";
//Characteristic Length {19,18,17,16,5,6,14,13,52,47,51,48,8,12,41,56,55,44,42,54,7,11,43,53,50,45,46,49,10,9,4,3,2,1,15} = 0.1;
//Characteristic Length {16,18,5,13,51,52,19,56,17,14,55,12,48,47,6,41,44,8,53,54,11,50,49,45,10,46,42,43,9,7,4,2,3,15,1} = 0.1;
......
Merge "Block.stp";
SetFactory("OpenCASCADE");
Geometry.OCCTargetUnit = "MM";
Merge "Block.stp";
Wedge(2) = {-32, -2.1, -15.5, 40, 40, 60, 0};
//+
BooleanIntersection{ Volume{2}; Delete; }{ Volume{1}; Delete; }
......
Geometry.OCCTargetUnit = "MM";
Merge "Solid_56.step";
Mesh.CharacteristicLengthMax = 3;
Mesh.CharacteristicLengthFromCurvature = 1;
......
Geometry.OCCTargetUnit = "MM";
Merge "io1-pe-203.step";
......
......@@ -9,6 +9,7 @@ Mesh.CharacteristicLengthMax = 4.0; //-clmax
Mesh.MinimumCirclePoints=15; //default=7
//Mesh.CharacteristicLengthExtendFromBoundary=0;
Geometry.OCCTargetUnit = "MM";
Merge "linkrods.step";
//Characteristic Length {5} = 0.001;
Mesh.CharacteristicLengthFactor=.2;
Mesh.CharacteristicLengthMin = 0.25; //-clmin
Mesh.CharacteristicLengthMax = 4.0; //-clmax
Geometry.OCCTargetUnit = "MM";
Merge "linkrods.step";
......@@ -26,10 +30,10 @@ tmp[] = Extrude {0, 0, (zmax - zmin) + 2 * l} {
};
Delete { Volume{tmp[1]}; }
Surface Loop(10029) = {10027,10006,10015,10019,10023,10028};
Surface Loop(10029) = {10027,10006,10015,10019,10023,10028};
Surface Loop(10030) = {7,9,10,11,8,6,28,26,36,15,2,4,5,12,3,1,13,24,23,14,
16,22,21,18,20,37,34,19,17,35,31,33,32,30,29,27,25};
Volume(10031) = {10029,10030};
16,22,21,18,20,37,34,19,17,35,31,33,32,30,29,27,25};
Volume(10031) = {10029,10030};
//Mesh.CharacteristicLengthFactor = 0.3;
SetFactory("OpenCASCADE");
Mesh.CharacteristicLengthMin = 1;
Mesh.CharacteristicLengthMax = 1;
Mesh.CharacteristicLengthMin = 1e-3;
Mesh.CharacteristicLengthMax = 1e-3;
a() = ShapeFromFile("component8.step");
......
......@@ -2,6 +2,7 @@ SetFactory("OpenCASCADE");
Mesh.CharacteristicLengthMin = 3;
Mesh.CharacteristicLengthMax = 3;
Geometry.OCCTargetUnit = "MM";
DefineConstant[
z = {16, Name "Parameters/z position of box"}
......
SetFactory("OpenCASCADE");
Mesh.CharacteristicLengthMin = 3;
Mesh.CharacteristicLengthMax = 3;
Mesh.CharacteristicLengthMin = 3e-3;
Mesh.CharacteristicLengthMax = 3e-3;
Geometry.OCCTargetUnit = "M";
DefineConstant[
angle = {90, Name "Parameters/wedge angle"}
......@@ -9,6 +10,6 @@ DefineConstant[
a() = ShapeFromFile("component8.step");
Cylinder(2) = {0,150,0, 0,200,0, 40, angle*2*Pi/360};
Cylinder(2) = {0,0.15,0, 0,0.2,0, 0.04, angle*2*Pi/360};
BooleanIntersection{ Volume{a(0)}; Delete; }{ Volume{2}; Delete; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment