0024610: Visualization, Visual3d_View::MinMaxValues() - skip erased objects while...
[occt.git] / src / Graphic3d / Graphic3d_StructureManager.cxx
1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #define XTRACE
17
18
19
20 //-Version      
21
22 //-Design       Declaration of variables specific to managers
23
24 //-Warning      Manager manages a set of structures
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>
35 static Standard_Boolean Initialisation = Standard_True;
36 static int StructureManager_ArrayId[StructureManager_MAX];
37 static 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
64 //      -- les structures detectables
65 //      MyPickStructure         :       SequenceOfStructure;
66
67 //      -- le generateur d'identificateurs de structures
68 //      MyStructGenId           :       GenId;
69
70 //-Constructors
71
72 Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
73 MyDisplayedStructure (),
74 MyHighlightedStructure (),
75 MyPickStructure () {
76
77 Standard_Real Coef;
78 Standard_Integer i;
79 Standard_Boolean NotFound       = Standard_True;
80 Standard_Integer Limit  = Graphic3d_StructureManager::Limit ();
81
82         /* Initialize PHIGS and start up */
83         if (Initialisation) {
84
85                 Initialisation = Standard_False;
86                 /* table to manage IDs of StructureManager */
87                 for (i=0; i<Limit; i++) StructureManager_ArrayId[i]    = 0;
88
89                 StructureManager_CurrentId      = 0;
90                 StructureManager_ArrayId[0]     = 1;
91
92         }
93         else {
94                 for (i=0; i<Limit && NotFound; i++)
95                         if (StructureManager_ArrayId[i] == 0) {
96                                 NotFound        = Standard_False;
97                                 StructureManager_CurrentId      = i;
98                                 StructureManager_ArrayId[i]     = 1;
99                         }
100
101                 if (NotFound)
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                 }
108         }
109
110         Coef            = (Structure_IDMIN+Structure_IDMAX)/Limit;
111         Aspect_GenId theGenId(
112           Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
113           Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
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;
124         MyGraphicDriver         = theDriver;
125
126 }
127
128 //-Destructors
129
130 void 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 ();
139         MyPickStructure.Clear ();
140         StructureManager_ArrayId[MyId]  = 0;
141
142 }
143
144 //-Methods, in order
145
146 void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
147
148         MyUpdateMode    = AType;
149
150 }
151
152 Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
153
154         return (MyUpdateMode);
155
156 }
157
158 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
159
160         MyAspectLine3d          = CTX;
161
162 }
163
164 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
165
166         MyAspectFillArea3d      = CTX;
167
168 }
169
170 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
171
172         MyAspectText3d          = CTX;
173
174 }
175
176 void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
177
178         MyAspectMarker3d        = CTX;
179
180 }
181
182 void 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
191 Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
192
193         return (MyAspectLine3d);
194
195 }
196
197 Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
198
199         return (MyAspectText3d);
200
201 }
202
203 Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
204
205         return (MyAspectMarker3d);
206
207 }
208
209 Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
210
211         return (MyAspectFillArea3d);
212
213 }
214
215 void 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
225 void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
226
227   MyPickStructure.Add(AStructure);
228
229 }
230
231 void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
232
233   MyPickStructure.Remove(AStructure);
234  
235 }
236
237 void 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
248 Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
249
250 Standard_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
262 void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
263
264   SG.Assign(MyHighlightedStructure);
265
266 }
267
268 void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
269
270   SG.Assign(MyPickStructure);
271
272 }
273
274 Standard_Integer Graphic3d_StructureManager::NewIdentification () {
275
276 Standard_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
287 Handle(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
314 Standard_Integer Graphic3d_StructureManager::Identification () const {
315  
316         return (MyId);
317  
318 }
319
320 Standard_Integer Graphic3d_StructureManager::Limit () {
321
322         return (StructureManager_MAX);
323
324 }
325
326 Standard_Integer Graphic3d_StructureManager::CurrentId () {
327
328         return (StructureManager_CurrentId);
329
330 }
331
332 const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const {
333
334         return (MyGraphicDriver);
335
336 }
337
338 void Graphic3d_StructureManager::RecomputeStructures()
339 {
340   // Go through all unique structures including child (connected) ones and ensure that they are computed.
341   Graphic3d_MapOfStructure aStructNetwork;
342
343   for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next())
344   {
345     Handle(Graphic3d_Structure) aStructure = anIter.Key();
346     anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork);
347   }
348
349   RecomputeStructures (aStructNetwork);
350 }
351
352 void 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();
359   }
360 }