1 // Copyright (c) 2013 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <DsgPrs_DatumPrs.hxx>
22 #include <Graphic3d_Group.hxx>
23 #include <Graphic3d_AspectLine3d.hxx>
24 #include <Graphic3d_ArrayOfSegments.hxx>
25 #include <Prs3d_Arrow.hxx>
26 #include <Prs3d_LineAspect.hxx>
27 #include <Prs3d_DatumAspect.hxx>
28 #include <Prs3d_TextAspect.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
31 void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation,
32 const gp_Ax2& theDatum,
33 const Handle(Prs3d_Drawer)& theDrawer)
35 Handle(Prs3d_DatumAspect) aDatumAspect = theDrawer->DatumAspect();
36 Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation);
38 Quantity_Color aColor;
39 Aspect_TypeOfLine aTypeOfLine;
41 aDatumAspect->FirstAxisAspect()->Aspect()->Values(aColor, aTypeOfLine, aWidth);
43 gp_Ax2 anAxis(theDatum);
44 gp_Pnt anOrigin = anAxis.Location();
45 gp_Dir aXDir = anAxis.XDirection();
46 gp_Dir aYDir = anAxis.YDirection();
47 gp_Dir aZDir = anAxis.Direction();
49 Quantity_Length anAxisLength;
50 Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle();
52 Handle(Graphic3d_ArrayOfSegments) aPrims;
53 if (aDatumAspect->DrawFirstAndSecondAxis())
55 anAxisLength = aDatumAspect->FirstAxisLength();
56 const gp_Pnt aPoint1(anOrigin.XYZ() + aXDir.XYZ()*anAxisLength);
58 aGroup->SetPrimitivesAspect(aDatumAspect->FirstAxisAspect()->Aspect());
59 aPrims = new Graphic3d_ArrayOfSegments(2);
60 aPrims->AddVertex(anOrigin);
61 aPrims->AddVertex(aPoint1);
62 aGroup->AddPrimitiveArray(aPrims);
64 aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
65 Prs3d_Arrow::Draw(thePresentation,aPoint1,aXDir,anArrowAngle,anAxisLength/10.);
66 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
67 Graphic3d_Vertex aVertex1(aPoint1.X(),aPoint1.Y(),aPoint1.Z());
68 aGroup->Text(Standard_CString("X"), aVertex1,16.);
70 anAxisLength = aDatumAspect->SecondAxisLength();
71 const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength);
73 aGroup->SetPrimitivesAspect(aDatumAspect->SecondAxisAspect()->Aspect());
74 aPrims = new Graphic3d_ArrayOfSegments(2);
75 aPrims->AddVertex(anOrigin);
76 aPrims->AddVertex(aPoint2);
77 aGroup->AddPrimitiveArray(aPrims);
79 aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
80 Prs3d_Arrow::Draw(thePresentation,aPoint2,aYDir,anArrowAngle,anAxisLength/10.);
81 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
82 Graphic3d_Vertex aVertex2(aPoint2.X(),aPoint2.Y(),aPoint2.Z());
83 aGroup->Text(Standard_CString("Y"), aVertex2,16.);
85 if (aDatumAspect->DrawThirdAxis())
87 anAxisLength = aDatumAspect->ThirdAxisLength();
88 const gp_Pnt aPoint3(anOrigin.XYZ() + aZDir.XYZ()*anAxisLength);
90 aGroup->SetPrimitivesAspect(aDatumAspect->ThirdAxisAspect()->Aspect());
91 aPrims = new Graphic3d_ArrayOfSegments(2);
92 aPrims->AddVertex(anOrigin);
93 aPrims->AddVertex(aPoint3);
94 aGroup->AddPrimitiveArray(aPrims);
96 aGroup->SetPrimitivesAspect(theDrawer->ArrowAspect()->Aspect());
97 Prs3d_Arrow::Draw(thePresentation,aPoint3,aZDir,anArrowAngle,anAxisLength/10.);
98 aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect());
99 Graphic3d_Vertex aVertex3(aPoint3.X(),aPoint3.Y(),aPoint3.Z());
100 aGroup->Text(Standard_CString("Z"), aVertex3,16.);