0030450: Visualization - AIS_InteractiveContext::MoveTo() never uses V3d_View::Immedi...
[occt.git] / src / AIS / AIS_Trihedron.cxx
CommitLineData
b311480e 1// Created on: 1995-10-09
2// Created by: Arnaud BOUZY/Odile Olivier
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
1f7f5a90 17#include <AIS_Trihedron.hxx>
42cf5bc1 18
42cf5bc1 19#include <AIS_InteractiveContext.hxx>
bc001a40 20#include <AIS_TrihedronOwner.hxx>
7fd59977 21#include <Geom_Axis2Placement.hxx>
42cf5bc1 22#include <Geom_Transformation.hxx>
7fd59977 23#include <gp_Pnt.hxx>
bc001a40 24#include <Graphic3d_ArrayOfPoints.hxx>
25#include <Graphic3d_ArrayOfSegments.hxx>
42cf5bc1 26#include <Graphic3d_AspectLine3d.hxx>
bc001a40 27#include <Graphic3d_ArrayOfPoints.hxx>
28#include <Graphic3d_ArrayOfPolylines.hxx>
29
30#include <Prs3d_Arrow.hxx>
42cf5bc1 31#include <Prs3d_ArrowAspect.hxx>
32#include <Prs3d_DatumAspect.hxx>
7fd59977 33#include <Prs3d_Drawer.hxx>
34#include <Prs3d_LineAspect.hxx>
42cf5bc1 35#include <Prs3d_Presentation.hxx>
36#include <Prs3d_Projector.hxx>
bc001a40 37#include <Prs3d_ShadingAspect.hxx>
38#include <Prs3d_Text.hxx>
7fd59977 39#include <Prs3d_TextAspect.hxx>
bc001a40 40#include <Prs3d_ToolSphere.hxx>
41
42cf5bc1 42#include <Select3D_SensitivePoint.hxx>
bc001a40 43#include <Select3D_SensitivePrimitiveArray.hxx>
42cf5bc1 44#include <Select3D_SensitiveSegment.hxx>
7fd59977 45#include <Select3D_SensitiveTriangle.hxx>
42cf5bc1 46#include <SelectBasics_EntityOwner.hxx>
47#include <SelectMgr_EntityOwner.hxx>
48#include <Standard_Type.hxx>
7fd59977 49
bc001a40 50IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
92efcf78 51
7fd59977 52//=======================================================================
53//function : AIS_Trihedron
bc001a40 54//purpose :
7fd59977 55//=======================================================================
bc001a40 56AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
57: myHasOwnSize (Standard_False),
58 myHasOwnTextColor (Standard_False),
59 myHasOwnArrowColor (Standard_False),
60 myTrihDispMode (Prs3d_DM_WireFrame),
61 myComponent (theComponent)
046a1c9d 62{
bc001a40 63 // selection priorities
64 mySelectionPriority.Bind (Prs3d_DP_None, 5); // complete triedron: priority 5 (same as faces)
65 mySelectionPriority.Bind (Prs3d_DP_Origin, 8); // origin: priority 8
66 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
67 {
68 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 7); // axes: priority: 7
69 }
70 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
71 {
72 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
73 }
74
75 // trihedron labels
76 myLabel.Bind (Prs3d_DP_XAxis, "X");
77 myLabel.Bind (Prs3d_DP_YAxis, "Y");
78 myLabel.Bind (Prs3d_DP_ZAxis, "Z");
046a1c9d 79}
7fd59977 80
81//=======================================================================
82//function : SetComponent
bc001a40 83//purpose :
7fd59977 84//=======================================================================
bc001a40 85void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
7fd59977 86{
bc001a40 87 myComponent = theComponent;
88 LoadRecomputable (AIS_WireFrame);
7fd59977 89}
90
29d43f9c 91//=======================================================================
bc001a40 92//function : setOwnDatumAspect
1f7f5a90 93//purpose :
29d43f9c 94//=======================================================================
bc001a40 95void AIS_Trihedron::setOwnDatumAspect()
29d43f9c 96{
bc001a40 97 if (myDrawer->HasOwnDatumAspect())
98 return;
99
100 Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
101 myDrawer->SetDatumAspect(aNewAspect);
102
103 if (myDrawer->Link().IsNull())
104 return;
105
fae1ae11
ZA
106 myDrawer->DatumAspect()->SetDrawArrows (myDrawer->Link()->DatumAspect()->ToDrawArrows());
107 myDrawer->DatumAspect()->SetDrawLabels (myDrawer->Link()->DatumAspect()->ToDrawLabels());
bc001a40 108 *myDrawer->DatumAspect()->TextAspect()->Aspect() =
109 *myDrawer->Link()->DatumAspect()->TextAspect()->Aspect();
110 *myDrawer->DatumAspect()->PointAspect()->Aspect() =
111 *myDrawer->Link()->DatumAspect()->PointAspect()->Aspect();
112 *myDrawer->DatumAspect()->ArrowAspect()->Aspect() =
113 *myDrawer->Link()->DatumAspect()->ArrowAspect()->Aspect();
29d43f9c 114
bc001a40 115 for (int aPartIter = Prs3d_DP_Origin; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
116 {
117 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
118 if (!aNewAspect->LineAspect(aPart).IsNull())
119 *myDrawer->DatumAspect()->LineAspect(aPart)->Aspect() =
120 *myDrawer->Link()->DatumAspect()->LineAspect(aPart)->Aspect();
121 if (!aNewAspect->ShadingAspect(aPart).IsNull())
122 *myDrawer->DatumAspect()->ShadingAspect(aPart)->Aspect() =
123 *myDrawer->Link()->DatumAspect()->ShadingAspect(aPart)->Aspect();
124 }
29d43f9c 125}
7fd59977 126
127//=======================================================================
128//function : SetSize
bc001a40 129//purpose :
7fd59977 130//=======================================================================
131void AIS_Trihedron::SetSize(const Standard_Real aValue)
132{
133 myHasOwnSize = Standard_True;
bc001a40 134
135 setOwnDatumAspect();
136 myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
7fd59977 137
138 Update();
139 UpdateSelection();
140}
141
7fd59977 142//=======================================================================
143//function : UnsetSize
bc001a40 144//purpose :
7fd59977 145//=======================================================================
7fd59977 146void AIS_Trihedron::UnsetSize()
147{
bc001a40 148 if (!myHasOwnSize)
149 {
150 return;
151 }
152
7fd59977 153 myHasOwnSize = Standard_False;
bc001a40 154 if (hasOwnColor)
155 {
156 const Handle(Prs3d_DatumAspect) DA = myDrawer->HasLink()
157 ? myDrawer->Link()->DatumAspect()
158 : new Prs3d_DatumAspect();
159 myDrawer->DatumAspect()->SetAxisLength (DA->AxisLength (Prs3d_DP_XAxis),
160 DA->AxisLength (Prs3d_DP_YAxis),
161 DA->AxisLength (Prs3d_DP_ZAxis));
7fd59977 162 }
163 else
6262338c 164 {
bc001a40 165 Update();
6262338c 166 }
7fd59977 167 UpdateSelection();
7fd59977 168}
169
170//=======================================================================
171//function : Size
bc001a40 172//purpose :
7fd59977 173//=======================================================================
7fd59977 174Standard_Real AIS_Trihedron::Size() const
175{
bc001a40 176 return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
7fd59977 177}
178
179//=======================================================================
bc001a40 180//function : Compute
181//purpose :
7fd59977 182//=======================================================================
bc001a40 183void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
184 const Handle(Prs3d_Presentation)& thePrs,
185 const Standard_Integer theMode)
7fd59977 186{
bc001a40 187 if (theMode != 0)
046a1c9d 188 {
bc001a40 189 return;
046a1c9d 190 }
bc001a40 191
192 thePrs->SetInfiniteState (Standard_True);
193
194 gp_Ax2 anAxis (myComponent->Ax2());
195 updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
196 anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
197 computePresentation (thePrsMgr, thePrs);
7fd59977 198}
199
200//=======================================================================
bc001a40 201//function : Compute
202//purpose :
7fd59977 203//=======================================================================
bc001a40 204void AIS_Trihedron::Compute (const Handle(Prs3d_Projector)& theProjector,
205 const Handle(Geom_Transformation)& theTrsf,
206 const Handle(Prs3d_Presentation)& thePrs)
7fd59977 207{
bc001a40 208 PrsMgr_PresentableObject::Compute (theProjector, theTrsf, thePrs);
7fd59977 209}
210
211//=======================================================================
bc001a40 212//function : ComputeSelection
213//purpose :
7fd59977 214//=======================================================================
bc001a40 215void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
216 const Standard_Integer theMode)
7fd59977 217{
bc001a40 218 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
219 switch (theMode)
046a1c9d 220 {
bc001a40 221 case AIS_TrihedronSelectionMode_EntireObject:
222 {
223 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (
224 this, mySelectionPriority.Find (Prs3d_DP_None));
225 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
226 for (int aPartIter = isShadingMode ? Prs3d_DP_Origin : Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis;
227 ++aPartIter)
228 {
229 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
230 if (!anAspect->DrawDatumPart (aPart))
231 {
232 continue;
233 }
234 theSelection->Add (createSensitiveEntity (aPart, anOwner));
235 }
236 break;
237 }
238 case AIS_TrihedronSelectionMode_Origin:
239 {
240 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
241 if (anAspect->DrawDatumPart (aPart))
242 {
243 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
244 mySelectionPriority.Find (aPart));
245 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives(aPart);
246 theSelection->Add (createSensitiveEntity (aPart, anOwner));
247 }
248 break;
249 }
250 case AIS_TrihedronSelectionMode_Axes:
251 {
252 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
253 {
254 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
255 if (!anAspect->DrawDatumPart (aPart))
256 {
257 continue;
258 }
259 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
260 mySelectionPriority.Find (aPart));
261 theSelection->Add (createSensitiveEntity (aPart, anOwner));
262 }
263 break;
264 }
265 case AIS_TrihedronSelectionMode_MainPlanes:
266 {
267 // create owner for each trihedron plane
268 {
269 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
270 {
271 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
272 if (!anAspect->DrawDatumPart (aPart))
273 {
274 continue;
275 }
276 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
277 mySelectionPriority.Find (aPart));
278 theSelection->Add (createSensitiveEntity (aPart, anOwner));
279 }
280 }
281 break;
282 }
046a1c9d 283 }
7fd59977 284}
285
286//=======================================================================
bc001a40 287//function : HilightOwnerWithColor
288//purpose :
7fd59977 289//=======================================================================
bc001a40 290void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
291 const Handle(Prs3d_Drawer)& theStyle,
292 const Handle(SelectMgr_EntityOwner)& theOwner)
7fd59977 293{
bc001a40 294 Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
295 if (anOwner.IsNull())
296 {
297 /// default 0 selection mode
298 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
299 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
300 return;
7fd59977 301 }
7fd59977 302
bc001a40 303 Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
304 if (aPresentation.IsNull())
305 {
306 return;
307 }
7fd59977 308
bc001a40 309 aPresentation->Clear();
310 const Prs3d_DatumParts aPart = anOwner->DatumPart();
311 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
312 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
313 if (aPart >= Prs3d_DP_XOYAxis && aPart <= Prs3d_DP_XOZAxis)
314 {
315 // planes selection is equal in both shading and wireframe mode
316 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
317 }
318 else
319 {
320 if (myTrihDispMode == Prs3d_DM_Shaded)
321 {
322 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect(aPart)->Aspect());
323 }
324 else
325 {
326 if (aPart == Prs3d_DP_Origin)
327 {
328 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
329 }
330 else
331 {
332 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect(aPart)->Aspect());
333 }
334 }
335 }
336 aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
7fd59977 337
c29c0ad0 338 if (aPresentation->GetZLayer() != theStyle->ZLayer())
339 {
340 aPresentation->SetZLayer (theStyle->ZLayer());
341 }
bc001a40 342 aPresentation->Highlight (theStyle);
343 thePM->AddToImmediateList (aPresentation);
7fd59977 344}
345
bc001a40 346//========================================================================
347//function : HilightSelected
348//purpose :
349//========================================================================
350void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
351 const SelectMgr_SequenceOfOwner& theOwners)
7fd59977 352{
bc001a40 353 if (theOwners.IsEmpty() || !HasInteractiveContext())
354 {
355 return;
356 }
357
358 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
359 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
360
361 const Handle(Prs3d_Drawer)& aContextSelStyle = GetContext()->SelectionStyle();
362 const Quantity_Color& aSelectionColor = aContextSelStyle->Color();
363 for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
364 {
365 const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
366 Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
367 if (aTrihedronOwner.IsNull())
368 {
369 thePM->Color (this, aContextSelStyle, 0);
370 continue;
371 }
372
373 const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
374 Handle(Graphic3d_Group) aGroup;
375 if (mySelectedParts.Contains (aPart)
376 || !myPartToGroup.Find (aPart, aGroup))
377 {
378 continue;
379 }
380
381 if (aPart >= Prs3d_DP_XOYAxis
382 && aPart <= Prs3d_DP_XOZAxis)
383 {
384 getHighlightLineAspect()->SetColor (aSelectionColor);
385 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
386 }
387 else
388 {
389 if (isShadingMode)
390 {
391 getHighlightAspect()->SetColor (aSelectionColor);
392 aGroup->SetGroupPrimitivesAspect (getHighlightAspect()->Aspect());
393 }
394 else
395 {
396 if (aPart == Prs3d_DP_Origin)
397 {
398 getHighlightPointAspect()->SetColor (aSelectionColor);
399 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
400 }
401 else
402 {
403 getHighlightLineAspect()->SetColor (aSelectionColor);
404 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
405 }
406 }
407 }
408 mySelectedParts.Append (aPart);
7fd59977 409 }
410}
411
412//=======================================================================
bc001a40 413//function : ClearSelected
414//purpose :
7fd59977 415//=======================================================================
bc001a40 416void AIS_Trihedron::ClearSelected()
7fd59977 417{
bc001a40 418 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
419 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
420 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (mySelectedParts); anIterator.More();
421 anIterator.Next())
422 {
423 const Prs3d_DatumParts aPart = anIterator.Value();
424 Handle(Graphic3d_Group) aGroup = myPartToGroup.Find (aPart);
425 if (aPart >= Prs3d_DP_XOYAxis
426 && aPart <= Prs3d_DP_XOZAxis)
427 {
428 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
429 }
430 if (isShadingMode)
431 {
432 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
433 }
434 else
435 {
436 if (aPart == Prs3d_DP_Origin)
437 {
438 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
439 }
440 else
441 {
442 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
443 }
444 }
445 }
446 mySelectedParts.Clear();
7fd59977 447}
448
449//=======================================================================
bc001a40 450//function : computePresentation
451//purpose :
7fd59977 452//=======================================================================
bc001a40 453void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
454 const Handle(Prs3d_Presentation)& thePrs)
7fd59977 455{
bc001a40 456 myPartToGroup.Clear();
457 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
458 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
459 // display origin
460 {
461 // Origin is visualized only in shading mode
462 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
463 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
464 if (anAspect->DrawDatumPart(aPart))
465 {
466 myPartToGroup.Bind (aPart, aGroup);
467 if (isShadingMode)
468 {
469 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
470 }
471 else
472 {
473 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
474 }
475 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
476 }
477 }
29d43f9c 478
bc001a40 479 // display axes
480 {
481 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
29d43f9c 482 {
bc001a40 483 Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
484 if (!anAspect->DrawDatumPart (aPart))
485 {
486 continue;
487 }
29d43f9c 488
bc001a40 489 Handle(Graphic3d_Group) anAxisGroup = Prs3d_Root::NewGroup (thePrs);
490 myPartToGroup.Bind (aPart, anAxisGroup);
491 if (isShadingMode)
29d43f9c 492 {
bc001a40 493 anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
29d43f9c 494 }
bc001a40 495 else
496 {
497 anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
498 }
499 anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
500
501 // draw arrow
bc001a40 502 Prs3d_DatumParts anArrowPart = anAspect->ArrowPartForAxis (aPart);
503 if (!anAspect->DrawDatumPart (anArrowPart))
504 {
505 continue;
506 }
fae1ae11
ZA
507
508 Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
509 anArrowGroup->SetGroupPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
bc001a40 510 anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
7fd59977 511 }
bc001a40 512 }
7fd59977 513
bc001a40 514 // display labels
515 if (anAspect->ToDrawLabels())
516 {
517 Handle(Geom_Axis2Placement) aComponent = myComponent;
518 const gp_Pnt anOrigin = aComponent->Location();
519 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
520 {
521 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
522 if (!anAspect->DrawDatumPart (aPart))
523 {
524 continue;
7fd59977 525 }
29d43f9c 526
bc001a40 527 const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
528 const TCollection_ExtendedString& aLabel = myLabel.Find (aPart);
529 gp_Dir aDir;
530 switch (aPart)
531 {
532 case Prs3d_DP_XAxis: aDir = aComponent->XDirection(); break;
533 case Prs3d_DP_YAxis: aDir = aComponent->YDirection(); break;
534 case Prs3d_DP_ZAxis: aDir = aComponent->Direction(); break;
535 default: break;
536 }
537 Handle(Graphic3d_Group) aLabelGroup = Prs3d_Root::NewGroup (thePrs);
538 const gp_Pnt aPoint = anOrigin.XYZ() + aDir.XYZ() * anAxisLength;
539 Prs3d_Text::Draw (aLabelGroup, anAspect->TextAspect(), aLabel, aPoint);
7fd59977 540 }
bc001a40 541 }
542
543 // planes invisible group for planes selection
544 for (Standard_Integer anAxisIter = Prs3d_DP_XOYAxis; anAxisIter <= Prs3d_DP_XOZAxis; ++anAxisIter)
545 {
546 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
547 if (!anAspect->DrawDatumPart(aPart))
548 {
549 continue;
7fd59977 550 }
bc001a40 551
552 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
553 myPartToGroup.Bind (aPart, aGroup);
554
555 const Handle(Graphic3d_AspectLine3d)& aLineAspect = anAspect->LineAspect (aPart)->Aspect();
556 aLineAspect->SetType (Aspect_TOL_EMPTY);
557
558 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
559 aGroup->SetGroupPrimitivesAspect (aLineAspect);
7fd59977 560 }
7fd59977 561}
562
563//=======================================================================
bc001a40 564//function : LoadRecomputable
565//purpose :
7fd59977 566//=======================================================================
bc001a40 567void AIS_Trihedron::LoadRecomputable (const Standard_Integer theMode)
7fd59977 568{
bc001a40 569 myRecomputeEveryPrs = Standard_False;
570 if (!myToRecomputeModes.Contains (theMode))
571 {
572 myToRecomputeModes.Append (theMode);
573 }
7fd59977 574}
575
bc001a40 576//=======================================================================
577//function : SetColor
578//purpose :
579//=======================================================================
580void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
581 const Quantity_Color& theColor)
7fd59977 582{
bc001a40 583 setOwnDatumAspect();
7fd59977 584
bc001a40 585 myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
586 if (thePart != Prs3d_DP_Origin)
587 {
588 myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
589 }
7fd59977 590}
591
592//=======================================================================
593//function : SetTextColor
bc001a40 594//purpose :
7fd59977 595//=======================================================================
bc001a40 596void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
7fd59977 597{
bc001a40 598 setOwnDatumAspect();
599 myDrawer->DatumAspect()->TextAspect()->SetColor (theColor);
7fd59977 600}
601
bc001a40 602//=======================================================================
603//function : Color
604//purpose :
605//=======================================================================
606Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
7fd59977 607{
bc001a40 608 if (myTrihDispMode == Prs3d_DM_Shaded)
609 {
610 return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
611 }
612 else
613 {
614 return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
7fd59977 615 }
7fd59977 616}
617
618//=======================================================================
bc001a40 619//function : SetOriginColor
620//purpose :
7fd59977 621//=======================================================================
bc001a40 622void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
623{
624 if (myTrihDispMode == Prs3d_DM_Shaded)
625 {
626 SetDatumPartColor (Prs3d_DP_Origin, theColor);
627 }
7fd59977 628}
629
630//=======================================================================
bc001a40 631//function : SetXAxisColor
632//purpose :
633//=======================================================================
634void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
635{
636 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
7fd59977 637}
638
639//=======================================================================
bc001a40 640//function : SetYAxisColor
641//purpose :
642//=======================================================================
643void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
644{
645 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
7fd59977 646}
7fd59977 647
7fd59977 648//=======================================================================
bc001a40 649//function : SetAxisColor
650//purpose :
7fd59977 651//=======================================================================
bc001a40 652void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
7fd59977 653{
bc001a40 654 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
7fd59977 655}
bc001a40 656
7fd59977 657//=======================================================================
bc001a40 658//function : SetColor
659//purpose :
7fd59977 660//=======================================================================
bc001a40 661void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
662{
663 hasOwnColor = Standard_True;
664 myDrawer->SetColor (theColor);
7fd59977 665
bc001a40 666 SetDatumPartColor (Prs3d_DP_Origin, theColor);
667 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
668 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
669 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
670}
7fd59977 671
672//=======================================================================
bc001a40 673//function : SetArrowColor
674//purpose :
7fd59977 675//=======================================================================
bc001a40 676void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
677{
678 setOwnDatumAspect();
7fd59977 679
bc001a40 680 myHasOwnArrowColor = Standard_True;
681 myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
682}
7fd59977 683
684//=======================================================================
bc001a40 685//function : TextColor
686//purpose :
7fd59977 687//=======================================================================
bc001a40 688Quantity_Color AIS_Trihedron::TextColor() const
7fd59977 689{
bc001a40 690 return myDrawer->DatumAspect()->TextAspect()->Aspect()->Color();
7fd59977 691}
692
693//=======================================================================
bc001a40 694//function : ArrowColor
695//purpose :
7fd59977 696//=======================================================================
bc001a40 697Quantity_Color AIS_Trihedron::ArrowColor() const
698{
699 return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
700}
7fd59977 701
702//=======================================================================
703//function : UnsetColor
704//purpose :
705//=======================================================================
7fd59977 706void AIS_Trihedron::UnsetColor()
707{
bc001a40 708 hasOwnColor = Standard_False;
709 Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
710 SetColor (aDefaultColor);
711 if (HasTextColor())
712 {
713 SetTextColor (aDefaultColor);
7fd59977 714 myHasOwnTextColor = Standard_False;
715 }
bc001a40 716 if (HasArrowColor())
717 {
718 SetArrowColor (aDefaultColor);
7fd59977 719 myHasOwnArrowColor = Standard_False;
720 }
7fd59977 721}
722
fae1ae11
ZA
723//=======================================================================
724//function : ToDrawArrows
725//purpose :
726//=======================================================================
727Standard_Boolean AIS_Trihedron::ToDrawArrows() const
728{
729 return myDrawer->DatumAspect()->ToDrawArrows();
730}
731
732//=======================================================================
733//function : SetDrawArrows
734//purpose :
735//=======================================================================
736void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
737{
738 setOwnDatumAspect();
739 myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
740}
741
7fd59977 742//=======================================================================
bc001a40 743//function : createSensitiveEntity
744//purpose :
7fd59977 745//=======================================================================
bc001a40 746Handle(SelectBasics_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
747 const Handle(SelectBasics_EntityOwner)& theOwner) const
7fd59977 748{
bc001a40 749 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
750 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
751 if (aPrimitives.IsNull())
752 {
753 return Handle(SelectBasics_SensitiveEntity)();
754 }
7fd59977 755
bc001a40 756 if (thePart >= Prs3d_DP_XOYAxis
757 && thePart <= Prs3d_DP_XOZAxis)
758 { // plane
759 const gp_Pnt anXYZ1 = aPrimitives->Vertice (1);
760 const gp_Pnt anXYZ2 = aPrimitives->Vertice (2);
761 const gp_Pnt anXYZ3 = aPrimitives->Vertice (3);
762 return new Select3D_SensitiveTriangle (theOwner, anXYZ1, anXYZ2, anXYZ3);
763 }
764
765 if (myTrihDispMode == Prs3d_DM_Shaded)
766 {
767 Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
768 aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
769 return aSelArray;
770 }
771
772 if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
773 {
774 const gp_Pnt anXYZ1 = aPoints->Vertice (1);
775 return new Select3D_SensitivePoint (theOwner, anXYZ1);
776 }
777 else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
778 {
779 const gp_Pnt anXYZ1 = aSegments->Vertice (1);
780 const gp_Pnt anXYZ2 = aSegments->Vertice (2);
781 return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
782 }
783 return Handle(SelectBasics_SensitiveEntity)();
7fd59977 784}
bc001a40 785
786// =======================================================================
787// function : arrayOfPrimitives
788// purpose :
789// =======================================================================
790Handle(Graphic3d_ArrayOfPrimitives) AIS_Trihedron::arrayOfPrimitives(
791 Prs3d_DatumParts theDatumPart) const
7fd59977 792{
bc001a40 793 Handle(Graphic3d_ArrayOfPrimitives) anArray;
794 myPrimitives.Find(theDatumPart, anArray);
795 return anArray;
7fd59977 796}
797
bc001a40 798// =======================================================================
799// function : updatePrimitives
800// purpose :
801// =======================================================================
802void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
803 Prs3d_DatumMode theMode,
804 const gp_Pnt& theOrigin,
805 const gp_Dir& theXDirection,
806 const gp_Dir& theYDirection,
807 const gp_Dir& theZDirection)
7fd59977 808{
bc001a40 809 myPrimitives.Clear();
810
811 NCollection_DataMap<Prs3d_DatumParts, gp_Dir> anAxisDirs;
812 anAxisDirs.Bind(Prs3d_DP_XAxis, theXDirection);
813 anAxisDirs.Bind(Prs3d_DP_YAxis, theYDirection);
814 anAxisDirs.Bind(Prs3d_DP_ZAxis, theZDirection);
815
816 NCollection_DataMap<Prs3d_DatumParts, gp_Pnt> anAxisPoints;
817 gp_XYZ anXYZOrigin = theOrigin.XYZ();
818 for (int anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
819 {
820 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
821 anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
822 theAspect->AxisLength(aPart)));
823 }
824
825 if (theMode == Prs3d_DM_WireFrame)
826 {
827 // origin
828 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
829 {
830 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
831 aPrims->AddVertex(theOrigin);
832 myPrimitives.Bind(Prs3d_DP_Origin, aPrims);
833 }
834 // axes
835 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
836 {
837 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
838 if (theAspect->DrawDatumPart(aPart))
839 {
840 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
841 aPrims->AddVertex(theOrigin);
842 aPrims->AddVertex(anAxisPoints.Find(aPart));
843 myPrimitives.Bind(aPart, aPrims);
844 }
845
846 Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
847 if (theAspect->DrawDatumPart(anArrowPart))
848 {
849 myPrimitives.Bind(anArrowPart,
850 Prs3d_Arrow::DrawSegments(anAxisPoints.Find(aPart), anAxisDirs.Find(aPart),
851 theAspect->ArrowAspect()->Angle(),
852 theAspect->AxisLength(aPart) * theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent),
853 (Standard_Integer) theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes)));
854 }
855 }
856 }
857 else
858 {
859 // shading mode
860 // origin
861 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
862 {
863 const Standard_Real aSphereRadius = theAspect->AxisLength(Prs3d_DP_XAxis) *
864 theAspect->Attribute(Prs3d_DP_ShadingOriginRadiusPercent);
865 const Standard_Integer aNbOfFacettes =
866 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
867 gp_Trsf aSphereTransform;
868 aSphereTransform.SetTranslationPart(gp_Vec(gp::Origin(), theOrigin));
869 myPrimitives.Bind(Prs3d_DP_Origin, Prs3d_ToolSphere::Create(aSphereRadius, aNbOfFacettes,
870 aNbOfFacettes, aSphereTransform));
871 }
872 // axes
873 {
874 const Standard_Integer aNbOfFacettes =
875 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
876 const Standard_Real aTubeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingTubeRadiusPercent);
877 const Standard_Real aConeLengthPercent = theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
878 const Standard_Real aConeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingConeRadiusPercent);
879 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
da0e82aa 880 {
bc001a40 881 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
882 const Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
883 const bool aDrawArrow = theAspect->DrawDatumPart(anArrowPart);
884 const Standard_Real anAxisLength = theAspect->AxisLength(aPart);
885 const gp_Ax1 anAxis(theOrigin, anAxisDirs.Find(aPart));
886
887 if (theAspect->DrawDatumPart(aPart))
888 {
889 // draw cylinder
890 myPrimitives.Bind(aPart,
891 Prs3d_Arrow::DrawShaded(anAxis, anAxisLength * aTubeRadiusPercent,
892 aDrawArrow ? anAxisLength - anAxisLength * aConeLengthPercent : anAxisLength,
893 0.0, 0.0, aNbOfFacettes));
894 }
895
896 // draw arrow
897 if (aDrawArrow)
898 {
899 myPrimitives.Bind(anArrowPart, Prs3d_Arrow::DrawShaded(anAxis, 0.0, anAxisLength,
900 anAxisLength * aConeRadiusPercent,
901 anAxisLength * aConeLengthPercent, aNbOfFacettes));
902 }
da0e82aa 903 }
bc001a40 904 }
905 }
906 // planes
907 for (Standard_Integer aPlaneIter = Prs3d_DP_XOYAxis; aPlaneIter <= Prs3d_DP_XOZAxis; ++aPlaneIter)
908 {
909 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
910 if (!theAspect->DrawDatumPart(aPart))
29d43f9c 911 {
bc001a40 912 continue;
913 }
914
915 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
916 aPrims->AddVertex(theOrigin);
917
918 Prs3d_DatumParts aPart1 = Prs3d_DP_XAxis, aPart2 = Prs3d_DP_XAxis;
919 switch(aPart)
920 {
921 case Prs3d_DP_XOYAxis:
922 {
923 aPart1 = Prs3d_DP_XAxis;
924 aPart2 = Prs3d_DP_YAxis;
925 break;
926 }
927 case Prs3d_DP_YOZAxis:
928 {
929 aPart1 = Prs3d_DP_YAxis;
930 aPart2 = Prs3d_DP_ZAxis;
931 break;
932 }
933 case Prs3d_DP_XOZAxis:
934 {
935 aPart1 = Prs3d_DP_XAxis;
936 aPart2 = Prs3d_DP_ZAxis;
937 break;
938 }
939 default: break;
29d43f9c 940 }
bc001a40 941 aPrims->AddVertex(anAxisPoints.Find(aPart1));
942 aPrims->AddVertex(anAxisPoints.Find(aPart2));
943
944 aPrims->AddVertex(theOrigin);
945 myPrimitives.Bind(aPart, aPrims);
946 }
947}
948
949// =======================================================================
950// function : getHighlightAspect
951// purpose :
952// =======================================================================
953Handle(Prs3d_ShadingAspect) AIS_Trihedron::getHighlightAspect()
954{
955 if (!myHighlightAspect.IsNull())
956 return myHighlightAspect;
957
958 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
959 if (!myHilightDrawer.IsNull())
960 aHighlightColor = myHilightDrawer->Color();
961
962 myHighlightAspect = new Prs3d_ShadingAspect();
963 myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
964 myHighlightAspect->SetColor (aHighlightColor);
965
966 Graphic3d_MaterialAspect aHighlightMaterial;
967 aHighlightMaterial.SetColor (aHighlightColor);
968 myHighlightAspect->SetMaterial (aHighlightMaterial);
969
970 return myHighlightAspect;
971}
972
973// =======================================================================
974// function : getHighlightLineAspect
975// purpose :
976// =======================================================================
977Handle(Prs3d_LineAspect) AIS_Trihedron::getHighlightLineAspect()
978{
979 if (!myHighlightLineAspect.IsNull())
980 return myHighlightLineAspect;
981
982 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
983 if (!myHilightDrawer.IsNull())
984 aHighlightColor = myHilightDrawer->Color();
985
986 Handle(Prs3d_DatumAspect) aDatumAspect = Attributes()->DatumAspect();
987 Handle(Prs3d_LineAspect) aLineAspect = aDatumAspect->LineAspect(Prs3d_DP_XAxis);
988 myHighlightLineAspect = new Prs3d_LineAspect (aHighlightColor, aLineAspect->Aspect()->Type(),
989 aLineAspect->Aspect()->Width());
990
991 return myHighlightLineAspect;
992}
993
994// =======================================================================
995// function : getHighlightPointAspect
996// purpose :
997// =======================================================================
998Handle(Prs3d_PointAspect) AIS_Trihedron::getHighlightPointAspect()
999{
1000 if (!myHighlightPointAspect.IsNull())
1001 return myHighlightPointAspect;
1002
1003 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
1004 if (!myHilightDrawer.IsNull())
1005 aHighlightColor = myHilightDrawer->Color();
1006 myHighlightPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, aHighlightColor, 1.0);
1007
1008 return myHighlightPointAspect;
7fd59977 1009}