cgma
CoEdge.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : CoEdge.cpp
00003 //
00004 // Purpose       : 
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : Xuechen Liu
00009 //
00010 // Creation Date : 08/02/96
00011 //
00012 // Owner         : Jihong Ma
00013 //-------------------------------------------------------------------------
00014 
00015 // ********** BEGIN STANDARD INCLUDES      **********
00016 // ********** END STANDARD INCLUDES        **********
00017 
00018 // ********** BEGIN CUBIT INCLUDES         **********
00019 #include "CoEdge.hpp"
00020 #include "RefEdge.hpp"
00021 #include "RefFace.hpp"
00022 #include "Loop.hpp"
00023 #include "DLIList.hpp"
00024 #include "GeometryDefines.h"
00025 #include "GeometryQueryTool.hpp"
00026 #include "CastTo.hpp"
00027 #include "CoEdgeSM.hpp"
00028 #include "Curve.hpp"
00029 
00030 // ********** END CUBIT INCLUDES           **********
00031 
00032 // ********** BEGIN STATIC DECLARATIONS    **********
00033 // ********** END STATIC DECLARATIONS      **********
00034 
00035 // ********** BEGIN PUBLIC FUNCTIONS       **********
00036 //-------------------------------------------------------------------------
00037 // Purpose       : The default constructor.
00038 //
00039 // Special Notes :
00040 //
00041 // Creator       : Xuechen Liu
00042 //
00043 // Creation Date : 08/02/96
00044 //-------------------------------------------------------------------------
00045 CoEdge::CoEdge() 
00046 {
00047 }
00048 
00049 //-------------------------------------------------------------------------
00050 // Purpose       : The destructor.
00051 //
00052 // Special Notes :
00053 //
00054 // Creator       : Raikanta Sahu
00055 //
00056 // Creation Date : 10/22/96
00057 //-------------------------------------------------------------------------
00058 CoEdge::~CoEdge() 
00059 {
00060   remove_from_observers();
00061 }
00062 
00063 //-------------------------------------------------------------------------
00064 // Purpose       : The constructor with a pointer to a edge and the
00065 //                 sense of this CoEdge. 
00066 //
00067 // Special Notes :
00068 //
00069 // Creator       : Xuechen Liu
00070 //
00071 // Creation Date : 08/02/96
00072 //-------------------------------------------------------------------------
00073 CoEdge::CoEdge(RefEdge* edgePtr, CubitSense sense) 
00074 {
00075    attach_basic_topology_entity(edgePtr) ;
00076    set_sense(sense) ;
00077 }
00078 
00079 //-------------------------------------------------------------------------
00080 // Purpose       : 
00081 //
00082 // Special Notes : 
00083 //
00084 // Creator       : Jason Kraftcheck
00085 //
00086 // Creation Date : 07/22/03
00087 //-------------------------------------------------------------------------
00088 CoEdge::CoEdge( CoEdgeSM* osme_ptr )
00089 {
00090   set_co_edge_sm_ptr(osme_ptr);
00091 }
00092 
00093 //-------------------------------------------------------------------------
00094 // Purpose       : Get the RefEdge associated with this CoEdge.
00095 //
00096 // Special Notes :
00097 //
00098 // Creator       : Malcolm J. Panthaki
00099 //
00100 // Creation Date : 08/02/96
00101 //-------------------------------------------------------------------------
00102 RefEdge* CoEdge::get_ref_edge_ptr()  
00103 {
00104    // Call the generic function defined in the SenseEntity class to
00105    // do the real work
00106    BasicTopologyEntity* BTEPtr = get_basic_topology_entity_ptr();
00107 
00108    // Cast the returned pointer to RefEdge and return it
00109    return STATIC_CAST_TO( BTEPtr, RefEdge );
00110 }
00111 
00112 //-------------------------------------------------------------------------
00113 // Purpose       : Get the parent Loop
00114 //
00115 // Special Notes : 
00116 //
00117 // Creator       : Jason Kraftcheck
00118 //
00119 // Creation Date : 09/23/99
00120 //-------------------------------------------------------------------------
00121 Loop* CoEdge::get_loop_ptr()
00122 {
00123   return STATIC_CAST_TO( get_grouping_entity_ptr(), Loop );
00124 }
00125 
00126 
00127 //-------------------------------------------------------------------------
00128 // Purpose       : Get the ref_face associated with this CoEdge.
00129 //
00130 // Special Notes : Will assert if more than one ref_face but will
00131 //                 return NULL if no RefFaces are associated with it.
00132 //
00133 // Creator       : David White
00134 //
00135 // Creation Date : 3/14/97
00136 //-------------------------------------------------------------------------
00137 RefFace* CoEdge::get_ref_face()
00138 {
00139   return static_cast<RefFace*>(get_parent_basic_topology_entity_ptr());
00140 }
00141   
00142 
00143 
00144 //-------------------------------------------------------------------------
00145 // Purpose       : This function is called after a child of a TopologyEntity
00146 //                 is switched. The sense of a CoEdge may change if one 
00147 //                 of its RefEdges changes. This function takes care of 
00148 //                 that. If the sense of the RefEdges that were switched 
00149 //                 is same, nothing is done. If the RefEdges are of 
00150 //                 opposite sense, the sense of this object is switched, 
00151 //                 i.e. if it was FORWARD, it is made REVERSE, and vice
00152 //                 versa. 
00153 //
00154 // Special Notes :
00155 //
00156 // Creator       : Raikanta Sahu
00157 //
00158 // Creation Date : 02/26/97
00159 //-------------------------------------------------------------------------
00160 
00161 void CoEdge::switch_child_notify(TopologyEntity const* newChild,
00162                                  TopologyEntity const* oldChild)
00163 {
00164     // Make sure the entities being switched are RefEdges. If not,
00165     // get out of this function.
00166 
00167   TopologyEntity* tmp_new_child = const_cast<TopologyEntity*>(newChild);
00168   TopologyEntity* tmp_old_child = const_cast<TopologyEntity*>(oldChild);
00169   RefEdge * newChildRefEdge = CAST_TO(tmp_new_child, RefEdge) ;
00170   RefEdge * oldChildRefEdge = CAST_TO(tmp_old_child, RefEdge) ;
00171   
00172   if ( ( newChildRefEdge == NULL ) || ( oldChildRefEdge == NULL ) )
00173   {
00174     return ;
00175   }
00176 
00177     // If the children are RefEdges, get the sense of the old RefEdge 
00178     // relative to the new one.
00179 
00180   CubitSense sense;
00181   CubitBoolean spatially_equal;
00182     //We really don't care at this point if the two are spatially equal.  
00183     // The user could have done a force merge and in which case they are not.
00184     // So just ignore that spatial comparison.
00185 
00186 //When this function is called, the merge has already taken place, so force
00187 //  merge actually makes more sense to use here...
00188   CubitBoolean force_merge = CUBIT_TRUE;
00189 
00190   /*CubitStatus stat = */
00191   newChildRefEdge->relative_sense( 
00192      oldChildRefEdge, GeometryQueryTool::get_geometry_factor(), &sense,
00193      spatially_equal, force_merge );
00194   
00195     // If the sense of the old RefEdge relative to the new RefEdge is 
00196     // same, nothing needs to be done. However, if the relative sense
00197     // is reversed, switch the sense of the CoEdge.
00198   if ( sense == CUBIT_REVERSED ) 
00199   {
00200     if ( get_sense() == CUBIT_FORWARD )
00201     {
00202       set_sense(CUBIT_REVERSED) ;
00203     }
00204     else
00205     {
00206       set_sense(CUBIT_FORWARD) ;
00207     }
00208   }
00209 }
00210 
00211 //-------------------------------------------------------------------------
00212 // Purpose       : Get CoEdgeSM pointer
00213 //
00214 // Special Notes : 
00215 //
00216 // Creator       : Jason Kraftcheck
00217 //
00218 // Creation Date : 07/23/03
00219 //-------------------------------------------------------------------------
00220 CoEdgeSM* CoEdge::get_co_edge_sm_ptr() const
00221 {
00222   return static_cast<CoEdgeSM*>(bridge_manager()->topology_bridge());
00223 }
00224 
00225 
00226 CubitStatus CoEdge::set_co_edge_sm_ptr( CoEdgeSM* ptr )
00227 {
00228   if (!bridge_manager()->topology_bridge())
00229     return bridge_manager()->add_bridge(ptr);
00230   else if(bridge_manager()->topology_bridge() != ptr)
00231     return CUBIT_FAILURE;
00232   else
00233     return CUBIT_SUCCESS;
00234 }
00235 
00236 //-------------------------------------------------------------------------
00237 // Purpose       : Check if child RefEdges are equal and have correct
00238 //                 relative sense.
00239 //
00240 // Special Notes : 
00241 //
00242 // Creator       : Jason Kraftcheck
00243 //
00244 // Creation Date : 04/01/04
00245 //-------------------------------------------------------------------------
00246 CubitBoolean CoEdge::about_spatially_equal( CoEdge* other_coedge,
00247                                             CubitSense relative_sense,
00248                                             double tolerance_factor,
00249                                             CubitBoolean notify_refEntity )
00250 {
00251   RefEdge* this_ref_edge = get_ref_edge_ptr();
00252   RefEdge* other_ref_edge = other_coedge->get_ref_edge_ptr();
00253   CubitSense edge_sense;
00254   
00255   if (!this_ref_edge->about_spatially_equal( other_ref_edge,
00256                                              tolerance_factor,
00257                                              &edge_sense,
00258                                              notify_refEntity ))
00259     return CUBIT_FALSE;
00260   
00261   if (this_ref_edge->get_curve_ptr()->geometry_type() == POINT_CURVE_TYPE ||
00262       other_ref_edge->get_curve_ptr()->geometry_type() == POINT_CURVE_TYPE)
00263     return CUBIT_TRUE;
00264   
00265   if (edge_sense == CUBIT_UNKNOWN)
00266   {
00267     PRINT_WARNING("Failed to determine relative sense of curves.\n");
00268     return CUBIT_TRUE;
00269   }
00270   
00271   bool coedges_reversed = get_sense() != other_coedge->get_sense();
00272   bool want_reversed = edge_sense != relative_sense;
00273   if (coedges_reversed == want_reversed)
00274     return CUBIT_TRUE;
00275   
00276  // if (notify_refEntity)
00277  // {
00278  //   this_ref_edge->remove_compare_data();
00279  //   other_ref_edge->remove_compare_data();
00280  // }
00281   return CUBIT_FALSE;
00282 }
00283 
00284 //-------------------------------------------------------------------------
00285 // Purpose       : Get start/end vertex
00286 //
00287 // Special Notes : 
00288 //
00289 // Creator       : Jason Kraftcheck
00290 //
00291 // Creation Date : 05/11/04
00292 //-------------------------------------------------------------------------
00293 RefVertex* CoEdge::start_vertex() 
00294 {
00295   return get_sense() == CUBIT_FORWARD ? 
00296          get_ref_edge_ptr()->start_vertex() :
00297          get_ref_edge_ptr()->end_vertex();
00298 }
00299 RefVertex* CoEdge::end_vertex() 
00300 {
00301   return get_sense() == CUBIT_REVERSED ? 
00302          get_ref_edge_ptr()->start_vertex() :
00303          get_ref_edge_ptr()->end_vertex();
00304 }
00305 
00306 // ********** END PUBLIC FUNCTIONS         **********
00307 
00308 // ********** BEGIN PROTECTED FUNCTIONS    **********
00309 // ********** END PROTECTED FUNCTIONS      **********
00310 
00311 // ********** BEGIN PRIVATE FUNCTIONS      **********
00312 // ********** END PRIVATE FUNCTIONS        **********
00313 
00314 // ********** BEGIN HELPER CLASSES         **********
00315 // ********** END HELPER CLASSES           **********
00316 
00317 // ********** BEGIN EXTERN FUNCTIONS       **********
00318 // ********** END EXTERN FUNCTIONS         **********
00319 
00320 // ********** BEGIN STATIC FUNCTIONS       **********
00321 // ********** END STATIC FUNCTIONS         **********
00322 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines