cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : CompositePoint.cpp 00003 // 00004 // Purpose : Point decorator for composite topology 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Jason Kraftcheck 00009 // 00010 // Creation Date : 03/11/02 00011 //------------------------------------------------------------------------- 00012 00013 #include "CompositePoint.hpp" 00014 #include "CompositeEngine.hpp" 00015 #include "VirtualQueryEngine.hpp" 00016 00017 CompositePoint::CompositePoint( TBPoint* real_pt ) 00018 : HadBridgeRemoved(0), firstCurve(0), realPoint(real_pt), stitchNext(0) 00019 { 00020 if( real_pt->owner() ) 00021 real_pt->owner()->swap_bridge( real_pt, this, false ); 00022 real_pt->owner(this); 00023 } 00024 00025 CompositePoint::~CompositePoint() 00026 { 00027 // remove from all curves 00028 while( firstCurve ) 00029 { 00030 CompositeCurve* curve = firstCurve; 00031 if( curve->start_point() == this ) 00032 curve->start_point(0); 00033 if( curve->end_point() == this ) 00034 curve->end_point(0); 00035 assert(firstCurve != curve); 00036 } 00037 00038 if( stitchNext ) 00039 { 00040 // unmerge 00041 unstitch_all(); 00042 } 00043 00044 if (realPoint) 00045 { 00046 // update owner 00047 assert(realPoint->owner() == this); 00048 realPoint->owner(0); 00049 if( owner() ) 00050 owner()->swap_bridge( this, realPoint, false ); 00051 00052 realPoint = 0; 00053 } 00054 } 00055 00056 void CompositePoint::unstitch_all() 00057 { 00058 assert( !firstCurve ); 00059 while (stitchNext) 00060 { 00061 stitchNext->owner(0); 00062 if (owner()) 00063 owner()->notify_copied( stitchNext, this ); 00064 stitchNext = stitchNext->stitchNext; 00065 } 00066 } 00067 00068 00069 void CompositePoint::get_parents_virt( DLIList<TopologyBridge*>& list ) 00070 { 00071 DLIList<TopologyBridge*> point_parents; 00072 realPoint->get_parents_virt( point_parents ); 00073 for( int i = point_parents.size(); i--; ) 00074 { 00075 TopologyBridge* tb = point_parents.get_and_step(); 00076 if( CompositeCurve* curve = dynamic_cast<CompositeCurve*>(tb->owner()) ) 00077 { 00078 if( ! dynamic_cast<HiddenEntitySet*>(curve->owner()) ) 00079 list.append_unique( curve ); 00080 } 00081 else if( ! dynamic_cast<HiddenEntitySet*>(tb->owner()) ) 00082 list.append( tb ); 00083 } 00084 00085 // get point-curves also 00086 CompositeCurve* curve = 0; 00087 while ((curve = next_curve(curve))) 00088 if (curve->num_curves() == 0) 00089 list.append(curve); 00090 00091 if (stitchNext) 00092 { 00093 point_parents.clean_out(); 00094 stitchNext->get_parents_virt( point_parents ); 00095 point_parents.reset(); 00096 for (int j = point_parents.size(); j--; ) 00097 { 00098 TopologyBridge* bridge = point_parents.get_and_step(); 00099 CompositeCurve* curv = dynamic_cast<CompositeCurve*>(bridge); 00100 if (curv) 00101 list.append_unique( curv->primary_stitched_curve() ); 00102 else 00103 list.append_unique( bridge ); 00104 } 00105 } 00106 } 00107 00108 void CompositePoint::get_children_virt( DLIList<TopologyBridge*>& ) 00109 { 00110 } 00111 00112 00113 CubitStatus CompositePoint::remove_bridge( TopologyBridge* bridge ) 00114 { 00115 if( bridge->owner() != this ) 00116 { 00117 assert(0); 00118 return CUBIT_FAILURE; 00119 } 00120 00121 if( bridge == realPoint ) 00122 { 00123 realPoint = 0; 00124 } 00125 else 00126 { 00127 return CUBIT_FAILURE; 00128 } 00129 00130 bridge->owner(0); 00131 00132 if (!realPoint) 00133 CompositeEngine::instance().notify_deactivated(this); 00134 00135 HadBridgeRemoved = 1; 00136 00137 return CUBIT_SUCCESS; 00138 } 00139 00140 CubitStatus CompositePoint::swap_bridge( TopologyBridge* oldtb, 00141 TopologyBridge* newtb, 00142 bool ) 00143 { 00144 TBPoint* oldpt = dynamic_cast<TBPoint*>(oldtb); 00145 TBPoint* newpt = dynamic_cast<TBPoint*>(newtb); 00146 if( !(oldpt && newpt) || newpt->owner() ) 00147 return CUBIT_FAILURE; 00148 00149 assert(oldpt == realPoint ); 00150 00151 realPoint = newpt; 00152 00153 newtb->owner(this); 00154 oldtb->owner(0); 00155 return CUBIT_SUCCESS; 00156 } 00157 00158 00159 void CompositePoint::print_debug_info( const char* prefix, bool brief ) const 00160 { 00161 if( prefix == 0 ) prefix = ""; 00162 00163 #ifdef TOPOLOGY_BRIDGE_IDS 00164 PRINT_INFO("%sCompositePoint %d : %s %d\n", prefix, get_id(), 00165 realPoint ? fix_type_name(typeid(*realPoint).name()) : "NO REAL POINT", 00166 realPoint ? realPoint->get_id() : 0 ); 00167 #else 00168 PRINT_INFO("%sCompositePoint %p : %s %p\n", prefix, (void*)this, 00169 realPoint ? fix_type_name(typeid(*realPoint).name()) : "NO REAL POINT", 00170 (void*)realPoint); 00171 #endif 00172 00173 if ( !brief ) 00174 { 00175 CubitVector p = coordinates(); 00176 PRINT_INFO("%s (%f,%f,%f)\n", prefix, p.x(), p.y(), p.z() ); 00177 } 00178 } 00179 00180 void CompositePoint::notify_reversed( TopologyBridge* ) 00181 { } 00182 00183 CubitStatus CompositePoint::stitch( CompositePoint* point ) 00184 { 00185 if( !point || point->owner() != this->owner() ) 00186 { 00187 assert(0); 00188 return CUBIT_FAILURE; 00189 } 00190 00191 if( point->owner() ) 00192 point->owner()->notify_merged( point, this ); 00193 00194 if( point->owner() ) 00195 point->owner()->remove_bridge( point ); 00196 00197 point->owner( this ); 00198 CompositePoint* end = point; 00199 while (end->stitchNext) 00200 { 00201 end->stitchNext->owner( this ); 00202 end = end->stitchNext; 00203 } 00204 00205 end->stitchNext = stitchNext; 00206 stitchNext = end; 00207 00208 return CUBIT_SUCCESS; 00209 } 00210 00211 void CompositePoint::get_stitched( DLIList<CompositePoint*>& result ) 00212 { 00213 CompositePoint* pt = dynamic_cast<CompositePoint*>(owner()); 00214 if (!pt) 00215 pt = this; 00216 while (pt) 00217 { 00218 result.append(pt); 00219 pt = pt->stitchNext; 00220 } 00221 } 00222 00223 GeometryQueryEngine* CompositePoint::get_geometry_query_engine() const 00224 { return VirtualQueryEngine::instance(); }