1 // File: AIS_Trihedron.cxx
2 // Created: Mon Oct 9 16:24:53 1995
3 // Author: Arnaud BOUZY/Odile Olivier
6 #define GER61351 //GG_171199 Enable to set an object RGB color
7 // instead a restricted object NameOfColor.
9 #define IMP120100 // GG Add SetTextColor() and SetArrowColor() methods
11 #include <AIS_Trihedron.ixx>
12 #include <DsgPrs_DatumPrs.hxx>
13 #include <SelectBasics_EntityOwner.hxx>
14 #include <SelectMgr_EntityOwner.hxx>
15 #include <Select3D_SensitiveSegment.hxx>
16 #include <Select3D_SensitiveFace.hxx>
17 #include <Select3D_SensitivePoint.hxx>
18 #include <Geom_Axis2Placement.hxx>
19 #include <Geom_Line.hxx>
20 #include <Geom_Point.hxx>
21 #include <Geom_Plane.hxx>
22 #include <Geom_CartesianPoint.hxx>
28 #include <Prs3d_Drawer.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_TextAspect.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_DatumAspect.hxx>
33 #include <Graphic3d_AspectLine3d.hxx>
34 #include <Graphic3d_Structure.hxx>
35 #include <Graphic3d_MaterialAspect.hxx>
36 #include <Graphic3d_AspectFillArea3d.hxx>
37 #include <Aspect_TypeOfLine.hxx>
38 #include <AIS_Drawer.hxx>
39 #include <AIS_Plane.hxx>
40 #include <AIS_Axis.hxx>
41 #include <AIS_Point.hxx>
42 #include <UnitsAPI.hxx>
44 #include <Select3D_SensitiveBox.hxx>
45 #include <Select3D_SensitiveTriangle.hxx>
46 #include <TColgp_Array1OfPnt.hxx>
50 //=======================================================================
51 //function : AIS_Trihedron
53 //=======================================================================
54 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
55 myComponent(aComponent),
56 myHasOwnSize(Standard_False)
58 ,myHasOwnTextColor(Standard_False)
59 ,myHasOwnArrowColor(Standard_False)
66 //=======================================================================
67 //function : SetComponent
69 //=======================================================================
71 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
73 myComponent = aComponent;
75 // Remove from current context and nullify objects to update
76 Handle(AIS_InteractiveContext) anAISContext = GetContext();
77 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
78 Standard_Integer anIdx;
79 for (anIdx = 0; anIdx < 7; anIdx++)
84 if (anAISContext->IsSelected (myShapes[anIdx]))
85 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
87 anAISContext->Remove (myShapes[anIdx], Standard_False);
89 myShapes[anIdx].Nullify();
95 //=======================================================================
96 //function : SetLocation
98 //=======================================================================
100 void AIS_Trihedron::SetLocation(const TopLoc_Location& aLoc)
102 // Update location to the subshapes
103 Standard_Integer anIdx;
104 for (anIdx = 0; anIdx < 7; anIdx++)
105 myShapes[anIdx]->SetLocation (aLoc);
107 AIS_InteractiveObject::SetLocation (aLoc);
110 //=======================================================================
113 //=======================================================================
114 void AIS_Trihedron::SetSize(const Standard_Real aValue)
116 myHasOwnSize = Standard_True;
117 if(!myDrawer->HasDatumAspect()){
118 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
119 myDrawer->SetDatumAspect(DA);
122 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
124 for(Standard_Integer i=4;i<=6;i++)
125 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
133 //=======================================================================
134 //function : UnsetSize
135 //purpose : if the object has 1 color, the default size of the
136 // drawer is reproduced, otherwise DatumAspect becomes null
137 //=======================================================================
139 void AIS_Trihedron::UnsetSize()
141 if(!myHasOwnSize) return;
143 myHasOwnSize = Standard_False;
145 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
146 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
147 DA->SecondAxisLength(),
148 DA->ThirdAxisLength());
151 myDrawer->DatumAspect().Nullify();
157 //=======================================================================
160 //=======================================================================
162 Standard_Real AIS_Trihedron::Size() const
164 if(myDrawer->HasDatumAspect()){
165 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
166 return myDrawer->DatumAspect()->FirstAxisLength();
169 //return the Defaut value
175 //=======================================================================
178 //=======================================================================
179 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
181 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
182 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
186 //=======================================================================
189 //=======================================================================
190 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
192 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
193 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
197 //=======================================================================
200 //=======================================================================
201 Handle(AIS_Axis) AIS_Trihedron::Axis() const
203 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
204 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
208 //=======================================================================
209 //function : Position
211 //=======================================================================
212 Handle(AIS_Point) AIS_Trihedron::Position() const
214 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
216 gp_Pnt aPnt = myComponent->Ax2().Location();
217 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
218 aPt = new AIS_Point (aPoint);
223 //=======================================================================
226 //=======================================================================
227 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
229 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
230 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
234 //=======================================================================
237 //=======================================================================
238 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
240 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
241 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
245 //=======================================================================
248 //=======================================================================
249 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
251 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
252 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
256 //=======================================================================
259 //=======================================================================
260 void AIS_Trihedron::Compute(
261 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
262 const Handle(Prs3d_Presentation)& aPresentation,
263 const Standard_Integer aMode)
265 aPresentation->Clear();
267 aPresentation->SetInfiniteState (Standard_True);
270 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
279 //=======================================================================
282 //=======================================================================
284 void AIS_Trihedron::Compute(const Handle_Prs3d_Projector& aProjector,
285 const Handle_Geom_Transformation& aTransformation,
286 const Handle_Prs3d_Presentation& aPresentation)
288 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
289 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
292 //=======================================================================
293 //function : ComputeSelection
295 //=======================================================================
297 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
298 const Standard_Integer aMode)
300 // retrieve the tops of the trihedron.
301 Standard_Integer Prior, anIdx;
302 Handle(SelectMgr_EntityOwner) eown;
303 TColgp_Array1OfPnt PP(1,4),PO(1,4);
306 // remove shapes from active selections
307 Handle(AIS_InteractiveContext) anAISContext = GetContext();
308 if (!anAISContext.IsNull())
309 for (anIdx = 0; anIdx < 7; anIdx++)
312 if (anAISContext->IsSelected (myShapes[anIdx]))
313 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
315 anAISContext->Remove (myShapes[anIdx], Standard_False);
320 { // complete triedron only 1 owner : this... priority 5 (same as faces)
322 eown = new SelectMgr_EntityOwner(this,Prior);
323 for (Standard_Integer i=1; i<=3;i++)
324 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
330 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
332 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
333 // If the trihedron's shapes display and selection modes are the same
334 // the shapes are still displayed after selection, so we need to
335 // use different presentation and hide it by nullifying
336 if (!anAISContext.IsNull())
338 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
339 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
345 { //axes ... priority 7
347 for (Standard_Integer i=1; i<=3;i++){
348 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
349 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
353 // If the trihedron's shapes display and selection modes are the same
354 // the shapes are still displayed after selection, so we need to
355 // use different presentation and hide it by nullifying
356 AIS_TypeOfAxis anAxisType;
357 if (!anAISContext.IsNull())
358 for (anIdx = 1; anIdx <= 3; anIdx++)
360 // update AIS_Axis for selection
361 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
362 Handle(AIS_Drawer) aDrawer = anAxis->Attributes();
363 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
364 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
365 aDatum->SecondAxisLength(),
366 aDatum->ThirdAxisLength());
367 anAxisType = anAxis->TypeOfAxis();
368 anAxis->SetAxis2Placement (myComponent, anAxisType);
371 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
372 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
379 { // main planes priority 6
385 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
386 // PO(2) = PP(2);PO(3) = PP(3);
387 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
389 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
390 // PO(2) = PP(3);PO(3) = PP(4);
391 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
393 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
394 // PO(2) = PP(4);PO(3) = PP(2);
395 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
397 // If the trihedron's shapes display and selection modes are the same
398 // the shapes are still displayed after selection, so we need to
399 // use different presentation and hide it by nullifying
400 if (!anAISContext.IsNull())
401 for (anIdx = 4; anIdx < 7; anIdx++)
403 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
404 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
411 //=======================================================================
412 //function : SetColor
414 //=======================================================================
416 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
419 SetColor(Quantity_Color(aCol));
422 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
425 hasOwnColor=Standard_True;
428 if(!myDrawer->HasDatumAspect()){
429 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
431 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
432 myDrawer->DatumAspect()->SecondAxisLength(),
433 myDrawer->DatumAspect()->ThirdAxisLength());
434 myDrawer->SetDatumAspect(DA);
436 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
437 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
438 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
442 //=======================================================================
443 //function : SetTextColor
445 //=======================================================================
448 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
450 myHasOwnTextColor = Standard_True;
451 myOwnTextColor = aCol;
453 if(!myDrawer->HasDatumAspect()){
454 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
456 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
457 myDrawer->DatumAspect()->SecondAxisLength(),
458 myDrawer->DatumAspect()->ThirdAxisLength());
459 myDrawer->SetDatumAspect(DA);
461 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
462 aspect->SetColor(aCol);
463 myDrawer->SetTextAspect(aspect);
466 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
468 myHasOwnArrowColor = Standard_True;
469 myOwnArrowColor = aCol;
471 if(!myDrawer->HasDatumAspect()){
472 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
474 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
475 myDrawer->DatumAspect()->SecondAxisLength(),
476 myDrawer->DatumAspect()->ThirdAxisLength());
477 myDrawer->SetDatumAspect(DA);
479 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
480 aspect->SetColor(aCol);
481 myDrawer->SetArrowAspect(aspect);
484 //=======================================================================
485 Standard_Boolean AIS_Trihedron::HasTextColor() const {
487 return myHasOwnTextColor;
490 //=======================================================================
491 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
493 return myOwnTextColor;
496 //=======================================================================
497 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
499 return myHasOwnArrowColor;
502 //=======================================================================
503 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
505 return myOwnArrowColor;
509 //=======================================================================
511 //purpose : to avoid warning
512 //=======================================================================
513 void AIS_Trihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&,
514 const Handle(Graphic2d_GraphicObject)&,
515 const Standard_Integer)
519 //=======================================================================
521 //purpose : to avoid warning
522 //=======================================================================
523 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
524 const Handle(Prs3d_Presentation)&)
527 //=======================================================================
530 //=======================================================================
532 AIS_KindOfInteractive AIS_Trihedron::Type() const
533 {return AIS_KOI_Datum;}
536 //=======================================================================
537 //function : Signature
539 //=======================================================================
541 Standard_Integer AIS_Trihedron::Signature() const
544 //=======================================================================
545 //function : ExtremityPoints
546 //purpose : to avoid warning
547 //=======================================================================
548 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
550 gp_Ax2 theax(myComponent->Ax2());
551 PP(1) = theax.Location();
553 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
554 gp_Vec vec = theax.XDirection();
556 PP(2) = PP(1).Translated(vec);
558 len = myDrawer->DatumAspect()->SecondAxisLength();
559 vec = theax.YDirection();
561 PP(3) = PP(1).Translated(vec);
563 len = myDrawer->DatumAspect()->ThirdAxisLength();
564 vec = theax.Direction();
566 PP(4) = PP(1).Translated(vec);
569 //=======================================================================
570 //function : AcceptDisplayMode
572 //=======================================================================
574 Standard_Boolean AIS_Trihedron::
575 AcceptDisplayMode(const Standard_Integer aMode) const
580 //=======================================================================
581 //function : UnsetColor
583 //=======================================================================
585 void AIS_Trihedron::UnsetColor()
587 hasOwnColor=Standard_False;
588 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
589 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
590 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
591 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
593 if( HasTextColor() ) {
594 SetTextColor(myOwnColor.Name());
595 myHasOwnTextColor = Standard_False;
597 if( HasArrowColor() ) {
598 SetArrowColor(myOwnColor.Name());
599 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();
638 // Remove subobjects from current context
639 Handle(AIS_InteractiveContext) anAISContext = GetContext();
640 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
641 Standard_Integer anIdx;
642 for (anIdx = 0; anIdx < 7; anIdx++)
647 if (anAISContext->IsSelected (myShapes[anIdx]))
648 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
650 anAISContext->Remove (myShapes[anIdx], Standard_False);
652 myShapes[anIdx].Nullify();
655 AIS_InteractiveObject::SetContext (Ctx);
658 for(Standard_Integer i= 0;i<=6;i++)
659 myShapes[i]->SetContext (Ctx);