1 // Created on: 1995-10-09
2 // Created by: Arnaud BOUZY/Odile Olivier
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 //GER61351 //GG_171199 Enable to set an object RGB color instead a restricted object NameOfColor.
24 #define IMP120100 // GG Add SetTextColor() and SetArrowColor() methods
26 #include <AIS_Trihedron.ixx>
27 #include <DsgPrs_DatumPrs.hxx>
28 #include <SelectBasics_EntityOwner.hxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <Select3D_SensitiveSegment.hxx>
31 #include <Select3D_SensitiveFace.hxx>
32 #include <Select3D_SensitivePoint.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <Geom_Line.hxx>
35 #include <Geom_Point.hxx>
36 #include <Geom_Plane.hxx>
37 #include <Geom_CartesianPoint.hxx>
43 #include <Prs3d_Drawer.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <Prs3d_TextAspect.hxx>
46 #include <Prs3d_ArrowAspect.hxx>
47 #include <Prs3d_DatumAspect.hxx>
48 #include <Graphic3d_AspectLine3d.hxx>
49 #include <Graphic3d_Structure.hxx>
50 #include <Graphic3d_MaterialAspect.hxx>
51 #include <Graphic3d_AspectFillArea3d.hxx>
52 #include <Aspect_TypeOfLine.hxx>
53 #include <AIS_Drawer.hxx>
54 #include <AIS_Plane.hxx>
55 #include <AIS_Axis.hxx>
56 #include <AIS_Point.hxx>
57 #include <UnitsAPI.hxx>
59 #include <Select3D_SensitiveBox.hxx>
60 #include <Select3D_SensitiveTriangle.hxx>
61 #include <TColgp_Array1OfPnt.hxx>
65 //=======================================================================
66 //function : AIS_Trihedron
68 //=======================================================================
69 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
70 myComponent(aComponent),
71 myHasOwnSize(Standard_False)
73 ,myHasOwnTextColor(Standard_False)
74 ,myHasOwnArrowColor(Standard_False)
81 //=======================================================================
82 //function : SetComponent
84 //=======================================================================
86 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
88 myComponent = aComponent;
90 // Remove from current context and nullify objects to update
91 Handle(AIS_InteractiveContext) anAISContext = GetContext();
92 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
93 Standard_Integer anIdx;
94 for (anIdx = 0; anIdx < 7; anIdx++)
99 if (anAISContext->IsSelected (myShapes[anIdx]))
100 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
102 anAISContext->Remove (myShapes[anIdx], Standard_False);
104 myShapes[anIdx].Nullify();
110 //=======================================================================
111 //function : SetLocation
113 //=======================================================================
115 void AIS_Trihedron::SetLocation(const TopLoc_Location& aLoc)
117 // Update location to the subshapes
118 Standard_Integer anIdx;
119 for (anIdx = 0; anIdx < 7; anIdx++)
120 myShapes[anIdx]->SetLocation (aLoc);
122 AIS_InteractiveObject::SetLocation (aLoc);
125 //=======================================================================
128 //=======================================================================
129 void AIS_Trihedron::SetSize(const Standard_Real aValue)
131 myHasOwnSize = Standard_True;
132 if(!myDrawer->HasDatumAspect()){
133 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
134 myDrawer->SetDatumAspect(DA);
137 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
139 for(Standard_Integer i=4;i<=6;i++)
140 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
148 //=======================================================================
149 //function : UnsetSize
150 //purpose : if the object has 1 color, the default size of the
151 // drawer is reproduced, otherwise DatumAspect becomes null
152 //=======================================================================
154 void AIS_Trihedron::UnsetSize()
156 if(!myHasOwnSize) return;
158 myHasOwnSize = Standard_False;
160 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
161 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
162 DA->SecondAxisLength(),
163 DA->ThirdAxisLength());
166 myDrawer->DatumAspect().Nullify();
172 //=======================================================================
175 //=======================================================================
177 Standard_Real AIS_Trihedron::Size() const
179 if(myDrawer->HasDatumAspect()){
180 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
181 return myDrawer->DatumAspect()->FirstAxisLength();
184 //return the Defaut value
190 //=======================================================================
193 //=======================================================================
194 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
196 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
197 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
201 //=======================================================================
204 //=======================================================================
205 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
207 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
208 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
212 //=======================================================================
215 //=======================================================================
216 Handle(AIS_Axis) AIS_Trihedron::Axis() const
218 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
219 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
223 //=======================================================================
224 //function : Position
226 //=======================================================================
227 Handle(AIS_Point) AIS_Trihedron::Position() const
229 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
231 gp_Pnt aPnt = myComponent->Ax2().Location();
232 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
233 aPt = new AIS_Point (aPoint);
238 //=======================================================================
241 //=======================================================================
242 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
244 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
245 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
249 //=======================================================================
252 //=======================================================================
253 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
255 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
256 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
260 //=======================================================================
263 //=======================================================================
264 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
266 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
267 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
271 //=======================================================================
274 //=======================================================================
275 void AIS_Trihedron::Compute(
276 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
277 const Handle(Prs3d_Presentation)& aPresentation,
278 const Standard_Integer aMode)
280 aPresentation->Clear();
282 aPresentation->SetInfiniteState (Standard_True);
285 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
294 //=======================================================================
297 //=======================================================================
299 void AIS_Trihedron::Compute(const Handle_Prs3d_Projector& aProjector,
300 const Handle_Geom_Transformation& aTransformation,
301 const Handle_Prs3d_Presentation& aPresentation)
303 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
304 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
307 //=======================================================================
308 //function : ComputeSelection
310 //=======================================================================
312 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
313 const Standard_Integer aMode)
315 // retrieve the tops of the trihedron.
316 Standard_Integer Prior, anIdx;
317 Handle(SelectMgr_EntityOwner) eown;
318 TColgp_Array1OfPnt PP(1,4),PO(1,4);
321 // remove shapes from active selections
322 Handle(AIS_InteractiveContext) anAISContext = GetContext();
323 if (!anAISContext.IsNull())
324 for (anIdx = 0; anIdx < 7; anIdx++)
327 if (anAISContext->IsSelected (myShapes[anIdx]))
328 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
330 anAISContext->Remove (myShapes[anIdx], Standard_False);
335 { // complete triedron only 1 owner : this... priority 5 (same as faces)
337 eown = new SelectMgr_EntityOwner(this,Prior);
338 for (Standard_Integer i=1; i<=3;i++)
339 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
345 eown= new SelectMgr_EntityOwner(myShapes[0],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 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
364 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
368 // If the trihedron's shapes display and selection modes are the same
369 // the shapes are still displayed after selection, so we need to
370 // use different presentation and hide it by nullifying
371 AIS_TypeOfAxis anAxisType;
372 if (!anAISContext.IsNull())
373 for (anIdx = 1; anIdx <= 3; anIdx++)
375 // update AIS_Axis for selection
376 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
377 Handle(AIS_Drawer) aDrawer = anAxis->Attributes();
378 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
379 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
380 aDatum->SecondAxisLength(),
381 aDatum->ThirdAxisLength());
382 anAxisType = anAxis->TypeOfAxis();
383 anAxis->SetAxis2Placement (myComponent, anAxisType);
386 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
387 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
394 { // main planes priority 6
400 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
401 // PO(2) = PP(2);PO(3) = PP(3);
402 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
404 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
405 // PO(2) = PP(3);PO(3) = PP(4);
406 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
408 eown= new SelectMgr_EntityOwner(myShapes[6],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->HasDatumAspect()){
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 //=======================================================================
461 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
463 myHasOwnTextColor = Standard_True;
464 myOwnTextColor = aCol;
466 if(!myDrawer->HasDatumAspect()){
467 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
469 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
470 myDrawer->DatumAspect()->SecondAxisLength(),
471 myDrawer->DatumAspect()->ThirdAxisLength());
472 myDrawer->SetDatumAspect(DA);
474 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
475 aspect->SetColor(aCol);
476 myDrawer->SetTextAspect(aspect);
479 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
481 myHasOwnArrowColor = Standard_True;
482 myOwnArrowColor = aCol;
484 if(!myDrawer->HasDatumAspect()){
485 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
487 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
488 myDrawer->DatumAspect()->SecondAxisLength(),
489 myDrawer->DatumAspect()->ThirdAxisLength());
490 myDrawer->SetDatumAspect(DA);
492 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
493 aspect->SetColor(aCol);
494 myDrawer->SetArrowAspect(aspect);
497 //=======================================================================
498 Standard_Boolean AIS_Trihedron::HasTextColor() const {
500 return myHasOwnTextColor;
503 //=======================================================================
504 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
506 return myOwnTextColor;
509 //=======================================================================
510 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
512 return myHasOwnArrowColor;
515 //=======================================================================
516 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
518 return myOwnArrowColor;
522 //=======================================================================
524 //purpose : to avoid warning
525 //=======================================================================
526 void AIS_Trihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&,
527 const Handle(Graphic2d_GraphicObject)&,
528 const Standard_Integer)
532 //=======================================================================
534 //purpose : to avoid warning
535 //=======================================================================
536 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
537 const Handle(Prs3d_Presentation)&)
540 //=======================================================================
543 //=======================================================================
545 AIS_KindOfInteractive AIS_Trihedron::Type() const
546 {return AIS_KOI_Datum;}
549 //=======================================================================
550 //function : Signature
552 //=======================================================================
554 Standard_Integer AIS_Trihedron::Signature() const
557 //=======================================================================
558 //function : ExtremityPoints
559 //purpose : to avoid warning
560 //=======================================================================
561 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
563 gp_Ax2 theax(myComponent->Ax2());
564 PP(1) = theax.Location();
566 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
567 gp_Vec vec = theax.XDirection();
569 PP(2) = PP(1).Translated(vec);
571 len = myDrawer->DatumAspect()->SecondAxisLength();
572 vec = theax.YDirection();
574 PP(3) = PP(1).Translated(vec);
576 len = myDrawer->DatumAspect()->ThirdAxisLength();
577 vec = theax.Direction();
579 PP(4) = PP(1).Translated(vec);
582 //=======================================================================
583 //function : AcceptDisplayMode
585 //=======================================================================
587 Standard_Boolean AIS_Trihedron::
588 AcceptDisplayMode(const Standard_Integer aMode) const
593 //=======================================================================
594 //function : UnsetColor
596 //=======================================================================
598 void AIS_Trihedron::UnsetColor()
600 hasOwnColor=Standard_False;
601 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
602 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
603 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
604 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
606 if( HasTextColor() ) {
607 SetTextColor(myOwnColor.Name());
608 myHasOwnTextColor = Standard_False;
610 if( HasArrowColor() ) {
611 SetArrowColor(myOwnColor.Name());
612 myHasOwnArrowColor = Standard_False;
618 //=======================================================================
619 //function : UnsetWitdth
621 //=======================================================================
623 void AIS_Trihedron::UnsetWidth()
626 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
627 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
628 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
631 void AIS_Trihedron::LoadSubObjects()
633 myShapes[0] = Position();
634 myShapes[1] = XAxis();
635 myShapes[2] = YAxis();
636 myShapes[3] = Axis();
637 myShapes[4] = XYPlane();
638 myShapes[5] = XZPlane();
639 myShapes[6] = YZPlane();
642 //=======================================================================
643 //function : SetContext
645 //=======================================================================
647 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
649 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
651 // Remove subobjects from current context
652 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);
671 for(Standard_Integer i= 0;i<=6;i++)
672 myShapes[i]->SetContext (Ctx);