f1920406edb156c2a574638c2c7b6501137eef64
[occt.git] / src / XCAFDoc / XCAFDoc_Centroid.cxx
1 // Created on: 2000-09-08
2 // Created by: data exchange team
3 // Copyright (c) 2000-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 <gp_Pnt.hxx>
18 #include <Standard_GUID.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_RelocationTable.hxx>
23 #include <XCAFDoc_Centroid.hxx>
24
25 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_Centroid,TDF_Attribute)
26
27 //=======================================================================
28 //function : Constructor
29 //purpose  : 
30 //=======================================================================
31 XCAFDoc_Centroid::XCAFDoc_Centroid()
32 {
33 }
34
35 //=======================================================================
36 //function : GetID
37 //purpose  : 
38 //=======================================================================
39
40 const Standard_GUID& XCAFDoc_Centroid::GetID() 
41 {
42   static Standard_GUID CentroidID ("efd212f3-6dfd-11d4-b9c8-0060b0ee281b");
43   return CentroidID; 
44 }
45
46 //=======================================================================
47 //function : Set
48 //purpose  : 
49 //=======================================================================
50
51  Handle(XCAFDoc_Centroid) XCAFDoc_Centroid::Set(const TDF_Label& L,const gp_Pnt& pnt) 
52 {
53   Handle(XCAFDoc_Centroid) A;
54   if (!L.FindAttribute (XCAFDoc_Centroid::GetID(), A)) {
55     A = new XCAFDoc_Centroid ();
56     L.AddAttribute(A);
57   }
58   A->Set(pnt); 
59   return A;
60 }
61
62 //=======================================================================
63 //function : Set
64 //purpose  : 
65 //=======================================================================
66
67  void XCAFDoc_Centroid::Set(const gp_Pnt& pnt) 
68 {
69   Backup();
70   myCentroid = pnt;
71 }
72
73 //=======================================================================
74 //function : Get
75 //purpose  : 
76 //=======================================================================
77
78  gp_Pnt XCAFDoc_Centroid::Get() const
79 {
80   return myCentroid;
81 }
82
83 //=======================================================================
84 //function : Get
85 //purpose  : 
86 //=======================================================================
87
88 Standard_Boolean XCAFDoc_Centroid::Get(const TDF_Label& label,gp_Pnt& pnt) 
89 {
90   Handle(XCAFDoc_Centroid) aCentroid;
91   if (!label.FindAttribute(XCAFDoc_Centroid::GetID(), aCentroid))
92     return Standard_False;
93   
94   pnt = aCentroid->Get();
95   return Standard_True;
96 }
97
98 //=======================================================================
99 //function : ID
100 //purpose  : 
101 //=======================================================================
102
103 const Standard_GUID& XCAFDoc_Centroid::ID() const
104 {
105   return GetID();
106 }
107
108 //=======================================================================
109 //function : Restore
110 //purpose  : 
111 //=======================================================================
112
113  void XCAFDoc_Centroid::Restore(const Handle(TDF_Attribute)& With) 
114 {
115   myCentroid = Handle(XCAFDoc_Centroid)::DownCast(With)->Get();
116 }
117
118 //=======================================================================
119 //function : NewEmpty
120 //purpose  : 
121 //=======================================================================
122
123  Handle(TDF_Attribute) XCAFDoc_Centroid::NewEmpty() const
124 {
125   return new XCAFDoc_Centroid();
126 }
127
128 //=======================================================================
129 //function : Paste
130 //purpose  : 
131 //=======================================================================
132
133  void XCAFDoc_Centroid::Paste(const Handle(TDF_Attribute)& Into,const Handle(TDF_RelocationTable)& /* RT */) const
134 {
135   Handle(XCAFDoc_Centroid)::DownCast(Into)->Set(myCentroid);
136
137 }
138
139 //=======================================================================
140 //function : Dump
141 //purpose  : 
142 //=======================================================================
143
144 Standard_OStream& XCAFDoc_Centroid::Dump (Standard_OStream& anOS) const
145 {  
146   anOS << "Centroid ( "; 
147   anOS << myCentroid.X() << ",";
148   anOS << myCentroid.Y() << ",";
149   anOS << myCentroid.Z() << ")";
150   return anOS;
151 }