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_Plane.hxx>
45 #include <AIS_Axis.hxx>
46 #include <AIS_Point.hxx>
47 #include <UnitsAPI.hxx>
49 #include <Select3D_SensitiveBox.hxx>
50 #include <Select3D_SensitiveTriangle.hxx>
51 #include <TColgp_Array1OfPnt.hxx>
55 //=======================================================================
56 //function : AIS_Trihedron
58 //=======================================================================
59 AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent):
60 myComponent(aComponent),
61 myHasOwnSize(Standard_False),
62 myHasOwnTextColor(Standard_False),
63 myHasOwnArrowColor(Standard_False)
69 //=======================================================================
70 //function : SetComponent
72 //=======================================================================
74 void AIS_Trihedron::SetComponent(const Handle(Geom_Axis2Placement)& aComponent)
76 myComponent = aComponent;
78 // Remove from current context and nullify objects to update
79 Handle(AIS_InteractiveContext) anAISContext = GetContext();
80 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
81 Standard_Integer anIdx;
82 for (anIdx = 0; anIdx < 7; anIdx++)
87 if (anAISContext->IsSelected (myShapes[anIdx]))
88 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
90 anAISContext->Remove (myShapes[anIdx], Standard_False);
92 myShapes[anIdx].Nullify();
98 //=======================================================================
99 //function : SetLocation
101 //=======================================================================
103 void AIS_Trihedron::SetLocalTransformation (const gp_Trsf& theTransformation)
105 // Update location to the subshapes
106 Standard_Integer anIdx;
107 for (anIdx = 0; anIdx < 7; anIdx++)
108 myShapes[anIdx]->SetLocalTransformation (theTransformation);
110 AIS_InteractiveObject::SetLocalTransformation (theTransformation);
113 //=======================================================================
116 //=======================================================================
117 void AIS_Trihedron::SetSize(const Standard_Real aValue)
119 myHasOwnSize = Standard_True;
120 if(!myDrawer->HasOwnDatumAspect()){
121 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
122 myDrawer->SetDatumAspect(DA);
125 myDrawer->DatumAspect()->SetAxisLength(aValue,aValue,aValue);
127 for(Standard_Integer i=4;i<=6;i++)
128 (*((Handle(AIS_Plane)*)&myShapes[i]))->SetSize(aValue);
136 //=======================================================================
137 //function : UnsetSize
138 //purpose : if the object has 1 color, the default size of the
139 // drawer is reproduced, otherwise DatumAspect becomes null
140 //=======================================================================
142 void AIS_Trihedron::UnsetSize()
144 if(!myHasOwnSize) return;
146 myHasOwnSize = Standard_False;
148 const Handle(Prs3d_DatumAspect) DA =
149 myDrawer->HasLink() ? myDrawer->Link()->DatumAspect() : new Prs3d_DatumAspect();
150 myDrawer->DatumAspect()->SetAxisLength(DA->FirstAxisLength(),
151 DA->SecondAxisLength(),
152 DA->ThirdAxisLength());
156 myDrawer->SetDatumAspect (Handle(Prs3d_DatumAspect)());
163 //=======================================================================
166 //=======================================================================
168 Standard_Real AIS_Trihedron::Size() const
170 return myDrawer->DatumAspect()->FirstAxisLength();
173 //=======================================================================
176 //=======================================================================
177 Handle(AIS_Axis) AIS_Trihedron::XAxis() const
179 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]);
180 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis);
184 //=======================================================================
187 //=======================================================================
188 Handle(AIS_Axis) AIS_Trihedron::YAxis() const
190 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]);
191 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis);
195 //=======================================================================
198 //=======================================================================
199 Handle(AIS_Axis) AIS_Trihedron::Axis() const
201 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]);
202 if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis);
206 //=======================================================================
207 //function : Position
209 //=======================================================================
210 Handle(AIS_Point) AIS_Trihedron::Position() const
212 Handle(AIS_Point) aPt = Handle(AIS_Point)::DownCast(myShapes[0]);
214 gp_Pnt aPnt = myComponent->Ax2().Location();
215 Handle(Geom_Point) aPoint = new Geom_CartesianPoint(aPnt);
216 aPt = new AIS_Point (aPoint);
221 //=======================================================================
224 //=======================================================================
225 Handle(AIS_Plane) AIS_Trihedron::XYPlane() const
227 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[4]);
228 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XYPlane);
232 //=======================================================================
235 //=======================================================================
236 Handle(AIS_Plane) AIS_Trihedron::XZPlane() const
238 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[5]);
239 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_XZPlane);
243 //=======================================================================
246 //=======================================================================
247 Handle(AIS_Plane) AIS_Trihedron::YZPlane() const
249 Handle(AIS_Plane) aPl = Handle(AIS_Plane)::DownCast(myShapes[6]);
250 if (aPl.IsNull()) aPl = new AIS_Plane (myComponent,AIS_TOPL_YZPlane);
254 //=======================================================================
257 //=======================================================================
258 void AIS_Trihedron::Compute(
259 const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
260 const Handle(Prs3d_Presentation)& aPresentation,
261 const Standard_Integer aMode)
263 aPresentation->Clear();
265 aPresentation->SetInfiniteState (Standard_True);
268 DsgPrs_DatumPrs::Add(aPresentation,myComponent->Ax2(),myDrawer);
277 //=======================================================================
280 //=======================================================================
282 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)& aProjector,
283 const Handle(Geom_Transformation)& aTransformation,
284 const Handle(Prs3d_Presentation)& aPresentation)
286 // Standard_NotImplemented::Raise("AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&, const Handle(Geom_Transformation)&, const Handle(Prs3d_Presentation)&)");
287 PrsMgr_PresentableObject::Compute( aProjector , aTransformation , aPresentation) ;
290 //=======================================================================
291 //function : ComputeSelection
293 //=======================================================================
295 void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
296 const Standard_Integer aMode)
298 // retrieve the tops of the trihedron.
299 Standard_Integer Prior, anIdx;
300 Handle(SelectMgr_EntityOwner) eown;
301 TColgp_Array1OfPnt PP(1,4),PO(1,4);
304 // remove shapes from active selections
305 Handle(AIS_InteractiveContext) anAISContext = GetContext();
306 if (!anAISContext.IsNull())
307 for (anIdx = 0; anIdx < 7; anIdx++)
310 if (anAISContext->IsSelected (myShapes[anIdx]))
311 anAISContext->AddOrRemoveSelected (myShapes[anIdx], Standard_False);
313 anAISContext->Remove (myShapes[anIdx], Standard_False);
318 { // complete triedron only 1 owner : this... priority 5 (same as faces)
320 eown = new SelectMgr_EntityOwner(this,Prior);
321 for (Standard_Integer i=1; i<=3;i++)
322 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
328 eown= new SelectMgr_EntityOwner(myShapes[0],Prior);
330 aSelection->Add(new Select3D_SensitivePoint (eown,myComponent->Location()));
331 // If the trihedron's shapes display and selection modes are the same
332 // the shapes are still displayed after selection, so we need to
333 // use different presentation and hide it by nullifying
334 if (!anAISContext.IsNull())
336 anAISContext->Display (myShapes[0], 1, 0, Standard_False);
337 anAISContext->ClearPrs (myShapes[0], 1, Standard_False);
343 { //axes ... priority 7
345 for (Standard_Integer i=1; i<=3;i++){
346 eown= new SelectMgr_EntityOwner(myShapes[i],Prior);
347 aSelection->Add(new Select3D_SensitiveSegment(eown,PP(1),PP(i+1)));
351 // If the trihedron's shapes display and selection modes are the same
352 // the shapes are still displayed after selection, so we need to
353 // use different presentation and hide it by nullifying
354 AIS_TypeOfAxis anAxisType;
355 if (!anAISContext.IsNull())
356 for (anIdx = 1; anIdx <= 3; anIdx++)
358 // update AIS_Axis for selection
359 Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]);
360 Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes();
361 Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect();
362 aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(),
363 aDatum->SecondAxisLength(),
364 aDatum->ThirdAxisLength());
365 anAxisType = anAxis->TypeOfAxis();
366 anAxis->SetAxis2Placement (myComponent, anAxisType);
369 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
370 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
377 { // main planes priority 6
383 eown= new SelectMgr_EntityOwner(myShapes[4],Prior);
384 // PO(2) = PP(2);PO(3) = PP(3);
385 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(3)));
387 eown= new SelectMgr_EntityOwner(myShapes[5],Prior);
388 // PO(2) = PP(3);PO(3) = PP(4);
389 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(2),PP(4)));
391 eown= new SelectMgr_EntityOwner(myShapes[6],Prior);
392 // PO(2) = PP(4);PO(3) = PP(2);
393 aSelection->Add(new Select3D_SensitiveTriangle(eown,PP(1),PP(3),PP(4)));
395 // If the trihedron's shapes display and selection modes are the same
396 // the shapes are still displayed after selection, so we need to
397 // use different presentation and hide it by nullifying
398 if (!anAISContext.IsNull())
399 for (anIdx = 4; anIdx < 7; anIdx++)
401 anAISContext->Display (myShapes[anIdx], 1, 0, Standard_False);
402 anAISContext->ClearPrs (myShapes[anIdx], 1, Standard_False);
409 //=======================================================================
410 //function : SetColor
412 //=======================================================================
414 void AIS_Trihedron::SetColor(const Quantity_NameOfColor aCol)
416 SetColor(Quantity_Color(aCol));
419 void AIS_Trihedron::SetColor(const Quantity_Color &aCol)
421 hasOwnColor=Standard_True;
424 if(!myDrawer->HasOwnDatumAspect()){
425 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
427 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
428 myDrawer->DatumAspect()->SecondAxisLength(),
429 myDrawer->DatumAspect()->ThirdAxisLength());
430 myDrawer->SetDatumAspect(DA);
432 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(aCol);
433 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(aCol);
434 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(aCol);
438 //=======================================================================
439 //function : SetTextColor
441 //=======================================================================
443 void AIS_Trihedron::SetTextColor(const Quantity_NameOfColor aCol)
445 myHasOwnTextColor = Standard_True;
446 myOwnTextColor = aCol;
448 if(!myDrawer->HasOwnDatumAspect()){
449 Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect();
451 DA->SetAxisLength(myDrawer->DatumAspect()->FirstAxisLength(),
452 myDrawer->DatumAspect()->SecondAxisLength(),
453 myDrawer->DatumAspect()->ThirdAxisLength());
454 myDrawer->SetDatumAspect(DA);
456 Handle(Prs3d_TextAspect) aspect = myDrawer->TextAspect();
457 aspect->SetColor(aCol);
458 myDrawer->SetTextAspect(aspect);
461 void AIS_Trihedron::SetArrowColor(const Quantity_NameOfColor aCol)
463 myHasOwnArrowColor = Standard_True;
464 myOwnArrowColor = aCol;
466 if(!myDrawer->HasOwnDatumAspect()){
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_ArrowAspect) aspect = myDrawer->ArrowAspect();
475 aspect->SetColor(aCol);
476 myDrawer->SetArrowAspect(aspect);
479 //=======================================================================
480 Standard_Boolean AIS_Trihedron::HasTextColor() const {
482 return myHasOwnTextColor;
485 //=======================================================================
486 Quantity_NameOfColor AIS_Trihedron::TextColor() const {
488 return myOwnTextColor;
491 //=======================================================================
492 Standard_Boolean AIS_Trihedron::HasArrowColor() const {
494 return myHasOwnArrowColor;
497 //=======================================================================
498 Quantity_NameOfColor AIS_Trihedron::ArrowColor() const {
500 return myOwnArrowColor;
504 //=======================================================================
506 //purpose : to avoid warning
507 //=======================================================================
508 void AIS_Trihedron::Compute(const Handle(Prs3d_Projector)&,
509 const Handle(Prs3d_Presentation)&)
512 //=======================================================================
515 //=======================================================================
517 AIS_KindOfInteractive AIS_Trihedron::Type() const
518 {return AIS_KOI_Datum;}
521 //=======================================================================
522 //function : Signature
524 //=======================================================================
526 Standard_Integer AIS_Trihedron::Signature() const
529 //=======================================================================
530 //function : ExtremityPoints
531 //purpose : to avoid warning
532 //=======================================================================
533 void AIS_Trihedron::ExtremityPoints(TColgp_Array1OfPnt& PP) const
535 gp_Ax2 theax(myComponent->Ax2());
536 PP(1) = theax.Location();
538 Standard_Real len = myDrawer->DatumAspect()->FirstAxisLength();
539 gp_Vec vec = theax.XDirection();
541 PP(2) = PP(1).Translated(vec);
543 len = myDrawer->DatumAspect()->SecondAxisLength();
544 vec = theax.YDirection();
546 PP(3) = PP(1).Translated(vec);
548 len = myDrawer->DatumAspect()->ThirdAxisLength();
549 vec = theax.Direction();
551 PP(4) = PP(1).Translated(vec);
554 //=======================================================================
555 //function : AcceptDisplayMode
557 //=======================================================================
559 Standard_Boolean AIS_Trihedron::
560 AcceptDisplayMode(const Standard_Integer aMode) const
565 //=======================================================================
566 //function : UnsetColor
568 //=======================================================================
570 void AIS_Trihedron::UnsetColor()
572 hasOwnColor=Standard_False;
573 myOwnColor = Quantity_NOC_LIGHTSTEELBLUE4;
574 myDrawer->DatumAspect()->FirstAxisAspect()->SetColor(myOwnColor);
575 myDrawer->DatumAspect()->SecondAxisAspect()->SetColor(myOwnColor);
576 myDrawer->DatumAspect()->ThirdAxisAspect()->SetColor(myOwnColor);
577 if( HasTextColor() ) {
578 SetTextColor(myOwnColor.Name());
579 myHasOwnTextColor = Standard_False;
581 if( HasArrowColor() ) {
582 SetArrowColor(myOwnColor.Name());
583 myHasOwnArrowColor = Standard_False;
588 //=======================================================================
589 //function : UnsetWitdth
591 //=======================================================================
593 void AIS_Trihedron::UnsetWidth()
596 myDrawer->DatumAspect()->FirstAxisAspect()->SetWidth(1.);
597 myDrawer->DatumAspect()->SecondAxisAspect()->SetWidth(1.);
598 myDrawer->DatumAspect()->ThirdAxisAspect()->SetWidth(1.);
601 void AIS_Trihedron::LoadSubObjects()
603 myShapes[0] = Position();
604 myShapes[1] = XAxis();
605 myShapes[2] = YAxis();
606 myShapes[3] = Axis();
607 myShapes[4] = XYPlane();
608 myShapes[5] = XZPlane();
609 myShapes[6] = YZPlane();
612 //=======================================================================
613 //function : SetContext
615 //=======================================================================
617 void AIS_Trihedron::SetContext(const Handle(AIS_InteractiveContext)& Ctx)
619 // Standard_Boolean same_DA = myDrawer->Link() == Ctx->DefaultDrawer();
623 Standard_Integer anIdx;
624 for (anIdx = 0; anIdx < 7; anIdx++)
626 myShapes[anIdx]->SetContext(Ctx);
628 AIS_InteractiveObject::SetContext (Ctx);
631 // Remove subobjects from current context
632 Handle(AIS_InteractiveContext) anAISContext = GetContext();
634 Standard_Boolean hasContext = (anAISContext.IsNull() == Standard_False);
635 Standard_Integer anIdx;
636 for (anIdx = 0; anIdx < 7; anIdx++)
641 if (anAISContext->IsSelected (myShapes[anIdx]))
642 anAISContext->AddOrRemoveSelected (myShapes[anIdx]);
644 anAISContext->Remove (myShapes[anIdx], Standard_False);
646 myShapes[anIdx].Nullify();
649 AIS_InteractiveObject::SetContext (Ctx);
651 for(Standard_Integer i= 0;i<=6;i++)
652 myShapes[i]->SetContext (Ctx);