cgma
CubitAttribManager.cpp
Go to the documentation of this file.
00001 
00002 #include "CubitAttribManager.hpp"
00003 #include "CubitAttribUser.hpp"
00004 #include "CastTo.hpp"
00005 #include "assert.h"
00006 #include "CADefines.hpp"
00007 
00008 #include "RefEntity.hpp"
00009 #include "CubitMessage.hpp"
00010 
00011 CubitAttribManager::CubitAttribManager() 
00012     : silentFlag(false)
00013 {
00014 }
00015 
00016 CubitAttribManager::~CubitAttribManager()
00017 {
00018 /*
00019   std::map<int, CARegisterData*>::iterator iter = mTypeToCAData.begin();
00020 
00021   while (mTypeToCAData.end() != iter)
00022   {
00023     delete iter->second;
00024     iter++;
00025   }
00026 */
00027   int i;
00028   assert(mTypeNames.size() == mInternalNames.size());
00029 
00030 
00031   for (i=mTypeNames.size(); i>0; i--)
00032   {
00033     delete [] mTypeNames.get_and_step();
00034     delete [] mInternalNames.get_and_step();
00035   }
00036 
00037 }
00038 
00039 CubitStatus
00040 CubitAttribManager::register_attrib_type( const int att_type,
00041                                          const char* att_type_name,
00042                                       const char* att_internal_name,
00043                                       CACreateFunction p_create_function,
00044                                       CubitBoolean auto_actuate_flag,
00045                                       CubitBoolean auto_update_flag,
00046                                       CubitBoolean auto_write_flag,
00047                                       CubitBoolean auto_read_flag,
00048                                       CubitBoolean actuate_in_constructor,
00049                                       CubitBoolean actuate_after_geom_changes)
00050 {
00051   assert(CA_UNDEFINED != att_type);
00052   assert(CA_ALL_ATTRIBUTES != att_type);
00053 
00054 /*
00055   unsigned int flags = 0;
00056   if (auto_actuate_flag) flags |= CA_AUTOACTUATE;
00057   if (auto_update_flag) flags |= CA_AUTOUPDATE;
00058   if (auto_write_flag) flags |= CA_AUTOWRITE;
00059   if (auto_read_flag) flags |= CA_AUTOREAD;
00060   if (actuate_in_constructor) flags |= CA_ACTUATEINCONSTRUCTOR;
00061   if (actuate_after_geom_changes) flags |= CA_ACTUATEAFTERGEOMCHANGES;
00062   CARegisterData *p_entry = new CARegisterData(att_type_name, att_internal_name,
00063                                                p_create_function, flags);
00064   
00065   std::pair<std::map<int, CARegisterData*>::iterator, bool> result_pair;
00066   result_pair = mTypeToCAData.insert( std::pair<int, CARegisterData*>(att_type, p_entry) );
00067 
00068   if (!result_pair.second) // failed to insert because the type was already registered
00069   {
00070     assert(false);
00071     delete p_entry;
00072     return CUBIT_FAILURE;
00073   }
00074 */
00075 
00076   int index = mTypes.where_is_item(att_type);
00077   if (-1 != index) // type already registered
00078   {
00079     if (!silentFlag) PRINT_ERROR("Attribute type %d already registered\n.", att_type);
00080     return CUBIT_FAILURE;
00081   }
00082 
00083 #ifndef NDEBUG
00084   int size = mTypes.size();
00085   assert (mTypeNames.size() == size);
00086   assert (mCreatorFunctions.size() == size);
00087   assert (mInternalNames.size() == size);
00088   assert (mAutoActuateFlags.size() == size);
00089   assert (mAutoUpdateFlags.size() == size);
00090   assert (mAutoWriteFlags.size() == size);
00091   assert (mAutoReadFlags.size() == size);
00092   assert (mActuateInConstructor.size() == size);
00093   assert (mActuateAfterGeomChanges.size() == size);
00094 //  assert (mAttribImported.size() == size);
00095 #endif
00096 
00097   mTypes.append(att_type);
00098 
00099   int namesize = strlen(att_type_name);
00100   char *stemp = new char[namesize+1];
00101   strcpy(stemp, att_type_name);
00102   mTypeNames.append(stemp);
00103 
00104   namesize = strlen(att_internal_name);
00105   stemp = new char[namesize+1];
00106   strcpy(stemp, att_internal_name);
00107   mInternalNames.append(stemp);
00108 
00109   mCreatorFunctions.append(p_create_function);
00110 
00111   mAutoActuateFlags.append(auto_actuate_flag);
00112   mAutoUpdateFlags.append(auto_update_flag);
00113   mAutoWriteFlags.append(auto_write_flag);
00114   mAutoReadFlags.append(auto_read_flag);
00115   mActuateInConstructor.append(actuate_in_constructor);
00116   mActuateAfterGeomChanges.append(actuate_after_geom_changes);
00117 //  mAttribImported.append(CUBIT_FALSE); // TODO - get rid of mAttribImported
00118 
00119   return CUBIT_SUCCESS;
00120 }
00121 
00122 CubitAttrib*
00123 CubitAttribManager::create_cubit_attrib(const int attrib_type,
00124                                         RefEntity *attrib_user,
00125                                         const CubitSimpleAttrib &p_csa)
00126 {
00127   CubitAttrib* new_attrib = NULL;
00128 /*
00129   CARegisterData *p_entry = NULL;
00130   CACreateFunction p_creator;
00131   std::map<int, CARegisterData*>::iterator iter;
00132 
00133   iter = mTypeToCAData.find(attrib_type);
00134   if (mTypeToCAData.end() == iter)
00135   {
00136     assert(false);
00137     return NULL;
00138   }
00139 
00140   p_entry = iter->second;
00141   p_creator = p_entry->mCreateFunction;
00142   new_attrib = (*p_creator)(attrib_user);
00143   return new_attrib;
00144 */
00145 
00146   int index = mTypes.where_is_item(attrib_type);
00147   if (-1 == index) // type not registered
00148   {
00149     if (!silentFlag) PRINT_ERROR("Attribute type %d can't be created because it hasn't been registered.\n", 
00150                 attrib_type);
00151     return NULL;
00152   }
00153 
00154 
00155   CACreateFunction p_creator;
00156   mCreatorFunctions.reset();
00157   p_creator = mCreatorFunctions.next(index);
00158 
00159   new_attrib = (*p_creator)(attrib_user, p_csa);
00160   return new_attrib;
00161 
00162 }
00163 
00164 /*
00165 CubitStatus CubitAttribManager::actuate_list(DLIList<RefEntity*> entity_list)
00166 {
00167   int i, j;
00168   RefEntity * ref_ent;
00169   for(i = entity_list.size(); i > 0; i--)
00170   {
00171     ref_ent = entity_list.get_and_step();
00172 
00173     mTypes.reset();
00174     for (j = mTypes.size(); j>0; j--)
00175     {
00176       ref_ent->actuate_cubit_attrib(mTypes.get_and_step());
00177     }
00178   }
00179   return CUBIT_SUCCESS;
00180 }
00181 */
00182 CubitStatus CubitAttribManager::auto_update_attribs(RefEntity *cau)
00183 {
00184     //- create attribs whose auto update flag is set
00185 
00186   CubitStatus status = CUBIT_SUCCESS;
00187   DLIList<CubitAttrib*> attrib_list;
00188 
00189 /*
00190   std::map<int, CARegisterData*>::iterator iter = mTypeToCAData.begin();
00191 
00192   while (mTypeToCAData.end() != iter)
00193   {
00194     CubitBoolean auto_update = ((iter->second)->flags) & CA_AUTOUPDATE;
00195     int attrib_type = iter->first;
00196 
00197     if (auto_update)
00198     {
00199       attrib_list.clean_out();
00200       cau->find_cubit_attrib_type(attrib_type, attrib_list);
00201       if (attrib_list.size() == 0) {
00202         create_cubit_attrib(attrib_type, cau);
00203         if (status == CUBIT_FAILURE) break;
00204       }
00205     }
00206     iter++;
00207   }
00208 */
00209   mAutoUpdateFlags.reset();
00210   mTypes.reset();
00211   assert(mTypes.size() == mAutoUpdateFlags.size());
00212   int index;
00213   for (index=mAutoUpdateFlags.size(); index>0; index--) {
00214       // check the auto update flag first, if not set we can go
00215     if (mAutoUpdateFlags.get() == CUBIT_TRUE)
00216     {
00217 
00218         // else we must create a CA of type if there's not one already there
00219       attrib_list.clean_out();
00220       cau->find_cubit_attrib_type(mTypes.get(), attrib_list);
00221       if (attrib_list.size() == 0) {
00222         create_cubit_attrib(mTypes.get(), cau, CubitSimpleAttrib());
00223         if (status == CUBIT_FAILURE) break;
00224       }
00225     }
00226     mAutoUpdateFlags.step();
00227     mTypes.step();
00228   }
00229 
00230   return status;
00231 }
00232 
00233 void CubitAttribManager::set_all_auto_actuate_flags(CubitBoolean value)
00234 {
00235 
00236 //  std::map<int, CARegisterData*>::iterator iter = mTypeToCAData.begin();
00237 
00238 //  while (mTypeToCAData.end() != iter)
00239 //  {
00240 
00241   mAutoActuateFlags.reset();
00242   for (int i = mAutoActuateFlags.size(); i>0; i--)
00243   {
00244     mAutoActuateFlags.change_to(value);
00245     mAutoActuateFlags.step();
00246   }
00247 }
00248 
00249 CubitStatus CubitAttribManager::set_auto_actuate_flag(int attrib_type, CubitBoolean value)
00250 {
00251   assert(CA_UNDEFINED != attrib_type);
00252   assert(CA_ALL_ATTRIBUTES != attrib_type);
00253 
00254   int index = mTypes.where_is_item(attrib_type);
00255 
00256   if (-1 == index)
00257     return CUBIT_FAILURE;
00258 
00259   mAutoActuateFlags.reset();
00260   mAutoActuateFlags.step(index);
00261   mAutoActuateFlags.change_to(value);
00262   return CUBIT_SUCCESS;
00263 }
00264 
00265 void CubitAttribManager::set_all_auto_update_flags(CubitBoolean value)
00266 {
00267   mAutoUpdateFlags.reset();
00268   for (int i = mAutoUpdateFlags.size(); i>0; i--)
00269   {
00270     mAutoUpdateFlags.change_to(value);
00271     mAutoUpdateFlags.step();
00272   }
00273 }
00274 
00275 CubitStatus CubitAttribManager::set_auto_update_flag(int attrib_type, CubitBoolean value)
00276 {
00277   assert(CA_UNDEFINED != attrib_type);
00278   assert(CA_ALL_ATTRIBUTES != attrib_type);
00279 
00280   int index = mTypes.where_is_item(attrib_type);
00281 
00282   if (-1 == index)
00283     return CUBIT_FAILURE;
00284 
00285   mAutoUpdateFlags.reset();
00286   mAutoUpdateFlags.step(index);
00287   mAutoUpdateFlags.change_to(value);
00288   return CUBIT_SUCCESS;
00289 }
00290 
00291 void CubitAttribManager::set_all_auto_write_flags(CubitBoolean value)
00292 {
00293   mAutoWriteFlags.reset();
00294   for (int i = mAutoWriteFlags.size(); i>0; i--)
00295   {
00296     mAutoWriteFlags.change_to(value);
00297     mAutoWriteFlags.step();
00298   }
00299 }
00300 
00301 CubitStatus CubitAttribManager::set_auto_write_flag(int attrib_type, CubitBoolean value)
00302 {
00303   assert(CA_UNDEFINED != attrib_type);
00304   assert(CA_ALL_ATTRIBUTES != attrib_type);
00305 
00306   int index = mTypes.where_is_item(attrib_type);
00307 
00308   if (-1 == index)
00309     return CUBIT_FAILURE;
00310 
00311   mAutoWriteFlags.reset();
00312   mAutoWriteFlags.step(index);
00313   mAutoWriteFlags.change_to(value);
00314   return CUBIT_SUCCESS;
00315 }
00316 
00317 void CubitAttribManager::set_all_auto_read_flags(CubitBoolean value)
00318 {
00319   mAutoReadFlags.reset();
00320   for (int i = mAutoReadFlags.size(); i>0; i--)
00321   {
00322     mAutoReadFlags.change_to(value);
00323     mAutoReadFlags.step();
00324   }
00325 }
00326 
00327 CubitStatus CubitAttribManager::set_auto_read_flag(int attrib_type, CubitBoolean value)
00328 {
00329   assert(CA_UNDEFINED != attrib_type);
00330   assert(CA_ALL_ATTRIBUTES != attrib_type);
00331 
00332   int index = mTypes.where_is_item(attrib_type);
00333 
00334   if (-1 == index)
00335     return CUBIT_FAILURE;
00336 
00337   mAutoReadFlags.reset();
00338   mAutoReadFlags.step(index);
00339   mAutoReadFlags.change_to(value);
00340   return CUBIT_SUCCESS;
00341 }
00342 
00343 void CubitAttribManager::auto_flag(int flag) 
00344 {
00345   if (flag == -1) {
00346     flag = auto_flag();
00347     if (flag == -1) {
00348       if (!silentFlag) PRINT_ERROR("Can't change attribute flag with toggle, "
00349                   "some are already set.\n");
00350       return;
00351     }
00352   }
00353 
00354   CubitBoolean set_flag = (flag == 1 ? CUBIT_TRUE : CUBIT_FALSE);
00355   
00356   mAutoUpdateFlags.reset();
00357   mAutoActuateFlags.reset();
00358   assert (mAutoUpdateFlags.size() == mAutoActuateFlags.size());
00359   for (int i = mAutoUpdateFlags.size(); i>0; i--)
00360   {
00361     mAutoUpdateFlags.change_to(set_flag);
00362     mAutoUpdateFlags.step();
00363     mAutoActuateFlags.change_to(set_flag);
00364     mAutoActuateFlags.step();
00365   }
00366 
00367   if (!set_flag) {
00368       // make sure entity_name flag isn't set false here
00369 
00370     int index = mTypes.where_is_item(CA_ENTITY_NAME);
00371     assert(-1 != index);
00372 
00373     mAutoUpdateFlags.reset();
00374     mAutoUpdateFlags.step(index);
00375     mAutoUpdateFlags.change_to(CUBIT_TRUE);
00376 
00377     mAutoActuateFlags.reset();
00378     mAutoActuateFlags.step(index);
00379     mAutoActuateFlags.change_to(CUBIT_TRUE);
00380   }
00381 }
00382   
00383 int CubitAttribManager::auto_flag() 
00384 {
00385   int sum = 0;
00386   CubitBoolean b_temp;
00387   mAutoUpdateFlags.reset();
00388   mAutoActuateFlags.reset();
00389   assert (mAutoUpdateFlags.size() == mAutoActuateFlags.size());
00390   for (int i = mAutoUpdateFlags.size(); i>0; i--)
00391   {
00392     b_temp = mAutoUpdateFlags.get_and_step();
00393     if (b_temp) sum++;
00394     b_temp = mAutoActuateFlags.get_and_step();
00395     if (b_temp) sum++;
00396   }
00397     
00398   if (2*mAutoUpdateFlags.size() == sum) return 0;
00399   else if (sum == 0) return 1;
00400   else return -1;
00401 }
00402 
00403 int CubitAttribManager::attrib_type(const char* name)
00404 {
00405   int i;
00406   mTypeNames.reset();
00407   assert (mTypes.size() == mTypeNames.size());
00408   for (i=0; i<mTypeNames.size(); i++)
00409   {
00410     if (!strcmp(name, mTypeNames.get_and_step()))
00411     {
00412       mTypes.reset();
00413       mTypes.step(i);
00414       return mTypes.get();
00415     }
00416   }
00417 
00418   return CA_UNDEFINED;
00419 }
00420 
00421 int CubitAttribManager::attrib_type(const CubitSimpleAttrib& csa_ptr)
00422 {
00423   CubitString char_type = csa_ptr.character_type();
00424   return attrib_type_from_internal_name(char_type.c_str());
00425 }
00426 
00427 int CubitAttribManager::attrib_type_from_internal_name(const char* name)
00428 {
00429   int i;
00430   mInternalNames.reset();
00431   assert (mTypes.size() == mInternalNames.size());
00432   for (i=0; i<mInternalNames.size(); i++)
00433   {
00434     if (!strcmp(name, mInternalNames.get_and_step()))
00435     {
00436       mTypes.reset();
00437       mTypes.step(i);
00438       return mTypes.get();
00439     }
00440   }
00441 
00442   return CA_UNDEFINED;
00443 }
00444 
00445 CubitBoolean CubitAttribManager::auto_actuate_flag(int attrib_type)
00446 {
00447   int index = mTypes.where_is_item(attrib_type);
00448   if (-1 == index) {
00449     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00450     return false;
00451   }
00452 
00453   mAutoActuateFlags.reset();
00454   mAutoActuateFlags.step(index);
00455   return mAutoActuateFlags.get();
00456 }
00457 
00458 CubitBoolean CubitAttribManager::auto_update_flag(int attrib_type)
00459 {
00460   int index = mTypes.where_is_item(attrib_type);
00461   if (-1 == index) {
00462     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00463     return false;
00464   }
00465 
00466   mAutoUpdateFlags.reset();
00467   mAutoUpdateFlags.step(index);
00468   return mAutoUpdateFlags.get();
00469 }
00470 
00471 CubitBoolean CubitAttribManager::auto_write_flag(int attrib_type)
00472 {
00473   int index = mTypes.where_is_item(attrib_type);
00474   if (-1 == index) {
00475     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00476     return false;
00477   }
00478 
00479   mAutoWriteFlags.reset();
00480   mAutoWriteFlags.step(index);
00481   return mAutoWriteFlags.get();
00482 }
00483 
00484 CubitBoolean CubitAttribManager::auto_read_flag(int attrib_type)
00485 {
00486   int index = mTypes.where_is_item(attrib_type);
00487   if (-1 == index) {
00488     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00489     return false;
00490   }
00491 
00492   mAutoReadFlags.reset();
00493   mAutoReadFlags.step(index);
00494   return mAutoReadFlags.get();
00495 }
00496 
00497 //- return the internal name of this CA given the enumerated attribute type
00498 const char * CubitAttribManager::att_internal_name(int attrib_type)
00499 {
00500   int index = mTypes.where_is_item(attrib_type);
00501   if (-1 == index) {
00502     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00503     return NULL;
00504   }
00505 
00506   mInternalNames.reset();
00507   mInternalNames.step(index);
00508   return mInternalNames.get();
00509 } 
00510 
00511 //- return the name of this CA given the enumerated attribute type
00512 const char * CubitAttribManager::att_name(int attrib_type)
00513 {
00514   int index = mTypes.where_is_item(attrib_type);
00515   if (-1 == index) {
00516     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00517     return NULL;
00518   }
00519 
00520   mTypeNames.reset();
00521   mTypeNames.step(index);
00522   return mTypeNames.get();
00523 } 
00524 
00525 CubitBoolean CubitAttribManager::actuate_in_constructor(int attrib_type)
00526 {
00527   int index = mTypes.where_is_item(attrib_type);
00528   if (-1 == index) {
00529     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00530     return false;
00531   }
00532 
00533   mActuateInConstructor.reset();
00534   mActuateInConstructor.step(index);
00535   return mActuateInConstructor.get();
00536 }
00537 
00538 CubitBoolean CubitAttribManager::actuate_after_geom_changes(int attrib_type)
00539 {
00540   int index = mTypes.where_is_item(attrib_type);
00541   if (-1 == index) {
00542     if (!silentFlag) PRINT_ERROR("Attribute type %d not recognized.\n", attrib_type);
00543     return false;
00544   }
00545 
00546   mActuateAfterGeomChanges.reset();
00547   mActuateAfterGeomChanges.step(index);
00548   return mActuateAfterGeomChanges.get();
00549 }
00550 
00551 void CubitAttribManager::get_registered_types(DLIList<int> &types)
00552 {
00553   types = mTypes;
00554   types.reset();
00555 }
00556 
00557 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines