1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <DsgPrs_LengthPresentation.hxx>
19 #include <gce_MakeLin.hxx>
20 #include <Geom_Curve.hxx>
21 #include <Geom_Surface.hxx>
26 #include <Graphic3d_ArrayOfPolylines.hxx>
27 #include <Graphic3d_ArrayOfSegments.hxx>
28 #include <Graphic3d_AspectLine3d.hxx>
29 #include <Graphic3d_AspectMarker3d.hxx>
30 #include <Graphic3d_Group.hxx>
31 #include <Precision.hxx>
32 #include <Prs3d_Arrow.hxx>
33 #include <Prs3d_ArrowAspect.hxx>
34 #include <Prs3d_DimensionAspect.hxx>
35 #include <Prs3d_LineAspect.hxx>
36 #include <Prs3d_Presentation.hxx>
37 #include <Prs3d_Root.hxx>
38 #include <Prs3d_Text.hxx>
39 #include <TCollection_AsciiString.hxx>
40 #include <TCollection_ExtendedString.hxx>
42 void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
43 const Handle(Prs3d_Drawer)& aDrawer,
44 const TCollection_ExtendedString& aText,
45 const gp_Pnt& AttachmentPoint1,
46 const gp_Pnt& AttachmentPoint2,
47 const gp_Dir& aDirection,
48 const gp_Pnt& OffsetPoint)
50 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
51 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
53 gp_Lin L1 (AttachmentPoint1,aDirection);
54 gp_Lin L2 (AttachmentPoint2,aDirection);
55 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
56 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
57 gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2);
58 Standard_Real parmin,parmax,parcur;
59 parmin = ElCLib::Parameter(L3,Proj1);
61 parcur = ElCLib::Parameter(L3,Proj2);
62 Standard_Real dist = Abs(parmin-parcur);
63 if (parcur < parmin) parmin = parcur;
64 if (parcur > parmax) parmax = parcur;
65 parcur = ElCLib::Parameter(L3,OffsetPoint);
66 gp_Pnt offp = ElCLib::Value(parcur,L3);
68 Standard_Boolean outside = Standard_False;
69 if (parcur < parmin) {
71 outside = Standard_True;
73 if (parcur > parmax) {
75 outside = Standard_True;
78 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
79 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
81 // face processing : 1st group
82 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
83 aPrims->AddVertex(PointMin);
84 aPrims->AddVertex(PointMax);
86 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
87 outside = Standard_True;
89 gp_Dir arrdir = L3.Direction().Reversed();
93 // arrow 1 : 2nd group
94 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), Proj1, arrdir, LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
96 Prs3d_Root::NewGroup(aPresentation);
97 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
99 // arrow 2 : 3rd group
100 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation), Proj2, arrdir.Reversed(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
102 Prs3d_Root::NewGroup(aPresentation);
105 Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, offp);
107 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
109 // processing of call 1 : 5th group
110 aPrims->AddVertex(AttachmentPoint1);
111 aPrims->AddVertex(Proj1);
113 // processing of call 2 : 6th group
114 aPrims->AddVertex(AttachmentPoint2);
115 aPrims->AddVertex(Proj2);
117 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
120 //==================================================================================
122 //purpose : Adds presentation of length dimension between two planar faces
123 //==================================================================================
125 void DsgPrs_LengthPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
126 const Handle(Prs3d_Drawer)& aDrawer,
127 const TCollection_ExtendedString& aText,
128 const gp_Pnt& AttachmentPoint1,
129 const gp_Pnt& AttachmentPoint2,
130 const gp_Pln& PlaneOfFaces,
131 const gp_Dir& aDirection,
132 const gp_Pnt& OffsetPoint,
133 const DsgPrs_ArrowSide ArrowPrs )
135 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
136 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
138 gp_Pnt EndOfArrow1, EndOfArrow2;
141 DsgPrs::ComputePlanarFacesLengthPresentation( LA->ArrowAspect()->Length(),
142 LA->ArrowAspect()->Length(),
152 // Parameters for length's line
153 gp_Lin LengthLine( OffsetPoint, DirOfArrow1 );
154 Standard_Real Par1 = ElCLib::Parameter( LengthLine, EndOfArrow1 );
155 Standard_Real Par2 = ElCLib::Parameter( LengthLine, EndOfArrow2 );
156 gp_Pnt FirstPoint, LastPoint;
157 if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0))
159 FirstPoint = OffsetPoint;
160 LastPoint = (Abs( Par1 ) > Abs( Par2 ))? EndOfArrow1 : EndOfArrow2;
164 FirstPoint = EndOfArrow1;
165 LastPoint = EndOfArrow2;
168 // Creating the length's line
169 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
171 aPrims->AddVertex(FirstPoint);
172 aPrims->AddVertex(LastPoint);
174 // Add presentation of arrows
175 DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs );
178 Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, OffsetPoint);
180 // Line from AttachmentPoint1 to end of Arrow1
181 aPrims->AddVertex(AttachmentPoint1);
182 aPrims->AddVertex(EndOfArrow1);
184 // Line from AttachmentPoint2 to end of Arrow2
185 aPrims->AddVertex(AttachmentPoint2);
186 aPrims->AddVertex(EndOfArrow2);
188 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
192 //=========================================================================================
194 //purpose : adds presentation of length between two edges, vertex and edge or two vertices
195 //=========================================================================================
197 void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
198 const Handle(Prs3d_Drawer)& aDrawer,
199 const TCollection_ExtendedString& aText,
200 const gp_Pnt& AttachmentPoint1,
201 const gp_Pnt& AttachmentPoint2,
202 const gp_Dir& aDirection,
203 const gp_Pnt& OffsetPoint,
204 const DsgPrs_ArrowSide ArrowPrs)
206 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
207 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
209 gp_Lin L1 (AttachmentPoint1,aDirection);
210 gp_Lin L2 (AttachmentPoint2,aDirection);
211 gp_Pnt Proj1 = ElCLib::Value(ElCLib::Parameter(L1,OffsetPoint),L1);
212 gp_Pnt Proj2 = ElCLib::Value(ElCLib::Parameter(L2,OffsetPoint),L2);
213 gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2);
214 Standard_Real parmin,parmax,parcur;
215 parmin = ElCLib::Parameter(L3,Proj1);
217 parcur = ElCLib::Parameter(L3,Proj2);
218 Standard_Real dist = Abs(parmin-parcur);
219 if (parcur < parmin) parmin = parcur;
220 if (parcur > parmax) parmax = parcur;
221 parcur = ElCLib::Parameter(L3,OffsetPoint);
222 gp_Pnt offp = ElCLib::Value(parcur,L3);
224 Standard_Boolean outside = Standard_False;
225 if (parcur < parmin) {
227 outside = Standard_True;
229 if (parcur > parmax) {
231 outside = Standard_True;
234 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
235 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
237 // processing of face
238 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
240 aPrims->AddVertex(PointMin);
241 aPrims->AddVertex(PointMax);
243 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
244 outside = Standard_True;
246 gp_Dir arrdir = L3.Direction().Reversed();
250 // processing of call 1
251 aPrims->AddVertex(AttachmentPoint1);
252 aPrims->AddVertex(Proj1);
254 // processing of call 2
255 aPrims->AddVertex(AttachmentPoint2);
256 aPrims->AddVertex(Proj2);
258 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
261 Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, offp);
263 // symbols at the extremities of the face
264 DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs);
268 //==================================================================================
270 //purpose : Adds presentation of length dimension between two curvilinear faces
271 //==================================================================================
273 void DsgPrs_LengthPresentation::Add( const Handle(Prs3d_Presentation)& aPresentation,
274 const Handle(Prs3d_Drawer)& aDrawer,
275 const TCollection_ExtendedString& aText,
276 const Handle( Geom_Surface )& SecondSurf,
277 const gp_Pnt& AttachmentPoint1,
278 const gp_Pnt& AttachmentPoint2,
279 const gp_Dir& aDirection,
280 const gp_Pnt& OffsetPoint,
281 const DsgPrs_ArrowSide ArrowPrs )
283 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
284 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
288 Handle( Geom_Curve ) VCurve, UCurve;
289 Standard_Real FirstU, deltaU = 0.0e0, FirstV, deltaV = 0.0e0;
291 DsgPrs::ComputeCurvilinearFacesLengthPresentation( LA->ArrowAspect()->Length(),
292 LA->ArrowAspect()->Length(),
304 gp_Lin LengthLine( OffsetPoint, DirOfArrow1 );
305 Standard_Real Par1 = ElCLib::Parameter( LengthLine, AttachmentPoint1 );
306 Standard_Real Par2 = ElCLib::Parameter( LengthLine, EndOfArrow2 );
307 gp_Pnt FirstPoint, LastPoint;
308 if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0))
310 FirstPoint = OffsetPoint;
311 LastPoint = (Abs( Par1 ) > Abs( Par2 ))? AttachmentPoint1 : EndOfArrow2;
315 FirstPoint = AttachmentPoint1;
316 LastPoint = EndOfArrow2;
319 // Creating the length's line
320 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
321 aPrims->AddVertex(FirstPoint);
322 aPrims->AddVertex(LastPoint);
323 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
325 // Add presentation of arrows
326 DsgPrs::ComputeSymbol( aPresentation, LA, AttachmentPoint1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs );
329 Prs3d_Text::Draw (Prs3d_Root::CurrentGroup (aPresentation), LA->TextAspect(), aText, OffsetPoint);
331 // Two curves from end of Arrow2 to AttachmentPoint2
332 Standard_Real Alpha, delta;
333 Standard_Integer NodeNumber;
335 Alpha = Abs( deltaU );
336 if (Alpha > Precision::Angular() && Alpha<Precision::Infinite())
338 NodeNumber = Max( 4 , Standard_Integer (50. * Alpha / M_PI) );
339 delta = deltaU / (Standard_Real)( NodeNumber - 1 );
340 aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
341 for (Standard_Integer i = 1; i <= NodeNumber; i++, FirstU += delta)
342 aPrims->AddVertex(VCurve->Value( FirstU ));
343 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
345 Alpha = Abs( deltaV );
346 if (Alpha > Precision::Angular() && Alpha<Precision::Infinite())
348 NodeNumber = Max( 4 , Standard_Integer (50. * Alpha / M_PI) );
349 delta = deltaV / (Standard_Real)( NodeNumber - 1 );
350 aPrims = new Graphic3d_ArrayOfPolylines(NodeNumber);
351 for (Standard_Integer i = 1; i <= NodeNumber; i++, FirstV += delta)
352 aPrims->AddVertex(UCurve->Value( FirstV ));
353 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
358 //================================
360 // Purpose: Rob 26-mar-96
361 //=================================
363 void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPrs,
364 const Handle(Prs3d_Drawer)& aDrawer,
367 const DsgPrs_ArrowSide ArrowPrs)
369 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
370 aPrims->AddVertex(Pt1);
371 aPrims->AddVertex(Pt2);
372 Prs3d_Root::CurrentGroup(aPrs)->AddPrimitiveArray(aPrims);
377 case DsgPrs_AS_LASTAR:
378 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPrs), Pt2, gp_Dir(gp_Vec(Pt1,Pt2)),
379 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
380 aDrawer->DimensionAspect()->ArrowAspect()->Length());
382 case DsgPrs_AS_FIRSTAR:
383 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPrs), Pt1, gp_Dir(gp_Vec(Pt2,Pt1)),
384 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
385 aDrawer->DimensionAspect()->ArrowAspect()->Length());
387 case DsgPrs_AS_BOTHAR:
389 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPrs), Pt2, gp_Dir(V),
390 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
391 aDrawer->DimensionAspect()->ArrowAspect()->Length());
392 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPrs), Pt1, gp_Dir(V.Reversed()),
393 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
394 aDrawer->DimensionAspect()->ArrowAspect()->Length());