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 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();
40 Quantity_Length anAxisLength;
41 Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle();
43 const Standard_Boolean toDrawLabels = theDrawer->DatumAspect()->ToDrawLabels();
45 Handle(Graphic3d_ArrayOfSegments) aPrims;
46 if (aDatumAspect->DrawFirstAndSecondAxis())
48 anAxisLength = aDatumAspect->FirstAxisLength();
49 const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
51 aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
52 aPrims = new Graphic3d_ArrayOfSegments(2);
53 aPrims->AddVertex(anOrigin);
54 aPrims->AddVertex(aPoint1);
55 aGroup->AddPrimitiveArray(aPrims);
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());
63 aGroup->Text (Standard_CString ("X"), aVertex1, 16.0);
66 anAxisLength = aDatumAspect->SecondAxisLength();
67 const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength);
69 aGroup->SetPrimitivesAspect(aDatumAspect->SecondAxisAspect()->Aspect());
70 aPrims = new Graphic3d_ArrayOfSegments(2);
71 aPrims->AddVertex(anOrigin);
72 aPrims->AddVertex(aPoint2);
73 aGroup->AddPrimitiveArray(aPrims);
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());
81 aGroup->Text (Standard_CString ("Y"), aVertex2, 16.0);
84 if (aDatumAspect->DrawThirdAxis())
86 anAxisLength = aDatumAspect->ThirdAxisLength();
87 const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
89 aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
90 aPrims = new Graphic3d_ArrayOfSegments(2);
91 aPrims->AddVertex(anOrigin);
92 aPrims->AddVertex(aPoint3);
93 aGroup->AddPrimitiveArray(aPrims);
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());
101 aGroup->Text (Standard_CString ("Z"), aVertex3, 16.0);