cgma
OCCLoop.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : OCCLoop.cpp
00003 //
00004 // Purpose       : Loops for Facet-based geometry module
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : Steven J. Owen
00009 //
00010 // Creation Date : 12/06/00
00011 //
00012 // Owner         : Steven J. Owen
00013 //-------------------------------------------------------------------------
00014 
00015 #include "CastTo.hpp"
00016 #include "OCCLoop.hpp"
00017 #include "OCCQueryEngine.hpp"
00018 #include "CoEdgeSM.hpp"
00019 
00020 #include "OCCBody.hpp"
00021 #include "OCCLump.hpp"
00022 #include "OCCShell.hpp"
00023 #include "OCCSurface.hpp"
00024 #include "OCCCoEdge.hpp"
00025 #include "OCCCurve.hpp"
00026 #include "OCCPoint.hpp"
00027 
00028 #include <TopExp.hxx>
00029 #include <TopTools_IndexedMapOfShape.hxx>
00030 #include "TopExp_Explorer.hxx"
00031 #include "TopoDS.hxx"
00032 #include "TopTools_ListIteratorOfListOfShape.hxx"
00033 #include "TopTools_DataMapOfShapeInteger.hxx"
00034 #include "TopTools_DataMapOfOrientedShapeInteger.hxx"
00035 #include "TopTools_IndexedDataMapOfShapeListOfShape.hxx"
00036 #include "BRepBuilderAPI_Transform.hxx"
00037 #include "BRepBuilderAPI_GTransform.hxx"
00038 #include "BRepBuilderAPI_ModifyShape.hxx"
00039 #include "BRepAlgoAPI_BooleanOperation.hxx"
00040 #include "LocOpe_SplitShape.hxx"
00041 #include "BRepTools_WireExplorer.hxx"
00042 // ********** END CUBIT INCLUDES           **********
00043 
00044 // ********** BEGIN STATIC DECLARATIONS    **********
00045 // ********** END STATIC DECLARATIONS      **********
00046 
00047 // ********** BEGIN PUBLIC FUNCTIONS       **********
00048 
00049 //-------------------------------------------------------------------------
00050 // Purpose       : The constructor with a pointer to the TopoDS_Wire.
00051 //
00052 // Special Notes :
00053 //
00054 //-------------------------------------------------------------------------
00055 OCCLoop::OCCLoop( TopoDS_Wire *theWire )
00056 {
00057   myTopoDSWire = theWire;
00058 }
00059 
00060 //-------------------------------------------------------------------------
00061 // Purpose       : The default destructor.
00062 //
00063 // Special Notes :
00064 //
00065 //-------------------------------------------------------------------------
00066 OCCLoop::~OCCLoop()
00067 {
00068   disconnect_all_curves();
00069   if (myTopoDSWire)
00070   {
00071     myTopoDSWire->Nullify(); 
00072     delete (TopoDS_Wire*)myTopoDSWire;
00073     myTopoDSWire = NULL;
00074   }
00075 }
00076 
00077 void OCCLoop::set_TopoDS_Wire(TopoDS_Wire loop)
00078 {
00079    if(myTopoDSWire && loop.IsEqual(*myTopoDSWire))
00080      return;
00081    if(myTopoDSWire && !loop.IsSame(*myTopoDSWire))
00082    {
00083      DLIList<OCCCoEdge*> coedges = this->coedges();
00084      for(int i = 0; i < coedges.size(); i++)
00085      {
00086        OCCCoEdge* coedge = coedges.get_and_step();
00087        OCCCurve* curve = CAST_TO(coedge->curve(), OCCCurve);
00088        TopoDS_Edge *edge = curve->get_TopoDS_Edge( );
00089        BRepTools_WireExplorer Ex;
00090        CubitBoolean found = false;
00091        for (Ex.Init(loop); Ex.More(); Ex.Next())
00092        {
00093          TopoDS_Shape crv = Ex.Current();
00094          if(edge->IsPartner(crv))
00095          {
00096            found = true;
00097            break;
00098          }
00099        }
00100        if (!found)
00101          curve->remove_loop(this); 
00102      }
00103    }
00104    TopoDS_Wire* the_wire = new TopoDS_Wire(loop);
00105    if(myTopoDSWire)
00106      delete (TopoDS_Wire*)myTopoDSWire;
00107    myTopoDSWire = the_wire;
00108 }
00109 //-------------------------------------------------------------------------
00110 // Purpose       : Tear down topology
00111 //
00112 // Special Notes :
00113 //
00114 // Creator       : Jane Hu
00115 //
00116 // Creation Date : 11/29/07
00117 //-------------------------------------------------------------------------
00118 void OCCLoop::disconnect_all_curves()
00119 {
00120   myCoEdgeList.clean_out();
00121 }
00122 
00123 OCCCoEdge* OCCLoop::remove_coedge(OCCCoEdge *coedge)
00124 { 
00125   if(myCoEdgeList.remove(coedge))
00126     return coedge;
00127   return NULL;
00128 }
00129 
00130 //-------------------------------------------------------------------------
00131 // Purpose       : The purpose of this function is to append a
00132 //                 attribute to the GE. The name is attached to the
00133 //                 underlying solid model entity this one points to.
00134 //
00135 //
00136 // Special Notes :
00137 //
00138 //-------------------------------------------------------------------------
00139 void OCCLoop::append_simple_attribute_virt(const CubitSimpleAttrib& /*csattrib_ptr*/)
00140 {
00141 }
00142 
00143 //-------------------------------------------------------------------------
00144 // Purpose       : The purpose of this function is to remove a simple
00145 //                 attribute attached to this geometry entity. The name is
00146 //                 removed from the underlying BODY this points to.
00147 //
00148 // Special Notes :
00149 //
00150 //-------------------------------------------------------------------------
00151 void OCCLoop::remove_simple_attribute_virt(const CubitSimpleAttrib& /*csattrib_ptr*/)
00152 {
00153 }
00154 
00155 //-------------------------------------------------------------------------
00156 // Purpose       : The purpose of this function is to remove all simple
00157 //                 attributes attached to this geometry entity.  Also
00158 //                 removes lingering GTC attributes.
00159 //
00160 //
00161 // Special Notes :
00162 //
00163 //-------------------------------------------------------------------------
00164 void OCCLoop::remove_all_simple_attribute_virt()
00165 {
00166 }
00167 
00168 //-------------------------------------------------------------------------
00169 // Purpose       : The purpose of this function is to get the
00170 //                 attributes attached to this geometry entity. The name is
00171 //                 attached to the underlying BODY this points to.
00172 //
00173 // Special Notes :
00174 //
00175 //-------------------------------------------------------------------------
00176 CubitStatus OCCLoop::get_simple_attribute(DLIList<CubitSimpleAttrib>&
00177                                                  /*cubit_simple_attrib_list*/)
00178 {
00179   return CUBIT_FAILURE;
00180 }
00181 CubitStatus OCCLoop::get_simple_attribute(const CubitString&,
00182                                           DLIList<CubitSimpleAttrib>&)
00183   { return CUBIT_FAILURE; }
00184 
00185 void OCCLoop::get_parents_virt( DLIList<TopologyBridge*>& parents )
00186 {
00187   OCCQueryEngine* oqe = (OCCQueryEngine*) get_geometry_query_engine();
00188   OCCSurface * surf = NULL;
00189   DLIList <OCCSurface* > *surfs = oqe->SurfaceList;
00190   TopTools_IndexedDataMapOfShapeListOfShape M;
00191   for(int i = 0; i <  surfs->size(); i++)
00192   {
00193      surf = surfs->get_and_step();
00194      TopExp::MapShapesAndAncestors(*(surf->get_TopoDS_Face()),
00195                                    TopAbs_WIRE, TopAbs_FACE, M);
00196      if (!M.Contains(*(get_TopoDS_Wire())))
00197     continue;
00198 
00199      const TopTools_ListOfShape& ListOfShapes =
00200                                 M.FindFromKey(*(get_TopoDS_Wire()));
00201      if (!ListOfShapes.IsEmpty())
00202      {
00203          TopTools_ListIteratorOfListOfShape it(ListOfShapes) ;
00204          for (;it.More(); it.Next())
00205          {
00206            TopoDS_Face Face = TopoDS::Face(it.Value());
00207            int k = oqe->OCCMap->Find(Face);
00208            parents.append_unique((OCCSurface*)(oqe->OccToCGM->find(k))->second);
00209          }
00210      }
00211   }
00212 }
00213 
00214 void OCCLoop::get_children_virt( DLIList<TopologyBridge*>& children )
00215 {
00216   CAST_LIST_TO_PARENT(myCoEdgeList, children);
00217 }
00218 
00219 //-------------------------------------------------------------------------
00220 // Purpose       : compute bounding box of loop
00221 //
00222 // Special Notes :
00223 //
00224 //-------------------------------------------------------------------------
00225 CubitBox OCCLoop::bounding_box() const
00226 {
00227    CubitBox box;
00228    for (int i = myCoEdgeList.size(); i > 0; i--)
00229    {
00230       DLIList<OCCCoEdge*> coedges = myCoEdgeList;
00231       OCCCoEdge* coedge = coedges.get_and_step();
00232       box |= coedge->curve()->bounding_box();
00233    }
00234    return box;
00235 }
00236 
00237 //-------------------------------------------------------------------------
00238 // Purpose       : Get geometry modeling engine: OCCQueryEngine
00239 //
00240 // Special Notes :
00241 //
00242 //-------------------------------------------------------------------------
00243 GeometryQueryEngine* OCCLoop::get_geometry_query_engine() const
00244 {
00245    return OCCQueryEngine::instance();
00246 }                
00247 
00248 
00249 //----------------------------------------------------------------
00250 // Function: to update the core Loop
00251 //           for any movement of the body/surface.
00252 // Author: Jane Hu
00253 //----------------------------------------------------------------
00254 CubitStatus OCCLoop::update_OCC_entity( BRepBuilderAPI_ModifyShape *aBRepTrsf,
00255                                         BRepAlgoAPI_BooleanOperation *op)
00256 {
00257   assert(aBRepTrsf != NULL || op != NULL);
00258 
00259   TopoDS_Shape shape;
00260   CubitBoolean need_update = CUBIT_TRUE;
00261   BRepBuilderAPI_Transform* pTrsf = NULL;
00262   BRepBuilderAPI_GTransform* gTrsf = NULL;
00263   if(aBRepTrsf)
00264   {
00265     pTrsf = (BRepBuilderAPI_Transform*)aBRepTrsf;
00266     shape = pTrsf->ModifiedShape(*get_TopoDS_Wire());
00267     if(shape.IsNull())
00268     {
00269       gTrsf = (BRepBuilderAPI_GTransform*)aBRepTrsf;
00270       shape = gTrsf->ModifiedShape(*get_TopoDS_Wire());
00271     }
00272   }
00273   else
00274   {
00275     TopTools_ListOfShape shapes; 
00276     shapes.Assign(op->Modified(*get_TopoDS_Wire()));
00277     if(shapes.Extent() == 0)
00278          shapes.Assign(op->Generated(*get_TopoDS_Wire()));
00279     if(shapes.Extent())
00280       shape = shapes.First();
00281     else if (op->IsDeleted(*get_TopoDS_Wire()))
00282       ;
00283     else
00284       need_update = CUBIT_FALSE;
00285   }
00286 
00287   //set the curves
00288   for (int i = 1; i <= myCoEdgeList.size(); i++)
00289   {
00290      OCCCurve *curve = CAST_TO(myCoEdgeList.get_and_step()->curve(), OCCCurve);
00291      curve->update_OCC_entity(aBRepTrsf, op);
00292   }
00293   TopoDS_Wire loop;
00294   if (need_update)
00295   {
00296     loop = TopoDS::Wire(shape);
00297     OCCQueryEngine::instance()->update_OCC_map(*myTopoDSWire, loop);
00298   }
00299   return CUBIT_SUCCESS;
00300 }
00301 
00302 //----------------------------------------------------------------
00303 // Function: TopoDS_Shape level function to update the core Loop
00304 //           for split Boolean operation of the body.
00305 // Author: Jane Hu
00306 //----------------------------------------------------------------
00307 CubitStatus OCCLoop::update_OCC_entity(TopoDS_Wire & old_loop,
00308                                        LocOpe_SplitShape* sp)
00309 {
00310   TopTools_ListOfShape shapes;
00311   shapes.Assign(sp->DescendantShapes(old_loop));
00312   assert(shapes.Extent() == 1);
00313   TopoDS_Shape new_loop = shapes.First();
00314   TopoDS_Shape shape_edge;
00315 
00316   //set curves
00317   BRepTools_WireExplorer Ex;
00318   for(Ex.Init(old_loop); Ex.More();Ex.Next())   
00319   {
00320     TopoDS_Edge edge = Ex.Current();
00321     shapes.Assign(sp->DescendantShapes(edge));
00322     if(shapes.Extent() > 1)
00323     {
00324       shape_edge = shapes.First();
00325      
00326       OCCQueryEngine::instance()->update_OCC_map(edge, shape_edge);
00327     } 
00328   }
00329   
00330   OCCQueryEngine::instance()->update_OCC_map(old_loop , new_loop );
00331   return CUBIT_SUCCESS; 
00332 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines