cgma
CompositeCoEdge.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CompositeCoEdge.cpp
00003 //
00004 // Purpose       : Combined set of CoEdgeSMs
00005 //
00006 // Special Notes : 
00007 //
00008 // Creator       : Jason Kraftcheck
00009 //
00010 // Creation Date : 01/11/02
00011 //-------------------------------------------------------------------------
00012 
00013 #include "CompositeCoEdge.hpp"
00014 #include "CompositeCurve.hpp"
00015 #include "CompositeLoop.hpp"
00016 #include "CompositeEngine.hpp"
00017 #include "VirtualQueryEngine.hpp"
00018 
00019 // for printing debug info
00020 #include "RefEdge.hpp"
00021 
00022 //-------------------------------------------------------------------------
00023 // Purpose       : Constructor
00024 //
00025 // Special Notes : 
00026 //
00027 // Creator       : Jason Kraftcheck
00028 //
00029 // Creation Date : 01/11/02
00030 //-------------------------------------------------------------------------
00031 CompositeCoEdge::CompositeCoEdge( CoEdgeSM* coedge )
00032   : myLoop(0), 
00033     nextCoedge(0), 
00034     prevCoedge(0), 
00035     myCurve(0), 
00036     nextOnCurve(0)
00037 {
00038   mySense = coedge->sense();
00039   coedgeSet.push( coedge );
00040   if( coedge->owner() )
00041     coedge->owner()->swap_bridge( coedge, this, false );
00042   coedge->owner(this);
00043 }
00044 
00045 CompositeCoEdge::CompositeCoEdge( CompositeCurve* point_curve )
00046   : mySense(CUBIT_FORWARD),
00047     myLoop(0), 
00048     nextCoedge(0), 
00049     prevCoedge(0), 
00050     myCurve(0), 
00051     nextOnCurve(0)
00052 {
00053   assert(point_curve->num_curves() == 0);
00054   CubitStatus stat = point_curve->add(this);
00055   assert(stat);
00056   if (CUBIT_SUCCESS != stat) {
00057     PRINT_ERROR("Failed to add a coedge to point curve.\n");
00058   }
00059 }
00060 
00061 CompositeCoEdge::CompositeCoEdge()
00062   : mySense(CUBIT_UNKNOWN),
00063     myLoop(0), 
00064     nextCoedge( 0 ),
00065     prevCoedge( 0 ), 
00066     myCurve(0),
00067     nextOnCurve(0)
00068   {}
00069 
00070 //-------------------------------------------------------------------------
00071 // Purpose       : Destructor
00072 //
00073 // Special Notes : 
00074 //
00075 // Creator       : Jason Kraftcheck
00076 //
00077 // Creation Date : 01/11/02
00078 //-------------------------------------------------------------------------
00079 CompositeCoEdge::~CompositeCoEdge()
00080 {
00081   if( myLoop )
00082     myLoop->remove(this);
00083   if( myCurve )
00084     myCurve->remove(this);
00085 
00086   assert( !prevCoedge && !nextCoedge && !nextOnCurve );
00087 
00088   for( int i = 0; i < coedgeSet.size(); i++ )
00089     if( coedgeSet[i]->owner() == this )
00090       coedgeSet[i]->owner(0);
00091 }
00092 /*
00093 //-------------------------------------------------------------------------
00094 // Purpose       : Add an underlying coedge
00095 //
00096 // Special Notes : 
00097 //
00098 // Creator       : Jason Kraftcheck
00099 //
00100 // Creation Date : 01/11/02
00101 //-------------------------------------------------------------------------
00102 CubitStatus CompositeCoEdge::append( CoEdgeSM* coedge_ptr )
00103 {
00104   if( index_of( coedge_ptr ) >= 0 || coedge_ptr->owner() ) 
00105     return CUBIT_FAILURE;
00106   
00107   coedge_ptr->owner( this );
00108   coedgeSet.push( coedge_ptr );
00109   
00110   return CUBIT_SUCCESS;
00111 }
00112 */
00113 
00114 //-------------------------------------------------------------------------
00115 // Purpose       : find the index of the coedge that owns the passed curve
00116 //
00117 // Special Notes : returns -1 if not found
00118 //
00119 // Creator       : Jason Kraftcheck
00120 //
00121 // Creation Date : 01/11/02
00122 //-------------------------------------------------------------------------
00123 int CompositeCoEdge::index_of( Curve* ptr ) const
00124 {
00125   int i;
00126   DLIList<TopologyBridge*> curve_list;
00127   TopologyBridge* curve = ptr;
00128   for( i = coedgeSet.size() - 1; i > 0; i-- )
00129   {
00130     curve_list.clean_out();
00131     coedgeSet[i]->get_children( curve_list );
00132     if( curve_list.is_in_list( curve ) )
00133       break;
00134   }
00135   return i;
00136 }
00137 
00138 //-------------------------------------------------------------------------
00139 // Purpose       : Split this CompositeCoEdge into two at the specified index
00140 //
00141 // Special Notes : new/other gets CoEdge at the passed index
00142 //
00143 // Creator       : Jason Kraftcheck
00144 //
00145 // Creation Date : 01/11/02
00146 //-------------------------------------------------------------------------
00147 CompositeCoEdge* CompositeCoEdge::split( int index )
00148 {
00149   if( index < 0 || index >= coedgeSet.size() )
00150     return 0;
00151   
00152   ++index;
00153   CompositeCoEdge* new_cce = new CompositeCoEdge();
00154   new_cce->mySense = mySense;
00155   
00156   int new_cce_count = coedgeSet.size() - index;
00157   new_cce->coedgeSet.size( new_cce_count );
00158   
00159   for( int i = 0; i < new_cce_count; i++ )
00160   {
00161     new_cce->coedgeSet[i] = coedgeSet[i+index];
00162     new_cce->coedgeSet[i]->owner( new_cce );
00163   }
00164   coedgeSet.size( index );
00165   
00166   if( myLoop )
00167   {
00168     CubitStatus s;
00169     if( mySense == CUBIT_FORWARD )
00170       s = myLoop->insert_after( new_cce, this );
00171     else
00172       s = myLoop->insert_before( new_cce, this );
00173     assert( s );
00174     if (CUBIT_SUCCESS != s) {
00175       PRINT_ERROR("Failed to insert a child coedge.\n");
00176       return NULL;
00177     }
00178   }
00179   
00180   new_cce->mySense = mySense;
00181   
00182   return new_cce;
00183 }
00184 
00185 CubitStatus CompositeCoEdge::combine( CompositeCoEdge* dead, bool prepend )
00186 {
00187   int insert;
00188   if ( prepend )
00189   {
00190     insert = 0;
00191     coedgeSet.size_end( coedgeSet.size() + dead->coedgeSet.size() );
00192   }
00193   else
00194   {
00195     insert = coedgeSet.size();
00196     coedgeSet.size( coedgeSet.size() + dead->coedgeSet.size() );
00197   }
00198   
00199   for( int i = 0; i < dead->coedgeSet.size(); i++ )
00200   {
00201     CoEdgeSM* coedge = dead->coedgeSet[i];
00202     assert( coedge->owner() == dead );
00203     coedge->owner(this);
00204     coedgeSet[insert++] = coedge;
00205   }
00206   dead->coedgeSet.size(0);
00207   return CUBIT_SUCCESS;
00208 }
00209 
00210 /*
00211 //-------------------------------------------------------------------------
00212 // Purpose       : dequeue underlying coedge
00213 //
00214 // Special Notes : 
00215 //
00216 // Creator       : Jason Kraftcheck
00217 //
00218 // Creation Date : 01/11/02
00219 //-------------------------------------------------------------------------
00220 CoEdgeSM* CompositeCoEdge::remove_first()
00221 {
00222   CoEdgeSM* result = 0;
00223   if( coedgeSet.size() > 0 )
00224   {
00225     result = coedgeSet[0];
00226     coedgeSet.remove(0);
00227   }
00228   return result;
00229 }
00230 
00231 //-------------------------------------------------------------------------
00232 // Purpose       : pop underlying coedge
00233 //
00234 // Special Notes : 
00235 //
00236 // Creator       : Jason Kraftcheck
00237 //
00238 // Creation Date : 01/11/02
00239 //-------------------------------------------------------------------------
00240 CoEdgeSM* CompositeCoEdge::remove_last()
00241 {
00242   CoEdgeSM* result = 0;
00243   if( coedgeSet.size() > 0 )
00244   {
00245     result = coedgeSet.pop()
00246     result->owner(0);
00247   }
00248   return result;
00249 }
00250 */
00251 //-------------------------------------------------------------------------
00252 // Purpose       : get parents (pure virtual in TopologyBridge)
00253 //
00254 // Special Notes : 
00255 //
00256 // Creator       : Jason Kraftcheck
00257 //
00258 // Creation Date : 01/11/02
00259 //-------------------------------------------------------------------------
00260 void CompositeCoEdge::get_parents_virt( DLIList<TopologyBridge*>& parents )
00261 { 
00262   LoopSM* result = get_parent_loop();
00263   if( result ) 
00264   {
00265     parents.append( result ); 
00266   }
00267 }
00268   
00269 //-------------------------------------------------------------------------
00270 // Purpose       : get children (pure virtual in TopologyBridge)
00271 //
00272 // Special Notes : 
00273 //
00274 // Creator       : Jason Kraftcheck
00275 //
00276 // Creation Date : 01/11/02
00277 //-------------------------------------------------------------------------
00278 void CompositeCoEdge::get_children_virt( DLIList<TopologyBridge*>& children )
00279 { 
00280   if( myCurve ) 
00281   {
00282     children.append( myCurve->primary_stitched_curve() ); 
00283   }
00284 /*
00285   else if( num_coedges() )
00286   {
00287     DLIList<TopologyBridge*> coedge_children;
00288     coedge(0)->get_children( coedge_children );
00289     assert( coedge_children.size() == 1 );
00290     children.append( coedge_children.get() );
00291   }
00292 */
00293 }
00294     
00295 /*
00296 //-------------------------------------------------------------------------
00297 // Purpose       : Set child curve
00298 //
00299 // Special Notes : If curve is composite, update curve link to this
00300 //
00301 // Creator       : Jason Kraftcheck
00302 //
00303 // Creation Date : 01/11/02
00304 //-------------------------------------------------------------------------
00305 void CompositeCoEdge::curve( CompositeCurve* curve_ptr )
00306 {
00307   if( myCurve )
00308   {
00309     myCurve->remove(this);
00310     assert( !myCurve );
00311   }  
00312   
00313   if( curve_ptr )
00314   {
00315     curve_ptr->add(this);
00316     assert( myCurve == curve_ptr );
00317   }
00318 }
00319 
00320 //-------------------------------------------------------------------------
00321 // Purpose       : set loop pointer
00322 //
00323 // Special Notes : if loop is composite, add this to loop instead
00324 //
00325 // Creator       : Jason Kraftcheck
00326 //
00327 // Creation Date : 01/11/02
00328 //-------------------------------------------------------------------------
00329 void CompositeCoEdge::loop( CompositeLoop* loop_ptr )
00330 {
00331   if( myLoop )
00332     myLoop->remove( this );
00333   
00334   if( loop_ptr )
00335     loop_ptr->insert_before( loop_ptr->first_coedge(), this );
00336   
00337   myLoop = loop_ptr;
00338 }
00339 */
00340 //-------------------------------------------------------------------------
00341 // Purpose       : Get parent loop no higher than composite level
00342 //
00343 // Special Notes : 
00344 //
00345 // Creator       : Jason Kraftcheck
00346 //
00347 // Creation Date : 03/05/02
00348 //-------------------------------------------------------------------------
00349 LoopSM* CompositeCoEdge::get_parent_loop()
00350 {
00351   LoopSM* result = get_loop();
00352   
00353   if( !result && num_coedges() )
00354   {
00355     DLIList<TopologyBridge*> parents(1);
00356     get_coedge(0)->get_parents_virt( parents );
00357     assert( parents.size() == 1 );
00358     result = dynamic_cast<LoopSM*>(parents.get());
00359   }
00360   
00361   return result;
00362 }
00363 
00364 //-------------------------------------------------------------------------
00365 // Purpose       : remove an underlying bridge
00366 //
00367 // Special Notes : pure virtual in TBOwner
00368 //
00369 // Creator       : Jason Kraftcheck
00370 //
00371 // Creation Date : 01/11/02
00372 //-------------------------------------------------------------------------
00373 CubitStatus CompositeCoEdge::remove_bridge( TopologyBridge* bridge )
00374 {
00375   int index;
00376   for( index = coedgeSet.size() - 1; index >= 0; index-- )
00377     if( coedgeSet[index] == bridge )
00378       break;
00379   if( index < 0 )
00380     return CUBIT_FAILURE;
00381   
00382   coedgeSet.remove( index );
00383   bridge->owner(0);
00384 /*  
00385   if ( coedgeSet.size() > 0 )
00386     return CUBIT_SUCCESS;
00387   
00388   if ( get_curve() )
00389     get_curve()->remove(this);
00390 
00391   if ( get_loop() )
00392   {
00393     CompositeLoop* loop = get_loop();
00394     loop->remove(this);
00395     if ( loop->first_coedge() == 0 )
00396       delete loop;
00397   }
00398   
00399   delete this;  
00400 */    
00401   return CUBIT_SUCCESS;
00402 }
00403 
00404 //-------------------------------------------------------------------------
00405 // Purpose       : exchange one underlying coedge for another
00406 //
00407 // Special Notes : pure virtual in TBOwner
00408 //
00409 // Creator       : Jason Kraftcheck
00410 //
00411 // Creation Date : 01/11/02
00412 //-------------------------------------------------------------------------
00413 CubitStatus CompositeCoEdge::swap_bridge( TopologyBridge* old_tb,
00414                                           TopologyBridge* new_tb,
00415                                           bool )
00416 {
00417   CoEdgeSM* old_coedge = dynamic_cast<CoEdgeSM*>(old_tb);
00418   CoEdgeSM* new_coedge = dynamic_cast<CoEdgeSM*>(new_tb);
00419   
00420   int index = index_of( old_coedge );
00421   if( index < 0 || !new_coedge || index_of(new_coedge) >= 0 )
00422     return CUBIT_FAILURE;
00423   
00424   coedgeSet[index] = new_coedge;
00425 
00426   old_tb->owner(0);
00427   if( new_tb->owner() )
00428     new_tb->owner()->remove_bridge( new_tb );
00429   new_tb->owner(this);
00430   
00431   return CUBIT_SUCCESS;
00432 }
00433 
00434 //-------------------------------------------------------------------------
00435 // Purpose       : see if we are the owner of the passed TB
00436 //
00437 // Special Notes : pure virtual in TBOwner
00438 //
00439 // Creator       : Jason Kraftcheck
00440 //
00441 // Creation Date : 01/11/02
00442 //-------------------------------------------------------------------------
00443 CubitBoolean CompositeCoEdge::contains_bridge( TopologyBridge* bridge ) const
00444 {
00445   CompositeCoEdge* coedge = dynamic_cast<CompositeCoEdge*>(bridge);
00446   return (index_of(coedge) < 0) ? CUBIT_FALSE : CUBIT_TRUE;
00447 }
00448 
00449 void CompositeCoEdge::notify_reversed( TopologyBridge* )
00450   {}
00451   
00452 
00453 //-------------------------------------------------------------------------
00454 // Purpose       : Get CompositeEngine
00455 //
00456 // Special Notes : 
00457 //
00458 // Creator       : Jason Kraftcheck
00459 //
00460 // Creation Date : 01/11/02
00461 //-------------------------------------------------------------------------
00462 GeometryQueryEngine* CompositeCoEdge::get_geometry_query_engine() const
00463   { return VirtualQueryEngine::instance(); }
00464 
00465 //-------------------------------------------------------------------------
00466 // Purpose       : Attribute functions
00467 //
00468 // Special Notes : 
00469 //
00470 // Creator       : Jason Kraftcheck
00471 //
00472 // Creation Date : 01/11/02
00473 //-------------------------------------------------------------------------
00474 void CompositeCoEdge::append_simple_attribute_virt( const CubitSimpleAttrib& )
00475 { }
00476 void CompositeCoEdge::remove_simple_attribute_virt( const CubitSimpleAttrib& )
00477 { }
00478 void CompositeCoEdge::remove_all_simple_attribute_virt()
00479 { }
00480 CubitStatus CompositeCoEdge::get_simple_attribute( DLIList<CubitSimpleAttrib>& )
00481 { return CUBIT_FAILURE; }
00482 CubitStatus CompositeCoEdge::get_simple_attribute( const CubitString& ,
00483                                                 DLIList<CubitSimpleAttrib>& )
00484 { return CUBIT_FAILURE; }
00485 
00486 
00487 
00488 
00489 void CompositeCoEdge::reverse()
00490 {
00491   switch( mySense ) {
00492     case CUBIT_FORWARD:
00493       mySense = CUBIT_REVERSED;
00494       break;
00495     case CUBIT_REVERSED:
00496       mySense = CUBIT_FORWARD;
00497       break;
00498     default:
00499       mySense = CUBIT_UNKNOWN;
00500   }
00501   
00502   int half = coedgeSet.size() / 2;
00503   for( int i = 0; i < half; i++ )
00504   {
00505     int j = coedgeSet.size() - i - 1;
00506     CoEdgeSM* tmp = coedgeSet[i];
00507     coedgeSet[i] = coedgeSet[j];
00508     coedgeSet[j] = tmp;
00509   }
00510     
00511 }
00512 
00513 //-------------------------------------------------------------------------
00514 // Purpose       : Get start and end points reversed if sense is reversed
00515 //
00516 // Special Notes : 
00517 //
00518 // Creator       : Jason Kraftcheck
00519 //
00520 // Creation Date : 03/17/02
00521 //-------------------------------------------------------------------------
00522 CompositePoint* CompositeCoEdge::start_point()
00523 {
00524   return mySense == CUBIT_FORWARD 
00525        ? myCurve->start_point() 
00526        : myCurve->end_point();
00527 }
00528 CompositePoint* CompositeCoEdge::end_point()
00529 {
00530   return mySense == CUBIT_FORWARD 
00531        ? myCurve->end_point() 
00532        : myCurve->start_point();
00533 }
00534 
00535 
00536 CubitStatus CompositeCoEdge::remove_coedge( int index )
00537 {
00538   if( index < 0 || index >= coedgeSet.size() )
00539     return CUBIT_FAILURE;
00540   
00541   coedgeSet[index]->owner(0);
00542   coedgeSet.remove( index );
00543 
00544   return CUBIT_SUCCESS;
00545 }
00546 
00547 
00548 CubitStatus CompositeCoEdge::insert_coedge( int index, CoEdgeSM* coedge )
00549 {
00550   if( index < 0 || index > coedgeSet.size() )
00551     return CUBIT_FAILURE;
00552   
00553   coedgeSet.insert(coedge, index);
00554   coedge->owner(this);
00555   return CUBIT_SUCCESS;
00556 }
00557 
00558 void CompositeCoEdge::print_debug_info( const char* prefix, bool brief )
00559 {
00560   if( prefix == 0 ) prefix = "";
00561   
00562   const char* sense = mySense == CUBIT_FORWARD ? "Forward" :
00563                       mySense == CUBIT_REVERSED ? "Reverse" : "UNKNOWN";
00564                       
00565   PRINT_INFO("%sCompCoEdge %p %s ", prefix, (void*)this, sense );
00566   if ( num_coedges() == 1 )
00567     PRINT_INFO("%s %p ", fix_type_name(typeid(*get_coedge(0)).name()),
00568       (void*)get_coedge(0));
00569   else
00570     PRINT_INFO("%d coedges ", num_coedges() );
00571     
00572   if( !myCurve )
00573     PRINT_INFO("NULL CURVE\n");
00574   else if( brief )
00575 #ifdef TOPOLOGY_BRIDGE_IDS
00576     PRINT_INFO("curve %d\n", myCurve->get_id() );
00577 #else
00578     PRINT_INFO("curve %p\n", (void*)myCurve );
00579 #endif
00580   else
00581     { PRINT_INFO("\n  ");  myCurve->print_debug_info(prefix, true); }
00582 
00583 /*  
00584   if( coedgeSet.size() == 0 )
00585     PRINT_INFO(" No CoEdgeSMs!\n");
00586   else if( coedgeSet.size() == 1 )
00587     PRINT_INFO(" CoEdgeSM=%p\n", coedgeSet[0] );
00588   else
00589   {
00590     PRINT_INFO("\n");
00591     for( int i = 0; i < coedgeSet.size(); i++ )
00592       PRINT_INFO("%s  CoEdgeSM[%d] = %p\n", prefix, i, coedgeSet[i] );
00593   }
00594 */
00595 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines