1 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <DsgPrs_DatumPrs.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>
27 void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation,
28 const gp_Ax2& theDatum,
29 const Handle(Prs3d_Drawer)& theDrawer)
31 Handle(Prs3d_DatumAspect) aDatumAspect = theDrawer->DatumAspect();
32 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
34 Quantity_Color aColor;
35 Aspect_TypeOfLine aTypeOfLine;
37 aDatumAspect->FirstAxisAspect()->Aspect()->Values(aColor, aTypeOfLine, aWidth);
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();
45 Quantity_Length anAxisLength;
46 Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle();
48 const Standard_Boolean toDrawLabels = theDrawer->DatumAspect()->ToDrawLabels();
50 Handle(Graphic3d_ArrayOfSegments) aPrims;
51 if (aDatumAspect->DrawFirstAndSecondAxis())
53 anAxisLength = aDatumAspect->FirstAxisLength();
54 const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
56 aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
57 aPrims = new Graphic3d_ArrayOfSegments(2);
58 aPrims->AddVertex(anOrigin);
59 aPrims->AddVertex(aPoint1);
60 aGroup->AddPrimitiveArray(aPrims);
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());
68 aGroup->Text (Standard_CString ("X"), aVertex1, 16.0);
71 anAxisLength = aDatumAspect->SecondAxisLength();
72 const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength);
74 aGroup->SetPrimitivesAspect(aDatumAspect->SecondAxisAspect()->Aspect());
75 aPrims = new Graphic3d_ArrayOfSegments(2);
76 aPrims->AddVertex(anOrigin);
77 aPrims->AddVertex(aPoint2);
78 aGroup->AddPrimitiveArray(aPrims);
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());
86 aGroup->Text (Standard_CString ("Y"), aVertex2, 16.0);
89 if (aDatumAspect->DrawThirdAxis())
91 anAxisLength = aDatumAspect->ThirdAxisLength();
92 const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
94 aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
95 aPrims = new Graphic3d_ArrayOfSegments(2);
96 aPrims->AddVertex(anOrigin);
97 aPrims->AddVertex(aPoint3);
98 aGroup->AddPrimitiveArray(aPrims);
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());
106 aGroup->Text (Standard_CString ("Z"), aVertex3, 16.0);