0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / Prs3d / Prs3d_Arrow.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
4ad142d9 15#include <Prs3d_Arrow.hxx>
42cf5bc1 16
62ef08df 17#include <gp_Ax3.hxx>
42cf5bc1 18#include <gp_Dir.hxx>
19#include <gp_Pnt.hxx>
62ef08df 20#include <gp_Trsf.hxx>
b8ddfc2f 21#include <Graphic3d_ArrayOfPolylines.hxx>
42cf5bc1 22#include <Graphic3d_ArrayOfSegments.hxx>
23#include <Graphic3d_Group.hxx>
42cf5bc1 24#include <Prs3d_Presentation.hxx>
62ef08df 25#include <Prs3d_ToolCylinder.hxx>
26#include <Prs3d_ToolDisk.hxx>
27#include <Prs3d_ToolSphere.hxx>
7fd59977 28
29//=======================================================================
30//function : Draw
31//purpose :
32//=======================================================================
4ad142d9 33void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup,
bc001a40 34 const gp_Pnt& theLocation,
35 const gp_Dir& theDirection,
ee2be2a8 36 const Standard_Real theAngle,
37 const Standard_Real theLength)
b8ddfc2f 38{
bc001a40 39 Handle(Graphic3d_ArrayOfSegments) aPrimitives = Prs3d_Arrow::DrawSegments(theLocation,
40 theDirection, theAngle, theLength, 15);
41 theGroup->AddPrimitiveArray (aPrimitives);
42}
7fd59977 43
bc001a40 44//=======================================================================
45//function : DrawSegments
46//purpose :
47//=======================================================================
48Handle(Graphic3d_ArrayOfSegments) Prs3d_Arrow::DrawSegments (const gp_Pnt& theLocation,
49 const gp_Dir& theDir,
ee2be2a8 50 const Standard_Real theAngle,
51 const Standard_Real theLength,
bc001a40 52 const Standard_Integer theNbSegments)
53{
54 Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (theNbSegments + 1, 2 * (2 * theNbSegments));
7fd59977 55
bc001a40 56 // center of the base circle of the arrow
57 const gp_XYZ aC = theLocation.XYZ() + theDir.XYZ() * (-theLength);
7fd59977 58
bc001a40 59 // construction of i,j mark for the circle
60 gp_Dir aN;
61 if (Abs(theDir.X()) <= Abs(theDir.Y())
62 && Abs(theDir.X()) <= Abs(theDir.Z()))
63 {
64 aN = gp::DX();
65 }
66 else if (Abs(theDir.Y()) <= Abs(theDir.Z())
67 && Abs(theDir.Y()) <= Abs(theDir.X()))
68 {
69 aN = gp::DY();
70 }
71 else
72 {
73 aN = gp::DZ();
74 }
7fd59977 75
bc001a40 76 const gp_Dir anXYZi = theDir.Crossed (aN.XYZ());
77 const gp_XYZ anXYZj = theDir.XYZ().Crossed (anXYZi.XYZ());
78 aSegments->AddVertex (theLocation);
7fd59977 79
bc001a40 80 const Standard_Real Tg = Tan (theAngle);
81 for (Standard_Integer aVertIter = 1; aVertIter <= theNbSegments; ++aVertIter)
82 {
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));
7fd59977 85
bc001a40 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);
7fd59977 89
bc001a40 90 aSegments->AddVertex (pp);
91 }
7fd59977 92
bc001a40 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)
b8ddfc2f 97 {
bc001a40 98 aSegments->AddEdge (1);
99 aSegments->AddEdge (aVertIter);
100 ++anEdgeCount;
7fd59977 101 }
bc001a40 102 aSegments->AddEdge (aNbVertices);
103 aSegments->AddEdge (aFirstContourVertex);
104 ++anEdgeCount;
b8ddfc2f 105
bc001a40 106 for (Standard_Integer aVertIter = aFirstContourVertex; aVertIter <= aNbVertices - 1; ++aVertIter)
107 {
108 aSegments->AddEdge (aVertIter);
109 aSegments->AddEdge (aVertIter + 1);
110 ++anEdgeCount;
111 }
112 return aSegments;
7fd59977 113}
62ef08df 114
115// ============================================================================
116// function : DrawShaded
117// purpose :
118// ============================================================================
119Handle(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)
125{
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)
129 : 0;
130 const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0)
131 ? (Prs3d_ToolDisk ::TrianglesNb (theNbFacettes, 1)
132 + Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1))
133 : 0;
134
135 const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone;
136 if (aNbTris == 0)
137 {
138 return Handle(Graphic3d_ArrayOfTriangles)();
139 }
140
141 Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True);
142 if (aNbTrisTube != 0)
143 {
144 gp_Ax3 aSystem (theAxis.Location(), theAxis.Direction());
145 gp_Trsf aTrsf;
146 aTrsf.SetTransformation (aSystem, gp_Ax3());
147
148 Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1);
149 aTool.FillArray (anArray, aTrsf);
150 }
151
152 if (aNbTrisCone != 0)
153 {
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());
158 gp_Trsf aTrsf;
159 aTrsf.SetTransformation (aSystem, gp_Ax3());
160 {
161 Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1);
162 aTool.FillArray (anArray, aTrsf);
163 }
164 {
165 Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1);
166 aTool.FillArray (anArray, aTrsf);
167 }
168 }
169
170 return anArray;
171}