cgma
TopologyEntity.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : TopologyEntity.cpp
00003 //
00004 // Purpose       : Implementation of the TopologyEntity class.
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : Xuechen Liu
00009 //
00010 // Creation Date : 07/31/96
00011 //
00012 // Owner         : Malcolm J. Panthaki
00013 //-------------------------------------------------------------------------
00014 
00015 // ********** BEGIN STANDARD INCLUDES      **********
00016 #include <assert.h>
00017 // ********** END STANDARD INCLUDES        **********
00018 
00019 // ********** BEGIN CUBIT INCLUDES         **********
00020 #include "CubitDefines.h"
00021 #include "CubitMessage.hpp"
00022 
00023 #include "CastTo.hpp"
00024 #include "TopologyEntity.hpp"
00025 #include "TopologyBridge.hpp"
00026 
00027 #include "ModelQueryEngine.hpp"
00028 #include "GeometryQueryTool.hpp"
00029 
00030 #include "Body.hpp"
00031 #include "DLIList.hpp"
00032 #include "Shell.hpp"
00033 #include "Loop.hpp"
00034 #include "Chain.hpp"
00035 #include "RefVolume.hpp"
00036 #include "RefFace.hpp"
00037 #include "RefEdge.hpp"
00038 #include "RefVertex.hpp"
00039 #include "CoVolume.hpp"
00040 #include "CoFace.hpp"
00041 #include "CoEdge.hpp"
00042 #include "CoVertex.hpp"
00043 #include "AppUtil.hpp"
00044 #include "CubitEvent.hpp"
00045 
00046 // ********** END CUBIT INCLUDES           **********
00047 
00048 // ********** BEGIN STATIC DECLARATIONS    **********
00049 // ********** END STATIC DECLARATIONS      **********
00050 
00051 // ********** BEGIN PUBLIC FUNCTIONS       **********
00052 
00053 //-------------------------------------------------------------------------
00054 // Purpose       : Casting query functions
00055 //
00056 // Special Notes : 
00057 //
00058 // Creator       : Jason Kraftcheck
00059 //
00060 // Creation Date : 07/29/03
00061 //-------------------------------------------------------------------------
00062 #define DECLARE_TOPO_ENT_QUERY_FUNC( TYPE, NAME, QUERYTYPE ) \
00063  CubitStatus TopologyEntity::NAME(DLIList<TYPE*>& list) \
00064  { \
00065    DLIList<TopologyEntity*> temp_list ; \
00066    CubitStatus result; \
00067    ModelQueryEngine *const mqe = ModelQueryEngine::instance(); \
00068    \
00069    result = mqe->query_model( *this, DagType::QUERYTYPE(), temp_list ); \
00070    if (result == CUBIT_FAILURE) \
00071    { \
00072       PRINT_ERROR("In TopologyEntity::" #NAME "\n"); \
00073       PRINT_ERROR("       Query failed for unknown reason.\n"); \
00074       return CUBIT_FAILURE; \
00075    } \
00076    \
00077    temp_list.reset(); \
00078    for (int i = temp_list.size(); i--; ) \
00079    { \
00080      TYPE* ptr = static_cast<TYPE*>(temp_list.get_and_step()); \
00081      assert(!!ptr); \
00082      list.append(ptr); \
00083    } \
00084    \
00085    return CUBIT_SUCCESS; \
00086 }
00087 
00088 
00089 
00090 //-------------------------------------------------------------------------
00091 // Purpose       : Default constructor.
00092 //
00093 // Special Notes :
00094 //
00095 // Creator       : Xuechen Liu
00096 //
00097 // Creation Date : 07/31/96
00098 //-------------------------------------------------------------------------
00099 
00100 TopologyEntity::TopologyEntity() 
00101     : deactivatedStatus_(CUBIT_FALSE),
00102       encountered_(CUBIT_FALSE),
00103       bridgeMan()
00104 {
00105   bridgeMan.set_entity(this);
00106 }
00107 
00108 //-------------------------------------------------------------------------
00109 // Purpose       : Destructor.
00110 //
00111 // Special Notes :
00112 //
00113 // Creator       : Raikanta Sahu
00114 //
00115 // Creation Date : 09/10/96
00116 //-------------------------------------------------------------------------
00117 
00118 TopologyEntity::~TopologyEntity() 
00119 {
00120   // Make sure that the TopologyEntity class does not have a pointer to this
00121   // TopologyEntity in its list.  If it does, then remove the instances
00122   // of the pointer
00123   DAG::instance()->remove(this);
00124 }
00125 
00126 
00127 GeometryQueryEngine*
00128 TopologyEntity::get_geometry_query_engine() const
00129 {
00130   TopologyBridge* bridge = 
00131     const_cast<TopologyEntity*>(this)->bridgeMan.topology_bridge();
00132   if (bridge)
00133     return bridge->get_geometry_query_engine();
00134   else
00135     return NULL;
00136 }
00137 
00138 
00139 DECLARE_TOPO_ENT_QUERY_FUNC(      Body,       bodies,       body_type )
00140 DECLARE_TOPO_ENT_QUERY_FUNC(  CoVolume,   co_volumes,  co_volume_type )
00141 DECLARE_TOPO_ENT_QUERY_FUNC( RefVolume,  ref_volumes, ref_volume_type )
00142 DECLARE_TOPO_ENT_QUERY_FUNC(     Shell,       shells,      shell_type )
00143 DECLARE_TOPO_ENT_QUERY_FUNC(    CoFace,     co_faces,    co_face_type )
00144 DECLARE_TOPO_ENT_QUERY_FUNC(   RefFace,    ref_faces,   ref_face_type )
00145 DECLARE_TOPO_ENT_QUERY_FUNC(      Loop,        loops,       loop_type )
00146 DECLARE_TOPO_ENT_QUERY_FUNC(    CoEdge,     co_edges,    co_edge_type )
00147 DECLARE_TOPO_ENT_QUERY_FUNC(   RefEdge,    ref_edges,   ref_edge_type )
00148 DECLARE_TOPO_ENT_QUERY_FUNC(     Chain,       chains,      chain_type )
00149 DECLARE_TOPO_ENT_QUERY_FUNC(  CoVertex,  co_vertices,  co_vertex_type )
00150 DECLARE_TOPO_ENT_QUERY_FUNC( RefVertex, ref_vertices, ref_vertex_type )
00151 
00152 
00153 RefVertex *TopologyEntity::ref_vertex()
00154 {
00155   DLIList<RefVertex*> verts;
00156   ref_vertices(verts);
00157   if (verts.size() > 0) return verts.get();
00158   else return NULL;
00159 }
00160 
00161 RefEdge *TopologyEntity::ref_edge()
00162 {
00163   DLIList<RefEdge*> edges;
00164   ref_edges(edges);
00165   if (edges.size() > 0) return edges.get();
00166   else return NULL;
00167 }
00168 
00169 RefFace *TopologyEntity::ref_face()
00170 {
00171   DLIList<RefFace*> faces;
00172   ref_faces(faces);
00173   if (faces.size() > 0) return faces.get();
00174   else return NULL;
00175 }
00176 
00177 RefVolume *TopologyEntity::ref_volume()
00178 {
00179   DLIList<RefVolume*> volumes;
00180   ref_volumes(volumes);
00181   if (volumes.size() > 0) return volumes.get();
00182   else return NULL;
00183 }
00184 
00185 Body *TopologyEntity::body()
00186 {
00187   DLIList<Body*> these_bodies;
00188   this->bodies(these_bodies);
00189   if (these_bodies.size() > 0) return these_bodies.get();
00190   else return NULL;
00191 }
00192 
00193 
00194 CoEdge *TopologyEntity::co_edge() 
00195 {
00196   DLIList<CoEdge*> these_co_edges;
00197   co_edges(these_co_edges);
00198   if (these_co_edges.size() > 0) return these_co_edges.get();
00199   else return NULL;
00200 }
00201 
00202 int TopologyEntity::num_loops() 
00203 {
00204   DLIList<Loop*> these_loops;
00205   loops(these_loops);
00206   return these_loops.size();
00207 }
00208 
00209 
00210 int TopologyEntity::num_ref_volumes() 
00211 {
00212   DLIList<RefVolume*> these_ref_volumes;
00213   ref_volumes(these_ref_volumes);
00214   return these_ref_volumes.size();
00215 }
00216 
00217 int TopologyEntity::num_ref_faces() 
00218 {
00219   DLIList<RefFace*> these_ref_faces;
00220   ref_faces(these_ref_faces);
00221   return these_ref_faces.size();
00222 }
00223 
00224 int TopologyEntity::num_ref_edges() 
00225 {
00226   DLIList<RefEdge*> these_ref_edges;
00227   ref_edges(these_ref_edges);
00228   return these_ref_edges.size();
00229 }
00230 
00231 int TopologyEntity::num_ref_vertices() 
00232 {
00233   DLIList<RefVertex*> these_ref_vertices;
00234   ref_vertices(these_ref_vertices);
00235   return these_ref_vertices.size();
00236 }
00237 
00238 
00239   //- return the number of connected entities of the given type
00240 
00241 CubitBoolean TopologyEntity::is_directly_related( TopologyEntity* entity )
00242 {
00243     // NULL?
00244   if ( !entity )
00245     return CUBIT_FALSE;
00246   
00247     // self?
00248   if (entity == this)
00249     return CUBIT_TRUE;  
00250 
00251     // same type but not self?
00252   if ( dag_type() == entity->dag_type() )  
00253     return CUBIT_FALSE;
00254   
00255     // Get the entities of the right type.
00256   DLIList<TopologyEntity*> kin_folk;
00257   CubitStatus result = ModelQueryEngine::instance()->
00258     query_model( *this, entity->dag_type(), kin_folk );
00259     //only fails if types are the same, caught above. 
00260   assert(result != CUBIT_FAILURE); 
00261   if (CUBIT_FAILURE == result) {
00262     PRINT_ERROR("ModelQueryEngine::query_model failed.\n");
00263     return CUBIT_FALSE;
00264   }
00265 
00266     // Search entities for passed in entity.
00267   TopologyEntity* model_entity = CAST_TO(entity, TopologyEntity) ;
00268   return kin_folk.is_in_list( model_entity );
00269 }
00270 
00271 CubitStatus TopologyEntity::set_topology_bridge(TopologyBridge* TB_ptr)
00272 {
00273   assert (TB_ptr != NULL);
00274   CubitStatus rv = CUBIT_SUCCESS;
00275   
00276   BridgeManager* bridges = bridge_manager();
00277   bridges->remove_all_bridges();
00278   bridges->add_bridge(TB_ptr);
00279 
00280   return rv;
00281 }
00282 
00283 CubitStatus TopologyEntity::remove_from_DAG(CubitBoolean recurse_flag)
00284 {
00285      // This counter will be used in the recursion to test whether
00286      // the call is from outside or from the function itself. When
00287      // the call comes from outside, the counter should always be
00288      // zero.
00289 
00290   CubitBoolean this_recurse = recurse_flag;
00291   if (recurse_flag == CUBIT_FALSE) recurse_flag = CUBIT_TRUE;
00292 
00293   DLIList<TopologyEntity*> childModEntList;
00294 
00295      // Check to see if there are no parents of this object.
00296    if ( get_parents() == 0 )
00297    {
00298       if (this_recurse == CUBIT_FALSE)
00299       {
00300          // Since we are not recursing, this is a top-level entity.
00301          // Notify the static observers that a top-level entity is being
00302          // destructed.  This must be done before children are disconnected.
00303        CubitObservable *top_level = CAST_TO(this, CubitObservable);
00304        AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOP_LEVEL_ENTITY_DESTRUCTED, dynamic_cast<RefEntity*>(top_level)));
00305       }
00306 
00307         // Go through all the children and remove their link to
00308         // the current object.
00309 
00310       TopologyEntity* tempModEntPtr = NULL ;
00311       TopologyEntity* childModEntPtr = NULL ;
00312 
00313       childModEntList.clean_out();
00314       disconnect_all_children(&childModEntList);
00315 
00316         // The following while conditional may not work...it depends on
00317         // what is_at_end does when you step over the end...CHECK THIS
00318       int i;
00319       for( i = 0 ; i < childModEntList.size() ; i++ )
00320       {
00321            // Get the next ModelEnti in the child list and make sure its
00322            // pointer to its parent is removed.
00323          tempModEntPtr = childModEntList.get_and_step();
00324 
00325            // Try remove() on the child ModEnt. If it comes back with
00326            // a success, then delete it.
00327          childModEntPtr = tempModEntPtr;
00328 
00329          if ( childModEntPtr->remove_from_DAG(recurse_flag) == CUBIT_SUCCESS )
00330          {
00331               // Now deactivate the child ModEnt
00332             childModEntPtr->deactivated(CUBIT_TRUE) ;
00333 
00334               // remove it from observables, just before we go to delete it
00335             CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
00336             if (observable)
00337             {
00338               AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED, dynamic_cast<RefEntity*>(observable)));
00339             }
00340          }
00341       }
00342 
00343 
00344         // If this is the top of the recursion, then clean out all the deactivated
00345         // entities.
00346       if (this_recurse == CUBIT_FALSE)
00347       {
00348          this->deactivated(CUBIT_TRUE) ;
00349 
00350          // remove it from observables, just before we go to delete it
00351          CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
00352          if (observable)
00353          {
00354            AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED, dynamic_cast<RefEntity*>(observable)));
00355          }
00356          GeometryQueryTool::instance()->cleanout_deactivated_geometry() ;
00357       }
00358 
00359       return CUBIT_SUCCESS ;
00360    }
00361    else
00362    {
00363       return CUBIT_FAILURE ;
00364    }
00365 }
00366 
00367 void TopologyEntity::disconnect_from_DAG()
00368 {
00369     // disconnects this entity from any others
00370     // to which it is connected in the DAG; does not delete the DAGNode
00371 
00372   disconnect_all_children();
00373   disconnect_all_parents();
00374 }
00375 
00376 //-------------------------------------------------------------------------
00377 // Purpose       : Get and set functions for the deactivated flag.
00378 //
00379 // Special Notes :
00380 //
00381 // Creator       : Raikanta Sahu
00382 //
00383 // Creation Date : 12/02/96
00384 //-------------------------------------------------------------------------
00385 
00386 void TopologyEntity::deactivated(CubitBoolean flag)
00387 {
00388    if (deactivatedStatus_ != flag)
00389    {
00390      deactivatedStatus_ = flag ;
00391      if (flag == CUBIT_TRUE)
00392      {
00393         DAG::instance()->add_deactivated_DAG_node(this) ;
00394      }
00395      else
00396      {
00397         DAG::instance()->remove_deactivated_DAG_node(this) ;
00398      }
00399    }
00400 }
00401 
00402 CubitBoolean TopologyEntity::deactivated() const
00403 {
00404    return (CubitBoolean)deactivatedStatus_ ;
00405 }
00406 
00407 
00408 
00409 
00410 // ********** END PUBLIC FUNCTIONS         **********
00411 
00412 // ********** BEGIN PROTECTED FUNCTIONS    **********
00413 // ********** END PROTECTED FUNCTIONS      **********
00414 
00415 // ********** BEGIN PRIVATE FUNCTIONS      **********
00416 // ********** END PRIVATE FUNCTIONS        **********
00417 
00418 // ********** BEGIN HELPER CLASSES         **********
00419 // ********** END HELPER CLASSES           **********
00420 
00421 // ********** BEGIN EXTERN FUNCTIONS       **********
00422 // ********** END EXTERN FUNCTIONS         **********
00423 
00424 // ********** BEGIN STATIC FUNCTIONS       **********
00425 // ********** END STATIC FUNCTIONS         **********
00426 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines