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 | // |
973c2be1 |
7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public 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. |
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> |
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 | |
7fd59977 |
64 | // -- les structures detectables |
65 | // MyPickStructure : SequenceOfStructure; |
66 | |
67 | // -- le generateur d'identificateurs de structures |
68 | // MyStructGenId : GenId; |
69 | |
70 | //-Constructors |
71 | |
dc3fe572 |
72 | Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver): |
7fd59977 |
73 | MyDisplayedStructure (), |
74 | MyHighlightedStructure (), |
7fd59977 |
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; |
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 | |
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 (); |
7fd59977 |
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 | |
7fd59977 |
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 | |
7fd59977 |
274 | void Graphic3d_StructureManager::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { |
275 | |
276 | Standard_Boolean Flag = Standard_True; |
277 | Standard_Real Xm, Ym, Zm, XM, YM, ZM, RL, RF; |
278 | |
279 | RL = RealLast (); |
280 | RF = RealFirst (); |
281 | |
282 | XMin = YMin = ZMin = RL; |
283 | XMax = YMax = ZMax = RF; |
284 | |
285 | Graphic3d_MapIteratorOfMapOfStructure it(MyDisplayedStructure); |
286 | for (; it.More(); it.Next()) { |
287 | Handle(Graphic3d_Structure) SG = it.Key(); |
288 | if (! (SG->IsEmpty() || SG->IsInfinite ())) { |
289 | SG->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM); |
290 | if (Xm < XMin) XMin = Xm; |
291 | if (Ym < YMin) YMin = Ym; |
292 | if (Zm < ZMin) ZMin = Zm; |
293 | if (XM > XMax) XMax = XM; |
294 | if (YM > YMax) YMax = YM; |
295 | if (ZM > ZMax) ZMax = ZM; |
296 | Flag = Standard_False; |
297 | } |
298 | } |
299 | |
81bba717 |
300 | // If all structures are empty or infinite |
7fd59977 |
301 | if (Flag) { |
302 | XMin = YMin = ZMin = RF; |
303 | XMax = YMax = ZMax = RL; |
304 | } |
305 | |
306 | } |
307 | |
308 | Standard_Integer Graphic3d_StructureManager::NewIdentification () { |
309 | |
310 | Standard_Integer Id = MyStructGenId.Next (); |
311 | |
312 | #ifdef TRACE |
313 | cout << "Graphic3d_StructureManager::NewIdentification " << Id << "\n"; |
314 | cout << flush; |
315 | #endif |
316 | |
317 | return Id; |
318 | |
319 | } |
320 | |
321 | Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const { |
322 | |
323 | // Standard_Integer ind=0; |
324 | Standard_Boolean notfound = Standard_True; |
325 | |
326 | Handle(Graphic3d_Structure) StructNull; |
327 | |
328 | Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); |
329 | |
330 | Handle(Graphic3d_Structure) SGfound; |
331 | |
332 | for (; it.More() && notfound; it.Next()) { |
333 | Handle(Graphic3d_Structure) SG = it.Key(); |
334 | if ( SG->Identification () == AId) { |
335 | notfound = Standard_False; |
336 | SGfound = SG; |
337 | } |
338 | } |
339 | |
340 | |
341 | if (notfound) |
342 | return (StructNull); |
343 | else |
344 | return (SGfound); |
345 | |
346 | } |
347 | |
348 | Standard_Integer Graphic3d_StructureManager::Identification () const { |
349 | |
350 | return (MyId); |
351 | |
352 | } |
353 | |
354 | Standard_Integer Graphic3d_StructureManager::Limit () { |
355 | |
356 | return (StructureManager_MAX); |
357 | |
358 | } |
359 | |
360 | Standard_Integer Graphic3d_StructureManager::CurrentId () { |
361 | |
362 | return (StructureManager_CurrentId); |
363 | |
364 | } |
365 | |
dc3fe572 |
366 | const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const { |
7fd59977 |
367 | |
dc3fe572 |
368 | return (MyGraphicDriver); |
7fd59977 |
369 | |
370 | } |
eb4320f2 |
371 | |
372 | void Graphic3d_StructureManager::ReComputeStructures() |
373 | { |
374 | for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next()) |
375 | { |
376 | Handle(Graphic3d_Structure) aStructure = anIter.Key(); |
377 | |
378 | aStructure->Clear(); |
379 | aStructure->Compute(); |
380 | } |
381 | } |