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 #include <AIS_Trihedron.ixx>
18 #include <DsgPrs_DatumPrs.hxx>
19 #include <SelectBasics_EntityOwner.hxx>
20 #include <SelectMgr_EntityOwner.hxx>
21 #include <Select3D_SensitiveSegment.hxx>
22 #include <Select3D_SensitiveFace.hxx>
23 #include <Select3D_SensitivePoint.hxx>
24 #include <Geom_Axis2Placement.hxx>
25 #include <Geom_Line.hxx>
26 #include <Geom_Point.hxx>
27 #include <Geom_Plane.hxx>
28 #include <Geom_CartesianPoint.hxx>
34 #include <Prs3d_Drawer.hxx>
35 #include <Prs3d_LineAspect.hxx>
36 #include <Prs3d_TextAspect.hxx>
37 #include <Prs3d_ArrowAspect.hxx>
38 #include <Prs3d_DatumAspect.hxx>
39 #include <Graphic3d_AspectLine3d.hxx>
40 #include <Graphic3d_Structure.hxx>
41 #include <Graphic3d_MaterialAspect.hxx>
42 #include <Graphic3d_AspectFillArea3d.hxx>
43 #include <Aspect_TypeOfLine.hxx>
44 #include <AIS_Drawer.hxx>
45 #include <AIS_Plane.hxx>
46 #include <AIS_Axis.hxx>
47 #include <AIS_Point.hxx>
48 #include <UnitsAPI.hxx>
50 #include <Select3D_SensitiveBox.hxx>
51 #include <Select3D_SensitiveTriangle.hxx>
52 #include <TColgp_Array1OfPnt.hxx>
56 //=======================================================================
57 //function : AIS_Trihedron
59 //=======================================================================
60 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
61 myComponent(aComponent),
62 myHasOwnSize(Standard_False),
63 myHasOwnTextColor(Standard_False),
64 myHasOwnArrowColor(Standard_False)
70 //=======================================================================
71 //function : SetComponent
73 //=======================================================================
75 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
77 myComponent = aComponent;
79 // Remove from current context and nullify objects to update
80 Handle(AIS_InteractiveContext) anAISContext = GetContext();
81 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
82 Standard_Integer anIdx;
83 for (anIdx = 0; anIdx < 7; anIdx++)
88 if (anAISContext->IsSelected (myShapes[anIdx]))
89 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
91 anAISContext->Remove (myShapes[anIdx], Standard_False);
93 myShapes[anIdx].Nullify();
99 //=======================================================================
100 //function : SetLocation
102 //=======================================================================
104 void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation)
106 // Update location to the subshapes
107 Standard_Integer anIdx;
108 for (anIdx = 0; anIdx < 7; anIdx++)
109 myShapes[anIdx]->SetLocalTransformation (theTransformation);
111 AIS_InteractiveObject::SetLocalTransformation (theTransformation);
114 //=======================================================================
117 //=======================================================================
118 void AIS_Trihedron::SetSize(const Standard_Real aValue)
120 myHasOwnSize = Standard_True;
121 if(!myDrawer->HasDatumAspect()){
122 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
123 myDrawer->SetDatumAspect(DA);
126 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
128 for(Standard_Integer i=4;i<=6;i++)
129 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
137 //=======================================================================
138 //function : UnsetSize
139 //purpose : if the object has 1 color, the default size of the
140 // drawer is reproduced, otherwise DatumAspect becomes null
141 //=======================================================================
143 void AIS_Trihedron::UnsetSize()
145 if(!myHasOwnSize) return;
147 myHasOwnSize = Standard_False;
149 const Handle(Prs3d_DatumAspect)& DA = myDrawer->Link()->DatumAspect();
150 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
151 DA->SecondAxisLength(),
152 DA->ThirdAxisLength());
155 myDrawer->DatumAspect().Nullify();
161 //=======================================================================
164 //=======================================================================
166 Standard_Real AIS_Trihedron::Size() const
168 if(myDrawer->HasDatumAspect()){
169 myDrawer->Link()->DatumAspect(); // ? to ensure that myDrawer->myLink is not null for next call ?
170 return myDrawer->DatumAspect()->FirstAxisLength();
173 //return the Defaut value
179 //=======================================================================
182 //=======================================================================
183 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
185 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
186 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
190 //=======================================================================
193 //=======================================================================
194 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
196 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
197 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
201 //=======================================================================
204 //=======================================================================
205 Handle(AIS_Axis) AIS_Trihedron::Axis() const
207 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
208 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
212 //=======================================================================
213 //function : Position
215 //=======================================================================
216 Handle(AIS_Point) AIS_Trihedron::Position() const
218 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
220 gp_Pnt aPnt = myComponent->Ax2().Location();
221 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
222 aPt = new AIS_Point (aPoint);
227 //=======================================================================
230 //=======================================================================
231 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
233 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
234 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
238 //=======================================================================
241 //=======================================================================
242 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
244 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
245 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
249 //=======================================================================
252 //=======================================================================
253 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
255 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
256 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
260 //=======================================================================
263 //=======================================================================
264 void AIS_Trihedron::Compute(
265 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
266 const Handle(Prs3d_Presentation)& aPresentation,
267 const Standard_Integer aMode)
269 aPresentation->Clear();
271 aPresentation->SetInfiniteState (Standard_True);
274 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
283 //=======================================================================
286 //=======================================================================
288 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
289 const Handle(Geom_Transformation)& aTransformation,
290 const Handle(Prs3d_Presentation)& aPresentation)
292 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
293 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
296 //=======================================================================
297 //function : ComputeSelection
299 //=======================================================================
301 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
302 const Standard_Integer aMode)
304 // retrieve the tops of the trihedron.
305 Standard_Integer Prior, anIdx;
306 Handle(SelectMgr_EntityOwner) eown;
307 TColgp_Array1OfPnt PP(1,4),PO(1,4);
310 // remove shapes from active selections
311 Handle(AIS_InteractiveContext) anAISContext = GetContext();
312 if (!anAISContext.IsNull())
313 for (anIdx = 0; anIdx < 7; anIdx++)
316 if (anAISContext->IsSelected (myShapes[anIdx]))
317 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
319 anAISContext->Remove (myShapes[anIdx], Standard_False);
324 { // complete triedron only 1 owner : this... priority 5 (same as faces)
326 eown = new SelectMgr_EntityOwner(this,Prior);
327 for (Standard_Integer i=1; i<=3;i++)
328 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
334 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
336 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
337 // If the trihedron's shapes display and selection modes are the same
338 // the shapes are still displayed after selection, so we need to
339 // use different presentation and hide it by nullifying
340 if (!anAISContext.IsNull())
342 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
343 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
349 { //axes ... priority 7
351 for (Standard_Integer i=1; i<=3;i++){
352 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
353 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
357 // If the trihedron's shapes display and selection modes are the same
358 // the shapes are still displayed after selection, so we need to
359 // use different presentation and hide it by nullifying
360 AIS_TypeOfAxis anAxisType;
361 if (!anAISContext.IsNull())
362 for (anIdx = 1; anIdx <= 3; anIdx++)
364 // update AIS_Axis for selection
365 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
366 Handle(AIS_Drawer) aDrawer = anAxis->Attributes();
367 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
368 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
369 aDatum->SecondAxisLength(),
370 aDatum->ThirdAxisLength());
371 anAxisType = anAxis->TypeOfAxis();
372 anAxis->SetAxis2Placement (myComponent, anAxisType);
375 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
376 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
383 { // main planes priority 6
389 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
390 // PO(2) = PP(2);PO(3) = PP(3);
391 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
393 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
394 // PO(2) = PP(3);PO(3) = PP(4);
395 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
397 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
398 // PO(2) = PP(4);PO(3) = PP(2);
399 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
401 // If the trihedron's shapes display and selection modes are the same
402 // the shapes are still displayed after selection, so we need to
403 // use different presentation and hide it by nullifying
404 if (!anAISContext.IsNull())
405 for (anIdx = 4; anIdx < 7; anIdx++)
407 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
408 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
415 //=======================================================================
416 //function : SetColor
418 //=======================================================================
420 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
422 SetColor(Quantity_Color(aCol));
425 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
427 hasOwnColor=Standard_True;
430 if(!myDrawer->HasDatumAspect()){
431 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
433 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
434 myDrawer->DatumAspect()->SecondAxisLength(),
435 myDrawer->DatumAspect()->ThirdAxisLength());
436 myDrawer->SetDatumAspect(DA);
438 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
439 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
440 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
444 //=======================================================================
445 //function : SetTextColor
447 //=======================================================================
449 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
451 myHasOwnTextColor = Standard_True;
452 myOwnTextColor = aCol;
454 if(!myDrawer->HasDatumAspect()){
455 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
457 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
458 myDrawer->DatumAspect()->SecondAxisLength(),
459 myDrawer->DatumAspect()->ThirdAxisLength());
460 myDrawer->SetDatumAspect(DA);
462 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
463 aspect->SetColor(aCol);
464 myDrawer->SetTextAspect(aspect);
467 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
469 myHasOwnArrowColor = Standard_True;
470 myOwnArrowColor = aCol;
472 if(!myDrawer->HasDatumAspect()){
473 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
475 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
476 myDrawer->DatumAspect()->SecondAxisLength(),
477 myDrawer->DatumAspect()->ThirdAxisLength());
478 myDrawer->SetDatumAspect(DA);
480 Handle(Prs3d_ArrowAspect) aspect = myDrawer->ArrowAspect();
481 aspect->SetColor(aCol);
482 myDrawer->SetArrowAspect(aspect);
485 //=======================================================================
486 Standard_Boolean AIS_Trihedron::HasTextColor() const {
488 return myHasOwnTextColor;
491 //=======================================================================
492 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
494 return myOwnTextColor;
497 //=======================================================================
498 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
500 return myHasOwnArrowColor;
503 //=======================================================================
504 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
506 return myOwnArrowColor;
510 //=======================================================================
512 //purpose : to avoid warning
513 //=======================================================================
514 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
515 const Handle(Prs3d_Presentation)&)
518 //=======================================================================
521 //=======================================================================
523 AIS_KindOfInteractive AIS_Trihedron::Type() const
524 {return AIS_KOI_Datum;}
527 //=======================================================================
528 //function : Signature
530 //=======================================================================
532 Standard_Integer AIS_Trihedron::Signature() const
535 //=======================================================================
536 //function : ExtremityPoints
537 //purpose : to avoid warning
538 //=======================================================================
539 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
541 gp_Ax2 theax(myComponent->Ax2());
542 PP(1) = theax.Location();
544 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
545 gp_Vec vec = theax.XDirection();
547 PP(2) = PP(1).Translated(vec);
549 len = myDrawer->DatumAspect()->SecondAxisLength();
550 vec = theax.YDirection();
552 PP(3) = PP(1).Translated(vec);
554 len = myDrawer->DatumAspect()->ThirdAxisLength();
555 vec = theax.Direction();
557 PP(4) = PP(1).Translated(vec);
560 //=======================================================================
561 //function : AcceptDisplayMode
563 //=======================================================================
565 Standard_Boolean AIS_Trihedron::
566 AcceptDisplayMode(const Standard_Integer aMode) const
571 //=======================================================================
572 //function : UnsetColor
574 //=======================================================================
576 void AIS_Trihedron::UnsetColor()
578 hasOwnColor=Standard_False;
579 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
580 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
581 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
582 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
583 if( HasTextColor() ) {
584 SetTextColor(myOwnColor.Name());
585 myHasOwnTextColor = Standard_False;
587 if( HasArrowColor() ) {
588 SetArrowColor(myOwnColor.Name());
589 myHasOwnArrowColor = Standard_False;
594 //=======================================================================
595 //function : UnsetWitdth
597 //=======================================================================
599 void AIS_Trihedron::UnsetWidth()
602 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
603 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
604 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
607 void AIS_Trihedron::LoadSubObjects()
609 myShapes[0] = Position();
610 myShapes[1] = XAxis();
611 myShapes[2] = YAxis();
612 myShapes[3] = Axis();
613 myShapes[4] = XYPlane();
614 myShapes[5] = XZPlane();
615 myShapes[6] = YZPlane();
618 //=======================================================================
619 //function : SetContext
621 //=======================================================================
623 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
625 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
629 Standard_Integer anIdx;
630 for (anIdx = 0; anIdx < 7; anIdx++)
632 myShapes[anIdx]->SetContext(Ctx);
634 AIS_InteractiveObject::SetContext (Ctx);
637 // Remove subobjects from current context
638 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);
657 for(Standard_Integer i= 0;i<=6;i++)
658 myShapes[i]->SetContext (Ctx);