cgma
CAVirtualVG.cpp
Go to the documentation of this file.
00001 // CAVirtualVG class
00002 
00003 #include "CAVirtualVG.hpp"
00004 #include "CubitSimpleAttrib.hpp"
00005 #include "TopologyEntity.hpp"
00006 #include "RefEntity.hpp"
00007 #include "BasicTopologyEntity.hpp"
00008 #include "RefEdge.hpp"
00009 #include "RefVertex.hpp"
00010 #include "TDUniqueId.hpp"
00011 #include "CADeferredAttrib.hpp"
00012 
00013 CubitAttrib* CAVirtualVG_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
00014 {
00015   return new CAVirtualVG(entity, p_csa);
00016 }
00017 
00018 
00019 CAVirtualVG::CAVirtualVG(RefEntity *owner, const CubitSimpleAttrib &simple_attrib)
00020         : CubitAttrib(owner)
00021 {
00022   numVC = 0;
00023   numVV = 0;
00024 
00025   if(!simple_attrib.isEmpty())
00026   {
00027      // generate a simple attribute containing the data in this CA
00028     const std::vector<double> &d_list = simple_attrib.double_data_list();
00029     const std::vector<int> &i_list = simple_attrib.int_data_list();
00030 
00031       // (no string)
00032 
00033       // now the integers
00034       // numVV, numVC
00035     int offset = 0;
00036     numVV = i_list[offset++];
00037     numVC = i_list[offset++];
00038 
00039       // vgUIDs
00040     int i;
00041     for (i = numVV+(3*numVC); i > 0; i--)
00042       vgUIDs.append(i_list[offset++]);
00043 
00044       // numVCPoints
00045     int sum = 0;
00046     for (i = numVC; i > 0; i--) {
00047       int temp_int = i_list[offset++];
00048       numVCPoints.append(temp_int);
00049       sum += temp_int;
00050     }
00051 
00052     offset = 0;
00053       // pointUIDList
00054     for (i = numVV+sum; i > 0; i--) {
00055       double x = d_list[offset++];
00056       double y = d_list[offset++];
00057       double z = d_list[offset++];
00058       posVector.append(new CubitVector( x, y, z ) );
00059     }
00060 
00061       // If we are constructing from a CubitSimpleAttrib,
00062       // then this attrib is already written
00063     has_written(CUBIT_TRUE);
00064   }
00065 }
00066 
00067 CubitStatus CAVirtualVG::update()
00068 {
00069 
00070     // the owner entity is virtual; put a CAVirtualVG on the underlying entity to represent
00071     // this entity
00072 
00073   if (hasUpdated) return CUBIT_SUCCESS;
00074 /*  
00075   assert(attrib_owner() != 0);
00076 
00077   TopologyEntity *topo_entity = CAST_TO(attrib_owner(), TopologyEntity);
00078   assert(topo_entity != 0);
00079   
00080   DLIList<VirtualEntity*> ve_list;
00081   VirtualGeometryEngine::instance()->get_VEs(topo_entity, ve_list, CUBIT_FALSE, CUBIT_FALSE);
00082   
00083   for( int i = ve_list.size(); i--; )
00084   {
00085     ParasiteEntity *vge = dynamic_cast<ParasiteEntity*>(ve_list.get_and_step());
00086 
00087   if (vge == NULL) {
00088       // this entity isn't a virtual entity - if this entity doesn't have any virtual
00089       // entities registered, set delete flag, then exit
00090     if (numVV == 0 && numVC == 0)
00091       delete_attrib(CUBIT_TRUE);
00092     else {
00093       PRINT_DEBUG_90("Keeping CA_VIRTUAL_VG for %s %d\n",
00094                      attrib_owner()->class_name(), attrib_owner()->id());
00095       hasUpdated = CUBIT_TRUE;
00096     }
00097     
00098     continue;
00099   }
00100 
00101     // ok, we have a virtual entity; first get the underlying entity, and a CAVVG for that
00102     // entity
00103   BasicTopologyEntity* bte_ptr = vge->bte_bound_to();
00104   
00105   if (!bte_ptr) {
00106     PRINT_ERROR("Couldn't find underlying BTE for virtual entity %s %d.\n",
00107                 attrib_owner()->class_name(), attrib_owner()->id());
00108     return CUBIT_FAILURE;
00109   }
00110   
00111   CAVirtualVG *other_CAVVG = (CAVirtualVG *) bte_ptr->get_cubit_attrib(CA_VIRTUAL_VG);
00112 
00113     // if that other CAPVG's written flag is set, it's an old one from a
00114     // previous write and needs to be reset
00115   if (other_CAVVG->has_written() == CUBIT_TRUE) {
00116     other_CAVVG->reset();
00117     other_CAVVG->has_written(CUBIT_FALSE);
00118   }
00119 
00120     // now put virtual geometry-specific data on the attribute
00121   ParasitePoint *vvertex = CAST_TO(vge, ParasitePoint);
00122   ParasiteCurve *vcurve = CAST_TO(vge, ParasiteCurve);
00123   if (vvertex != NULL) {
00124       // put uids and position on ca
00125     other_CAVVG->add_vvertex(vvertex);
00126     other_CAVVG->delete_attrib(CUBIT_FALSE);
00127   }
00128 
00129   else if (vcurve != NULL) {
00130     other_CAVVG->add_vcurve(vcurve);
00131     other_CAVVG->delete_attrib(CUBIT_FALSE);
00132   }
00133 
00134   else {
00135     PRINT_ERROR("Shouldn't get here in CAVirtualVG::update.\n");
00136     return CUBIT_FAILURE;
00137   }
00138   }
00139 
00140   hasUpdated = CUBIT_TRUE;
00141   if (numVV == 0 && numVV == 0) delete_attrib(CUBIT_TRUE);
00142   
00143   return CUBIT_SUCCESS;
00144 */ 
00145 
00146   delete_attrib(CUBIT_TRUE);
00147   return CUBIT_SUCCESS;
00148 }
00149 
00150 
00151 CubitStatus CAVirtualVG::reset()
00152 {
00153     //- reset info; called from CAU and also from update!
00154   numVV = 0;
00155   numVC = 0;
00156     //- the number of virtual points and curves contained in this attr
00157 
00158   vgUIDs.clean_out();
00159     //- unique ids of virtual points and curves contained in this attr
00160 
00161   posVector.clean_out();
00162     //- position vectors for virtual curves
00163 
00164   numVCPoints.clean_out();
00165     //- for each virtual curve, the number of virtual points in that curve
00166 
00167   return CUBIT_SUCCESS;
00168 }
00169 
00170 CubitSimpleAttrib CAVirtualVG::cubit_simple_attrib()
00171 {
00172     // generate a simple attribute containing the data in this CA
00173   std::vector<CubitString> cs_list;
00174   std::vector<double> d_list;
00175   std::vector<int> i_list;
00176 
00177     // first the string
00178   cs_list.push_back(att_internal_name());
00179 
00180     // now the integers
00181     // numVV, numVC
00182   i_list.push_back(numVV);
00183   i_list.push_back(numVC);
00184 
00185     // vgUIDs
00186   int i;
00187   vgUIDs.reset();
00188   for (i = vgUIDs.size(); i > 0; i--)
00189     i_list.push_back(vgUIDs.get_and_step());
00190 
00191     // numVCPoints
00192   numVCPoints.reset();
00193   for (i = numVCPoints.size(); i > 0; i--)
00194     i_list.push_back(numVCPoints.get_and_step());
00195   
00196     // now the doubles
00197   posVector.reset();
00198   for (i = posVector.size(); i > 0; i--) {
00199     d_list.push_back(posVector.get()->x());
00200     d_list.push_back(posVector.get()->y());
00201     d_list.push_back(posVector.get_and_step()->z());
00202   }
00203   
00204   return CubitSimpleAttrib(&cs_list, &d_list, &i_list);
00205 }
00206 
00207 CubitStatus CAVirtualVG::actuate()
00208 {
00209     // actuate this CA
00210 /*
00211     // first, actuate the points, with this CA's owner as their owners
00212   int i, j;
00213   vgUIDs.reset();
00214   posVector.reset();
00215 
00216   DLIList<int> leftover_uids, leftover_vcpoints;
00217   DLIList<CubitVector*> leftover_posvector;
00218   int leftover_vvs = 0, leftover_vcs = 0;
00219 
00220   DLIList<ParasitePoint*> vpoint_list;
00221   for (i = 0; i < numVV; i++) {
00222     CubitVector pos_vec(*posVector.get_and_step());
00223       // make the virtual vertex
00224     BasicTopologyEntity *bte_ptr = CAST_TO(attrib_owner(), BasicTopologyEntity);
00225     RefVertex *new_vertex = 
00226       VirtualGeometryEngine::instance()->create_VirtualVertex(pos_vec, bte_ptr);
00227       // add a unique id to it, for referencing later
00228     TDUniqueId *uid_ptr = new TDUniqueId(new_vertex, vgUIDs.get());
00229     CADeferredAttrib::owner_created( new_vertex, vgUIDs.get_and_step() );
00230 
00231     if (new_vertex == NULL) {
00232       PRINT_WARNING("Problems making new vertex with uid = %d.\n", vgUIDs.prev());
00233       leftover_uids.append(vgUIDs.prev());
00234       leftover_posvector.append(posVector.prev());
00235       leftover_vvs++;
00236     }
00237   }
00238 
00239     // now actuate CAVVG's on lower order entities
00240   DLIList<RefEntity*> children;
00241   attrib_owner()->get_child_ref_entities(children);
00242   for (i = children.size(); i > 0; i--) {
00243     children.get_and_step()->actuate_cubit_attrib(CA_VIRTUAL_VG);
00244   }
00245 
00246     // now handle creating virtual curves
00247   numVCPoints.reset();
00248   DLIList<RefEdge*> vcurve_list;
00249   for (i = 0; i < numVC; i++) {
00250       // start by grabbing all the stuff off the attribute's lists
00251 
00252     int start_uid = vgUIDs.get_and_step(),
00253       end_uid = vgUIDs.get_and_step();
00254 
00255       // now get the intermediate points; these should all be virtual, and should
00256       // be in this entity's virtual point list
00257     DLIList<CubitVector*> vec_list;
00258       // get the number of virtual points in the list
00259     int num_points = numVCPoints.get_and_step();
00260     for (j = 0; j < num_points; j++)
00261       vec_list.append(posVector.get_and_step());
00262 
00263     int virtual_curve_uid = vgUIDs.get_and_step();
00264     
00265       // the first two are start and end points, and may not be virtual
00266     ToolDataUser *tdu = TDUniqueId::find_td_unique_id(start_uid);
00267     RefVertex *start_vertex = CAST_TO(tdu, RefVertex);
00268     tdu = TDUniqueId::find_td_unique_id(end_uid);
00269     RefVertex *end_vertex = CAST_TO(tdu, RefVertex);
00270     
00271     if (!start_vertex || !end_vertex) {
00272       PRINT_DEBUG_90("Couldn't restore virtual curve with uid = %d.\n",
00273                      virtual_curve_uid);
00274         // cache leftover data for restoring later
00275       leftover_uids.append(start_uid);
00276       leftover_uids.append(end_uid);
00277       leftover_uids.append(virtual_curve_uid);
00278       leftover_vcpoints.append(num_points);
00279       leftover_posvector += vec_list;
00280       leftover_vcs++;
00281       continue;
00282     }
00283     
00284       // make the virtual curve 
00285     RefEdge *virtual_edge = 
00286       VirtualGeometryEngine::instance()->create_VirtualEdge(start_vertex,
00287                                                             end_vertex,
00288                                                             vec_list);
00289     if (!virtual_edge) {
00290       PRINT_DEBUG_90("Couldn't restore virtual curve with uid = %d.\n",
00291                      virtual_curve_uid);
00292         // cache leftover data for restoring later
00293       leftover_uids.append(start_uid);
00294       leftover_uids.append(end_uid);
00295       leftover_uids.append(virtual_curve_uid);
00296       leftover_vcpoints.append(num_points);
00297       leftover_posvector += vec_list;
00298       leftover_vcs++;
00299       continue;
00300     }
00301 
00302     ParasiteEntity* curve = 
00303       dynamic_cast<ParasiteEntity*>(virtual_edge->get_geometry_entity_ptr());
00304     assert(curve != NULL);
00305     curve->bind_to( dynamic_cast<BasicTopologyEntity*>(attrib_owner())
00306       ->get_geometry_entity_ptr());
00307 
00308       // save the curve's unique id
00309     TDUniqueId *uid_ptr = new TDUniqueId(virtual_edge, virtual_curve_uid);
00310     
00311     CADeferredAttrib::owner_created( virtual_edge, virtual_curve_uid );
00312     //virtual_edge->actuate_cubit_attrib(CA_VIRTUAL_VG);
00313       //virtual_edge->actuate_cubit_attrib(CA_PARTITION_VG);
00314   }
00315 
00316   if (0 == leftover_vvs && 0 == leftover_vcs)
00317     hasActuated = CUBIT_TRUE;
00318   else {
00319       // have some leftover data - reset data in this attribute
00320     numVV = leftover_vvs;
00321     numVC = leftover_vcs;
00322     vgUIDs = leftover_uids;
00323     numVCPoints = leftover_vcpoints;
00324     posVector = leftover_posvector;
00325     hasActuated = CUBIT_FALSE;
00326 
00327       // now add this attribute to the unactuated list in CADA
00328     CADeferredAttrib::add_unactuated_ca(this);
00329   }
00330 
00331    // we're done
00332   return (CUBIT_FALSE == hasActuated ?
00333           CUBIT_FAILURE : CUBIT_SUCCESS);
00334 */ return CUBIT_FAILURE;
00335 }
00336 
00337 /*
00338 void CAVirtualVG::add_vvertex(ParasitePoint *vpoint)
00339 {
00340 
00341   TopologyEntity *vpoint_topo_entity = vpoint->topology_entity();
00342   RefVertex *owning_vertex = CAST_TO(vpoint_topo_entity, RefVertex);
00343   assert(owning_vertex != 0);
00344   int vvertex_uid = TDUniqueId::get_unique_id(owning_vertex);
00345   
00346     //- adds data for this vpoint to this CA
00347   numVV++;
00348   vgUIDs.insert_first(vvertex_uid);
00349   posVector.insert_first(new CubitVector(vpoint->coordinates()));
00350 }
00351 */
00352 /*
00353 void CAVirtualVG::add_vcurve(ParasiteCurve *vcurve)
00354 {
00355     // need to get list of vpoint uids defining the virtual curve
00356     // the owner should be a RefEdge
00357   TopologyEntity *vcurve_topo_entity = vcurve->topology_entity();
00358   RefEdge *virtual_edge = CAST_TO(vcurve_topo_entity, RefEdge);
00359   assert(virtual_edge != 0);
00360 
00361     // first get start and end points, and their uids
00362   DLIList<int> uid_list;
00363   RefVertex *temp_vertex = virtual_edge->start_vertex();
00364   int start_uid = TDUniqueId::get_unique_id(temp_vertex);
00365   vgUIDs.append(start_uid);
00366   temp_vertex = virtual_edge->end_vertex();
00367   int end_uid = TDUniqueId::get_unique_id(temp_vertex);
00368   vgUIDs.append(end_uid);
00369 
00370     // now get the other points and their uids
00371   DLIList<ParasitePoint*> vpoint_list;
00372   vcurve->getSegments(vpoint_list);
00373   vpoint_list.reset();
00374 
00375   for (int i = vpoint_list.size(); i > 0; i--) {
00376     ParasitePoint *temp_point = vpoint_list.get_and_step();
00377     posVector.append(new CubitVector(temp_point->coordinates()));
00378   }
00379 
00380   int owner_uid = TDUniqueId::get_unique_id(virtual_edge);
00381   
00382     //- adds data for this vcurve to this CA
00383   vgUIDs.append(owner_uid);
00384   numVCPoints.append(vpoint_list.size());
00385   numVC++;
00386 }
00387 
00388 */
00389 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines