0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / Prs3d / Prs3d_Vector.gxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19 #include <Graphic3d_Group.hxx>
20 #include <Graphic3d_AspectMarker3d.hxx>
21 #include <Graphic3d_AspectLine3d.hxx>
22 #include <Prs3d_Arrow.hxx>
23 #include <gp_Dir.hxx>
24 #include <Prs3d_LineAspect.hxx>
25 #include <gp_Vec.hxx>
26 #include <gp_Pnt.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28
29
30 void Prs3d_Vector::Add(const Handle(Prs3d_Presentation)& aPresentation,
31                        const anyVector&                  aVector,
32                        const Handle(Prs3d_Drawer)&       aDrawer ) 
33 {
34   gp_Pnt Pnt = VectorTool::Location(aVector);
35   gp_Vec Vec = VectorTool::Vec(aVector);
36   gp_Pnt Pnt2 = Pnt.Translated(Vec);
37
38   Handle(Graphic3d_Group) G = Prs3d_Root::CurrentGroup(aPresentation);
39   G->SetPrimitivesAspect(aDrawer->VectorAspect()->Aspect());
40
41   Quantity_Color Col; Aspect_TypeOfLine Tol; Standard_Real W;
42   aDrawer->VectorAspect()->Aspect()->Values(Col,Tol,W);
43
44 //
45 // Trace d'une petite sphere au debut du vecteur:
46 //
47   Quantity_Length x1,y1,z1;
48   Pnt.Coord(x1,y1,z1);
49   Graphic3d_Vertex VTX(x1,y1,z1);
50   Handle(Graphic3d_AspectMarker3d) Asp = new Graphic3d_AspectMarker3d(Aspect_TOM_BALL,Col,1.);
51   G->SetPrimitivesAspect(Asp);
52   G->Marker(VTX);
53
54   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
55   aPrims->AddVertex(Pnt);
56   aPrims->AddVertex(Pnt2);
57   G->AddPrimitiveArray(aPrims);
58
59   Prs3d_Arrow::Draw(aPresentation,Pnt2,gp_Dir(Vec),M_PI/180.*10.,Vec.Magnitude()/10.);
60 }