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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//-------------------------------------------------------------------------
// Filename      : CoEdge.cpp
//
// Purpose       : 
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 08/02/96
//
// Owner         : Jihong Ma
//-------------------------------------------------------------------------

// ********** BEGIN STANDARD INCLUDES      **********
// ********** END STANDARD INCLUDES        **********

// ********** BEGIN CUBIT INCLUDES         **********
#include "CoEdge.hpp"
#include "RefEdge.hpp"
#include "RefFace.hpp"
#include "Loop.hpp"
#include "DLIList.hpp"
#include "GeometryDefines.h"
#include "GeometryQueryTool.hpp"
#include "CastTo.hpp"
#include "CoEdgeSM.hpp"
#include "Curve.hpp"

// ********** END CUBIT INCLUDES           **********

// ********** BEGIN STATIC DECLARATIONS    **********
// ********** END STATIC DECLARATIONS      **********

// ********** BEGIN PUBLIC FUNCTIONS       **********
//-------------------------------------------------------------------------
// Purpose       : The default constructor.
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 08/02/96
//-------------------------------------------------------------------------
CoEdge::CoEdge() 
{
}

//-------------------------------------------------------------------------
// Purpose       : The destructor.
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 10/22/96
//-------------------------------------------------------------------------
CoEdge::~CoEdge() 
{
  remove_from_observers();
}

//-------------------------------------------------------------------------
// Purpose       : The constructor with a pointer to a edge and the
//                 sense of this CoEdge. 
//
// Special Notes :
//
// Creator       : Xuechen Liu
//
// Creation Date : 08/02/96
//-------------------------------------------------------------------------
CoEdge::CoEdge(RefEdge* edgePtr, CubitSense sense) 
{
   attach_basic_topology_entity(edgePtr) ;
   set_sense(sense) ;
}

//-------------------------------------------------------------------------
// Purpose       : 
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 07/22/03
//-------------------------------------------------------------------------
CoEdge::CoEdge( CoEdgeSM* osme_ptr )
{
  set_co_edge_sm_ptr(osme_ptr);
}

//-------------------------------------------------------------------------
// Purpose       : Get the RefEdge associated with this CoEdge.
//
// Special Notes :
//
// Creator       : Malcolm J. Panthaki
//
// Creation Date : 08/02/96
//-------------------------------------------------------------------------
RefEdge* CoEdge::get_ref_edge_ptr()  
{
   // Call the generic function defined in the SenseEntity class to
   // do the real work
   BasicTopologyEntity* BTEPtr = get_basic_topology_entity_ptr();

   // Cast the returned pointer to RefEdge and return it
   return STATIC_CAST_TO( BTEPtr, RefEdge );
}

//-------------------------------------------------------------------------
// Purpose       : Get the parent Loop
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 09/23/99
//-------------------------------------------------------------------------
Loop* CoEdge::get_loop_ptr()
{
  return STATIC_CAST_TO( get_grouping_entity_ptr(), Loop );
}


//-------------------------------------------------------------------------
// Purpose       : Get the ref_face associated with this CoEdge.
//
// Special Notes : Will assert if more than one ref_face but will
//                 return NULL if no RefFaces are associated with it.
//
// Creator       : David White
//
// Creation Date : 3/14/97
//-------------------------------------------------------------------------
RefFace* CoEdge::get_ref_face()
{
  return static_cast<RefFace*>(get_parent_basic_topology_entity_ptr());
}
  


//-------------------------------------------------------------------------
// Purpose       : This function is called after a child of a TopologyEntity
//                 is switched. The sense of a CoEdge may change if one 
//                 of its RefEdges changes. This function takes care of 
//                 that. If the sense of the RefEdges that were switched 
//                 is same, nothing is done. If the RefEdges are of 
//                 opposite sense, the sense of this object is switched, 
//                 i.e. if it was FORWARD, it is made REVERSE, and vice
//                 versa. 
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 02/26/97
//-------------------------------------------------------------------------

void CoEdge::switch_child_notify(TopologyEntity const* newChild,<--- The function 'switch_child_notify' is never used.
                                 TopologyEntity const* oldChild)
{
    // Make sure the entities being switched are RefEdges. If not,
    // get out of this function.

  TopologyEntity* tmp_new_child = const_cast<TopologyEntity*>(newChild);
  TopologyEntity* tmp_old_child = const_cast<TopologyEntity*>(oldChild);
  RefEdge * newChildRefEdge = CAST_TO(tmp_new_child, RefEdge) ;
  RefEdge * oldChildRefEdge = CAST_TO(tmp_old_child, RefEdge) ;
  
  if ( ( newChildRefEdge == NULL ) || ( oldChildRefEdge == NULL ) )
  {
    return ;
  }

    // If the children are RefEdges, get the sense of the old RefEdge 
    // relative to the new one.

  CubitSense sense;
  CubitBoolean spatially_equal;
    //We really don't care at this point if the two are spatially equal.  
    // The user could have done a force merge and in which case they are not.
    // So just ignore that spatial comparison.

//When this function is called, the merge has already taken place, so force
//  merge actually makes more sense to use here...
  CubitBoolean force_merge = CUBIT_TRUE;

  /*CubitStatus stat = */
  newChildRefEdge->relative_sense( 
     oldChildRefEdge, GeometryQueryTool::get_geometry_factor(), &sense,
     spatially_equal, force_merge );
  
    // If the sense of the old RefEdge relative to the new RefEdge is 
    // same, nothing needs to be done. However, if the relative sense
    // is reversed, switch the sense of the CoEdge.
  if ( sense == CUBIT_REVERSED ) 
  {
    if ( get_sense() == CUBIT_FORWARD )
    {
      set_sense(CUBIT_REVERSED) ;
    }
    else
    {
      set_sense(CUBIT_FORWARD) ;
    }
  }
}

//-------------------------------------------------------------------------
// Purpose       : Get CoEdgeSM pointer
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 07/23/03
//-------------------------------------------------------------------------
CoEdgeSM* CoEdge::get_co_edge_sm_ptr() const
{
  return static_cast<CoEdgeSM*>(bridge_manager()->topology_bridge());
}


CubitStatus CoEdge::set_co_edge_sm_ptr( CoEdgeSM* ptr )
{
  if (!bridge_manager()->topology_bridge())
    return bridge_manager()->add_bridge(ptr);
  else if(bridge_manager()->topology_bridge() != ptr)
    return CUBIT_FAILURE;
  else
    return CUBIT_SUCCESS;
}

//-------------------------------------------------------------------------
// Purpose       : Check if child RefEdges are equal and have correct
//                 relative sense.
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 04/01/04
//-------------------------------------------------------------------------
CubitBoolean CoEdge::about_spatially_equal( CoEdge* other_coedge,
                                            CubitSense relative_sense,
                                            double tolerance_factor,
                                            CubitBoolean notify_refEntity )
{
  RefEdge* this_ref_edge = get_ref_edge_ptr();
  RefEdge* other_ref_edge = other_coedge->get_ref_edge_ptr();
  CubitSense edge_sense;
  
  if (!this_ref_edge->about_spatially_equal( other_ref_edge,
                                             tolerance_factor,
                                             &edge_sense,
                                             notify_refEntity ))
    return CUBIT_FALSE;
  
  if (this_ref_edge->get_curve_ptr()->geometry_type() == POINT_CURVE_TYPE ||
      other_ref_edge->get_curve_ptr()->geometry_type() == POINT_CURVE_TYPE)
    return CUBIT_TRUE;
  
  if (edge_sense == CUBIT_UNKNOWN)
  {
    PRINT_WARNING("Failed to determine relative sense of curves.\n");
    return CUBIT_TRUE;
  }
  
  bool coedges_reversed = get_sense() != other_coedge->get_sense();
  bool want_reversed = edge_sense != relative_sense;
  if (coedges_reversed == want_reversed)
    return CUBIT_TRUE;
  
 // if (notify_refEntity)
 // {
 //   this_ref_edge->remove_compare_data();
 //   other_ref_edge->remove_compare_data();
 // }
  return CUBIT_FALSE;
}

//-------------------------------------------------------------------------
// Purpose       : Get start/end vertex
//
// Special Notes : 
//
// Creator       : Jason Kraftcheck
//
// Creation Date : 05/11/04
//-------------------------------------------------------------------------
RefVertex* CoEdge::start_vertex() 
{
  return get_sense() == CUBIT_FORWARD ? 
         get_ref_edge_ptr()->start_vertex() :
         get_ref_edge_ptr()->end_vertex();
}
RefVertex* CoEdge::end_vertex() 
{
  return get_sense() == CUBIT_REVERSED ? 
         get_ref_edge_ptr()->start_vertex() :
         get_ref_edge_ptr()->end_vertex();
}

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

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

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

// ********** BEGIN HELPER CLASSES         **********
// ********** END HELPER CLASSES           **********

// ********** BEGIN EXTERN FUNCTIONS       **********
// ********** END EXTERN FUNCTIONS         **********

// ********** BEGIN STATIC FUNCTIONS       **********
// ********** END STATIC FUNCTIONS         **********