0027756: Visualization - add Draw() method taking Graphic3d_Group to tools Prs3d_Arro...
[occt.git] / src / DsgPrs / DsgPrs_ParalPresentation.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.hxx>
19 #include <DsgPrs_ParalPresentation.hxx>
20 #include <ElCLib.hxx>
21 #include <gce_MakeLin.hxx>
22 #include <gp_Dir.hxx>
23 #include <gp_Lin.hxx>
24 #include <gp_Pnt.hxx>
25 #include <Graphic3d_ArrayOfSegments.hxx>
26 #include <Graphic3d_AspectLine3d.hxx>
27 #include <Graphic3d_Group.hxx>
28 #include <Prs3d_Arrow.hxx>
29 #include <Prs3d_ArrowAspect.hxx>
30 #include <Prs3d_DimensionAspect.hxx>
31 #include <Prs3d_LineAspect.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <Prs3d_Text.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TCollection_ExtendedString.hxx>
36
37 void DsgPrs_ParalPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
38                                     const Handle(Prs3d_Drawer)& aDrawer,
39                                     const TCollection_ExtendedString& aText,
40                                     const gp_Pnt& AttachmentPoint1,
41                                     const gp_Pnt& AttachmentPoint2,
42                                     const gp_Dir& aDirection,
43                                     const gp_Pnt& OffsetPoint)
44 {
45   Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
46   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
47   gp_Lin L1 (AttachmentPoint1,aDirection);
48   gp_Lin L2 (AttachmentPoint2,aDirection);
49   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
50   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
51   gp_Lin L3 = gce_MakeLin(Proj1,Proj2);
52   Standard_Real parmin,parmax,parcur;
53   parmin = ElCLib::Parameter(L3,Proj1);
54   parmax = parmin;
55   parcur = ElCLib::Parameter(L3,Proj2);
56   Standard_Real dist = Abs(parmin-parcur);
57   if (parcur < parmin) parmin = parcur;
58   if (parcur > parmax) parmax = parcur;
59   parcur = ElCLib::Parameter(L3,OffsetPoint);
60   gp_Pnt offp = ElCLib::Value(parcur,L3);
61
62   Standard_Boolean outside = Standard_False;
63   if (parcur < parmin) {
64     parmin = parcur;
65     outside = Standard_True;
66   }
67   if (parcur > parmax) {
68     parmax = parcur;
69     outside = Standard_True;
70   }
71
72   gp_Pnt PointMin = ElCLib::Value(parmin,L3);
73   gp_Pnt PointMax = ElCLib::Value(parmax,L3);
74
75   // processing of side : 1st group
76   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
77   aPrims->AddVertex(PointMin);
78   aPrims->AddVertex(PointMax);
79
80   Prs3d_Root::NewGroup(aPresentation);
81   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
82   
83   if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
84     outside = Standard_True;
85   gp_Dir arrdir = L3.Direction().Reversed();
86   if (outside)
87     arrdir.Reverse();
88
89   // arrow 1 : 2nd group
90   Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), Proj1, arrdir, LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
91
92   Prs3d_Root::NewGroup(aPresentation);
93   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
94   
95   // arrow 2 : 3rd group
96   Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), Proj2, arrdir.Reversed(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
97
98   Prs3d_Root::NewGroup(aPresentation);
99   
100   // text : 4th group
101   Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, offp);
102
103   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
104
105   // processing of call 1 : 5th group
106   aPrims->AddVertex(AttachmentPoint1);
107   aPrims->AddVertex(Proj1);
108   
109   // processing of call 2 : 6th group
110   aPrims->AddVertex(AttachmentPoint2);
111   aPrims->AddVertex(Proj2);
112
113   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
114 }
115
116
117 //==========================================================================
118 // function : DsgPrs_ParalPresentation::Add
119 // purpose  : it is possible to choose the symbol of extremities of the face (arrow, point...)
120 //==========================================================================
121 void DsgPrs_ParalPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
122                                     const Handle(Prs3d_Drawer)& aDrawer,
123                                     const TCollection_ExtendedString& aText,
124                                     const gp_Pnt& AttachmentPoint1,
125                                     const gp_Pnt& AttachmentPoint2,
126                                     const gp_Dir& aDirection,
127                                     const gp_Pnt& OffsetPoint,
128                                     const DsgPrs_ArrowSide ArrowPrs)
129 {
130   Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
131   Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
132
133   gp_Lin L1 (AttachmentPoint1,aDirection);
134   gp_Lin L2 (AttachmentPoint2,aDirection);
135   gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
136   gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
137   gp_Lin L3 = gce_MakeLin(Proj1,Proj2);
138   Standard_Real parmin,parmax,parcur;
139   parmin = ElCLib::Parameter(L3,Proj1);
140   parmax = parmin;
141   parcur = ElCLib::Parameter(L3,Proj2);
142   Standard_Real dist = Abs(parmin-parcur);
143   if (parcur < parmin) parmin = parcur;
144   if (parcur > parmax) parmax = parcur;
145   parcur = ElCLib::Parameter(L3,OffsetPoint);
146   gp_Pnt offp = ElCLib::Value(parcur,L3);
147
148   Standard_Boolean outside = Standard_False;
149   if (parcur < parmin) {
150     parmin = parcur;
151     outside = Standard_True;
152   }
153   if (parcur > parmax) {
154     parmax = parcur;
155     outside = Standard_True;
156   }
157
158   gp_Pnt PointMin = ElCLib::Value(parmin,L3);
159   gp_Pnt PointMax = ElCLib::Value(parmax,L3);
160
161   // processing of face 
162   Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
163   aPrims->AddVertex(PointMin);
164   aPrims->AddVertex(PointMax);
165   
166   if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
167     outside = Standard_True;
168   gp_Dir arrdir = L3.Direction().Reversed();
169   if (outside)
170     arrdir.Reverse();
171
172   // processing of call 1 
173   aPrims->AddVertex(AttachmentPoint1);
174   aPrims->AddVertex(Proj1);
175   
176   // processing of call 2 
177   aPrims->AddVertex(AttachmentPoint2);
178   aPrims->AddVertex(Proj2);
179
180   Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
181
182   // text 
183   Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, offp);
184   
185   //arrows
186   DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs);
187 }