cgma
GeometryFeatureTool.cpp
Go to the documentation of this file.
00001 // *** BEGIN INCLUDES *** //
00002 #include "GeometryFeatureTool.hpp"
00003 #include "Body.hpp"
00004 #include "RefEntityFactory.hpp"
00005 #include "TopologyEntity.hpp"
00006 #include "CastTo.hpp"
00007 #include "RefFace.hpp"
00008 #include "BasicTopologyEntity.hpp"
00009 #include "TDSourceFeature.hpp"
00010 // *** END INCLUDES *** //
00011 
00012 GeometryFeatureTool* GeometryFeatureTool::instance_ = 0;
00013 
00014 // *** BEGIN PUBLIC FUNCTIONS *** //
00015 GeometryFeatureTool* GeometryFeatureTool::instance( GeometryFeatureEngine *GFEPtr )
00016 {
00017    // Check to see if we have created an instance of the class;
00018    // if not, proceed to create one.
00019    if (instance_ == 0)
00020    {
00021       // When creating the instance, we should always have a valid
00022       // gfePtr. If not, complain.
00023       instance_ = new GeometryFeatureTool(GFEPtr);
00024 
00025       // Check to make sure there's a ref entity factory extant:
00026       // RefEntityFactory *factory =
00027       RefEntityFactory::instance();
00028    }
00029    // If there is an existing instance of the class, check if there
00030    // is a request to set the default engine. If so, do so.
00031    else if ( GFEPtr != NULL && !instance_->gfeList.move_to(GFEPtr) )
00032    {
00033       delete instance_->gfeList.remove();
00034       instance_->gfeList.insert(GFEPtr);
00035    }
00036 
00037    // Return the a pointer to the instance of the class.
00038    return instance_;
00039 }
00040 
00041 GeometryFeatureTool::~GeometryFeatureTool()
00042 {
00043    for (int i = gfeList.size(); i > 0; i--)
00044       delete gfeList.get_and_step();
00045 
00046    gfeList.clean_out();
00047    instance_ = NULL;
00048 }
00049 
00050 // *** BEGIN ENGINE OPERATIONS *** //
00051 void GeometryFeatureTool::add_gfe( GeometryFeatureEngine *gfe_ptr )
00052 {
00053    assert(gfe_ptr != 0);
00054 
00055    if (!gfeList.move_to(gfe_ptr))
00056       gfeList.append(gfe_ptr);
00057 }
00058 
00059 GeometryFeatureEngine* GeometryFeatureTool::get_engine( TopologyBridge *tb_ptr ) const
00060 {
00061   GeometryFeatureEngine *gfe;
00062 
00063   for (int i = 0; i < gfeList.size(); i++)
00064   {
00065     gfe = gfeList.next(i);
00066     if (gfe->is_feature_engine(tb_ptr))
00067        return gfe;
00068   }
00069 
00070   return NULL;
00071 }
00072 
00073 GeometryFeatureEngine* GeometryFeatureTool::get_engine( TopologyEntity *te_ptr ) const
00074 {
00075   GeometryFeatureEngine *gfe;
00076 
00077   TopologyBridge *tb_ptr = te_ptr->bridge_manager()->topology_bridge();
00078 
00079   for (int i = 0; i < gfeList.size(); i++)
00080   {
00081     gfe = gfeList.next(i);
00082     if (gfe->is_feature_engine(tb_ptr))
00083        return gfe;
00084   }
00085 
00086   return NULL;
00087 }
00088 
00089 CubitBoolean GeometryFeatureTool::same_feature_engine( DLIList<RefEntity*> &ref_entity_list,
00090                                                            CubitBoolean check_children ) const
00091 {
00092    DLIList<RefEntity*> complete_entity_list;
00093 
00094    //Check the check_children option and check all the children if necessary
00095    if (check_children)
00096    {
00097       //Make a complete list of all the RefEntities and their children
00098       DLIList<RefEntity*> temp = ref_entity_list;
00099       RefEntity* ref_entity_ptr;
00100 
00101       for (int i = 0; i < ref_entity_list.size(); i++)
00102       {
00103          ref_entity_ptr = ref_entity_list.get_and_step();
00104          complete_entity_list.clean_out();
00105          ref_entity_ptr->get_all_child_ref_entities(complete_entity_list);
00106          temp += complete_entity_list;
00107       }
00108 
00109       complete_entity_list.clean_out();
00110       complete_entity_list.merge_unique(temp);
00111    }
00112 
00113    //Now make sure all the RefEntities are from the same geometry engine
00114    DLIList<TopologyEntity*> te_list;
00115    CAST_LIST(complete_entity_list, te_list, TopologyEntity);
00116    return same_feature_engine(te_list);
00117 }
00118 
00119 CubitBoolean GeometryFeatureTool::same_feature_engine( DLIList<TopologyEntity*> &topo_list ) const
00120 {
00121    GeometryFeatureEngine *gePtr1 = get_engine(topo_list.get_and_step());
00122    GeometryFeatureEngine *gePtr2;
00123 
00124    for (int i = 1; i < topo_list.size(); i++)
00125    {
00126       gePtr2 = get_engine(topo_list.get_and_step());
00127       if (gePtr1 != gePtr2)
00128       {
00129          return CUBIT_FALSE;
00130       }
00131    }
00132    return CUBIT_TRUE;
00133 }
00134 
00135 // *** END ENGINE OPERATIONS *** //
00136 
00137 // *** BEGIN FEATURE FUNCTIONS *** //
00138 
00139 GeometryFeatureEngine::FeatureType
00140 GeometryFeatureTool::feature_type(BasicTopologyEntity* bte)
00141 {
00142     // first check to see if the feature information is in the tool data
00143     TDSourceFeature *tdss = 0;
00144     tdss = (TDSourceFeature *)bte->
00145         get_TD(&TDSourceFeature::is_source_feature);
00146 
00147     if(tdss)
00148         return tdss->source_feature();
00149 
00150     // if the feature information is not in the tool data 
00151     // then call the engine specific FeatureEngine
00152     TopologyEntity* topo_ptr = CAST_TO(bte, TopologyEntity);
00153 
00154     if (!topo_ptr)
00155         return GeometryFeatureEngine::FEATURE_UNDEFINED;
00156 
00157     GeometryFeatureEngine* gfe = get_engine(topo_ptr);
00158 
00159     if(!gfe)
00160         return GeometryFeatureEngine::FEATURE_UNDEFINED;
00161 
00162     return gfe->feature_type(bte->get_geometry_entity_ptr());
00163 }
00164 
00165 CubitStatus GeometryFeatureTool::get_related_by_feature(
00166     BasicTopologyEntity* bte,
00167     DLIList<GeometryEntity*>& return_list)
00168 {
00169     TopologyEntity* topo_ptr = CAST_TO(bte, TopologyEntity);
00170 
00171     if (!topo_ptr)
00172         return CUBIT_FAILURE;
00173 
00174     GeometryFeatureEngine* gfe = get_engine(topo_ptr);
00175 
00176     if(!gfe)
00177         return CUBIT_FAILURE;
00178 
00179     return gfe->get_related_by_feature(bte->get_geometry_entity_ptr(),return_list);
00180 }
00181 
00182 DLIList<GeometryFeatureEngine::FeatureType> 
00183 GeometryFeatureTool::available_feature_types(BasicTopologyEntity* bte)
00184 {
00185     TopologyEntity* topo_ptr = CAST_TO(bte, TopologyEntity);
00186     DLIList<GeometryFeatureEngine::FeatureType> null_list;
00187     if (!topo_ptr)
00188         return null_list;
00189 
00190     GeometryFeatureEngine* gfe = get_engine(topo_ptr);
00191 
00192     if(!gfe)
00193         return null_list;
00194 
00195     return gfe->available_feature_types(bte->get_geometry_entity_ptr());
00196 }
00197 
00198 // *** END PUBLIC FUNCTIONS *** //
00199 
00200 // *** BEGIN PROTECTED FUNCTIONS *** //
00201 
00202 GeometryFeatureTool::GeometryFeatureTool( GeometryFeatureEngine* GFEPtr )
00203 {
00204   if (GFEPtr != NULL)
00205      add_gfe(GFEPtr);
00206 }
00207 
00208 // *** END PROTECTED FUNCTIONS *** //
00209 
00210 // *** BEGIN PRIVATE FUNCTIONS *** //
00211 
00212 // *** END PRIVATE FUNCTIONS *** //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines