[cgma-dev] r1796 - cgm/trunk/geom/OCC

janehu at mcs.anl.gov janehu at mcs.anl.gov
Tue May 6 14:05:59 CDT 2008


Author: janehu
Date: 2008-05-06 14:05:58 -0500 (Tue, 06 May 2008)
New Revision: 1796

Modified:
   cgm/trunk/geom/OCC/OCCLump.cpp
   cgm/trunk/geom/OCC/OCCLump.hpp
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCShell.cpp
   cgm/trunk/geom/OCC/OCCShell.hpp
   cgm/trunk/geom/OCC/OCCSurface.cpp
   cgm/trunk/geom/OCC/OCCSurface.hpp
Log:
Added update for solids when doing body level booleans.

Modified: cgm/trunk/geom/OCC/OCCLump.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.cpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCLump.cpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -337,3 +337,34 @@
 
 }
 
+//----------------------------------------------------------------
+// Function: TopoDS_Shape level function to update the core Lump
+//           for any movement  or Boolean operation of the body.
+// Author: Jane Hu
+//----------------------------------------------------------------
+CubitStatus OCCLump::update_OCC_entity(TopoDS_Solid& old_solid,
+                                       TopoDS_Shape& new_solid,
+                                       BRepAlgoAPI_BooleanOperation *op)
+{
+  //set the Shells
+  TopTools_IndexedMapOfShape M;
+  TopoDS_Shape shape;
+  TopExp::MapShapes(old_solid, TopAbs_SHELL, M);
+  TopTools_ListOfShape shapes;
+ 
+  for(int ii=1; ii<=M.Extent(); ii++)
+  {
+    TopoDS_Shell shell = TopoDS::Shell(M(ii));
+
+    if(!new_solid.IsNull())
+    {
+       TopTools_ListOfShape shapes;
+       shapes.Assign(op->Modified(shell));
+       if (shapes.Extent() > 0)
+         shape = shapes.First();
+    }
+    if(shapes.Extent() > 0 || op->IsDeleted(shell))
+      OCCShell::update_OCC_entity(shell, shape, op);
+  }
+  OCCQueryEngine::instance()->update_OCC_map(old_solid, new_solid);
+}

Modified: cgm/trunk/geom/OCC/OCCLump.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.hpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCLump.hpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -154,7 +154,9 @@
 
   CubitStatus update_OCC_entity( BRepBuilderAPI_Transform *aBRepTrsf,
                                 BRepAlgoAPI_BooleanOperation *op = NULL);
-
+  static CubitStatus update_OCC_entity(TopoDS_Solid& old_shape,
+                                       TopoDS_Shape& new_shape,
+                                       BRepAlgoAPI_BooleanOperation *op);
 protected: 
   
 private:

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -1667,7 +1667,7 @@
                                           bool imprint,
                                           bool keep_old) const
 {
-  // copy the bodies in case subtraction has some errors
+  // copy the bodies in case keep_old is true
   DLIList<TopoDS_Shape*> tool_bodies_copy;
   DLIList<TopoDS_Shape*> from_bodies_copy;
   DLIList<CubitBoolean> is_volume;
@@ -1681,19 +1681,29 @@
     if(surface)
     {
        TopoDS_Face* topo_face = surface->get_TopoDS_Face();
-       BRepBuilderAPI_Copy api_copy(*topo_face);
-       TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_face);
-       TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
-       from_bodies_copy.append(newShape_ptr);
+       if(keep_old)
+       {
+         BRepBuilderAPI_Copy api_copy(*topo_face);
+         TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_face);
+         TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
+         from_bodies_copy.append(newShape_ptr);
+       }
+       else
+         from_bodies_copy.append(topo_face);
        is_volume.change_to( CUBIT_FALSE);
     }
     else if(shell)
     {
        TopoDS_Shell* topo_shell = shell->get_TopoDS_Shell();
-       BRepBuilderAPI_Copy api_copy(*topo_shell);
-       TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_shell); 
-       TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
-       from_bodies_copy.append(newShape_ptr);
+       if(keep_old)
+       {
+         BRepBuilderAPI_Copy api_copy(*topo_shell);
+         TopoDS_Shape newShape = api_copy.ModifiedShape(*topo_shell); 
+         TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
+         from_bodies_copy.append(newShape_ptr);
+       }
+       else
+         from_bodies_copy.append(topo_shell);
        is_volume.change_to( CUBIT_FALSE);
     }
     else
@@ -1706,19 +1716,15 @@
        }
  
        TopoDS_Solid* solid = CAST_TO(lumps.get(), OCCLump)->get_TopoDS_Solid();
-       TopExp_Explorer Ex_edge;
-       TopoDS_Edge edge;
-       int num_edge = 0;
-       for (Ex_edge.Init(*solid,TopAbs_EDGE); Ex_edge.More(); Ex_edge.Next())
+       if(keep_old)
        {
-         edge = TopoDS::Edge(Ex_edge.Current());
-         num_edge++;
+         BRepBuilderAPI_Copy api_copy(*solid);
+         TopoDS_Shape newShape = api_copy.ModifiedShape(*solid);
+         TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
+         from_bodies_copy.append(newShape_ptr);
        }
-
-       BRepBuilderAPI_Copy api_copy(*solid);
-       TopoDS_Shape newShape = api_copy.ModifiedShape(*solid);
-       TopoDS_Shape* newShape_ptr = new TopoDS_Shape(newShape);
-       from_bodies_copy.append(newShape_ptr);
+       else
+         from_bodies_copy.append(solid);
     }
   }
 
@@ -1815,6 +1821,12 @@
           }
           continue;
         }
+        //got cut. Update the entities
+        if(after_mass > tol*tol*tol)
+        {
+          TopoDS_Solid old_solid = TopoDS::Solid(*from_shape);
+          OCCLump::update_OCC_entity(old_solid , cut_shape, &cutter);
+        }
       }
       else
       {
@@ -1836,6 +1848,20 @@
           }
           continue;
         }
+        //got cut. Update the entities
+        if(after_mass > tol*tol)
+        { 
+          if(from_shape->TShape()->ShapeType() == TopAbs_SHELL)
+          {
+            TopoDS_Shell old_shell = TopoDS::Shell(*from_shape);
+	    OCCShell::update_OCC_entity(old_shell,cut_shape, &cutter);
+          }
+          else
+          {
+            TopoDS_Face old_face = TopoDS::Face(*from_shape);
+            OCCSurface::update_OCC_entity(old_face,cut_shape, &cutter);
+          }
+        }
       }
       delete from_shape;
       from_shape = new TopoDS_Shape(cut_shape);

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -1106,13 +1106,13 @@
 
 BodySM* OCCQueryEngine::populate_topology_bridge(TopoDS_CompSolid aShape)
 {
-  TopoDS_CompSolid *posolid =  new TopoDS_CompSolid;
-  *posolid = aShape;
   OCCBody *body;
-  if (!OCCMap->IsBound(*posolid))
+  if (!OCCMap->IsBound(aShape))
     {
       if(PRINT_RESULT)
 	PRINT_INFO("Adding Bodies.\n");
+      TopoDS_CompSolid *posolid =  new TopoDS_CompSolid;
+      *posolid = aShape;
       (iTotalTBCreated)++;
       body = new OCCBody(posolid);
       OCCMap->Bind(*posolid, iTotalTBCreated);
@@ -1122,9 +1122,9 @@
     }
   else
     {
-      int k = OCCMap->Find(*posolid);
+      int k = OCCMap->Find(aShape);
       body = (OCCBody*)(OccToCGM->find(k))->second;
-      body->set_TopoDS_Shape(*posolid);
+      body->set_TopoDS_Shape(aShape);
     }
 
   TopExp_Explorer Ex;
@@ -1144,14 +1144,14 @@
 		 			       CubitBoolean build_body)
 {
   //one OCCBody corresponds one OCCLump
-  TopoDS_Solid *posolid =  new TopoDS_Solid;
-  *posolid = aShape;
   OCCLump *lump;
   OCCBody *body;
-  if (!OCCMap->IsBound(*posolid))
+  if (!OCCMap->IsBound(aShape))
   {
     if(PRINT_RESULT)
       PRINT_INFO("Adding solids.\n");
+    TopoDS_Solid *posolid =  new TopoDS_Solid;
+    *posolid = aShape;
     iTotalTBCreated++;
     lump = new OCCLump(posolid);
     if (build_body)
@@ -1168,9 +1168,9 @@
   }
   else 
   {
-    int k = OCCMap->Find(*posolid);
+    int k = OCCMap->Find(aShape);
     lump = (OCCLump*)(OccToCGM->find(k))->second;
-    lump->set_TopoDS_Solid(*posolid);
+    lump->set_TopoDS_Solid(aShape);
   }
  
   TopExp_Explorer Ex;
@@ -1183,14 +1183,14 @@
 OCCShell* OCCQueryEngine::populate_topology_bridge(TopoDS_Shell aShape,
 						   CubitBoolean standalone)
 {
-  TopoDS_Shell *poshell = new TopoDS_Shell;
-  *poshell = aShape;
   OCCShell *shell ;
   CubitBoolean build_body = CUBIT_FALSE;
-  if (!OCCMap->IsBound(*poshell))
+  if (!OCCMap->IsBound(aShape))
   {
     if(PRINT_RESULT)
       PRINT_INFO("Adding shells.\n");
+    TopoDS_Shell *poshell = new TopoDS_Shell;
+    *poshell = aShape;
     iTotalTBCreated++;
     shell = new OCCShell(poshell);
     OCCMap->Bind(*poshell, iTotalTBCreated);
@@ -1208,9 +1208,9 @@
   }
   else
   {
-    int k = OCCMap->Find(*poshell);
+    int k = OCCMap->Find(aShape);
     shell = (OCCShell*)(OccToCGM->find(k))->second;
-    shell->set_TopoDS_Shell(*poshell);
+    shell->set_TopoDS_Shell(aShape);
   }
 
   TopExp_Explorer Ex;
@@ -1237,11 +1237,11 @@
 Surface* OCCQueryEngine::populate_topology_bridge(TopoDS_Face aShape,
                                                   CubitBoolean build_body)
 {
-  TopoDS_Face *poface = new TopoDS_Face;
-  *poface = aShape;
   OCCSurface *surface = NULL;
-  if (!OCCMap->IsBound(*poface))
+  if (!OCCMap->IsBound(aShape))
   {
+    TopoDS_Face *poface = new TopoDS_Face;
+    *poface = aShape;
     surface = new OCCSurface(poface);
 
     if(PRINT_RESULT)
@@ -1267,9 +1267,9 @@
 
   else 
   {
-    int k = OCCMap->Find(*poface);
+    int k = OCCMap->Find(aShape);
     surface = (OCCSurface*)(OccToCGM->find(k))->second;
-    surface->set_TopoDS_Face(*poface);
+    surface->set_TopoDS_Face(aShape);
   }
 
   TopExp_Explorer Ex;
@@ -1282,13 +1282,13 @@
 OCCLoop* OCCQueryEngine::populate_topology_bridge(TopoDS_Wire aShape,
 						  CubitBoolean standalone)
 {
-  TopoDS_Wire *powire = new TopoDS_Wire;
-  *powire = aShape;
   OCCLoop *loop ;
-  if (!OCCMap->IsBound(*powire))
+  if (!OCCMap->IsBound(aShape))
     {
       if(PRINT_RESULT)
 	PRINT_INFO("Adding loops.\n");
+      TopoDS_Wire *powire = new TopoDS_Wire;
+      *powire = aShape;
       iTotalTBCreated++;
       loop = new OCCLoop(powire);
       OCCMap->Bind(*powire, iTotalTBCreated);
@@ -1299,9 +1299,9 @@
     }
   else
     {
-      int k = OCCMap->Find(*powire);
+      int k = OCCMap->Find(aShape);
       loop = (OCCLoop*)(OccToCGM->find(k))->second;
-      loop->set_TopoDS_Wire(*powire);
+      loop->set_TopoDS_Wire(aShape);
     }
 
   BRepTools_WireExplorer Ex;
@@ -1342,12 +1342,12 @@
 Curve* OCCQueryEngine::populate_topology_bridge(TopoDS_Edge aShape)
 {
   Curve *curve;
-  TopoDS_Edge *poedge = new TopoDS_Edge;
-  *poedge = aShape;
-  if (!OCCMap->IsBound(*poedge)) 
+  if (!OCCMap->IsBound(aShape)) 
     {
       if(PRINT_RESULT)
 	PRINT_INFO("Adding edges.\n");
+      TopoDS_Edge *poedge = new TopoDS_Edge;
+      *poedge = aShape;
       iTotalTBCreated++;
       curve = new OCCCurve(poedge);
       OCCMap->Bind(*poedge, iTotalTBCreated);
@@ -1357,9 +1357,9 @@
     }
   else 
     {
-      int i = OCCMap->Find(*poedge);
+      int i = OCCMap->Find(aShape);
       curve = (OCCCurve*)(OccToCGM->find(i))->second;
-      CAST_TO(curve, OCCCurve)->set_TopoDS_Edge(*poedge);
+      CAST_TO(curve, OCCCurve)->set_TopoDS_Edge(aShape);
     }
 
   TopExp_Explorer Ex;
@@ -1372,12 +1372,12 @@
 Point* OCCQueryEngine::populate_topology_bridge(TopoDS_Vertex aShape)
 {
   OCCPoint *point;
-  TopoDS_Vertex *povertex = new TopoDS_Vertex;
-  *povertex = aShape;
-  if (iTotalTBCreated == 0 || !OCCMap->IsBound(*povertex)) 
+  if (iTotalTBCreated == 0 || !OCCMap->IsBound(aShape)) 
     {
       if(PRINT_RESULT)
 	PRINT_INFO("Adding vertices.\n");
+      TopoDS_Vertex *povertex = new TopoDS_Vertex;
+      *povertex = aShape;
       iTotalTBCreated++;
       point = new OCCPoint(povertex);
       OCCMap->Bind(*povertex, iTotalTBCreated);
@@ -1386,9 +1386,9 @@
     } 
   else 
     {
-      int i = OCCMap->Find(*povertex);
+      int i = OCCMap->Find(aShape);
       point = (OCCPoint*)(OccToCGM->find(i))->second;
-      point->set_TopoDS_Vertex(*povertex);
+      point->set_TopoDS_Vertex(aShape);
     }
   return point;
 }
@@ -1428,6 +1428,28 @@
     GeometryEntity* ref_entity_ptr,
     bool remove_lower_entities) const
 {
+     //Lump
+   Lump* lump = CAST_TO(ref_entity_ptr, Lump);
+   if(lump != NULL)
+   {
+     BodySM* body = CAST_TO(lump, OCCLump)->get_body();
+     
+     if (remove_lower_entities)
+       return delete_solid_model_entities(body);
+
+     CubitStatus stat = this->unhook_BodySM_from_OCC(body); 
+     if(stat)
+     {
+       DLIList<TopologyBridge*> children;
+       CAST_TO(lump, OCCLump)->get_children_virt(children);
+       while (children.size())
+          delete children.pop();
+       delete lump;
+       delete body;
+     }
+     return stat;
+   }
+
      // Surface
    Surface* ref_face_ptr = CAST_TO(ref_entity_ptr, Surface);
    if (ref_face_ptr != NULL)
@@ -2507,6 +2529,15 @@
     GeometryEntity* ge =  CAST_TO(tb, GeometryEntity);
     if(ge)
       delete_solid_model_entities( ge, CUBIT_FALSE );
+    else
+    {
+      ShellSM * shell = CAST_TO(tb, ShellSM);
+      if(shell)
+      {
+        unhook_ShellSM_from_OCC(shell);
+        delete shell;
+      }
+    }
   }
 
   else

Modified: cgm/trunk/geom/OCC/OCCShell.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShell.cpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCShell.cpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -250,6 +250,32 @@
   return myProps.Mass();
 }
 
+//----------------------------------------------------------------
+// Function: TopoDS_Shape level function to update the core Shell
+//           for any boolean operation of the body.
+// Author: Jane Hu
+//----------------------------------------------------------------
+CubitStatus OCCShell::update_OCC_entity(TopoDS_Shell& old_shell,
+                                        TopoDS_Shape& new_shell,
+                                        BRepAlgoAPI_BooleanOperation *op)
+{
+  //set the surfaces
+  TopTools_IndexedMapOfShape M;
+  TopoDS_Shape shape;
+  TopExp::MapShapes(old_shell, TopAbs_FACE, M);
+  TopTools_ListOfShape shapes;
+  for(int ii=1; ii<=M.Extent(); ii++)
+  {
+    TopoDS_Face face = TopoDS::Face(M(ii));
+    shapes.Assign(op->Modified(face));
+    if(shapes.Extent() > 0)
+      shape = shapes.First();
+    if(shapes.Extent() > 0 || op->IsDeleted(face))
+      OCCSurface::update_OCC_entity(face,shape, op);
+  }
+  OCCQueryEngine::instance()->update_OCC_map(old_shell, new_shell);
+  return CUBIT_SUCCESS;
+}
 // ********** END PUBLIC FUNCTIONS         **********
 
 // ********** BEGIN PROTECTED FUNCTIONS    **********

Modified: cgm/trunk/geom/OCC/OCCShell.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShell.hpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCShell.hpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -118,6 +118,9 @@
   CubitStatus update_OCC_entity( BRepBuilderAPI_Transform *aBRepTrsf,
                                  BRepAlgoAPI_BooleanOperation *op = NULL);
   double measure(); //area of the shell
+  static CubitStatus update_OCC_entity(TopoDS_Shell& old_shell,
+                                       TopoDS_Shape& new_shell,
+                                       BRepAlgoAPI_BooleanOperation *op);
 protected: 
   
 private:

Modified: cgm/trunk/geom/OCC/OCCSurface.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.cpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCSurface.cpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -819,33 +819,37 @@
 // Author: Jane Hu
 //----------------------------------------------------------------
 CubitStatus OCCSurface::update_OCC_entity(TopoDS_Face& old_surface,
-                                          TopoDS_Face& new_surface,
+                                          TopoDS_Shape& new_surface,
                                           BRepAlgoAPI_BooleanOperation *op)
 {
   //set the Wires
   TopTools_IndexedMapOfShape M;
   TopoDS_Shape shape, shape_edge, shape_vertex;
   TopExp::MapShapes(old_surface, TopAbs_WIRE, M);
-  double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance();
-  int ii;
+
   TopTools_ListOfShape shapes;  
 
-  for (ii=1; ii<=M.Extent(); ii++) 
+  for (int ii=1; ii<=M.Extent(); ii++) 
   {
      TopoDS_Wire wire = TopoDS::Wire(M(ii));
-
      if(!new_surface.IsNull())
      {
        TopTools_ListOfShape shapes;
        shapes.Assign(op->Modified(wire));
        if (shapes.Extent() > 0)
          shape = shapes.First();
-       else
+       else if(op->IsDeleted(wire))
        {
          TopTools_IndexedMapOfShape M_new;
          TopExp::MapShapes(new_surface, TopAbs_WIRE, M_new);
-         shape = M_new(ii);
+         if (M_new.Extent()>= ii)
+           shape = M_new(ii);
        }
+       else
+       {
+         shape = wire;
+         continue;
+       }
      } 
      //set curves
      BRepTools_WireExplorer Ex;
@@ -859,8 +863,10 @@
        else if (op->IsDeleted(edge))
          ; 
        else 
+       {
+         shape_edge = edge;
          continue;
-
+       }
        if(wire.Orientation() == TopAbs_REVERSED && !shape_edge.IsNull())
        {
          shape_edge.Orientation(

Modified: cgm/trunk/geom/OCC/OCCSurface.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.hpp	2008-05-06 01:05:46 UTC (rev 1795)
+++ cgm/trunk/geom/OCC/OCCSurface.hpp	2008-05-06 19:05:58 UTC (rev 1796)
@@ -62,7 +62,7 @@
     //- The destructor
    
   static CubitStatus update_OCC_entity(TopoDS_Face& old_surface,
-                                       TopoDS_Face& new_surface,
+                                       TopoDS_Shape& new_surface,
                                        BRepAlgoAPI_BooleanOperation *op);
 
 




More information about the cgma-dev mailing list