cgma
|
00001 #include "RefEntityFactory.hpp" 00002 #include "RefVertex.hpp" 00003 #include "RefEdge.hpp" 00004 #include "RefFace.hpp" 00005 #include "RefVolume.hpp" 00006 #include "Body.hpp" 00007 #include "RefGroup.hpp" 00008 #include "GeometryQueryTool.hpp" 00009 #include "DLIList.hpp" 00010 #include "AppUtil.hpp" 00011 #include "GeometryEvent.hpp" 00012 00013 static int sort_by_ascending_ids(CubitEntity*& a, CubitEntity*& b) 00014 { 00015 if( a->id() < b->id() ) 00016 return -1; 00017 else 00018 return 1; 00019 } 00020 00021 static int sort_by_ascending_ids(RefVertex*& a, RefVertex*& b) 00022 { 00023 if( a->id() < b->id() ) 00024 return -1; 00025 else 00026 return 1; 00027 } 00028 00029 static int sort_by_ascending_ids(RefVolume*& a, RefVolume*& b) 00030 { 00031 if( a->id() < b->id() ) 00032 return -1; 00033 else 00034 return 1; 00035 } 00036 00037 static int sort_by_ascending_ids(RefEdge*& a, RefEdge*& b) 00038 { 00039 if( a->id() < b->id() ) 00040 return -1; 00041 else 00042 return 1; 00043 } 00044 00045 static int sort_by_ascending_ids(RefFace*& a, RefFace*& b) 00046 { 00047 if( a->id() < b->id() ) 00048 return -1; 00049 else 00050 return 1; 00051 } 00052 00053 static int sort_by_ascending_ids(Body*& a, Body*& b) 00054 { 00055 if( a->id() < b->id() ) 00056 return -1; 00057 else 00058 return 1; 00059 } 00060 00061 static int sort_by_ascending_ids(RefGroup*& a, RefGroup*& b) 00062 { 00063 if( a->id() < b->id() ) 00064 return -1; 00065 else 00066 return 1; 00067 } 00068 00069 RefEntityFactory *RefEntityFactory::instance_ = NULL; 00070 00071 RefEntityFactory *RefEntityFactory::instance() 00072 { 00073 if (instance_ == NULL) { 00074 new RefEntityFactory(); 00075 } 00076 00077 return instance_; 00078 } 00079 00080 RefEntityFactory::RefEntityFactory(bool make_lists) 00081 { 00082 instance_ = this; 00083 00084 AppUtil::instance()->event_dispatcher().add_observer(this); 00085 00086 00087 if (make_lists) { 00088 refVertexList = new DLIList<RefVertex*>(); 00089 refEdgeList = new DLIList<RefEdge*>(); 00090 refFaceList = new DLIList<RefFace*>(); 00091 refGroupList = new DLIList<RefGroup*>(); 00092 refVolumeList = new DLIList<RefVolume*>(); 00093 bodyList = new DLIList<Body*>(); 00094 register_observer(this); 00095 } 00096 else { 00097 refVertexList = NULL; 00098 refEdgeList = NULL; 00099 refFaceList = NULL; 00100 refGroupList = NULL; 00101 refVolumeList = NULL; 00102 bodyList = NULL; 00103 } 00104 00105 refVertexListIsSorted = true; 00106 refEdgeListIsSorted = true; 00107 refFaceListIsSorted = true; 00108 refVolumeListIsSorted = true; 00109 bodyListIsSorted = true; 00110 refGroupListIsSorted = true; 00111 ManageListSorting = true; 00112 00113 reset_ids(); 00114 } 00115 00116 void RefEntityFactory::delete_instance() 00117 { 00118 if( NULL != instance_ ) 00119 { 00120 delete instance_; 00121 instance_ = NULL; 00122 } 00123 } 00124 00125 RefEntityFactory::~RefEntityFactory() 00126 { 00127 if (refVertexList != NULL) delete refVertexList; 00128 if (refEdgeList != NULL) delete refEdgeList; 00129 if (refFaceList != NULL) delete refFaceList; 00130 if (refGroupList != NULL) delete refGroupList; 00131 if (refVolumeList != NULL) delete refVolumeList; 00132 if (bodyList != NULL) delete bodyList; 00133 unregister_observer(this); 00134 instance_ = NULL; 00135 } 00136 00137 RefVertex *RefEntityFactory::construct_RefVertex(TBPoint *point) 00138 { 00139 RefVertex *temp = new RefVertex(point); 00140 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00141 return temp; 00142 } 00143 00144 RefEdge *RefEntityFactory::construct_RefEdge(Curve *curve) 00145 { 00146 RefEdge *temp = new RefEdge(curve); 00147 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00148 return temp; 00149 } 00150 00151 RefFace *RefEntityFactory::construct_RefFace(Surface *surface) 00152 { 00153 RefFace *temp = new RefFace(surface); 00154 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00155 return temp; 00156 } 00157 00158 RefVolume *RefEntityFactory::construct_RefVolume(Lump *lump) 00159 { 00160 RefVolume *temp = new RefVolume(lump); 00161 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00162 return temp; 00163 } 00164 00165 Body *RefEntityFactory::construct_Body(BodySM *body_sm) 00166 { 00167 Body *temp = new Body(body_sm); 00168 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00169 return temp; 00170 } 00171 00172 RefGroup *RefEntityFactory::construct_RefGroup(const char* name) 00173 { 00174 RefGroup *temp = new RefGroup(name); 00175 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00176 return temp; 00177 } 00178 00179 RefGroup *RefEntityFactory::construct_RefGroup (DLIList<RefEntity*>& entity_list) 00180 { 00181 RefGroup *temp = new RefGroup(entity_list); 00182 AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED, temp)); 00183 return temp; 00184 } 00185 00186 CubitStatus RefEntityFactory::ref_entity_list( char const* keyword, 00187 DLIList<RefEntity*> &entity_list, 00188 const CubitBoolean print_errors ) 00189 { 00190 if ( !strcmp( keyword, "body" ) || !strcmp( keyword, "Body" )) { 00191 CAST_LIST_TO_PARENT((*bodyList), entity_list) ; 00192 } 00193 else if ( !strcmp( keyword, "curve" ) || !strcmp( keyword, "Curve" ) ) { 00194 CAST_LIST_TO_PARENT((*refEdgeList), entity_list) ; 00195 } 00196 else if ( !strcmp( keyword, "volume" ) || !strcmp( keyword, "Volume" ) ) { 00197 CAST_LIST_TO_PARENT((*refVolumeList), entity_list) ; 00198 } 00199 else if ( !strcmp( keyword, "vertex" ) || !strcmp( keyword, "Vertex" ) ) { 00200 CAST_LIST_TO_PARENT((*refVertexList), entity_list) ; 00201 } 00202 else if ( !strcmp( keyword, "surface" ) || !strcmp( keyword, "Surface" ) ) { 00203 CAST_LIST_TO_PARENT((*refFaceList), entity_list) ; 00204 } 00205 else if ( !strcmp( keyword, "group" ) || !strcmp( keyword, "Group" ) ) { 00206 CAST_LIST_TO_PARENT((*refGroupList), entity_list) ; 00207 } 00208 else 00209 { 00210 if (print_errors) 00211 PRINT_ERROR("Invalid list type for the ref_entity_list " 00212 "function: %s\n", keyword); 00213 return CUBIT_FAILURE; 00214 } 00215 00216 return CUBIT_SUCCESS; 00217 } 00218 00219 void RefEntityFactory::add(RefEntity* ref_entity) 00220 { 00221 assert(ref_entity != 0); 00222 00223 RefGroup *group; 00224 RefVolume *volume; 00225 RefFace *face; 00226 RefEdge *edge; 00227 RefVertex *vertex; 00228 Body *body; 00229 00230 if ( (group = CAST_TO(ref_entity, RefGroup)) != NULL ) { 00231 add(group); 00232 } 00233 else if ( (volume = CAST_TO(ref_entity, RefVolume)) != NULL ) { 00234 add(volume); 00235 } 00236 else if ( (face = CAST_TO(ref_entity, RefFace)) != NULL ) { 00237 add(face); 00238 } 00239 else if ( (edge = CAST_TO(ref_entity, RefEdge)) != NULL ) { 00240 add(edge); 00241 } 00242 else if ( (vertex = CAST_TO(ref_entity, RefVertex)) != NULL ) { 00243 add(vertex); 00244 } 00245 else if ( (body = CAST_TO(ref_entity, Body)) != NULL ) { 00246 add(body); 00247 } 00248 } 00249 00250 void RefEntityFactory::add(RefGroup* refGPtr) 00251 { 00252 assert(!refGroupList->is_in_list(refGPtr)); 00253 if(refGroupList->size() > 0) 00254 { 00255 refGroupList->last(); 00256 if(ManageListSorting && refGPtr->id() < refGroupList->get()->id()) 00257 refGroupListIsSorted = false; 00258 } 00259 refGroupList->append(refGPtr); 00260 if (refGPtr->id() > maxRefGroupId) maxRefGroupId = refGPtr->id(); 00261 } 00262 00263 void RefEntityFactory::add(Body* bodyPtr) 00264 { 00265 assert(!bodyList->is_in_list(bodyPtr)); 00266 if(bodyList->size() > 0) 00267 { 00268 bodyList->last(); 00269 if(ManageListSorting && bodyPtr->id() < bodyList->get()->id()) 00270 bodyListIsSorted = false; 00271 } 00272 bodyList->append(bodyPtr); 00273 if (bodyPtr->id() > maxBodyId) maxBodyId = bodyPtr->id(); 00274 } 00275 00276 void RefEntityFactory::add(RefVolume* refVPtr) 00277 { 00278 assert(!refVolumeList->is_in_list(refVPtr)); 00279 if(refVolumeList->size() > 0) 00280 { 00281 refVolumeList->last(); 00282 if(ManageListSorting && refVPtr->id() < refVolumeList->get()->id()) 00283 refVolumeListIsSorted = false; 00284 } 00285 refVolumeList->append(refVPtr); 00286 if (refVPtr->id() > maxRefVolumeId) 00287 maxRefVolumeId = refVPtr->id(); 00288 } 00289 00290 void RefEntityFactory::add(RefFace* refFPtr) 00291 { 00292 assert(!refFaceList->is_in_list(refFPtr)); 00293 if(refFaceList->size() > 0) 00294 { 00295 refFaceList->last(); 00296 if(ManageListSorting && refFPtr->id() < refFaceList->get()->id()) 00297 refFaceListIsSorted = false; 00298 } 00299 refFaceList->append(refFPtr); 00300 if (refFPtr->entityId > maxRefFaceId) 00301 maxRefFaceId = refFPtr->entityId; 00302 } 00303 00304 void RefEntityFactory::add(RefEdge* refEPtr) 00305 { 00306 assert(!refEdgeList->is_in_list(refEPtr)); 00307 if(refEdgeList->size() > 0) 00308 { 00309 refEdgeList->last(); 00310 if(ManageListSorting && refEPtr->id() < refEdgeList->get()->id()) 00311 refEdgeListIsSorted = false; 00312 } 00313 refEdgeList->append(refEPtr); 00314 if (refEPtr->id() > maxRefEdgeId) 00315 maxRefEdgeId = refEPtr->id(); 00316 } 00317 00318 void RefEntityFactory::add(RefVertex* refVPtr) 00319 { 00320 assert(!refVertexList->is_in_list(refVPtr)); 00321 if(refVertexList->size() > 0) 00322 { 00323 refVertexList->last(); 00324 if(ManageListSorting && refVPtr->id() < refVertexList->get()->id()) 00325 refVertexListIsSorted = false; 00326 } 00327 refVertexList->append(refVPtr); 00328 if (refVPtr->id() > maxRefVertexId) 00329 maxRefVertexId = refVPtr->id(); 00330 } 00331 00332 00333 void RefEntityFactory::remove(RefEntity* ref_entity) 00334 { 00335 assert(ref_entity != 0); 00336 00337 RefGroup *group; 00338 RefVolume *volume; 00339 RefFace *face; 00340 RefEdge *edge; 00341 RefVertex *vertex; 00342 Body *body; 00343 00344 if ( (group = CAST_TO(ref_entity, RefGroup)) != NULL ) { 00345 remove(group); 00346 } 00347 else if ( (volume = CAST_TO(ref_entity, RefVolume)) != NULL ) { 00348 remove(volume); 00349 } 00350 else if ( (face = CAST_TO(ref_entity, RefFace)) != NULL ) { 00351 remove(face); 00352 } 00353 else if ( (edge = CAST_TO(ref_entity, RefEdge)) != NULL ) { 00354 remove(edge); 00355 } 00356 else if ( (vertex = CAST_TO(ref_entity, RefVertex)) != NULL ) { 00357 remove(vertex); 00358 } 00359 else if ( (body = CAST_TO(ref_entity, Body)) != NULL ) { 00360 remove(body); 00361 } 00362 } 00363 00364 void RefEntityFactory::remove (RefVertex *ref_vertex_ptr) 00365 { 00366 if (!refVertexList) return; 00367 00368 if (ref_vertex_ptr != NULL) 00369 { 00370 if (refVertexList->move_to ( ref_vertex_ptr )) 00371 refVertexList->remove (); 00372 else assert(0); 00373 } 00374 } 00375 00376 void RefEntityFactory::remove (RefEdge *ref_edge_ptr) 00377 { 00378 if (!refEdgeList) return; 00379 00380 if (ref_edge_ptr != NULL) 00381 { 00382 if (refEdgeList->move_to ( ref_edge_ptr )) 00383 refEdgeList->remove (); 00384 else assert(0); 00385 } 00386 } 00387 00388 void RefEntityFactory::remove (RefFace *ref_face_ptr) 00389 { 00390 if (!refFaceList) return; 00391 00392 if (ref_face_ptr != NULL) 00393 { 00394 if (refFaceList->move_to ( ref_face_ptr )) 00395 refFaceList->remove (); 00396 else assert(0); 00397 } 00398 } 00399 00400 void RefEntityFactory::remove (RefVolume *ref_volume_ptr) 00401 { 00402 if (!refVolumeList) return; 00403 00404 if (ref_volume_ptr != NULL) 00405 { 00406 if (refVolumeList->move_to ( ref_volume_ptr )) 00407 refVolumeList->remove (); 00408 else assert(0); 00409 } 00410 } 00411 00412 void RefEntityFactory::remove (RefGroup *ref_group_ptr) 00413 { 00414 if (!refGroupList) return; 00415 00416 if (ref_group_ptr != NULL) 00417 { 00418 if (refGroupList->move_to ( ref_group_ptr )) 00419 refGroupList->remove (); 00420 else assert(0); 00421 } 00422 } 00423 00424 void RefEntityFactory::remove (Body *body_ptr) 00425 { 00426 if (!bodyList) return; 00427 00428 if (body_ptr != NULL) 00429 { 00430 if (bodyList->move_to ( body_ptr )) 00431 bodyList->remove (); 00432 else assert(0); 00433 } 00434 } 00435 00436 void RefEntityFactory::bodies(DLIList<Body*> &bodies) 00437 { 00438 bodies = *bodyList; 00439 } 00440 00441 void RefEntityFactory::ref_volumes(DLIList<RefVolume*> &ref_volumes) 00442 { 00443 ref_volumes = *refVolumeList; 00444 } 00445 00446 void RefEntityFactory::ref_groups(DLIList<RefGroup*> &ref_groups) 00447 { 00448 ref_groups = *refGroupList; 00449 } 00450 00451 void RefEntityFactory::ref_faces(DLIList<RefFace*> &ref_faces) 00452 { 00453 ref_faces = *refFaceList; 00454 } 00455 00456 void RefEntityFactory::ref_edges(DLIList<RefEdge*> &ref_edges) 00457 { 00458 ref_edges = *refEdgeList; 00459 } 00460 00461 void RefEntityFactory::ref_vertices(DLIList<RefVertex*> &ref_vertices) 00462 { 00463 ref_vertices = *refVertexList; 00464 } 00465 00466 #ifdef PROE 00467 void RefEntityFactory::ref_parts(DLIList<RefPart*> &ref_parts) 00468 { 00469 ref_parts = *refPartList; 00470 } 00471 00472 void RefEntityFactory::ref_assemblies(DLIList<RefAssembly*> &ref_assemblies) 00473 { 00474 ref_assemblies = *refAssemblyList; 00475 } 00476 #endif 00477 00478 int RefEntityFactory::num_bodies() const {return bodyList->size();} 00479 int RefEntityFactory::num_ref_volumes() const {return refVolumeList->size();} 00480 int RefEntityFactory::num_ref_groups() const {return refGroupList->size();} 00481 int RefEntityFactory::num_ref_faces() const {return refFaceList->size();} 00482 int RefEntityFactory::num_ref_edges() const {return refEdgeList->size();} 00483 int RefEntityFactory::num_ref_vertices() const {return refVertexList->size();} 00484 00485 RefEntity* RefEntityFactory::get_ref_entity(const char *type_string, int id) 00486 { 00487 // Call the right function, cast it. 00488 switch( toupper(*type_string) ) 00489 { 00490 case 'B': 00491 if( !strcmp(type_string+1,"ody") ) 00492 return get_body(id); 00493 break; 00494 case 'V': 00495 if( !strcmp(type_string+1,"olume" ) ) 00496 return get_ref_volume(id); 00497 else if(!strcmp(type_string+1,"ertex") ) 00498 return get_ref_vertex(id); 00499 break; 00500 case 'S': 00501 if( !strcmp(type_string+1,"urface") ) 00502 return get_ref_face(id); 00503 break; 00504 case 'C': 00505 if( !strcmp(type_string+1,"urve") ) 00506 return get_ref_edge(id); 00507 break; 00508 case 'G': 00509 if( !strcmp(type_string+1,"roup") ) 00510 return get_ref_group(id); 00511 break; 00512 } 00513 00514 PRINT_ERROR("Invalid list type for the get_ref_entity " 00515 "function: %s\n", type_string); 00516 return NULL; 00517 } 00518 //_________ Add Code by DZ of Cat, 3/17/99 11:24:22 AM _________ 00519 RefEntity* RefEntityFactory::get_ref_entity (const std::type_info& type, int id) 00520 { 00521 // Call the right function, cast it. 00522 if( type == typeid(RefGroup) ) 00523 return CAST_TO(get_ref_group(id), RefEntity); 00524 else if( type == typeid(Body) ) 00525 return CAST_TO(get_body(id), RefEntity); 00526 else if( type == typeid(RefVolume) ) 00527 return CAST_TO(get_ref_volume(id), RefEntity); 00528 else if( type == typeid(RefFace) ) 00529 return CAST_TO(get_ref_face(id), RefEntity); 00530 else if( type == typeid(RefEdge) ) 00531 return CAST_TO(get_ref_edge(id), RefEntity); 00532 else if( type == typeid(RefVertex) ) 00533 return CAST_TO(get_ref_vertex(id), RefEntity); 00534 00535 return NULL; 00536 } 00537 //_________ Code End by DZ of Cat, 3/17/99 11:24:22 AM _________ 00538 00539 Body* RefEntityFactory::get_body (int id) 00540 { 00541 if (!bodyList->size()) 00542 return NULL; 00543 00544 // Make sure the list is sorted for the binary search. 00545 if(ManageListSorting && !bodyListIsSorted) 00546 { 00547 bodyList->sort(sort_by_ascending_ids); 00548 bodyListIsSorted = true; 00549 } 00550 00551 // Do a binary search on the sorted list. We are making the assumption 00552 // here that there are no NULL entries in the list. 00553 bool found = false; 00554 int left_index = 0; 00555 int right_index = bodyList->size()-1; 00556 int mid_index = (left_index + right_index)/2; 00557 int mid_id = ((*bodyList)[mid_index])->id(); 00558 00559 while(!found && (right_index-left_index) > 1) 00560 { 00561 if(mid_id == id) 00562 found = true; 00563 else 00564 { 00565 if(mid_id > id) 00566 right_index = mid_index; 00567 else 00568 left_index = mid_index; 00569 mid_index = (left_index + right_index)/2; 00570 mid_id = ((*bodyList)[mid_index])->id(); 00571 } 00572 } 00573 00574 if(!found) 00575 { 00576 if(((*bodyList)[left_index])->id() == id) 00577 return ((*bodyList)[left_index]); 00578 else if(((*bodyList)[right_index])->id() == id) 00579 return ((*bodyList)[right_index]); 00580 } 00581 else 00582 return ((*bodyList)[mid_index]); 00583 00584 return NULL ; 00585 } 00586 00587 RefGroup* RefEntityFactory::get_ref_group (int id) 00588 { 00589 if (!refGroupList->size()) 00590 return NULL; 00591 00592 // Make sure the list is sorted for the binary search. 00593 if(ManageListSorting && !refGroupListIsSorted) 00594 { 00595 refGroupList->sort(sort_by_ascending_ids); 00596 refGroupListIsSorted = true; 00597 } 00598 00599 // Do a binary search on the sorted list. We are making the assumption 00600 // here that there are no NULL entries in the list. 00601 bool found = false; 00602 int left_index = 0; 00603 int right_index = refGroupList->size()-1; 00604 int mid_index = (left_index + right_index)/2; 00605 int mid_id = ((*refGroupList)[mid_index])->id(); 00606 00607 while(!found && (right_index-left_index) > 1) 00608 { 00609 if(mid_id == id) 00610 found = true; 00611 else 00612 { 00613 if(mid_id > id) 00614 right_index = mid_index; 00615 else 00616 left_index = mid_index; 00617 mid_index = (left_index + right_index)/2; 00618 mid_id = ((*refGroupList)[mid_index])->id(); 00619 } 00620 } 00621 00622 if(!found) 00623 { 00624 if(((*refGroupList)[left_index])->id() == id) 00625 return ((*refGroupList)[left_index]); 00626 else if(((*refGroupList)[right_index])->id() == id) 00627 return ((*refGroupList)[right_index]); 00628 } 00629 else 00630 return ((*refGroupList)[mid_index]); 00631 00632 return NULL ; 00633 } 00634 00635 RefVolume* RefEntityFactory::get_ref_volume (int id) 00636 { 00637 if (!refVolumeList->size()) 00638 return NULL; 00639 00640 // Make sure the list is sorted for the binary search. 00641 if(ManageListSorting && !refVolumeListIsSorted) 00642 { 00643 refVolumeList->sort(sort_by_ascending_ids); 00644 refVolumeListIsSorted = true; 00645 } 00646 00647 // Do a binary search on the sorted list. We are making the assumption 00648 // here that there are no NULL entries in the list. 00649 bool found = false; 00650 int left_index = 0; 00651 int right_index = refVolumeList->size()-1; 00652 int mid_index = (left_index + right_index)/2; 00653 int mid_id = ((*refVolumeList)[mid_index])->id(); 00654 00655 while(!found && (right_index-left_index) > 1) 00656 { 00657 if(mid_id == id) 00658 found = true; 00659 else 00660 { 00661 if(mid_id > id) 00662 right_index = mid_index; 00663 else 00664 left_index = mid_index; 00665 mid_index = (left_index + right_index)/2; 00666 mid_id = ((*refVolumeList)[mid_index])->id(); 00667 } 00668 } 00669 00670 if(!found) 00671 { 00672 if(((*refVolumeList)[left_index])->id() == id) 00673 return ((*refVolumeList)[left_index]); 00674 else if(((*refVolumeList)[right_index])->id() == id) 00675 return ((*refVolumeList)[right_index]); 00676 } 00677 else 00678 return ((*refVolumeList)[mid_index]); 00679 00680 return NULL ; 00681 } 00682 00683 RefFace* RefEntityFactory::get_ref_face (int id) 00684 { 00685 if (!refFaceList->size()) 00686 return NULL; 00687 00688 // Make sure the list is sorted for the binary search. 00689 if(ManageListSorting && !refFaceListIsSorted) 00690 { 00691 refFaceList->sort(sort_by_ascending_ids); 00692 refFaceListIsSorted = true; 00693 } 00694 00695 // Do a binary search on the sorted list. We are making the assumption 00696 // here that there are no NULL entries in the list. 00697 bool found = false; 00698 int left_index = 0; 00699 int right_index = refFaceList->size()-1; 00700 int mid_index = (left_index + right_index)/2; 00701 int mid_id = ((*refFaceList)[mid_index])->id(); 00702 00703 while(!found && (right_index-left_index) > 1) 00704 { 00705 if(mid_id == id) 00706 found = true; 00707 else 00708 { 00709 if(mid_id > id) 00710 right_index = mid_index; 00711 else 00712 left_index = mid_index; 00713 mid_index = (left_index + right_index)/2; 00714 mid_id = ((*refFaceList)[mid_index])->id(); 00715 } 00716 } 00717 00718 if(!found) 00719 { 00720 if(((*refFaceList)[left_index])->id() == id) 00721 return ((*refFaceList)[left_index]); 00722 else if(((*refFaceList)[right_index])->id() == id) 00723 return ((*refFaceList)[right_index]); 00724 } 00725 else 00726 return ((*refFaceList)[mid_index]); 00727 00728 return NULL ; 00729 } 00730 00731 RefEdge* RefEntityFactory::get_ref_edge (int id) 00732 { 00733 if (!refEdgeList->size()) 00734 return NULL; 00735 00736 // Make sure the list is sorted for the binary search. 00737 if(ManageListSorting && !refEdgeListIsSorted) 00738 { 00739 refEdgeList->sort(sort_by_ascending_ids); 00740 refEdgeListIsSorted = true; 00741 } 00742 00743 // Do a binary search on the sorted list. We are making the assumption 00744 // here that there are no NULL entries in the list. 00745 bool found = false; 00746 int left_index = 0; 00747 int right_index = refEdgeList->size()-1; 00748 int mid_index = (left_index + right_index)/2; 00749 int mid_id = ((*refEdgeList)[mid_index])->id(); 00750 00751 while(!found && (right_index-left_index) > 1) 00752 { 00753 if(mid_id == id) 00754 found = true; 00755 else 00756 { 00757 if(mid_id > id) 00758 right_index = mid_index; 00759 else 00760 left_index = mid_index; 00761 mid_index = (left_index + right_index)/2; 00762 mid_id = ((*refEdgeList)[mid_index])->id(); 00763 } 00764 } 00765 00766 if(!found) 00767 { 00768 if(((*refEdgeList)[left_index])->id() == id) 00769 return ((*refEdgeList)[left_index]); 00770 else if(((*refEdgeList)[right_index])->id() == id) 00771 return ((*refEdgeList)[right_index]); 00772 } 00773 else 00774 return ((*refEdgeList)[mid_index]); 00775 00776 return NULL ; 00777 } 00778 00779 RefVertex* RefEntityFactory::get_ref_vertex (int id) 00780 { 00781 if (!refVertexList->size()) 00782 return NULL; 00783 00784 // Make sure the list is sorted for the binary search. 00785 if(ManageListSorting && !refVertexListIsSorted) 00786 { 00787 refVertexList->sort(sort_by_ascending_ids); 00788 refVertexListIsSorted = true; 00789 } 00790 00791 // Do a binary search on the sorted list. We are making the assumption 00792 // here that there are no NULL entries in the list. 00793 bool found = false; 00794 int left_index = 0; 00795 int right_index = refVertexList->size()-1; 00796 int mid_index = (left_index + right_index)/2; 00797 int mid_id = ((*refVertexList)[mid_index])->id(); 00798 00799 while(!found && (right_index-left_index) > 1) 00800 { 00801 if(mid_id == id) 00802 found = true; 00803 else 00804 { 00805 if(mid_id > id) 00806 right_index = mid_index; 00807 else 00808 left_index = mid_index; 00809 mid_index = (left_index + right_index)/2; 00810 mid_id = ((*refVertexList)[mid_index])->id(); 00811 } 00812 } 00813 00814 if(!found) 00815 { 00816 if(((*refVertexList)[left_index])->id() == id) 00817 return ((*refVertexList)[left_index]); 00818 else if(((*refVertexList)[right_index])->id() == id) 00819 return ((*refVertexList)[right_index]); 00820 } 00821 else 00822 return ((*refVertexList)[mid_index]); 00823 00824 return NULL ; 00825 } 00826 00827 //* Methods: next*Id 00828 //** Increments the maximum object ID and returns this value. 00829 //== 00830 int RefEntityFactory::next_body_id () 00831 { 00832 return ++maxBodyId; 00833 } 00834 00835 int RefEntityFactory::next_ref_group_id () 00836 { 00837 return ++maxRefGroupId; 00838 } 00839 00840 int RefEntityFactory::next_ref_volume_id () 00841 { 00842 return ++maxRefVolumeId; 00843 } 00844 00845 int RefEntityFactory::next_ref_face_id () 00846 { 00847 return ++maxRefFaceId; 00848 } 00849 00850 int RefEntityFactory::next_ref_edge_id () 00851 { 00852 return ++maxRefEdgeId; 00853 } 00854 00855 int RefEntityFactory::next_ref_vertex_id () 00856 { 00857 return ++maxRefVertexId; 00858 } 00859 00860 #ifdef PROE 00861 int RefEntityFactory::next_ref_assembly_id () 00862 { 00863 return ++maxRefAssemblyId; 00864 } 00865 00866 int RefEntityFactory::next_ref_part_id () 00867 { 00868 return ++maxRefPartId; 00869 } 00870 #endif 00871 00872 Body *RefEntityFactory::get_first_body() 00873 { 00874 bodyList->reset(); 00875 return bodyList->size() ? bodyList->get() : 0; 00876 } 00877 00878 RefVolume *RefEntityFactory::get_first_ref_volume() 00879 { 00880 refVolumeList->reset(); 00881 return refVolumeList->size() ? refVolumeList->get() : 0; 00882 } 00883 00884 RefGroup *RefEntityFactory::get_first_ref_group() 00885 { 00886 refGroupList->reset(); 00887 return refGroupList->size() ? refGroupList->get() : 0; 00888 } 00889 00890 RefFace *RefEntityFactory::get_first_ref_face() 00891 { 00892 refFaceList->reset(); 00893 return refFaceList->size() ? refFaceList->get() : 0; 00894 } 00895 00896 RefEdge *RefEntityFactory::get_first_ref_edge() 00897 { 00898 refEdgeList->reset(); 00899 return refEdgeList->size() ? refEdgeList->get() : 0; 00900 } 00901 00902 RefVertex *RefEntityFactory::get_first_ref_vertex() 00903 { 00904 refVertexList->reset(); 00905 return refVertexList->size() ? refVertexList->get() : 0; 00906 } 00907 00908 00909 Body *RefEntityFactory::get_next_body() 00910 {return bodyList->size() ? bodyList->step_and_get() : 0;} 00911 00912 RefVolume *RefEntityFactory::get_next_ref_volume() 00913 {return refVolumeList->size() ? refVolumeList->step_and_get() : 0;} 00914 00915 RefGroup *RefEntityFactory::get_next_ref_group() 00916 {return refGroupList->size() ? refGroupList->step_and_get() : 0;} 00917 00918 RefFace *RefEntityFactory::get_next_ref_face() 00919 {return refFaceList->size() ? refFaceList->step_and_get() : 0;} 00920 00921 RefEdge *RefEntityFactory::get_next_ref_edge() 00922 {return refEdgeList->size() ? refEdgeList->step_and_get() : 0;} 00923 00924 RefVertex *RefEntityFactory::get_next_ref_vertex() 00925 {return refVertexList->size() ? refVertexList->step_and_get() : 0;} 00926 00927 Body *RefEntityFactory::get_last_body() 00928 { 00929 bodyList->last(); 00930 return bodyList->size() ? bodyList->get() : 0; 00931 } 00932 00933 RefVolume *RefEntityFactory::get_last_ref_volume() 00934 { 00935 refVolumeList->last(); 00936 return refVolumeList->size() ? refVolumeList->get() : 0; 00937 } 00938 00939 RefGroup *RefEntityFactory::get_last_ref_group() 00940 { 00941 refGroupList->last(); 00942 return refGroupList->size() ? refGroupList->get() : 0; 00943 } 00944 00945 RefFace *RefEntityFactory::get_last_ref_face() 00946 { 00947 refFaceList->last(); 00948 return refFaceList->size() ? refFaceList->get() : 0; 00949 } 00950 00951 RefEdge *RefEntityFactory::get_last_ref_edge() 00952 { 00953 refEdgeList->last(); 00954 return refEdgeList->size() ? refEdgeList->get() : 0; 00955 } 00956 00957 RefVertex *RefEntityFactory::get_last_ref_vertex() 00958 { 00959 refVertexList->last(); 00960 return refVertexList->size() ? refVertexList->get() : 0; 00961 } 00962 00963 void RefEntityFactory::incorporate_id (RefEntity *ref_ent) 00964 { 00965 if (ref_ent) 00966 { 00967 //________ Change Code by DZ of Cat, 3/17/99 10:47:39 AM ________ 00968 int max_ent_id = 0; 00969 00970 max_ent_id = ref_ent->id(); 00971 // Do nothing with groups 00972 if( CAST_TO( ref_ent, RefGroup ) ) { 00973 if (maxRefGroupId < max_ent_id) 00974 maxRefGroupId = max_ent_id; 00975 } 00976 else if( CAST_TO( ref_ent, Body ) ) 00977 { 00978 if (maxBodyId < max_ent_id) 00979 maxBodyId = max_ent_id; 00980 } 00981 else if( CAST_TO( ref_ent, RefVolume ) ) 00982 { 00983 if (maxRefVolumeId < max_ent_id) 00984 maxRefVolumeId = max_ent_id; 00985 } 00986 else if( CAST_TO( ref_ent, RefFace ) ) 00987 { 00988 if (maxRefFaceId < max_ent_id) 00989 maxRefFaceId = max_ent_id; 00990 } 00991 else if( CAST_TO( ref_ent, RefEdge ) ) 00992 { 00993 if (maxRefEdgeId < max_ent_id) 00994 maxRefEdgeId = max_ent_id; 00995 } 00996 else if( CAST_TO( ref_ent, RefVertex ) ) 00997 { 00998 if (maxRefVertexId < max_ent_id) 00999 maxRefVertexId = max_ent_id; 01000 } 01001 //________ Change End by DZ of Cat, 3/17/99 10:47:39 AM ________ 01002 } 01003 } 01004 01005 int RefEntityFactory::maximum_id(const char *entity_type) 01006 { 01007 if (strcmp("body", entity_type) == 0) 01008 return maxBodyId; 01009 else if (strcmp("curve", entity_type) == 0) 01010 return maxRefEdgeId; 01011 else if (strcmp("group", entity_type) == 0) 01012 return maxRefGroupId; 01013 else if (strcmp("volume", entity_type) == 0) 01014 return maxRefVolumeId; 01015 else if (strcmp("vertex", entity_type) == 0) 01016 return maxRefVertexId; 01017 else if (strcmp("surface", entity_type) == 0) 01018 return maxRefFaceId; 01019 else { 01020 PRINT_ERROR("Unrecognized entity_type: '%s'\n", entity_type); 01021 return 0; 01022 } 01023 } 01024 01025 void RefEntityFactory::maximum_id (const std::type_info& type, int max_id) 01026 { 01027 if( type == typeid(RefGroup) ) 01028 maxRefGroupId = max_id; 01029 else if( type == typeid(Body) ) 01030 maxBodyId = max_id; 01031 else if( type == typeid(RefVolume) ) 01032 maxRefVolumeId = max_id; 01033 else if( type == typeid(RefFace) ) 01034 maxRefFaceId = max_id; 01035 else if( type == typeid(RefEdge) ) 01036 maxRefEdgeId = max_id; 01037 else if( type == typeid(RefVertex) ) 01038 maxRefVertexId = max_id; 01039 } 01040 01041 int RefEntityFactory::maximum_id (RefEntity *ref_ent) 01042 { 01043 if (!ref_ent) 01044 return 0; 01045 else if( CAST_TO( ref_ent, RefGroup ) ) 01046 return maxRefGroupId; 01047 else if( CAST_TO( ref_ent, Body ) ) 01048 return maxBodyId; 01049 else if( CAST_TO( ref_ent, RefVolume ) ) 01050 return maxRefVolumeId; 01051 else if( CAST_TO( ref_ent, RefFace ) ) 01052 return maxRefFaceId; 01053 else if( CAST_TO( ref_ent, RefEdge ) ) 01054 return maxRefEdgeId; 01055 else if( CAST_TO( ref_ent, RefVertex ) ) 01056 return maxRefVertexId; 01057 else 01058 return 0; 01059 } 01060 01061 void RefEntityFactory::compress_ref_ids(const char *entity_type, int retain_max_id) 01062 { 01063 const std::type_info& type = RefEntity::get_entity_type_info(entity_type); 01064 assert(type != typeid(InvalidEntity)); 01065 01066 /* 01067 #ifdef VIRTUAL_GEOMETRY_ENGINE_HPP 01068 VirtualGeometryEngine::instance()-> 01069 hidden_entity_mngr.compress_hidden_ids(type); 01070 #endif 01071 */ 01072 /* 01073 DLIList<GeometryQueryEngine*> gqeList; 01074 GeometryQueryTool::instance()->get_gqe_list(gqeList);//Get the gqeList from the GQT 01075 gqeList.reset(); 01076 int i; 01077 for (i = 0; i < gqeList.size(); i++)//Step through the list and call compress_ids. 01078 { //The VGE is the only engine that will do work. 01079 gqeList.get_and_step()->compress_ids(type); 01080 } 01081 */ 01082 01083 DLIList<CubitEntity*> list; 01084 DLIList<RefEntity*> temp_list; 01085 CubitStatus result = ref_entity_list(entity_type, temp_list, CUBIT_FALSE); 01086 if ( result == CUBIT_SUCCESS ) { 01087 CAST_LIST_TO_PARENT(temp_list, list); 01088 compress_ids(list); 01089 } 01090 01091 // set the maximum entity id to the new max values. 01092 if (!retain_max_id) 01093 { 01094 // must use the num_xxx() functions here, since we may have a derived factory! 01095 if( type == typeid(RefGroup) ) 01096 maxRefGroupId = num_ref_groups(); 01097 else if( type == typeid(Body) ) 01098 maxBodyId = num_bodies(); 01099 else if( type == typeid(RefVolume) ) 01100 maxRefVolumeId = num_ref_volumes(); 01101 else if( type == typeid(RefFace) ) 01102 maxRefFaceId = num_ref_faces(); 01103 else if( type == typeid(RefEdge) ) 01104 maxRefEdgeId = num_ref_edges(); 01105 else if( type == typeid(RefVertex) ) 01106 maxRefVertexId = num_ref_vertices(); 01107 } 01108 } 01109 01110 void RefEntityFactory::compress_ids(DLIList<CubitEntity*> &list) 01111 { 01112 int id = 1; 01113 CubitEntity* entity; 01114 01115 if (list.size()) 01116 { 01117 list.reset(); 01118 // if these are ref volumes, recompute color 01119 CubitBoolean set_color = CUBIT_FALSE; 01120 if (CAST_TO(list.get(), RefVolume)) set_color = CUBIT_TRUE; 01121 01122 // sort list so ids of entities are ascending order 01123 list.sort( sort_by_ascending_ids); 01124 01125 for (int i=list.size(); i > 0; i--) 01126 { 01127 entity = list.get_and_step(); 01128 if (entity->id() != id){ 01129 entity->set_id(id); 01130 if (set_color) { 01131 entity->color(CUBIT_DEFAULT_COLOR_INDEX); 01132 } 01133 } 01134 id++; 01135 } 01136 } 01137 } 01138 01139 void RefEntityFactory::reset_ids() 01140 { 01141 maxBodyId = 0; 01142 maxRefVolumeId = 0; 01143 maxRefGroupId = 0; 01144 maxRefFaceId = 0; 01145 maxRefEdgeId = 0; 01146 maxRefVertexId = 0; 01147 maxSurfSubDomainId = 0; 01148 maxCurveSubDomainId = 0; 01149 maxRefCoordSysId = 0; 01150 #ifdef PROE 01151 maxRefAssemblyId = 0; 01152 maxRefPartId = 0; 01153 #endif 01154 } 01155 01156 #if 0 01157 static int re_factory_sort_volumes(RefVolume*& /*a*/, RefVolume*& /*b*/) 01158 { 01159 // This is currently not implemented. When it is added to CGM, 01160 // look at MRefEntityFactory to see what to do. 01161 return 0; 01162 } 01163 #endif 01164 01165 void RefEntityFactory::renumber_geometry_by_properties(CubitBoolean retain_max) 01166 { 01167 // See MRefEntityFactory::renumber_geometry_by_properties. 01168 // If you want this implemented, copy what was done there. 01169 PRINT_ERROR("'Sort' option not supported.\n" 01170 " Compressing IDs without sorting."); 01171 compress_ref_ids("group", retain_max); 01172 compress_ref_ids("body", retain_max); 01173 compress_ref_ids("volume", retain_max); 01174 compress_ref_ids("surface", retain_max); 01175 compress_ref_ids("curve", retain_max); 01176 compress_ref_ids("vertex", retain_max); 01177 } 01178 01179 void RefEntityFactory::notify_observer(const CubitEvent *observer_event) 01180 { 01181 01182 const GeometryEvent* geom_event = dynamic_cast<const GeometryEvent*>(observer_event); 01183 if(!geom_event) 01184 return; 01185 01186 RefEntity* entity = geom_event->get_entity(); 01187 01188 //- handle MODEL_ENTITY_DESTRUCTED/MODEL_ENTITY_CONSTRUCTED events 01189 if (geom_event->get_type() == GeometryEvent::TOPOLOGY_ENTITY_CONSTRUCTED) 01190 add(entity); 01191 else if (geom_event->get_type() == GeometryEvent::TOPOLOGY_ENTITY_DESTRUCTED) 01192 remove(entity); 01193 else if (geom_event->get_type() == GeometryEvent::ID_SET) 01194 { 01195 if(CAST_TO(entity, RefEdge) && ManageListSorting) 01196 refEdgeListIsSorted = false; 01197 else if(CAST_TO(entity, RefFace) && ManageListSorting) 01198 refFaceListIsSorted = false; 01199 else if(CAST_TO(entity, RefVertex) && ManageListSorting) 01200 refVertexListIsSorted = false; 01201 else if(CAST_TO(entity, RefVolume) && ManageListSorting) 01202 refVolumeListIsSorted = false; 01203 else if(CAST_TO(entity, RefGroup) && ManageListSorting) 01204 refGroupListIsSorted = false; 01205 else if(CAST_TO(entity, Body) && ManageListSorting) 01206 bodyListIsSorted = false; 01207 } 01208 } 01209