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, 2024 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
47PLOTTER::PLOTTER( const PROJECT* aProject ) :
48 m_project( aProject )
49{
50 m_plotScale = 1;
51 m_currentPenWidth = -1; // To-be-set marker
52 m_penState = 'Z'; // End-of-path idle
53 m_plotMirror = false; // Plot mirror option flag
55 m_yaxisReversed = false;
56 m_outputFile = nullptr;
57 m_colorMode = false; // Starts as a BW plot
58 m_negativeMode = false;
59
60 // Temporary init to avoid not initialized vars, will be set later
61 m_IUsPerDecimil = 1; // will be set later to the actual value
62 m_iuPerDeviceUnit = 1; // will be set later to the actual value
63 m_renderSettings = nullptr;
64}
65
66
68{
69 // Emergency cleanup, but closing the file is usually made in EndPlot().
70 if( m_outputFile )
71 fclose( m_outputFile );
72}
73
74
75bool PLOTTER::OpenFile( const wxString& aFullFilename )
76{
77 m_filename = aFullFilename;
78
79 wxASSERT( !m_outputFile );
80
81 // Open the file in text mode (not suitable for all plotters but only for most of them.
82 m_outputFile = wxFopen( m_filename, wxT( "wt" ) );
83
84 if( m_outputFile == nullptr )
85 return false ;
86
87 return true;
88}
89
90
92{
93 VECTOR2I pos = aCoordinate - m_plotOffset;
94
95 double x = pos.x * m_plotScale;
96 double y = ( m_paperSize.y - pos.y * m_plotScale );
97
98 if( m_plotMirror )
99 {
101 x = ( m_paperSize.x - pos.x * m_plotScale );
102 else
103 y = pos.y * m_plotScale;
104 }
105
106 if( m_yaxisReversed )
107 y = m_paperSize.y - y;
108
111
112 return VECTOR2D( x, y );
113}
114
115
117{
118 return VECTOR2D( size.x * m_plotScale * m_iuPerDeviceUnit,
120}
121
122
123double PLOTTER::userToDeviceSize( double size ) const
124{
125 return size * m_plotScale * m_iuPerDeviceUnit;
126}
127
128
129#define IU_PER_MILS ( m_IUsPerDecimil * 10 )
130
131
132double PLOTTER::GetDotMarkLenIU( int aLineWidth ) const
133{
134 return userToDeviceSize( m_renderSettings->GetDotLength( aLineWidth ) );
135}
136
137
138double PLOTTER::GetDashMarkLenIU( int aLineWidth ) const
139{
140 return userToDeviceSize( m_renderSettings->GetDashLength( aLineWidth ) );
141}
142
143
144double PLOTTER::GetDashGapLenIU( int aLineWidth ) const
145{
146 return userToDeviceSize( m_renderSettings->GetGapLength( aLineWidth ) );
147}
148
149#include <wx/log.h>
150void PLOTTER::Arc( const VECTOR2D& aStart, const VECTOR2D& aMid, const VECTOR2D& aEnd, FILL_T aFill,
151 int aWidth )
152{
153 VECTOR2D aCenter = CalcArcCenter( aStart, aMid, aEnd );
154
155 EDA_ANGLE startAngle( aStart - aCenter );
156 EDA_ANGLE endAngle( aEnd - aCenter );
157
158 // < 0: left, 0 : on the line, > 0 : right
159 double det = ( aEnd - aStart ).Cross( aMid - aStart );
160
161 int cw = det <= 0;
162 EDA_ANGLE angle = endAngle - startAngle;
163
164 if( cw )
165 angle.Normalize();
166 else
167 angle.NormalizeNegative();
168
169 double radius = ( aStart - aCenter ).EuclideanNorm();
170 Arc( aCenter, startAngle, angle, radius, aFill, aWidth );
171}
172
173
174void PLOTTER::Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle,
175 double aRadius, FILL_T aFill, int aWidth )
176{
177 polyArc( aCenter, aStartAngle, aAngle, aRadius, aFill, aWidth );
178}
179
180
181void PLOTTER::polyArc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
182 const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth )
183{
184 EDA_ANGLE startAngle = aStartAngle;
185 EDA_ANGLE endAngle = startAngle + aAngle;
186 const EDA_ANGLE delta( 5.0, DEGREES_T ); // increment to draw arc
187 VECTOR2I start, end;
188 const int sign = 1;
189
190 if( aAngle < ANGLE_0 )
191 std::swap( startAngle, endAngle );
192
193 SetCurrentLineWidth( aWidth );
194
195 start.x = KiROUND( aCenter.x + aRadius * startAngle.Cos() );
196 start.y = KiROUND( aCenter.y + sign * aRadius * startAngle.Sin() );
197
198 if( aFill != FILL_T::NO_FILL )
199 {
200 MoveTo( aCenter );
201 LineTo( start );
202 }
203 else
204 {
205 MoveTo( start );
206 }
207
208 for( EDA_ANGLE ii = startAngle + delta; ii < endAngle; ii += delta )
209 {
210 end.x = KiROUND( aCenter.x + aRadius * ii.Cos() );
211 end.y = KiROUND( aCenter.y + sign * aRadius * ii.Sin() );
212 LineTo( end );
213 }
214
215 end.x = KiROUND( aCenter.x + aRadius * endAngle.Cos() );
216 end.y = KiROUND( aCenter.y + sign * aRadius * endAngle.Sin() );
217
218 if( aFill != FILL_T::NO_FILL )
219 {
220 LineTo( end );
221 FinishTo( aCenter );
222 }
223 else
224 {
225 FinishTo( end );
226 }
227}
228
229
230void PLOTTER::BezierCurve( const VECTOR2I& aStart, const VECTOR2I& aControl1,
231 const VECTOR2I& aControl2, const VECTOR2I& aEnd,
232 int aTolerance, int aLineThickness )
233{
234 // Generic fallback: Quadratic Bezier curve plotted as a polyline
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, aTolerance );
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 = size.EuclideanNorm() + 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 int aWidth )
599{
600 VECTOR2D center = aArcShape.getCenter();
601 VECTOR2D mid = aArcShape.GetArcMid();
602 VECTOR2D start = aArcShape.GetStart();
603 VECTOR2D end = aArcShape.GetEnd();
604
605 EDA_ANGLE startAngle( start - center );
606 EDA_ANGLE endAngle( end - center );
607 EDA_ANGLE angle = endAngle - startAngle;
608
609 // < 0: left, 0 : on the line, > 0 : right
610 double det = ( end - start ).Cross( mid - start );
611
612 if( det <= 0 ) // cw
613 angle.Normalize();
614 else
615 angle.NormalizeNegative();
616
617 double radius = ( start - center ).EuclideanNorm();
618
619 ThickArc( center, startAngle, angle, radius, aWidth, aTraceMode, aData );
620}
621
622
623void PLOTTER::ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
624 OUTLINE_MODE tracemode, void* aData )
625{
626 if( tracemode == FILLED )
627 {
628 Rect( p1, p2, FILL_T::NO_FILL, width );
629 }
630 else
631 {
633 VECTOR2I offsetp1( p1.x - ( width - m_currentPenWidth ) / 2,
634 p1.y - (width - m_currentPenWidth) / 2 );
635 VECTOR2I offsetp2( p2.x + ( width - m_currentPenWidth ) / 2,
636 p2.y + (width - m_currentPenWidth) / 2 );
637 Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
638 offsetp1.x += ( width - m_currentPenWidth );
639 offsetp1.y += ( width - m_currentPenWidth );
640 offsetp2.x -= ( width - m_currentPenWidth );
641 offsetp2.y -= ( width - m_currentPenWidth );
642 Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
643 }
644}
645
646
647void PLOTTER::ThickCircle( const VECTOR2I& pos, int diametre, int width, OUTLINE_MODE tracemode,
648 void* aData )
649{
650 if( tracemode == FILLED )
651 {
652 Circle( pos, diametre, FILL_T::NO_FILL, width );
653 }
654 else
655 {
657 Circle( pos, diametre - width + m_currentPenWidth, FILL_T::NO_FILL, -1 );
658 Circle( pos, diametre + width - m_currentPenWidth, FILL_T::NO_FILL, -1 );
659 }
660}
661
662
663void PLOTTER::FilledCircle( const VECTOR2I& pos, int diametre, OUTLINE_MODE tracemode, void* aData )
664{
665 if( tracemode == FILLED )
666 {
667 Circle( pos, diametre, FILL_T::FILLED_SHAPE, 0 );
668 }
669 else
670 {
672 Circle( pos, diametre, FILL_T::NO_FILL, -1 );
673 }
674}
675
676
677void PLOTTER::PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int aWidth, void* aData )
678{
679 std::vector<VECTOR2I> cornerList;
680 cornerList.reserve( aCornerList.PointCount() );
681
682 for( int ii = 0; ii < aCornerList.PointCount(); ii++ )
683 cornerList.emplace_back( aCornerList.CPoint( ii ) );
684
685 if( aCornerList.IsClosed() && cornerList.front() != cornerList.back() )
686 cornerList.emplace_back( aCornerList.CPoint( 0 ) );
687
688 PlotPoly( cornerList, aFill, aWidth, aData );
689}
690
691
692void PLOTTER::Text( const VECTOR2I& aPos,
693 const COLOR4D& aColor,
694 const wxString& aText,
695 const EDA_ANGLE& aOrient,
696 const VECTOR2I& aSize,
697 enum GR_TEXT_H_ALIGN_T aH_justify,
698 enum GR_TEXT_V_ALIGN_T aV_justify,
699 int aPenWidth,
700 bool aItalic,
701 bool aBold,
702 bool aMultilineAllowed,
703 KIFONT::FONT* aFont,
704 const KIFONT::METRICS& aFontMetrics,
705 void* aData )
706{
708
709 SetColor( aColor );
710
711 if( aPenWidth == 0 && aBold ) // Use default values if aPenWidth == 0
712 aPenWidth = GetPenSizeForBold( std::min( aSize.x, aSize.y ) );
713
714 if( aPenWidth < 0 )
715 aPenWidth = -aPenWidth;
716
717 CALLBACK_GAL callback_gal( empty_opts,
718 // Stroke callback
719 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
720 {
721 SetCurrentLineWidth( aPenWidth );
722 MoveTo( aPt1 );
723 LineTo( aPt2 );
724 PenFinish();
725 },
726 // Polygon callback
727 [&]( const SHAPE_LINE_CHAIN& aPoly )
728 {
729 PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
730 } );
731
732 TEXT_ATTRIBUTES attributes;
733 attributes.m_Angle = aOrient;
734 attributes.m_StrokeWidth = aPenWidth;
735 attributes.m_Italic = aItalic;
736 attributes.m_Bold = aBold;
737 attributes.m_Halign = aH_justify;
738 attributes.m_Valign = aV_justify;
739 attributes.m_Size = aSize;
740
741 // if Size.x is < 0, the text is mirrored (we have no other param to know a text is mirrored)
742 if( attributes.m_Size.x < 0 )
743 {
744 attributes.m_Size.x = -attributes.m_Size.x;
745 attributes.m_Mirrored = true;
746 }
747
748 if( !aFont )
749 aFont = KIFONT::FONT::GetFont();
750
751 aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
752}
753
754void PLOTTER::PlotText( const VECTOR2I& aPos,
755 const COLOR4D& aColor,
756 const wxString& aText,
757 const TEXT_ATTRIBUTES& aAttributes,
758 KIFONT::FONT* aFont,
759 const KIFONT::METRICS& aFontMetrics,
760 void* aData )
761{
763
764 TEXT_ATTRIBUTES attributes = aAttributes;
765 int penWidth = attributes.m_StrokeWidth;
766
767 SetColor( aColor );
768 SetCurrentLineWidth( penWidth, aData );
769
770 if( penWidth == 0 && attributes.m_Bold ) // Use default values if aPenWidth == 0
771 penWidth = GetPenSizeForBold( std::min( attributes.m_Size.x, attributes.m_Size.y ) );
772
773 if( penWidth < 0 )
774 penWidth = -penWidth;
775
776 attributes.m_StrokeWidth = penWidth;
777
778 CALLBACK_GAL callback_gal( empty_opts,
779 // Stroke callback
780 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
781 {
782 MoveTo( aPt1 );
783 LineTo( aPt2 );
784 PenFinish();
785 },
786 // Polygon callback
787 [&]( const SHAPE_LINE_CHAIN& aPoly )
788 {
789 PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0, aData );
790 } );
791
792 if( !aFont )
793 aFont = KIFONT::FONT::GetFont();
794
795 aFont->Draw( &callback_gal, aText, aPos, attributes, aFontMetrics );
796}
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
Bezier curves to polygon converter.
Definition: bezier_curves.h:38
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
EDA_ANGLE NormalizeNegative()
Definition: eda_angle.h:238
double Sin() const
Definition: eda_angle.h:170
double Cos() const
Definition: eda_angle.h:189
VECTOR2I getCenter() const
Definition: eda_shape.cpp:752
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:796
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, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=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:258
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:132
virtual void ThickArc(const EDA_SHAPE &aArcShape, OUTLINE_MODE aTraceMode, void *aData, int aWidth)
Definition: plotter.cpp:597
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:623
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:647
static const unsigned MARKER_COUNT
Draw a marker (used for the drill map).
Definition: plotter.h:485
double GetDashGapLenIU(int aLineWidth) const
Definition: plotter.cpp:144
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:75
bool m_mirrorIsHorizontal
Definition: plotter.h:658
virtual void Arc(const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH)
Definition: plotter.cpp:150
bool m_plotMirror
Definition: plotter.h:656
virtual void FilledCircle(const VECTOR2I &pos, int diametre, OUTLINE_MODE tracemode, void *aData)
Definition: plotter.cpp:663
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:181
void MoveTo(const VECTOR2I &pos)
Definition: plotter.h:244
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:254
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:230
bool m_yaxisReversed
Definition: plotter.h:659
double m_iuPerDeviceUnit
Definition: plotter.h:653
VECTOR2I m_plotOffset
Definition: plotter.h:655
virtual VECTOR2D userToDeviceCoordinates(const VECTOR2I &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:91
virtual ~PLOTTER()
Definition: plotter.cpp:67
VECTOR2I m_paperSize
Definition: plotter.h:677
virtual VECTOR2D userToDeviceSize(const VECTOR2I &size)
Modify size according to the plotter scale factors (VECTOR2I version, returns a VECTOR2D).
Definition: plotter.cpp:116
void sketchOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, int aWidth)
Definition: plotter.cpp:501
char m_penState
Definition: plotter.h:668
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:667
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:645
void markerCircle(const VECTOR2I &pos, int radius)
Plot a circle centered on the position.
Definition: plotter.cpp:303
PLOTTER(const PROJECT *aProject=nullptr)
Definition: plotter.cpp:47
FILE * m_outputFile
Output file.
Definition: plotter.h:662
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:249
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:260
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont=nullptr, const KIFONT::METRICS &aFontMetrics=KIFONT::METRICS::Default(), void *aData=nullptr)
Definition: plotter.cpp:754
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:681
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:692
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:666
double m_IUsPerDecimil
Definition: plotter.h:651
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:148
bool m_colorMode
Definition: plotter.h:665
double GetDashMarkLenIU(int aLineWidth) const
Definition: plotter.cpp:138
virtual void SetColor(const COLOR4D &color)=0
wxString m_filename
Definition: plotter.h:672
Container for project specific data.
Definition: project.h:64
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.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:283
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
FILL_T
Definition: eda_shape.h:56
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:229
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:521
constexpr int sign(T val)
Definition: util.h:159
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
VECTOR2< double > VECTOR2D
Definition: vector2d.h:690