cgma
VirtualQueryEngine.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : VirtualQueryEngine.cc 
00003 //
00004 // Purpose       : This file contains the implementation of the class 
00005 //                 VirtualQueryEngine. 
00006 //
00007 // Special Notes : There are several functions in this class which are 
00008 //                 inhereted from GeometryQueryEngine that are not
00009 //                 implemented or applicable in this class.  These
00010 //                 functions, if called, will print an error message
00011 //                 and return the most appropriate error condition available.
00012 //
00013 // Creator       : Jason Kraftcheck
00014 //
00015 // Creation Date : 08/01/97 
00016 //-------------------------------------------------------------------------
00017 
00018 // ********** BEGIN STANDARD INCLUDES      **********
00019 #include <assert.h>
00020 // ********** END STANDARD INCLUDES        **********
00021 
00022 // ********** BEGIN CUBIT INCLUDES         **********
00023 
00024 #include "VirtualQueryEngine.hpp"
00025 #include "CompositeTool.hpp"
00026 #include "PartitionTool.hpp"
00027 #include "CompositeEngine.hpp"
00028 #include "PartitionEngine.hpp"
00029 #include "GeometryUtil.hpp"
00030 
00031 #include "CubitDefines.h"
00032 #include "GeometryDefines.h"
00033 #include "CubitVector.hpp"
00034 
00035 #include "CastTo.hpp"
00036 #include "GMem.hpp"
00037 
00038 #include "ModelQueryEngine.hpp"
00039 #include "AppUtil.hpp"
00040 
00041 #include "Body.hpp"
00042 #include "CoVolume.hpp"
00043 #include "RefVolume.hpp"
00044 #include "RefFace.hpp"
00045 #include "Loop.hpp"
00046 #include "CoEdge.hpp"
00047 #include "RefEdge.hpp"
00048 #include "Chain.hpp"
00049 #include "CoVertex.hpp"
00050 #include "RefVertex.hpp"
00051 #include "RefEntityFactory.hpp"
00052 #include "CoFace.hpp"
00053 
00054 
00055 #include "CompositePoint.hpp"
00056 #include "CompositeCurve.hpp"
00057 #include "CompositeSurface.hpp"
00058 #include "CompositeLump.hpp"
00059 #include "CompositeBody.hpp"
00060 #include "PartitionBody.hpp"
00061 #include "PartitionLump.hpp"
00062 #include "PartitionSurface.hpp"
00063 #include "PartitionCurve.hpp"
00064 
00065 
00066 #include "Shell.hpp"
00067 #include "GeometryQueryTool.hpp"
00068 #include "CubitPointData.hpp"
00069 #include "CubitFacetData.hpp"
00070 #include "CubitFacetEdgeData.hpp"
00071 
00072 #include "CACompositeVG.hpp"
00073 #include "CAPartitionVG.hpp"
00074 #include "CAVirtualVG.hpp"
00075 
00076 #include "HiddenEntitySet.hpp"
00077 #include "SubEntitySet.hpp"
00078 
00079 // ********** END CUBIT INCLUDES           **********
00080 
00081 // ********** BEGIN STATIC DECLARATIONS    **********
00082 VirtualQueryEngine* VirtualQueryEngine::instance_ = NULL; 
00083 //- A pointer to the single instance of this class
00084 
00085 
00086 const int VirtualQueryEngine::VGE_MAJOR_VERSION = 10;
00087 const int VirtualQueryEngine::VGE_MINOR_VERSION = 0;
00088 const int VirtualQueryEngine::VGE_SUBMINOR_VERSION = 0;
00089 
00090 const double VirtualQueryEngine::param_epsilon_fraction = 1000000;
00091 //- This value is used to determine epsilon for
00092 //- compensating for rounding error in parameter
00093 //- conversion between virtaul geometry and real
00094 //- geometry.
00095 
00096 // ********** END STATIC DECLARATIONS      **********
00097 
00098 // ********** BEGIN PUBLIC FUNCTIONS       **********
00099 
00100 //-------------------------------------------------------------------------
00101 // Purpose   : Destructor
00102 //
00103 // Special Notes :
00104 //
00105 // Creator   : Jason Kraftcheck
00106 //
00107 // Creation Date : 08/01/97
00108 //-------------------------------------------------------------------------
00109 VirtualQueryEngine::~VirtualQueryEngine( )
00110 {
00111 //  destroy_all_virtual_entities();
00112 //  if( virtual_entity_list_.size() )
00113 //      PRINT_WARNING("Not all virtual geometry has been removed.  "
00114 //                    "This is a bug (memory leak).  Please report it.\n");
00115 //  assert( virtual_entity_list_.size() == 0 );
00116 
00117   PartitionEngine::delete_instance();
00118   CompositeEngine::delete_instance();
00119 
00120   instance_ = NULL;
00121 }
00122 
00123 void VirtualQueryEngine::delete_instance()
00124 {
00125   if( NULL != instance_ )
00126   {
00127     delete instance_;
00128     instance_ = NULL;
00129   }
00130 }    
00131 
00132 
00133 //-------------------------------------------------------------------------
00134 // Purpose   : Return a description of this ModelingEngine
00135 //
00136 // Special Notes :
00137 //
00138 // Creator   : Jason Kraftcheck
00139 //
00140 // Creation Date : 08/01/97
00141 //-------------------------------------------------------------------------
00142 int VirtualQueryEngine::get_major_version()
00143 {
00144   return VGE_MAJOR_VERSION;
00145 }
00146 
00147 int VirtualQueryEngine::get_minor_version()
00148 {
00149   return VGE_MINOR_VERSION;
00150 }
00151 
00152 int VirtualQueryEngine::get_subminor_version()
00153 {
00154   return VGE_SUBMINOR_VERSION;
00155 }
00156 
00157 CubitString VirtualQueryEngine::get_engine_version_string()
00158 {
00159   CubitString return_this(
00160     "VirtualQueryEngine v1.2 by Jason Kraftcheck.\n" );
00161   return_this += "I-CARVE Lab., University of Wisconsin - Madison,  August 1, 1997.\n";
00162   return_this += "This ModelingEngine performs the necessary topological ";
00163   return_this += "operations for working with VirtualEntities, including ";
00164   return_this += "objects of type CompositeEntity, PartitionEntity, and ";
00165   return_this += "ParasiteEntity.  ComposinteModelingEngine also ";
00166   return_this += "provides the interface for creating, destroying, and ";
00167   return_this += "modifying VirtualEntities.\n";
00168   
00169   return return_this;
00170 }
00171 
00172 CubitStatus VirtualQueryEngine::transform_vec_position(
00173   CubitVector const& ,
00174   BodySM *,
00175   CubitVector & ) const
00176 {
00177   return CUBIT_FAILURE;
00178 }
00179 
00180 //This is only for partition surfaces!!!!!!!!!!!!!!!!!!
00181 CubitStatus VirtualQueryEngine::get_graphics( Surface* surf_ptr,
00182                                               GMem *gmem,
00183                                               std::vector<TopologyBridge*> &vertex_edge_to_point_vector,
00184                                               std::vector<std::pair<TopologyBridge*, std::pair<int,int> > > &facet_edges_on_curves,
00185                                               unsigned short normal_tol, 
00186                                               double dist_tol, 
00187                                               double max_edge_length ) const
00188 {
00189   PartitionSurface* ps_ptr = CAST_TO(surf_ptr, PartitionSurface );
00190   if( ps_ptr != NULL )
00191   {
00192     return get_partition_surface_facetting( ps_ptr, gmem, &vertex_edge_to_point_vector, &facet_edges_on_curves,
00193                                             normal_tol, dist_tol, max_edge_length );
00194   }
00195   
00196   CompositeSurface* cs_ptr = CAST_TO(surf_ptr, CompositeSurface );
00197   if( cs_ptr != NULL )
00198   {
00199     return get_composite_surface_facetting( cs_ptr, gmem, &vertex_edge_to_point_vector, &facet_edges_on_curves,
00200                                             normal_tol, dist_tol, max_edge_length );
00201   }
00202     //PRINT_INFO("VirtualQueryEngine::get_graphics_facets"
00203     //           "( s%p, %p, %d, %f ) = CUBIT_FAILURE\n",
00204     //           surf_ptr, gmem, normal_tol, dist_tol);
00205   return CUBIT_FAILURE;
00206 }
00207 
00208 
00209 
00210 //-------------------------------------------------------------------------
00211 // Purpose       : This function determines faceting information for use
00212 //                   by HOOPS.
00213 //
00214 // Special Notes : 
00215 //
00216 // Creator       : Jason Kraftcheck
00217 //
00218 // Creation Date : 
00219 //-------------------------------------------------------------------------
00220 CubitStatus VirtualQueryEngine::get_graphics(
00221   Surface* surf_ptr, 
00222   GMem* gMem,
00223   unsigned short normal_tol,
00224   double dist_tol,
00225   double max_edge_length ) const
00226 {
00227   CompositeSurface* cs_ptr = CAST_TO(surf_ptr, CompositeSurface );
00228   PartitionSurface* ps_ptr = CAST_TO(surf_ptr, PartitionSurface );
00229   if( cs_ptr != NULL )
00230   {
00231     return get_composite_surface_facetting( cs_ptr, gMem, NULL, NULL,
00232                                             normal_tol, dist_tol, max_edge_length );
00233   }
00234   else if( ps_ptr != NULL )
00235   {
00236     return get_partition_surface_facetting( ps_ptr, gMem, NULL, NULL,
00237                                             normal_tol, dist_tol, max_edge_length );
00238   }
00239   else
00240   {
00241     PRINT_INFO("VirtualQueryEngine::get_graphics_facets"
00242                "( s%p, %p, %d, %f ) = CUBIT_FAILURE\n",
00243                (void*)surf_ptr, (void*)gMem, normal_tol, dist_tol);
00244     return CUBIT_FAILURE;
00245   }
00246 }
00247 
00248 //-----------------------------------------------------------------------
00249 // Purpose   : This function returns the necessary faceting information
00250 //         to display the curve.
00251 //
00252 // Special Notes :
00253 //
00254 // Creator   : Jason Kraftcheck
00255 //
00256 // Creation Date : 10/10/97
00257 //-----------------------------------------------------------------------
00258 CubitStatus VirtualQueryEngine::get_graphics( Curve* curve_ptr,
00259                                               GMem* gMem,
00260                                               double angle_tolerance, 
00261                                               double distance_tolerance, 
00262                                               double max_edge_length ) const
00263 {
00264   CompositeCurve* ccurve = CAST_TO( curve_ptr, CompositeCurve );
00265   PartitionCurve* pcurve = CAST_TO( curve_ptr, PartitionCurve );
00266   
00267   CubitStatus result;
00268   
00269   if( ccurve != NULL )
00270   {
00271     result = get_composite_curve_facetting( ccurve, gMem, angle_tolerance, 
00272                                           distance_tolerance, max_edge_length );
00273   }
00274   else if( pcurve != NULL )
00275   {
00276     result = get_partition_curve_facetting( pcurve, gMem, angle_tolerance, 
00277                                           distance_tolerance, max_edge_length );
00278   }
00279   else
00280   {
00281     PRINT_ERROR("Unknown curve type or NULL curve passed to "
00282                 "VirtualQueryEngine::get_graphics_edges()\n");
00283     return CUBIT_FAILURE;
00284   }
00285   
00286   return result;
00287 }
00288 
00289 // This is the template for an unimplemented version of this function.
00290 CubitStatus VirtualQueryEngine::get_isoparametric_points(Surface*,
00291                                                             int &nu, int &nv,
00292                                                             GMem*& ) const
00293 {
00294   nu = nv = 0;
00295   return CUBIT_FAILURE;
00296 }
00297 
00298 // This is the template for an unimplemented version of this function.
00299 CubitStatus VirtualQueryEngine::get_u_isoparametric_points(Surface*,
00300                                                             double , int& ,
00301                                                             GMem*& ) const
00302 {
00303   return CUBIT_FAILURE;
00304 }
00305 
00306 // This is the template for an unimplemented version of this function.
00307 CubitStatus VirtualQueryEngine::get_v_isoparametric_points(Surface*,
00308                                                             double , int& ,
00309                                                             GMem*&) const
00310 {
00311   return CUBIT_FAILURE;
00312 }
00313 
00314 //-----------------------------------------------------------------------
00315 // Purpose   : This function constructs the edge facetting information
00316 //         of a CompositeCurve for use by HOOPS.
00317 //
00318 // Special Notes :
00319 //
00320 // Creator   : Jason Kraftcheck
00321 //
00322 // Creation Date : 10/10/97
00323 //-----------------------------------------------------------------------
00324 CubitStatus VirtualQueryEngine::get_composite_curve_facetting(
00325                                     CompositeCurve* ccurve_ptr,
00326                                     GMem* gMem, 
00327                                     double angle_tolerance,
00328                                     double distance_tolerance,
00329                                     double max_edge_length ) const
00330 {
00331     // Just return if gMem is NULL
00332   if (gMem == NULL)
00333   {
00334     return CUBIT_SUCCESS;
00335   }
00336   
00337   GMem current_gmem; 
00338   int point_count = 0; //Current total of points returned
00339     // from underlying edges
00340   
00341   int next_index = 0; //index of next insert spot in passed GMem object.
00342   
00343     //Get points for each underlying curve
00344   current_gmem.clean_out();
00345   for( int i = 0; i < ccurve_ptr->num_curves(); i++ )
00346   {
00347       // Get the next curve and its GME
00348     Curve* curve_ptr = ccurve_ptr->get_curve(i);
00349     GeometryQueryEngine* GQE_ptr = 
00350       curve_ptr->get_geometry_query_engine();
00351     
00352       // Get the GME to facet the curve
00353     CubitStatus current_status = 
00354       GQE_ptr->get_graphics( curve_ptr, &current_gmem, angle_tolerance,
00355                               distance_tolerance, max_edge_length );
00356     if( current_status == CUBIT_FAILURE )
00357       return CUBIT_FAILURE;
00358     
00359     int this_point_count = current_gmem.pointListCount;
00360       
00361     // Make sure the passed in gmem is big enough
00362     gMem->allocate_more_polylines(this_point_count-1);
00363       //assert( gMem->pts_size >= point_count );
00364     
00365       // If this isn't the first curve, we don't need to
00366       // repeat one of the end nodes.
00367     if (point_count != 0)
00368       this_point_count--;
00369       // Add to the total number of points so far
00370     point_count += this_point_count;
00371     
00372       //Copy points to passed GMem, in the correct order
00373       //for the sense of the underlying edge wrt the
00374       //composite.
00375     CubitSense sense = ccurve_ptr->get_sense( i );
00376     
00377     if( sense == CUBIT_FORWARD )
00378     {
00379       if (next_index == 0)
00380         for(int j = 0; j < point_count; j++)
00381         {
00382           gMem->point_list()[j] = current_gmem.point_list()[j];
00383         }
00384       else
00385           // cur_gmem has one more point than we will access,
00386           // so last index is point_count-next_index.
00387         for(int j = next_index; j < point_count; j++)
00388         {
00389           gMem->point_list()[j] = current_gmem.point_list()[j - next_index + 1];
00390         }
00391     }
00392     else //( sense == CUBIT_REVERSED )
00393     {
00394         // All but the first curve will not use one of its points.
00395         // This is taken into account by decrementing point_count
00396         // earlier.
00397       for(int j = next_index; j < point_count; j++)
00398       {
00399         gMem->point_list()[j] = current_gmem.point_list()[point_count-j-1];
00400       }
00401     }
00402     next_index = point_count;
00403     gMem->pointListCount = point_count;
00404   }
00405   
00406   gMem->pointListCount = point_count;
00407   return CUBIT_SUCCESS;
00408 }
00409 
00410 //-----------------------------------------------------------------------
00411 // Purpose   : This function constructs the edge facetting information
00412 //         of a PartitionCurve for use by HOOPS.
00413 //
00414 // Special Notes : It is currently not possible to split a face which
00415 //                 has more than one loop (holes) because we cannot
00416 //                 determine which partition the holes should lie on with
00417 //                 the current implementation of ParasiteCurve.
00418 //
00419 // Creator       : Jason Kraftcheck 
00420 //
00421 // Creation Date : 10/10/97
00422 //-----------------------------------------------------------------------
00423 CubitStatus VirtualQueryEngine::get_partition_curve_facetting(
00424                                    PartitionCurve* pcurve_ptr, 
00425                                    GMem* gMem, 
00426                                    double angle_tolerance,
00427                                    double distance_tolerance,
00428                                    double max_edge_length ) const
00429 {
00430   assert( gMem != NULL );
00431   CubitStatus result = pcurve_ptr->get_graphics( *gMem, angle_tolerance, 
00432                                     distance_tolerance, max_edge_length );
00433   return result;
00434 }
00435 
00436 
00437 //-------------------------------------------------------------------------
00438 // Purpose       : get Hoops facetting information for a CompositeSurface.
00439 //
00440 // Special Notes : 
00441 //
00442 // Creator       : Jason Kraftcheck
00443 //
00444 // Creation Date : 03/17/98
00445 //-------------------------------------------------------------------------
00446 CubitStatus VirtualQueryEngine::get_composite_surface_facetting(
00447   CompositeSurface* surf_ptr,
00448   GMem* gMem,
00449   std::vector<TopologyBridge*> *vertex_edge_to_point_vector,
00450   std::vector<std::pair<TopologyBridge*, std::pair<int,int> > > *facet_edges_on_curves,
00451   unsigned short normal_tol,
00452   double dist_tol,
00453   double longest_edge ) const
00454 {
00455   if( gMem == NULL )
00456     return CUBIT_FAILURE;
00457    
00458   if (surf_ptr->get_graphics(*gMem))
00459   {
00460     /*
00461     if( vertex_edge_to_point_vector )
00462     {
00463       vertex_edge_to_point_vector->resize( gMem->pointListCount, NULL );
00464       //get all the points on the surface
00465       DLIList<TBPoint*> points;
00466       surf_ptr->points( points );    
00467 
00468       for( int i=points.size(); i--; )
00469       {
00470         TBPoint *tb_pt = points.get_and_step();
00471         CompositePoint *comp_pt = CAST_TO( tb_pt, CompositePoint );
00472 
00473         if( comp_pt )
00474         {
00475           CubitPoint *facet_point = comp_pt->facet_point();
00476           (*vertex_edge_to_point_vector)[facet_point->marked()] = comp_pt;
00477         }
00478       }
00479     }
00480 
00481     if( facet_edges_on_curves )
00482     {
00483       DLIList<Curve*> tmp_curves;
00484       surf_ptr->curves( tmp_curves );
00485 
00486       for( int i=tmp_curves.size(); i--; )
00487       {
00488         Curve *tmp_curve = tmp_curves.get_and_step();
00489         CompositeCurve *comp_curve = CAST_TO( tmp_curve, CompositeCurve );
00490 
00491         if( comp_curve )
00492         {
00493           DLIList<CubitFacetEdgeData*> facet_edges;
00494           comp_curve->get_facet_data( facet_edges );
00495 
00496           for( int j=facet_edges.size(); j--; )
00497           {
00498             CubitFacetEdge *facet_edge = facet_edges.get_and_step();
00499 
00500             facet_edges_on_curves->push_back( std::make_pair( tmp_curve, 
00501               std::make_pair( facet_edge->point(0)->marked(), 
00502               facet_edge->point(1)->marked() )));
00503           }
00504         }
00505       }
00506     }
00507 */
00508     return CUBIT_SUCCESS;
00509   }
00510     
00511 
00512     // Get the underlying Surfaces
00513   GeometryQueryEngine* gqe_ptr;
00514   GMem *gMem_list = new GMem[ surf_ptr->num_surfs() ];
00515   
00516   int total_number_points = 0;
00517   int total_number_facets = 0;
00518   
00519     // Get the facets of each Surface
00520   int i;
00521   for(i = 0; i < surf_ptr->num_surfs(); i++)
00522   {
00523     Surface* surface_ptr = surf_ptr->get_surface(i);
00524     
00525     gqe_ptr = surface_ptr->get_geometry_query_engine();
00526     
00527     gqe_ptr->get_graphics( surface_ptr, &(gMem_list[i]),
00528                                   normal_tol, dist_tol, longest_edge );
00529     
00530     total_number_facets += gMem_list[i].fListCount;
00531     total_number_points += gMem_list[i].pointListCount;
00532   }
00533   
00534   int point_offset = 0;
00535   int face_offset = 0;
00536   gMem->replace_point_list(new GPoint[total_number_points],
00537                            total_number_points, total_number_points);
00538   gMem->replace_facet_list(new int[total_number_facets],
00539                            total_number_facets, total_number_facets);
00540   
00541   for( i = 0; i < surf_ptr->num_surfs(); i++ )
00542   {
00543     int j;
00544     for(  j = 0; j < gMem_list[i].pointListCount; j++ )
00545     {
00546       assert((point_offset + j) < gMem->pointListCount );
00547       gMem->point_list()[j + point_offset].x = gMem_list[i].point_list()[j].x;
00548       gMem->point_list()[j + point_offset].y = gMem_list[i].point_list()[j].y;
00549       gMem->point_list()[j + point_offset].z = gMem_list[i].point_list()[j].z;
00550     }
00551     
00552     int k;
00553     for( k = 0; k < gMem_list[i].fListCount;)
00554     {
00555       int count = gMem_list[i].facet_list()[k];
00556       assert( k + count < gMem->fListCount );
00557       
00558       gMem->facet_list()[k + face_offset] = count;
00559       k++;
00560       for( int l = 0; l < count; l++, k++ )
00561       {
00562         assert( k + face_offset < gMem->fListCount );
00563         assert( k < gMem_list[i].fListCount );
00564         gMem->facet_list()[k + face_offset] = gMem_list[i].facet_list()[k] 
00565           + point_offset;
00566       }
00567     }
00568     
00569     point_offset += j;
00570     face_offset += k;
00571   }
00572   
00573   gMem->consolidate_points(10*GEOMETRY_RESABS);
00574 //     // Debug!!!
00575 //   int q;
00576 //   for (q = 0; q < bte_list.size(); q++)
00577 //   {
00578 //     PRINT_INFO("Printing Points for Surface %d.\n", q);
00579 //     int r;
00580 //     for (r = 0; r < gMem_list[q].pointListCount; r++)
00581 //     {
00582 //       PRINT_INFO("%g %g %g\n",
00583 //                  gMem_list[q].point_list()[r].x,
00584 //                  gMem_list[q].point_list()[r].y,
00585 //                  gMem_list[q].point_list()[r].z);
00586 //     }
00587 //     PRINT_INFO("Printing FList for Surface %d.\n", q);
00588 //     for (r = 0; r < gMem_list[q].fListCount; r++)
00589 //     {
00590 //       PRINT_INFO("%d %s",
00591 //                  gMem_list[q].facet_list()[r],
00592 //                  r % 4 ? "" : "\n");
00593 //     }
00594 //   }
00595 //   PRINT_INFO("Composite points:\n");
00596 //   for (q = 0; q < gMem->pointListCount; q++)
00597 //   {
00598 //     PRINT_INFO("%g %g %g\n",
00599 //                gMem->point_list()[q].x,
00600 //                gMem->point_list()[q].y,
00601 //                gMem->point_list()[q].z);
00602 //   }
00603 //   PRINT_INFO("Composite facet list:\n");
00604 //   for (q = 0; q < gMem->fListCount; q++)
00605 //   {
00606 //     PRINT_INFO("%d %s",
00607 //                gMem->facet_list()[q],
00608 //                q % 4 ? "" : "\n");
00609 //   }
00610 
00611   if( vertex_edge_to_point_vector )
00612   {
00613     vertex_edge_to_point_vector->resize( gMem->pointListCount, NULL );
00614     //get all the points on the surface
00615     DLIList<TBPoint*> points;
00616     surf_ptr->points( points );    
00617 
00618     for( int i=points.size(); i--; )
00619     {
00620       TBPoint *tb_pt = points.get_and_step();
00621       PartitionPoint *ppt = CAST_TO( tb_pt, PartitionPoint );
00622 
00623       if( ppt )
00624       {
00625         CubitPoint *facet_point = ppt->facet_point();
00626         (*vertex_edge_to_point_vector)[facet_point->marked()] = ppt;
00627       }
00628     }
00629   }
00630 
00631   if( facet_edges_on_curves )
00632   {
00633     DLIList<Curve*> tmp_curves;
00634     surf_ptr->curves( tmp_curves );
00635 
00636     for( int i=tmp_curves.size(); i--; )
00637     {
00638       Curve *tmp_curve = tmp_curves.get_and_step();
00639       PartitionCurve *pt_curve = CAST_TO( tmp_curve, PartitionCurve );
00640 
00641       if( pt_curve )
00642       {
00643         DLIList<CubitFacetEdgeData*> facet_edges;
00644         pt_curve->get_facet_data( facet_edges );
00645 
00646         for( int j=facet_edges.size(); j--; )
00647         {
00648           CubitFacetEdge *facet_edge = facet_edges.get_and_step();
00649 
00650           facet_edges_on_curves->push_back( std::make_pair( tmp_curve, 
00651             std::make_pair( facet_edge->point(0)->marked(), 
00652                             facet_edge->point(1)->marked() )));
00653 
00654         }
00655       }
00656     }
00657   }
00658   
00659   delete [] gMem_list;  
00660   return CUBIT_SUCCESS;
00661 }
00662 
00663 //-------------------------------------------------------------------------
00664 // Purpose       : get hoops facets for a partition surface
00665 //
00666 // Special Notes : 
00667 //
00668 // Creator       : Jason Kraftcheck 
00669 //
00670 // Creation Date : 06/18/98
00671 //-------------------------------------------------------------------------
00672 CubitStatus VirtualQueryEngine::get_partition_surface_facetting(
00673   PartitionSurface* surf_ptr,
00674   GMem* gMem,
00675   std::vector<TopologyBridge*> *vertex_edge_to_point_vector,
00676   std::vector<std::pair<TopologyBridge*, std::pair<int,int> > > *facet_edges_on_curves,
00677   unsigned short ,
00678   double,
00679   double ) const
00680 {
00681   int i, j;
00682   
00683   DLIList<CubitFacetData*> surf_facets;
00684   DLIList<CubitPoint*> surf_points;
00685   
00686     // get surface facets
00687   surf_ptr->get_facet_data( surf_facets );
00688 
00689     // get list of points from list of facets
00690   for( i = surf_facets.size(); i--; )
00691   {
00692     CubitFacetData* facet = surf_facets.step_and_get();
00693     for( j = 0; j< 3; j++ )
00694       facet->point(j)->marked(1);
00695   }
00696   for( i = surf_facets.size(); i--; )
00697   {
00698     CubitFacetData* facet = surf_facets.step_and_get();
00699     for( j = 0; j< 3; j++ )
00700     {
00701       if( facet->point(j)->marked() )
00702       {
00703         facet->point(j)->marked(0);
00704         surf_points.append( facet->point(j) );
00705       }
00706     }
00707   }
00708 
00709   if( ! gMem ) return CUBIT_SUCCESS;
00710 
00711     // allocate storage for facet data
00712   gMem->allocate_tri( surf_facets.size() );
00713   gMem->fListCount = surf_facets.size() * 4;
00714   gMem->pointListCount = surf_points.size();
00715     
00716     // put points in GMem and mark each point with
00717     // its index in the array
00718   surf_points.reset();
00719   for( i = 0; i < gMem->pointListCount; i++ )
00720   {
00721     GPoint* gpt = gMem->point_list() + i;
00722     CubitPoint* pt = surf_points.get_and_step();
00723     pt->marked(i);
00724     gpt->x = (float)(pt->coordinates().x() );
00725     gpt->y = (float)(pt->coordinates().y() );
00726     gpt->z = (float)(pt->coordinates().z() );
00727   }
00728   
00729     // put each facet in the GMem.  retreive
00730     // point indices from marks.
00731   surf_facets.reset();
00732   int* gfacet_ptr = gMem->facet_list();
00733   for( i = 0; i < surf_facets.size(); i++ )
00734   {
00735     CubitFacetData* facet = surf_facets.get_and_step();
00736     *gfacet_ptr = 3;
00737     gfacet_ptr++;
00738     for( j = 0; j < 3; j++ )
00739     {
00740       *gfacet_ptr = facet->point(j)->marked();
00741       gfacet_ptr++;
00742     }
00743   }
00744 
00745   if( vertex_edge_to_point_vector )
00746   {
00747     vertex_edge_to_point_vector->resize( gMem->pointListCount, NULL );
00748     //get all the points on the surface
00749     DLIList<TBPoint*> points;
00750     surf_ptr->points( points );    
00751 
00752     for( int i=points.size(); i--; )
00753     {
00754       TBPoint *tb_pt = points.get_and_step();
00755       PartitionPoint *ppt = CAST_TO( tb_pt, PartitionPoint );
00756 
00757       if( ppt )
00758       {
00759         CubitPoint *facet_point = ppt->facet_point();
00760         (*vertex_edge_to_point_vector)[facet_point->marked()] = ppt;
00761       }
00762     }
00763   }
00764 
00765   if( facet_edges_on_curves )
00766   {
00767     DLIList<Curve*> tmp_curves;
00768     surf_ptr->curves( tmp_curves );
00769 
00770     for( int i=tmp_curves.size(); i--; )
00771     {
00772       Curve *tmp_curve = tmp_curves.get_and_step();
00773       PartitionCurve *pt_curve = CAST_TO( tmp_curve, PartitionCurve );
00774 
00775       if( pt_curve )
00776       {
00777         DLIList<CubitFacetEdgeData*> facet_edges;
00778         pt_curve->get_facet_data( facet_edges );
00779 
00780         for( int j=facet_edges.size(); j--; )
00781         {
00782           CubitFacetEdge *facet_edge = facet_edges.get_and_step();
00783 
00784           facet_edges_on_curves->push_back( std::make_pair( tmp_curve, 
00785             std::make_pair( facet_edge->point(0)->marked(), 
00786                             facet_edge->point(1)->marked() )));
00787 
00788         }
00789       }
00790     }
00791   }
00792   
00793     // clear point marks
00794   for( i = surf_points.size(); i--; )
00795     surf_points.step_and_get()->marked(0);
00796   
00797   return CUBIT_SUCCESS;
00798 }
00799 
00800 // ********** END PUBLIC FUNCTIONS         **********
00801 
00802 // ********** BEGIN PROTECTED FUNCTIONS    **********
00803 
00804 //-------------------------------------------------------------------------
00805 // Purpose       : The constructor of the VirtualQueryEngine class.
00806 //
00807 // Special Notes : 
00808 //
00809 // Creator       : Wes Gill
00810 //
00811 // Creation Date : 10/5/01
00812 //-------------------------------------------------------------------------
00813 
00814 VirtualQueryEngine::VirtualQueryEngine()
00815 {
00816   assert( !instance_);
00817     //Add the VirtualQueryEngine to the GeometryQueryTool's gqeList and
00818     //set the VGE to the GQT's default engine.
00819    //GeometryQueryTool::instance()->add_gqe(this);
00820    //GeometryQueryTool::instance()->set_default_engine(this); 
00821   CompositeEngine::instance();
00822   PartitionEngine::instance();
00823 }
00824 
00825 
00826 //-------------------------------------------------------------------------
00827 // Purpose       : get child virtual geometry
00828 //
00829 // Special Notes : 
00830 //
00831 // Creator       : Jason Kraftcheck 
00832 //
00833 // Creation Date : 08/11/98
00834 //-------------------------------------------------------------------------
00835 void VirtualQueryEngine::get_VEs( TopologyEntity* te_ptr,
00836                                      DLIList<TopologyBridge*>& ve_list, 
00837                                      CubitBoolean visible,
00838                                      const CubitBoolean children_too)
00839 {
00840   DLIList<TopologyBridge*> child_list;
00841   Body*      body_ptr   = CAST_TO( te_ptr, Body );
00842   CoVolume*  covol_ptr  = CAST_TO( te_ptr, CoVolume );
00843   RefVolume* vol_ptr    = CAST_TO( te_ptr, RefVolume );
00844   Shell*     shell_ptr  = CAST_TO( te_ptr, Shell );
00845   CoFace*    coface_ptr = CAST_TO( te_ptr, CoFace );
00846   RefFace*   face_ptr   = CAST_TO( te_ptr, RefFace );
00847   Loop*      loop_ptr   = CAST_TO( te_ptr, Loop );
00848   CoEdge*    coedge_ptr = CAST_TO( te_ptr, CoEdge );
00849   RefEdge*   edge_ptr   = CAST_TO( te_ptr, RefEdge );
00850   Chain*     chain_ptr  = CAST_TO( te_ptr, Chain );
00851   CoVertex*  covex_ptr  = CAST_TO( te_ptr, CoVertex );
00852   RefVertex* vex_ptr    = CAST_TO( te_ptr, RefVertex );
00853   
00854   if( (body_ptr != NULL) || (covol_ptr != NULL) )
00855   {
00856     if (children_too) {
00857       DLIList<RefVolume*> vol_list;
00858       te_ptr->ref_volumes( vol_list );
00859       for( int i = vol_list.size(); i > 0; i-- )
00860       {
00861         child_list.clean_out();
00862         get_VEs( vol_list.get_and_step(), child_list, visible,
00863                  children_too);
00864         ve_list.merge_unique( child_list );
00865       }
00866     }
00867   }
00868   else if( vol_ptr != NULL )
00869   {
00870     get_VEs( vol_ptr, ve_list, visible, children_too );
00871   }
00872   else if( (shell_ptr != NULL) || (coface_ptr != NULL) )
00873   {
00874     if (children_too) {
00875       DLIList<RefFace*> face_list;
00876       te_ptr->ref_faces( face_list );
00877       for( int i = face_list.size(); i> 0; i-- )
00878       {
00879         child_list.clean_out();
00880         get_VEs( face_list.get_and_step(), child_list, visible,
00881                  children_too);
00882         ve_list.merge_unique( child_list );
00883       }
00884     }
00885   }
00886   else if( face_ptr != NULL )
00887   {
00888     get_VEs( face_ptr, ve_list, visible, children_too );
00889   }
00890   else if( (loop_ptr != NULL) || (coedge_ptr != NULL) )
00891   {
00892     if (children_too) {
00893       DLIList<RefEdge*> edge_list;
00894       te_ptr->ref_edges( edge_list );
00895       for( int i = edge_list.size(); i > 0; i-- )
00896       {
00897         child_list.clean_out();
00898         get_VEs( edge_list.get_and_step(), child_list, visible,
00899                  children_too);
00900         ve_list.merge_unique( child_list );
00901       }
00902     }
00903   }
00904   else if( edge_ptr != NULL )
00905   {
00906     get_VEs( edge_ptr, ve_list, visible, children_too );
00907   }
00908   else if( (chain_ptr != NULL) || (covex_ptr != NULL ) )
00909   {
00910     if (children_too) {
00911       DLIList<RefVertex*> vertex_list;
00912       te_ptr->ref_vertices( vertex_list );
00913       for( int i = vertex_list.size(); i > 0; i-- )
00914       {
00915         child_list.clean_out();
00916         get_VEs( vertex_list.get_and_step(), child_list, visible,
00917                  children_too);
00918         ve_list.merge_unique( child_list );
00919       }
00920     }
00921   }
00922   else if( vex_ptr != NULL )
00923   {
00924     get_VEs( vex_ptr, ve_list, visible, children_too );
00925   }
00926   else
00927     {
00928       PRINT_ERROR("Unknown type of TopologyEntity passed to "
00929                     "VirtualQueryEngine::get_VEs(..).  Passed pointer"
00930                                 " may be stale.\n");
00931     }
00932 }
00933 
00934 
00935 void VirtualQueryEngine::get_VEs( RefVolume* volume_ptr,
00936                                      DLIList<TopologyBridge*>& ve_list,
00937                                      CubitBoolean visible,
00938                                      const CubitBoolean children_too )
00939 {
00940   DLIList<BasicTopologyEntity*> bte_list;
00941   int i;
00942   
00943   DLIList<TopologyBridge*> tb_list;
00944   volume_ptr->bridge_manager()->get_bridge_list( tb_list );
00945   
00946   for( i = tb_list.size(); i--; )
00947   {  
00948     TopologyBridge* tb_ptr = tb_list.get_and_step();
00949     PartitionEntity* ve_ptr = dynamic_cast<PartitionEntity*>(tb_ptr);
00950     CompositeLump* ce_ptr = dynamic_cast<CompositeLump*>(tb_ptr);
00951     if( ve_ptr || ce_ptr )
00952     {
00953       ve_list.append( tb_ptr );
00954     }
00955   }
00956   
00957   if (!children_too) return;
00958   DLIList<TopologyBridge*> child_list;
00959   
00960   DLIList<RefFace*> face_list;
00961   volume_ptr->ref_faces( face_list );
00962   DLIList<BasicTopologyEntity*> temp_face_list;
00963   CAST_LIST_TO_PARENT( face_list, temp_face_list );
00964   bte_list.merge_unique( temp_face_list );
00965 //  bte_list.merge_unique( face_list );
00966   for( i = bte_list.size();i > 0;i--)
00967   {
00968     child_list.clean_out();
00969     get_VEs( bte_list.get_and_step(), child_list, visible );
00970     ve_list.merge_unique( child_list );
00971   }
00972 }
00973 
00974 void VirtualQueryEngine::get_VEs( RefFace* face_ptr,
00975                                      DLIList<TopologyBridge*>& ve_list,
00976                                      CubitBoolean visible,
00977                                      const CubitBoolean children_too )
00978 {
00979   DLIList<BasicTopologyEntity*> bte_list;
00980   DLIList<TopologyBridge*> tb_list;
00981   int i;
00982   
00983   face_ptr->bridge_manager()->get_bridge_list( tb_list );
00984   tb_list.reset();
00985   
00986   for( i = tb_list.size(); i--; )
00987   {
00988   
00989     TopologyBridge* ve_ptr = tb_list.get_and_step();
00990     if( dynamic_cast<PartitionEntity*>(ve_ptr) ||
00991         dynamic_cast<CompositeSurface*>(ve_ptr) )
00992     {
00993       ve_list.append( ve_ptr );
00994     }
00995   }
00996   
00997   
00998   if (!children_too) return;
00999 
01000   DLIList<TopologyBridge*> child_list;
01001   DLIList<RefEdge*> edge_list;
01002   face_ptr->ref_edges( edge_list );
01003   DLIList<BasicTopologyEntity*> temp_edge_list;
01004   CAST_LIST_TO_PARENT( edge_list, temp_edge_list );
01005   bte_list.merge_unique( temp_edge_list );
01006 
01007   for( i = bte_list.size();i > 0;i--)
01008   {
01009     child_list.clean_out();
01010     get_VEs( bte_list.get_and_step(), child_list, visible );
01011     ve_list.merge_unique( child_list );
01012   }
01013 }
01014 
01015 void VirtualQueryEngine::get_VEs( RefEdge* edge_ptr,
01016                                      DLIList<TopologyBridge*>& ve_list,
01017                                      CubitBoolean visible,
01018                                      const CubitBoolean children_too )
01019 {
01020   DLIList<BasicTopologyEntity*> bte_list;
01021   DLIList<TopologyBridge*> tb_list;
01022   int i;
01023   
01024   edge_ptr->bridge_manager()->get_bridge_list( tb_list );
01025   tb_list.reset();
01026   
01027   for( i = tb_list.size(); i--; )
01028   {
01029   
01030     TopologyBridge* ve_ptr = tb_list.get_and_step();
01031     if( dynamic_cast<PartitionCurve*>(ve_ptr) ||
01032         dynamic_cast<CompositeCurve*>(ve_ptr) )
01033     {
01034       ve_list.append( ve_ptr );
01035     }
01036   }
01037   
01038   if (!children_too) return;
01039   DLIList<TopologyBridge*> child_list;
01040   DLIList<RefVertex*> vex_list;
01041   edge_ptr->ref_vertices( vex_list );
01042   DLIList<BasicTopologyEntity*> temp_vex_list;
01043   CAST_LIST_TO_PARENT( vex_list, temp_vex_list );
01044   bte_list.merge_unique( temp_vex_list );
01045 
01046   for( i = bte_list.size();i > 0;i--)
01047   {
01048     child_list.clean_out();
01049     get_VEs( bte_list.get_and_step(), child_list, visible );
01050     ve_list.merge_unique( child_list );
01051   }
01052 }
01053 
01054 void VirtualQueryEngine::get_VEs( RefVertex* vex_ptr,
01055                                      DLIList<TopologyBridge*>& ve_list,
01056                                      CubitBoolean ,
01057                                      const CubitBoolean )
01058 {
01059   DLIList<TopologyBridge*> tb_list;
01060   vex_ptr->bridge_manager()->get_bridge_list( tb_list );
01061   tb_list.reset();
01062   for( int i = tb_list.size(); i--; )
01063   {
01064     TopologyBridge* tb = tb_list.get_and_step();
01065     if( dynamic_cast<PartitionPoint*>(tb) ||
01066         dynamic_cast<CompositePoint*>(tb) )
01067       ve_list.append( tb );
01068   }
01069 }
01070 
01071 
01072 //-------------------------------------------------------------------------
01073 // Purpose       : check if the entity is virtual or has virtual entities. 
01074 //
01075 // Special Notes : all is_virtual entity, has_virtual = true
01076 //                 only body, refvolume, refface can be non-virtual but has
01077 //                 virtual.
01078 //
01079 // Creator       : Jane Hu
01080 //
01081 // Creation Date : 10/01/04
01082 //-------------------------------------------------------------------------
01083 CubitBoolean VirtualQueryEngine::has_virtual(TopologyEntity* te_ptr)
01084 {
01085   if (te_ptr == NULL)
01086     return CUBIT_FALSE;
01087   
01088   if (is_virtual(te_ptr))
01089     return CUBIT_TRUE;
01090   
01091     // check if children has partition or composite entities
01092   int i;
01093   Body      * body_ptr = CAST_TO (te_ptr, Body);
01094   RefVolume * vol_ptr  = CAST_TO (te_ptr, RefVolume);
01095   RefFace   * face_ptr = CAST_TO (te_ptr, RefFace);
01096   CubitBoolean has_vir = CUBIT_FALSE;
01097   
01098   if (body_ptr != NULL)
01099   {
01100     DLIList<RefVolume*> vol_list;
01101     te_ptr->ref_volumes(vol_list);
01102     for (i = vol_list.size(); i > 0; i--)
01103     {
01104       if (has_virtual(vol_list.get_and_step()))
01105       {
01106         has_vir = CUBIT_TRUE;
01107         break;
01108       }
01109     }
01110   }
01111                                                                                 
01112   if (vol_ptr != NULL)
01113   {
01114     DLIList<RefFace*> face_list;
01115     te_ptr->ref_faces(face_list);
01116     for (i = face_list.size(); i > 0; i --)
01117     {
01118        if (has_virtual(face_list.get_and_step()))
01119        { 
01120          has_vir = CUBIT_TRUE;
01121          break;
01122        }
01123     }
01124   }
01125                                                                                 
01126   if (face_ptr != NULL)
01127   {
01128     DLIList<RefEdge *> edge_list;
01129     te_ptr->ref_edges(edge_list);
01130     for (i = edge_list.size(); i > 0; i --)
01131     {
01132        if (is_virtual(edge_list.get_and_step()))
01133        {
01134          has_vir = CUBIT_TRUE;
01135          break;
01136        }
01137     }
01138   }
01139 
01140   return has_vir;
01141 } 
01142 
01143 CubitBoolean VirtualQueryEngine::is_virtual(TopologyEntity *entity,
01144                                                const CubitBoolean children_too)
01145 //Check if a TopologyEntity has any topologyBridge that is composite or 
01146 //partition type.
01147 {
01148   if ( entity == NULL )
01149       return CUBIT_FALSE;
01150   
01151   if (CAST_TO(entity, Body) !=NULL)
01152   {
01153      int i;
01154      DLIList<TopologyBridge*> list;
01155      entity->bridge_manager()->get_bridge_list(list);
01156      TopologyBridge * tb;
01157      for (i = list.size(); i > 0; i--)
01158      {
01159         tb =  list.get_and_step();
01160         if (CAST_TO(tb, PartitionBody) != NULL ||
01161             CAST_TO(tb, CompositeBody) != NULL)
01162            return CUBIT_TRUE;
01163       }
01164   }
01165 
01166   DLIList<TopologyBridge*> ve_list;
01167   get_VEs(entity, ve_list, CUBIT_TRUE, children_too);
01168   return (ve_list.size() ? CUBIT_TRUE : CUBIT_FALSE);
01169 }
01170 
01171 CubitBoolean VirtualQueryEngine::is_virtual(DLIList<Body*> &entity_list,
01172                                                const CubitBoolean children_too)
01173 {
01174   if (!children_too) return CUBIT_FALSE;
01175                                                                                 
01176   int i;
01177   for (i = entity_list.size(); i > 0; i--)
01178     if (is_virtual(entity_list.get_and_step(), children_too)) return CUBIT_TRUE;                                                                                
01179   return CUBIT_FALSE;
01180 }
01181 
01182 CubitBoolean VirtualQueryEngine::is_virtual(DLIList<RefEntity*> &entity_list,
01183                                                const CubitBoolean children_too)
01184 {
01185   int i;
01186   for (i = entity_list.size(); i > 0; i--) {
01187     RefEntity *ref_entity = entity_list.get_and_step();
01188     if (is_virtual(CAST_TO(ref_entity, TopologyEntity), children_too)) return CUBIT_TRUE;
01189   }
01190                                                                                 
01191   return CUBIT_FALSE;
01192 }
01193 
01194 CubitBoolean VirtualQueryEngine::is_partition( RefEntity *ref_entity )
01195 {
01196   RefEdge *ref_edge = CAST_TO( ref_entity, RefEdge );
01197 
01198   if( ref_edge )
01199   {
01200     Curve *curve_ptr = ref_edge->get_curve_ptr();
01201     PartitionCurve *part_curve = CAST_TO(curve_ptr, PartitionCurve);
01202 
01203     if( part_curve )
01204       return CUBIT_TRUE;
01205   }
01206 
01207   return CUBIT_FALSE;
01208 }
01209 
01210 CubitStatus VirtualQueryEngine::get_sister_partitions( RefEntity *ref_entity,
01211                                                        DLIList<RefEntity*> &sisters)
01212 {
01213   RefEdge *ref_edge = CAST_TO( ref_entity, RefEdge );
01214 
01215   if( ref_edge )
01216   {
01217     Curve *curve_ptr = ref_edge->get_curve_ptr();
01218     PartitionCurve *part_curve = CAST_TO(curve_ptr, PartitionCurve);
01219 
01220     if( part_curve )
01221     {
01222       DLIList<TopologyBridge*> tb_list;
01223       part_curve->sub_entity_set().get_owners( tb_list );
01224       
01225       int k;
01226       for( k=tb_list.size(); k--; )
01227       {
01228         TopologyBridge *tmp_bridge = tb_list.get_and_step();
01229         TopologyEntity *te = tmp_bridge->topology_entity();
01230         if( te )
01231         {
01232           RefEntity *sister = CAST_TO(te, RefEntity ); 
01233           if( sister )
01234             sisters.append( sister );
01235         }
01236       }
01237     }
01238   }
01239 
01240   return CUBIT_SUCCESS;
01241 }
01242 
01243 //-------------------------------------------------------------------------
01244 // Purpose   : Sort a DLList of RefEdges to be used in the construction
01245 //         of a CompositeCurve.
01246 //
01247 // Special Notes : Sorted using topological information
01248 //
01249 // Creator   : Jason Kraftcheck
01250 //
01251 // Creation Date : 08/04/97
01252 //-------------------------------------------------------------------------
01253 CubitStatus VirtualQueryEngine::sort_edges( 
01254   DLIList<RefEdge*>& edge_list ) const
01255 {
01256   DLIList<RefEdge*> sorted_edge_list;
01257   RefEdge *first, *current = NULL, *prev;
01258   CubitStatus return_value = CUBIT_SUCCESS;
01259   
01260   if( edge_list.size( ) <= 0 )
01261   {
01262     return CUBIT_FAILURE;
01263   }
01264   
01265   if( edge_list.size() == 1 )
01266   {
01267     return CUBIT_SUCCESS;
01268   }
01269   
01270     //Note: this part badly needs some optimization.  Given the array-based
01271     // implementation of the DLList class, this is a very inefficient
01272     // approach to sorting the edges.  Look into a different seach
01273     // algorithm, and possible switching functions in DLList.
01274   
01275     //add first Curve
01276   edge_list.reset( );
01277   first = prev = edge_list.remove( );
01278   sorted_edge_list.append( first );
01279   
01280     //sort the rest of the Curves
01281   int i;
01282   for( i = 0; i < edge_list.size( ); i++ ) //loop for each remaining RefEdge
01283   {
01284     edge_list.reset( );
01285       //look through list for next RefEdge
01286     for( int j = 0; j < edge_list.size( ); j++ )
01287     {
01288       current = edge_list.get( );
01289       if( prev->common_ref_vertex( current ) != NULL )
01290       {
01291         edge_list.remove( );
01292         sorted_edge_list.append( current );
01293         i--; //edge_list.size() decreases with removal of edge
01294         prev = current;
01295         break;
01296       }
01297       else if( first->common_ref_vertex( current ) != NULL )
01298       {
01299         edge_list.remove( );
01300         sorted_edge_list.insert_first( current );
01301         first = current;
01302         i--; //edge_list.size() decreases with removal of edge
01303         break;
01304       }
01305       else
01306       {
01307         edge_list.step( );
01308       }
01309     }//end for(j)
01310   }//end for(i)
01311   
01312     //check if all the RefEdges got sorted
01313   if( edge_list.size( ) > 0 )
01314   {
01315     return_value =  CUBIT_FAILURE;
01316     
01317       //Sort the rest of the edges anyway, for use by
01318       //other functions than composite edge creation.
01319     
01320     sort_edges( edge_list );
01321     edge_list.reset( );
01322     for( i = 0; i < edge_list.size(); i++ )
01323     {
01324       current = edge_list.get_and_step( );
01325       sorted_edge_list.append( current );
01326     }
01327   }
01328   else
01329   {
01330     return_value = CUBIT_SUCCESS;
01331   }
01332   
01333   edge_list.clean_out( );
01334   edge_list = sorted_edge_list;
01335   edge_list.reset( );
01336   return return_value;
01337 }
01338 
01339 
01340 
01341 // ********** BEGIN PRIVATE FUNCTIONS      **********
01342 
01343 //-------------------------------------------------------------------------
01344 // Purpose: Display a default error message for certain inherited functions
01345 //-------------------------------------------------------------------------
01346 void VirtualQueryEngine::default_error_message( 
01347   const char callers_name[] ) const
01348 {
01349   PRINT_ERROR("A call was made to:\n");
01350   PRINT_ERROR("VirtualQueryEngine::");
01351   PRINT_ERROR("%s", callers_name);
01352   PRINT_ERROR("\n");
01353   PRINT_ERROR("Although this function is inhereted from GeometryQueryEngine\n");
01354   PRINT_ERROR("it is not applicable or implememtend in VirtualQueryEngine.\n");
01355   PRINT_ERROR("\nTHIS IS A BUG.  This function should NEVER be called.\n");
01356   PRINT_ERROR("\nThis function exists only because it is pure virtual in\n");
01357   PRINT_ERROR("the abstract class GeometryQueryEngine, and must be\n");
01358   PRINT_ERROR("defined in VirtualQueryEngine for the class to be\n");
01359   PRINT_ERROR("instantiated.\n");
01360 }
01361 
01362 // ********** END PRIVATE FUNCTIONS        **********
01363 
01364 // ********** BEGIN HELPER CLASSES         **********
01365 // ********** END HELPER CLASSES           **********
01366 
01367 // ********** BEGIN EXTERN FUNCTIONS       **********
01368 // ********** END EXTERN FUNCTIONS         **********
01369 
01370 // ********** BEGIN STATIC FUNCTIONS       **********
01371 // ********** END STATIC FUNCTIONS         **********
01372 
01373 
01374     
01375 CubitStatus 
01376 VirtualQueryEngine::get_intersections( Curve* , Curve* ,
01377                                          DLIList<CubitVector>& /*intersection_list*/,
01378                                          CubitBoolean /*bounded*/,
01379                                          CubitBoolean /*closest*/ )
01380 {
01381   return CUBIT_FAILURE;
01382 }
01383 
01384 CubitStatus
01385 VirtualQueryEngine::get_intersections(Curve* curve, CubitVector &point1,
01386                                          CubitVector &point2,
01387                                          DLIList<CubitVector>& intersection_list,
01388                                          CubitBoolean bounded,
01389                                          CubitBoolean closest )
01390 {
01391   DLIList<TopologyBridge*> curve_list;
01392   get_underlying_curves( curve, curve_list );
01393   int i;
01394   for (i = 0; i < curve_list.size(); i++)
01395   {
01396     // Get the next curve and its GME
01397     Curve* curve_ptr = CAST_TO(curve_list.get_and_step(), Curve);
01398     GeometryQueryEngine* GQE_ptr =
01399       curve_ptr->get_geometry_query_engine();
01400     GQE_ptr->get_intersections(curve_ptr, point1, point2, intersection_list,
01401                                bounded, closest);
01402   }
01403   return CUBIT_SUCCESS;
01404 }
01405 
01406 CubitStatus 
01407 VirtualQueryEngine::get_intersections( Curve*, Surface*,
01408                                           DLIList<CubitVector>& /* intersection_list */,
01409                                           CubitBoolean /* bounded */)
01410 {
01411    return CUBIT_FAILURE;
01412 }
01413 
01414 int VirtualQueryEngine::curve_is_on_ignored_surface(Curve *curve_in, Surface *surf) 
01415 { 
01416   int i, ret = 0;
01417 
01418   CompositeSurface *cs = dynamic_cast<CompositeSurface*>(surf);
01419   if(cs && curve_in)
01420   {
01421     DLIList<Surface*> ignored_surfs;
01422     cs->get_ignored_surfs(ignored_surfs);
01423     for(i=ignored_surfs.size(); i>0 && !ret; i--)
01424     {
01425       Surface *surf = ignored_surfs.get_and_step();
01426       DLIList<Curve*> crvs;
01427       surf->curves(crvs);
01428       if(crvs.is_in_list(curve_in))
01429         ret = 1;
01430     }
01431   }
01432 
01433   return ret;
01434 }
01435 
01436 //-------------------------------------------------------------------------
01437 // Purpose       : This function get underlying curves for virtual curves
01438 //
01439 // Special Notes :
01440 //
01441 // Creator       : Jane Hu
01442 //
01443 // Creation Date :
01444 //-------------------------------------------------------------------------
01445 CubitStatus VirtualQueryEngine::get_underlying_curves(Curve * curve_ptr,
01446                                         DLIList<TopologyBridge*>& curve_list)
01447 {
01448    assert (curve_ptr);
01449    CompositeCurve *comp_curve = CAST_TO(curve_ptr, CompositeCurve);
01450    PartitionCurve *part_curve = CAST_TO(curve_ptr, PartitionCurve);
01451    if ( comp_curve )
01452    {
01453      int i;
01454      for (i = 0; i < comp_curve->num_curves(); i ++)
01455      {
01456        part_curve = CAST_TO(comp_curve->get_curve(i), PartitionCurve);
01457        if (!part_curve)
01458          curve_list.append_unique(CAST_TO(comp_curve->get_curve(i),
01459                                   TopologyBridge));
01460        else
01461        {
01462          if(dynamic_cast<Curve*>(part_curve->partitioned_entity()))
01463          {
01464            curve_list.append_unique(CAST_TO(part_curve->partitioned_entity(),
01465                                     TopologyBridge));
01466          }
01467        }
01468      }
01469    }
01470    else if ( part_curve )
01471      curve_list.append(CAST_TO(part_curve->partitioned_entity(),
01472                        TopologyBridge));
01473    return CUBIT_SUCCESS;
01474 }
01475 
01476 CubitStatus VirtualQueryEngine::get_underlying_surfaces(Surface * surf_ptr,
01477                                         DLIList<TopologyBridge*>& surf_list)
01478 {
01479    assert (surf_ptr);
01480    CompositeSurface *comp_surf = CAST_TO(surf_ptr, CompositeSurface);
01481    PartitionSurface *part_surf = CAST_TO(surf_ptr, PartitionSurface);
01482    if ( comp_surf )
01483    {
01484      int i;
01485      for (i = 0; i < comp_surf->num_surfs(); i ++)
01486      {
01487        part_surf = CAST_TO(comp_surf->get_surface(i), PartitionSurface);
01488        if (!part_surf)
01489          surf_list.append_unique(CAST_TO(comp_surf->get_surface(i),
01490                                   TopologyBridge));
01491        else
01492        {
01493          if(dynamic_cast<Surface*>(part_surf->partitioned_entity()))
01494          {
01495            surf_list.append_unique(CAST_TO(part_surf->partitioned_entity(),
01496                                     TopologyBridge));
01497          }
01498        }
01499      }
01500    }
01501    else if ( part_surf )
01502      surf_list.append(CAST_TO(part_surf->partitioned_entity(),
01503                        TopologyBridge));
01504    return CUBIT_SUCCESS;
01505 }
01506 
01507 CubitStatus VirtualQueryEngine::get_underlying_bridges(TopologyBridge* bridge_ptr,
01508                                         DLIList<TopologyBridge*>& bridge_list)
01509 {
01510    assert (bridge_ptr);
01511    CompositeSurface *comp_surf = CAST_TO(bridge_ptr, CompositeSurface);
01512    PartitionSurface *part_surf = CAST_TO(bridge_ptr, PartitionSurface);
01513    CompositeCurve *comp_curve = CAST_TO(bridge_ptr, CompositeCurve);
01514    PartitionCurve *part_curve = CAST_TO(bridge_ptr, PartitionCurve);
01515    CompositePoint *comp_point = CAST_TO(bridge_ptr, CompositePoint);
01516    PartitionPoint *part_point = CAST_TO(bridge_ptr, PartitionPoint);
01517    PartitionBody *part_body = CAST_TO(bridge_ptr, PartitionBody);
01518 
01519    if (part_body )
01520    {
01521      bridge_list.append( part_body->partitioned_entity() );
01522    }
01523    else if ( comp_surf )
01524    {
01525      int i;
01526      for (i = 0; i < comp_surf->num_surfs(); i ++)
01527      {
01528        part_surf = CAST_TO(comp_surf->get_surface(i), PartitionSurface);
01529        if (!part_surf)
01530          bridge_list.append_unique(CAST_TO(comp_surf->get_surface(i),
01531                                   TopologyBridge));
01532        else
01533        {
01534          if(dynamic_cast<Surface*>(part_surf->partitioned_entity()))
01535          {
01536            bridge_list.append_unique(CAST_TO(part_surf->partitioned_entity(),
01537                                     TopologyBridge));
01538          }
01539        }
01540      }
01541    }
01542    else if ( part_surf )
01543      bridge_list.append( part_surf->partitioned_entity() );
01544    else if ( comp_curve )
01545    {
01546      int i;
01547      for (i = 0; i < comp_curve->num_curves(); i ++)
01548      {
01549        part_curve = CAST_TO(comp_curve->get_curve(i), PartitionCurve);
01550        if (!part_curve)
01551          bridge_list.append_unique(comp_curve->get_curve(i));
01552        else
01553        {
01554          if(dynamic_cast<Curve*>(part_curve->partitioned_entity()))
01555          {
01556            bridge_list.append_unique( part_curve->partitioned_entity() );
01557          }
01558        }
01559      }
01560    }
01561    else if ( part_curve )
01562      bridge_list.append( part_curve->partitioned_entity() );
01563    else if ( part_point )
01564    {
01565      TopologyBridge *tb_point = part_point->real_point();
01566      if( tb_point )
01567        bridge_list.append( tb_point ); 
01568    }
01569    else if ( comp_point )
01570    {
01571      TopologyBridge *tb_point = comp_point->get_point();
01572      if( tb_point )
01573        bridge_list.append( tb_point ); 
01574    }
01575    
01576    return CUBIT_SUCCESS;
01577 }
01578 
01579 //================================================================================
01580 // Description: Find extrema position on an entity list
01581 // Author     : 
01582 // Date       : 
01583 //================================================================================
01584 CubitStatus 
01585 VirtualQueryEngine::entity_extrema( DLIList<GeometryEntity*> &, 
01586                                        const CubitVector *, 
01587                                        const CubitVector *,
01588                                        const CubitVector *, 
01589                                        CubitVector &,
01590                                        GeometryEntity *& )
01591 {
01592   PRINT_ERROR("Entity extrema calculation not yet supported for virtual geometry.\n");
01593   return CUBIT_FAILURE;
01594 }
01595  
01596 //================================================================================
01597 // Description: Find distance between two entities and closest positions.
01598 // Author     : 
01599 // Date       : 
01600 //================================================================================
01601 CubitStatus
01602 VirtualQueryEngine::entity_entity_distance( GeometryEntity *ge1,
01603                                            GeometryEntity *ge2,
01604                                            CubitVector &p1, CubitVector &p2,
01605                                            double &distance )
01606 {
01607   CompositeCurve *cc1 = dynamic_cast<CompositeCurve*>(ge1);
01608   CompositeCurve *cc2 = dynamic_cast<CompositeCurve*>(ge2);
01609   CompositeSurface *cs1 = dynamic_cast<CompositeSurface*>(ge1);
01610   CompositeSurface *cs2 = dynamic_cast<CompositeSurface*>(ge2);
01611 
01612   DLIList<GeometryEntity*> geometry_entities_1;
01613   DLIList<GeometryEntity*> geometry_entities_2;
01614   DLIList<GeometryQueryEngine*> gqes_1;
01615   DLIList<GeometryQueryEngine*> gqes_2;
01616 
01617   int i, j;
01618   int still_ok = 1;
01619 
01620   if(cc1)
01621   {
01622     for(i=cc1->num_curves()-1; i>-1 && still_ok; i--)
01623     {
01624       GeometryEntity *ge = cc1->get_curve(i);
01625       if(dynamic_cast<PartitionEntity*>(ge))
01626         still_ok = 0;
01627       GeometryQueryEngine *gqe = ge->get_geometry_query_engine();
01628       geometry_entities_1.append(ge);
01629       gqes_1.append(gqe);
01630     }
01631   }
01632   else if(cs1)
01633   {
01634     for(i=cs1->num_surfs()-1; i>-1 && still_ok; i--)
01635     {
01636       GeometryEntity *ge = cs1->get_surface(i);
01637       if(dynamic_cast<PartitionEntity*>(ge))
01638         still_ok = 0;
01639       GeometryQueryEngine *gqe = ge->get_geometry_query_engine();
01640       geometry_entities_1.append(ge);
01641       gqes_1.append(gqe);
01642     }
01643   }
01644   else
01645   {
01646     if(dynamic_cast<PartitionEntity*>(ge1))
01647       still_ok = 0;
01648     else if(dynamic_cast<Curve*>(ge1) || dynamic_cast<Surface*>(ge1))
01649     {
01650       GeometryQueryEngine *gqe = ge1->get_geometry_query_engine();
01651       geometry_entities_1.append(ge1);
01652       gqes_1.append(gqe);
01653     }
01654     else
01655     {
01656       PRINT_ERROR("Entity-entity distance not yet supported for virtual geometry.\n");
01657       return CUBIT_FAILURE;
01658     }
01659   }
01660   if(cc2)
01661   {
01662     for(i=cc2->num_curves()-1; i>-1 && still_ok; i--)
01663     {
01664       GeometryEntity *ge = cc2->get_curve(i);
01665       if(dynamic_cast<PartitionEntity*>(ge))
01666         still_ok = 0;
01667       GeometryQueryEngine *gqe = ge->get_geometry_query_engine();
01668       geometry_entities_2.append(ge);
01669       gqes_2.append(gqe);
01670     }
01671   }
01672   else if(cs2)
01673   {
01674     for(i=cs2->num_surfs()-1; i>-1 && still_ok; i--)
01675     {
01676       GeometryEntity *ge = cs2->get_surface(i);
01677       if(dynamic_cast<PartitionEntity*>(ge))
01678         still_ok = 0;
01679       GeometryQueryEngine *gqe = ge->get_geometry_query_engine();
01680       geometry_entities_2.append(ge);
01681       gqes_2.append(gqe);
01682     }
01683   }
01684   else
01685   {
01686     if(dynamic_cast<PartitionEntity*>(ge2))
01687       still_ok = 0;
01688     else if(dynamic_cast<Curve*>(ge2) || dynamic_cast<Surface*>(ge2))
01689     {
01690       GeometryQueryEngine *gqe = ge2->get_geometry_query_engine();
01691       geometry_entities_2.append(ge2);
01692       gqes_2.append(gqe);
01693     }
01694     else
01695     {
01696       PRINT_ERROR("Entity-entity distance not yet supported for virtual geometry.\n");
01697       return CUBIT_FAILURE;
01698     }
01699   }
01700 
01701   if(still_ok)
01702   {
01703     double smallest_distance = CUBIT_DBL_MAX;
01704     for(i=geometry_entities_1.size(); i--;)
01705     {
01706       GeometryEntity *ge1 = geometry_entities_1.get_and_step();
01707       GeometryQueryEngine *gqe1 = gqes_1.get_and_step();
01708       for(j=geometry_entities_2.size(); j--;)
01709       {
01710         GeometryEntity *ge2 = geometry_entities_2.get_and_step();
01711         //GeometryQueryEngine *gqe2 = gqes_2.get_and_step();
01712 
01713         CubitVector cur_pos1, cur_pos2;
01714         double cur_distance;
01715 
01716         gqe1->entity_entity_distance(ge1, ge2, cur_pos1, cur_pos2, cur_distance);
01717 
01718         if(cur_distance < smallest_distance)
01719         {
01720           smallest_distance = cur_distance;
01721           distance = cur_distance;
01722           p1 = cur_pos1;
01723           p2 = cur_pos2;
01724         }
01725       }
01726     }
01727   }
01728   else
01729   {
01730     PRINT_ERROR("Entity-entity distance not yet supported for virtual geometry.\n");
01731     return CUBIT_FAILURE;
01732   }
01733 
01734   return CUBIT_SUCCESS;
01735 }
01736 
01737 //-------------------------------------------------------------------------
01738 // Purpose       : Remove all possible virtual geometry.
01739 //
01740 // Special Notes : 
01741 //
01742 // Creator       : Jason Kraftcheck
01743 //
01744 // Creation Date : 06/28/00
01745 //-------------------------------------------------------------------------
01746 void VirtualQueryEngine::remove_virtual_geometry( RefEntity* entity_ptr,
01747                                              CubitBoolean all_children )
01748 {
01749   if ( Body* body_ptr = dynamic_cast<Body*>(entity_ptr) )
01750     remove_virtual_geometry(body_ptr, all_children);
01751   else if( RefVolume* vol_ptr = dynamic_cast<RefVolume*>(entity_ptr) )
01752     remove_virtual_geometry(vol_ptr, all_children);
01753   else if( RefFace* face_ptr = dynamic_cast<RefFace*>(entity_ptr) )
01754     remove_virtual_geometry(face_ptr);
01755 }
01756 
01757 void VirtualQueryEngine::remove_virtual_geometry( Body* body_ptr,
01758                                              bool all_children )
01759 {
01760   int i;
01761   DLIList<RefVolume*> volumes, part_results;
01762   body_ptr->ref_volumes(volumes);
01763   for ( i = volumes.size(); i--; ) {
01764     RefVolume* vol = volumes.step_and_get();
01765     if ( ! dynamic_cast<PartitionLump*>(vol->get_lump_ptr()) )
01766       volumes.change_to(0);
01767   }
01768   volumes.remove_all_with_value(0);
01769   if ( volumes.size() )
01770     PartitionTool::instance()->unpartitionAll(volumes, part_results);
01771   
01772   if ( !all_children )
01773     return;
01774     
01775   volumes.clean_out();
01776   body_ptr->ref_volumes(volumes);
01777   for ( i = volumes.size(); i--; )
01778     remove_virtual_geometry( volumes.step_and_get(), true );
01779 }
01780 
01781 void VirtualQueryEngine::remove_virtual_geometry( RefVolume* vol_ptr,
01782                                              bool all_children )
01783 {
01784   int i;
01785   DLIList<RefFace*> faces, part_results;
01786   bool had_virtual_geometry = false;
01787   vol_ptr->ref_faces( faces );
01788   for ( i = faces.size(); i--; ) 
01789   {
01790     if ( dynamic_cast<CompositeSurface*>(faces.step_and_get()->get_surface_ptr()) )
01791     {
01792       CompositeTool::instance()->uncomposite(faces.get());
01793       had_virtual_geometry = true;
01794     }
01795   }
01796   
01797   faces.clean_out();
01798   vol_ptr->ref_faces( faces );
01799   for ( i = faces.size(); i--; ) 
01800   {
01801     if ( !dynamic_cast<PartitionSurface*>(faces.step_and_get()->get_surface_ptr()))
01802       faces.change_to(0);
01803   }
01804   faces.remove_all_with_value(0);
01805   if ( faces.size() )
01806   {
01807     PartitionTool::instance()->unpartitionAll(faces, part_results);
01808     had_virtual_geometry = true;
01809   }
01810   
01811   if ( !all_children )  
01812     return;
01813   
01814   faces.clean_out();
01815   vol_ptr->ref_faces( faces );
01816   for ( i = faces.size(); i--; )
01817     remove_virtual_geometry( faces.step_and_get() );
01818 
01819   if( had_virtual_geometry )
01820     AppUtil::instance()->send_event(GeometryEvent(GeometryEvent::TOPOLOGY_MODIFIED, vol_ptr));
01821 }
01822 
01823 void VirtualQueryEngine::remove_virtual_geometry( RefFace* face_ptr )
01824 {
01825   int i;
01826   DLIList<RefEdge*> edges, part_results;
01827   face_ptr->ref_edges( edges );
01828   for ( i = edges.size(); i--; ) {
01829     if ( dynamic_cast<CompositeCurve*>(edges.step_and_get()->get_curve_ptr()) )
01830       CompositeTool::instance()->uncomposite(edges.get());
01831   }
01832   
01833   edges.clean_out();
01834   face_ptr->ref_edges( edges );
01835   for ( i = edges.size(); i--; ) {
01836     if ( !dynamic_cast<PartitionCurve*>(edges.step_and_get()->get_curve_ptr()))
01837       edges.change_to(0);
01838   }
01839   edges.remove_all_with_value(0);
01840   if ( edges.size() )
01841     PartitionTool::instance()->unpartitionAll(edges, part_results);
01842 }
01843   
01844    
01845   
01846        
01847 CubitStatus VirtualQueryEngine::export_solid_model( DLIList<TopologyBridge*>& ,
01848                                         const char* ,
01849                                         Model_File_Type ,
01850                                         const CubitString &,
01851                                         ModelExportOptions & )                                                       
01852 {
01853   return CUBIT_FAILURE;
01854 }
01855 
01856 CubitStatus VirtualQueryEngine::save_temp_geom_file( DLIList<TopologyBridge*>& ,
01857                                         const char* ,
01858                                         const CubitString &,
01859                                         CubitString &, 
01860                                         CubitString &)  
01861 {
01862   return CUBIT_FAILURE;
01863 }
01864   
01865 CubitStatus VirtualQueryEngine::import_solid_model( const char* ,
01866                                                     Model_File_Type,
01867                                                     DLIList<TopologyBridge*>&,
01868                                                     ModelImportOptions &import_options )  
01869 {
01870   PRINT_INFO("VirtualQueryEngine::import_solid_model\n");
01871   
01872   default_error_message( "import_solid_model()");
01873   return CUBIT_FAILURE;
01874 }
01875 
01876 void VirtualQueryEngine::delete_solid_model_entities(DLIList<BodySM*>& list) const
01877 {
01878   for ( int i = list.size(); i--; )
01879     delete_solid_model_entities( list.get_and_step() );
01880 }
01881       
01882 
01883 
01884 CubitStatus VirtualQueryEngine::delete_solid_model_entities(
01885   BodySM* bodysm ) const
01886 { 
01887   CompositeBody* compbod = dynamic_cast<CompositeBody*>(bodysm);
01888   if (compbod)
01889   {
01890     while (compbod->num_bodies())
01891     {
01892       BodySM* dead_body = compbod->get_body( compbod->num_bodies() - 1 );
01893       dead_body->get_geometry_query_engine()->delete_solid_model_entities( dead_body );
01894     }
01895   
01896     CompositeEngine::instance().clean_out_deactivated_geometry();
01897     return CUBIT_SUCCESS;
01898   }
01899   
01900   
01901   PartitionBody* bod = dynamic_cast<PartitionBody*>(bodysm);
01902   if ( !bod )
01903     return CUBIT_FAILURE;
01904   
01905   PartitionEngine::instance().delete_solid_model_entities( bod, bodysm );
01906   if ( bodysm ) {
01907     bodysm->get_geometry_query_engine()->delete_solid_model_entities(bodysm);
01908   }
01909   return CUBIT_SUCCESS;
01910 }
01911 
01912 CubitStatus VirtualQueryEngine::delete_solid_model_entities(
01913   Surface* surf_ptr ) const
01914 {
01915   PartitionSurface* ps_ptr = dynamic_cast<PartitionSurface*>(surf_ptr);
01916   CompositeSurface* cs_ptr = dynamic_cast<CompositeSurface*>(surf_ptr);
01917   
01918   if (cs_ptr)
01919   {
01920     while(cs_ptr->num_surfs())
01921     {
01922       Surface* dead_surf = cs_ptr->get_surface(cs_ptr->num_surfs()-1);
01923       dead_surf->get_geometry_query_engine()->delete_solid_model_entities(dead_surf);
01924     }
01925     
01926     CompositeEngine::instance().clean_out_deactivated_geometry();
01927   }
01928   
01929   else if( ps_ptr )
01930   {
01931     PartitionEngine::instance().delete_solid_model_entities( ps_ptr, surf_ptr );
01932     if ( surf_ptr )
01933       surf_ptr->get_geometry_query_engine()->delete_solid_model_entities(surf_ptr);
01934   }
01935   
01936   return CUBIT_SUCCESS;
01937 }
01938 
01939 CubitStatus VirtualQueryEngine::delete_solid_model_entities(
01940   Curve* curve_ptr ) const
01941 {
01942   CompositeCurve* cc_ptr = dynamic_cast<CompositeCurve*>(curve_ptr);
01943   PartitionCurve* pc_ptr = dynamic_cast<PartitionCurve*>(curve_ptr);
01944 
01945   if( cc_ptr )
01946   {
01947     while(cc_ptr->num_curves())
01948     {
01949       Curve* dead_curv = cc_ptr->get_curve(cc_ptr->num_curves()-1);
01950       dead_curv->get_geometry_query_engine()->delete_solid_model_entities(dead_curv);
01951     }
01952     
01953     CompositeEngine::instance().clean_out_deactivated_geometry();
01954   }
01955   else if( pc_ptr )
01956   {
01957     PartitionEngine::instance().delete_solid_model_entities( pc_ptr, curve_ptr );
01958     if ( curve_ptr )
01959       curve_ptr->get_geometry_query_engine()->delete_solid_model_entities(curve_ptr);
01960   }
01961  
01962   return CUBIT_SUCCESS;
01963 }
01964 
01965 CubitStatus VirtualQueryEngine::delete_solid_model_entities( TBPoint* ) const
01966 {
01967   return CUBIT_FAILURE;
01968 }
01969 
01970 CubitStatus VirtualQueryEngine::fire_ray( CubitVector &origin,
01971                                           CubitVector &direction,
01972                                           DLIList<TopologyBridge*> &at_entity_list,
01973                                           DLIList<double> &ray_params,
01974                                           int max_hits,
01975                                           double ray_radius,
01976                                           DLIList<TopologyBridge*> *hit_entity_list_ptr) const
01977 {
01978   // Note: for now assume we will only get curves or surfaces
01979 
01980   int i;
01981   int prev_num_hits = ray_params.size();
01982   GeometryQueryEngine *gqe = 0;
01983   TopologyBridge *bridge_ptr;
01984 
01985   // This is only needed because this function is "const"
01986   VirtualQueryEngine *vqe = VirtualQueryEngine::instance();
01987 
01988   at_entity_list.reset();
01989   for( i=at_entity_list.size(); i--; )
01990   {
01991     prev_num_hits = ray_params.size();
01992     bridge_ptr = at_entity_list.get_and_step();
01993 
01994     gqe = bridge_ptr->get_geometry_query_engine();
01995     if( !gqe )
01996     {
01997       PRINT_ERROR( "Unable to find geometry engine associated with an entity!\n" );
01998       return CUBIT_FAILURE;
01999     }
02000 
02001     Curve *curve_ptr = CAST_TO( bridge_ptr, Curve );
02002     if( curve_ptr )
02003     {
02004       DLIList<TopologyBridge*> tb_curve_list;
02005       vqe->get_underlying_curves( curve_ptr, tb_curve_list );
02006 
02007       if( tb_curve_list.size() > 0 )
02008       {
02009         gqe = tb_curve_list.get()->get_geometry_query_engine();
02010 
02011         gqe->fire_ray( origin, direction, tb_curve_list, ray_params, max_hits,
02012           ray_radius, hit_entity_list_ptr );
02013 
02014         // If curve_ptr is a PartitionCurve, it could be smaller than the underlying curve.
02015         // This means we have to check to make sure any hit points lie inside the curve. Remove if they don't.
02016         if (CAST_TO(curve_ptr, PartitionCurve))
02017         {
02018             // start iterating at the first new ray_param
02019             ray_params.reset();
02020             ray_params.step(prev_num_hits);
02021             hit_entity_list_ptr->reset();
02022             hit_entity_list_ptr->step(prev_num_hits);
02023             
02024             int j;
02025             for (j=prev_num_hits; j<ray_params.size(); j++)
02026             {
02027                 CubitVector *loc_ptr;
02028                 double param = ray_params.get();
02029 
02030                 loc_ptr = new CubitVector;
02031                 origin.next_point( direction, param, *loc_ptr );
02032                 
02033                 CubitPointContainment containment = CUBIT_PNT_UNKNOWN;
02034                 containment = curve_ptr->point_containment(*loc_ptr);
02035                 if ( (containment != CUBIT_PNT_ON) && (containment != CUBIT_PNT_BOUNDARY) )
02036                 {
02037                     //remove from the hit list
02038                     ray_params.remove();
02039                     hit_entity_list_ptr->remove();
02040                 }
02041                 else
02042                 {
02043                     ray_params.step();
02044                     hit_entity_list_ptr->step();
02045                 }
02046             }
02047         }
02048 
02049       }
02050     }
02051 
02052     Surface *surface_ptr = CAST_TO( bridge_ptr, Surface );
02053     if( surface_ptr )
02054     {
02055       DLIList<TopologyBridge*> tb_surface_list;
02056       vqe->get_underlying_surfaces( surface_ptr, tb_surface_list );
02057 
02058       if( tb_surface_list.size() > 0 )
02059       {
02060         gqe = tb_surface_list.get()->get_geometry_query_engine();
02061 
02062         gqe->fire_ray( origin, direction, tb_surface_list, ray_params, max_hits,
02063           ray_radius, hit_entity_list_ptr );
02064         
02065         // If surface_ptr is a PartitionSurface, it could be smaller than the underlying surface.
02066         // This means we have to check to make sure any hit points lie inside the surface. Remove if they don't.
02067         if (CAST_TO(surface_ptr, PartitionSurface))
02068         {
02069             // start iterating at the first new ray_param
02070             ray_params.reset();
02071             ray_params.step(prev_num_hits);
02072             hit_entity_list_ptr->reset();
02073             hit_entity_list_ptr->step(prev_num_hits);
02074             
02075             int j;
02076             for (j=prev_num_hits; j<ray_params.size(); j++)
02077             {
02078                 CubitVector *loc_ptr;
02079                 double param = ray_params.get();
02080 
02081                 loc_ptr = new CubitVector;
02082                 origin.next_point( direction, param, *loc_ptr );
02083                 
02084                 CubitPointContainment containment = CUBIT_PNT_UNKNOWN;
02085                 containment = surface_ptr->point_containment(*loc_ptr);
02086                 if ( (containment != CUBIT_PNT_ON) && (containment != CUBIT_PNT_BOUNDARY) )
02087                 {
02088                     //remove from the hit list
02089                     ray_params.remove();
02090                     hit_entity_list_ptr->remove();
02091                 }
02092                 else
02093                 {
02094                     ray_params.step();
02095                     hit_entity_list_ptr->step();
02096                 }
02097             }
02098         }
02099 
02100       }
02101     }
02102 
02103   }
02104 
02105   if( hit_entity_list_ptr && hit_entity_list_ptr->size() != ray_params.size() )
02106     PRINT_WARNING( "Hit entity list size not equal to number of hits\n" );
02107 
02108   // Account for max hits
02109   if( max_hits != 0 )
02110   {
02111     if( ray_params.size() <= max_hits )
02112       return CUBIT_SUCCESS;
02113 
02114     for( i=ray_params.size()-max_hits; i--; )
02115     {
02116       ray_params.last();
02117       ray_params.remove();
02118       if( hit_entity_list_ptr )
02119       {
02120         hit_entity_list_ptr->last();
02121         hit_entity_list_ptr->remove();
02122       }
02123     }
02124   }
02125 
02126   return CUBIT_SUCCESS;
02127 }
02128 
02129 double VirtualQueryEngine::get_sme_resabs_tolerance() const
02130 {
02131   return GEOMETRY_RESABS;
02132 }
02133 
02134 double VirtualQueryEngine::set_sme_resabs_tolerance( double )
02135 {
02136   PRINT_INFO("VirtualQueryEngine::set_sme_resabs_tolerance\n");
02137   
02138   default_error_message( "set_sme_resabs_tolerance()");
02139   return 0;
02140 }
02141 
02142 CubitStatus VirtualQueryEngine::set_int_option( const char* , int )
02143 {
02144   PRINT_INFO("VirtualQueryEngine::set_int_option\n");
02145   
02146   default_error_message( "set_int_option()");
02147   return CUBIT_FAILURE;
02148 }
02149 
02150 CubitStatus VirtualQueryEngine::set_dbl_option( const char* , double )
02151 {
02152   PRINT_INFO("VirtualQueryEngine::set_dbl_option\n");
02153   
02154   default_error_message( "set_dbl_option()");
02155   return CUBIT_FAILURE;
02156 }
02157 
02158 CubitStatus VirtualQueryEngine::set_str_option( const char* , const char* )
02159 {
02160   PRINT_INFO("VirtualQueryEngine::set_str_option\n");
02161   
02162   default_error_message( "set_str_option()");
02163   return CUBIT_FAILURE;
02164 }
02165 
02166 void VirtualQueryEngine::register_attributes()
02167 {
02168   CubitStatus result;
02169   result = CGMApp::instance()->attrib_manager()->register_attrib_type(
02170                                                CA_PARTITION_VG, "partition vg", "PARTITION_VG",
02171                                                CAPartitionVG_creator, CUBIT_FALSE,
02172                                                CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE,
02173                                                CUBIT_FALSE, CUBIT_FALSE);
02174   if (CUBIT_SUCCESS != result) {
02175     PRINT_ERROR("Failed to register attribute type partition vg.\n");
02176     return;
02177   }
02178 
02179   result = CGMApp::instance()->attrib_manager()->register_attrib_type(
02180                                                CA_COMPOSITE_VG, "composite vg", "COMPOSITE_VG",
02181                                                CACompositeVG_creator, CUBIT_FALSE,
02182                                                CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE,
02183                                                CUBIT_FALSE, CUBIT_FALSE);
02184   if (CUBIT_SUCCESS != result) {
02185     PRINT_ERROR("Failed to register attribute type composite vg.\n");
02186     return;
02187   }
02188 
02189   result = CGMApp::instance()->attrib_manager()->register_attrib_type(
02190                                                CA_VIRTUAL_VG, "virtual vg", "VIRTUAL_VG",
02191                                                CAVirtualVG_creator, CUBIT_FALSE,
02192                                                CUBIT_FALSE, CUBIT_TRUE, CUBIT_TRUE,
02193                                                CUBIT_FALSE, CUBIT_FALSE);
02194   if (CUBIT_SUCCESS != result) {
02195     PRINT_ERROR("Failed to register attribute type virtual vg.\n");
02196   }
02197 }
02198 
02199 
02200 
02201 CubitStatus VirtualQueryEngine::translate( BodySM* body, 
02202                                               const CubitVector& offset )
02203 {
02204   if (PartitionBody* part = dynamic_cast<PartitionBody*>(body))
02205     return PartitionEngine::instance().translate( part, offset );
02206   else if(CompositeBody* comp = dynamic_cast<CompositeBody*>(body))
02207     return CompositeEngine::instance().translate( comp, offset );
02208 
02209   PRINT_ERROR("Non-virtual entity in VGE::translate.\n");
02210   return CUBIT_FAILURE;
02211 }
02212 
02213 CubitStatus VirtualQueryEngine::rotate   ( BodySM* body, 
02214                                               const CubitVector& axis, 
02215                                               double angle )
02216 {
02217   if (PartitionBody* part = dynamic_cast<PartitionBody*>(body))
02218     return PartitionEngine::instance().rotate( part, axis, angle );
02219   else if(CompositeBody* comp = dynamic_cast<CompositeBody*>(body))
02220     return CompositeEngine::instance().rotate( comp, axis, angle );
02221 
02222   PRINT_ERROR("Non-virtual entity in VGE::rotate.\n");
02223   return CUBIT_FAILURE;
02224 }
02225 
02226 CubitStatus VirtualQueryEngine::scale    ( BodySM* body, 
02227                                               double factor )
02228 {
02229   return scale( body, CubitVector(factor,factor,factor) );
02230 }
02231 
02232 CubitStatus VirtualQueryEngine::scale    ( BodySM* body, 
02233                                               const CubitVector& factors )
02234 {
02235   if (PartitionBody* part = dynamic_cast<PartitionBody*>(body))
02236     return PartitionEngine::instance().scale( part, factors );
02237   else if(CompositeBody* comp = dynamic_cast<CompositeBody*>(body))
02238     return CompositeEngine::instance().scale( comp, factors );
02239 
02240   PRINT_ERROR("Non-virtual entity in VGE::scale.\n");
02241   return CUBIT_FAILURE;
02242 }
02243 
02244 CubitStatus VirtualQueryEngine::reflect  ( BodySM* body, 
02245                                               const CubitVector& axis )
02246 {
02247   if (PartitionBody* part = dynamic_cast<PartitionBody*>(body))
02248     return PartitionEngine::instance().reflect( part, axis );
02249   else if(CompositeBody* comp = dynamic_cast<CompositeBody*>(body))
02250     return CompositeEngine::instance().reflect( comp, axis );
02251 
02252   PRINT_ERROR("Non-virtual entity in VGE::reflect.\n");
02253   return CUBIT_FAILURE;
02254 }
02255 
02256 CubitStatus VirtualQueryEngine::restore_transform( BodySM* body )
02257 {
02258   if (PartitionBody* part = dynamic_cast<PartitionBody*>(body))
02259     return PartitionEngine::instance().restore_transform( part );
02260   else if(CompositeBody* comp = dynamic_cast<CompositeBody*>(body))
02261     return CompositeEngine::instance().restore_transform( comp );
02262 
02263   PRINT_ERROR("Non-virtual entity in VGE::restore_transform.\n");
02264   return CUBIT_FAILURE;
02265 }
02266 
02267 CubitStatus VirtualQueryEngine::translate( GeometryEntity* ent, 
02268                                               const CubitVector& offset )
02269 {
02270   if (PartitionEntity* part = dynamic_cast<PartitionEntity*>(ent))
02271     return PartitionEngine::instance().translate( part, offset );
02272   else if(CompositeSurface* csurf = dynamic_cast<CompositeSurface*>(ent))
02273     return CompositeEngine::instance().translate( csurf, offset );
02274   else if(CompositeCurve* ccurve = dynamic_cast<CompositeCurve*>(ent))
02275     return CompositeEngine::instance().translate( ccurve, offset );
02276 
02277   PRINT_ERROR("Non-virtual entity in VGE::translate.\n");
02278   return CUBIT_FAILURE;
02279 }
02280 
02281 CubitStatus VirtualQueryEngine::rotate   ( GeometryEntity* ent, 
02282                                               const CubitVector& axis, 
02283                                               double degrees )
02284 {
02285   if (PartitionEntity* part = dynamic_cast<PartitionEntity*>(ent))
02286     return PartitionEngine::instance().rotate( part, axis, degrees );
02287   else if(CompositeSurface* csurf = dynamic_cast<CompositeSurface*>(ent))
02288     return CompositeEngine::instance().rotate( csurf, axis, degrees );
02289   else if(CompositeCurve* ccurve = dynamic_cast<CompositeCurve*>(ent))
02290     return CompositeEngine::instance().rotate( ccurve, axis, degrees );
02291 
02292   PRINT_ERROR("Non-virtual entity in VGE::rotate.\n");
02293   return CUBIT_FAILURE;
02294 }
02295 
02296 CubitStatus VirtualQueryEngine::scale    ( GeometryEntity* ent, 
02297                                               double factor )
02298 {
02299   return scale( ent, CubitVector( factor, factor, factor ) );
02300 }
02301 
02302 CubitStatus VirtualQueryEngine::scale    ( GeometryEntity* ent, 
02303                                               const CubitVector& factors )
02304 {
02305   if (PartitionEntity* part = dynamic_cast<PartitionEntity*>(ent))
02306     return PartitionEngine::instance().scale( part, factors );
02307   else if(CompositeSurface* csurf = dynamic_cast<CompositeSurface*>(ent))
02308     return CompositeEngine::instance().scale( csurf, factors );
02309   else if(CompositeCurve* ccurve = dynamic_cast<CompositeCurve*>(ent))
02310     return CompositeEngine::instance().scale( ccurve, factors );
02311 
02312   PRINT_ERROR("Non-virtual entity in VGE::scale.\n");
02313   return CUBIT_FAILURE;
02314 }
02315 
02316 CubitStatus VirtualQueryEngine::reflect  ( GeometryEntity* ent, 
02317                                               const CubitVector& axis )
02318 {
02319   if (PartitionEntity* part = dynamic_cast<PartitionEntity*>(ent))
02320     return PartitionEngine::instance().reflect( part, axis );
02321   else if(CompositeSurface* csurf = dynamic_cast<CompositeSurface*>(ent))
02322     return CompositeEngine::instance().reflect( csurf, axis );
02323   else if(CompositeCurve* ccurve = dynamic_cast<CompositeCurve*>(ent))
02324     return CompositeEngine::instance().reflect( ccurve, axis );
02325 
02326   PRINT_ERROR("Non-virtual entity in VGE::reflect.\n");
02327   return CUBIT_FAILURE;
02328 }
02329 
02330 //Function should only be called on volumes of multi-volume bodies
02331 CubitBoolean VirtualQueryEngine::volumes_overlap (Lump *lump1, Lump *lump2 ) const
02332 {
02333   PartitionLump* partition_lump1 = dynamic_cast<PartitionLump*>(lump1);
02334   PartitionLump* partition_lump2 = dynamic_cast<PartitionLump*>(lump2);
02335 
02336   Lump *tmp_lump1 = lump1; 
02337   if( partition_lump1 )
02338     tmp_lump1 = partition_lump1->real_lump();
02339 
02340   Lump *tmp_lump2 = lump2; 
02341   if( partition_lump2 )
02342     tmp_lump2 = partition_lump2->real_lump();
02343 
02344   GeometryQueryEngine *gqe = tmp_lump1->get_geometry_query_engine();
02345   if( gqe != tmp_lump2->get_geometry_query_engine() )
02346   {
02347     PRINT_ERROR("Volumes must be of the same type (, SolidWorks, etc) to\n"
02348                 "find if they overlap.\n");
02349     return CUBIT_FALSE;
02350   }
02351 
02352   return gqe->volumes_overlap( tmp_lump1, tmp_lump2 );
02353 }
02354 
02355 
02356 CubitBoolean VirtualQueryEngine::bodies_overlap (BodySM *body_ptr_1, BodySM *body_ptr_2 ) const
02357 {
02358   PartitionBody* partition_body1 = dynamic_cast<PartitionBody*>(body_ptr_1);
02359   PartitionBody* partition_body2 = dynamic_cast<PartitionBody*>(body_ptr_2);
02360 
02361   BodySM *body1 = body_ptr_1;
02362   if( partition_body1 )
02363     body1 = partition_body1->real_body();
02364 
02365   BodySM *body2 = body_ptr_2;
02366   if( partition_body2 )
02367     body2 = partition_body2->real_body();
02368   
02369   GeometryQueryEngine *gqe = body1->get_geometry_query_engine();
02370   if( gqe != body2->get_geometry_query_engine() )
02371   {
02372     PRINT_ERROR("Volumes must be of the same type (, SolidWorks, etc) to\n"
02373                 "find if they overlap.\n");
02374     return CUBIT_FALSE;
02375   }
02376 
02377   return gqe->bodies_overlap( body1, body2 );
02378 
02379 }
02380 
02381 TopologyBridge* VirtualQueryEngine::get_visible_entity_at_point(TopologyBridge* hidden_tb, CubitVector* point)
02382 {
02383     // Determine entity type; should only be Curve or TBPoint
02384 
02385     int j, k;
02386     bool added_entity = false;
02387     TopologyBridge* bridge_ptr = hidden_tb;
02388     TopologyBridge* tb_owner = NULL;
02389     bool hidden = CUBIT_TRUE;
02390 
02391     TopologyBridge* visible_tb = NULL;
02392 
02393     while (hidden)
02394     {
02395         tb_owner = dynamic_cast<TopologyBridge*>(bridge_ptr->owner());
02396         if( tb_owner )
02397         {
02398             if( tb_owner->topology_entity() )
02399             {
02400                 visible_tb = tb_owner;
02401                 hidden = CUBIT_FALSE;
02402                 added_entity = true;
02403                 continue;
02404             }
02405             else
02406                 hidden = CUBIT_TRUE;      
02407         }
02408         else
02409         {
02410             if( bridge_ptr->topology_entity() )
02411             {
02412                 visible_tb = bridge_ptr;
02413                 hidden = CUBIT_FALSE;
02414                 added_entity = true;
02415                 continue;
02416             }
02417             else
02418             {
02419                 hidden = CUBIT_TRUE;
02420             }
02421         }
02422 
02423 
02424         TopologyBridge *tb_ptr;
02425         if( tb_owner )
02426             tb_ptr = tb_owner;
02427         else
02428             tb_ptr = bridge_ptr;
02429 
02430         TBOwner* tb_owner = tb_ptr->owner();
02431         if (CAST_TO(tb_owner, HiddenEntitySet)) // virtual geometry
02432         {
02433             TopologyBridge* parent = NULL;
02434             while (CAST_TO(tb_owner, HiddenEntitySet)) // virtual geometry
02435             {
02436                 HiddenEntitySet* hidden_set_ptr = CAST_TO(tb_owner, HiddenEntitySet);
02437                 parent = dynamic_cast<TopologyBridge*>(hidden_set_ptr->owner());
02438                 if (parent)
02439                     tb_owner = parent->owner();
02440             }
02441             if (parent)
02442             {
02443                 bridge_ptr = parent;
02444                 added_entity = true;
02445                 continue;
02446             }
02447         }
02448         else if (CAST_TO(tb_owner, SubEntitySet)) // partition geometry
02449     {
02450             SubEntitySet* sub_set_ptr = CAST_TO(tb_owner, SubEntitySet);
02451 
02452             DLIList<TopologyBridge*> owner_list;
02453             sub_set_ptr->get_owners(owner_list);
02454             owner_list.reset();
02455             // need to traverse all the entities that make up the original geometry
02456             //  if intersected a surface, and the surface is partitioned into mult surfaces,
02457             //  which surface did we hit? Did we hit the curve in between? The vertices? gahhhh...
02458             for (j=0; j<owner_list.size(); j++)
02459             {
02460                 TopologyBridge* owner_partition = owner_list.get_and_step();
02461                 //determine geometry type and call point_containment
02462 
02463                 CubitPointContainment containment = CUBIT_PNT_UNKNOWN;
02464 
02465                 if (CAST_TO(owner_partition, Surface))
02466                 {
02467                     containment = CAST_TO(owner_partition, Surface)->point_containment(*point);
02468                     switch (containment)
02469                     {
02470                     case CUBIT_PNT_OFF:
02471                         break;
02472                     case CUBIT_PNT_ON:
02473                         bridge_ptr = owner_partition;
02474                         added_entity = true;
02475                         break;
02476                     case CUBIT_PNT_UNKNOWN:
02477                         break;
02478                     case CUBIT_PNT_BOUNDARY:
02479                         {
02480                             DLIList<TopologyBridge*> children, related_loops, related_coedges;
02481                             DLIList<TopologyBridge*> related_curves, temp;
02482 
02483                             // Goal: get curves (incl. virtual ones)
02484                             // Note: can't use ->curves() func b/c it won't grab the virtual curves
02485 
02486                             // get all Loops, including virtual
02487                             owner_partition->get_children( related_loops, true );
02488 
02489                             related_loops.reset();
02490                             int ii;
02491 
02492                             // get all CoEdges
02493                             for (ii = related_loops.size(); ii--;)
02494                             {
02495                                 temp.clean_out();
02496                                 related_loops.get_and_step()->get_children(temp, true);
02497                                 related_coedges.merge_unique(temp);
02498                             }
02499                             // get all Curves
02500                             for (ii = related_coedges.size(); ii--;)
02501                             {
02502                                 temp.clean_out();
02503                                 related_coedges.get_and_step()->get_children(temp, true);
02504                                 related_curves.merge_unique(temp);
02505                             }
02506 
02507                             CAST_LIST(related_curves, children, TopologyBridge);
02508                             for (k=0; k<children.size(); k++)
02509                             {
02510                                 // CAST and do point_containment for each curve
02511                                 containment = CUBIT_PNT_UNKNOWN;
02512                                 TopologyBridge* partition_curve = children.get_and_step();
02513                                 containment = CAST_TO(partition_curve, Curve)->point_containment(*point);
02514                                 switch (containment)
02515                                 {
02516                                 case CUBIT_PNT_OFF:
02517                                 case CUBIT_PNT_UNKNOWN:
02518                                     break;
02519                                 case CUBIT_PNT_ON:
02520                                     bridge_ptr = partition_curve;
02521                                     added_entity = true;
02522                                     break;
02523                                 case CUBIT_PNT_BOUNDARY:
02524                                     {
02525                                         // CAST and do point_containment for each vertex
02526                                         children.clean_out();
02527                                         partition_curve->get_children(children, true);
02528                                         int kk;
02529                                         for (kk=0; kk<children.size(); kk++)
02530                                         {
02531                                             TopologyBridge* partition_vertex = children.get_and_step();
02532                                             containment = CUBIT_PNT_UNKNOWN;
02533                                             CubitVector coords = CAST_TO(partition_vertex, TBPoint)->coordinates();
02534                                             if (coords.distance_between_squared(*point) < GEOMETRY_RESABS*GEOMETRY_RESABS)
02535                                             {
02536                                                 containment = CUBIT_PNT_ON;
02537                                                 bridge_ptr = partition_vertex;
02538                                                 added_entity = true;
02539                                                 break;
02540                                             }
02541                                             else
02542                                                 containment = CUBIT_PNT_OFF;
02543                                         }
02544                                     }
02545                                 }
02546 
02547                                 if (added_entity)
02548                                     break;
02549                             }                              
02550                             break;
02551                         }
02552                     }
02553                     if (added_entity)
02554                         break;
02555                 }
02556                 else if (CAST_TO(owner_partition, Curve))
02557                 {
02558                     // CAST and do point_containment for each curve
02559                     containment = CUBIT_PNT_UNKNOWN;
02560                     containment = CAST_TO(owner_partition, Curve)->point_containment(*point);
02561                     switch (containment)
02562                     {
02563                     case CUBIT_PNT_OFF:
02564                     case CUBIT_PNT_UNKNOWN:
02565                         break;
02566                     case CUBIT_PNT_ON:
02567                         bridge_ptr = owner_partition;
02568                         added_entity = true;
02569                         break;
02570                     case CUBIT_PNT_BOUNDARY:
02571                         {
02572                             // CAST and do point_containment for each vertex
02573                             DLIList<TopologyBridge*> children;
02574                             children.clean_out();
02575                             owner_partition->get_children(children, true);
02576                             int kk;
02577                             for (kk=0; kk<children.size(); kk++)
02578                             {
02579                                 TopologyBridge* partition_vertex = children.get_and_step();
02580                                 containment = CUBIT_PNT_UNKNOWN;
02581                                 CubitVector coords = CAST_TO(partition_vertex, TBPoint)->coordinates();
02582                                 if (coords.distance_between_squared(*point) < GEOMETRY_RESABS*GEOMETRY_RESABS)
02583                                 {
02584                                     containment = CUBIT_PNT_ON;
02585                                     bridge_ptr = partition_vertex;
02586                                     added_entity = true;
02587                                     break;
02588                                 }
02589                                 else
02590                                     containment = CUBIT_PNT_OFF;
02591                             }
02592                             break;
02593                         }
02594                     }
02595 
02596                     if (added_entity)
02597                         break;
02598                 }
02599 
02600                 else if (CAST_TO(owner_partition, TBPoint))
02601                 {
02602                     CubitVector coords = CAST_TO(owner_partition, TBPoint)->coordinates();
02603                     if (coords.distance_between_squared(*point) < GEOMETRY_RESABS*GEOMETRY_RESABS)
02604                     {
02605                         containment = CUBIT_PNT_ON;
02606                         bridge_ptr = owner_partition;
02607                         added_entity = true;
02608                         break;
02609                     }
02610                     else
02611                         containment = CUBIT_PNT_OFF;
02612                 }
02613 
02614                 else
02615                     PRINT_WARNING("Hit unknown partition entity.\n");
02616 
02617 
02618             }
02619             if (!added_entity)
02620             {
02621                 visible_tb = NULL;
02622                 hidden = CUBIT_FALSE;
02623                 //break;
02624             }
02625 
02626         }
02627 
02628 
02629     } //while
02630 
02631     return visible_tb;
02632 }
02633 
02634 
02635 CubitStatus VirtualQueryEngine::get_visible_entities( TopologyBridge *hidden_tb, 
02636                                                       DLIList<TopologyBridge*> &real_tbs )
02637 {
02638     int j;  
02639     TopologyBridge* bridge_ptr = NULL;
02640     TopologyBridge* tb_owner = NULL;
02641 
02642     TopologyBridge* visible_tb = NULL;
02643 
02644   DLIList<TopologyBridge*> tbs_to_search;
02645   tbs_to_search.append( hidden_tb );
02646 
02647     while(tbs_to_search.size())
02648     {
02649     bridge_ptr = tbs_to_search.pop();
02650 
02651         tb_owner = dynamic_cast<TopologyBridge*>(bridge_ptr->owner());
02652         if( tb_owner )
02653         {
02654             if( tb_owner->topology_entity() )
02655             {
02656                 visible_tb = tb_owner;
02657                 real_tbs.append( visible_tb ); 
02658         continue;
02659             }       
02660         }
02661         else
02662         {
02663             if( bridge_ptr->topology_entity() )
02664             {
02665                 visible_tb = bridge_ptr;
02666                 real_tbs.append( visible_tb );        
02667         continue;
02668             }           
02669         }
02670 
02671 
02672         TopologyBridge *tb_ptr;
02673         if( tb_owner )
02674             tb_ptr = tb_owner;
02675         else
02676             tb_ptr = bridge_ptr;
02677 
02678         TBOwner* tb_owner = tb_ptr->owner();
02679         if (CAST_TO(tb_owner, HiddenEntitySet)) // it is a composite
02680         {
02681             TopologyBridge* parent = NULL;
02682             while (CAST_TO(tb_owner, HiddenEntitySet)) // virtual geometry
02683             {
02684                 HiddenEntitySet* hidden_set_ptr = CAST_TO(tb_owner, HiddenEntitySet);
02685                 parent = dynamic_cast<TopologyBridge*>(hidden_set_ptr->owner());
02686                 if (parent)
02687                     tb_owner = parent->owner();
02688             }
02689             if (parent)
02690             {
02691                 tbs_to_search.append( parent );
02692                 continue;
02693             }
02694         }
02695         else if (CAST_TO(tb_owner, SubEntitySet)) // partition geometry
02696     {
02697             SubEntitySet* sub_set_ptr = CAST_TO(tb_owner, SubEntitySet);
02698 
02699             DLIList<TopologyBridge*> owner_list;
02700             sub_set_ptr->get_owners(owner_list);
02701             owner_list.reset();
02702             // need to traverse all the entities that make up the original geometry
02703             //  if intersected a surface, and the surface is partitioned into mult surfaces,
02704             //  which surface did we hit? Did we hit the curve in between? The vertices? gahhhh...
02705             for (j=0; j<owner_list.size(); j++)
02706             {
02707                 TopologyBridge* owner_partition = owner_list.get_and_step();
02708         tbs_to_search.append( owner_partition );        
02709             }
02710         }
02711   }
02712 
02713   real_tbs.uniquify_ordered();
02714 
02715   return CUBIT_SUCCESS;
02716 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines