0026005: Problem with transient TFunction_Logbook
[occt.git] / src / TFunction / TFunction_Scope.cxx
CommitLineData
b311480e 1// Created on: 2008-06-22
2// Created by: Vladislav ROMASHKO
973c2be1 3// Copyright (c) 2008-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 <Standard_GUID.hxx>
18#include <Standard_Type.hxx>
19#include <TDF_Attribute.hxx>
20#include <TDF_Label.hxx>
7fd59977 21#include <TDF_MapIteratorOfLabelMap.hxx>
42cf5bc1 22#include <TDF_RelocationTable.hxx>
42cf5bc1 23#include <TFunction_Scope.hxx>
7fd59977 24
25//=======================================================================
26//function : GetID
27//purpose : Static method to get an ID
28//=======================================================================
7fd59977 29const Standard_GUID& TFunction_Scope::GetID()
30{
31 static Standard_GUID TFunction_ScopeID("F2DE4EFF-7FE8-40a3-AAD5-5B6DDEA83469");
32 return TFunction_ScopeID;
33}
34
35//=======================================================================
36//function : Set
37//purpose : Finds or creates a Scope attribute
38//=======================================================================
39
40Handle(TFunction_Scope) TFunction_Scope::Set(const TDF_Label& Access)
41{
42 Handle(TFunction_Scope) S;
43 if (!Access.Root().FindAttribute(TFunction_Scope::GetID(), S))
44 {
45 S = new TFunction_Scope();
46 Access.Root().AddAttribute(S);
47 }
48 return S;
49}
50
51//=======================================================================
52//function : ID
53//purpose : Returns GUID of the function
54//=======================================================================
55
56const Standard_GUID& TFunction_Scope::ID() const
57{
58 return GetID();
59}
60
61//=======================================================================
62//function : TFunction_Scope
63//purpose : Constructor
64//=======================================================================
65
66TFunction_Scope::TFunction_Scope():myFreeID(1)
67{
68
69}
70
71//=======================================================================
72//function : AddFunction
73//purpose : Adds a function to the scope.
74//=======================================================================
75
76Standard_Boolean TFunction_Scope::AddFunction(const TDF_Label& L)
77{
78 if (myFunctions.IsBound2(L))
79 return Standard_False;
80
81 Backup();
82
83 myFunctions.Bind(myFreeID++, L);
84 return Standard_True;
85}
86
87//=======================================================================
88//function : RemoveFunction
89//purpose : Removes a function from the scope.
90//=======================================================================
91
92Standard_Boolean TFunction_Scope::RemoveFunction(const TDF_Label& L)
93{
94 if (!myFunctions.IsBound2(L))
95 return Standard_False;
96
97 Backup();
98
99 return myFunctions.UnBind2(L);
100}
101
102//=======================================================================
103//function : RemoveFunction
104//purpose : Removes a function from the scope.
105//=======================================================================
106
107Standard_Boolean TFunction_Scope::RemoveFunction(const Standard_Integer ID)
108{
109 if (!myFunctions.IsBound1(ID))
110 return Standard_False;
111
112 Backup();
113
114 return myFunctions.UnBind1(ID);
115}
116
117//=======================================================================
118//function : RemoveAllFunctions
119//purpose : Removes a function from the scope.
120//=======================================================================
121
122void TFunction_Scope::RemoveAllFunctions()
123{
124 if (myFunctions.IsEmpty())
125 return;
126
127 Backup();
128
129 myFunctions.Clear();
130}
131
132//=======================================================================
133//function : HasFunction
134//purpose : Checks presence of a function.
135//=======================================================================
136
137Standard_Boolean TFunction_Scope::HasFunction(const Standard_Integer ID) const
138{
139 return myFunctions.IsBound1(ID);
140}
141
142//=======================================================================
143//function : HasFunction
144//purpose : Checks presence of a function.
145//=======================================================================
146
147Standard_Boolean TFunction_Scope::HasFunction(const TDF_Label& L) const
148{
149 return myFunctions.IsBound2(L);
150}
151
152//=======================================================================
153//function : GetFunction
154//purpose : Returns a function.
155//=======================================================================
156
157Standard_Integer TFunction_Scope::GetFunction(const TDF_Label& L) const
158{
159 return myFunctions.Find2(L);
160}
161
162//=======================================================================
163//function : GetFunction
164//purpose : Returns a function.
165//=======================================================================
166
167const TDF_Label& TFunction_Scope::GetFunction(const Standard_Integer ID) const
168{
169 return myFunctions.Find1(ID);
170}
171
172//=======================================================================
173//function : GetLogbook
174//purpose : Returns the Logbook.
175//=======================================================================
176
f486f64d 177Handle(TFunction_Logbook) TFunction_Scope::GetLogbook() const
7fd59977 178{
f486f64d 179 Handle(TFunction_Logbook) logbook;
180 FindAttribute(TFunction_Logbook::GetID(), logbook);
181 return logbook;
7fd59977 182}
183
184//=======================================================================
185//function : Restore
186//purpose :
187//=======================================================================
188
189void TFunction_Scope::Restore(const Handle(TDF_Attribute)& other)
190{
191 Handle(TFunction_Scope) S = Handle(TFunction_Scope)::DownCast(other);
192
193 // Functions
194 myFunctions = S->myFunctions; // copying...
195 myFreeID = S->myFreeID;
7fd59977 196}
197
198//=======================================================================
199//function : Paste
200//purpose : Method for Copy mechanism
201//=======================================================================
202
203void TFunction_Scope::Paste(const Handle(TDF_Attribute)& /*into*/,
204 const Handle(TDF_RelocationTable)& /*RT*/) const
205{
206 // Do we need to copy a Scope attribute somewhere?
207}
208
209//=======================================================================
210//function : NewEmpty
211//purpose : Returns new empty graph node attribute
212//=======================================================================
213
214Handle(TDF_Attribute) TFunction_Scope::NewEmpty() const
215{
216 return new TFunction_Scope();
217}
218
219//=======================================================================
220//function : Dump
221//purpose : Dump of the scope of functions
222//=======================================================================
223
224Standard_OStream& TFunction_Scope::Dump (Standard_OStream& anOS) const
225{
226 TDF_Attribute::Dump(anOS);
227 return anOS;
228}
229
230//=======================================================================
231//function : GetFunctions
232//purpose : Returns the scope of functions.
233//=======================================================================
234
235const TFunction_DoubleMapOfIntegerLabel& TFunction_Scope::GetFunctions() const
236{
237 return myFunctions;
238}
239
240//=======================================================================
241//function : ChangeFunctions
242//purpose : Returns the scope of functions.
243//=======================================================================
244
245TFunction_DoubleMapOfIntegerLabel& TFunction_Scope::ChangeFunctions()
246{
247 return myFunctions;
248}
249
250//=======================================================================
251//function : SetFreeID
252//purpose : Defines a free function ID
253//=======================================================================
254
255void TFunction_Scope::SetFreeID (const Standard_Integer ID)
256{
257 if (myFreeID == ID)
258 return;
259
260 Backup();
261
262 myFreeID = ID;
263}
264
265//=======================================================================
266//function : GetFreeID
267//purpose : Returns a free function ID
268//=======================================================================
269
270Standard_Integer TFunction_Scope::GetFreeID () const
271{
272 return myFreeID;
273}