0027756: Visualization - add Draw() method taking Graphic3d_Group to tools Prs3d_Arro...
[occt.git] / src / DsgPrs / DsgPrs_PerpenPresentation.cxx
1 // Created on: 1995-11-28
2 // Created by: Jean-Pierre COMBE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <DsgPrs_PerpenPresentation.hxx>
19 #include <ElCLib.hxx>
20 #include <gce_MakeDir.hxx>
21 #include <gce_MakeLin.hxx>
22 #include <Geom_CartesianPoint.hxx>
23 #include <gp_Dir.hxx>
24 #include <gp_Lin.hxx>
25 #include <gp_Pnt.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_Group.hxx>
30 #include <Prs3d_Arrow.hxx>
31 #include <Prs3d_ArrowAspect.hxx>
32 #include <Prs3d_DimensionAspect.hxx>
33 #include <Prs3d_LineAspect.hxx>
34 #include <Prs3d_PointAspect.hxx>
35 #include <Prs3d_Presentation.hxx>
36 #include <Prs3d_Text.hxx>
37 #include <Prs3d_TextAspect.hxx>
38 #include <StdPrs_Point.hxx>
39 #include <TCollection_AsciiString.hxx>
40
41 void DsgPrs_PerpenPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
42                                      const Handle(Prs3d_Drawer)& aDrawer,
43                                      const gp_Pnt& pAx1,
44                                      const gp_Pnt& pAx2,
45                                      const gp_Pnt& pnt1,
46                                      const gp_Pnt& pnt2,
47                                      const gp_Pnt& OffsetPoint,
48                                      const Standard_Boolean intOut1,
49                                      const Standard_Boolean intOut2)
50 {
51   Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
52   LA->LineAspect()->SetTypeOfLine(Aspect_TOL_SOLID); // ou DOT ou DOTDASH
53   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
54   
55   // segments
56   Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfPolylines(6,2);
57
58   aPrims->AddBound(3);
59   aPrims->AddVertex(OffsetPoint);
60   aPrims->AddVertex(pAx1);
61   aPrims->AddVertex(pAx2);
62
63   // Symbol
64   gp_Vec vec1(gce_MakeDir(OffsetPoint,pAx1));
65   gp_Vec vec2(gce_MakeDir(OffsetPoint,pAx2));
66   vec1 *= .2 * OffsetPoint.Distance(pAx1);
67   vec2 *= .2 * OffsetPoint.Distance(pAx2);
68
69   gp_Pnt pAx11 = OffsetPoint.Translated(vec1);
70   gp_Pnt pAx22 = OffsetPoint.Translated(vec2);
71   gp_Pnt p_symb = pAx22.Translated(vec1);
72
73   aPrims->AddBound(3);
74   aPrims->AddVertex(pAx11);
75   aPrims->AddVertex(p_symb);
76   aPrims->AddVertex(pAx22);
77
78   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
79
80   // points attache
81   if (intOut1 || intOut2)
82   {
83     LA->LineAspect()->SetTypeOfLine(Aspect_TOL_DOT); // ou DOT ou DOTDASH
84     Prs3d_Root::NewGroup(aPresentation);
85     Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
86
87     if (intOut1) {
88       aPrims = new Graphic3d_ArrayOfSegments(2);
89       aPrims->AddVertex(pAx1);
90       aPrims->AddVertex(pnt1);
91       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
92     }
93     if (intOut2) {
94       aPrims = new Graphic3d_ArrayOfSegments(2);
95       aPrims->AddVertex(pAx2);
96       aPrims->AddVertex(pnt2);
97       Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
98     }
99   }
100 }