0022312: Translation of french commentaries in OCCT files
[occt.git] / src / DsgPrs / DsgPrs_DiameterPresentation.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1996
2// File: DsgPrs_DiameterPresentation.cxx
3// Created: Wed Aug 21 15:36:02 1996
4// Author: Jacques MINOT
5// <jmi>
6// modified 12-january-98
7// Sergey ZARITCHNY
8// <szy@androxx.nnov.matra-dtv.fr>
9// szy
10#include <DsgPrs_DiameterPresentation.ixx>
11
12#include <Prs3d_LineAspect.hxx>
13#include <Prs3d_TextAspect.hxx>
14#include <Prs3d_LengthAspect.hxx>
15#include <Prs3d_Arrow.hxx>
16#include <Prs3d_Text.hxx>
17#include <Prs3d_ArrowAspect.hxx>
18
19#include <Graphic3d_Group.hxx>
20#include <Graphic3d_Array1OfVertex.hxx>
21
22#include <gp_Dir.hxx>
23#include <gp_Pnt.hxx>
24#include <gp_Vec.hxx>
25
26#include <ElCLib.hxx>
27
28#include <Graphic3d_Vertex.hxx>
29#include <Graphic3d_AspectMarker3d.hxx>
30#include <Graphic3d_AspectLine3d.hxx>
31#include <Aspect_TypeOfLine.hxx>
32#include <Aspect_TypeOfMarker.hxx>
33#include <Aspect_AspectMarker.hxx>
34#include <Quantity_Color.hxx>
35#include <DsgPrs.hxx>
36
37//==========================================================================
38// function : DsgPrs_DiameterPresentation::Add
81bba717 39// purpose : it is possible to choose the symbol of extremities of the face (arrow, point ...)
7fd59977 40//==========================================================================
41void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
42 const Handle(Prs3d_Drawer)& aDrawer,
43 const TCollection_ExtendedString& aText,
44 const gp_Pnt& AttachmentPoint,
45 const gp_Circ& aCircle,
46 const DsgPrs_ArrowSide ArrowPrs,
47 const Standard_Boolean IsDiamSymbol )
48{
49
50
51 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
52 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
53
54 Standard_Real parat = ElCLib::Parameter(aCircle, AttachmentPoint);
55 gp_Pnt ptoncirc = ElCLib::Value (parat, aCircle);
56
81bba717 57 // sideline
7fd59977 58
59 gp_Pnt center = aCircle.Location();
60 gp_Vec vecrap (ptoncirc,center);
61
62 Standard_Real dist = center.Distance(AttachmentPoint);
63 Standard_Real aRadius = aCircle.Radius();
64 Standard_Boolean inside = Standard_False;
65
66 gp_Pnt pt1 = AttachmentPoint;
67 if (dist < aRadius) {
68 pt1 = ptoncirc;
69 dist = aRadius;
70 inside = Standard_True;
71 }
72 vecrap.Normalize();
73 vecrap *= (dist+aRadius);
74 gp_Pnt OppositePoint = pt1.Translated(vecrap);
75
76
77 Graphic3d_Array1OfVertex V(1,2);
78 Quantity_Length X,Y,Z;
79 pt1.Coord(X,Y,Z);
80 V(1).SetCoord(X,Y,Z);
81 OppositePoint.Coord(X,Y,Z);
82 V(2).SetCoord(X,Y,Z);
83 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
84
85 // value
86 TCollection_ExtendedString Text = aText;
87 if(IsDiamSymbol)
88 Text = TCollection_ExtendedString("\330 ") + aText; // VRO (2007-05-17) inserted a blank.
89 Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, AttachmentPoint);
90
91 // arrows
92
93 gp_Dir arrdir (vecrap);
94 if (inside) arrdir.Reverse();
95
96
97 gp_Vec vecrap2 = vecrap;
98 gp_Pnt ptoncirc2 = ptoncirc;
99 gp_Dir arrdir2 = arrdir;
100 vecrap2.Normalize();
101 vecrap2 *= (aCircle.Radius() * 2.);
102 ptoncirc2.Translate (vecrap2);
103 arrdir2.Reverse();
104
105 DsgPrs::ComputeSymbol(aPresentation,LA,ptoncirc,ptoncirc2,arrdir,arrdir2,ArrowPrs);
106}
107
108
109static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar,
110 const Standard_Real lpar,
111 const Standard_Real para)
112{
113 if (fpar >= 0.) {
114 if(lpar > fpar)
115 return ((para >= fpar) && (para <= lpar));
116 else { // fpar > lpar
117 Standard_Real delta = 2*PI-fpar;
118 Standard_Real lp, par, fp;
119 lp = lpar + delta;
120 par = para + delta;
121 while(lp > 2*PI) lp-=2*PI;
122 while(par > 2*PI) par-=2*PI;
123 fp = 0.;
124 return ((par >= fp) && (par <= lp));
125 }
126
127 }
128 if (para >= (fpar+2*PI)) return Standard_True;
129 if (para <= lpar) return Standard_True;
130 return Standard_False;
131}
132
133
134//=======================================================================
135//function : DsgPrs_DiameterPresentation::Add
136//purpose : SZY 12-february-98
137//=======================================================================
138
139void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation,
140 const Handle(Prs3d_Drawer)& aDrawer,
141 const TCollection_ExtendedString& aText,
142 const gp_Pnt& AttachmentPoint,
143 const gp_Circ& aCircle,
144 const Standard_Real uFirst,
145 const Standard_Real uLast,
146 const DsgPrs_ArrowSide ArrowPrs,//ArrowSide
147 const Standard_Boolean IsDiamSymbol )
148{
149 Standard_Real fpara = uFirst;
150 Standard_Real lpara = uLast;
151 while (lpara > 2*PI) {
152 fpara -= 2*PI;
153 lpara -= 2*PI;
154 }
155
156 Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
157// Handle(Prs3d_TextAspect) TA = aDrawer->TextAspect();
158 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
159// AspectText3d from Graphic3d
160 Standard_Real parEndOfArrow = ElCLib::Parameter(aCircle,AttachmentPoint); //
161 gp_Pnt EndOfArrow;
81bba717 162 gp_Pnt DrawPosition = AttachmentPoint;// point of attachment
7fd59977 163 Standard_Boolean otherside = Standard_False;
164
165 gp_Pnt Center = aCircle.Location();
166 gp_Pnt FirstPoint = ElCLib::Value(uFirst, aCircle);
167 gp_Pnt SecondPoint = ElCLib::Value(uLast, aCircle);
168
169 if ( !DsgPrs_InDomain(fpara,lpara,parEndOfArrow)) {
170 Standard_Real otherpar = parEndOfArrow + PI;// not in domain
171 if (otherpar > 2*PI) otherpar -= 2*PI;
172 if (DsgPrs_InDomain(fpara,lpara,otherpar)) {
173 parEndOfArrow = otherpar; // parameter on circle
174 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
175 otherside = Standard_True;
176 }
177 else {
178 gp_Dir dir1(gp_Vec(Center, FirstPoint));
179 gp_Dir dir2(gp_Vec(Center, SecondPoint));
180 gp_Lin L1( Center, dir1 );
181 gp_Lin L2( Center, dir2 );
182 if(L1.Distance(AttachmentPoint) < L2.Distance(AttachmentPoint))
183 {
184 EndOfArrow = FirstPoint; //***
185 DrawPosition = ElCLib::Value(ElCLib::Parameter( L1, AttachmentPoint ), L1);
186 }
187 else
188 {
189 EndOfArrow = SecondPoint; //***
190 DrawPosition = ElCLib::Value(ElCLib::Parameter( L2, AttachmentPoint ), L2);
191 }
192 }
193// EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
194// DrawPosition = AttachmentPoint;
195 }
196 else {
197 EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle);
198 DrawPosition = AttachmentPoint;
199 }
200 Graphic3d_Array1OfVertex Vrap(1,2);
201
202 Quantity_Length X,Y,Z;
203
204 DrawPosition.Coord(X,Y,Z);
205 Vrap(1).SetCoord(X,Y,Z);
206
207 EndOfArrow.Coord(X,Y,Z);
208 Vrap(2).SetCoord(X,Y,Z);
209
210 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap);
211
212 // text
213 TCollection_ExtendedString Text = aText;
214 if(IsDiamSymbol)
215 Text = TCollection_ExtendedString("\330 ") + Text;// => \330 | \370?
216 Prs3d_Text::Draw(aPresentation,LA->TextAspect(),Text,DrawPosition);
217
218// Add presentation of arrow
219 gp_Dir DirOfArrow(gp_Vec(DrawPosition, EndOfArrow).XYZ());
220 DsgPrs::ComputeSymbol(aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs);
221
222}