]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
Add PreCAD
authorgdd <gdd>
Tue, 26 Jul 2011 17:19:50 +0000 (17:19 +0000)
committergdd <gdd>
Tue, 26 Jul 2011 17:19:50 +0000 (17:19 +0000)
TODO: GUI to PreCAD options

adm_local/unix/config_files/check_BLSURF.m4
idl/BLSURFPlugin_Algorithm.idl
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx
src/GUI/BLSURFPluginGUI_HypothesisCreator.cxx
src/GUI/BLSURFPlugin_msg_en.ts
src/GUI/BLSURFPlugin_msg_fr.ts

index 37558e22719c72402c8fc1ff636daeacc4f983ee..7c813cc7ec6efc007534f07b691922a338b49ae1 100644 (file)
@@ -60,10 +60,10 @@ if test "$with_blsurf" != "no" ; then
     echo
 
     LOCAL_INCLUDES="-I$BLSURF_HOME/include"
-    LOCAL_LIBS="-L$BLSURF_HOME/lib -lBLSurf"
+    LOCAL_LIBS="-L$BLSURF_HOME/lib -lBLSurf -lPreCAD"
     if test $(`which arch`) = x86_64 ; then
       if test -f $BLSURF_HOME/lib/Linux_64/libBLSurf.so ; then
-        LOCAL_LIBS="-L$BLSURF_HOME/lib/Linux_64 -lBLSurf -ldistene"
+        LOCAL_LIBS="-L$BLSURF_HOME/lib/Linux_64 -lBLSurf -ldistene -lPreCAD"
       fi
     fi
 
index 9a3cae140d8fe23473d4fc8057e5ed5d3639076b..ddfdeca1d06d51b3106de84d134dc10f43be2e9a 100644 (file)
@@ -123,6 +123,7 @@ module BLSURFPlugin
      * Sets topology usage way defining how mesh conformity is assured
      * value=0 - mesh conformity is assured by conformity of a shape
      * value=1,2 - mesh conformity is assured by pre-processing a CAD model
+     * value=3 - mesh conformity is assured by pre-processing a CAD model with Pre-CAD
      */
     void SetTopology(in long way);
     long GetTopology();
index 779fcb00349bba8006a4d5962c80b3484f1378e0..8a10a63c92fbea89967ff3f9277226bba12eee43 100644 (file)
@@ -31,6 +31,7 @@
 extern "C"{
 #include <distene/api.h>
 #include <distene/blsurf.h>
+#include <distene/precad.h>
 }
 
 #include <structmember.h>
@@ -665,7 +666,10 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction
 
 void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
                                         blsurf_session_t *             bls,
-                                        SMESH_Mesh&                   mesh)
+                                        precad_session_t *             pcs,
+                                        SMESH_Mesh&                   mesh,
+                                        bool *                  use_precad
+                                       )
 {
   int    _topology      = BLSURFPlugin_Hypothesis::GetDefaultTopology();
   int    _physicalMesh  = BLSURFPlugin_Hypothesis::GetDefaultPhysicalMesh();
@@ -678,6 +682,13 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
   bool   _decimesh      = BLSURFPlugin_Hypothesis::GetDefaultDecimesh();
   int    _verb          = BLSURFPlugin_Hypothesis::GetDefaultVerbosity();
 
+  // PreCAD
+  int _precadOptimCad     = BLSURFPlugin_Hypothesis::GetDefaultPreCADOptimCAD();
+  int _precadDiscardInput = BLSURFPlugin_Hypothesis::GetDefaultPreCADDiscardInput();
+  int _precadManifoldGeom = BLSURFPlugin_Hypothesis::GetDefaultPreCADManifoldGeom();
+  int _precadClosedGeom   = BLSURFPlugin_Hypothesis::GetDefaultPreCADClosedGeom();
+
+
   if (hyp) {
     MESSAGE("BLSURFPlugin_BLSURF::SetParameters");
     _topology      = (int) hyp->GetTopology();
@@ -690,7 +701,6 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
     _quadAllowed   = hyp->GetQuadAllowed();
     _decimesh      = hyp->GetDecimesh();
     _verb          = hyp->GetVerbosity();
-
     if ( hyp->GetPhyMin() != ::BLSURFPlugin_Hypothesis::undefinedDouble() )
       blsurf_set_param(bls, "hphymin", to_string(hyp->GetPhyMin()).c_str());
     if ( hyp->GetPhyMax() != ::BLSURFPlugin_Hypothesis::undefinedDouble() )
@@ -708,21 +718,47 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
         blsurf_set_param(bls, opIt->first.c_str(), opIt->second.c_str());
       }
 
+    // PreCAD
+    _precadOptimCad = hyp->GetPreCADOptimCAD();
+    _precadDiscardInput = hyp->GetPreCADDiscardInput();
+    _precadManifoldGeom = hyp->GetPreCADManifoldGeom();
+    _precadClosedGeom = hyp->GetPreCADClosedGeom();
+    
   } else {
     //0020968: EDF1545 SMESH: Problem in the creation of a mesh group on geometry
     // GetDefaultPhySize() sometimes leads to computation failure
     _phySize = mesh.GetShapeDiagonalSize() / _gen->GetBoundaryBoxSegmentation();
     MESSAGE("BLSURFPlugin_BLSURF::SetParameters using defaults");
   }
+  
+  // PreCAD
+  if (_topology == BLSURFPlugin_Hypothesis::PreCAD) {
+    *use_precad = true;
+    precad_set_param(pcs, "verbose",                to_string(_verb).c_str());
+
+    precad_set_param(pcs, "merge_edges",            _precadOptimCad > 0 ? "1" : "0");
+    precad_set_param(pcs, "remove_nano_edges",      _precadOptimCad > 0 ? "1" : "0");
+    precad_set_param(pcs, "discard_input_topology", _precadDiscardInput ? "1" : "0");
+    precad_set_param(pcs, "manifold_geometry",      _precadManifoldGeom ? "1" : "0");
+    precad_set_param(pcs, "closed_geometry",        _precadClosedGeom ? "1" : "0");
+    /*
+    precad_set_param(pcs, "merge_edges",            "0");
+    precad_set_param(pcs, "remove_nano_edges",      "0");
+    precad_set_param(pcs, "discard_input_topology", "0");
+    precad_set_param(pcs, "manifold_geometry",      "0");
+    precad_set_param(pcs, "closed_geometry",        "0");
+    */
+  }
+  
   _smp_phy_size = _phySize;
-  blsurf_set_param(bls, "topo_points",       _topology > 0 ? "1" : "0");
-  blsurf_set_param(bls, "topo_curves",       _topology > 0 ? "1" : "0");
-  blsurf_set_param(bls, "topo_project",      _topology > 0 ? "1" : "0");
-  blsurf_set_param(bls, "clean_boundary",    _topology > 1 ? "1" : "0");
-  blsurf_set_param(bls, "close_boundary",    _topology > 1 ? "1" : "0");
+  blsurf_set_param(bls, "topo_points",       _topology == BLSURFPlugin_Hypothesis::Process || _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0");
+  blsurf_set_param(bls, "topo_curves",       _topology == BLSURFPlugin_Hypothesis::Process || _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0");
+  blsurf_set_param(bls, "topo_project",      _topology == BLSURFPlugin_Hypothesis::Process || _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0");
+  blsurf_set_param(bls, "clean_boundary",    _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0");
+  blsurf_set_param(bls, "close_boundary",    _topology == BLSURFPlugin_Hypothesis::Process2 ? "1" : "0");
   blsurf_set_param(bls, "hphy_flag",         to_string(_physicalMesh).c_str());
-//  blsurf_set_param(bls, "hphy_flag",         "2");
-  if ((to_string(_physicalMesh))=="2"){
+
+  if (_physicalMesh == BLSURFPlugin_Hypothesis::SizeMap){
     TopoDS_Shape GeomShape;
     TopoDS_Shape AttShape;
     TopAbs_ShapeEnum GeomType;
@@ -976,9 +1012,9 @@ void BLSURFPlugin_BLSURF::SetParameters(const BLSURFPlugin_Hypothesis* hyp,
   blsurf_set_param(bls, "patch_independent", _decimesh ? "1" : "0");
   blsurf_set_param(bls, "element",           _quadAllowed ? "q1.0" : "p1");
   blsurf_set_param(bls, "verb",              to_string(_verb).c_str());
-#ifdef _DEBUG_
-  blsurf_set_param(bls, "debug",             "1");
-#endif
+// #ifdef _DEBUG_
+//   blsurf_set_param(bls, "debug",             "1");
+// #endif
 }
 
 status_t curv_fun(real t, real *uv, real *dt, real *dtt, void *user_data);
@@ -1024,8 +1060,6 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   /* create the CAD object we will work on. It is associated to the context ctx. */
   cad_t *c = cad_new(ctx);
 
-  blsurf_session_t *bls = blsurf_session_new(ctx);
-
   FacesWithSizeMap.Clear();
   FaceId2SizeMap.clear();
   FaceId2ClassAttractor.clear();
@@ -1035,15 +1069,26 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   VerticesWithSizeMap.Clear();
   VertexId2SizeMap.clear();
 
-  MESSAGE("BEGIN SetParameters");
-  SetParameters(_hypothesis, bls, aMesh);
-  MESSAGE("END SetParameters");
 
   /* Now fill the CAD object with data from your CAD
    * environement. This is the most complex part of a successfull
    * integration.
    */
 
+  // PreCAD
+  // If user requests it, send the CAD through Distene preprocessor : PreCAD
+  cad_t *cleanc = NULL;
+  precad_session_t *pcs = precad_session_new(ctx);
+  precad_data_set_cad(pcs, c);
+  
+  blsurf_session_t *bls = blsurf_session_new(ctx);
+
+  MESSAGE("BEGIN SetParameters");
+  bool use_precad = false;
+  SetParameters(_hypothesis, bls, pcs, aMesh, &use_precad);
+  MESSAGE("END SetParameters");
+  
+  
   // needed to prevent the opencascade memory managmement from freeing things
   vector<Handle(Geom2d_Curve)> curves;
   vector<Handle(Geom_Surface)> surfaces;
@@ -1074,7 +1119,9 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
   int iface = 0;
   string bad_end = "return";
   int faceKey = -1;
-  int ienf = 0;
+  TopTools_IndexedMapOfShape _map;
+  TopExp::MapShapes(aShape,TopAbs_VERTEX,_map);
+  int ienf = _map.Extent();
   BLSURFPlugin_Attractor myAttractor;
   for (TopExp_Explorer face_iter(aShape,TopAbs_FACE);face_iter.More();face_iter.Next()) {
     TopoDS_Face f=TopoDS::Face(face_iter.Current());
@@ -1116,7 +1163,7 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
       
       
       if (FaceId2SizeMap.find(faceKey)!=FaceId2SizeMap.end()){
-       MESSAGE("A size map is defined on face :"<<faceKey)
+        MESSAGE("A size map is defined on face :"<<faceKey)
         theSizeMapStr = FaceId2SizeMap[faceKey];
         // check if function ends with "return"
         if (theSizeMapStr.find(bad_end) == (theSizeMapStr.size()-bad_end.size()-1))
@@ -1354,8 +1401,35 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
 
 
   PyGILState_Release(gstate);
-
-  blsurf_data_set_cad(bls, c);
+  
+  if (use_precad){
+    /* Now launch the PreCAD process */
+    status = precad_process(pcs);
+    if(status != STATUS_OK){
+      cout << "PreCAD processing failed with error code " << status << "\n";
+      // Now we can delete the PreCAD session 
+      precad_session_delete(pcs);
+    }
+    else {
+      // retrieve the pre-processed CAD object 
+      cleanc = precad_new_cad(pcs);
+      if(!cleanc){
+        cout << "Unable to retrieve PreCAD result \n";
+      }
+      
+      // Now we can delete the PreCAD session 
+      precad_session_delete(pcs);
+    }
+  }
+  
+  if (cleanc) {
+    // Give the pre-processed CAD object to the current BLSurf session
+    blsurf_data_set_cad(bls, cleanc);
+  }
+  else {
+    // Use the original one
+    blsurf_data_set_cad(bls, c);
+  }
 
   std::cout << std::endl;
   std::cout << "Beginning of Surface Mesh generation" << std::endl;
@@ -1499,11 +1573,6 @@ bool BLSURFPlugin_BLSURF::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
           MESSAGE("Group name is empty: '"<<currentEnfVertex->grpName<<"' => group is not created");
       }
     }
-#ifdef _DEBUG_
-    else
-      MESSAGE("No enforced vertex found @ " << xyz[0] << ", " << xyz[1] << ", " << xyz[2]);
-#endif
-
 
 
     // internal point are tagged to zero
index 6e81b2a4c00d2dd1bc943d9a657735cca90ddd44..4c90a3c4339d164504be0e7f0f7765352063703f 100644 (file)
@@ -49,6 +49,7 @@
 extern "C"{
 #include "distene/blsurf.h"
 #include "distene/api.h"
+#include "distene/precad.h"
 }
 
 #include <BRepClass_FaceClassifier.hxx>
@@ -70,7 +71,7 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
                                  const TopoDS_Shape&                  aShape,
                                  SMESH_Hypothesis::Hypothesis_Status& aStatus);
 
-    void SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsurf_session_t *bls,SMESH_Mesh& aMesh);
+    void SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsurf_session_t *bls, precad_session_t *pcs, SMESH_Mesh& aMesh, bool *use_precad);
 
     virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
 
index 41d3d058ddd82f620da26b69fb1125e29bf55ccc..7fb73c95c7ece9802ea7f50b6e46d87716a93e58 100644 (file)
@@ -55,6 +55,10 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _quadAllowed(GetDefaultQuadAllowed()),
   _decimesh(GetDefaultDecimesh()),
   _verb(GetDefaultVerbosity()),
+  _preCADOptimCAD(GetDefaultPreCADOptimCAD()),
+  _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
+  _preCADManifoldGeom(GetDefaultPreCADManifoldGeom()),
+  _preCADClosedGeom(GetDefaultPreCADClosedGeom()),
   _sizeMap(GetDefaultSizeMap()),
   _attractors(GetDefaultSizeMap()),
   _classAttractors(GetDefaultAttractorMap()),
@@ -260,6 +264,39 @@ void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
     NotifySubMeshesHypothesisModification();
   }
 }
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetPreCADOptimCAD(bool theVal) {
+  if (theVal != _preCADOptimCAD) {
+    _preCADOptimCAD = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal) {
+  if (theVal != _preCADDiscardInput) {
+    _preCADDiscardInput = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetPreCADManifoldGeom(bool theVal) {
+  if (theVal != _preCADManifoldGeom) {
+    _preCADManifoldGeom = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetPreCADClosedGeom(bool theVal) {
+  if (theVal != _preCADClosedGeom) {
+    _preCADClosedGeom = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
     throw (std::invalid_argument) {
@@ -918,6 +955,7 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
       << _angleMeshS << " " << _gradation << " " << (int) _quadAllowed << " " << (int) _decimesh;
   save << " " << _phyMin << " " << _phyMax << " " << _angleMeshC << " " << _hgeoMin << " " << _hgeoMax << " " << _verb;
+  save << " " << (int) _preCADOptimCAD << " " << (int) _preCADDiscardInput << " " << (int) _preCADManifoldGeom << " " << (int) _preCADClosedGeom;
 
   TOptionValues::iterator op_val = _option2value.begin();
   if (op_val != _option2value.end()) {
@@ -1105,6 +1143,30 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   else
     load.clear(std::ios::badbit | load.rdstate());
 
+  isOK = (load >> i);
+  if (isOK)
+    _preCADOptimCAD = (bool) i;
+  else
+    load.clear(std::ios::badbit | load.rdstate());
+
+  isOK = (load >> i);
+  if (isOK)
+    _preCADDiscardInput = (bool) i;
+  else
+    load.clear(std::ios::badbit | load.rdstate());
+
+  isOK = (load >> i);
+  if (isOK)
+    _preCADManifoldGeom = (bool) i;
+  else
+    load.clear(std::ios::badbit | load.rdstate());
+
+  isOK = (load >> i);
+  if (isOK)
+    _preCADClosedGeom = (bool) i;
+  else
+    load.clear(std::ios::badbit | load.rdstate());
+
   std::string option_or_sm;
   bool hasOptions = false;
   bool hasSizeMap = false;
index f136089f2cc2501714749dbeeea7d465e35ed747..c2681482086aef7d75f2417c9f0ebe743ce8309b 100644 (file)
@@ -48,7 +48,8 @@ public:
   enum Topology {
     FromCAD,
     Process,
-    Process2
+    Process2,
+    PreCAD
   };
 
   enum PhysicalMesh {
@@ -109,6 +110,18 @@ public:
   void ClearEntry(const std::string& entry);
   void ClearSizeMaps();
 
+  void SetPreCADOptimCAD(bool theVal);
+  bool GetPreCADOptimCAD() const { return _preCADOptimCAD; }
+
+  void SetPreCADDiscardInput(bool theVal);
+  bool GetPreCADDiscardInput() const { return _preCADDiscardInput; }
+
+  void SetPreCADManifoldGeom(bool theVal);
+  bool GetPreCADManifoldGeom() const { return _preCADManifoldGeom; }
+
+  void SetPreCADClosedGeom(bool theVal);
+  bool GetPreCADClosedGeom() const { return _preCADClosedGeom; }
+    
   typedef std::map<std::string,std::string> TSizeMap;
 
   void SetSizeMapEntry(const std::string& entry,const std::string& sizeMap );
@@ -272,6 +285,12 @@ public:
   static bool            GetDefaultQuadAllowed();
   static bool            GetDefaultDecimesh();
   static int             GetDefaultVerbosity() { return 10; }
+  // PreCAD
+  static bool            GetDefaultPreCADOptimCAD() { return false; }
+  static bool            GetDefaultPreCADDiscardInput() { return false; }
+  static bool            GetDefaultPreCADManifoldGeom() { return false; }
+  static bool            GetDefaultPreCADClosedGeom() { return false; }
+  
   static TSizeMap        GetDefaultSizeMap() { return TSizeMap();}
   static TAttractorMap   GetDefaultAttractorMap() { return TAttractorMap(); }
 
@@ -330,6 +349,12 @@ private:
   bool            _quadAllowed;
   bool            _decimesh;
   int             _verb;
+  
+  bool            _preCADOptimCAD;
+  bool            _preCADDiscardInput;
+  bool            _preCADManifoldGeom;
+  bool            _preCADClosedGeom;
+  
   TOptionValues   _option2value;
   TOptionNames    _doubleOptions, _charOptions;
   TSizeMap        _sizeMap;
index 628681eb5f7de24e8b250f8e749bb1bf10d35a9c..6828af0ef814bdf06e242fafaa5cdd5465258b19 100644 (file)
@@ -84,7 +84,8 @@
 enum Topology {
     FromCAD,
     Process,
-    Process2
+    Process2,
+    PreCAD
   } ;
 
 enum PhysicalMesh
@@ -734,7 +735,10 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
 
   myTopology = new QComboBox( myAdvGroup );
   QStringList topologyTypes;
-  topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) << tr( "BLSURF_TOPOLOGY_PROCESS" ) << tr( "BLSURF_TOPOLOGY_PROCESS2" );
+  topologyTypes << tr( "BLSURF_TOPOLOGY_CAD" ) 
+                << tr( "BLSURF_TOPOLOGY_PROCESS" ) 
+                << tr( "BLSURF_TOPOLOGY_PROCESS2" ) 
+                << tr( "BLSURF_TOPOLOGY_PRECAD" );
   myTopology->addItems( topologyTypes );
 
   myVerbosity = new QSpinBox( myAdvGroup );
index fecda28696b285be8ad4b8eab3509bf53df9f0e2..864b039e2675efaeae53e956f04c10f8f3adfd8c 100644 (file)
         <source>BLSURF_TOPOLOGY_PROCESS2</source>
         <translation>Pre-process++</translation>
     </message>
+    <message>
+        <source>BLSURF_TOPOLOGY_PRECAD</source>
+        <translation>PreCAD</translation>
+    </message>
     <message>
         <source>BLSURF_VERBOSITY</source>
         <translation>Verbosity level</translation>
index 9e46651c19a2d919fbfa7aac6edeea536b0114bf..20d490449d548f7b96fc64524df6871b442b6b57 100755 (executable)
         <source>BLSURF_TOPOLOGY_PROCESS2</source>
         <translation>Prétraitement++</translation>
     </message>
+    <message>
+        <source>BLSURF_TOPOLOGY_PRECAD</source>
+        <translation>PreCAD</translation>
+    </message>
     <message>
         <source>BLSURF_VERBOSITY</source>
         <translation>Niveau de verbosité</translation>