be964ee45de88b52ecb08db112533ee667cde2c8
[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   Quantity_Color aColor;
35   Aspect_TypeOfLine aTypeOfLine;
36   Standard_Real aWidth;
37   aDatumAspect->FirstAxisAspect()->Aspect()->Values(aColor, aTypeOfLine, aWidth);
38
39   gp_Ax2 anAxis(theDatum);
40   gp_Pnt anOrigin = anAxis.Location();
41   gp_Dir aXDir = anAxis.XDirection();
42   gp_Dir aYDir = anAxis.YDirection();
43   gp_Dir aZDir = anAxis.Direction();
44
45   Quantity_Length anAxisLength;
46   Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle();
47
48   const Standard_Boolean toDrawLabels = theDrawer->DatumAspect()->ToDrawLabels();
49
50   Handle(Graphic3d_ArrayOfSegments) aPrims;
51   if (aDatumAspect->DrawFirstAndSecondAxis())
52   {
53     anAxisLength = aDatumAspect->FirstAxisLength();
54     const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
55     
56     aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
57     aPrims = new Graphic3d_ArrayOfSegments(2);
58     aPrims->AddVertex(anOrigin);
59     aPrims->AddVertex(aPoint1);
60     aGroup->AddPrimitiveArray(aPrims);
61
62     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
63     Prs3d_Arrow::Draw(thePresentation,aPoint1,aXDir,anArrowAngle,anAxisLength/10.);
64     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
65     Graphic3d_Vertex aVertex1(aPoint1.X(),aPoint1.Y(),aPoint1.Z());
66     if (toDrawLabels)
67     {
68       aGroup->Text (Standard_CString ("X"), aVertex1, 16.0);
69     }
70
71     anAxisLength = aDatumAspect->SecondAxisLength();
72     const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength);
73
74     aGroup->SetPrimitivesAspect(aDatumAspect->SecondAxisAspect()->Aspect());
75     aPrims = new Graphic3d_ArrayOfSegments(2);
76     aPrims->AddVertex(anOrigin);
77     aPrims->AddVertex(aPoint2);
78     aGroup->AddPrimitiveArray(aPrims);
79
80     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
81     Prs3d_Arrow::Draw(thePresentation,aPoint2,aYDir,anArrowAngle,anAxisLength/10.);
82     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
83     Graphic3d_Vertex aVertex2(aPoint2.X(),aPoint2.Y(),aPoint2.Z());
84     if (toDrawLabels)
85     {
86       aGroup->Text (Standard_CString ("Y"), aVertex2, 16.0);
87     }
88   }
89   if (aDatumAspect->DrawThirdAxis())
90   {
91     anAxisLength = aDatumAspect->ThirdAxisLength();
92     const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
93
94     aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
95     aPrims = new Graphic3d_ArrayOfSegments(2);
96     aPrims->AddVertex(anOrigin);
97     aPrims->AddVertex(aPoint3);
98     aGroup->AddPrimitiveArray(aPrims);
99
100     aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
101     Prs3d_Arrow::Draw(thePresentation,aPoint3,aZDir,anArrowAngle,anAxisLength/10.);
102     aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
103     Graphic3d_Vertex aVertex3(aPoint3.X(),aPoint3.Y(),aPoint3.Z());
104     if (toDrawLabels)
105     {
106       aGroup->Text (Standard_CString ("Z"), aVertex3, 16.0);
107     }
108   }
109 }