d3fc872d5a7f4267a87f909fcbea4bd8e9f20a0b
[occt.git] / src / TDataXtd / TDataXtd_Point.cxx
1 // Created on: 2009-04-06
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BRep_Tool.hxx>
18 #include <BRepBuilderAPI_MakeVertex.hxx>
19 #include <Geom_CartesianPoint.hxx>
20 #include <gp_Pnt.hxx>
21 #include <Standard_GUID.hxx>
22 #include <Standard_Type.hxx>
23 #include <TDataStd.hxx>
24 #include <TDataXtd.hxx>
25 #include <TDataXtd_Point.hxx>
26 #include <TDF_Attribute.hxx>
27 #include <TDF_Label.hxx>
28 #include <TDF_RelocationTable.hxx>
29 #include <TNaming_Builder.hxx>
30 #include <TNaming_NamedShape.hxx>
31 #include <TNaming_Tool.hxx>
32 #include <TopAbs.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Vertex.hxx>
35
36 IMPLEMENT_DERIVED_ATTRIBUTE(TDataXtd_Point, TDataStd_GenericEmpty)
37
38 //=======================================================================
39 //function : GetID
40 //purpose  : 
41 //=======================================================================
42 const Standard_GUID& TDataXtd_Point::GetID() 
43 {
44   static Standard_GUID TDataXtd_PointID("2a96b60d-ec8b-11d0-bee7-080009dc3333");
45   return TDataXtd_PointID;
46 }
47
48
49 //=======================================================================
50 //function : Set
51 //purpose  : 
52 //=======================================================================
53
54 Handle(TDataXtd_Point) TDataXtd_Point::Set (const TDF_Label& L)
55
56   Handle(TDataXtd_Point) A; 
57   if (!L.FindAttribute(TDataXtd_Point::GetID(),A)) {
58     A = new TDataXtd_Point (); 
59     L.AddAttribute(A);
60   }
61   return A;
62 }
63
64 //=======================================================================
65 //function : Set
66 //purpose  : 
67 //=======================================================================
68
69 Handle(TDataXtd_Point) TDataXtd_Point::Set (const TDF_Label& L, const gp_Pnt& P)
70
71   Handle(TDataXtd_Point) A = Set (L);
72
73   Handle(TNaming_NamedShape) aNS;
74   if(L.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
75     if(!aNS->Get().IsNull())
76        if(aNS->Get().ShapeType() == TopAbs_VERTEX) {
77          gp_Pnt anOldPnt = BRep_Tool::Pnt(TopoDS::Vertex(aNS->Get()));
78          if(anOldPnt.X() == P.X() &&
79             anOldPnt.Y() == P.Y() &&
80             anOldPnt.Z() == P.Z()
81             )
82            return A;
83        }
84   }
85
86   TNaming_Builder B(L);
87   B.Generated(BRepBuilderAPI_MakeVertex(P));
88   return A;
89 }
90
91
92 //=======================================================================
93 //function : TDataXtd_Point
94 //purpose  : 
95 //=======================================================================
96
97 TDataXtd_Point::TDataXtd_Point () {}
98
99
100
101 //=======================================================================
102 //function : ID
103 //purpose  : 
104 //=======================================================================
105
106 const Standard_GUID& TDataXtd_Point::ID() const { return GetID ();}
107
108
109 //=======================================================================
110 //function : Dump
111 //purpose  : 
112 //=======================================================================
113
114 Standard_OStream& TDataXtd_Point::Dump (Standard_OStream& anOS) const
115 {  
116   anOS << "Point";
117   return anOS;
118 }