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_Presentation.hxx>
36 #include <Prs3d_Projector.hxx>
37 #include <Prs3d_ShadingAspect.hxx>
38 #include <Prs3d_Text.hxx>
39 #include <Prs3d_TextAspect.hxx>
40 #include <Prs3d_ToolSphere.hxx>
42 #include <Select3D_SensitivePoint.hxx>
43 #include <Select3D_SensitivePrimitiveArray.hxx>
44 #include <Select3D_SensitiveSegment.hxx>
45 #include <Select3D_SensitiveTriangle.hxx>
46 #include <SelectBasics_EntityOwner.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 // 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)
68 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 7); // axes: priority: 7
70 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
72 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
76 myLabel.Bind (Prs3d_DP_XAxis, "X");
77 myLabel.Bind (Prs3d_DP_YAxis, "Y");
78 myLabel.Bind (Prs3d_DP_ZAxis, "Z");
81 //=======================================================================
82 //function : SetComponent
84 //=======================================================================
85 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
87 myComponent = theComponent;
88 LoadRecomputable (AIS_WireFrame);
91 //=======================================================================
92 //function : setOwnDatumAspect
94 //=======================================================================
95 void AIS_Trihedron::setOwnDatumAspect()
97 if (myDrawer->HasOwnDatumAspect())
100 Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
101 myDrawer->SetDatumAspect(aNewAspect);
103 if (myDrawer->Link().IsNull())
106 myDrawer->DatumAspect()->SetDrawArrows (myDrawer->Link()->DatumAspect()->ToDrawArrows());
107 myDrawer->DatumAspect()->SetDrawLabels (myDrawer->Link()->DatumAspect()->ToDrawLabels());
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();
115 for (int aPartIter = Prs3d_DP_Origin; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
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();
127 //=======================================================================
130 //=======================================================================
131 void AIS_Trihedron::SetSize(const Standard_Real aValue)
133 myHasOwnSize = Standard_True;
136 myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
142 //=======================================================================
143 //function : UnsetSize
145 //=======================================================================
146 void AIS_Trihedron::UnsetSize()
153 myHasOwnSize = Standard_False;
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));
170 //=======================================================================
173 //=======================================================================
174 Standard_Real AIS_Trihedron::Size() const
176 return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
179 //=======================================================================
182 //=======================================================================
183 void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
184 const Handle(Prs3d_Presentation)& thePrs,
185 const Standard_Integer theMode)
192 thePrs->SetInfiniteState (Standard_True);
194 gp_Ax2 anAxis (myComponent->Ax2());
195 updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
196 anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
197 computePresentation (thePrsMgr, thePrs);
200 //=======================================================================
203 //=======================================================================
204 void AIS_Trihedron::Compute (const Handle(Prs3d_Projector)& theProjector,
205 const Handle(Geom_Transformation)& theTrsf,
206 const Handle(Prs3d_Presentation)& thePrs)
208 PrsMgr_PresentableObject::Compute (theProjector, theTrsf, thePrs);
211 //=======================================================================
212 //function : ComputeSelection
214 //=======================================================================
215 void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
216 const Standard_Integer theMode)
218 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
221 case AIS_TrihedronSelectionMode_EntireObject:
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;
229 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
230 if (!anAspect->DrawDatumPart (aPart))
234 theSelection->Add (createSensitiveEntity (aPart, anOwner));
238 case AIS_TrihedronSelectionMode_Origin:
240 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
241 if (anAspect->DrawDatumPart (aPart))
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));
250 case AIS_TrihedronSelectionMode_Axes:
252 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
254 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
255 if (!anAspect->DrawDatumPart (aPart))
259 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
260 mySelectionPriority.Find (aPart));
261 theSelection->Add (createSensitiveEntity (aPart, anOwner));
265 case AIS_TrihedronSelectionMode_MainPlanes:
267 // create owner for each trihedron plane
269 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
271 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
272 if (!anAspect->DrawDatumPart (aPart))
276 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
277 mySelectionPriority.Find (aPart));
278 theSelection->Add (createSensitiveEntity (aPart, anOwner));
286 //=======================================================================
287 //function : HilightOwnerWithColor
289 //=======================================================================
290 void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
291 const Handle(Prs3d_Drawer)& theStyle,
292 const Handle(SelectMgr_EntityOwner)& theOwner)
294 Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
295 if (anOwner.IsNull())
297 /// default 0 selection mode
298 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
299 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
303 Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
304 if (aPresentation.IsNull())
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)
315 // planes selection is equal in both shading and wireframe mode
316 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
320 if (myTrihDispMode == Prs3d_DM_Shaded)
322 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect(aPart)->Aspect());
326 if (aPart == Prs3d_DP_Origin)
328 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
332 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect(aPart)->Aspect());
336 aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
338 if (aPresentation->GetZLayer() != theStyle->ZLayer())
340 aPresentation->SetZLayer (theStyle->ZLayer());
342 aPresentation->Highlight (theStyle);
343 thePM->AddToImmediateList (aPresentation);
346 //========================================================================
347 //function : HilightSelected
349 //========================================================================
350 void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
351 const SelectMgr_SequenceOfOwner& theOwners)
353 if (theOwners.IsEmpty() || !HasInteractiveContext())
358 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
359 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
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())
365 const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
366 Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
367 if (aTrihedronOwner.IsNull())
369 thePM->Color (this, aContextSelStyle, 0);
373 const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
374 Handle(Graphic3d_Group) aGroup;
375 if (mySelectedParts.Contains (aPart)
376 || !myPartToGroup.Find (aPart, aGroup))
381 if (aPart >= Prs3d_DP_XOYAxis
382 && aPart <= Prs3d_DP_XOZAxis)
384 getHighlightLineAspect()->SetColor (aSelectionColor);
385 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
391 getHighlightAspect()->SetColor (aSelectionColor);
392 aGroup->SetGroupPrimitivesAspect (getHighlightAspect()->Aspect());
396 if (aPart == Prs3d_DP_Origin)
398 getHighlightPointAspect()->SetColor (aSelectionColor);
399 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
403 getHighlightLineAspect()->SetColor (aSelectionColor);
404 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
408 mySelectedParts.Append (aPart);
412 //=======================================================================
413 //function : ClearSelected
415 //=======================================================================
416 void AIS_Trihedron::ClearSelected()
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();
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)
428 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
432 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
436 if (aPart == Prs3d_DP_Origin)
438 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
442 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
446 mySelectedParts.Clear();
449 //=======================================================================
450 //function : computePresentation
452 //=======================================================================
453 void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
454 const Handle(Prs3d_Presentation)& thePrs)
456 myPartToGroup.Clear();
457 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
458 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
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))
466 myPartToGroup.Bind (aPart, aGroup);
469 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
473 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
475 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
481 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
483 Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
484 if (!anAspect->DrawDatumPart (aPart))
489 Handle(Graphic3d_Group) anAxisGroup = Prs3d_Root::NewGroup (thePrs);
490 myPartToGroup.Bind (aPart, anAxisGroup);
493 anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
497 anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
499 anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
502 Prs3d_DatumParts anArrowPart = anAspect->ArrowPartForAxis (aPart);
503 if (!anAspect->DrawDatumPart (anArrowPart))
508 Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
509 anArrowGroup->SetGroupPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
510 anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
515 if (anAspect->ToDrawLabels())
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)
521 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
522 if (!anAspect->DrawDatumPart (aPart))
527 const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
528 const TCollection_ExtendedString& aLabel = myLabel.Find (aPart);
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;
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);
543 // planes invisible group for planes selection
544 for (Standard_Integer anAxisIter = Prs3d_DP_XOYAxis; anAxisIter <= Prs3d_DP_XOZAxis; ++anAxisIter)
546 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
547 if (!anAspect->DrawDatumPart(aPart))
552 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
553 myPartToGroup.Bind (aPart, aGroup);
555 const Handle(Graphic3d_AspectLine3d)& aLineAspect = anAspect->LineAspect (aPart)->Aspect();
556 aLineAspect->SetType (Aspect_TOL_EMPTY);
558 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
559 aGroup->SetGroupPrimitivesAspect (aLineAspect);
563 //=======================================================================
564 //function : LoadRecomputable
566 //=======================================================================
567 void AIS_Trihedron::LoadRecomputable (const Standard_Integer theMode)
569 myRecomputeEveryPrs = Standard_False;
570 if (!myToRecomputeModes.Contains (theMode))
572 myToRecomputeModes.Append (theMode);
576 //=======================================================================
577 //function : SetColor
579 //=======================================================================
580 void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
581 const Quantity_Color& theColor)
585 myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
586 if (thePart != Prs3d_DP_Origin)
588 myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
592 //=======================================================================
593 //function : SetTextColor
595 //=======================================================================
596 void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
599 myDrawer->DatumAspect()->TextAspect()->SetColor (theColor);
602 //=======================================================================
605 //=======================================================================
606 Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
608 if (myTrihDispMode == Prs3d_DM_Shaded)
610 return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
614 return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
618 //=======================================================================
619 //function : SetOriginColor
621 //=======================================================================
622 void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
624 if (myTrihDispMode == Prs3d_DM_Shaded)
626 SetDatumPartColor (Prs3d_DP_Origin, theColor);
630 //=======================================================================
631 //function : SetXAxisColor
633 //=======================================================================
634 void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
636 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
639 //=======================================================================
640 //function : SetYAxisColor
642 //=======================================================================
643 void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
645 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
648 //=======================================================================
649 //function : SetAxisColor
651 //=======================================================================
652 void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
654 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
657 //=======================================================================
658 //function : SetColor
660 //=======================================================================
661 void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
663 hasOwnColor = Standard_True;
664 myDrawer->SetColor (theColor);
666 SetDatumPartColor (Prs3d_DP_Origin, theColor);
667 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
668 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
669 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
672 //=======================================================================
673 //function : SetArrowColor
675 //=======================================================================
676 void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
680 myHasOwnArrowColor = Standard_True;
681 myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
684 //=======================================================================
685 //function : TextColor
687 //=======================================================================
688 Quantity_Color AIS_Trihedron::TextColor() const
690 return myDrawer->DatumAspect()->TextAspect()->Aspect()->Color();
693 //=======================================================================
694 //function : ArrowColor
696 //=======================================================================
697 Quantity_Color AIS_Trihedron::ArrowColor() const
699 return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
702 //=======================================================================
703 //function : UnsetColor
705 //=======================================================================
706 void AIS_Trihedron::UnsetColor()
708 hasOwnColor = Standard_False;
709 Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
710 SetColor (aDefaultColor);
713 SetTextColor (aDefaultColor);
714 myHasOwnTextColor = Standard_False;
718 SetArrowColor (aDefaultColor);
719 myHasOwnArrowColor = Standard_False;
723 //=======================================================================
724 //function : ToDrawArrows
726 //=======================================================================
727 Standard_Boolean AIS_Trihedron::ToDrawArrows() const
729 return myDrawer->DatumAspect()->ToDrawArrows();
732 //=======================================================================
733 //function : SetDrawArrows
735 //=======================================================================
736 void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
739 myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
742 //=======================================================================
743 //function : createSensitiveEntity
745 //=======================================================================
746 Handle(SelectBasics_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
747 const Handle(SelectBasics_EntityOwner)& theOwner) const
749 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
750 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
751 if (aPrimitives.IsNull())
753 return Handle(SelectBasics_SensitiveEntity)();
756 if (thePart >= Prs3d_DP_XOYAxis
757 && thePart <= Prs3d_DP_XOZAxis)
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);
765 if (myTrihDispMode == Prs3d_DM_Shaded)
767 Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
768 aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
772 if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
774 const gp_Pnt anXYZ1 = aPoints->Vertice (1);
775 return new Select3D_SensitivePoint (theOwner, anXYZ1);
777 else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
779 const gp_Pnt anXYZ1 = aSegments->Vertice (1);
780 const gp_Pnt anXYZ2 = aSegments->Vertice (2);
781 return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
783 return Handle(SelectBasics_SensitiveEntity)();
786 // =======================================================================
787 // function : arrayOfPrimitives
789 // =======================================================================
790 Handle(Graphic3d_ArrayOfPrimitives) AIS_Trihedron::arrayOfPrimitives(
791 Prs3d_DatumParts theDatumPart) const
793 Handle(Graphic3d_ArrayOfPrimitives) anArray;
794 myPrimitives.Find(theDatumPart, anArray);
798 // =======================================================================
799 // function : updatePrimitives
801 // =======================================================================
802 void 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)
809 myPrimitives.Clear();
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);
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)
820 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
821 anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
822 theAspect->AxisLength(aPart)));
825 if (theMode == Prs3d_DM_WireFrame)
828 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
830 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
831 aPrims->AddVertex(theOrigin);
832 myPrimitives.Bind(Prs3d_DP_Origin, aPrims);
835 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
837 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
838 if (theAspect->DrawDatumPart(aPart))
840 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
841 aPrims->AddVertex(theOrigin);
842 aPrims->AddVertex(anAxisPoints.Find(aPart));
843 myPrimitives.Bind(aPart, aPrims);
846 Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
847 if (theAspect->DrawDatumPart(anArrowPart))
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)));
861 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
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));
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)
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));
887 if (theAspect->DrawDatumPart(aPart))
890 myPrimitives.Bind(aPart,
891 Prs3d_Arrow::DrawShaded(anAxis, anAxisLength * aTubeRadiusPercent,
892 aDrawArrow ? anAxisLength - anAxisLength * aConeLengthPercent : anAxisLength,
893 0.0, 0.0, aNbOfFacettes));
899 myPrimitives.Bind(anArrowPart, Prs3d_Arrow::DrawShaded(anAxis, 0.0, anAxisLength,
900 anAxisLength * aConeRadiusPercent,
901 anAxisLength * aConeLengthPercent, aNbOfFacettes));
907 for (Standard_Integer aPlaneIter = Prs3d_DP_XOYAxis; aPlaneIter <= Prs3d_DP_XOZAxis; ++aPlaneIter)
909 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
910 if (!theAspect->DrawDatumPart(aPart))
915 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
916 aPrims->AddVertex(theOrigin);
918 Prs3d_DatumParts aPart1 = Prs3d_DP_XAxis, aPart2 = Prs3d_DP_XAxis;
921 case Prs3d_DP_XOYAxis:
923 aPart1 = Prs3d_DP_XAxis;
924 aPart2 = Prs3d_DP_YAxis;
927 case Prs3d_DP_YOZAxis:
929 aPart1 = Prs3d_DP_YAxis;
930 aPart2 = Prs3d_DP_ZAxis;
933 case Prs3d_DP_XOZAxis:
935 aPart1 = Prs3d_DP_XAxis;
936 aPart2 = Prs3d_DP_ZAxis;
941 aPrims->AddVertex(anAxisPoints.Find(aPart1));
942 aPrims->AddVertex(anAxisPoints.Find(aPart2));
944 aPrims->AddVertex(theOrigin);
945 myPrimitives.Bind(aPart, aPrims);
949 // =======================================================================
950 // function : getHighlightAspect
952 // =======================================================================
953 Handle(Prs3d_ShadingAspect) AIS_Trihedron::getHighlightAspect()
955 if (!myHighlightAspect.IsNull())
956 return myHighlightAspect;
958 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
959 if (!myHilightDrawer.IsNull())
960 aHighlightColor = myHilightDrawer->Color();
962 myHighlightAspect = new Prs3d_ShadingAspect();
963 myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
964 myHighlightAspect->SetColor (aHighlightColor);
966 Graphic3d_MaterialAspect aHighlightMaterial;
967 aHighlightMaterial.SetColor (aHighlightColor);
968 myHighlightAspect->SetMaterial (aHighlightMaterial);
970 return myHighlightAspect;
973 // =======================================================================
974 // function : getHighlightLineAspect
976 // =======================================================================
977 Handle(Prs3d_LineAspect) AIS_Trihedron::getHighlightLineAspect()
979 if (!myHighlightLineAspect.IsNull())
980 return myHighlightLineAspect;
982 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
983 if (!myHilightDrawer.IsNull())
984 aHighlightColor = myHilightDrawer->Color();
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());
991 return myHighlightLineAspect;
994 // =======================================================================
995 // function : getHighlightPointAspect
997 // =======================================================================
998 Handle(Prs3d_PointAspect) AIS_Trihedron::getHighlightPointAspect()
1000 if (!myHighlightPointAspect.IsNull())
1001 return myHighlightPointAspect;
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);
1008 return myHighlightPointAspect;