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 <SelectMgr_EntityOwner.hxx>
47 #include <Standard_Type.hxx>
49 IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron, AIS_InteractiveObject)
51 //=======================================================================
52 //function : AIS_Trihedron
54 //=======================================================================
55 AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
56 : myHasOwnSize (Standard_False),
57 myHasOwnTextColor (Standard_False),
58 myHasOwnArrowColor (Standard_False),
59 myTrihDispMode (Prs3d_DM_WireFrame),
60 myComponent (theComponent)
62 // selection priorities
63 mySelectionPriority.Bind (Prs3d_DP_None, 5); // complete triedron: priority 5 (same as faces)
64 mySelectionPriority.Bind (Prs3d_DP_Origin, 8); // origin: priority 8
65 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
67 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 7); // axes: priority: 7
69 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
71 mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
75 myLabel.Bind (Prs3d_DP_XAxis, "X");
76 myLabel.Bind (Prs3d_DP_YAxis, "Y");
77 myLabel.Bind (Prs3d_DP_ZAxis, "Z");
80 //=======================================================================
81 //function : SetComponent
83 //=======================================================================
84 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
86 myComponent = theComponent;
90 //=======================================================================
91 //function : setOwnDatumAspect
93 //=======================================================================
94 void AIS_Trihedron::setOwnDatumAspect()
96 if (myDrawer->HasOwnDatumAspect())
99 Handle(Prs3d_DatumAspect) aNewAspect = new Prs3d_DatumAspect();
100 myDrawer->SetDatumAspect(aNewAspect);
102 if (myDrawer->Link().IsNull())
105 myDrawer->DatumAspect()->SetDrawArrows (myDrawer->Link()->DatumAspect()->ToDrawArrows());
106 myDrawer->DatumAspect()->SetDrawLabels (myDrawer->Link()->DatumAspect()->ToDrawLabels());
107 *myDrawer->DatumAspect()->TextAspect()->Aspect() =
108 *myDrawer->Link()->DatumAspect()->TextAspect()->Aspect();
109 *myDrawer->DatumAspect()->PointAspect()->Aspect() =
110 *myDrawer->Link()->DatumAspect()->PointAspect()->Aspect();
111 *myDrawer->DatumAspect()->ArrowAspect()->Aspect() =
112 *myDrawer->Link()->DatumAspect()->ArrowAspect()->Aspect();
114 for (int aPartIter = Prs3d_DP_Origin; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
116 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
117 if (!aNewAspect->LineAspect(aPart).IsNull())
118 *myDrawer->DatumAspect()->LineAspect(aPart)->Aspect() =
119 *myDrawer->Link()->DatumAspect()->LineAspect(aPart)->Aspect();
120 if (!aNewAspect->ShadingAspect(aPart).IsNull())
121 *myDrawer->DatumAspect()->ShadingAspect(aPart)->Aspect() =
122 *myDrawer->Link()->DatumAspect()->ShadingAspect(aPart)->Aspect();
126 //=======================================================================
129 //=======================================================================
130 void AIS_Trihedron::SetSize(const Standard_Real aValue)
132 myHasOwnSize = Standard_True;
135 myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
138 UpdatePresentations();
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));
166 UpdatePresentations();
171 //=======================================================================
174 //=======================================================================
175 Standard_Real AIS_Trihedron::Size() const
177 return myDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
180 //=======================================================================
183 //=======================================================================
184 void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
185 const Handle(Prs3d_Presentation)& thePrs,
186 const Standard_Integer theMode)
193 thePrs->SetInfiniteState (Standard_True);
195 gp_Ax2 anAxis (myComponent->Ax2());
196 updatePrimitives (myDrawer->DatumAspect(), myTrihDispMode, anAxis.Location(),
197 anAxis.XDirection(), anAxis.YDirection(), anAxis.Direction());
198 computePresentation (thePrsMgr, thePrs);
201 //=======================================================================
204 //=======================================================================
205 void AIS_Trihedron::Compute (const Handle(Prs3d_Projector)& theProjector,
206 const Handle(Geom_Transformation)& theTrsf,
207 const Handle(Prs3d_Presentation)& thePrs)
209 PrsMgr_PresentableObject::Compute (theProjector, theTrsf, thePrs);
212 //=======================================================================
213 //function : ComputeSelection
215 //=======================================================================
216 void AIS_Trihedron::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
217 const Standard_Integer theMode)
219 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
222 case AIS_TrihedronSelectionMode_EntireObject:
224 Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (
225 this, mySelectionPriority.Find (Prs3d_DP_None));
226 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
227 for (int aPartIter = isShadingMode ? Prs3d_DP_Origin : Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis;
230 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
231 if (!anAspect->DrawDatumPart (aPart))
235 theSelection->Add (createSensitiveEntity (aPart, anOwner));
239 case AIS_TrihedronSelectionMode_Origin:
241 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
242 if (anAspect->DrawDatumPart (aPart))
244 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
245 mySelectionPriority.Find (aPart));
246 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives(aPart);
247 theSelection->Add (createSensitiveEntity (aPart, anOwner));
251 case AIS_TrihedronSelectionMode_Axes:
253 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
255 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
256 if (!anAspect->DrawDatumPart (aPart))
260 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
261 mySelectionPriority.Find (aPart));
262 theSelection->Add (createSensitiveEntity (aPart, anOwner));
266 case AIS_TrihedronSelectionMode_MainPlanes:
268 // create owner for each trihedron plane
270 for (int aPartIter = Prs3d_DP_XOYAxis; aPartIter <= Prs3d_DP_XOZAxis; ++aPartIter)
272 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )aPartIter;
273 if (!anAspect->DrawDatumPart (aPart))
277 Handle(SelectMgr_EntityOwner) anOwner = new AIS_TrihedronOwner (this, aPart,
278 mySelectionPriority.Find (aPart));
279 theSelection->Add (createSensitiveEntity (aPart, anOwner));
287 //=======================================================================
288 //function : HilightOwnerWithColor
290 //=======================================================================
291 void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
292 const Handle(Prs3d_Drawer)& theStyle,
293 const Handle(SelectMgr_EntityOwner)& theOwner)
295 Handle(AIS_TrihedronOwner) anOwner = Handle(AIS_TrihedronOwner)::DownCast (theOwner);
296 if (anOwner.IsNull())
298 /// default 0 selection mode
299 Standard_Integer aHiMode = HasHilightMode() ? HilightMode() : 0;
300 thePM->Color (this, theStyle, aHiMode, NULL, Graphic3d_ZLayerId_Top);
304 Handle(Prs3d_Presentation) aPresentation = GetHilightPresentation (thePM);
305 if (aPresentation.IsNull())
310 aPresentation->Clear();
311 const Prs3d_DatumParts aPart = anOwner->DatumPart();
312 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
313 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
314 if (aPart >= Prs3d_DP_XOYAxis && aPart <= Prs3d_DP_XOZAxis)
316 // planes selection is equal in both shading and wireframe mode
317 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
321 if (myTrihDispMode == Prs3d_DM_Shaded)
323 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect(aPart)->Aspect());
327 if (aPart == Prs3d_DP_Origin)
329 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
333 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect(aPart)->Aspect());
337 aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
339 if (aPresentation->GetZLayer() != theStyle->ZLayer())
341 aPresentation->SetZLayer (theStyle->ZLayer());
343 aPresentation->Highlight (theStyle);
344 thePM->AddToImmediateList (aPresentation);
347 //========================================================================
348 //function : HilightSelected
350 //========================================================================
351 void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)& thePM,
352 const SelectMgr_SequenceOfOwner& theOwners)
354 if (theOwners.IsEmpty() || !HasInteractiveContext())
359 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
360 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
362 const Handle(Prs3d_Drawer)& aContextSelStyle = GetContext()->SelectionStyle();
363 const Quantity_Color& aSelectionColor = aContextSelStyle->Color();
364 for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
366 const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
367 Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
368 if (aTrihedronOwner.IsNull())
370 thePM->Color (this, aContextSelStyle, 0);
374 const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
375 Handle(Graphic3d_Group) aGroup;
376 if (mySelectedParts.Contains (aPart)
377 || !myPartToGroup.Find (aPart, aGroup))
382 if (aPart >= Prs3d_DP_XOYAxis
383 && aPart <= Prs3d_DP_XOZAxis)
385 getHighlightLineAspect()->SetColor (aSelectionColor);
386 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
392 getHighlightAspect()->SetColor (aSelectionColor);
393 aGroup->SetGroupPrimitivesAspect (getHighlightAspect()->Aspect());
397 if (aPart == Prs3d_DP_Origin)
399 getHighlightPointAspect()->SetColor (aSelectionColor);
400 aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
404 getHighlightLineAspect()->SetColor (aSelectionColor);
405 aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
409 mySelectedParts.Append (aPart);
413 //=======================================================================
414 //function : ClearSelected
416 //=======================================================================
417 void AIS_Trihedron::ClearSelected()
419 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
420 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
421 for (NCollection_List<Prs3d_DatumParts>::Iterator anIterator (mySelectedParts); anIterator.More();
424 const Prs3d_DatumParts aPart = anIterator.Value();
425 Handle(Graphic3d_Group) aGroup = myPartToGroup.Find (aPart);
426 if (aPart >= Prs3d_DP_XOYAxis
427 && aPart <= Prs3d_DP_XOZAxis)
429 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
433 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
437 if (aPart == Prs3d_DP_Origin)
439 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
443 aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
447 mySelectedParts.Clear();
450 //=======================================================================
451 //function : computePresentation
453 //=======================================================================
454 void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
455 const Handle(Prs3d_Presentation)& thePrs)
457 myPartToGroup.Clear();
458 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
459 const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
462 // Origin is visualized only in shading mode
463 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
464 const Prs3d_DatumParts aPart = Prs3d_DP_Origin;
465 if (anAspect->DrawDatumPart(aPart))
467 myPartToGroup.Bind (aPart, aGroup);
470 aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
474 aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
476 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
482 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
484 Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
485 if (!anAspect->DrawDatumPart (aPart))
490 Handle(Graphic3d_Group) anAxisGroup = Prs3d_Root::NewGroup (thePrs);
491 myPartToGroup.Bind (aPart, anAxisGroup);
494 anAxisGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
498 anAxisGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
500 anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
503 Prs3d_DatumParts anArrowPart = anAspect->ArrowPartForAxis (aPart);
504 if (!anAspect->DrawDatumPart (anArrowPart))
509 Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
510 anArrowGroup->SetGroupPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
511 anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
516 if (anAspect->ToDrawLabels())
518 Handle(Geom_Axis2Placement) aComponent = myComponent;
519 const gp_Pnt anOrigin = aComponent->Location();
520 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
522 const Prs3d_DatumParts aPart = (Prs3d_DatumParts )anAxisIter;
523 if (!anAspect->DrawDatumPart (aPart))
528 const Standard_Real anAxisLength = anAspect->AxisLength (aPart);
529 const TCollection_ExtendedString& aLabel = myLabel.Find (aPart);
533 case Prs3d_DP_XAxis: aDir = aComponent->XDirection(); break;
534 case Prs3d_DP_YAxis: aDir = aComponent->YDirection(); break;
535 case Prs3d_DP_ZAxis: aDir = aComponent->Direction(); break;
538 Handle(Graphic3d_Group) aLabelGroup = Prs3d_Root::NewGroup (thePrs);
539 const gp_Pnt aPoint = anOrigin.XYZ() + aDir.XYZ() * anAxisLength;
540 Prs3d_Text::Draw (aLabelGroup, anAspect->TextAspect(), aLabel, aPoint);
544 // planes invisible group for planes selection
545 for (Standard_Integer anAxisIter = Prs3d_DP_XOYAxis; anAxisIter <= Prs3d_DP_XOZAxis; ++anAxisIter)
547 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
548 if (!anAspect->DrawDatumPart(aPart))
553 Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
554 myPartToGroup.Bind (aPart, aGroup);
556 const Handle(Graphic3d_AspectLine3d)& aLineAspect = anAspect->LineAspect (aPart)->Aspect();
557 aLineAspect->SetType (Aspect_TOL_EMPTY);
559 aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
560 aGroup->SetGroupPrimitivesAspect (aLineAspect);
564 //=======================================================================
565 //function : SetColor
567 //=======================================================================
568 void AIS_Trihedron::SetDatumPartColor (const Prs3d_DatumParts thePart,
569 const Quantity_Color& theColor)
573 myDrawer->DatumAspect()->ShadingAspect (thePart)->SetColor (theColor);
574 if (thePart != Prs3d_DP_Origin)
576 myDrawer->DatumAspect()->LineAspect (thePart)->SetColor (theColor);
580 //=======================================================================
581 //function : SetTextColor
583 //=======================================================================
584 void AIS_Trihedron::SetTextColor (const Quantity_Color& theColor)
587 myDrawer->DatumAspect()->TextAspect()->SetColor (theColor);
590 //=======================================================================
593 //=======================================================================
594 Quantity_Color AIS_Trihedron::DatumPartColor (Prs3d_DatumParts thePart)
596 if (myTrihDispMode == Prs3d_DM_Shaded)
598 return myDrawer->DatumAspect()->ShadingAspect (thePart)->Color();
602 return myDrawer->DatumAspect()->LineAspect (thePart)->Aspect()->Color();
606 //=======================================================================
607 //function : SetOriginColor
609 //=======================================================================
610 void AIS_Trihedron::SetOriginColor (const Quantity_Color& theColor)
612 if (myTrihDispMode == Prs3d_DM_Shaded)
614 SetDatumPartColor (Prs3d_DP_Origin, theColor);
618 //=======================================================================
619 //function : SetXAxisColor
621 //=======================================================================
622 void AIS_Trihedron::SetXAxisColor (const Quantity_Color& theColor)
624 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
627 //=======================================================================
628 //function : SetYAxisColor
630 //=======================================================================
631 void AIS_Trihedron::SetYAxisColor (const Quantity_Color& theColor)
633 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
636 //=======================================================================
637 //function : SetAxisColor
639 //=======================================================================
640 void AIS_Trihedron::SetAxisColor (const Quantity_Color& theColor)
642 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
645 //=======================================================================
646 //function : SetColor
648 //=======================================================================
649 void AIS_Trihedron::SetColor (const Quantity_Color& theColor)
651 hasOwnColor = Standard_True;
652 myDrawer->SetColor (theColor);
654 SetDatumPartColor (Prs3d_DP_Origin, theColor);
655 SetDatumPartColor (Prs3d_DP_XAxis, theColor);
656 SetDatumPartColor (Prs3d_DP_YAxis, theColor);
657 SetDatumPartColor (Prs3d_DP_ZAxis, theColor);
660 //=======================================================================
661 //function : SetArrowColor
663 //=======================================================================
664 void AIS_Trihedron::SetArrowColor (const Quantity_Color& theColor)
668 myHasOwnArrowColor = Standard_True;
669 myDrawer->DatumAspect()->ArrowAspect()->SetColor (theColor);
672 //=======================================================================
673 //function : TextColor
675 //=======================================================================
676 Quantity_Color AIS_Trihedron::TextColor() const
678 return myDrawer->DatumAspect()->TextAspect()->Aspect()->Color();
681 //=======================================================================
682 //function : ArrowColor
684 //=======================================================================
685 Quantity_Color AIS_Trihedron::ArrowColor() const
687 return myDrawer->DatumAspect()->ArrowAspect()->Aspect()->Color();
690 //=======================================================================
691 //function : UnsetColor
693 //=======================================================================
694 void AIS_Trihedron::UnsetColor()
696 hasOwnColor = Standard_False;
697 Quantity_Color aDefaultColor (Quantity_NOC_LIGHTSTEELBLUE4);
698 SetColor (aDefaultColor);
701 SetTextColor (aDefaultColor);
702 myHasOwnTextColor = Standard_False;
706 SetArrowColor (aDefaultColor);
707 myHasOwnArrowColor = Standard_False;
711 //=======================================================================
712 //function : ToDrawArrows
714 //=======================================================================
715 Standard_Boolean AIS_Trihedron::ToDrawArrows() const
717 return myDrawer->DatumAspect()->ToDrawArrows();
720 //=======================================================================
721 //function : SetDrawArrows
723 //=======================================================================
724 void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
727 myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
730 //=======================================================================
731 //function : createSensitiveEntity
733 //=======================================================================
734 Handle(Select3D_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
735 const Handle(SelectMgr_EntityOwner)& theOwner) const
737 Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
738 Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
739 if (aPrimitives.IsNull())
741 return Handle(Select3D_SensitiveEntity)();
744 if (thePart >= Prs3d_DP_XOYAxis
745 && thePart <= Prs3d_DP_XOZAxis)
747 const gp_Pnt anXYZ1 = aPrimitives->Vertice (1);
748 const gp_Pnt anXYZ2 = aPrimitives->Vertice (2);
749 const gp_Pnt anXYZ3 = aPrimitives->Vertice (3);
750 return new Select3D_SensitiveTriangle (theOwner, anXYZ1, anXYZ2, anXYZ3);
753 if (myTrihDispMode == Prs3d_DM_Shaded)
755 Handle(Select3D_SensitivePrimitiveArray) aSelArray = new Select3D_SensitivePrimitiveArray (theOwner);
756 aSelArray->InitTriangulation (aPrimitives->Attributes(), aPrimitives->Indices(), TopLoc_Location());
760 if (Handle(Graphic3d_ArrayOfPoints) aPoints = Handle(Graphic3d_ArrayOfPoints)::DownCast(aPrimitives))
762 const gp_Pnt anXYZ1 = aPoints->Vertice (1);
763 return new Select3D_SensitivePoint (theOwner, anXYZ1);
765 else if (Handle(Graphic3d_ArrayOfSegments) aSegments = Handle(Graphic3d_ArrayOfSegments)::DownCast(aPrimitives))
767 const gp_Pnt anXYZ1 = aSegments->Vertice (1);
768 const gp_Pnt anXYZ2 = aSegments->Vertice (2);
769 return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
771 return Handle(Select3D_SensitiveEntity)();
774 // =======================================================================
775 // function : arrayOfPrimitives
777 // =======================================================================
778 Handle(Graphic3d_ArrayOfPrimitives) AIS_Trihedron::arrayOfPrimitives(
779 Prs3d_DatumParts theDatumPart) const
781 Handle(Graphic3d_ArrayOfPrimitives) anArray;
782 myPrimitives.Find(theDatumPart, anArray);
786 // =======================================================================
787 // function : updatePrimitives
789 // =======================================================================
790 void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
791 Prs3d_DatumMode theMode,
792 const gp_Pnt& theOrigin,
793 const gp_Dir& theXDirection,
794 const gp_Dir& theYDirection,
795 const gp_Dir& theZDirection)
797 myPrimitives.Clear();
799 NCollection_DataMap<Prs3d_DatumParts, gp_Dir> anAxisDirs;
800 anAxisDirs.Bind(Prs3d_DP_XAxis, theXDirection);
801 anAxisDirs.Bind(Prs3d_DP_YAxis, theYDirection);
802 anAxisDirs.Bind(Prs3d_DP_ZAxis, theZDirection);
804 NCollection_DataMap<Prs3d_DatumParts, gp_Pnt> anAxisPoints;
805 gp_XYZ anXYZOrigin = theOrigin.XYZ();
806 for (int anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
808 Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
809 anAxisPoints.Bind(aPart, gp_Pnt(anXYZOrigin + anAxisDirs.Find(aPart).XYZ() *
810 theAspect->AxisLength(aPart)));
813 if (theMode == Prs3d_DM_WireFrame)
816 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
818 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPoints(1);
819 aPrims->AddVertex(theOrigin);
820 myPrimitives.Bind(Prs3d_DP_Origin, aPrims);
823 for (int aPartIter = Prs3d_DP_XAxis; aPartIter <= Prs3d_DP_ZAxis; ++aPartIter)
825 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPartIter;
826 if (theAspect->DrawDatumPart(aPart))
828 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
829 aPrims->AddVertex(theOrigin);
830 aPrims->AddVertex(anAxisPoints.Find(aPart));
831 myPrimitives.Bind(aPart, aPrims);
834 Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
835 if (theAspect->DrawDatumPart(anArrowPart))
837 myPrimitives.Bind(anArrowPart,
838 Prs3d_Arrow::DrawSegments(anAxisPoints.Find(aPart), anAxisDirs.Find(aPart),
839 theAspect->ArrowAspect()->Angle(),
840 theAspect->AxisLength(aPart) * theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent),
841 (Standard_Integer) theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes)));
849 if (theAspect->DrawDatumPart(Prs3d_DP_Origin))
851 const Standard_Real aSphereRadius = theAspect->AxisLength(Prs3d_DP_XAxis) *
852 theAspect->Attribute(Prs3d_DP_ShadingOriginRadiusPercent);
853 const Standard_Integer aNbOfFacettes =
854 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
855 gp_Trsf aSphereTransform;
856 aSphereTransform.SetTranslationPart(gp_Vec(gp::Origin(), theOrigin));
857 myPrimitives.Bind(Prs3d_DP_Origin, Prs3d_ToolSphere::Create(aSphereRadius, aNbOfFacettes,
858 aNbOfFacettes, aSphereTransform));
862 const Standard_Integer aNbOfFacettes =
863 (Standard_Integer)theAspect->Attribute(Prs3d_DP_ShadingNumberOfFacettes);
864 const Standard_Real aTubeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingTubeRadiusPercent);
865 const Standard_Real aConeLengthPercent = theAspect->Attribute(Prs3d_DP_ShadingConeLengthPercent);
866 const Standard_Real aConeRadiusPercent = theAspect->Attribute(Prs3d_DP_ShadingConeRadiusPercent);
867 for (Standard_Integer anAxisIter = Prs3d_DP_XAxis; anAxisIter <= Prs3d_DP_ZAxis; ++anAxisIter)
869 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)anAxisIter;
870 const Prs3d_DatumParts anArrowPart = theAspect->ArrowPartForAxis(aPart);
871 const bool aDrawArrow = theAspect->DrawDatumPart(anArrowPart);
872 const Standard_Real anAxisLength = theAspect->AxisLength(aPart);
873 const gp_Ax1 anAxis(theOrigin, anAxisDirs.Find(aPart));
875 if (theAspect->DrawDatumPart(aPart))
878 myPrimitives.Bind(aPart,
879 Prs3d_Arrow::DrawShaded(anAxis, anAxisLength * aTubeRadiusPercent,
880 aDrawArrow ? anAxisLength - anAxisLength * aConeLengthPercent : anAxisLength,
881 0.0, 0.0, aNbOfFacettes));
887 myPrimitives.Bind(anArrowPart, Prs3d_Arrow::DrawShaded(anAxis, 0.0, anAxisLength,
888 anAxisLength * aConeRadiusPercent,
889 anAxisLength * aConeLengthPercent, aNbOfFacettes));
895 for (Standard_Integer aPlaneIter = Prs3d_DP_XOYAxis; aPlaneIter <= Prs3d_DP_XOZAxis; ++aPlaneIter)
897 const Prs3d_DatumParts aPart = (Prs3d_DatumParts)aPlaneIter;
898 if (!theAspect->DrawDatumPart(aPart))
903 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(4);
904 aPrims->AddVertex(theOrigin);
906 Prs3d_DatumParts aPart1 = Prs3d_DP_XAxis, aPart2 = Prs3d_DP_XAxis;
909 case Prs3d_DP_XOYAxis:
911 aPart1 = Prs3d_DP_XAxis;
912 aPart2 = Prs3d_DP_YAxis;
915 case Prs3d_DP_YOZAxis:
917 aPart1 = Prs3d_DP_YAxis;
918 aPart2 = Prs3d_DP_ZAxis;
921 case Prs3d_DP_XOZAxis:
923 aPart1 = Prs3d_DP_XAxis;
924 aPart2 = Prs3d_DP_ZAxis;
929 aPrims->AddVertex(anAxisPoints.Find(aPart1));
930 aPrims->AddVertex(anAxisPoints.Find(aPart2));
932 aPrims->AddVertex(theOrigin);
933 myPrimitives.Bind(aPart, aPrims);
937 // =======================================================================
938 // function : getHighlightAspect
940 // =======================================================================
941 Handle(Prs3d_ShadingAspect) AIS_Trihedron::getHighlightAspect()
943 if (!myHighlightAspect.IsNull())
944 return myHighlightAspect;
946 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
947 if (!myHilightDrawer.IsNull())
948 aHighlightColor = myHilightDrawer->Color();
950 myHighlightAspect = new Prs3d_ShadingAspect();
951 myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
952 myHighlightAspect->SetColor (aHighlightColor);
954 Graphic3d_MaterialAspect aHighlightMaterial;
955 aHighlightMaterial.SetColor (aHighlightColor);
956 myHighlightAspect->SetMaterial (aHighlightMaterial);
958 return myHighlightAspect;
961 // =======================================================================
962 // function : getHighlightLineAspect
964 // =======================================================================
965 Handle(Prs3d_LineAspect) AIS_Trihedron::getHighlightLineAspect()
967 if (!myHighlightLineAspect.IsNull())
968 return myHighlightLineAspect;
970 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
971 if (!myHilightDrawer.IsNull())
972 aHighlightColor = myHilightDrawer->Color();
974 Handle(Prs3d_DatumAspect) aDatumAspect = Attributes()->DatumAspect();
975 Handle(Prs3d_LineAspect) aLineAspect = aDatumAspect->LineAspect(Prs3d_DP_XAxis);
976 myHighlightLineAspect = new Prs3d_LineAspect (aHighlightColor, aLineAspect->Aspect()->Type(),
977 aLineAspect->Aspect()->Width());
979 return myHighlightLineAspect;
982 // =======================================================================
983 // function : getHighlightPointAspect
985 // =======================================================================
986 Handle(Prs3d_PointAspect) AIS_Trihedron::getHighlightPointAspect()
988 if (!myHighlightPointAspect.IsNull())
989 return myHighlightPointAspect;
991 Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
992 if (!myHilightDrawer.IsNull())
993 aHighlightColor = myHilightDrawer->Color();
994 myHighlightPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, aHighlightColor, 1.0);
996 return myHighlightPointAspect;