0022792: Globally defined symbol PI conflicts with VTK definition (Intel compiler)
[occt.git] / src / DsgPrs / DsgPrs_EqualDistancePresentation.cxx
CommitLineData
7fd59977 1// File: DsgPrs_EqualDistancePresentation.cxx
2// Created: Tue Jan 27 17:05:12 1998
3// Author: Julia GERASIMOVA
4// <jgv@velox.nnov.matra-dtv.fr>
5
6
7#include <DsgPrs_EqualDistancePresentation.ixx>
8
9#include <DsgPrs.hxx>
10#include <Graphic3d_Group.hxx>
11#include <Prs3d_LengthAspect.hxx>
12#include <Prs3d_LineAspect.hxx>
13#include <Graphic3d_Array1OfVertex.hxx>
14#include <Prs3d_Root.hxx>
15#include <gp_Dir.hxx>
16#include <gce_MakeDir.hxx>
17#include <gp_Vec.hxx>
18#include <gp_Pln.hxx>
19#include <Precision.hxx>
20#include <ElCLib.hxx>
21#include <gp_Circ.hxx>
22#include <TCollection_ExtendedString.hxx>
23#include <Prs3d_Text.hxx>
24
25//=================================================================================
26//function : Add
27//=================================================================================
28void DsgPrs_EqualDistancePresentation::Add( const Handle( Prs3d_Presentation )& aPresentation,
29 const Handle( Prs3d_Drawer )& aDrawer,
30 const gp_Pnt& Point1,
31 const gp_Pnt& Point2,
32 const gp_Pnt& Point3,
33 const gp_Pnt& Point4,
34 const Handle( Geom_Plane )& Plane )
35{
36 Handle( Prs3d_LengthAspect ) LA = aDrawer->LengthAspect();
37 Prs3d_Root::CurrentGroup( aPresentation )->SetPrimitivesAspect( LA->LineAspect()->Aspect() );
38
39 Graphic3d_Array1OfVertex VertexArray( 1, 2 );
40 Quantity_Length X,Y,Z;
41
42 // Line between two middles
43 gp_Pnt Middle12( (Point1.XYZ() + Point2.XYZ()) * 0.5 ), Middle34( (Point3.XYZ() + Point4.XYZ()) * 0.5 );
44
45 Middle12.Coord( X, Y, Z );
46 VertexArray( 1 ).SetCoord( X, Y, Z );
47 Middle34.Coord( X, Y, Z );
48 VertexArray( 2 ).SetCoord( X, Y, Z );
49 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( VertexArray );
50
51 // Add presentation of arrows (points)
52 gp_Dir aDir( 0, 0, 1 );
53 DsgPrs::ComputeSymbol(aPresentation, LA,
54 Middle12, Middle34,
55 aDir, aDir,
56 DsgPrs_AS_BOTHPT );
57// ota -- begin --
58 // Two small lines in the middle of this line
59 gp_Pnt Middle( (Middle12.XYZ() + Middle34.XYZ()) * 0.5 ), aTextPos;
60 Standard_Real Dist = Middle12.Distance( Middle34 );
61 Standard_Real SmallDist;
62 gp_Dir LineDir, OrtDir;
63 gp_Vec LineVec, OrtVec;
64
65 if (Dist > Precision::Confusion())
66 {
67 SmallDist = Dist * 0.05; // 1/20.0 part
68 if (SmallDist <= Precision::Confusion())
69 SmallDist = Dist;
70 LineDir = gce_MakeDir( Middle12, Middle34 );
71 OrtDir = Plane->Pln().Axis().Direction() ^ LineDir;
72 LineVec = gp_Vec( LineDir ) * SmallDist;
73 OrtVec = gp_Vec( OrtDir ) * SmallDist;
74
75 aTextPos = Middle.Translated( OrtVec );
76 }
77 else
78 {
79 gp_Vec Vec1( Middle, Point1 );
80
81 if (Vec1.SquareMagnitude() > Precision::Confusion()*Precision::Confusion())
82 {
83 Standard_Real Angle = gp_Vec( Middle, Point1 ).Angle( gp_Vec( Middle, Point3 ) );
84 gp_Pnt MidPnt = Point1.Rotated( Plane->Pln().Axis(), Angle*0.5 );
85 OrtDir = gce_MakeDir( Middle, MidPnt );
86 LineDir = OrtDir ^ Plane->Pln().Axis().Direction();
87
88 Standard_Real Distance = Point1.Distance( Point2 );
89 SmallDist = Distance * 0.05; // 1/20.0
90 if (SmallDist <= Precision::Confusion())
91 SmallDist = Distance;
92
93 OrtVec = gp_Vec( OrtDir ) * SmallDist;
94 LineVec = gp_Vec( LineDir ) * SmallDist;
95 }
96 else
97 {
98 SmallDist = 5.0;
99 OrtVec = gp_Vec( Plane->Pln().XAxis().Direction() ) * SmallDist;
100 LineVec = gp_Vec( Plane->Pln().YAxis().Direction() ) * SmallDist;
101 }
102 aTextPos = Middle.Translated (OrtVec);
103 }
104
105 TCollection_ExtendedString aText("==");
106
107 //Draw the text
108 Prs3d_Text::Draw(aPresentation,LA->TextAspect(), aText, aTextPos);
109}
110
111//==================================================================================
112//function : AddInterval
113//purpose : is used for presentation of interval between two lines or two points,
114// or between one line and one point.
115//==================================================================================
116 void DsgPrs_EqualDistancePresentation::AddInterval(const Handle(Prs3d_Presentation)& aPresentation,
117 const Handle(Prs3d_Drawer)& aDrawer,
118 const gp_Pnt& aPoint1,
119 const gp_Pnt& aPoint2,
120 const gp_Dir& aDirection,
121 const gp_Pnt& aPosition,
122 const DsgPrs_ArrowSide anArrowSide,
123 gp_Pnt& aProj1,
124 gp_Pnt& aProj2)
125{
126 const Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
127//set color
128 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
129
130 gp_Lin L1 (aPoint1,aDirection);
131 gp_Lin L2 (aPoint2,aDirection);
132 aProj1 = ElCLib::Value(ElCLib::Parameter(L1, aPosition),L1);
133 aProj2 = ElCLib::Value(ElCLib::Parameter(L2, aPosition),L2);
134
135 Graphic3d_Array1OfVertex V(1,2);
136
137 Quantity_Length X,Y,Z;
138
139 aProj1.Coord (X, Y, Z);
140 V(1).SetCoord(X, Y, Z);
141
142 aPoint1.Coord(X, Y, Z);
143 V(2).SetCoord(X, Y, Z);
144
145 //add first attached line
146 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
147
148 //add distance interval
149 aProj2.Coord(X, Y, Z);
150 V(2).SetCoord(X, Y, Z);
151 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
152
153
154 //add second attached line
155 aPoint2.Coord(X, Y, Z);
156 V(1).SetCoord(X, Y, Z);
157 Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V);
158
159 //add arrows presentation
160 gp_Dir aDir(aProj2.XYZ() - aProj1.XYZ());
161
162 DsgPrs::ComputeSymbol(aPresentation, LA,
163 aProj1, aProj2,
164 aDir.Reversed(), aDir,
165 anArrowSide);
166}
167
168//========================================================================
169// function : AddIntervalBetweenTwoArcs
170// purpose : is used for presentation of interval between two arcs. One
171// of the arcs can have a zero radius (being a point really)
172//========================================================================
173 void
174 DsgPrs_EqualDistancePresentation::AddIntervalBetweenTwoArcs(const Handle(Prs3d_Presentation)& aPresentation,
175 const Handle(Prs3d_Drawer)& aDrawer,
176 const gp_Circ& aCirc1,
177 const gp_Circ& aCirc2,
178 const gp_Pnt& aPoint1,
179 const gp_Pnt& aPoint2,
180 const gp_Pnt& aPoint3,
181 const gp_Pnt& aPoint4,
182 const DsgPrs_ArrowSide anArrowSide)
183{
184//it seems to set color
185 const Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect();
186 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect());
187 Standard_Real aPar11, aPar12, aPar21, aPar22;
188 if(aCirc1.Radius() > Precision::Confusion()){
189 aPar11 = ElCLib::Parameter (aCirc1, aPoint1);
190 aPar12 = ElCLib::Parameter(aCirc1, aPoint2);
191 }
192 else {
c6541a0c
D
193 aPar11 = M_PI;
194 aPar12 = M_PI;
7fd59977 195 }
196 if (aCirc2.Radius() > Precision::Confusion()){
197 aPar21 = ElCLib::Parameter(aCirc2, aPoint3 );
198 aPar22 = ElCLib::Parameter(aCirc2, aPoint4);
199 }
200 else {
c6541a0c
D
201 aPar21 = M_PI;
202 aPar22 = M_PI;
7fd59977 203 }
204
205 Graphic3d_Array1OfVertex V(1,2);
206 V(1).SetCoord(aPoint2.X(), aPoint2.Y(), aPoint2.Z());
207 V(2).SetCoord(aPoint4.X(), aPoint4.Y(), aPoint4.Z());
208 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( V );
209
210 Standard_Integer aNodeNb;
211 Standard_Real aDelta, aCurPar;
c6541a0c 212 if(aPar12 < aPar11 ) aPar12 +=2*M_PI;
7fd59977 213 if (Abs(aPar12 - aPar11) > Precision::Confusion()) {
c6541a0c 214 aNodeNb = Standard_Integer(Max(Abs(aPar12 - aPar11)*50./M_PI + 0.5, 4.));
7fd59977 215 Graphic3d_Array1OfVertex ApproxArc1( 1, aNodeNb+1);
216 aDelta = (aPar12 - aPar11)/aNodeNb;
217 aCurPar= aPar11;
218 for ( int i = 1; i<= aNodeNb ; aCurPar+= aDelta, i++)
219 {
220 gp_Pnt CurPnt = ElCLib::Value( aCurPar, aCirc1);
221 ApproxArc1(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() );
222 }
223 ApproxArc1(aNodeNb+1).SetCoord( aPoint2.X(), aPoint2.Y(), aPoint2.Z() );
224
225 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc1 );
226 }
c6541a0c 227 if (aPar22 < aPar21) aPar22 += 2*M_PI;
7fd59977 228 if ( Abs(aPar22 - aPar21) > Precision::Confusion()){
c6541a0c 229 aNodeNb = Standard_Integer(Max(Abs(aPar22 - aPar21)*50./M_PI + 0.5, 4.));
7fd59977 230 Graphic3d_Array1OfVertex ApproxArc2( 1, aNodeNb+1);
231 aDelta = (aPar22 - aPar21)/aNodeNb;
232 aCurPar= aPar21;
233 for ( int i=1; i<= aNodeNb; aCurPar+= aDelta, i++)
234 {
235 gp_Pnt CurPnt = ElCLib::Value( aCurPar, aCirc2);
236 ApproxArc2(i).SetCoord( CurPnt.X(), CurPnt.Y(), CurPnt.Z() );
237 }
238 ApproxArc2(aNodeNb+1).SetCoord( aPoint4.X(), aPoint4.Y(), aPoint4.Z() );
239 Prs3d_Root::CurrentGroup( aPresentation )->Polyline( ApproxArc2 );
240 }
241
242 //get the direction of interval
243 gp_Dir DirOfArrow;
244 if(aPoint4.Distance(aPoint2) > Precision::Confusion()){
245 DirOfArrow.SetXYZ(aPoint4.XYZ() - aPoint2.XYZ());
246 }
247 else {
248 //Let's take the radius direction
249 gp_Pnt aCenter = aCirc1.Location();
250 if(aPoint4.Distance(aCenter) < Precision::Confusion())
251 return;
252 DirOfArrow.SetXYZ(aPoint4.XYZ() - aCenter.XYZ());
253 }
254
255 // Add presentation of arrows
256 DsgPrs::ComputeSymbol( aPresentation, LA, aPoint2, aPoint4, DirOfArrow.Reversed(), DirOfArrow, anArrowSide );
257
258}
259//-- ota -- end