0027958: Visualization, AIS_Trihedron - add shaded presentation option
[occt.git] / src / DsgPrs / DsgPrs_DatumPrs.cxx
1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <DsgPrs_DatumPrs.hxx>
15 #include <gp_Dir.hxx>
16 #include <gp_Pnt.hxx>
17 #include <gp_Ax2.hxx>
18 #include <Graphic3d_Group.hxx>
19 #include <Graphic3d_AspectLine3d.hxx>
20 #include <Graphic3d_ArrayOfSegments.hxx>
21 #include <Prs3d_Arrow.hxx>
22 #include <Prs3d_LineAspect.hxx>
23 #include <Prs3d_DatumAspect.hxx>
24 #include <Prs3d_TextAspect.hxx>
25 #include <Prs3d_ArrowAspect.hxx>
26
27 void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation,
28                            const gp_Ax2&                     theDatum,
29                            const Handle(Prs3d_Drawer)&       theDrawer)
30 {
31   Handle(Prs3d_DatumAspect) aDatumAspect = theDrawer->DatumAspect();
32   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
33
34   gp_Ax2 anAxis(theDatum);
35   gp_Pnt anOrigin = anAxis.Location();
36   gp_Dir aXDir = anAxis.XDirection();
37   gp_Dir aYDir = anAxis.YDirection();
38   gp_Dir aZDir = anAxis.Direction();
39
40   Quantity_Length anAxisLength;
41   Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle();
42
43   const Standard_Boolean toDrawLabels = theDrawer->DatumAspect()->ToDrawLabels();
44
45   Handle(Graphic3d_ArrayOfSegments) aPrims;
46   if (aDatumAspect->DrawFirstAndSecondAxis())
47   {
48     anAxisLength = aDatumAspect->FirstAxisLength();
49     const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
50     
51     aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
52     aPrims = new Graphic3d_ArrayOfSegments(2);
53     aPrims->AddVertex(anOrigin);
54     aPrims->AddVertex(aPoint1);
55     aGroup->AddPrimitiveArray(aPrims);
56
57     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
58     Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (thePresentation), aPoint1, aXDir, anArrowAngle, anAxisLength/10.);
59     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
60     Graphic3d_Vertex aVertex1(aPoint1.X(),aPoint1.Y(),aPoint1.Z());
61     if (toDrawLabels)
62     {
63       aGroup->Text (Standard_CString ("X"), aVertex1, 16.0);
64     }
65
66     anAxisLength = aDatumAspect->SecondAxisLength();
67     const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength);
68
69     aGroup->SetPrimitivesAspect(aDatumAspect->SecondAxisAspect()->Aspect());
70     aPrims = new Graphic3d_ArrayOfSegments(2);
71     aPrims->AddVertex(anOrigin);
72     aPrims->AddVertex(aPoint2);
73     aGroup->AddPrimitiveArray(aPrims);
74
75     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
76     Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (thePresentation), aPoint2, aYDir, anArrowAngle, anAxisLength/10.);
77     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
78     Graphic3d_Vertex aVertex2(aPoint2.X(),aPoint2.Y(),aPoint2.Z());
79     if (toDrawLabels)
80     {
81       aGroup->Text (Standard_CString ("Y"), aVertex2, 16.0);
82     }
83   }
84   if (aDatumAspect->DrawThirdAxis())
85   {
86     anAxisLength = aDatumAspect->ThirdAxisLength();
87     const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
88
89     aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
90     aPrims = new Graphic3d_ArrayOfSegments(2);
91     aPrims->AddVertex(anOrigin);
92     aPrims->AddVertex(aPoint3);
93     aGroup->AddPrimitiveArray(aPrims);
94
95     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
96     Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (thePresentation), aPoint3, aZDir, anArrowAngle, anAxisLength/10.);
97     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
98     Graphic3d_Vertex aVertex3(aPoint3.X(),aPoint3.Y(),aPoint3.Z());
99     if (toDrawLabels)
100     {
101       aGroup->Text (Standard_CString ("Z"), aVertex3, 16.0);
102     }
103   }
104 }