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_Axis.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_Plane.hxx>
23 #include <AIS_Point.hxx>
24 #include <Aspect_TypeOfLine.hxx>
25 #include <DsgPrs_DatumPrs.hxx>
26 #include <Geom_Axis2Placement.hxx>
27 #include <Geom_CartesianPoint.hxx>
28 #include <Geom_Line.hxx>
29 #include <Geom_Plane.hxx>
30 #include <Geom_Point.hxx>
31 #include <Geom_Transformation.hxx>
36 #include <gp_Trsf.hxx>
38 #include <Graphic3d_AspectFillArea3d.hxx>
39 #include <Graphic3d_AspectLine3d.hxx>
40 #include <Graphic3d_MaterialAspect.hxx>
41 #include <Graphic3d_Structure.hxx>
42 #include <Prs3d_ArrowAspect.hxx>
43 #include <Prs3d_DatumAspect.hxx>
44 #include <Prs3d_Drawer.hxx>
45 #include <Prs3d_LineAspect.hxx>
46 #include <Prs3d_Presentation.hxx>
47 #include <Prs3d_Projector.hxx>
48 #include <Prs3d_TextAspect.hxx>
49 #include <Quantity_Color.hxx>
50 #include <Select3D_SensitiveBox.hxx>
51 #include <Select3D_SensitivePoint.hxx>
52 #include <Select3D_SensitiveSegment.hxx>
53 #include <Select3D_SensitiveTriangle.hxx>
54 #include <SelectBasics_EntityOwner.hxx>
55 #include <SelectMgr_EntityOwner.hxx>
56 #include <Standard_Type.hxx>
57 #include <TColgp_Array1OfPnt.hxx>
58 #include <UnitsAPI.hxx>
60 IMPLEMENT_STANDARD_RTTIEXT(AIS_Trihedron,AIS_InteractiveObject)
62 //=======================================================================
63 //function : AIS_Trihedron
65 //=======================================================================
66 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
67 myComponent (aComponent),
68 myHasOwnSize (Standard_False),
69 myHasOwnTextColor (Standard_False),
70 myHasOwnArrowColor (Standard_False)
75 //=======================================================================
76 //function : SetComponent
78 //=======================================================================
80 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
82 myComponent = aComponent;
84 // Remove from current context and nullify objects to update
85 Handle(AIS_InteractiveContext) anAISContext = GetContext();
86 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
87 Standard_Integer anIdx;
88 for (anIdx = 0; anIdx < 7; anIdx++)
93 if (anAISContext->IsSelected (myShapes[anIdx]))
94 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
96 anAISContext->Remove (myShapes[anIdx], Standard_False);
98 myShapes[anIdx].Nullify();
104 //=======================================================================
105 //function : setLocalTransformation
107 //=======================================================================
109 void AIS_Trihedron::setLocalTransformation (const Handle(Geom_Transformation)& theTrsf)
111 // Update location to the subshapes
112 Standard_Integer anIdx;
113 for (anIdx = 0; anIdx < 7; anIdx++)
114 myShapes[anIdx]->SetLocalTransformation (theTrsf);
116 AIS_InteractiveObject::setLocalTransformation (theTrsf);
119 //=======================================================================
122 //=======================================================================
123 void AIS_Trihedron::SetSize(const Standard_Real aValue)
125 myHasOwnSize = Standard_True;
126 if(!myDrawer->HasOwnDatumAspect()){
127 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
128 myDrawer->SetDatumAspect(DA);
131 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
133 for(Standard_Integer i=4;i<=6;i++)
134 Handle(AIS_Plane)::DownCast (myShapes[i])->SetSize(aValue);
142 //=======================================================================
143 //function : UnsetSize
144 //purpose : if the object has 1 color, the default size of the
145 // drawer is reproduced, otherwise DatumAspect becomes null
146 //=======================================================================
148 void AIS_Trihedron::UnsetSize()
150 if(!myHasOwnSize) return;
152 myHasOwnSize = Standard_False;
154 const Handle(Prs3d_DatumAspect) DA =
155 myDrawer->HasLink() ? myDrawer->Link()->DatumAspect() : new Prs3d_DatumAspect();
156 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
157 DA->SecondAxisLength(),
158 DA->ThirdAxisLength());
162 myDrawer->SetDatumAspect (Handle(Prs3d_DatumAspect)());
169 //=======================================================================
172 //=======================================================================
174 Standard_Real AIS_Trihedron::Size() const
176 return myDrawer->DatumAspect()->FirstAxisLength();
179 //=======================================================================
182 //=======================================================================
183 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
185 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
188 anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
193 //=======================================================================
196 //=======================================================================
197 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
199 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
202 anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
208 //=======================================================================
211 //=======================================================================
212 Handle(AIS_Axis) AIS_Trihedron::Axis() const
214 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
217 anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
222 //=======================================================================
223 //function : Position
225 //=======================================================================
226 Handle(AIS_Point) AIS_Trihedron::Position() const
228 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
230 gp_Pnt aPnt = myComponent->Ax2().Location();
231 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
232 aPt = new AIS_Point (aPoint);
237 //=======================================================================
240 //=======================================================================
241 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
243 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
244 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
248 //=======================================================================
251 //=======================================================================
252 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
254 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
255 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
259 //=======================================================================
262 //=======================================================================
263 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
265 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
266 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
270 //=======================================================================
273 //=======================================================================
274 void AIS_Trihedron::Compute(
275 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
276 const Handle(Prs3d_Presentation)& aPresentation,
277 const Standard_Integer aMode)
279 aPresentation->SetInfiniteState (Standard_True);
282 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
291 //=======================================================================
294 //=======================================================================
296 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
297 const Handle(Geom_Transformation)& aTransformation,
298 const Handle(Prs3d_Presentation)& aPresentation)
300 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
301 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
304 //=======================================================================
305 //function : ComputeSelection
307 //=======================================================================
309 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
310 const Standard_Integer aMode)
312 // retrieve the tops of the trihedron.
313 Standard_Integer Prior, anIdx;
314 Handle(SelectMgr_EntityOwner) eown;
315 TColgp_Array1OfPnt PP(1,4),PO(1,4);
318 // remove shapes from active selections
319 Handle(AIS_InteractiveContext) anAISContext = GetContext();
320 if (!anAISContext.IsNull())
321 for (anIdx = 0; anIdx < 7; anIdx++)
324 if (anAISContext->IsSelected (myShapes[anIdx]))
325 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
327 anAISContext->Remove (myShapes[anIdx], Standard_False);
332 { // complete triedron only 1 owner : this... priority 5 (same as faces)
334 eown = new SelectMgr_EntityOwner(this,Prior);
335 for (Standard_Integer i=1; i<=3;i++)
336 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
342 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
343 eown= new SelectMgr_EntityOwner(anObj,Prior);
345 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
346 // If the trihedron's shapes display and selection modes are the same
347 // the shapes are still displayed after selection, so we need to
348 // use different presentation and hide it by nullifying
349 if (!anAISContext.IsNull())
351 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
352 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
358 { //axes ... priority 7
360 for (Standard_Integer i=1; i<=3;i++){
361 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
362 eown= new SelectMgr_EntityOwner(anObj,Prior);
363 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
367 // If the trihedron's shapes display and selection modes are the same
368 // the shapes are still displayed after selection, so we need to
369 // use different presentation and hide it by nullifying
370 AIS_TypeOfAxis anAxisType;
371 if (!anAISContext.IsNull())
372 for (anIdx = 1; anIdx <= 3; anIdx++)
374 // update AIS_Axis for selection
375 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
376 Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes();
377 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
378 aDrawer->SetDatumAspect (aDatum);
379 anAxisType = anAxis->TypeOfAxis();
380 anAxis->SetAxis2Placement (myComponent, anAxisType);
383 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
384 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
391 { // main planes priority 6
397 const Handle(SelectMgr_SelectableObject)& anObj4 = myShapes[4]; // to avoid ambiguity
398 eown= new SelectMgr_EntityOwner(anObj4,Prior);
399 // PO(2) = PP(2);PO(3) = PP(3);
400 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
402 const Handle(SelectMgr_SelectableObject)& anObj5 = myShapes[5]; // to avoid ambiguity
403 eown= new SelectMgr_EntityOwner(anObj5,Prior);
404 // PO(2) = PP(3);PO(3) = PP(4);
405 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
407 const Handle(SelectMgr_SelectableObject)& anObj6 = myShapes[6]; // to avoid ambiguity
408 eown= new SelectMgr_EntityOwner(anObj6,Prior);
409 // PO(2) = PP(4);PO(3) = PP(2);
410 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
412 // If the trihedron's shapes display and selection modes are the same
413 // the shapes are still displayed after selection, so we need to
414 // use different presentation and hide it by nullifying
415 if (!anAISContext.IsNull())
416 for (anIdx = 4; anIdx < 7; anIdx++)
418 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
419 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
426 //=======================================================================
427 //function : SetColor
429 //=======================================================================
431 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
433 SetColor(Quantity_Color(aCol));
436 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
438 hasOwnColor=Standard_True;
441 if(!myDrawer->HasOwnDatumAspect()){
442 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
444 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
445 myDrawer->DatumAspect()->SecondAxisLength(),
446 myDrawer->DatumAspect()->ThirdAxisLength());
447 myDrawer->SetDatumAspect(DA);
449 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
450 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
451 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
455 //=======================================================================
456 //function : SetTextColor
458 //=======================================================================
460 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
462 myHasOwnTextColor = Standard_True;
463 myOwnTextColor = aCol;
465 if(!myDrawer->HasOwnDatumAspect()){
466 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
468 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
469 myDrawer->DatumAspect()->SecondAxisLength(),
470 myDrawer->DatumAspect()->ThirdAxisLength());
471 myDrawer->SetDatumAspect(DA);
473 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
474 aspect->SetColor(aCol);
475 myDrawer->SetTextAspect(aspect);
478 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
480 myHasOwnArrowColor = Standard_True;
481 myOwnArrowColor = aCol;
483 if(!myDrawer->HasOwnDatumAspect()){
484 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
486 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
487 myDrawer->DatumAspect()->SecondAxisLength(),
488 myDrawer->DatumAspect()->ThirdAxisLength());
489 myDrawer->SetDatumAspect(DA);
491 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
492 aspect->SetColor(aCol);
493 myDrawer->SetArrowAspect(aspect);
496 //=======================================================================
497 Standard_Boolean AIS_Trihedron::HasTextColor() const {
499 return myHasOwnTextColor;
502 //=======================================================================
503 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
505 return myOwnTextColor;
508 //=======================================================================
509 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
511 return myHasOwnArrowColor;
514 //=======================================================================
515 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
517 return myOwnArrowColor;
521 //=======================================================================
523 //purpose : to avoid warning
524 //=======================================================================
525 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
526 const Handle(Prs3d_Presentation)&)
529 //=======================================================================
532 //=======================================================================
534 AIS_KindOfInteractive AIS_Trihedron::Type() const
535 {return AIS_KOI_Datum;}
538 //=======================================================================
539 //function : Signature
541 //=======================================================================
543 Standard_Integer AIS_Trihedron::Signature() const
546 //=======================================================================
547 //function : ExtremityPoints
548 //purpose : to avoid warning
549 //=======================================================================
550 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
552 gp_Ax2 theax(myComponent->Ax2());
553 PP(1) = theax.Location();
555 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
556 gp_Vec vec = theax.XDirection();
558 PP(2) = PP(1).Translated(vec);
560 len = myDrawer->DatumAspect()->SecondAxisLength();
561 vec = theax.YDirection();
563 PP(3) = PP(1).Translated(vec);
565 len = myDrawer->DatumAspect()->ThirdAxisLength();
566 vec = theax.Direction();
568 PP(4) = PP(1).Translated(vec);
571 //=======================================================================
572 //function : AcceptDisplayMode
574 //=======================================================================
576 Standard_Boolean AIS_Trihedron::
577 AcceptDisplayMode(const Standard_Integer aMode) const
582 //=======================================================================
583 //function : UnsetColor
585 //=======================================================================
587 void AIS_Trihedron::UnsetColor()
589 hasOwnColor=Standard_False;
590 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
591 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
592 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
593 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
594 if( HasTextColor() ) {
595 SetTextColor(myOwnColor.Name());
596 myHasOwnTextColor = Standard_False;
598 if( HasArrowColor() ) {
599 SetArrowColor(myOwnColor.Name());
600 myHasOwnArrowColor = Standard_False;
605 //=======================================================================
606 //function : UnsetWitdth
608 //=======================================================================
610 void AIS_Trihedron::UnsetWidth()
613 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
614 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
615 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
618 void AIS_Trihedron::LoadSubObjects()
620 myShapes[0] = Position();
621 myShapes[1] = XAxis();
622 myShapes[2] = YAxis();
623 myShapes[3] = Axis();
624 myShapes[4] = XYPlane();
625 myShapes[5] = XZPlane();
626 myShapes[6] = YZPlane();
629 //=======================================================================
630 //function : SetContext
632 //=======================================================================
634 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
636 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
640 Standard_Integer anIdx;
641 for (anIdx = 0; anIdx < 7; anIdx++)
643 myShapes[anIdx]->SetContext(Ctx);
645 AIS_InteractiveObject::SetContext (Ctx);
648 // Remove subobjects from current context
649 Handle(AIS_InteractiveContext) anAISContext = GetContext();
651 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
652 Standard_Integer anIdx;
653 for (anIdx = 0; anIdx < 7; anIdx++)
658 if (anAISContext->IsSelected (myShapes[anIdx]))
659 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
661 anAISContext->Remove (myShapes[anIdx], Standard_False);
663 myShapes[anIdx].Nullify();
666 AIS_InteractiveObject::SetContext (Ctx);
668 for(Standard_Integer i= 0;i<=6;i++)
669 myShapes[i]->SetContext (Ctx);