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 #define GER61351 //GG_171199 Enable to set an object RGB color
23 // instead a restricted object NameOfColor.
25 #define IMP120100 // GG Add SetTextColor() and SetArrowColor() methods
27 #include <AIS_Trihedron.ixx>
28 #include <DsgPrs_DatumPrs.hxx>
29 #include <SelectBasics_EntityOwner.hxx>
30 #include <SelectMgr_EntityOwner.hxx>
31 #include <Select3D_SensitiveSegment.hxx>
32 #include <Select3D_SensitiveFace.hxx>
33 #include <Select3D_SensitivePoint.hxx>
34 #include <Geom_Axis2Placement.hxx>
35 #include <Geom_Line.hxx>
36 #include <Geom_Point.hxx>
37 #include <Geom_Plane.hxx>
38 #include <Geom_CartesianPoint.hxx>
44 #include <Prs3d_Drawer.hxx>
45 #include <Prs3d_LineAspect.hxx>
46 #include <Prs3d_TextAspect.hxx>
47 #include <Prs3d_ArrowAspect.hxx>
48 #include <Prs3d_DatumAspect.hxx>
49 #include <Graphic3d_AspectLine3d.hxx>
50 #include <Graphic3d_Structure.hxx>
51 #include <Graphic3d_MaterialAspect.hxx>
52 #include <Graphic3d_AspectFillArea3d.hxx>
53 #include <Aspect_TypeOfLine.hxx>
54 #include <AIS_Drawer.hxx>
55 #include <AIS_Plane.hxx>
56 #include <AIS_Axis.hxx>
57 #include <AIS_Point.hxx>
58 #include <UnitsAPI.hxx>
60 #include <Select3D_SensitiveBox.hxx>
61 #include <Select3D_SensitiveTriangle.hxx>
62 #include <TColgp_Array1OfPnt.hxx>
66 //=======================================================================
67 //function : AIS_Trihedron
69 //=======================================================================
70 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
71 myComponent(aComponent),
72 myHasOwnSize(Standard_False)
74 ,myHasOwnTextColor(Standard_False)
75 ,myHasOwnArrowColor(Standard_False)
82 //=======================================================================
83 //function : SetComponent
85 //=======================================================================
87 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
89 myComponent = aComponent;
91 // Remove from current context and nullify objects to update
92 Handle(AIS_InteractiveContext) anAISContext = GetContext();
93 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
94 Standard_Integer anIdx;
95 for (anIdx = 0; anIdx < 7; anIdx++)
100 if (anAISContext->IsSelected (myShapes[anIdx]))
101 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
103 anAISContext->Remove (myShapes[anIdx], Standard_False);
105 myShapes[anIdx].Nullify();
111 //=======================================================================
112 //function : SetLocation
114 //=======================================================================
116 void AIS_Trihedron::SetLocation(const TopLoc_Location& aLoc)
118 // Update location to the subshapes
119 Standard_Integer anIdx;
120 for (anIdx = 0; anIdx < 7; anIdx++)
121 myShapes[anIdx]->SetLocation (aLoc);
123 AIS_InteractiveObject::SetLocation (aLoc);
126 //=======================================================================
129 //=======================================================================
130 void AIS_Trihedron::SetSize(const Standard_Real aValue)
132 myHasOwnSize = Standard_True;
133 if(!myDrawer->HasDatumAspect()){
134 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
135 myDrawer->SetDatumAspect(DA);
138 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
140 for(Standard_Integer i=4;i<=6;i++)
141 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
149 //=======================================================================
150 //function : UnsetSize
151 //purpose : if the object has 1 color, the default size of the
152 // drawer is reproduced, otherwise DatumAspect becomes null
153 //=======================================================================
155 void AIS_Trihedron::UnsetSize()
157 if(!myHasOwnSize) return;
159 myHasOwnSize = Standard_False;
161 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
162 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
163 DA->SecondAxisLength(),
164 DA->ThirdAxisLength());
167 myDrawer->DatumAspect().Nullify();
173 //=======================================================================
176 //=======================================================================
178 Standard_Real AIS_Trihedron::Size() const
180 if(myDrawer->HasDatumAspect()){
181 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
182 return myDrawer->DatumAspect()->FirstAxisLength();
185 //return the Defaut value
191 //=======================================================================
194 //=======================================================================
195 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
197 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
198 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
202 //=======================================================================
205 //=======================================================================
206 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
208 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
209 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
213 //=======================================================================
216 //=======================================================================
217 Handle(AIS_Axis) AIS_Trihedron::Axis() const
219 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
220 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
224 //=======================================================================
225 //function : Position
227 //=======================================================================
228 Handle(AIS_Point) AIS_Trihedron::Position() const
230 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
232 gp_Pnt aPnt = myComponent->Ax2().Location();
233 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
234 aPt = new AIS_Point (aPoint);
239 //=======================================================================
242 //=======================================================================
243 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
245 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
246 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
250 //=======================================================================
253 //=======================================================================
254 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
256 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
257 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
261 //=======================================================================
264 //=======================================================================
265 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
267 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
268 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
272 //=======================================================================
275 //=======================================================================
276 void AIS_Trihedron::Compute(
277 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
278 const Handle(Prs3d_Presentation)& aPresentation,
279 const Standard_Integer aMode)
281 aPresentation->Clear();
283 aPresentation->SetInfiniteState (Standard_True);
286 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
295 //=======================================================================
298 //=======================================================================
300 void AIS_Trihedron::Compute(const Handle_Prs3d_Projector& aProjector,
301 const Handle_Geom_Transformation& aTransformation,
302 const Handle_Prs3d_Presentation& aPresentation)
304 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
305 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
308 //=======================================================================
309 //function : ComputeSelection
311 //=======================================================================
313 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
314 const Standard_Integer aMode)
316 // retrieve the tops of the trihedron.
317 Standard_Integer Prior, anIdx;
318 Handle(SelectMgr_EntityOwner) eown;
319 TColgp_Array1OfPnt PP(1,4),PO(1,4);
322 // remove shapes from active selections
323 Handle(AIS_InteractiveContext) anAISContext = GetContext();
324 if (!anAISContext.IsNull())
325 for (anIdx = 0; anIdx < 7; anIdx++)
328 if (anAISContext->IsSelected (myShapes[anIdx]))
329 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
331 anAISContext->Remove (myShapes[anIdx], Standard_False);
336 { // complete triedron only 1 owner : this... priority 5 (same as faces)
338 eown = new SelectMgr_EntityOwner(this,Prior);
339 for (Standard_Integer i=1; i<=3;i++)
340 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
346 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
348 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
349 // If the trihedron's shapes display and selection modes are the same
350 // the shapes are still displayed after selection, so we need to
351 // use different presentation and hide it by nullifying
352 if (!anAISContext.IsNull())
354 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
355 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
361 { //axes ... priority 7
363 for (Standard_Integer i=1; i<=3;i++){
364 eown= new SelectMgr_EntityOwner(myShapes[i],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(AIS_Drawer) aDrawer = anAxis->Attributes();
379 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
380 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
381 aDatum->SecondAxisLength(),
382 aDatum->ThirdAxisLength());
383 anAxisType = anAxis->TypeOfAxis();
384 anAxis->SetAxis2Placement (myComponent, anAxisType);
387 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
388 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
395 { // main planes priority 6
401 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
402 // PO(2) = PP(2);PO(3) = PP(3);
403 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
405 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
406 // PO(2) = PP(3);PO(3) = PP(4);
407 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
409 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
410 // PO(2) = PP(4);PO(3) = PP(2);
411 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
413 // If the trihedron's shapes display and selection modes are the same
414 // the shapes are still displayed after selection, so we need to
415 // use different presentation and hide it by nullifying
416 if (!anAISContext.IsNull())
417 for (anIdx = 4; anIdx < 7; anIdx++)
419 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
420 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
427 //=======================================================================
428 //function : SetColor
430 //=======================================================================
432 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
435 SetColor(Quantity_Color(aCol));
438 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
441 hasOwnColor=Standard_True;
444 if(!myDrawer->HasDatumAspect()){
445 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
447 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
448 myDrawer->DatumAspect()->SecondAxisLength(),
449 myDrawer->DatumAspect()->ThirdAxisLength());
450 myDrawer->SetDatumAspect(DA);
452 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
453 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
454 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
458 //=======================================================================
459 //function : SetTextColor
461 //=======================================================================
464 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
466 myHasOwnTextColor = Standard_True;
467 myOwnTextColor = aCol;
469 if(!myDrawer->HasDatumAspect()){
470 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
472 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
473 myDrawer->DatumAspect()->SecondAxisLength(),
474 myDrawer->DatumAspect()->ThirdAxisLength());
475 myDrawer->SetDatumAspect(DA);
477 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
478 aspect->SetColor(aCol);
479 myDrawer->SetTextAspect(aspect);
482 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
484 myHasOwnArrowColor = Standard_True;
485 myOwnArrowColor = aCol;
487 if(!myDrawer->HasDatumAspect()){
488 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
490 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
491 myDrawer->DatumAspect()->SecondAxisLength(),
492 myDrawer->DatumAspect()->ThirdAxisLength());
493 myDrawer->SetDatumAspect(DA);
495 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
496 aspect->SetColor(aCol);
497 myDrawer->SetArrowAspect(aspect);
500 //=======================================================================
501 Standard_Boolean AIS_Trihedron::HasTextColor() const {
503 return myHasOwnTextColor;
506 //=======================================================================
507 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
509 return myOwnTextColor;
512 //=======================================================================
513 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
515 return myHasOwnArrowColor;
518 //=======================================================================
519 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
521 return myOwnArrowColor;
525 //=======================================================================
527 //purpose : to avoid warning
528 //=======================================================================
529 void AIS_Trihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&,
530 const Handle(Graphic2d_GraphicObject)&,
531 const Standard_Integer)
535 //=======================================================================
537 //purpose : to avoid warning
538 //=======================================================================
539 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
540 const Handle(Prs3d_Presentation)&)
543 //=======================================================================
546 //=======================================================================
548 AIS_KindOfInteractive AIS_Trihedron::Type() const
549 {return AIS_KOI_Datum;}
552 //=======================================================================
553 //function : Signature
555 //=======================================================================
557 Standard_Integer AIS_Trihedron::Signature() const
560 //=======================================================================
561 //function : ExtremityPoints
562 //purpose : to avoid warning
563 //=======================================================================
564 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
566 gp_Ax2 theax(myComponent->Ax2());
567 PP(1) = theax.Location();
569 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
570 gp_Vec vec = theax.XDirection();
572 PP(2) = PP(1).Translated(vec);
574 len = myDrawer->DatumAspect()->SecondAxisLength();
575 vec = theax.YDirection();
577 PP(3) = PP(1).Translated(vec);
579 len = myDrawer->DatumAspect()->ThirdAxisLength();
580 vec = theax.Direction();
582 PP(4) = PP(1).Translated(vec);
585 //=======================================================================
586 //function : AcceptDisplayMode
588 //=======================================================================
590 Standard_Boolean AIS_Trihedron::
591 AcceptDisplayMode(const Standard_Integer aMode) const
596 //=======================================================================
597 //function : UnsetColor
599 //=======================================================================
601 void AIS_Trihedron::UnsetColor()
603 hasOwnColor=Standard_False;
604 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
605 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
606 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
607 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
609 if( HasTextColor() ) {
610 SetTextColor(myOwnColor.Name());
611 myHasOwnTextColor = Standard_False;
613 if( HasArrowColor() ) {
614 SetArrowColor(myOwnColor.Name());
615 myHasOwnArrowColor = Standard_False;
621 //=======================================================================
622 //function : UnsetWitdth
624 //=======================================================================
626 void AIS_Trihedron::UnsetWidth()
629 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
630 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
631 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
634 void AIS_Trihedron::LoadSubObjects()
636 myShapes[0] = Position();
637 myShapes[1] = XAxis();
638 myShapes[2] = YAxis();
639 myShapes[3] = Axis();
640 myShapes[4] = XYPlane();
641 myShapes[5] = XZPlane();
642 myShapes[6] = YZPlane();
645 //=======================================================================
646 //function : SetContext
648 //=======================================================================
650 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
652 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
654 // Remove subobjects from current context
655 Handle(AIS_InteractiveContext) anAISContext = GetContext();
656 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
657 Standard_Integer anIdx;
658 for (anIdx = 0; anIdx < 7; anIdx++)
663 if (anAISContext->IsSelected (myShapes[anIdx]))
664 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
666 anAISContext->Remove (myShapes[anIdx], Standard_False);
668 myShapes[anIdx].Nullify();
671 AIS_InteractiveObject::SetContext (Ctx);
674 for(Standard_Integer i= 0;i<=6;i++)
675 myShapes[i]->SetContext (Ctx);