cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : OCCBody.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : David White 00009 // 00010 // Creation Date : 7/18/00 00011 // 00012 //------------------------------------------------------------------------- 00013 00014 // ********** BEGIN STANDARD INCLUDES ********** 00015 #include <assert.h> 00016 // ********** END STANDARD INCLUDES ********** 00017 00018 // ********** BEGIN CUBIT INCLUDES ********** 00019 #include "CubitDefines.h" 00020 #include "CubitString.hpp" 00021 #include "CastTo.hpp" 00022 #include "BodySM.hpp" 00023 #include "Body.hpp" 00024 #include "OCCBody.hpp" 00025 #include "CubitSimpleAttrib.hpp" 00026 #include "OCCQueryEngine.hpp" 00027 #include "DLIList.hpp" 00028 #include "Surface.hpp" 00029 #include "OCCSurface.hpp" 00030 #include "CubitTransformMatrix.hpp" 00031 #include "OCCPoint.hpp" 00032 #include "OCCCurve.hpp" 00033 #include "OCCCoEdge.hpp" 00034 #include "OCCLoop.hpp" 00035 #include "OCCShell.hpp" 00036 #include "OCCLump.hpp" 00037 #include "OCCModifyEngine.hpp" 00038 #include "OCCAttribSet.hpp" 00039 00040 #include <TopExp.hxx> 00041 #include <TopTools_IndexedMapOfShape.hxx> 00042 #include "BRepBuilderAPI_ModifyShape.hxx" 00043 #include "BRepBuilderAPI_Transform.hxx" 00044 #include "BRepBuilderAPI_GTransform.hxx" 00045 #include "TopTools_DataMapOfShapeInteger.hxx" 00046 #include "TopTools_ListIteratorOfListOfShape.hxx" 00047 #include "gp_Ax1.hxx" 00048 #include "gp_Ax2.hxx" 00049 #include "gp_GTrsf.hxx" 00050 #include "Bnd_Box.hxx" 00051 #include "BRepBndLib.hxx" 00052 #include "TopExp_Explorer.hxx" 00053 #include "BRep_Builder.hxx" 00054 #include "TopoDS.hxx" 00055 #include "GProp_GProps.hxx" 00056 #include "BRepGProp.hxx" 00057 #include "Standard_Boolean.hxx" 00058 #include "LocOpe_SplitShape.hxx" 00059 #include "TopoDS_Compound.hxx" 00060 //------------------------------------------------------------------------- 00061 // Purpose : A constructor with a list of lumps that are attached. 00062 // 00063 // Special Notes : 00064 // 00065 //------------------------------------------------------------------------- 00066 OCCBody::OCCBody(TopoDS_Compound *theShape, 00067 OCCSurface* surface, OCCShell* shell, Lump* lump) 00068 { 00069 myTopoDSShape = theShape; 00070 if (surface != NULL) 00071 mySheetSurfaces.append(surface); 00072 if( shell != NULL) 00073 myShells.append(shell); 00074 if (lump != NULL) 00075 myLumps.append(lump); 00076 update_bounding_box(); 00077 if (myTopoDSShape && !myTopoDSShape->IsNull()) 00078 assert(myTopoDSShape->ShapeType() == TopAbs_COMPOUND); 00079 } 00080 00081 TopoDS_Compound* OCCBody::get_TopoDS_Shape() 00082 { 00083 if (myTopoDSShape && !myTopoDSShape->IsNull()) 00084 { 00085 assert(myTopoDSShape->ShapeType() == TopAbs_COMPOUND); 00086 return myTopoDSShape; 00087 } 00088 return (TopoDS_Compound*)NULL; 00089 } 00090 00091 void OCCBody::get_TopoDS_Shape(TopoDS_Shape *& shape) 00092 { 00093 if (myTopoDSShape && !myTopoDSShape->IsNull()) 00094 { 00095 assert(myTopoDSShape->ShapeType() == TopAbs_COMPOUND); 00096 shape = myTopoDSShape; 00097 } 00098 else 00099 { 00100 DLIList<Lump*> lumps = this->lumps(); 00101 DLIList<OCCShell*> shells = this->shells(); 00102 DLIList<OCCSurface*> surfaces = this->my_sheet_surfaces(); 00103 if(lumps.size() + shells.size() + surfaces.size() == 1) 00104 { 00105 if(lumps.size() == 1) 00106 { 00107 OCCLump* lump = CAST_TO(lumps.get(), OCCLump); 00108 assert(lump != NULL); 00109 shape = CAST_TO(lump, OCCLump)->get_TopoDS_Solid(); 00110 } 00111 else if(shells.size() == 1) 00112 shape = shells.get()->get_TopoDS_Shell(); 00113 else 00114 shape = surfaces.get()->get_TopoDS_Face(); 00115 } 00116 else 00117 shape = NULL; 00118 } 00119 } 00120 00121 void OCCBody::set_sheet_surfaces(DLIList<OCCSurface*> surfaces) 00122 { 00123 mySheetSurfaces = surfaces; 00124 } 00125 00126 void OCCBody::lumps(DLIList<Lump*>& my_lumps) 00127 { 00128 myLumps = my_lumps; 00129 } 00130 00131 CubitBoolean OCCBody::is_sheet_body() 00132 { 00133 if(myLumps.size() == 0 && myShells.size() == 0 && mySheetSurfaces.size() == 1) 00134 return CUBIT_TRUE; 00135 return CUBIT_FALSE; 00136 } 00137 00138 void OCCBody::set_TopoDS_Shape( TopoDS_Compound& theshape) 00139 { 00140 if(!theshape.IsNull()) 00141 assert(theshape.ShapeType() == TopAbs_COMPOUND); 00142 00143 else 00144 { 00145 if(myTopoDSShape && !myTopoDSShape->IsNull()) 00146 myTopoDSShape->Nullify(); 00147 return; 00148 } 00149 00150 if(myTopoDSShape && !myTopoDSShape->IsNull() && theshape.IsEqual(*myTopoDSShape)) 00151 return; 00152 00153 if (myTopoDSShape && !myTopoDSShape->IsNull() && theshape.IsPartner(*myTopoDSShape)) 00154 { 00155 myTopoDSShape->Location(theshape.Location()); 00156 myTopoDSShape->Orientation(theshape.Orientation()); 00157 } 00158 00159 else 00160 { 00161 if(myTopoDSShape) 00162 myTopoDSShape->Nullify(); 00163 *myTopoDSShape = theshape; 00164 } 00165 } 00166 00167 OCCBody::OCCBody(DLIList<Lump*>& my_lumps, 00168 DLIList<OCCShell*>& shells, 00169 DLIList<OCCSurface*>& surfaces) 00170 { 00171 myLumps = my_lumps; 00172 mySheetSurfaces = surfaces; 00173 myShells = shells; 00174 TopoDS_Compound* new_top = make_Compound(my_lumps, shells, surfaces); 00175 myTopoDSShape = new_top; 00176 assert (myTopoDSShape->ShapeType() == TopAbs_COMPOUND); 00177 update_bounding_box(); 00178 } 00179 00180 TopoDS_Compound* OCCBody::make_Compound(DLIList<Lump*>& my_lumps, 00181 DLIList<OCCShell*>& shells, 00182 DLIList<OCCSurface*>& surfaces) 00183 { 00184 BRep_Builder B; 00185 TopoDS_Compound Co; 00186 B.MakeCompound(Co); 00187 for(int i = 0; i < my_lumps.size(); i ++) 00188 { 00189 OCCLump* lump = CAST_TO(my_lumps.get_and_step(), OCCLump); 00190 if(!lump) 00191 { 00192 PRINT_ERROR("Cannot create an OCC BodySM from the given lumps.\n" 00193 "Possible incompatible geometry engines.\n"); 00194 return (TopoDS_Compound *)NULL; 00195 } 00196 TopoDS_Solid * solid = CAST_TO(lump, OCCLump)->get_TopoDS_Solid(); 00197 B.Add(Co, *solid); 00198 } 00199 for(int i = 0; i < shells.size(); i ++) 00200 { 00201 TopoDS_Shell * shell = shells.get_and_step()->get_TopoDS_Shell(); 00202 B.Add(Co, *shell); 00203 } 00204 for(int i = 0; i < surfaces.size(); i ++) 00205 { 00206 TopoDS_Face * face = surfaces.get_and_step()->get_TopoDS_Face(); 00207 B.Add(Co, *face); 00208 } 00209 00210 TopoDS_Compound* new_top = new TopoDS_Compound(Co); 00211 return new_top; 00212 } 00213 00214 OCCBody::~OCCBody() 00215 { 00216 if (myTopoDSShape) 00217 { 00218 myTopoDSShape->Nullify(); 00219 delete (TopoDS_Compound*)myTopoDSShape; 00220 myTopoDSShape = NULL; 00221 } 00222 } 00223 00224 GeometryQueryEngine* OCCBody::get_geometry_query_engine() const 00225 { 00226 return OCCQueryEngine::instance(); 00227 } 00228 00229 void OCCBody::append_simple_attribute_virt(const CubitSimpleAttrib &csa) 00230 { 00231 if (myTopoDSShape != NULL) 00232 { 00233 OCCAttribSet::append_attribute(csa, *myTopoDSShape); 00234 return; 00235 } 00236 csa_list.append_unique(csa); 00237 } 00238 00239 void OCCBody::remove_simple_attribute_virt(const CubitSimpleAttrib &csa) 00240 { 00241 DLIList<Lump*> my_lumps; 00242 my_lumps = lumps(); 00243 DLIList<OCCShell*> shells = this->shells(); 00244 DLIList<OCCSurface*> surfaces = this->my_sheet_surfaces(); 00245 00246 if (myTopoDSShape != NULL) 00247 { 00248 OCCAttribSet::remove_attribute(csa, *myTopoDSShape); 00249 return; 00250 } 00251 00252 else if (my_lumps.size() == 1) 00253 { 00254 OCCLump* lump = CAST_TO(my_lumps.get(), OCCLump); 00255 TopoDS_Solid* solid = lump->get_TopoDS_Solid(); 00256 OCCAttribSet::remove_attribute(csa, *solid); 00257 if(!csa.isEmpty()) 00258 csa_list.remove(csa); 00259 else 00260 csa_list.clean_out(); 00261 return; 00262 } 00263 00264 else if(shells.size() == 1) 00265 { 00266 TopoDS_Shell * shell = shells.get()->get_TopoDS_Shell(); 00267 OCCAttribSet::remove_attribute(csa, *shell); 00268 if(!csa.isEmpty()) 00269 csa_list.remove(csa); 00270 else 00271 csa_list.clean_out(); 00272 return; 00273 } 00274 00275 else if(surfaces.size() == 1) 00276 { 00277 TopoDS_Face* surf = surfaces.get()->get_TopoDS_Face(); 00278 OCCAttribSet::remove_attribute(csa, *surf); 00279 if(!csa.isEmpty()) 00280 csa_list.remove(csa); 00281 else 00282 csa_list.clean_out(); 00283 return; 00284 } 00285 } 00286 00287 00288 void OCCBody::remove_all_simple_attribute_virt() 00289 { 00290 remove_simple_attribute_virt(CubitSimpleAttrib()); 00291 } 00292 00293 CubitStatus OCCBody::get_simple_attribute(DLIList<CubitSimpleAttrib>& csas) 00294 { 00295 if (myTopoDSShape != NULL) 00296 return OCCAttribSet::get_attributes(*myTopoDSShape,csas); 00297 00298 else 00299 csas = csa_list; 00300 return CUBIT_SUCCESS; 00301 } 00302 00303 CubitStatus OCCBody::get_simple_attribute( const CubitString& name, 00304 DLIList<CubitSimpleAttrib>& csas ) 00305 { 00306 if (myTopoDSShape != NULL) 00307 return OCCAttribSet::get_attributes( name, *myTopoDSShape, csa_list ); 00308 00309 for(int i = 0 ; i < csa_list.size(); i ++) 00310 { 00311 const CubitSimpleAttrib& csa = csa_list.get_and_step(); 00312 if(csa.string_data_list().size() > 0) 00313 if (csa.string_data_list()[0] == name) 00314 csas.append(csa); 00315 } 00316 return CUBIT_SUCCESS; 00317 } 00318 00319 CubitStatus OCCBody::get_transforms( CubitTransformMatrix &tfm ) 00320 { 00321 return CUBIT_SUCCESS; 00322 } 00323 00324 00325 //---------------------------------------------------------------- 00326 // Function: copy 00327 // Description: create a new copy of the body. 00328 // Author: sjowen 00329 //---------------------------------------------------------------- 00330 BodySM* OCCBody::copy() 00331 { 00332 return (BodySM*)NULL; 00333 } 00334 00335 //---------------------------------------------------------------- 00336 // Function: move 00337 // Description: translate the body and its child entities 00338 // 00339 // Author: Jane Hu 00340 //---------------------------------------------------------------- 00341 CubitStatus OCCBody::move(double dx, double dy, double dz) 00342 { 00343 double tol = OCCQueryEngine::instance()->get_sme_resabs_tolerance(); 00344 if(fabs(dx) < tol && fabs(dy) < tol && fabs(dz) < tol) 00345 return CUBIT_SUCCESS; 00346 00347 gp_Vec aVec(dx, dy, dz); 00348 gp_Trsf aTrsf; 00349 aTrsf.SetTranslation(aVec); 00350 00351 BRepBuilderAPI_Transform aBRepTrsf(aTrsf); 00352 00353 return transform(aBRepTrsf); 00354 } 00355 00356 00357 //---------------------------------------------------------------- 00358 // Function: rotate 00359 // Description: rotate the body and its child entities 00360 // 00361 // Author: Jane Hu 00362 //---------------------------------------------------------------- 00363 CubitStatus OCCBody::rotate( double x, double y, double z, 00364 double angle )//in radians 00365 { 00366 gp_Pnt aOrigin(0,0,0); 00367 gp_Dir aDir(x, y, z); 00368 gp_Ax1 anAxis(aOrigin, aDir); 00369 00370 //a is angular value of rotation in radians 00371 gp_Trsf aTrsf; 00372 aTrsf.SetRotation(anAxis, angle); 00373 00374 BRepBuilderAPI_Transform aBRepTrsf(aTrsf); 00375 00376 return transform(aBRepTrsf); 00377 } 00378 00379 //---------------------------------------------------------------- 00380 // Function: transform 00381 // Description: transform the body and its child entities 00382 // use a transform matrix 00383 // 00384 // Author: Jane Hu 00385 //---------------------------------------------------------------- 00386 CubitStatus OCCBody::transform(BRepBuilderAPI_Transform& aBRepTrsf) 00387 { 00388 TopoDS_Shape * shape; 00389 get_TopoDS_Shape(shape); 00390 aBRepTrsf.Perform(*shape); 00391 00392 update_OCC_entity(&aBRepTrsf); 00393 // calculate for bounding box 00394 update_bounding_box(); 00395 00396 return CUBIT_SUCCESS; 00397 } 00398 00399 //---------------------------------------------------------------- 00400 // Function: scale 00401 // Description: scale the body and its child entities 00402 // use a constant scale factor 00403 // 00404 // Author: Jane Hu 00405 //---------------------------------------------------------------- 00406 CubitStatus OCCBody::scale(double scale_factor ) 00407 { 00408 gp_Trsf aTrsf; 00409 aTrsf.SetScaleFactor(scale_factor); 00410 00411 BRepBuilderAPI_Transform aBRepTrsf(aTrsf); 00412 CubitStatus stat = transform(aBRepTrsf); 00413 return stat; 00414 } 00415 00416 //---------------------------------------------------------------- 00417 // Function: scale 00418 // Description: deforming transformation of the body and its child entities 00419 // Author: Jane Hu 00420 //---------------------------------------------------------------- 00421 CubitStatus OCCBody::scale(double scale_factor_x, 00422 double scale_factor_y, 00423 double scale_factor_z ) 00424 { 00425 gp_GTrsf gTrsf; 00426 gTrsf.SetValue(1,1, scale_factor_x); 00427 gTrsf.SetValue(2,2, scale_factor_y); 00428 gTrsf.SetValue(3,3, scale_factor_z); 00429 00430 BRepBuilderAPI_GTransform gBRepTrsf(gTrsf); 00431 00432 TopoDS_Shape * shape; 00433 get_TopoDS_Shape(shape); 00434 gBRepTrsf.Perform(*shape); 00435 00436 update_OCC_entity(&gBRepTrsf); 00437 // calculate for bounding box 00438 update_bounding_box(); 00439 00440 return CUBIT_SUCCESS; 00441 } 00442 00443 //---------------------------------------------------------------- 00444 // Function: reflect 00445 // Description: reflect the body about an plane given the normal 00446 // vector. 00447 // 00448 // Author: Jane Hu 00449 //---------------------------------------------------------------- 00450 CubitStatus OCCBody::reflect( double reflect_axis_x, 00451 double reflect_axis_y, 00452 double reflect_axis_z ) 00453 { 00454 gp_Pnt aOrigin(0,0,0); 00455 gp_Dir aDir(reflect_axis_x, reflect_axis_y,reflect_axis_z); 00456 gp_Ax2 anAx2(aOrigin, aDir); 00457 00458 gp_Trsf aTrsf; 00459 aTrsf.SetMirror(anAx2); 00460 00461 BRepBuilderAPI_Transform aBRepTrsf(aTrsf); 00462 return transform(aBRepTrsf); 00463 } 00464 00465 //---------------------------------------------------------------- 00466 // Function: private function to update the core compound and 00467 // for any movement of the body. 00468 // Note: input shape must have the same number of Compound 00469 // as the body's lumps number. 00470 // Author: Jane Hu 00471 //---------------------------------------------------------------- 00472 CubitStatus OCCBody::update_OCC_entity( BRepBuilderAPI_ModifyShape *aBRepTrsf, 00473 BRepAlgoAPI_BooleanOperation *op) 00474 { 00475 assert(aBRepTrsf != NULL || op != NULL); 00476 00477 TopoDS_Compound compsolid; 00478 TopoDS_Shape shape; 00479 shape = aBRepTrsf->Shape(); 00480 if(aBRepTrsf && myTopoDSShape) 00481 { 00482 compsolid = TopoDS::Compound(shape); 00483 00484 if(OCCQueryEngine::instance()->OCCMap->IsBound(*myTopoDSShape) ) 00485 OCCQueryEngine::instance()->update_OCC_map(*myTopoDSShape, shape); 00486 else if (!shape.IsEqual(*myTopoDSShape)) 00487 set_TopoDS_Shape(compsolid); 00488 } 00489 00490 //Boolean operation works only on one lump body 00491 //set the lumps 00492 DLIList<Lump *> lumps; 00493 lumps = this->lumps(); 00494 for (int i = 1; i <= lumps.size(); i++) 00495 { 00496 OCCLump *lump = CAST_TO(lumps.get_and_step(), OCCLump); 00497 lump->update_OCC_entity(aBRepTrsf, op); 00498 } 00499 00500 for(int i = 0; i < mySheetSurfaces.size(); i++) 00501 { 00502 OCCSurface* surface = mySheetSurfaces.get_and_step(); 00503 surface->update_OCC_entity(aBRepTrsf, op); 00504 } 00505 for(int i = 0; i <myShells.size() ; i++) 00506 { 00507 OCCShell* occ_shell = myShells.get_and_step(); 00508 occ_shell->update_OCC_entity(aBRepTrsf,op); 00509 } 00510 00511 if (aBRepTrsf && !compsolid.IsNull()) 00512 set_TopoDS_Shape(compsolid); 00513 00514 update_bounding_box(); 00515 00516 //unset marks. 00517 DLIList<OCCCurve*> curves; 00518 DLIList<OCCPoint*> points; 00519 get_all_curves(curves); 00520 get_all_points(points); 00521 00522 for(int i = 0; i < curves.size(); i++) 00523 curves.get_and_step()->set_myMarked(CUBIT_FALSE); 00524 00525 for(int i = 0; i < points.size(); i++) 00526 points.get_and_step()->set_myMarked(CUBIT_FALSE); 00527 return CUBIT_SUCCESS; 00528 } 00529 00530 //---------------------------------------------------------------- 00531 // Function: TopoDS_Shape level function to update the core Body 00532 // for any Boolean operation of the body. 00533 // Author: Jane Hu 00534 //---------------------------------------------------------------- 00535 CubitStatus OCCBody::update_OCC_entity(TopoDS_Shape& old_shape, 00536 TopoDS_Shape& new_shape, 00537 BRepBuilderAPI_MakeShape *op, 00538 LocOpe_SplitShape* sp) 00539 { 00540 //set the Shells 00541 TopTools_IndexedMapOfShape M; 00542 TopExp::MapShapes(old_shape, TopAbs_SOLID, M); 00543 TopTools_IndexedMapOfShape M_new; 00544 TopExp::MapShapes(new_shape, TopAbs_SOLID, M_new); 00545 TopTools_ListOfShape shapes; 00546 TopoDS_Shape shape; 00547 00548 CubitBoolean updated = CUBIT_FALSE; 00549 if(!old_shape.IsNull() && old_shape.ShapeType() == TopAbs_COMPOUND && 00550 !new_shape.IsNull() && new_shape.ShapeType() == TopAbs_COMPOUND && 00551 !old_shape.IsSame(new_shape)) 00552 { 00553 //By updating underling solids, shells etc., the old_shape will get changed. 00554 //trying to make sure the the number of each entity in the old and new 00555 //shapes are the same, which means that nothing is delete, that we can 00556 //update the map here. Otherwise, when deleting solids, it'll delete the 00557 //the old body and create new body. This is Ok for general boolean operation //except imprint when booleans are called, usually the original body are 00558 // supposed to be kept. 00559 updated = CUBIT_TRUE; 00560 OCCQueryEngine::instance()->update_OCC_map(old_shape, new_shape); 00561 } 00562 00563 DLIList<int> new_solid_nums; 00564 DLIList<int> unfound_nums; 00565 for(int ii=1; ii<=M.Extent(); ii++) 00566 { 00567 TopoDS_Solid solid = TopoDS::Solid(M(ii)); 00568 00569 TopTools_ListOfShape shapes; 00570 if(op) 00571 { 00572 shapes.Assign(op->Modified(solid)); 00573 if(shapes.Extent() == 0) 00574 shapes.Assign(op->Generated(solid)); 00575 } 00576 else if(sp) 00577 shapes.Assign(sp->DescendantShapes(solid)); 00578 00579 if (shapes.Extent() == 1) 00580 shape = shapes.First(); 00581 00582 else if(shapes.Extent() > 1) 00583 { 00584 //update all attributes first. 00585 TopTools_ListIteratorOfListOfShape it; 00586 it.Initialize(shapes); 00587 for(; it.More(); it.Next()) 00588 { 00589 shape = it.Value(); 00590 OCCQueryEngine::instance()->copy_attributes(solid, shape); 00591 } 00592 shape = shapes.First(); 00593 } 00594 00595 else if(op->IsDeleted(solid)) 00596 { 00597 if (M_new.Extent()== 1 && ii == 1) 00598 shape = M_new(1); 00599 else if(M_new.Extent()== 1 && ii > 1) 00600 shape.Nullify(); 00601 else if(M_new.Extent() > 1) 00602 { 00603 GProp_GProps myProps; 00604 BRepGProp::VolumeProperties(solid, myProps); 00605 double bf_mass = myProps.Mass(); 00606 gp_Pnt old_center = myProps.CentreOfMass(); 00607 CubitBoolean found = CUBIT_FALSE; 00608 for(int l = 1; l <= M_new.Extent(); l++) 00609 { 00610 BRepGProp::VolumeProperties(M_new(l), myProps); 00611 double af_mass = myProps.Mass(); 00612 double dTol = OCCQueryEngine::instance()->get_sme_resabs_tolerance(); 00613 if(fabs(bf_mass-af_mass) < dTol) //unchanged 00614 { 00615 gp_Pnt new_center = myProps.CentreOfMass(); 00616 if(new_center.IsEqual(old_center, dTol)) 00617 { 00618 found = CUBIT_TRUE; 00619 shape = M_new(l); 00620 new_solid_nums.append(l); 00621 break; 00622 } 00623 } 00624 } 00625 if(!found) 00626 { 00627 unfound_nums.append(ii); 00628 continue; 00629 } 00630 } 00631 else 00632 shape.Nullify(); 00633 } 00634 else 00635 { 00636 shape = solid; 00637 continue; 00638 } 00639 00640 if(shapes.Extent() > 0 || (op && op->IsDeleted(solid))) 00641 OCCLump::update_OCC_entity(solid, shape, op, sp); 00642 } 00643 00644 if( unfound_nums.size() == 1 ) 00645 { 00646 TopoDS_Solid solid = TopoDS::Solid(M(unfound_nums.get())); 00647 for(int kk = 1; kk <= M_new.Extent(); kk++) 00648 { 00649 if(!new_solid_nums.move_to(kk)) 00650 { 00651 shape = M_new(kk); 00652 break; 00653 } 00654 } 00655 OCCLump::update_OCC_entity(solid, shape, op, sp); 00656 } 00657 else if(unfound_nums.size() > 1) 00658 { 00659 shape.Nullify(); 00660 for(int kk = 1; kk <=unfound_nums.size(); kk++) 00661 { 00662 TopoDS_Solid solid = TopoDS::Solid(M(unfound_nums.get_and_step())); 00663 OCCLump::update_OCC_entity(solid, shape, op, sp); 00664 } 00665 } 00666 if(!old_shape.IsSame(new_shape) && !updated) 00667 OCCQueryEngine::instance()->update_OCC_map(old_shape, new_shape); 00668 return CUBIT_SUCCESS; 00669 } 00670 //---------------------------------------------------------------- 00671 // Function: update_bounding_box 00672 // Description: calculate for bounding box of this OCCBody 00673 // 00674 // Author: janehu 00675 //---------------------------------------------------------------- 00676 void OCCBody::update_bounding_box() 00677 { 00678 Bnd_Box box; 00679 TopoDS_Shape shape; 00680 00681 for (int i = 0; i < myLumps.size(); i++) 00682 { 00683 OCCLump *lump = CAST_TO(myLumps.get_and_step(), OCCLump); 00684 shape = *lump->get_TopoDS_Solid(); 00685 BRepBndLib::Add(shape, box); 00686 } 00687 00688 for(int i = 0; i < mySheetSurfaces.size(); i++) 00689 { 00690 OCCSurface* surface = mySheetSurfaces.get_and_step(); 00691 shape = *surface->get_TopoDS_Face(); 00692 BRepBndLib::Add(shape, box); 00693 } 00694 00695 for(int i = 0; i <myShells.size() ; i++) 00696 { 00697 OCCShell* occ_shell = myShells.get_and_step(); 00698 shape = *occ_shell->get_TopoDS_Shell(); 00699 BRepBndLib::Add(shape, box); 00700 } 00701 00702 //calculate the bounding box 00703 if(myLumps.size() + mySheetSurfaces.size() + myShells.size() == 0) 00704 { 00705 if(!myTopoDSShape) 00706 return; 00707 TopoDS_Shape shape = *myTopoDSShape; 00708 BRepBndLib::Add(shape, box); 00709 } 00710 00711 double min[3], max[3]; 00712 00713 //get values 00714 box.Get(min[0], min[1], min[2], max[0], max[1], max[2]); 00715 00716 //update boundingbox. 00717 boundingbox.reset(min, max); 00718 } 00719 00720 //---------------------------------------------------------------- 00721 // Function: get_bounding_box 00722 // Description: get the bounding box of this OCCBody 00723 // 00724 // Author: janehu 00725 //---------------------------------------------------------------- 00726 CubitBox OCCBody::get_bounding_box() 00727 { 00728 return boundingbox ; 00729 } 00730 00731 void OCCBody::get_parents_virt( DLIList<TopologyBridge*>& ) 00732 {} 00733 00734 void OCCBody::get_children_virt( DLIList<TopologyBridge*>& lumps ) 00735 { 00736 for(int i = 0; i < mySheetSurfaces.size(); i++) 00737 { 00738 OCCSurface* surface = mySheetSurfaces.get_and_step(); 00739 lumps.append(surface->my_lump()); 00740 } 00741 00742 for(int i = 0; i <myShells.size() ; i++) 00743 { 00744 OCCShell* occ_shell = myShells.get_and_step(); 00745 lumps.append(occ_shell->my_lump()); 00746 } 00747 00748 for(int i = 0; i <myLumps.size(); i++) 00749 lumps.append( myLumps.get_and_step()); 00750 return; 00751 } 00752 00753 //------------------------------------------------------------------------- 00754 // Purpose : Find centroid and volume for lumps and shells 00755 // 00756 // Special Notes : 00757 // 00758 // Author : Jane Hu 00759 // 00760 // Creation Date : 11/30/07 00761 //------------------------------------------------------------------------- 00762 CubitStatus OCCBody::mass_properties( CubitVector& centroid, 00763 double& volume ) 00764 { 00765 if( myShells.size() == 0 && myLumps.size() == 0) 00766 return CUBIT_FAILURE; 00767 GProp_GProps myProps; 00768 TopoDS_Shape* pshape = myTopoDSShape; 00769 if(!pshape || pshape->IsNull())//single lump or shell or surface 00770 { 00771 DLIList<Lump*> lumps = this->lumps(); 00772 if (lumps.size() > 0) 00773 pshape = CAST_TO(lumps.get(), OCCLump)->get_TopoDS_Solid(); 00774 } 00775 if(!pshape || pshape->IsNull()) 00776 return CUBIT_FAILURE; 00777 00778 BRepGProp::VolumeProperties(*pshape, myProps); 00779 volume = myProps.Mass(); 00780 gp_Pnt pt = myProps.CentreOfMass(); 00781 centroid.set(pt.X(), pt.Y(), pt.Z()); 00782 return CUBIT_SUCCESS; 00783 } 00784 00785 //------------------------------------------------------------------------- 00786 // Purpose : Used to be OCCQueryEngine::is_point_in_body 00787 // 00788 // Special Notes : 00789 // 00790 // Creator : Jason Kraftcheck 00791 // 00792 // Creation Date : 05/10/04 00793 //------------------------------------------------------------------------- 00794 CubitPointContainment OCCBody::point_containment( const CubitVector &point, double /*tolerance*/ ) 00795 { 00796 CubitPointContainment pc_value; 00797 OCCLump *lump; 00798 00799 int i; 00800 for( i=myLumps.size(); i--;) 00801 { 00802 lump = dynamic_cast<OCCLump*>(myLumps.get_and_step()); 00803 pc_value = lump->point_containment( point ); 00804 if( pc_value == CUBIT_PNT_INSIDE ) 00805 return CUBIT_PNT_INSIDE; 00806 else if( pc_value == CUBIT_PNT_BOUNDARY ) 00807 return CUBIT_PNT_BOUNDARY; 00808 } 00809 00810 for(int i = 0; i < mySheetSurfaces.size(); i++) 00811 { 00812 OCCSurface* surface = mySheetSurfaces.get_and_step(); 00813 pc_value = surface->point_containment( point ); 00814 if( pc_value == CUBIT_PNT_INSIDE ) 00815 return CUBIT_PNT_INSIDE; 00816 else if( pc_value == CUBIT_PNT_BOUNDARY ) 00817 return CUBIT_PNT_BOUNDARY; 00818 } 00819 00820 for(int i = 0; i <myShells.size() ; i++) 00821 { 00822 OCCShell* occ_shell = myShells.get_and_step(); 00823 DLIList<TopologyBridge*> children; 00824 occ_shell->get_children_virt(children); 00825 for(int j = 0; j < children.size(); j++) 00826 { 00827 OCCSurface* surface = CAST_TO(children.get_and_step(), OCCSurface); 00828 pc_value = surface->point_containment( point ); 00829 if( pc_value == CUBIT_PNT_INSIDE ) 00830 return CUBIT_PNT_INSIDE; 00831 else if( pc_value == CUBIT_PNT_BOUNDARY ) 00832 return CUBIT_PNT_BOUNDARY; 00833 } 00834 } 00835 return CUBIT_PNT_OUTSIDE; 00836 } 00837 00838 //------------------------------------------------------------------------- 00839 // Purpose : return all surfaces in this body. 00840 // 00841 // Special Notes : 00842 // 00843 // Creator : Jane Hu 00844 // 00845 // Creation Date : 01/10/08 00846 //------------------------------------------------------------------------- 00847 00848 void OCCBody::get_all_surfaces(DLIList<OCCSurface*> &surfaces) 00849 { 00850 TopoDS_Shape *shape; 00851 get_TopoDS_Shape(shape); 00852 00853 TopTools_IndexedMapOfShape M; 00854 TopExp::MapShapes(*shape, TopAbs_FACE, M); 00855 int ii; 00856 for (ii=1; ii<=M.Extent(); ii++) { 00857 TopologyBridge *face = OCCQueryEngine::instance()->occ_to_cgm(M(ii)); 00858 OCCSurface* occ_face = CAST_TO(face, OCCSurface); 00859 if (occ_face) 00860 surfaces.append_unique(occ_face); 00861 } 00862 } 00863 00864 //------------------------------------------------------------------------- 00865 // Purpose : return all curves in this body. 00866 // 00867 // Special Notes : 00868 // 00869 // Creator : Jane Hu 00870 // 00871 // Creation Date : 01/10/08 00872 //------------------------------------------------------------------------- 00873 00874 void OCCBody::get_all_curves(DLIList<OCCCurve*> &curves) 00875 { 00876 TopoDS_Shape *shape; 00877 get_TopoDS_Shape(shape); 00878 00879 TopTools_IndexedMapOfShape M; 00880 TopExp::MapShapes(*shape, TopAbs_EDGE, M); 00881 int ii; 00882 for (ii=1; ii<=M.Extent(); ii++) { 00883 TopologyBridge *curve = OCCQueryEngine::instance()->occ_to_cgm(M(ii)); 00884 OCCCurve* occ_curve = CAST_TO(curve, OCCCurve); 00885 if (occ_curve) 00886 curves.append_unique(occ_curve); 00887 } 00888 } 00889 00890 //------------------------------------------------------------------------- 00891 // Purpose : return all points in this body. 00892 // 00893 // Special Notes : 00894 // 00895 // Creator : Jane Hu 00896 // 00897 // Creation Date : 01/10/08 00898 //------------------------------------------------------------------------- 00899 00900 void OCCBody::get_all_points(DLIList<OCCPoint*> &points) 00901 { 00902 TopoDS_Shape *shape; 00903 get_TopoDS_Shape(shape); 00904 00905 TopTools_IndexedMapOfShape M; 00906 TopExp::MapShapes(*shape, TopAbs_VERTEX, M); 00907 int ii; 00908 for (ii=1; ii<=M.Extent(); ii++) { 00909 TopologyBridge *vertex = OCCQueryEngine::instance()->occ_to_cgm(M(ii)); 00910 OCCPoint* occ_point = CAST_TO(vertex, OCCPoint); 00911 if (occ_point) 00912 points.append_unique(occ_point); 00913 } 00914 00915 DLIList<OCCSurface*> surfaces; 00916 this->get_all_surfaces(surfaces); 00917 for(int i = 0; i < surfaces.size(); i++) 00918 { 00919 OCCSurface* occ_surf = surfaces.get_and_step(); 00920 points += occ_surf->get_hardpoints(); 00921 } 00922 } 00923