cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : RefVertex.cpp 00003 // 00004 // Purpose : This file contains the implementation of the class 00005 // RefVertex. A RefVertex is a TopologyEntity and represents 00006 // a point or vertex in the topology of the Model. 00007 // 00008 // Special Notes : 00009 // 00010 // Creator : Xuechen Liu 00011 // 00012 // Creation Date : 07/11/96 00013 // 00014 // Owner : Malcolm J. Panthaki 00015 //------------------------------------------------------------------------- 00016 00017 00018 #include <assert.h> 00019 00020 #include "CubitDefines.h" 00021 #include "GeometryDefines.h" 00022 00023 #include "RefEntityFactory.hpp" 00024 #include "GeometryQueryTool.hpp" 00025 #include "GeometryQueryEngine.hpp" 00026 #include "ModelQueryEngine.hpp" 00027 00028 #include "RefVolume.hpp" 00029 #include "RefFace.hpp" 00030 #include "RefEdge.hpp" 00031 #include "RefVertex.hpp" 00032 #include "Point.hpp" 00033 #include "DLIList.hpp" 00034 #include "CastTo.hpp" 00035 #include "ToolData.hpp" 00036 #include "CoVertex.hpp" 00037 00038 //------------------------------------------------------------------------- 00039 // Purpose : Constructor with a pointer to a Point 00040 // 00041 // Special Notes : 00042 // 00043 // Creator : Xuechen Liu 00044 // 00045 // Creation Date : 07/11/96 00046 //------------------------------------------------------------------------- 00047 RefVertex::RefVertex(TBPoint* pointPtr) 00048 { 00049 // Set the GeometryEntity pointer 00050 if (pointPtr != NULL) 00051 { 00052 set_geometry_entity_ptr(pointPtr) ; 00053 } 00054 else 00055 { 00056 PRINT_ERROR("In the RefVertex(TBPoint*) constructor\n"); 00057 PRINT_ERROR(" Input TBPoint pointer is NULL\n"); 00058 assert(CUBIT_FALSE); 00059 } 00060 00061 // Initialize the member data 00062 initialize(); 00063 } 00064 00065 //------------------------------------------------------------------------- 00066 // Purpose : The destructor. 00067 // 00068 // Special Notes : 00069 // 00070 // Creator : Malcolm J. Panthaki 00071 // 00072 // Creation Date : 11/06/96 00073 //------------------------------------------------------------------------- 00074 RefVertex::~RefVertex() 00075 { 00076 } 00077 00078 //------------------------------------------------------------------------- 00079 // Purpose : Return a pointer to the point associated with a vertex. 00080 // 00081 // Special Notes : 00082 // 00083 // Creator : Xuechen Liu 00084 // 00085 // Creation Date : 08/02/96 00086 //------------------------------------------------------------------------- 00087 TBPoint* RefVertex::get_point_ptr() 00088 { 00089 return CAST_TO(get_geometry_entity_ptr(), TBPoint) ; 00090 } 00091 00092 const TBPoint* RefVertex::get_point_ptr() const 00093 { 00094 return CAST_TO(get_geometry_entity_ptr(), TBPoint) ; 00095 } 00096 00097 00098 //------------------------------------------------------------------------- 00099 // Purpose : Returns the global coordinates of this RefVertex. 00100 // 00101 // Special Notes : 00102 // 00103 // Creator : Malcolm J. Panthaki 00104 // 00105 // Creation Date : 09/25/96 00106 //------------------------------------------------------------------------- 00107 CubitVector RefVertex::coordinates() const 00108 { 00109 const TBPoint* point_ptr = get_point_ptr(); 00110 00111 if (point_ptr != NULL) 00112 { 00113 return point_ptr->coordinates(); 00114 } 00115 else 00116 { 00117 PRINT_ERROR("In RefVertex::coordinates\n" 00118 " RefVertex %d has no GeometryEntity attached to it.\n" 00119 " THIS IS A BUG - PLEASE REPORT IT.\n", id()); 00120 assert( point_ptr != NULL ); 00121 return CubitVector(); 00122 } 00123 } 00124 00125 //------------------------------------------------------------------------- 00126 // Purpose : Return the "center point" of the RefVertex -- its 00127 // coordinates. 00128 // 00129 // Special Notes : 00130 // 00131 // Creator : Raikanta Sahu 00132 // 00133 // Creation Date : 10/30/96 00134 //------------------------------------------------------------------------- 00135 CubitVector RefVertex::center_point() 00136 { 00137 return this->coordinates(); 00138 } 00139 void RefVertex::common_ref_edges(RefVertex *other_vertex, 00140 DLIList <RefEdge*> &common_ref_edges, 00141 RefFace *owning_face) 00142 { 00143 //- returns an edge sharing the other vertex and owned by owning_face 00144 //- (if non-NULL) 00145 //- The edge must have this vertex and other_vertex as its 00146 //- start and end vertices. 00147 DLIList<RefEntity*> temp_list; 00148 join(other_vertex, temp_list); 00149 00150 int i; 00151 for (i = temp_list.size(); i > 0; i--) 00152 { 00153 RefEdge *common_edge = CAST_TO(temp_list.get(), RefEdge); 00154 //This extra 'if' block is needed in case other_vertex == this 00155 if (common_edge && 00156 ((common_edge->start_vertex() == other_vertex && 00157 common_edge->end_vertex() == this) || 00158 ( common_edge->start_vertex() == this && 00159 common_edge->end_vertex() == other_vertex ))) 00160 { 00161 if (common_edge && (!owning_face || common_edge->is_child(owning_face))) 00162 common_ref_edges.append(common_edge); 00163 } 00164 temp_list.step(); 00165 } 00166 return; 00167 } 00168 00169 RefEdge *RefVertex::common_ref_edge(RefVertex *other_vertex, 00170 RefFace *owning_face) 00171 { 00172 //- returns an edge sharing the other vertex and owned by owning_face 00173 //- (if non-NULL) 00174 //- The edge must have this vertex and other_vertex as its 00175 //- start and end vertices. 00176 DLIList<RefEntity*> temp_list; 00177 join(other_vertex, temp_list); 00178 00179 int i; 00180 for (i = temp_list.size(); i > 0; i--) { 00181 RefEdge *common_edge = CAST_TO(temp_list.get(), RefEdge); 00182 00183 if( NULL == common_edge ) 00184 continue; 00185 00186 //This extra 'if' block is needed in case other_vertex == this 00187 if ( ( common_edge->start_vertex() == other_vertex && 00188 common_edge->end_vertex() == this) || 00189 ( common_edge->start_vertex() == this && 00190 common_edge->end_vertex() == other_vertex ) ) 00191 { 00192 if (common_edge && (!owning_face || common_edge->is_child(owning_face))) 00193 return common_edge; 00194 else 00195 temp_list.step(); 00196 } 00197 else 00198 temp_list.step(); 00199 } 00200 00201 return NULL; 00202 } 00203 00204 //------------------------------------------------------------------------- 00205 // Purpose : Spatially compare two RefVertexes, notification is made if 00206 // the flag notify_ref_entity is set. 00207 // 00208 // Special Notes : 00209 // 00210 // Creator : David White 00211 // 00212 // Creation Date : 04/08/97 00213 //------------------------------------------------------------------------- 00214 CubitBoolean RefVertex::about_spatially_equal( 00215 RefVertex* ref_vertex_ptr_2, 00216 double tolerance_factor, 00217 CubitBoolean notify_ref_entity ) 00218 { 00219 if( this == ref_vertex_ptr_2 ) 00220 { 00221 if (notify_ref_entity) 00222 remove_compare_data(); 00223 return CUBIT_TRUE; 00224 } 00225 00226 const CubitVector vertex_1_position = this->coordinates(); 00227 const CubitVector vertex_2_position = ref_vertex_ptr_2->coordinates(); 00228 if (!GeometryQueryTool::instance()-> about_spatially_equal( 00229 vertex_1_position, vertex_2_position, tolerance_factor)) 00230 return CUBIT_FALSE; 00231 00232 if ( notify_ref_entity == CUBIT_TRUE ) 00233 this->comparison_found(ref_vertex_ptr_2); 00234 00235 return CUBIT_TRUE; 00236 } 00237 00238 // ********** END PUBLIC FUNCTIONS ********** 00239 00240 // ********** BEGIN PROTECTED FUNCTIONS ********** 00241 // ********** END PROTECTED FUNCTIONS ********** 00242 00243 // ********** BEGIN PRIVATE FUNCTIONS ********** 00244 00245 //------------------------------------------------------------------------- 00246 // Purpose : Initializes member data 00247 // 00248 // Special Notes : 00249 // 00250 // Creator : Malcolm J. Panthaki 00251 // 00252 // Creation Date : 10/07/96 00253 //------------------------------------------------------------------------- 00254 void RefVertex::initialize() 00255 { 00256 GeometryEntity* geom_ptr = get_geometry_entity_ptr(); 00257 int saved_id = geom_ptr->get_saved_id(); 00258 if ( !saved_id || RefEntityFactory::instance()->get_ref_vertex(saved_id) ) 00259 { 00260 saved_id = RefEntityFactory::instance()->next_ref_vertex_id(); 00261 geom_ptr->set_saved_id(saved_id); 00262 } 00263 entityId = saved_id; 00264 00265 // Initialize some attributes 00266 00267 // read and initialize attributes 00268 auto_read_cubit_attrib(); 00269 auto_actuate_cubit_attrib(); 00270 00271 // Assign a default entity name 00272 assign_default_name(); 00273 00274 } 00275 00276 void RefVertex::get_parent_ref_entities(DLIList<RefEntity*>& entity_list) 00277 { 00278 00279 // First get the type of RefEntity that is a child of "this" one 00280 DagType parent_type = get_parent_ref_entity_type();; 00281 00282 DLIList<TopologyEntity*> tempList ; 00283 00284 CubitStatus result = ModelQueryEngine::instance()-> 00285 query_model( *this, parent_type, tempList ); 00286 if (result == CUBIT_FAILURE) 00287 { 00288 PRINT_ERROR("In RefEntity::get_parent_ref_entities\n"); 00289 PRINT_ERROR(" Query failed for unknown reason.\n"); 00290 return; 00291 } 00292 00293 entity_list.clean_out(); 00294 for(int i=0; i<tempList.size(); i++) 00295 { 00296 entity_list.append(static_cast<ParentType*>(tempList[i])); 00297 } 00298 }