Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created by: NW,JPB,CAL |
2 | // Copyright (c) 1991-1999 Matra Datavision | |
973c2be1 | 3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
2831708b | 16 | #include <Graphic3d_Structure.hxx> |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <Bnd_Box.hxx> |
19 | #include <gp_Pnt.hxx> | |
42cf5bc1 | 20 | #include <Graphic3d_DataStructureManager.hxx> |
7fd59977 | 21 | #include <Graphic3d_GraphicDriver.hxx> |
42cf5bc1 | 22 | #include <Graphic3d_Group.hxx> |
7fd59977 | 23 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
42cf5bc1 | 24 | #include <Graphic3d_MapOfStructure.hxx> |
42cf5bc1 | 25 | #include <Graphic3d_PriorityDefinitionError.hxx> |
42cf5bc1 | 26 | #include <Graphic3d_StructureDefinitionError.hxx> |
27 | #include <Graphic3d_StructureManager.hxx> | |
42cf5bc1 | 28 | #include <Graphic3d_TransformError.hxx> |
29 | #include <Graphic3d_Vector.hxx> | |
7fd59977 | 30 | #include <Quantity_Color.hxx> |
42cf5bc1 | 31 | #include <Standard_Type.hxx> |
7fd59977 | 32 | |
2831708b | 33 | #include "Graphic3d_Structure.pxx" |
34 | ||
63bcc448 | 35 | #include <stdio.h> |
2831708b | 36 | |
92efcf78 | 37 | IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Structure,MMgt_TShared) |
38 | ||
63bcc448 | 39 | //============================================================================= |
40 | //function : Graphic3d_Structure | |
41 | //purpose : | |
42 | //============================================================================= | |
43 | Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager) | |
44 | : myStructureManager (theManager.operator->()), | |
45 | myFirstStructureManager (theManager.operator->()), | |
46 | myComputeVisual (Graphic3d_TOS_ALL), | |
63bcc448 | 47 | myOwner (NULL), |
48 | myVisual (Graphic3d_TOS_ALL) | |
7fd59977 | 49 | { |
c357e426 | 50 | myCStructure = theManager->GraphicDriver()->CreateStructure (theManager); |
7fd59977 | 51 | } |
52 | ||
679ecdee | 53 | //============================================================================= |
54 | //function : Graphic3d_Structure | |
55 | //purpose : | |
56 | //============================================================================= | |
57 | Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManager)& theManager, | |
58 | const Handle(Graphic3d_Structure)& thePrs) | |
59 | : myStructureManager (theManager.operator->()), | |
60 | myFirstStructureManager (theManager.operator->()), | |
61 | myComputeVisual (thePrs->myComputeVisual), | |
679ecdee | 62 | myOwner (thePrs->myOwner), |
63 | myVisual (thePrs->myVisual) | |
64 | { | |
65 | myCStructure = thePrs->myCStructure->ShadowLink (theManager); | |
679ecdee | 66 | } |
67 | ||
63bcc448 | 68 | //============================================================================= |
e6f550da | 69 | //function : ~Graphic3d_Structure |
63bcc448 | 70 | //purpose : |
71 | //============================================================================= | |
e6f550da | 72 | Graphic3d_Structure::~Graphic3d_Structure() |
63bcc448 | 73 | { |
74 | // as myFirstStructureManager can be already destroyed, | |
bbf32d01 | 75 | // avoid attempts to access it |
63bcc448 | 76 | myFirstStructureManager = NULL; |
77 | Remove(); | |
7fd59977 | 78 | } |
79 | ||
63bcc448 | 80 | //============================================================================= |
81 | //function : Clear | |
82 | //purpose : | |
83 | //============================================================================= | |
84 | void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction) | |
98178592 A |
85 | { |
86 | if (IsDeleted()) return; | |
7fd59977 | 87 | |
98178592 | 88 | // clean groups in graphics driver at first |
63bcc448 | 89 | GraphicClear (theWithDestruction); |
7fd59977 | 90 | |
b64d84be | 91 | myCStructure->ContainsFacet = 0; |
63bcc448 | 92 | myStructureManager->Clear (this, theWithDestruction); |
7fd59977 | 93 | |
50d06d8f | 94 | Update (true); |
7fd59977 | 95 | } |
96 | ||
b7cd4ba7 | 97 | //======================================================================= |
98 | //function : CalculateBoundBox | |
99 | //purpose : Calculates AABB of a structure. | |
100 | //======================================================================= | |
101 | void Graphic3d_Structure::CalculateBoundBox() | |
102 | { | |
7c3ef2f7 | 103 | Graphic3d_BndBox3d aBox; |
b7cd4ba7 | 104 | addTransformed (aBox, Standard_True); |
7c3ef2f7 | 105 | myCStructure->ChangeBoundingBox() = aBox; |
b7cd4ba7 | 106 | } |
107 | ||
63bcc448 | 108 | //============================================================================= |
109 | //function : Remove | |
110 | //purpose : | |
111 | //============================================================================= | |
112 | void Graphic3d_Structure::Remove() | |
113 | { | |
114 | if (IsDeleted()) return; | |
98178592 | 115 | |
6c8126b5 A |
116 | // clean groups in graphics driver at first; this is also should be done |
117 | // to avoid unwanted group cleaning in group's destructor | |
118 | // Pass Standard_False to Clear(..) method to avoid updating in | |
119 | // structure manager, it isn't necessary, besides of it structure manager | |
120 | // could be already destroyed and invalid pointers used in structure; | |
b64d84be | 121 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) |
122 | { | |
123 | aGroupIter.ChangeValue()->Clear (Standard_False); | |
124 | } | |
98178592 | 125 | |
7fd59977 | 126 | Standard_Address APtr = (void *) this; |
81bba717 | 127 | // It is necessary to remove the eventual pointer on the structure |
128 | // that can be destroyed, in the list of descendants | |
b64d84be | 129 | // of ancestors of this structure and in the list of ancestors |
81bba717 | 130 | // of descendants of the same structure. |
7fd59977 | 131 | |
602d1ead | 132 | for (Standard_Integer aStructIdx = 1, aNbDesc = myDescendants.Size(); aStructIdx <= aNbDesc; ++aStructIdx) |
63bcc448 | 133 | { |
602d1ead | 134 | ((Graphic3d_Structure *)myDescendants.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_ANCESTOR); |
63bcc448 | 135 | } |
7fd59977 | 136 | |
602d1ead | 137 | for (Standard_Integer aStructIdx = 1, aNbAnces = myAncestors.Size(); aStructIdx <= aNbAnces; ++aStructIdx) |
63bcc448 | 138 | { |
602d1ead | 139 | ((Graphic3d_Structure *)myAncestors.FindKey (aStructIdx))->Remove (APtr, Graphic3d_TOC_DESCENDANT); |
63bcc448 | 140 | } |
7fd59977 | 141 | |
81bba717 | 142 | // Destruction of me in the graphic library |
63bcc448 | 143 | const Standard_Integer aStructId = myCStructure->Id; |
016e5959 | 144 | myCStructure->GraphicDriver()->RemoveIdentification(aStructId); |
63bcc448 | 145 | myCStructure->GraphicDriver()->RemoveStructure (myCStructure); |
146 | myCStructure.Nullify(); | |
7fd59977 | 147 | } |
148 | ||
63bcc448 | 149 | //============================================================================= |
150 | //function : Display | |
151 | //purpose : | |
152 | //============================================================================= | |
153 | void Graphic3d_Structure::Display() | |
154 | { | |
155 | if (IsDeleted()) return; | |
7fd59977 | 156 | |
63bcc448 | 157 | if (!myCStructure->stick) |
158 | { | |
159 | myCStructure->stick = 1; | |
160 | myStructureManager->Display (this); | |
7fd59977 | 161 | } |
162 | ||
a1954302 | 163 | if (myCStructure->visible != 1) |
164 | { | |
165 | myCStructure->visible = 1; | |
166 | myCStructure->OnVisibilityChanged(); | |
167 | } | |
7fd59977 | 168 | } |
169 | ||
b7cd4ba7 | 170 | //============================================================================= |
171 | //function : SetIsForHighlight | |
172 | //purpose : | |
173 | //============================================================================= | |
174 | void Graphic3d_Structure::SetIsForHighlight (const Standard_Boolean isForHighlight) | |
175 | { | |
176 | myCStructure->IsForHighlight = isForHighlight; | |
177 | } | |
178 | ||
63bcc448 | 179 | //============================================================================= |
180 | //function : SetDisplayPriority | |
181 | //purpose : | |
182 | //============================================================================= | |
183 | void Graphic3d_Structure::SetDisplayPriority (const Standard_Integer thePriority) | |
184 | { | |
185 | if (IsDeleted() | |
186 | || thePriority == myCStructure->Priority) | |
187 | { | |
188 | return; | |
189 | } | |
7fd59977 | 190 | |
63bcc448 | 191 | myCStructure->PreviousPriority = myCStructure->Priority; |
192 | myCStructure->Priority = thePriority; | |
7fd59977 | 193 | |
63bcc448 | 194 | if (myCStructure->Priority != myCStructure->PreviousPriority) |
195 | { | |
196 | Graphic3d_PriorityDefinitionError_Raise_if ((myCStructure->Priority > Structure_MAX_PRIORITY) | |
197 | || (myCStructure->Priority < Structure_MIN_PRIORITY), | |
198 | "Bad value for StructurePriority"); | |
199 | if (myCStructure->stick) | |
200 | { | |
201 | myStructureManager->ChangeDisplayPriority (this, myCStructure->PreviousPriority, myCStructure->Priority); | |
202 | } | |
7fd59977 | 203 | } |
7fd59977 | 204 | } |
205 | ||
63bcc448 | 206 | //============================================================================= |
207 | //function : ResetDisplayPriority | |
208 | //purpose : | |
209 | //============================================================================= | |
210 | void Graphic3d_Structure::ResetDisplayPriority() | |
211 | { | |
212 | if (IsDeleted() | |
213 | || myCStructure->Priority == myCStructure->PreviousPriority) | |
214 | { | |
215 | return; | |
7fd59977 | 216 | } |
217 | ||
63bcc448 | 218 | const Standard_Integer aPriority = myCStructure->Priority; |
219 | myCStructure->Priority = myCStructure->PreviousPriority; | |
220 | if (myCStructure->stick) | |
221 | { | |
222 | myStructureManager->ChangeDisplayPriority (this, aPriority, myCStructure->Priority); | |
223 | } | |
7fd59977 | 224 | } |
7fd59977 | 225 | |
63bcc448 | 226 | //============================================================================= |
227 | //function : DisplayPriority | |
228 | //purpose : | |
229 | //============================================================================= | |
230 | Standard_Integer Graphic3d_Structure::DisplayPriority() const | |
231 | { | |
232 | return myCStructure->Priority; | |
7fd59977 | 233 | } |
234 | ||
63bcc448 | 235 | //============================================================================= |
236 | //function : Erase | |
237 | //purpose : | |
238 | //============================================================================= | |
239 | void Graphic3d_Structure::Erase() | |
240 | { | |
241 | if (IsDeleted()) | |
242 | { | |
243 | return; | |
7fd59977 | 244 | } |
245 | ||
63bcc448 | 246 | if (myCStructure->stick) |
247 | { | |
248 | myCStructure->stick = 0; | |
249 | myStructureManager->Erase (this); | |
250 | } | |
7fd59977 | 251 | } |
252 | ||
63bcc448 | 253 | //============================================================================= |
254 | //function : Highlight | |
255 | //purpose : | |
256 | //============================================================================= | |
8e5fb5ea | 257 | void Graphic3d_Structure::Highlight (const Handle(Graphic3d_HighlightStyle)& theStyle, |
258 | const Standard_Boolean theToUpdateMgr) | |
63bcc448 | 259 | { |
260 | if (IsDeleted()) | |
261 | { | |
262 | return; | |
263 | } | |
7fd59977 | 264 | |
81bba717 | 265 | // Highlight on already Highlighted structure. |
63bcc448 | 266 | if (myCStructure->highlight) |
267 | { | |
268 | Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode(); | |
269 | if (anUpdateMode == Aspect_TOU_WAIT) | |
270 | { | |
271 | UnHighlight(); | |
272 | } | |
273 | else | |
274 | { | |
275 | // To avoid call of method : Update() | |
81bba717 | 276 | // Not useful and can be costly. |
63bcc448 | 277 | myStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
278 | UnHighlight(); | |
279 | myStructureManager->SetUpdateMode (anUpdateMode); | |
7fd59977 | 280 | } |
281 | } | |
282 | ||
63bcc448 | 283 | SetDisplayPriority (Structure_MAX_PRIORITY - 1); |
7fd59977 | 284 | |
8e5fb5ea | 285 | myCStructure->GraphicHighlight (theStyle, this); |
7fd59977 | 286 | |
a1954302 | 287 | if (!theToUpdateMgr) |
63bcc448 | 288 | { |
289 | return; | |
290 | } | |
7fd59977 | 291 | |
a1954302 | 292 | if (myCStructure->stick) |
63bcc448 | 293 | { |
8e5fb5ea | 294 | myStructureManager->Highlight (this); |
7fd59977 | 295 | } |
296 | ||
a1954302 | 297 | Update(); |
7fd59977 | 298 | } |
299 | ||
63bcc448 | 300 | //============================================================================= |
301 | //function : SetVisible | |
302 | //purpose : | |
303 | //============================================================================= | |
304 | void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue) | |
305 | { | |
306 | if (IsDeleted()) return; | |
7fd59977 | 307 | |
a1954302 | 308 | const unsigned isVisible = theValue ? 1 : 0; |
309 | if (myCStructure->visible == isVisible) | |
63bcc448 | 310 | { |
a1954302 | 311 | return; |
63bcc448 | 312 | } |
a1954302 | 313 | |
314 | myCStructure->visible = isVisible; | |
315 | myCStructure->OnVisibilityChanged(); | |
50d06d8f | 316 | Update (true); |
7fd59977 | 317 | } |
318 | ||
63bcc448 | 319 | //============================================================================= |
320 | //function : UnHighlight | |
321 | //purpose : | |
322 | //============================================================================= | |
323 | void Graphic3d_Structure::UnHighlight() | |
324 | { | |
325 | if (IsDeleted()) return; | |
7fd59977 | 326 | |
63bcc448 | 327 | if (myCStructure->highlight) |
328 | { | |
329 | myCStructure->highlight = 0; | |
7fd59977 | 330 | |
8e5fb5ea | 331 | myCStructure->GraphicUnhighlight(); |
63bcc448 | 332 | myStructureManager->UnHighlight (this); |
7fd59977 | 333 | |
7fd59977 | 334 | ResetDisplayPriority(); |
63bcc448 | 335 | Update(); |
7fd59977 | 336 | } |
7fd59977 | 337 | } |
338 | ||
63bcc448 | 339 | //============================================================================= |
8e5fb5ea | 340 | //function : HighlightStyle |
63bcc448 | 341 | //purpose : |
342 | //============================================================================= | |
8e5fb5ea | 343 | const Handle(Graphic3d_HighlightStyle)& Graphic3d_Structure::HighlightStyle() const |
63bcc448 | 344 | { |
8e5fb5ea | 345 | return myCStructure->HighlightStyle(); |
7fd59977 | 346 | } |
347 | ||
63bcc448 | 348 | //============================================================================= |
349 | //function : IsDisplayed | |
350 | //purpose : | |
351 | //============================================================================= | |
352 | Standard_Boolean Graphic3d_Structure::IsDisplayed() const | |
353 | { | |
354 | return myCStructure->stick ? Standard_True : Standard_False; | |
7fd59977 | 355 | } |
356 | ||
63bcc448 | 357 | //============================================================================= |
358 | //function : IsDeleted | |
359 | //purpose : | |
360 | //============================================================================= | |
361 | Standard_Boolean Graphic3d_Structure::IsDeleted() const | |
362 | { | |
363 | return myCStructure.IsNull(); | |
7fd59977 | 364 | } |
365 | ||
63bcc448 | 366 | //============================================================================= |
367 | //function : IsHighlighted | |
368 | //purpose : | |
369 | //============================================================================= | |
370 | Standard_Boolean Graphic3d_Structure::IsHighlighted() const | |
371 | { | |
372 | return myCStructure->highlight ? Standard_True : Standard_False; | |
7fd59977 | 373 | } |
374 | ||
63bcc448 | 375 | //============================================================================= |
376 | //function : IsVisible | |
377 | //purpose : | |
378 | //============================================================================= | |
379 | Standard_Boolean Graphic3d_Structure::IsVisible() const | |
380 | { | |
381 | return myCStructure->visible ? Standard_True : Standard_False; | |
7fd59977 | 382 | } |
383 | ||
63bcc448 | 384 | //============================================================================= |
385 | //function : IsTransformed | |
386 | //purpose : | |
387 | //============================================================================= | |
388 | Standard_Boolean Graphic3d_Structure::IsTransformed() const | |
389 | { | |
1f7f5a90 | 390 | return !myCStructure->Transformation().IsNull() |
391 | && myCStructure->Transformation()->Form() != gp_Identity; | |
7fd59977 | 392 | } |
393 | ||
63bcc448 | 394 | //============================================================================= |
395 | //function : ContainsFacet | |
396 | //purpose : | |
397 | //============================================================================= | |
398 | Standard_Boolean Graphic3d_Structure::ContainsFacet() const | |
399 | { | |
400 | if (IsDeleted()) | |
401 | { | |
402 | return Standard_False; | |
403 | } | |
404 | else if (myCStructure->ContainsFacet > 0) | |
405 | { | |
406 | // if one of groups contains at least one facet, the structure contains it too | |
407 | return Standard_True; | |
408 | } | |
7fd59977 | 409 | |
63bcc448 | 410 | // stop at the first descendant containing at least one facet |
602d1ead | 411 | for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) |
63bcc448 | 412 | { |
602d1ead | 413 | if (((const Graphic3d_Structure *)anIter.Value())->ContainsFacet()) |
63bcc448 | 414 | { |
415 | return Standard_True; | |
416 | } | |
417 | } | |
418 | return Standard_False; | |
7fd59977 | 419 | } |
420 | ||
63bcc448 | 421 | //============================================================================= |
422 | //function : IsEmpty | |
423 | //purpose : | |
424 | //============================================================================= | |
425 | Standard_Boolean Graphic3d_Structure::IsEmpty() const | |
426 | { | |
427 | if (IsDeleted()) | |
428 | { | |
429 | return Standard_True; | |
430 | } | |
7fd59977 | 431 | |
63bcc448 | 432 | // structure is empty: |
433 | // - if all these groups are empty | |
434 | // - or if all groups are empty and all their descendants are empty | |
435 | // - or if all its descendants are empty | |
b64d84be | 436 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) |
63bcc448 | 437 | { |
b64d84be | 438 | if (!aGroupIter.Value()->IsEmpty()) |
63bcc448 | 439 | { |
440 | return Standard_False; | |
441 | } | |
442 | } | |
7fd59977 | 443 | |
63bcc448 | 444 | // stop at the first non-empty descendant |
602d1ead | 445 | for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) |
63bcc448 | 446 | { |
602d1ead | 447 | if (!((const Graphic3d_Structure* )anIter.Value())->IsEmpty()) |
63bcc448 | 448 | { |
449 | return Standard_False; | |
450 | } | |
451 | } | |
452 | return Standard_True; | |
7fd59977 | 453 | } |
454 | ||
63bcc448 | 455 | //============================================================================= |
456 | //function : GroupsWithFacet | |
457 | //purpose : | |
458 | //============================================================================= | |
459 | void Graphic3d_Structure::GroupsWithFacet (const Standard_Integer theDelta) | |
460 | { | |
461 | myCStructure->ContainsFacet = myCStructure->ContainsFacet + theDelta; | |
462 | if (myCStructure->ContainsFacet < 0) | |
463 | { | |
464 | myCStructure->ContainsFacet = 0; | |
465 | } | |
7fd59977 | 466 | } |
467 | ||
63bcc448 | 468 | //============================================================================= |
469 | //function : Compute | |
470 | //purpose : | |
471 | //============================================================================= | |
eb4320f2 | 472 | void Graphic3d_Structure::Compute() |
473 | { | |
474 | // Implemented by Presentation | |
475 | } | |
476 | ||
63bcc448 | 477 | //============================================================================= |
478 | //function : Compute | |
479 | //purpose : | |
480 | //============================================================================= | |
481 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& ) | |
482 | { | |
7fd59977 | 483 | // Implemented by Presentation |
484 | return this; | |
485 | } | |
486 | ||
63bcc448 | 487 | //============================================================================= |
488 | //function : Compute | |
489 | //purpose : | |
490 | //============================================================================= | |
491 | Handle(Graphic3d_Structure) Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , | |
1f7f5a90 | 492 | const Handle(Geom_Transformation)& ) |
63bcc448 | 493 | { |
7fd59977 | 494 | // Implemented by Presentation |
495 | return this; | |
496 | } | |
497 | ||
63bcc448 | 498 | //============================================================================= |
499 | //function : Compute | |
500 | //purpose : | |
501 | //============================================================================= | |
502 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , | |
503 | Handle(Graphic3d_Structure)& ) | |
504 | { | |
7fd59977 | 505 | // Implemented by Presentation |
506 | } | |
507 | ||
63bcc448 | 508 | //============================================================================= |
509 | //function : Compute | |
510 | //purpose : | |
511 | //============================================================================= | |
512 | void Graphic3d_Structure::Compute (const Handle(Graphic3d_DataStructureManager)& , | |
1f7f5a90 | 513 | const Handle(Geom_Transformation)& , |
63bcc448 | 514 | Handle(Graphic3d_Structure)& ) |
515 | { | |
7fd59977 | 516 | // Implemented by Presentation |
517 | } | |
518 | ||
63bcc448 | 519 | //============================================================================= |
520 | //function : ReCompute | |
521 | //purpose : | |
522 | //============================================================================= | |
523 | void Graphic3d_Structure::ReCompute() | |
524 | { | |
525 | myStructureManager->ReCompute (this); | |
7fd59977 | 526 | } |
527 | ||
63bcc448 | 528 | //============================================================================= |
529 | //function : ReCompute | |
530 | //purpose : | |
531 | //============================================================================= | |
532 | void Graphic3d_Structure::ReCompute (const Handle(Graphic3d_DataStructureManager)& theProjector) | |
533 | { | |
534 | myStructureManager->ReCompute (this, theProjector); | |
7fd59977 | 535 | } |
536 | ||
197ac94e | 537 | //============================================================================= |
538 | //function : SetInfiniteState | |
539 | //purpose : | |
540 | //============================================================================= | |
541 | void Graphic3d_Structure::SetInfiniteState (const Standard_Boolean theToSet) | |
542 | { | |
63bcc448 | 543 | myCStructure->IsInfinite = theToSet ? 1 : 0; |
7fd59977 | 544 | } |
545 | ||
63bcc448 | 546 | //============================================================================= |
547 | //function : IsInfinite | |
548 | //purpose : | |
549 | //============================================================================= | |
550 | Standard_Boolean Graphic3d_Structure::IsInfinite() const | |
551 | { | |
552 | return IsDeleted() | |
553 | || myCStructure->IsInfinite; | |
7fd59977 | 554 | } |
555 | ||
63bcc448 | 556 | //============================================================================= |
557 | //function : GraphicClear | |
558 | //purpose : | |
559 | //============================================================================= | |
560 | void Graphic3d_Structure::GraphicClear (const Standard_Boolean theWithDestruction) | |
5e27df78 | 561 | { |
b64d84be | 562 | if (myCStructure.IsNull()) |
5e27df78 | 563 | { |
b64d84be | 564 | return; |
5e27df78 | 565 | } |
7fd59977 | 566 | |
b64d84be | 567 | // clean and empty each group |
568 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) | |
5e27df78 | 569 | { |
b64d84be | 570 | aGroupIter.ChangeValue()->Clear(); |
571 | } | |
572 | if (!theWithDestruction) | |
573 | { | |
574 | return; | |
575 | } | |
7fd59977 | 576 | |
b64d84be | 577 | while (!myCStructure->Groups().IsEmpty()) |
578 | { | |
579 | Handle(Graphic3d_Group) aGroup = myCStructure->Groups().First(); | |
580 | aGroup->Remove(); | |
7fd59977 | 581 | } |
b64d84be | 582 | myCStructure->Clear(); |
7fd59977 | 583 | } |
584 | ||
63bcc448 | 585 | //============================================================================= |
586 | //function : GraphicConnect | |
587 | //purpose : | |
588 | //============================================================================= | |
bf75be98 | 589 | void Graphic3d_Structure::GraphicConnect (const Handle(Graphic3d_Structure)& theDaughter) |
590 | { | |
63bcc448 | 591 | myCStructure->Connect (*theDaughter->myCStructure); |
7fd59977 | 592 | } |
593 | ||
63bcc448 | 594 | //============================================================================= |
595 | //function : GraphicDisconnect | |
596 | //purpose : | |
597 | //============================================================================= | |
bf75be98 | 598 | void Graphic3d_Structure::GraphicDisconnect (const Handle(Graphic3d_Structure)& theDaughter) |
599 | { | |
63bcc448 | 600 | myCStructure->Disconnect (*theDaughter->myCStructure); |
7fd59977 | 601 | } |
602 | ||
63bcc448 | 603 | //============================================================================= |
604 | //function : Groups | |
605 | //purpose : | |
606 | //============================================================================= | |
607 | const Graphic3d_SequenceOfGroup& Graphic3d_Structure::Groups() const | |
608 | { | |
b64d84be | 609 | return myCStructure->Groups(); |
7fd59977 | 610 | } |
611 | ||
63bcc448 | 612 | //============================================================================= |
613 | //function : NumberOfGroups | |
614 | //purpose : | |
615 | //============================================================================= | |
616 | Standard_Integer Graphic3d_Structure::NumberOfGroups() const | |
617 | { | |
b64d84be | 618 | return myCStructure->Groups().Length(); |
7fd59977 | 619 | } |
620 | ||
63bcc448 | 621 | //============================================================================= |
622 | //function : SetVisual | |
623 | //purpose : | |
624 | //============================================================================= | |
625 | void Graphic3d_Structure::SetVisual (const Graphic3d_TypeOfStructure theVisual) | |
626 | { | |
627 | if (IsDeleted() | |
628 | || myVisual == theVisual) | |
629 | { | |
630 | return; | |
7fd59977 | 631 | } |
7fd59977 | 632 | |
63bcc448 | 633 | if (!myCStructure->stick) |
634 | { | |
635 | myVisual = theVisual; | |
636 | SetComputeVisual (theVisual); | |
637 | } | |
638 | else | |
639 | { | |
640 | Aspect_TypeOfUpdate anUpdateMode = myStructureManager->UpdateMode(); | |
641 | if (anUpdateMode == Aspect_TOU_WAIT) | |
642 | { | |
643 | Erase(); | |
644 | myVisual = theVisual; | |
645 | SetComputeVisual (theVisual); | |
646 | Display(); | |
7fd59977 | 647 | } |
648 | else { | |
81bba717 | 649 | // To avoid calling method : Update () |
650 | // Not useful and can be costly. | |
63bcc448 | 651 | myStructureManager->SetUpdateMode (Aspect_TOU_WAIT); |
652 | Erase(); | |
653 | myVisual = theVisual; | |
654 | SetComputeVisual (theVisual); | |
655 | myStructureManager->SetUpdateMode (anUpdateMode); | |
656 | Display(); | |
7fd59977 | 657 | } |
658 | } | |
7fd59977 | 659 | } |
660 | ||
63bcc448 | 661 | //============================================================================= |
662 | //function : SetZoomLimit | |
663 | //purpose : | |
664 | //============================================================================= | |
665 | void Graphic3d_Structure::SetZoomLimit (const Standard_Real theLimitInf, | |
666 | const Standard_Real theLimitSup) | |
667 | { | |
668 | (void )theLimitInf; | |
669 | (void )theLimitSup; | |
670 | Graphic3d_StructureDefinitionError_Raise_if (theLimitInf <= 0.0, | |
671 | "Bad value for ZoomLimit inf"); | |
672 | Graphic3d_StructureDefinitionError_Raise_if (theLimitSup <= 0.0, | |
673 | "Bad value for ZoomLimit sup"); | |
674 | Graphic3d_StructureDefinitionError_Raise_if (theLimitSup < theLimitInf, | |
675 | "ZoomLimit sup < ZoomLimit inf"); | |
7fd59977 | 676 | } |
677 | ||
63bcc448 | 678 | //============================================================================= |
679 | //function : Visual | |
680 | //purpose : | |
681 | //============================================================================= | |
682 | Graphic3d_TypeOfStructure Graphic3d_Structure::Visual() const | |
683 | { | |
684 | return myVisual; | |
7fd59977 | 685 | } |
686 | ||
63bcc448 | 687 | //============================================================================= |
688 | //function : AcceptConnection | |
689 | //purpose : | |
690 | //============================================================================= | |
691 | Standard_Boolean Graphic3d_Structure::AcceptConnection (const Handle(Graphic3d_Structure)& theStructure1, | |
692 | const Handle(Graphic3d_Structure)& theStructure2, | |
693 | const Graphic3d_TypeOfConnection theType) | |
694 | { | |
7fd59977 | 695 | // cycle detection |
63bcc448 | 696 | Graphic3d_MapOfStructure aSet; |
697 | Graphic3d_Structure::Network (theStructure2, theType, aSet); | |
698 | return !aSet.Contains (theStructure1); | |
7fd59977 | 699 | } |
700 | ||
63bcc448 | 701 | //============================================================================= |
702 | //function : Ancestors | |
703 | //purpose : | |
704 | //============================================================================= | |
705 | void Graphic3d_Structure::Ancestors (Graphic3d_MapOfStructure& theSet) const | |
706 | { | |
602d1ead | 707 | for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myAncestors); anIter.More(); anIter.Next()) |
63bcc448 | 708 | { |
602d1ead | 709 | theSet.Add ((Graphic3d_Structure* )anIter.Value()); |
63bcc448 | 710 | } |
7fd59977 | 711 | } |
712 | ||
63bcc448 | 713 | //============================================================================= |
714 | //function : SetOwner | |
715 | //purpose : | |
716 | //============================================================================= | |
717 | void Graphic3d_Structure::SetOwner (const Standard_Address theOwner) | |
718 | { | |
719 | myOwner = theOwner; | |
7fd59977 | 720 | } |
721 | ||
63bcc448 | 722 | //============================================================================= |
723 | //function : Owner | |
724 | //purpose : | |
725 | //============================================================================= | |
726 | Standard_Address Graphic3d_Structure::Owner() const | |
727 | { | |
728 | return myOwner; | |
7fd59977 | 729 | } |
730 | ||
63bcc448 | 731 | //============================================================================= |
732 | //function : Descendants | |
733 | //purpose : | |
734 | //============================================================================= | |
735 | void Graphic3d_Structure::Descendants (Graphic3d_MapOfStructure& theSet) const | |
736 | { | |
602d1ead | 737 | for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) |
63bcc448 | 738 | { |
602d1ead | 739 | theSet.Add ((Graphic3d_Structure* )anIter.Value()); |
63bcc448 | 740 | } |
7fd59977 | 741 | } |
742 | ||
d4aaad5b | 743 | //============================================================================= |
602d1ead | 744 | //function : AppendAncestor |
d4aaad5b | 745 | //purpose : |
746 | //============================================================================= | |
602d1ead | 747 | Standard_Boolean Graphic3d_Structure::AppendAncestor (const Standard_Address theAncestor) |
d4aaad5b | 748 | { |
602d1ead | 749 | const Standard_Integer aSize = myAncestors.Size(); |
d4aaad5b | 750 | |
602d1ead | 751 | return myAncestors.Add (theAncestor) > aSize; // new object |
d4aaad5b | 752 | } |
753 | ||
754 | //============================================================================= | |
602d1ead | 755 | //function : AppendDescendant |
d4aaad5b | 756 | //purpose : |
757 | //============================================================================= | |
602d1ead | 758 | Standard_Boolean Graphic3d_Structure::AppendDescendant (const Standard_Address theDescendant) |
d4aaad5b | 759 | { |
602d1ead | 760 | const Standard_Integer aSize = myDescendants.Size(); |
d4aaad5b | 761 | |
602d1ead | 762 | return myDescendants.Add (theDescendant) > aSize; // new object |
d4aaad5b | 763 | } |
764 | ||
765 | //============================================================================= | |
602d1ead | 766 | //function : RemoveAncestor |
d4aaad5b | 767 | //purpose : |
768 | //============================================================================= | |
602d1ead | 769 | Standard_Boolean Graphic3d_Structure::RemoveAncestor (const Standard_Address theAncestor) |
d4aaad5b | 770 | { |
602d1ead | 771 | const Standard_Integer anIndex = myAncestors.FindIndex (theAncestor); |
772 | ||
773 | if (anIndex != 0) | |
d4aaad5b | 774 | { |
602d1ead | 775 | myAncestors.Swap (anIndex, myAncestors.Size()); |
776 | myAncestors.RemoveLast(); | |
d4aaad5b | 777 | } |
778 | ||
602d1ead | 779 | return anIndex != 0; // object was found |
d4aaad5b | 780 | } |
781 | ||
782 | //============================================================================= | |
602d1ead | 783 | //function : RemoveDescendant |
d4aaad5b | 784 | //purpose : |
785 | //============================================================================= | |
602d1ead | 786 | Standard_Boolean Graphic3d_Structure::RemoveDescendant (const Standard_Address theDescendant) |
d4aaad5b | 787 | { |
602d1ead | 788 | const Standard_Integer anIndex = myDescendants.FindIndex (theDescendant); |
d4aaad5b | 789 | |
602d1ead | 790 | if (anIndex != 0) |
d4aaad5b | 791 | { |
602d1ead | 792 | myDescendants.Swap (anIndex, myDescendants.Size()); |
793 | myDescendants.RemoveLast(); | |
d4aaad5b | 794 | } |
795 | ||
602d1ead | 796 | return anIndex != 0; // object was found |
d4aaad5b | 797 | } |
798 | ||
63bcc448 | 799 | //============================================================================= |
800 | //function : Connect | |
801 | //purpose : | |
802 | //============================================================================= | |
803 | void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructure, | |
804 | const Graphic3d_TypeOfConnection theType, | |
805 | const Standard_Boolean theWithCheck) | |
806 | { | |
d4aaad5b | 807 | if (IsDeleted()) |
808 | { | |
809 | return; | |
810 | } | |
7fd59977 | 811 | |
63bcc448 | 812 | // cycle detection |
813 | if (theWithCheck | |
814 | && !Graphic3d_Structure::AcceptConnection (this, theStructure, theType)) | |
7fd59977 | 815 | { |
63bcc448 | 816 | return; |
817 | } | |
7fd59977 | 818 | |
d4aaad5b | 819 | const Standard_Address aStructure = theStructure.operator->(); |
820 | ||
821 | if (theType == Graphic3d_TOC_DESCENDANT) | |
63bcc448 | 822 | { |
d4aaad5b | 823 | if (!AppendDescendant (aStructure)) |
7fd59977 | 824 | { |
d4aaad5b | 825 | return; |
826 | } | |
7fd59977 | 827 | |
d4aaad5b | 828 | CalculateBoundBox(); |
829 | theStructure->Connect (this, Graphic3d_TOC_ANCESTOR); | |
7fd59977 | 830 | |
d4aaad5b | 831 | GraphicConnect (theStructure); |
832 | myStructureManager->Connect (this, theStructure); | |
7fd59977 | 833 | |
50d06d8f | 834 | Update (true); |
d4aaad5b | 835 | } |
836 | else // Graphic3d_TOC_ANCESTOR | |
837 | { | |
838 | if (!AppendAncestor (aStructure)) | |
839 | { | |
63bcc448 | 840 | return; |
7fd59977 | 841 | } |
63bcc448 | 842 | |
d4aaad5b | 843 | CalculateBoundBox(); |
844 | theStructure->Connect (this, Graphic3d_TOC_DESCENDANT); | |
63bcc448 | 845 | |
d4aaad5b | 846 | // myStructureManager->Connect is called in case if connection between parent and child |
7fd59977 | 847 | } |
7fd59977 | 848 | } |
849 | ||
63bcc448 | 850 | //============================================================================= |
851 | //function : Disconnect | |
852 | //purpose : | |
853 | //============================================================================= | |
854 | void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStructure) | |
855 | { | |
d4aaad5b | 856 | if (IsDeleted()) |
63bcc448 | 857 | { |
d4aaad5b | 858 | return; |
859 | } | |
7fd59977 | 860 | |
d4aaad5b | 861 | const Standard_Address aStructure = theStructure.operator->(); |
7fd59977 | 862 | |
d4aaad5b | 863 | if (RemoveDescendant (aStructure)) |
864 | { | |
865 | theStructure->Disconnect (this); | |
b7cd4ba7 | 866 | |
d4aaad5b | 867 | GraphicDisconnect (theStructure); |
868 | myStructureManager->Disconnect (this, theStructure); | |
7fd59977 | 869 | |
d4aaad5b | 870 | CalculateBoundBox(); |
50d06d8f | 871 | Update (true); |
d4aaad5b | 872 | } |
873 | else if (RemoveAncestor (aStructure)) | |
63bcc448 | 874 | { |
d4aaad5b | 875 | theStructure->Disconnect (this); |
876 | CalculateBoundBox(); | |
877 | ||
878 | // no call of myStructureManager->Disconnect in case of an ancestor | |
7fd59977 | 879 | } |
7fd59977 | 880 | } |
881 | ||
63bcc448 | 882 | //============================================================================= |
883 | //function : DisconnectAll | |
884 | //purpose : | |
885 | //============================================================================= | |
886 | void Graphic3d_Structure::DisconnectAll (const Graphic3d_TypeOfConnection theType) | |
887 | { | |
888 | if (IsDeleted()) return; | |
7fd59977 | 889 | |
63bcc448 | 890 | switch (theType) |
7fd59977 | 891 | { |
63bcc448 | 892 | case Graphic3d_TOC_DESCENDANT: |
893 | { | |
602d1ead | 894 | for (Standard_Integer anIdx = 1, aLength = myDescendants.Size(); anIdx <= aLength; ++anIdx) |
63bcc448 | 895 | { |
896 | // Value (1) instead of Value (i) as myDescendants | |
897 | // is modified by : | |
898 | // Graphic3d_Structure::Disconnect (AStructure) | |
899 | // that takes AStructure from myDescendants | |
602d1ead | 900 | ((Graphic3d_Structure* )(myDescendants.FindKey (1)))->Disconnect (this); |
63bcc448 | 901 | } |
902 | break; | |
903 | } | |
904 | case Graphic3d_TOC_ANCESTOR: | |
905 | { | |
602d1ead | 906 | for (Standard_Integer anIdx = 1, aLength = myAncestors.Size(); anIdx <= aLength; ++anIdx) |
63bcc448 | 907 | { |
908 | // Value (1) instead of Value (i) as myAncestors | |
909 | // is modified by : | |
910 | // Graphic3d_Structure::Disconnect (AStructure) | |
911 | // that takes AStructure from myAncestors | |
602d1ead | 912 | ((Graphic3d_Structure* )(myAncestors.FindKey (1)))->Disconnect (this); |
63bcc448 | 913 | } |
914 | break; | |
915 | } | |
7fd59977 | 916 | } |
7fd59977 | 917 | } |
918 | ||
63bcc448 | 919 | //============================================================================= |
920 | //function : SetTransform | |
921 | //purpose : | |
922 | //============================================================================= | |
1f7f5a90 | 923 | void Graphic3d_Structure::SetTransformation (const Handle(Geom_Transformation)& theTrsf) |
63bcc448 | 924 | { |
925 | if (IsDeleted()) return; | |
7fd59977 | 926 | |
1f7f5a90 | 927 | const Standard_Boolean wasTransformed = IsTransformed(); |
928 | ||
929 | if (!theTrsf.IsNull() | |
930 | && theTrsf->Trsf().Form() == gp_Identity) | |
63bcc448 | 931 | { |
1f7f5a90 | 932 | myCStructure->SetTransformation (Handle(Geom_Transformation)()); |
7fd59977 | 933 | } |
1f7f5a90 | 934 | else |
63bcc448 | 935 | { |
1f7f5a90 | 936 | myCStructure->SetTransformation (theTrsf); |
7fd59977 | 937 | } |
938 | ||
63bcc448 | 939 | // If transformation, no validation of hidden already calculated parts |
6bd94e0d | 940 | if (IsTransformed() || (!IsTransformed() && wasTransformed)) |
63bcc448 | 941 | { |
942 | ReCompute(); | |
943 | } | |
7fd59977 | 944 | |
1f7f5a90 | 945 | myStructureManager->SetTransform (this, theTrsf); |
7fd59977 | 946 | |
50d06d8f | 947 | Update (true); |
7fd59977 | 948 | } |
949 | ||
197ac94e | 950 | //============================================================================= |
951 | //function : MinMaxValues | |
952 | //purpose : | |
953 | //============================================================================= | |
ed063270 | 954 | Bnd_Box Graphic3d_Structure::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const |
197ac94e | 955 | { |
7c3ef2f7 | 956 | Graphic3d_BndBox3d aBox; |
b7cd4ba7 | 957 | addTransformed (aBox, theToIgnoreInfiniteFlag); |
7c3ef2f7 | 958 | if (!aBox.IsValid()) |
197ac94e | 959 | { |
7c3ef2f7 | 960 | return Bnd_Box(); |
961 | } | |
962 | ||
963 | Bnd_Box aResult; | |
964 | aResult.Update (aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), | |
965 | aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); | |
966 | ||
967 | Standard_Real aLimMin = ShortRealFirst() + 1.0; | |
968 | Standard_Real aLimMax = ShortRealLast() - 1.0; | |
969 | gp_Pnt aMin = aResult.CornerMin(); | |
970 | gp_Pnt aMax = aResult.CornerMax(); | |
971 | if (aMin.X() < aLimMin && aMin.Y() < aLimMin && aMin.Z() < aLimMin | |
972 | && aMax.X() > aLimMax && aMax.Y() > aLimMax && aMax.Z() > aLimMax) | |
973 | { | |
974 | //For structure which infinite in all three dimensions the Whole bounding box will be returned | |
975 | aResult.SetWhole(); | |
197ac94e | 976 | } |
ed063270 | 977 | return aResult; |
7fd59977 | 978 | } |
979 | ||
63bcc448 | 980 | //============================================================================= |
981 | //function : Identification | |
982 | //purpose : | |
983 | //============================================================================= | |
984 | Standard_Integer Graphic3d_Structure::Identification() const | |
985 | { | |
986 | return myCStructure->Id; | |
7fd59977 | 987 | } |
988 | ||
63bcc448 | 989 | //============================================================================= |
990 | //function : SetTransformPersistence | |
991 | //purpose : | |
992 | //============================================================================= | |
778cd667 | 993 | void Graphic3d_Structure::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers) |
7fd59977 | 994 | { |
778cd667 | 995 | if (IsDeleted()) |
996 | { | |
997 | return; | |
998 | } | |
7fd59977 | 999 | |
778cd667 | 1000 | myCStructure->SetTransformPersistence (theTrsfPers); |
7fd59977 | 1001 | } |
1002 | ||
63bcc448 | 1003 | //============================================================================= |
1004 | //function : Remove | |
1005 | //purpose : | |
1006 | //============================================================================= | |
1007 | void Graphic3d_Structure::Remove (const Standard_Address thePtr, | |
1008 | const Graphic3d_TypeOfConnection theType) | |
1009 | { | |
d4aaad5b | 1010 | if (theType == Graphic3d_TOC_DESCENDANT) |
7fd59977 | 1011 | { |
d4aaad5b | 1012 | RemoveDescendant (thePtr); |
1013 | } | |
1014 | else | |
1015 | { | |
1016 | RemoveAncestor (thePtr); | |
7fd59977 | 1017 | } |
7fd59977 | 1018 | } |
1019 | ||
b64d84be | 1020 | //============================================================================= |
1021 | //function : NewGroup | |
1022 | //purpose : | |
1023 | //============================================================================= | |
1024 | Handle(Graphic3d_Group) Graphic3d_Structure::NewGroup() | |
1025 | { | |
1026 | return myCStructure->NewGroup (this); | |
1027 | } | |
1028 | ||
63bcc448 | 1029 | //============================================================================= |
1030 | //function : Remove | |
1031 | //purpose : | |
1032 | //============================================================================= | |
1033 | void Graphic3d_Structure::Remove (const Handle(Graphic3d_Group)& theGroup) | |
1034 | { | |
b64d84be | 1035 | if (theGroup.IsNull() |
1036 | || theGroup->myStructure != this) | |
63bcc448 | 1037 | { |
b64d84be | 1038 | return; |
63bcc448 | 1039 | } |
b64d84be | 1040 | |
1041 | myCStructure->RemoveGroup (theGroup); | |
1042 | theGroup->myStructure = NULL; | |
7fd59977 | 1043 | } |
1044 | ||
63bcc448 | 1045 | //============================================================================= |
1046 | //function : StructureManager | |
1047 | //purpose : | |
1048 | //============================================================================= | |
1049 | Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const | |
1050 | { | |
1051 | return myStructureManager; | |
7fd59977 | 1052 | } |
1053 | ||
197ac94e | 1054 | //============================================================================= |
b7cd4ba7 | 1055 | //function : minMaxCoord |
197ac94e | 1056 | //purpose : |
1057 | //============================================================================= | |
8d3aa19e | 1058 | Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const |
197ac94e | 1059 | { |
b7cd4ba7 | 1060 | Graphic3d_BndBox4f aBnd; |
b64d84be | 1061 | for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next()) |
197ac94e | 1062 | { |
8d3aa19e | 1063 | aBnd.Combine (aGroupIter.Value()->BoundingBox()); |
197ac94e | 1064 | } |
b7cd4ba7 | 1065 | return aBnd; |
197ac94e | 1066 | } |
1067 | ||
1068 | //============================================================================= | |
b7cd4ba7 | 1069 | //function : addTransformed |
197ac94e | 1070 | //purpose : |
1071 | //============================================================================= | |
7c3ef2f7 | 1072 | void Graphic3d_Structure::getBox (Graphic3d_BndBox3d& theBox, |
0717ddc1 | 1073 | const Standard_Boolean theToIgnoreInfiniteFlag) const |
197ac94e | 1074 | { |
8d3aa19e | 1075 | Graphic3d_BndBox4f aBoxF = minMaxCoord(); |
b7cd4ba7 | 1076 | if (aBoxF.IsValid()) |
197ac94e | 1077 | { |
7c3ef2f7 | 1078 | theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMin().x(), |
0717ddc1 | 1079 | (Standard_Real )aBoxF.CornerMin().y(), |
7c3ef2f7 | 1080 | (Standard_Real )aBoxF.CornerMin().z()), |
1081 | Graphic3d_Vec3d ((Standard_Real )aBoxF.CornerMax().x(), | |
0717ddc1 | 1082 | (Standard_Real )aBoxF.CornerMax().y(), |
7c3ef2f7 | 1083 | (Standard_Real )aBoxF.CornerMax().z())); |
b7cd4ba7 | 1084 | if (IsInfinite() |
1085 | && !theToIgnoreInfiniteFlag) | |
197ac94e | 1086 | { |
7c3ef2f7 | 1087 | const Graphic3d_Vec3d aDiagVec = theBox.CornerMax() - theBox.CornerMin(); |
1088 | if (aDiagVec.SquareModulus() >= 500000.0 * 500000.0) | |
b7cd4ba7 | 1089 | { |
1090 | // bounding borders of infinite line has been calculated as own point in center of this line | |
7c3ef2f7 | 1091 | theBox = Graphic3d_BndBox3d ((theBox.CornerMin() + theBox.CornerMax()) * 0.5); |
b7cd4ba7 | 1092 | } |
1093 | else | |
1094 | { | |
7c3ef2f7 | 1095 | theBox = Graphic3d_BndBox3d (Graphic3d_Vec3d (RealFirst(), RealFirst(), RealFirst()), |
1096 | Graphic3d_Vec3d (RealLast(), RealLast(), RealLast())); | |
b7cd4ba7 | 1097 | return; |
1098 | } | |
197ac94e | 1099 | } |
197ac94e | 1100 | } |
0717ddc1 | 1101 | } |
1102 | ||
1103 | //============================================================================= | |
1104 | //function : addTransformed | |
1105 | //purpose : | |
1106 | //============================================================================= | |
7c3ef2f7 | 1107 | void Graphic3d_Structure::addTransformed (Graphic3d_BndBox3d& theBox, |
0717ddc1 | 1108 | const Standard_Boolean theToIgnoreInfiniteFlag) const |
1109 | { | |
7c3ef2f7 | 1110 | Graphic3d_BndBox3d aCombinedBox, aBox; |
0717ddc1 | 1111 | getBox (aCombinedBox, theToIgnoreInfiniteFlag); |
7fd59977 | 1112 | |
602d1ead | 1113 | for (Graphic3d_IndexedMapOfAddress::Iterator anIter (myDescendants); anIter.More(); anIter.Next()) |
197ac94e | 1114 | { |
602d1ead | 1115 | const Graphic3d_Structure* aStruct = (const Graphic3d_Structure* )anIter.Value(); |
0717ddc1 | 1116 | aStruct->getBox (aBox, theToIgnoreInfiniteFlag); |
1117 | aCombinedBox.Combine (aBox); | |
197ac94e | 1118 | } |
7fd59977 | 1119 | |
0717ddc1 | 1120 | aBox = aCombinedBox; |
b7cd4ba7 | 1121 | if (aBox.IsValid()) |
197ac94e | 1122 | { |
1f7f5a90 | 1123 | if (!myCStructure->Transformation().IsNull()) |
1124 | { | |
1125 | TransformBoundaries (myCStructure->Transformation()->Trsf(), | |
1126 | aBox.CornerMin().x(), aBox.CornerMin().y(), aBox.CornerMin().z(), | |
1127 | aBox.CornerMax().x(), aBox.CornerMax().y(), aBox.CornerMax().z()); | |
1128 | } | |
0717ddc1 | 1129 | |
1130 | // if box is still valid after transformation | |
1131 | if (aBox.IsValid()) | |
1132 | { | |
1133 | theBox.Combine (aBox); | |
1134 | } | |
1135 | else // it was infinite, return untransformed | |
1136 | { | |
1137 | theBox.Combine (aCombinedBox); | |
1138 | } | |
7fd59977 | 1139 | } |
7fd59977 | 1140 | } |
1141 | ||
63bcc448 | 1142 | //============================================================================= |
1143 | //function : Transforms | |
1144 | //purpose : | |
1145 | //============================================================================= | |
1f7f5a90 | 1146 | void Graphic3d_Structure::Transforms (const gp_Trsf& theTrsf, |
63bcc448 | 1147 | const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, |
1148 | Standard_Real& theNewX, Standard_Real& theNewY, Standard_Real& theNewZ) | |
1149 | { | |
1150 | const Standard_Real aRL = RealLast(); | |
1151 | const Standard_Real aRF = RealFirst(); | |
1f7f5a90 | 1152 | theNewX = theX; |
1153 | theNewY = theY; | |
1154 | theNewZ = theZ; | |
63bcc448 | 1155 | if ((theX == aRF) || (theY == aRF) || (theZ == aRF) |
1156 | || (theX == aRL) || (theY == aRL) || (theZ == aRL)) | |
1157 | { | |
1f7f5a90 | 1158 | return; |
7fd59977 | 1159 | } |
7fd59977 | 1160 | |
1f7f5a90 | 1161 | theTrsf.Transforms (theNewX, theNewY, theNewZ); |
7fd59977 | 1162 | } |
1163 | ||
197ac94e | 1164 | //============================================================================= |
1165 | //function : Transforms | |
1166 | //purpose : | |
1167 | //============================================================================= | |
1f7f5a90 | 1168 | void Graphic3d_Structure::TransformBoundaries (const gp_Trsf& theTrsf, |
197ac94e | 1169 | Standard_Real& theXMin, |
1170 | Standard_Real& theYMin, | |
1171 | Standard_Real& theZMin, | |
1172 | Standard_Real& theXMax, | |
1173 | Standard_Real& theYMax, | |
1174 | Standard_Real& theZMax) | |
1175 | { | |
1176 | Standard_Real aXMin, aYMin, aZMin, aXMax, aYMax, aZMax, anU, aV, aW; | |
1177 | ||
1178 | Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMin, aXMin, aYMin, aZMin); | |
1179 | Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMax, aXMax, aYMax, aZMax); | |
1180 | ||
1181 | Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMin, theZMax, anU, aV, aW); | |
1182 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1183 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1184 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1185 | ||
1186 | Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMax, anU, aV, aW); | |
1187 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1188 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1189 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1190 | ||
1191 | Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMin, theZMin, anU, aV, aW); | |
1192 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1193 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1194 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1195 | ||
1196 | Graphic3d_Structure::Transforms (theTrsf, theXMax, theYMax, theZMin, anU, aV, aW); | |
1197 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1198 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1199 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1200 | ||
1201 | Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMax, anU, aV, aW); | |
1202 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1203 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1204 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1205 | ||
1206 | Graphic3d_Structure::Transforms (theTrsf, theXMin, theYMax, theZMin, anU, aV, aW); | |
1207 | aXMin = Min (anU, aXMin); aXMax = Max (anU, aXMax); | |
1208 | aYMin = Min (aV, aYMin); aYMax = Max (aV, aYMax); | |
1209 | aZMin = Min (aW, aZMin); aZMax = Max (aW, aZMax); | |
1210 | ||
1211 | theXMin = aXMin; | |
1212 | theYMin = aYMin; | |
1213 | theZMin = aZMin; | |
1214 | theXMax = aXMax; | |
1215 | theYMax = aYMax; | |
1216 | theZMax = aZMax; | |
1217 | } | |
1218 | ||
63bcc448 | 1219 | //============================================================================= |
1220 | //function : Network | |
1221 | //purpose : | |
1222 | //============================================================================= | |
1223 | void Graphic3d_Structure::Network (const Handle(Graphic3d_Structure)& theStructure, | |
1224 | const Graphic3d_TypeOfConnection theType, | |
1225 | Graphic3d_MapOfStructure& theSet) | |
1226 | { | |
1227 | Graphic3d_MapOfStructure aSetD, aSetA; | |
1228 | theStructure->Descendants (aSetD); | |
1229 | theStructure->Ancestors (aSetA); | |
1230 | theSet.Add (theStructure); | |
1231 | switch (theType) | |
7fd59977 | 1232 | { |
63bcc448 | 1233 | case Graphic3d_TOC_DESCENDANT: |
1234 | for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetD); anIter.More(); anIter.Next()) | |
1235 | { | |
1236 | Graphic3d_Structure::Network (anIter.Key(), theType, theSet); | |
1237 | } | |
1238 | break; | |
1239 | case Graphic3d_TOC_ANCESTOR: | |
1240 | for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSetA); anIter.More(); anIter.Next()) | |
1241 | { | |
1242 | Graphic3d_Structure::Network (anIter.Key (), theType, theSet); | |
1243 | } | |
1244 | break; | |
7fd59977 | 1245 | } |
7fd59977 | 1246 | } |
1247 | ||
63bcc448 | 1248 | //============================================================================= |
1249 | //function : PrintNetwork | |
1250 | //purpose : | |
1251 | //============================================================================= | |
1252 | void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theStructure, | |
1253 | const Graphic3d_TypeOfConnection theType) | |
7fd59977 | 1254 | { |
63bcc448 | 1255 | Graphic3d_MapOfStructure aSet; |
1256 | Graphic3d_Structure::Network (theStructure, theType, aSet); | |
1257 | for (Graphic3d_MapIteratorOfMapOfStructure anIter (aSet); anIter.More(); anIter.Next()) | |
1258 | { | |
1259 | std::cout << "\tIdent " << (anIter.Key())->Identification () << "\n"; | |
7fd59977 | 1260 | } |
63bcc448 | 1261 | std::cout << std::flush; |
7fd59977 | 1262 | } |
1263 | ||
63bcc448 | 1264 | //============================================================================= |
1265 | //function : Update | |
1266 | //purpose : | |
1267 | //============================================================================= | |
50d06d8f | 1268 | void Graphic3d_Structure::Update (const bool theUpdateLayer) const |
7fd59977 | 1269 | { |
63bcc448 | 1270 | if (IsDeleted()) |
1271 | { | |
1272 | return; | |
1273 | } | |
7fd59977 | 1274 | |
50d06d8f | 1275 | myStructureManager->Update (myStructureManager->UpdateMode(), |
1276 | theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN); | |
63bcc448 | 1277 | } |
7fd59977 | 1278 | |
63bcc448 | 1279 | //============================================================================= |
1280 | //function : GraphicTransform | |
1281 | //purpose : | |
1282 | //============================================================================= | |
1f7f5a90 | 1283 | void Graphic3d_Structure::GraphicTransform (const Handle(Geom_Transformation)& theTrsf) |
63bcc448 | 1284 | { |
1f7f5a90 | 1285 | myCStructure->SetTransformation (theTrsf); |
7fd59977 | 1286 | } |
1287 | ||
63bcc448 | 1288 | //============================================================================= |
1289 | //function : ComputeVisual | |
1290 | //purpose : | |
1291 | //============================================================================= | |
1292 | Graphic3d_TypeOfStructure Graphic3d_Structure::ComputeVisual() const | |
1293 | { | |
1294 | return myComputeVisual; | |
7fd59977 | 1295 | } |
1296 | ||
63bcc448 | 1297 | //============================================================================= |
1298 | //function : SetComputeVisual | |
1299 | //purpose : | |
1300 | //============================================================================= | |
1301 | void Graphic3d_Structure::SetComputeVisual (const Graphic3d_TypeOfStructure theVisual) | |
35e08fe8 | 1302 | { |
63bcc448 | 1303 | // The ComputeVisual is saved only if the structure is declared TOS_ALL, TOS_WIREFRAME or TOS_SHADING. |
1304 | // This declaration permits to calculate proper representation of the structure calculated by Compute instead of passage to TOS_COMPUTED. | |
1305 | if (theVisual != Graphic3d_TOS_COMPUTED) | |
1306 | { | |
1307 | myComputeVisual = theVisual; | |
7fd59977 | 1308 | } |
7fd59977 | 1309 | } |
1310 | ||
63bcc448 | 1311 | //============================================================================= |
63bcc448 | 1312 | //function : SetHLRValidation |
1313 | //purpose : | |
1314 | //============================================================================= | |
1315 | void Graphic3d_Structure::SetHLRValidation (const Standard_Boolean theFlag) | |
1316 | { | |
1317 | myCStructure->HLRValidation = theFlag ? 1 : 0; | |
1318 | } | |
7fd59977 | 1319 | |
63bcc448 | 1320 | //============================================================================= |
1321 | //function : HLRValidation | |
1322 | //purpose : | |
1323 | //============================================================================= | |
1324 | Standard_Boolean Graphic3d_Structure::HLRValidation() const | |
1325 | { | |
81bba717 | 1326 | // Hidden parts stored in <me> are valid if : |
1327 | // 1/ the owner is defined. | |
1328 | // 2/ they are not invalid. | |
63bcc448 | 1329 | return myOwner != NULL |
1330 | && myCStructure->HLRValidation != 0; | |
7fd59977 | 1331 | } |
1332 | ||
59f45b7c | 1333 | //======================================================================= |
1334 | //function : SetZLayer | |
1335 | //purpose : | |
1336 | //======================================================================= | |
a1954302 | 1337 | void Graphic3d_Structure::SetZLayer (const Graphic3d_ZLayerId theLayerId) |
59f45b7c | 1338 | { |
1339 | // if the structure is not displayed, unable to change its display layer | |
1340 | if (IsDeleted ()) | |
1341 | return; | |
1342 | ||
63bcc448 | 1343 | myStructureManager->ChangeZLayer (this, theLayerId); |
a1954302 | 1344 | myCStructure->SetZLayer (theLayerId); |
59f45b7c | 1345 | } |
1346 | ||
1347 | //======================================================================= | |
1348 | //function : GetZLayer | |
1349 | //purpose : | |
1350 | //======================================================================= | |
a1954302 | 1351 | Graphic3d_ZLayerId Graphic3d_Structure::GetZLayer() const |
59f45b7c | 1352 | { |
a1954302 | 1353 | return myCStructure->ZLayer(); |
59f45b7c | 1354 | } |
4269bd1b | 1355 | |
1356 | //======================================================================= | |
1357 | //function : SetClipPlanes | |
1358 | //purpose : | |
1359 | //======================================================================= | |
3202bf1e | 1360 | void Graphic3d_Structure::SetClipPlanes (const Handle(Graphic3d_SequenceOfHClipPlane)& thePlanes) |
4269bd1b | 1361 | { |
63bcc448 | 1362 | myCStructure->SetClipPlanes (thePlanes); |
4269bd1b | 1363 | } |
1364 | ||
1365 | //======================================================================= | |
1366 | //function : GetClipPlanes | |
1367 | //purpose : | |
1368 | //======================================================================= | |
3202bf1e | 1369 | const Handle(Graphic3d_SequenceOfHClipPlane)& Graphic3d_Structure::ClipPlanes() const |
4269bd1b | 1370 | { |
63bcc448 | 1371 | return myCStructure->ClipPlanes(); |
4269bd1b | 1372 | } |
b7cd4ba7 | 1373 | |
1374 | //======================================================================= | |
1375 | //function : SetMutable | |
1376 | //purpose : | |
1377 | //======================================================================= | |
1378 | void Graphic3d_Structure::SetMutable (const Standard_Boolean theIsMutable) | |
1379 | { | |
1380 | myCStructure->IsMutable = theIsMutable; | |
1381 | } | |
1382 | ||
1383 | //======================================================================= | |
1384 | //function : IsMutable | |
1385 | //purpose : | |
1386 | //======================================================================= | |
1387 | Standard_Boolean Graphic3d_Structure::IsMutable() const | |
1388 | { | |
1389 | return myCStructure->IsMutable; | |
1390 | } |