cgma
|
00001 //- File: CAEntitySense.cpp 00002 //- Owner: Corey Ernst 00003 //- Description: Cubit Attribute for entity colors. 00004 //- Checked By: 00005 //- Version: 00006 00007 #include "CAEntitySense.hpp" 00008 #include "RefEntity.hpp" 00009 #include "RefEdge.hpp" 00010 #include "RefFace.hpp" 00011 #include "BridgeManager.hpp" 00012 #include "BasicTopologyEntity.hpp" 00013 #include "CastTo.hpp" 00014 #include "CubitMessage.hpp" 00015 00016 00017 CubitAttrib* CAEntitySense_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa) 00018 { 00019 return new CAEntitySense(entity, p_csa); 00020 } 00021 00022 CAEntitySense::CAEntitySense(RefEntity* new_attrib_owner, 00023 const CubitSimpleAttrib &csa_ptr) 00024 : CubitAttrib(new_attrib_owner) 00025 { 00026 std::vector<int, std::allocator<int> > i_list = csa_ptr.int_data_list(); 00027 00028 if( i_list.size() > 0) 00029 { 00030 int i = i_list[0]; 00031 if( i == -1 ) 00032 entitySense = CUBIT_UNKNOWN; 00033 else if( i == 0 ) 00034 entitySense = CUBIT_FORWARD; 00035 else if( i == 1 ) 00036 entitySense = CUBIT_REVERSED; 00037 } 00038 else 00039 entitySense = CUBIT_UNKNOWN; 00040 } 00041 00042 CAEntitySense::CAEntitySense(RefEntity* new_attrib_owner) 00043 : CubitAttrib(new_attrib_owner) 00044 { 00045 entitySense = CUBIT_FORWARD; 00046 } 00047 00048 CAEntitySense::~CAEntitySense() 00049 { 00050 } 00051 00052 00053 CubitStatus CAEntitySense::actuate() 00054 { 00055 if ( hasActuated) 00056 return CUBIT_SUCCESS; 00057 00058 if ( !attribOwnerEntity ) 00059 return CUBIT_FAILURE; 00060 00061 deleteAttrib = CUBIT_FALSE; 00062 00063 int dimension = attribOwnerEntity->dimension(); 00064 if( 1 == dimension || 2 == dimension ) 00065 { 00066 BasicTopologyEntity* bte_ptr = CAST_TO(attribOwnerEntity, BasicTopologyEntity); 00067 CubitSense tmp_sense = CUBIT_UNKNOWN; 00068 if( bte_ptr ) 00069 { 00070 tmp_sense = bte_ptr->bridge_manager()->topology_bridge()->bridge_sense(); 00071 if( tmp_sense != entitySense ) 00072 { 00073 if( 1==dimension ) 00074 { 00075 RefEdge *ref_edge = dynamic_cast<RefEdge*>( bte_ptr ); 00076 ref_edge->reverse_tangent(); 00077 } 00078 else if( 2 == dimension ) 00079 { 00080 RefFace *ref_face = dynamic_cast<RefFace*>( bte_ptr ); 00081 ref_face->reverse_normal(); 00082 } 00083 } 00084 } 00085 } 00086 00087 hasActuated = CUBIT_TRUE; 00088 return CUBIT_SUCCESS; 00089 } 00090 00091 CubitStatus CAEntitySense::update() 00092 { 00093 int dimension = attribOwnerEntity->dimension(); 00094 if( 1 == dimension || 2 == dimension ) 00095 { 00096 BasicTopologyEntity* bte_ptr = CAST_TO(attribOwnerEntity, BasicTopologyEntity); 00097 entitySense = CUBIT_UNKNOWN; 00098 if( bte_ptr ) 00099 entitySense = bte_ptr->bridge_manager()->topology_bridge()->bridge_sense(); 00100 } 00101 00102 if( entitySense == CUBIT_FORWARD || entitySense == CUBIT_UNKNOWN ) 00103 delete_attrib(CUBIT_TRUE); 00104 00105 return CUBIT_SUCCESS; 00106 } 00107 00108 CubitSimpleAttrib CAEntitySense::cubit_simple_attrib() 00109 { 00110 std::vector<CubitString> cs_list; 00111 std::vector<int, std::allocator<int> > i_list; 00112 00113 i_list.push_back( entitySense ); 00114 00115 cs_list.push_back(att_internal_name()); 00116 00117 CubitSimpleAttrib csattrib_ptr(&cs_list, NULL, &i_list); 00118 00119 return csattrib_ptr; 00120 } 00121 00122 void CAEntitySense::print() 00123 { 00124 // print info on this attribute 00125 00126 PRINT_INFO("CAEntitySense: owner = %s %d: color ", 00127 attribOwnerEntity->class_name(), attribOwnerEntity->id()); 00128 if( entitySense == CUBIT_UNKNOWN ) 00129 PRINT_INFO(" CUBIT_UNKNOWN\n"); 00130 else if( entitySense == CUBIT_FORWARD ) 00131 PRINT_INFO(" CUBIT_FORWARD\n"); 00132 else if( entitySense == CUBIT_REVERSED ) 00133 PRINT_INFO(" CUBIT_REVERSED\n"); 00134 }