0023634: Eliminate Polyline and Polygon usage in drawers
[occt.git] / src / DsgPrs / DsgPrs_IdenticPresentation.cxx
CommitLineData
b311480e 1// Created on: 1997-01-03
2// Created by: Flore Lantheaume
3// Copyright (c) 1997-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
7fd59977 21
22
23#include <DsgPrs_IdenticPresentation.ixx>
24
25#include <Graphic3d_Group.hxx>
b8ddfc2f 26#include <Graphic3d_ArrayOfSegments.hxx>
27#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 28#include <Graphic3d_AspectMarker3d.hxx>
29#include <Graphic3d_AspectLine3d.hxx>
30
31#include <Prs3d_LineAspect.hxx>
32#include <Prs3d_LengthAspect.hxx>
33#include <Prs3d_Text.hxx>
34
35#include <TCollection_AsciiString.hxx>
36
37#include <gp_Vec.hxx>
38#include <gp_Dir.hxx>
39
40#include <ElCLib.hxx>
41
42#include <Precision.hxx>
43#include <gp_Elips.hxx>
44
45void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
46 const Handle(Prs3d_Drawer)& aDrawer,
47 const TCollection_ExtendedString& aText,
48 const gp_Pnt& aPntAttach,
49 const gp_Pnt& aPntOffset)
50{
51 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
52 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
53
b8ddfc2f 54 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
55 aPrims->AddVertex(aPntAttach);
56 aPrims->AddVertex(aPntOffset);
57 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 58
59 // On ajoute un rond au point d'attache
60 Prs3d_Root::NewGroup(aPresentation);
61 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
62 Handle(Graphic3d_AspectMarker3d) MarkerAsp = new Graphic3d_AspectMarker3d();
63 MarkerAsp->SetType(Aspect_TOM_BALL);
64 MarkerAsp->SetScale(0.8);
65 Quantity_Color acolor;
66 Aspect_TypeOfLine atype;
67 Standard_Real awidth;
68 LA->LineAspect()->Aspect()->Values(acolor, atype, awidth);
69 MarkerAsp->SetColor(acolor);
70 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(MarkerAsp);
71 Graphic3d_Vertex V3d(aPntAttach.X(), aPntAttach.Y(), aPntAttach.Z());
72 Prs3d_Root::CurrentGroup(aPresentation)->Marker(V3d);
73
74 // texte
75 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
76}
77
78
7fd59977 79void DsgPrs_IdenticPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
80 const Handle(Prs3d_Drawer)& aDrawer,
81 const TCollection_ExtendedString& aText,
82 const gp_Pnt& aFAttach,
83 const gp_Pnt& aSAttach,
84 const gp_Pnt& aPntOffset)
85{
86 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
87 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
88
b8ddfc2f 89 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(4);
7fd59977 90
b8ddfc2f 91 aPrims->AddVertex(aFAttach);
92 aPrims->AddVertex(aSAttach);
7fd59977 93
94 // trait joignant aPntOffset
7fd59977 95 gp_Vec v1(aFAttach, aSAttach);
96 gp_Vec v2(aSAttach, aPntOffset);
b8ddfc2f 97
98 aPrims->AddVertex(aPntOffset);
99 if ( !v1.IsParallel(v2, Precision::Angular()))
100 {
7fd59977 101 // on joint aPntOffset a son projete
102 gp_Lin ll(aFAttach, gp_Dir(v1));
b8ddfc2f 103 aPrims->AddVertex(ElCLib::Value(ElCLib::Parameter(ll,aPntOffset ), ll));
7fd59977 104 }
b8ddfc2f 105 else
106 aPrims->AddVertex(aSAttach);
107
108 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 109
110 // texte
111 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
112}
113
114
7fd59977 115void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
116 const Handle(Prs3d_Drawer)& aDrawer,
117 const TCollection_ExtendedString& aText,
118 const gp_Ax2& theAxe,
119 const gp_Pnt& aCenter,
120 const gp_Pnt& aFAttach,
121 const gp_Pnt& aSAttach,
122 const gp_Pnt& aPntOffset)
123{
124 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
125 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
126
127 gp_Ax2 ax = theAxe;
128 ax.SetLocation(aCenter);
129 Standard_Real rad = aCenter.Distance(aFAttach);
130 gp_Circ CC(ax,rad );
131 Standard_Real pFAttach = ElCLib::Parameter(CC, aFAttach);
132 Standard_Real pSAttach = ElCLib::Parameter(CC, aSAttach);
133 Standard_Real alpha = pSAttach - pFAttach;
b8ddfc2f 134 if ( alpha < 0 ) alpha += 2. * M_PI;
135 const Standard_Integer nb = (Standard_Integer )( 50. * alpha / M_PI);
136 const Standard_Integer nbp = Max (4, nb);
137 const Standard_Real dteta = alpha/(nbp-1);
7fd59977 138
b8ddfc2f 139 Handle(Graphic3d_ArrayOfPolylines) aPrims;
7fd59977 140
141 // trait joignant aPntOffset
b8ddfc2f 142 if ( Abs((aPntOffset.Distance(aCenter) - rad )) >= Precision::Confusion() )
143 {
144 aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2);
145 aPrims->AddBound(2);
146 aPrims->AddVertex(aPntOffset);
147 aPrims->AddVertex(ElCLib::Value(ElCLib::Parameter(CC,aPntOffset ), CC));
148 aPrims->AddBound(nbp);
7fd59977 149 }
b8ddfc2f 150 else
151 aPrims = new Graphic3d_ArrayOfPolylines(nbp);
152
153 for (Standard_Integer i = 1; i<=nbp; i++)
154 aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),CC));
155
156 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 157
158 // texte
159 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
160}
161
162// jfa 16/10/2000
163void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
164 const Handle(Prs3d_Drawer)& aDrawer,
165 const TCollection_ExtendedString& aText,
166 const gp_Ax2& theAxe,
167 const gp_Pnt& aCenter,
168 const gp_Pnt& aFAttach,
169 const gp_Pnt& aSAttach,
170 const gp_Pnt& aPntOffset,
171 const gp_Pnt& aPntOnCirc)
172{
173 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
174 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
175
176 gp_Ax2 ax = theAxe;
177 ax.SetLocation(aCenter);
178 Standard_Real rad = aCenter.Distance(aFAttach);
179 gp_Circ CC(ax,rad );
b8ddfc2f 180 Standard_Real pFAttach = ElCLib::Parameter(CC, aFAttach);
181 Standard_Real pSAttach = ElCLib::Parameter(CC, aSAttach);
7fd59977 182 Standard_Real alpha = pSAttach - pFAttach;
b8ddfc2f 183 if ( alpha < 0 ) alpha += 2. * M_PI;
184 const Standard_Integer nb = (Standard_Integer)( 50. * alpha / M_PI);
185 const Standard_Integer nbp = Max (4, nb);
186 const Standard_Real dteta = alpha/(nbp-1);
187
188 Handle(Graphic3d_ArrayOfPolylines) aPrims;
7fd59977 189
7fd59977 190 // trait joignant aPntOffset
7fd59977 191 if ( aPntOffset.Distance(aPntOnCirc) >= Precision::Confusion() )
b8ddfc2f 192 {
193 aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2);
194 aPrims->AddBound(2);
195 aPrims->AddVertex(aPntOffset);
196 aPrims->AddVertex(aPntOnCirc);
197 aPrims->AddBound(nbp);
198 }
199 else
200 aPrims = new Graphic3d_ArrayOfPolylines(nbp);
201
202 for (Standard_Integer i = 1; i<=nbp; i++)
203 aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),CC));
204
205 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 206
207 // texte
208 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
209}
210// jfa 16/10/2000 end
211
212// jfa 10/10/2000
213void DsgPrs_IdenticPresentation::Add(const Handle(Prs3d_Presentation)& aPresentation,
214 const Handle(Prs3d_Drawer)& aDrawer,
215 const TCollection_ExtendedString& aText,
216 const gp_Elips& anEllipse,
217 const gp_Pnt& aFAttach,
218 const gp_Pnt& aSAttach,
219 const gp_Pnt& aPntOffset,
220 const gp_Pnt& aPntOnElli)
221{
222 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
223 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
224
225 Standard_Real pFAttach = ElCLib::Parameter(anEllipse, aFAttach);
226 Standard_Real pSAttach = ElCLib::Parameter(anEllipse, aSAttach);
227 Standard_Real alpha = pSAttach - pFAttach;
b8ddfc2f 228 if ( alpha < 0 ) alpha += 2. * M_PI;
229 const Standard_Integer nb = (Standard_Integer)(50.0*alpha/M_PI);
230 const Standard_Integer nbp = Max (4, nb);
231 const Standard_Real dteta = alpha/(nbp-1);
7fd59977 232
b8ddfc2f 233 Handle(Graphic3d_ArrayOfPolylines) aPrims;
7fd59977 234
235 // trait joignant aPntOffset
7fd59977 236 if ( ! aPntOnElli.IsEqual(aPntOffset, Precision::Confusion()) )
b8ddfc2f 237 {
238 aPrims = new Graphic3d_ArrayOfPolylines(nbp+2,2);
239 aPrims->AddBound(2);
240 aPrims->AddVertex(aPntOffset);
241 aPrims->AddVertex(aPntOnElli);
242 aPrims->AddBound(nbp);
243 }
244 else
245 aPrims = new Graphic3d_ArrayOfPolylines(nbp);
246
247 for (Standard_Integer i = 1; i<=nbp; i++)
248 aPrims->AddVertex(ElCLib::Value(pFAttach + dteta*(i-1),anEllipse));
249
250 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
7fd59977 251
252 // texte
253 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,aPntOffset);
254}
255// jfa 10/10/2000 end