0022627: Change OCCT memory management defaults
[occt.git] / src / Graphic3d / Graphic3d_StructureManager.cxx
CommitLineData
7fd59977 1
2#define XTRACE
3
4// File Graphic3d_StructureManager.cxx
5// Created Mars 1992
6// Author NW,JPB,CAL
7
8//-Copyright MatraDatavision 1991,1992
9
10//-Version
11
81bba717 12//-Design Declaration of variables specific to managers
7fd59977 13
81bba717 14//-Warning Manager manages a set of structures
7fd59977 15
16//-References
17
18//-Language C++ 2.0
19
20//-Declarations
21
22// for the class
23#include <Graphic3d_StructureManager.ixx>
24#include <Graphic3d_StructureManager.pxx>
25static Standard_Boolean Initialisation = Standard_True;
26static int StructureManager_ArrayId[StructureManager_MAX];
27static Standard_Integer StructureManager_CurrentId = 0;
28
29#include <Graphic3d_Structure.pxx>
30#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
31
32//-Aliases
33
34//-Global data definitions
35
36// -- l'identifieur du manager
37// MyId : Standard_Integer;
38
39// -- le mode de mise a jour de l'affichage
40// MyUpdateMode : TypeOfUpdate;
41
42// -- les differents contextes de primitives
43// MyAspectLine3d : AspectLine3d;
44// MyAspectText3d : AspectText3d;
45// MyAspectMarker3d : AspectMarker3d;
46// MyAspectFillArea3d : AspectFillArea3d;
47
48// -- les structures affichees
49// MyDisplayedStructure : SequenceOfStructure;
50
51// -- les structures mises en evidence
52// MyHighlightedStructure : SequenceOfStructure;
53
54// -- les structures visibles
55// MyVisibleStructure : SequenceOfStructure;
56
57// -- les structures detectables
58// MyPickStructure : SequenceOfStructure;
59
60// -- le generateur d'identificateurs de structures
61// MyStructGenId : GenId;
62
63//-Constructors
64
65Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Aspect_GraphicDevice)& aDevice):
66MyDisplayedStructure (),
67MyHighlightedStructure (),
68MyVisibleStructure (),
69MyPickStructure () {
70
71Standard_Real Coef;
72Standard_Integer i;
73Standard_Boolean NotFound = Standard_True;
74Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
75
76 /* Initialize PHIGS and start up */
77 if (Initialisation) {
78
79 Initialisation = Standard_False;
81bba717 80 /* table to manage IDs of StructureManager */
7fd59977 81 for (i=1; i<=Limit; i++) StructureManager_ArrayId[i] = 0;
82
83 StructureManager_CurrentId = 1;
84 StructureManager_ArrayId[1] = 1;
85
86 }
87 else {
88 for (i=1; i<=Limit && NotFound; i++)
89 if (StructureManager_ArrayId[i] == 0) {
90 NotFound = Standard_False;
91 StructureManager_CurrentId = i;
92 StructureManager_ArrayId[i] = 1;
93 }
94
95 if (NotFound)
96 Graphic3d_InitialisationError::Raise
97 ("Too many ViewManagers are defined");
98 }
99
100 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
101 Aspect_GenId theGenId(
102 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId-1)),
103 Standard_Integer (Structure_IDMIN+Coef*StructureManager_CurrentId-1));
104 MyStructGenId = theGenId;
105
106 MyId = StructureManager_CurrentId;
107
108 MyAspectLine3d = new Graphic3d_AspectLine3d ();
109 MyAspectText3d = new Graphic3d_AspectText3d ();
110 MyAspectMarker3d = new Graphic3d_AspectMarker3d ();
111 MyAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
112
113 MyUpdateMode = Aspect_TOU_WAIT;
114 MyGraphicDevice = aDevice;
115
116}
117
118//-Destructors
119
120void Graphic3d_StructureManager::Destroy () {
121
122#ifdef TRACE
123 cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
124 cout << flush;
125#endif
126
127 MyDisplayedStructure.Clear ();
128 MyHighlightedStructure.Clear ();
129 MyVisibleStructure.Clear ();
130 MyPickStructure.Clear ();
131 StructureManager_ArrayId[MyId] = 0;
132
133}
134
135//-Methods, in order
136
137void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
138
139 MyUpdateMode = AType;
140
141}
142
143Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
144
145 return (MyUpdateMode);
146
147}
148
149void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
150
151 MyAspectLine3d = CTX;
152
153}
154
155void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
156
157 MyAspectFillArea3d = CTX;
158
159}
160
161void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
162
163 MyAspectText3d = CTX;
164
165}
166
167void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
168
169 MyAspectMarker3d = CTX;
170
171}
172
173void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
174
175 CTXL = MyAspectLine3d;
176 CTXT = MyAspectText3d;
177 CTXM = MyAspectMarker3d;
178 CTXF = MyAspectFillArea3d;
179
180}
181
182Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
183
184 return (MyAspectLine3d);
185
186}
187
188Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
189
190 return (MyAspectText3d);
191
192}
193
194Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
195
196 return (MyAspectMarker3d);
197
198}
199
200Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
201
202 return (MyAspectFillArea3d);
203
204}
205
206void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
207
208#ifdef TRACE
209 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
210#endif
211
212 MyStructGenId.Free (AnId);
213
214}
215
216void Graphic3d_StructureManager::Visible (const Handle(Graphic3d_Structure)& AStructure) {
217
218 MyVisibleStructure.Add(AStructure);
219
220}
221
222void Graphic3d_StructureManager::Invisible (const Handle(Graphic3d_Structure)& AStructure) {
223
224 MyVisibleStructure.Remove(AStructure);
225
226}
227
228void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
229
230 MyPickStructure.Add(AStructure);
231
232}
233
234void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
235
236 MyPickStructure.Remove(AStructure);
237
238}
239
240void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
241
242 SG.Assign(MyDisplayedStructure);
243
244 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
245
246 //JMBfor (Standard_Integer i=1; i<=Length; i++)
247 //JMB SG.Add (MyDisplayedStructure.Value (i));
248
249}
250
251Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
252
253Standard_Integer Length = MyDisplayedStructure.Extent ();
254
255 return (Length);
256
257}
258
259//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
260
261//return (MyDisplayedStructure.Value (AnIndex));
262
263//}
264
265void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
266
267 SG.Assign(MyHighlightedStructure);
268
269}
270
271void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
272
273 SG.Assign(MyPickStructure);
274
275}
276
277void Graphic3d_StructureManager::VisibleStructures (Graphic3d_MapOfStructure& SG) const {
278
279 SG.Assign(MyVisibleStructure);
280
281
282}
283
284void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
285
286Standard_Boolean Flag = Standard_True;
287Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
288
289 RL = RealLast ();
290 RF = RealFirst ();
291
292 XMin = YMin = ZMin = RL;
293 XMax = YMax = ZMax = RF;
294
295 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
296 for (; it.More(); it.Next()) {
297 Handle(Graphic3d_Structure) SG = it.Key();
298 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
299 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
300 if (Xm < XMin) XMin = Xm;
301 if (Ym < YMin) YMin = Ym;
302 if (Zm < ZMin) ZMin = Zm;
303 if (XM > XMax) XMax = XM;
304 if (YM > YMax) YMax = YM;
305 if (ZM > ZMax) ZMax = ZM;
306 Flag = Standard_False;
307 }
308 }
309
81bba717 310 // If all structures are empty or infinite
7fd59977 311 if (Flag) {
312 XMin = YMin = ZMin = RF;
313 XMax = YMax = ZMax = RL;
314 }
315
316}
317
318Standard_Integer Graphic3d_StructureManager::NewIdentification () {
319
320Standard_Integer Id = MyStructGenId.Next ();
321
322#ifdef TRACE
323 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
324 cout << flush;
325#endif
326
327 return Id;
328
329}
330
331Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
332
333// Standard_Integer ind=0;
334 Standard_Boolean notfound = Standard_True;
335
336 Handle(Graphic3d_Structure) StructNull;
337
338 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
339
340 Handle(Graphic3d_Structure) SGfound;
341
342 for (; it.More() && notfound; it.Next()) {
343 Handle(Graphic3d_Structure) SG = it.Key();
344 if ( SG->Identification () == AId) {
345 notfound = Standard_False;
346 SGfound = SG;
347 }
348 }
349
350
351 if (notfound)
352 return (StructNull);
353 else
354 return (SGfound);
355
356}
357
358Standard_Integer Graphic3d_StructureManager::Identification () const {
359
360 return (MyId);
361
362}
363
364Standard_Integer Graphic3d_StructureManager::Limit () {
365
366 return (StructureManager_MAX);
367
368}
369
370Standard_Integer Graphic3d_StructureManager::CurrentId () {
371
372 return (StructureManager_CurrentId);
373
374}
375
376Handle(Aspect_GraphicDevice) Graphic3d_StructureManager::GraphicDevice () const {
377
378 return (MyGraphicDevice);
379
380}