Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1993-11-22 |
2 | // Created by: Stephane CALLEGARI | |
3 | // Copyright (c) 1993-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | #define xTRACE |
22 | ||
7fd59977 | 23 | // Modified 23/02/98 : FMN ; Remplacement PI par Standard_PI |
24 | // Modified 16/03/98 GG | |
25 | // OPTIMISATION | |
81bba717 | 26 | // Add fields myWDriver and myPDriver initializing correctly |
27 | // when the driver is "WindowDriver" or "plotterdriver". | |
28 | // Avoid call of empty contructors. | |
7fd59977 | 29 | |
30 | #define CTS17857//GG_200897 | |
81bba717 | 31 | // Allow suppressing clipping on primitives. |
7fd59977 | 32 | |
33 | #define CSR_PRO12324 //SYL_030798 | |
81bba717 | 34 | // the Plot of an objet should be a normal |
7fd59977 | 35 | |
36 | #define DCB_220798 // DCB | |
37 | // Using pointers to drivers instead of handles | |
38 | // Reason : to avoid undesirable incrementation | |
39 | // of handle's links. | |
40 | ||
41 | // Modified 17/12/1998 SYL pour S3604 | |
42 | // Aspect_PlotterDriver devient PlotMgt_PlotterDriver | |
43 | ||
44 | #define BUC60650 //GG 010300 Add protection on scale parameters | |
45 | // in SetxxxxTextAttrib() methods | |
46 | ||
47 | #define OCC402 //SAV added method to map merkers operating with arrays | |
48 | ||
49 | #include <Graphic2d_Drawer.ixx> | |
50 | #include <Graphic2d_Primitive.pxx> | |
51 | #include <Standard_Type.hxx> | |
52 | #include <Aspect_Units.hxx> | |
53 | #include <Precision.hxx> | |
54 | ||
55 | #define MAXPOINTS 1023 | |
56 | ||
57 | #ifdef WNT | |
58 | # include <WNT_DDriver.hxx> | |
59 | #endif // WNT | |
60 | ||
61 | Graphic2d_Drawer::Graphic2d_Drawer () { | |
62 | ||
63 | myOverride = Standard_False; | |
64 | #ifdef DCB_220798 | |
65 | myDriver = NULL; | |
66 | myWDriver = NULL; | |
67 | myPDriver = NULL; | |
68 | #else // DCB_220798 | |
69 | myDriver.Nullify(); | |
70 | myWDriver.Nullify(); | |
71 | myPDriver.Nullify(); | |
72 | #endif // DCB_220798 | |
73 | myDriverIsDefined = Standard_False; | |
74 | myMinMaxIsActivated = Standard_False; | |
75 | myClippingIsActivated = Standard_True; | |
76 | myMinX = myMinY = ShortRealLast(); | |
77 | myMaxX = myMaxY = ShortRealFirst(); | |
78 | ||
79 | myDrawPrecision = 0.; | |
80 | myDeflectionCoefficient = 0.; | |
81 | myTypeOfDeflection = Aspect_TOD_RELATIVE; | |
82 | myTextPrecision = 0.; | |
83 | ||
84 | myOverrideColor = 0; | |
85 | ||
86 | myOffSet = 0; | |
87 | ||
88 | mySpaceWidth = 1. METER; | |
89 | mySpaceHeight = 1. METER; | |
90 | ||
91 | SetValues (0., 0., 1. METER, 0., 0., 1., 1.); | |
92 | ||
93 | } | |
94 | ||
95 | void Graphic2d_Drawer::SetDrawPrecision(const Standard_Real aPrecision, | |
96 | const Standard_Real aCoefficient, | |
97 | const Aspect_TypeOfDeflection aType) { | |
98 | ||
99 | myDrawPrecision = Standard_ShortReal(aPrecision); | |
100 | myDeflectionCoefficient = aCoefficient; | |
101 | myTypeOfDeflection = aType; | |
102 | ||
103 | } | |
104 | ||
105 | void Graphic2d_Drawer::DrawPrecision(Standard_ShortReal& aPrecision, | |
106 | Standard_ShortReal& aCoefficient, | |
107 | Aspect_TypeOfDeflection& aType) const { | |
108 | ||
109 | aPrecision = myDrawPrecision; | |
110 | aCoefficient = Standard_ShortReal(myDeflectionCoefficient); | |
111 | aType = myTypeOfDeflection; | |
112 | ||
113 | } | |
114 | ||
115 | void Graphic2d_Drawer::SetTextPrecision(const Standard_ShortReal aPrecision) { | |
116 | ||
117 | myTextPrecision = aPrecision; | |
118 | ||
119 | } | |
120 | ||
121 | Standard_ShortReal Graphic2d_Drawer::TextPrecision() const { | |
122 | ||
123 | return myTextPrecision; | |
124 | ||
125 | } | |
126 | ||
127 | void Graphic2d_Drawer::SetDriver(const Handle(Aspect_Driver)& aDriver) { | |
128 | ||
129 | Standard_Real w,h; | |
130 | ||
131 | #ifdef DCB_220798 | |
132 | myDriver = aDriver.operator->(); | |
133 | if( aDriver->IsKind(STANDARD_TYPE(Aspect_WindowDriver)) ) { | |
134 | myWDriver = (Handle(Aspect_WindowDriver)::DownCast(aDriver)).operator->(); | |
135 | myPDriver = NULL; | |
136 | } else { | |
137 | myWDriver = NULL; | |
138 | myPDriver = (Handle(PlotMgt_PlotterDriver)::DownCast(aDriver)).operator->(); | |
139 | } | |
140 | #else // DCB_220798 | |
141 | myDriver = aDriver; | |
142 | myWDriver = Handle(Aspect_WindowDriver)::DownCast(aDriver); | |
143 | myPDriver = Handle(PlotMgt_PlotterDriver)::DownCast(aDriver); | |
144 | #endif // DCB_220798 | |
145 | myDriverIsDefined = Standard_True; | |
146 | myDriver->WorkSpace(w,h); | |
147 | mySpaceWidth = Standard_ShortReal(w); | |
148 | mySpaceHeight = Standard_ShortReal(h); | |
149 | #ifdef TRACE | |
150 | cout << "Graphic2d_Drawer::SetDriver() -> IsWindowDriver ? " | |
151 | << (myWDriver ? "TRUE " : "FALSE ") << flush; | |
152 | cout << "Graphic2d_Drawer::SetDriver() -> myDriverIsDefined: " | |
153 | << (myDriverIsDefined ? "TRUE " : "FALSE ") | |
154 | << (int)myDriverIsDefined << endl << flush; | |
155 | cout << "Graphic2d_Drawer::SetDriver() -> Space: " | |
156 | << mySpaceWidth << " x " << mySpaceHeight << endl << flush; | |
157 | #endif | |
158 | ||
159 | } | |
160 | ||
161 | Handle(Aspect_Driver) Graphic2d_Drawer::Driver() const { | |
162 | ||
163 | // if (! myDriverIsDefined ) | |
164 | // Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
165 | ||
166 | return myDriver; | |
167 | ||
168 | } | |
169 | ||
170 | Standard_Boolean Graphic2d_Drawer::IsWindowDriver() const { | |
171 | ||
172 | #ifdef DCB_220798 | |
173 | return (myWDriver) ? Standard_True : Standard_False; | |
174 | #else | |
175 | return (myWDriver.IsNull()) ? Standard_False : Standard_True; | |
176 | #endif | |
177 | } | |
178 | ||
179 | Standard_Boolean Graphic2d_Drawer::IsPlotterDriver() const { | |
180 | ||
181 | #ifdef DCB_220798 | |
182 | return (myPDriver) ? Standard_True : Standard_False; | |
183 | #else | |
184 | return (myPDriver.IsNull()) ? Standard_False : Standard_True; | |
185 | #endif | |
186 | } | |
187 | ||
188 | Handle(Aspect_WindowDriver) Graphic2d_Drawer::WindowDriver() const { | |
189 | ||
190 | return myWDriver; | |
191 | } | |
192 | ||
193 | Handle(PlotMgt_PlotterDriver) Graphic2d_Drawer::PlotterDriver() const { | |
194 | ||
195 | return myPDriver; | |
196 | } | |
197 | ||
198 | void Graphic2d_Drawer::SetValues (const Standard_Real XF, | |
199 | const Standard_Real YF, | |
200 | const Standard_Real SF, | |
201 | const Standard_Real XT, | |
202 | const Standard_Real YT, | |
203 | const Standard_Real ST, | |
204 | const Standard_Real ZF){ | |
205 | ||
206 | myXF = Standard_ShortReal(XF); | |
207 | myYF = Standard_ShortReal(YF); | |
208 | mySF = Standard_ShortReal(SF>Precision::Confusion()?SF:Precision::Confusion()); | |
209 | myXT = Standard_ShortReal(XT); | |
210 | myYT = Standard_ShortReal(YT); | |
211 | myST = Standard_ShortReal(ST>Precision::Confusion()?ST:Precision::Confusion()); | |
212 | myZF = Standard_ShortReal(ZF); | |
213 | ||
214 | } | |
215 | ||
216 | void Graphic2d_Drawer::Values(Standard_ShortReal& XF, | |
217 | Standard_ShortReal& YF, | |
218 | Standard_ShortReal& SF, | |
219 | Standard_ShortReal& XT, | |
220 | Standard_ShortReal& YT, | |
221 | Standard_ShortReal& ST, | |
222 | Standard_ShortReal& ZF) const { | |
223 | ||
224 | XF = myXF; | |
225 | YF = myYF; | |
226 | SF = mySF; | |
227 | XT = myXT; | |
228 | YT = myYT; | |
229 | ST = myST; | |
230 | ZF = myZF; | |
231 | ||
232 | } | |
233 | ||
234 | void Graphic2d_Drawer::SetOverride(const Standard_Boolean aValue) { | |
235 | ||
236 | myOverride = aValue; | |
237 | ||
238 | } | |
239 | ||
240 | void Graphic2d_Drawer::SetOverrideColor(const Standard_Integer anIndex) { | |
241 | ||
242 | myOverrideColor = anIndex; | |
243 | ||
244 | } | |
245 | ||
246 | void Graphic2d_Drawer::SetOffSet(const Standard_Integer anOffSet) { | |
247 | ||
248 | myOffSet = anOffSet; | |
249 | ||
250 | } | |
251 | ||
252 | void Graphic2d_Drawer::GetMapFrom(const Standard_ShortReal x1, | |
253 | const Standard_ShortReal y1, | |
254 | Standard_ShortReal& x2, | |
255 | Standard_ShortReal& y2) const { | |
256 | ||
257 | x2 = (x1-myXF)/mySF; | |
258 | y2 = (y1-myYF)/mySF; | |
259 | ||
260 | } | |
261 | ||
262 | void Graphic2d_Drawer::GetMapFromTo(const Standard_ShortReal x1, | |
263 | const Standard_ShortReal y1, | |
264 | Standard_ShortReal& x2, | |
265 | Standard_ShortReal& y2) const { | |
266 | ||
267 | x2 = myXT + ((x1-myXF)/mySF) *myST; | |
268 | y2 = myYT + ((y1-myYF)/mySF) *myST; | |
269 | ||
270 | } | |
271 | ||
272 | Standard_Boolean Graphic2d_Drawer::GetTextSize( | |
273 | const TCollection_ExtendedString &aText, | |
274 | Standard_ShortReal &aWidth, | |
275 | Standard_ShortReal &aHeight) const { | |
276 | ||
277 | if( IsWindowDriver() ) { | |
278 | myWDriver->TextSize(aText,aWidth,aHeight); | |
279 | aWidth /= Scale(); | |
280 | aHeight /= Scale(); | |
281 | return Standard_True; | |
282 | #ifdef WNT | |
283 | } else | |
284 | if ( myDriver -> IsKind ( STANDARD_TYPE( WNT_DDriver ) ) ) { | |
285 | ||
286 | Handle( WNT_DDriver ) :: DownCast ( myDriver ) -> TextSize ( aText, aWidth, aHeight ); | |
287 | aWidth /= Scale (); | |
288 | aHeight /= Scale (); | |
289 | return Standard_True; | |
290 | #endif // WNT | |
291 | } else { | |
292 | aWidth = aHeight = 0.; | |
293 | return Standard_False; | |
294 | } // end else | |
295 | } | |
296 | ||
297 | Standard_Boolean Graphic2d_Drawer::GetTextSize( | |
298 | const TCollection_ExtendedString &aText, | |
299 | Standard_ShortReal &aWidth, | |
300 | Standard_ShortReal &aHeight, | |
301 | Standard_ShortReal &anXoffset, | |
302 | Standard_ShortReal &anYoffset) const { | |
303 | ||
304 | if( IsWindowDriver() ) { | |
305 | myWDriver->TextSize(aText,aWidth,aHeight,anXoffset,anYoffset); | |
306 | aWidth /= Scale(); | |
307 | aHeight /= Scale(); | |
308 | anXoffset /= Scale(); | |
309 | anYoffset /= Scale(); | |
310 | return Standard_True; | |
311 | #ifdef WNT | |
312 | } else | |
313 | if ( myDriver -> IsKind ( STANDARD_TYPE( WNT_DDriver ) ) ) { | |
314 | ||
315 | Handle( WNT_DDriver ) :: DownCast ( myDriver ) -> TextSize ( aText, aWidth, aHeight ); | |
316 | aWidth /= Scale (); | |
317 | aHeight /= Scale (); | |
318 | return Standard_True; | |
319 | #endif // WNT | |
320 | } else { | |
321 | aWidth = aHeight = anXoffset = anYoffset = 0.; | |
322 | return Standard_False; | |
323 | } // end else | |
324 | } | |
325 | ||
326 | Standard_Boolean Graphic2d_Drawer::GetFontSize( | |
327 | Standard_ShortReal &aHeight, | |
328 | Standard_ShortReal &aBheight, | |
329 | Standard_ShortReal &aSlant) const { | |
330 | ||
331 | if( IsWindowDriver() ) { | |
332 | Quantity_PlaneAngle slant; | |
333 | myWDriver->FontSize(slant,aHeight,aBheight); | |
334 | aHeight /= Scale(); | |
335 | aBheight /= Scale(); | |
336 | aSlant = Standard_ShortReal(slant); | |
337 | return Standard_True; | |
338 | } else { | |
339 | aHeight = aBheight = aSlant = 0.; | |
340 | return Standard_False; | |
341 | } | |
342 | } | |
343 | ||
344 | Standard_Boolean Graphic2d_Drawer::GetImageSize( | |
345 | const Standard_CString aFileName, | |
346 | Standard_ShortReal &aWidth, | |
347 | Standard_ShortReal &aHeight) const { | |
348 | ||
349 | Standard_Boolean theStatus = Standard_False; | |
350 | Standard_Integer width,height; | |
351 | ||
352 | if( myDriverIsDefined ) { | |
353 | if(( theStatus = myDriver->SizeOfImageFile(aFileName,width,height))){ | |
354 | aWidth = Standard_ShortReal(myDriver->Convert(width)/Scale()); | |
355 | aHeight = Standard_ShortReal(myDriver->Convert(height)/Scale()); | |
356 | } | |
357 | } | |
358 | ||
359 | if( !theStatus ) { | |
360 | aWidth = aHeight = 0.; | |
361 | } | |
362 | return theStatus; | |
363 | } | |
364 | ||
365 | Standard_Boolean Graphic2d_Drawer::GetImageSize( | |
366 | const Standard_CString aFileName, | |
367 | Standard_Integer &aWidth, | |
368 | Standard_Integer &aHeight) const { | |
369 | Standard_Boolean theStatus = Standard_False; | |
370 | ||
371 | if( myDriverIsDefined ) { | |
372 | theStatus = myDriver->SizeOfImageFile(aFileName,aWidth,aHeight); | |
373 | } | |
374 | ||
375 | if( !theStatus ) { | |
376 | aWidth = aHeight = 0; | |
377 | } | |
378 | return theStatus; | |
379 | } | |
380 | ||
381 | void Graphic2d_Drawer::MapSegmentFromTo ( | |
382 | const Standard_ShortReal x1, | |
383 | const Standard_ShortReal y1, | |
384 | const Standard_ShortReal x2, | |
385 | const Standard_ShortReal y2, | |
386 | const Standard_Integer aMode) { | |
387 | ||
388 | if (! myDriverIsDefined) | |
389 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
390 | ||
391 | Standard_ShortReal mx1,my1,mx2,my2; | |
392 | mx1 = myXT + ((x1-myXF)/mySF) *myST; | |
393 | my1 = myYT + ((y1-myYF)/mySF) *myST; | |
394 | mx2 = myXT + ((x2-myXF)/mySF) *myST; | |
395 | my2 = myYT + ((y2-myYF)/mySF) *myST; | |
396 | ||
397 | if( aMode > 0 ) myDriver->BeginSegments(); | |
398 | myDriver->DrawSegment(mx1,my1,mx2,my2); | |
399 | if( aMode < 0 ) myDriver->ClosePrimitive(); | |
400 | if( myMinMaxIsActivated ) { | |
401 | myMinX = Min(mx1,myMinX); myMinX = Min(mx2,myMinX); | |
402 | myMinY = Min(my1,myMinY); myMinY = Min(my2,myMinY); | |
403 | myMaxX = Max(mx1,myMaxX); myMaxX = Max(mx2,myMaxX); | |
404 | myMaxY = Max(my1,myMaxY); myMaxY = Max(my2,myMaxY); | |
405 | } | |
406 | ||
407 | } | |
408 | ||
409 | void Graphic2d_Drawer::DrawSegment ( | |
410 | const Standard_ShortReal x1, | |
411 | const Standard_ShortReal y1, | |
412 | const Standard_ShortReal x2, | |
413 | const Standard_ShortReal y2) { | |
414 | ||
415 | if (! myDriverIsDefined) | |
416 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
417 | ||
418 | myDriver->DrawSegment(x1,y1,x2,y2); | |
419 | if( myMinMaxIsActivated ) { | |
420 | myMinX = Min(x1,myMinX); myMinX = Min(x2,myMinX); | |
421 | myMinY = Min(y1,myMinY); myMinY = Min(y2,myMinY); | |
422 | myMaxX = Max(x1,myMaxX); myMaxX = Max(x2,myMaxX); | |
423 | myMaxY = Max(y1,myMaxY); myMaxY = Max(y2,myMaxY); | |
424 | } | |
425 | } | |
426 | ||
427 | void Graphic2d_Drawer::DrawText( | |
428 | const TCollection_ExtendedString& aText, | |
429 | const Standard_ShortReal x, | |
430 | const Standard_ShortReal y, | |
431 | const Standard_ShortReal anAngle, | |
432 | const Aspect_TypeOfText aType) { | |
433 | ||
434 | if (! myDriverIsDefined) | |
435 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
436 | ||
437 | Standard_ShortReal mx = x,my = y; | |
438 | ||
439 | myDriver->DrawText(aText,mx,my,anAngle,aType); | |
440 | ||
441 | if( myMinMaxIsActivated && IsWindowDriver() ) { | |
442 | Standard_ShortReal width,height,xoffset,yoffset; | |
443 | myWDriver->TextSize(aText,width,height,xoffset,yoffset); | |
444 | if( width > 0. && height > 0. ) { | |
445 | Standard_ShortReal x1,y1,x2,y2,x3,y3,x4,y4; | |
446 | ||
447 | if ( !anAngle ) { | |
448 | Standard_ShortReal cosa = Standard_ShortReal(Cos(anAngle)); | |
449 | Standard_ShortReal sina = Standard_ShortReal(Sin(anAngle)); | |
450 | ||
451 | x1 = mx + XROTATE(xoffset,-yoffset) ; | |
452 | y1 = my + YROTATE(xoffset,-yoffset) ; | |
453 | ||
454 | x2 = mx + XROTATE(xoffset,height-yoffset) ; | |
455 | y2 = my + YROTATE(xoffset,height-yoffset) ; | |
456 | ||
457 | x3 = mx + XROTATE(width+xoffset,height-yoffset) ; | |
458 | y3 = my + YROTATE(width+xoffset,height-yoffset) ; | |
459 | ||
460 | x4 = mx + XROTATE(width+xoffset,-yoffset) ; | |
461 | y4 = my + YROTATE(width+xoffset,-yoffset) ; | |
462 | ||
463 | } else { | |
464 | x1 = mx+xoffset; y1 = my-yoffset; | |
465 | x2 = mx+xoffset; y2 = my+height-yoffset; | |
466 | x3 = mx+width+xoffset; y3 = my+height-yoffset; | |
467 | x4 = mx+width+xoffset; y4 = my-yoffset; | |
468 | } | |
469 | myMinX = Min(x1,myMinX); myMinY = Min(y1,myMinY); | |
470 | myMaxX = Max(x1,myMaxX); myMaxY = Max(y1,myMaxY); | |
471 | myMinX = Min(x2,myMinX); myMinY = Min(y2,myMinY); | |
472 | myMaxX = Max(x2,myMaxX); myMaxY = Max(y2,myMaxY); | |
473 | myMinX = Min(x3,myMinX); myMinY = Min(y3,myMinY); | |
474 | myMaxX = Max(x3,myMaxX); myMaxY = Max(y3,myMaxY); | |
475 | myMinX = Min(x4,myMinX); myMinY = Min(y4,myMinY); | |
476 | myMaxX = Max(x4,myMaxX); myMaxY = Max(y4,myMaxY); | |
477 | } | |
478 | } | |
479 | } | |
480 | ||
481 | void Graphic2d_Drawer::MapTextFromTo( | |
482 | const TCollection_ExtendedString& aText, | |
483 | const Standard_ShortReal x, | |
484 | const Standard_ShortReal y, | |
485 | const Standard_ShortReal anAngle, | |
486 | const Standard_ShortReal aDeltax, | |
487 | const Standard_ShortReal aDeltay, | |
488 | const Aspect_TypeOfText aType) { | |
489 | ||
490 | if (! myDriverIsDefined) | |
491 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
492 | ||
493 | Standard_ShortReal mx,my; | |
494 | mx = myXT + aDeltax + ((x-myXF)/mySF) *myST; | |
495 | my = myYT + aDeltay + ((y-myYF)/mySF) *myST; | |
496 | DrawText(aText,mx,my,anAngle,aType); | |
497 | } | |
498 | ||
499 | void Graphic2d_Drawer::DrawPolyText( | |
500 | const TCollection_ExtendedString& aText, | |
501 | const Standard_ShortReal x, | |
502 | const Standard_ShortReal y, | |
503 | const Standard_ShortReal anAngle, | |
504 | const Standard_ShortReal aMargin, | |
505 | const Aspect_TypeOfText aType) { | |
506 | ||
507 | if (! myDriverIsDefined) | |
508 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
509 | ||
510 | Standard_ShortReal mx = x,my = y; | |
511 | myDriver->DrawPolyText(aText,mx,my,aMargin,anAngle,aType); | |
512 | ||
513 | if( myMinMaxIsActivated && IsWindowDriver() ) { | |
514 | Standard_ShortReal width,height,xoffset,yoffset; | |
515 | myWDriver->TextSize(aText,width,height,xoffset,yoffset); | |
516 | if( width > 0. && height > 0. ) { | |
517 | Standard_ShortReal x1,y1,x2,y2,x3,y3,x4,y4,dxm,dym; | |
518 | dxm = dym = height*aMargin; | |
519 | ||
520 | if( !anAngle ) { | |
521 | Standard_ShortReal cosa = Standard_ShortReal(Cos(anAngle)); | |
522 | Standard_ShortReal sina = Standard_ShortReal(Sin(anAngle)); | |
523 | ||
524 | x1 = mx + XROTATE(-dxm+xoffset,-dym-yoffset) ; | |
525 | y1 = my + YROTATE(-dxm+xoffset,-dym-yoffset) ; | |
526 | ||
527 | x2 = mx + XROTATE(-dxm+xoffset,height+dym-yoffset) ; | |
528 | y2 = my + YROTATE(-dxm+xoffset,height+dym-yoffset) ; | |
529 | ||
530 | x3 = mx + XROTATE(width+dxm+xoffset,height+dym-yoffset) ; | |
531 | y3 = my + YROTATE(width+dxm+xoffset,height+dym-yoffset) ; | |
532 | ||
533 | x4 = mx + XROTATE(width+dxm+xoffset,-dym-yoffset) ; | |
534 | y4 = my + YROTATE(width+dxm+xoffset,-dym-yoffset) ; | |
535 | ||
536 | } else { | |
537 | x1 = mx-dxm+xoffset; y1 = my-dym-yoffset; | |
538 | x2 = mx-dxm+xoffset; y2 = my+height+dym-yoffset; | |
539 | x3 = mx+width+dxm+xoffset; y3 = my+height+dym-yoffset; | |
540 | x4 = mx+width+dxm+xoffset; y4 = my-dym-yoffset; | |
541 | } | |
542 | myMinX = Min(x1,myMinX); myMinY = Min(y1,myMinY); | |
543 | myMaxX = Max(x1,myMaxX); myMaxY = Max(y1,myMaxY); | |
544 | myMinX = Min(x2,myMinX); myMinY = Min(y2,myMinY); | |
545 | myMaxX = Max(x2,myMaxX); myMaxY = Max(y2,myMaxY); | |
546 | myMinX = Min(x3,myMinX); myMinY = Min(y3,myMinY); | |
547 | myMaxX = Max(x3,myMaxX); myMaxY = Max(y3,myMaxY); | |
548 | myMinX = Min(x4,myMinX); myMinY = Min(y4,myMinY); | |
549 | myMaxX = Max(x4,myMaxX); myMaxY = Max(y4,myMaxY); | |
550 | } | |
551 | } | |
552 | } | |
553 | ||
554 | void Graphic2d_Drawer::MapPolyTextFromTo( | |
555 | const TCollection_ExtendedString& aText, | |
556 | const Standard_ShortReal x, | |
557 | const Standard_ShortReal y, | |
558 | const Standard_ShortReal anAngle, | |
559 | const Standard_ShortReal aMargin, | |
560 | const Standard_ShortReal aDeltax, | |
561 | const Standard_ShortReal aDeltay, | |
562 | const Aspect_TypeOfText aType) { | |
563 | ||
564 | if (! myDriverIsDefined) | |
565 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
566 | ||
567 | Standard_ShortReal mx,my; | |
568 | mx = myXT + aDeltax + ((x-myXF)/mySF) *myST; | |
569 | my = myYT + aDeltay + ((y-myYF)/mySF) *myST; | |
570 | DrawPolyText(aText,mx,my,anAngle,aMargin,aType); | |
571 | } | |
572 | ||
573 | void Graphic2d_Drawer::DrawFramedText( | |
574 | const TCollection_ExtendedString& aText, | |
575 | const Standard_ShortReal x, | |
576 | const Standard_ShortReal y, | |
577 | const Standard_ShortReal anAngle, | |
578 | const Standard_ShortReal aMargin, | |
579 | const Aspect_TypeOfText aType) { | |
580 | ||
581 | DrawPolyText(aText,x,y,anAngle,aMargin,aType); | |
582 | } | |
583 | ||
584 | ||
585 | void Graphic2d_Drawer::MapFramedTextFromTo( | |
586 | const TCollection_ExtendedString& aText, | |
587 | const Standard_ShortReal x, | |
588 | const Standard_ShortReal y, | |
589 | const Standard_ShortReal anAngle, | |
590 | const Standard_ShortReal aMargin, | |
591 | const Standard_ShortReal aDeltax, | |
592 | const Standard_ShortReal aDeltay, | |
593 | const Aspect_TypeOfText aType) { | |
594 | ||
595 | if (! myDriverIsDefined) | |
596 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
597 | ||
598 | Standard_ShortReal mx,my; | |
599 | mx = myXT + aDeltax + ((x-myXF)/mySF) *myST; | |
600 | my = myYT + aDeltay + ((y-myYF)/mySF) *myST; | |
601 | DrawFramedText(aText,mx,my,anAngle,aMargin,aType); | |
602 | } | |
603 | ||
604 | void Graphic2d_Drawer::UnMapFromTo (const Standard_ShortReal x1, | |
605 | const Standard_ShortReal y1, | |
606 | Standard_ShortReal& x2, | |
607 | Standard_ShortReal& y2) const { | |
608 | ||
609 | x2 = ((x1-myXT) /myST) *mySF + myXF; | |
610 | y2 = ((y1-myYT) /myST) *mySF + myYF; | |
611 | ||
612 | } | |
613 | ||
614 | void Graphic2d_Drawer::DrawPolyline ( | |
615 | const Standard_Real aDeltaX, | |
616 | const Standard_Real aDeltaY, | |
617 | const TShort_Array1OfShortReal& aListX, | |
618 | const TShort_Array1OfShortReal& aListY) { | |
619 | ||
620 | if (! myDriverIsDefined) | |
621 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
622 | ||
623 | Standard_Integer n1 = aListX.Lower(); | |
624 | Standard_Integer n2 = aListX.Upper(); | |
625 | Standard_ShortReal X,Y; | |
626 | ||
627 | myDriver->BeginPolyline(n2-n1+1); | |
628 | for (Standard_Integer i=n1 ; i<=n2; i++) { | |
629 | X = Standard_ShortReal(aDeltaX) + Standard_ShortReal(aListX(i)); | |
630 | Y = Standard_ShortReal(aDeltaY) + Standard_ShortReal(aListY(i)); | |
631 | myDriver->DrawPoint(X,Y); | |
632 | if( myMinMaxIsActivated ) { | |
633 | myMinX = Min(X,myMinX); | |
634 | myMinY = Min(Y,myMinY); | |
635 | myMaxX = Max(X,myMaxX); | |
636 | myMaxY = Max(Y,myMaxY); | |
637 | } | |
638 | } | |
639 | myDriver->ClosePrimitive(); | |
640 | ||
641 | } | |
642 | ||
643 | void Graphic2d_Drawer::MapPolylineFromTo ( | |
644 | const TShort_Array1OfShortReal& aListX, | |
645 | const TShort_Array1OfShortReal& aListY, | |
646 | const Standard_Integer Npoint) { | |
647 | ||
648 | if (! myDriverIsDefined) | |
649 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
650 | ||
651 | Standard_Integer n1 = aListX.Lower(); | |
652 | Standard_Integer n2 = (Npoint > 0) ? n1+Npoint-1 : aListX.Upper(); | |
653 | Standard_ShortReal X,Y; | |
654 | ||
655 | myDriver->BeginPolyline(n2-n1+1); | |
656 | for (Standard_Integer i=n1 ; i<=n2; i++) { | |
657 | X = myXT + ((aListX(i)-myXF)/mySF) *myST; | |
658 | Y = myYT + ((aListY(i)-myYF)/mySF) *myST; | |
659 | myDriver->DrawPoint(X,Y); | |
660 | if( myMinMaxIsActivated ) { | |
661 | myMinX = Min(X,myMinX); | |
662 | myMinY = Min(Y,myMinY); | |
663 | myMaxX = Max(X,myMaxX); | |
664 | myMaxY = Max(Y,myMaxY); | |
665 | } | |
666 | } | |
667 | myDriver->ClosePrimitive(); | |
668 | ||
669 | } | |
670 | ||
671 | void Graphic2d_Drawer::MapPolylineFromTo ( | |
672 | const Standard_ShortReal x, | |
673 | const Standard_ShortReal y, | |
674 | const Standard_Integer aMode) { | |
675 | ||
676 | if (! myDriverIsDefined) | |
677 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
678 | ||
679 | Standard_ShortReal X,Y; | |
680 | X = myXT + ((x-myXF)/mySF) *myST; | |
681 | Y = myYT + ((y-myYF)/mySF) *myST; | |
682 | ||
683 | if( aMode > 0 ) myDriver->BeginPolyline(aMode); | |
684 | myDriver->DrawPoint(X,Y); | |
685 | if( myMinMaxIsActivated ) { | |
686 | myMinX = Min(X,myMinX); | |
687 | myMinY = Min(Y,myMinY); | |
688 | myMaxX = Max(X,myMaxX); | |
689 | myMaxY = Max(Y,myMaxY); | |
690 | } | |
691 | if( aMode < 0 ) myDriver->ClosePrimitive(); | |
692 | } | |
693 | ||
694 | void Graphic2d_Drawer::DrawMarker( | |
695 | const Standard_Integer anindex, | |
696 | const Standard_ShortReal x, | |
697 | const Standard_ShortReal y, | |
698 | const Standard_ShortReal awidth, | |
699 | const Standard_ShortReal anheight, | |
700 | const Standard_ShortReal anAngle) { | |
701 | if (! myDriverIsDefined) | |
702 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
703 | ||
704 | Standard_ShortReal mx = x,my = y; | |
705 | ||
706 | if( anindex > 0 && awidth > 0. && anheight > 0. ) { | |
707 | myDriver->DrawMarker(anindex,mx,my,awidth,anheight,anAngle); | |
708 | if( myMinMaxIsActivated ) { | |
709 | Standard_ShortReal d = Standard_ShortReal(Sqrt(awidth*awidth + anheight*anheight)); | |
710 | myMinX = Min(mx-d,myMinX); | |
711 | myMinY = Min(my-d,myMinY); | |
712 | myMaxX = Max(mx+d,myMaxX); | |
713 | myMaxY = Max(my+d,myMaxY); | |
714 | } | |
715 | } else { | |
716 | myDriver->DrawPoint(mx,my); | |
717 | if( myMinMaxIsActivated ) { | |
718 | myMinX = Min(mx,myMinX); | |
719 | myMinY = Min(my,myMinY); | |
720 | myMaxX = Max(mx,myMaxX); | |
721 | myMaxY = Max(my,myMaxY); | |
722 | } | |
723 | } | |
724 | } | |
725 | ||
726 | void Graphic2d_Drawer::MapMarkerFromTo( | |
727 | const Standard_Integer anindex, | |
728 | const Standard_ShortReal x, | |
729 | const Standard_ShortReal y, | |
730 | const Standard_ShortReal awidth, | |
731 | const Standard_ShortReal anheight, | |
732 | const Standard_ShortReal anAngle, | |
733 | const Standard_Integer aMode) { | |
734 | if (! myDriverIsDefined) | |
735 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
736 | ||
737 | Standard_ShortReal mx,my; | |
738 | mx = myXT + ((x-myXF)/mySF) *myST; | |
739 | my = myYT + ((y-myYF)/mySF) *myST; | |
740 | ||
741 | if( anindex > 0 && awidth > 0. && anheight > 0. ) { | |
742 | if( aMode > 0 ) myDriver->BeginMarkers(); | |
743 | myDriver->DrawMarker(anindex,mx,my,awidth,anheight,anAngle); | |
744 | if( myMinMaxIsActivated ) { | |
745 | Standard_ShortReal d = Standard_ShortReal(Sqrt(awidth*awidth + anheight*anheight)); | |
746 | myMinX = Min(mx-d,myMinX); | |
747 | myMinY = Min(my-d,myMinY); | |
748 | myMaxX = Max(mx+d,myMaxX); | |
749 | myMaxY = Max(my+d,myMaxY); | |
750 | } | |
751 | } else { | |
752 | if( aMode > 0 ) myDriver->BeginPoints(); | |
753 | myDriver->DrawPoint(mx,my); | |
754 | if( myMinMaxIsActivated ) { | |
755 | myMinX = Min(mx,myMinX); | |
756 | myMinY = Min(my,myMinY); | |
757 | myMaxX = Max(mx,myMaxX); | |
758 | myMaxY = Max(my,myMaxY); | |
759 | } | |
760 | } | |
761 | if( aMode < 0 ) myDriver->ClosePrimitive(); | |
762 | ||
763 | } | |
764 | ||
765 | void Graphic2d_Drawer | |
766 | ::MapMarkersFromTo( const Standard_Integer anindex, | |
767 | const Handle(TShort_HArray1OfShortReal)& x, | |
768 | const Handle(TShort_HArray1OfShortReal)& y, | |
769 | const Standard_ShortReal awidth, | |
770 | const Standard_ShortReal anheight, | |
771 | const Standard_ShortReal anAngle, | |
772 | const Standard_Integer aMode) | |
773 | { | |
774 | #ifdef OCC402 | |
775 | ||
776 | if (! myDriverIsDefined) | |
777 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
778 | ||
779 | if( anindex > 0 && awidth > 0. && anheight > 0. ) { | |
780 | ||
781 | Standard_ShortReal mx,my; | |
782 | myDriver->BeginMarkers(); | |
783 | ||
784 | for ( Standard_Integer i = x->Lower(); i <= x->Upper(); i++ ) { | |
785 | mx = myXT + ( ( x->Value( i ) - myXF ) / mySF ) * myST; | |
786 | my = myYT + ( ( y->Value( i ) - myYF ) / mySF ) * myST; | |
787 | myDriver->DrawMarker(anindex,mx,my,awidth,anheight,anAngle); | |
788 | } | |
789 | myDriver->ClosePrimitive(); | |
790 | } | |
791 | #endif | |
792 | } | |
793 | ||
794 | void Graphic2d_Drawer::DrawPolygon ( | |
795 | const Standard_Real aDeltaX, | |
796 | const Standard_Real aDeltaY, | |
797 | const TShort_Array1OfShortReal& aListX, | |
798 | const TShort_Array1OfShortReal& aListY) { | |
799 | ||
800 | if (! myDriverIsDefined) | |
801 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
802 | ||
803 | Standard_Integer n1 = aListX.Lower(); | |
804 | Standard_Integer n2 = aListX.Upper(); | |
805 | Standard_ShortReal X,Y; | |
806 | ||
807 | myDriver->BeginPolygon(n2-n1+1); | |
808 | for (Standard_Integer i=n1 ; i<=n2; i++) { | |
809 | X = Standard_ShortReal(aDeltaX) + Standard_ShortReal(aListX(i)); | |
810 | Y = Standard_ShortReal(aDeltaY) + Standard_ShortReal(aListY(i)); | |
811 | myDriver->DrawPoint(X,Y); | |
812 | if( myMinMaxIsActivated ) { | |
813 | myMinX = Min(X,myMinX); | |
814 | myMinY = Min(Y,myMinY); | |
815 | myMaxX = Max(X,myMaxX); | |
816 | myMaxY = Max(Y,myMaxY); | |
817 | } | |
818 | } | |
819 | myDriver->ClosePrimitive(); | |
820 | ||
821 | } | |
822 | ||
823 | void Graphic2d_Drawer::MapPolygonFromTo ( | |
824 | const TShort_Array1OfShortReal& aListX, | |
825 | const TShort_Array1OfShortReal& aListY, | |
826 | const Standard_Integer Npoint) { | |
827 | ||
828 | if (! myDriverIsDefined) | |
829 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
830 | ||
831 | Standard_Integer n1 = aListX.Lower(); | |
832 | Standard_Integer n2 = (Npoint > 0) ? n1+Npoint-1 : aListX.Upper(); | |
833 | Standard_ShortReal X,Y; | |
834 | ||
835 | myDriver->BeginPolygon(n2-n1+1); | |
836 | for (Standard_Integer i=n1 ; i<=n2; i++) { | |
837 | X = myXT + ((aListX(i)-myXF)/mySF) *myST; | |
838 | Y = myYT + ((aListY(i)-myYF)/mySF) *myST; | |
839 | myDriver->DrawPoint(X,Y); | |
840 | if( myMinMaxIsActivated ) { | |
841 | myMinX = Min(X,myMinX); | |
842 | myMinY = Min(Y,myMinY); | |
843 | myMaxX = Max(X,myMaxX); | |
844 | myMaxY = Max(Y,myMaxY); | |
845 | } | |
846 | } | |
847 | myDriver->ClosePrimitive(); | |
848 | ||
849 | } | |
850 | ||
851 | void Graphic2d_Drawer::MapPolygonFromTo ( | |
852 | const Standard_ShortReal x, | |
853 | const Standard_ShortReal y, | |
854 | const Standard_Integer aMode) { | |
855 | ||
856 | if (! myDriverIsDefined) | |
857 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
858 | ||
859 | Standard_ShortReal X,Y; | |
860 | X = myXT + ((x-myXF)/mySF) *myST; | |
861 | Y = myYT + ((y-myYF)/mySF) *myST; | |
862 | ||
863 | if( aMode > 0 ) myDriver->BeginPolygon(aMode); | |
864 | myDriver->DrawPoint(X,Y); | |
865 | if( myMinMaxIsActivated ) { | |
866 | myMinX = Min(X,myMinX); | |
867 | myMinY = Min(Y,myMinY); | |
868 | myMaxX = Max(X,myMaxX); | |
869 | myMaxY = Max(Y,myMaxY); | |
870 | } | |
871 | if( aMode < 0 ) myDriver->ClosePrimitive(); | |
872 | ||
873 | } | |
874 | ||
875 | void Graphic2d_Drawer::DrawArc( | |
876 | const Standard_Real aDeltaX, | |
877 | const Standard_Real aDeltaY, | |
878 | const Standard_ShortReal aRadius, | |
879 | const Standard_ShortReal Angle1, | |
880 | const Standard_ShortReal Angle2) { | |
881 | if (! myDriverIsDefined) | |
882 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
883 | ||
884 | Standard_ShortReal mx,my,a1,a2,da; | |
885 | mx = Standard_ShortReal(aDeltaX); | |
886 | my = Standard_ShortReal(aDeltaY); | |
c6541a0c D |
887 | a1 = (Angle1 >= 0.) ? Angle1 : Angle1 + Standard_ShortReal(2. * M_PI); |
888 | a2 = (Angle2 >= 0.) ? Angle2 : Angle2 + Standard_ShortReal(2. * M_PI); | |
7fd59977 | 889 | if( a2 > a1 ) { |
890 | da = a2 - a1; | |
891 | } else if( a2 < a1 ) { | |
c6541a0c | 892 | da = Standard_ShortReal(2. * M_PI + a2 - a1); |
7fd59977 | 893 | } else { |
c6541a0c | 894 | a1 = 0.; da = Standard_ShortReal(2. * M_PI); |
7fd59977 | 895 | } |
896 | ||
897 | if( aRadius > 0. ) { // Try to use hardware first | |
898 | Standard_Boolean status = | |
899 | myDriver->DrawArc(mx,my,aRadius,aRadius,a1,da); | |
900 | if( !status ) { // or Emulate | |
901 | Standard_ShortReal precis = myDrawPrecision; | |
902 | Standard_ShortReal value; | |
903 | if( myTypeOfDeflection == Aspect_TOD_RELATIVE) { | |
904 | precis = Standard_ShortReal(aRadius * myDeflectionCoefficient); | |
905 | } | |
906 | if( aRadius > precis ) | |
907 | value = Standard_ShortReal(Max( 0.0044, Min (0.7854 , 2. * ACos(1.-precis/aRadius)))); | |
908 | else | |
909 | value = Standard_ShortReal(0.7854); // = PI/4. | |
910 | Standard_Integer nbpoints = Min(MAXPOINTS, | |
911 | Standard_Integer(Abs(da)/value)+2); | |
912 | Standard_ShortReal teta = da/nbpoints; | |
913 | Standard_ShortReal cosin = Standard_ShortReal(Cos(teta)); | |
914 | Standard_ShortReal x1 = Standard_ShortReal(aRadius * Cos(a1)); | |
915 | Standard_ShortReal y1 = Standard_ShortReal(aRadius * Sin(a1)); | |
916 | Standard_ShortReal x2 = Standard_ShortReal(aRadius * Cos(a1+teta)); | |
917 | Standard_ShortReal y2 = Standard_ShortReal(aRadius * Sin(a1+teta)); | |
918 | Standard_ShortReal x,y; | |
919 | ||
920 | nbpoints++; | |
921 | myDriver->BeginPolyline(nbpoints); | |
922 | myDriver->DrawPoint(mx+x1,my+y1); | |
923 | myDriver->DrawPoint(mx+x2,my+y2); | |
924 | for (Standard_Integer i=3; i<= nbpoints; i++) { | |
925 | x = 2*x2*cosin - x1; x1 = x2; x2 = x; | |
926 | y = 2*y2*cosin - y1; y1 = y2; y2 = y; | |
927 | myDriver->DrawPoint(mx+x,my+y); | |
928 | } | |
929 | myDriver->ClosePrimitive(); | |
930 | } | |
931 | if( myMinMaxIsActivated ) { | |
932 | myMinX = Min(mx-aRadius,myMinX); | |
933 | myMinY = Min(my-aRadius,myMinY); | |
934 | myMaxX = Max(mx+aRadius,myMaxX); | |
935 | myMaxY = Max(my+aRadius,myMaxY); | |
936 | } | |
937 | } | |
938 | } | |
939 | ||
940 | void Graphic2d_Drawer::MapArcFromTo( | |
941 | const Standard_ShortReal x, | |
942 | const Standard_ShortReal y, | |
943 | const Standard_ShortReal aRadius, | |
944 | const Standard_ShortReal Angle1, | |
945 | const Standard_ShortReal Angle2, | |
946 | const Standard_Integer aMode) { | |
947 | if (! myDriverIsDefined) | |
948 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
949 | ||
950 | Standard_ShortReal mx,my,r; | |
951 | mx = myXT + ((x-myXF)/mySF) *myST; | |
952 | my = myYT + ((y-myYF)/mySF) *myST; | |
953 | r = aRadius/mySF*myST; | |
954 | ||
955 | if( aRadius > 0. ) { | |
956 | DrawArc(mx,my,r,Angle1,Angle2); | |
957 | if( myMinMaxIsActivated ) { | |
958 | myMinX = Min(mx-aRadius,myMinX); | |
959 | myMinY = Min(my-aRadius,myMinY); | |
960 | myMaxX = Max(mx+aRadius,myMaxX); | |
961 | myMaxY = Max(my+aRadius,myMaxY); | |
962 | } | |
963 | } | |
964 | } | |
965 | ||
966 | void Graphic2d_Drawer::DrawPolyArc( | |
967 | const Standard_Real aDeltaX, | |
968 | const Standard_Real aDeltaY, | |
969 | const Standard_ShortReal aRadius, | |
970 | const Standard_ShortReal Angle1, | |
971 | const Standard_ShortReal Angle2) { | |
972 | if (! myDriverIsDefined) | |
973 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
974 | ||
975 | Standard_ShortReal mx,my,a1,a2,da; | |
976 | mx = Standard_ShortReal(aDeltaX); | |
977 | my = Standard_ShortReal(aDeltaY); | |
c6541a0c D |
978 | a1 = (Angle1 >= 0.) ? Angle1 : Angle1 + Standard_ShortReal(2. * M_PI); |
979 | a2 = (Angle2 >= 0.) ? Angle2 : Angle2 + Standard_ShortReal(2. * M_PI); | |
7fd59977 | 980 | if( a2 > a1 ) { |
981 | da = a2 - a1; | |
982 | } else if( a2 < a1 ) { | |
c6541a0c | 983 | da = Standard_ShortReal(2. * M_PI + a2 - a1); |
7fd59977 | 984 | } else { |
c6541a0c | 985 | a1 = 0.; da = Standard_ShortReal(2. * M_PI); |
7fd59977 | 986 | } |
987 | ||
988 | if( aRadius > 0. ) { // Try to use hardware first | |
989 | Standard_Boolean status = | |
990 | myDriver->DrawPolyArc(mx,my,aRadius,aRadius,a1,da); | |
991 | if( !status ) { // or Emulate | |
992 | Standard_ShortReal precis = myDrawPrecision; | |
993 | Standard_ShortReal value; | |
994 | if( myTypeOfDeflection == Aspect_TOD_RELATIVE) { | |
995 | precis = Standard_ShortReal(aRadius * myDeflectionCoefficient); | |
996 | } | |
997 | if( aRadius > precis ) | |
998 | value = Standard_ShortReal(Max( 0.0044, Min (0.7854 , 2. * ACos(1.-precis/aRadius)))); | |
999 | else | |
1000 | value = Standard_ShortReal(0.7854); // = PI/4. | |
1001 | Standard_Integer nbpoints = Min(MAXPOINTS, | |
1002 | Standard_Integer(Abs(da)/value)+2); | |
1003 | Standard_ShortReal teta = da/nbpoints; | |
1004 | Standard_ShortReal cosin = Standard_ShortReal(Cos(teta)); | |
1005 | Standard_ShortReal x1 = Standard_ShortReal(aRadius * Cos(a1)); | |
1006 | Standard_ShortReal y1 = Standard_ShortReal(aRadius * Sin(a1)); | |
1007 | Standard_ShortReal x2 = Standard_ShortReal(aRadius * Cos(a1+teta)); | |
1008 | Standard_ShortReal y2 = Standard_ShortReal(aRadius * Sin(a1+teta)); | |
1009 | Standard_ShortReal x,y; | |
1010 | ||
1011 | nbpoints++; | |
1012 | myDriver->BeginPolygon(nbpoints); | |
1013 | myDriver->DrawPoint(mx+x1,my+y1); | |
1014 | myDriver->DrawPoint(mx+x2,my+y2); | |
1015 | for (Standard_Integer i=3; i<= nbpoints; i++) { | |
1016 | x = 2*x2*cosin - x1; x1 = x2; x2 = x; | |
1017 | y = 2*y2*cosin - y1; y1 = y2; y2 = y; | |
1018 | myDriver->DrawPoint(mx+x,my+y); | |
1019 | } | |
1020 | myDriver->ClosePrimitive(); | |
1021 | } | |
1022 | if( myMinMaxIsActivated ) { | |
1023 | myMinX = Min(mx-aRadius,myMinX); | |
1024 | myMinY = Min(my-aRadius,myMinY); | |
1025 | myMaxX = Max(mx+aRadius,myMaxX); | |
1026 | myMaxY = Max(my+aRadius,myMaxY); | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | ||
1031 | void Graphic2d_Drawer::MapPolyArcFromTo( | |
1032 | const Standard_ShortReal x, | |
1033 | const Standard_ShortReal y, | |
1034 | const Standard_ShortReal aRadius, | |
1035 | const Standard_ShortReal Angle1, | |
1036 | const Standard_ShortReal Angle2, | |
1037 | const Standard_Integer aMode) { | |
1038 | if (! myDriverIsDefined) | |
1039 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1040 | ||
1041 | Standard_ShortReal mx,my,r; | |
1042 | mx = myXT + ((x-myXF)/mySF) *myST; | |
1043 | my = myYT + ((y-myYF)/mySF) *myST; | |
1044 | r = aRadius/mySF*myST; | |
1045 | ||
1046 | if( aRadius > 0. ) { | |
1047 | DrawPolyArc(mx,my,r,Angle1,Angle2); | |
1048 | if( myMinMaxIsActivated ) { | |
1049 | myMinX = Min(mx-aRadius,myMinX); | |
1050 | myMinY = Min(my-aRadius,myMinY); | |
1051 | myMaxX = Max(mx+aRadius,myMaxX); | |
1052 | myMaxY = Max(my+aRadius,myMaxY); | |
1053 | } | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | void Graphic2d_Drawer::SetRejection( const Standard_Boolean aClippingFlag) { | |
1058 | myClippingIsActivated = aClippingFlag; | |
1059 | } | |
1060 | ||
1061 | Standard_Boolean Graphic2d_Drawer::IsIn( | |
1062 | const Standard_ShortReal aMinX, | |
1063 | const Standard_ShortReal aMaxX, | |
1064 | const Standard_ShortReal aMinY, | |
1065 | const Standard_ShortReal aMaxY)const | |
1066 | { | |
1067 | #ifdef CTS17857 | |
1068 | if( !myClippingIsActivated ) return Standard_True; | |
1069 | #endif | |
1070 | ||
1071 | Standard_ShortReal x,X,y,Y; | |
1072 | ||
1073 | x = myXT + ((aMinX-myXF)/mySF) *myST; | |
1074 | y = myYT + ((aMinY-myYF)/mySF) *myST; | |
1075 | X = myXT + ((aMaxX-myXF)/mySF) *myST; | |
1076 | Y = myYT + ((aMaxY-myYF)/mySF) *myST; | |
1077 | ||
1078 | Standard_Boolean clip = ((x < 0. && X < 0.) || | |
1079 | (x > mySpaceWidth && X > mySpaceWidth) || | |
1080 | (y < 0. && Y < 0.) || | |
1081 | (y > mySpaceHeight && Y > mySpaceHeight)); | |
1082 | ||
1083 | #ifdef TRACE | |
1084 | if( clip ) printf(" *Rejected primitive %f,%f,%f,%f\n", | |
1085 | aMinX,aMinY,aMaxX,aMaxY); | |
1086 | #endif | |
1087 | ||
1088 | return !clip; | |
1089 | } | |
1090 | ||
1091 | void Graphic2d_Drawer::DrawInfiniteLine ( | |
1092 | const Standard_ShortReal x, | |
1093 | const Standard_ShortReal y, | |
1094 | const Standard_ShortReal dx, | |
1095 | const Standard_ShortReal dy) { | |
1096 | ||
1097 | if (! myDriverIsDefined) | |
1098 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1099 | ||
1100 | Standard_ShortReal mx = x,my = y,x1,y1,x2=0,y2=0; | |
1101 | Standard_Boolean status = Standard_True; | |
1102 | ||
1103 | if ( dx == 0. ) { | |
81bba717 | 1104 | // Bug with rejection of infinite lines |
7fd59977 | 1105 | // if ( my >= 0. && my <= mySpaceHeight ) |
1106 | x1 = mx; y1 = 0.; x2 = mx; y2 = mySpaceHeight; | |
1107 | } | |
1108 | else if ( dy == 0.) { | |
81bba717 | 1109 | // Bug with rejection of infinite lines |
7fd59977 | 1110 | // if ( mx >= 0. && mx <= mySpaceWidth ) |
1111 | x1 = 0.; y1 = my; x2 = mySpaceWidth; y2 = my; | |
1112 | } | |
1113 | else { | |
1114 | // equation of the line: X = mx + lambda * dx | |
1115 | // Y = my + lambda * dy | |
1116 | Standard_ShortReal lambda, lmin=ShortRealLast(),lmax= ShortRealFirst(); | |
1117 | ||
1118 | lambda = -mx/dx; y1 = my + lambda *dy; | |
1119 | if ( y1 >= 0. && y1 <= mySpaceHeight) { | |
1120 | lmin = lmax = lambda;} | |
1121 | ||
1122 | lambda = (mySpaceWidth-mx)/dx; y1 = my + lambda *dy; | |
1123 | if ( y1 >= 0. && y1 <= mySpaceHeight) { | |
1124 | lmin = lambda < lmin ? lambda : lmin; | |
1125 | lmax = lambda > lmax ? lambda : lmax;} | |
1126 | ||
1127 | lambda = -my/dy; x1 = mx + lambda *dx; | |
1128 | if ( x1 >= 0. && x1 <= mySpaceWidth) { | |
1129 | lmin = lambda < lmin ? lambda : lmin; | |
1130 | lmax = lambda > lmax ? lambda : lmax;} | |
1131 | ||
1132 | lambda = (mySpaceHeight-my)/dy; x1 = mx + lambda *dx; | |
1133 | if ( x1 >= 0. && x1 <= mySpaceWidth) { | |
1134 | lmin = lambda < lmin ? lambda : lmin; | |
1135 | lmax = lambda > lmax ? lambda : lmax;} | |
1136 | ||
1137 | if (lmin != ShortRealLast() && lmax != ShortRealFirst() && | |
1138 | lmin < lmax ) { | |
1139 | x1 = mx + lmin *dx; y1 = my + lmin *dy; | |
1140 | x2 = mx + lmax *dx; y2 = my + lmax *dy; | |
1141 | } else status = Standard_False; | |
1142 | } | |
1143 | if( status ) { | |
1144 | myDriver->DrawSegment(x1,y1,x2,y2); | |
1145 | if( myMinMaxIsActivated ) { | |
1146 | myMinX = Min(x1,myMinX); myMinX = Min(x2,myMinX); | |
1147 | myMinY = Min(y1,myMinY); myMinY = Min(y2,myMinY); | |
1148 | myMaxX = Max(x1,myMaxX); myMaxX = Max(x2,myMaxX); | |
1149 | myMaxY = Max(y1,myMaxY); myMaxY = Max(y2,myMaxY); | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | } | |
1154 | ||
1155 | void Graphic2d_Drawer::MapInfiniteLineFromTo ( | |
1156 | const Standard_ShortReal x, | |
1157 | const Standard_ShortReal y, | |
1158 | const Standard_ShortReal dx, | |
1159 | const Standard_ShortReal dy) { | |
1160 | ||
1161 | if (! myDriverIsDefined) | |
1162 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1163 | ||
1164 | // Standard_ShortReal mx,my,x1,y1,x2,y2; | |
1165 | Standard_ShortReal mx,my; | |
1166 | // Standard_Boolean status = Standard_True; | |
1167 | ||
1168 | mx = myXT + ((x-myXF)/mySF) *myST; | |
1169 | my = myYT + ((y-myYF)/mySF) *myST; | |
1170 | DrawInfiniteLine(mx,my,dx,dy); | |
1171 | ||
1172 | } | |
1173 | ||
1174 | void Graphic2d_Drawer::SetLineAttrib(const Standard_Integer ColorIndex, | |
1175 | const Standard_Integer TypeIndex, | |
1176 | const Standard_Integer WidthIndex) { | |
1177 | ||
1178 | if (! myDriverIsDefined) | |
1179 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1180 | ||
1181 | #ifdef CSR_PRO12324 | |
1182 | if(myOverride && !IsPlotterDriver()) | |
1183 | #else | |
1184 | if(myOverride) | |
1185 | #endif | |
1186 | myDriver->SetLineAttrib(myOverrideColor, | |
1187 | TypeIndex,WidthIndex); | |
1188 | else if( ColorIndex > 0 ) | |
1189 | myDriver->SetLineAttrib(ColorIndex+myOffSet, | |
1190 | TypeIndex,WidthIndex); | |
1191 | else myDriver->SetLineAttrib(ColorIndex,TypeIndex,WidthIndex); | |
1192 | ||
1193 | } | |
1194 | ||
1195 | void Graphic2d_Drawer::SetMarkerAttrib(const Standard_Integer ColorIndex, | |
1196 | const Standard_Integer WidthIndex, | |
1197 | const Standard_Boolean FillMarker) { | |
1198 | ||
1199 | if (! myDriverIsDefined) | |
1200 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1201 | ||
1202 | #ifdef CSR_PRO12324 | |
1203 | if(myOverride && !IsPlotterDriver()) | |
1204 | #else | |
1205 | if(myOverride) | |
1206 | #endif | |
1207 | myDriver->SetMarkerAttrib(myOverrideColor, | |
1208 | WidthIndex,FillMarker); | |
1209 | else if( ColorIndex > 0 ) | |
1210 | myDriver->SetMarkerAttrib(ColorIndex+myOffSet, | |
1211 | WidthIndex,FillMarker); | |
1212 | else myDriver->SetMarkerAttrib(ColorIndex, | |
1213 | WidthIndex,FillMarker); | |
1214 | ||
1215 | } | |
1216 | ||
1217 | void Graphic2d_Drawer::SetPolyAttrib(const Standard_Integer ColorIndex, | |
1218 | const Standard_Integer TileIndex, | |
1219 | const Standard_Boolean DrawEdge) { | |
1220 | ||
1221 | if (! myDriverIsDefined) | |
1222 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1223 | ||
1224 | #ifdef CSR_PRO12324 | |
1225 | if(myOverride && !IsPlotterDriver()) | |
1226 | #else | |
1227 | if(myOverride) | |
1228 | #endif | |
1229 | myDriver->SetPolyAttrib(myOverrideColor,TileIndex,DrawEdge); | |
1230 | else if( ColorIndex > 0 ) | |
1231 | myDriver->SetPolyAttrib(ColorIndex+myOffSet,TileIndex,DrawEdge); | |
1232 | else myDriver->SetPolyAttrib(ColorIndex,TileIndex,DrawEdge); | |
1233 | ||
1234 | } | |
1235 | ||
1236 | void Graphic2d_Drawer::SetHidingPolyAttrib( | |
1237 | const Standard_Integer HidingColorIndex, | |
1238 | const Standard_Integer FrameColorIndex, | |
1239 | const Standard_Integer FrameTypeIndex, | |
1240 | const Standard_Integer FrameWidthIndex) { | |
1241 | ||
1242 | if (! myDriverIsDefined) | |
1243 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1244 | #ifdef CSR_PRO12324 | |
1245 | if(myOverride && !IsPlotterDriver()) { | |
1246 | #else | |
1247 | if(myOverride) { | |
1248 | #endif | |
1249 | myDriver->SetLineAttrib(myOverrideColor,FrameTypeIndex,FrameWidthIndex); | |
1250 | if( HidingColorIndex > 0 ) { | |
1251 | myDriver->SetPolyAttrib(HidingColorIndex+myOffSet,0,Standard_True); | |
1252 | } else { | |
1253 | myDriver->SetPolyAttrib(HidingColorIndex,0,Standard_True); | |
1254 | } | |
1255 | } else { | |
1256 | Standard_Boolean DrawEdge = Standard_False; | |
1257 | if( (FrameColorIndex > 0) && (FrameColorIndex != HidingColorIndex) ) { | |
1258 | DrawEdge = Standard_True; | |
1259 | myDriver->SetLineAttrib(FrameColorIndex+myOffSet,FrameTypeIndex,FrameWidthIndex); | |
1260 | } | |
1261 | if( HidingColorIndex > 0 ) { | |
1262 | myDriver->SetPolyAttrib(HidingColorIndex+myOffSet,0,DrawEdge); | |
1263 | } else { | |
1264 | myDriver->SetPolyAttrib(HidingColorIndex,0,DrawEdge); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | } | |
1269 | ||
1270 | void Graphic2d_Drawer::SetTextAttrib(const Standard_Integer ColorIndex, | |
1271 | const Standard_Integer FontIndex, | |
1272 | const Standard_ShortReal aSlant, | |
1273 | const Standard_ShortReal aHScale, | |
1274 | const Standard_ShortReal aWScale, | |
1275 | const Standard_Boolean isUnderlined) { | |
1276 | ||
1277 | if (! myDriverIsDefined) | |
1278 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1279 | ||
1280 | #ifdef BUC60650 | |
1281 | Standard_ShortReal hscale = (aHScale > 0.) ? aHScale : | |
1282 | (aWScale > 0.) ? aWScale : Standard_ShortReal(1.0); | |
1283 | Standard_ShortReal wscale = (aWScale > 0.) ? aWScale : hscale; | |
1284 | #else | |
1285 | Standard_ShortReal hscale = aHScale; | |
1286 | Standard_ShortReal wscale = aWScale; | |
1287 | #endif | |
1288 | ||
1289 | ||
1290 | #ifdef CSR_PRO12324 | |
1291 | if(myOverride && !IsPlotterDriver()) | |
1292 | #else | |
1293 | if(myOverride) | |
1294 | #endif | |
1295 | myDriver->SetTextAttrib(myOverrideColor,FontIndex, | |
1296 | aSlant,hscale,wscale,isUnderlined); | |
1297 | else if( ColorIndex > 0 ) | |
1298 | myDriver->SetTextAttrib(ColorIndex+myOffSet,FontIndex, | |
1299 | aSlant,hscale,wscale,isUnderlined); | |
1300 | else myDriver->SetTextAttrib(ColorIndex,FontIndex, | |
1301 | aSlant,hscale,wscale,isUnderlined); | |
1302 | ||
1303 | } | |
1304 | ||
1305 | void Graphic2d_Drawer::SetHidingTextAttrib(const Standard_Integer ColorIndex, | |
1306 | const Standard_Integer HidingColorIndex, | |
1307 | const Standard_Integer FrameColorIndex, | |
1308 | const Standard_Integer FrameWidthIndex, | |
1309 | const Standard_Integer FontIndex, | |
1310 | const Standard_ShortReal aSlant, | |
1311 | const Standard_ShortReal aHScale, | |
1312 | const Standard_ShortReal aWScale, | |
1313 | const Standard_Boolean isUnderlined) { | |
1314 | ||
1315 | if (! myDriverIsDefined) | |
1316 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1317 | ||
1318 | #ifdef BUC60650 | |
1319 | Standard_ShortReal hscale = (aHScale > 0.) ? aHScale : | |
1320 | (aWScale > 0.) ? aWScale : Standard_ShortReal(1.0); | |
1321 | Standard_ShortReal wscale = (aWScale > 0.) ? aWScale : hscale; | |
1322 | #else | |
1323 | Standard_ShortReal hscale = aHScale; | |
1324 | Standard_ShortReal wscale = aWScale; | |
1325 | #endif | |
1326 | ||
1327 | #ifdef CSR_PRO12324 | |
1328 | if(myOverride && !IsPlotterDriver()) { | |
1329 | #else | |
1330 | if(myOverride) { | |
1331 | #endif | |
1332 | if( ColorIndex >= 0 ) { | |
1333 | myDriver->SetTextAttrib(myOverrideColor,FontIndex, | |
1334 | aSlant,hscale,wscale,isUnderlined); | |
1335 | } | |
1336 | myDriver->SetLineAttrib(myOverrideColor,0,FrameWidthIndex); | |
1337 | if( HidingColorIndex > 0 ) { | |
1338 | myDriver->SetPolyAttrib(HidingColorIndex+myOffSet,0,Standard_True); | |
1339 | } else { | |
1340 | myDriver->SetPolyAttrib(HidingColorIndex,0,Standard_True); | |
1341 | } | |
1342 | } else { | |
1343 | Standard_Boolean DrawEdge = Standard_False; | |
1344 | if( ColorIndex >= 0 ) { | |
1345 | if( (ColorIndex > 0) && (ColorIndex != HidingColorIndex) ) { | |
1346 | myDriver->SetTextAttrib(ColorIndex+myOffSet,FontIndex, | |
1347 | aSlant,hscale,wscale,isUnderlined); | |
1348 | } else { | |
1349 | myDriver->SetTextAttrib(0,FontIndex, | |
1350 | aSlant,hscale,wscale,isUnderlined); | |
1351 | } | |
1352 | } | |
1353 | if( (FrameColorIndex > 0) && (FrameColorIndex != HidingColorIndex) ) { | |
1354 | DrawEdge = Standard_True; | |
1355 | myDriver->SetLineAttrib(FrameColorIndex+myOffSet,0,FrameWidthIndex); | |
1356 | } | |
1357 | if( HidingColorIndex > 0 ) { | |
1358 | myDriver->SetPolyAttrib(HidingColorIndex+myOffSet,0,DrawEdge); | |
1359 | } else { | |
1360 | myDriver->SetPolyAttrib(HidingColorIndex,0,DrawEdge); | |
1361 | } | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | void Graphic2d_Drawer::SetFramedTextAttrib(const Standard_Integer ColorIndex, | |
1366 | const Standard_Integer FrameColorIndex, | |
1367 | const Standard_Integer FrameWidthIndex, | |
1368 | const Standard_Integer FontIndex, | |
1369 | const Standard_ShortReal aSlant, | |
1370 | const Standard_ShortReal aHScale, | |
1371 | const Standard_ShortReal aWScale, | |
1372 | const Standard_Boolean isUnderlined) { | |
1373 | ||
1374 | if (! myDriverIsDefined) | |
1375 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1376 | ||
1377 | #ifdef BUC60650 | |
1378 | Standard_ShortReal hscale = (aHScale > 0.) ? aHScale : | |
1379 | (aWScale > 0.) ? aWScale : Standard_ShortReal(1.0); | |
1380 | Standard_ShortReal wscale = (aWScale > 0.) ? aWScale : hscale; | |
1381 | #else | |
1382 | Standard_ShortReal hscale = aHScale; | |
1383 | Standard_ShortReal wscale = aWScale; | |
1384 | #endif | |
1385 | ||
1386 | #ifdef CSR_PRO12324 | |
1387 | if(myOverride && !IsPlotterDriver()) { | |
1388 | #else | |
1389 | if(myOverride) { | |
1390 | #endif | |
1391 | if( ColorIndex >= 0 ) { | |
1392 | myDriver->SetTextAttrib(myOverrideColor,FontIndex, | |
1393 | aSlant,hscale,wscale,isUnderlined); | |
1394 | } | |
1395 | myDriver->SetLineAttrib(myOverrideColor,0,FrameWidthIndex); | |
1396 | } else { | |
1397 | if( ColorIndex >= 0 ) { | |
1398 | if( ColorIndex > 0 ) { | |
1399 | myDriver->SetTextAttrib(ColorIndex+myOffSet,FontIndex, | |
1400 | aSlant,hscale,wscale,isUnderlined); | |
1401 | } else { | |
1402 | myDriver->SetTextAttrib(ColorIndex,FontIndex, | |
1403 | aSlant,hscale,wscale,isUnderlined); | |
1404 | } | |
1405 | } | |
1406 | if( FrameColorIndex > 0 ) { | |
1407 | myDriver->SetLineAttrib(FrameColorIndex+myOffSet,0,FrameWidthIndex); | |
1408 | } else if( ColorIndex > 0 ) { | |
1409 | myDriver->SetLineAttrib(ColorIndex+myOffSet,0,FrameWidthIndex); | |
1410 | } else { | |
1411 | myDriver->SetLineAttrib(ColorIndex,0,FrameWidthIndex); | |
1412 | } | |
1413 | } | |
1414 | myDriver->SetPolyAttrib(ColorIndex,-1,Standard_True); | |
1415 | } | |
1416 | ||
1417 | Standard_Boolean Graphic2d_Drawer::IsKnownImage(const Handle(Standard_Transient)& anImageId) { | |
1418 | ||
1419 | if (! myDriverIsDefined) | |
1420 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1421 | ||
1422 | return myDriver->IsKnownImage(anImageId); | |
1423 | ||
1424 | } | |
1425 | ||
1426 | void Graphic2d_Drawer::ClearImage(const Handle(Standard_Transient)& anImageId) { | |
1427 | ||
1428 | if (! myDriverIsDefined) | |
1429 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1430 | ||
1431 | myDriver->ClearImage(anImageId); | |
1432 | ||
1433 | } | |
1434 | ||
1435 | void Graphic2d_Drawer::DrawImage(const Handle(Standard_Transient)& anImageId, | |
1436 | const Standard_ShortReal aX, | |
1437 | const Standard_ShortReal aY) { | |
1438 | ||
1439 | if (! myDriverIsDefined) | |
1440 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1441 | ||
1442 | Standard_ShortReal X,Y; | |
1443 | X = myXT + ((aX-myXF)/mySF) *myST; | |
1444 | Y = myYT + ((aY-myYF)/mySF) *myST; | |
1445 | myDriver->DrawImage(anImageId,X,Y); | |
1446 | } | |
1447 | ||
1448 | void Graphic2d_Drawer::ClearImageFile(const Standard_CString aName) { | |
1449 | ||
1450 | if (! myDriverIsDefined) | |
1451 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1452 | ||
1453 | myDriver->ClearImageFile(aName); | |
1454 | ||
1455 | } | |
1456 | ||
1457 | void Graphic2d_Drawer::DrawImageFile (const Standard_CString aName, | |
1458 | const Standard_ShortReal aX, | |
1459 | const Standard_ShortReal aY, | |
1460 | const Quantity_Factor aScale) { | |
1461 | ||
1462 | if (! myDriverIsDefined) | |
1463 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1464 | ||
1465 | Standard_ShortReal X,Y; | |
1466 | X = myXT + ((aX-myXF)/mySF) *myST; | |
1467 | Y = myYT + ((aY-myYF)/mySF) *myST; | |
1468 | myDriver->DrawImageFile (aName, X, Y, aScale); | |
1469 | if( myMinMaxIsActivated ) { | |
1470 | Standard_ShortReal width,height; | |
1471 | if( GetImageSize(aName,width,height) ) { | |
1472 | Standard_ShortReal x1 = Standard_ShortReal(X-width/2.); | |
1473 | Standard_ShortReal y1 = Standard_ShortReal(Y-height/2.); | |
1474 | Standard_ShortReal x2 = Standard_ShortReal(X+width/2.); | |
1475 | Standard_ShortReal y2 = Standard_ShortReal(Y+height/2.); | |
1476 | myMinX = Min(x1,myMinX); | |
1477 | myMinY = Min(y1,myMinY); | |
1478 | myMaxX = Max(x2,myMaxX); | |
1479 | myMaxY = Max(y2,myMaxY); | |
1480 | } | |
1481 | } | |
1482 | ||
1483 | } | |
1484 | ||
1485 | void Graphic2d_Drawer::FillAndDrawImage(const Handle(Standard_Transient)& anImageId, | |
1486 | const Standard_ShortReal aX, | |
1487 | const Standard_ShortReal aY, | |
1488 | const Standard_Integer aWidth, | |
1489 | const Standard_Integer aHeight, | |
1490 | const Standard_Address anArrayOfPixels) { | |
1491 | ||
1492 | if (! myDriverIsDefined) | |
1493 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1494 | ||
1495 | Standard_ShortReal X,Y; | |
1496 | X = myXT + ((aX-myXF)/mySF) *myST; | |
1497 | Y = myYT + ((aY-myYF)/mySF) *myST; | |
1498 | myDriver->FillAndDrawImage | |
1499 | (anImageId,X,Y,aWidth,aHeight,anArrayOfPixels); | |
1500 | if( myMinMaxIsActivated ) { | |
1501 | Standard_ShortReal width = Convert(aWidth); | |
1502 | Standard_ShortReal height = Convert(aHeight); | |
1503 | Standard_ShortReal x1 = Standard_ShortReal(X-width/2.); | |
1504 | Standard_ShortReal y1 = Standard_ShortReal(Y-height/2.); | |
1505 | Standard_ShortReal x2 = Standard_ShortReal(X+width/2.); | |
1506 | Standard_ShortReal y2 = Standard_ShortReal(Y+height/2.); | |
1507 | myMinX = Min(x1,myMinX); | |
1508 | myMinY = Min(y1,myMinY); | |
1509 | myMaxX = Max(x2,myMaxX); | |
1510 | myMaxY = Max(y2,myMaxY); | |
1511 | } | |
1512 | ||
1513 | } | |
1514 | ||
1515 | void Graphic2d_Drawer::FillAndDrawImage(const Handle(Standard_Transient)& anImageId, | |
1516 | const Standard_ShortReal aX, | |
1517 | const Standard_ShortReal aY, | |
1518 | const Standard_Integer anIndexOfLine, | |
1519 | const Standard_Integer aWidth, | |
1520 | const Standard_Integer aHeight, | |
1521 | const Standard_Address anArrayOfPixels) { | |
1522 | if (! myDriverIsDefined) | |
1523 | Graphic2d_DrawerDefinitionError::Raise ("No defined driver"); | |
1524 | ||
1525 | Standard_ShortReal X,Y; | |
1526 | X = myXT + ((aX-myXF)/mySF) *myST; | |
1527 | Y = myYT + ((aY-myYF)/mySF) *myST; | |
1528 | myDriver->FillAndDrawImage | |
1529 | (anImageId,X,Y,anIndexOfLine,aWidth,aHeight,anArrayOfPixels); | |
1530 | if( myMinMaxIsActivated ) { | |
1531 | Standard_ShortReal width = Convert(aWidth); | |
1532 | Standard_ShortReal height = Convert(aHeight); | |
1533 | Standard_ShortReal x1 = Standard_ShortReal(X-width/2.); | |
1534 | Standard_ShortReal y1 = Standard_ShortReal(Y-height/2.); | |
1535 | Standard_ShortReal x2 = Standard_ShortReal(X+width/2.); | |
1536 | Standard_ShortReal y2 = Standard_ShortReal(Y+height/2.); | |
1537 | myMinX = Min(x1,myMinX); | |
1538 | myMinY = Min(y1,myMinY); | |
1539 | myMaxX = Max(x2,myMaxX); | |
1540 | myMaxY = Max(y2,myMaxY); | |
1541 | } | |
1542 | ||
1543 | } | |
1544 | ||
1545 | Standard_ShortReal Graphic2d_Drawer::Convert(const Standard_ShortReal aValue) const { | |
1546 | ||
1547 | return aValue/mySF * myST; | |
1548 | ||
1549 | } | |
1550 | ||
1551 | Standard_ShortReal Graphic2d_Drawer::Convert(const Standard_Integer aValue) const { | |
1552 | Standard_ShortReal dValue = 0.; | |
1553 | ||
1554 | if( myDriverIsDefined ) { | |
1555 | dValue = Standard_ShortReal(myDriver->Convert(aValue)); | |
1556 | } | |
1557 | return dValue; | |
1558 | } | |
1559 | ||
1560 | Standard_ShortReal Graphic2d_Drawer::Scale() const { | |
1561 | ||
1562 | return myST/mySF; | |
1563 | ||
1564 | } | |
1565 | ||
1566 | Standard_ShortReal Graphic2d_Drawer::ConvertMapToFrom(const Standard_ShortReal x) const { | |
1567 | ||
1568 | return x/myST * mySF; | |
1569 | ||
1570 | } |