Commit | Line | Data |
---|---|---|
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 | // Modified 1/08/97 ; PCT : ajout texture mapping |
21 | // 20/08/97 ; PCT : ajout transparence pour texture | |
22 | // 11/97 ; CAL : gestion du GraphicClear | |
23 | // 11/97 ; CAL : ajout pointer StructPtr | |
24 | // 11/97 ; CAL : amelioration de l'effacement SetManager | |
25 | // CAL : 15 janvier 1998 | |
26 | // Ajout de la methode IsTransformed dans une Structure. | |
27 | // (Permet la transmission de cette Trsf vers | |
28 | // la structure COMPUTED si necessaire) | |
7fd59977 | 29 | // Ajout de la methode IsRotated dans une Structure. |
30 | // (Permet de connaitre le type de transformation | |
31 | // pour declencher le calcul des parties cachees | |
32 | // de maniere plus sioux) | |
7fd59977 | 33 | // Ajout de 3 nouvelles methodes Compute virtual dans Structure. |
34 | // (Permet des Compute un peu plus specialises) | |
7fd59977 | 35 | // Ajout des 2 methodes sur Owner dans Structure. |
36 | // (evite de calculer 2 fois les parties cachees | |
37 | // pour 2 representations differentes affichees | |
38 | // d'un meme Presentable Object (Owner)) | |
7fd59977 | 39 | // Ajout des 2 methodes sur HLRValidation dans Structure. |
40 | // (permet de valider ou d'invalider le calcul des | |
41 | // parties cachees sur certaines representations) | |
7fd59977 | 42 | // Ajout de la transmission de la transformation d'une structure |
43 | // vers sa COMPUTED. | |
44 | // 24/2/98 ; CAL : Modification de la gestion des champs | |
45 | // CAL : 26 mars 1998 | |
46 | // Patch, erreur dans la gestion du nombre de Group avec | |
47 | // facettes dans Graphic3d_Structure avec une operation | |
48 | // de Clear. (PRO12795) | |
49 | // FGU : 30 Avril 1998 | |
50 | // Ajout emission | |
51 | // CAL : 20 mai 1998 | |
52 | // Perfs. Connection entre structures COMPUTED. | |
bbf32d01 K |
53 | // 30/11/98 ; FMN : S4069. Textes always visible. |
54 | // 22/03/04 ; SAN : OCC4895 High-level interface for controlling polygon offsets | |
7fd59977 | 55 | |
56 | #define G003 //EUG 26/01/00 Degeneration management | |
57 | ||
bbf32d01 | 58 | #define BUC60918 //GG 31/05/01 A transparente structure priority must have the |
7fd59977 | 59 | // MAX_PRIORITY value so, the highlighted structure must have |
bbf32d01 | 60 | // MAX_PRIORITY-1 value. |
7fd59977 | 61 | // Add ResetDisplayPriority() method. |
62 | ||
63 | #define OCC1174 // SAV 08/01/03 Added back face interior color controling | |
64 | ||
65 | ||
7fd59977 | 66 | |
bbf32d01 | 67 | //-Version |
7fd59977 | 68 | |
81bba717 | 69 | //-Design Declaration of variables specific to graphic structures |
7fd59977 | 70 | |
81bba717 | 71 | //-Warning A structure is defined in a manager |
72 | // This is a sequence of groups of primitives | |
7fd59977 | 73 | |
bbf32d01 | 74 | //-References |
7fd59977 | 75 | |
76 | //-Language C++ 2.0 | |
77 | ||
78 | //-Declarations | |
79 | ||
80 | // for the class | |
81 | ||
82 | #define XDOWNCAST | |
83 | #define XDESTROY | |
84 | #define XDEBUG | |
85 | #define XTRACE | |
86 | #define XTRACE_ISTRSF | |
87 | ||
88 | #include <stdio.h> | |
89 | ||
90 | #include <Graphic3d_Structure.ixx> | |
91 | #include <Graphic3d_Structure.pxx> | |
92 | ||
93 | #include <Graphic3d_GraphicDevice.hxx> | |
94 | #include <Graphic3d_GraphicDriver.hxx> | |
95 | #include <Graphic3d_MaterialAspect.hxx> | |
96 | ||
97 | #include <Graphic3d_MapOfStructure.hxx> | |
98 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> | |
99 | ||
100 | #include <Quantity_Color.hxx> | |
101 | #include <TColStd_Array2OfReal.hxx> | |
102 | #include <Graphic3d_TextureMap.hxx> | |
103 | ||
bbf32d01 | 104 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 105 | #include <Aspect_PolygonOffsetMode.hxx> |
bbf32d01 | 106 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 107 | |
108 | //-Aliases | |
109 | ||
110 | //-Global data definitions | |
111 | ||
112 | //-Constructors | |
113 | ||
114 | Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& AManager): | |
115 | MyGroupGenId (Group_IDMIN, Group_IDMAX), | |
116 | MyAncestors (), | |
117 | MyDescendants (), | |
118 | MyGroups (), | |
119 | MyHighlightColor (Quantity_NOC_WHITE) | |
120 | { | |
121 | ||
122 | Standard_Integer i, j; | |
123 | ||
124 | MyOwner = NULL; | |
125 | ||
126 | Handle(Graphic3d_AspectLine3d) aAspectLine3d = | |
127 | new Graphic3d_AspectLine3d (); | |
128 | Handle(Graphic3d_AspectText3d) aAspectText3d = | |
129 | new Graphic3d_AspectText3d (); | |
130 | Handle(Graphic3d_AspectMarker3d) aAspectMarker3d = | |
131 | new Graphic3d_AspectMarker3d (); | |
132 | Handle(Graphic3d_AspectFillArea3d) aAspectFillArea3d = | |
133 | new Graphic3d_AspectFillArea3d (); | |
134 | ||
81bba717 | 135 | // Return default values |
7fd59977 | 136 | AManager->PrimitivesAspect (aAspectLine3d, aAspectText3d, |
137 | aAspectMarker3d, aAspectFillArea3d); | |
138 | ||
bbf32d01 | 139 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 140 | // It is necessary to set default polygon offsets for a new presentation |
141 | aAspectFillArea3d->SetPolygonOffsets( Aspect_POM_Fill, 1., 0. ); | |
bbf32d01 | 142 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 143 | |
81bba717 | 144 | // Update the associated CStructure |
7fd59977 | 145 | UpdateStructure (aAspectLine3d, aAspectText3d, |
146 | aAspectMarker3d, aAspectFillArea3d); | |
147 | ||
148 | MyFirstPtrStructureManager = MyPtrStructureManager = | |
149 | (void *) AManager.operator->(); | |
150 | MyCStructure.Id = int (AManager->NewIdentification ()); | |
151 | ||
152 | MyCStructure.IsOpen = 0; | |
153 | MyCStructure.IsDeleted = 0; | |
154 | ||
155 | MyCStructure.Composition = 0; /* Graphic3d_TOC_REPLACE */ | |
156 | ||
157 | for (i=0; i<=3; i++) | |
158 | for (j=0; j<=3; j++) | |
159 | if (i == j) | |
160 | MyCStructure.Transformation[i][j] = float (1.0); | |
161 | else | |
162 | MyCStructure.Transformation[i][j] = float (0.0); | |
163 | ||
164 | MyCStructure.Priority = int (Structure_MAX_PRIORITY / 2); | |
165 | MyCStructure.PreviousPriority = MyCStructure.Priority; | |
166 | MyCStructure.stick = 0, | |
167 | MyCStructure.highlight = 0, | |
168 | MyCStructure.visible = 1, | |
169 | MyCStructure.pick = 1; | |
170 | MyCStructure.ContainsFacet = 0, | |
171 | MyCStructure.IsInfinite = 0, | |
172 | MyCStructure.HLRValidation = 0; | |
173 | ||
174 | MyCStructure.GroupBegin = Structure_GROUPBEGIN; | |
175 | MyCStructure.GroupEnd = Structure_GROUPEND; | |
176 | ||
177 | MyCStructure.ContextLine.IsDef = 1, | |
178 | MyCStructure.ContextFillArea.IsDef = 1, | |
179 | MyCStructure.ContextMarker.IsDef = 1, | |
180 | MyCStructure.ContextText.IsDef = 1; | |
181 | ||
182 | MyCStructure.ContextLine.IsSet = 0, | |
183 | MyCStructure.ContextFillArea.IsSet = 0, | |
184 | MyCStructure.ContextMarker.IsSet = 0, | |
185 | MyCStructure.ContextText.IsSet = 0; | |
186 | ||
187 | MyVisual = Graphic3d_TOS_ALL; | |
188 | MyComputeVisual = Graphic3d_TOS_ALL; | |
189 | ||
190 | /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ | |
191 | /*MyCStructure.TransformPersistence.IsDef = 1;*/ | |
192 | MyCStructure.TransformPersistence.IsSet = 0; | |
193 | MyCStructure.TransformPersistence.Flag = Graphic3d_TMF_None; | |
194 | MyCStructure.TransformPersistence.Point.x = 0.0; | |
195 | MyCStructure.TransformPersistence.Point.y = 0.0; | |
196 | MyCStructure.TransformPersistence.Point.z = 0.0; | |
197 | /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ | |
198 | Handle(Aspect_GraphicDriver) agd = | |
199 | (AManager->GraphicDevice ())->GraphicDriver (); | |
200 | ||
201 | MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd; | |
202 | ||
203 | MyGraphicDriver->Structure (MyCStructure); | |
204 | ||
205 | #ifdef TRACE | |
206 | cout << "Graphic3d_Structure::Create (" << MyCStructure.Id << ")\n"; | |
207 | #endif | |
208 | ||
209 | } | |
210 | ||
211 | //-Destructors | |
212 | ||
213 | void Graphic3d_Structure::Destroy () { | |
214 | ||
215 | #ifdef DESTROY | |
216 | cout << "Graphic3d_Structure::Destroy (" << MyCStructure.Id << ")\n"; | |
217 | #endif | |
218 | ||
219 | // as MyFirstPtrStructureManager can be already destroyed, | |
bbf32d01 | 220 | // avoid attempts to access it |
7fd59977 | 221 | MyFirstPtrStructureManager = 0; |
222 | Remove (); | |
223 | ||
224 | } | |
225 | ||
226 | //-Methods, in order | |
227 | ||
98178592 A |
228 | void Graphic3d_Structure::Clear (const Standard_Boolean WithDestruction) |
229 | { | |
230 | if (IsDeleted()) return; | |
7fd59977 | 231 | |
98178592 | 232 | MyCStructure.ContainsFacet = 0; |
7fd59977 | 233 | |
98178592 | 234 | // clean groups in graphics driver at first |
98178592 | 235 | GraphicClear (WithDestruction); |
7fd59977 | 236 | |
98178592 A |
237 | // only then remove group references |
238 | if (WithDestruction) | |
239 | { | |
240 | MyGroupGenId.Free(); | |
241 | MyGroups.Clear(); | |
242 | } | |
7fd59977 | 243 | |
7fd59977 | 244 | MyStructureManager->Clear (this, WithDestruction); |
245 | ||
98178592 | 246 | Update(); |
7fd59977 | 247 | } |
248 | ||
249 | void Graphic3d_Structure::Remove () { | |
250 | ||
251 | if (IsDeleted ()) return; | |
252 | ||
253 | #ifdef DESTROY | |
254 | if (MyDescendants.Length () != 0) { | |
255 | cout << "The structure " << MyCStructure.Id << " have " | |
256 | << MyDescendants.Length () << " descendants.\n" << flush; | |
257 | } | |
258 | if (MyAncestors.Length () != 0) { | |
259 | cout << "The structure " << MyCStructure.Id << " have " | |
260 | << MyAncestors.Length () << " ancestors.\n" << flush; | |
261 | } | |
262 | #endif | |
263 | ||
264 | Standard_Integer i, Length; | |
98178592 | 265 | |
6c8126b5 A |
266 | // clean groups in graphics driver at first; this is also should be done |
267 | // to avoid unwanted group cleaning in group's destructor | |
268 | // Pass Standard_False to Clear(..) method to avoid updating in | |
269 | // structure manager, it isn't necessary, besides of it structure manager | |
270 | // could be already destroyed and invalid pointers used in structure; | |
98178592 A |
271 | Length = MyGroups.Length(); |
272 | for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId) | |
6c8126b5 | 273 | MyGroups.ChangeValue (aGrId)->Clear (Standard_False); |
98178592 | 274 | |
7fd59977 | 275 | // Standard_Address APtr = (void *) This ().operator->(); |
276 | Standard_Address APtr = (void *) this; | |
81bba717 | 277 | // It is necessary to remove the eventual pointer on the structure |
278 | // that can be destroyed, in the list of descendants | |
279 | // of ancesters of this structure and in the list of ancesters | |
280 | // of descendants of the same structure. | |
7fd59977 | 281 | |
282 | Length = MyDescendants.Length (); | |
283 | for (i=1; i<=Length; i++) | |
284 | ((Graphic3d_Structure *) | |
285 | (MyDescendants.Value (i)))->Remove (APtr, Graphic3d_TOC_ANCESTOR); | |
286 | ||
287 | Length = MyAncestors.Length (); | |
288 | for (i=1; i<=Length; i++) | |
289 | ((Graphic3d_Structure *) | |
290 | (MyAncestors.Value (i)))->Remove (APtr, Graphic3d_TOC_DESCENDANT); | |
291 | ||
292 | MyCStructure.ContainsFacet = 0; | |
293 | MyCStructure.IsDeleted = 1; | |
294 | ||
81bba717 | 295 | // Destruction of me in the graphic library |
7fd59977 | 296 | MyGraphicDriver->RemoveStructure (MyCStructure); |
297 | ||
bbf32d01 | 298 | // Liberation of the identification if the destroyed structure |
81bba717 | 299 | // in the first manager that performs creation of the structure. |
7fd59977 | 300 | if ( MyFirstPtrStructureManager ) |
301 | MyFirstStructureManager->Remove (Standard_Integer (MyCStructure.Id)); | |
302 | ||
303 | } | |
304 | ||
305 | void Graphic3d_Structure::Display () { | |
306 | ||
307 | if (IsDeleted ()) return; | |
308 | ||
309 | if (! MyCStructure.stick) { | |
310 | MyCStructure.stick = 1; | |
311 | MyStructureManager->Display (this); | |
312 | } | |
313 | ||
314 | } | |
315 | ||
316 | void Graphic3d_Structure::Display (const Standard_Integer Priority) { | |
317 | ||
318 | if (IsDeleted ()) return; | |
319 | ||
320 | SetDisplayPriority (Priority); | |
321 | ||
322 | if (! MyCStructure.stick) { | |
323 | MyCStructure.stick = 1; | |
324 | MyStructureManager->Display (this); | |
325 | } | |
326 | ||
327 | } | |
328 | ||
329 | void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer Priority) { | |
330 | ||
331 | if (IsDeleted ()) return; | |
332 | ||
333 | #ifdef BUC60918 | |
334 | if( Priority == MyCStructure.Priority ) return; | |
335 | #endif | |
336 | ||
337 | MyCStructure.PreviousPriority = MyCStructure.Priority; | |
338 | MyCStructure.Priority = int (Priority); | |
339 | ||
340 | if (MyCStructure.Priority != MyCStructure.PreviousPriority) { | |
341 | if ( (MyCStructure.Priority > Structure_MAX_PRIORITY) || | |
342 | (MyCStructure.Priority < Structure_MIN_PRIORITY) ) | |
343 | Graphic3d_PriorityDefinitionError::Raise | |
344 | ("Bad value for StructurePriority"); | |
345 | ||
346 | if (MyCStructure.stick) | |
347 | MyStructureManager->ChangeDisplayPriority (this, | |
348 | Standard_Integer (MyCStructure.PreviousPriority), | |
349 | Standard_Integer (MyCStructure.Priority)); | |
350 | } | |
351 | ||
352 | } | |
353 | ||
354 | #ifdef BUC60918 | |
355 | void Graphic3d_Structure::ResetDisplayPriority () { | |
356 | ||
357 | if (IsDeleted ()) return; | |
358 | ||
359 | if (MyCStructure.Priority != MyCStructure.PreviousPriority) { | |
360 | Standard_Integer priority = MyCStructure.Priority; | |
361 | MyCStructure.Priority = MyCStructure.PreviousPriority; | |
362 | ||
363 | if (MyCStructure.stick) | |
364 | MyStructureManager->ChangeDisplayPriority (this, | |
365 | priority, | |
366 | Standard_Integer (MyCStructure.Priority)); | |
367 | } | |
368 | ||
369 | } | |
370 | #endif | |
371 | ||
372 | Standard_Integer Graphic3d_Structure::DisplayPriority () const { | |
373 | ||
374 | return Standard_Integer (MyCStructure.Priority); | |
375 | ||
376 | } | |
377 | ||
378 | void Graphic3d_Structure::Erase () { | |
379 | ||
380 | if (IsDeleted ()) return; | |
381 | ||
382 | if (MyCStructure.stick) { | |
383 | MyCStructure.stick = 0; | |
384 | MyStructureManager->Erase (this); | |
385 | } | |
386 | ||
387 | } | |
388 | ||
389 | void Graphic3d_Structure::Highlight (const Aspect_TypeOfHighlightMethod AMethod) { | |
390 | ||
391 | if (IsDeleted ()) return; | |
392 | ||
81bba717 | 393 | // Highlight on already Highlighted structure. |
7fd59977 | 394 | if (MyCStructure.highlight) { |
395 | ||
396 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); | |
397 | if (UpdateMode == Aspect_TOU_WAIT) | |
398 | UnHighlight (); | |
399 | else { | |
81bba717 | 400 | // To avoid call of method : Update () |
401 | // Not useful and can be costly. | |
7fd59977 | 402 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
403 | UnHighlight (); | |
404 | MyStructureManager->SetUpdateMode (UpdateMode); | |
405 | } | |
406 | } | |
407 | ||
408 | #ifdef BUC60918 | |
409 | SetDisplayPriority (Standard_Integer (Structure_MAX_PRIORITY)-1); | |
410 | #else | |
411 | SetDisplayPriority (Standard_Integer (Structure_MAX_PRIORITY)); | |
412 | #endif | |
413 | ||
414 | GraphicHighlight (AMethod); | |
415 | MyStructureManager->Highlight (this, AMethod); | |
416 | ||
417 | Update (); | |
418 | ||
419 | } | |
420 | ||
421 | void Graphic3d_Structure::SetHighlightColor (const Quantity_Color& AColor) { | |
422 | ||
423 | if (IsDeleted ()) return; | |
424 | ||
425 | if (! MyCStructure.highlight) | |
426 | MyHighlightColor = AColor; | |
427 | else { | |
81bba717 | 428 | // Change highlight color on already Highlighted structure. |
7fd59977 | 429 | |
430 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); | |
431 | if (UpdateMode == Aspect_TOU_WAIT) | |
432 | UnHighlight (); | |
433 | else { | |
81bba717 | 434 | // To avoid call of method : Update () |
435 | // Not useful and can be costly. | |
7fd59977 | 436 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
437 | UnHighlight (); | |
438 | MyStructureManager->SetUpdateMode (UpdateMode); | |
439 | } | |
440 | MyHighlightColor = AColor; | |
441 | Highlight (MyHighlightMethod); | |
442 | } | |
443 | ||
444 | } | |
445 | ||
446 | void Graphic3d_Structure::SetVisible (const Standard_Boolean AValue) { | |
447 | ||
448 | if (IsDeleted ()) return; | |
449 | ||
450 | MyCStructure.visible = AValue ? 1:0; | |
451 | ||
452 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
453 | ||
454 | if (AValue) | |
455 | MyStructureManager->Visible (this); | |
456 | else | |
457 | MyStructureManager->Invisible (this); | |
458 | ||
459 | Update (); | |
460 | ||
461 | } | |
462 | ||
463 | void Graphic3d_Structure::SetPick (const Standard_Boolean AValue) { | |
464 | ||
465 | if (IsDeleted ()) return; | |
466 | ||
467 | MyCStructure.pick = AValue ? 1:0; | |
468 | ||
469 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
470 | ||
471 | if (AValue) | |
472 | MyStructureManager->Detectable (this); | |
473 | else | |
474 | MyStructureManager->Undetectable (this); | |
475 | ||
476 | Update (); | |
477 | ||
478 | } | |
479 | ||
480 | void Graphic3d_Structure::UnHighlight () { | |
481 | ||
482 | if (IsDeleted ()) return; | |
483 | ||
484 | if (MyCStructure.highlight) { | |
485 | MyCStructure.highlight = 0; | |
486 | ||
487 | GraphicUnHighlight (); | |
488 | MyStructureManager->UnHighlight (this); | |
489 | #ifdef BUC60918 | |
490 | ResetDisplayPriority(); | |
491 | #else | |
492 | SetDisplayPriority | |
493 | (Standard_Integer (MyCStructure.PreviousPriority)); | |
494 | #endif | |
495 | Update (); | |
496 | } | |
497 | ||
498 | } | |
499 | ||
500 | Quantity_Color Graphic3d_Structure::HighlightColor () const { | |
501 | ||
502 | return (MyHighlightColor); | |
503 | ||
504 | } | |
505 | ||
506 | Standard_Boolean Graphic3d_Structure::IsDisplayed () const { | |
507 | ||
508 | if (MyCStructure.stick) | |
509 | return (Standard_True); | |
510 | else | |
511 | return (Standard_False); | |
512 | ||
513 | } | |
514 | ||
515 | Standard_Boolean Graphic3d_Structure::IsDeleted () const { | |
516 | ||
517 | if (MyCStructure.IsDeleted) | |
518 | return (Standard_True); | |
519 | else | |
520 | return (Standard_False); | |
521 | ||
522 | } | |
523 | ||
524 | Standard_Boolean Graphic3d_Structure::IsHighlighted () const { | |
525 | ||
526 | if (MyCStructure.highlight) | |
527 | return (Standard_True); | |
528 | else | |
529 | return (Standard_False); | |
530 | ||
531 | } | |
532 | ||
533 | Standard_Boolean Graphic3d_Structure::IsSelectable () const { | |
534 | ||
535 | if (MyCStructure.pick) | |
536 | return (Standard_True); | |
537 | else | |
538 | return (Standard_False); | |
539 | ||
540 | } | |
541 | ||
542 | Standard_Boolean Graphic3d_Structure::IsVisible () const { | |
543 | ||
544 | if (MyCStructure.visible) | |
545 | return (Standard_True); | |
546 | else | |
547 | return (Standard_False); | |
548 | ||
549 | } | |
550 | ||
551 | Standard_Boolean Graphic3d_Structure::IsRotated () const { | |
552 | ||
81bba717 | 553 | // A somewhat light test ! |
7fd59977 | 554 | return ( MyCStructure.Transformation[0][1] != 0. |
555 | || MyCStructure.Transformation[0][2] != 0. | |
556 | || MyCStructure.Transformation[1][0] != 0. | |
557 | || MyCStructure.Transformation[1][2] != 0. | |
558 | || MyCStructure.Transformation[2][0] != 0. | |
559 | || MyCStructure.Transformation[2][1] != 0. ); | |
560 | ||
561 | } | |
562 | ||
563 | Standard_Boolean Graphic3d_Structure::IsTransformed () const { | |
564 | ||
565 | Standard_Boolean Result = Standard_False; | |
566 | Standard_Integer i, j; | |
567 | ||
568 | for (i=0; i<=3 && ! Result; i++) | |
569 | for (j=0; j<=3 && ! Result; j++) | |
570 | if (i == j) | |
571 | Result = MyCStructure.Transformation[i][j] != 1.; | |
572 | else | |
573 | Result = MyCStructure.Transformation[i][j] != 0.; | |
574 | ||
575 | #ifdef TRACE_ISTRSF | |
81bba717 | 576 | cout << "Structure " << Identification (); |
7fd59977 | 577 | if (Result) |
81bba717 | 578 | cout << " is transformed\n" << flush; |
7fd59977 | 579 | else |
81bba717 | 580 | cout << " is not transformed\n" << flush; |
7fd59977 | 581 | #endif |
582 | ||
583 | return Result; | |
584 | ||
585 | } | |
586 | ||
587 | Standard_Boolean Graphic3d_Structure::ContainsFacet () const { | |
588 | ||
589 | if (IsDeleted ()) return (Standard_False); | |
590 | ||
81bba717 | 591 | // A structure contains at least one facet : |
592 | // if one of these groups contains at least one facet. | |
7fd59977 | 593 | |
594 | Standard_Boolean Result1 = Standard_False; | |
595 | Standard_Boolean Result2 = Standard_False; | |
596 | Standard_Integer i, Length; | |
597 | ||
598 | Result1 = (MyCStructure.ContainsFacet > 0); | |
599 | ||
81bba717 | 600 | // If one of groups contains at least one facet, the structure contains it too. |
7fd59977 | 601 | if (Result1) return (Result1); |
602 | ||
603 | Length = MyDescendants.Length (); | |
604 | ||
81bba717 | 605 | // Stop at the first descendant containing at least one facet. |
7fd59977 | 606 | for (i=1; i<=Length && ! Result2; i++) |
607 | Result2 = ((Graphic3d_Structure *) | |
608 | (MyDescendants.Value (i)))->ContainsFacet (); | |
609 | ||
610 | return (Result2); | |
611 | ||
612 | } | |
613 | ||
614 | Standard_Boolean Graphic3d_Structure::IsEmpty () const { | |
615 | ||
616 | if (IsDeleted ()) return (Standard_True); | |
617 | ||
81bba717 | 618 | // A structure is empty : |
bbf32d01 | 619 | // if all these groups are empty or if all |
81bba717 | 620 | // groups are empty and all their descendants |
621 | // are empty or if all its descendants are empty. | |
7fd59977 | 622 | |
623 | Standard_Boolean Result1 = Standard_True; | |
624 | Standard_Integer i, Length = MyGroups.Length (); | |
625 | ||
81bba717 | 626 | // Stop at the first non-empty group |
7fd59977 | 627 | for (i=1; i<=Length && Result1; i++) |
628 | Result1 = (MyGroups.Value (i))->IsEmpty (); | |
629 | ||
81bba717 | 630 | // If a group is non-empty the structure is also non-empty. |
7fd59977 | 631 | if (! Result1) return (Standard_False); |
632 | ||
633 | Standard_Boolean Result2 = Standard_True; | |
634 | ||
635 | Length = MyDescendants.Length (); | |
636 | ||
bbf32d01 | 637 | // Stop at the first non-empty descendant |
7fd59977 | 638 | for (i=1; i<=Length && Result2; i++) |
639 | Result2 = ((Graphic3d_Structure *) | |
640 | (MyDescendants.Value (i)))->IsEmpty (); | |
641 | ||
642 | return (Result2); | |
643 | ||
644 | } | |
645 | ||
646 | void Graphic3d_Structure::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const { | |
647 | ||
648 | CTXL = Line3dAspect (); | |
649 | CTXT = Text3dAspect (); | |
650 | CTXM = Marker3dAspect (); | |
651 | CTXF = FillArea3dAspect (); | |
652 | ||
653 | } | |
654 | ||
655 | void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer ADelta) { | |
656 | ||
657 | MyCStructure.ContainsFacet = MyCStructure.ContainsFacet + ADelta; | |
658 | if (MyCStructure.ContainsFacet < 0) MyCStructure.ContainsFacet = 0; | |
659 | ||
660 | #ifdef DEBUG | |
661 | cout << "MyCStructure.ContainsFacet " << MyCStructure.ContainsFacet; | |
662 | cout << endl << flush; | |
663 | #endif | |
664 | ||
665 | } | |
666 | ||
667 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ) { | |
668 | ||
669 | // Implemented by Presentation | |
670 | return this; | |
671 | } | |
672 | ||
673 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& ) { | |
674 | ||
675 | // Implemented by Presentation | |
676 | return this; | |
677 | } | |
678 | ||
679 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , Handle(Graphic3d_Structure)& ) { | |
680 | ||
681 | // Implemented by Presentation | |
682 | } | |
683 | ||
684 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , const TColStd_Array2OfReal& , Handle(Graphic3d_Structure)& ) { | |
685 | ||
686 | // Implemented by Presentation | |
687 | } | |
688 | ||
689 | void Graphic3d_Structure::ReCompute () { | |
690 | ||
691 | MyStructureManager->ReCompute (this); | |
692 | ||
693 | } | |
694 | ||
695 | void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& aProjector) { | |
696 | ||
697 | MyStructureManager->ReCompute (this, aProjector); | |
698 | ||
699 | } | |
700 | ||
701 | void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean AValue) { | |
702 | ||
703 | MyCStructure.IsInfinite = AValue ? 1:0; | |
704 | ||
705 | } | |
706 | ||
707 | Standard_Boolean Graphic3d_Structure::IsInfinite () const { | |
708 | ||
709 | if (IsDeleted ()) return (Standard_True); | |
710 | ||
711 | if (MyCStructure.IsInfinite) | |
712 | return (Standard_True); | |
713 | else | |
714 | return (Standard_False); | |
715 | ||
716 | } | |
717 | ||
5e27df78 | 718 | void Graphic3d_Structure::GraphicClear (const Standard_Boolean WithDestruction) |
719 | { | |
720 | // clean and empty each group | |
721 | Standard_Integer Length = MyGroups.Length(); | |
722 | for (Standard_Integer aGrId = 1; aGrId <= Length; ++aGrId) | |
723 | { | |
724 | MyGroups.ChangeValue (aGrId)->Clear(); | |
725 | } | |
7fd59977 | 726 | |
727 | if (WithDestruction) | |
5e27df78 | 728 | { |
7fd59977 | 729 | /* |
7fd59977 | 730 | * void Prs3d_Presentation::Clear () { |
731 | * Graphic3d_Structure::Clear (); | |
732 | * myCurrentGroup = new Graphic3d_Group (this); | |
733 | * } | |
734 | */ | |
5e27df78 | 735 | while (!MyGroups.IsEmpty()) |
736 | { | |
737 | Handle(Graphic3d_Group) aGroup = MyGroups.First(); | |
738 | aGroup->Remove(); | |
739 | } | |
7fd59977 | 740 | |
5e27df78 | 741 | MyGraphicDriver->ClearStructure (MyCStructure); |
7fd59977 | 742 | } |
7fd59977 | 743 | } |
744 | ||
745 | void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& ADaughter) { | |
746 | ||
747 | MyGraphicDriver->Connect | |
748 | (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure())); | |
749 | ||
750 | } | |
751 | ||
752 | void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& ADaughter) { | |
753 | ||
754 | MyGraphicDriver->Disconnect | |
755 | (MyCStructure, *((CALL_DEF_STRUCTURE *)ADaughter->CStructure())); | |
756 | ||
757 | } | |
758 | ||
759 | Handle(Graphic3d_AspectLine3d) Graphic3d_Structure::Line3dAspect () const { | |
760 | ||
761 | Standard_Real R, G, B; | |
762 | Standard_Real AWidth; | |
763 | Quantity_Color AColor; | |
764 | Aspect_TypeOfLine ALType; | |
765 | ||
766 | // ContextLine | |
767 | R = Standard_Real (MyCStructure.ContextLine.Color.r); | |
768 | G = Standard_Real (MyCStructure.ContextLine.Color.g); | |
769 | B = Standard_Real (MyCStructure.ContextLine.Color.b); | |
770 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
771 | ALType = Aspect_TypeOfLine (MyCStructure.ContextLine.LineType); | |
772 | AWidth = Standard_Real (MyCStructure.ContextLine.Width); | |
773 | ||
774 | Handle(Graphic3d_AspectLine3d) CTXL = | |
775 | new Graphic3d_AspectLine3d (AColor, ALType, AWidth); | |
776 | ||
777 | return CTXL; | |
778 | ||
779 | } | |
780 | ||
781 | Handle(Graphic3d_AspectText3d) Graphic3d_Structure::Text3dAspect () const { | |
782 | ||
783 | Standard_Real R, G, B; | |
784 | Standard_CString AFont; | |
785 | Standard_Real ASpace; | |
786 | Standard_Real AnExpansion; | |
787 | Quantity_Color AColor; | |
788 | Aspect_TypeOfStyleText AStyle; | |
789 | Aspect_TypeOfDisplayText ADisplayType; | |
790 | ||
791 | // ContextText | |
792 | R = Standard_Real (MyCStructure.ContextText.Color.r); | |
793 | G = Standard_Real (MyCStructure.ContextText.Color.g); | |
794 | B = Standard_Real (MyCStructure.ContextText.Color.b); | |
795 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
796 | AFont = Standard_CString (MyCStructure.ContextText.Font); | |
797 | AnExpansion = Standard_Real (MyCStructure.ContextText.Expan); | |
798 | ASpace = Standard_Real (MyCStructure.ContextText.Space); | |
799 | AStyle = Aspect_TypeOfStyleText (MyCStructure.ContextText.Style); | |
800 | ADisplayType = Aspect_TypeOfDisplayText (MyCStructure.ContextText.DisplayType); | |
801 | ||
802 | Handle(Graphic3d_AspectText3d) CTXT = | |
803 | new Graphic3d_AspectText3d (AColor, AFont, AnExpansion, ASpace,AStyle,ADisplayType); | |
804 | ||
805 | return CTXT; | |
806 | ||
807 | } | |
808 | ||
809 | Handle(Graphic3d_AspectMarker3d) Graphic3d_Structure::Marker3dAspect () const { | |
810 | ||
811 | Standard_Real R, G, B; | |
812 | Standard_Real AScale; | |
813 | Quantity_Color AColor; | |
814 | Aspect_TypeOfMarker AMType; | |
815 | ||
816 | // ContextMarker | |
817 | R = Standard_Real (MyCStructure.ContextMarker.Color.r); | |
818 | G = Standard_Real (MyCStructure.ContextMarker.Color.g); | |
819 | B = Standard_Real (MyCStructure.ContextMarker.Color.b); | |
820 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
821 | AMType = Aspect_TypeOfMarker (MyCStructure.ContextMarker.MarkerType); | |
822 | AScale = Standard_Real (MyCStructure.ContextMarker.Scale); | |
823 | ||
824 | Handle(Graphic3d_AspectMarker3d) CTXM = | |
825 | new Graphic3d_AspectMarker3d (AMType, AColor, AScale); | |
826 | ||
827 | return CTXM; | |
828 | ||
829 | } | |
830 | ||
831 | Handle(Graphic3d_AspectFillArea3d) Graphic3d_Structure::FillArea3dAspect () const { | |
832 | ||
833 | Standard_Real R, G, B; | |
834 | Standard_Real AWidth; | |
835 | Quantity_Color AColor; | |
836 | Quantity_Color AnIntColor; | |
837 | Quantity_Color AnEdgeColor; | |
838 | Aspect_TypeOfLine ALType; | |
839 | Aspect_InteriorStyle AStyle; | |
840 | Standard_Boolean EdgeOn = Standard_False; | |
841 | Graphic3d_MaterialAspect Front; | |
842 | Graphic3d_MaterialAspect Back; | |
843 | ||
844 | // ContextFillArea | |
845 | AStyle = Aspect_InteriorStyle (MyCStructure.ContextFillArea.Style); | |
846 | R = Standard_Real (MyCStructure.ContextFillArea.IntColor.r); | |
847 | G = Standard_Real (MyCStructure.ContextFillArea.IntColor.g); | |
848 | B = Standard_Real (MyCStructure.ContextFillArea.IntColor.b); | |
849 | AnIntColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
850 | // Edges | |
851 | if (MyCStructure.ContextFillArea.Edge == 1) EdgeOn = Standard_True; | |
852 | R = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.r); | |
853 | G = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.g); | |
854 | B = Standard_Real (MyCStructure.ContextFillArea.EdgeColor.b); | |
855 | AnEdgeColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
856 | ALType = Aspect_TypeOfLine (MyCStructure.ContextFillArea.LineType); | |
857 | AWidth = Standard_Real (MyCStructure.ContextFillArea.Width); | |
858 | // Back Material | |
859 | Back.SetShininess ( | |
860 | Standard_Real (MyCStructure.ContextFillArea.Back.Shininess)); | |
861 | Back.SetAmbient ( | |
862 | Standard_Real (MyCStructure.ContextFillArea.Back.Ambient)); | |
863 | Back.SetDiffuse ( | |
864 | Standard_Real (MyCStructure.ContextFillArea.Back.Diffuse)); | |
865 | Back.SetSpecular ( | |
866 | Standard_Real (MyCStructure.ContextFillArea.Back.Specular)); | |
867 | Back.SetTransparency ( | |
868 | Standard_Real (MyCStructure.ContextFillArea.Back.Transparency)); | |
869 | Back.SetEmissive ( | |
870 | Standard_Real (MyCStructure.ContextFillArea.Back.Emission)); | |
871 | if (MyCStructure.ContextFillArea.Back.IsAmbient == 1) | |
872 | Back.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); | |
873 | else | |
874 | Back.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); | |
875 | if (MyCStructure.ContextFillArea.Back.IsDiffuse == 1) | |
876 | Back.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); | |
877 | else | |
878 | Back.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); | |
879 | if (MyCStructure.ContextFillArea.Back.IsSpecular == 1) | |
880 | Back.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); | |
881 | else | |
882 | Back.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); | |
883 | if (MyCStructure.ContextFillArea.Back.IsEmission == 1) | |
884 | Back.SetReflectionModeOn (Graphic3d_TOR_EMISSION); | |
885 | else | |
886 | Back.SetReflectionModeOff (Graphic3d_TOR_EMISSION); | |
887 | ||
888 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.r); | |
889 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.g); | |
890 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorSpec.b); | |
891 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
892 | Back.SetSpecularColor (AColor); | |
893 | ||
894 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.r); | |
895 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.g); | |
896 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorAmb.b); | |
897 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
898 | Back.SetAmbientColor (AColor); | |
899 | ||
900 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.r); | |
901 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.g); | |
902 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorDif.b); | |
903 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
904 | Back.SetDiffuseColor (AColor); | |
905 | ||
906 | R = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.r); | |
907 | G = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.g); | |
908 | B = Standard_Real (MyCStructure.ContextFillArea.Back.ColorEms.b); | |
909 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
910 | Back.SetEmissiveColor (AColor); | |
911 | ||
912 | Back.SetEnvReflexion (MyCStructure.ContextFillArea.Back.EnvReflexion); | |
913 | ||
bbf32d01 K |
914 | Graphic3d_TypeOfMaterial mType = |
915 | MyCStructure.ContextFillArea.Back.IsPhysic ? | |
7fd59977 | 916 | Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT; |
917 | Back.SetMaterialType(mType); | |
918 | ||
919 | // Front Material | |
920 | Front.SetShininess ( | |
921 | Standard_Real (MyCStructure.ContextFillArea.Front.Shininess)); | |
922 | Front.SetAmbient ( | |
923 | Standard_Real (MyCStructure.ContextFillArea.Front.Ambient)); | |
924 | Front.SetDiffuse ( | |
925 | Standard_Real (MyCStructure.ContextFillArea.Front.Diffuse)); | |
926 | Front.SetSpecular ( | |
927 | Standard_Real (MyCStructure.ContextFillArea.Front.Specular)); | |
928 | Front.SetTransparency ( | |
929 | Standard_Real (MyCStructure.ContextFillArea.Front.Transparency)); | |
930 | Front.SetEmissive ( | |
931 | Standard_Real (MyCStructure.ContextFillArea.Front.Emission)); | |
932 | if (MyCStructure.ContextFillArea.Front.IsAmbient == 1) | |
933 | Front.SetReflectionModeOn (Graphic3d_TOR_AMBIENT); | |
934 | else | |
935 | Front.SetReflectionModeOff (Graphic3d_TOR_AMBIENT); | |
936 | if (MyCStructure.ContextFillArea.Front.IsDiffuse == 1) | |
937 | Front.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE); | |
938 | else | |
939 | Front.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE); | |
940 | if (MyCStructure.ContextFillArea.Front.IsSpecular == 1) | |
941 | Front.SetReflectionModeOn (Graphic3d_TOR_SPECULAR); | |
942 | else | |
943 | Front.SetReflectionModeOff (Graphic3d_TOR_SPECULAR); | |
944 | if (MyCStructure.ContextFillArea.Front.Emission == 1) | |
945 | Front.SetReflectionModeOn (Graphic3d_TOR_EMISSION); | |
946 | else | |
947 | Front.SetReflectionModeOff (Graphic3d_TOR_EMISSION); | |
948 | ||
949 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.r); | |
950 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.g); | |
951 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorSpec.b); | |
952 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
953 | Front.SetSpecularColor (AColor); | |
954 | ||
955 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.r); | |
956 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.g); | |
957 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorAmb.b); | |
958 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
959 | Front.SetAmbientColor (AColor); | |
960 | ||
961 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.r); | |
962 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.g); | |
963 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorDif.b); | |
964 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
965 | Front.SetDiffuseColor (AColor); | |
966 | ||
967 | R = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.r); | |
968 | G = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.g); | |
969 | B = Standard_Real (MyCStructure.ContextFillArea.Front.ColorEms.b); | |
970 | AColor.SetValues (R, G, B, Quantity_TOC_RGB); | |
971 | Front.SetEmissiveColor (AColor); | |
972 | ||
973 | Front.SetEnvReflexion (MyCStructure.ContextFillArea.Front.EnvReflexion); | |
974 | ||
975 | mType = MyCStructure.ContextFillArea.Front.IsPhysic ? Graphic3d_MATERIAL_PHYSIC : Graphic3d_MATERIAL_ASPECT; | |
976 | Front.SetMaterialType(mType); | |
977 | ||
978 | Handle(Graphic3d_AspectFillArea3d) CTXF = | |
979 | new Graphic3d_AspectFillArea3d (AStyle, AnIntColor, AnEdgeColor, ALType, AWidth, Front, Back); | |
980 | ||
981 | // Edges | |
982 | if (EdgeOn) | |
983 | CTXF->SetEdgeOn (); | |
984 | else | |
985 | CTXF->SetEdgeOff (); | |
986 | // Hatch | |
987 | CTXF->SetHatchStyle(Aspect_HatchStyle (MyCStructure.ContextFillArea.Hatch)); | |
988 | // Materials | |
989 | // Front and Back face | |
990 | if (MyCStructure.ContextFillArea.Distinguish == 1) | |
991 | CTXF->SetDistinguishOn (); | |
992 | else | |
993 | CTXF->SetDistinguishOff (); | |
994 | if (MyCStructure.ContextFillArea.BackFace == 1) | |
995 | CTXF->SuppressBackFace (); | |
996 | else | |
997 | CTXF->AllowBackFace (); | |
998 | // Texture | |
999 | // Pb sur les textures | |
1000 | //if (MyCStructure.ContextFillArea.Texture.TexId == -1) | |
1001 | //else | |
1002 | if (MyCStructure.ContextFillArea.Texture.doTextureMap == 1) | |
1003 | CTXF->SetTextureMapOn (); | |
1004 | else | |
1005 | CTXF->SetTextureMapOff (); | |
1006 | #ifdef G003 | |
1007 | Aspect_TypeOfDegenerateModel dMode = Aspect_TypeOfDegenerateModel( | |
bbf32d01 | 1008 | MyCStructure.ContextFillArea.DegenerationMode); |
7fd59977 | 1009 | Quantity_Ratio dRatio = |
1010 | MyCStructure.ContextFillArea.SkipRatio; | |
1011 | CTXF->SetDegenerateModel(dMode,dRatio); | |
1012 | #endif // G003 | |
1013 | ||
bbf32d01 K |
1014 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
1015 | CTXF->SetPolygonOffsets(MyCStructure.ContextFillArea.PolygonOffsetMode, | |
7fd59977 | 1016 | MyCStructure.ContextFillArea.PolygonOffsetFactor, |
1017 | MyCStructure.ContextFillArea.PolygonOffsetUnits); | |
bbf32d01 | 1018 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 1019 | |
1020 | return CTXF; | |
1021 | ||
1022 | } | |
1023 | ||
bbf32d01 K |
1024 | const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const { |
1025 | return MyGroups; | |
7fd59977 | 1026 | } |
1027 | ||
1028 | Standard_Integer Graphic3d_Structure::NumberOfGroups () const { | |
7fd59977 | 1029 | return (MyGroups.Length ()); |
7fd59977 | 1030 | } |
1031 | ||
1032 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) { | |
1033 | ||
1034 | if (IsDeleted ()) return; | |
1035 | ||
1036 | Standard_Real R, G, B; | |
1037 | Standard_Real AWidth; | |
1038 | Quantity_Color AColor; | |
1039 | Aspect_TypeOfLine ALType; | |
1040 | ||
1041 | CTX->Values (AColor, ALType, AWidth); | |
1042 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
1043 | ||
1044 | MyCStructure.ContextLine.Color.r = float (R); | |
1045 | MyCStructure.ContextLine.Color.g = float (G); | |
1046 | MyCStructure.ContextLine.Color.b = float (B); | |
1047 | MyCStructure.ContextLine.LineType = int (ALType); | |
1048 | MyCStructure.ContextLine.Width = float (AWidth); | |
1049 | MyCStructure.ContextLine.IsDef = 1; | |
1050 | ||
1051 | MyGraphicDriver->ContextStructure (MyCStructure); | |
1052 | ||
1053 | // CAL 14/04/95 | |
bbf32d01 K |
1054 | // Attributes are "IsSet" during the first update |
1055 | // of context (line, marker...) | |
7fd59977 | 1056 | MyCStructure.ContextLine.IsSet = 1; |
1057 | MyCStructure.ContextFillArea.IsSet = 1; | |
1058 | MyCStructure.ContextMarker.IsSet = 1; | |
1059 | MyCStructure.ContextText.IsSet = 1; | |
1060 | ||
1061 | Update (); | |
1062 | ||
1063 | } | |
1064 | ||
1065 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) { | |
1066 | ||
1067 | if (IsDeleted ()) return; | |
1068 | ||
1069 | Standard_Real R, G, B; | |
1070 | Standard_Real AWidth; | |
1071 | Quantity_Color AnIntColor; | |
1072 | Quantity_Color BackIntColor; | |
1073 | Quantity_Color AnEdgeColor; | |
1074 | Aspect_TypeOfLine ALType; | |
1075 | Aspect_InteriorStyle AStyle; | |
1076 | ||
1077 | CTX->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth); | |
1078 | AnIntColor.Values (R, G, B, Quantity_TOC_RGB); | |
1079 | ||
1080 | MyCStructure.ContextFillArea.Style = int (AStyle); | |
1081 | MyCStructure.ContextFillArea.IntColor.r = float (R); | |
1082 | MyCStructure.ContextFillArea.IntColor.g = float (G); | |
1083 | MyCStructure.ContextFillArea.IntColor.b = float (B); | |
1084 | ||
1085 | #ifdef OCC1174 | |
1086 | if ( CTX->Distinguish() ) | |
1087 | BackIntColor.Values( R, G, B, Quantity_TOC_RGB ); | |
1088 | #endif | |
1089 | MyCStructure.ContextFillArea.BackIntColor.r = float( R ); | |
1090 | MyCStructure.ContextFillArea.BackIntColor.g = float( G ); | |
1091 | MyCStructure.ContextFillArea.BackIntColor.b = float( B ); | |
1092 | ||
1093 | ||
1094 | // Edges | |
1095 | MyCStructure.ContextFillArea.Edge = CTX->Edge () ? 1:0; | |
1096 | AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB); | |
1097 | MyCStructure.ContextFillArea.EdgeColor.r = float (R); | |
1098 | MyCStructure.ContextFillArea.EdgeColor.g = float (G); | |
1099 | MyCStructure.ContextFillArea.EdgeColor.b = float (B); | |
1100 | MyCStructure.ContextFillArea.LineType = int (ALType); | |
1101 | MyCStructure.ContextFillArea.Width = float (AWidth); | |
1102 | MyCStructure.ContextFillArea.Hatch = int (CTX->HatchStyle ()); | |
1103 | #ifdef G003 | |
1104 | Quantity_Ratio ratio; | |
bbf32d01 | 1105 | MyCStructure.ContextFillArea.DegenerationMode = |
7fd59977 | 1106 | int (CTX->DegenerateModel(ratio)); |
1107 | MyCStructure.ContextFillArea.SkipRatio = float (ratio); | |
1108 | #endif // G003 | |
1109 | ||
1110 | /*** Front and Back face ***/ | |
1111 | MyCStructure.ContextFillArea.Distinguish = CTX->Distinguish () ? 1:0; | |
1112 | MyCStructure.ContextFillArea.BackFace = CTX->BackFace () ? 1:0; | |
1113 | ||
1114 | /*** Back Material ***/ | |
1115 | // Light specificity | |
1116 | MyCStructure.ContextFillArea.Back.Shininess = | |
1117 | float ((CTX->BackMaterial ()).Shininess ()); | |
1118 | MyCStructure.ContextFillArea.Back.Ambient = | |
1119 | float ((CTX->BackMaterial ()).Ambient ()); | |
1120 | MyCStructure.ContextFillArea.Back.Diffuse = | |
1121 | float ((CTX->BackMaterial ()).Diffuse ()); | |
1122 | MyCStructure.ContextFillArea.Back.Specular = | |
1123 | float ((CTX->BackMaterial ()).Specular ()); | |
1124 | MyCStructure.ContextFillArea.Back.Transparency = | |
1125 | float ((CTX->BackMaterial ()).Transparency ()); | |
1126 | MyCStructure.ContextFillArea.Back.Emission = | |
1127 | float ((CTX->BackMaterial ()).Emissive ()); | |
1128 | ||
1129 | // Reflection mode | |
1130 | MyCStructure.ContextFillArea.Back.IsAmbient = | |
1131 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); | |
1132 | MyCStructure.ContextFillArea.Back.IsDiffuse = | |
1133 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); | |
1134 | MyCStructure.ContextFillArea.Back.IsSpecular = | |
1135 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); | |
1136 | MyCStructure.ContextFillArea.Back.IsEmission = | |
1137 | ( (CTX->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); | |
1138 | ||
1139 | // Material type | |
1140 | //JR/Hp | |
1141 | const Graphic3d_MaterialAspect ama = CTX->BackMaterial () ; | |
1142 | Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; | |
1143 | MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 ); | |
1144 | ||
bbf32d01 | 1145 | // Specular Color |
7fd59977 | 1146 | MyCStructure.ContextFillArea.Back.ColorSpec.r = |
1147 | float (((CTX->BackMaterial ()).SpecularColor ()).Red ()); | |
1148 | MyCStructure.ContextFillArea.Back.ColorSpec.g = | |
1149 | float (((CTX->BackMaterial ()).SpecularColor ()).Green ()); | |
1150 | MyCStructure.ContextFillArea.Back.ColorSpec.b = | |
1151 | float (((CTX->BackMaterial ()).SpecularColor ()).Blue ()); | |
1152 | ||
1153 | // Ambient color | |
1154 | MyCStructure.ContextFillArea.Back.ColorAmb.r = | |
1155 | float (((CTX->BackMaterial ()).AmbientColor ()).Red ()); | |
1156 | MyCStructure.ContextFillArea.Back.ColorAmb.g = | |
1157 | float (((CTX->BackMaterial ()).AmbientColor ()).Green ()); | |
1158 | MyCStructure.ContextFillArea.Back.ColorAmb.b = | |
1159 | float (((CTX->BackMaterial ()).AmbientColor ()).Blue ()); | |
1160 | ||
1161 | // Diffuse color | |
1162 | MyCStructure.ContextFillArea.Back.ColorDif.r = | |
1163 | float (((CTX->BackMaterial ()).DiffuseColor ()).Red ()); | |
1164 | MyCStructure.ContextFillArea.Back.ColorDif.g = | |
1165 | float (((CTX->BackMaterial ()).DiffuseColor ()).Green ()); | |
1166 | MyCStructure.ContextFillArea.Back.ColorDif.b = | |
1167 | float (((CTX->BackMaterial ()).DiffuseColor ()).Blue ()); | |
1168 | ||
1169 | // Emissive color | |
1170 | MyCStructure.ContextFillArea.Back.ColorEms.r = | |
1171 | float (((CTX->BackMaterial ()).EmissiveColor ()).Red ()); | |
1172 | MyCStructure.ContextFillArea.Back.ColorEms.g = | |
1173 | float (((CTX->BackMaterial ()).EmissiveColor ()).Green ()); | |
1174 | MyCStructure.ContextFillArea.Back.ColorEms.b = | |
1175 | float (((CTX->BackMaterial ()).EmissiveColor ()).Blue ()); | |
1176 | ||
bbf32d01 | 1177 | MyCStructure.ContextFillArea.Back.EnvReflexion = |
7fd59977 | 1178 | float ((CTX->BackMaterial ()).EnvReflexion()); |
1179 | ||
1180 | /*** Front Material ***/ | |
1181 | // Light specificity | |
1182 | MyCStructure.ContextFillArea.Front.Shininess = | |
1183 | float ((CTX->FrontMaterial ()).Shininess ()); | |
1184 | MyCStructure.ContextFillArea.Front.Ambient = | |
1185 | float ((CTX->FrontMaterial ()).Ambient ()); | |
1186 | MyCStructure.ContextFillArea.Front.Diffuse = | |
1187 | float ((CTX->FrontMaterial ()).Diffuse ()); | |
1188 | MyCStructure.ContextFillArea.Front.Specular = | |
1189 | float ((CTX->FrontMaterial ()).Specular ()); | |
1190 | MyCStructure.ContextFillArea.Front.Transparency = | |
1191 | float ((CTX->FrontMaterial ()).Transparency ()); | |
1192 | MyCStructure.ContextFillArea.Front.Emission = | |
1193 | float ((CTX->FrontMaterial ()).Emissive ()); | |
1194 | ||
1195 | // Reflection mode | |
1196 | MyCStructure.ContextFillArea.Front.IsAmbient = | |
1197 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); | |
1198 | MyCStructure.ContextFillArea.Front.IsDiffuse = | |
1199 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); | |
1200 | MyCStructure.ContextFillArea.Front.IsSpecular = | |
1201 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); | |
1202 | MyCStructure.ContextFillArea.Front.IsEmission = | |
1203 | ( (CTX->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); | |
1204 | ||
1205 | // Materail type | |
1206 | //JR/Hp | |
1207 | const Graphic3d_MaterialAspect amas = CTX->FrontMaterial () ; | |
1208 | Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; | |
1209 | MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 ); | |
1210 | ||
1211 | // Specular Color | |
1212 | MyCStructure.ContextFillArea.Front.ColorSpec.r = | |
1213 | float (((CTX->FrontMaterial ()).SpecularColor ()).Red ()); | |
1214 | MyCStructure.ContextFillArea.Front.ColorSpec.g = | |
1215 | float (((CTX->FrontMaterial ()).SpecularColor ()).Green ()); | |
1216 | MyCStructure.ContextFillArea.Front.ColorSpec.b = | |
1217 | float (((CTX->FrontMaterial ()).SpecularColor ()).Blue ()); | |
1218 | ||
1219 | // Ambient color | |
1220 | MyCStructure.ContextFillArea.Front.ColorAmb.r = | |
1221 | float (((CTX->FrontMaterial ()).AmbientColor ()).Red ()); | |
1222 | MyCStructure.ContextFillArea.Front.ColorAmb.g = | |
1223 | float (((CTX->FrontMaterial ()).AmbientColor ()).Green ()); | |
1224 | MyCStructure.ContextFillArea.Front.ColorAmb.b = | |
1225 | float (((CTX->FrontMaterial ()).AmbientColor ()).Blue ()); | |
1226 | ||
1227 | // Diffuse color | |
1228 | MyCStructure.ContextFillArea.Front.ColorDif.r = | |
1229 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Red ()); | |
1230 | MyCStructure.ContextFillArea.Front.ColorDif.g = | |
1231 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Green ()); | |
1232 | MyCStructure.ContextFillArea.Front.ColorDif.b = | |
1233 | float (((CTX->FrontMaterial ()).DiffuseColor ()).Blue ()); | |
1234 | ||
1235 | // Emissive color | |
1236 | MyCStructure.ContextFillArea.Front.ColorEms.r = | |
1237 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Red ()); | |
1238 | MyCStructure.ContextFillArea.Front.ColorEms.g = | |
1239 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Green ()); | |
1240 | MyCStructure.ContextFillArea.Front.ColorEms.b = | |
1241 | float (((CTX->FrontMaterial ()).EmissiveColor ()).Blue ()); | |
1242 | ||
bbf32d01 | 1243 | MyCStructure.ContextFillArea.Front.EnvReflexion = |
7fd59977 | 1244 | float ((CTX->FrontMaterial ()).EnvReflexion()); |
1245 | ||
1246 | MyCStructure.ContextFillArea.IsDef = 1; // Definition material ok | |
1247 | ||
1248 | Handle(Graphic3d_TextureMap) TempTextureMap = CTX->TextureMap(); | |
1249 | if (! TempTextureMap.IsNull() ) | |
1250 | MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId(); | |
1251 | else | |
1252 | MyCStructure.ContextFillArea.Texture.TexId = -1; | |
1253 | ||
1254 | MyCStructure.ContextFillArea.Texture.doTextureMap = CTX->TextureMapState() ? 1:0; | |
1255 | ||
bbf32d01 | 1256 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 1257 | Standard_Integer aPolyMode; |
60be1f9b | 1258 | Standard_ShortReal aPolyFactor, aPolyUnits; |
7fd59977 | 1259 | CTX->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits); |
1260 | MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode; | |
1261 | MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor; | |
1262 | MyCStructure.ContextFillArea.PolygonOffsetUnits = aPolyUnits; | |
bbf32d01 | 1263 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 1264 | |
1265 | MyGraphicDriver->ContextStructure (MyCStructure); | |
1266 | #ifdef G003 | |
1267 | MyGraphicDriver -> DegenerateStructure (MyCStructure); | |
1268 | #endif | |
1269 | ||
1270 | // CAL 14/04/95 | |
81bba717 | 1271 | // Attributes are "IsSet" during the first update |
1272 | // of context (line, marker...) | |
7fd59977 | 1273 | MyCStructure.ContextLine.IsSet = 1; |
1274 | MyCStructure.ContextFillArea.IsSet = 1; | |
1275 | MyCStructure.ContextMarker.IsSet = 1; | |
1276 | MyCStructure.ContextText.IsSet = 1; | |
1277 | ||
1278 | Update (); | |
1279 | ||
1280 | } | |
1281 | ||
1282 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) { | |
1283 | ||
1284 | if (IsDeleted ()) return; | |
1285 | ||
1286 | Standard_Real R, G, B; | |
1287 | Standard_Real Rs, Gs, Bs; | |
1288 | Standard_CString AFont; | |
1289 | Standard_Real ASpace; | |
1290 | Standard_Real AnExpansion; | |
1291 | Quantity_Color AColor; | |
1292 | Aspect_TypeOfStyleText AStyle; | |
1293 | Aspect_TypeOfDisplayText ADisplayType; | |
1294 | Quantity_Color AColorSubTitle; | |
1295 | Standard_Boolean ATextZoomable; | |
1296 | Standard_Real ATextAngle; | |
1297 | OSD_FontAspect ATextFontAspect; | |
1298 | ||
1299 | CTX->Values (AColor, AFont, AnExpansion, ASpace, AStyle, ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect); | |
1300 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
1301 | AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB); | |
1302 | ||
1303 | MyCStructure.ContextText.Color.r = float (R); | |
1304 | MyCStructure.ContextText.Color.g = float (G); | |
1305 | MyCStructure.ContextText.Color.b = float (B); | |
1306 | MyCStructure.ContextText.Font = (char*) (AFont); | |
1307 | MyCStructure.ContextText.Expan = float (AnExpansion); | |
1308 | MyCStructure.ContextText.Space = float (ASpace); | |
1309 | MyCStructure.ContextText.Style = int (AStyle); | |
1310 | MyCStructure.ContextText.DisplayType = int (ADisplayType); | |
1311 | MyCStructure.ContextText.ColorSubTitle.r = float (Rs); | |
1312 | MyCStructure.ContextText.ColorSubTitle.g = float (Gs); | |
1313 | MyCStructure.ContextText.ColorSubTitle.b = float (Bs); | |
bbf32d01 | 1314 | MyCStructure.ContextText.TextZoomable = ATextZoomable; |
60be1f9b | 1315 | MyCStructure.ContextText.TextAngle = float (ATextAngle); |
bbf32d01 | 1316 | MyCStructure.ContextText.TextFontAspect = (int)ATextFontAspect; |
7fd59977 | 1317 | |
1318 | MyCStructure.ContextText.IsDef = 1; | |
1319 | ||
1320 | MyGraphicDriver->ContextStructure (MyCStructure); | |
1321 | ||
1322 | // CAL 14/04/95 | |
81bba717 | 1323 | // Attributes are "IsSet" during the first update of a context (line, marker...) |
7fd59977 | 1324 | MyCStructure.ContextLine.IsSet = 1; |
1325 | MyCStructure.ContextFillArea.IsSet = 1; | |
1326 | MyCStructure.ContextMarker.IsSet = 1; | |
1327 | MyCStructure.ContextText.IsSet = 1; | |
1328 | ||
1329 | Update (); | |
1330 | ||
1331 | } | |
1332 | ||
1333 | void Graphic3d_Structure::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) { | |
1334 | ||
1335 | if (IsDeleted ()) return; | |
1336 | ||
1337 | Standard_Real R, G, B; | |
1338 | Standard_Real AScale; | |
1339 | Quantity_Color AColor; | |
1340 | Aspect_TypeOfMarker AMType; | |
1341 | ||
1342 | CTX->Values (AColor, AMType, AScale); | |
1343 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
1344 | ||
1345 | MyCStructure.ContextMarker.Color.r = float (R); | |
1346 | MyCStructure.ContextMarker.Color.g = float (G); | |
1347 | MyCStructure.ContextMarker.Color.b = float (B); | |
1348 | MyCStructure.ContextMarker.MarkerType = int (AMType); | |
1349 | MyCStructure.ContextMarker.Scale = float (AScale); | |
1350 | MyCStructure.ContextMarker.IsDef = 1; | |
1351 | ||
1352 | MyGraphicDriver->ContextStructure (MyCStructure); | |
1353 | ||
81bba717 | 1354 | // Attributes are "IsSet" during the first update of a context (line, marker...) |
7fd59977 | 1355 | MyCStructure.ContextLine.IsSet = 1; |
1356 | MyCStructure.ContextFillArea.IsSet = 1; | |
1357 | MyCStructure.ContextMarker.IsSet = 1; | |
1358 | MyCStructure.ContextText.IsSet = 1; | |
1359 | ||
1360 | Update (); | |
1361 | ||
1362 | } | |
1363 | ||
1364 | void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure AVisual) { | |
1365 | ||
1366 | if (IsDeleted ()) return; | |
1367 | if (MyVisual == AVisual) return; | |
1368 | ||
1369 | if (! MyCStructure.stick) { | |
1370 | MyVisual = AVisual; | |
1371 | SetComputeVisual (AVisual); | |
1372 | } | |
1373 | else { | |
1374 | ||
1375 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); | |
1376 | if (UpdateMode == Aspect_TOU_WAIT) { | |
1377 | Erase (); | |
1378 | MyVisual = AVisual; | |
1379 | SetComputeVisual (AVisual); | |
1380 | Display (); | |
1381 | } | |
1382 | else { | |
81bba717 | 1383 | // To avoid calling method : Update () |
1384 | // Not useful and can be costly. | |
7fd59977 | 1385 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
1386 | Erase (); | |
1387 | MyVisual = AVisual; | |
1388 | SetComputeVisual (AVisual); | |
1389 | MyStructureManager->SetUpdateMode (UpdateMode); | |
1390 | Display (); | |
1391 | } | |
1392 | } | |
1393 | ||
1394 | } | |
1395 | ||
1396 | void Graphic3d_Structure::SetZoomLimit (const Standard_Real LimitInf, const Standard_Real LimitSup) { | |
1397 | ||
1398 | if (LimitInf <= 0.0) | |
1399 | Graphic3d_StructureDefinitionError::Raise | |
1400 | ("Bad value for ZoomLimit inf"); | |
1401 | ||
1402 | if (LimitSup <= 0.0) | |
1403 | Graphic3d_StructureDefinitionError::Raise | |
1404 | ("Bad value for ZoomLimit sup"); | |
1405 | ||
1406 | if (LimitSup < LimitInf) | |
1407 | Graphic3d_StructureDefinitionError::Raise | |
1408 | ("ZoomLimit sup < ZoomLimit inf"); | |
1409 | ||
1410 | } | |
1411 | ||
1412 | Graphic3d_TypeOfStructure Graphic3d_Structure::Visual () const { | |
1413 | ||
1414 | return (MyVisual); | |
1415 | ||
1416 | } | |
1417 | ||
1418 | Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& AStructure1, const Handle(Graphic3d_Structure)& AStructure2, const Graphic3d_TypeOfConnection AType) { | |
1419 | ||
1420 | Graphic3d_MapOfStructure ASet; | |
1421 | ||
1422 | // cycle detection | |
1423 | Graphic3d_Structure::Network (AStructure2, AType, ASet); | |
1424 | ||
1425 | return (! ASet.Contains (AStructure1)); | |
1426 | ||
1427 | } | |
1428 | ||
1429 | void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure &SG) const { | |
1430 | ||
1431 | Standard_Integer i, Length = MyAncestors.Length (); | |
1432 | ||
1433 | for (i=1; i<=Length; i++) | |
1434 | SG.Add ((Graphic3d_Structure *) (MyAncestors.Value (i))); | |
1435 | ||
1436 | ||
1437 | } | |
1438 | ||
1439 | void Graphic3d_Structure::SetOwner (const Standard_Address Owner) { | |
1440 | ||
1441 | MyOwner = Owner; | |
1442 | ||
1443 | } | |
1444 | ||
1445 | Standard_Address Graphic3d_Structure::Owner () const { | |
1446 | ||
1447 | return MyOwner; | |
1448 | ||
1449 | } | |
1450 | ||
1451 | void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& SG) const { | |
1452 | ||
1453 | Standard_Integer i, Length = MyDescendants.Length (); | |
1454 | ||
1455 | for (i=1; i<=Length; i++) | |
1456 | SG.Add ((Graphic3d_Structure *) (MyDescendants.Value (i))); | |
1457 | ||
1458 | } | |
1459 | ||
1460 | void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, const Standard_Boolean WithCheck) { | |
1461 | ||
1462 | if (IsDeleted ()) return; | |
1463 | ||
1464 | if (WithCheck) | |
1465 | // cycle detection | |
1466 | if (! Graphic3d_Structure::AcceptConnection | |
1467 | (this, AStructure, AType)) | |
1468 | return; | |
1469 | ||
1470 | // connection | |
1471 | Standard_Integer i; | |
bbf32d01 | 1472 | switch (AType) |
7fd59977 | 1473 | { |
1474 | ||
bbf32d01 | 1475 | case Graphic3d_TOC_DESCENDANT : |
7fd59977 | 1476 | { |
1477 | Standard_Integer indexD = 0; | |
1478 | Standard_Integer LengthD = MyDescendants.Length (); | |
1479 | for (i=1; i<=LengthD && indexD==0; i++) | |
1480 | if ((void *) (MyDescendants.Value (i)) == | |
1481 | (void *) (AStructure.operator->())) indexD = i; | |
1482 | ||
1483 | if (indexD == 0) { | |
1484 | MyDescendants.Append ((void *) AStructure.operator->()); | |
1485 | AStructure->Connect (this, Graphic3d_TOC_ANCESTOR); | |
1486 | ||
1487 | GraphicConnect (AStructure); | |
1488 | MyStructureManager->Connect (this, AStructure); | |
1489 | ||
1490 | Update (); | |
1491 | } | |
1492 | } | |
1493 | break; | |
1494 | ||
bbf32d01 | 1495 | case Graphic3d_TOC_ANCESTOR : |
7fd59977 | 1496 | { |
1497 | Standard_Integer indexA = 0; | |
1498 | Standard_Integer LengthA = MyAncestors.Length (); | |
1499 | for (i=1; i<=LengthA && indexA==0; i++) | |
1500 | if ((void *) (MyAncestors.Value (i)) == | |
1501 | (void *) (AStructure.operator->())) indexA = i; | |
1502 | ||
1503 | if (indexA == 0) { | |
1504 | MyAncestors.Append ((void *) AStructure.operator->()); | |
1505 | AStructure->Connect (this, Graphic3d_TOC_DESCENDANT); | |
1506 | ||
81bba717 | 1507 | // MyGraphicDriver->Connect is called in case |
1508 | // if connection between parent and child | |
7fd59977 | 1509 | } |
1510 | } | |
1511 | break; | |
1512 | } | |
1513 | ||
1514 | } | |
1515 | ||
1516 | void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& AStructure) { | |
1517 | ||
1518 | if (IsDeleted ()) return; | |
1519 | ||
1520 | Standard_Integer i; | |
1521 | ||
1522 | Standard_Integer indexD = 0; | |
1523 | Standard_Integer LengthD = MyDescendants.Length (); | |
1524 | for (i=1; i<=LengthD && indexD==0; i++) | |
1525 | if ((void *) (MyDescendants.Value (i)) == | |
1526 | (void *) (AStructure.operator->())) indexD = i; | |
1527 | ||
81bba717 | 1528 | // Search in the Descendants |
7fd59977 | 1529 | if (indexD != 0) { |
1530 | MyDescendants.Remove (indexD); | |
1531 | AStructure->Disconnect (this); | |
1532 | ||
1533 | GraphicDisconnect (AStructure); | |
1534 | MyStructureManager->Disconnect (this, AStructure); | |
1535 | ||
1536 | Update (); | |
1537 | } | |
1538 | else { | |
1539 | Standard_Integer indexA = 0; | |
1540 | Standard_Integer LengthA = MyAncestors.Length (); | |
1541 | for (i=1; i<=LengthA && indexA==0; i++) | |
1542 | if ((void *) (MyAncestors.Value (i)) == | |
1543 | (void *) (AStructure.operator->())) indexA = i; | |
1544 | ||
81bba717 | 1545 | // Search in the Ancestors |
7fd59977 | 1546 | if (indexA != 0) { |
1547 | MyAncestors.Remove (indexA); | |
1548 | AStructure->Disconnect (this); | |
1549 | ||
81bba717 | 1550 | // No call of MyGraphicDriver->Disconnect |
1551 | // in case of an ancestor | |
7fd59977 | 1552 | } |
1553 | } | |
1554 | ||
1555 | } | |
1556 | ||
1557 | void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection AType) { | |
1558 | ||
1559 | if (IsDeleted ()) return; | |
1560 | ||
1561 | Standard_Integer i, Length; | |
1562 | ||
1563 | // disconnection | |
bbf32d01 | 1564 | switch (AType) |
7fd59977 | 1565 | { |
1566 | case Graphic3d_TOC_DESCENDANT : | |
1567 | Length = MyDescendants.Length (); | |
1568 | for (i=1; i<=Length; i++) | |
81bba717 | 1569 | // Value (1) instead of Value (i) as MyDescendants |
1570 | // is modified by : | |
7fd59977 | 1571 | // Graphic3d_Structure::Disconnect (AStructure) |
81bba717 | 1572 | // that takes AStructure from MyDescendants |
7fd59977 | 1573 | ((Graphic3d_Structure *) |
1574 | (MyDescendants.Value (1)))->Disconnect (this); | |
1575 | break; | |
1576 | case Graphic3d_TOC_ANCESTOR : | |
1577 | Length = MyAncestors.Length (); | |
1578 | for (i=1; i<=Length; i++) | |
bbf32d01 | 1579 | // Value (1) instead of Value (i) as MyAncestors |
81bba717 | 1580 | // is modified by : |
7fd59977 | 1581 | // Graphic3d_Structure::Disconnect (AStructure) |
81bba717 | 1582 | // that takes AStructure from MyAncestors |
7fd59977 | 1583 | ((Graphic3d_Structure *) |
1584 | (MyAncestors.Value (1)))->Disconnect (this); | |
1585 | break; | |
1586 | } | |
1587 | ||
1588 | } | |
1589 | ||
1590 | Graphic3d_TypeOfComposition Graphic3d_Structure::Composition () const { | |
1591 | ||
1592 | if (MyCStructure.Composition) | |
1593 | return (Graphic3d_TOC_POSTCONCATENATE); | |
1594 | else | |
1595 | return (Graphic3d_TOC_REPLACE); | |
1596 | ||
1597 | } | |
1598 | ||
1599 | void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& AMatrix, const Graphic3d_TypeOfComposition AType) { | |
1600 | ||
1601 | if (IsDeleted ()) return; | |
1602 | ||
1603 | Standard_Integer lr, ur, lc, uc; | |
1604 | Standard_Real valuetrsf; | |
1605 | Standard_Real valueoldtrsf; | |
1606 | Standard_Real valuenewtrsf; | |
1607 | Standard_Integer i, j, k; | |
1608 | TColStd_Array2OfReal TheTrsf (0, 3, 0, 3); | |
1609 | TColStd_Array2OfReal NewTrsf (0, 3, 0, 3); | |
1610 | TColStd_Array2OfReal AMatrix44 (0, 3, 0, 3); | |
1611 | ||
1612 | // Assign the new transformation in an array [0..3][0..3] | |
81bba717 | 1613 | // Avoid problemes if the user has defined matrice [1..4][1..4] |
bbf32d01 | 1614 | // or [3..6][-1..2] !! |
7fd59977 | 1615 | lr = AMatrix.LowerRow (); |
1616 | ur = AMatrix.UpperRow (); | |
1617 | lc = AMatrix.LowerCol (); | |
1618 | uc = AMatrix.UpperCol (); | |
1619 | ||
1620 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) | |
1621 | Graphic3d_TransformError::Raise | |
1622 | ("Transform : not a 4x4 matrix"); | |
1623 | ||
1624 | if (AType == Graphic3d_TOC_REPLACE) { | |
1625 | MyCStructure.Composition = 0; | |
81bba717 | 1626 | // Update of CStructure |
7fd59977 | 1627 | for (i=0; i<=3; i++) |
1628 | for (j=0; j<=3; j++) { | |
1629 | MyCStructure.Transformation[i][j] = | |
1630 | float (AMatrix (lr + i, lc + j)); | |
1631 | NewTrsf (i, j) = AMatrix (lr + i, lc + j); | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | if (AType == Graphic3d_TOC_POSTCONCATENATE) { | |
1636 | MyCStructure.Composition = 1; | |
81bba717 | 1637 | // To simplify management of indices |
7fd59977 | 1638 | for (i=0; i<=3; i++) |
1639 | for (j=0; j<=3; j++) | |
1640 | AMatrix44 (i, j) = AMatrix (lr + i, lc + j); | |
81bba717 | 1641 | // Calculation of the product of matrices |
7fd59977 | 1642 | for (i=0; i<=3; i++) |
1643 | for (j=0; j<=3; j++) { | |
1644 | NewTrsf (i, j) = 0.0; | |
1645 | for (k=0; k<=3; k++) { | |
1646 | valueoldtrsf = MyCStructure.Transformation[i][k]; | |
1647 | valuetrsf = AMatrix44 (k, j); | |
1648 | valuenewtrsf = NewTrsf (i, j) + | |
1649 | valueoldtrsf * valuetrsf; | |
1650 | NewTrsf (i, j) = valuenewtrsf; | |
1651 | } | |
1652 | } | |
81bba717 | 1653 | // Update of CStructure |
7fd59977 | 1654 | for (i=0; i<=3; i++) |
1655 | for (j=0; j<=3; j++) | |
1656 | MyCStructure.Transformation[i][j] = float (NewTrsf (i, j)); | |
1657 | } | |
1658 | ||
81bba717 | 1659 | // If transformation, no validation of hidden already calculated parts. |
7fd59977 | 1660 | if (IsRotated ()) |
1661 | ReCompute (); | |
1662 | ||
1663 | GraphicTransform (NewTrsf); | |
1664 | MyStructureManager->SetTransform (this, NewTrsf); | |
1665 | ||
1666 | Update (); | |
1667 | ||
1668 | } | |
1669 | ||
1670 | void Graphic3d_Structure::Transform (TColStd_Array2OfReal& AMatrix) const { | |
1671 | ||
1672 | Standard_Integer lr = AMatrix.LowerRow (); | |
1673 | Standard_Integer ur = AMatrix.UpperRow (); | |
1674 | Standard_Integer lc = AMatrix.LowerCol (); | |
1675 | Standard_Integer uc = AMatrix.UpperCol (); | |
1676 | ||
1677 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) | |
1678 | Graphic3d_TransformError::Raise | |
1679 | ("Transform : not a 4x4 matrix"); | |
1680 | ||
1681 | for (Standard_Integer i=0; i<=3; i++) | |
1682 | for (Standard_Integer j=0; j<=3; j++) | |
1683 | AMatrix (lr + i, lc + j) = MyCStructure.Transformation[i][j]; | |
1684 | ||
1685 | } | |
1686 | ||
1687 | void Graphic3d_Structure::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { | |
1688 | ||
1689 | Standard_Real RL = RealLast (); | |
1690 | Standard_Real RF = RealFirst (); | |
1691 | ||
1692 | Standard_Real XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax, U, V, W; | |
1693 | ||
1694 | MinMaxCoord (XTMin, YTMin, ZTMin, XTMax, YTMax, ZTMax); | |
1695 | if ((XTMin == RF) && (YTMin == RF) && | |
1696 | (ZTMin == RF) && (XTMax == RL) && | |
1697 | (YTMax == RL) && (ZTMax == RL)) { | |
bbf32d01 | 1698 | // Case impossible as it would mean that |
81bba717 | 1699 | // the structure is empty |
bbf32d01 K |
1700 | XMin = RF; |
1701 | YMin = RF; | |
7fd59977 | 1702 | ZMin = RF; |
bbf32d01 | 1703 | |
7fd59977 | 1704 | XMax = RL; |
1705 | YMax = RL; | |
1706 | ZMax = RL; | |
1707 | } | |
1708 | else { | |
1709 | Standard_Integer i, j; | |
1710 | TColStd_Array2OfReal TheTrsf (0, 3, 0, 3); | |
1711 | ||
1712 | for (i=0; i<=3; i++) | |
1713 | for (j=0; j<=3; j++) | |
1714 | TheTrsf (i, j) = MyCStructure.Transformation[i][j]; | |
1715 | ||
1716 | Graphic3d_Structure::Transforms | |
1717 | (TheTrsf, XTMin, YTMin, ZTMin, XMin, YMin, ZMin); | |
1718 | Graphic3d_Structure::Transforms | |
1719 | (TheTrsf, XTMax, YTMax, ZTMax, XMax, YMax, ZMax); | |
1720 | Graphic3d_Structure::Transforms | |
1721 | (TheTrsf, XTMin, YTMin, ZTMax, U, V, W); | |
1722 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1723 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1724 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1725 | Graphic3d_Structure::Transforms | |
1726 | (TheTrsf, XTMax, YTMin, ZTMax, U, V, W); | |
1727 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1728 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1729 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1730 | Graphic3d_Structure::Transforms | |
1731 | (TheTrsf, XTMax, YTMin, ZTMin, U, V, W); | |
1732 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1733 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1734 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1735 | Graphic3d_Structure::Transforms | |
1736 | (TheTrsf, XTMax, YTMax, ZTMin, U, V, W); | |
1737 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1738 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1739 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1740 | Graphic3d_Structure::Transforms | |
1741 | (TheTrsf, XTMin, YTMax, ZTMax, U, V, W); | |
1742 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1743 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1744 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1745 | Graphic3d_Structure::Transforms | |
1746 | (TheTrsf, XTMin, YTMax, ZTMin, U, V, W); | |
1747 | XMin = Min(U,XMin) ; XMax = Max(U,XMax) ; | |
1748 | YMin = Min(V,YMin) ; YMax = Max(V,YMax) ; | |
1749 | ZMin = Min(W,ZMin) ; ZMax = Max(W,ZMax) ; | |
1750 | } | |
1751 | } | |
1752 | ||
1753 | void Graphic3d_Structure::GroupLabels (Standard_Integer& LB, Standard_Integer& LE) { | |
1754 | ||
1755 | LB = MyGroupGenId.Next (); | |
1756 | LE = MyGroupGenId.Next (); | |
1757 | ||
1758 | } | |
1759 | ||
1760 | Standard_Integer Graphic3d_Structure::Identification () const { | |
1761 | ||
1762 | Standard_Integer Result = MyCStructure.Id; | |
1763 | ||
1764 | return Result; | |
1765 | ||
1766 | } | |
1767 | ||
1768 | void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag ) | |
1769 | { | |
1770 | SetTransformPersistence( AFlag, gp_Pnt( 0, 0, 0 ) ); | |
1771 | } | |
1772 | ||
1773 | void Graphic3d_Structure::SetTransformPersistence( const Graphic3d_TransModeFlags& AFlag, | |
1774 | const gp_Pnt& APoint ) | |
1775 | { | |
bbf32d01 | 1776 | if (IsDeleted ()) return; |
7fd59977 | 1777 | |
1778 | MyCStructure.TransformPersistence.Flag = AFlag; | |
60be1f9b | 1779 | MyCStructure.TransformPersistence.Point.x = float (APoint.X()); |
1780 | MyCStructure.TransformPersistence.Point.y = float (APoint.Y()); | |
1781 | MyCStructure.TransformPersistence.Point.z = float (APoint.Z()); | |
7fd59977 | 1782 | //MyStructureManager->Update (); |
1783 | //Update(); | |
1784 | MyGraphicDriver->ContextStructure( MyCStructure ); | |
1785 | ||
1786 | MyCStructure.TransformPersistence.IsSet = 1; | |
1787 | } | |
1788 | ||
1789 | Graphic3d_TransModeFlags Graphic3d_Structure::TransformPersistenceMode() const | |
1790 | { | |
1791 | return MyCStructure.TransformPersistence.Flag; | |
1792 | } | |
1793 | ||
1794 | gp_Pnt Graphic3d_Structure::TransformPersistencePoint() const | |
1795 | { | |
1796 | gp_Pnt aPnt( 0., 0., 0. ); | |
1797 | aPnt.SetX( MyCStructure.TransformPersistence.Point.x ); | |
1798 | aPnt.SetY( MyCStructure.TransformPersistence.Point.y ); | |
1799 | aPnt.SetZ( MyCStructure.TransformPersistence.Point.z ); | |
1800 | ||
1801 | return aPnt; | |
1802 | } | |
1803 | ||
1804 | void Graphic3d_Structure::Add (const Handle(Graphic3d_Group)& AGroup) { | |
1805 | ||
81bba717 | 1806 | // Method called only by the constructor of Graphic3d_Group |
1807 | // It is easy to check presence of <AGroup> | |
1808 | // in sequence MyGroups. | |
7fd59977 | 1809 | MyGroups.Append (AGroup); |
1810 | ||
1811 | } | |
1812 | ||
1813 | void Graphic3d_Structure::Remove (const Standard_Address APtr, const Graphic3d_TypeOfConnection AType) { | |
1814 | ||
1815 | Standard_Integer i, index, length; | |
1816 | ||
bbf32d01 | 1817 | switch (AType) |
7fd59977 | 1818 | { |
1819 | case Graphic3d_TOC_DESCENDANT : | |
1820 | index = 0; | |
1821 | length = MyDescendants.Length (); | |
1822 | for (i=1; i<=length && index==0; i++) | |
1823 | if ((void *) (MyDescendants.Value (i)) == APtr) | |
1824 | index = i; | |
1825 | if (index != 0) | |
1826 | MyDescendants.Remove (index); | |
1827 | #ifdef TRACE | |
1828 | else | |
1829 | cout << "Error, Graphic3d_Structure::Remove\n"; | |
1830 | #endif | |
1831 | break; | |
1832 | ||
1833 | case Graphic3d_TOC_ANCESTOR : | |
1834 | index = 0; | |
1835 | length = MyAncestors.Length (); | |
1836 | for (i=1; i<=length && index==0; i++) | |
1837 | if ((void *) (MyAncestors.Value (i)) == APtr) | |
1838 | index = i; | |
1839 | if (index != 0) | |
1840 | MyAncestors.Remove (index); | |
1841 | #ifdef TRACE | |
1842 | else | |
1843 | cout << "Error, Graphic3d_Structure::Remove\n"; | |
1844 | #endif | |
1845 | break; | |
1846 | } | |
1847 | ||
1848 | } | |
1849 | ||
1850 | void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& AGroup) { | |
1851 | ||
1852 | Standard_Integer index = 0; | |
1853 | Standard_Integer Length = MyGroups.Length (); | |
1854 | for (Standard_Integer i=1; i<=Length && index==0; i++) | |
1855 | if (MyGroups.Value (i) == AGroup) index = i; | |
1856 | ||
81bba717 | 1857 | // Search in Groups |
7fd59977 | 1858 | if (index != 0) { |
1859 | Standard_Integer GroupLabelBegin, GroupLabelEnd; | |
1860 | AGroup->Labels (GroupLabelBegin, GroupLabelEnd); | |
1861 | MyGroupGenId.Free (GroupLabelBegin); | |
1862 | MyGroupGenId.Free (GroupLabelEnd); | |
1863 | MyGroups.Remove (index); | |
1864 | } | |
1865 | ||
1866 | } | |
1867 | ||
1868 | Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager () const { | |
1869 | ||
1870 | #ifdef DOWNCAST | |
1871 | return | |
1872 | (Handle(Graphic3d_StructureManager)::DownCast(Handle(Standard_Transient) | |
1873 | ((Standard_Transient*) MyPtrStructureManager))); | |
1874 | #else | |
1875 | return MyStructureManager; | |
1876 | #endif | |
1877 | ||
1878 | } | |
1879 | ||
7fd59977 | 1880 | |
1881 | void Graphic3d_Structure::MinMaxCoord (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { | |
1882 | ||
1883 | Standard_Real RL = RealLast (); | |
1884 | Standard_Real RF = RealFirst (); | |
1885 | ||
1886 | Standard_Real Xm, Ym, Zm, XM, YM, ZM; | |
1887 | ||
1888 | //Bounding borders of infinite line has been calculated as own point | |
1889 | //in center of this line | |
1890 | if (IsEmpty () || IsInfinite ()) { | |
1891 | if( IsInfinite ()){ | |
1892 | for (int i=1; i<=MyGroups.Length (); i++) | |
1893 | if (! (MyGroups.Value (i))->IsEmpty () ) { | |
1894 | (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM); | |
1895 | Graphic3d_Vertex vertex1(Xm, Ym, Zm); | |
1896 | Graphic3d_Vertex vertex2(XM, YM, ZM); | |
1897 | Standard_Real distance = vertex1.Distance( vertex1,vertex2 ); | |
1898 | if( distance >= 500000.0){ | |
1899 | XMin = XMax = (Xm+ XM)/2.0; | |
1900 | YMin = YMax = (Ym+ YM)/2.0; | |
1901 | ZMin = ZMax = (Zm+ ZM)/2.0; | |
1902 | return; | |
bbf32d01 | 1903 | } |
7fd59977 | 1904 | } |
1905 | } | |
1906 | XMin = RF; | |
1907 | YMin = RF; | |
1908 | ZMin = RF; | |
1909 | ||
1910 | XMax = RL; | |
1911 | YMax = RL; | |
1912 | ZMax = RL; | |
1913 | } | |
1914 | else { | |
1915 | XMin = RL; | |
1916 | YMin = RL; | |
1917 | ZMin = RL; | |
1918 | ||
1919 | XMax = RF; | |
1920 | YMax = RF; | |
1921 | ZMax = RF; | |
1922 | Standard_Integer i, Length; | |
1923 | ||
1924 | Length = MyGroups.Length (); | |
1925 | for (i=1; i<=Length; i++) | |
1926 | if (! (MyGroups.Value (i))->IsEmpty () ) { | |
1927 | (MyGroups.Value (i))->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM); | |
1928 | if (Xm < XMin) XMin = Xm; | |
1929 | if (Ym < YMin) YMin = Ym; | |
1930 | if (Zm < ZMin) ZMin = Zm; | |
1931 | if (XM > XMax) XMax = XM; | |
1932 | if (YM > YMax) YMax = YM; | |
1933 | if (ZM > ZMax) ZMax = ZM; | |
1934 | } | |
1935 | ||
1936 | Length = MyDescendants.Length (); | |
1937 | for (i=1; i<=Length; i++) | |
1938 | if (! ((Graphic3d_Structure *) | |
1939 | (MyDescendants.Value (i)))->IsEmpty () ) { | |
1940 | ((Graphic3d_Structure *) | |
1941 | (MyDescendants.Value (i)))->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM); | |
1942 | ||
1943 | if (Xm < XMin) XMin = Xm; | |
1944 | if (Ym < YMin) YMin = Ym; | |
1945 | if (Zm < ZMin) ZMin = Zm; | |
1946 | if (XM > XMax) XMax = XM; | |
1947 | if (YM > YMax) YMax = YM; | |
1948 | if (ZM > ZMax) ZMax = ZM; | |
1949 | } | |
1950 | ||
1951 | if ((XMin == RL) && (YMin == RL) && | |
1952 | (ZMin == RL) && (XMax == RF) && | |
1953 | (YMax == RF) && (ZMax == RF)) { | |
bbf32d01 | 1954 | // Case impossible as it would mean |
81bba717 | 1955 | // that the structure is empty |
7fd59977 | 1956 | XMin = RF; |
1957 | YMin = RF; | |
1958 | ZMin = RF; | |
1959 | ||
1960 | XMax = RL; | |
1961 | YMax = RL; | |
1962 | ZMax = RL; | |
1963 | } | |
1964 | ||
1965 | } | |
1966 | ||
1967 | } | |
1968 | ||
1969 | void Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& NewX, Standard_Real& NewY, Standard_Real& NewZ) { | |
1970 | ||
1971 | Standard_Real A, B, C, D; | |
1972 | ||
1973 | Standard_Real RL = RealLast (); | |
1974 | Standard_Real RF = RealFirst (); | |
1975 | ||
1976 | if ((X == RF) || (Y == RF) || (Z == RF) || | |
1977 | (X == RL) || (Y == RL) || (Z == RL)) { | |
1978 | NewX = X; | |
1979 | NewY = Y; | |
1980 | NewZ = Z; | |
1981 | } | |
1982 | else { | |
1983 | A = ATrsf (0, 0); | |
1984 | B = ATrsf (0, 1); | |
1985 | C = ATrsf (0, 2); | |
1986 | D = ATrsf (0, 3); | |
1987 | NewX = A * X + B * Y + C * Z + D; | |
1988 | A = ATrsf (1, 0); | |
1989 | B = ATrsf (1, 1); | |
1990 | C = ATrsf (1, 2); | |
1991 | D = ATrsf (1, 3); | |
1992 | NewY = A * X + B * Y + C * Z + D; | |
1993 | A = ATrsf (2, 0); | |
1994 | B = ATrsf (2, 1); | |
1995 | C = ATrsf (2, 2); | |
1996 | D = ATrsf (2, 3); | |
1997 | NewZ = A * X + B * Y + C * Z + D; | |
1998 | } | |
1999 | ||
2000 | } | |
2001 | ||
2002 | Graphic3d_Vector Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vector& Coord) { | |
2003 | ||
2004 | Standard_Real NewX, NewY, NewZ; | |
2005 | Graphic3d_Vector Result; | |
2006 | ||
2007 | Graphic3d_Structure::Transforms | |
2008 | (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ); | |
2009 | Result.SetCoord (NewX, NewY, NewZ); | |
2010 | ||
2011 | return (Result); | |
2012 | ||
2013 | } | |
2014 | ||
2015 | Graphic3d_Vertex Graphic3d_Structure::Transforms (const TColStd_Array2OfReal& ATrsf, const Graphic3d_Vertex& Coord) { | |
2016 | ||
2017 | Standard_Real NewX, NewY, NewZ; | |
2018 | Graphic3d_Vertex Result; | |
2019 | ||
2020 | Graphic3d_Structure::Transforms | |
2021 | (ATrsf, Coord.X (), Coord.Y (), Coord.Z (), NewX, NewY, NewZ); | |
2022 | Result.SetCoord (NewX, NewY, NewZ); | |
2023 | ||
2024 | return (Result); | |
2025 | ||
2026 | } | |
2027 | ||
2028 | void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType, Graphic3d_MapOfStructure& ASet) { | |
2029 | ||
2030 | ||
2031 | Graphic3d_MapOfStructure h1; | |
2032 | Graphic3d_MapOfStructure h2; | |
2033 | AStructure->Descendants (h1); | |
2034 | AStructure->Ancestors (h2); | |
2035 | ||
2036 | Graphic3d_MapIteratorOfMapOfStructure IteratorD (h1); | |
2037 | Graphic3d_MapIteratorOfMapOfStructure IteratorA (h2); | |
2038 | ||
2039 | ASet.Add (AStructure); | |
2040 | ||
2041 | // exploration | |
bbf32d01 | 2042 | switch (AType) |
7fd59977 | 2043 | { |
2044 | ||
2045 | case Graphic3d_TOC_DESCENDANT : | |
2046 | while (IteratorD.More ()) { | |
2047 | Graphic3d_Structure::Network | |
2048 | (IteratorD.Key (), AType, ASet); | |
81bba717 | 2049 | // IteratorD.Next () is located on the next structure |
7fd59977 | 2050 | IteratorD.Next (); |
2051 | } | |
2052 | break; | |
2053 | ||
2054 | case Graphic3d_TOC_ANCESTOR : | |
2055 | while (IteratorA.More ()) { | |
2056 | Graphic3d_Structure::Network | |
2057 | (IteratorA.Key (), AType, ASet); | |
bbf32d01 K |
2058 | // IteratorA.Next () is located on the next structure |
2059 | IteratorA.Next (); | |
7fd59977 | 2060 | } |
2061 | break; | |
2062 | } | |
2063 | ||
2064 | } | |
2065 | ||
bbf32d01 | 2066 | void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& AStructure, const Graphic3d_TypeOfConnection AType) |
7fd59977 | 2067 | { |
2068 | ||
2069 | Graphic3d_MapOfStructure ASet; | |
2070 | ||
2071 | Graphic3d_MapIteratorOfMapOfStructure IteratorASet (ASet); | |
2072 | ||
2073 | Graphic3d_Structure::Network (AStructure, AType, ASet); | |
2074 | ||
2075 | while (IteratorASet.More ()) { | |
2076 | cout << "\tIdent " | |
2077 | << (IteratorASet.Key ())->Identification () << "\n"; | |
2078 | IteratorASet.Next (); | |
2079 | } | |
2080 | cout << flush; | |
2081 | ||
2082 | } | |
2083 | ||
bbf32d01 | 2084 | void Graphic3d_Structure::Update () const |
7fd59977 | 2085 | { |
2086 | ||
2087 | if (IsDeleted ()) return; | |
2088 | ||
2089 | if (MyStructureManager->UpdateMode () == Aspect_TOU_ASAP) | |
2090 | MyStructureManager->Update (); | |
2091 | ||
2092 | } | |
2093 | ||
bbf32d01 | 2094 | void Graphic3d_Structure::UpdateStructure (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF) |
7fd59977 | 2095 | { |
2096 | ||
2097 | Standard_Real R, G, B; | |
2098 | Standard_Real Rs, Gs, Bs; | |
2099 | Standard_CString AFont; | |
2100 | Standard_Real ASpace; | |
2101 | Standard_Real AnExpansion; | |
2102 | Standard_Real AWidth; | |
2103 | Standard_Real AScale; | |
2104 | Quantity_Color AColor; | |
2105 | Quantity_Color AnIntColor; | |
2106 | Quantity_Color BackIntColor; | |
2107 | Quantity_Color AnEdgeColor; | |
2108 | Aspect_TypeOfLine ALType; | |
2109 | Aspect_TypeOfMarker AMType; | |
2110 | Aspect_InteriorStyle AStyle; | |
2111 | Aspect_TypeOfStyleText AStyleT; | |
2112 | Aspect_TypeOfDisplayText ADisplayType; | |
bbf32d01 | 2113 | Quantity_Color AColorSubTitle; |
7fd59977 | 2114 | Standard_Boolean ATextZoomable; |
2115 | Standard_Real ATextAngle; | |
2116 | OSD_FontAspect ATextFontAspect; | |
2117 | ||
2118 | ||
2119 | CTXL->Values (AColor, ALType, AWidth); | |
2120 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
2121 | ||
2122 | MyCStructure.ContextLine.Color.r = float (R); | |
2123 | MyCStructure.ContextLine.Color.g = float (G); | |
2124 | MyCStructure.ContextLine.Color.b = float (B); | |
2125 | MyCStructure.ContextLine.LineType = int (ALType); | |
2126 | MyCStructure.ContextLine.Width = float (AWidth); | |
2127 | ||
2128 | CTXM->Values (AColor, AMType, AScale); | |
2129 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
2130 | ||
2131 | MyCStructure.ContextMarker.Color.r = float (R); | |
2132 | MyCStructure.ContextMarker.Color.g = float (G); | |
2133 | MyCStructure.ContextMarker.Color.b = float (B); | |
2134 | MyCStructure.ContextMarker.MarkerType = int (AMType); | |
2135 | MyCStructure.ContextMarker.Scale = float (AScale); | |
2136 | ||
2137 | CTXT->Values (AColor, AFont, AnExpansion, ASpace,AStyleT,ADisplayType,AColorSubTitle,ATextZoomable,ATextAngle,ATextFontAspect); | |
2138 | AColor.Values (R, G, B, Quantity_TOC_RGB); | |
2139 | AColorSubTitle.Values (Rs, Gs, Bs, Quantity_TOC_RGB); | |
2140 | ||
2141 | MyCStructure.ContextText.Color.r = float (R); | |
2142 | MyCStructure.ContextText.Color.g = float (G); | |
2143 | MyCStructure.ContextText.Color.b = float (B); | |
2144 | MyCStructure.ContextText.Font = (char*) (AFont); | |
2145 | MyCStructure.ContextText.Expan = float (AnExpansion); | |
2146 | MyCStructure.ContextText.Style = int (AStyleT); | |
2147 | MyCStructure.ContextText.DisplayType = int (ADisplayType); | |
2148 | MyCStructure.ContextText.Space = float (ASpace); | |
2149 | MyCStructure.ContextText.ColorSubTitle.r = float (Rs); | |
2150 | MyCStructure.ContextText.ColorSubTitle.g = float (Gs); | |
2151 | MyCStructure.ContextText.ColorSubTitle.b = float (Bs); | |
2152 | MyCStructure.ContextText.TextZoomable = ATextZoomable; | |
60be1f9b | 2153 | MyCStructure.ContextText.TextAngle = float (ATextAngle); |
bbf32d01 | 2154 | MyCStructure.ContextText.TextFontAspect = (int)ATextFontAspect; |
7fd59977 | 2155 | |
2156 | ||
2157 | ||
2158 | CTXF->Values (AStyle, AnIntColor, BackIntColor, AnEdgeColor, ALType, AWidth); | |
2159 | AnIntColor.Values (R, G, B, Quantity_TOC_RGB); | |
2160 | ||
2161 | MyCStructure.ContextFillArea.Style = int (AStyle); | |
2162 | MyCStructure.ContextFillArea.IntColor.r = float (R); | |
2163 | MyCStructure.ContextFillArea.IntColor.g = float (G); | |
2164 | MyCStructure.ContextFillArea.IntColor.b = float (B); | |
2165 | #ifdef OCC1174 | |
2166 | if ( CTXF->Distinguish() ) | |
2167 | BackIntColor.Values( R, G, B, Quantity_TOC_RGB ); | |
2168 | #endif | |
2169 | MyCStructure.ContextFillArea.BackIntColor.r = float( R ); | |
2170 | MyCStructure.ContextFillArea.BackIntColor.g = float( G ); | |
2171 | MyCStructure.ContextFillArea.BackIntColor.b = float( B ); | |
2172 | ||
2173 | // Edges | |
2174 | MyCStructure.ContextFillArea.Edge = CTXF->Edge () ? 1:0; | |
2175 | AnEdgeColor.Values (R, G, B, Quantity_TOC_RGB); | |
2176 | MyCStructure.ContextFillArea.EdgeColor.r = float (R); | |
2177 | MyCStructure.ContextFillArea.EdgeColor.g = float (G); | |
2178 | MyCStructure.ContextFillArea.EdgeColor.b = float (B); | |
2179 | MyCStructure.ContextFillArea.LineType = int (ALType); | |
2180 | MyCStructure.ContextFillArea.Width = float (AWidth); | |
2181 | MyCStructure.ContextFillArea.Hatch = int (CTXF->HatchStyle ()); | |
2182 | #ifdef G003 | |
2183 | Quantity_Ratio ratio; | |
bbf32d01 | 2184 | MyCStructure.ContextFillArea.DegenerationMode = |
7fd59977 | 2185 | int (CTXF->DegenerateModel(ratio)); |
2186 | MyCStructure.ContextFillArea.SkipRatio = float (ratio); | |
2187 | #endif // G003 | |
2188 | ||
2189 | ||
2190 | /*** Front and Back face ***/ | |
2191 | MyCStructure.ContextFillArea.Distinguish = CTXF->Distinguish () ? 1:0; | |
2192 | MyCStructure.ContextFillArea.BackFace = CTXF->BackFace () ? 1:0; | |
2193 | /*** Back Material ***/ | |
2194 | // Light specificity | |
2195 | MyCStructure.ContextFillArea.Back.Shininess = | |
2196 | float ((CTXF->BackMaterial ()).Shininess ()); | |
2197 | MyCStructure.ContextFillArea.Back.Ambient = | |
2198 | float ((CTXF->BackMaterial ()).Ambient ()); | |
2199 | MyCStructure.ContextFillArea.Back.Diffuse = | |
2200 | float ((CTXF->BackMaterial ()).Diffuse ()); | |
2201 | MyCStructure.ContextFillArea.Back.Specular = | |
2202 | float ((CTXF->BackMaterial ()).Specular ()); | |
2203 | MyCStructure.ContextFillArea.Back.Transparency = | |
2204 | float ((CTXF->BackMaterial ()).Transparency ()); | |
2205 | MyCStructure.ContextFillArea.Back.Emission = | |
2206 | float ((CTXF->BackMaterial ()).Emissive ()); | |
2207 | ||
2208 | // Reflection mode | |
2209 | MyCStructure.ContextFillArea.Back.IsAmbient = | |
2210 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); | |
2211 | MyCStructure.ContextFillArea.Back.IsDiffuse = | |
2212 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); | |
2213 | MyCStructure.ContextFillArea.Back.IsSpecular = | |
2214 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); | |
2215 | MyCStructure.ContextFillArea.Back.IsEmission = | |
2216 | ( (CTXF->BackMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); | |
2217 | ||
2218 | // Material type | |
2219 | //JR/Hp | |
2220 | const Graphic3d_MaterialAspect ama = CTXF->BackMaterial () ; | |
2221 | Standard_Boolean amt = ama.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; | |
2222 | MyCStructure.ContextFillArea.Back.IsPhysic = ( amt ? 1 : 0 ); | |
2223 | ||
2224 | // Specular color | |
2225 | MyCStructure.ContextFillArea.Back.ColorSpec.r = | |
2226 | float (((CTXF->BackMaterial ()).SpecularColor ()).Red ()); | |
2227 | MyCStructure.ContextFillArea.Back.ColorSpec.g = | |
2228 | float (((CTXF->BackMaterial ()).SpecularColor ()).Green ()); | |
2229 | MyCStructure.ContextFillArea.Back.ColorSpec.b = | |
2230 | float (((CTXF->BackMaterial ()).SpecularColor ()).Blue ()); | |
2231 | ||
2232 | // Ambient color | |
2233 | MyCStructure.ContextFillArea.Back.ColorAmb.r = | |
2234 | float (((CTXF->BackMaterial ()).AmbientColor ()).Red ()); | |
2235 | MyCStructure.ContextFillArea.Back.ColorAmb.g = | |
2236 | float (((CTXF->BackMaterial ()).AmbientColor ()).Green ()); | |
2237 | MyCStructure.ContextFillArea.Back.ColorAmb.b = | |
2238 | float (((CTXF->BackMaterial ()).AmbientColor ()).Blue ()); | |
2239 | ||
2240 | // Diffuse color | |
2241 | MyCStructure.ContextFillArea.Back.ColorDif.r = | |
2242 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Red ()); | |
2243 | MyCStructure.ContextFillArea.Back.ColorDif.g = | |
2244 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Green ()); | |
2245 | MyCStructure.ContextFillArea.Back.ColorDif.b = | |
2246 | float (((CTXF->BackMaterial ()).DiffuseColor ()).Blue ()); | |
2247 | ||
2248 | // Emissive color | |
2249 | MyCStructure.ContextFillArea.Back.ColorEms.r = | |
2250 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Red ()); | |
2251 | MyCStructure.ContextFillArea.Back.ColorEms.g = | |
2252 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Green ()); | |
2253 | MyCStructure.ContextFillArea.Back.ColorEms.b = | |
2254 | float (((CTXF->BackMaterial ()).EmissiveColor ()).Blue ()); | |
2255 | ||
bbf32d01 | 2256 | MyCStructure.ContextFillArea.Back.EnvReflexion = |
7fd59977 | 2257 | float ((CTXF->BackMaterial ()).EnvReflexion()); |
2258 | ||
2259 | /*** Front Material ***/ | |
2260 | // Light specificity | |
2261 | MyCStructure.ContextFillArea.Front.Shininess = | |
2262 | float ((CTXF->FrontMaterial ()).Shininess ()); | |
2263 | MyCStructure.ContextFillArea.Front.Ambient = | |
2264 | float ((CTXF->FrontMaterial ()).Ambient ()); | |
2265 | MyCStructure.ContextFillArea.Front.Diffuse = | |
2266 | float ((CTXF->FrontMaterial ()).Diffuse ()); | |
2267 | MyCStructure.ContextFillArea.Front.Specular = | |
2268 | float ((CTXF->FrontMaterial ()).Specular ()); | |
2269 | MyCStructure.ContextFillArea.Front.Transparency = | |
2270 | float ((CTXF->FrontMaterial ()).Transparency ()); | |
2271 | MyCStructure.ContextFillArea.Front.Emission = | |
2272 | float ((CTXF->FrontMaterial ()).Emissive ()); | |
2273 | ||
2274 | // Reflection mode | |
2275 | MyCStructure.ContextFillArea.Front.IsAmbient = | |
2276 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0 ); | |
2277 | MyCStructure.ContextFillArea.Front.IsDiffuse = | |
2278 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0 ); | |
2279 | MyCStructure.ContextFillArea.Front.IsSpecular = | |
2280 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0 ); | |
2281 | MyCStructure.ContextFillArea.Front.IsEmission = | |
2282 | ( (CTXF->FrontMaterial ()).ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0 ); | |
2283 | ||
2284 | // Material type | |
2285 | //JR/Hp | |
2286 | const Graphic3d_MaterialAspect amas = CTXF->FrontMaterial () ; | |
2287 | Standard_Boolean amty = amas.MaterialType(Graphic3d_MATERIAL_PHYSIC) ; | |
2288 | MyCStructure.ContextFillArea.Front.IsPhysic = ( amty ? 1 : 0 ); | |
2289 | ||
2290 | // Specular color | |
2291 | MyCStructure.ContextFillArea.Front.ColorSpec.r = | |
2292 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Red ()); | |
2293 | MyCStructure.ContextFillArea.Front.ColorSpec.g = | |
2294 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Green ()); | |
2295 | MyCStructure.ContextFillArea.Front.ColorSpec.b = | |
2296 | float (((CTXF->FrontMaterial ()).SpecularColor ()).Blue ()); | |
2297 | ||
2298 | // Ambient color | |
2299 | MyCStructure.ContextFillArea.Front.ColorAmb.r = | |
2300 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Red ()); | |
2301 | MyCStructure.ContextFillArea.Front.ColorAmb.g = | |
2302 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Green ()); | |
2303 | MyCStructure.ContextFillArea.Front.ColorAmb.b = | |
2304 | float (((CTXF->FrontMaterial ()).AmbientColor ()).Blue ()); | |
2305 | ||
2306 | // Diffuse color | |
2307 | MyCStructure.ContextFillArea.Front.ColorDif.r = | |
2308 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Red ()); | |
2309 | MyCStructure.ContextFillArea.Front.ColorDif.g = | |
2310 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Green ()); | |
2311 | MyCStructure.ContextFillArea.Front.ColorDif.b = | |
2312 | float (((CTXF->FrontMaterial ()).DiffuseColor ()).Blue ()); | |
2313 | ||
2314 | // Emissive color | |
2315 | MyCStructure.ContextFillArea.Front.ColorEms.r = | |
2316 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Red ()); | |
2317 | MyCStructure.ContextFillArea.Front.ColorEms.g = | |
2318 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Green ()); | |
2319 | MyCStructure.ContextFillArea.Front.ColorEms.b = | |
2320 | float (((CTXF->FrontMaterial ()).EmissiveColor ()).Blue ()); | |
2321 | ||
bbf32d01 | 2322 | MyCStructure.ContextFillArea.Front.EnvReflexion = |
7fd59977 | 2323 | float ((CTXF->FrontMaterial ()).EnvReflexion()); |
2324 | ||
2325 | Handle(Graphic3d_TextureMap) TempTextureMap = CTXF->TextureMap(); | |
2326 | if (! TempTextureMap.IsNull() ) | |
2327 | MyCStructure.ContextFillArea.Texture.TexId = TempTextureMap->TextureId(); | |
2328 | else | |
2329 | MyCStructure.ContextFillArea.Texture.TexId = -1; | |
2330 | ||
2331 | MyCStructure.ContextFillArea.Texture.doTextureMap = CTXF->TextureMapState() ? 1:0; | |
2332 | ||
bbf32d01 | 2333 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 2334 | Standard_Integer aPolyMode; |
60be1f9b | 2335 | Standard_ShortReal aPolyFactor, aPolyUnits; |
7fd59977 | 2336 | CTXF->PolygonOffsets(aPolyMode, aPolyFactor, aPolyUnits); |
2337 | MyCStructure.ContextFillArea.PolygonOffsetMode = aPolyMode; | |
2338 | MyCStructure.ContextFillArea.PolygonOffsetFactor = aPolyFactor; | |
2339 | MyCStructure.ContextFillArea.PolygonOffsetUnits = aPolyUnits; | |
bbf32d01 | 2340 | // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets |
7fd59977 | 2341 | } |
2342 | ||
2343 | void Graphic3d_Structure::GraphicHighlight (const Aspect_TypeOfHighlightMethod AMethod) { | |
2344 | ||
2345 | Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax; | |
2346 | Standard_Real R, G, B; | |
2347 | ||
2348 | MyCStructure.highlight = 1; | |
2349 | MyHighlightMethod = AMethod; | |
2350 | ||
bbf32d01 | 2351 | switch (AMethod) |
7fd59977 | 2352 | { |
2353 | case Aspect_TOHM_COLOR : | |
2354 | MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB); | |
2355 | MyGraphicDriver->HighlightColor | |
2356 | (MyCStructure, float (R), float (G), | |
2357 | float (B) , Standard_True); | |
2358 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
2359 | break; | |
2360 | case Aspect_TOHM_BLINK : | |
2361 | MyGraphicDriver->Blink (MyCStructure, Standard_True); | |
2362 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
2363 | break; | |
2364 | case Aspect_TOHM_BOUNDBOX : | |
2365 | if (IsEmpty () || IsInfinite ()) { | |
81bba717 | 2366 | // Empty or infinite structure |
7fd59977 | 2367 | XMin = YMin = ZMin = 0.; |
2368 | XMax = YMax = ZMax = 0.; | |
2369 | } | |
2370 | else { | |
2371 | MinMaxCoord | |
2372 | (XMin, YMin, ZMin, XMax, YMax, ZMax); | |
2373 | } | |
2374 | MyCStructure.BoundBox.Pmin.x = float (XMin); | |
2375 | MyCStructure.BoundBox.Pmin.y = float (YMin); | |
2376 | MyCStructure.BoundBox.Pmin.z = float (ZMin); | |
2377 | MyCStructure.BoundBox.Pmax.x = float (XMax); | |
2378 | MyCStructure.BoundBox.Pmax.y = float (YMax); | |
2379 | MyCStructure.BoundBox.Pmax.z = float (ZMax); | |
2380 | MyHighlightColor.Values (R, G, B, Quantity_TOC_RGB); | |
2381 | MyCStructure.BoundBox.Color.r = float (R); | |
2382 | MyCStructure.BoundBox.Color.g = float (G); | |
2383 | MyCStructure.BoundBox.Color.b = float (B); | |
2384 | MyGraphicDriver->BoundaryBox (MyCStructure, Standard_True); | |
2385 | break; | |
2386 | } | |
2387 | ||
2388 | } | |
2389 | ||
2390 | void Graphic3d_Structure::GraphicTransform (const TColStd_Array2OfReal& AMatrix) { | |
2391 | ||
2392 | Standard_Integer i, j; | |
2393 | ||
2394 | for (i=0; i<=3; i++) | |
2395 | for (j=0; j<=3; j++) | |
2396 | MyCStructure.Transformation[i][j] = float (AMatrix (i, j)); | |
2397 | ||
2398 | MyGraphicDriver->TransformStructure (MyCStructure); | |
2399 | ||
2400 | } | |
2401 | ||
2402 | void Graphic3d_Structure::GraphicUnHighlight () { | |
2403 | ||
2404 | MyCStructure.highlight = 0; | |
2405 | ||
bbf32d01 | 2406 | switch (MyHighlightMethod) |
7fd59977 | 2407 | { |
2408 | case Aspect_TOHM_COLOR : | |
2409 | MyGraphicDriver->HighlightColor | |
2410 | (MyCStructure, 0.0, 0.0, 0.0 , Standard_False); | |
2411 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
2412 | break; | |
2413 | case Aspect_TOHM_BLINK : | |
2414 | MyGraphicDriver->Blink (MyCStructure, Standard_False); | |
2415 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
2416 | break; | |
2417 | case Aspect_TOHM_BOUNDBOX : | |
2418 | MyGraphicDriver->BoundaryBox | |
2419 | (MyCStructure, Standard_False); | |
2420 | MyGraphicDriver->NameSetStructure (MyCStructure); | |
2421 | break; | |
2422 | } | |
2423 | ||
2424 | } | |
2425 | ||
2426 | Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual () const { | |
2427 | ||
2428 | return (MyComputeVisual); | |
2429 | ||
2430 | } | |
2431 | ||
2432 | void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure AVisual) { | |
2433 | ||
81bba717 | 2434 | // The ComputeVisual is saved only if the structure is |
2435 | // declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING. | |
2436 | // This declaration permits to calculate | |
2437 | // proper representation of the structure calculated by Compute | |
2438 | // instead of passage to TOS_COMPUTED. | |
7fd59977 | 2439 | if (AVisual != Graphic3d_TOS_COMPUTED) |
2440 | MyComputeVisual = AVisual; | |
2441 | ||
2442 | } | |
2443 | ||
2444 | void Graphic3d_Structure::Plot (const Handle(Graphic3d_Plotter)& ) { | |
2445 | ||
2446 | } | |
2447 | ||
2448 | void Graphic3d_Structure::SetManager (const Handle(Graphic3d_StructureManager)& AManager, const Standard_Boolean WithPropagation) { | |
2449 | ||
81bba717 | 2450 | // All connected structures should follow ? |
7fd59977 | 2451 | #ifdef IMPLEMENTED |
2452 | if (WithPropagation) { | |
2453 | Standard_Integer i, Length; | |
2454 | Length = MyDescendants.Length (); | |
2455 | for (i=1; i<=Length; i++) | |
2456 | ((Graphic3d_Structure *) | |
2457 | (MyDescendants.Value (i)))->SetStructureManager (AManager); | |
2458 | ||
2459 | Length = MyAncestors.Length (); | |
2460 | for (i=1; i<=Length; i++) | |
2461 | ((Graphic3d_Structure *) | |
2462 | (MyAncestors.Value (i)))->SetStructureManager (AManager); | |
2463 | } | |
2464 | #endif | |
2465 | ||
81bba717 | 2466 | // change of identification ? |
7fd59977 | 2467 | // MyStructureManager->Remove (Standard_Integer (MyCStructure.Id)); |
2468 | // AManager->NewIdentification (); | |
2469 | // MyCStructure.Id = int (AManager->NewIdentification ()); | |
2470 | ||
2471 | Aspect_TypeOfUpdate UpdateMode = MyStructureManager->UpdateMode (); | |
2472 | Aspect_TypeOfUpdate NewUpdateMode = AManager->UpdateMode (); | |
2473 | MyStructureManager->SetUpdateMode (Aspect_TOU_WAIT); | |
2474 | AManager->SetUpdateMode (Aspect_TOU_WAIT); | |
2475 | ||
2476 | if (MyCStructure.stick) { | |
2477 | MyStructureManager->Erase (this); | |
2478 | AManager->Display (this); | |
2479 | } | |
2480 | ||
2481 | if (MyCStructure.highlight) { | |
2482 | } | |
2483 | ||
2484 | if (MyCStructure.visible) { | |
2485 | MyStructureManager->Invisible (this); | |
2486 | AManager->Visible (this); | |
2487 | } | |
2488 | ||
2489 | if (MyCStructure.pick) { | |
2490 | MyStructureManager->Undetectable (this); | |
2491 | AManager->Detectable (this); | |
2492 | } | |
2493 | ||
2494 | MyStructureManager->SetUpdateMode (UpdateMode); | |
2495 | AManager->SetUpdateMode (NewUpdateMode); | |
2496 | ||
81bba717 | 2497 | // New manager |
7fd59977 | 2498 | MyPtrStructureManager = (void *) AManager.operator->(); |
2499 | ||
2500 | } | |
2501 | ||
2502 | void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean AFlag) { | |
2503 | ||
2504 | MyCStructure.HLRValidation = AFlag ? 1:0; | |
2505 | ||
2506 | } | |
2507 | ||
2508 | Standard_Boolean Graphic3d_Structure::HLRValidation () const { | |
2509 | ||
81bba717 | 2510 | // Hidden parts stored in <me> are valid if : |
2511 | // 1/ the owner is defined. | |
2512 | // 2/ they are not invalid. | |
7fd59977 | 2513 | |
2514 | Standard_Boolean Result = MyOwner != NULL && MyCStructure.HLRValidation != 0; | |
2515 | ||
2516 | return Result; | |
2517 | ||
2518 | } | |
2519 | ||
2520 | Standard_Address Graphic3d_Structure::CStructure () const { | |
2521 | ||
2522 | return Standard_Address (&MyCStructure); | |
2523 | ||
2524 | } | |
59f45b7c | 2525 | |
2526 | //======================================================================= | |
2527 | //function : SetZLayer | |
2528 | //purpose : | |
2529 | //======================================================================= | |
2530 | ||
2531 | void Graphic3d_Structure::SetZLayer (const Standard_Integer theLayerId) | |
2532 | { | |
2533 | // if the structure is not displayed, unable to change its display layer | |
2534 | if (IsDeleted ()) | |
2535 | return; | |
2536 | ||
2537 | MyStructureManager->ChangeZLayer (this, theLayerId); | |
2538 | } | |
2539 | ||
2540 | //======================================================================= | |
2541 | //function : GetZLayer | |
2542 | //purpose : | |
2543 | //======================================================================= | |
2544 | ||
2545 | Standard_Integer Graphic3d_Structure::GetZLayer () const | |
2546 | { | |
2547 | return MyStructureManager->GetZLayer (this); | |
2548 | } |