0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / Prs3d / Prs3d_Arrow.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 0ca101d..cedd23a
-#include <Prs3d_Arrow.ixx>
+// Copyright (c) 1995-1999 Matra Datavision
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Prs3d_Arrow.hxx>
+
+#include <gp_Ax3.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_Trsf.hxx>
+#include <Graphic3d_ArrayOfPolylines.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
 #include <Graphic3d_Group.hxx>
-#include <Graphic3d_Array1OfVertex.hxx>
+#include <Prs3d_Presentation.hxx>
+#include <Prs3d_ToolCylinder.hxx>
+#include <Prs3d_ToolDisk.hxx>
+#include <Prs3d_ToolSphere.hxx>
 
 //=======================================================================
 //function : Draw
 //purpose  : 
 //=======================================================================
+void Prs3d_Arrow::Draw(const Handle(Graphic3d_Group)& theGroup,
+                       const gp_Pnt& theLocation,
+                       const gp_Dir& theDirection,
+                       const Standard_Real theAngle,
+                       const Standard_Real theLength)
+{
+  Handle(Graphic3d_ArrayOfSegments) aPrimitives = Prs3d_Arrow::DrawSegments(theLocation,
+                                                  theDirection, theAngle, theLength, 15);
+  theGroup->AddPrimitiveArray (aPrimitives);
+}
 
-void Prs3d_Arrow::Draw(const Handle(Prs3d_Presentation)& aPresentation,
-                       const gp_Pnt& aLocation,
-                      const gp_Dir& aDirection,
-                       const Quantity_PlaneAngle anAngle,
-                      const Quantity_Length aLength) {
-
-  Quantity_Length dx,dy,dz;  aDirection.Coord(dx,dy,dz);
-//
-// Point of the arrow:
-  Quantity_Length xo,yo,zo;  aLocation.Coord(xo,yo,zo);
-
-// Center of the base circle of the arrow:
-  Quantity_Length xc = xo - dx * aLength;
-  Quantity_Length yc = yo - dy * aLength;
-  Quantity_Length zc = zo - dz * aLength;
-
-// Construction of i,j mark for the circle:
-  Quantity_Length xn=0., yn=0., zn=0.;
+//=======================================================================
+//function : DrawSegments
+//purpose  :
+//=======================================================================
+Handle(Graphic3d_ArrayOfSegments) Prs3d_Arrow::DrawSegments (const gp_Pnt& theLocation,
+                                                             const gp_Dir& theDir,
+                                                             const Standard_Real theAngle,
+                                                             const Standard_Real theLength,
+                                                             const Standard_Integer theNbSegments)
+{
+  Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (theNbSegments + 1, 2 * (2 * theNbSegments));
 
-  if ( Abs(dx) <= Abs(dy) && Abs(dx) <= Abs(dz)) xn=1.;
-  else if ( Abs(dy) <= Abs(dz) && Abs(dy) <= Abs(dx)) yn=1.;
-  else zn=1.;
-  Quantity_Length xi = dy * zn - dz * yn;
-  Quantity_Length yi = dz * xn - dx * zn;
-  Quantity_Length zi = dx * yn - dy * xn;
+  // center of the base circle of the arrow
+  const gp_XYZ aC = theLocation.XYZ() + theDir.XYZ() * (-theLength);
 
-  Quantity_Length Norme = sqrt ( xi*xi + yi*yi + zi*zi );
-  xi = xi / Norme; yi = yi / Norme; zi = zi/Norme;
+  // construction of i,j mark for the circle
+  gp_Dir aN;
+  if (Abs(theDir.X()) <= Abs(theDir.Y())
+   && Abs(theDir.X()) <= Abs(theDir.Z()))
+  {
+    aN = gp::DX();
+  }
+  else if (Abs(theDir.Y()) <= Abs(theDir.Z())
+        && Abs(theDir.Y()) <= Abs(theDir.X()))
+  {
+    aN = gp::DY();
+  }
+  else
+  {
+    aN = gp::DZ();
+  }
 
-  Quantity_Length  xj = dy * zi - dz * yi;
-  Quantity_Length  yj = dz * xi - dx * zi;
-  Quantity_Length  zj = dx * yi - dy * xi;
+  const gp_Dir anXYZi = theDir.Crossed (aN.XYZ());
+  const gp_XYZ anXYZj = theDir.XYZ().Crossed (anXYZi.XYZ());
+  aSegments->AddVertex (theLocation);
 
-  Standard_Integer NbPoints = 15;
+  const Standard_Real Tg = Tan (theAngle);
+  for (Standard_Integer aVertIter = 1; aVertIter <= theNbSegments; ++aVertIter)
+  {
+    const Standard_Real aCos = Cos (2.0 * M_PI / theNbSegments * (aVertIter - 1));
+    const Standard_Real aSin = Sin (2.0 * M_PI / theNbSegments * (aVertIter - 1));
 
-  Graphic3d_Array1OfVertex VN(1,NbPoints+1);
-  Graphic3d_Array1OfVertex V2(1,2);
-  V2(1).SetCoord(xo,yo,zo);
+    const gp_Pnt pp(aC.X() + (aCos * anXYZi.X() + aSin * anXYZj.X()) * theLength * Tg,
+                    aC.Y() + (aCos * anXYZi.Y() + aSin * anXYZj.Y()) * theLength * Tg,
+                    aC.Z() + (aCos * anXYZi.Z() + aSin * anXYZj.Z()) * theLength * Tg);
 
-  Quantity_Length x,y,z;
-  Standard_Real cosinus,sinus, Tg=tan(anAngle);
+    aSegments->AddVertex (pp);
+  }
 
-  for (Standard_Integer i = 1 ; i <= NbPoints ; i++) {
+  Standard_Integer aNbVertices = theNbSegments + 1;
+  Standard_Integer aFirstContourVertex = 2;
+  Standard_Integer anEdgeCount = 0;
+  for (Standard_Integer aVertIter = aFirstContourVertex; aVertIter <= aNbVertices; ++aVertIter)
+  {
+    aSegments->AddEdge (1);
+    aSegments->AddEdge (aVertIter);
+    ++anEdgeCount;
+  }
+  aSegments->AddEdge (aNbVertices);
+  aSegments->AddEdge (aFirstContourVertex);
+  ++anEdgeCount;
+
+  for (Standard_Integer aVertIter = aFirstContourVertex; aVertIter <= aNbVertices - 1; ++aVertIter)
+  {
+    aSegments->AddEdge (aVertIter);
+    aSegments->AddEdge (aVertIter + 1);
+    ++anEdgeCount;
+  }
+  return aSegments;
+}
 
-    cosinus = cos ( 2 * M_PI / NbPoints * (i-1) );   
-    sinus   = sin ( 2 * M_PI / NbPoints * (i-1) );
+// ============================================================================
+// function : DrawShaded
+// purpose  :
+// ============================================================================
+Handle(Graphic3d_ArrayOfTriangles) Prs3d_Arrow::DrawShaded (const gp_Ax1&          theAxis,
+                                                            const Standard_Real    theTubeRadius,
+                                                            const Standard_Real    theAxisLength,
+                                                            const Standard_Real    theConeRadius,
+                                                            const Standard_Real    theConeLength,
+                                                            const Standard_Integer theNbFacettes)
+{
+  const Standard_Real aTubeLength = Max (0.0, theAxisLength - theConeLength);
+  const Standard_Integer aNbTrisTube = (theTubeRadius > 0.0 && aTubeLength > 0.0)
+                                     ? Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1)
+                                     : 0;
+  const Standard_Integer aNbTrisCone = (theConeRadius > 0.0 && theConeLength > 0.0)
+                                     ? (Prs3d_ToolDisk    ::TrianglesNb (theNbFacettes, 1)
+                                      + Prs3d_ToolCylinder::TrianglesNb (theNbFacettes, 1))
+                                     : 0;
+
+  const Standard_Integer aNbTris = aNbTrisTube + aNbTrisCone;
+  if (aNbTris == 0)
+  {
+    return Handle(Graphic3d_ArrayOfTriangles)();
+  }
 
-    x = xc + (cosinus * xi + sinus * xj) * aLength * Tg;
-    y = yc + (cosinus * yi + sinus * yj) * aLength * Tg;
-    z = zc + (cosinus * zi + sinus * zj) * aLength * Tg;
+  Handle(Graphic3d_ArrayOfTriangles) anArray = new Graphic3d_ArrayOfTriangles (aNbTris * 3, 0, Standard_True);
+  if (aNbTrisTube != 0)
+  {
+    gp_Ax3  aSystem (theAxis.Location(), theAxis.Direction());
+    gp_Trsf aTrsf;
+    aTrsf.SetTransformation (aSystem, gp_Ax3());
 
-    VN(i).SetCoord(x,y,z);
-    if(i==1) VN(NbPoints+1).SetCoord(x,y,z);
-    V2(2).SetCoord(x,y,z);
-    Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V2);
+    Prs3d_ToolCylinder aTool (theTubeRadius, theTubeRadius, aTubeLength, theNbFacettes, 1);
+    aTool.FillArray (anArray, aTrsf);
   }
-  Prs3d_Root::CurrentGroup(aPresentation)->Polyline(VN);
-}
 
-//=======================================================================
-//function : Fill
-//purpose  : 
-//=======================================================================
+  if (aNbTrisCone != 0)
+  {
+    gp_Pnt aConeOrigin = theAxis.Location().Translated (gp_Vec (theAxis.Direction().X() * aTubeLength,
+                                                                theAxis.Direction().Y() * aTubeLength,
+                                                                theAxis.Direction().Z() * aTubeLength));
+    gp_Ax3  aSystem (aConeOrigin, theAxis.Direction());
+    gp_Trsf aTrsf;
+    aTrsf.SetTransformation (aSystem, gp_Ax3());
+    {
+      Prs3d_ToolDisk aTool (0.0, theConeRadius, theNbFacettes, 1);
+      aTool.FillArray (anArray, aTrsf);
+    }
+    {
+      Prs3d_ToolCylinder aTool (theConeRadius, 0.0, theConeLength, theNbFacettes, 1);
+      aTool.FillArray (anArray, aTrsf);
+    }
+  }
 
-void Prs3d_Arrow::Fill(const Handle(Prs3d_Presentation)& /*aPresentation*/,
-                       const gp_Pnt& /*aLocation*/,
-                       const gp_Dir& /*aDirection*/,
-                       const Quantity_PlaneAngle /*anAngle*/,
-                      const Quantity_Length /*aLength*/)
-{
+  return anArray;
 }