cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : OCCShell.cpp 00003 // 00004 // Purpose : 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : David White 00009 // 00010 // Creation Date : 7/18/2000 00011 // 00012 //------------------------------------------------------------------------- 00013 00014 // ********** BEGIN STANDARD INCLUDES ********** 00015 #include <stddef.h> 00016 // ********** END STANDARD INCLUDES ********** 00017 // ********** BEGIN CUBIT INCLUDES ********** 00018 #include "CastTo.hpp" 00019 #include "CubitUtil.hpp" 00020 00021 #include "OCCQueryEngine.hpp" 00022 #include "OCCShell.hpp" 00023 #include "ShellSM.hpp" 00024 #include "Lump.hpp" 00025 #include "Surface.hpp" 00026 00027 #include "OCCBody.hpp" 00028 #include "OCCLump.hpp" 00029 #include "OCCSurface.hpp" 00030 #include "GfxDebug.hpp" 00031 00032 #include <TopExp.hxx> 00033 #include <TopTools_IndexedMapOfShape.hxx> 00034 #include "TopExp_Explorer.hxx" 00035 #include "TopTools_IndexedDataMapOfShapeListOfShape.hxx" 00036 #include "TopoDS.hxx" 00037 #include "TopTools_ListIteratorOfListOfShape.hxx" 00038 #include "GProp_GProps.hxx" 00039 #include "BRepGProp.hxx" 00040 #include "TopTools_DataMapOfShapeInteger.hxx" 00041 #include "TopTools_ListOfShape.hxx" 00042 #include "BRepAlgoAPI_BooleanOperation.hxx" 00043 #include "BRepBuilderAPI_MakeShape.hxx" 00044 #include "BRepBuilderAPI_ModifyShape.hxx" 00045 #include "BRepBuilderAPI_Transform.hxx" 00046 #include "BRepBuilderAPI_GTransform.hxx" 00047 #include "LocOpe_SplitShape.hxx" 00048 #include "TopoDS_Compound.hxx" 00049 // ********** END CUBIT INCLUDES ********** 00050 00051 // ********** BEGIN STATIC DECLARATIONS ********** 00052 // ********** END STATIC DECLARATIONS ********** 00053 00054 // ********** BEGIN PUBLIC FUNCTIONS ********** 00055 00056 00057 //------------------------------------------------------------------------- 00058 // Purpose : A constructor with a pointer to an OCC SHELL. 00059 // 00060 // Special Notes : 00061 // 00062 //------------------------------------------------------------------------- 00063 OCCShell::OCCShell(TopoDS_Shell *theShell, OCCSurface* surface) 00064 { 00065 myTopoDSShell = theShell; 00066 mySheetSurface = surface; 00067 if(myTopoDSShell && !myTopoDSShell->IsNull()) 00068 assert (myTopoDSShell->ShapeType() == TopAbs_SHELL); 00069 } 00070 00071 //------------------------------------------------------------------------- 00072 // Purpose : The destructor. 00073 // 00074 // Special Notes : 00075 // 00076 //------------------------------------------------------------------------- 00077 OCCShell::~OCCShell() 00078 { 00079 if(myTopoDSShell) 00080 { 00081 myTopoDSShell->Nullify(); 00082 delete (TopoDS_Shell*)myTopoDSShell; 00083 myTopoDSShell = NULL; 00084 } 00085 } 00086 00087 void OCCShell::set_TopoDS_Shell(TopoDS_Shell shell) 00088 { 00089 if(myTopoDSShell && shell.IsEqual(*myTopoDSShell)) 00090 return; 00091 00092 if (myTopoDSShell) 00093 myTopoDSShell->Nullify(); 00094 00095 *myTopoDSShell = shell; 00096 } 00097 00098 //------------------------------------------------------------------------- 00099 // Purpose : Get geometry modeling engine: OCCQueryEngine 00100 // 00101 // Special Notes : 00102 // 00103 //------------------------------------------------------------------------- 00104 GeometryQueryEngine* 00105 OCCShell::get_geometry_query_engine() const 00106 { 00107 return OCCQueryEngine::instance(); 00108 } 00109 00110 void OCCShell::append_simple_attribute_virt(const CubitSimpleAttrib&) 00111 { 00112 } 00113 void OCCShell::remove_simple_attribute_virt(const CubitSimpleAttrib& ) 00114 { 00115 } 00116 void OCCShell::remove_all_simple_attribute_virt() 00117 { 00118 } 00119 CubitStatus OCCShell::get_simple_attribute(DLIList<CubitSimpleAttrib>&) 00120 { 00121 return CUBIT_FAILURE; 00122 } 00123 CubitStatus OCCShell::get_simple_attribute(const CubitString&, 00124 DLIList<CubitSimpleAttrib>&) 00125 { return CUBIT_FAILURE; } 00126 00127 //------------------------------------------------------------------------- 00128 // Purpose : Query solid modeler topology 00129 // 00130 // Special Notes : 00131 // 00132 // Author : Jane Hu 00133 // 00134 // Creation Date : 11/28/07 00135 //------------------------------------------------------------------------- 00136 void OCCShell::get_parents_virt( DLIList<TopologyBridge*>& parents ) 00137 { 00138 if(mySheetSurface) 00139 { 00140 parents.append(mySheetSurface->my_lump()); 00141 return; 00142 } 00143 00144 OCCQueryEngine* oqe = (OCCQueryEngine*) get_geometry_query_engine(); 00145 OCCBody * body = NULL; 00146 DLIList <OCCBody* > *bodies = oqe->BodyList; 00147 TopTools_IndexedDataMapOfShapeListOfShape M; 00148 for(int i = 0; i < bodies->size(); i++) 00149 { 00150 body = bodies->get_and_step(); 00151 TopoDS_Shape* shape ; 00152 body->get_TopoDS_Shape(shape); 00153 assert(shape != NULL); 00154 TopExp::MapShapesAndAncestors(*shape, 00155 TopAbs_SHELL, TopAbs_SOLID, M); 00156 TopoDS_Shell *shell = get_TopoDS_Shell(); 00157 if (!M.Contains(*shell)) 00158 continue; 00159 00160 const TopTools_ListOfShape& ListOfShapes = 00161 M.FindFromKey(*(get_TopoDS_Shell())); 00162 if (!ListOfShapes.IsEmpty()) 00163 { 00164 TopTools_ListIteratorOfListOfShape it(ListOfShapes) ; 00165 for (;it.More(); it.Next()) 00166 { 00167 TopoDS_Solid Solid = TopoDS::Solid(it.Value()); 00168 int k = oqe->OCCMap->Find(Solid); 00169 parents.append((OCCLump*)(oqe->OccToCGM->find(k))->second); 00170 } 00171 } 00172 } 00173 } 00174 00175 00176 void OCCShell::get_children_virt( DLIList<TopologyBridge*>& children ) 00177 { 00178 if(mySheetSurface) 00179 { 00180 children.append(mySheetSurface); 00181 return; 00182 } 00183 TopTools_IndexedMapOfShape M; 00184 TopExp::MapShapes(*myTopoDSShell, TopAbs_FACE, M); 00185 int ii; 00186 for (ii=1; ii<=M.Extent(); ii++) { 00187 TopologyBridge *surface = OCCQueryEngine::instance()->occ_to_cgm(M(ii)); 00188 if(surface) 00189 children.append_unique(surface); 00190 } 00191 } 00192 00193 //---------------------------------------------------------------- 00194 // Function: to update the core Shell 00195 // for any movement of the body. 00196 // Author: Jane Hu 00197 //---------------------------------------------------------------- 00198 CubitStatus OCCShell::update_OCC_entity( BRepBuilderAPI_ModifyShape *aBRepTrsf, 00199 BRepAlgoAPI_BooleanOperation *op) 00200 { 00201 if(mySheetSurface && op == NULL) 00202 return CUBIT_FAILURE; 00203 00204 assert (aBRepTrsf != NULL || op != NULL); 00205 00206 TopoDS_Shape shape; 00207 if(aBRepTrsf) 00208 shape = aBRepTrsf->ModifiedShape(*get_TopoDS_Shell()); 00209 00210 else if(!mySheetSurface) 00211 { 00212 TopTools_ListOfShape shapes; 00213 shapes.Assign(op->Modified(*get_TopoDS_Shell())); 00214 if(shapes.Extent() == 0) 00215 shapes.Assign(op->Generated(*get_TopoDS_Shell())); 00216 if (shapes.Extent()) 00217 shape = shapes.First(); 00218 00219 else if(op->IsDeleted(*get_TopoDS_Shell())) 00220 ; 00221 else 00222 return CUBIT_SUCCESS; 00223 } 00224 TopoDS_Shell shell; 00225 if (!shape.IsNull()) 00226 shell = TopoDS::Shell(shape); 00227 00228 //set the surfaces 00229 DLIList<TopologyBridge *> surfaces; 00230 this->get_children_virt(surfaces); 00231 for (int i = 1; i <= surfaces.size(); i++) 00232 { 00233 OCCSurface *surface = CAST_TO(surfaces.get_and_step(), OCCSurface); 00234 surface->update_OCC_entity(aBRepTrsf, op); 00235 } 00236 OCCQueryEngine::instance()->update_OCC_map(*myTopoDSShell, shell); 00237 return CUBIT_SUCCESS; 00238 } 00239 00240 //------------------------------------------------------------------------- 00241 // Purpose : Returns the area of the Shell 00242 // 00243 //------------------------------------------------------------------------- 00244 double OCCShell::measure() 00245 { 00246 GProp_GProps myProps; 00247 BRepGProp::SurfaceProperties(*myTopoDSShell, myProps); 00248 return myProps.Mass(); 00249 } 00250 00251 //---------------------------------------------------------------- 00252 // Function: TopoDS_Shape level function to update the core Shell 00253 // for any boolean operation of the body. 00254 // Author: Jane Hu 00255 //---------------------------------------------------------------- 00256 CubitStatus OCCShell::update_OCC_entity(TopoDS_Shell& old_shell, 00257 TopoDS_Shape& new_shell, 00258 BRepBuilderAPI_MakeShape *op, 00259 LocOpe_SplitShape* sp) 00260 { 00261 //set the surfaces 00262 TopTools_IndexedMapOfShape M; 00263 TopoDS_Shape shape; 00264 TopExp::MapShapes(old_shell, TopAbs_FACE, M); 00265 TopTools_ListOfShape shapes; 00266 for(int ii=1; ii<=M.Extent(); ii++) 00267 { 00268 TopoDS_Face face = TopoDS::Face(M(ii)); 00269 if (op) 00270 { 00271 shapes.Assign(op->Modified(face)); 00272 if(shapes.Extent() == 0) 00273 shapes.Assign(op->Generated(face)); 00274 } 00275 else if(sp) 00276 shapes.Assign(sp->DescendantShapes(face)); 00277 00278 if(shapes.Extent() == 1) 00279 shape = shapes.First(); 00280 else if(shapes.Extent() > 1) 00281 { 00282 shape = shapes.First() ; 00283 } 00284 else 00285 { 00286 TopoDS_Face nullFace; 00287 shape = nullFace; 00288 } 00289 if(shapes.Extent() > 0 || (op && op->IsDeleted(face))) 00290 OCCSurface::update_OCC_entity(face,shape, op, NULL, sp); 00291 } 00292 if(!old_shell.IsSame(new_shell)) 00293 OCCQueryEngine::instance()->update_OCC_map(old_shell, new_shell); 00294 return CUBIT_SUCCESS; 00295 } 00296 // ********** END PUBLIC FUNCTIONS ********** 00297 00298 // ********** BEGIN PROTECTED FUNCTIONS ********** 00299 // ********** END PROTECTED FUNCTIONS ********** 00300 00301 // ********** BEGIN PRIVATE FUNCTIONS ********** 00302 // ********** END PRIVATE FUNCTIONS ********** 00303 00304 // ********** BEGIN HELPER CLASSES ********** 00305 // ********** END HELPER CLASSES ********** 00306 00307 // ********** BEGIN EXTERN FUNCTIONS ********** 00308 // ********** END EXTERN FUNCTIONS ********** 00309 00310 // ********** BEGIN STATIC FUNCTIONS ********** 00311 // ********** END STATIC FUNCTIONS ********** 00312