1 // Created on: 1995-10-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <AIS_Trihedron.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_TrihedronOwner.hxx>
21 #include <Geom_Axis2Placement.hxx>
22 #include <Geom_Transformation.hxx>
24 #include <Graphic3d_ArrayOfPoints.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26 #include <Graphic3d_AspectLine3d.hxx>
27 #include <Graphic3d_ArrayOfPoints.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
30 #include <Prs3d_Arrow.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_DatumAspect.hxx>
33 #include <Prs3d_Drawer.hxx>
34 #include <Prs3d_LineAspect.hxx>
35 #include <Prs3d_PointAspect.hxx>
36 #include <Prs3d_Presentation.hxx>
37 #include <Prs3d_Projector.hxx>
38 #include <Prs3d_ShadingAspect.hxx>
39 #include <Prs3d_Text.hxx>
40 #include <Prs3d_TextAspect.hxx>
41 #include <Prs3d_ToolSphere.hxx>
43 #include <Select3D_SensitivePoint.hxx>
44 #include <Select3D_SensitivePrimitiveArray.hxx>
45 #include <Select3D_SensitiveSegment.hxx>
46 #include <Select3D_SensitiveTriangle.hxx>
47 #include <SelectMgr_EntityOwner.hxx>
48 #include <Standard_Type.hxx>
50 IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
52 //=======================================================================
53 //function : AIS_Trihedron
55 //=======================================================================
56 AIS_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)
63 myAutoHilight = Standard_False;
65 // selection priorities
66 mySelectionPriority.Bind (Prs3d_DP_None, 5); // complete triedron: priority 5 (same as faces)
67 mySelectionPriority.Bind (Prs3d_DP_Origin, 8); // origin: priority 8
68 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
70 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 7); // axes: priority: 7
72 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
74 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
76 myHiddenLineAspect = new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_EMPTY, 1.0f);
79 myLabel.Bind (Prs3d_DP_XAxis, "X");
80 myLabel.Bind (Prs3d_DP_YAxis, "Y");
81 myLabel.Bind (Prs3d_DP_ZAxis, "Z");
84 //=======================================================================
85 //function : SetComponent
87 //=======================================================================
88 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
90 myComponent = theComponent;
94 //=======================================================================
95 //function : setOwnDatumAspect
97 //=======================================================================
98 void AIS_Trihedron::setOwnDatumAspect()
100 if (myDrawer->HasOwnDatumAspect())
103 Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
104 myDrawer->SetDatumAspect(aNewAspect);
106 if (myDrawer->Link().IsNull())
109 myDrawer->DatumAspect()->SetDrawArrows (myDrawer->Link()->DatumAspect()->ToDrawArrows());
110 myDrawer->DatumAspect()->SetDrawLabels (myDrawer->Link()->DatumAspect()->ToDrawLabels());
111 *myDrawer->DatumAspect()->TextAspect()->Aspect() =
112 *myDrawer->Link()->DatumAspect()->TextAspect()->Aspect();
113 *myDrawer->DatumAspect()->PointAspect()->Aspect() =
114 *myDrawer->Link()->DatumAspect()->PointAspect()->Aspect();
115 *myDrawer->DatumAspect()->ArrowAspect()->Aspect() =
116 *myDrawer->Link()->DatumAspect()->ArrowAspect()->Aspect();
118 for (int aPartIter = Prs3d_DP_Origin; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
120 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
121 if (!aNewAspect->LineAspect(aPart).IsNull())
122 *myDrawer->DatumAspect()->LineAspect(aPart)->Aspect() =
123 *myDrawer->Link()->DatumAspect()->LineAspect(aPart)->Aspect();
124 if (!aNewAspect->ShadingAspect(aPart).IsNull())
125 *myDrawer->DatumAspect()->ShadingAspect(aPart)->Aspect() =
126 *myDrawer->Link()->DatumAspect()->ShadingAspect(aPart)->Aspect();
130 //=======================================================================
133 //=======================================================================
134 void AIS_Trihedron::SetSize(const Standard_Real aValue)
136 myHasOwnSize = Standard_True;
139 myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
145 //=======================================================================
146 //function : UnsetSize
148 //=======================================================================
149 void AIS_Trihedron::UnsetSize()
156 myHasOwnSize = Standard_False;
159 const Handle(Prs3d_DatumAspect) DA = myDrawer->HasLink()
160 ? myDrawer->Link()->DatumAspect()
161 : new Prs3d_DatumAspect();
162 myDrawer->DatumAspect()->SetAxisLength (DA->AxisLength (Prs3d_DP_XAxis),
163 DA->AxisLength (Prs3d_DP_YAxis),
164 DA->AxisLength (Prs3d_DP_ZAxis));
173 //=======================================================================
176 //=======================================================================
177 Standard_Real AIS_Trihedron::Size() const
179 return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
182 //=======================================================================
185 //=======================================================================
186 void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
187 const Handle(Prs3d_Presentation)& thePrs,
188 const Standard_Integer theMode)
195 thePrs->SetInfiniteState (Standard_True);
197 gp_Ax2 anAxis (myComponent->Ax2());
198 updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
199 anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
200 computePresentation (thePrsMgr, thePrs);
203 //=======================================================================
206 //=======================================================================
207 void AIS_Trihedron::Compute (const Handle(Prs3d_Projector)& theProjector,
208 const Handle(Geom_Transformation)& theTrsf,
209 const Handle(Prs3d_Presentation)& thePrs)
211 PrsMgr_PresentableObject::Compute (theProjector, theTrsf, thePrs);
214 //=======================================================================
215 //function : ComputeSelection
217 //=======================================================================
218 void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
219 const Standard_Integer theMode)
221 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
224 case AIS_TrihedronSelectionMode_EntireObject:
226 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (
227 this, mySelectionPriority.Find (Prs3d_DP_None));
228 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
229 for (int aPartIter = isShadingMode ? Prs3d_DP_Origin : Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis;
232 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
233 if (!anAspect->DrawDatumPart (aPart))
237 theSelection->Add (createSensitiveEntity (aPart, anOwner));
241 case AIS_TrihedronSelectionMode_Origin:
243 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
244 if (anAspect->DrawDatumPart (aPart))
246 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
247 mySelectionPriority.Find (aPart));
248 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives(aPart);
249 theSelection->Add (createSensitiveEntity (aPart, anOwner));
253 case AIS_TrihedronSelectionMode_Axes:
255 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
257 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
258 if (!anAspect->DrawDatumPart (aPart))
262 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
263 mySelectionPriority.Find (aPart));
264 theSelection->Add (createSensitiveEntity (aPart, anOwner));
268 case AIS_TrihedronSelectionMode_MainPlanes:
270 // create owner for each trihedron plane
272 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
274 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
275 if (!anAspect->DrawDatumPart (aPart))
279 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
280 mySelectionPriority.Find (aPart));
281 theSelection->Add (createSensitiveEntity (aPart, anOwner));
289 //=======================================================================
290 //function : HilightOwnerWithColor
292 //=======================================================================
293 void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
294 const Handle(Prs3d_Drawer)& theStyle,
295 const Handle(SelectMgr_EntityOwner)& theOwner)
297 Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
298 if (anOwner.IsNull())
300 /// default 0 selection mode
301 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
302 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
306 Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
307 if (aPresentation.IsNull())
312 aPresentation->Clear();
313 const Prs3d_DatumParts aPart = anOwner->DatumPart();
314 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
315 if (aPart >= Prs3d_DP_XOYAxis && aPart <= Prs3d_DP_XOZAxis)
317 // planes selection is equal in both shading and wireframe mode
318 aGroup->SetGroupPrimitivesAspect (theStyle->LineAspect()->Aspect());
322 if (myTrihDispMode == Prs3d_DM_Shaded)
324 aGroup->SetGroupPrimitivesAspect (theStyle->ShadingAspect()->Aspect());
328 if (aPart == Prs3d_DP_Origin)
330 aGroup->SetGroupPrimitivesAspect (theStyle->PointAspect()->Aspect());
334 aGroup->SetGroupPrimitivesAspect(theStyle->LineAspect()->Aspect());
338 aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
340 const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer();
341 if (aPresentation->GetZLayer() != aLayer)
343 aPresentation->SetZLayer (aLayer);
346 aPresentation->Highlight (theStyle);
347 thePM->AddToImmediateList (aPresentation);
350 //========================================================================
351 //function : HilightSelected
353 //========================================================================
354 void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
355 const SelectMgr_SequenceOfOwner& theOwners)
357 if (theOwners.IsEmpty() || !HasInteractiveContext())
362 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
364 Handle(Prs3d_Drawer) anAspect = !myHilightDrawer.IsNull() ? myHilightDrawer : GetContext()->SelectionStyle();
365 for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
367 const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
368 Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
369 if (aTrihedronOwner.IsNull())
371 thePM->Color (this, anAspect, 0);
375 const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
376 Handle(Graphic3d_Group) aGroup;
377 if (mySelectedParts.Contains (aPart) || !myPartToGroup.Find (aPart, aGroup))
382 if (aPart >= Prs3d_DP_XOYAxis
383 && aPart <= Prs3d_DP_XOZAxis)
385 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
391 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect()->Aspect());
395 if (aPart == Prs3d_DP_Origin)
397 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
401 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
405 mySelectedParts.Append (aPart);
409 //=======================================================================
410 //function : ClearSelected
412 //=======================================================================
413 void AIS_Trihedron::ClearSelected()
415 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
416 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
417 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (mySelectedParts); anIterator.More();
420 const Prs3d_DatumParts aPart = anIterator.Value();
421 Handle(Graphic3d_Group) aGroup = myPartToGroup.Find (aPart);
422 if (aPart >= Prs3d_DP_XOYAxis
423 && aPart <= Prs3d_DP_XOZAxis)
425 aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
427 else if (isShadingMode)
429 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
433 if (aPart == Prs3d_DP_Origin)
435 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
439 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
443 mySelectedParts.Clear();
446 //=======================================================================
447 //function : computePresentation
449 //=======================================================================
450 void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
451 const Handle(Prs3d_Presentation)& thePrs)
453 myPartToGroup.Clear();
454 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
455 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
458 // Origin is visualized only in shading mode
459 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
460 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
461 if (anAspect->DrawDatumPart(aPart))
463 myPartToGroup.Bind (aPart, aGroup);
466 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
470 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
472 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
478 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
480 Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
481 if (!anAspect->DrawDatumPart (aPart))
486 Handle(Graphic3d_Group) anAxisGroup = Prs3d_Root::NewGroup (thePrs);
487 myPartToGroup.Bind (aPart, anAxisGroup);
490 anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
494 anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
496 anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
499 Prs3d_DatumParts anArrowPart = anAspect->ArrowPartForAxis (aPart);
500 if (!anAspect->DrawDatumPart (anArrowPart))
505 Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
506 anArrowGroup->SetGroupPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
507 anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
512 if (anAspect->ToDrawLabels())
514 Handle(Geom_Axis2Placement) aComponent = myComponent;
515 const gp_Pnt anOrigin = aComponent->Location();
516 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
518 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
519 if (!anAspect->DrawDatumPart (aPart))
524 const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
525 const TCollection_ExtendedString& aLabel = myLabel.Find (aPart);
529 case Prs3d_DP_XAxis: aDir = aComponent->XDirection(); break;
530 case Prs3d_DP_YAxis: aDir = aComponent->YDirection(); break;
531 case Prs3d_DP_ZAxis: aDir = aComponent->Direction(); break;
534 Handle(Graphic3d_Group) aLabelGroup = Prs3d_Root::NewGroup (thePrs);
535 const gp_Pnt aPoint = anOrigin.XYZ() + aDir.XYZ() * anAxisLength;
536 Prs3d_Text::Draw (aLabelGroup, anAspect->TextAspect(), aLabel, aPoint);
540 // planes invisible group for planes selection
541 for (Standard_Integer anAxisIter = Prs3d_DP_XOYAxis; anAxisIter <= Prs3d_DP_XOZAxis; ++anAxisIter)
543 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
544 if (!anAspect->DrawDatumPart(aPart))
549 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
550 myPartToGroup.Bind (aPart, aGroup);
552 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
553 aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
557 //=======================================================================
558 //function : SetColor
560 //=======================================================================
561 void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
562 const Quantity_Color& theColor)
566 myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
567 if (thePart != Prs3d_DP_Origin)
569 myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
573 //=======================================================================
574 //function : SetTextColor
576 //=======================================================================
577 void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
580 myDrawer->DatumAspect()->TextAspect()->SetColor (theColor);
583 //=======================================================================
586 //=======================================================================
587 Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
589 if (myTrihDispMode == Prs3d_DM_Shaded)
591 return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
595 return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
599 //=======================================================================
600 //function : SetOriginColor
602 //=======================================================================
603 void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
605 if (myTrihDispMode == Prs3d_DM_Shaded)
607 SetDatumPartColor (Prs3d_DP_Origin, theColor);
611 //=======================================================================
612 //function : SetXAxisColor
614 //=======================================================================
615 void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
617 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
620 //=======================================================================
621 //function : SetYAxisColor
623 //=======================================================================
624 void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
626 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
629 //=======================================================================
630 //function : SetAxisColor
632 //=======================================================================
633 void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
635 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
638 //=======================================================================
639 //function : SetColor
641 //=======================================================================
642 void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
644 hasOwnColor = Standard_True;
645 myDrawer->SetColor (theColor);
647 SetDatumPartColor (Prs3d_DP_Origin, theColor);
648 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
649 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
650 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
653 //=======================================================================
654 //function : SetArrowColor
656 //=======================================================================
657 void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
661 myHasOwnArrowColor = Standard_True;
662 myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
665 //=======================================================================
666 //function : TextColor
668 //=======================================================================
669 Quantity_Color AIS_Trihedron::TextColor() const
671 return myDrawer->DatumAspect()->TextAspect()->Aspect()->Color();
674 //=======================================================================
675 //function : ArrowColor
677 //=======================================================================
678 Quantity_Color AIS_Trihedron::ArrowColor() const
680 return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
683 //=======================================================================
684 //function : UnsetColor
686 //=======================================================================
687 void AIS_Trihedron::UnsetColor()
689 hasOwnColor = Standard_False;
690 Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
691 SetColor (aDefaultColor);
694 SetTextColor (aDefaultColor);
695 myHasOwnTextColor = Standard_False;
699 SetArrowColor (aDefaultColor);
700 myHasOwnArrowColor = Standard_False;
704 //=======================================================================
705 //function : ToDrawArrows
707 //=======================================================================
708 Standard_Boolean AIS_Trihedron::ToDrawArrows() const
710 return myDrawer->DatumAspect()->ToDrawArrows();
713 //=======================================================================
714 //function : SetDrawArrows
716 //=======================================================================
717 void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
720 myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
723 //=======================================================================
724 //function : createSensitiveEntity
726 //=======================================================================
727 Handle(Select3D_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
728 const Handle(SelectMgr_EntityOwner)& theOwner) const
730 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
731 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
732 if (aPrimitives.IsNull())
734 return Handle(Select3D_SensitiveEntity)();
737 if (thePart >= Prs3d_DP_XOYAxis
738 && thePart <= Prs3d_DP_XOZAxis)
740 const gp_Pnt anXYZ1 = aPrimitives->Vertice (1);
741 const gp_Pnt anXYZ2 = aPrimitives->Vertice (2);
742 const gp_Pnt anXYZ3 = aPrimitives->Vertice (3);
743 return new Select3D_SensitiveTriangle (theOwner, anXYZ1, anXYZ2, anXYZ3);
746 if (myTrihDispMode == Prs3d_DM_Shaded)
748 Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
749 aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
753 if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
755 const gp_Pnt anXYZ1 = aPoints->Vertice (1);
756 return new Select3D_SensitivePoint (theOwner, anXYZ1);
758 else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
760 const gp_Pnt anXYZ1 = aSegments->Vertice (1);
761 const gp_Pnt anXYZ2 = aSegments->Vertice (2);
762 return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
764 return Handle(Select3D_SensitiveEntity)();
767 // =======================================================================
768 // function : arrayOfPrimitives
770 // =======================================================================
771 Handle(Graphic3d_ArrayOfPrimitives) AIS_Trihedron::arrayOfPrimitives(
772 Prs3d_DatumParts theDatumPart) const
774 Handle(Graphic3d_ArrayOfPrimitives) anArray;
775 myPrimitives.Find(theDatumPart, anArray);
779 // =======================================================================
780 // function : updatePrimitives
782 // =======================================================================
783 void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
784 Prs3d_DatumMode theMode,
785 const gp_Pnt& theOrigin,
786 const gp_Dir& theXDirection,
787 const gp_Dir& theYDirection,
788 const gp_Dir& theZDirection)
790 myPrimitives.Clear();
792 NCollection_DataMap<Prs3d_DatumParts, gp_Dir> anAxisDirs;
793 anAxisDirs.Bind(Prs3d_DP_XAxis, theXDirection);
794 anAxisDirs.Bind(Prs3d_DP_YAxis, theYDirection);
795 anAxisDirs.Bind(Prs3d_DP_ZAxis, theZDirection);
797 NCollection_DataMap<Prs3d_DatumParts, gp_Pnt> anAxisPoints;
798 gp_XYZ anXYZOrigin = theOrigin.XYZ();
799 for (int anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
801 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
802 anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
803 theAspect->AxisLength(aPart)));
806 if (theMode == Prs3d_DM_WireFrame)
809 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
811 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
812 aPrims->AddVertex(theOrigin);
813 myPrimitives.Bind(Prs3d_DP_Origin, aPrims);
816 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
818 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
819 if (theAspect->DrawDatumPart(aPart))
821 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
822 aPrims->AddVertex(theOrigin);
823 aPrims->AddVertex(anAxisPoints.Find(aPart));
824 myPrimitives.Bind(aPart, aPrims);
827 Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
828 if (theAspect->DrawDatumPart(anArrowPart))
830 myPrimitives.Bind(anArrowPart,
831 Prs3d_Arrow::DrawSegments(anAxisPoints.Find(aPart), anAxisDirs.Find(aPart),
832 theAspect->ArrowAspect()->Angle(),
833 theAspect->AxisLength(aPart) * theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent),
834 (Standard_Integer) theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes)));
842 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
844 const Standard_Real aSphereRadius = theAspect->AxisLength(Prs3d_DP_XAxis) *
845 theAspect->Attribute(Prs3d_DP_ShadingOriginRadiusPercent);
846 const Standard_Integer aNbOfFacettes =
847 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
848 gp_Trsf aSphereTransform;
849 aSphereTransform.SetTranslationPart(gp_Vec(gp::Origin(), theOrigin));
850 myPrimitives.Bind(Prs3d_DP_Origin, Prs3d_ToolSphere::Create(aSphereRadius, aNbOfFacettes,
851 aNbOfFacettes, aSphereTransform));
855 const Standard_Integer aNbOfFacettes =
856 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
857 const Standard_Real aTubeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingTubeRadiusPercent);
858 const Standard_Real aConeLengthPercent = theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
859 const Standard_Real aConeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingConeRadiusPercent);
860 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
862 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
863 const Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
864 const bool aDrawArrow = theAspect->DrawDatumPart(anArrowPart);
865 const Standard_Real anAxisLength = theAspect->AxisLength(aPart);
866 const gp_Ax1 anAxis(theOrigin, anAxisDirs.Find(aPart));
868 if (theAspect->DrawDatumPart(aPart))
871 myPrimitives.Bind(aPart,
872 Prs3d_Arrow::DrawShaded(anAxis, anAxisLength * aTubeRadiusPercent,
873 aDrawArrow ? anAxisLength - anAxisLength * aConeLengthPercent : anAxisLength,
874 0.0, 0.0, aNbOfFacettes));
880 myPrimitives.Bind(anArrowPart, Prs3d_Arrow::DrawShaded(anAxis, 0.0, anAxisLength,
881 anAxisLength * aConeRadiusPercent,
882 anAxisLength * aConeLengthPercent, aNbOfFacettes));
888 for (Standard_Integer aPlaneIter = Prs3d_DP_XOYAxis; aPlaneIter <= Prs3d_DP_XOZAxis; ++aPlaneIter)
890 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
891 if (!theAspect->DrawDatumPart(aPart))
896 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
897 aPrims->AddVertex(theOrigin);
899 Prs3d_DatumParts aPart1 = Prs3d_DP_XAxis, aPart2 = Prs3d_DP_XAxis;
902 case Prs3d_DP_XOYAxis:
904 aPart1 = Prs3d_DP_XAxis;
905 aPart2 = Prs3d_DP_YAxis;
908 case Prs3d_DP_YOZAxis:
910 aPart1 = Prs3d_DP_YAxis;
911 aPart2 = Prs3d_DP_ZAxis;
914 case Prs3d_DP_XOZAxis:
916 aPart1 = Prs3d_DP_XAxis;
917 aPart2 = Prs3d_DP_ZAxis;
922 aPrims->AddVertex(anAxisPoints.Find(aPart1));
923 aPrims->AddVertex(anAxisPoints.Find(aPart2));
925 aPrims->AddVertex(theOrigin);
926 myPrimitives.Bind(aPart, aPrims);