7fd59977 |
1 | #include <Prs2d_ToleranceFrame.ixx> |
2 | #include <Prs2d_Tolerance.hxx> |
3 | #include <Prs2d_Straightness.hxx> |
4 | #include <Prs2d_Flatness.hxx> |
5 | #include <Prs2d_Circularity.hxx> |
6 | #include <Prs2d_Cylindric.hxx> |
7 | #include <Prs2d_LineProfile.hxx> |
8 | #include <Prs2d_SurfProfile.hxx> |
9 | #include <Prs2d_Parallelism.hxx> |
10 | #include <Prs2d_Perpendicular.hxx> |
11 | #include <Prs2d_Angularity.hxx> |
12 | #include <Prs2d_Position.hxx> |
13 | #include <Prs2d_Concentric.hxx> |
14 | #include <Prs2d_Symmetry.hxx> |
15 | #include <Prs2d_SymCircular.hxx> |
16 | #include <Prs2d_SymTotal.hxx> |
17 | #include <Prs2d_Taper.hxx> |
18 | |
19 | Prs2d_ToleranceFrame::Prs2d_ToleranceFrame( const Handle(Graphic2d_GraphicObject)& aGO, |
20 | const Quantity_Length aX, |
21 | const Quantity_Length aY, |
22 | const Quantity_Length aHeight, |
23 | const Prs2d_TypeOfTolerance aTolType, |
24 | const Standard_CString aTolTxt, |
25 | const Standard_CString aTxt1, |
26 | const Standard_CString aTxt2, |
27 | const Standard_Real anAngle, |
28 | const Standard_Real aScale ) |
29 | |
30 | : Graphic2d_Line( aGO ), |
31 | |
32 | myX( Standard_ShortReal( aX ) ), |
33 | myY( Standard_ShortReal( aY ) ), |
34 | myTolTxt( TCollection_ExtendedString(aTolTxt) ), |
35 | myTxt1( TCollection_ExtendedString(aTxt1) ), |
36 | myTxt2( TCollection_ExtendedString(aTxt2) ), |
37 | myHeight( Standard_ShortReal( aHeight ) ), |
38 | myAngle( Standard_ShortReal( anAngle ) ), |
39 | myScale( Standard_ShortReal( aScale ) ), |
40 | myXVert( 1, 4 ), |
41 | myYVert( 1, 4 ) |
42 | |
43 | { |
44 | |
45 | gp_Pnt2d PntP( myX, myY ); |
46 | gp_Vec2d theV1( gp_Pnt2d( myX, myY - myHeight/2 ), PntP ); |
47 | theV1.Rotate( myAngle ); |
48 | theV1.Reverse(); |
49 | gp_Pnt2d Pnt0 = PntP.Translated( theV1 ); |
50 | gp_Vec2d theVecG( Pnt0, gp_Pnt2d( Pnt0.X() + 1.0, Pnt0.Y() ) ); |
51 | theVecG.Rotate( myAngle ); |
52 | gp_Vec2d theVecV = theVecG.Rotated( Standard_PI / 2 ); |
53 | theVecG.Normalize(); |
54 | theVecV.Normalize(); |
55 | |
56 | gp_Pnt2d Pnt1 = Pnt0.Translated( theVecV * myHeight ); |
57 | myXVert(1) = Standard_ShortReal( Pnt0.X() ); |
58 | myYVert(1) = Standard_ShortReal( Pnt0.Y() ); |
59 | myXVert(2) = Standard_ShortReal( Pnt1.X() ); |
60 | myYVert(2) = Standard_ShortReal( Pnt1.Y() ); |
61 | gp_Pnt2d Pnt2 = Pnt0.Translated( theVecG * myHeight ); |
62 | myXVert(4) = Standard_ShortReal( Pnt2.X() ); |
63 | myYVert(4) = Standard_ShortReal( Pnt2.Y() ); |
64 | Pnt2 = Pnt1.Translated( theVecG * myHeight ); |
65 | myXVert(3) = Standard_ShortReal( Pnt2.X() ); |
66 | myYVert(3) = Standard_ShortReal( Pnt2.Y() ); |
67 | |
68 | myMinX = myX; |
69 | myMinY = myY; |
70 | myMaxX = myX; |
71 | myMaxY = myY; |
72 | |
73 | for ( Standard_Integer i = 1; i <= 4; i++ ) { |
74 | if ( myXVert(i) < myMinX ) myMinX = myXVert(i); |
75 | if ( myYVert(i) < myMinY ) myMinY = myYVert(i); |
76 | if ( myXVert(i) > myMaxX ) myMaxX = myXVert(i); |
77 | if ( myYVert(i) > myMaxY ) myMaxY = myYVert(i); |
78 | } |
79 | |
80 | gp_Vec2d VecTol( PntP, gp_Pnt2d( myX + myHeight/2, myY ) ); |
81 | VecTol.Rotate( myAngle ); |
82 | PntP.Translate( VecTol ); |
83 | Standard_Real xTTol = PntP.X(), |
84 | yTTol = PntP.Y(), |
85 | theSz1 = myHeight * 2/5, |
86 | theSz2 = myHeight * 3/5; |
87 | |
88 | switch ( aTolType ) { |
89 | case Prs2d_TOT_TAPER: |
90 | myHTol = new Prs2d_Taper( aGO, xTTol, yTTol, theSz2, myAngle ); |
91 | break; |
92 | case Prs2d_TOT_SYMTOTAL: |
93 | myHTol = new Prs2d_SymTotal( aGO, xTTol, yTTol, theSz2, myAngle ); |
94 | break; |
95 | case Prs2d_TOT_SYMCIRCULAR: |
96 | myHTol = new Prs2d_SymCircular( aGO, xTTol, yTTol, theSz2, myAngle ); |
97 | break; |
98 | case Prs2d_TOT_SYMMETRY: |
99 | myHTol = new Prs2d_Symmetry( aGO, xTTol, yTTol, theSz2, myAngle ); |
100 | break; |
101 | case Prs2d_TOT_CONCENTRIC: |
102 | myHTol = new Prs2d_Concentric( aGO, xTTol, yTTol, theSz2, myAngle ); |
103 | break; |
104 | case Prs2d_TOT_POSITION: |
105 | myHTol = new Prs2d_Position( aGO, xTTol, yTTol, theSz2, myAngle ); |
106 | break; |
107 | case Prs2d_TOT_ANGULARITY: |
108 | myHTol = new Prs2d_Angularity( aGO, xTTol, yTTol, theSz2, myAngle ); |
109 | break; |
110 | case Prs2d_TOT_PERPENDIC: |
111 | myHTol = new Prs2d_Perpendicular( aGO, xTTol, yTTol, theSz2, myAngle ); |
112 | break; |
113 | case Prs2d_TOT_PARALLELISM: |
114 | myHTol = new Prs2d_Parallelism( aGO, xTTol, yTTol, theSz1, myAngle ); |
115 | break; |
116 | case Prs2d_TOT_SURFACEPROF: |
117 | myHTol = new Prs2d_SurfProfile( aGO, xTTol, yTTol, theSz2, myAngle ); |
118 | break; |
119 | case Prs2d_TOT_LINEPROF: |
120 | myHTol = new Prs2d_LineProfile( aGO, xTTol, yTTol, theSz2, myAngle ); |
121 | break; |
122 | case Prs2d_TOT_CYLINDRIC: |
123 | myHTol = new Prs2d_Cylindric( aGO, xTTol, yTTol, theSz1, myAngle ); |
124 | break; |
125 | case Prs2d_TOT_CIRCULARITY: |
126 | myHTol = new Prs2d_Circularity( aGO, xTTol, yTTol, theSz2, myAngle ); |
127 | break; |
128 | case Prs2d_TOT_FLATNESS: |
129 | myHTol = new Prs2d_Flatness( aGO, xTTol, yTTol, theSz1, myAngle ); |
130 | break; |
131 | case Prs2d_TOT_STRAIGHTNESS: |
132 | myHTol = new Prs2d_Straightness( aGO, xTTol, yTTol, theSz2, myAngle ); |
133 | break; |
134 | case Prs2d_TOT_NONE: |
135 | default: |
136 | break; |
137 | |
138 | } |
139 | } |
140 | |
141 | void Prs2d_ToleranceFrame::Draw( const Handle(Graphic2d_Drawer)& aDrawer ) { |
142 | |
143 | Standard_Boolean IsIn = Standard_False; |
144 | |
145 | if ( ! myGOPtr->IsTransformed() ) |
146 | IsIn = aDrawer->IsIn( myMinX, myMaxX, myMinY,myMaxY ); |
147 | else { |
148 | Standard_ShortReal minx, miny, maxx, maxy; |
149 | MinMax(minx,maxx,miny,maxy); |
150 | IsIn = aDrawer->IsIn( minx, maxx, miny, maxy ); |
151 | } |
152 | |
153 | if ( IsIn ) { |
154 | |
155 | DrawLineAttrib( aDrawer ); |
156 | |
157 | gp_GTrsf2d aTrsf; |
158 | Standard_Real a1, b1; |
159 | |
160 | TShort_Array1OfShortReal Xpoint( 1, 4 ), Ypoint( 1, 4 ); |
161 | Xpoint.Assign( myXVert ); |
162 | Ypoint.Assign( myYVert ); |
163 | |
164 | if ( myGOPtr->IsTransformed() ) { |
165 | aTrsf = myGOPtr->Transform (); |
166 | for ( Standard_Integer j = 1; j <= 4; j++ ) { |
167 | a1 = Standard_Real( Xpoint(j) ); |
168 | b1 = Standard_Real( Ypoint(j) ); |
169 | aTrsf.Transforms( a1, b1 ); |
170 | Xpoint(j) = Standard_ShortReal( a1 ); |
171 | Ypoint(j) = Standard_ShortReal( b1 ); |
172 | } |
173 | } |
174 | aDrawer->MapPolygonFromTo( Xpoint, Ypoint ); |
175 | |
176 | //------------additional text's cells |
177 | |
178 | if ( myTolTxt.Length() || myTxt1.Length() || myTxt1.Length() ) { |
179 | gp_Pnt2d PntP( myX, myY ); |
180 | gp_Vec2d theV1( gp_Pnt2d( myX, myY - myHeight/2 ), PntP ); |
181 | theV1.Rotate( myAngle ); |
182 | theV1.Reverse(); |
183 | gp_Pnt2d Pnt0 = PntP.Translated( theV1 ), |
184 | PntT = PntP.Translated( theV1 / 2 ); |
185 | gp_Vec2d theVecT( PntT, gp_Pnt2d( PntT.X() + 1.0, PntT.Y() ) ); |
186 | theVecT.Rotate( myAngle ); |
187 | theVecT.Normalize(); |
188 | gp_Vec2d theVecG( Pnt0, gp_Pnt2d( Pnt0.X() + 1.0, Pnt0.Y() ) ); |
189 | theVecG.Rotate( myAngle ); |
190 | gp_Vec2d theVecV = theVecG.Rotated( Standard_PI / 2 ); |
191 | theVecG.Normalize(); |
192 | theVecV.Normalize(); |
193 | |
194 | gp_Pnt2d Pnt1 = Pnt0.Translated( theVecV * myHeight ); |
195 | gp_Pnt2d Pnt2 = Pnt0.Translated( theVecG * myHeight ); |
196 | |
197 | const Standard_ShortReal offS = Standard_ShortReal( 5 ); |
198 | aDrawer->SetTextAttrib( myColorIndex, 0, 0, Standard_ShortReal(myScale*aDrawer->Scale()), |
199 | Standard_ShortReal(myScale*aDrawer->Scale()), Standard_False ); |
200 | |
201 | Standard_ShortReal tVecSize = myHeight; |
202 | Standard_ShortReal ws = 0.0, hs; |
203 | gp_Pnt2d tmpPntTxt; |
204 | Standard_ShortReal X1=0., Y1=0., X2=0., Y2=0., X3, Y3, X4, Y4; |
205 | if ( myTolTxt.Length() ) { |
206 | tVecSize += offS; |
207 | tmpPntTxt = PntT.Translated( theVecT * tVecSize ); |
208 | X1 = Standard_ShortReal( tmpPntTxt.X() ); |
209 | Y1 = Standard_ShortReal( tmpPntTxt.Y() ); |
210 | if ( myGOPtr->IsTransformed () ) { |
211 | aTrsf = myGOPtr->Transform(); |
212 | a1 = Standard_Real( X1 ); |
213 | b1 = Standard_Real( Y1 ); |
214 | aTrsf.Transforms( a1, b1 ); |
215 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
216 | } |
217 | aDrawer->MapTextFromTo( myTolTxt, X1, Y1, myAngle, 0.0, 0.0, Aspect_TOT_SOLID ); |
218 | aDrawer->GetTextSize( myTolTxt, ws, hs ); |
219 | tVecSize += ws + offS; |
220 | |
221 | Pnt2 = Pnt0.Translated( theVecG * tVecSize ); |
222 | X1 = Standard_ShortReal( Pnt2.X() ); |
223 | Y1 = Standard_ShortReal( Pnt2.Y() ); |
224 | Pnt2 = Pnt1.Translated( theVecG * tVecSize ); |
225 | X2 = Standard_ShortReal( Pnt2.X() ); |
226 | Y2 = Standard_ShortReal( Pnt2.Y() ); |
227 | if ( myGOPtr->IsTransformed () ) { |
228 | aTrsf = myGOPtr->Transform(); |
229 | a1 = Standard_Real( X1 ); |
230 | b1 = Standard_Real( Y1 ); |
231 | aTrsf.Transforms( a1, b1 ); |
232 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
233 | a1 = Standard_Real( X2 ); |
234 | b1 = Standard_Real( Y2 ); |
235 | aTrsf.Transforms( a1, b1 ); |
236 | X2 = Standard_ShortReal( a1 ); Y2 = Standard_ShortReal( b1 ); |
237 | } |
238 | aDrawer->MapSegmentFromTo( X1, Y1, X2, Y2 ); |
239 | } |
240 | |
241 | if ( myTxt1.Length() ) { |
242 | tVecSize += offS; |
243 | tmpPntTxt = PntT.Translated( theVecT * tVecSize ); |
244 | X1 = Standard_ShortReal( tmpPntTxt.X() ); Y1 = Standard_ShortReal( tmpPntTxt.Y() ); |
245 | if ( myGOPtr->IsTransformed () ) { |
246 | aTrsf = myGOPtr->Transform(); |
247 | a1 = Standard_Real( X1 ); |
248 | b1 = Standard_Real( Y1 ); |
249 | aTrsf.Transforms( a1, b1 ); |
250 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
251 | } |
252 | aDrawer->MapTextFromTo( myTxt1, X1, Y1, myAngle, 0., 0.,Aspect_TOT_SOLID ); |
253 | aDrawer->GetTextSize( myTxt1, ws, hs ); |
254 | tVecSize += ws + offS; |
255 | |
256 | Pnt2 = Pnt0.Translated( theVecG * tVecSize ); |
257 | X1 = Standard_ShortReal( Pnt2.X() ); |
258 | Y1 = Standard_ShortReal( Pnt2.Y() ); |
259 | Pnt2 = Pnt1.Translated( theVecG * tVecSize ); |
260 | X2 = Standard_ShortReal( Pnt2.X() ); |
261 | Y2 = Standard_ShortReal( Pnt2.Y() ); |
262 | if ( myGOPtr->IsTransformed () ) { |
263 | aTrsf = myGOPtr->Transform(); |
264 | a1 = Standard_Real( X1 ); |
265 | b1 = Standard_Real( Y1 ); |
266 | aTrsf.Transforms( a1, b1 ); |
267 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
268 | a1 = Standard_Real( X2 ); |
269 | b1 = Standard_Real( Y2 ); |
270 | aTrsf.Transforms( a1, b1 ); |
271 | X2 = Standard_ShortReal( a1 ); Y2 = Standard_ShortReal( b1 ); |
272 | } |
273 | aDrawer->MapSegmentFromTo( X1, Y1, X2, Y2 ); |
274 | } |
275 | |
276 | if ( myTxt2.Length() ) { |
277 | tVecSize += offS; |
278 | tmpPntTxt = PntT.Translated( theVecT * tVecSize ); |
279 | X1 = Standard_ShortReal( tmpPntTxt.X() ); Y1 = Standard_ShortReal( tmpPntTxt.Y() ); |
280 | if ( myGOPtr->IsTransformed () ) { |
281 | aTrsf = myGOPtr->Transform(); |
282 | a1 = Standard_Real( X1 ); |
283 | b1 = Standard_Real( Y1 ); |
284 | aTrsf.Transforms( a1, b1 ); |
285 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
286 | } |
287 | aDrawer->MapTextFromTo( myTxt2, X1, Y1, myAngle, 0., 0., Aspect_TOT_SOLID ); |
288 | aDrawer->GetTextSize( myTxt2, ws, hs ); |
289 | tVecSize += ws + offS; |
290 | |
291 | Pnt2 = Pnt0.Translated( theVecG * tVecSize ); |
292 | X1 = Standard_ShortReal( Pnt2.X() ); |
293 | Y1 = Standard_ShortReal( Pnt2.Y() ); |
294 | Pnt2 = Pnt1.Translated( theVecG * tVecSize ); |
295 | X2 = Standard_ShortReal( Pnt2.X() ); |
296 | Y2 = Standard_ShortReal( Pnt2.Y() ); |
297 | if ( myGOPtr->IsTransformed () ) { |
298 | aTrsf = myGOPtr->Transform(); |
299 | a1 = Standard_Real( X1 ); |
300 | b1 = Standard_Real( Y1 ); |
301 | aTrsf.Transforms( a1, b1 ); |
302 | X1 = Standard_ShortReal( a1 ); Y1 = Standard_ShortReal( b1 ); |
303 | a1 = Standard_Real( X2 ); |
304 | b1 = Standard_Real( Y2 ); |
305 | aTrsf.Transforms( a1, b1 ); |
306 | X2 = Standard_ShortReal( a1 ); Y2 = Standard_ShortReal( b1 ); |
307 | } |
308 | aDrawer->MapSegmentFromTo( X1, Y1, X2, Y2 ); |
309 | } |
310 | |
311 | X3 = Standard_ShortReal( Pnt0.X() ); |
312 | Y3 = Standard_ShortReal( Pnt0.Y() ); |
313 | X4 = Standard_ShortReal( Pnt1.X() ); |
314 | Y4 = Standard_ShortReal( Pnt1.Y() ); |
315 | if ( myGOPtr->IsTransformed () ) { |
316 | aTrsf = myGOPtr->Transform(); |
317 | a1 = Standard_Real( X3 ); |
318 | b1 = Standard_Real( Y3 ); |
319 | aTrsf.Transforms( a1, b1 ); |
320 | X3 = Standard_ShortReal( a1 ); Y3 = Standard_ShortReal( b1 ); |
321 | a1 = Standard_Real( X4 ); |
322 | b1 = Standard_Real( Y4 ); |
323 | aTrsf.Transforms( a1, b1 ); |
324 | X4 = Standard_ShortReal( a1 ); Y4 = Standard_ShortReal( b1 ); |
325 | } |
326 | aDrawer->MapSegmentFromTo( X1, Y1, X3, Y3 ); |
327 | aDrawer->MapSegmentFromTo( X2, Y2, X4, Y4 ); |
328 | |
329 | } // end if one of text strings isn't empty |
330 | } // end if IsIn |
331 | |
332 | if ( ! myHTol.IsNull() ) |
333 | myHTol->Draw( aDrawer ); |
334 | |
335 | } |
336 | |
337 | Standard_Boolean Prs2d_ToleranceFrame::Pick( |
338 | const Standard_ShortReal X, |
339 | const Standard_ShortReal Y, |
340 | const Standard_ShortReal aPrecision, |
341 | const Handle(Graphic2d_Drawer)& /*aDrawer*/ ) { |
342 | if ( IsInMinMax( X, Y, aPrecision ) ) |
343 | return Standard_True; |
344 | return Standard_False; |
345 | } |
346 | |
347 | void Prs2d_ToleranceFrame::SetHeight( const Standard_Real aHSize ) { |
348 | |
349 | myHeight = Standard_ShortReal( aHSize ); |
350 | } |
351 | |
352 | Standard_Real Prs2d_ToleranceFrame::Height() const { |
353 | |
354 | return myHeight; |
355 | } |
356 | |
357 | void Prs2d_ToleranceFrame::Save(Aspect_FStream& aFStream) const |
358 | { |
359 | } |
360 | |
361 | const Handle(TColgp_HArray1OfPnt2d) Prs2d_ToleranceFrame::ArrayOfPnt2d( ) const |
362 | { |
363 | Handle(TColgp_HArray1OfPnt2d) points = new TColgp_HArray1OfPnt2d( 1, 4 ); |
364 | |
365 | for ( Standard_Integer i = 1; i <= 4; i++ ) |
366 | { |
367 | points->SetValue( i, gp_Pnt2d( myXVert(i), myYVert(i) ) ); |
368 | } |
369 | return points; |
370 | } |
371 | |
372 | void Prs2d_ToleranceFrame::SetTolText( const Standard_CString aTolTxt ) |
373 | { |
374 | myTolTxt = TCollection_ExtendedString(aTolTxt); |
375 | } |
376 | |
377 | void Prs2d_ToleranceFrame::SetText1( const Standard_CString aTxt1 ) |
378 | { |
379 | myTxt1 = TCollection_ExtendedString(aTxt1); |
380 | } |
381 | |
382 | void Prs2d_ToleranceFrame::SetText2( const Standard_CString aTxt2 ) |
383 | { |
384 | myTxt2 = TCollection_ExtendedString(aTxt2); |
385 | } |
386 | |
387 | TCollection_ExtendedString Prs2d_ToleranceFrame::TolText( ) const |
388 | { |
389 | return myTolTxt; |
390 | } |
391 | |
392 | TCollection_ExtendedString Prs2d_ToleranceFrame::Text1() const |
393 | { |
394 | return myTxt1; |
395 | } |
396 | |
397 | TCollection_ExtendedString Prs2d_ToleranceFrame::Text2() const |
398 | { |
399 | return myTxt2; |
400 | } |
401 | |
402 | Standard_Real Prs2d_ToleranceFrame::TextScale( ) const |
403 | { |
404 | return myScale; |
405 | } |