0024428: Implementation of LGPL license
[occt.git] / src / DsgPrs / DsgPrs_DatumPrs.cxx
CommitLineData
d7223c76 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
d7223c76 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
d7223c76 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
d7223c76 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
27void 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 Handle(Graphic3d_ArrayOfSegments) aPrims;
49 if (aDatumAspect->DrawFirstAndSecondAxis())
50 {
51 anAxisLength = aDatumAspect->FirstAxisLength();
52 const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
53
54 aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
55 aPrims = new Graphic3d_ArrayOfSegments(2);
56 aPrims->AddVertex(anOrigin);
57 aPrims->AddVertex(aPoint1);
58 aGroup->AddPrimitiveArray(aPrims);
59
60 aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
61 Prs3d_Arrow::Draw(thePresentation,aPoint1,aXDir,anArrowAngle,anAxisLength/10.);
62 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
63 Graphic3d_Vertex aVertex1(aPoint1.X(),aPoint1.Y(),aPoint1.Z());
64 aGroup->Text(Standard_CString("X"), aVertex1,16.);
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(thePresentation,aPoint2,aYDir,anArrowAngle,anAxisLength/10.);
77 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
78 Graphic3d_Vertex aVertex2(aPoint2.X(),aPoint2.Y(),aPoint2.Z());
79 aGroup->Text(Standard_CString("Y"), aVertex2,16.);
80 }
81 if (aDatumAspect->DrawThirdAxis())
82 {
83 anAxisLength = aDatumAspect->ThirdAxisLength();
84 const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
85
86 aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
87 aPrims = new Graphic3d_ArrayOfSegments(2);
88 aPrims->AddVertex(anOrigin);
89 aPrims->AddVertex(aPoint3);
90 aGroup->AddPrimitiveArray(aPrims);
91
92 aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
93 Prs3d_Arrow::Draw(thePresentation,aPoint3,aZDir,anArrowAngle,anAxisLength/10.);
94 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
95 Graphic3d_Vertex aVertex3(aPoint3.X(),aPoint3.Y(),aPoint3.Z());
96 aGroup->Text(Standard_CString("Z"), aVertex3,16.);
97 }
98}
99