cgma
OCCPoint.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Filename      : OCCPoint.cpp
00003 //
00004 // Purpose       : 
00005 //
00006 // Special Notes :
00007 //
00008 // Creator       : Steven J. Owen
00009 //
00010 // Creation Date : 07/15/00
00011 //
00012 // Owner         : Steven J. Owen
00013 //-------------------------------------------------------------------------
00014 
00015 // ********** BEGIN STANDARD INCLUDES      **********
00016 #include <assert.h>
00017 // ********** END STANDARD INCLUDES        **********
00018 
00019 // ********** BEGIN CUBIT INCLUDES         **********
00020 #include "OCCPoint.hpp"
00021 #include "OCCCurve.hpp"
00022 #include "OCCQueryEngine.hpp"
00023 #include "CastTo.hpp"
00024 #include "OCCAttribSet.hpp"
00025 #include "BRep_Tool.hxx"
00026 #include "TopExp.hxx"
00027 #include "TopoDS_Edge.hxx"
00028 #include "TopoDS.hxx"
00029 #include "TopTools_ListIteratorOfListOfShape.hxx"
00030 #include "TopTools_DataMapOfShapeInteger.hxx"
00031 #include "TopTools_IndexedDataMapOfShapeListOfShape.hxx"
00032 #include "BRepBuilderAPI_ModifyShape.hxx"
00033 #include "BRepBuilderAPI_Transform.hxx"
00034 #include "BRepBuilderAPI_GTransform.hxx"
00035 #include "BRepAlgoAPI_BooleanOperation.hxx"
00036 // ********** END CUBIT INCLUDES           **********
00037 
00038 // ********** BEGIN STATIC DECLARATIONS    **********
00039 // ********** END STATIC DECLARATIONS      **********
00040 
00041 // ********** BEGIN PUBLIC FUNCTIONS       **********
00042 
00043 //-------------------------------------------------------------------------
00044 // Purpose       : The constructor with a pointer to the location
00045 //
00046 // Special Notes :
00047 //
00048 // Creator       : Jane Hu
00049 //
00050 // Creation Date : 10/08/07
00051 //-------------------------------------------------------------------------
00052 OCCPoint::OCCPoint( const CubitVector &location )
00053 {
00054   gp_Pnt pt = gp_Pnt( location.x(), location.y(), location.z());
00055   TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(pt);
00056   myTopoDSVertex = new TopoDS_Vertex(theVertex);
00057 }
00058 
00059  //-------------------------------------------------------------------------
00060 // Purpose       : The constructor with a gp_Pnt point
00061 //
00062 // Special Notes :
00063 //
00064 // Creator       : Jane Hu
00065 //
00066 // Creation Date : 10/19/07
00067 //-------------------------------------------------------------------------
00068 OCCPoint::OCCPoint( gp_Pnt& thePoint )
00069 {
00070   TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(thePoint);
00071   myTopoDSVertex = new TopoDS_Vertex(theVertex);
00072 }
00073 
00074 //-------------------------------------------------------------------------
00075 // Purpose       : The destructor. 
00076 //
00077 // Special Notes :
00078 //
00079 // Creator       : Jane Hu
00080 //
00081 // Creation Date : 10/08/07
00082 //-------------------------------------------------------------------------
00083 OCCPoint::~OCCPoint() 
00084 {
00085   if (myTopoDSVertex)
00086   {
00087     delete (TopoDS_Vertex*)myTopoDSVertex;
00088     myTopoDSVertex = NULL;
00089   }
00090 }
00091 
00092 void OCCPoint::add_curve(OCCCurve* curve)
00093 {
00094   assert(curve != NULL);
00095   myCurveList.append_unique(curve);
00096 }
00097 
00098 void OCCPoint::remove_curve(OCCCurve* curve)
00099 {
00100   assert(curve != NULL);
00101   myCurveList.remove(curve);
00102 }
00103 
00104 void OCCPoint::set_TopoDS_Vertex(TopoDS_Vertex vertex)
00105 {
00106   if(myTopoDSVertex && vertex.IsEqual(*myTopoDSVertex))
00107     return;
00108   if(myTopoDSVertex)
00109     myTopoDSVertex->Nullify();
00110   *myTopoDSVertex = vertex;
00111 }
00112 //-------------------------------------------------------------------------
00113 // Purpose       : The purpose of this function is to append a
00114 //                 attribute to the GE. The name is attached to the 
00115 //                 underlying solid model entity this one points to.
00116 //
00117 //
00118 // Special Notes : 
00119 //
00120 // Creator       : Steve Owen
00121 //
00122 // Creation Date : 07/16/00
00123 //-------------------------------------------------------------------------
00124 void OCCPoint::append_simple_attribute_virt(const CubitSimpleAttrib &csa)
00125   { OCCAttribSet::append_attribute(csa, *myTopoDSVertex); }
00126 
00127 //-------------------------------------------------------------------------
00128 // Purpose       : The purpose of this function is to remove a simple 
00129 //                 attribute attached to this geometry entity. The name is 
00130 //                 removed from the underlying BODY this points to.
00131 //
00132 // Special Notes : 
00133 //
00134 // Creator       : Steve Owen
00135 //
00136 // Creation Date : 07/16/00
00137 //-------------------------------------------------------------------------
00138 void OCCPoint::remove_simple_attribute_virt(const CubitSimpleAttrib &csa)
00139   { OCCAttribSet::remove_attribute(csa, *myTopoDSVertex); }
00140 
00141 //-------------------------------------------------------------------------
00142 // Purpose       : The purpose of this function is to remove all simple 
00143 //                 attributes attached to this geometry entity.  Also
00144 //                 removes lingering GTC attributes.
00145 //
00146 //
00147 // Special Notes : 
00148 //
00149 // Creator       : Steve Owen
00150 //
00151 // Creation Date : 07/16/00
00152 //-------------------------------------------------------------------------
00153 void OCCPoint::remove_all_simple_attribute_virt()
00154 {
00155   OCCAttribSet::remove_attribute(CubitSimpleAttrib(), *myTopoDSVertex);
00156 }
00157 
00158 //-------------------------------------------------------------------------
00159 // Purpose       : The purpose of this function is to get the  
00160 //                 attributes attached to this geometry entity. The name is 
00161 //                 attached to the underlying BODY this points to.
00162 //
00163 // Special Notes : 
00164 //
00165 // Creator       : Steve Owen
00166 //
00167 // Creation Date : 07/16/00
00168 //-------------------------------------------------------------------------
00169 CubitStatus OCCPoint::get_simple_attribute(DLIList<CubitSimpleAttrib>&
00170                                                csa_list)
00171   { return OCCAttribSet::get_attributes(*myTopoDSVertex,csa_list);
00172   }
00173 
00174 CubitStatus OCCPoint::get_simple_attribute(const CubitString& name,
00175                                      DLIList<CubitSimpleAttrib>& csa_list )
00176   { return OCCAttribSet::get_attributes( name, *myTopoDSVertex, csa_list );
00177   }
00178 
00179 //-------------------------------------------------------------------------
00180 // Purpose       : Returns the coordinates of this Point. 
00181 //
00182 // Special Notes :
00183 //
00184 // Creator       : Jane Hu
00185 //
00186 // Creation Date : 10/08/07
00187 //-------------------------------------------------------------------------
00188 CubitVector OCCPoint::coordinates() const
00189 {
00190   gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
00191   CubitVector p(pt.X(), pt.Y(), pt.Z());
00192   return p;
00193 }
00194 
00195 CubitBoolean OCCPoint::is_equal(OCCPoint & other, double Tol)
00196 {
00197   gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
00198   TopoDS_Vertex otherVertex = *(other.get_TopoDS_Vertex());
00199   const gp_Pnt otherPnt = BRep_Tool::Pnt(otherVertex);
00200   return pt.IsEqual(otherPnt, Tol);
00201 }   
00202   
00203 double OCCPoint::distance(OCCPoint & other)
00204 {
00205   gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
00206   return pt.Distance(BRep_Tool::Pnt(*(other.get_TopoDS_Vertex())));
00207 }
00208 
00209 double OCCPoint::SquareDistance (OCCPoint & other)
00210 {
00211   gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
00212   return pt.SquareDistance(BRep_Tool::Pnt(*(other.get_TopoDS_Vertex())));
00213 }
00214 //-------------------------------------------------------------------------
00215 // Purpose       : Get geometry modeling engine: OCCGeometryEngine
00216 //
00217 // Special Notes :
00218 //
00219 // Creator       : Steve Owen
00220 //
00221 // Creation Date : 07/16/00
00222 //-------------------------------------------------------------------------
00223 GeometryQueryEngine* OCCPoint::get_geometry_query_engine() const
00224 {
00225   return OCCQueryEngine::instance();
00226 }                 
00227 
00228 //-------------------------------------------------------------------------
00229 // Purpose       : Get the bounding box of the object.
00230 //
00231 // Special Notes :
00232 //
00233 // Creator       : Steve Owen
00234 //
00235 // Creation Date : 07/16/00
00236 //-------------------------------------------------------------------------
00237 CubitBox OCCPoint::bounding_box() const 
00238 {
00239   CubitVector temp_vector = this->coordinates();
00240   CubitBox temp_box(temp_vector);
00241   return temp_box;
00242 }
00243 
00244 
00245 void OCCPoint::get_parents_virt( DLIList<TopologyBridge*>& parents ) 
00246 {
00247   CAST_LIST_TO_PARENT(myCurveList, parents);
00248 }
00249 void OCCPoint::get_children_virt( DLIList<TopologyBridge*>& ) 
00250   {  }
00251 
00252 //----------------------------------------------------------------
00253 // Function: to update the core vertex
00254 //           for any movement of the body/surface/curve/vertex.
00255 // Author: Jane Hu
00256 //----------------------------------------------------------------
00257 void OCCPoint::update_OCC_entity( BRepBuilderAPI_ModifyShape *aBRepTrsf,
00258                                   BRepAlgoAPI_BooleanOperation *op)
00259 {
00260   if (this->myMarked == CUBIT_TRUE)
00261     return;
00262 
00263   assert(aBRepTrsf != NULL || op != NULL);
00264 
00265   TopoDS_Shape shape;
00266   if(aBRepTrsf)
00267     shape = aBRepTrsf->ModifiedShape(*get_TopoDS_Vertex());
00268  
00269   else
00270   {
00271     TopTools_ListOfShape shapes;
00272     shapes.Assign(op->Modified(*get_TopoDS_Vertex()));
00273     if(shapes.Extent() == 0)
00274       shapes.Assign(op->Generated(*get_TopoDS_Vertex()));
00275     if(shapes.Extent() == 1)
00276       shape = shapes.First();
00277     else if(shapes.Extent() > 1)
00278     {
00279       //update all attributes first.
00280       TopTools_ListIteratorOfListOfShape it;
00281       it.Initialize(shapes);
00282       shape = shapes.First();
00283     }
00284     else if(op->IsDeleted(*get_TopoDS_Vertex()))
00285       ;
00286     else
00287       return ;
00288   }
00289   TopoDS_Vertex vertex;
00290   if(!shape.IsNull())
00291     vertex = TopoDS::Vertex(shape);
00292 
00293   OCCQueryEngine::instance()->update_OCC_map(*myTopoDSVertex, vertex);
00294 
00295   set_myMarked(CUBIT_TRUE);
00296   set_TopoDS_Vertex(vertex);
00297 }
00298 
00299 // ********** END PUBLIC FUNCTIONS         **********
00300 
00301 // ********** BEGIN PROTECTED FUNCTIONS    **********
00302 // ********** END PROTECTED FUNCTIONS      **********
00303 
00304 // ********** BEGIN PRIVATE FUNCTIONS      **********
00305 // ********** END PRIVATE FUNCTIONS        **********
00306 
00307 // ********** BEGIN HELPER CLASSES         **********
00308 // ********** END HELPER CLASSES           **********
00309 
00310 // ********** BEGIN EXTERN FUNCTIONS       **********
00311 // ********** END EXTERN FUNCTIONS         **********
00312 
00313 // ********** BEGIN STATIC FUNCTIONS       **********
00314 // ********** END STATIC FUNCTIONS         **********
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines