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