cgma
CAEntityName.cpp
Go to the documentation of this file.
00001 //- Class:          CAEntityName
00002 //- Owner:          Greg Nielson
00003 //- Description:    Cubit Attribute for entity names.
00004 //- Checked By:
00005 //- Version:
00006 
00007 #include "CAEntityName.hpp"
00008 #include "BasicTopologyEntity.hpp"
00009 #include "Body.hpp"
00010 #include "RefEntityName.hpp"
00011 #include "CastTo.hpp"
00012 #include "CubitMessage.hpp"
00013 
00014 CubitAttrib* CAEntityName_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
00015 {
00016   return new CAEntityName(entity, p_csa);
00017 }
00018 
00019 CAEntityName::CAEntityName(RefEntity* new_attrib_owner,
00020                            const CubitSimpleAttrib &csa_ptr)
00021         : CubitAttrib(new_attrib_owner)
00022 {
00023   if(!csa_ptr.isEmpty())
00024   {
00025     PRINT_DEBUG_94( "Creating ENTITY_NAME attribute from CSA for %s %d\n",
00026                 (attribOwnerEntity ? attribOwnerEntity->class_name() : "(none)"),
00027                 (attribOwnerEntity ? attribOwnerEntity->id() : 0));
00028 
00029     const std::vector<CubitString>& cs_list = csa_ptr.string_data_list();
00030 
00031       // step over the attribute type
00032 
00033       // now read name / option pairs
00034     for (size_t i = 1; i<cs_list.size(); i++)
00035     {
00036       CubitString cs = cs_list[i];
00037       if (cs.length() == 0)
00038         PRINT_WARNING("Empty name attribute for %s %d.\n",
00039                       attribOwnerEntity->class_name(),
00040                       attribOwnerEntity->id());
00041       else
00042         entityNames.append(cs);
00043     }
00044 
00045     if (entityNames.size() == 0)
00046       deleteAttrib = CUBIT_TRUE;
00047   }
00048 }
00049 
00050 CAEntityName::~CAEntityName()
00051 {
00052   PRINT_DEBUG_94("Deleting ENTITY_NAME attribute\n");
00053 }
00054 
00055 CubitStatus CAEntityName::actuate()
00056 {
00057   if (hasActuated == CUBIT_TRUE) return CUBIT_SUCCESS;
00058 
00059   PRINT_DEBUG_94( "Actuating ENTITY_NAME attribute for %s %d\n",
00060               attribOwnerEntity->class_name(), attribOwnerEntity->id());
00061 
00062   entityNames.reset();
00063 
00064   CubitBoolean update_attribs = (CubitBoolean) 
00065       (RefEntityName::instance()->get_generate_default_names()!=1);
00066   
00067   RefEntityName::instance()->add_refentity_name(attribOwnerEntity,entityNames,
00068                                                 update_attribs);
00069 
00070   hasActuated = CUBIT_TRUE;
00071   return CUBIT_SUCCESS;
00072 }
00073 
00074 CubitStatus CAEntityName::update()
00075 {
00076   if (hasUpdated) return CUBIT_SUCCESS;
00077   
00078   PRINT_DEBUG_94( "Updating ENTITY_NAME attribute for %s %d\n",
00079               attribOwnerEntity->class_name(), attribOwnerEntity->id());
00080 
00081     // set the updated flag
00082   hasUpdated = CUBIT_TRUE;
00083 
00084     // first, remove this attrib in its old form from the geometry entity
00085   if (hasWritten == CUBIT_TRUE) {
00086     attribOwnerEntity->remove_attrib_geometry_entity(this);
00087     hasWritten = CUBIT_FALSE;
00088   }
00089   
00090   DLIList<CubitString> names;
00091   int num_names = RefEntityName::instance()->
00092       get_refentity_name(attribOwnerEntity,names);
00093   if( num_names == 0)
00094   {
00095     delete_attrib(CUBIT_TRUE);
00096     return CUBIT_SUCCESS;
00097   }
00098   else
00099   {
00100       // get the names; since RefEntityName passes back pointers to
00101       // its own strings, create new ones here
00102     int i;
00103 
00104       // first, delete all the old names on the list
00105     entityNames.clean_out();
00106     
00107     for (i = names.size(); i > 0; i--) {
00108       entityNames.append(names.get_and_step());
00109     }
00110     
00111       // reset the delete flag if it was set before
00112     delete_attrib(CUBIT_FALSE);
00113     
00114       // now, write to geometry entity
00115     attribOwnerEntity->write_specific_cubit_attrib(this);
00116   }
00117   return CUBIT_SUCCESS;
00118 }
00119 
00120 CubitStatus CAEntityName::reset()
00121 {
00122   PRINT_DEBUG_94("CAEntityName::reset()\n");
00123   
00124   //- reset function, cleans out name list
00125   entityNames.clean_out();
00126 
00127     // need to reset hasUpdated flag too, so next update will do something
00128   hasUpdated = CUBIT_FALSE;
00129   return CUBIT_SUCCESS;
00130 }
00131 
00132 CubitSimpleAttrib CAEntityName::split_owner()
00133 {
00134     // if this entity is to be split, pass back a simple attribute with
00135     // duplicate name data to be put on new entity
00136   PRINT_DEBUG_94("CAEntityName::split_owner()\n");
00137   update();
00138   if( deleteAttrib )
00139     return CubitSimpleAttrib();
00140   else
00141     return cubit_simple_attrib();
00142 }
00143 
00144 void CAEntityName::merge_owner(CubitAttrib *deletable_attrib)
00145 {
00146     // if this entity is to be merged, copy names over from deletable entity
00147   CAEntityName *caen_ptr = CAST_TO(deletable_attrib, CAEntityName);
00148   if (caen_ptr)
00149   {
00150     DLIList<CubitString> &other_names = caen_ptr->entityNames;
00151     other_names.reset();
00152     for (int i = other_names.size(); i--; )
00153     {
00154       entityNames.append(other_names.get_and_step());
00155     }
00156   }
00157 }
00158 
00159 CubitSimpleAttrib CAEntityName::cubit_simple_attrib()
00160 {
00161   PRINT_DEBUG_94("CAEntityName::cubit_simple_attrib()\n");
00162   
00163   std::vector<CubitString> cs_list;
00164 
00165     // pack the string list:
00166     // character type of this CA
00167   cs_list.push_back(att_internal_name());
00168 
00169     // name, option pairs
00170   int i;
00171   for ( i = entityNames.size(); i > 0; i--) {
00172     cs_list.push_back(entityNames.get_and_step());
00173   }
00174 
00175   return CubitSimpleAttrib(&cs_list, NULL, NULL);
00176 }
00177 
00178 
00179 void CAEntityName::print()
00180 {
00181     // print info on this attribute
00182   entityNames.reset();
00183   
00184   PRINT_INFO("CAEntityName: owner = %s %d; names: ",
00185              attribOwnerEntity->class_name(), attribOwnerEntity->id());
00186   for (int i = entityNames.size(); i > 0; i--)
00187     PRINT_INFO("%s ", entityNames.get_and_step().c_str());
00188 
00189   PRINT_INFO("\n");
00190 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines