0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[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
7fd59977 69// -- les structures detectables
70// MyPickStructure : SequenceOfStructure;
71
72// -- le generateur d'identificateurs de structures
73// MyStructGenId : GenId;
74
75//-Constructors
76
dc3fe572 77Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
7fd59977 78MyDisplayedStructure (),
79MyHighlightedStructure (),
7fd59977 80MyPickStructure () {
81
82Standard_Real Coef;
83Standard_Integer i;
84Standard_Boolean NotFound = Standard_True;
85Standard_Integer Limit = Graphic3d_StructureManager::Limit ();
86
87 /* Initialize PHIGS and start up */
88 if (Initialisation) {
89
90 Initialisation = Standard_False;
81bba717 91 /* table to manage IDs of StructureManager */
f163f612 92 for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0;
7fd59977 93
f163f612 94 StructureManager_CurrentId = 0;
95 StructureManager_ArrayId[0] = 1;
7fd59977 96
97 }
98 else {
f163f612 99 for (i=0; i<Limit && NotFound; i++)
7fd59977 100 if (StructureManager_ArrayId[i] == 0) {
101 NotFound = Standard_False;
102 StructureManager_CurrentId = i;
103 StructureManager_ArrayId[i] = 1;
104 }
105
106 if (NotFound)
f163f612 107 {
108 Standard_SStream anErrorDescription;
109 anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<<
110 "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n";
111 Graphic3d_InitialisationError::Raise(anErrorDescription);
112 }
7fd59977 113 }
114
115 Coef = (Structure_IDMIN+Structure_IDMAX)/Limit;
116 Aspect_GenId theGenId(
f163f612 117 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)),
118 Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1));
7fd59977 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;
dc3fe572 129 MyGraphicDriver = theDriver;
7fd59977 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 ();
7fd59977 144 MyPickStructure.Clear ();
145 StructureManager_ArrayId[MyId] = 0;
146
147}
148
149//-Methods, in order
150
151void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) {
152
153 MyUpdateMode = AType;
154
155}
156
157Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const {
158
159 return (MyUpdateMode);
160
161}
162
163void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) {
164
165 MyAspectLine3d = CTX;
166
167}
168
169void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) {
170
171 MyAspectFillArea3d = CTX;
172
173}
174
175void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) {
176
177 MyAspectText3d = CTX;
178
179}
180
181void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) {
182
183 MyAspectMarker3d = CTX;
184
185}
186
187void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const {
188
189 CTXL = MyAspectLine3d;
190 CTXT = MyAspectText3d;
191 CTXM = MyAspectMarker3d;
192 CTXF = MyAspectFillArea3d;
193
194}
195
196Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const {
197
198 return (MyAspectLine3d);
199
200}
201
202Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const {
203
204 return (MyAspectText3d);
205
206}
207
208Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const {
209
210 return (MyAspectMarker3d);
211
212}
213
214Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const {
215
216 return (MyAspectFillArea3d);
217
218}
219
220void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) {
221
222#ifdef TRACE
223 cout << "Graphic3d_StructureManager::Remove " << AnId << "\n" << flush;
224#endif
225
226 MyStructGenId.Free (AnId);
227
228}
229
7fd59977 230void Graphic3d_StructureManager::Detectable (const Handle(Graphic3d_Structure)& AStructure) {
231
232 MyPickStructure.Add(AStructure);
233
234}
235
236void Graphic3d_StructureManager::Undetectable (const Handle(Graphic3d_Structure)& AStructure) {
237
238 MyPickStructure.Remove(AStructure);
239
240}
241
242void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const {
243
244 SG.Assign(MyDisplayedStructure);
245
246 //JMBStandard_Integer Length = MyDisplayedStructure.Length ();
247
248 //JMBfor (Standard_Integer i=1; i<=Length; i++)
249 //JMB SG.Add (MyDisplayedStructure.Value (i));
250
251}
252
253Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
254
255Standard_Integer Length = MyDisplayedStructure.Extent ();
256
257 return (Length);
258
259}
260
261//Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const {
262
263//return (MyDisplayedStructure.Value (AnIndex));
264
265//}
266
267void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const {
268
269 SG.Assign(MyHighlightedStructure);
270
271}
272
273void Graphic3d_StructureManager::PickStructures (Graphic3d_MapOfStructure& SG) const {
274
275 SG.Assign(MyPickStructure);
276
277}
278
7fd59977 279void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {
280
281Standard_Boolean Flag = Standard_True;
282Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF;
283
284 RL = RealLast ();
285 RF = RealFirst ();
286
287 XMin = YMin = ZMin = RL;
288 XMax = YMax = ZMax = RF;
289
290 Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure);
291 for (; it.More(); it.Next()) {
292 Handle(Graphic3d_Structure) SG = it.Key();
293 if (! (SG->IsEmpty() || SG->IsInfinite ())) {
294 SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
295 if (Xm < XMin) XMin = Xm;
296 if (Ym < YMin) YMin = Ym;
297 if (Zm < ZMin) ZMin = Zm;
298 if (XM > XMax) XMax = XM;
299 if (YM > YMax) YMax = YM;
300 if (ZM > ZMax) ZMax = ZM;
301 Flag = Standard_False;
302 }
303 }
304
81bba717 305 // If all structures are empty or infinite
7fd59977 306 if (Flag) {
307 XMin = YMin = ZMin = RF;
308 XMax = YMax = ZMax = RL;
309 }
310
311}
312
313Standard_Integer Graphic3d_StructureManager::NewIdentification () {
314
315Standard_Integer Id = MyStructGenId.Next ();
316
317#ifdef TRACE
318 cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n";
319 cout << flush;
320#endif
321
322 return Id;
323
324}
325
326Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const {
327
328// Standard_Integer ind=0;
329 Standard_Boolean notfound = Standard_True;
330
331 Handle(Graphic3d_Structure) StructNull;
332
333 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
334
335 Handle(Graphic3d_Structure) SGfound;
336
337 for (; it.More() && notfound; it.Next()) {
338 Handle(Graphic3d_Structure) SG = it.Key();
339 if ( SG->Identification () == AId) {
340 notfound = Standard_False;
341 SGfound = SG;
342 }
343 }
344
345
346 if (notfound)
347 return (StructNull);
348 else
349 return (SGfound);
350
351}
352
353Standard_Integer Graphic3d_StructureManager::Identification () const {
354
355 return (MyId);
356
357}
358
359Standard_Integer Graphic3d_StructureManager::Limit () {
360
361 return (StructureManager_MAX);
362
363}
364
365Standard_Integer Graphic3d_StructureManager::CurrentId () {
366
367 return (StructureManager_CurrentId);
368
369}
370
dc3fe572 371const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const {
7fd59977 372
dc3fe572 373 return (MyGraphicDriver);
7fd59977 374
375}
eb4320f2 376
377void Graphic3d_StructureManager::ReComputeStructures()
378{
379 for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next())
380 {
381 Handle(Graphic3d_Structure) aStructure = anIter.Key();
382
383 aStructure->Clear();
384 aStructure->Compute();
385 }
386}