0023544: Texture management in TKOpenGl should be redesigned
[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 */
f163f612 96 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
7fd59977 97
f163f612 98 StructureManager_CurrentId = 0;
99 StructureManager_ArrayId[0] = 1;
7fd59977 100
101 }
102 else {
f163f612 103 for (i=0; i<Limit && NotFound; i++)
7fd59977 104 if (StructureManager_ArrayId[i] == 0) {
105 NotFound = Standard_False;
106 StructureManager_CurrentId = i;
107 StructureManager_ArrayId[i] = 1;
108 }
109
110 if (NotFound)
f163f612 111 {
112 Standard_SStream anErrorDescription;
113 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
114 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
115 Graphic3d_InitialisationError::Raise(anErrorDescription);
116 }
7fd59977 117 }
118
119 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
120 Aspect_GenId theGenId(
f163f612 121 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
122 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
7fd59977 123 MyStructGenId = theGenId;
124
125 MyId = StructureManager_CurrentId;
126
127 MyAspectLine3d = new Graphic3d_AspectLine3d ();
128 MyAspectText3d = new Graphic3d_AspectText3d ();
129 MyAspectMarker3d = new Graphic3d_AspectMarker3d ();
130 MyAspectFillArea3d = new Graphic3d_AspectFillArea3d ();
131
132 MyUpdateMode = Aspect_TOU_WAIT;
133 MyGraphicDevice = aDevice;
134
135}
136
137//-Destructors
138
139void Graphic3d_StructureManager::Destroy () {
140
141#ifdef TRACE
142 cout << "Graphic3d_StructureManager::Destroy (" << MyId << ")\n";
143 cout << flush;
144#endif
145
146 MyDisplayedStructure.Clear ();
147 MyHighlightedStructure.Clear ();
148 MyVisibleStructure.Clear ();
149 MyPickStructure.Clear ();
150 StructureManager_ArrayId[MyId] = 0;
151
152}
153
154//-Methods, in order
155
156void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
157
158 MyUpdateMode = AType;
159
160}
161
162Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
163
164 return (MyUpdateMode);
165
166}
167
168void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
169
170 MyAspectLine3d = CTX;
171
172}
173
174void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
175
176 MyAspectFillArea3d = CTX;
177
178}
179
180void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
181
182 MyAspectText3d = CTX;
183
184}
185
186void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
187
188 MyAspectMarker3d = CTX;
189
190}
191
192void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
193
194 CTXL = MyAspectLine3d;
195 CTXT = MyAspectText3d;
196 CTXM = MyAspectMarker3d;
197 CTXF = MyAspectFillArea3d;
198
199}
200
201Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
202
203 return (MyAspectLine3d);
204
205}
206
207Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
208
209 return (MyAspectText3d);
210
211}
212
213Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
214
215 return (MyAspectMarker3d);
216
217}
218
219Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
220
221 return (MyAspectFillArea3d);
222
223}
224
225void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
226
227#ifdef TRACE
228 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
229#endif
230
231 MyStructGenId.Free (AnId);
232
233}
234
235void Graphic3d_StructureManager::Visible (const Handle(Graphic3d_Structure)& AStructure) {
236
237 MyVisibleStructure.Add(AStructure);
238
239}
240
241void Graphic3d_StructureManager::Invisible (const Handle(Graphic3d_Structure)& AStructure) {
242
243 MyVisibleStructure.Remove(AStructure);
244
245}
246
247void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
248
249 MyPickStructure.Add(AStructure);
250
251}
252
253void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
254
255 MyPickStructure.Remove(AStructure);
256
257}
258
259void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
260
261 SG.Assign(MyDisplayedStructure);
262
263 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
264
265 //JMBfor (Standard_Integer i=1; i<=Length; i++)
266 //JMB SG.Add (MyDisplayedStructure.Value (i));
267
268}
269
270Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
271
272Standard_Integer Length = MyDisplayedStructure.Extent ();
273
274 return (Length);
275
276}
277
278//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
279
280//return (MyDisplayedStructure.Value (AnIndex));
281
282//}
283
284void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
285
286 SG.Assign(MyHighlightedStructure);
287
288}
289
290void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
291
292 SG.Assign(MyPickStructure);
293
294}
295
296void Graphic3d_StructureManager::VisibleStructures (Graphic3d_MapOfStructure& SG) const {
297
298 SG.Assign(MyVisibleStructure);
299
300
301}
302
303void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
304
305Standard_Boolean Flag = Standard_True;
306Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
307
308 RL = RealLast ();
309 RF = RealFirst ();
310
311 XMin = YMin = ZMin = RL;
312 XMax = YMax = ZMax = RF;
313
314 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
315 for (; it.More(); it.Next()) {
316 Handle(Graphic3d_Structure) SG = it.Key();
317 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
318 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
319 if (Xm < XMin) XMin = Xm;
320 if (Ym < YMin) YMin = Ym;
321 if (Zm < ZMin) ZMin = Zm;
322 if (XM > XMax) XMax = XM;
323 if (YM > YMax) YMax = YM;
324 if (ZM > ZMax) ZMax = ZM;
325 Flag = Standard_False;
326 }
327 }
328
81bba717 329 // If all structures are empty or infinite
7fd59977 330 if (Flag) {
331 XMin = YMin = ZMin = RF;
332 XMax = YMax = ZMax = RL;
333 }
334
335}
336
337Standard_Integer Graphic3d_StructureManager::NewIdentification () {
338
339Standard_Integer Id = MyStructGenId.Next ();
340
341#ifdef TRACE
342 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
343 cout << flush;
344#endif
345
346 return Id;
347
348}
349
350Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
351
352// Standard_Integer ind=0;
353 Standard_Boolean notfound = Standard_True;
354
355 Handle(Graphic3d_Structure) StructNull;
356
357 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
358
359 Handle(Graphic3d_Structure) SGfound;
360
361 for (; it.More() && notfound; it.Next()) {
362 Handle(Graphic3d_Structure) SG = it.Key();
363 if ( SG->Identification () == AId) {
364 notfound = Standard_False;
365 SGfound = SG;
366 }
367 }
368
369
370 if (notfound)
371 return (StructNull);
372 else
373 return (SGfound);
374
375}
376
377Standard_Integer Graphic3d_StructureManager::Identification () const {
378
379 return (MyId);
380
381}
382
383Standard_Integer Graphic3d_StructureManager::Limit () {
384
385 return (StructureManager_MAX);
386
387}
388
389Standard_Integer Graphic3d_StructureManager::CurrentId () {
390
391 return (StructureManager_CurrentId);
392
393}
394
395Handle(Aspect_GraphicDevice) Graphic3d_StructureManager::GraphicDevice () const {
396
397 return (MyGraphicDevice);
398
399}