0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / DsgPrs / DsgPrs_TangentPresentation.cxx
1 // Created on: 1996-01-16
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 #include <DsgPrs_TangentPresentation.ixx>
22
23 #include <Graphic3d_Group.hxx>
24 #include <Graphic3d_ArrayOfSegments.hxx>
25 #include <Prs3d_Arrow.hxx>
26 #include <Prs3d_ArrowAspect.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_LengthAspect.hxx>
29 #include <Graphic3d_AspectLine3d.hxx>
30 #include <Prs3d_PointAspect.hxx>
31 #include <Geom_CartesianPoint.hxx>
32 #include <StdPrs_Point.hxx>
33 #include <gp_Vec.hxx>
34 #include <Prs3d_Arrow.hxx>
35
36 void DsgPrs_TangentPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
37                                       const Handle(Prs3d_Drawer)& aDrawer,
38                                       const gp_Pnt& OffsetPoint,
39                                       const gp_Dir& aDirection,
40                                       const Standard_Real length)
41 {
42   gp_Vec vec(aDirection);
43   gp_Vec vec1 = vec.Multiplied(length);
44   gp_Vec vec2 = vec.Multiplied(-length);
45   gp_Pnt p1 = OffsetPoint.Translated(vec1);
46   gp_Pnt p2 = OffsetPoint.Translated(vec2);
47   
48   // Aspect
49   Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
50   LA->LineAspect()->SetTypeOfLine(Aspect_TOL_SOLID);
51   Handle(Prs3d_ArrowAspect) ARR1 = LA->Arrow1Aspect();
52   Handle(Prs3d_ArrowAspect) ARR2 = LA->Arrow2Aspect();
53   ARR1->SetLength(length/5);
54   ARR2->SetLength(length/5);
55
56   // Array1OfVertex
57   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
58
59   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
60   aPrims->AddVertex(p1);
61   aPrims->AddVertex(p2);
62   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
63
64   // fleche 1 : 
65   Prs3d_Root::NewGroup(aPresentation);
66   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
67   Prs3d_Arrow::Draw(aPresentation,p1,aDirection,LA->Arrow1Aspect()->Angle(),LA->Arrow1Aspect()->Length());
68
69   // fleche 2
70   Prs3d_Root::NewGroup(aPresentation);
71   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
72   Prs3d_Arrow::Draw(aPresentation,p2,aDirection.Reversed(),LA->Arrow2Aspect()->Angle(),LA->Arrow2Aspect()->Length());
73 }