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.ixx>
19 #include <gce_MakeLin.hxx>
20 #include <Graphic3d_Group.hxx>
21 #include <Graphic3d_ArrayOfSegments.hxx>
22 #include <Graphic3d_ArrayOfPolylines.hxx>
23 #include <Prs3d_Root.hxx>
24 #include <Prs3d_Arrow.hxx>
25 #include <Prs3d_ArrowAspect.hxx>
26 #include <Prs3d_LineAspect.hxx>
27 #include <Prs3d_DimensionAspect.hxx>
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>
40 #include <Geom_Curve.hxx>
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)
51 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
52 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
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);
58 gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2);
59 Standard_Real parmin,parmax,parcur;
60 parmin = ElCLib::Parameter(L3,Proj1);
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);
69 Standard_Boolean outside = Standard_False;
70 if (parcur < parmin) {
72 outside = Standard_True;
74 if (parcur > parmax) {
76 outside = Standard_True;
79 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
80 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
82 // face processing : 1st group
83 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
84 aPrims->AddVertex(PointMin);
85 aPrims->AddVertex(PointMax);
87 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
88 outside = Standard_True;
90 gp_Dir arrdir = L3.Direction().Reversed();
94 // arrow 1 : 2nd group
95 Prs3d_Arrow::Draw(aPresentation,Proj1,arrdir, LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
97 Prs3d_Root::NewGroup(aPresentation);
98 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
100 // arrow 2 : 3rd group
101 Prs3d_Arrow::Draw(aPresentation,Proj2,arrdir.Reversed(), LA->ArrowAspect()->Angle(), LA->ArrowAspect()->Length());
103 Prs3d_Root::NewGroup(aPresentation);
106 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
108 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
110 // processing of call 1 : 5th group
111 aPrims->AddVertex(AttachmentPoint1);
112 aPrims->AddVertex(Proj1);
114 // processing of call 2 : 6th group
115 aPrims->AddVertex(AttachmentPoint2);
116 aPrims->AddVertex(Proj2);
118 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
121 //==================================================================================
123 //purpose : Adds presentation of length dimension between two planar faces
124 //==================================================================================
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 )
136 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
137 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
139 gp_Pnt EndOfArrow1, EndOfArrow2;
142 DsgPrs::ComputePlanarFacesLengthPresentation( LA->ArrowAspect()->Length(),
143 LA->ArrowAspect()->Length(),
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;
158 if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0))
160 FirstPoint = OffsetPoint;
161 LastPoint = (Abs( Par1 ) > Abs( Par2 ))? EndOfArrow1 : EndOfArrow2;
165 FirstPoint = EndOfArrow1;
166 LastPoint = EndOfArrow2;
169 // Creating the length's line
170 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
172 aPrims->AddVertex(FirstPoint);
173 aPrims->AddVertex(LastPoint);
175 // Add presentation of arrows
176 DsgPrs::ComputeSymbol( aPresentation, LA, EndOfArrow1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs );
179 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint );
181 // Line from AttachmentPoint1 to end of Arrow1
182 aPrims->AddVertex(AttachmentPoint1);
183 aPrims->AddVertex(EndOfArrow1);
185 // Line from AttachmentPoint2 to end of Arrow2
186 aPrims->AddVertex(AttachmentPoint2);
187 aPrims->AddVertex(EndOfArrow2);
189 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
193 //=========================================================================================
195 //purpose : adds presentation of length between two edges, vertex and edge or two vertices
196 //=========================================================================================
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)
207 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
208 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
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);
214 gp_Lin L3 = Proj1.IsEqual(Proj2,Precision::Confusion())? gp_Lin(Proj1,aDirection) : gce_MakeLin(Proj1,Proj2);
215 Standard_Real parmin,parmax,parcur;
216 parmin = ElCLib::Parameter(L3,Proj1);
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);
225 Standard_Boolean outside = Standard_False;
226 if (parcur < parmin) {
228 outside = Standard_True;
230 if (parcur > parmax) {
232 outside = Standard_True;
235 gp_Pnt PointMin = ElCLib::Value(parmin,L3);
236 gp_Pnt PointMax = ElCLib::Value(parmax,L3);
238 // processing of face
239 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(6);
241 aPrims->AddVertex(PointMin);
242 aPrims->AddVertex(PointMax);
244 if (dist < (LA->ArrowAspect()->Length()+LA->ArrowAspect()->Length()))
245 outside = Standard_True;
247 gp_Dir arrdir = L3.Direction().Reversed();
251 // processing of call 1
252 aPrims->AddVertex(AttachmentPoint1);
253 aPrims->AddVertex(Proj1);
255 // processing of call 2
256 aPrims->AddVertex(AttachmentPoint2);
257 aPrims->AddVertex(Proj2);
259 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
262 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),aText,offp);
264 // symbols at the extremities of the face
265 DsgPrs::ComputeSymbol(aPresentation,LA,Proj1,Proj2,arrdir,arrdir.Reversed(),ArrowPrs);
269 //==================================================================================
271 //purpose : Adds presentation of length dimension between two curvilinear faces
272 //==================================================================================
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 )
284 Handle(Prs3d_DimensionAspect) LA = aDrawer->DimensionAspect();
285 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
289 Handle( Geom_Curve ) VCurve, UCurve;
290 Standard_Real FirstU, deltaU = 0.0e0, FirstV, deltaV = 0.0e0;
292 DsgPrs::ComputeCurvilinearFacesLengthPresentation( LA->ArrowAspect()->Length(),
293 LA->ArrowAspect()->Length(),
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;
309 if ((Par1 > 0.0 && Par2 > 0.0) || (Par1 < 0.0 && Par2 < 0.0))
311 FirstPoint = OffsetPoint;
312 LastPoint = (Abs( Par1 ) > Abs( Par2 ))? AttachmentPoint1 : EndOfArrow2;
316 FirstPoint = AttachmentPoint1;
317 LastPoint = EndOfArrow2;
320 // Creating the length's line
321 Handle(Graphic3d_ArrayOfPrimitives) aPrims = new Graphic3d_ArrayOfSegments(2);
322 aPrims->AddVertex(FirstPoint);
323 aPrims->AddVertex(LastPoint);
324 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
326 // Add presentation of arrows
327 DsgPrs::ComputeSymbol( aPresentation, LA, AttachmentPoint1, EndOfArrow2, DirOfArrow1, DirOfArrow1.Reversed(), ArrowPrs );
330 Prs3d_Text::Draw( aPresentation, LA->TextAspect(), aText, OffsetPoint );
332 // Two curves from end of Arrow2 to AttachmentPoint2
333 Standard_Real Alpha, delta;
334 Standard_Integer NodeNumber;
336 Alpha = Abs( deltaU );
337 if (Alpha > Precision::Angular() && Alpha<Precision::Infinite())
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);
346 Alpha = Abs( deltaV );
347 if (Alpha > Precision::Angular() && Alpha<Precision::Infinite())
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);
359 //================================
361 // Purpose: Rob 26-mar-96
362 //=================================
364 void DsgPrs_LengthPresentation::Add (const Handle(Prs3d_Presentation)& aPrs,
365 const Handle(Prs3d_Drawer)& aDrawer,
368 const DsgPrs_ArrowSide ArrowPrs)
370 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2);
371 aPrims->AddVertex(Pt1);
372 aPrims->AddVertex(Pt2);
373 Prs3d_Root::CurrentGroup(aPrs)->AddPrimitiveArray(aPrims);
378 case DsgPrs_AS_LASTAR:
379 Prs3d_Arrow::Draw(aPrs,Pt2,gp_Dir(gp_Vec(Pt1,Pt2)),
380 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
381 aDrawer->DimensionAspect()->ArrowAspect()->Length());
383 case DsgPrs_AS_FIRSTAR:
384 Prs3d_Arrow::Draw(aPrs,Pt1,gp_Dir(gp_Vec(Pt2,Pt1)),
385 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
386 aDrawer->DimensionAspect()->ArrowAspect()->Length());
388 case DsgPrs_AS_BOTHAR:
390 Prs3d_Arrow::Draw(aPrs,Pt2,gp_Dir(V),
391 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
392 aDrawer->DimensionAspect()->ArrowAspect()->Length());
393 Prs3d_Arrow::Draw(aPrs,Pt1,gp_Dir(V.Reversed()),
394 aDrawer->DimensionAspect()->ArrowAspect()->Angle(),
395 aDrawer->DimensionAspect()->ArrowAspect()->Length());