b311480e |
1 | // Created on: 2009-04-06 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2009-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <gp_Pnt.hxx> |
18 | #include <Standard_GUID.hxx> |
19 | #include <Standard_Type.hxx> |
20 | #include <TDataXtd_Position.hxx> |
21 | #include <TDF_Attribute.hxx> |
7fd59977 |
22 | #include <TDF_Label.hxx> |
42cf5bc1 |
23 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
24 | |
25 | //======================================================================= |
26 | //function : Set (class method) |
27 | //purpose : |
28 | //======================================================================= |
29 | void TDataXtd_Position::Set(const TDF_Label& aLabel, const gp_Pnt& aPos) |
30 | { |
31 | Handle(TDataXtd_Position) pos; |
32 | if (!aLabel.FindAttribute(TDataXtd_Position::GetID(), pos)) { |
33 | pos = new TDataXtd_Position(); |
34 | aLabel.AddAttribute(pos); |
35 | } |
36 | pos->SetPosition( aPos ); |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : Set |
41 | //purpose : |
42 | //======================================================================= |
43 | Handle(TDataXtd_Position) TDataXtd_Position::Set (const TDF_Label& L) |
44 | { |
45 | Handle(TDataXtd_Position) POS; |
46 | if (!L.FindAttribute (TDataXtd_Position::GetID (), POS)) { |
47 | POS = new TDataXtd_Position; |
48 | L.AddAttribute(POS); |
49 | } |
50 | return POS; |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : Get (class method) |
55 | //purpose : |
56 | //======================================================================= |
57 | Standard_Boolean TDataXtd_Position::Get(const TDF_Label& aLabel, gp_Pnt& aPos) |
58 | { |
59 | Handle(TDataXtd_Position) pos; |
60 | if( aLabel.FindAttribute( TDataXtd_Position::GetID(), pos) ) { |
61 | aPos = pos->GetPosition(); |
62 | return Standard_True; |
63 | } |
64 | return Standard_False; |
65 | } |
66 | |
67 | //======================================================================= |
68 | //function : GetID |
69 | //purpose : |
70 | //======================================================================= |
71 | const Standard_GUID& TDataXtd_Position::GetID() |
72 | { |
73 | static Standard_GUID TDataXtd_Position_guid("55553252-ce0c-11d1-b5d8-00a0c9064368"); |
74 | return TDataXtd_Position_guid; |
75 | } |
76 | |
77 | //======================================================================= |
78 | //function : TDataXtd_Position |
79 | //purpose : |
80 | //======================================================================= |
81 | TDataXtd_Position::TDataXtd_Position() |
82 | :myPosition(gp_Pnt(0.,0.,0.)) |
83 | { |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : GetPosition |
88 | //purpose : |
89 | //======================================================================= |
90 | const gp_Pnt& TDataXtd_Position::GetPosition() const |
91 | { |
92 | return myPosition; |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Position |
97 | //purpose : |
98 | //======================================================================= |
99 | void TDataXtd_Position::SetPosition(const gp_Pnt& aPos) |
100 | { |
101 | // OCC2932 correction |
102 | if(myPosition.X() == aPos.X() && |
103 | myPosition.Y() == aPos.Y() && |
104 | myPosition.Z() == aPos.Z()) |
105 | return; |
106 | |
107 | Backup(); |
108 | myPosition = aPos; |
109 | } |
110 | |
111 | |
112 | |
113 | //======================================================================= |
114 | //function : ID |
115 | //purpose : |
116 | //======================================================================= |
117 | const Standard_GUID& TDataXtd_Position::ID() const |
118 | { |
119 | return GetID(); |
120 | } |
121 | |
122 | //======================================================================= |
123 | //function : Restore |
124 | //purpose : |
125 | //======================================================================= |
126 | void TDataXtd_Position::Restore(const Handle(TDF_Attribute)& anAttribute) |
127 | { |
128 | myPosition = Handle(TDataXtd_Position)::DownCast(anAttribute)->GetPosition(); |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : NewEmpty |
133 | //purpose : |
134 | //======================================================================= |
135 | Handle(TDF_Attribute) TDataXtd_Position::NewEmpty() const |
136 | { |
137 | return new TDataXtd_Position; |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : Paste |
142 | //purpose : |
143 | //======================================================================= |
144 | void TDataXtd_Position::Paste(const Handle(TDF_Attribute)& intoAttribute, |
145 | const Handle(TDF_RelocationTable)&) const |
146 | { |
147 | Handle(TDataXtd_Position)::DownCast(intoAttribute)->SetPosition(myPosition); |
148 | } |