cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : CompositeLump.cpp 00003 // 00004 // Purpose : Combine Lumps 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Jason Kraftcheck 00009 // 00010 // Creation Date : 01/11/02 00011 //------------------------------------------------------------------------- 00012 00013 #include "CompositeLump.hpp" 00014 #include "CompositeShell.hpp" 00015 #include "CompositeBody.hpp" 00016 #include "VirtualQueryEngine.hpp" 00017 #include "CompositeEngine.hpp" 00018 00019 //------------------------------------------------------------------------- 00020 // Purpose : Public constructor - replace real Lump with Composite 00021 // 00022 // Special Notes : 00023 // 00024 // Creator : Jason Kraftcheck 00025 // 00026 // Creation Date : 07/20/02 00027 //------------------------------------------------------------------------- 00028 CompositeLump::CompositeLump( Lump* lump ) 00029 : myBody(0), nextLump(0), firstShell(0), hiddenSet(0) 00030 { 00031 assert( lump != NULL ); 00032 compGeom = new CompositeGeom(1); 00033 compGeom->append( lump, CUBIT_FORWARD ); 00034 if( lump->owner() ) 00035 lump->owner()->swap_bridge( lump, this, false ); 00036 lump->owner( this ); 00037 } 00038 00039 //------------------------------------------------------------------------- 00040 // Purpose : Internal constructor for splitting Composites 00041 // 00042 // Special Notes : 00043 // 00044 // Creator : Jason Kraftcheck 00045 // 00046 // Creation Date : 07/20/02 00047 //------------------------------------------------------------------------- 00048 CompositeLump::CompositeLump( CompositeGeom* geometry ) 00049 : myBody(0), 00050 nextLump(0), 00051 compGeom( geometry ), 00052 firstShell(0), 00053 hiddenSet(0) 00054 { 00055 assert( geometry != NULL ); 00056 for( int i = 0; i < compGeom->num_entities(); i++ ) 00057 { 00058 GeometryEntity* entity = compGeom->entity(i); 00059 assert( !entity->owner() ); 00060 entity->owner(this); 00061 } 00062 } 00063 00064 //------------------------------------------------------------------------- 00065 // Purpose : Destructor 00066 // 00067 // Special Notes : 00068 // 00069 // Creator : Jason Kraftcheck 00070 // 00071 // Creation Date : 07/20/02 00072 //------------------------------------------------------------------------- 00073 CompositeLump::~CompositeLump() 00074 { 00075 int i; 00076 assert( !myBody ); 00077 00078 while( firstShell ) 00079 remove( firstShell ); 00080 00081 for( i = 0; i < num_lumps(); i++ ) 00082 if( get_lump(i)->owner() == this ) 00083 get_lump(i)->owner(0); 00084 00085 delete hiddenSet; 00086 delete compGeom; 00087 } 00088 00089 CubitStatus CompositeLump::add( CompositeShell* shell ) 00090 { 00091 if( shell->myLump ) 00092 return CUBIT_FAILURE; 00093 00094 shell->lumpNext = firstShell; 00095 firstShell = shell; 00096 shell->myLump = this; 00097 return CUBIT_SUCCESS; 00098 } 00099 00100 CubitStatus CompositeLump::remove( CompositeShell* shell ) 00101 { 00102 if( shell->myLump != this ) 00103 return CUBIT_FAILURE; 00104 00105 if( firstShell == shell ) 00106 { 00107 firstShell = firstShell->lumpNext; 00108 } 00109 else 00110 { 00111 CompositeShell *prev = firstShell, *next = firstShell->lumpNext; 00112 while( next != shell ) 00113 { 00114 assert( next != NULL ); 00115 prev = next; 00116 next = next->lumpNext; 00117 } 00118 00119 prev->lumpNext = shell->lumpNext; 00120 } 00121 00122 shell->lumpNext = 0; 00123 shell->myLump = 0; 00124 00125 return CUBIT_SUCCESS; 00126 } 00127 00128 00129 CubitBox CompositeLump::bounding_box() const 00130 { return compGeom->bounding_box(); } 00131 00132 double CompositeLump::measure() 00133 { return compGeom->measure( compGeom->num_entities() -1 ); } 00134 00135 void CompositeLump::get_parents_virt( DLIList<TopologyBridge*>& parents ) 00136 { if( myBody ) parents.append( myBody ); } 00137 00138 void CompositeLump::get_children_virt( DLIList<TopologyBridge*>& children ) 00139 { 00140 for( CompositeShell* shell = firstShell; shell; shell = shell->lumpNext ) 00141 children.append( shell ); 00142 } 00143 00144 00145 //------------------------------------------------------------------------- 00146 // Purpose : Get CompositeEngine 00147 // 00148 // Special Notes : 00149 // 00150 // Creator : Jason Kraftcheck 00151 // 00152 // Creation Date : 01/11/02 00153 //------------------------------------------------------------------------- 00154 GeometryQueryEngine* CompositeLump::get_geometry_query_engine() const 00155 { return VirtualQueryEngine::instance(); } 00156 00157 00158 CubitStatus CompositeLump::add( Lump* lump ) 00159 { 00160 if( !lump->owner() && compGeom->append(lump,CUBIT_FORWARD) ) 00161 { 00162 lump->owner(this); 00163 return CUBIT_SUCCESS; 00164 } 00165 return CUBIT_FAILURE; 00166 } 00167 00168 CubitStatus CompositeLump::remove( Lump* lump ) 00169 { return remove_lump( index_of( lump ) ); } 00170 00171 CubitStatus CompositeLump::remove_lump( int index ) 00172 { 00173 if( index < 0 || index >= num_lumps() ) 00174 return CUBIT_FAILURE; 00175 00176 TopologyBridge* lump = compGeom->entity(index); 00177 if( compGeom->remove( index, false ) ) 00178 { 00179 if( lump->owner() == this ) 00180 lump->owner(0); 00181 return CUBIT_SUCCESS; 00182 } 00183 return CUBIT_FAILURE; 00184 } 00185 00186 CubitStatus CompositeLump::remove_bridge( TopologyBridge* bridge ) 00187 { 00188 int i = compGeom->index_of(bridge); 00189 if (i < 0) 00190 return CUBIT_FAILURE; 00191 00192 assert (bridge->owner() == this); 00193 bridge->owner(0); 00194 if (!compGeom->remove(i, true)) 00195 return CUBIT_FAILURE; 00196 00197 if (compGeom->num_entities() == 0) 00198 CompositeEngine::instance().notify_deactivated(this); 00199 00200 return CUBIT_SUCCESS; 00201 } 00202 00203 00204 CubitStatus CompositeLump::swap_bridge( TopologyBridge* old_tb, 00205 TopologyBridge* new_tb, 00206 bool ) 00207 { 00208 if( new_tb->owner() ) 00209 return CUBIT_FAILURE; 00210 00211 int index = compGeom->index_of( old_tb ); 00212 GeometryEntity* ge = dynamic_cast<GeometryEntity*>(new_tb); 00213 if( index >= 0 && ge != 0 ) 00214 { 00215 if( old_tb->owner() == this ) 00216 old_tb->owner(0); 00217 new_tb->owner(this); 00218 return compGeom->swap( index, ge ); 00219 } 00220 00221 return CUBIT_FAILURE; 00222 } 00223 00224 CubitBoolean CompositeLump::contains_bridge( TopologyBridge* bridge ) const 00225 { 00226 return compGeom->index_of(bridge) < 0 ? CUBIT_FALSE : CUBIT_TRUE; 00227 } 00228 00229 void CompositeLump::notify_reversed( TopologyBridge* ) 00230 { assert(0); } 00231 00232 00233 //------------------------------------------------------------------------- 00234 // Purpose : Attribute functions 00235 // 00236 // Special Notes : 00237 // 00238 // Creator : Jason Kraftcheck 00239 // 00240 // Creation Date : 01/11/02 00241 //------------------------------------------------------------------------- 00242 void CompositeLump::append_simple_attribute_virt( const CubitSimpleAttrib& csa ) 00243 { compGeom->add_attribute(csa); } 00244 void CompositeLump::remove_simple_attribute_virt( const CubitSimpleAttrib& csa ) 00245 { compGeom->rem_attribute(csa); } 00246 void CompositeLump::remove_all_simple_attribute_virt() 00247 { compGeom->rem_all_attributes(); } 00248 CubitStatus CompositeLump::get_simple_attribute( DLIList<CubitSimpleAttrib>& list ) 00249 { compGeom->get_attributes( list ); return CUBIT_SUCCESS; } 00250 CubitStatus CompositeLump::get_simple_attribute( 00251 const CubitString& name, DLIList<CubitSimpleAttrib>& attrib_list ) 00252 { 00253 compGeom->get_attributes( name.c_str(), attrib_list ); 00254 return CUBIT_SUCCESS; 00255 } 00256 00257 00258 //------------------------------------------------------------------------- 00259 // Purpose : Split this CompositeLump into two. 00260 // 00261 // Special Notes : 00262 // 00263 // Creator : Jason Kraftcheck 00264 // 00265 // Creation Date : 06/11/04 00266 //------------------------------------------------------------------------- 00267 CompositeLump* CompositeLump::split( VGArray<int>& indices_to_move ) 00268 { 00269 int i; 00270 00271 for( i = 0; i < indices_to_move.size(); i++ ) 00272 if( indices_to_move[i] < 0 || indices_to_move[i] >= num_lumps() ) 00273 return 0; 00274 00275 CompositeGeom* new_geom = compGeom->split( indices_to_move ); 00276 if( !new_geom ) 00277 return 0; 00278 00279 for( i = 0; i < new_geom->num_entities(); i++ ) 00280 new_geom->entity(i)->owner( 0 ); 00281 00282 return new CompositeLump( new_geom ); 00283 } 00284 00285 //------------------------------------------------------------------------- 00286 // Purpose : Combine composite volumes 00287 // 00288 // Special Notes : 00289 // 00290 // Creator : Jason Kraftcheck 00291 // 00292 // Creation Date : 06/11/04 00293 //------------------------------------------------------------------------- 00294 CubitStatus CompositeLump::combine( CompositeLump* dead_lump ) 00295 { 00296 int old_size = compGeom->num_entities(); 00297 compGeom->merge( *(dead_lump->compGeom) ); 00298 if( dead_lump->hiddenSet != 0 ) 00299 hidden_entities().merge( dead_lump->hiddenSet ); 00300 for( int i = old_size; i < compGeom->num_entities(); i++ ) 00301 { 00302 TopologyBridge* bridge = compGeom->entity(i); 00303 assert( bridge->owner() == dead_lump ); 00304 bridge->owner( this ); 00305 } 00306 00307 return CUBIT_SUCCESS; 00308 } 00309 00310 //------------------------------------------------------------------------- 00311 // Purpose : Debug output 00312 // 00313 // Special Notes : 00314 // 00315 // Creator : Jason Kraftcheck 00316 // 00317 // Creation Date : 09/16/04 00318 //------------------------------------------------------------------------- 00319 void CompositeLump::print_debug_info( const char* prefix, bool brief ) 00320 { 00321 if( prefix == 0 ) prefix = ""; 00322 CompositeShell* shell = 0; 00323 if (brief) 00324 { 00325 int count = 0; 00326 while ((shell = next_shell(shell)) != NULL ) ++count; 00327 PRINT_INFO( "%sCompositeLump %p : %d shells, %d lumps.\n", 00328 prefix, (void*)this, count, num_lumps() ); 00329 return; 00330 } 00331 00332 PRINT_INFO("%sCompositeLump %p:\n", prefix, (void*)this ); 00333 00334 char* new_prefix = new char[strlen(prefix)+3]; 00335 strcpy( new_prefix, prefix ); 00336 strcat( new_prefix, " " ); 00337 if (hiddenSet) hiddenSet->print_debug_info( new_prefix ); 00338 else PRINT_INFO("%sNo Hidden Entities.\n", new_prefix ); 00339 while ((shell = next_shell( shell )) != NULL ) 00340 shell->print_debug_info( new_prefix ); 00341 delete [] new_prefix; 00342 } 00343 00344 00345 void CompositeLump::get_hidden_surfaces( DLIList<Surface*>& surfs ) 00346 { 00347 if (hiddenSet) 00348 hiddenSet->hidden_surfaces( surfs ); 00349 } 00350 00351 CubitStatus CompositeLump::mass_properties( CubitVector ¢roid, double &volume ) 00352 { 00353 PRINT_ERROR("CompositeLump::mass_properties is not implemented\n"); 00354 centroid.set(0,0,0); 00355 volume = 0; 00356 return CUBIT_FAILURE; 00357 }