cgma
CACompositeVG.cpp
Go to the documentation of this file.
00001 // CACompositeVG class
00002 
00003 #include "CACompositeVG.hpp"
00004 #include "CADeferredAttrib.hpp"
00005 #include "CAUniqueId.hpp"
00006 #include "TDUniqueId.hpp"
00007 #include "CastTo.hpp"
00008 #include "RefFace.hpp"
00009 #include "RefEdge.hpp"
00010 #include "BasicTopologyEntity.hpp"
00011 #include "PartitionEntity.hpp"
00012 #include "TopologyBridge.hpp"
00013 #include "CubitMessage.hpp"
00014 
00015 
00016 #include "CompositeTool.hpp"
00017 #include "CompositeSurface.hpp"
00018 #include "CompositeCurve.hpp"
00019 
00020 CubitAttrib* CACompositeVG_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
00021 {
00022   return new CACompositeVG(entity, p_csa);
00023 }
00024 
00025 CACompositeVG::CACompositeVG(RefEntity *owner, const CubitSimpleAttrib &simple_attrib)
00026         : CubitAttrib(owner)
00027 {
00028 
00029   compositeId = -1;
00030 
00031   if(!simple_attrib.isEmpty())
00032   {
00033 
00034       // generate a simple attribute containing the data in this CA
00035     const std::vector<int>& i_list = simple_attrib.int_data_list();
00036 
00037       // (no string)
00038 
00039       // now the integers
00040       // compositeId, numSubEntities
00041     compositeId = i_list[0];
00042     int numSubEntities = i_list[1];
00043     int i;
00044     for (i = 0; i < numSubEntities; i++)
00045     {
00046       subEntityIds.append(i_list[i+2]);
00047     }
00048 
00049       // If we are constructing from a CubitSimpleAttrib,
00050       // then this attrib is already written
00051     has_written(CUBIT_TRUE);
00052   }
00053 }
00054 
00055 CubitStatus CACompositeVG::update()
00056 {
00057   hasUpdated = CUBIT_TRUE;
00058   delete_attrib(CUBIT_TRUE);
00059   return CUBIT_SUCCESS;
00060 }
00061 
00062 CubitStatus CACompositeVG::reset()
00063 {
00064 
00065     // reset the info on this CACVG; don't reset info on underlying
00066     // entities, since the lists on this CACVG get *assigned* to that
00067     // entity and not *appended*
00068   compositeId = -1;
00069   subEntityIds.clean_out();
00070   return CUBIT_SUCCESS;
00071 }
00072   
00073 CubitSimpleAttrib CACompositeVG::cubit_simple_attrib()
00074 {
00075     // generate a simple attribute containing the data in this CA
00076   std::vector<CubitString> cs_list;
00077   std::vector<int> i_list;
00078 
00079     // first the string
00080   cs_list.push_back(att_internal_name());
00081 
00082     // now the integers
00083     // compositeId, numSubEntities
00084   i_list.push_back(compositeId);
00085   i_list.push_back(subEntityIds.size());
00086   int i;
00087   subEntityIds.reset();
00088   for (i = subEntityIds.size(); i > 0; i--)
00089     i_list.push_back(subEntityIds.get_and_step());
00090     
00091 
00092   return CubitSimpleAttrib(&cs_list, NULL, &i_list);
00093 }
00094 
00095 CubitStatus CACompositeVG::actuate()
00096 {
00097     // actuate this CA
00098   if (has_actuated() == CUBIT_TRUE) return CUBIT_SUCCESS;
00099 
00100     // actuate all the unique id attribute first, since CA_COMPOSITE_VG
00101     // depends on CA_UNIQUEID
00102   CAUniqueId::actuate_all();
00103   
00104     // now, gather up all the sub entities; if they're not all around,
00105     // exit without setting the actuate flag
00106   DLIList<ToolDataUser*> tdu_list;
00107   int i;
00108   subEntityIds.reset();
00109   CubitBoolean all_actuated = CUBIT_TRUE;
00110 
00111   DLIList<CACompositeVG*> comp_attribs;
00112 
00113   for (i = subEntityIds.size(); i > 0; i--) {
00114     ToolDataUser *tdu = TDUniqueId::find_td_unique_id(subEntityIds.get_and_step());
00115     if (tdu != NULL) tdu_list.append(tdu);
00116     else {
00117 
00118       // put this CA on a list for future actuation
00119       //has_actuated( CUBIT_FALSE );
00120       bool result = CADeferredAttrib::add_unactuated_ca(this);
00121 
00122       if (true == result) {
00123         PRINT_DEBUG_90("Can't actuate composite vg attrib on %s %d; adding to unactuated "
00124                        "list.\n",
00125                       attrib_owner()->class_name(), attrib_owner()->id());
00126       }
00127       return CUBIT_FAILURE;
00128     }
00129 
00130     //The portion of code below examines the entities that this entity will be 
00131     //composited with.  If the CACompositeVG attribute on these entities-to-be-composited 
00132     //do not have their 'has_actuated' variable set to TRUE, then this Composite attribute
00133     //is not ready to be actuated.  All entities-to-be-composited must have their 
00134     //'has_actuated' flag set to TRUE to be ready to be composited
00135     
00136     RefEntity *ref_entity = CAST_TO( tdu, RefEntity );
00137     if( ref_entity == NULL )
00138       return CUBIT_FAILURE;
00139     else
00140     {
00141       CACompositeVG *comp_vg_attrib = (CACompositeVG *) ref_entity->get_cubit_attrib(CA_COMPOSITE_VG);
00142       if( comp_vg_attrib ) 
00143       {
00144         comp_attribs.append( comp_vg_attrib );
00145         if( ref_entity == attrib_owner() ) //skip owner of this attribute..it will be actuated in a minute
00146           continue;
00147         if( !comp_vg_attrib->has_actuated() )
00148           all_actuated = CUBIT_FALSE;
00149         continue;
00150       }
00151       else
00152       {
00153         all_actuated = CUBIT_FALSE;
00154         continue;  
00155       }
00156     }
00157   }
00158 
00159   has_actuated( CUBIT_TRUE );
00160 
00161   //if all sub entities CACompositeVG attribs haven't been here, 
00162   //set this one and get out 
00163   if( all_actuated == CUBIT_FALSE )
00164     return CUBIT_SUCCESS;
00165 
00166     // ok, we've got a list of tdu's; cast to list of ref edges or faces (currently
00167     // the only entities we know how to composite)
00168   DLIList<RefEdge*> ref_edges;
00169   CAST_LIST(tdu_list, ref_edges, RefEdge);
00170   DLIList<RefFace*> ref_faces;
00171   CAST_LIST(tdu_list, ref_faces, RefFace);
00172 
00173     // do a little error checking: the entities should all be the same type, and
00174     // should be either ref edges or ref faces
00175   if ((ref_edges.size() > 0 && ref_faces.size() > 0) ||
00176       (ref_edges.size() > 0 && ref_edges.size() != tdu_list.size()) ||
00177       (ref_faces.size() > 0 && ref_faces.size() != tdu_list.size())) {
00178     PRINT_ERROR("Entities for composite containing %s %d not all the same.\n",
00179                 attrib_owner()->class_name(), attrib_owner()->id());
00180     return CUBIT_FAILURE;
00181   }
00182   else if (ref_edges.size() == 0 && ref_faces.size() == 0) {
00183     PRINT_ERROR("Can't find any faces or edges for composite containing %s %d.\n",
00184                 attrib_owner()->class_name(), attrib_owner()->id());
00185     return CUBIT_FAILURE;
00186   }
00187 
00188     // first, check to see that we can composite these entities; if
00189     // not, return without setting actuated flag; this CA will get 
00190     // re-actuated if a parent gets composited or partitioned.
00191   DLIList<BasicTopologyEntity*> bte_list;
00192   if (ref_edges.size() > 0) {
00193     CAST_LIST_TO_PARENT(ref_edges, bte_list);
00194   }
00195   else {
00196     CAST_LIST_TO_PARENT(ref_faces, bte_list);
00197   }
00198   
00199   if (!CompositeTool::instance()->okayToComposite(bte_list, NULL, NULL, CUBIT_FALSE))
00200   {
00201     for( int k = comp_attribs.size(); k--; )
00202       comp_attribs.get_and_step()->has_actuated( CUBIT_FALSE );
00203     has_actuated( CUBIT_FALSE );
00204     return CUBIT_FAILURE;
00205   }
00206     
00207 // ok, we can build the composite
00208   RefEntity *new_entity = NULL;
00209   if (ref_edges.size() > 0) {
00210     PRINT_DEBUG_90("Creating composite edge from %d edges\n",
00211                    ref_edges.size());
00212 
00213     //need to get the RefEdge that owns this attribute
00214     RefEdge *edge_to_keep= NULL;
00215     edge_to_keep = CAST_TO( attrib_owner(), RefEdge );
00216 
00217     if( edge_to_keep == NULL )
00218       return CUBIT_FAILURE;
00219 
00220     new_entity = CompositeTool::instance()->composite(ref_edges, NULL, edge_to_keep);
00221 
00222     new TDUniqueId(new_entity, compositeId);
00223     CADeferredAttrib::owner_created(new_entity, compositeId);
00224   }
00225   else if (ref_faces.size() > 0) {
00226     PRINT_DEBUG_90("Creating composite face from %d faces\n",
00227                    ref_faces.size());
00228 
00229     //need to get the RefFace that owns this attribute
00230     RefFace *face_to_keep = NULL;
00231     face_to_keep = CAST_TO( attrib_owner(), RefFace );
00232     
00233     if( face_to_keep == NULL )
00234       return CUBIT_FAILURE;
00235 
00236     new_entity = CompositeTool::instance()->composite(ref_faces, face_to_keep);
00237 
00238     new TDUniqueId(new_entity, compositeId);
00239     CADeferredAttrib::owner_created(new_entity, compositeId);
00240   }
00241   else {
00242       // shouldn't get here
00243     assert(CUBIT_FALSE);
00244   }
00245 /*
00246     // otherwise, we're done
00247     // set the actuated flag for all the CACVG's for this composite
00248   for (i = tdu_list.size(); i > 0; i--) {
00249     RefEntity *entity;
00250     if (ref_faces.size() > 0) entity = ref_faces.get_and_step();
00251     else entity = ref_edges.get_and_step();
00252     CACompositeVG *cacvg = (CACompositeVG *) entity->get_cubit_attrib(CA_COMPOSITE_VG);
00253     assert(cacvg != 0);
00254     cacvg->has_actuated(CUBIT_TRUE);
00255   }
00256 */
00257     // ok, we've composited; now check for CACVG's on any children, and
00258     // call actuate functions on those if they exist
00259   check_child_cacvgs(new_entity);
00260 
00261   return CUBIT_SUCCESS;
00262 }
00263 
00264 void CACompositeVG::check_child_cacvgs(RefEntity *new_entity) 
00265 {
00266     // check the new entity's children for CACVG's, and actuate those
00267     // if they exist
00268   DLIList<RefEntity*> children;
00269   new_entity->get_child_ref_entities(children);
00270 
00271   DLIList<CubitAttrib*> ca_list;
00272   
00273     // get the CA list first, then actuate; if we looped over entities,
00274     // actuating as we went, some entities might eventually be gone
00275     // when we got to them
00276   int i;
00277   for (i = children.size(); i > 0; i--) {
00278     RefEntity *child = children.get_and_step();
00279     child->find_cubit_attrib_type(CA_COMPOSITE_VG, ca_list);
00280   }
00281 
00282   //get unactuated deferred attribs
00283   DLIList<CubitAttrib*> unact_deferred_attribs;
00284   unact_deferred_attribs = CADeferredAttrib::get_unactuated_deferred_attribs();
00285 
00286 
00287   for (i = ca_list.size(); i > 0; i--) 
00288   {
00289     CubitAttrib *ca_ptr = ca_list.get();
00290     if (ca_ptr->has_actuated() == CUBIT_TRUE)
00291       ca_list.remove();
00292     else
00293       ca_list.step();
00294   }
00295 
00296     // for the same reason, don't delete until we've gone through the list
00297   for (i = ca_list.size(); i > 0; i--) {
00298     CubitAttrib *ca_ptr = ca_list.get();
00299 
00300     //don't try and actuate unactuated deferred attribs.....wait till later
00301     if( unact_deferred_attribs.move_to( ca_ptr ) )
00302     {
00303       ca_list.remove();
00304       continue;
00305     }
00306 
00307     if (ca_ptr->delete_attrib() == CUBIT_FALSE && 
00308         ca_ptr->has_actuated() == CUBIT_FALSE) 
00309     {
00310       ca_ptr->actuate();
00311     }
00312 
00313       // remove undeletable attribs from the list so we don't delete them later
00314     if (ca_ptr->delete_attrib() == CUBIT_FALSE)
00315       ca_list.remove();
00316     else
00317       ca_list.step();
00318   }
00319   
00320   for (i = ca_list.size(); i > 0; i--)
00321     delete ca_list.get_and_step();
00322 }
00323 
00324 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines