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