1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <Prs3d_Arrow.hxx>
20 #include <gp_Trsf.hxx>
21 #include <Graphic3d_ArrayOfPolylines.hxx>
22 #include <Graphic3d_ArrayOfSegments.hxx>
23 #include <Graphic3d_Group.hxx>
24 #include <Prs3d_Presentation.hxx>
25 #include <Prs3d_ToolCylinder.hxx>
26 #include <Prs3d_ToolDisk.hxx>
27 #include <Prs3d_ToolSphere.hxx>
29 //=======================================================================
32 //=======================================================================
33 void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup,
34 const gp_Pnt& theLocation,
35 const gp_Dir& theDirection,
36 const Standard_Real theAngle,
37 const Standard_Real theLength)
39 Handle(Graphic3d_ArrayOfSegments) aPrimitives = Prs3d_Arrow::DrawSegments(theLocation,
40 theDirection, theAngle, theLength, 15);
41 theGroup->AddPrimitiveArray (aPrimitives);
44 //=======================================================================
45 //function : DrawSegments
47 //=======================================================================
48 Handle(Graphic3d_ArrayOfSegments) Prs3d_Arrow::DrawSegments (const gp_Pnt& theLocation,
50 const Standard_Real theAngle,
51 const Standard_Real theLength,
52 const Standard_Integer theNbSegments)
54 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (theNbSegments + 1, 2 * (2 * theNbSegments));
56 // center of the base circle of the arrow
57 const gp_XYZ aC = theLocation.XYZ() + theDir.XYZ() * (-theLength);
59 // construction of i,j mark for the circle
61 if (Abs(theDir.X()) <= Abs(theDir.Y())
62 && Abs(theDir.X()) <= Abs(theDir.Z()))
66 else if (Abs(theDir.Y()) <= Abs(theDir.Z())
67 && Abs(theDir.Y()) <= Abs(theDir.X()))
76 const gp_Dir anXYZi = theDir.Crossed (aN.XYZ());
77 const gp_XYZ anXYZj = theDir.XYZ().Crossed (anXYZi.XYZ());
78 aSegments->AddVertex (theLocation);
80 const Standard_Real Tg = Tan (theAngle);
81 for (Standard_Integer aVertIter = 1; aVertIter <= theNbSegments; ++aVertIter)
83 const Standard_Real aCos = Cos (2.0 * M_PI / theNbSegments * (aVertIter - 1));
84 const Standard_Real aSin = Sin (2.0 * M_PI / theNbSegments * (aVertIter - 1));
86 const gp_Pnt pp(aC.X() + (aCos * anXYZi.X() + aSin * anXYZj.X()) * theLength * Tg,
87 aC.Y() + (aCos * anXYZi.Y() + aSin * anXYZj.Y()) * theLength * Tg,
88 aC.Z() + (aCos * anXYZi.Z() + aSin * anXYZj.Z()) * theLength * Tg);
90 aSegments->AddVertex (pp);
93 Standard_Integer aNbVertices = theNbSegments + 1;
94 Standard_Integer aFirstContourVertex = 2;
95 Standard_Integer anEdgeCount = 0;
96 for (Standard_Integer aVertIter = aFirstContourVertex; aVertIter <= aNbVertices; ++aVertIter)
98 aSegments->AddEdge (1);
99 aSegments->AddEdge (aVertIter);
102 aSegments->AddEdge (aNbVertices);
103 aSegments->AddEdge (aFirstContourVertex);
106 for (Standard_Integer aVertIter = aFirstContourVertex; aVertIter <= aNbVertices - 1; ++aVertIter)
108 aSegments->AddEdge (aVertIter);
109 aSegments->AddEdge (aVertIter + 1);
115 // ============================================================================
116 // function : DrawShaded
118 // ============================================================================
119 Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1& theAxis,
120 const Standard_Real theTubeRadius,
121 const Standard_Real theAxisLength,
122 const Standard_Real theConeRadius,
123 const Standard_Real theConeLength,
124 const Standard_Integer theNbFacettes)
126 const Standard_Real aTubeLength = Max (0.0, theAxisLength - theConeLength);
127 const Standard_Integer aNbTrisTube = (theTubeRadius > 0.0 && aTubeLength > 0.0)
128 ? Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1)
130 const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0)
131 ? (Prs3d_ToolDisk ::TrianglesNb (theNbFacettes, 1)
132 + Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1))
135 const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone;
138 return Handle(Graphic3d_ArrayOfTriangles)();
141 Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True);
142 if (aNbTrisTube != 0)
144 gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction());
146 aTrsf.SetTransformation (aSystem, gp_Ax3());
148 Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1);
149 aTool.FillArray (anArray, aTrsf);
152 if (aNbTrisCone != 0)
154 gp_Pnt aConeOrigin = theAxis.Location().Translated (gp_Vec (theAxis.Direction().X() * aTubeLength,
155 theAxis.Direction().Y() * aTubeLength,
156 theAxis.Direction().Z() * aTubeLength));
157 gp_Ax3 aSystem (aConeOrigin, theAxis.Direction());
159 aTrsf.SetTransformation (aSystem, gp_Ax3());
161 Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1);
162 aTool.FillArray (anArray, aTrsf);
165 Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1);
166 aTool.FillArray (anArray, aTrsf);