b311480e |
1 | // Created on: 1997-03-06 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <Standard_GUID.hxx> |
19 | #include <Standard_Type.hxx> |
20 | #include <TDataStd_Integer.hxx> |
21 | #include <TDF_Attribute.hxx> |
22 | #include <TDF_Label.hxx> |
7fd59977 |
23 | #include <TDF_Reference.hxx> |
42cf5bc1 |
24 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Integer,TDF_Attribute) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : GetID |
30 | //purpose : |
31 | //======================================================================= |
7fd59977 |
32 | const Standard_GUID& TDataStd_Integer::GetID() |
33 | { |
34 | static Standard_GUID TDataStd_IntegerID ("2a96b606-ec8b-11d0-bee7-080009dc3333"); |
35 | return TDataStd_IntegerID; |
36 | } |
37 | |
38 | |
39 | //======================================================================= |
40 | //function : Set |
41 | //purpose : |
42 | //======================================================================= |
43 | |
44 | Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, |
45 | const Standard_Integer V) |
46 | |
47 | { |
48 | Handle(TDataStd_Integer) A; |
49 | if (!L.FindAttribute (TDataStd_Integer::GetID(), A)) { |
50 | A = new TDataStd_Integer (); |
fa53efef |
51 | A->SetID(GetID()); |
7fd59977 |
52 | L.AddAttribute(A); |
53 | } |
54 | A->Set (V); |
55 | return A; |
56 | } |
57 | |
fa53efef |
58 | //======================================================================= |
59 | //function : Set |
60 | //purpose : Set user defined attribute |
61 | //======================================================================= |
62 | |
63 | Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, const Standard_GUID& theGuid, |
64 | const Standard_Integer V) |
65 | { |
66 | Handle(TDataStd_Integer) A; |
67 | if (!L.FindAttribute(theGuid, A)) { |
68 | A = new TDataStd_Integer (); |
69 | A->SetID(theGuid); |
70 | L.AddAttribute(A); |
71 | } |
72 | A->Set (V); |
73 | return A; |
74 | } |
7fd59977 |
75 | //======================================================================= |
76 | //function : TDataStd_Integer |
77 | //purpose : Empty Constructor |
78 | //======================================================================= |
79 | |
80 | TDataStd_Integer::TDataStd_Integer () |
81 | : myValue (-1) |
82 | { } |
83 | |
84 | |
85 | //======================================================================= |
86 | //function : Set |
87 | //purpose : |
88 | //======================================================================= |
89 | |
90 | void TDataStd_Integer::Set(const Standard_Integer v) |
91 | { |
92 | // OCC2932 correction |
93 | if(myValue == v) return; |
94 | |
95 | Backup(); |
96 | myValue = v; |
97 | } |
98 | |
99 | |
100 | //======================================================================= |
101 | //function : Get |
102 | //purpose : |
103 | //======================================================================= |
104 | |
105 | Standard_Integer TDataStd_Integer::Get () const { return myValue; } |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : IsCaptured |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Standard_Boolean TDataStd_Integer::IsCaptured() const |
114 | { |
115 | Handle(TDF_Reference) R; |
116 | return (Label().FindAttribute(TDF_Reference::GetID(),R)); |
117 | } |
118 | |
119 | //======================================================================= |
120 | //function : ID |
121 | //purpose : |
122 | //======================================================================= |
123 | |
fa53efef |
124 | const Standard_GUID& TDataStd_Integer::ID () const { return myID; } |
7fd59977 |
125 | |
fa53efef |
126 | //======================================================================= |
127 | //function : SetID |
128 | //purpose : |
129 | //======================================================================= |
7fd59977 |
130 | |
fa53efef |
131 | void TDataStd_Integer::SetID( const Standard_GUID& theGuid) |
132 | { |
133 | if(myID == theGuid) return; |
134 | |
135 | Backup(); |
136 | myID = theGuid; |
137 | } |
7fd59977 |
138 | //======================================================================= |
139 | //function : NewEmpty |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | Handle(TDF_Attribute) TDataStd_Integer::NewEmpty () const |
144 | { |
fa53efef |
145 | Handle(TDataStd_Integer) Att = new TDataStd_Integer(); |
146 | Att->SetID(myID); |
147 | return Att; |
7fd59977 |
148 | } |
149 | |
150 | //======================================================================= |
151 | //function : Restore |
152 | //purpose : |
153 | //======================================================================= |
154 | |
155 | void TDataStd_Integer::Restore(const Handle(TDF_Attribute)& With) |
156 | { |
fa53efef |
157 | Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (With); |
158 | myValue = anInt->Get(); |
159 | myID = anInt->ID(); |
7fd59977 |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : Paste |
164 | //purpose : |
165 | //======================================================================= |
166 | |
167 | void TDataStd_Integer::Paste (const Handle(TDF_Attribute)& Into, |
35e08fe8 |
168 | const Handle(TDF_RelocationTable)& /*RT*/) const |
7fd59977 |
169 | { |
fa53efef |
170 | Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (Into); |
171 | anInt->Set(myValue); |
172 | anInt->SetID(myID); |
7fd59977 |
173 | } |
174 | |
175 | //======================================================================= |
176 | //function : Dump |
177 | //purpose : |
178 | //======================================================================= |
179 | |
180 | Standard_OStream& TDataStd_Integer::Dump (Standard_OStream& anOS) const |
181 | { |
182 | anOS << "Integer:: "<< this <<" : "; |
183 | anOS << myValue; |
fa53efef |
184 | Standard_Character sguid[Standard_GUID_SIZE_ALLOC]; |
185 | myID.ToCString(sguid); |
186 | anOS << sguid; |
7fd59977 |
187 | // |
188 | anOS <<"\nAttribute fields: "; |
008aef40 |
189 | TDF_Attribute::Dump(anOS); |
7fd59977 |
190 | return anOS; |
191 | } |
192 | |