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.
18 #include <AIS_Axis.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <AIS_InteractiveObject.hxx>
21 #include <AIS_Plane.hxx>
22 #include <AIS_Point.hxx>
23 #include <AIS_Trihedron.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 : SetLocation
107 //=======================================================================
109 void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation)
111 // Update location to the subshapes
112 Standard_Integer anIdx;
113 for (anIdx = 0; anIdx < 7; anIdx++)
114 myShapes[anIdx]->SetLocalTransformation (theTransformation);
116 AIS_InteractiveObject::SetLocalTransformation (theTransformation);
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->Clear();
281 aPresentation->SetInfiniteState (Standard_True);
284 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
293 //=======================================================================
296 //=======================================================================
298 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
299 const Handle(Geom_Transformation)& aTransformation,
300 const Handle(Prs3d_Presentation)& aPresentation)
302 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
303 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
306 //=======================================================================
307 //function : ComputeSelection
309 //=======================================================================
311 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
312 const Standard_Integer aMode)
314 // retrieve the tops of the trihedron.
315 Standard_Integer Prior, anIdx;
316 Handle(SelectMgr_EntityOwner) eown;
317 TColgp_Array1OfPnt PP(1,4),PO(1,4);
320 // remove shapes from active selections
321 Handle(AIS_InteractiveContext) anAISContext = GetContext();
322 if (!anAISContext.IsNull())
323 for (anIdx = 0; anIdx < 7; anIdx++)
326 if (anAISContext->IsSelected (myShapes[anIdx]))
327 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
329 anAISContext->Remove (myShapes[anIdx], Standard_False);
334 { // complete triedron only 1 owner : this... priority 5 (same as faces)
336 eown = new SelectMgr_EntityOwner(this,Prior);
337 for (Standard_Integer i=1; i<=3;i++)
338 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
344 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[0]; // to avoid ambiguity
345 eown= new SelectMgr_EntityOwner(anObj,Prior);
347 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
348 // If the trihedron's shapes display and selection modes are the same
349 // the shapes are still displayed after selection, so we need to
350 // use different presentation and hide it by nullifying
351 if (!anAISContext.IsNull())
353 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
354 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
360 { //axes ... priority 7
362 for (Standard_Integer i=1; i<=3;i++){
363 const Handle(SelectMgr_SelectableObject)& anObj = myShapes[i]; // to avoid ambiguity
364 eown= new SelectMgr_EntityOwner(anObj,Prior);
365 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
369 // If the trihedron's shapes display and selection modes are the same
370 // the shapes are still displayed after selection, so we need to
371 // use different presentation and hide it by nullifying
372 AIS_TypeOfAxis anAxisType;
373 if (!anAISContext.IsNull())
374 for (anIdx = 1; anIdx <= 3; anIdx++)
376 // update AIS_Axis for selection
377 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
378 Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes();
379 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
380 aDrawer->SetDatumAspect (aDatum);
381 anAxisType = anAxis->TypeOfAxis();
382 anAxis->SetAxis2Placement (myComponent, anAxisType);
385 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
386 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
393 { // main planes priority 6
399 const Handle(SelectMgr_SelectableObject)& anObj4 = myShapes[4]; // to avoid ambiguity
400 eown= new SelectMgr_EntityOwner(anObj4,Prior);
401 // PO(2) = PP(2);PO(3) = PP(3);
402 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
404 const Handle(SelectMgr_SelectableObject)& anObj5 = myShapes[5]; // to avoid ambiguity
405 eown= new SelectMgr_EntityOwner(anObj5,Prior);
406 // PO(2) = PP(3);PO(3) = PP(4);
407 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
409 const Handle(SelectMgr_SelectableObject)& anObj6 = myShapes[6]; // to avoid ambiguity
410 eown= new SelectMgr_EntityOwner(anObj6,Prior);
411 // PO(2) = PP(4);PO(3) = PP(2);
412 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
414 // If the trihedron's shapes display and selection modes are the same
415 // the shapes are still displayed after selection, so we need to
416 // use different presentation and hide it by nullifying
417 if (!anAISContext.IsNull())
418 for (anIdx = 4; anIdx < 7; anIdx++)
420 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
421 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
428 //=======================================================================
429 //function : SetColor
431 //=======================================================================
433 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
435 SetColor(Quantity_Color(aCol));
438 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
440 hasOwnColor=Standard_True;
443 if(!myDrawer->HasOwnDatumAspect()){
444 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
446 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
447 myDrawer->DatumAspect()->SecondAxisLength(),
448 myDrawer->DatumAspect()->ThirdAxisLength());
449 myDrawer->SetDatumAspect(DA);
451 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
452 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
453 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
457 //=======================================================================
458 //function : SetTextColor
460 //=======================================================================
462 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
464 myHasOwnTextColor = Standard_True;
465 myOwnTextColor = aCol;
467 if(!myDrawer->HasOwnDatumAspect()){
468 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
470 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
471 myDrawer->DatumAspect()->SecondAxisLength(),
472 myDrawer->DatumAspect()->ThirdAxisLength());
473 myDrawer->SetDatumAspect(DA);
475 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
476 aspect->SetColor(aCol);
477 myDrawer->SetTextAspect(aspect);
480 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
482 myHasOwnArrowColor = Standard_True;
483 myOwnArrowColor = aCol;
485 if(!myDrawer->HasOwnDatumAspect()){
486 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
488 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
489 myDrawer->DatumAspect()->SecondAxisLength(),
490 myDrawer->DatumAspect()->ThirdAxisLength());
491 myDrawer->SetDatumAspect(DA);
493 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
494 aspect->SetColor(aCol);
495 myDrawer->SetArrowAspect(aspect);
498 //=======================================================================
499 Standard_Boolean AIS_Trihedron::HasTextColor() const {
501 return myHasOwnTextColor;
504 //=======================================================================
505 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
507 return myOwnTextColor;
510 //=======================================================================
511 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
513 return myHasOwnArrowColor;
516 //=======================================================================
517 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
519 return myOwnArrowColor;
523 //=======================================================================
525 //purpose : to avoid warning
526 //=======================================================================
527 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
528 const Handle(Prs3d_Presentation)&)
531 //=======================================================================
534 //=======================================================================
536 AIS_KindOfInteractive AIS_Trihedron::Type() const
537 {return AIS_KOI_Datum;}
540 //=======================================================================
541 //function : Signature
543 //=======================================================================
545 Standard_Integer AIS_Trihedron::Signature() const
548 //=======================================================================
549 //function : ExtremityPoints
550 //purpose : to avoid warning
551 //=======================================================================
552 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
554 gp_Ax2 theax(myComponent->Ax2());
555 PP(1) = theax.Location();
557 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
558 gp_Vec vec = theax.XDirection();
560 PP(2) = PP(1).Translated(vec);
562 len = myDrawer->DatumAspect()->SecondAxisLength();
563 vec = theax.YDirection();
565 PP(3) = PP(1).Translated(vec);
567 len = myDrawer->DatumAspect()->ThirdAxisLength();
568 vec = theax.Direction();
570 PP(4) = PP(1).Translated(vec);
573 //=======================================================================
574 //function : AcceptDisplayMode
576 //=======================================================================
578 Standard_Boolean AIS_Trihedron::
579 AcceptDisplayMode(const Standard_Integer aMode) const
584 //=======================================================================
585 //function : UnsetColor
587 //=======================================================================
589 void AIS_Trihedron::UnsetColor()
591 hasOwnColor=Standard_False;
592 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
593 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
594 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
595 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
596 if( HasTextColor() ) {
597 SetTextColor(myOwnColor.Name());
598 myHasOwnTextColor = Standard_False;
600 if( HasArrowColor() ) {
601 SetArrowColor(myOwnColor.Name());
602 myHasOwnArrowColor = Standard_False;
607 //=======================================================================
608 //function : UnsetWitdth
610 //=======================================================================
612 void AIS_Trihedron::UnsetWidth()
615 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
616 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
617 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
620 void AIS_Trihedron::LoadSubObjects()
622 myShapes[0] = Position();
623 myShapes[1] = XAxis();
624 myShapes[2] = YAxis();
625 myShapes[3] = Axis();
626 myShapes[4] = XYPlane();
627 myShapes[5] = XZPlane();
628 myShapes[6] = YZPlane();
631 //=======================================================================
632 //function : SetContext
634 //=======================================================================
636 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
638 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
642 Standard_Integer anIdx;
643 for (anIdx = 0; anIdx < 7; anIdx++)
645 myShapes[anIdx]->SetContext(Ctx);
647 AIS_InteractiveObject::SetContext (Ctx);
650 // Remove subobjects from current context
651 Handle(AIS_InteractiveContext) anAISContext = GetContext();
653 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
654 Standard_Integer anIdx;
655 for (anIdx = 0; anIdx < 7; anIdx++)
660 if (anAISContext->IsSelected (myShapes[anIdx]))
661 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
663 anAISContext->Remove (myShapes[anIdx], Standard_False);
665 myShapes[anIdx].Nullify();
668 AIS_InteractiveObject::SetContext (Ctx);
670 for(Standard_Integer i= 0;i<=6;i++)
671 myShapes[i]->SetContext (Ctx);