1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
//-------------------------------------------------------------------------
// Filename      : RefVertex.cpp
//
// Purpose       : This file contains the implementation of the class 
//                 RefVertex. A RefVertex is a TopologyEntity and represents
//                 a point or vertex in the topology of the Model. 
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 07/11/96 
//
// Owner         : Malcolm J. Panthaki
//-------------------------------------------------------------------------


#include <assert.h>

#include "CubitDefines.h"
#include "GeometryDefines.h"

#include "RefEntityFactory.hpp"
#include "GeometryQueryTool.hpp"
#include "GeometryQueryEngine.hpp"
#include "ModelQueryEngine.hpp"

#include "RefVolume.hpp"
#include "RefFace.hpp"
#include "RefEdge.hpp"
#include "RefVertex.hpp"
#include "Point.hpp"
#include "DLIList.hpp"
#include "CastTo.hpp"
#include "ToolData.hpp"
#include "CoVertex.hpp"

//-------------------------------------------------------------------------
// Purpose       : Constructor with a pointer to a Point
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 07/11/96
//-------------------------------------------------------------------------
RefVertex::RefVertex(TBPoint* pointPtr)
{
   // Set the GeometryEntity pointer
   if (pointPtr != NULL)
   {
      set_geometry_entity_ptr(pointPtr) ;
   }
   else
   {
      PRINT_ERROR("In the RefVertex(TBPoint*) constructor\n");
      PRINT_ERROR("       Input TBPoint pointer is NULL\n");
      assert(CUBIT_FALSE);
   }
   
   // Initialize the member data
   initialize();
}

//-------------------------------------------------------------------------
// Purpose       : The destructor.
//
// Special Notes :
//
// Creator       : Malcolm J. Panthaki
//
// Creation Date : 11/06/96
//-------------------------------------------------------------------------
RefVertex::~RefVertex()
{
}

//-------------------------------------------------------------------------
// Purpose       : Return a pointer to the point associated with a vertex.
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 08/02/96
//-------------------------------------------------------------------------
TBPoint* RefVertex::get_point_ptr() 
{
  return CAST_TO(get_geometry_entity_ptr(), TBPoint) ;
}

const TBPoint* RefVertex::get_point_ptr() const 
{
  return CAST_TO(get_geometry_entity_ptr(), TBPoint) ;
}


//-------------------------------------------------------------------------
// Purpose       : Returns the global coordinates of this RefVertex.
//
// Special Notes :
//
// Creator       : Malcolm J. Panthaki
//
// Creation Date : 09/25/96
//-------------------------------------------------------------------------
CubitVector RefVertex::coordinates() const
{
  const TBPoint* point_ptr = get_point_ptr();
  
  if (point_ptr != NULL)
  {
    return point_ptr->coordinates();
  }
  else
  {
    PRINT_ERROR("In RefVertex::coordinates\n"
                "       RefVertex %d has no GeometryEntity attached to it.\n"
                "       THIS IS A BUG - PLEASE REPORT IT.\n", id());
    assert( point_ptr != NULL );
    return CubitVector();
  }
}

//-------------------------------------------------------------------------
// Purpose       : Return the "center point" of the RefVertex -- its 
//                 coordinates.
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 10/30/96
//-------------------------------------------------------------------------
CubitVector RefVertex::center_point()
{
   return this->coordinates();
}
void RefVertex::common_ref_edges(RefVertex *other_vertex,
                                DLIList <RefEdge*> &common_ref_edges,
                                RefFace *owning_face) 
{
    //- returns an edge sharing the other vertex and owned by owning_face 
    //- (if non-NULL)
    //- The edge must have this vertex and other_vertex as its
    //- start and end vertices.
  DLIList<RefEntity*> temp_list;
  join(other_vertex, temp_list);

  int i;
  for (i = temp_list.size(); i > 0; i--)
  {
    RefEdge *common_edge = CAST_TO(temp_list.get(), RefEdge);
      //This extra 'if' block is needed in case other_vertex == this
    if (common_edge &&  
        ((common_edge->start_vertex() == other_vertex &&
           common_edge->end_vertex() == this) ||
         ( common_edge->start_vertex() == this &&
           common_edge->end_vertex() == other_vertex )))
    {
      if (common_edge && (!owning_face || common_edge->is_child(owning_face)))
        common_ref_edges.append(common_edge);
    }
    temp_list.step();
  }
  return;
}

RefEdge *RefVertex::common_ref_edge(RefVertex *other_vertex, 
                                    RefFace *owning_face) 
{
    //- returns an edge sharing the other vertex and owned by owning_face
    //- (if non-NULL)
    //- The edge must have this vertex and other_vertex as its
    //- start and end vertices.
  DLIList<RefEntity*> temp_list;
  join(other_vertex, temp_list);

  int i;
  for (i = temp_list.size(); i > 0; i--) {
    RefEdge *common_edge = CAST_TO(temp_list.get(), RefEdge);

    if( NULL == common_edge )<--- Assuming that condition 'NULL==common_edge' is not redundant
      continue;

      //This extra 'if' block is needed in case other_vertex == this
    if ( ( common_edge->start_vertex() == other_vertex &&
           common_edge->end_vertex() == this) ||
         ( common_edge->start_vertex() == this &&
           common_edge->end_vertex() == other_vertex ) )
    {
      if (common_edge && (!owning_face || common_edge->is_child(owning_face)))<--- Condition 'common_edge' is always true
        return common_edge;
      else
        temp_list.step();
    }
    else
      temp_list.step();
  }
  
  return NULL;
}

//-------------------------------------------------------------------------
// Purpose       : Spatially compare two RefVertexes, notification is made if
//                 the flag notify_ref_entity is set.
//
// Special Notes :
//
// Creator       : David White
//
// Creation Date : 04/08/97
//-------------------------------------------------------------------------
CubitBoolean RefVertex::about_spatially_equal(
                                RefVertex* ref_vertex_ptr_2,
                                double tolerance_factor,
                                CubitBoolean notify_ref_entity )
{
   if( this == ref_vertex_ptr_2 )
   {
      if (notify_ref_entity)
        remove_compare_data();
      return CUBIT_TRUE;
   }
 
   const CubitVector vertex_1_position = this->coordinates();
   const CubitVector vertex_2_position = ref_vertex_ptr_2->coordinates();
   if (!GeometryQueryTool::instance()-> about_spatially_equal(
     vertex_1_position, vertex_2_position, tolerance_factor))
     return CUBIT_FALSE;
     
   if ( notify_ref_entity == CUBIT_TRUE )
     this->comparison_found(ref_vertex_ptr_2);

   return CUBIT_TRUE;
}  

// ********** END PUBLIC FUNCTIONS         **********

// ********** BEGIN PROTECTED FUNCTIONS    **********
// ********** END PROTECTED FUNCTIONS      **********

// ********** BEGIN PRIVATE FUNCTIONS      **********

//-------------------------------------------------------------------------
// Purpose       : Initializes member data
//
// Special Notes :
//
// Creator       : Malcolm J. Panthaki
//
// Creation Date : 10/07/96
//-------------------------------------------------------------------------
void RefVertex::initialize()
{
   GeometryEntity* geom_ptr = get_geometry_entity_ptr();
   int saved_id = geom_ptr->get_saved_id();
   if ( !saved_id || RefEntityFactory::instance()->get_ref_vertex(saved_id) )
   {
     saved_id =  RefEntityFactory::instance()->next_ref_vertex_id();
     geom_ptr->set_saved_id(saved_id);
   }
   entityId = saved_id;

   // Initialize some attributes

     // read and initialize attributes
   auto_read_cubit_attrib();
   auto_actuate_cubit_attrib();
   
   // Assign a default entity name
   assign_default_name();

}

void RefVertex::get_parent_ref_entities(DLIList<RefEntity*>& entity_list)
{

  // First get the type of RefEntity that is a child of "this" one
  DagType parent_type = get_parent_ref_entity_type();;

  DLIList<TopologyEntity*> tempList ;

  CubitStatus result = ModelQueryEngine::instance()->
      query_model( *this, parent_type, tempList );
  if (result == CUBIT_FAILURE)
  {
    PRINT_ERROR("In RefEntity::get_parent_ref_entities\n");
    PRINT_ERROR("       Query failed for unknown reason.\n");
    return;
  }

  entity_list.clean_out();
  for(int i=0; i<tempList.size(); i++)
  {
    entity_list.append(static_cast<ParentType*>(tempList[i]));
  }
}