root/cgm/trunk/geom/virtual/CACompositeVG.cpp

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

Version 10.2 of cgm.

  • Property svn:executable set to *
Line 
1// CACompositeVG class
2
3#include "CACompositeVG.hpp"
4#include "CADeferredAttrib.hpp"
5#include "CAUniqueId.hpp"
6#include "TDUniqueId.hpp"
7#include "CastTo.hpp"
8#include "RefFace.hpp"
9#include "RefEdge.hpp"
10#include "BasicTopologyEntity.hpp"
11#include "PartitionEntity.hpp"
12#include "TopologyBridge.hpp"
13
14#include "CompositeTool.hpp"
15#include "CompositeSurface.hpp"
16#include "CompositeCurve.hpp"
17
18CubitAttrib* CACompositeVG_creator(RefEntity* entity, CubitSimpleAttrib *p_csa)
19{
20  CACompositeVG *new_attrib = NULL;
21  if (NULL == p_csa)
22  {
23    new_attrib = new CACompositeVG(entity);
24  }
25  else
26  {
27    new_attrib = new CACompositeVG(entity, p_csa);
28  }
29
30  return new_attrib;
31}
32
33CACompositeVG::CACompositeVG(RefEntity *owner) 
34        : CubitAttrib(owner)
35{
36  compositeId = -1;
37}
38
39CACompositeVG::CACompositeVG(RefEntity *owner, CubitSimpleAttrib *simple_attrib) 
40        : CubitAttrib(owner)
41{
42    // generate a simple attribute containing the data in this CA
43  DLIList<CubitString*> *cs_list = simple_attrib->string_data_list();
44  DLIList<int*> *i_list = simple_attrib->int_data_list();
45
46  cs_list->reset();
47  i_list->reset();
48 
49    // (no string)
50
51    // now the integers
52    // compositeId, numSubEntities
53  compositeId = *i_list->get_and_step();
54  int numSubEntities = *i_list->get_and_step();
55  int i;
56  for (i = 0; i < numSubEntities; i++)
57    subEntityIds.append(*i_list->get_and_step());
58 
59    // If we are constructing from a CubitSimpleAttrib,
60    // then this attrib is already written
61  has_written(CUBIT_TRUE);
62}
63
64CubitStatus CACompositeVG::update()
65{
66  hasUpdated = CUBIT_TRUE;
67  delete_attrib(CUBIT_TRUE);
68  return CUBIT_SUCCESS;
69}
70
71CubitStatus CACompositeVG::reset()
72{
73
74    // reset the info on this CACVG; don't reset info on underlying
75    // entities, since the lists on this CACVG get *assigned* to that
76    // entity and not *appended*
77  compositeId = -1;
78  subEntityIds.clean_out();
79  return CUBIT_SUCCESS;
80}
81 
82CubitSimpleAttrib *CACompositeVG::cubit_simple_attrib()
83{
84    // generate a simple attribute containing the data in this CA
85  DLIList<CubitString*> cs_list;
86  DLIList<int> i_list;
87
88    // first the string
89  cs_list.append(new CubitString(att_internal_name()));
90
91    // now the integers
92    // compositeId, numSubEntities
93  i_list.append(compositeId);
94  i_list.append(subEntityIds.size());
95  int i;
96  subEntityIds.reset();
97  for (i = subEntityIds.size(); i > 0; i--)
98    i_list.append(subEntityIds.get_and_step());
99   
100
101  CubitSimpleAttrib* csattrib_ptr = new CubitSimpleAttrib(&cs_list,
102                                                          NULL,
103                                                          &i_list);
104
105  for(i=cs_list.size(); i--;) delete cs_list.get_and_step();
106
107  return csattrib_ptr;
108}
109
110CubitStatus CACompositeVG::actuate()
111{
112    // actuate this CA
113  if (has_actuated() == CUBIT_TRUE) return CUBIT_SUCCESS;
114
115    // actuate all the unique id attribute first, since CA_COMPOSITE_VG
116    // depends on CA_UNIQUEID
117  CAUniqueId::actuate_all();
118 
119    // now, gather up all the sub entities; if they're not all around,
120    // exit without setting the actuate flag
121  DLIList<ToolDataUser*> tdu_list;
122  int i;
123  subEntityIds.reset();
124  CubitBoolean all_actuated = CUBIT_TRUE;
125
126  DLIList<CACompositeVG*> comp_attribs;
127
128  for (i = subEntityIds.size(); i > 0; i--) {
129    ToolDataUser *tdu = TDUniqueId::find_td_unique_id(subEntityIds.get_and_step());
130    if (tdu != NULL) tdu_list.append(tdu);
131    else {
132
133      // put this CA on a list for future actuation
134      //has_actuated( CUBIT_FALSE );
135      bool result = CADeferredAttrib::add_unactuated_ca(this);
136
137      if (true == result)
138        PRINT_DEBUG_90("Can't actuate composite vg attrib on %s %d; adding to unactuated "
139                       "list.\n",
140                      attrib_owner()->class_name(), attrib_owner()->id());
141      return CUBIT_FAILURE;
142    }
143
144    //The portion of code below examines the entities that this entity will be
145    //composited with.  If the CACompositeVG attribute on these entities-to-be-composited
146    //do not have their 'has_actuated' variable set to TRUE, then this Composite attribute
147    //is not ready to be actuated.  All entities-to-be-composited must have their
148    //'has_actuated' flag set to TRUE to be ready to be composited
149   
150    RefEntity *ref_entity = CAST_TO( tdu, RefEntity );
151    if( ref_entity == NULL )
152      return CUBIT_FAILURE;
153    else
154    {
155      CACompositeVG *comp_vg_attrib = (CACompositeVG *) ref_entity->get_cubit_attrib(CA_COMPOSITE_VG);
156      if( comp_vg_attrib ) 
157      {
158        comp_attribs.append( comp_vg_attrib );
159        if( ref_entity == attrib_owner() ) //skip owner of this attribute..it will be actuated in a minute
160          continue;
161        if( !comp_vg_attrib->has_actuated() )
162          all_actuated = CUBIT_FALSE;
163        continue;
164      }
165      else
166      {
167        all_actuated = CUBIT_FALSE;
168        continue; 
169      }
170    }
171  }
172
173  has_actuated( CUBIT_TRUE );
174
175  //if all sub entities CACompositeVG attribs haven't been here,
176  //set this one and get out
177  if( all_actuated == CUBIT_FALSE )
178    return CUBIT_SUCCESS;
179
180    // ok, we've got a list of tdu's; cast to list of ref edges or faces (currently
181    // the only entities we know how to composite)
182  DLIList<RefEdge*> ref_edges;
183  CAST_LIST(tdu_list, ref_edges, RefEdge);
184  DLIList<RefFace*> ref_faces;
185  CAST_LIST(tdu_list, ref_faces, RefFace);
186
187    // do a little error checking: the entities should all be the same type, and
188    // should be either ref edges or ref faces
189  if ((ref_edges.size() > 0 && ref_faces.size() > 0) ||
190      (ref_edges.size() > 0 && ref_edges.size() != tdu_list.size()) ||
191      (ref_faces.size() > 0 && ref_faces.size() != tdu_list.size())) {
192    PRINT_ERROR("Entities for composite containing %s %d not all the same.\n",
193                attrib_owner()->class_name(), attrib_owner()->id());
194    return CUBIT_FAILURE;
195  }
196  else if (ref_edges.size() == 0 && ref_faces.size() == 0) {
197    PRINT_ERROR("Can't find any faces or edges for composite containing %s %d.\n",
198                attrib_owner()->class_name(), attrib_owner()->id());
199    return CUBIT_FAILURE;
200  }
201
202    // first, check to see that we can composite these entities; if
203    // not, return without setting actuated flag; this CA will get
204    // re-actuated if a parent gets composited or partitioned.
205  DLIList<BasicTopologyEntity*> bte_list;
206  if (ref_edges.size() > 0) {
207    CAST_LIST_TO_PARENT(ref_edges, bte_list);
208  }
209  else {
210    CAST_LIST_TO_PARENT(ref_faces, bte_list);
211  }
212 
213  if (!CompositeTool::instance()->okayToComposite(bte_list, NULL, NULL, CUBIT_FALSE))
214  {
215    for( int k = comp_attribs.size(); k--; )
216      comp_attribs.get_and_step()->has_actuated( CUBIT_FALSE );
217    has_actuated( CUBIT_FALSE );
218    return CUBIT_FAILURE;
219  }
220   
221// ok, we can build the composite
222  RefEntity *new_entity = NULL;
223  if (ref_edges.size() > 0) {
224    PRINT_DEBUG_90("Creating composite edge from %d edges\n",
225                   ref_edges.size());
226
227    //need to get the RefEdge that owns this attribute
228    RefEdge *edge_to_keep= NULL;
229    edge_to_keep = CAST_TO( attrib_owner(), RefEdge );
230
231    if( edge_to_keep == NULL )
232      return CUBIT_FAILURE;
233
234    new_entity = CompositeTool::instance()->composite(ref_edges, NULL, edge_to_keep);
235
236    new TDUniqueId(new_entity, compositeId);
237    CADeferredAttrib::owner_created(new_entity, compositeId);
238  }
239  else if (ref_faces.size() > 0) {
240    PRINT_DEBUG_90("Creating composite face from %d faces\n",
241                   ref_faces.size());
242
243    //need to get the RefFace that owns this attribute
244    RefFace *face_to_keep = NULL;
245    face_to_keep = CAST_TO( attrib_owner(), RefFace );
246   
247    if( face_to_keep == NULL )
248      return CUBIT_FAILURE;
249
250    new_entity = CompositeTool::instance()->composite(ref_faces, face_to_keep);
251
252    new TDUniqueId(new_entity, compositeId);
253    CADeferredAttrib::owner_created(new_entity, compositeId);
254  }
255  else {
256      // shouldn't get here
257    assert(CUBIT_FALSE);
258  }
259/*
260    // otherwise, we're done
261    // set the actuated flag for all the CACVG's for this composite
262  for (i = tdu_list.size(); i > 0; i--) {
263    RefEntity *entity;
264    if (ref_faces.size() > 0) entity = ref_faces.get_and_step();
265    else entity = ref_edges.get_and_step();
266    CACompositeVG *cacvg = (CACompositeVG *) entity->get_cubit_attrib(CA_COMPOSITE_VG);
267    assert(cacvg != 0);
268    cacvg->has_actuated(CUBIT_TRUE);
269  }
270*/
271    // ok, we've composited; now check for CACVG's on any children, and
272    // call actuate functions on those if they exist
273  check_child_cacvgs(new_entity);
274
275  return CUBIT_SUCCESS;
276}
277
278void CACompositeVG::check_child_cacvgs(RefEntity *new_entity) 
279{
280    // check the new entity's children for CACVG's, and actuate those
281    // if they exist
282  DLIList<RefEntity*> children;
283  new_entity->get_child_ref_entities(children);
284
285  DLIList<CubitAttrib*> ca_list;
286 
287    // get the CA list first, then actuate; if we looped over entities,
288    // actuating as we went, some entities might eventually be gone
289    // when we got to them
290  int i;
291  for (i = children.size(); i > 0; i--) {
292    RefEntity *child = children.get_and_step();
293    child->find_cubit_attrib_type(CA_COMPOSITE_VG, ca_list);
294  }
295
296  //get unactuated deferred attribs
297  DLIList<CubitAttrib*> unact_deferred_attribs;
298  unact_deferred_attribs = CADeferredAttrib::get_unactuated_deferred_attribs();
299
300
301  for (i = ca_list.size(); i > 0; i--) 
302  {
303    CubitAttrib *ca_ptr = ca_list.get();
304    if (ca_ptr->has_actuated() == CUBIT_TRUE)
305      ca_list.remove();
306    else
307      ca_list.step();
308  }
309
310    // for the same reason, don't delete until we've gone through the list
311  for (i = ca_list.size(); i > 0; i--) {
312    CubitAttrib *ca_ptr = ca_list.get();
313
314    //don't try and actuate unactuated deferred attribs.....wait till later
315    if( unact_deferred_attribs.move_to( ca_ptr ) )
316    {
317      ca_list.remove();
318      continue;
319    }
320
321    if (ca_ptr->delete_attrib() == CUBIT_FALSE && 
322        ca_ptr->has_actuated() == CUBIT_FALSE) 
323    {
324      ca_ptr->actuate();
325    }
326
327      // remove undeletable attribs from the list so we don't delete them later
328    if (ca_ptr->delete_attrib() == CUBIT_FALSE)
329      ca_list.remove();
330    else
331      ca_list.step();
332  }
333 
334  for (i = ca_list.size(); i > 0; i--)
335    delete ca_list.get_and_step();
336}
337
Note: See TracBrowser for help on using the browser.