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;
78 //=======================================================================
81 //=======================================================================
82 void AIS_Trihedron::SetSize(const Standard_Real aValue)
84 myHasOwnSize = Standard_True;
85 if(!myDrawer->HasDatumAspect()){
86 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
87 myDrawer->SetDatumAspect(DA);
90 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
92 for(Standard_Integer i=4;i<=6;i++)
93 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
101 //=======================================================================
102 //function : UnsetSize
103 //purpose : if the object has 1 color, the default size of the
104 // drawer is reproduced, otherwise DatumAspect becomes null
105 //=======================================================================
107 void AIS_Trihedron::UnsetSize()
109 if(!myHasOwnSize) return;
111 myHasOwnSize = Standard_False;
113 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
114 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
115 DA->SecondAxisLength(),
116 DA->ThirdAxisLength());
119 myDrawer->DatumAspect().Nullify();
125 //=======================================================================
128 //=======================================================================
130 Standard_Real AIS_Trihedron::Size() const
132 if(myDrawer->HasDatumAspect()){
133 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
134 return myDrawer->DatumAspect()->FirstAxisLength();
137 //return the Defaut value
143 //=======================================================================
146 //=======================================================================
147 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
149 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
150 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
154 //=======================================================================
157 //=======================================================================
158 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
160 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
161 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
165 //=======================================================================
168 //=======================================================================
169 Handle(AIS_Axis) AIS_Trihedron::Axis() const
171 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
172 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
176 //=======================================================================
177 //function : Position
179 //=======================================================================
180 Handle(AIS_Point) AIS_Trihedron::Position() const
182 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
184 gp_Pnt aPnt = myComponent->Ax2().Location();
185 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
186 aPt = new AIS_Point (aPoint);
191 //=======================================================================
194 //=======================================================================
195 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
197 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
198 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
202 //=======================================================================
205 //=======================================================================
206 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
208 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
209 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
213 //=======================================================================
216 //=======================================================================
217 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
219 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
220 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
224 //=======================================================================
227 //=======================================================================
228 void AIS_Trihedron::Compute(
229 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
230 const Handle(Prs3d_Presentation)& aPresentation,
231 const Standard_Integer aMode)
233 aPresentation->Clear();
235 aPresentation->SetInfiniteState (Standard_True);
238 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
247 //=======================================================================
250 //=======================================================================
252 void AIS_Trihedron::Compute(const Handle_Prs3d_Projector& aProjector,
253 const Handle_Geom_Transformation& aTransformation,
254 const Handle_Prs3d_Presentation& aPresentation)
256 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle_Prs3d_Projector&, const Handle_Geom_Transformation&, const Handle_Prs3d_Presentation&)");
257 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
260 //=======================================================================
261 //function : ComputeSelection
263 //=======================================================================
265 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
266 const Standard_Integer aMode)
268 // retrieve the tops of the trihedron.
269 Standard_Integer Prior;
270 Handle(SelectMgr_EntityOwner) eown;
271 TColgp_Array1OfPnt PP(1,4),PO(1,4);
275 { // complete triedron only 1 owner : this... priority 5 (same as faces)
277 eown = new SelectMgr_EntityOwner(this,Prior);
278 for (Standard_Integer i=1; i<=3;i++)
279 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
285 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
287 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
292 { //axes ... priority 7
294 for (Standard_Integer i=1; i<=3;i++){
295 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
296 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
303 { // main planes priority 6
309 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
310 // PO(2) = PP(2);PO(3) = PP(3);
311 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
313 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
314 // PO(2) = PP(3);PO(3) = PP(4);
315 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
317 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
318 // PO(2) = PP(4);PO(3) = PP(2);
319 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
326 //=======================================================================
327 //function : SetColor
329 //=======================================================================
331 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
334 SetColor(Quantity_Color(aCol));
337 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
340 hasOwnColor=Standard_True;
343 if(!myDrawer->HasDatumAspect()){
344 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
346 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
347 myDrawer->DatumAspect()->SecondAxisLength(),
348 myDrawer->DatumAspect()->ThirdAxisLength());
349 myDrawer->SetDatumAspect(DA);
351 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
352 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
353 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
357 //=======================================================================
358 //function : SetTextColor
360 //=======================================================================
363 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
365 myHasOwnTextColor = Standard_True;
366 myOwnTextColor = aCol;
368 if(!myDrawer->HasDatumAspect()){
369 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
371 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
372 myDrawer->DatumAspect()->SecondAxisLength(),
373 myDrawer->DatumAspect()->ThirdAxisLength());
374 myDrawer->SetDatumAspect(DA);
376 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
377 aspect->SetColor(aCol);
378 myDrawer->SetTextAspect(aspect);
381 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
383 myHasOwnArrowColor = Standard_True;
384 myOwnArrowColor = aCol;
386 if(!myDrawer->HasDatumAspect()){
387 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
389 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
390 myDrawer->DatumAspect()->SecondAxisLength(),
391 myDrawer->DatumAspect()->ThirdAxisLength());
392 myDrawer->SetDatumAspect(DA);
394 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
395 aspect->SetColor(aCol);
396 myDrawer->SetArrowAspect(aspect);
399 //=======================================================================
400 Standard_Boolean AIS_Trihedron::HasTextColor() const {
402 return myHasOwnTextColor;
405 //=======================================================================
406 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
408 return myOwnTextColor;
411 //=======================================================================
412 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
414 return myHasOwnArrowColor;
417 //=======================================================================
418 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
420 return myOwnArrowColor;
424 //=======================================================================
426 //purpose : to avoid warning
427 //=======================================================================
428 void AIS_Trihedron::Compute(const Handle(PrsMgr_PresentationManager2d)&,
429 const Handle(Graphic2d_GraphicObject)&,
430 const Standard_Integer)
434 //=======================================================================
436 //purpose : to avoid warning
437 //=======================================================================
438 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
439 const Handle(Prs3d_Presentation)&)
442 //=======================================================================
445 //=======================================================================
447 AIS_KindOfInteractive AIS_Trihedron::Type() const
448 {return AIS_KOI_Datum;}
451 //=======================================================================
452 //function : Signature
454 //=======================================================================
456 Standard_Integer AIS_Trihedron::Signature() const
459 //=======================================================================
460 //function : ExtremityPoints
461 //purpose : to avoid warning
462 //=======================================================================
463 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
465 gp_Ax2 theax(myComponent->Ax2());
466 PP(1) = theax.Location();
468 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
469 gp_Vec vec = theax.XDirection();
471 PP(2) = PP(1).Translated(vec);
473 len = myDrawer->DatumAspect()->SecondAxisLength();
474 vec = theax.YDirection();
476 PP(3) = PP(1).Translated(vec);
478 len = myDrawer->DatumAspect()->ThirdAxisLength();
479 vec = theax.Direction();
481 PP(4) = PP(1).Translated(vec);
484 //=======================================================================
485 //function : AcceptDisplayMode
487 //=======================================================================
489 Standard_Boolean AIS_Trihedron::
490 AcceptDisplayMode(const Standard_Integer aMode) const
495 //=======================================================================
496 //function : UnsetColor
498 //=======================================================================
500 void AIS_Trihedron::UnsetColor()
502 hasOwnColor=Standard_False;
503 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
504 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
505 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
506 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
508 if( HasTextColor() ) {
509 SetTextColor(myOwnColor.Name());
510 myHasOwnTextColor = Standard_False;
512 if( HasArrowColor() ) {
513 SetArrowColor(myOwnColor.Name());
514 myHasOwnArrowColor = Standard_False;
520 //=======================================================================
521 //function : UnsetWitdth
523 //=======================================================================
525 void AIS_Trihedron::UnsetWidth()
528 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
529 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
530 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
533 void AIS_Trihedron::LoadSubObjects()
535 myShapes[0] = Position();
536 myShapes[1] = XAxis();
537 myShapes[2] = YAxis();
538 myShapes[3] = Axis();
539 myShapes[4] = XYPlane();
540 myShapes[5] = XZPlane();
541 myShapes[6] = YZPlane();
544 //=======================================================================
545 //function : SetContext
547 //=======================================================================
549 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
551 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
553 AIS_InteractiveObject::SetContext(Ctx);
556 for(Standard_Integer i= 0;i<=6;i++)
557 myShapes[i]->SetContext(Ctx);