cgma
|
00001 //- Class: CAUniqueId 00002 //- Owner: Tim Tautges 00003 //- Description: Cubit Attribute for unique ids 00004 //- Checked By: 00005 //- Version: 00006 00007 #include "CAUniqueId.hpp" 00008 #include "CubitSimpleAttrib.hpp" 00009 #include "RefEntity.hpp" 00010 #include "TDUniqueId.hpp" 00011 #include "GSaveOpen.hpp" 00012 #include "GeometryQueryTool.hpp" 00013 00014 DLIList<CAUniqueId *> CAUniqueId::allCAUniqueIds; 00015 bool CAUniqueId::autoUniqueId = false; 00016 UIDMap CAUniqueId::oldUIDToNewUID; 00017 00018 CubitAttrib* CAUniqueId_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa) 00019 { 00020 return new CAUniqueId(entity, p_csa); 00021 } 00022 00023 CAUniqueId::~CAUniqueId() 00024 { 00025 if (allCAUniqueIds.move_to(this)) 00026 allCAUniqueIds.extract(); 00027 } 00028 00029 CAUniqueId::CAUniqueId(RefEntity* new_attrib_owner, 00030 const CubitSimpleAttrib &csa_ptr) 00031 : CubitAttrib(new_attrib_owner) 00032 { 00033 uniqueId = -1; 00034 00035 if(!csa_ptr.isEmpty()) 00036 { 00037 uniqueId = csa_ptr.int_data_list()[0]; 00038 } 00039 allCAUniqueIds.append(this); 00040 } 00041 00042 CubitStatus CAUniqueId::actuate() 00043 { 00044 00045 if (hasActuated == CUBIT_TRUE) return CUBIT_SUCCESS; 00046 00047 // create a TDUniqueId for the entity, if it doesn't already 00048 // exist 00049 TDUniqueId *uid = (TDUniqueId *) attrib_owner()->get_TD(&TDUniqueId::is_unique_id); 00050 00051 if (uid != NULL) { 00052 // check to make sure it's the same unique id 00053 if (uid->unique_id() != uniqueId) { 00054 PRINT_ERROR("Different unique id found for %s %d.\n", 00055 attrib_owner()->class_name(), attrib_owner()->id()); 00056 return CUBIT_FAILURE; 00057 } 00058 } 00059 else 00060 { 00061 if( !GSaveOpen::performingUndo && 00062 GeometryQueryTool::importingSolidModel && 00063 !GeometryQueryTool::mergeGloballyOnImport) 00064 { 00065 //Is there an entity that already has this id? 00066 ToolDataUser *tdu = TDUniqueId::find_td_unique_id(uniqueId); 00067 if( tdu ) 00068 { 00069 //is it already in the map 00070 UIDMap::iterator iter; 00071 iter = oldUIDToNewUID.find( uniqueId ); 00072 00073 if( iter != oldUIDToNewUID.end() ) 00074 uniqueId = (*iter).second; 00075 else 00076 { 00077 int new_unique_id = TDUniqueId::generate_unique_id(); 00078 UIDMap::value_type this_pair(uniqueId, new_unique_id); 00079 oldUIDToNewUID.insert(this_pair); 00080 uniqueId = new_unique_id; 00081 } 00082 } 00083 } 00084 00085 // else make a new one 00086 uid = new TDUniqueId(attrib_owner(), uniqueId); 00087 } 00088 00089 delete_attrib(CUBIT_TRUE); 00090 hasActuated = CUBIT_TRUE; 00091 00092 return CUBIT_SUCCESS; 00093 } 00094 00095 CubitStatus CAUniqueId::update() 00096 { 00097 if (hasUpdated) return CUBIT_SUCCESS; 00098 00099 // set the updated flag 00100 hasUpdated = CUBIT_TRUE; 00101 00102 // if the owner has a unique id, save it, otherwise delete this one 00103 TDUniqueId *td_uid = (TDUniqueId *) attrib_owner()->get_TD(&TDUniqueId::is_unique_id); 00104 00105 if (NULL == td_uid && autoUniqueId) 00106 td_uid = new TDUniqueId(attrib_owner()); 00107 00108 if (td_uid == NULL) { 00109 delete_attrib(CUBIT_TRUE); 00110 } 00111 00112 else { 00113 uniqueId = td_uid->unique_id(); 00114 if (delete_attrib() == CUBIT_TRUE) delete_attrib(CUBIT_FALSE); 00115 } 00116 00117 return CUBIT_SUCCESS; 00118 } 00119 00120 CubitSimpleAttrib CAUniqueId::cubit_simple_attrib() 00121 { 00122 return CubitSimpleAttrib(att_internal_name(), "", "", 00123 &uniqueId); 00124 } 00125 00126 CubitStatus CAUniqueId::actuate_all() 00127 { 00128 //- actuate all the CAUI's on the list, then empty the list 00129 for (int i = allCAUniqueIds.size(); i > 0; i--) { 00130 CAUniqueId *cauid = allCAUniqueIds.get(); 00131 if (cauid->actuate() == CUBIT_SUCCESS) allCAUniqueIds.extract(); 00132 else allCAUniqueIds.step(); 00133 } 00134 00135 return CUBIT_SUCCESS; 00136 } 00137 00138 void CAUniqueId::print() 00139 { 00140 // print info on this attribute 00141 00142 PRINT_INFO("CAUniqueId: owner = %s %d: uid=%d\n", 00143 attribOwnerEntity->class_name(), attribOwnerEntity->id(), 00144 uniqueId); 00145 } 00146 00147 void CAUniqueId::clear_out_old_to_new_map() 00148 { 00149 oldUIDToNewUID.clear(); 00150 } 00151