cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : HiddenEntitySet.cpp 00003 // 00004 // Purpose : A class to hold a list of hidden entites and act as 00005 // their owner. 00006 // 00007 // Special Notes : 00008 // 00009 // Creator : Jason Kraftcheck 00010 // 00011 // Creation Date : 01/14/02 00012 //------------------------------------------------------------------------- 00013 00014 #include "VGDefines.h" 00015 #include "HiddenEntitySet.hpp" 00016 00017 #include "BodySM.hpp" 00018 #include "Lump.hpp" 00019 #include "ShellSM.hpp" 00020 #include "Surface.hpp" 00021 #include "LoopSM.hpp" 00022 #include "CoEdgeSM.hpp" 00023 #include "Curve.hpp" 00024 #include "Point.hpp" 00025 00026 // for debug output 00027 #include "CompositePoint.hpp" 00028 #include "CompositeCurve.hpp" 00029 #include "CompositeCoEdge.hpp" 00030 #include "CompositeSurface.hpp" 00031 #include "CubitMessage.hpp" 00032 00033 00034 HiddenEntitySet::~HiddenEntitySet() 00035 { 00036 std::vector<TopologyBridge*>::iterator iter; 00037 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00038 (*iter)->owner(0); 00039 00040 hiddenList.clear(); 00041 } 00042 00043 CubitStatus HiddenEntitySet::hide( TopologyBridge* bridge ) 00044 { 00045 if( bridge->owner() && !bridge->owner()->remove_bridge(bridge) ) 00046 return CUBIT_FAILURE; 00047 00048 bridge->owner( this ); 00049 00050 // It would be simpler to just add new hidden entities at the back of the list 00051 // but this code mimics the previous behavior of inserting new entities 00052 // after the first entity in the list. Changing this changes the ids of 00053 // geometry entities when a composite is removed. BWH - 11/09/05 00054 // 00055 // TODO - BWH - do we want to change the order now to make things simpler or come up 00056 // with a way to keep ids after removing composites 00057 // 00058 // TODO - BWH - the list functions in HiddenEntitySet are almost identical to the list functions in BridgeManager 00059 // the main difference is the order that entities are inserted. If we want to make the behavior consistent, maybe a TBList class 00060 // could be implemented to use in both places. 00061 00062 std::vector<TopologyBridge*>::iterator iter; 00063 iter = hiddenList.begin(); 00064 if (hiddenList.size() > 0) 00065 iter++; 00066 hiddenList.insert(iter, bridge); 00067 00068 return CUBIT_SUCCESS; 00069 } 00070 00071 CubitStatus HiddenEntitySet::restore( TopologyBridge* bridge ) 00072 { 00073 if( bridge->owner() != this ) 00074 return CUBIT_FAILURE; 00075 00076 std::vector<TopologyBridge*>::iterator iter; 00077 iter = std::find(hiddenList.begin(), hiddenList.end(), bridge); 00078 if (iter != hiddenList.end()) 00079 hiddenList.erase(iter); 00080 else 00081 return CUBIT_FAILURE; 00082 00083 bridge->owner( 0 ); 00084 00085 return CUBIT_SUCCESS; 00086 } 00087 00088 CubitStatus HiddenEntitySet::remove_bridge( TopologyBridge* bridge ) 00089 { 00090 return restore(bridge); 00091 } 00092 00093 CubitStatus HiddenEntitySet::swap_bridge( TopologyBridge* old_tb, 00094 TopologyBridge* new_tb, 00095 bool ) 00096 { 00097 if ( new_tb->owner() || !restore(old_tb) ) 00098 { 00099 assert(0); 00100 return CUBIT_FAILURE; 00101 } 00102 00103 return hide(new_tb); 00104 } 00105 00106 CubitStatus HiddenEntitySet::merge( HiddenEntitySet* other ) 00107 { 00108 std::vector<TopologyBridge*>::iterator iter; 00109 std::vector<TopologyBridge*> other_list; 00110 00111 // copy the list being merged so we can operate on the real list 00112 // without invalidating the iterator 00113 other_list = other->hiddenList; 00114 for (iter=other_list.begin(); iter!=other_list.end(); iter++ ) 00115 { 00116 other->restore( *iter ); 00117 hide( *iter ); 00118 } 00119 00120 return CUBIT_SUCCESS; 00121 } 00122 00123 00124 void HiddenEntitySet::hidden_surfaces( DLIList<Surface*>& result ) 00125 { 00126 std::vector<TopologyBridge*>::iterator iter; 00127 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00128 { 00129 if (Surface* ptr = dynamic_cast<Surface*>( *iter )) 00130 result.append(ptr); 00131 } 00132 } 00133 00134 void HiddenEntitySet::hidden_coedges( DLIList<CoEdgeSM*>& result ) 00135 { 00136 std::vector<TopologyBridge*>::iterator iter; 00137 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00138 { 00139 if (CoEdgeSM* ptr = dynamic_cast<CoEdgeSM*>( *iter )) 00140 result.append(ptr); 00141 } 00142 } 00143 00144 void HiddenEntitySet::hidden_curves( DLIList<Curve*>& result ) 00145 { 00146 std::vector<TopologyBridge*>::iterator iter; 00147 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00148 { 00149 if (Curve* ptr = dynamic_cast<Curve*>( *iter )) 00150 result.append(ptr); 00151 } 00152 } 00153 00154 void HiddenEntitySet::hidden_points( DLIList<TBPoint*>& result ) 00155 { 00156 std::vector<TopologyBridge*>::iterator iter; 00157 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00158 { 00159 if (TBPoint* ptr = dynamic_cast<TBPoint*>( *iter )) 00160 result.append(ptr); 00161 } 00162 } 00163 00164 void HiddenEntitySet::print_debug_info( const char* prefix ) const 00165 { 00166 if (!prefix) 00167 prefix = ""; 00168 00169 PRINT_INFO("%sHiddenEntitySet %p owned by %s %p\n", 00170 prefix, (void*)this, 00171 myOwner ? fix_type_name(typeid(*myOwner).name()) : "(null)", 00172 (void*)myOwner ); 00173 00174 char* new_prefix = new char[strlen(prefix)+3]; 00175 strcpy( new_prefix, prefix ); 00176 strcat( new_prefix, " "); 00177 00178 std::vector<TopologyBridge*>::const_iterator iter; 00179 for (iter=hiddenList.begin(); iter!=hiddenList.end(); iter++) 00180 { 00181 if( CompositePoint* cp = dynamic_cast<CompositePoint*>(*iter) ) 00182 cp->print_debug_info(new_prefix, true); 00183 else if( CompositeCurve* cc = dynamic_cast<CompositeCurve*>(*iter) ) 00184 cc->print_debug_info(new_prefix, true); 00185 else if( CompositeCoEdge* ce = dynamic_cast<CompositeCoEdge*>(*iter) ) 00186 ce->print_debug_info(new_prefix, true); 00187 else if( CompositeSurface* cs = dynamic_cast<CompositeSurface*>(*iter) ) 00188 cs->print_debug_info(new_prefix, true); 00189 else 00190 #ifdef TOPOLOGY_BRIDGE_IDS 00191 PRINT_INFO("%s%s %d\n", new_prefix, fix_type_name(typeid(*(*iter)).name()), (*iter)->get_id() ); 00192 #else 00193 PRINT_INFO("%s%s %p\n", new_prefix, fix_type_name(typeid(*(*iter)).name()), (void*)(*iter) ); 00194 #endif 00195 } 00196 delete [] new_prefix; 00197 } 00198 00199 void HiddenEntitySet::notify_reversed( TopologyBridge* ) 00200 {}