cgma
GroupingEntity.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : GroupingEntity.cpp
00003 //
00004 // Purpose       : This file contains the implementation of the class 
00005 //                 GroupingEntity. 
00006 //
00007 // Special Notes :
00008 //
00009 // Creator       : Xuechen Liu
00010 //
00011 // Creation Date : 07/11/96 
00012 //
00013 // Owner         :  Malcolm J. Panthaki
00014 //-------------------------------------------------------------------------
00015 
00016 // ********** BEGIN STANDARD INCLUDES      **********
00017 // ********** END STANDARD INCLUDES        **********
00018 
00019 // ********** BEGIN CUBIT INCLUDES         **********
00020 #include "GroupingEntity.hpp"
00021 #include "SenseEntity.hpp"
00022 #include "BasicTopologyEntity.hpp"
00023 
00024 #include "DLIList.hpp"
00025 #include "ModelQueryEngine.hpp"
00026 
00027 // ********** END CUBIT INCLUDES           **********
00028 
00029 
00030 // ********** BEGIN STATIC DECLARATIONS    **********
00031 // ********** END STATIC DECLARATIONS      **********
00032 
00033 // ********** BEGIN PUBLIC FUNCTIONS       **********
00034 
00035 //-------------------------------------------------------------------------
00036 // Purpose       : The destructor
00037 //
00038 // Special Notes :
00039 //
00040 // Creator       : Malcolm J. Panthaki
00041 //
00042 // Creation Date : 09/03/96
00043 //-------------------------------------------------------------------------
00044 GroupingEntity::~GroupingEntity()
00045 {
00046   if (myParent)
00047     myParent->remove_grouping_entity(this);
00048   while (firstSenseEntity && remove_sense_entity(firstSenseEntity));
00049     
00050   assert (!myParent && !nextInParent && !firstSenseEntity);
00051 }
00052 
00053 //-------------------------------------------------------------------------
00054 // Purpose       : This function returns a list of SenseEntity
00055 //                 pointers associated with this grouping entity.
00056 //
00057 // Special Notes : Complete reimplementation - j.k. July 2003
00058 //
00059 // Creator       : Xuechen Liu
00060 //
00061 // Creation Date : 07/28/96
00062 //-------------------------------------------------------------------------
00063 CubitStatus GroupingEntity::get_sense_entity_list( DLIList<SenseEntity*>& list)
00064 {
00065   if (!firstSenseEntity)
00066     return CUBIT_SUCCESS;
00067   
00068   for (SenseEntity* ptr = firstSenseEntity; ptr; ptr = ptr->next())
00069   {
00070     assert(ptr->get_grouping_entity_ptr() == this);
00071     list.append(ptr);
00072   }
00073   return CUBIT_SUCCESS;
00074 }
00075 
00076 //-------------------------------------------------------------------------
00077 // Purpose       : This function adds a sense entity to the list of 
00078 //                 sense entities of a grouping entity.
00079 //
00080 // Special Notes : In the DAG, the sense entities associated with the 
00081 //                 current grouping entity are linked from one sense
00082 //                 entity to another in order to maintain the order in
00083 //                 which the sense entities were added to the grouping
00084 //                 entity.
00085 //
00086 //                 Complete reimplementation - j.k. July 2003
00087 //
00088 // Creator       : Malcolm J. Panthaki
00089 //
00090 // Creation Date : 07/31/96
00091 //-------------------------------------------------------------------------
00092 CubitStatus GroupingEntity::add_sense_entity(SenseEntity *sense_entity,
00093                                              SenseEntity *after_this) 
00094 {
00095     // Check to make sure that we are getting the correct type of 
00096     // SenseEntity.
00097   if ( dag_type() != sense_entity->dag_type().parent() )
00098      return CUBIT_FAILURE ;
00099    
00100     // Check that the sense entity is not already in some other
00101     // grouping entity
00102   if ( sense_entity->get_grouping_entity_ptr() )
00103     return CUBIT_FAILURE;
00104   
00105     // prev and next ptrs should be NULL if sense entity is not
00106     // in a grouping entity
00107   assert (!sense_entity->next() && !sense_entity->previous());
00108   
00109   if (after_this)
00110   {
00111     if (after_this->get_grouping_entity_ptr() != this )
00112       return CUBIT_FAILURE;
00113   
00114     if (!sense_entity->gpe_insert_after(after_this))
00115       return CUBIT_FAILURE;
00116       
00117     if (after_this == lastSenseEntity)
00118       lastSenseEntity = sense_entity;
00119   }
00120   else if (lastSenseEntity)
00121   {
00122     if (!sense_entity->gpe_insert_after(lastSenseEntity))
00123       return CUBIT_FAILURE;
00124     lastSenseEntity = sense_entity;
00125   }
00126   else
00127   {
00128     firstSenseEntity = lastSenseEntity = sense_entity;
00129   }
00130   
00131   sense_entity->set_grouping_entity_ptr(this);
00132   return CUBIT_SUCCESS;
00133 }
00134 
00135 
00136 //-------------------------------------------------------------------------
00137 // Purpose       : Remove a child sense entity
00138 //
00139 // Special Notes : 
00140 //
00141 // Creator       : Jason Kraftcheck
00142 //
00143 // Creation Date : 07/22/03
00144 //-------------------------------------------------------------------------
00145 CubitStatus GroupingEntity::remove_sense_entity( SenseEntity* sense_entity_ptr )
00146 {
00147   if (sense_entity_ptr->get_grouping_entity_ptr() != this)
00148     return CUBIT_FAILURE;
00149   
00150   if (firstSenseEntity == sense_entity_ptr)
00151     firstSenseEntity = sense_entity_ptr->next();
00152   if (lastSenseEntity == sense_entity_ptr)
00153     lastSenseEntity = sense_entity_ptr->previous();
00154   
00155   sense_entity_ptr->gpe_remove();
00156   sense_entity_ptr->set_grouping_entity_ptr(NULL);
00157   return CUBIT_SUCCESS;
00158 }
00159 
00160 //-------------------------------------------------------------------------
00161 // Purpose       : Change/update/re-order child SenseEntity list
00162 //
00163 // Special Notes : 
00164 //
00165 // Creator       : Jason Kraftcheck
00166 //
00167 // Creation Date : 11/03/03
00168 //-------------------------------------------------------------------------
00169 CubitStatus GroupingEntity::set_sense_entity_list( 
00170                                         DLIList<SenseEntity*>& list,
00171                                         DLIList<SenseEntity*>& removed )
00172 {
00173   int i;
00174   
00175     // Remove all?
00176   if (list.size() == 0)
00177   {
00178     get_sense_entity_list( removed );
00179     return disconnect_all_children();
00180   }
00181   
00182     // Check for error conditions before modifying anything
00183   list.reset();
00184   for (i = list.size(); i--; )
00185   {
00186     SenseEntity* sense_entity = list.get_and_step();
00187     
00188       // Check to make sure that we are getting the correct type of 
00189       // SenseEntity.
00190     if ( dag_type() != sense_entity->dag_type().parent() )
00191        return CUBIT_FAILURE ;
00192    
00193       // Check that the sense entity is not already in some other
00194       // grouping entity
00195     if ( sense_entity->get_grouping_entity_ptr() &&
00196          sense_entity->get_grouping_entity_ptr() != this )
00197       return CUBIT_FAILURE;
00198   }
00199 
00200     // Special case for first entity in list.
00201   list.reset();
00202   SenseEntity* new_first = list.get_and_step();
00203     // No sense entities currently attached...
00204   if (!firstSenseEntity)
00205   {
00206     firstSenseEntity = lastSenseEntity = new_first;
00207     new_first->set_grouping_entity_ptr(this);
00208   }
00209     // Already attached, but not first in list...
00210   else if( firstSenseEntity != new_first )
00211   {
00212     if (!new_first->get_grouping_entity_ptr())
00213       new_first->set_grouping_entity_ptr(this);
00214     else
00215     {
00216       if (lastSenseEntity == new_first)
00217         lastSenseEntity = new_first->previous();
00218       new_first->gpe_remove();
00219     }
00220       
00221     new_first->gpe_insert_before(firstSenseEntity);
00222     firstSenseEntity = new_first;
00223   }
00224   
00225     // Now loop through remaining sense entities.
00226   SenseEntity* prev = new_first;
00227   for (i = list.size() - 1; i--; )
00228   {
00229     SenseEntity* curr = list.get_and_step();
00230 
00231       // If next sense entity in input list is not
00232       // next sense entity in this GroupingEntity...
00233     if (prev->next() != curr)
00234     {
00235       if (!curr->get_grouping_entity_ptr())
00236         curr->set_grouping_entity_ptr(this);
00237       else
00238       {
00239         if (lastSenseEntity == curr)
00240           lastSenseEntity = curr->previous();
00241         curr->gpe_remove();
00242       }
00243       curr->gpe_insert_after(prev);
00244     }
00245     
00246       // update lastSenseEntity if necessary...
00247     if (lastSenseEntity == prev)
00248       lastSenseEntity = curr;
00249       
00250       // iterate
00251     prev = curr;
00252   }
00253   
00254     // Disconnect any sense entities in this GroupingEntity
00255     // that were not in in the input list (they should now
00256     // be at the end of the list of sense entities in this)
00257     // and pass them back in the 'removed' list.
00258   CubitStatus result = CUBIT_SUCCESS;
00259   while (prev != lastSenseEntity)
00260   {
00261     removed.append(prev->next());
00262     if (!remove_sense_entity(prev->next()))
00263     {
00264       assert(0);
00265       result = CUBIT_FAILURE;
00266       prev = prev->next();
00267     }
00268   }
00269   
00270   return result;
00271 }
00272   
00273 
00274 //-------------------------------------------------------------------------
00275 // Purpose       : Invert
00276 //
00277 // Special Notes : 
00278 //
00279 // Creator       : Jason Kraftcheck
00280 //
00281 // Creation Date : 07/22/03
00282 //-------------------------------------------------------------------------
00283 void GroupingEntity::reverse_direction()
00284 {
00285   SenseEntity* ptr;
00286   if (!firstSenseEntity)
00287     return;
00288   
00289     // For each child sense entity
00290   for (ptr = firstSenseEntity; ptr; ptr = ptr->previous())
00291   {
00292       // change linked list pointers
00293     ptr->swap_gpe_list_ptrs();
00294       // change sense
00295     ptr->reverse_sense();
00296   }
00297   
00298     // Change first pointer the old last entity
00299     // (Preserves order as returnd by old DLIList rep and 
00300     //  makes this work to reverse a chain.)
00301   ptr = firstSenseEntity;
00302   firstSenseEntity = lastSenseEntity;
00303   lastSenseEntity = ptr;
00304 }
00305 
00306 //-------------------------------------------------------------------------
00307 // Purpose       : Get parent basic topology entity.
00308 //
00309 // Special Notes : 
00310 //
00311 // Creator       : Jason Kraftcheck
00312 //
00313 // Creation Date : 07/22/03
00314 //-------------------------------------------------------------------------
00315 int GroupingEntity::get_parents( DLIList<TopologyEntity*>* list ) const
00316 {
00317   if (!myParent)
00318     return 0;
00319   
00320   if (list)
00321     list->append(myParent);
00322   
00323   return 1;
00324 }
00325 
00326 //-------------------------------------------------------------------------
00327 // Purpose       : Get child sense entities
00328 //
00329 // Special Notes : 
00330 //
00331 // Creator       : Jason Kraftcheck
00332 //
00333 // Creation Date : 07/22/03
00334 //-------------------------------------------------------------------------
00335 int GroupingEntity::get_children( DLIList<TopologyEntity*>* list ) const
00336 {
00337   if (!firstSenseEntity)
00338     return 0;
00339   
00340   int count = 0;
00341   for (SenseEntity* ptr = firstSenseEntity; ptr; ptr = ptr->next() )
00342   {
00343     assert(ptr->get_grouping_entity_ptr() == this);
00344     if(list)
00345       list->append(ptr);
00346     count++;
00347   }
00348   
00349   return count;
00350 }
00351 
00352 // ********** END PUBLIC FUNCTIONS         **********
00353 
00354 // ********** BEGIN PROTECTED FUNCTIONS    **********
00355 
00356 //-------------------------------------------------------------------------
00357 // Purpose       : Remove a child sense entity
00358 //
00359 // Special Notes : 
00360 //
00361 // Creator       : Jason Kraftcheck
00362 //
00363 // Creation Date : 07/22/03
00364 //-------------------------------------------------------------------------
00365 CubitStatus GroupingEntity::remove_child_link( TopologyEntity* child_ptr )
00366 {
00367   SenseEntity* se = dynamic_cast<SenseEntity*>(child_ptr);
00368   if (!se)
00369     return CUBIT_FAILURE;
00370   
00371   return remove_sense_entity(se);
00372 }
00373 
00374 //-------------------------------------------------------------------------
00375 // Purpose       : Remove from all parent BasicTopologyEntities
00376 //
00377 // Special Notes : 
00378 //
00379 // Creator       : Jason Kraftcheck
00380 //
00381 // Creation Date : 07/22/03
00382 //-------------------------------------------------------------------------
00383 CubitStatus GroupingEntity::disconnect_all_parents( DLIList<TopologyEntity*>* list )
00384 {
00385   if (!myParent)
00386     return CUBIT_SUCCESS;
00387   if (list) 
00388     list->append(myParent);
00389   return myParent->remove_grouping_entity(this);
00390 }
00391 
00392 //-------------------------------------------------------------------------
00393 // Purpose       : Remove all child SenseEntitys
00394 //
00395 // Special Notes : 
00396 //
00397 // Creator       : Jason Kraftcheck
00398 //
00399 // Creation Date : 07/22/03
00400 //-------------------------------------------------------------------------
00401 CubitStatus GroupingEntity::disconnect_all_children( DLIList<TopologyEntity*>* list)
00402 {
00403   while (firstSenseEntity)
00404   {
00405     if (list)
00406       list->append(firstSenseEntity);
00407     if (!remove_sense_entity(firstSenseEntity))
00408       return CUBIT_FAILURE;
00409   }
00410   return CUBIT_SUCCESS;
00411 }
00412 
00413 //-------------------------------------------------------------------------
00414 // Purpose       : Functions to support ModelQueryEngine
00415 //
00416 // Special Notes : 
00417 //
00418 // Creator       : Jason Kraftcheck
00419 //
00420 // Creation Date : 07/24/03
00421 //-------------------------------------------------------------------------
00422 CubitBoolean GroupingEntity::query_append_parents( DLIList<TopologyEntity*>& list )
00423 {
00424   if (myParent && !ModelQueryEngine::instance()->encountered(myParent))
00425   {
00426     list.append(myParent);
00427     return CUBIT_TRUE;
00428   }
00429   
00430   return CUBIT_FALSE;
00431 }
00432 CubitBoolean GroupingEntity::query_append_children( DLIList<TopologyEntity*>& list )
00433 {
00434   ModelQueryEngine *const mqe = ModelQueryEngine::instance();
00435   CubitBoolean found_some = CUBIT_FALSE;
00436   
00437   if (!firstSenseEntity)
00438     return CUBIT_FALSE;
00439   
00440   for (SenseEntity* ptr = firstSenseEntity; ptr; ptr = ptr->next())
00441   {
00442     if (!mqe->encountered(ptr))
00443     {
00444       list.append(ptr);
00445       found_some = CUBIT_TRUE;
00446     }
00447   }
00448     
00449   return found_some;
00450 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines