cgma
CAActuateSet.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CAActuateSet.cpp
00003 //
00004 // Purpose       : Maintain the list of entities for which attributes are
00005 //                 being actuated such that any entities destroyed 
00006 //                 during actuation (e.g. merging) get removed from the
00007 //                 list.
00008 //
00009 // Special Notes : 
00010 //
00011 // Creator       : Jason Kraftcheck
00012 //
00013 // Creation Date : 05/28/02
00014 //-------------------------------------------------------------------------
00015 
00016 #include "CAActuateSet.hpp"
00017 #include "RefEntity.hpp"
00018 #include "ModelQueryEngine.hpp"
00019 #include "Body.hpp"
00020 #include "BasicTopologyEntity.hpp"
00021 #include "AppUtil.hpp"
00022 #include "GeometryEvent.hpp"
00023 
00024 #include "RefFace.hpp"
00025 #include "RefEdge.hpp"
00026 #include "RefVertex.hpp"
00027 #include "RefVolume.hpp"
00028 #include "RefGroup.hpp"
00029 
00030 //-------------------------------------------------------------------------
00031 // Purpose       : Constructor
00032 //
00033 // Special Notes : 
00034 //
00035 // Creator       : Jason Kraftcheck
00036 //
00037 // Creation Date : 05/28/02
00038 //-------------------------------------------------------------------------
00039 CAActuateSet::CAActuateSet( DLIList<RefEntity*>& actuate_list )
00040   : currentDimension(-1)
00041 {
00042     // register this as a static observer so that we can
00043     // remove entities from the lists as they are destroyed
00044   AppUtil::instance()->event_dispatcher().add_observer(this);
00045   
00046     // put all entities in the actuate_list into the typeList
00047     // for the appropriate dimension of entity.
00048   for( int i = actuate_list.size(); i--; )
00049   {
00050     RefEntity* entity_ptr = actuate_list.get_and_step();
00051     int dimension = entity_ptr->dimension();
00052     if( dimension < 0 ) // body
00053       dimension = 4;
00054     typeList[dimension].append( entity_ptr );
00055   }
00056 }
00057 
00058 //-------------------------------------------------------------------------
00059 // Purpose       : Destructor
00060 //
00061 // Special Notes : 
00062 //
00063 // Creator       : Jason Kraftcheck
00064 //
00065 // Creation Date : 05/28/02
00066 //-------------------------------------------------------------------------
00067 CAActuateSet::~CAActuateSet()
00068 {
00069     // remove from static observer list
00070 
00071   AppUtil::instance()->event_dispatcher().remove_observer(this);
00072 }
00073 
00074 //-------------------------------------------------------------------------
00075 // Purpose       : Populate currentList with entities of the specified
00076 //                 dimension.  This includes children of any entities 
00077 //                 of a higher dimension that are in the lists managed
00078 //                 by this object.
00079 //
00080 // Special Notes : 
00081 //
00082 // Creator       : Jason Kraftcheck
00083 //
00084 // Creation Date : 05/28/02
00085 //-------------------------------------------------------------------------
00086 void CAActuateSet::set_current_dimension( int dimension )
00087 {
00088   int i;
00089   DLIList<TopologyEntity*> query_source, query_target;
00090   DLIList<RefEntity*> temp_list;
00091   
00092     // Clean out current list before adding new entities
00093   currentList.clean_out();
00094   
00095     // Get the target type to query for.
00096   DagType type = get_type_id( dimension );
00097 
00098     // Get children of higher-order entities
00099   for( i = 4; i > dimension; i-- )
00100   {
00101     query_source.clean_out();
00102     query_target.clean_out();
00103     
00104     CAST_LIST( typeList[i], query_source, TopologyEntity );
00105     ModelQueryEngine::instance()
00106       ->query_model( query_source, type, query_target );
00107     
00108     temp_list.clean_out();
00109     CAST_LIST( query_target, temp_list, RefEntity );
00110     
00111     append_to_current( temp_list );
00112   }
00113   
00114     // Add lcoal entities of current dimension
00115   append_to_current( typeList[dimension] );
00116 
00117     // Save current dimension
00118   currentDimension = dimension;
00119 }
00120 
00121 //-------------------------------------------------------------------------
00122 // Purpose       : Add entities to currentList
00123 //
00124 // Special Notes : Make sure no duplicates are added
00125 //
00126 // Creator       : Jason Kraftcheck
00127 //
00128 // Creation Date : 05/28/02
00129 //-------------------------------------------------------------------------
00130 void CAActuateSet::append_to_current( DLIList<RefEntity*>& list )
00131 {
00132   int i;
00133   
00134     // Set marks on all new entities
00135   for( i = list.size(); i--; )
00136     list.get_and_step()->marked(1);
00137   
00138     // Clear marks on entities in current list, 
00139     // including those also in the new list.
00140   for( i = currentList.size(); i--; )
00141     currentList.get_and_step()->marked(0);
00142   
00143     // Any entities in the new list that are still
00144     // marked are not already in the current list.
00145     // Add them.
00146   for( i = list.size(); i--; )
00147   {
00148     RefEntity* entity_ptr = list.get_and_step();
00149     if( entity_ptr->marked() )
00150     {
00151       currentList.append( entity_ptr );
00152       entity_ptr->marked(0);
00153     }
00154   }
00155 }
00156 
00157 //-------------------------------------------------------------------------
00158 // Purpose       : Remove deleted entities from lists
00159 //
00160 // Special Notes : 
00161 //
00162 // Creator       : Jason Kraftcheck
00163 //
00164 // Creation Date : 05/28/02
00165 //-------------------------------------------------------------------------
00166 void CAActuateSet::notify_observer( const CubitEvent* observer_event)
00167 {
00168   RefEntity* entity_ptr;
00169   int dimension;
00170 
00171   const GeometryEvent* geom_event = dynamic_cast<const GeometryEvent*>(observer_event);
00172   
00173     // only care about entities that are destroyed
00174   if(!geom_event || geom_event->get_type() != GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED)
00175     return;
00176 
00177 
00178     // is it a body?
00179   if( (entity_ptr = dynamic_cast<Body*>(geom_event->get_entity()) ) != NULL )
00180     dimension = 4;
00181 
00182     // is it some other topology entity
00183   else if( (entity_ptr = dynamic_cast<BasicTopologyEntity*>(geom_event->get_entity()) )
00184            != NULL )
00185     dimension = entity_ptr->dimension();
00186 
00187     // otherwise we don't care about it
00188   else
00189     return;
00190   
00191 
00192     // if it exists in the type list, remove it
00193   if( typeList[dimension].move_to( entity_ptr ) )
00194     typeList[dimension].extract();
00195   
00196     // if it exists in the current list, remove it.
00197   if( dimension == currentDimension && 
00198       currentList.move_to( entity_ptr ) )
00199     currentList.extract();
00200     
00201 }
00202 
00203 DagType CAActuateSet::get_type_id( int dimension )
00204 {
00205   switch( dimension )
00206   {
00207     case 4:  return DagType::body_type();     
00208     case 3:  return DagType::ref_volume_type();
00209     case 2:  return DagType::ref_face_type();  
00210     case 1:  return DagType::ref_edge_type();  
00211     case 0:  return DagType::ref_vertex_type();
00212     default: assert(0); 
00213              return DagType::invalid_type();
00214   }
00215 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines