Warnings on vc14 were eliminated
[occt.git] / src / TDataStd / TDataStd_Current.cxx
1 // Created on: 1999-08-02
2 // Created by: Denis PASCAL
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Standard_DomainError.hxx>
19 #include <Standard_GUID.hxx>
20 #include <Standard_Type.hxx>
21 #include <TDataStd_Current.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Data.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_RelocationTable.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Current,TDF_Attribute)
28
29 //=======================================================================
30 //function : GetID
31 //purpose  : 
32 //=======================================================================
33 const Standard_GUID& TDataStd_Current::GetID () 
34 {
35   static Standard_GUID TDataStd_CurrentID("2a96b623-ec8b-11d0-bee7-080009dc3333");
36   return TDataStd_CurrentID;
37 }
38
39 //=======================================================================
40 //function : Set
41 //purpose  : 
42 //=======================================================================
43
44 void TDataStd_Current::Set (const TDF_Label& current)
45
46   Handle(TDataStd_Current) A;
47   Handle(TDF_Data) D = current.Data();
48   if (!D->Root().FindAttribute (TDataStd_Current::GetID(), A)) {
49     A = new TDataStd_Current (); 
50     D->Root().AddAttribute(A);
51   }
52   A->SetLabel (current);
53 }
54
55 //=======================================================================
56 //function : Get
57 //purpose  : 
58 //=======================================================================
59
60 TDF_Label TDataStd_Current::Get (const TDF_Label& access)
61
62 //  TDF_Label current;
63   Handle(TDataStd_Current) A;
64   if (!access.Data()->Root().FindAttribute (TDataStd_Current::GetID(), A)) {
65     throw Standard_DomainError("TDataStd_Current::Get : not setted");
66   }  
67   return A->GetLabel();
68 }
69
70 //=======================================================================
71 //function : Has
72 //purpose  : 
73 //=======================================================================
74
75 Standard_Boolean TDataStd_Current::Has (const TDF_Label& access)
76
77   return (access.Data()->Root().IsAttribute (TDataStd_Current::GetID()));
78 }
79
80 //=======================================================================
81 //function : TDataStd_Current
82 //purpose  : 
83 //=======================================================================
84
85 TDataStd_Current::TDataStd_Current () { }
86
87
88
89 //=======================================================================
90 //function : SetLabel
91 //purpose  : 
92 //=======================================================================
93
94 void TDataStd_Current::SetLabel (const TDF_Label& current) 
95 {
96   // OCC2932 correction
97   if(myLabel == current) return;
98
99   Backup();
100   myLabel = current;
101 }
102
103 //=======================================================================
104 //function : GetLabel
105 //purpose  : 
106 //=======================================================================
107
108 TDF_Label TDataStd_Current::GetLabel () const
109 {
110   return myLabel;
111 }
112
113
114 //=======================================================================
115 //function : ID
116 //purpose  : 
117 //=======================================================================
118
119 const Standard_GUID& TDataStd_Current::ID() const { return GetID(); }
120
121
122 //=======================================================================
123 //function : NewEmpty
124 //purpose  : 
125 //=======================================================================
126
127 Handle(TDF_Attribute) TDataStd_Current::NewEmpty () const
128 {  
129   return new TDataStd_Current(); 
130 }
131
132 //=======================================================================
133 //function : Restore
134 //purpose  : 
135 //=======================================================================
136
137 void TDataStd_Current::Restore(const Handle(TDF_Attribute)& With) 
138 {
139   myLabel = Handle(TDataStd_Current)::DownCast (With)->GetLabel ();
140 }
141
142 //=======================================================================
143 //function : Paste
144 //purpose  : 
145 //=======================================================================
146
147 void TDataStd_Current::Paste (const Handle(TDF_Attribute)& Into,
148                                 const Handle(TDF_RelocationTable)& RT) const
149 {
150   TDF_Label tLab;
151   if (!myLabel.IsNull()) {
152     if (!RT->HasRelocation(myLabel,tLab)) tLab = myLabel;
153   }
154   Handle(TDataStd_Current)::DownCast(Into)->SetLabel(tLab);
155 }
156
157 //=======================================================================
158 //function : Dump
159 //purpose  : 
160 //=======================================================================
161
162 Standard_OStream& TDataStd_Current::Dump (Standard_OStream& anOS) const
163 {  
164   anOS << "Current";
165   return anOS;
166 }
167
168