cgma
|
00001 #include "CASourceFeature.hpp" 00002 #include "BasicTopologyEntity.hpp" 00003 #include "Body.hpp" 00004 #include "RefEntityName.hpp" 00005 #include "CastTo.hpp" 00006 #include "CubitMessage.hpp" 00007 #include "TDSourceFeature.hpp" 00008 00009 CubitAttrib* CASourceFeature_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa) 00010 { 00011 return new CASourceFeature(entity, p_csa); 00012 } 00013 00014 CASourceFeature::CASourceFeature(RefEntity* new_attrib_owner, 00015 const CubitSimpleAttrib& csa_ptr) 00016 : CubitAttrib(new_attrib_owner) 00017 { 00018 sourceFeature = GeometryFeatureEngine::FEATURE_UNDEFINED; 00019 00020 if(!csa_ptr.isEmpty()) 00021 { 00022 00023 const std::vector<CubitString>& cs_list = csa_ptr.string_data_list(); 00024 00025 // step over the attribute type 00026 // now read name / option pairs 00027 if(cs_list.size()==2) 00028 { 00029 CubitString cs = cs_list[1]; 00030 if (cs.length() == 0) 00031 PRINT_WARNING("Empty feature attribute for %s %d.\n", 00032 attribOwnerEntity->class_name(), 00033 attribOwnerEntity->id()); 00034 else 00035 sourceFeature = string_to_feature_type(cs); 00036 } 00037 else 00038 deleteAttrib = CUBIT_TRUE; 00039 } 00040 } 00041 00042 CASourceFeature::~CASourceFeature() 00043 { 00044 } 00045 00046 CubitStatus CASourceFeature::actuate() 00047 { 00048 if (hasActuated == CUBIT_TRUE) 00049 return CUBIT_SUCCESS; 00050 00051 // create a TDSourceFeature for the entity, if it doesn't already 00052 // exist 00053 TDSourceFeature *source_feature_data = 00054 (TDSourceFeature *) attrib_owner()->get_TD(&TDSourceFeature::is_source_feature); 00055 00056 if (!source_feature_data) 00057 { 00058 // else make a new one 00059 TDSourceFeature* new_tool_data = new TDSourceFeature(sourceFeature); 00060 attrib_owner()->add_TD(new_tool_data); 00061 } 00062 00063 delete_attrib(CUBIT_TRUE); 00064 hasActuated = CUBIT_TRUE; 00065 00066 return CUBIT_SUCCESS; 00067 } 00068 00069 CubitStatus CASourceFeature::update() 00070 { 00071 if(hasUpdated) 00072 return CUBIT_SUCCESS; 00073 00074 // set the updated flag 00075 hasUpdated = CUBIT_TRUE; 00076 00077 // if the owner has a unique id, save it, otherwise delete this one 00078 TDSourceFeature *source_feature_data = 00079 (TDSourceFeature *) attrib_owner()->get_TD(&TDSourceFeature::is_source_feature); 00080 00081 if (!source_feature_data) 00082 delete_attrib(CUBIT_TRUE); 00083 else 00084 { 00085 if (delete_attrib() == CUBIT_TRUE) 00086 delete_attrib(CUBIT_FALSE); 00087 00088 sourceFeature = source_feature_data->source_feature(); 00089 } 00090 00091 return CUBIT_SUCCESS; 00092 } 00093 00094 CubitStatus CASourceFeature::reset() 00095 { 00096 sourceFeature = GeometryFeatureEngine::FEATURE_UNDEFINED; 00097 00098 hasUpdated = CUBIT_FALSE; 00099 return CUBIT_SUCCESS; 00100 } 00101 00102 CubitSimpleAttrib CASourceFeature::cubit_simple_attrib() 00103 { 00104 std::vector<CubitString> cs_list; 00105 00106 // pack the string list: 00107 // character type of this CA 00108 cs_list.push_back(att_internal_name()); 00109 00110 // name, option pairs 00111 cs_list.push_back(feature_type_to_string(sourceFeature)); 00112 00113 return CubitSimpleAttrib(&cs_list, NULL, NULL); 00114 } 00115 00116 00117 void CASourceFeature::print() 00118 { 00119 // print info on this attribute 00120 PRINT_INFO("CASourceFeature: owner = %s %d; feature: ", 00121 attribOwnerEntity->class_name(), attribOwnerEntity->id()); 00122 PRINT_INFO("%s ", feature_type_to_string(sourceFeature).c_str()); 00123 00124 PRINT_INFO("\n"); 00125 } 00126 00127 GeometryFeatureEngine::FeatureType 00128 CASourceFeature::string_to_feature_type(CubitString value_in) 00129 { 00130 /* 00131 FEATURE_UNDEFINED, 00132 FEATURE_HOLE, 00133 FEATURE_ROUND, 00134 FEATURE_CHAMFER, 00135 FEATURE_SLOT , 00136 FEATURE_CUT, 00137 FEATURE_IMPRINT 00138 */ 00139 if(value_in == "IMPRINT") 00140 return GeometryFeatureEngine::FEATURE_IMPRINT; 00141 else if(value_in == "HOLE") 00142 return GeometryFeatureEngine::FEATURE_HOLE; 00143 else if(value_in == "ROUND") 00144 return GeometryFeatureEngine::FEATURE_ROUND; 00145 else if(value_in == "CHAMFER") 00146 return GeometryFeatureEngine::FEATURE_CHAMFER; 00147 else if(value_in == "SLOT") 00148 return GeometryFeatureEngine::FEATURE_SLOT; 00149 else if(value_in == "CUT") 00150 return GeometryFeatureEngine::FEATURE_CUT; 00151 else 00152 return GeometryFeatureEngine::FEATURE_UNDEFINED; 00153 } 00154 00155 // returning a cubit simple attribute string for the input feature type 00156 CubitString 00157 CASourceFeature::feature_type_to_string(GeometryFeatureEngine::FeatureType type_in) 00158 { 00159 switch(type_in) 00160 { 00161 case GeometryFeatureEngine::FEATURE_IMPRINT: 00162 return "IMPRINT"; 00163 case GeometryFeatureEngine::FEATURE_HOLE: 00164 return "HOLE"; 00165 case GeometryFeatureEngine::FEATURE_ROUND: 00166 return "ROUND"; 00167 case GeometryFeatureEngine::FEATURE_CHAMFER: 00168 return "CHAMFER"; 00169 case GeometryFeatureEngine::FEATURE_SLOT: 00170 return "SLOT"; 00171 case GeometryFeatureEngine::FEATURE_CUT: 00172 return "CUT"; 00173 default: 00174 return ""; 00175 } 00176 }