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