KiCad PCB EDA Suite
Loading...
Searching...
No Matches
plotter.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
40#include <trigo.h>
41#include <plotters/plotter.h>
43#include <bezier_curves.h>
44#include <callback_gal.h>
45#include <math/util.h> // for KiROUND
46
48{
49 m_plotScale = 1;
50 m_currentPenWidth = -1; // To-be-set marker
51 m_penState = 'Z'; // End-of-path idle
52 m_plotMirror = false; // Plot mirror option flag
54 m_yaxisReversed = false;
55 m_outputFile = nullptr;
56 m_colorMode = false; // Starts as a BW plot
57 m_negativeMode = false;
58
59 // Temporary init to avoid not initialized vars, will be set later
60 m_IUsPerDecimil = 1; // will be set later to the actual value
61 m_iuPerDeviceUnit = 1; // will be set later to the actual value
62 m_renderSettings = nullptr;
63}
64
65
67{
68 // Emergency cleanup, but closing the file is usually made in EndPlot().
69 if( m_outputFile )
70 fclose( m_outputFile );
71}
72
73
74bool PLOTTER::OpenFile( const wxString& aFullFilename )
75{
76 m_filename = aFullFilename;
77
78 wxASSERT( !m_outputFile );
79
80 // Open the file in text mode (not suitable for all plotters but only for most of them.
81 m_outputFile = wxFopen( m_filename, wxT( "wt" ) );
82
83 if( m_outputFile == nullptr )
84 return false ;
85
86 return true;
87}
88
89
91{
92 VECTOR2I pos = aCoordinate - m_plotOffset;
93
94 double x = pos.x * m_plotScale;
95 double y = ( m_paperSize.y - pos.y * m_plotScale );
96
97 if( m_plotMirror )
98 {
100 x = ( m_paperSize.x - pos.x * m_plotScale );
101 else
102 y = pos.y * m_plotScale;
103 }
104
105 if( m_yaxisReversed )
106 y = m_paperSize.y - y;
107
110
111 return VECTOR2D( x, y );
112}
113
114
116{
117 return VECTOR2D( size.x * m_plotScale * m_iuPerDeviceUnit,
119}
120
121
122double PLOTTER::userToDeviceSize( double size ) const
123{
124 return size * m_plotScale * m_iuPerDeviceUnit;
125}
126
127
128#define IU_PER_MILS ( m_IUsPerDecimil * 10 )
129
130
131double PLOTTER::GetDotMarkLenIU( int aLineWidth ) const
132{
133 return userToDeviceSize( m_renderSettings->GetDotLength( aLineWidth ) );
134}
135
136
137double PLOTTER::GetDashMarkLenIU( int aLineWidth ) const
138{
139 return userToDeviceSize( m_renderSettings->GetDashLength( aLineWidth ) );
140}
141
142
143double PLOTTER::GetDashGapLenIU( int aLineWidth ) const
144{
145 return userToDeviceSize( m_renderSettings->GetGapLength( aLineWidth ) );
146}
147
148#include <wx/log.h>
149void PLOTTER::Arc( const VECTOR2D& aStart, const VECTOR2D& aMid, const VECTOR2D& aEnd, FILL_T aFill,
150 int aWidth )
151{
152 VECTOR2D aCenter = CalcArcCenter( aStart, aMid, aEnd );
153
154 EDA_ANGLE startAngle( aStart - aCenter );
155 EDA_ANGLE endAngle( aEnd - aCenter );
156
157 // < 0: left, 0 : on the line, > 0 : right
158 double det = ( aEnd - aStart ).Cross( aMid - aStart );
159
160 int cw = det <= 0;
161 EDA_ANGLE angle = endAngle - startAngle;
162
163 if( cw )
164 angle.Normalize();
165 else
166 angle.NormalizeNegative();
167
168 double radius = ( aStart - aCenter ).EuclideanNorm();
169 Arc( aCenter, startAngle, angle, radius, aFill, aWidth );
170}
171
172
173void PLOTTER::Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle,
174 double aRadius, FILL_T aFill, int aWidth )
175{
176 polyArc( aCenter, aStartAngle, aAngle, aRadius, aFill, aWidth );
177}
178
179
180void PLOTTER::polyArc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
181 const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth )
182{
183 EDA_ANGLE startAngle = aStartAngle;
184 EDA_ANGLE endAngle = startAngle + aAngle;
185 const EDA_ANGLE delta( 5.0, DEGREES_T ); // increment to draw arc
186 VECTOR2I start, end;
187 const int sign = 1;
188
189 if( aAngle < ANGLE_0 )
190 std::swap( startAngle, endAngle );
191
192 SetCurrentLineWidth( aWidth );
193
194 start.x = KiROUND( aCenter.x + aRadius * startAngle.Cos() );
195 start.y = KiROUND( aCenter.y + sign * aRadius * startAngle.Sin() );
196
197 if( aFill != FILL_T::NO_FILL )
198 {
199 MoveTo( aCenter );
200 LineTo( start );
201 }
202 else
203 {
204 MoveTo( start );
205 }
206
207 for( EDA_ANGLE ii = startAngle + delta; ii < endAngle; ii += delta )
208 {
209 end.x = KiROUND( aCenter.x + aRadius * ii.Cos() );
210 end.y = KiROUND( aCenter.y + sign * aRadius * ii.Sin() );
211 LineTo( end );
212 }
213
214 end.x = KiROUND( aCenter.x + aRadius * endAngle.Cos() );
215 end.y = KiROUND( aCenter.y + sign * aRadius * endAngle.Sin() );
216
217 if( aFill != FILL_T::NO_FILL )
218 {
219 LineTo( end );
220 FinishTo( aCenter );
221 }
222 else
223 {
224 FinishTo( end );
225 }
226}
227
228
229void PLOTTER::BezierCurve( const VECTOR2I& aStart, const VECTOR2I& aControl1,
230 const VECTOR2I& aControl2, const VECTOR2I& aEnd,
231 int aTolerance, int aLineThickness )
232{
233 // Generic fallback: Quadratic Bezier curve plotted as a polyline
234 int minSegLen = aLineThickness; // The segment min length to approximate a bezier curve
235
236 std::vector<VECTOR2I> ctrlPoints;
237 ctrlPoints.reserve( 4 );
238
239 ctrlPoints.push_back( aStart );
240 ctrlPoints.push_back( aControl1 );
241 ctrlPoints.push_back( aControl2 );
242 ctrlPoints.push_back( aEnd );
243
244 BEZIER_POLY bezier_converter( ctrlPoints );
245
246 std::vector<VECTOR2I> approxPoints;
247 bezier_converter.GetPoly( approxPoints, minSegLen );
248
249 SetCurrentLineWidth( aLineThickness );
250 MoveTo( aStart );
251
252 for( unsigned ii = 1; ii < approxPoints.size()-1; ii++ )
253 LineTo( approxPoints[ii] );
254
255 FinishTo( aEnd );
256}
257
258
259void PLOTTER::PlotImage( const wxImage& aImage, const VECTOR2I& aPos, double aScaleFactor )
260{
261 VECTOR2I size( aImage.GetWidth() * aScaleFactor, aImage.GetHeight() * aScaleFactor );
262
263 VECTOR2I start = aPos;
264 start.x -= size.x / 2;
265 start.y -= size.y / 2;
266
267 VECTOR2I end = start;
268 end.x += size.x;
269 end.y += size.y;
270
271 Rect( start, end, FILL_T::NO_FILL );
272}
273
274
275void PLOTTER::markerSquare( const VECTOR2I& position, int radius )
276{
277 double r = KiROUND( radius / 1.4142 );
278 std::vector<VECTOR2I> corner_list;
279 VECTOR2I corner;
280
281 corner_list.reserve( 4 );
282
283 corner.x = position.x + r;
284 corner.y = position.y + r;
285 corner_list.push_back( corner );
286 corner.x = position.x + r;
287 corner.y = position.y - r;
288 corner_list.push_back( corner );
289 corner.x = position.x - r;
290 corner.y = position.y - r;
291 corner_list.push_back( corner );
292 corner.x = position.x - r;
293 corner.y = position.y + r;
294 corner_list.push_back( corner );
295 corner.x = position.x + r;
296 corner.y = position.y + r;
297 corner_list.push_back( corner );
298
299 PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
300}
301
302
303void PLOTTER::markerCircle( const VECTOR2I& position, int radius )
304{
305 Circle( position, radius * 2, FILL_T::NO_FILL, GetCurrentLineWidth() );
306}
307
308
309void PLOTTER::markerLozenge( const VECTOR2I& position, int radius )
310{
311 std::vector<VECTOR2I> corner_list;
312 VECTOR2I corner;
313
314 corner_list.reserve( 4 );
315
316 corner.x = position.x;
317 corner.y = position.y + radius;
318 corner_list.push_back( corner );
319 corner.x = position.x + radius;
320 corner.y = position.y,
321 corner_list.push_back( corner );
322 corner.x = position.x;
323 corner.y = position.y - radius;
324 corner_list.push_back( corner );
325 corner.x = position.x - radius;
326 corner.y = position.y;
327 corner_list.push_back( corner );
328 corner.x = position.x;
329 corner.y = position.y + radius;
330 corner_list.push_back( corner );
331
332 PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
333}
334
335
336void PLOTTER::markerHBar( const VECTOR2I& pos, int radius )
337{
338 MoveTo( VECTOR2I( pos.x - radius, pos.y ) );
339 FinishTo( VECTOR2I( pos.x + radius, pos.y ) );
340}
341
342
343void PLOTTER::markerSlash( const VECTOR2I& pos, int radius )
344{
345 MoveTo( VECTOR2I( pos.x - radius, pos.y - radius ) );
346 FinishTo( VECTOR2I( pos.x + radius, pos.y + radius ) );
347}
348
349
350void PLOTTER::markerBackSlash( const VECTOR2I& pos, int radius )
351{
352 MoveTo( VECTOR2I( pos.x + radius, pos.y - radius ) );
353 FinishTo( VECTOR2I( pos.x - radius, pos.y + radius ) );
354}
355
356
357void PLOTTER::markerVBar( const VECTOR2I& pos, int radius )
358{
359 MoveTo( VECTOR2I( pos.x, pos.y - radius ) );
360 FinishTo( VECTOR2I( pos.x, pos.y + radius ) );
361}
362
363
364void PLOTTER::Marker( const VECTOR2I& position, int diametre, unsigned aShapeId )
365{
366 int radius = diametre / 2;
367
368 /* Marker are composed by a series of 'parts' superimposed; not every
369 combination make sense, obviously. Since they are used in order I
370 tried to keep the uglier/more complex constructions at the end.
371 Also I avoided the |/ |\ -/ -\ construction because they're *very*
372 ugly... if needed they could be added anyway... I'd like to see
373 a board with more than 58 drilling/slotting tools!
374 If Visual C++ supported the 0b literals they would be optimally
375 and easily encoded as an integer array. We have to do with octal */
376 static const unsigned char marker_patterns[MARKER_COUNT] = {
377
378 // Bit order: O Square Lozenge - | \ /
379 // First choice: simple shapes
380 0003, // X
381 0100, // O
382 0014, // +
383 0040, // Sq
384 0020, // Lz
385
386 // Two simple shapes
387 0103, // X O
388 0017, // X +
389 0043, // X Sq
390 0023, // X Lz
391 0114, // O +
392 0140, // O Sq
393 0120, // O Lz
394 0054, // + Sq
395 0034, // + Lz
396 0060, // Sq Lz
397
398 // Three simple shapes
399 0117, // X O +
400 0143, // X O Sq
401 0123, // X O Lz
402 0057, // X + Sq
403 0037, // X + Lz
404 0063, // X Sq Lz
405 0154, // O + Sq
406 0134, // O + Lz
407 0074, // + Sq Lz
408
409 // Four simple shapes
410 0174, // O Sq Lz +
411 0163, // X O Sq Lz
412 0157, // X O Sq +
413 0137, // X O Lz +
414 0077, // X Sq Lz +
415
416 // This draws *everything *
417 0177, // X O Sq Lz +
418
419 // Here we use the single bars... so the cross is forbidden
420 0110, // O -
421 0104, // O |
422 0101, // O /
423 0050, // Sq -
424 0044, // Sq |
425 0041, // Sq /
426 0030, // Lz -
427 0024, // Lz |
428 0021, // Lz /
429 0150, // O Sq -
430 0144, // O Sq |
431 0141, // O Sq /
432 0130, // O Lz -
433 0124, // O Lz |
434 0121, // O Lz /
435 0070, // Sq Lz -
436 0064, // Sq Lz |
437 0061, // Sq Lz /
438 0170, // O Sq Lz -
439 0164, // O Sq Lz |
440 0161, // O Sq Lz /
441
442 // Last resort: the backlash component (easy to confound)
443 0102, // \ O
444 0042, // \ Sq
445 0022, // \ Lz
446 0142, // \ O Sq
447 0122, // \ O Lz
448 0062, // \ Sq Lz
449 0162 // \ O Sq Lz
450 };
451
452 if( aShapeId >= MARKER_COUNT )
453 {
454 // Fallback shape
455 markerCircle( position, radius );
456 }
457 else
458 {
459 // Decode the pattern and draw the corresponding parts
460 unsigned char pat = marker_patterns[aShapeId];
461
462 if( pat & 0001 )
463 markerSlash( position, radius );
464
465 if( pat & 0002 )
466 markerBackSlash( position, radius );
467
468 if( pat & 0004 )
469 markerVBar( position, radius );
470
471 if( pat & 0010 )
472 markerHBar( position, radius );
473
474 if( pat & 0020 )
475 markerLozenge( position, radius );
476
477 if( pat & 0040 )
478 markerSquare( position, radius );
479
480 if( pat & 0100 )
481 markerCircle( position, radius );
482 }
483}
484
485
486void PLOTTER::segmentAsOval( const VECTOR2I& start, const VECTOR2I& end, int aWidth,
487 OUTLINE_MODE aTraceMode )
488{
489 VECTOR2I center( ( start.x + end.x ) / 2, ( start.y + end.y ) / 2 );
490 VECTOR2I size( end.x - start.x, end.y - start.y );
491 EDA_ANGLE orient( size );
492 orient = -orient; // this is due to our Y axis orientation
493
494 size.x = KiROUND( EuclideanNorm( size ) ) + aWidth;
495 size.y = aWidth;
496
497 FlashPadOval( center, size, orient, aTraceMode, nullptr );
498}
499
500
501void PLOTTER::sketchOval( const VECTOR2I& aPos, const VECTOR2I& aSize, const EDA_ANGLE& aOrient,
502 int aWidth )
503{
504 SetCurrentLineWidth( aWidth );
505
506 EDA_ANGLE orient( aOrient );
507 VECTOR2I size( aSize );
508
509 if( size.x > size.y )
510 {
511 std::swap( size.x, size.y );
512 orient += ANGLE_90;
513 }
514
515 int deltaxy = size.y - size.x; /* distance between centers of the oval */
516 int radius = size.x / 2;
517
518 // Build a vertical oval shape giving the start and end points of arcs and edges,
519 // and the middle point of arcs
520 std::vector<VECTOR2I> corners;
521 corners.reserve( 6 );
522 // Shape is (x = corner and arc ends, c = arc centre)
523 // xcx
524 //
525 // xcx
526 int half_height = deltaxy / 2;
527 corners.emplace_back( -radius, -half_height );
528 corners.emplace_back( -radius, half_height );
529 corners.emplace_back( 0, half_height );
530 corners.emplace_back( radius, half_height );
531 corners.emplace_back( radius, -half_height );
532 corners.emplace_back( 0, -half_height );
533
534 // Rotate and move to the actual position
535 for( size_t ii = 0; ii < corners.size(); ii++ )
536 {
537 RotatePoint( corners[ii], orient );
538 corners[ii] += aPos;
539 }
540
541 // Gen shape (2 lines and 2 180 deg arcs):
542 MoveTo( corners[0] );
543 FinishTo( corners[1] );
544
545 Arc( corners[2], -orient, ANGLE_180, radius, FILL_T::NO_FILL );
546
547 MoveTo( corners[3] );
548 FinishTo( corners[4] );
549
550 Arc( corners[5], -orient, -ANGLE_180, radius, FILL_T::NO_FILL );
551}
552
553
554void PLOTTER::ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
555 OUTLINE_MODE tracemode, void* aData )
556{
557 if( tracemode == FILLED )
558 {
559 if( start == end )
560 {
561 Circle( start, width, FILL_T::FILLED_SHAPE, 0 );
562 }
563 else
564 {
565 SetCurrentLineWidth( width );
566 MoveTo( start );
567 FinishTo( end );
568 }
569 }
570 else
571 {
573 segmentAsOval( start, end, width, tracemode );
574 }
575}
576
577
578void PLOTTER::ThickArc( const VECTOR2D& centre, const EDA_ANGLE& aStartAngle,
579 const EDA_ANGLE& aAngle, double aRadius, int aWidth,
580 OUTLINE_MODE aTraceMode, void* aData )
581{
582 if( aTraceMode == FILLED )
583 {
584 Arc( centre, aStartAngle, aAngle, aRadius, FILL_T::NO_FILL, aWidth );
585 }
586 else
587 {
589 Arc( centre, aStartAngle, aAngle, aRadius - ( aWidth - m_currentPenWidth ) / 2,
590 FILL_T::NO_FILL, -1 );
591 Arc( centre, aStartAngle, aAngle, aRadius + ( aWidth - m_currentPenWidth ) / 2,
592 FILL_T::NO_FILL, -1 );
593 }
594}
595
596
597void PLOTTER::ThickArc( const EDA_SHAPE& aArcShape, OUTLINE_MODE aTraceMode, void* aData )
598{
599 VECTOR2D center = aArcShape.getCenter();
600 VECTOR2D mid = aArcShape.GetArcMid();
601 VECTOR2D start = aArcShape.GetStart();
602 VECTOR2D end = aArcShape.GetEnd();
603
604 EDA_ANGLE startAngle( start - center );
605 EDA_ANGLE endAngle( end - center );
606 EDA_ANGLE angle = endAngle - startAngle;
607
608 // < 0: left, 0 : on the line, > 0 : right
609 double det = ( end - start ).Cross( mid - start );
610
611 if( det <= 0 ) // cw
612 angle.Normalize();
613 else
614 angle.NormalizeNegative();
615
616 double radius = ( start - center ).EuclideanNorm();
617
618 ThickArc( center, startAngle, angle, radius, aArcShape.GetWidth(), aTraceMode, aData );
619}
620
621
622void PLOTTER::ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
623 OUTLINE_MODE tracemode, void* aData )
624{
625 if( tracemode == FILLED )
626 {
627 Rect( p1, p2, FILL_T::NO_FILL, width );
628 }
629 else
630 {
632 VECTOR2I offsetp1( p1.x - ( width - m_currentPenWidth ) / 2,
633 p1.y - (width - m_currentPenWidth) / 2 );
634 VECTOR2I offsetp2( p2.x + ( width - m_currentPenWidth ) / 2,
635 p2.y + (width - m_currentPenWidth) / 2 );
636 Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
637 offsetp1.x += ( width - m_currentPenWidth );
638 offsetp1.y += ( width - m_currentPenWidth );
639 offsetp2.x -= ( width - m_currentPenWidth );
640 offsetp2.y -= ( width - m_currentPenWidth );
641 Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
642 }
643}
644
645
646void PLOTTER::ThickCircle( const VECTOR2I& pos, int diametre, int width, OUTLINE_MODE tracemode,
647 void* aData )
648{
649 if( tracemode == FILLED )
650 {
651 Circle( pos, diametre, FILL_T::NO_FILL, width );
652 }
653 else
654 {
656 Circle( pos, diametre - width + m_currentPenWidth, FILL_T::NO_FILL, -1 );
657 Circle( pos, diametre + width - m_currentPenWidth, FILL_T::NO_FILL, -1 );
658 }
659}
660
661
662void PLOTTER::FilledCircle( const VECTOR2I& pos, int diametre, OUTLINE_MODE tracemode, void* aData )
663{
664 if( tracemode == FILLED )
665 {
666 Circle( pos, diametre, FILL_T::FILLED_SHAPE, 0 );
667 }
668 else
669 {
671 Circle( pos, diametre, FILL_T::NO_FILL, -1 );
672 }
673}
674
675
676void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int aWidth, void* aData )
677{
678 std::vector<VECTOR2I> cornerList;
679 cornerList.reserve( aCornerList.PointCount() );
680
681 for( int ii = 0; ii < aCornerList.PointCount(); ii++ )
682 cornerList.emplace_back( aCornerList.CPoint( ii ) );
683
684 if( aCornerList.IsClosed() && cornerList.front() != cornerList.back() )
685 cornerList.emplace_back( aCornerList.CPoint( 0 ) );
686
687 PlotPoly( cornerList, aFill, aWidth, aData );
688}
689
690
691void PLOTTER::Text( const VECTOR2I& aPos,
692 const COLOR4D& aColor,
693 const wxString& aText,
694 const EDA_ANGLE& aOrient,
695 const VECTOR2I& aSize,
696 enum GR_TEXT_H_ALIGN_T aH_justify,
697 enum GR_TEXT_V_ALIGN_T aV_justify,
698 int aPenWidth,
699 bool aItalic,
700 bool aBold,
701 bool aMultilineAllowed,
702 KIFONT::FONT* aFont,
703 const KIFONT::METRICS& aFontMetrics,
704 void* aData )
705{
707
708 SetColor( aColor );
709
710 if( aPenWidth == 0 && aBold ) // Use default values if aPenWidth == 0
711 aPenWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
712
713 if( aPenWidth < 0 )
714 aPenWidth = -aPenWidth;
715
716 CALLBACK_GAL callback_gal( empty_opts,
717 // Stroke callback
718 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
719 {
720 SetCurrentLineWidth( aPenWidth );
721 MoveTo( aPt1 );
722 LineTo( aPt2 );
723 PenFinish();
724 },
725 // Polygon callback
726 [&]( const SHAPE_LINE_CHAIN& aPoly )
727 {
728 PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
729 } );
730
731 TEXT_ATTRIBUTES attributes;
732 attributes.m_Angle = aOrient;
733 attributes.m_StrokeWidth = aPenWidth;
734 attributes.m_Italic = aItalic;
735 attributes.m_Bold = aBold;
736 attributes.m_Halign = aH_justify;
737 attributes.m_Valign = aV_justify;
738 attributes.m_Size = aSize;
739
740 // if Size.x is < 0, the text is mirrored (we have no other param to know a text is mirrored)
741 if( attributes.m_Size.x < 0 )
742 {
743 attributes.m_Size.x = -attributes.m_Size.x;
744 attributes.m_Mirrored = true;
745 }
746
747 if( !aFont )
748 aFont = KIFONT::FONT::GetFont();
749
750 aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
751}
752
753void PLOTTER::PlotText( const VECTOR2I& aPos,
754 const COLOR4D& aColor,
755 const wxString& aText,
756 const TEXT_ATTRIBUTES& aAttributes,
757 KIFONT::FONT* aFont,
758 const KIFONT::METRICS& aFontMetrics,
759 void* aData )
760{
762
763 TEXT_ATTRIBUTES attributes = aAttributes;
764 int penWidth = attributes.m_StrokeWidth;
765
766 SetColor( aColor );
767 SetCurrentLineWidth( penWidth, aData );
768
769 if( penWidth == 0 && attributes.m_Bold ) // Use default values if aPenWidth == 0
770 penWidth = GetPenSizeForBold( std::min( attributes.m_Size.x, attributes.m_Size.y ) );
771
772 if( penWidth < 0 )
773 penWidth = -penWidth;
774
775 attributes.m_StrokeWidth = penWidth;
776
777 CALLBACK_GAL callback_gal( empty_opts,
778 // Stroke callback
779 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
780 {
781 MoveTo( aPt1 );
782 LineTo( aPt2 );
783 PenFinish();
784 },
785 // Polygon callback
786 [&]( const SHAPE_LINE_CHAIN& aPoly )
787 {
788 PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
789 } );
790
791 if( !aFont )
792 aFont = KIFONT::FONT::GetFont();
793
794 aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
795}
Bezier curves to polygon converter.
Definition: bezier_curves.h:38
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMinSegLen=0, int aMaxSegCount=32)
Convert a Bezier curve to a polygon.
EDA_ANGLE Normalize()
Definition: eda_angle.h:255
EDA_ANGLE NormalizeNegative()
Definition: eda_angle.h:272
double Sin() const
Definition: eda_angle.h:212
double Cos() const
Definition: eda_angle.h:227
VECTOR2I getCenter() const
Definition: eda_shape.cpp:517
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:150
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:125
virtual int GetWidth() const
Definition: eda_shape.h:110
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:561
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:131
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics) const
Draw a string.
Definition: font.cpp:257
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double GetGapLength(int aLineWidth) const
double GetDotLength(int aLineWidth) const
double GetDashLength(int aLineWidth) const
double GetDotMarkLenIU(int aLineWidth) const
Definition: plotter.cpp:131
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:554
virtual void PlotImage(const wxImage &aImage, const VECTOR2I &aPos, double aScaleFactor)
Only PostScript plotters can plot bitmaps.
Definition: plotter.cpp:259
virtual void ThickRect(const VECTOR2I &p1, const VECTOR2I &p2, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:622
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:646
static const unsigned MARKER_COUNT
Draw a marker (used for the drill map).
Definition: plotter.h:484
double GetDashGapLenIU(int aLineWidth) const
Definition: plotter.cpp:143
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
virtual bool OpenFile(const wxString &aFullFilename)
Open or create the plot file aFullFilename.
Definition: plotter.cpp:74
bool m_mirrorIsHorizontal
Definition: plotter.h:657
PLOTTER()
Definition: plotter.cpp:47
virtual void Arc(const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH)
Definition: plotter.cpp:149
bool m_plotMirror
Definition: plotter.h:655
virtual void FilledCircle(const VECTOR2I &pos, int diametre, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:662
virtual void polyArc(const VECTOR2D &aCentre, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH)
Generic fallback: arc rendered as a polyline.
Definition: plotter.cpp:180
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:243
void markerSlash(const VECTOR2I &pos, int radius)
Plot a / bar centered on the position.
Definition: plotter.cpp:343
void FinishTo(const VECTOR2I &pos)
Definition: plotter.h:253
virtual void BezierCurve(const VECTOR2I &aStart, const VECTOR2I &aControl1, const VECTOR2I &aControl2, const VECTOR2I &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH)
Generic fallback: Cubic Bezier curve rendered as a polyline In KiCad the bezier curves have 4 control...
Definition: plotter.cpp:229
bool m_yaxisReversed
Definition: plotter.h:658
double m_iuPerDeviceUnit
Definition: plotter.h:652
VECTOR2I m_plotOffset
Definition: plotter.h:654
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:90
virtual ~PLOTTER()
Definition: plotter.cpp:66
VECTOR2I m_paperSize
Definition: plotter.h:676
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
Definition: plotter.cpp:115
void sketchOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, int aWidth)
Definition: plotter.cpp:501
char m_penState
Definition: plotter.h:667
void Marker(const VECTOR2I &position, int diametre, unsigned aShapeId)
Draw a pattern shape number aShapeId, to coord position.
Definition: plotter.cpp:364
void markerHBar(const VECTOR2I &pos, int radius)
Plot a - bar centered on the position.
Definition: plotter.cpp:336
int m_currentPenWidth
Definition: plotter.h:666
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:644
void markerCircle(const VECTOR2I &pos, int radius)
Plot a circle centered on the position.
Definition: plotter.cpp:303
virtual void ThickArc(const EDA_SHAPE &aArcShape, OUTLINE_MODE aTraceMode, void *aData)
Definition: plotter.cpp:597
FILE * m_outputFile
Output file.
Definition: plotter.h:661
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.
void LineTo(const VECTOR2I &pos)
Definition: plotter.h:248
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
void PenFinish()
Definition: plotter.h:259
void markerLozenge(const VECTOR2I &position, int radius)
Plot a lozenge centered on the position.
Definition: plotter.cpp:309
RENDER_SETTINGS * m_renderSettings
Definition: plotter.h:680
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aPenWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Draw text with the plotter.
Definition: plotter.cpp:691
void markerBackSlash(const VECTOR2I &pos, int radius)
Plot a \ bar centered on the position.
Definition: plotter.cpp:350
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, OUTLINE_MODE aTraceMode, void *aData)=0
void segmentAsOval(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode)
Convert a thick segment and plot it as an oval.
Definition: plotter.cpp:486
bool m_negativeMode
Definition: plotter.h:665
double m_IUsPerDecimil
Definition: plotter.h:650
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr)
Definition: plotter.cpp:753
void markerVBar(const VECTOR2I &pos, int radius)
Plot a | bar centered on the position.
Definition: plotter.cpp:357
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0
void markerSquare(const VECTOR2I &position, int radius)
Plot a square centered on the position.
Definition: plotter.cpp:275
virtual int GetCurrentLineWidth() const
Definition: plotter.h:147
bool m_colorMode
Definition: plotter.h:664
double GetDashMarkLenIU(int aLineWidth) const
Definition: plotter.cpp:137
virtual void SetColor(const COLOR4D &color)=0
wxString m_filename
Definition: plotter.h:671
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:439
FILL_T
Definition: eda_shape.h:55
static const bool FILLED
Definition: gr_basic.cpp:30
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
OUTLINE_MODE
Definition: outline_mode.h:25
constexpr int delta
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:228
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
Definition: trigo.cpp:520
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:128
int sign(T val)
Definition: util.h:135
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588