b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #include <DsgPrs_LengthPresentation.ixx> |
16 | #include <gp_Lin.hxx> |
17 | #include <gp_Dir.hxx> |
18 | #include <ElCLib.hxx> |
19 | #include <gce_MakeLin.hxx> |
20 | #include <Graphic3d_Group.hxx> |
b8ddfc2f |
21 | #include <Graphic3d_ArrayOfSegments.hxx> |
22 | #include <Graphic3d_ArrayOfPolylines.hxx> |
7fd59977 |
23 | #include <Prs3d_Root.hxx> |
24 | #include <Prs3d_Arrow.hxx> |
25 | #include <Prs3d_ArrowAspect.hxx> |
26 | #include <Prs3d_LineAspect.hxx> |
a6eb515f |
27 | #include <Prs3d_DimensionAspect.hxx> |
7fd59977 |
28 | #include <TCollection_AsciiString.hxx> |
29 | #include <Graphic3d_AspectLine3d.hxx> |
30 | #include <Prs3d_Text.hxx> |
31 | #include <Precision.hxx> |
32 | #include <Graphic3d_Vertex.hxx> |
33 | #include <Graphic3d_AspectMarker3d.hxx> |
34 | #include <Aspect_TypeOfLine.hxx> |
35 | #include <Aspect_TypeOfMarker.hxx> |
36 | #include <Aspect_AspectMarker.hxx> |
37 | #include <Quantity_Color.hxx> |
38 | #include <DsgPrs.hxx> |
39 | |
40 | #include <Geom_Curve.hxx> |
41 | |
42 | |
43 | void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
44 | const Handle(Prs3d_Drawer)& aDrawer, |
45 | const TCollection_ExtendedString& aText, |
46 | const gp_Pnt& AttachmentPoint1, |
47 | const gp_Pnt& AttachmentPoint2, |
48 | const gp_Dir& aDirection, |
49 | const gp_Pnt& OffsetPoint) |
50 | { |
a6eb515f |
51 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
52 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f |
53 | |
7fd59977 |
54 | gp_Lin L1 (AttachmentPoint1,aDirection); |
55 | gp_Lin L2 (AttachmentPoint2,aDirection); |
56 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
57 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
b8ddfc2f |
58 | gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2); |
7fd59977 |
59 | Standard_Real parmin,parmax,parcur; |
60 | parmin = ElCLib::Parameter(L3,Proj1); |
61 | parmax = parmin; |
62 | parcur = ElCLib::Parameter(L3,Proj2); |
63 | Standard_Real dist = Abs(parmin-parcur); |
64 | if (parcur < parmin) parmin = parcur; |
65 | if (parcur > parmax) parmax = parcur; |
66 | parcur = ElCLib::Parameter(L3,OffsetPoint); |
67 | gp_Pnt offp = ElCLib::Value(parcur,L3); |
68 | |
69 | Standard_Boolean outside = Standard_False; |
70 | if (parcur < parmin) { |
71 | parmin = parcur; |
72 | outside = Standard_True; |
73 | } |
74 | if (parcur > parmax) { |
75 | parmax = parcur; |
76 | outside = Standard_True; |
77 | } |
78 | |
79 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
80 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
81 | |
81bba717 |
82 | // face processing : 1st group |
b8ddfc2f |
83 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
84 | aPrims->AddVertex(PointMin); |
85 | aPrims->AddVertex(PointMax); |
7fd59977 |
86 | |
a6eb515f |
87 | if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length())) |
7fd59977 |
88 | outside = Standard_True; |
7fd59977 |
89 | |
b8ddfc2f |
90 | gp_Dir arrdir = L3.Direction().Reversed(); |
91 | if (outside) |
7fd59977 |
92 | arrdir.Reverse(); |
b8ddfc2f |
93 | |
81bba717 |
94 | // arrow 1 : 2nd group |
a6eb515f |
95 | Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir, LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length()); |
7fd59977 |
96 | |
97 | Prs3d_Root::NewGroup(aPresentation); |
98 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
99 | |
81bba717 |
100 | // arrow 2 : 3rd group |
a6eb515f |
101 | Prs3d_Arrow::Draw(aPresentation,Proj2,arrdir.Reversed(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length()); |
7fd59977 |
102 | |
103 | Prs3d_Root::NewGroup(aPresentation); |
104 | |
81bba717 |
105 | // text : 4th group |
7fd59977 |
106 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp); |
107 | |
7fd59977 |
108 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
b8ddfc2f |
109 | |
81bba717 |
110 | // processing of call 1 : 5th group |
b8ddfc2f |
111 | aPrims->AddVertex(AttachmentPoint1); |
112 | aPrims->AddVertex(Proj1); |
7fd59977 |
113 | |
81bba717 |
114 | // processing of call 2 : 6th group |
b8ddfc2f |
115 | aPrims->AddVertex(AttachmentPoint2); |
116 | aPrims->AddVertex(Proj2); |
117 | |
118 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
119 | } |
120 | |
121 | //================================================================================== |
122 | //function : Add |
123 | //purpose : Adds presentation of length dimension between two planar faces |
124 | //================================================================================== |
125 | |
126 | void DsgPrs_LengthPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation, |
127 | const Handle(Prs3d_Drawer)& aDrawer, |
128 | const TCollection_ExtendedString& aText, |
129 | const gp_Pnt& AttachmentPoint1, |
130 | const gp_Pnt& AttachmentPoint2, |
131 | const gp_Pln& PlaneOfFaces, |
132 | const gp_Dir& aDirection, |
133 | const gp_Pnt& OffsetPoint, |
134 | const DsgPrs_ArrowSide ArrowPrs ) |
135 | { |
a6eb515f |
136 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
137 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
138 | |
139 | gp_Pnt EndOfArrow1, EndOfArrow2; |
140 | gp_Dir DirOfArrow1; |
141 | |
a6eb515f |
142 | DsgPrs::ComputePlanarFacesLengthPresentation( LA->ArrowAspect()->Length(), |
143 | LA->ArrowAspect()->Length(), |
7fd59977 |
144 | AttachmentPoint1, |
145 | AttachmentPoint2, |
146 | aDirection, |
147 | OffsetPoint, |
148 | PlaneOfFaces, |
149 | EndOfArrow1, |
150 | EndOfArrow2, |
151 | DirOfArrow1 ); |
7fd59977 |
152 | |
153 | // Parameters for length's line |
154 | gp_Lin LengthLine( OffsetPoint, DirOfArrow1 ); |
155 | Standard_Real Par1 = ElCLib::Parameter( LengthLine, EndOfArrow1 ); |
156 | Standard_Real Par2 = ElCLib::Parameter( LengthLine, EndOfArrow2 ); |
157 | gp_Pnt FirstPoint, LastPoint; |
0ebaa4db |
158 | if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0)) |
b8ddfc2f |
159 | { |
160 | FirstPoint = OffsetPoint; |
161 | LastPoint = (Abs( Par1 ) > Abs( Par2 ))? EndOfArrow1 : EndOfArrow2; |
162 | } |
7fd59977 |
163 | else |
b8ddfc2f |
164 | { |
165 | FirstPoint = EndOfArrow1; |
166 | LastPoint = EndOfArrow2; |
167 | } |
7fd59977 |
168 | |
169 | // Creating the length's line |
b8ddfc2f |
170 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
171 | |
172 | aPrims->AddVertex(FirstPoint); |
173 | aPrims->AddVertex(LastPoint); |
7fd59977 |
174 | |
175 | // Add presentation of arrows |
b8ddfc2f |
176 | DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs ); |
7fd59977 |
177 | |
178 | // Drawing the text |
179 | Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint ); |
180 | |
181 | // Line from AttachmentPoint1 to end of Arrow1 |
b8ddfc2f |
182 | aPrims->AddVertex(AttachmentPoint1); |
183 | aPrims->AddVertex(EndOfArrow1); |
7fd59977 |
184 | |
185 | // Line from AttachmentPoint2 to end of Arrow2 |
b8ddfc2f |
186 | aPrims->AddVertex(AttachmentPoint2); |
187 | aPrims->AddVertex(EndOfArrow2); |
188 | |
189 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
190 | } |
191 | |
192 | |
193 | //========================================================================================= |
194 | //function : Add |
195 | //purpose : adds presentation of length between two edges, vertex and edge or two vertices |
196 | //========================================================================================= |
197 | |
198 | void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
199 | const Handle(Prs3d_Drawer)& aDrawer, |
200 | const TCollection_ExtendedString& aText, |
201 | const gp_Pnt& AttachmentPoint1, |
202 | const gp_Pnt& AttachmentPoint2, |
203 | const gp_Dir& aDirection, |
204 | const gp_Pnt& OffsetPoint, |
205 | const DsgPrs_ArrowSide ArrowPrs) |
206 | { |
a6eb515f |
207 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
208 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
209 | |
210 | gp_Lin L1 (AttachmentPoint1,aDirection); |
211 | gp_Lin L2 (AttachmentPoint2,aDirection); |
212 | gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1); |
213 | gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2); |
b8ddfc2f |
214 | gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2); |
7fd59977 |
215 | Standard_Real parmin,parmax,parcur; |
216 | parmin = ElCLib::Parameter(L3,Proj1); |
217 | parmax = parmin; |
218 | parcur = ElCLib::Parameter(L3,Proj2); |
219 | Standard_Real dist = Abs(parmin-parcur); |
220 | if (parcur < parmin) parmin = parcur; |
221 | if (parcur > parmax) parmax = parcur; |
222 | parcur = ElCLib::Parameter(L3,OffsetPoint); |
223 | gp_Pnt offp = ElCLib::Value(parcur,L3); |
224 | |
225 | Standard_Boolean outside = Standard_False; |
226 | if (parcur < parmin) { |
227 | parmin = parcur; |
228 | outside = Standard_True; |
229 | } |
230 | if (parcur > parmax) { |
231 | parmax = parcur; |
232 | outside = Standard_True; |
233 | } |
234 | |
235 | gp_Pnt PointMin = ElCLib::Value(parmin,L3); |
236 | gp_Pnt PointMax = ElCLib::Value(parmax,L3); |
237 | |
b8ddfc2f |
238 | // processing of face |
239 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6); |
7fd59977 |
240 | |
b8ddfc2f |
241 | aPrims->AddVertex(PointMin); |
242 | aPrims->AddVertex(PointMax); |
7fd59977 |
243 | |
a6eb515f |
244 | if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length())) |
7fd59977 |
245 | outside = Standard_True; |
7fd59977 |
246 | |
b8ddfc2f |
247 | gp_Dir arrdir = L3.Direction().Reversed(); |
248 | if (outside) |
7fd59977 |
249 | arrdir.Reverse(); |
7fd59977 |
250 | |
81bba717 |
251 | // processing of call 1 |
b8ddfc2f |
252 | aPrims->AddVertex(AttachmentPoint1); |
253 | aPrims->AddVertex(Proj1); |
7fd59977 |
254 | |
81bba717 |
255 | // processing of call 2 |
b8ddfc2f |
256 | aPrims->AddVertex(AttachmentPoint2); |
257 | aPrims->AddVertex(Proj2); |
258 | |
259 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
260 | |
81bba717 |
261 | // text |
7fd59977 |
262 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp); |
263 | |
81bba717 |
264 | // symbols at the extremities of the face |
7fd59977 |
265 | DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs); |
266 | } |
267 | |
268 | |
7fd59977 |
269 | //================================================================================== |
270 | //function : Add |
271 | //purpose : Adds presentation of length dimension between two curvilinear faces |
272 | //================================================================================== |
273 | |
274 | void DsgPrs_LengthPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation, |
275 | const Handle(Prs3d_Drawer)& aDrawer, |
276 | const TCollection_ExtendedString& aText, |
277 | const Handle( Geom_Surface )& SecondSurf, |
278 | const gp_Pnt& AttachmentPoint1, |
279 | const gp_Pnt& AttachmentPoint2, |
280 | const gp_Dir& aDirection, |
281 | const gp_Pnt& OffsetPoint, |
282 | const DsgPrs_ArrowSide ArrowPrs ) |
283 | { |
a6eb515f |
284 | Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect(); |
7fd59977 |
285 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
286 | |
287 | gp_Pnt EndOfArrow2; |
288 | gp_Dir DirOfArrow1; |
289 | Handle( Geom_Curve ) VCurve, UCurve; |
290 | Standard_Real FirstU, deltaU = 0.0e0, FirstV, deltaV = 0.0e0; |
291 | |
a6eb515f |
292 | DsgPrs::ComputeCurvilinearFacesLengthPresentation( LA->ArrowAspect()->Length(), |
293 | LA->ArrowAspect()->Length(), |
7fd59977 |
294 | SecondSurf, |
295 | AttachmentPoint1, |
296 | AttachmentPoint2, |
297 | aDirection, |
298 | EndOfArrow2, |
299 | DirOfArrow1, |
300 | VCurve, |
301 | UCurve, |
302 | FirstU, deltaU, |
303 | FirstV, deltaV ); |
304 | |
7fd59977 |
305 | gp_Lin LengthLine( OffsetPoint, DirOfArrow1 ); |
306 | Standard_Real Par1 = ElCLib::Parameter( LengthLine, AttachmentPoint1 ); |
307 | Standard_Real Par2 = ElCLib::Parameter( LengthLine, EndOfArrow2 ); |
308 | gp_Pnt FirstPoint, LastPoint; |
0ebaa4db |
309 | if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0)) |
b8ddfc2f |
310 | { |
311 | FirstPoint = OffsetPoint; |
312 | LastPoint = (Abs( Par1 ) > Abs( Par2 ))? AttachmentPoint1 : EndOfArrow2; |
313 | } |
7fd59977 |
314 | else |
b8ddfc2f |
315 | { |
316 | FirstPoint = AttachmentPoint1; |
317 | LastPoint = EndOfArrow2; |
318 | } |
7fd59977 |
319 | |
320 | // Creating the length's line |
b8ddfc2f |
321 | Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2); |
322 | aPrims->AddVertex(FirstPoint); |
323 | aPrims->AddVertex(LastPoint); |
324 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
7fd59977 |
325 | |
326 | // Add presentation of arrows |
b8ddfc2f |
327 | DsgPrs::ComputeSymbol( aPresentation, LA, AttachmentPoint1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs ); |
7fd59977 |
328 | |
329 | // Drawing the text |
330 | Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint ); |
331 | |
332 | // Two curves from end of Arrow2 to AttachmentPoint2 |
333 | Standard_Real Alpha, delta; |
334 | Standard_Integer NodeNumber; |
335 | |
336 | Alpha = Abs( deltaU ); |
337 | if (Alpha > Precision::Angular() && Alpha<Precision::Infinite()) |
b8ddfc2f |
338 | { |
339 | NodeNumber = Max( 4 , Standard_Integer (50. * Alpha / M_PI) ); |
340 | delta = deltaU / (Standard_Real)( NodeNumber - 1 ); |
341 | aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber); |
342 | for (Standard_Integer i = 1; i <= NodeNumber; i++, FirstU += delta) |
343 | aPrims->AddVertex(VCurve->Value( FirstU )); |
344 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
345 | } |
7fd59977 |
346 | Alpha = Abs( deltaV ); |
347 | if (Alpha > Precision::Angular() && Alpha<Precision::Infinite()) |
b8ddfc2f |
348 | { |
349 | NodeNumber = Max( 4 , Standard_Integer (50. * Alpha / M_PI) ); |
350 | delta = deltaV / (Standard_Real)( NodeNumber - 1 ); |
351 | aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber); |
352 | for (Standard_Integer i = 1; i <= NodeNumber; i++, FirstV += delta) |
353 | aPrims->AddVertex(UCurve->Value( FirstV )); |
354 | Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims); |
355 | } |
7fd59977 |
356 | } |
357 | |
358 | |
7fd59977 |
359 | //================================ |
360 | // Function: |
361 | // Purpose: Rob 26-mar-96 |
362 | //================================= |
363 | |
364 | void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPrs, |
365 | const Handle(Prs3d_Drawer)& aDrawer, |
366 | const gp_Pnt& Pt1, |
367 | const gp_Pnt& Pt2, |
368 | const DsgPrs_ArrowSide ArrowPrs) |
369 | { |
b8ddfc2f |
370 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); |
371 | aPrims->AddVertex(Pt1); |
372 | aPrims->AddVertex(Pt2); |
373 | Prs3d_Root::CurrentGroup(aPrs)->AddPrimitiveArray(aPrims); |
374 | |
7fd59977 |
375 | gp_Vec V ; |
b8ddfc2f |
376 | switch(ArrowPrs) |
377 | { |
378 | case DsgPrs_AS_LASTAR: |
7fd59977 |
379 | Prs3d_Arrow::Draw(aPrs,Pt2,gp_Dir(gp_Vec(Pt1,Pt2)), |
a6eb515f |
380 | aDrawer->DimensionAspect()->ArrowAspect()->Angle(), |
381 | aDrawer->DimensionAspect()->ArrowAspect()->Length()); |
7fd59977 |
382 | break; |
b8ddfc2f |
383 | case DsgPrs_AS_FIRSTAR: |
7fd59977 |
384 | Prs3d_Arrow::Draw(aPrs,Pt1,gp_Dir(gp_Vec(Pt2,Pt1)), |
a6eb515f |
385 | aDrawer->DimensionAspect()->ArrowAspect()->Angle(), |
386 | aDrawer->DimensionAspect()->ArrowAspect()->Length()); |
7fd59977 |
387 | break; |
b8ddfc2f |
388 | case DsgPrs_AS_BOTHAR: |
7fd59977 |
389 | V = gp_Vec(Pt1,Pt2); |
390 | Prs3d_Arrow::Draw(aPrs,Pt2,gp_Dir(V), |
a6eb515f |
391 | aDrawer->DimensionAspect()->ArrowAspect()->Angle(), |
392 | aDrawer->DimensionAspect()->ArrowAspect()->Length()); |
7fd59977 |
393 | Prs3d_Arrow::Draw(aPrs,Pt1,gp_Dir(V.Reversed()), |
a6eb515f |
394 | aDrawer->DimensionAspect()->ArrowAspect()->Angle(), |
395 | aDrawer->DimensionAspect()->ArrowAspect()->Length()); |
7fd59977 |
396 | break; |
b8ddfc2f |
397 | default: |
7fd59977 |
398 | break; |
7fd59977 |
399 | } |
7fd59977 |
400 | } |