0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / TDataXtd / TDataXtd_Position.cxx
CommitLineData
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
92efcf78 25IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Position,TDF_Attribute)
26
7fd59977 27//=======================================================================
28//function : Set (class method)
29//purpose :
30//=======================================================================
31void TDataXtd_Position::Set(const TDF_Label& aLabel, const gp_Pnt& aPos)
32{
33 Handle(TDataXtd_Position) pos;
34 if (!aLabel.FindAttribute(TDataXtd_Position::GetID(), pos)) {
35 pos = new TDataXtd_Position();
36 aLabel.AddAttribute(pos);
37 }
38 pos->SetPosition( aPos );
39}
40
41//=======================================================================
42//function : Set
43//purpose :
44//=======================================================================
45Handle(TDataXtd_Position) TDataXtd_Position::Set (const TDF_Label& L)
46{
47 Handle(TDataXtd_Position) POS;
48 if (!L.FindAttribute (TDataXtd_Position::GetID (), POS)) {
49 POS = new TDataXtd_Position;
50 L.AddAttribute(POS);
51 }
52 return POS;
53}
54
55//=======================================================================
56//function : Get (class method)
57//purpose :
58//=======================================================================
59Standard_Boolean TDataXtd_Position::Get(const TDF_Label& aLabel, gp_Pnt& aPos)
60{
61 Handle(TDataXtd_Position) pos;
62 if( aLabel.FindAttribute( TDataXtd_Position::GetID(), pos) ) {
63 aPos = pos->GetPosition();
64 return Standard_True;
65 }
66 return Standard_False;
67}
68
69//=======================================================================
70//function : GetID
71//purpose :
72//=======================================================================
73const Standard_GUID& TDataXtd_Position::GetID()
74{
75 static Standard_GUID TDataXtd_Position_guid("55553252-ce0c-11d1-b5d8-00a0c9064368");
76 return TDataXtd_Position_guid;
77}
78
79//=======================================================================
80//function : TDataXtd_Position
81//purpose :
82//=======================================================================
83TDataXtd_Position::TDataXtd_Position()
84 :myPosition(gp_Pnt(0.,0.,0.))
85{
86}
87
88//=======================================================================
89//function : GetPosition
90//purpose :
91//=======================================================================
92const gp_Pnt& TDataXtd_Position::GetPosition() const
93{
94 return myPosition;
95}
96
97//=======================================================================
98//function : Position
99//purpose :
100//=======================================================================
101void TDataXtd_Position::SetPosition(const gp_Pnt& aPos)
102{
103 // OCC2932 correction
104 if(myPosition.X() == aPos.X() &&
105 myPosition.Y() == aPos.Y() &&
106 myPosition.Z() == aPos.Z())
107 return;
108
109 Backup();
110 myPosition = aPos;
111}
112
113
114
115//=======================================================================
116//function : ID
117//purpose :
118//=======================================================================
119const Standard_GUID& TDataXtd_Position::ID() const
120{
121 return GetID();
122}
123
124//=======================================================================
125//function : Restore
126//purpose :
127//=======================================================================
128void TDataXtd_Position::Restore(const Handle(TDF_Attribute)& anAttribute)
129{
130 myPosition = Handle(TDataXtd_Position)::DownCast(anAttribute)->GetPosition();
131}
132
133//=======================================================================
134//function : NewEmpty
135//purpose :
136//=======================================================================
137Handle(TDF_Attribute) TDataXtd_Position::NewEmpty() const
138{
139 return new TDataXtd_Position;
140}
141
142//=======================================================================
143//function : Paste
144//purpose :
145//=======================================================================
146void TDataXtd_Position::Paste(const Handle(TDF_Attribute)& intoAttribute,
147 const Handle(TDF_RelocationTable)&) const
148{
149 Handle(TDataXtd_Position)::DownCast(intoAttribute)->SetPosition(myPosition);
150}