cgma
TDCAGE.cpp
Go to the documentation of this file.
00001 #include "TDCAGE.hpp"
00002 #include "RefGroup.hpp"
00003 #include "RefEntity.hpp"
00004 #include "DLIList.hpp"
00005 #include "CastTo.hpp"
00006 
00007 int TDCAGE::is_cage(const ToolData* td)
00008 {
00009   return (CAST_TO(const_cast<ToolData*>(td), TDCAGE) != NULL);
00010 }
00011 
00012 
00013 int TDCAGE::td_sequence_number(const RefGroup *group)
00014 {
00015     // go through the group list and get the sequence number;
00016     // return -1 if the group isn't in the list
00017 
00018   groupList.reset();
00019   sequenceList.reset();
00020   for (int i = groupList.size(); i > 0; i--) {
00021     if (group == groupList.get_and_step()) return sequenceList.get();
00022 
00023     else sequenceList.step();
00024   }
00025   
00026   return -1;
00027 }
00028 
00029 void TDCAGE::insert_entity(RefEntity *entity, const int seq_num,
00030                            RefGroup *into_group)
00031 {
00032     //- insert the entity into the group following the sequence number
00033     //- given
00034   TDCAGE *td_cage;
00035   CubitBoolean inserted = CUBIT_FALSE;
00036   DLIList<RefEntity*> copy_group_list;
00037   copy_group_list = into_group->entityList;
00038   
00039   into_group->entityList.last();
00040   for (int i = into_group->entityList.size(); i > 0; i--) {
00041     RefEntity *into_entity = into_group->entityList.get();
00042     td_cage = (TDCAGE *) into_entity->get_TD(&TDCAGE::is_cage);
00043     if (td_cage && td_cage->td_sequence_number(into_group) < seq_num) {
00044       if ( !copy_group_list.move_to(entity) )
00045         into_group->entityList.insert(entity);
00046       inserted = CUBIT_TRUE;
00047       break;
00048     }
00049     else into_group->entityList.back();
00050   }
00051   
00052     // if we got here and didn't insert, either the list is empty
00053     // or it isn't and our seq_num is less than all items; either
00054     // way, we insert at beginning
00055   if (inserted == CUBIT_FALSE){
00056       if ( !copy_group_list.move_to(entity) )
00057         into_group->entityList.insert_first(entity);
00058   }
00059 
00060     // now register the observable entity in the group
00061   into_group->register_observable(entity);
00062 
00063     // now, make sure the inserted entity has a td_cage and this group
00064     // and seq number are registered
00065   td_cage = (TDCAGE *) entity->get_TD(&TDCAGE::is_cage);
00066   if (!td_cage) {
00067     td_cage = new TDCAGE(-1);
00068     entity->add_TD(td_cage);
00069   }
00070   
00071   td_cage->insert_group(into_group, seq_num);
00072 }
00073 
00074 int TDCAGE::group_sequence_number(RefGroup *group, const RefEntity *entity)
00075 {
00076     //- return the sequence number of the given entity in the given group
00077 
00078     // built for speed; don't accumulate index, use loop counter for that
00079   group->entityList.reset();
00080   for (int i = group->entityList.size(); i > 0; i--) {
00081     if (group->entityList.get_and_step() == entity)
00082         // index in reverse direction, so subtract to get real index
00083       return group->entityList.size() - i;
00084   }
00085   
00086   return -1;
00087 }
00088 
00089 void TDCAGE::initialize_group_sequence_list(RefEntity *entity) 
00090 {
00091     //- get the groups owning entity and build the sequence lists
00092   DLIList<RefGroup*> ref_groups;
00093   RefGroup::get_groups_within(entity, ref_groups, CUBIT_FALSE);
00094 
00095   groupList.clean_out();
00096   sequenceList.clean_out();
00097   
00098   for (int i = ref_groups.size(); i > 0; i--) {
00099     RefGroup *ref_group = ref_groups.get_and_step();
00100     groupList.append(ref_group);
00101     sequenceList.append(group_sequence_number(ref_group, entity));
00102   }
00103 }
00104 
00105     
00106   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines