Author: janehu Date: 2008-04-22 14:30:00 -0500 (Tue, 22 Apr 2008) New Revision: 1773 Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp cgm/trunk/geom/OCC/OCCQueryEngine.cpp cgm/trunk/geom/OCC/OCCQueryEngine.hpp Log: worked on interface of stitch_surf into a shell body or into a solid body. Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCModifyEngine.cpp 2008-04-21 19:49:42 UTC (rev 1772) +++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp 2008-04-22 19:30:00 UTC (rev 1773) @@ -1016,7 +1016,7 @@ if (surface_list.size() < 2) return (Lump*) NULL; - //all surfaces should be stand along surface bodies + //all surfaces should be stand along surface bodies or shell bodies' surface DLIList<BodySM*> body_list; for(int i = 0; i < surface_list.size(); i++) { @@ -1028,18 +1028,33 @@ return (Lump *)NULL; } OCCBody* occ_body = occ_surface->my_body(); - if(occ_body->my_sheet_surface() == NULL) + if(occ_body && occ_body->my_sheet_surface() == NULL) { PRINT_ERROR("Cannot create an OCC lump from the given surfaces.\n" "The surfaces are not free.\n"); - return (Lump *)NULL; + return (Lump *)NULL; } - body_list.append(occ_body); + else if(!occ_body) + { + OCCShell* shell = occ_surface->my_shell(); + if(!shell) + { + PRINT_ERROR("This is a bug, please report it. \n"); + return (Lump*)NULL; + } + occ_body = shell->my_body(); + } + body_list.append_unique(occ_body); } TopoDS_Shape aShape; CubitStatus stat = stitch_surfs(body_list, aShape); - + if(!stat) + { + PRINT_ERROR("The surfaces are not all connected, can't make a lump. \n"); + return (Lump*)NULL; + } + TopExp_Explorer Ex, Ex2; TopoDS_Shell aShell ; for (Ex.Init(aShape, TopAbs_SHELL, TopAbs_SOLID); Ex.More()&& stat; Ex.Next()) @@ -1052,7 +1067,7 @@ { TopoDS_Edge edge1 = TopoDS::Edge(Ex.Current()); num_edges++; - for (Ex2.Init(aShell, TopAbs_EDGE); Ex2.More()&& stat; Ex2.Next()) + for (Ex2.Init(aShell, TopAbs_EDGE); Ex2.More(); Ex2.Next()) { TopoDS_Edge edge2 = TopoDS::Edge(Ex2.Current()); if (!edge1.IsEqual(edge2)&& edge1.IsSame(edge2)) @@ -1080,9 +1095,6 @@ TopoDS_Solid aSolid = aMakeSolid.Solid(); - int num_edge = 0; - for (Ex.Init(aSolid, TopAbs_EDGE); Ex.More()&& stat; Ex.Next()) - num_edge++; return OCCQueryEngine::instance()->populate_topology_bridge(aSolid, CUBIT_TRUE); } @@ -1163,26 +1175,10 @@ } TopoDS_Solid* solid = occ_lump->get_TopoDS_Solid(); B.Add(CS, *solid); - - BodySM* bodysm_ptr = occ_lump->get_body(); - if(bodysm_ptr == NULL) - continue; - - bodysm_list.append_unique(bodysm_ptr); } BodySM* bodysm = OCCQueryEngine::instance()->populate_topology_bridge(CS); - if(bodysm) - { - //remove each Lump's body from the BodyList - for(int i = 0; i < bodysm_list.size(); i++) - { - BodySM* bodysm_ptr = bodysm_list.get_and_step(); - - OCCQueryEngine::instance()->unhook_BodySM_from_OCC(bodysm_ptr); - } - } return bodysm; } @@ -1517,34 +1513,36 @@ //=============================================================================== CubitStatus OCCModifyEngine::stitch_surfs( DLIList<BodySM*>& surf_bodies, - BodySM*& stitched_body) const + BodySM*& new_body) const { - stitched_body = NULL; if (surf_bodies.size()==0) return CUBIT_SUCCESS; if (surf_bodies.size()==1) { - stitched_body = surf_bodies.get(); + new_body = surf_bodies.get(); return CUBIT_SUCCESS; } TopoDS_Shape fuse; CubitStatus stat = stitch_surfs(surf_bodies, fuse); - if (stat == CUBIT_FAILURE) - return stat; - + DLIList<TopologyBridge*> tbs = OCCQueryEngine::instance()-> populate_topology_bridge(fuse); - OCCBody* body = CAST_TO(tbs.get(), OCCBody); - if (body) - stitched_body = body ; + if (stat) + { + OCCBody* body = CAST_TO(tbs.get(), OCCBody); + + if (body) + new_body = body ; + } + else { - OCCSurface* face = CAST_TO(tbs.get(), OCCSurface); - if(face) - stitched_body = face->my_body(); + surf_bodies.clean_out(); + for(int i= 0; i<tbs.size(); i++) + surf_bodies.append(CAST_TO(tbs.get_and_step(), OCCBody)); } return CUBIT_SUCCESS; @@ -1566,16 +1564,26 @@ return CUBIT_SUCCESS; DLIList<TopoDS_Face*> faces_to_stitch; + DLIList<OCCSurface*> surfaces; for (int i = 0; i < surf_bodies.size(); i++) { BodySM * tool_body = surf_bodies.get_and_step(); OCCBody* occ_body = CAST_TO(tool_body, OCCBody); OCCSurface* surface = occ_body->my_sheet_surface(); + OCCShell* shell = occ_body->shell(); if (surface == NULL) { PRINT_ERROR("Can't stitch non-sheet bodySM's. \n"); return CUBIT_FAILURE; } + surfaces.append(surface); + + delete occ_body; + delete surface->my_shell(); + delete surface->my_lump(); + surface->set_shell(NULL); + surface->set_lump(NULL); + surface->set_body(NULL); TopoDS_Face* topods_face = surface->get_TopoDS_Face(); if (topods_face != NULL) faces_to_stitch.append(topods_face); @@ -1590,8 +1598,8 @@ { second_face = faces_to_stitch[i]; BRepAlgoAPI_Fuse fuser(*second_face, *first_face); - OCCBody* occ_body = CAST_TO(surf_bodies[i], OCCBody); - occ_body->my_sheet_surface()->update_OCC_entity(NULL, &fuser); + OCCSurface* surface = surfaces[i]; + surface->update_OCC_entity(NULL, &fuser); TopoDS_Shape new_shape ; TopTools_IndexedMapOfShape M; TopExp::MapShapes(*first_face, TopAbs_FACE, M); @@ -3018,15 +3026,54 @@ //=============================================================================== // Function : create_body_from_surfs // Member Type: PUBLIC -// Description: -// Author : Steve Owen -// Date : 9/11/03 +// Description: +// Author : Jane Hu +// Date : 4/22/08 //=============================================================================== CubitStatus OCCModifyEngine::create_solid_bodies_from_surfs(DLIList<Surface*> & ref_face_list, DLIList<BodySM*>& new_bodies, bool keep_old, bool heal) const { + //keep_old and heal are ignored, always delete old. + //all surfaces should be stand along surface bodies or shell bodies' surface + DLIList<BodySM*> body_list; + for(int i = 0; i < ref_face_list.size(); i++) + { + OCCSurface* occ_surface = CAST_TO(ref_face_list.get_and_step(), OCCSurface); + if (occ_surface == NULL) + { + PRINT_ERROR("Cannot create an OCC lump from the given surfaces.\n" + "Possible incompatible geometry engines.\n"); + return CUBIT_FAILURE; + } + OCCBody* occ_body = occ_surface->my_body(); + if(occ_body && occ_body->my_sheet_surface() == NULL) + { + PRINT_ERROR("Cannot create an OCC lump from the given surfaces.\n" + "The surfaces are not free.\n"); + return CUBIT_FAILURE; + } + else if(!occ_body) + { + OCCShell* shell = occ_surface->my_shell(); + if(!shell) + { + PRINT_ERROR("This is a bug, please report it. \n"); + return CUBIT_FAILURE; + } + occ_body = shell->my_body(); + } + body_list.append_unique(occ_body); + } + + BodySM* new_body = NULL; + CubitStatus stat = stitch_surfs(body_list,new_body); + if (!new_body) + new_bodies = body_list; + else + new_bodies.append(new_body); + return CUBIT_SUCCESS; } Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp =================================================================== --- cgm/trunk/geom/OCC/OCCQueryEngine.cpp 2008-04-21 19:49:42 UTC (rev 1772) +++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp 2008-04-22 19:30:00 UTC (rev 1773) @@ -1404,7 +1404,11 @@ { if (remove_lower_entities) return ( this->delete_solid_model_entities(ref_face_ptr) ); - return ( this->unhook_Surface_from_OCC(ref_face_ptr)); + TopoDS_Face *face = NULL; + CubitStatus stat = this->unhook_Surface_from_OCC(ref_face_ptr, face); + if(stat) + delete face; + return stat; } // Curve @@ -1413,7 +1417,11 @@ { if (remove_lower_entities) return ( this->delete_solid_model_entities(ref_edge_ptr)); - return ( this->unhook_Curve_from_OCC(ref_edge_ptr)); + TopoDS_Edge *edge = NULL; + CubitStatus stat = this->unhook_Curve_from_OCC(ref_edge_ptr, edge); + if(stat) + delete edge; + return stat; } // Point @@ -1460,30 +1468,66 @@ { delete occ_shell->my_body(); delete occ_shell->my_lump(); - return unhook_ShellSM_from_OCC(occ_shell); + TopoDS_Shell* Shell; + CubitStatus stat = unhook_ShellSM_from_OCC(occ_shell,Shell); + DLIList<TopologyBridge*> tb_surfaces; + occ_shell->get_children_virt(tb_surfaces); + for(int k = 0; k < tb_surfaces.size(); k++) + delete_solid_model_entities(CAST_TO(tb_surfaces.get_and_step(), Surface)); + if(Shell) + delete Shell; + return stat; } + TopoDS_Shape* shape = NULL; + CubitStatus stat = unhook_BodySM_from_OCC(bodysm, shape); + + DLIList<TopologyBridge*> children; DLIList<Lump*> lumps = occ_body->lumps(); + DLIList<TopoDS_Shell*> Shell_list; + for(int i =0; i < lumps.size(); i++) { Lump* lump = lumps.get_and_step(); OCCLump* occ_lump = CAST_TO(lump, OCCLump); - if (occ_lump) - occ_lump->remove_body(); - unhook_Lump_from_OCC(lump); + if (!occ_lump) + continue; + children.clean_out(); + occ_lump->get_children_virt(children); + for(int j = 0; j < children.size(); j++) + { + ShellSM* shell = CAST_TO(children.get_and_step(), ShellSM); + + TopoDS_Shell* Shell = CAST_TO(shell, OCCShell)->get_TopoDS_Shell(); + if (Shell) + Shell_list.append(Shell); + DLIList<TopologyBridge*> tb_surfaces; + shell->get_children_virt(tb_surfaces); + for(int k = 0; k < tb_surfaces.size(); k++) + delete_solid_model_entities(CAST_TO(tb_surfaces.get_and_step(), Surface)); + } + + for(int j = 0; j < Shell_list.size(); j++) + delete Shell_list.pop(); + + TopoDS_Solid* solid = occ_lump->get_TopoDS_Solid(); + delete solid; } - return unhook_BodySM_from_OCC(bodysm); + if(shape) + delete shape; + return stat; } CubitStatus -OCCQueryEngine::unhook_BodySM_from_OCC( BodySM* bodysm)const +OCCQueryEngine::unhook_BodySM_from_OCC( BodySM* bodysm, + TopoDS_Shape*& shape)const { OCCBody* occ_body = dynamic_cast<OCCBody*>(bodysm); if (!occ_body) return CUBIT_FAILURE; - TopoDS_Shape* shape = occ_body->get_TopoDS_Shape(); + shape = occ_body->get_TopoDS_Shape(); if (!shape) return CUBIT_FAILURE; @@ -1503,15 +1547,25 @@ if(!OccToCGM->erase(k)) PRINT_ERROR("The OccBody and TopoDS_Shape pair is not in the map!"); } - DLIList<Lump*> lumps; - occ_body->lumps(lumps); if (occ_body_find) BodyList->remove(occ_body_find); else BodyList->remove(occ_body); - //delete shape; - delete shape; + + DLIList<Lump*> lumps = occ_body->lumps(); + for(int i =0; i < lumps.size(); i++) + { + Lump* lump = lumps.get_and_step(); + OCCLump* occ_lump = CAST_TO(lump, OCCLump); + if (occ_lump) + occ_lump->remove_body(); + + TopoDS_Solid* solid; + unhook_Lump_from_OCC(lump, solid); + } + delete bodysm; + return CUBIT_SUCCESS; } //------------------------------------------------------------------------- @@ -1524,7 +1578,7 @@ // Creation Date : 11/29/07 //------------------------------------------------------------------------- CubitStatus -OCCQueryEngine::unhook_Lump_from_OCC( Lump* lump ) const +OCCQueryEngine::unhook_Lump_from_OCC( Lump* lump, TopoDS_Solid*& solid ) const { if (lump == NULL) return CUBIT_FAILURE; @@ -1533,7 +1587,7 @@ if (!occ_lump) return CUBIT_FAILURE; - TopoDS_Solid* solid = occ_lump->get_TopoDS_Solid(); + solid = occ_lump->get_TopoDS_Solid(); if(!solid) return CUBIT_FAILURE; @@ -1556,11 +1610,11 @@ for(int i = 0; i < children.size(); i++) { ShellSM* shell = CAST_TO(children.get_and_step(), ShellSM); - unhook_ShellSM_from_OCC(shell); + TopoDS_Shell* Shell; + unhook_ShellSM_from_OCC(shell,Shell); } if (occ_lump->get_body() != NULL) BodyList->remove(CAST_TO(occ_lump->get_body(), OCCBody)); - delete solid; delete lump; return CUBIT_SUCCESS; } @@ -1575,13 +1629,14 @@ // Creation Date : 12/12/07 //------------------------------------------------------------------------- CubitStatus -OCCQueryEngine::unhook_ShellSM_from_OCC( ShellSM* shell ) const +OCCQueryEngine::unhook_ShellSM_from_OCC( ShellSM* shell, + TopoDS_Shell*& Shell ) const { OCCShell* occ_shell = dynamic_cast<OCCShell*>(shell); if (!occ_shell) return CUBIT_FAILURE; - TopoDS_Shell* Shell = occ_shell->get_TopoDS_Shell(); + Shell = occ_shell->get_TopoDS_Shell(); if(!Shell) return CUBIT_FAILURE; @@ -1599,14 +1654,6 @@ PRINT_ERROR("The OccSurface and TopoDS_Face pair is not in the map!"); } - DLIList<TopologyBridge*> children; - occ_shell->get_children_virt(children); - for(int i = 0; i < children.size(); i++) - { - Surface* surface = CAST_TO(children.get_and_step(), Surface); - delete_solid_model_entities(surface); - } - delete Shell; delete shell; return CUBIT_SUCCESS; } @@ -1634,9 +1681,11 @@ LoopSM* loop = CAST_TO(children.get_and_step(), LoopSM); delete_loop(loop); } - - return unhook_Surface_from_OCC(surface); - + TopoDS_Face* face; + CubitStatus stat = unhook_Surface_from_OCC(surface, face); + if (stat) + delete face; + return stat; } //------------------------------------------------------------------------- @@ -1649,13 +1698,14 @@ // Creation Date : 12/12/07 //------------------------------------------------------------------------- CubitStatus -OCCQueryEngine::unhook_Surface_from_OCC( Surface* surface ) const +OCCQueryEngine::unhook_Surface_from_OCC( Surface* surface, + TopoDS_Face*& face ) const { OCCSurface* fsurf = dynamic_cast<OCCSurface*>(surface); if (!fsurf) return CUBIT_FAILURE; - TopoDS_Face* face = fsurf->get_TopoDS_Face(); + face = fsurf->get_TopoDS_Face(); if(!face) return CUBIT_FAILURE; @@ -1675,7 +1725,6 @@ PRINT_WARNING("The OccSurface and TopoDS_Face pair is not in the map!"); } - delete face; delete surface; return CUBIT_SUCCESS; } @@ -1707,17 +1756,60 @@ if (occ_curve == NULL) continue; + delete_solid_model_entities(curve); + } + + TopoDS_Wire* wire; + CubitStatus status = unhook_LoopSM_from_OCC(loopsm, wire); + if (status) + delete wire; + return status; +} + +//------------------------------------------------------------------------- +// Purpose : unhook a LoopSM from its underlining OCC entity. +// +// Special Notes : +// +// Creator : Jane Hu +// +// Creation Date : 12/12/07 +//------------------------------------------------------------------------- +CubitStatus +OCCQueryEngine::unhook_LoopSM_from_OCC( LoopSM* loopsm, + TopoDS_Wire*& wire ) const +{ + OCCLoop* occ_loop = dynamic_cast<OCCLoop*>(loopsm); + if (!occ_loop) + return CUBIT_FAILURE; + + wire = occ_loop->get_TopoDS_Wire(); + + if(!wire) + return CUBIT_FAILURE; + + DLIList<OCCCoEdge*> children; + children = occ_loop->coedges(); + int size = children.size(); + while(size > 0) + { + OCCCoEdge* coedge = children.pop(); + Curve* curve = coedge->curve(); + OCCCurve *occ_curve = CAST_TO(curve, OCCCurve); + if (occ_curve == NULL) + continue; + DLIList<OCCLoop*> loops; - + //remove all coedges corresponding to this curve from their loops. loops = occ_curve->loops(); for(int j = 0; j < loops.size(); j++) { OCCLoop* occ_loop = loops.get_and_step(); - OCCCoEdge* found_coedge = occ_loop->remove_coedge(coedge); + OCCCoEdge* found_coedge = occ_loop->remove_coedge(coedge); if (found_coedge) - delete found_coedge; + delete found_coedge; //there might be 2 coedges in the same loop that uses the same curve //as in a scar curve situation @@ -1727,40 +1819,15 @@ found_coedge = coedges.get_and_step(); if (CAST_TO(found_coedge->curve(), OCCCurve) == occ_curve) { - occ_loop->remove_coedge(found_coedge); + occ_loop->remove_coedge(found_coedge); children.remove(found_coedge); delete found_coedge; } } } size = children.size(); - delete_solid_model_entities(curve); } - - return unhook_LoopSM_from_OCC(loopsm); -} -//------------------------------------------------------------------------- -// Purpose : unhook a LoopSM from its underlining OCC entity. -// -// Special Notes : -// -// Creator : Jane Hu -// -// Creation Date : 12/12/07 -//------------------------------------------------------------------------- -CubitStatus -OCCQueryEngine::unhook_LoopSM_from_OCC( LoopSM* loopsm ) const -{ - OCCLoop* occ_loop = dynamic_cast<OCCLoop*>(loopsm); - if (!occ_loop) - return CUBIT_FAILURE; - - TopoDS_Wire* wire = occ_loop->get_TopoDS_Wire(); - - if(!wire) - return CUBIT_FAILURE; - //remove the entry from the map int k; if(OCCMap->IsBound(*wire)) @@ -1775,7 +1842,6 @@ } WireList->remove(CAST_TO(loopsm, OCCLoop)); - delete wire; delete loopsm; return CUBIT_SUCCESS; } @@ -1803,8 +1869,12 @@ Point* point = CAST_TO(children.get_and_step(), Point); delete_solid_model_entities(point); } - - return unhook_Curve_from_OCC(curve); + + TopoDS_Edge* edge; + CubitStatus stat = unhook_Curve_from_OCC(curve, edge); + if (stat) + delete edge; + return stat; } //------------------------------------------------------------------------- @@ -1817,14 +1887,14 @@ // Creation Date : 12/12/07 //------------------------------------------------------------------------- CubitStatus -OCCQueryEngine::unhook_Curve_from_OCC( Curve* curve ) const +OCCQueryEngine::unhook_Curve_from_OCC( Curve* curve, TopoDS_Edge*& edge ) const { OCCCurve* fcurve = dynamic_cast<OCCCurve*>(curve); if (!fcurve ) return CUBIT_FAILURE; fcurve->clean_loops(); - TopoDS_Edge * edge = fcurve->get_TopoDS_Edge(); + edge = fcurve->get_TopoDS_Edge(); if (!edge) return CUBIT_FAILURE; @@ -1841,7 +1911,6 @@ PRINT_WARNING("The OccCurve and TopoDS_Edge pair is not in the map!"); } - delete edge; delete curve; return CUBIT_SUCCESS; } @@ -1861,8 +1930,11 @@ if (!fpoint) return CUBIT_FAILURE; - return unhook_Point_from_OCC(point); - + TopoDS_Vertex* vertex; + CubitStatus stat = unhook_Point_from_OCC(point, vertex); + if(stat) + delete vertex; + return stat; } //------------------------------------------------------------------------- @@ -1875,13 +1947,14 @@ // Creation Date : 12/12/07 //------------------------------------------------------------------------- CubitStatus -OCCQueryEngine::unhook_Point_from_OCC( Point* point ) const +OCCQueryEngine::unhook_Point_from_OCC( Point* point, + TopoDS_Vertex*& vertex ) const { OCCPoint* fpoint = dynamic_cast<OCCPoint*>(point); if (!fpoint) return CUBIT_FAILURE; - TopoDS_Vertex *vertex = fpoint->get_TopoDS_Vertex(); + vertex = fpoint->get_TopoDS_Vertex(); if (!vertex) return CUBIT_FAILURE; @@ -1897,7 +1970,6 @@ if(!OccToCGM->erase(k)) PRINT_ERROR("The OccPoint and TopoDS_Vertex pair is not in the map!"); } - delete vertex; delete point; return CUBIT_SUCCESS; } Modified: cgm/trunk/geom/OCC/OCCQueryEngine.hpp =================================================================== --- cgm/trunk/geom/OCC/OCCQueryEngine.hpp 2008-04-21 19:49:42 UTC (rev 1772) +++ cgm/trunk/geom/OCC/OCCQueryEngine.hpp 2008-04-22 19:30:00 UTC (rev 1773) @@ -248,7 +248,14 @@ CubitBoolean import_vertices = CUBIT_TRUE, CubitBoolean free_surfaces = CUBIT_TRUE ); - CubitStatus unhook_BodySM_from_OCC( BodySM* bodysm)const; + CubitStatus unhook_BodySM_from_OCC( BodySM* bodysm, + TopoDS_Shape*& shape)const; + CubitStatus unhook_Surface_from_OCC( Surface* surface, + TopoDS_Face*& topo_face ) const; + CubitStatus unhook_Curve_from_OCC( Curve* curve, + TopoDS_Edge*& edge ) const; + CubitStatus unhook_Point_from_OCC( Point* point, + TopoDS_Vertex*& vertex ) const; private: CubitStatus import_solid_model(FILE *file_ptr, @@ -263,12 +270,11 @@ CubitBoolean import_vertices = CUBIT_TRUE, CubitBoolean free_surfaces = CUBIT_TRUE); - CubitStatus unhook_Lump_from_OCC( Lump* lump ) const; - CubitStatus unhook_ShellSM_from_OCC( ShellSM* shell ) const; - CubitStatus unhook_LoopSM_from_OCC( LoopSM* loopsm ) const; - CubitStatus unhook_Surface_from_OCC( Surface* surface ) const; - CubitStatus unhook_Curve_from_OCC( Curve* curve ) const; - CubitStatus unhook_Point_from_OCC( Point* point ) const; + CubitStatus unhook_Lump_from_OCC( Lump* lump, TopoDS_Solid*& solid ) const; + CubitStatus unhook_ShellSM_from_OCC( ShellSM* shell, + TopoDS_Shell*& shell ) const; + CubitStatus unhook_LoopSM_from_OCC( LoopSM* loopsm, + TopoDS_Wire*& wire ) const; CubitStatus delete_loop( LoopSM* loopsm)const; public: virtual void delete_solid_model_entities(DLIList<BodySM*>& body_list) const;
participants (1)
-
janehu@mcs.anl.gov