root/cgm/trunk/geom/CAActuateSet.cpp

Revision 1040, 6.2 KB (checked in by tautges, 2 years ago)

Version 10.2 of cgm.

Line 
1//-------------------------------------------------------------------------
2// Filename      : CAActuateSet.cpp
3//
4// Purpose       : Maintain the list of entities for which attributes are
5//                 being actuated such that any entities destroyed
6//                 during actuation (e.g. merging) get removed from the
7//                 list.
8//
9// Special Notes :
10//
11// Creator       : Jason Kraftcheck
12//
13// Creation Date : 05/28/02
14//-------------------------------------------------------------------------
15
16#include "CAActuateSet.hpp"
17#include "RefEntity.hpp"
18#include "ModelEntity.hpp"
19#include "ModelQueryEngine.hpp"
20#include "Body.hpp"
21#include "BasicTopologyEntity.hpp"
22
23#include "RefFace.hpp"
24#include "RefEdge.hpp"
25#include "RefVertex.hpp"
26#include "RefVolume.hpp"
27#include "RefGroup.hpp"
28
29//-------------------------------------------------------------------------
30// Purpose       : Constructor
31//
32// Special Notes :
33//
34// Creator       : Jason Kraftcheck
35//
36// Creation Date : 05/28/02
37//-------------------------------------------------------------------------
38CAActuateSet::CAActuateSet( DLIList<RefEntity*>& actuate_list )
39  : currentDimension(-1)
40{
41    // register this as a static observer so that we can
42    // remove entities from the lists as they are destroyed
43  register_static_observer( this );
44 
45    // put all entities in the actuate_list into the typeList
46    // for the appropriate dimension of entity.
47  for( int i = actuate_list.size(); i--; )
48  {
49    RefEntity* entity_ptr = actuate_list.get_and_step();
50    int dimension = entity_ptr->dimension();
51    if( dimension < 0 ) // body
52      dimension = 4;
53    typeList[dimension].append( entity_ptr );
54  }
55}
56
57//-------------------------------------------------------------------------
58// Purpose       : Destructor
59//
60// Special Notes :
61//
62// Creator       : Jason Kraftcheck
63//
64// Creation Date : 05/28/02
65//-------------------------------------------------------------------------
66CAActuateSet::~CAActuateSet()
67{
68    // remove from static observer list
69  unregister_static_observer( this );
70}
71
72//-------------------------------------------------------------------------
73// Purpose       : Populate currentList with entities of the specified
74//                 dimension.  This includes children of any entities
75//                 of a higher dimension that are in the lists managed
76//                 by this object.
77//
78// Special Notes :
79//
80// Creator       : Jason Kraftcheck
81//
82// Creation Date : 05/28/02
83//-------------------------------------------------------------------------
84void CAActuateSet::set_current_dimension( int dimension )
85{
86  int i;
87  DLIList<ModelEntity*> query_source, query_target;
88  DLIList<RefEntity*> temp_list;
89 
90    // Clean out current list before adding new entities
91  currentList.clean_out();
92 
93    // Get the target type to query for.
94  DagType type = get_type_id( dimension );
95
96    // Get children of higher-order entities
97  for( i = 4; i > dimension; i-- )
98  {
99    query_source.clean_out();
100    query_target.clean_out();
101   
102    CAST_LIST( typeList[i], query_source, ModelEntity );
103    ModelQueryEngine::instance()
104      ->query_model( query_source, type, query_target );
105   
106    temp_list.clean_out();
107    CAST_LIST( query_target, temp_list, RefEntity );
108   
109    append_to_current( temp_list );
110  }
111 
112    // Add lcoal entities of current dimension
113  append_to_current( typeList[dimension] );
114
115    // Save current dimension
116  currentDimension = dimension;
117}
118
119//-------------------------------------------------------------------------
120// Purpose       : Add entities to currentList
121//
122// Special Notes : Make sure no duplicates are added
123//
124// Creator       : Jason Kraftcheck
125//
126// Creation Date : 05/28/02
127//-------------------------------------------------------------------------
128void CAActuateSet::append_to_current( DLIList<RefEntity*>& list )
129{
130  int i;
131 
132    // Set marks on all new entities
133  for( i = list.size(); i--; )
134    list.get_and_step()->marked(1);
135 
136    // Clear marks on entities in current list,
137    // including those also in the new list.
138  for( i = currentList.size(); i--; )
139    currentList.get_and_step()->marked(0);
140 
141    // Any entities in the new list that are still
142    // marked are not already in the current list.
143    // Add them.
144  for( i = list.size(); i--; )
145  {
146    RefEntity* entity_ptr = list.get_and_step();
147    if( entity_ptr->marked() )
148    {
149      currentList.append( entity_ptr );
150      entity_ptr->marked(0);
151    }
152  }
153}
154
155//-------------------------------------------------------------------------
156// Purpose       : Remove deleted entities from lists
157//
158// Special Notes :
159//
160// Creator       : Jason Kraftcheck
161//
162// Creation Date : 05/28/02
163//-------------------------------------------------------------------------
164CubitStatus CAActuateSet::notify_observer( CubitObservable* observable,
165                               const CubitEvent& observer_event,
166                               CubitBoolean )
167{
168  RefEntity* entity_ptr;
169  int dimension;
170 
171    // only care about entities that are destroyed
172  if( observer_event.get_event_type() != MODEL_ENTITY_DESTRUCTED &&
173      observer_event.get_event_type() != ENTITY_DESTRUCTED )
174    return CUBIT_SUCCESS;
175
176
177    // is it a body?
178  if( (entity_ptr = dynamic_cast<Body*>(observable) ) != NULL )
179    dimension = 4;
180
181    // is it some other topology entity
182  else if( (entity_ptr = dynamic_cast<BasicTopologyEntity*>(observable) )
183           != NULL )
184    dimension = entity_ptr->dimension();
185
186    // otherwise we don't care about it
187  else
188    return CUBIT_FAILURE;
189 
190
191    // if it exists in the type list, remove it
192  if( typeList[dimension].move_to( entity_ptr ) )
193    typeList[dimension].extract();
194 
195    // if it exists in the current list, remove it.
196  if( dimension == currentDimension && 
197      currentList.move_to( entity_ptr ) )
198    currentList.extract();
199   
200  return CUBIT_SUCCESS;
201}
202
203DagType CAActuateSet::get_type_id( int dimension )
204{
205  switch( dimension )
206  {
207    case 4:  return DagType::body_type();     
208    case 3:  return DagType::ref_volume_type();
209    case 2:  return DagType::ref_face_type(); 
210    case 1:  return DagType::ref_edge_type(); 
211    case 0:  return DagType::ref_vertex_type();
212    default: assert(0); 
213             return DagType::invalid_type();
214  }
215}
Note: See TracBrowser for help on using the browser.