cgma
CompositeGeom.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CompositeGeom.cpp
00003 //
00004 // Purpose       : Object used by CompositeSurface and CompositeCurve
00005 //                 to manage underlying entities.
00006 //
00007 // Special Notes : 
00008 //
00009 // Creator       : Jason Kraftcheck
00010 //
00011 // Creation Date : 12/19/01
00012 //-------------------------------------------------------------------------
00013 
00014 #include "VGDefines.h"
00015 #include "GeometryEntity.hpp"
00016 #include "CompositeGeom.hpp"
00017 #include "CompositeAttrib.hpp"
00018 #include "DLIList.hpp"
00019 #include "CubitMessage.hpp"
00020 
00021   // used to print debug info:
00022 #include "Lump.hpp"
00023 #include "Surface.hpp"
00024 #include "Curve.hpp"
00025 #include "Point.hpp"
00026 
00027 const char* const COMPOSITE_DATA_ATTRIB_NAME = "COMPOSITE_ATTRIB";
00028   
00029 
00030 //-------------------------------------------------------------------------
00031 // Purpose       : Constructor
00032 //
00033 // Special Notes : 
00034 //
00035 // Creator       : Jason Kraftcheck
00036 //
00037 // Creation Date : 12/19/01
00038 //-------------------------------------------------------------------------
00039 CompositeGeom::CompositeGeom( int size )
00040   : entityList(size), 
00041     currentIndex(0),
00042     firstIndex(-1),
00043     needToUpdateBbox( true ),
00044     needToUpdateMeasure( true ),
00045     listHead(0)
00046 {
00047     // initialization above both allocated space for size
00048     // entities, and set the current count in the list to
00049     // size.  We want the initial memory, but need to set
00050     // the count back to zero.
00051   entityList.size(0);
00052 }
00053 
00054 //-------------------------------------------------------------------------
00055 // Purpose       : Destructor
00056 //
00057 // Special Notes : 
00058 //
00059 // Creator       : Jason Kraftcheck
00060 //
00061 // Creation Date : 12/19/01
00062 //-------------------------------------------------------------------------
00063 CompositeGeom::~CompositeGeom()
00064 {
00065   while(listHead)
00066   {
00067     CompositeAttrib* dead = listHead;
00068     listHead = listHead->next;
00069     delete dead;
00070   }
00071 }
00072 
00073 //-------------------------------------------------------------------------
00074 // Purpose       : Find the index of an entity
00075 //
00076 // Special Notes : 
00077 //
00078 // Creator       : Jason Kraftcheck
00079 //
00080 // Creation Date : 12/19/01
00081 //-------------------------------------------------------------------------
00082 int CompositeGeom::index_of( TopologyBridge* ptr ) const
00083 {
00084   int i;
00085   for( i = entityList.size() - 1; i >= 0; i-- )
00086     if( entityList[i].entity == ptr )
00087       break;
00088 
00089   return i;
00090 }
00091 
00092 //-------------------------------------------------------------------------
00093 // Purpose       : Insert an entry
00094 //
00095 // Special Notes : 
00096 //
00097 // Creator       : Jason Kraftcheck
00098 //
00099 // Creation Date : 12/19/01
00100 //-------------------------------------------------------------------------
00101 CubitStatus CompositeGeom::insert( int index, GeometryEntity* geom_ptr, 
00102                                    CubitSense sense )
00103 {
00104   if( index < 0 )
00105   {
00106     assert( index >= 0 );
00107     index = 0;
00108   }
00109   else if( index > entityList.size() )
00110   {
00111     assert( index <= entityList.size() );
00112     index = entityList.size();
00113   }
00114   
00115   CompositeEntry ent;
00116   ent.entity  = geom_ptr;
00117   ent.sense   = sense;
00118   ent.dist_sqr = ent.measure = 0.;
00119 
00120   //force 0th surface to be one that has the composite attrib on it.
00121   DLIList<CubitSimpleAttrib> list;
00122   geom_ptr->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00123   if( list.size() )
00124     index = 0;
00125 
00126   entityList.insert( ent, index );
00127 
00128   update_cached_data();
00129    
00130   return CUBIT_SUCCESS;
00131 }
00132 
00133 //-------------------------------------------------------------------------
00134 // Purpose       : Remove an entry
00135 //
00136 // Special Notes : 
00137 //
00138 // Creator       : Jason Kraftcheck
00139 //
00140 // Creation Date : 12/19/01
00141 //-------------------------------------------------------------------------
00142 CubitStatus CompositeGeom::remove( int index, bool dead )
00143 {
00144   if( (index < 0) || (index >= entityList.size()) )
00145   {
00146     assert( index >= 0 && index < entityList.size() );
00147     return CUBIT_FAILURE;
00148   }
00149   
00150   if (!dead)
00151     clean_up_attribs(entityList[index].entity);
00152   
00153   entityList.remove( index );
00154   update_cached_data();
00155   
00156   return CUBIT_SUCCESS;
00157 }
00158 
00159 //-------------------------------------------------------------------------
00160 // Purpose       : Split this composite into two, where all entries
00161 //                 before the passed index remain in this entity and all
00162 //                 entries after the index become part of a new composite.
00163 //
00164 // Special Notes : The entry at the specified index remains in this.
00165 //
00166 // Creator       : Jason Kraftcheck
00167 //
00168 // Creation Date : 12/19/01
00169 //-------------------------------------------------------------------------
00170 CompositeGeom* CompositeGeom::split( int index )
00171 {
00172   int i;
00173   if( (index < 0) || (index >= entityList.size()) )
00174   {
00175     assert( index >= 0 && index < entityList.size() );
00176     return 0;
00177   }
00178   
00179     // find EntityName attribute
00180   CompositeAttrib* name_attrib = listHead;
00181   while (name_attrib && name_attrib->name() != "ENTITY_NAME")
00182     name_attrib = name_attrib->next;
00183       
00184   int first = index + 1;
00185   CompositeGeom* new_geom = new CompositeGeom( entityList.size() - first );
00186   
00187   for( i = first; i < entityList.size(); i++ )
00188     new_geom->append( entityList[i].entity, entityList[i].sense );
00189   
00190   entityList.size( first );
00191   update_cached_data();
00192   
00193     // copy entityname attrib to new entity
00194   if ( name_attrib )
00195   {
00196     assert(!new_geom->listHead);
00197     new_geom->listHead = new CompositeAttrib(*name_attrib);
00198   }
00199  
00200   return new_geom;
00201 }
00202 CompositeGeom* CompositeGeom::split( VGArray<int>& index_array )
00203 {
00204   int i, j;
00205   
00206   if( index_array.size() == 0 )
00207     return 0;
00208   
00209   for( i = 0; i < index_array.size(); i++ )
00210     if( index_array[i] < 0 || index_array[i] >= entityList.size() )
00211     {
00212       assert(0);
00213       return 0;
00214     }
00215   
00216   
00217     // find EntityName attribute
00218   CompositeAttrib* name_attrib = listHead;
00219   while (name_attrib && name_attrib->name() != "ENTITY_NAME")
00220     name_attrib = name_attrib->next;
00221   
00222   CompositeGeom* new_geom = new CompositeGeom( index_array.size() );
00223   for( i = 0; i < index_array.size(); i++ )
00224   {
00225     int index = index_array[i];
00226     assert( entityList[index].entity != NULL );
00227     new_geom->append( entityList[index].entity, entityList[index].sense );
00228     entityList[index].entity = 0;
00229   }
00230     
00231   for( i = 0; i < entityList.size() && entityList[i].entity; i++ );
00232   for( j = i + 1; j < entityList.size(); j++ )
00233   {
00234     if( entityList[j].entity )
00235     {
00236       entityList[i].entity = entityList[j].entity;
00237       entityList[i].sense  = entityList[j].sense;
00238       entityList[j].entity = 0;
00239       i++;
00240     }
00241   }
00242   entityList.size( i );
00243   
00244     // copy entityname attrib to new entity
00245   if ( name_attrib )
00246   {
00247     assert(!new_geom->listHead);
00248     new_geom->listHead = new CompositeAttrib(*name_attrib);
00249   }
00250   
00251   update_cached_data();
00252   return new_geom;
00253 }
00254 
00255 //-------------------------------------------------------------------------
00256 // Purpose       : change geometry entity
00257 //
00258 // Special Notes : 
00259 //
00260 // Creator       : Jason Kraftcheck
00261 //
00262 // Creation Date : 01/11/02
00263 //-------------------------------------------------------------------------
00264 CubitStatus CompositeGeom::swap( int index, GeometryEntity* new_geom )
00265 {
00266   if( (index < 0) || (index >= entityList.size()) )
00267   {
00268     assert( index >= 0 && index < entityList.size() );
00269     return CUBIT_FAILURE;
00270   }
00271   
00272   entityList[index].entity = new_geom;
00273   update_cached_data();
00274   return CUBIT_SUCCESS;
00275 }
00276 
00277 //-------------------------------------------------------------------------
00278 // Purpose       : Return union of bounding boxes of all entities.
00279 //
00280 // Special Notes : 
00281 //
00282 // Creator       : Jason Kraftcheck
00283 //
00284 // Creation Date : 12/19/01
00285 //-------------------------------------------------------------------------
00286 CubitBox CompositeGeom::bounding_box()
00287 {
00288   if( entityList.size() == 0 )
00289   {
00290     return CubitBox();
00291   }
00292   
00293   if( needToUpdateBbox )
00294     update_data_bbox();
00295     
00296   CubitBox box( entityList[0].bbox );
00297   for( int i = 1; i < entityList.size(); i++ )
00298     box |= entityList[i].bbox;
00299   return box;
00300 }
00301 
00302 //-------------------------------------------------------------------------
00303 // Purpose       : Return sum of measure() for all entities.
00304 //
00305 // Special Notes : 
00306 //
00307 // Creator       : Jason Kraftcheck
00308 //
00309 // Creation Date : 12/19/01
00310 //-------------------------------------------------------------------------
00311 double CompositeGeom::measure() 
00312 {
00313   if( entityList.size() == 0 )
00314     return 0.0;
00315   
00316   if( needToUpdateMeasure )
00317     update_data_measure();
00318 
00319   return entityList[entityList.size()-1].measure;
00320 }
00321 
00322 //-------------------------------------------------------------------------
00323 // Purpose       : Update cached data for each entity
00324 //
00325 // Special Notes : 
00326 //
00327 // Creator       : Jason Kraftcheck
00328 //
00329 // Creation Date : 12/19/01
00330 //-------------------------------------------------------------------------
00331 void CompositeGeom::update_data_measure()
00332 {
00333   needToUpdateMeasure = false;
00334   double sum = 0.0;
00335   for( int i = 0; i < entityList.size(); i++ )
00336   {
00337     sum += entityList[i].entity->measure();
00338     entityList[i].measure = sum;
00339   }
00340 }
00341 
00342 //-------------------------------------------------------------------------
00343 // Purpose       : Update cached data for each entity
00344 //
00345 // Special Notes : 
00346 //
00347 // Creator       : Jason Kraftcheck
00348 //
00349 // Creation Date : 12/19/01
00350 //-------------------------------------------------------------------------
00351 void CompositeGeom::update_data_bbox()
00352 {
00353   needToUpdateBbox = false;
00354   for( int i = 0; i < entityList.size(); i++ )
00355   {
00356     entityList[i].bbox    = entityList[i].entity->bounding_box();
00357   }
00358 }
00359 
00360 //-------------------------------------------------------------------------
00361 // Purpose       : Setup search based on distance between passed position
00362 //                 and the bounding box of each entity, and return the
00363 //                 index of the entity with the bounding box closest to
00364 //                 the passed position.
00365 //
00366 // Special Notes : 
00367 //
00368 // Creator       : Jason Kraftcheck
00369 //
00370 // Creation Date : 12/19/01
00371 //-------------------------------------------------------------------------
00372 int CompositeGeom::closest_box( const CubitVector& position )
00373 {
00374   if( entityList.size() <= 0 ) return -1;
00375   
00376   if( needToUpdateBbox ) update_data_bbox();
00377   
00378   int min_index = 0;
00379   double min_dist = entityList[0].dist_sqr 
00380     = entityList[0].bbox.distance_squared( position );
00381     
00382   for( int i = 1; i < entityList.size(); i++  )
00383   {
00384     CompositeEntry& ent = entityList[i];
00385     double dist_sqr = ent.dist_sqr = ent.bbox.distance_squared( position );
00386     if( dist_sqr < min_dist )
00387       min_index = i;
00388   }
00389 
00390   firstIndex = -1;
00391   currentIndex = min_index;
00392   return currentIndex;
00393 }
00394 
00395 //-------------------------------------------------------------------------
00396 // Purpose       : Interate through entities with bounding boxes
00397 //                 within the specified distance (squared) from the
00398 //                 position passed to closest_box().
00399 //
00400 // Special Notes : -1 is returned ONCE to indicate the end of the list.
00401 //                 Behavior is undefined if closest_box() has never been
00402 //                 called.
00403 //
00404 // Creator       : Jason Kraftcheck
00405 //
00406 // Creation Date : 12/19/01
00407 //-------------------------------------------------------------------------
00408 int CompositeGeom::next_box_within_dist( double dist_squared )
00409 {
00410   if( entityList.size() > 0 ) 
00411   {
00412     if( firstIndex < 0 )
00413     {
00414       firstIndex = currentIndex;
00415     }
00416     else if( firstIndex == currentIndex )
00417     {
00418       return -1;
00419     }
00420     
00421     while( (currentIndex = (currentIndex + 1) % entityList.size()) 
00422                 != firstIndex )
00423     {
00424       if( entityList[currentIndex].dist_sqr < dist_squared )
00425       {
00426         return currentIndex;
00427       }
00428     }
00429   }
00430     
00431   return -1;
00432 }
00433 
00434 //-------------------------------------------------------------------------
00435 // Purpose       : Reverse sense of composite
00436 //
00437 // Special Notes : 
00438 //
00439 // Creator       : Jason Kraftcheck
00440 //
00441 // Creation Date : 
00442 //-------------------------------------------------------------------------
00443 CubitStatus CompositeGeom::reverse()
00444 {
00445   reverse_order();
00446   reverse_rel_senses();
00447   return CUBIT_SUCCESS;
00448 }
00449 CubitStatus CompositeGeom::reverse_order()
00450 {
00451   int i, half = entityList.size() / 2;
00452   for( i = 0; i < half; i++ )
00453   {
00454     int j = entityList.size() - (i+1);
00455     GeometryEntity* temp_entity = entityList[i].entity;
00456     entityList[i].entity = entityList[j].entity;
00457     entityList[j].entity = temp_entity;
00458     CubitSense temp_sense = entityList[i].sense;
00459     entityList[i].sense = entityList[j].sense;
00460     entityList[j].sense = temp_sense;
00461   }
00462   update_cached_data();
00463   return CUBIT_SUCCESS;
00464 }
00465 CubitStatus CompositeGeom::reverse_rel_senses()
00466 {
00467   for( int i = 0; i < entityList.size(); i++ )
00468   {
00469     entityList[i].sense = 
00470       entityList[i].sense == CUBIT_FORWARD  ? CUBIT_REVERSED :
00471       entityList[i].sense == CUBIT_REVERSED ? CUBIT_FORWARD  :
00472       CUBIT_UNKNOWN;
00473   }
00474   
00475   return CUBIT_SUCCESS;
00476 }
00477 
00478 
00479 //-------------------------------------------------------------------------
00480 // Purpose       : Combine 
00481 //
00482 // Special Notes : 
00483 //
00484 // Creator       : Jason Kraftcheck
00485 //
00486 // Creation Date : 03/04/02
00487 //-------------------------------------------------------------------------
00488 CubitStatus CompositeGeom::merge( CompositeGeom& dead, bool prepend )
00489 {
00490   int i;
00491 
00492   if (entityList.size() == 1)
00493   {
00494     DLIList<CubitSimpleAttrib> list;
00495     entityList[0].entity->get_simple_attribute(list);
00496     list.reset();
00497     for (i = list.size(); i--; )
00498     {
00499       const CubitSimpleAttrib csa = list.get_and_step();
00500       if (csa.character_type() != COMPOSITE_DATA_ATTRIB_NAME)
00501         listHead = new CompositeAttrib(csa, listHead);
00502     }
00503   }
00504   
00505     // find EntityName attribute
00506   CompositeAttrib* this_name = listHead;
00507   while (this_name && this_name->name() != "ENTITY_NAME")
00508     this_name = this_name->next;
00509   
00510     // merge entity name attributes
00511   CompositeAttrib* dead_name = dead.listHead;
00512   if (dead_name)
00513   {
00514     if (dead_name->name() == "ENTITY_NAME")
00515     {
00516       dead_name = dead.listHead;
00517       dead.listHead = dead_name->next;
00518       dead_name->next = 0;
00519     }
00520     else 
00521     {
00522       while(dead_name->next && dead_name->next->name() != "ENTITY_NAME")
00523         dead_name = dead_name->next;
00524       if(dead_name->next)
00525       {
00526         CompositeAttrib* prev = dead_name;
00527         prev->next = dead_name = dead_name->next;
00528         dead_name->next = 0;
00529       }
00530     }
00531   }
00532   
00533 
00534   int insert ;
00535   if ( prepend )
00536   {
00537     insert = 0;
00538     entityList.size_end( entityList.size() + dead.entityList.size() );
00539   }
00540   else
00541   {
00542     insert = entityList.size();
00543     entityList.size( entityList.size() + dead.entityList.size() );
00544   }
00545   
00546   for( i = 0; i < dead.entityList.size(); i++ )
00547   {
00548     entityList[insert].entity = dead.entityList[i].entity;
00549     entityList[insert].sense  = dead.entityList[i].sense;
00550     insert++;
00551   }
00552 
00553   dead.entityList.size(0);
00554   update_cached_data();
00555 
00556   return CUBIT_SUCCESS;
00557 }
00558 
00559 
00560 //-------------------------------------------------------------------------
00561 // Purpose       : Store an attribute
00562 //
00563 // Special Notes : 
00564 //
00565 // Creator       : Jason Kraftcheck
00566 //
00567 // Creation Date : 06/18/02
00568 //-------------------------------------------------------------------------
00569 void CompositeGeom::add_attribute( const CubitSimpleAttrib& csa )
00570 {
00571   if (entityList.size() == 1)
00572     entityList[0].entity->append_simple_attribute_virt(csa);
00573   else
00574     listHead = new CompositeAttrib( csa, listHead );
00575 }
00576 
00577 //-------------------------------------------------------------------------
00578 // Purpose       : Remove an attribute
00579 //
00580 // Special Notes : 
00581 //
00582 // Creator       : Jason Kraftcheck
00583 //
00584 // Creation Date : 06/18/02
00585 //-------------------------------------------------------------------------
00586 void CompositeGeom::rem_attribute( const CubitSimpleAttrib& csa )
00587 {
00588   while (listHead && listHead->equals(csa))
00589   {
00590     CompositeAttrib* dead = listHead;
00591     listHead = dead->next;
00592     delete dead;
00593   }
00594   
00595   if (listHead)
00596   {
00597     CompositeAttrib* attrib = listHead;
00598     while (attrib->next)
00599     {
00600       if(attrib->next->equals(csa))
00601       {
00602         CompositeAttrib* dead = attrib->next;
00603         attrib->next = dead->next;
00604         delete dead;
00605       }
00606       else
00607       {
00608         attrib = attrib->next;
00609       }
00610     }
00611   }
00612   
00613   if (entityList.size() == 1)
00614     entityList[0].entity->remove_simple_attribute_virt(csa);
00615 }
00616 
00617 //-------------------------------------------------------------------------
00618 // Purpose       : Remove all attributes
00619 //
00620 // Special Notes : 
00621 //
00622 // Creator       : Jason Kraftcheck
00623 //
00624 // Creation Date : 06/18/02
00625 //-------------------------------------------------------------------------
00626 void CompositeGeom::rem_all_attributes() 
00627 {
00628   while(listHead)
00629   {
00630     CompositeAttrib* dead = listHead;
00631     listHead = listHead->next;
00632     delete dead;
00633   }
00634   
00635   if (entityList.size() == 1)
00636     entityList[0].entity->remove_all_simple_attribute_virt();
00637 }
00638 
00639 
00640 //-------------------------------------------------------------------------
00641 // Purpose       : Get all attributes
00642 //
00643 // Special Notes : 
00644 //
00645 // Creator       : Jason Kraftcheck
00646 //
00647 // Creation Date : 06/18/02
00648 //-------------------------------------------------------------------------
00649 void CompositeGeom::get_attributes( DLIList<CubitSimpleAttrib>& list )
00650 {
00651     // special case: single-entity 'composite'
00652   if (entityList.size() == 1)
00653   {
00654     TopologyBridge* entity = entityList[0].entity;
00655     entity->get_simple_attribute(list);
00656     
00657       // handle 8.1 attribs on single-entity 'composites'
00658     for (int i = list.size(); i--; )
00659     {
00660       const CubitSimpleAttrib& attrib = list.step_and_get();
00661       if (attrib.character_type() == COMPOSITE_DATA_ATTRIB_NAME &&
00662           attrib.int_data_list()[0] == 1)
00663       {
00664         entity->remove_simple_attribute_virt(attrib);
00665         CubitSimpleAttrib newattrib = attrib;
00666         newattrib.string_data_list().erase(newattrib.string_data_list().begin());
00667         newattrib.int_data_list().erase(newattrib.int_data_list().begin());
00668         entity->append_simple_attribute_virt(newattrib);
00669       }
00670     }
00671   }
00672       
00673     
00674   for (CompositeAttrib* ptr = listHead; ptr; ptr = ptr->next)
00675     list.append(ptr->csa());
00676 }
00677 
00678 //-------------------------------------------------------------------------
00679 // Purpose       : Get named attributes
00680 //
00681 // Special Notes : 
00682 //
00683 // Creator       : Jason Kraftcheck
00684 //
00685 // Creation Date : 03/03/03
00686 //-------------------------------------------------------------------------
00687 void CompositeGeom::get_attributes( const char* name,
00688                                     DLIList<CubitSimpleAttrib>& list )
00689 {
00690   if (entityList.size() == 1)
00691   {
00692       // handle 8.1 attribs on single-entity 'composites'
00693     list.clean_out();
00694     entityList[0].entity->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00695     while (list.size())
00696     {
00697       CubitSimpleAttrib attrib = list.pop();
00698       if (attrib.int_data_list()[0] == 1)
00699       {
00700         entityList[0].entity->remove_simple_attribute_virt(attrib);
00701         std::vector<CubitString> s(attrib.string_data_list().begin()+1, attrib.string_data_list().end());
00702         std::vector<int> i(attrib.int_data_list().begin()+1, attrib.int_data_list().end());
00703         CubitSimpleAttrib new_attrib(&s, &attrib.double_data_list(), &i);
00704         entityList[0].entity->append_simple_attribute_virt(new_attrib);
00705       }
00706     }
00707     
00708     entityList[0].entity->get_simple_attribute(name, list);
00709   }
00710     
00711   for (CompositeAttrib* ptr = listHead; ptr; ptr = ptr->next)
00712     if (ptr->name() == name)
00713       list.append(ptr->csa());
00714 }
00715 
00716 //-------------------------------------------------------------------------
00717 // Purpose       : Write info about object for debugging
00718 //
00719 // Special Notes : 
00720 //
00721 // Creator       : Jason Kraftcheck
00722 //
00723 // Creation Date : 
00724 //-------------------------------------------------------------------------
00725 void CompositeGeom::print_debug_info( const char* line_prefix )
00726 {
00727   if( needToUpdateBbox )
00728     update_data_bbox();
00729   if( needToUpdateMeasure )
00730     update_data_measure();
00731   if( line_prefix == 0 )
00732     line_prefix = "";
00733   
00734   PRINT_INFO("%sCompositeGeom @ %p : \n", line_prefix, (void*)this );
00735   for( int i = 0; i < entityList.size(); i++ )
00736   {
00737     GeometryEntity* ptr = entityList[i].entity;
00738 #ifdef TOPOLOGY_BRIDGE_IDS
00739     PRINT_INFO("%s  %15s %d %7s\n", line_prefix, 
00740       ptr ? fix_type_name(typeid(*ptr).name()) : "GeometryEntity",
00741       ptr ? ptr->get_id() : 0, 
00742       entityList[i].sense == CUBIT_FORWARD ? "Forward" :
00743       entityList[i].sense == CUBIT_REVERSED ? "Reverse" :
00744       "Unknown");
00745 #else    
00746     /*
00747     PRINT_INFO("%s  %15s %p %7s\n", line_prefix, 
00748       ptr ? fix_type_name(typeid(*ptr).name()) : "GeometryEntity",
00749       ptr, 
00750       entityList[i].sense == CUBIT_FORWARD ? "Forward" :
00751       entityList[i].sense == CUBIT_REVERSED ? "Reverse" :
00752       "Unknown");
00753       */
00754     PRINT_INFO("%s  %15s %d %7s\n", line_prefix, 
00755       ptr ? fix_type_name(typeid(*ptr).name()) : "GeometryEntity",
00756       ptr ? ptr->get_saved_id() : 0, 
00757       entityList[i].sense == CUBIT_FORWARD ? "Forward" :
00758       entityList[i].sense == CUBIT_REVERSED ? "Reverse" :
00759       "Unknown");
00760             
00761 #endif
00762   }
00763 }
00764 
00765 //-------------------------------------------------------------------------
00766 // Purpose       : Reverse geometric sense of composite
00767 //
00768 // Special Notes : 
00769 //
00770 // Creator       : Jason Kraftcheck
00771 //
00772 // Creation Date : 
00773 //-------------------------------------------------------------------------
00774 void CompositeGeom::reverse_sense( int index )
00775 {
00776   assert(index < entityList.size() );
00777   CubitSense old = entityList[index].sense;
00778   entityList[index].sense = (old == CUBIT_REVERSED) ? CUBIT_FORWARD : CUBIT_REVERSED;
00779 }
00780 
00781 //-------------------------------------------------------------------------
00782 // Purpose       : Read and remove attributes from underlying entities
00783 //
00784 // Special Notes : 
00785 //
00786 // Creator       : Jason Kraftcheck
00787 //
00788 // Creation Date : 06/30/03
00789 //-------------------------------------------------------------------------
00790 void CompositeGeom::read_attributes( GeometryEntity* geom_ptr )
00791 {
00792   DLIList<CubitSimpleAttrib> list;
00793   int i;
00794 
00795     // remove any attributes from previous read
00796   rem_all_attributes();
00797 
00798   if (geom_ptr)
00799   {
00800       // Special case for point-curves (no real curves to write
00801       // attirbutes to.)  Write to passed entity instead.
00802     assert(entityList.size() == 0);
00803     geom_ptr->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00804     
00805     list.reset();
00806     for (i = list.size(); i--; )
00807     {
00808       const CubitSimpleAttrib& attrib = list.get_and_step();
00809       assert(attrib.int_data_list().size());
00810       if (attrib.int_data_list()[0] == entityList.size())
00811       {
00812         geom_ptr->remove_simple_attribute_virt(attrib);
00813         CubitSimpleAttrib c = attrib;
00814         c.int_data_list().erase(c.int_data_list().begin());
00815         c.string_data_list().erase(c.string_data_list().begin());
00816         listHead = new CompositeAttrib(c,listHead);
00817       }
00818     }
00819     
00820     return;
00821   }
00822 
00823   for (i = 0; i < entityList.size(); i++)
00824   {
00825     list.clean_out();
00826     entityList[i].entity->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00827 
00828     list.reset();
00829     for (int j = list.size(); j--; )
00830     {
00831       const CubitSimpleAttrib& attrib = list.get_and_step();
00832       assert(attrib.int_data_list().size());
00833       if (attrib.int_data_list()[0] == entityList.size())
00834       {
00835         // Take the attributes off of the current entity and put them on the first entity
00836         // in this list.  I believe this is ok to do because the attributes should apply to
00837         // the whole composite surface and not just the underlying entity they are on 
00838         // (the one exception to this might be UNIQUE_ID but I haven't seen any problems
00839         // with this yet).  The reason for doing this is that there is some code (I believe
00840         // in uncomposite() that assumes any attributes will be on the first entity
00841         // in the list.  Previous code actually moved the entity to the beginning
00842         // of the list but this reordering of the list does not fly with composite
00843         // curves because there is code depending on the curves in the list being
00844         // ordered so that they connect end to end in a contiguous manner (the 
00845         // faceting code, for one, relies on this).  BWC 1/7/07.
00846         entityList[i].entity->remove_simple_attribute_virt(attrib);
00847         entityList[0].entity->append_simple_attribute_virt(attrib);
00848 
00849         CubitSimpleAttrib c = attrib;
00850         c.int_data_list().erase(c.int_data_list().begin());
00851         c.string_data_list().erase(c.string_data_list().begin());      
00852 
00853         if( NULL == listHead )
00854           listHead = new CompositeAttrib(c,listHead);               
00855         else //this assures that we are not adding duplicate attribs 
00856         {
00857           bool is_duplicate = false;
00858 
00859           CompositeAttrib* curr_attrib = listHead;
00860 
00861           while( curr_attrib )
00862           {
00863             if( curr_attrib->equals( c ) )
00864             {
00865               is_duplicate = true;
00866               break;
00867             }
00868             curr_attrib = curr_attrib->next;
00869           }
00870 
00871           if( false == is_duplicate )
00872             listHead = new CompositeAttrib(c,listHead);
00873         }
00874       }
00875     }
00876   }
00877 }
00878 
00879 //-------------------------------------------------------------------------
00880 // Purpose       : Save attributes on first underlying entity
00881 //
00882 // Special Notes : 
00883 //
00884 // Creator       : Jason Kraftcheck
00885 //
00886 // Creation Date : 06/30/03
00887 //-------------------------------------------------------------------------
00888 void CompositeGeom::write_attributes( GeometryEntity* geom_ptr )
00889 {
00890   DLIList<CubitSimpleAttrib> list;
00891 
00892   if (geom_ptr)
00893   {
00894       // Special case for point-curves (no real curves to write
00895       // attirbutes to.)  Write to passed entity instead.
00896     assert(entityList.size() == 0);
00897  
00898       // clean up any attributes from the previous write
00899     geom_ptr->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00900     while (list.size())
00901     {
00902       CubitSimpleAttrib csa = list.pop();
00903       geom_ptr->remove_simple_attribute_virt(csa);
00904     }
00905   }
00906   else
00907   {
00908     geom_ptr = entityList[0].entity;
00909  
00910       // clean up any attributes from the previous write
00911     for (int i = 0; i < entityList.size(); i++)
00912     {
00913       entityList[i].entity->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00914       while (list.size())
00915       {
00916         CubitSimpleAttrib csa = list.pop();
00917         entityList[i].entity->remove_simple_attribute_virt(csa);
00918       } 
00919     }
00920   }
00921   
00922   
00923   CubitString name = COMPOSITE_DATA_ATTRIB_NAME;
00924   int count = entityList.size();
00925   CubitSimpleAttrib attrib;
00926   
00927   for (CompositeAttrib* ptr = listHead; ptr; ptr = ptr->next)
00928   {
00929     attrib.string_data_list().push_back(name);
00930     attrib.int_data_list().push_back(count);
00931   
00932     ptr->append_to_csa(attrib);
00933     
00934     //append the name attribute on all the rest of the entities too.  This 
00935     //is so that if a one gets split, the results each get the name as well:
00936     //jack --> jack and jack@A
00937     if( ptr->name() == "ENTITY_NAME" )
00938     {
00939       for( int k=1; k<entityList.size(); k++ )
00940         entityList[k].entity->append_simple_attribute_virt( attrib );
00941     }
00942 
00943     geom_ptr->append_simple_attribute_virt(attrib);    
00944     
00945     attrib.string_data_list().clear();
00946     attrib.int_data_list().clear();
00947     attrib.double_data_list().clear();
00948   }
00949 }
00950 
00951 //-------------------------------------------------------------------------
00952 // Purpose       : Clean out composite attributes.
00953 //
00954 // Special Notes : 
00955 //
00956 // Creator       : Jason Kraftcheck
00957 //
00958 // Creation Date : 07/01/03
00959 //-------------------------------------------------------------------------
00960 void CompositeGeom::clean_up_attribs( GeometryEntity* ent )
00961 {
00962   DLIList<CubitSimpleAttrib> list;
00963   ent->get_simple_attribute(COMPOSITE_DATA_ATTRIB_NAME,list);
00964   while (list.size())
00965   {
00966     CubitSimpleAttrib csa = list.pop();
00967     ent->remove_simple_attribute_virt(csa);
00968   }
00969 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines