cgma
TopologyBridge.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : TopologyBridge.cpp
00003 //
00004 // Purpose       : 
00005 //                 
00006 // Creator       : Tim Tautges
00007 //
00008 // Creation Date : 03/22/99
00009 //
00010 // Owner         : Darryl Melander
00011 //-------------------------------------------------------------------------
00012 #include "TopologyBridge.hpp"
00013 #include "TopologyEntity.hpp"
00014 #include "DLIList.hpp"
00015 #include "BodySM.hpp"
00016 #include "Lump.hpp"
00017 #include "ShellSM.hpp"
00018 #include "Surface.hpp"
00019 #include "LoopSM.hpp"
00020 #include "Curve.hpp"
00021 #include "CoEdgeSM.hpp"
00022 #include "Point.hpp"
00023 #include "CubitSimpleAttrib.hpp"
00024 #include "BridgeManager.hpp"
00025 #include "TBOwner.hpp"
00026 #include "TBOwnerSet.hpp"
00027 #include "CADefines.hpp"
00028 
00029 TopologyBridge::~TopologyBridge()
00030 {
00031   if (bridgeOwner)
00032     bridgeOwner->bridge_destroyed(this);
00033 }
00034 
00035 TopologyEntity* TopologyBridge::topology_entity() const
00036 {
00037   BridgeManager* bridgeManager = bridge_manager();
00038   if (bridgeManager)
00039     return bridgeManager->topology_entity();
00040   else
00041     return NULL;
00042 }
00043 
00044 BodySM *TopologyBridge::bodysm()
00045 {
00046   DLIList<BodySM*> bodies;
00047   bodysms(bodies);
00048   if (bodies.size() > 0) return bodies.get();
00049   else return NULL;
00050 }
00051 
00052 Lump *TopologyBridge::lump()
00053 {
00054   DLIList<Lump*> lump_list;
00055   lumps(lump_list);
00056   if (lump_list.size() > 0) return lump_list.get();
00057   else return NULL;
00058 }
00059 
00060 
00061 LoopSM *TopologyBridge::loopsm()
00062 {
00063   DLIList<LoopSM*> loopsm_list;
00064   loopsms(loopsm_list);
00065   if (loopsm_list.size() > 0) return loopsm_list.get();
00066   else return NULL;
00067 }
00068 
00069 
00070 
00071 
00072 void TopologyBridge::bodysms( DLIList<BodySM*>& bodies, bool unique )
00073 {
00074   DLIList<TopologyBridge*> parents;
00075   BodySM* this_body = dynamic_cast<BodySM*>(this);
00076   if( this_body )
00077   {
00078     bodies.append( this_body );
00079   }
00080   else if( dynamic_cast<Lump*>(this) )
00081   {
00082     get_parents( parents );
00083     parents.reset();
00084     for ( int i = parents.size(); i--; )
00085       bodies.append (dynamic_cast<BodySM*>(parents.get_and_step()));
00086   }
00087   else
00088   {
00089     get_parents( parents );
00090     for( int i = parents.size(); i--; )
00091       parents.get_and_step()->bodysms( bodies, false );
00092     
00093     if (unique)
00094       bodies.uniquify_ordered();
00095   }
00096 }
00097     
00098 void TopologyBridge::lumps( DLIList<Lump*>& lumps, bool unique )
00099 {
00100   DLIList<TopologyBridge*> related;
00101   Lump* this_lump = dynamic_cast<Lump*>(this);
00102   if( this_lump )
00103   {
00104     lumps.append( this_lump );
00105   }
00106   else if( dynamic_cast<BodySM*>(this) )
00107   {
00108     get_children( related );
00109     related.reset();
00110     for ( int i = related.size(); i--; )
00111       lumps.append( dynamic_cast<Lump*>(related.get_and_step()) );
00112   }
00113   else if( dynamic_cast<ShellSM*>(this) )
00114   {
00115     get_parents( related );
00116     related.reset();
00117     for ( int i = related.size(); i--; )
00118       lumps.append( dynamic_cast<Lump*>(related.get_and_step()) );
00119   }
00120   else
00121   {
00122     get_parents( related );
00123     for( int i = related.size(); i--; )
00124       related.get_and_step()->lumps( lumps, false );
00125       
00126     if (unique)
00127       lumps.uniquify_ordered();
00128   }
00129 }
00130 
00131 void TopologyBridge::shellsms( DLIList<ShellSM*>& shells, bool unique )
00132 {
00133   DLIList<TopologyBridge*> related;
00134   ShellSM* this_shell = dynamic_cast<ShellSM*>(this);
00135   if( this_shell )
00136   {
00137     shells.append(this_shell);
00138   }
00139   else if( dynamic_cast<Lump*>(this) )
00140   {
00141     get_children( related );
00142     related.reset();
00143     for ( int i = related.size(); i--; )
00144       shells.append( dynamic_cast<ShellSM*>(related.get_and_step()) );
00145   }
00146   else if( dynamic_cast<Surface*>(this) )
00147   {
00148     get_parents( related );
00149     related.reset();
00150     for ( int i = related.size(); i--; )
00151       shells.append( dynamic_cast<ShellSM*>(related.get_and_step()) );
00152   }
00153   else if( dynamic_cast<BodySM*>(this) )
00154   {
00155     get_children( related );
00156     for ( int i = related.size(); i--; )
00157       related.get_and_step()->shellsms( shells );
00158   }
00159   else 
00160   {
00161     get_parents( related );
00162       
00163     for( int i = related.size(); i--; )
00164       related.get_and_step()->shellsms( shells, false );
00165     
00166     if ( unique )
00167       shells.uniquify_ordered();
00168   }
00169 }  
00170 
00171 void TopologyBridge::surfaces( DLIList<Surface*>& surfaces, bool unique )
00172 {
00173   DLIList<TopologyBridge*> related;
00174   Surface* this_surf = dynamic_cast<Surface*>(this);
00175   if( this_surf )
00176   {
00177     surfaces.append(this_surf);
00178   }
00179   else if( dynamic_cast<LoopSM*>(this) )
00180   {
00181     get_parents( related );
00182     related.reset();
00183     for (int i = related.size(); i--; )
00184       surfaces.append( dynamic_cast<Surface*>(related.get_and_step()) );
00185   }
00186   else if( dynamic_cast<ShellSM*>(this) )
00187   {
00188     get_children( related );
00189     related.reset();
00190     for (int i = related.size(); i--; )
00191       surfaces.append( dynamic_cast<Surface*>(related.get_and_step()) );
00192   }
00193   else if ( dynamic_cast<BodySM*>(this) || dynamic_cast<Lump*>(this) )
00194   {
00195     get_children(related);
00196     related.reset();
00197     for (int i = related.size(); i--; )
00198       related.get_and_step()->surfaces( surfaces, false );
00199       
00200     if (unique)
00201       surfaces.uniquify_ordered();
00202   }
00203   else
00204   {
00205     get_parents(related);
00206     related.reset();
00207     for (int i = related.size(); i--; )
00208       related.get_and_step()->surfaces( surfaces, false );
00209 
00210     if (unique && !dynamic_cast<CoEdgeSM*>(this))
00211       related.uniquify_ordered();
00212   }
00213 }  
00214 
00215 void TopologyBridge::loopsms( DLIList<LoopSM*>& loops, bool unique )
00216 {
00217   DLIList<TopologyBridge*> related;
00218   
00219   LoopSM* this_loop = dynamic_cast<LoopSM*>(this);
00220   if( this_loop )
00221   {
00222     loops.append(this_loop);
00223   }
00224   else if( dynamic_cast<CoEdgeSM*>(this ) )
00225   {
00226     get_parents( related );
00227     related.reset();
00228     for (int i = related.size(); i--; )
00229       loops.append( dynamic_cast<LoopSM*>(related.get_and_step()) );
00230   }
00231   else if( dynamic_cast<Surface*>(this) )
00232   {
00233     get_children( related );
00234     related.reset();
00235     for (int i = related.size(); i--; )
00236       loops.append( dynamic_cast<LoopSM*>(related.get_and_step()) );
00237   }
00238   else
00239   {
00240     if( dynamic_cast<Curve*>(this) || dynamic_cast<TBPoint*>(this) )
00241       get_parents( related );
00242     else
00243       get_children( related );
00244       
00245     related.reset();
00246     for( int i = related.size(); i--; )
00247       related.get_and_step()->loopsms( loops, false );
00248     
00249     if (unique)
00250       loops.uniquify_ordered();
00251   }
00252 }  
00253 
00254 
00255 void TopologyBridge::coedgesms( DLIList<CoEdgeSM*>& coedges, bool unique )
00256 {
00257   DLIList<TopologyBridge*> related;
00258   
00259   CoEdgeSM* this_coedge = dynamic_cast<CoEdgeSM*>(this);
00260   if( this_coedge )
00261   {
00262     coedges.append(this_coedge);
00263   }
00264   else if( dynamic_cast<Curve*>(this) )
00265   {
00266     get_parents( related );
00267     related.reset();
00268     for (int i = related.size(); i--; )
00269       coedges.append( dynamic_cast<CoEdgeSM*>(related.get_and_step()) );
00270   }
00271   else if( dynamic_cast<LoopSM*>(this) )
00272   {
00273     get_children( related );
00274     related.reset();
00275     for (int i = related.size(); i--; )
00276       coedges.append( dynamic_cast<CoEdgeSM*>(related.get_and_step()) );
00277   }
00278   else
00279   {
00280     if( dynamic_cast<TBPoint*>(this) )
00281       get_parents( related );
00282     else
00283       get_children( related );
00284     
00285     related.reset();  
00286     for( int i = related.size(); i--; )
00287       related.get_and_step()->coedgesms(coedges, false);
00288     
00289     if (unique)
00290       coedges.uniquify_ordered();
00291   }
00292 }  
00293 
00294 void TopologyBridge::curves_ignore_virtual( DLIList<Curve*>& curves, bool unique )
00295 {
00296   int i;
00297   if(dynamic_cast<BodySM*>(this))
00298   {
00299     DLIList<TopologyBridge*> lumps;
00300     this->get_children_virt(lumps);
00301     for(i=lumps.size(); i>0; i--)
00302       lumps.get_and_step()->curves_ignore_virtual(curves, unique);
00303   }
00304   else if(dynamic_cast<Lump*>(this))
00305   {
00306     DLIList<TopologyBridge*> shells;
00307     this->get_children_virt(shells);
00308     for(i=shells.size(); i>0; i--)
00309       shells.get_and_step()->curves_ignore_virtual(curves, unique);
00310   }
00311   else if(dynamic_cast<ShellSM*>(this))
00312   {
00313     DLIList<TopologyBridge*> surfs;
00314     this->get_children_virt(surfs);
00315     for(i=surfs.size(); i>0; i--)
00316       surfs.get_and_step()->curves_ignore_virtual(curves, unique);
00317   }
00318   else if(dynamic_cast<Surface*>(this))
00319   {
00320     DLIList<TopologyBridge*> loops;
00321     this->get_children_virt(loops);
00322     for(i=loops.size(); i>0; i--)
00323       loops.get_and_step()->curves_ignore_virtual(curves, unique);
00324   }
00325   else if(dynamic_cast<LoopSM*>(this))
00326   {
00327     DLIList<TopologyBridge*> coedges;
00328     this->get_children_virt(coedges);
00329     for(i=coedges.size(); i>0; i--)
00330       coedges.get_and_step()->curves_ignore_virtual(curves, unique);
00331   }
00332   else if(dynamic_cast<CoEdgeSM*>(this))
00333   {
00334     DLIList<TopologyBridge*> tmp_curves;
00335     this->get_children_virt(tmp_curves);
00336     for(i=tmp_curves.size(); i>0; i--)
00337       tmp_curves.get_and_step()->curves_ignore_virtual(curves, unique);
00338   }
00339   else if(dynamic_cast<Curve*>(this))
00340   {
00341     curves.append(dynamic_cast<Curve*>(this));
00342   }
00343   if(unique)
00344     curves.uniquify_ordered();
00345 }
00346 
00347 void TopologyBridge::surfaces_ignore_virtual( DLIList<Surface*>& surfaces, bool unique )
00348 {
00349   int i;
00350   if(dynamic_cast<BodySM*>(this))
00351   {
00352     DLIList<TopologyBridge*> lumps;
00353     this->get_children_virt(lumps);
00354     for(i=lumps.size(); i>0; i--)
00355       lumps.get_and_step()->surfaces_ignore_virtual(surfaces, unique);
00356   }
00357   else if(dynamic_cast<Lump*>(this))
00358   {
00359     DLIList<TopologyBridge*> shells;
00360     this->get_children_virt(shells);
00361     for(i=shells.size(); i>0; i--)
00362       shells.get_and_step()->surfaces_ignore_virtual(surfaces, unique);
00363   }
00364   else if(dynamic_cast<ShellSM*>(this))
00365   {
00366     DLIList<TopologyBridge*> surfs;
00367     this->get_children_virt(surfs);
00368     for(i=surfs.size(); i>0; i--)
00369       surfs.get_and_step()->surfaces_ignore_virtual(surfaces, unique);
00370   }
00371   else if(dynamic_cast<Surface*>(this))
00372   {
00373     surfaces.append(dynamic_cast<Surface*>(this));
00374   }
00375   if(unique)
00376     surfaces.uniquify_ordered();
00377 }
00378 
00379 void TopologyBridge::curves( DLIList<Curve*>& curves, bool unique )
00380 {
00381   DLIList<TopologyBridge*> related;
00382   
00383   Curve* this_curve = dynamic_cast<Curve*>(this);
00384   if( this_curve )
00385   {
00386     curves.append(this_curve);
00387   }
00388   else if( dynamic_cast<TBPoint*>(this) )
00389   {
00390     get_parents( related );
00391     related.reset();
00392     for (int i = related.size(); i--; )
00393       curves.append( dynamic_cast<Curve*>(related.get_and_step()) );
00394   }
00395   else if( dynamic_cast<CoEdgeSM*>(this) )
00396   {
00397     get_children( related );
00398     related.reset();
00399     for (int i = related.size(); i--; )
00400       curves.append( dynamic_cast<Curve*>(related.get_and_step()) );
00401   }
00402   else
00403   {
00404     get_children( related );
00405     
00406     related.reset();
00407     for (int i = related.size(); i--; )
00408       related.get_and_step()->curves (curves, false);
00409     
00410     if (unique)
00411       curves.uniquify_ordered();
00412   }
00413 }  
00414 
00415 void TopologyBridge::points( DLIList<TBPoint*>& points, bool unique )
00416 {
00417   DLIList<TopologyBridge*> children;
00418   
00419   TBPoint* this_point = dynamic_cast<TBPoint*>(this);
00420   if( this_point )
00421   {
00422     points.append(this_point);
00423   }
00424   else if( dynamic_cast<Curve*>(this) )
00425   {
00426     get_children( children );
00427     children.reset();
00428     for (int i = children.size(); i--; )
00429       points.append( dynamic_cast<TBPoint*>(children.get_and_step()) );
00430   }
00431   else
00432   {
00433     get_children( children );
00434       
00435     for( int i = children.size(); i--; )
00436       children.get_and_step()->points(points, false);
00437     
00438     if (unique)
00439       points.uniquify_ordered();
00440   }
00441 }  
00442 
00443 BridgeManager* TopologyBridge::bridge_manager() const
00444 { return dynamic_cast<BridgeManager*>(bridgeOwner); }
00445 
00446 void TopologyBridge::bridge_manager( BridgeManager* manager )
00447 { bridgeOwner = manager; }
00448 
00449 void TopologyBridge::get_parents( DLIList<TopologyBridge*>& parents )
00450 {
00451   parents.clean_out();
00452   get_parents_virt( parents );
00453   for ( int i = parents.size(); i--; )
00454   {
00455     TopologyBridge* tb_ptr = parents.step_and_get();
00456     TBOwnerSet* partition_body = dynamic_cast<TBOwnerSet*>(tb_ptr->owner());
00457     if ( partition_body )
00458     {
00459       DLIList<TopologyBridge*> owner_list;
00460       partition_body->get_owners(owner_list);
00461       assert(owner_list.size() == 1);
00462       parents.change_to(owner_list.get());
00463     }
00464   }
00465 }
00466 
00467 /*
00468 void TopologyBridge::get_parents( DLIList<TopologyBridge*>& parents,
00469                                   int layer, bool return_hidden )
00470 {
00471   assert( this->layer() <= layer );
00472   DLIList<TopologyBridge*> parents_real;
00473   get_parents_virt( parents_real );
00474   while( parents_real.size() )
00475   {
00476       // order of parent lists not important (i.e. okay if 
00477       // result list is reverse of parents_real.)
00478     TopologyBridge* parent_real = parents_real.pop();
00479     TBOwner* owner = parent_real->owner();
00480 
00481     TBOwnerSet* set = 0;
00482     TopologyBridge* composite = 0;
00483 
00484     if( !owner || dynamic_cast<BridgeManager*>(owner) )
00485     {
00486       parents.append_unique( parent_real );
00487     }
00488     else if( set = dynamic_cast<TBOwnerSet*>(owner) )
00489     {
00490       if( set->get_owner_layer() > layer )
00491       {
00492         parents.append_unique( parent_real );
00493       }
00494       else
00495       {
00496         DLIList<TopologyBridge*> bridge_set, children;
00497         set->get_owners( bridge_set );
00498         for( int i = bridge_set.size(); i--; )
00499         {
00500           TopologyBridge* partition = bridge_set.get_and_step();
00501           children.clean_out();
00502           partition->get_children_virt( children );
00503           if( children.is_in_list( this ) )
00504             parents_real.append_unique( partition );
00505         }
00506       }
00507     }
00508     else if( composite = dynamic_cast<TopologyBridge*>(owner) )
00509     {
00510       if( composite->layer() > layer )
00511         parents.append_unique(parent_real);
00512       else
00513         parents_real.append_unique( composite );
00514     }
00515     else if( return_hidden )
00516     {
00517       parents.append( parent_real );
00518     }
00519     else
00520     {
00521       ; // Do nothing.  This entity is hidden by some composite.
00522     }
00523   }
00524 }
00525 */
00526             
00527 void TopologyBridge::get_children( DLIList<TopologyBridge*>& children,
00528                                    bool return_hidden, int layer )
00529 {
00530   assert(this->layer() <= layer);
00531   
00532   DLIList<TopologyBridge*> child_list[2], partitions;
00533   int current = 0;
00534   
00535   get_children_virt( child_list[current] );
00536   // Note: be careful to return result list in the same order
00537   // as the child list we got above.
00538   
00539   bool done = false;
00540   while( !done )
00541   {
00542     done = true;
00543     
00544     int next = 1 - current;
00545     child_list[current].reset();
00546     child_list[next].clean_out();
00547     for( int i = child_list[current].size(); i--; )
00548     {
00549       TopologyBridge* child = child_list[current].get_and_step();
00550       TBOwner* owner = child->owner();
00551       
00552       TopologyBridge* composite = 0;
00553       TBOwnerSet* partition = 0;
00554       
00555       if( !owner || dynamic_cast<BridgeManager*>(owner) )
00556       {
00557         child_list[next].append( child );
00558       }
00559       else if( (partition = dynamic_cast<TBOwnerSet*>(owner) ) != NULL )
00560       {
00561         if( partition->get_owner_layer() > layer )
00562         {
00563           child_list[next].append(child);
00564         }
00565         else
00566         {
00567           done = false;
00568           partitions.clean_out();
00569           partition->get_owners( partitions );
00570           partitions.reset();
00571           child_list[next] += partitions;
00572         }
00573       }
00574       else if( (composite = dynamic_cast<TopologyBridge*>(owner) ) != NULL )
00575       {
00576         if( composite->layer() > layer )
00577         {
00578            child_list[next].append(child);
00579         }
00580         else
00581         {
00582           done = false;
00583           if( !child_list[current].is_in_list(composite) )
00584             child_list[next].append_unique( composite );
00585         }
00586       }
00587       else if( return_hidden )
00588       {
00589         child_list[next].append( child );
00590       }
00591       else
00592       {
00593         ; // Do nothing. This entity is hidden by some composite.
00594       }
00595     }
00596       
00597     current = next;
00598   }
00599   
00600   children = child_list[current];
00601 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines