cgma
CAEntityTol.cpp
Go to the documentation of this file.
00001 //- File:           CAEntityTol.cpp
00002 //- Owner:          W. Roshan Quadros
00003 //- Description:    Cubit Attribute for entity ids.
00004 //- Checked By:
00005 //- Version:
00006 
00007 
00008 #include "CAEntityTol.hpp"
00009 #include "CAMergePartner.hpp"
00010 #include "TDUniqueId.hpp"
00011 #include "TopologyBridge.hpp"
00012 #include "RefEntity.hpp"
00013 #include "RefVertex.hpp"
00014 #include "RefEdge.hpp"
00015 #include "RefFace.hpp"
00016 #include "CastTo.hpp"
00017 #include "MergeTool.hpp"
00018 #include "RefEntityFactory.hpp"
00019 #include "GeometryQueryTool.hpp"
00020 #include "GSaveOpen.hpp"
00021 #include "CADeferredAttrib.hpp"
00022 #include "BasicTopologyEntity.hpp"
00023 #include "GeometryEntity.hpp"
00024 
00025 CubitAttrib* CAEntityTol_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
00026 {
00027     return new CAEntityTol(entity, p_csa);
00028 }
00029 
00030 CAEntityTol::CAEntityTol(RefEntity* new_attrib_owner,
00031                        const CubitSimpleAttrib &csa_ptr)
00032         : CubitAttrib(new_attrib_owner)
00033 {
00034   entityTol = 0.0;
00035   if(!csa_ptr.isEmpty())
00036   {
00037    PRINT_DEBUG_95( "Creating ENTITY_TOL attribute from CSA for %s %d\n",
00038       (attribOwnerEntity ? attribOwnerEntity->class_name() : "(none)"),
00039       (attribOwnerEntity ? attribOwnerEntity->id() : 0));
00040    
00041    const std::vector<double>& d_list = csa_ptr.double_data_list();
00042 
00043    assert(d_list.size() == 1);
00044    entityTol =  d_list[0];
00045   }
00046 }
00047 
00048 CAEntityTol::CAEntityTol(RefEntity* new_attrib_owner)
00049         : CubitAttrib(new_attrib_owner)
00050 {
00051   entityTol = 0.0;
00052     
00053   PRINT_DEBUG_95( "Creating ENTITY_TOL attribute for %s %d\n",
00054               (attribOwnerEntity ? attribOwnerEntity->class_name() : "(none)"),
00055               (attribOwnerEntity ? attribOwnerEntity->id() : 0));
00056 }
00057 
00058 CAEntityTol::~CAEntityTol()
00059 {
00060 }
00061 
00062 CubitStatus CAEntityTol::reset()
00063 {
00064 
00065   return CUBIT_SUCCESS;
00066 }
00067 
00068 CubitStatus CAEntityTol::actuate()
00069 {
00070    if ( hasActuated)
00071       return CUBIT_SUCCESS;
00072    
00073    if ( !attribOwnerEntity )
00074       return CUBIT_FAILURE;
00075    
00076    deleteAttrib = CUBIT_FALSE;
00077    
00078    //- If actuating after import, change the tol.  Else (auto actuated) tol is already changed...
00079    if( attribOwnerEntity->local_tolerance() == 0.0 )
00080    {
00081       attribOwnerEntity->local_tolerance(entityTol);
00082    }
00083    
00084    hasActuated = CUBIT_TRUE;
00085    return CUBIT_SUCCESS;
00086 }
00087 
00088 CubitStatus CAEntityTol::update()
00089 {
00090   //delete_attrib(CUBIT_TRUE);
00091   //return CUBIT_SUCCESS;
00092 
00093   if (hasUpdated) return CUBIT_SUCCESS;
00094   
00095   PRINT_DEBUG_95( "Updating ENTITY_TOL attribute for %s %d\n",
00096               attribOwnerEntity->class_name(), attribOwnerEntity->id());
00097 
00098     // set the updated flag
00099   hasUpdated = CUBIT_TRUE;
00100 
00101     // first, remove this attrib in its old form from the geometry entity
00102   if (hasWritten == CUBIT_TRUE) 
00103   {
00104     attribOwnerEntity->remove_attrib_geometry_entity(this);
00105     hasWritten = CUBIT_FALSE;
00106   }
00107   
00108   double local_tol = attribOwnerEntity->local_tolerance();
00109   if( local_tol == 0.0)
00110   {
00111     delete_attrib(CUBIT_TRUE);
00112     return CUBIT_SUCCESS;
00113   }
00114   else
00115   {
00116          
00117     // reset the delete flag if it was set before
00118     delete_attrib(CUBIT_FALSE);
00119     
00120       // now, write to geometry entity
00121     entityTol = local_tol;
00122     attribOwnerEntity->write_specific_cubit_attrib(this);
00123   }
00124   return CUBIT_SUCCESS;
00125 }
00126 
00127 void CAEntityTol::merge_owner(CubitAttrib *deletable_attrib)
00128 {
00129     // take the id with the lowest value
00130   CAEntityTol *other_ca_tol = CAST_TO(deletable_attrib, CAEntityTol);
00131   
00132   if (other_ca_tol && ( entityTol == 0.0 || entityTol < other_ca_tol->tolerance() ))
00133     entityTol = other_ca_tol->tolerance();
00134 }
00135 
00136 CubitSimpleAttrib CAEntityTol::cubit_simple_attrib()
00137 {
00138   std::vector<CubitString> cs_list;
00139   std::vector<double> d_list;
00140   std::vector<int, std::allocator<int> > i_list;
00141 
00142   d_list.push_back ( entityTol );
00143 
00144   cs_list.push_back(att_internal_name());
00145 
00146   CubitSimpleAttrib csattrib_ptr(&cs_list, &d_list, &i_list);
00147  
00148   return csattrib_ptr;
00149 }
00150 
00151 void CAEntityTol::print()
00152 {
00153     // print info on this attribute
00154   
00155   PRINT_INFO("CAEntityTol: owner = %s %d:  tolerance =%f\n",
00156              attribOwnerEntity->class_name(), attribOwnerEntity->id(),
00157              entityTol);
00158 }
00159 
00160 
00161 CubitSimpleAttrib CAEntityTol::split_owner()
00162 {
00163     // if this entity is to be split, pass back a simple attribute with
00164     // duplicate tol data to be put on new entity
00165   PRINT_DEBUG_95("CAEntityName::split_owner()\n");
00166   update();
00167   return cubit_simple_attrib();
00168 }
00169 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines