cgma
OCCQueryEngine.hpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : OCCQueryEngine.hpp
00003 //
00004 // Purpose       : OCC geometry engine.
00005 //
00006 //                 This class is implemented as a Singleton pattern. Only
00007 //                 one instance is created and it is accessed through the 
00008 //                 {instance()} static member function.
00009 //
00010 // Special Notes :
00011 //
00012 // Creator       : Jane Hu
00013 //
00014 // Creation Date : 10/07
00015 //
00016 //-------------------------------------------------------------------------
00017 
00018 #ifndef OCC_GEOMETRY_ENGINE_HPP
00019 #define OCC_GEOMETRY_ENGINE_HPP
00020 
00021 // ********** BEGIN STANDARD INCLUDES         **********
00022 
00023 #include <typeinfo>
00024 #if !defined(NT) && !defined(CANT_USE_STD)
00025 using std::type_info;
00026 #endif
00027 
00028 // ********** END STANDARD INCLUDES           **********
00029 #include "TDF_Label.hxx"
00030 // ********** BEGIN CUBIT INCLUDES            **********
00031 #include "CubitFileIOWrapper.hpp"
00032 #include "GeometryQueryEngine.hpp"
00033 #include "Handle_TDocStd_Document.hxx"
00034 #include <map>
00035 
00036 // ********** END CUBIT INCLUDES              **********
00037 
00038 // ********** BEGIN FORWARD DECLARATIONS
00039 class BRep_Builder;
00040 class TopologyEntity;
00041 class TopologyBridge;
00042 class RefEntity;
00043 class Body;
00044 class Shell;
00045 class ShellSM;
00046 class Loop;
00047 class Chain;
00048 class LoopSM;
00049 class RefVolume;
00050 class RefFace;
00051 class RefEdge;
00052 class RefVertex;
00053 class TBPoint;
00054 class Curve;
00055 class Surface;
00056 class Lump;
00057 class BodySM;
00058 
00059 class GeometryEntity;
00060 class BodySM;
00061 class ShellSM;
00062 class Surface;
00063 class Curve;
00064 class CoEdgeSM;
00065 class TopologyEntity;
00066 class CubitBox;
00067 class CubitString;
00068 class CubitSimpleAttrib;
00069 
00070 class OtherSolidModelingEntity;
00071 class OCCLump;
00072 class OCCShell;
00073 class OCCLoop;
00074 class OCCSurface;
00075 class OCCBody;
00076 class OCCCoEdge;
00077 class OCCCurve;
00078 class OCCPoint;
00079  
00080 class TopTools_DataMapOfShapeInteger;
00081 class BRepAlgoAPI_BooleanOperation;
00082 class TopTools_IndexedMapOfShape;
00083 class BRepBuilderAPI_ModifyShape;
00084 class TopoDS_Vertex;
00085 class TopoDS_Edge;
00086 class TopoDS_Shape;
00087 class TopoDS_Wire;
00088 class TopoDS_Face;
00089 class TopoDS_Solid;
00090 class TopoDS_Shell;
00091 class TopoDS_Compound;
00092 // ********** END FORWARD DECLARATIONS        **********
00093 
00094 // ********** BEGIN MACRO DEFINITIONS         **********
00095 // ********** END MACRO DEFINITIONS           **********
00096 
00097 // ********** BEGIN ENUM DEFINITIONS          **********
00098 
00099 // ********** END ENUM DEFINITIONS            **********
00100 class OCCQueryEngine : public GeometryQueryEngine
00101 {
00102 public:
00103 // ********** BEGIN FRIEND DECLARATIONS        **********
00104   friend class OCCSurface;
00105   
00106 // ********** END FRIEND DECLARATIONS        **********
00107 
00108 //HEADER- Constructor and Destructor
00109   
00110   static OCCQueryEngine* instance();
00111     //- Singleton pattern
00112     //- Controlled access and creation of the sole instance of this class.
00113 
00114   CubitBoolean EXPORT_ATTRIB;
00115 
00116   void copy_attributes(TopoDS_Shape& old_shape,
00117                        TopoDS_Shape& new_shape);
00118 
00119   int update_OCC_map(TopoDS_Shape& old_shape, TopoDS_Shape& new_shape);
00120 
00121   virtual ~OCCQueryEngine();
00122   
00123   const char* modeler_type()
00124      { return "OCC"; }
00125 
00126   TopoDS_Shape *get_TopoDS_Shape_of_entity( TopologyBridge * entity);
00127   
00128   void body_attributes_for_writing(DLIList<OCCBody*> &OCC_bodies, //input
00129                                  BRep_Builder &B, //input
00130                                  TopoDS_Compound &Co, //input and output,
00131                                  DLIList<OCCLump*> &single_lumps, //output
00132                                  DLIList< DLIList<CubitSimpleAttrib>*> &lists);
00133 
00134   int get_major_version();
00135 
00136   int get_minor_version();
00137 
00138   int get_subminor_version();
00139 
00140   CubitString get_engine_version_string();
00141 
00142 //HEADER- RTTI and safe casting functions.
00143   
00144   virtual const type_info& entity_type_info() const ;
00145     //R- The geometric modeler type
00146     //- This function returns the type of the geometric modeler.
00147   
00148   virtual CubitBoolean is_solid_modeler_type() const 
00149     {return CUBIT_FALSE;}
00150     //R CubitBoolean
00151     //R- This  is not a solid modeling engine.
00152 //HEADER- Functions for importing and exporting solid models.
00153 
00154   virtual CubitStatus restore_transform( BodySM* body );
00155 
00156   using GeometryQueryEngine::get_graphics;
00157 
00158   virtual CubitStatus get_graphics( Surface* surface_ptr,
00159                                     GMem* gMem,
00160                                     unsigned short normal_tolerance = 15,
00161                                     double distance_tolerance = 0,
00162                                     double longest_edge = 0) const;
00163     CubitStatus get_graphics( TopoDS_Face* face_ptr,
00164                             GMem* g_mem,                                          
00165                             unsigned short normal_tolerance = 15,
00166                             double distance_tolerance = 0,
00167                             double max_edge_length = 0) const;
00168 
00169 
00170   virtual CubitStatus get_graphics( Curve* curve_ptr,
00171                                     GMem* gMem = NULL,
00172                                     double angle_tolerance=0,
00173                                     double distance_tolerance=0,
00174                                     double max_edge_length = 0.0 ) const;
00175 
00176 
00177 
00178   CubitStatus get_graphics( TopoDS_Edge* edge_ptr,
00179     GMem* gMem = NULL,
00180     double angle_tolerance = 0,
00181     double distance_tolerance = 0,
00182     double max_edge_length = 0 ) const;
00183 
00184 
00185     //R CubitStatus
00186     //R- CUBIT_SUCCESS/CUBIT_FAILURE
00187     //I ref_edge_ptr
00188     //I- The RefEdge for which hoops facetting information will be
00189     //I- gathered.
00190     //O numSteps
00191     //O- The number of points in resulting polyline.
00192     //O gMem
00193     //O- The storage place for edges, involved in facetting.
00194     //I tolerance
00195     //I- The tolerance deviation used when facetting the curve (optional
00196     //I- and currently IGNORED by this engine).
00197     //- This function gathers and outputs  edge information for
00198     //- hoops involved in facetting a RefEdge.  If all goes well,
00199     //- CUBIT_SUCCESS is returned.  Otherwise, CUBIT_FAILURE is
00200     //- returned.
00201  
00202   virtual CubitStatus fire_ray( CubitVector &origin,
00203                                 CubitVector &direction,
00204                                 DLIList<TopologyBridge*> &at_entity_list,
00205                                 DLIList<double> &ray_params,
00206                                 int max_hits = 0,
00207                                 double ray_radius = 0.0,
00208                                 DLIList<TopologyBridge*> *hit_entity_list=0 ) const ;
00209     //- Fire a ray at specified entities, returning the parameters (distances)
00210     //- along the ray and optionally the entities hit.  Returned lists are
00211     //- appended to.  Input entities can be any of bodies, volumes, faces,
00212     //- edges or vertices.  Optionally you can specify the maximum number of
00213     //- hits to return (default = 0 = unlimited), and the ray radius to use for
00214     //- intersecting the entities (default = 0.0 = use modeller default).
00215 
00216   virtual CubitStatus get_isoparametric_points(Surface* ,
00217                                                int&, int&,
00218                                                GMem*&) const;
00219   
00220   virtual CubitStatus get_u_isoparametric_points(Surface* ref_face_ptr,
00221                                                  double v, int& n,
00222                                                  GMem *&gMem) const;
00223   
00224   virtual CubitStatus get_v_isoparametric_points(Surface* ref_face_ptr,
00225                                                  double u, int&n,
00226                                                  GMem *&gMem) const;
00227   
00228   virtual CubitStatus transform_vec_position( 
00229     CubitVector const& ,
00230     BodySM *,
00231     CubitVector & ) const;
00232   
00233   virtual CubitStatus get_intersections( Curve*, CubitVector& point1,
00234                                          CubitVector&,
00235                                          DLIList<CubitVector>& ,
00236                                          CubitBoolean,
00237                                          CubitBoolean );
00238 
00239   virtual CubitStatus get_intersections( Curve* , Curve* ,
00240                                          DLIList<CubitVector>& ,
00241                                          CubitBoolean,
00242                                          CubitBoolean );
00243   virtual CubitStatus get_intersections( Curve* ref_edge, Surface* ref_face,
00244                                         DLIList<CubitVector>& intersection_list,
00245                                         CubitBoolean bounded = CUBIT_FALSE );
00246 
00247   virtual CubitStatus entity_extrema( DLIList<GeometryEntity*> &ref_entity_list, 
00248                                       const CubitVector *dir1, 
00249                                       const CubitVector *dir2,
00250                                       const CubitVector *dir3, 
00251                                       CubitVector &extrema,
00252                                       GeometryEntity *&extrema_entity_ptr );
00253   //- Gets the extrema position along the first given direction. If there 
00254   //- is more than one extrema position, the other directions will be used 
00255   //- to determine a unique position.  Directions 2 and 3 can be NULL.
00256   //- Entities supported include bodies, volumes, surfaces, curves and
00257   //- vertices.  The entity the extrema is found on is also returned.
00258 
00259   virtual CubitStatus entity_entity_distance( GeometryEntity *ref_entity_ptr1,
00260                                               GeometryEntity *ref_entity_ptr2,
00261                                               CubitVector &pos1, CubitVector &pos2,
00262                                               double &distance );
00263   //- Gets the minimum distance between two entities and the closest positions 
00264   //- on those entities. Supports vertices, curves, surfaces, volumes and bodies.
00265 
00266   virtual CubitStatus export_solid_model( DLIList<TopologyBridge*>& bridge_list,
00267                                           const char* file_name,
00268                                           Model_File_Type  file_type,
00269                                           const CubitString &cubit_version,
00270                                           ModelExportOptions &export_options );
00271 
00272 
00273   // write shapes to buffer as binary format
00274   virtual CubitStatus export_solid_model( DLIList<TopologyBridge*>& ref_entity_list,
00275                       char*& p_buffer,
00276                       int& n_buffer_size,
00277                       bool b_export_buffer);
00278 
00279   virtual CubitStatus save_temp_geom_file( DLIList<TopologyBridge*>& ref_entity_list,
00280                                           const char *file_name,
00281                                           const CubitString &cubit_version,
00282                                           CubitString &created_file,
00283                                           CubitString &created_file_type ); 
00284 
00285  virtual CubitStatus import_temp_geom_file(FILE* file_ptr,
00286                                       const char* file_name,
00287                                       Model_File_Type file_type,
00288                                       DLIList<TopologyBridge*> &bridge_list );
00289 
00290  virtual CubitStatus import_solid_model(const char* file_name,
00291                                         Model_File_Type file_type,
00292                                         DLIList<TopologyBridge*>& imported_entities,
00293                                         ModelImportOptions& options);
00294   virtual CubitStatus import_solid_model(DLIList<TopologyBridge*> &imported_entities,
00295                      const char* pBuffer,
00296                      const int n_buffer_size);
00297     
00298   CubitStatus unhook_BodySM_from_OCC( BodySM* bodysm,
00299                                     bool remove_lower_entities=CUBIT_TRUE)const;
00300   CubitStatus unhook_Surface_from_OCC( Surface* surface) const;
00301   CubitStatus unhook_Curve_from_OCC( Curve* curve) const;
00302   CubitStatus unhook_Point_from_OCC( TBPoint* point) const;
00303   void bound_TopoDS_Shape(const TopoDS_Shape & aShape);
00304 
00305 private:
00306   CubitStatus import_solid_model(FILE *file_ptr,
00307                                  const char* /*file_type*/,
00308                                  DLIList<TopologyBridge*> &imported_entities,
00309                                  CubitBoolean print_results = CUBIT_TRUE,
00310                                  const char* logfile_name = NULL,
00311                                  CubitBoolean heal_step = CUBIT_TRUE,
00312                                  CubitBoolean import_bodies = CUBIT_TRUE,
00313                                  CubitBoolean import_surfaces = CUBIT_TRUE,
00314                                  CubitBoolean import_curves = CUBIT_TRUE,
00315                                  CubitBoolean import_vertices = CUBIT_TRUE,
00316                                  CubitBoolean free_surfaces = CUBIT_TRUE);
00317 
00318   CubitStatus unhook_Lump_from_OCC( Lump* lump ) const;
00319   CubitStatus unhook_ShellSM_from_OCC( ShellSM* shell ) const;
00320   CubitStatus unhook_CoEdges_from_OCC( DLIList<OCCCoEdge*>& coedges) const;
00321   CubitStatus unhook_LoopSM_from_OCC( LoopSM* loopsm) const;
00322   CubitStatus delete_loop( LoopSM* loopsm)const;
00323   void unhook_coedges_of_a_curve(OCCCurve* curve,
00324                                  OCCLoop*  loop)const;
00325 
00326   void add_shape_to_map(TopoDS_Shape& sh,
00327                         TopoDS_Shape& aShape, /*In, parent shape*/
00328                         int &current_id /*Out*/);
00329 public:
00330   virtual void delete_solid_model_entities(DLIList<BodySM*>& body_list)const;
00331     //- Deletes all solid model entities associated with the Bodies in 
00332     //- the input list. 
00333   void delete_bodies(DLIList<BodySM*>& body_list,
00334                      bool remove_lower_entities =CUBIT_TRUE) const;
00335   using GeometryQueryEngine::delete_solid_model_entities;
00336   virtual CubitStatus delete_solid_model_entities(
00337           GeometryEntity* ref_entity_ptr,
00338           bool remove_lower_entities) const;
00339   virtual CubitStatus delete_solid_model_entities( BodySM* body_ptr)const; 
00340   CubitStatus delete_body(BodySM* body_ptr ,
00341                           bool remove_lower_entities =CUBIT_TRUE) const;
00342   virtual CubitStatus delete_solid_model_entities(Surface* surf_ptr)const;
00343   virtual CubitStatus delete_solid_model_entities( Curve* curve_ptr)const; 
00344   virtual CubitStatus delete_solid_model_entities( TBPoint* point_ptr)const;
00345 
00346   virtual double get_sme_resabs_tolerance() const; // Gets solid modeler's resolution absolute tolerance
00347   virtual double set_sme_resabs_tolerance( double new_resabs );
00348 
00349   virtual CubitStatus set_int_option( const char* opt_name, int val );
00350   virtual CubitStatus set_dbl_option( const char* opt_name, double val );
00351   virtual CubitStatus set_str_option( const char* opt_name, const char* val );
00352     //- Set solid modeler options
00353 
00354   CubitStatus ensure_is_ascii_stl_file(FILE * fp, CubitBoolean &is_ascii);
00355   //- returns true in is_ascii if fp points to an ascii stl file
00356 
00357   CubitStatus create_super_bounding_box(
00358                                 DLIList<BodySM*>& body_list,
00359                                 CubitBox& super_box );
00360 
00361   //ModifyShape refers to only Transform and GTransform for now (1/10/11)
00362   CubitStatus update_entity_shape(GeometryEntity* entity_ptr,
00363                                   BRepBuilderAPI_ModifyShape* aTranf,
00364                                   BRepAlgoAPI_BooleanOperation *op = NULL);
00365 
00366   void set_TopoDS_Shape(TopologyBridge* tb, TopoDS_Shape& new_shape);
00367   CubitStatus translate( BodySM* body, const CubitVector& offset );
00368   CubitStatus rotate   ( BodySM* body, const CubitVector& axis, double angle );
00369   CubitStatus scale    ( BodySM* body, double factor );
00370   CubitStatus scale    ( BodySM* body, const CubitVector& factors );
00371   CubitStatus reflect  ( BodySM* body, const CubitVector& axis );
00372 
00373   CubitStatus translate( GeometryEntity* ent, const CubitVector& offset );
00374   CubitStatus rotate   ( GeometryEntity* ent, const CubitVector& axis, double degrees );
00375   CubitStatus scale    ( GeometryEntity* ent, double factor );
00376   CubitStatus scale    ( GeometryEntity* ent, const CubitVector& factors );
00377   CubitStatus reflect  ( GeometryEntity* ent, const CubitVector& axis );
00378 
00379   CubitStatus get_connected_patch( DLIList<OCCSurface*>& remaining_surfs,
00380                                    DLIList<OCCSurface*>& output_patch );
00381   virtual CubitBoolean bodies_overlap (BodySM *body_ptr_1,
00382                                        BodySM *body_ptr_2 ) const;
00383   //R CubitBoolean
00384   //R- CUBIT_TRUE if the two bodies overlap, CUBIT_FALSE if they don't
00385   //R- overlap.  If the bodies are touching the function
00386   //R- should return CUBIT_FALSE.
00387   //I body_ptr_1, body_ptr_2
00388   //I- The two body pointers that are being tested for overlap.
00389   //-  The function uses the intersect call to test if the bodies
00390   //-  are overlaping.  The full intersect Boolean is needed to see if
00391   //-  the bodies actually overlap and don't just touch.
00392 
00393   TopologyBridge* occ_to_cgm(const TopoDS_Shape& shape);
00394   
00395   virtual CubitBoolean volumes_overlap (Lump *lump1, Lump *lump2 ) const ;
00396 
00397   DLIList<TopologyBridge*> populate_topology_bridge(TopoDS_Shape& aShape);
00398   BodySM* populate_topology_bridge(const TopoDS_Compound& aShape);
00399   Lump* populate_topology_bridge(const TopoDS_Solid& aShape, 
00400                    CubitBoolean build_body = CUBIT_FALSE);
00401   Surface* populate_topology_bridge(const TopoDS_Face& aShape,
00402                                     CubitBoolean build_body = CUBIT_FALSE);
00403   Curve* populate_topology_bridge(const TopoDS_Edge& aShape,
00404                                   CubitBoolean stand_along = CUBIT_FALSE );
00405   TBPoint* populate_topology_bridge(const TopoDS_Vertex& aShape,
00406                                   CubitBoolean stand_along = CUBIT_FALSE);
00407 
00408   OCCShell* populate_topology_bridge(const TopoDS_Shell& aShape,
00409                                      CubitBoolean standalone = CUBIT_FALSE );
00410   DLIList<OCCBody*> *BodyList ;
00411   DLIList<OCCSurface*> *SurfaceList ;
00412   DLIList<OCCLoop*> *WireList; //standalone wire list
00413   DLIList<OCCCurve*> *CurveList ;
00414   Handle(TDocStd_Document) MyDF;
00415   TDF_Label mainLabel;
00416   TopTools_DataMapOfShapeInteger* OCCMap;
00417   std::map<int, TopologyBridge*>* OccToCGM;
00418   std::map<int, TDF_Label>* Shape_Label_Map;
00419   static int iTotalTBCreated ;
00420   static int total_coedges;
00421 protected:
00422   
00423   OCCQueryEngine();
00424   
00425 private:
00426 
00427   OCCLoop* populate_topology_bridge(const TopoDS_Wire& aShape,
00428                     CubitBoolean standalone = CUBIT_FALSE);  
00429 
00430   CubitStatus write_topology( const char* file_name, 
00431                               Model_File_Type file_type,
00432                               DLIList<OCCBody*> &facet_bodies,
00433                               DLIList<OCCSurface*> &facet_surfaces,
00434                               DLIList<OCCCurve*> &facet_curves,
00435                               DLIList<OCCPoint*> &facet_points );
00436 
00437   CubitStatus write_topology( char*& p_buffer,
00438                   int& n_buffer_size,
00439                   bool b_export_buffer,
00440                   DLIList<OCCBody*> &OCC_bodies,
00441                   DLIList<OCCSurface*> &OCC_surfaces,
00442                   DLIList<OCCCurve*> &OCC_curves,
00443                   DLIList<OCCPoint*> &OCC_points);
00444   
00445   CubitBoolean Write(const TopoDS_Shape& Sh,
00446                      const Standard_CString File,
00447                      TDF_Label label);
00448 
00449   CubitBoolean Write(const TopoDS_Shape& Sh,
00450              char*& p_buffer,
00451              int& n_buffer_size,
00452              bool b_export_buffer,
00453                      TDF_Label label);
00454   
00455   CubitBoolean Read(TopoDS_Shape& Shapes,
00456                     const Standard_CString File,
00457                     TDF_Label label);
00458 
00459   CubitBoolean Read(TopoDS_Shape& Sh,
00460             const char* pBuffer,
00461             const int n_buffer_size,
00462                     TDF_Label label);
00463 
00464   static OCCQueryEngine* instance_;
00465     //- static pointer to unique instance of this class
00466 };
00467 
00468 // ********** BEGIN INLINE FUNCTIONS          **********
00469 // ********** END INLINE FUNCTIONS            **********
00470 
00471 // ********** BEGIN FRIEND FUNCTIONS          **********
00472 // ********** END FRIEND FUNCTIONS            **********
00473 
00474 // ********** BEGIN EXTERN FUNCTIONS          **********
00475 // ********** END EXTERN FUNCTIONS            **********
00476 
00477 // ********** BEGIN HELPER CLASS DECLARATIONS **********
00478 // ********** END HELPER CLASS DECLARATIONS   **********
00479 
00480 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines