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 <AIS_TrihedronSelectionMode.hxx>
22 #include <Geom_Axis2Placement.hxx>
24 #include <Graphic3d_AspectLine3d.hxx>
25 #include <Graphic3d_ArrayOfPoints.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
28 #include <Prs3d_Arrow.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_DatumAspect.hxx>
31 #include <Prs3d_Drawer.hxx>
32 #include <Prs3d_LineAspect.hxx>
33 #include <Prs3d_PointAspect.hxx>
34 #include <Prs3d_Presentation.hxx>
35 #include <Prs3d_ShadingAspect.hxx>
36 #include <Prs3d_Text.hxx>
37 #include <Prs3d_TextAspect.hxx>
38 #include <Prs3d_ToolSphere.hxx>
40 #include <Select3D_SensitivePoint.hxx>
41 #include <Select3D_SensitivePrimitiveArray.hxx>
42 #include <Select3D_SensitiveSegment.hxx>
43 #include <Select3D_SensitiveTriangle.hxx>
44 #include <SelectMgr_EntityOwner.hxx>
45 #include <Standard_Type.hxx>
47 IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
49 //=======================================================================
50 //function : AIS_Trihedron
52 //=======================================================================
53 AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
54 : myComponent (theComponent),
55 myTrihDispMode (Prs3d_DM_WireFrame),
56 myHasOwnSize (Standard_False),
57 myHasOwnTextColor (Standard_False),
58 myHasOwnArrowColor (Standard_False)
60 myAutoHilight = Standard_False;
62 // selection priorities
63 memset (mySelectionPriority, 0, sizeof(mySelectionPriority));
64 mySelectionPriority[Prs3d_DatumParts_None] = 5; // complete trihedron: priority 5 (same as faces)
65 mySelectionPriority[Prs3d_DatumParts_Origin] = 8; // origin: priority 8
66 for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
68 mySelectionPriority[aPartIter] = 7; // axes: priority: 7
70 for (int aPartIter = Prs3d_DatumParts_XOYAxis; aPartIter <= Prs3d_DatumParts_XOZAxis; ++aPartIter)
72 mySelectionPriority[aPartIter] = 5; // planes: priority: 5
74 myHiddenLineAspect = new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_EMPTY, 1.0f);
77 myLabels[Prs3d_DatumParts_XAxis] = "X";
78 myLabels[Prs3d_DatumParts_YAxis] = "Y";
79 myLabels[Prs3d_DatumParts_ZAxis] = "Z";
82 //=======================================================================
83 //function : SetComponent
85 //=======================================================================
86 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
88 myComponent = theComponent;
92 //=======================================================================
93 //function : setOwnDatumAspect
95 //=======================================================================
96 void AIS_Trihedron::setOwnDatumAspect()
98 if (myDrawer->HasOwnDatumAspect())
103 Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
104 myDrawer->SetDatumAspect (aNewAspect);
105 if (!myDrawer->Link().IsNull())
107 aNewAspect->CopyAspectsFrom (myDrawer->Link()->DatumAspect());
111 //=======================================================================
114 //=======================================================================
115 void AIS_Trihedron::SetSize(const Standard_Real theValue)
117 myHasOwnSize = Standard_True;
120 myDrawer->DatumAspect()->SetAxisLength (theValue, theValue, theValue);
126 //=======================================================================
127 //function : UnsetSize
129 //=======================================================================
130 void AIS_Trihedron::UnsetSize()
137 myHasOwnSize = Standard_False;
140 const Handle(Prs3d_DatumAspect) DA = myDrawer->HasLink()
141 ? myDrawer->Link()->DatumAspect()
142 : new Prs3d_DatumAspect();
143 myDrawer->DatumAspect()->SetAxisLength (DA->AxisLength (Prs3d_DatumParts_XAxis),
144 DA->AxisLength (Prs3d_DatumParts_YAxis),
145 DA->AxisLength (Prs3d_DatumParts_ZAxis));
154 //=======================================================================
157 //=======================================================================
158 Standard_Real AIS_Trihedron::Size() const
160 return myDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
163 //=======================================================================
166 //=======================================================================
167 void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
168 const Handle(Prs3d_Presentation)& thePrs,
169 const Standard_Integer theMode)
176 thePrs->SetInfiniteState (Standard_True);
178 gp_Ax2 anAxis (myComponent->Ax2());
179 updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
180 anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
181 computePresentation (thePrsMgr, thePrs);
184 //=======================================================================
185 //function : ComputeSelection
187 //=======================================================================
188 void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
189 const Standard_Integer theMode)
191 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
194 case AIS_TrihedronSelectionMode_EntireObject:
196 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this, mySelectionPriority[Prs3d_DatumParts_None]);
197 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
198 for (int aPartIter = isShadingMode ? Prs3d_DatumParts_Origin : Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis;
201 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
202 if (!anAspect->DrawDatumPart (aPart))
206 theSelection->Add (createSensitiveEntity (aPart, anOwner));
210 case AIS_TrihedronSelectionMode_Origin:
212 const Prs3d_DatumParts aPart = Prs3d_DatumParts_Origin;
213 if (anAspect->DrawDatumPart (aPart))
215 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
216 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives(aPart);
217 theSelection->Add (createSensitiveEntity (aPart, anOwner));
221 case AIS_TrihedronSelectionMode_Axes:
223 for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
225 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
226 if (!anAspect->DrawDatumPart (aPart))
230 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
231 theSelection->Add (createSensitiveEntity (aPart, anOwner));
235 case AIS_TrihedronSelectionMode_MainPlanes:
237 // create owner for each trihedron plane
239 for (int aPartIter = Prs3d_DatumParts_XOYAxis; aPartIter <= Prs3d_DatumParts_XOZAxis; ++aPartIter)
241 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
242 if (!anAspect->DrawDatumPart (aPart))
246 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart, mySelectionPriority[aPart]);
247 theSelection->Add (createSensitiveEntity (aPart, anOwner));
255 //=======================================================================
256 //function : HilightOwnerWithColor
258 //=======================================================================
259 void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager)& thePM,
260 const Handle(Prs3d_Drawer)& theStyle,
261 const Handle(SelectMgr_EntityOwner)& theOwner)
263 Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
264 if (anOwner.IsNull())
266 // default 0 selection mode
267 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
268 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
272 Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
273 if (aPresentation.IsNull())
278 aPresentation->Clear();
279 const Prs3d_DatumParts aPart = anOwner->DatumPart();
280 Handle(Graphic3d_Group) aGroup = aPresentation->CurrentGroup();
281 if (aPart >= Prs3d_DatumParts_XOYAxis && aPart <= Prs3d_DatumParts_XOZAxis)
283 // planes selection is equal in both shading and wireframe mode
284 aGroup->SetGroupPrimitivesAspect (theStyle->LineAspect()->Aspect());
288 if (myTrihDispMode == Prs3d_DM_Shaded)
290 aGroup->SetGroupPrimitivesAspect (theStyle->ShadingAspect()->Aspect());
294 if (aPart == Prs3d_DatumParts_Origin)
296 aGroup->SetGroupPrimitivesAspect (theStyle->PointAspect()->Aspect());
300 aGroup->SetGroupPrimitivesAspect(theStyle->LineAspect()->Aspect());
304 aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
306 const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer();
307 if (aPresentation->GetZLayer() != aLayer)
309 aPresentation->SetZLayer (aLayer);
312 aPresentation->Highlight (theStyle);
313 thePM->AddToImmediateList (aPresentation);
316 //========================================================================
317 //function : HilightSelected
319 //========================================================================
320 void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager)& thePM,
321 const SelectMgr_SequenceOfOwner& theOwners)
323 if (theOwners.IsEmpty() || !HasInteractiveContext())
328 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
330 Handle(Prs3d_Drawer) anAspect = !myHilightDrawer.IsNull() ? myHilightDrawer : GetContext()->SelectionStyle();
331 for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
333 const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
334 Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
335 if (aTrihedronOwner.IsNull())
337 thePM->Color (this, anAspect, 0);
341 const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
342 if (myPartToGroup[aPart].IsNull()
343 || mySelectedParts.Contains (aPart))
348 const Handle(Graphic3d_Group)& aGroup = myPartToGroup[aPart];
349 if (aPart >= Prs3d_DatumParts_XOYAxis
350 && aPart <= Prs3d_DatumParts_XOZAxis)
352 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
358 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect()->Aspect());
362 if (aPart == Prs3d_DatumParts_Origin)
364 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
368 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
372 mySelectedParts.Append (aPart);
376 //=======================================================================
377 //function : ClearSelected
379 //=======================================================================
380 void AIS_Trihedron::ClearSelected()
382 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
383 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
384 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (mySelectedParts); anIterator.More();
387 const Prs3d_DatumParts aPart = anIterator.Value();
388 const Handle(Graphic3d_Group)& aGroup = myPartToGroup[aPart];
389 if (aPart >= Prs3d_DatumParts_XOYAxis
390 && aPart <= Prs3d_DatumParts_XOZAxis)
392 aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
394 else if (isShadingMode)
396 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
400 if (aPart == Prs3d_DatumParts_Origin)
402 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
406 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
410 mySelectedParts.Clear();
413 //=======================================================================
414 //function : computePresentation
416 //=======================================================================
417 void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager)& /*thePrsMgr*/,
418 const Handle(Prs3d_Presentation)& thePrs)
420 for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_NB; ++aPartIter)
422 myPartToGroup[aPartIter].Nullify();
425 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
426 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
429 // Origin is visualized only in shading mode
430 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
431 const Prs3d_DatumParts aPart = Prs3d_DatumParts_Origin;
432 if (anAspect->DrawDatumPart(aPart))
434 myPartToGroup[aPart] = aGroup;
437 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
441 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
443 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
449 for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
451 Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
452 if (!anAspect->DrawDatumPart (aPart))
457 Handle(Graphic3d_Group) anAxisGroup = thePrs->NewGroup();
458 myPartToGroup[aPart] = anAxisGroup;
461 anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
465 anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
467 anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
470 const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
471 if (!anAspect->DrawDatumPart (anArrowPart))
476 Handle(Graphic3d_Group) anArrowGroup = thePrs->NewGroup();
479 anArrowGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (anArrowPart)->Aspect());
483 anArrowGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (anArrowPart)->Aspect());
485 anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
490 if (anAspect->ToDrawLabels())
492 Handle(Geom_Axis2Placement) aComponent = myComponent;
493 const gp_Pnt anOrigin = aComponent->Location();
494 for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
496 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
497 if (!anAspect->DrawDatumPart (aPart))
502 const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
503 const TCollection_ExtendedString& aLabel = myLabels[aPart];
507 case Prs3d_DatumParts_XAxis: aDir = aComponent->XDirection(); break;
508 case Prs3d_DatumParts_YAxis: aDir = aComponent->YDirection(); break;
509 case Prs3d_DatumParts_ZAxis: aDir = aComponent->Direction(); break;
512 Handle(Graphic3d_Group) aLabelGroup = thePrs->NewGroup();
513 const gp_Pnt aPoint = anOrigin.XYZ() + aDir.XYZ() * anAxisLength;
514 Prs3d_Text::Draw (aLabelGroup, anAspect->TextAspect (aPart), aLabel, aPoint);
518 // planes invisible group for planes selection
519 for (Standard_Integer anAxisIter = Prs3d_DatumParts_XOYAxis; anAxisIter <= Prs3d_DatumParts_XOZAxis; ++anAxisIter)
521 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
522 if (!anAspect->DrawDatumPart(aPart))
527 Handle(Graphic3d_Group) aGroup = thePrs->NewGroup();
528 myPartToGroup[aPart] = aGroup;
530 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
531 aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
535 //=======================================================================
536 //function : SetColor
538 //=======================================================================
539 void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
540 const Quantity_Color& theColor)
544 myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
545 if (thePart != Prs3d_DatumParts_Origin)
547 myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
551 //=======================================================================
552 //function : SetTextColor
554 //=======================================================================
555 void AIS_Trihedron::SetTextColor (const Prs3d_DatumParts thePart,
556 const Quantity_Color& theColor)
559 myDrawer->DatumAspect()->TextAspect (thePart)->SetColor (theColor);
562 //=======================================================================
563 //function : SetTextColor
565 //=======================================================================
566 void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
569 myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_XAxis)->SetColor (theColor);
570 myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_YAxis)->SetColor (theColor);
571 myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_ZAxis)->SetColor (theColor);
574 //=======================================================================
577 //=======================================================================
578 Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
580 if (myTrihDispMode == Prs3d_DM_Shaded)
582 return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
586 return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
590 //=======================================================================
591 //function : SetOriginColor
593 //=======================================================================
594 void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
596 if (myTrihDispMode == Prs3d_DM_Shaded)
598 SetDatumPartColor (Prs3d_DatumParts_Origin, theColor);
602 //=======================================================================
603 //function : SetXAxisColor
605 //=======================================================================
606 void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
608 SetDatumPartColor (Prs3d_DatumParts_XAxis, theColor);
611 //=======================================================================
612 //function : SetYAxisColor
614 //=======================================================================
615 void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
617 SetDatumPartColor (Prs3d_DatumParts_YAxis, theColor);
620 //=======================================================================
621 //function : SetAxisColor
623 //=======================================================================
624 void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
626 SetDatumPartColor (Prs3d_DatumParts_ZAxis, theColor);
629 //=======================================================================
630 //function : SetColor
632 //=======================================================================
633 void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
635 hasOwnColor = Standard_True;
636 myDrawer->SetColor (theColor);
638 SetDatumPartColor (Prs3d_DatumParts_Origin, theColor);
639 SetDatumPartColor (Prs3d_DatumParts_XAxis, theColor);
640 SetDatumPartColor (Prs3d_DatumParts_YAxis, theColor);
641 SetDatumPartColor (Prs3d_DatumParts_ZAxis, theColor);
644 //=======================================================================
645 //function : SetArrowColor
647 //=======================================================================
648 void AIS_Trihedron::SetArrowColor (const Prs3d_DatumParts thePart,
649 const Quantity_Color& theColor)
652 myHasOwnArrowColor = Standard_True;
653 const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (thePart);
654 myDrawer->DatumAspect()->ShadingAspect(anArrowPart)->SetColor (theColor);
655 myDrawer->DatumAspect()->LineAspect (anArrowPart)->SetColor (theColor);
658 //=======================================================================
659 //function : SetArrowColor
661 //=======================================================================
662 void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
666 myHasOwnArrowColor = Standard_True;
667 myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
668 for (Standard_Integer anAxisIter = Prs3d_DatumParts_XArrow; anAxisIter <= Prs3d_DatumParts_ZArrow; ++anAxisIter)
670 myDrawer->DatumAspect()->ShadingAspect((Prs3d_DatumParts )anAxisIter)->SetColor (theColor);
671 myDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )anAxisIter)->SetColor (theColor);
675 //=======================================================================
676 //function : TextColor
678 //=======================================================================
679 Quantity_Color AIS_Trihedron::TextColor() const
681 return myDrawer->DatumAspect()->TextAspect (Prs3d_DatumParts_XAxis)->Aspect()->Color();
684 //=======================================================================
685 //function : ArrowColor
687 //=======================================================================
688 Quantity_Color AIS_Trihedron::ArrowColor() const
690 return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
693 //=======================================================================
694 //function : UnsetColor
696 //=======================================================================
697 void AIS_Trihedron::UnsetColor()
699 hasOwnColor = Standard_False;
700 Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
701 SetColor (aDefaultColor);
704 SetTextColor (aDefaultColor);
705 myHasOwnTextColor = Standard_False;
709 SetArrowColor (aDefaultColor);
710 myHasOwnArrowColor = Standard_False;
714 //=======================================================================
715 //function : ToDrawArrows
717 //=======================================================================
718 Standard_Boolean AIS_Trihedron::ToDrawArrows() const
720 return myDrawer->DatumAspect()->ToDrawArrows();
723 //=======================================================================
724 //function : SetDrawArrows
726 //=======================================================================
727 void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
730 myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
733 //=======================================================================
734 //function : createSensitiveEntity
736 //=======================================================================
737 Handle(Select3D_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
738 const Handle(SelectMgr_EntityOwner)& theOwner) const
740 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
741 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
742 if (aPrimitives.IsNull())
744 return Handle(Select3D_SensitiveEntity)();
747 if (thePart >= Prs3d_DatumParts_XOYAxis
748 && thePart <= Prs3d_DatumParts_XOZAxis)
750 const gp_Pnt anXYZ1 = aPrimitives->Vertice (1);
751 const gp_Pnt anXYZ2 = aPrimitives->Vertice (2);
752 const gp_Pnt anXYZ3 = aPrimitives->Vertice (3);
753 return new Select3D_SensitiveTriangle (theOwner, anXYZ1, anXYZ2, anXYZ3);
756 if (myTrihDispMode == Prs3d_DM_Shaded)
758 Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
759 aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
763 if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
765 const gp_Pnt anXYZ1 = aPoints->Vertice (1);
766 return new Select3D_SensitivePoint (theOwner, anXYZ1);
768 else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
770 const gp_Pnt anXYZ1 = aSegments->Vertice (1);
771 const gp_Pnt anXYZ2 = aSegments->Vertice (2);
772 return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
774 return Handle(Select3D_SensitiveEntity)();
777 // =======================================================================
778 // function : updatePrimitives
780 // =======================================================================
781 void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
782 Prs3d_DatumMode theMode,
783 const gp_Pnt& theOrigin,
784 const gp_Dir& theXDirection,
785 const gp_Dir& theYDirection,
786 const gp_Dir& theZDirection)
788 for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_NB; ++aPartIter)
790 myPrimitives[aPartIter].Nullify();
793 NCollection_DataMap<Prs3d_DatumParts, gp_Dir> anAxisDirs;
794 anAxisDirs.Bind(Prs3d_DatumParts_XAxis, theXDirection);
795 anAxisDirs.Bind(Prs3d_DatumParts_YAxis, theYDirection);
796 anAxisDirs.Bind(Prs3d_DatumParts_ZAxis, theZDirection);
798 NCollection_DataMap<Prs3d_DatumParts, gp_Pnt> anAxisPoints;
799 gp_XYZ anXYZOrigin = theOrigin.XYZ();
800 for (int anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
802 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
803 anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
804 theAspect->AxisLength(aPart)));
807 if (theMode == Prs3d_DM_WireFrame)
810 if (theAspect->DrawDatumPart(Prs3d_DatumParts_Origin))
812 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
813 aPrims->AddVertex(theOrigin);
814 myPrimitives[Prs3d_DatumParts_Origin] = aPrims;
817 for (int aPartIter = Prs3d_DatumParts_XAxis; aPartIter <= Prs3d_DatumParts_ZAxis; ++aPartIter)
819 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
820 if (theAspect->DrawDatumPart(aPart))
822 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
823 aPrims->AddVertex(theOrigin);
824 aPrims->AddVertex(anAxisPoints.Find(aPart));
825 myPrimitives[aPart] = aPrims;
828 const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
829 if (theAspect->DrawDatumPart(anArrowPart))
831 myPrimitives[anArrowPart] = Prs3d_Arrow::DrawSegments (anAxisPoints.Find(aPart), anAxisDirs.Find(aPart),
832 theAspect->ArrowAspect()->Angle(),
833 theAspect->AxisLength(aPart) * theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeLengthPercent),
834 (Standard_Integer) theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes));
842 if (theAspect->DrawDatumPart(Prs3d_DatumParts_Origin))
844 const Standard_Real aSphereRadius = theAspect->AxisLength(Prs3d_DatumParts_XAxis) *
845 theAspect->Attribute(Prs3d_DatumAttribute_ShadingOriginRadiusPercent);
846 const Standard_Integer aNbOfFacettes =
847 (Standard_Integer)theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes);
848 gp_Trsf aSphereTransform;
849 aSphereTransform.SetTranslationPart(gp_Vec(gp::Origin(), theOrigin));
850 myPrimitives[Prs3d_DatumParts_Origin] = Prs3d_ToolSphere::Create (aSphereRadius, aNbOfFacettes, aNbOfFacettes, aSphereTransform);
854 const Standard_Integer aNbOfFacettes =
855 (Standard_Integer)theAspect->Attribute(Prs3d_DatumAttribute_ShadingNumberOfFacettes);
856 const Standard_Real aTubeRadiusPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingTubeRadiusPercent);
857 const Standard_Real aConeLengthPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeLengthPercent);
858 const Standard_Real aConeRadiusPercent = theAspect->Attribute(Prs3d_DatumAttribute_ShadingConeRadiusPercent);
859 for (Standard_Integer anAxisIter = Prs3d_DatumParts_XAxis; anAxisIter <= Prs3d_DatumParts_ZAxis; ++anAxisIter)
861 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
862 const Prs3d_DatumParts anArrowPart = Prs3d_DatumAspect::ArrowPartForAxis (aPart);
863 const bool aDrawArrow = theAspect->DrawDatumPart(anArrowPart);
864 const Standard_Real anAxisLength = theAspect->AxisLength(aPart);
865 const gp_Ax1 anAxis(theOrigin, anAxisDirs.Find(aPart));
867 if (theAspect->DrawDatumPart(aPart))
870 myPrimitives[aPart] = Prs3d_Arrow::DrawShaded (anAxis, anAxisLength * aTubeRadiusPercent,
871 aDrawArrow ? (anAxisLength - anAxisLength * aConeLengthPercent) : anAxisLength,
872 0.0, 0.0, aNbOfFacettes);
878 myPrimitives[anArrowPart] = Prs3d_Arrow::DrawShaded (anAxis, 0.0, anAxisLength,
879 anAxisLength * aConeRadiusPercent,
880 anAxisLength * aConeLengthPercent, aNbOfFacettes);
886 for (Standard_Integer aPlaneIter = Prs3d_DatumParts_XOYAxis; aPlaneIter <= Prs3d_DatumParts_XOZAxis; ++aPlaneIter)
888 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
889 if (!theAspect->DrawDatumPart(aPart))
894 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
895 aPrims->AddVertex(theOrigin);
897 Prs3d_DatumParts aPart1 = Prs3d_DatumParts_XAxis, aPart2 = Prs3d_DatumParts_XAxis;
900 case Prs3d_DatumParts_XOYAxis:
902 aPart1 = Prs3d_DatumParts_XAxis;
903 aPart2 = Prs3d_DatumParts_YAxis;
906 case Prs3d_DatumParts_YOZAxis:
908 aPart1 = Prs3d_DatumParts_YAxis;
909 aPart2 = Prs3d_DatumParts_ZAxis;
912 case Prs3d_DatumParts_XOZAxis:
914 aPart1 = Prs3d_DatumParts_XAxis;
915 aPart2 = Prs3d_DatumParts_ZAxis;
920 aPrims->AddVertex(anAxisPoints.Find(aPart1));
921 aPrims->AddVertex(anAxisPoints.Find(aPart2));
923 aPrims->AddVertex(theOrigin);
924 myPrimitives[aPart] = aPrims;
928 //=======================================================================
929 //function : DumpJson
931 //=======================================================================
932 void AIS_Trihedron::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
934 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
936 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
938 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnSize)
939 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnTextColor)
940 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnArrowColor)
941 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTrihDispMode)