cgma
CAEntityColor.cpp
Go to the documentation of this file.
00001 //- File:           CAEntityColor.cpp
00002 //- Owner:          Joel Kopp
00003 //- Description:    Cubit Attribute for entity colors.
00004 //- Checked By:
00005 //- Version:
00006 
00007 #include "CAEntityColor.hpp"
00008 #include "RefEntity.hpp"
00009 #include "RefVolume.hpp"
00010 #include "CastTo.hpp"
00011 #include "CubitMessage.hpp"
00012 
00013 CubitAttrib* CAEntityColor_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
00014 {
00015   return new CAEntityColor(entity, p_csa);
00016 }
00017 
00018 CAEntityColor::CAEntityColor(RefEntity* new_attrib_owner,
00019                        const CubitSimpleAttrib &csa_ptr)
00020         : CubitAttrib(new_attrib_owner)
00021 {
00022   entityColor = 0;
00023 
00024   if(!csa_ptr.isEmpty())
00025   {
00026     const std::vector<int>& i_list = csa_ptr.int_data_list();
00027     assert(i_list.size() > 0);
00028     entityColor = i_list[0];
00029   }
00030 }
00031 
00032 CAEntityColor::~CAEntityColor()
00033 {
00034 }
00035 
00036 
00037 CubitStatus CAEntityColor::actuate()
00038 {
00039    if ( hasActuated)
00040       return CUBIT_SUCCESS;
00041    
00042    if ( !attribOwnerEntity )
00043       return CUBIT_FAILURE;
00044    
00045    deleteAttrib = CUBIT_FALSE;
00046    
00047    //- If actuating after import, change the color.  Else (auto actuated) color is already changed...
00048    if( attribOwnerEntity->color() == CUBIT_DEFAULT_COLOR_INDEX || 
00049        dynamic_cast<RefVolume*>(attribOwnerEntity) )
00050    {
00051       attribOwnerEntity->color(entityColor);
00052    }
00053    
00054    hasActuated = CUBIT_TRUE;
00055    return CUBIT_SUCCESS;
00056 }
00057 
00058 CubitStatus CAEntityColor::update()
00059 {
00060       delete_attrib(CUBIT_TRUE);
00061       return CUBIT_SUCCESS;
00062 
00063 /*
00064    if ( hasUpdated ) 
00065       return CUBIT_SUCCESS;
00066    
00067    if ( !attribOwnerEntity)
00068       return CUBIT_FAILURE;
00069    
00070    entityColor = attribOwnerEntity->color();
00071    
00072    // set the updated flag
00073    hasUpdated = CUBIT_TRUE;
00074 
00075    if( entityColor == -1 )
00076    {
00077       delete_attrib(CUBIT_TRUE);
00078       return CUBIT_SUCCESS;
00079    }
00080    
00081    return CUBIT_SUCCESS;
00082    */
00083 }
00084 
00085 void CAEntityColor::merge_owner(CubitAttrib *deletable_attrib)
00086 {
00087     // take the id with the lowest value
00088   CAEntityColor *other_caecolor = CAST_TO(deletable_attrib, CAEntityColor);
00089   
00090   if (other_caecolor)
00091     entityColor = other_caecolor->color();
00092 }
00093 
00094 CubitSimpleAttrib CAEntityColor::cubit_simple_attrib()
00095 {
00096   std::vector<CubitString> cs_list;
00097   std::vector<int> i_list;
00098 
00099   i_list.push_back ( entityColor );
00100     
00101   cs_list.push_back(att_internal_name());
00102 
00103   return CubitSimpleAttrib(&cs_list, NULL, &i_list);
00104 }
00105 
00106 void CAEntityColor::print()
00107 {
00108     // print info on this attribute
00109   
00110   PRINT_INFO("CAEntityColor: owner = %s %d:   color ",
00111              attribOwnerEntity->class_name(), attribOwnerEntity->id());
00112   if ( entityColor > -1 )
00113      PRINT_INFO("                             %d\n",
00114      entityColor);
00115   else
00116      PRINT_INFO("\n");
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines