cgma
ModelQueryEngine.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Copyright Notice
00003 //
00004 // Copyright (c) 1996 
00005 // by Malcolm J. Panthaki, DBA, and the University of New Mexico.
00006 //-------------------------------------------------------------------------
00007 
00008 //-------------------------------------------------------------------------
00009 //
00010 // Filename      : ModelQueryEngine.C 
00011 //
00012 // Purpose       : This file contains the implementation of the class 
00013 //                 ModelQueryEngine.
00014 //
00015 // Special Notes : 
00016 //
00017 // Creator       : Xuechen Liu 
00018 //
00019 // Creation Date : 06/08/96
00020 //
00021 // Owner         : Malcolm J. Panthaki
00022 //-------------------------------------------------------------------------
00023 
00024 // ********** BEGIN STANDARD INCLUDES      **********
00025 
00026 #include <stdio.h>
00027 
00028 // ********** END STANDARD INCLUDES        **********
00029 
00030 // ********** BEGIN MOTIF INCLUDES         **********
00031 // ********** END MOTIF INCLUDES           **********
00032 
00033 // ********** BEGIN OPEN INVENTOR INCLUDES **********
00034 // ********** END OPEN INVENTOR INCLUDES   **********
00035 
00036 // ********** BEGIN CUBIT INCLUDES         **********
00037 
00038 #include "CubitMessage.hpp"
00039 #include "ModelQueryEngine.hpp"
00040 #include "TopologyEntity.hpp"
00041 #include "DLIList.hpp"
00042 #include "CastTo.hpp"
00043 #include "RefVertex.hpp"
00044 #include "CoVertex.hpp"
00045 #include "Chain.hpp"
00046 #include "RefEdge.hpp"
00047 #include "CoEdge.hpp"
00048 #include "Loop.hpp"
00049 #include "RefFace.hpp"
00050 #include "CoFace.hpp"
00051 #include "Shell.hpp"
00052 #include "Body.hpp"
00053 #include "CoVolume.hpp"
00054 // ********** END CUBIT INCLUDES           **********
00055 
00056 // ********** BEGIN STATIC DECLARATIONS    **********
00057 
00058 ModelQueryEngine* ModelQueryEngine::instance_ = NULL;
00059 
00060 // ********** END STATIC DECLARATIONS      **********
00061 
00062 // ********** BEGIN PUBLIC FUNCTIONS       **********
00063 
00064 //-------------------------------------------------------------------------
00065 // Purpose       : Controls the access and creation of the sole instance
00066 //                 of this class.
00067 //
00068 // Special Notes :
00069 //
00070 // Creator       : Xuechen Liu 
00071 //
00072 // Creation Date : 06/08/96
00073 //-------------------------------------------------------------------------
00074 ModelQueryEngine* ModelQueryEngine::instance()
00075 {
00076   if (instance_ == NULL)
00077   {
00078     instance_ = new ModelQueryEngine;
00079   }
00080   return instance_;
00081 }
00082 
00083 //-------------------------------------------------------------------------
00084 // Purpose       : Destructor of the ModelQueryEngine class. 
00085 //
00086 // Special Notes :
00087 //
00088 // Creator       : Xuechen Liu 
00089 //
00090 // Creation Date : 06/08/96
00091 //-------------------------------------------------------------------------
00092 ModelQueryEngine::~ModelQueryEngine()
00093 {
00094    // Set static instance_ to zero to indicated that we are dead.
00095    instance_ = NULL;
00096 }
00097 
00098 
00099 // ********** END PUBLIC FUNCTIONS         **********
00100 
00101 // ********** BEGIN PROTECTED FUNCTIONS    **********
00102 
00103 //-------------------------------------------------------------------------
00104 // Purpose       : Constructor of the ModelQueryEngine class. 
00105 //
00106 // Special Notes :
00107 //
00108 // Creator       : Xuechen Liu 
00109 //
00110 // Creation Date : 06/08/96
00111 //-------------------------------------------------------------------------
00112 ModelQueryEngine::ModelQueryEngine() : queryCallStackDepth(0)
00113 {
00114 }
00115 
00116 
00117 //-------------------------------------------------------------------------
00118 // Purpose       : Query model
00119 //
00120 // Special Notes : 
00121 //
00122 // Creator       : Jason Kraftcheck
00123 //
00124 // Creation Date : 07/29/03
00125 //-------------------------------------------------------------------------
00126 CubitStatus ModelQueryEngine::query_model_and_append( 
00127                                           TopologyEntity& source_object,
00128                                           DagType target_type,
00129                                           DLIList<TopologyEntity*>& result_set )
00130 {
00131   BeginQuery lock;
00132   
00133   DagType source_type = source_object.dag_type();
00134 
00135   if (!source_type.is_valid() || !target_type.is_valid())
00136     return CUBIT_FAILURE;
00137 
00138   else if (source_type < target_type)
00139     return query_append_parents( source_object, target_type, result_set );
00140 
00141   else if (source_type > target_type)
00142     return query_append_children( source_object, target_type, result_set );  
00143 
00144   else // same type
00145   {
00146     assert(source_type == target_type);
00147     if (!encountered(&source_object))
00148       result_set.append(&source_object);
00149     return CUBIT_SUCCESS;
00150   }
00151 }
00152 
00153 
00154 //-------------------------------------------------------------------------
00155 // Purpose       : Query model
00156 //
00157 // Special Notes : 
00158 //
00159 // Creator       : Jason Kraftcheck
00160 //
00161 // Creation Date : 07/29/03
00162 //-------------------------------------------------------------------------
00163 CubitStatus ModelQueryEngine::query_model( 
00164                                           TopologyEntity& source_object,
00165                                           DagType target_type,
00166                                           DLIList<TopologyEntity*>& result_set )
00167 {
00168   result_set.clean_out();
00169   return query_model_and_append( source_object, target_type, result_set );
00170 }
00171 
00172 
00173 //-------------------------------------------------------------------------
00174 // Purpose       : Query model
00175 //
00176 // Special Notes : 
00177 //
00178 // Creator       : Jason Kraftcheck
00179 //
00180 // Creation Date : 07/29/03
00181 //-------------------------------------------------------------------------
00182 CubitStatus ModelQueryEngine::query_model( 
00183                                     DLIList<TopologyEntity*>& source_set,
00184                                     DagType target_type,
00185                                     DLIList<TopologyEntity*>& result_set )
00186 {
00187   result_set.clean_out();
00188   return query_model_and_append( source_set, target_type, result_set );
00189 }
00190 
00191 
00192 //-------------------------------------------------------------------------
00193 // Purpose       : Query model
00194 //
00195 // Special Notes : 
00196 //
00197 // Creator       : Jason Kraftcheck
00198 //
00199 // Creation Date : 07/29/03
00200 //-------------------------------------------------------------------------
00201 CubitStatus ModelQueryEngine::query_model_and_append( 
00202                                     DLIList<TopologyEntity*>& source_set,
00203                                     DagType target_type,
00204                                     DLIList<TopologyEntity*>& result_set )
00205 {
00206   BeginQuery lock;
00207   CubitStatus result = CUBIT_SUCCESS;
00208   
00209   source_set.reset();
00210   for (int i = source_set.size(); i--; )
00211   {
00212     TopologyEntity& source = *source_set.get_and_step();
00213     if (!query_model_and_append( source, target_type, result_set ))
00214       result = CUBIT_FAILURE;
00215   }
00216   
00217   return result;
00218 }
00219 
00220 // ********** END PROTECTED FUNCTIONS      **********
00221 
00222 //-------------------------------------------------------------------------
00223 // Purpose       : Query downwards
00224 //
00225 // Special Notes : 
00226 //
00227 // Creator       : Jason Kraftcheck
00228 //
00229 // Creation Date : 07/29/03
00230 //-------------------------------------------------------------------------
00231 CubitStatus ModelQueryEngine::query_append_children ( 
00232                                         TopologyEntity& source_object,
00233                                         DagType target_type,
00234                                         DLIList<TopologyEntity*>& result_set )
00235 {
00236   BeginQuery lock;
00237   
00238   DagType current_type = source_object.dag_type();
00239   assert(current_type.is_valid() && target_type.is_valid());
00240   assert(current_type > target_type);
00241   
00242   intermediateNodeSets[0].clean_out();
00243   intermediateNodeSets[0].append(&source_object);
00244   int current_index = 0;
00245   
00246   while (current_type > target_type)
00247   {
00248     DLIList<TopologyEntity*>& current_set = intermediateNodeSets[ current_index];
00249     DLIList<TopologyEntity*>&    next_set = intermediateNodeSets[!current_index];
00250     
00251     next_set.clean_out();
00252     current_set.reset();
00253     for (int i = current_set.size(); i--; )
00254     {
00255       TopologyEntity* current_ptr = current_set.get_and_step();
00256       current_ptr->query_append_children(next_set);
00257     }
00258 
00259     current_index = !current_index;
00260     current_type--;
00261   }
00262   
00263   result_set += intermediateNodeSets[current_index];
00264   return CUBIT_SUCCESS;
00265 }
00266 
00267 
00268 //-------------------------------------------------------------------------
00269 // Purpose       : Query upwards
00270 //
00271 // Special Notes : 
00272 //
00273 // Creator       : Jason Kraftcheck
00274 //
00275 // Creation Date : 07/29/03
00276 //-------------------------------------------------------------------------
00277 CubitStatus ModelQueryEngine::query_append_parents( 
00278                                         TopologyEntity& source_object,
00279                                         DagType target_type,
00280                                         DLIList<TopologyEntity*>& result_set )
00281 {
00282   BeginQuery lock;
00283   
00284   DagType current_type = source_object.dag_type();
00285   assert(current_type.is_valid() && target_type.is_valid());
00286   assert(current_type < target_type);
00287   
00288   intermediateNodeSets[0].clean_out();
00289   intermediateNodeSets[0].append(&source_object);
00290   int current_index = 0;
00291   
00292   while (current_type < target_type)
00293   {
00294     DLIList<TopologyEntity*>& current_set = intermediateNodeSets[ current_index];
00295     DLIList<TopologyEntity*>&    next_set = intermediateNodeSets[!current_index];
00296     
00297     next_set.clean_out();
00298     current_set.reset();
00299     for (int i = current_set.size(); i--; )
00300     {
00301       TopologyEntity* current_ptr = current_set.get_and_step();
00302       current_ptr->query_append_parents(next_set);
00303     }
00304 
00305     current_index = !current_index;
00306     current_type++;
00307   }
00308   
00309   result_set += intermediateNodeSets[current_index];
00310   return CUBIT_SUCCESS;
00311 }
00312 
00313 //-------------------------------------------------------------------------
00314 // Purpose       : Mark node encountered
00315 //
00316 // Special Notes : 
00317 //
00318 // Creator       : Jason Kraftcheck
00319 //
00320 // Creation Date : 07/24/03
00321 //-------------------------------------------------------------------------
00322 bool ModelQueryEngine::encountered( TopologyEntity* node_ptr )
00323 {
00324   if (node_ptr->encountered_)
00325     return true;
00326   
00327   encounteredSet.append(node_ptr);
00328   node_ptr->encountered_ = true;
00329   return false;
00330 }
00331 
00332 void ModelQueryEngine::inc_query_call_stack()
00333 {
00334   queryCallStackDepth++;
00335 }
00336 
00337 void ModelQueryEngine::dec_query_call_stack()
00338 {
00339   assert(queryCallStackDepth > 0);
00340   queryCallStackDepth--;
00341   if (queryCallStackDepth == 0)
00342     while (encounteredSet.size())
00343       encounteredSet.pop()->encountered_ = CUBIT_FALSE;
00344 }
00345 
00346 // ********** BEGIN PRIVATE FUNCTIONS      **********
00347 // ********** END PRIVATE FUNCTIONS        **********
00348  
00349 // ********** BEGIN HELPER CLASSES         **********
00350 // ********** END HELPER CLASSES           **********
00351  
00352 // ********** BEGIN EXTERN FUNCTIONS       **********
00353 // ********** END EXTERN FUNCTIONS         **********
00354  
00355 // ********** BEGIN STATIC FUNCTIONS       **********
00356 // ********** END STATIC FUNCTIONS         **********
00357  
00358 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines