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 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
19 #define IMP120100 // GG Add SetTextColor() and SetArrowColor() methods
21 #include <AIS_Trihedron.ixx>
22 #include <DsgPrs_DatumPrs.hxx>
23 #include <SelectBasics_EntityOwner.hxx>
24 #include <SelectMgr_EntityOwner.hxx>
25 #include <Select3D_SensitiveSegment.hxx>
26 #include <Select3D_SensitiveFace.hxx>
27 #include <Select3D_SensitivePoint.hxx>
28 #include <Geom_Axis2Placement.hxx>
29 #include <Geom_Line.hxx>
30 #include <Geom_Point.hxx>
31 #include <Geom_Plane.hxx>
32 #include <Geom_CartesianPoint.hxx>
38 #include <Prs3d_Drawer.hxx>
39 #include <Prs3d_LineAspect.hxx>
40 #include <Prs3d_TextAspect.hxx>
41 #include <Prs3d_ArrowAspect.hxx>
42 #include <Prs3d_DatumAspect.hxx>
43 #include <Graphic3d_AspectLine3d.hxx>
44 #include <Graphic3d_Structure.hxx>
45 #include <Graphic3d_MaterialAspect.hxx>
46 #include <Graphic3d_AspectFillArea3d.hxx>
47 #include <Aspect_TypeOfLine.hxx>
48 #include <AIS_Drawer.hxx>
49 #include <AIS_Plane.hxx>
50 #include <AIS_Axis.hxx>
51 #include <AIS_Point.hxx>
52 #include <UnitsAPI.hxx>
54 #include <Select3D_SensitiveBox.hxx>
55 #include <Select3D_SensitiveTriangle.hxx>
56 #include <TColgp_Array1OfPnt.hxx>
60 //=======================================================================
61 //function : AIS_Trihedron
63 //=======================================================================
64 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
65 myComponent(aComponent),
66 myHasOwnSize(Standard_False)
68 ,myHasOwnTextColor(Standard_False)
69 ,myHasOwnArrowColor(Standard_False)
76 //=======================================================================
77 //function : SetComponent
79 //=======================================================================
81 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
83 myComponent = aComponent;
85 // Remove from current context and nullify objects to update
86 Handle(AIS_InteractiveContext) anAISContext = GetContext();
87 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
88 Standard_Integer anIdx;
89 for (anIdx = 0; anIdx < 7; anIdx++)
94 if (anAISContext->IsSelected (myShapes[anIdx]))
95 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
97 anAISContext->Remove (myShapes[anIdx], Standard_False);
99 myShapes[anIdx].Nullify();
105 //=======================================================================
106 //function : SetLocation
108 //=======================================================================
110 void AIS_Trihedron::SetLocation(const TopLoc_Location& aLoc)
112 // Update location to the subshapes
113 Standard_Integer anIdx;
114 for (anIdx = 0; anIdx < 7; anIdx++)
115 myShapes[anIdx]->SetLocation (aLoc);
117 AIS_InteractiveObject::SetLocation (aLoc);
120 //=======================================================================
123 //=======================================================================
124 void AIS_Trihedron::SetSize(const Standard_Real aValue)
126 myHasOwnSize = Standard_True;
127 if(!myDrawer->HasDatumAspect()){
128 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
129 myDrawer->SetDatumAspect(DA);
132 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
134 for(Standard_Integer i=4;i<=6;i++)
135 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
143 //=======================================================================
144 //function : UnsetSize
145 //purpose : if the object has 1 color, the default size of the
146 // drawer is reproduced, otherwise DatumAspect becomes null
147 //=======================================================================
149 void AIS_Trihedron::UnsetSize()
151 if(!myHasOwnSize) return;
153 myHasOwnSize = Standard_False;
155 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
156 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
157 DA->SecondAxisLength(),
158 DA->ThirdAxisLength());
161 myDrawer->DatumAspect().Nullify();
167 //=======================================================================
170 //=======================================================================
172 Standard_Real AIS_Trihedron::Size() const
174 if(myDrawer->HasDatumAspect()){
175 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
176 return myDrawer->DatumAspect()->FirstAxisLength();
179 //return the Defaut value
185 //=======================================================================
188 //=======================================================================
189 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
191 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
192 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
196 //=======================================================================
199 //=======================================================================
200 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
202 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
203 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
207 //=======================================================================
210 //=======================================================================
211 Handle(AIS_Axis) AIS_Trihedron::Axis() const
213 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
214 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
218 //=======================================================================
219 //function : Position
221 //=======================================================================
222 Handle(AIS_Point) AIS_Trihedron::Position() const
224 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
226 gp_Pnt aPnt = myComponent->Ax2().Location();
227 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
228 aPt = new AIS_Point (aPoint);
233 //=======================================================================
236 //=======================================================================
237 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
239 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
240 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
244 //=======================================================================
247 //=======================================================================
248 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
250 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
251 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
255 //=======================================================================
258 //=======================================================================
259 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
261 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
262 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
266 //=======================================================================
269 //=======================================================================
270 void AIS_Trihedron::Compute(
271 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
272 const Handle(Prs3d_Presentation)& aPresentation,
273 const Standard_Integer aMode)
275 aPresentation->Clear();
277 aPresentation->SetInfiniteState (Standard_True);
280 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
289 //=======================================================================
292 //=======================================================================
294 void AIS_Trihedron::Compute(const Handle_Prs3d_Projector& aProjector,
295 const Handle_Geom_Transformation& aTransformation,
296 const Handle_Prs3d_Presentation& aPresentation)
298 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
299 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
302 //=======================================================================
303 //function : ComputeSelection
305 //=======================================================================
307 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
308 const Standard_Integer aMode)
310 // retrieve the tops of the trihedron.
311 Standard_Integer Prior, anIdx;
312 Handle(SelectMgr_EntityOwner) eown;
313 TColgp_Array1OfPnt PP(1,4),PO(1,4);
316 // remove shapes from active selections
317 Handle(AIS_InteractiveContext) anAISContext = GetContext();
318 if (!anAISContext.IsNull())
319 for (anIdx = 0; anIdx < 7; anIdx++)
322 if (anAISContext->IsSelected (myShapes[anIdx]))
323 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
325 anAISContext->Remove (myShapes[anIdx], Standard_False);
330 { // complete triedron only 1 owner : this... priority 5 (same as faces)
332 eown = new SelectMgr_EntityOwner(this,Prior);
333 for (Standard_Integer i=1; i<=3;i++)
334 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
340 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
342 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
343 // If the trihedron's shapes display and selection modes are the same
344 // the shapes are still displayed after selection, so we need to
345 // use different presentation and hide it by nullifying
346 if (!anAISContext.IsNull())
348 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
349 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
355 { //axes ... priority 7
357 for (Standard_Integer i=1; i<=3;i++){
358 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
359 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
363 // If the trihedron's shapes display and selection modes are the same
364 // the shapes are still displayed after selection, so we need to
365 // use different presentation and hide it by nullifying
366 AIS_TypeOfAxis anAxisType;
367 if (!anAISContext.IsNull())
368 for (anIdx = 1; anIdx <= 3; anIdx++)
370 // update AIS_Axis for selection
371 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
372 Handle(AIS_Drawer) aDrawer = anAxis->Attributes();
373 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
374 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
375 aDatum->SecondAxisLength(),
376 aDatum->ThirdAxisLength());
377 anAxisType = anAxis->TypeOfAxis();
378 anAxis->SetAxis2Placement (myComponent, anAxisType);
381 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
382 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
389 { // main planes priority 6
395 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
396 // PO(2) = PP(2);PO(3) = PP(3);
397 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
399 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
400 // PO(2) = PP(3);PO(3) = PP(4);
401 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
403 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
404 // PO(2) = PP(4);PO(3) = PP(2);
405 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
407 // If the trihedron's shapes display and selection modes are the same
408 // the shapes are still displayed after selection, so we need to
409 // use different presentation and hide it by nullifying
410 if (!anAISContext.IsNull())
411 for (anIdx = 4; anIdx < 7; anIdx++)
413 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
414 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
421 //=======================================================================
422 //function : SetColor
424 //=======================================================================
426 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
428 SetColor(Quantity_Color(aCol));
431 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
433 hasOwnColor=Standard_True;
436 if(!myDrawer->HasDatumAspect()){
437 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
439 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
440 myDrawer->DatumAspect()->SecondAxisLength(),
441 myDrawer->DatumAspect()->ThirdAxisLength());
442 myDrawer->SetDatumAspect(DA);
444 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
445 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
446 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
450 //=======================================================================
451 //function : SetTextColor
453 //=======================================================================
456 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
458 myHasOwnTextColor = Standard_True;
459 myOwnTextColor = aCol;
461 if(!myDrawer->HasDatumAspect()){
462 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
464 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
465 myDrawer->DatumAspect()->SecondAxisLength(),
466 myDrawer->DatumAspect()->ThirdAxisLength());
467 myDrawer->SetDatumAspect(DA);
469 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
470 aspect->SetColor(aCol);
471 myDrawer->SetTextAspect(aspect);
474 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
476 myHasOwnArrowColor = Standard_True;
477 myOwnArrowColor = aCol;
479 if(!myDrawer->HasDatumAspect()){
480 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
482 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
483 myDrawer->DatumAspect()->SecondAxisLength(),
484 myDrawer->DatumAspect()->ThirdAxisLength());
485 myDrawer->SetDatumAspect(DA);
487 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
488 aspect->SetColor(aCol);
489 myDrawer->SetArrowAspect(aspect);
492 //=======================================================================
493 Standard_Boolean AIS_Trihedron::HasTextColor() const {
495 return myHasOwnTextColor;
498 //=======================================================================
499 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
501 return myOwnTextColor;
504 //=======================================================================
505 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
507 return myHasOwnArrowColor;
510 //=======================================================================
511 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
513 return myOwnArrowColor;
518 //=======================================================================
520 //purpose : to avoid warning
521 //=======================================================================
522 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
523 const Handle(Prs3d_Presentation)&)
526 //=======================================================================
529 //=======================================================================
531 AIS_KindOfInteractive AIS_Trihedron::Type() const
532 {return AIS_KOI_Datum;}
535 //=======================================================================
536 //function : Signature
538 //=======================================================================
540 Standard_Integer AIS_Trihedron::Signature() const
543 //=======================================================================
544 //function : ExtremityPoints
545 //purpose : to avoid warning
546 //=======================================================================
547 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
549 gp_Ax2 theax(myComponent->Ax2());
550 PP(1) = theax.Location();
552 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
553 gp_Vec vec = theax.XDirection();
555 PP(2) = PP(1).Translated(vec);
557 len = myDrawer->DatumAspect()->SecondAxisLength();
558 vec = theax.YDirection();
560 PP(3) = PP(1).Translated(vec);
562 len = myDrawer->DatumAspect()->ThirdAxisLength();
563 vec = theax.Direction();
565 PP(4) = PP(1).Translated(vec);
568 //=======================================================================
569 //function : AcceptDisplayMode
571 //=======================================================================
573 Standard_Boolean AIS_Trihedron::
574 AcceptDisplayMode(const Standard_Integer aMode) const
579 //=======================================================================
580 //function : UnsetColor
582 //=======================================================================
584 void AIS_Trihedron::UnsetColor()
586 hasOwnColor=Standard_False;
587 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
588 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
589 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
590 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
592 if( HasTextColor() ) {
593 SetTextColor(myOwnColor.Name());
594 myHasOwnTextColor = Standard_False;
596 if( HasArrowColor() ) {
597 SetArrowColor(myOwnColor.Name());
598 myHasOwnArrowColor = Standard_False;
604 //=======================================================================
605 //function : UnsetWitdth
607 //=======================================================================
609 void AIS_Trihedron::UnsetWidth()
612 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
613 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
614 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
617 void AIS_Trihedron::LoadSubObjects()
619 myShapes[0] = Position();
620 myShapes[1] = XAxis();
621 myShapes[2] = YAxis();
622 myShapes[3] = Axis();
623 myShapes[4] = XYPlane();
624 myShapes[5] = XZPlane();
625 myShapes[6] = YZPlane();
628 //=======================================================================
629 //function : SetContext
631 //=======================================================================
633 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
635 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
639 Standard_Integer anIdx;
640 for (anIdx = 0; anIdx < 7; anIdx++)
642 myShapes[anIdx]->SetContext(Ctx);
644 AIS_InteractiveObject::SetContext (Ctx);
647 // Remove subobjects from current context
648 Handle(AIS_InteractiveContext) anAISContext = GetContext();
650 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
651 Standard_Integer anIdx;
652 for (anIdx = 0; anIdx < 7; anIdx++)
657 if (anAISContext->IsSelected (myShapes[anIdx]))
658 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
660 anAISContext->Remove (myShapes[anIdx], Standard_False);
662 myShapes[anIdx].Nullify();
665 AIS_InteractiveObject::SetContext (Ctx);
667 for(Standard_Integer i= 0;i<=6;i++)
668 myShapes[i]->SetContext (Ctx);