cgma
OCCLump.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : OCCLump.cpp
00003 //
00004 // Purpose       : 
00005 //
00006 // Creator       : David White
00007 //
00008 // Creation Date : 7/18/2000
00009 //
00010 //-------------------------------------------------------------------------
00011 
00012 // ********** BEGIN STANDARD INCLUDES      **********
00013 #include <assert.h>
00014 // ********** END STANDARD INCLUDES        **********
00015 // ********** BEGIN CUBIT INCLUDES         **********
00016 #include "OCCQueryEngine.hpp"
00017 #include "OCCLump.hpp"
00018 #include "CastTo.hpp"
00019 #include "Surface.hpp"
00020 #include "DLIList.hpp"
00021 #include "CubitVector.hpp"
00022 #include "CubitString.hpp"
00023 #include "ShellSM.hpp"
00024 #include "BodySM.hpp"
00025 #include "Body.hpp"
00026 
00027 #include "OCCBody.hpp"
00028 #include "OCCShell.hpp"
00029 #include "OCCSurface.hpp"
00030 #include "OCCLoop.hpp"
00031 #include "OCCCoEdge.hpp"
00032 #include "OCCCurve.hpp"
00033 #include "OCCPoint.hpp"
00034 #include "OCCAttribSet.hpp"
00035 
00036 #include <TopExp.hxx>
00037 #include <TopTools_IndexedMapOfShape.hxx>
00038 #include "BRepBuilderAPI_Transform.hxx"
00039 #include "BRepBuilderAPI_GTransform.hxx"
00040 #include "TopTools_DataMapOfShapeInteger.hxx"
00041 #include "TopTools_ListIteratorOfListOfShape.hxx"
00042 #include "BRepAlgoAPI_BooleanOperation.hxx"
00043 #include "BRepBuilderAPI_MakeShape.hxx"
00044 #include "BRepBuilderAPI_ModifyShape.hxx"
00045 #include "Bnd_Box.hxx"
00046 #include "BRepBndLib.hxx"
00047 #include "GProp_GProps.hxx"
00048 #include "BRepGProp.hxx"
00049 #include "BRepClass3d_SolidExplorer.hxx"
00050 #include "BRepClass3d_SClassifier.hxx"
00051 #include "TopExp_Explorer.hxx"
00052 #include "TopoDS.hxx"
00053 #include "BRep_Tool.hxx"
00054 #include "LocOpe_SplitShape.hxx"
00055 // ********** END CUBIT INCLUDES           **********
00056 
00057 // ********** BEGIN FORWARD DECLARATIONS   **********
00058 class RefVolume;
00059 // ********** END FORWARD DECLARATIONS     **********
00060 
00061 // ********** BEGIN STATIC DECLARATIONS    **********
00062 // ********** END STATIC DECLARATIONS      **********
00063 
00064 // ********** BEGIN PUBLIC FUNCTIONS       **********
00065 
00066 //-------------------------------------------------------------------------
00067 // Purpose       : The constructor with a pointer to TopoDS_Solid
00068 //
00069 // Special Notes :
00070 //
00071 //-------------------------------------------------------------------------
00072 OCCLump::OCCLump(TopoDS_Solid *theSolid, OCCSurface* surface, OCCShell* shell)
00073 {
00074   myTopoDSSolid = theSolid;
00075   mySheetSurface = surface;
00076   myShell = shell;
00077   if(myTopoDSSolid && !myTopoDSSolid->IsNull())
00078     assert(myTopoDSSolid->ShapeType() == TopAbs_SOLID);
00079 }
00080 
00081 OCCLump::~OCCLump()
00082 { 
00083   if (myTopoDSSolid)
00084   {
00085     myTopoDSSolid->Nullify();
00086     delete myTopoDSSolid;
00087   }
00088 }
00089 
00090 void OCCLump::set_TopoDS_Solid(TopoDS_Solid solid)
00091 {
00092   if(myTopoDSSolid && solid.IsEqual(*myTopoDSSolid) )
00093     return;
00094 
00095   if(myTopoDSSolid)
00096     myTopoDSSolid->Nullify() ;
00097 
00098   *myTopoDSSolid = solid;
00099 }
00100 //-------------------------------------------------------------------------
00101 // Purpose       : Find centroid
00102 //
00103 // Special Notes :
00104 //
00105 // Author       : Jane Hu
00106 //
00107 // Creation Date : 12/06/07
00108 //-------------------------------------------------------------------------
00109 CubitStatus OCCLump::mass_properties( CubitVector& centroid,
00110                                       double& volume )
00111 {
00112   if (mySheetSurface || myShell)
00113     return CUBIT_FAILURE;
00114 
00115   GProp_GProps myProps;
00116   BRepGProp::VolumeProperties(*myTopoDSSolid, myProps);
00117   volume = myProps.Mass();
00118   gp_Pnt pt = myProps.CentreOfMass();
00119   centroid.set(pt.X(), pt.Y(), pt.Z());
00120 
00121   return CUBIT_SUCCESS;
00122 }
00123 
00124 //-------------------------------------------------------------------------
00125 // Purpose       : The purpose of this function is to append a
00126 //                 attribute to the GE. The name is attached to the 
00127 //                 underlying solid model entity this one points to.
00128 //
00129 //
00130 // Special Notes : 
00131 //
00132 // Creator       : Malcolm J. Panthaki
00133 //
00134 // Creation Date : 11/21/96
00135 //-------------------------------------------------------------------------
00136 void OCCLump::append_simple_attribute_virt(const CubitSimpleAttrib &csa)
00137 { 
00138   TopoDS_Shape shape;
00139   if(mySheetSurface)
00140     shape = *(mySheetSurface->get_TopoDS_Face());
00141   else if(myShell)
00142     shape = *(myShell->get_TopoDS_Shell());
00143   else
00144     shape =*myTopoDSSolid;
00145   OCCAttribSet::append_attribute(csa, shape); 
00146 }
00147 
00148 //-------------------------------------------------------------------------
00149 // Purpose       : The purpose of this function is to remove a simple 
00150 //                 attribute attached to this geometry entity. The name is 
00151 //                 removed from the underlying BODY this points to.
00152 //
00153 // Special Notes : 
00154 //
00155 // Creator       : David R. White
00156 //
00157 // Creation Date : 03/18/97
00158 //-------------------------------------------------------------------------
00159 void OCCLump::remove_simple_attribute_virt(const CubitSimpleAttrib &csa )
00160 { 
00161   TopoDS_Shape shape;
00162   if(mySheetSurface)
00163     shape = *(mySheetSurface->get_TopoDS_Face());
00164   else if(myShell)
00165     shape = *(myShell->get_TopoDS_Shell());
00166   else
00167     shape =*myTopoDSSolid;
00168   OCCAttribSet::remove_attribute(csa, shape); 
00169 }
00170 
00171 //-------------------------------------------------------------------------
00172 // Purpose       : The purpose of this function is to remove all simple 
00173 //                 attributes attached to this geometry entity.  Also
00174 //                 removes lingering GTC attributes.
00175 //
00176 //
00177 // Special Notes : 
00178 //
00179 // Creator       : Greg Nielson
00180 //
00181 // Creation Date : 07/10/98
00182 //-------------------------------------------------------------------------
00183 void OCCLump::remove_all_simple_attribute_virt()
00184 { 
00185   TopoDS_Shape shape;
00186   if(mySheetSurface)
00187     shape = *(mySheetSurface->get_TopoDS_Face());
00188   else if(myShell)
00189     shape = *(myShell->get_TopoDS_Shell());
00190   else
00191     shape =*myTopoDSSolid;
00192   OCCAttribSet::remove_attribute(CubitSimpleAttrib(), shape);
00193 }
00194 
00195 //-------------------------------------------------------------------------
00196 // Purpose       : The purpose of this function is to get the  
00197 //                 attributes attached to this geometry entity. The name is 
00198 //                 attached to the underlying BODY this points to.
00199 //
00200 // Special Notes : 
00201 //
00202 //-------------------------------------------------------------------------
00203 CubitStatus OCCLump::get_simple_attribute(DLIList<CubitSimpleAttrib>& csa_list)
00204 { 
00205   TopoDS_Shape shape;
00206   if(mySheetSurface)
00207     shape = *(mySheetSurface->get_TopoDS_Face());
00208   else if(myShell)
00209     shape = *(myShell->get_TopoDS_Shell());
00210   else
00211     shape =*myTopoDSSolid;
00212   return OCCAttribSet::get_attributes(shape, csa_list ); 
00213 }
00214 
00215 CubitStatus OCCLump::get_simple_attribute( const CubitString& name,
00216                                         DLIList<CubitSimpleAttrib>& csa_list )
00217 {
00218   TopoDS_Shape shape;
00219   if(mySheetSurface)
00220     shape = *(mySheetSurface->get_TopoDS_Face());
00221   else if(myShell)
00222     shape = *(myShell->get_TopoDS_Shell());
00223   else
00224     shape =*myTopoDSSolid;
00225   return OCCAttribSet::get_attributes( name, shape, csa_list ); 
00226 }
00227 
00228 
00229 //-------------------------------------------------------------------------
00230 // Purpose       : Get the bounding box of the object.
00231 //
00232 // Special Notes :
00233 //
00234 //-------------------------------------------------------------------------
00235 CubitBox OCCLump::bounding_box() const 
00236 {
00237   Bnd_Box box;
00238   TopoDS_Shape shape;
00239   if(mySheetSurface)
00240     shape = *(mySheetSurface->get_TopoDS_Face());
00241   else if(myShell)
00242     shape = *(myShell->get_TopoDS_Shell());
00243   else
00244     shape =*myTopoDSSolid;
00245 
00246   //calculate the bounding box
00247   BRepBndLib::Add(shape, box);
00248   double min[3], max[3];
00249 
00250   //get values
00251   box.Get(min[0], min[1], min[2], max[0], max[1], max[2]);
00252 
00253   //update boundingbox.
00254   CubitBox cBox(min, max);
00255   return cBox;
00256 }
00257 
00258 //-------------------------------------------------------------------------
00259 // Purpose       : Get geometry modeling engine: OCCGeometryEngine
00260 //
00261 // Special Notes :
00262 //
00263 //-------------------------------------------------------------------------
00264 GeometryQueryEngine* 
00265                  OCCLump::get_geometry_query_engine() const
00266 {
00267    return OCCQueryEngine::instance();
00268 }                 
00269 
00270 //-------------------------------------------------------------------------
00271 // Purpose       : Returns the volume of the Lump
00272 //
00273 // Special Notes :
00274 //
00275 // Creator       : 
00276 //
00277 // Creation Date : 
00278 //-------------------------------------------------------------------------
00279 double OCCLump::measure()
00280 {
00281   if(mySheetSurface) 
00282     return mySheetSurface->measure();
00283   else if(myShell)
00284     return myShell->measure();
00285 
00286   GProp_GProps myProps;
00287   BRepGProp::VolumeProperties(*myTopoDSSolid, myProps);
00288   return myProps.Mass();
00289 }
00290 
00291 void OCCLump::get_parents_virt(DLIList<TopologyBridge*> &bodies) 
00292 {
00293   if(mySheetSurface)
00294     bodies.append(mySheetSurface->my_body());
00295   else if (myShell)
00296     bodies.append(myShell->my_body());
00297   else
00298     bodies.append(myBodyPtr);
00299 }
00300 
00301 BodySM* OCCLump::get_body() const
00302 {
00303   if(mySheetSurface)
00304     return mySheetSurface->my_body();
00305   if(myShell)
00306     return myShell->my_body();
00307   return myBodyPtr;
00308 }
00309 
00310 void OCCLump::get_children_virt(DLIList<TopologyBridge*> &shellsms)
00311 {
00312   if (mySheetSurface)
00313   {
00314     shellsms.append(mySheetSurface->my_shell());
00315     return;
00316   }
00317   else if(myShell)
00318   {
00319     shellsms.append(myShell);
00320     return;
00321   }
00322   TopTools_IndexedMapOfShape M;
00323   TopExp::MapShapes(*myTopoDSSolid, TopAbs_SHELL, M);
00324   int ii;
00325   for (ii=1; ii<=M.Extent(); ii++) {
00326       TopologyBridge *shell = OCCQueryEngine::instance()->occ_to_cgm(M(ii));
00327           if (shell)
00328         shellsms.append_unique(shell);
00329   }
00330 }
00331 
00332 
00333 
00334 CubitPointContainment OCCLump::point_containment( const CubitVector &point )
00335 {
00336   if (mySheetSurface || myShell)
00337     return CUBIT_PNT_UNKNOWN;
00338 
00339   TopoDS_Solid * solid = get_TopoDS_Solid();
00340   gp_Pnt pnt(point.x(), point.y(), point.z());
00341   BRepClass3d_SolidExplorer ex(*solid);
00342    
00343   //use face tolerance at the tolerence to see if the point is on.
00344   TopExp_Explorer Ex;
00345   Ex.Init(*solid, TopAbs_FACE);
00346   TopoDS_Face face = TopoDS::Face(Ex.Current());
00347   
00348   double dtol = BRep_Tool::Tolerance(face);
00349   BRepClass3d_SClassifier ps(ex, pnt, dtol);
00350   
00351   TopAbs_State state = ps.State();
00352   if (state == TopAbs_IN)
00353      return CUBIT_PNT_INSIDE;
00354   else if (state == TopAbs_OUT)
00355      return CUBIT_PNT_OUTSIDE;
00356   else if (state == TopAbs_ON)
00357      return CUBIT_PNT_BOUNDARY;
00358 
00359   return CUBIT_PNT_UNKNOWN;
00360   
00361 }
00362 
00363 //----------------------------------------------------------------
00364 // Function: to update the core Solid
00365 //           for any movement of the lump.
00366 // Author: Jane Hu
00367 //----------------------------------------------------------------
00368 CubitStatus OCCLump::update_OCC_entity( BRepBuilderAPI_ModifyShape *aBRepTrsf,
00369                                         BRepAlgoAPI_BooleanOperation *op)
00370 {
00371   if(mySheetSurface || myShell)
00372     return CUBIT_FAILURE;
00373 
00374   assert(aBRepTrsf != NULL || op != NULL);
00375  
00376   TopoDS_Shape shape;
00377   if(aBRepTrsf)
00378     shape = aBRepTrsf->ModifiedShape(*get_TopoDS_Solid());
00379 
00380   else
00381   {
00382     TopTools_ListOfShape shapes;
00383     shapes.Assign(op->Modified(*get_TopoDS_Solid()));
00384     if(shapes.Extent() == 0)
00385       shapes.Assign(op->Generated(*get_TopoDS_Solid()));
00386     if(shapes.Extent() > 1)
00387     { 
00388       //update all attributes first.
00389       TopTools_ListIteratorOfListOfShape it;
00390       it.Initialize(shapes);
00391       for(; it.More(); it.Next())
00392       {
00393         shape = it.Value();
00394         OCCQueryEngine::instance()->copy_attributes(*get_TopoDS_Solid(), 
00395                                                     shape);
00396       }
00397       shape = shapes.First();
00398     }
00399     else if (shapes.Extent() == 1)
00400       shape = shapes.First();
00401     else if(op->IsDeleted(*get_TopoDS_Solid()))
00402       ;
00403     else
00404       return CUBIT_SUCCESS;
00405   }
00406   
00407   TopoDS_Solid solid;
00408   if(aBRepTrsf || !op->IsDeleted(*get_TopoDS_Solid()))
00409     solid = TopoDS::Solid(shape);
00410 
00411   //set the lumps
00412   DLIList<TopologyBridge *> shells;
00413   this->get_children_virt(shells);
00414   for (int i = 1; i <= shells.size(); i++)
00415   {
00416      OCCShell *shell = CAST_TO(shells.get_and_step(), OCCShell);
00417      shell->update_OCC_entity(aBRepTrsf, op);
00418   }
00419   OCCQueryEngine::instance()->update_OCC_map(*myTopoDSSolid, solid);
00420 
00421   return CUBIT_SUCCESS;
00422 }
00423 
00424 //----------------------------------------------------------------
00425 // Function: TopoDS_Shape level function to update the core Lump
00426 //           for any movement  or Boolean operation of the body.
00427 // Author: Jane Hu
00428 //----------------------------------------------------------------
00429 CubitStatus OCCLump::update_OCC_entity(TopoDS_Solid& old_solid,
00430                                        TopoDS_Shape& new_shape,
00431                                        BRepBuilderAPI_MakeShape *op,
00432                                        LocOpe_SplitShape* sp)
00433 {
00434   //set the Shells
00435   TopTools_IndexedMapOfShape M;
00436   TopoDS_Shape shape, shape2;
00437   TopExp::MapShapes(new_shape, TopAbs_SOLID,M);
00438   TopoDS_Solid new_solid;
00439   CubitBoolean isCompound = CUBIT_FALSE;
00440   if(M.Extent() > 1 )
00441     isCompound = CUBIT_TRUE;
00442 
00443   if(M.Extent() == 1 )
00444     new_solid = TopoDS::Solid(M(1));  
00445 
00446   M.Clear();
00447   TopExp::MapShapes(old_solid, TopAbs_SHELL, M);
00448   TopTools_ListOfShape shapes;
00449  
00450   for(int ii=1; ii<=M.Extent(); ii++)
00451   {
00452     TopoDS_Shell shell = TopoDS::Shell(M(ii));
00453 
00454     TopTools_ListOfShape shapes;
00455     TopTools_IndexedMapOfShape M2;
00456     if (op)
00457     {
00458       shapes.Assign(op->Modified(shell));
00459       if(shapes.Extent() == 0)
00460          shapes.Assign(op->Generated(shell));
00461       // bug fix for hollow operation, in which a new shell is genearted
00462       // but the shapes we get from old_shell->Generated() is still old_shell
00463       // not the new one.
00464       if(!new_solid.IsNull())  
00465          TopExp::MapShapes(new_solid, TopAbs_SHELL, M2);
00466     }
00467     else if(sp)
00468       shapes.Assign(sp->DescendantShapes(shell));
00469 
00470     if (shapes.Extent() == 1)
00471     {
00472       shape = shapes.First(); 
00473       if(M2.Extent() > 0)
00474         shape2 = TopoDS::Shell(M2(1)); 
00475       if(M2.Extent() == 1 && !shape.IsSame(shape2))
00476          shape = shape2;
00477       else if(M2.Extent() > 1)
00478       {
00479          shapes.Clear(); 
00480          for(int jj = 1; jj <= M2.Extent(); jj++) 
00481            shapes.Append(M2(jj));
00482       }
00483     }
00484 
00485     else if(shapes.Extent() > 1)
00486     {
00487       //update all attributes first.
00488       TopTools_ListIteratorOfListOfShape it;
00489       it.Initialize(shapes);
00490       for(; it.More(); it.Next())
00491       {
00492         shape = it.Value();
00493         OCCQueryEngine::instance()->copy_attributes(shell, shape);
00494       }
00495       shape = shapes.First();
00496     }
00497     else if(op->IsDeleted(shell))
00498     {
00499        TopTools_IndexedMapOfShape M_new;
00500        TopExp::MapShapes(new_shape, TopAbs_SHELL, M_new);
00501        if (M_new.Extent()== 1)
00502          shape = M_new(1);
00503        else
00504          shape.Nullify();
00505     }
00506     else
00507     {
00508        shape = shell;
00509        continue;
00510     }
00511  
00512     if(shapes.Extent() > 0 || (op && op->IsDeleted(shell)))
00513       OCCShell::update_OCC_entity(shell, shape, op, sp);
00514   }
00515   if(!new_solid.IsNull() && !old_solid.IsSame(new_solid))
00516     OCCQueryEngine::instance()->update_OCC_map(old_solid, new_solid);
00517   else if(isCompound)
00518     OCCQueryEngine::instance()->update_OCC_map(old_solid, new_shape);  
00519   return CUBIT_SUCCESS;
00520 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines