KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_textbox.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <advanced_config.h>
21#include <common.h>
22#include <pcb_edit_frame.h>
23#include <base_units.h>
24#include <bitmaps.h>
25#include <board.h>
27#include <core/mirror.h>
28#include <footprint.h>
29#include <pcb_textbox.h>
30#include <pcb_painter.h>
31#include <trigo.h>
32#include <string_utils.h>
34#include <geometry/shape_rect.h>
36#include <callback_gal.h>
38#include <macros.h>
39#include <core/ignore.h>
40#include <api/api_enums.h>
41#include <api/api_utils.h>
42#include <api/board/board_types.pb.h>
43#include <properties/property.h>
45
46
48 PCB_SHAPE( aParent, aType, SHAPE_T::RECTANGLE ),
50 m_borderEnabled( true ),
52{
55 SetMultilineAllowed( true );
56
57 int defaultMargin = GetLegacyTextMargin();
58 m_marginLeft = defaultMargin;
59 m_marginTop = defaultMargin;
60 m_marginRight = defaultMargin;
61 m_marginBottom = defaultMargin;
62}
63
64
68
69
70void PCB_TEXTBOX::CopyFrom( const BOARD_ITEM* aOther )
71{
72 wxCHECK( aOther && aOther->Type() == PCB_TEXTBOX_T, /* void */ );
73 *this = *static_cast<const PCB_TEXTBOX*>( aOther );
74}
75
76
77void PCB_TEXTBOX::Serialize( kiapi::board::types::BoardTextBox& boardText ) const
78{
79 using namespace kiapi::common::types;
80 using namespace kiapi::board;
82 boardText.mutable_id()->set_value( m_Uuid.AsStdString() );
83 boardText.set_locked( IsLocked() ? LockedState::LS_LOCKED : LockedState::LS_UNLOCKED );
84
85 TextBox& text = *boardText.mutable_textbox();
86
87 kiapi::common::PackVector2( *text.mutable_top_left(), GetPosition() );
88 kiapi::common::PackVector2( *text.mutable_bottom_right(), GetEnd() );
89 text.set_text( GetText().ToStdString() );
90
91 kiapi::common::PackTextAttributes( *text.mutable_attributes(), GetAttributes() );
92
93 text.set_border_enabled( IsBorderEnabled() );
94 text.mutable_margin_left()->set_value_nm( GetMarginLeft() );
95 text.mutable_margin_top()->set_value_nm( GetMarginTop() );
96 text.mutable_margin_right()->set_value_nm( GetMarginRight() );
97 text.mutable_margin_bottom()->set_value_nm( GetMarginBottom() );
98
99 boardText.set_knockout( IsKnockout() );
100 kiapi::common::PackStroke( *boardText.mutable_border_stroke(), GetStroke() );
101
102 if( FOOTPRINT* parent = GetParentFootprint() )
103 boardText.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
104 else if( const BOARD* board = GetBoard() )
105 boardText.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
106
107 kiapi::common::PackCustomProperties( boardText.mutable_custom_properties(), *this );
108}
109
110
111void PCB_TEXTBOX::Serialize( google::protobuf::Any& aContainer ) const
112{
113 kiapi::board::types::BoardTextBox boardText;
114 Serialize( boardText );
115
116 if( !aContainer.PackFrom( boardText ) )
117 wxFAIL_MSG( wxT( "Failed to pack PCB_TEXTBOX" ) );
118}
119
120
121bool PCB_TEXTBOX::Deserialize( const kiapi::board::types::BoardTextBox& boardText )
122{
123 using namespace kiapi::board;
124
125
126 SetUuidDirect( KIID( boardText.id().value() ) );
128 SetLocked( boardText.locked() == kiapi::common::types::LockedState::LS_LOCKED );
129
130 const kiapi::common::types::TextBox& text = boardText.textbox();
131
133 SetEnd( kiapi::common::UnpackVector2( text.bottom_right() ) );
134 SetText( wxString( text.text().c_str(), wxConvUTF8 ) );
135
136 if( text.has_attributes() )
137 {
139 kiapi::common::UnpackTextAttributes( attrs, text.attributes() );
140 SetAttributes( attrs );
141
142 // Handles setting shape to rectangle or polygon
143 SetTextAngle( attrs.m_Angle.GetAngle() );
144 }
145
146 if( text.has_margin_left() )
147 SetMarginLeft( text.margin_left().value_nm() );
148 if( text.has_margin_top() )
149 SetMarginTop( text.margin_top().value_nm() );
150 if( text.has_margin_right() )
151 SetMarginRight( text.margin_right().value_nm() );
152 if( text.has_margin_bottom() )
153 SetMarginBottom( text.margin_bottom().value_nm() );
154
155 SetBorderEnabled( text.border_enabled() );
156 SetIsKnockout( boardText.knockout() );
157
158 if( boardText.has_border_stroke() )
159 {
160 STROKE_PARAMS stroke;
161 kiapi::common::UnpackStroke( stroke, boardText.border_stroke() );
162 SetStroke( stroke );
163 }
164
165 kiapi::common::UnpackCustomProperties( boardText.custom_properties(), *this );
166
167 return true;
168}
169
170
171bool PCB_TEXTBOX::Deserialize( const google::protobuf::Any& aContainer )
172{
173 kiapi::board::types::BoardTextBox boardText;
174
175 if( !aContainer.UnpackTo( &boardText ) )
176 return false;
177
178 return Deserialize( boardText );
179}
180
181
182void PCB_TEXTBOX::StyleFromSettings( const BOARD_DESIGN_SETTINGS& aSettings, bool aCheckSide )
183{
184 PCB_SHAPE::StyleFromSettings( aSettings, aCheckSide );
185
186 SetTextSize( aSettings.GetTextSize( GetLayer() ) );
188 SetItalic( aSettings.GetTextItalic( GetLayer() ) );
189
190 if( GetParentFootprint() )
191 SetKeepUpright( aSettings.GetTextUpright( GetLayer() ) );
192
193 if( aCheckSide )
194 {
195 if( BOARD* board = GetBoard() )
196 SetMirrored( board->IsBackLayer( GetLayer() ) );
197 else
199 }
200}
201
202
204{
205 return KiROUND( GetStroke().GetWidth() / 2.0 ) + KiROUND( GetTextSize().y * 0.75 );
206}
207
208
210{
211 if( GetText().IsEmpty() )
212 return VECTOR2I( 0, 0 );
213
214 BOX2I textBox = GetTextBox( nullptr );
215
216 int textHeight = std::abs( textBox.GetHeight() );
217
218 if( GetTextAngle().IsHorizontal() )
219 textHeight += GetMarginTop() + GetMarginBottom();
220 else
221 textHeight += GetMarginLeft() + GetMarginRight();
222
223 // Only enforce minimum height. Width returns 0 so the user can freely shrink width
224 // (text rewraps) while height is constrained to fit the wrapped text content.
225 // GetTextBox returns dimensions in text-local coordinates. For 90/270 degree rotations,
226 // the text's natural height maps to screen x-axis.
227 EDA_ANGLE rotation = GetDrawRotation();
228
229 if( rotation == ANGLE_90 || rotation == ANGLE_270 )
230 return VECTOR2I( textHeight, 0 );
231
232 return VECTOR2I( 0, textHeight );
233}
234
235
237{
238 EDA_SHAPE::SetShape( aShape );
239 m_libShape = aShape;
240}
241
242
243std::vector<VECTOR2I> PCB_TEXTBOX::GetCorners() const
244{
246}
247
248
249std::vector<VECTOR2I> PCB_TEXTBOX::GetCornersInSequence( EDA_ANGLE angle ) const
250{
252 return EDA_SHAPE::GetCornersInSequence( angle );
253
254 const int left = std::min( m_start.x, m_end.x );
255 const int right = std::max( m_start.x, m_end.x );
256 const int top = std::min( m_start.y, m_end.y );
257 const int bottom = std::max( m_start.y, m_end.y );
258
259 const VECTOR2I center( ( left + right ) / 2, ( top + bottom ) / 2 );
260
261 std::vector<VECTOR2I> pts = {
262 VECTOR2I( left, top ),
263 VECTOR2I( right, top ),
264 VECTOR2I( right, bottom ),
265 VECTOR2I( left, bottom ),
266 };
267
268 angle.Normalize();
269
270 if( !angle.IsZero() )
271 {
272 for( VECTOR2I& p : pts )
273 RotatePoint( p, center, angle );
274 }
275
276 return pts;
277}
278
279
281{
282 EDA_ANGLE rotation = GetDrawRotation();
283
284 if( rotation == ANGLE_90 )
285 return VECTOR2I( GetStartX(), GetEndY() );
286 else if( rotation == ANGLE_180 )
287 return GetEnd();
288 else if( rotation == ANGLE_270 )
289 return VECTOR2I( GetEndX(), GetStartY() );
290 else
291 return GetStart();
292}
293
294
296{
297 EDA_ANGLE rotation = GetDrawRotation();
298
299 if( rotation == ANGLE_90 )
300 return VECTOR2I( GetEndX(), GetStartY() );
301 else if( rotation == ANGLE_180 )
302 return GetStart();
303 else if( rotation == ANGLE_270 )
304 return VECTOR2I( GetStartX(), GetEndY() );
305 else
306 return GetEnd();
307}
308
309
310void PCB_TEXTBOX::SetTop( int aVal )
311{
312 EDA_ANGLE rotation = GetDrawRotation();
313
314 if( rotation == ANGLE_90 || rotation == ANGLE_180 )
315 SetEndY( aVal );
316 else
317 SetStartY( aVal );
318}
319
320
322{
323 EDA_ANGLE rotation = GetDrawRotation();
324
325 if( rotation == ANGLE_90 || rotation == ANGLE_180 )
326 SetStartY( aVal );
327 else
328 SetEndY( aVal );
329}
330
331
332void PCB_TEXTBOX::SetLeft( int aVal )
333{
334 EDA_ANGLE rotation = GetDrawRotation();
335
336 if( rotation == ANGLE_180 || rotation == ANGLE_270 )
337 SetEndX( aVal );
338 else
339 SetStartX( aVal );
340}
341
342
343void PCB_TEXTBOX::SetRight( int aVal )
344{
345 EDA_ANGLE rotation = GetDrawRotation();
346
347 if( rotation == ANGLE_180 || rotation == ANGLE_270 )
348 SetStartX( aVal );
349 else
350 SetEndX( aVal );
351}
352
353
355{
356 if( const FOOTPRINT* fp = GetParentFootprint() )
357 {
358 EDA_ANGLE angle = m_libTextAngle.GetAngle() + fp->GetOrientation();
359 return angle.Normalized();
360 }
361
362 return m_libTextAngle.GetAngle();
363}
364
365
367{
368 EDA_ANGLE delta = aAngle.Normalized() - GetTextAngle();
370}
371
372
374{
375 return GetDrawPos( false );
376}
377
378
379VECTOR2I PCB_TEXTBOX::GetDrawPos( bool aIsFlipped ) const
380{
381 EDA_ANGLE drawAngle = GetDrawRotation();
382 std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle );
383 GR_TEXT_H_ALIGN_T horizontalAlignment = GetHorizJustify();
384 GR_TEXT_V_ALIGN_T verticalAlignment = GetVertJustify();
385 VECTOR2I textAnchor;
386 VECTOR2I offset;
387
388 // Calculate midpoints
389 VECTOR2I midTop = ( corners[0] + corners[1] ) / 2;
390 VECTOR2I midBottom = ( corners[3] + corners[2] ) / 2;
391 VECTOR2I midLeft = ( corners[0] + corners[3] ) / 2;
392 VECTOR2I midRight = ( corners[1] + corners[2] ) / 2;
393 VECTOR2I center = ( corners[0] + corners[1] + corners[2] + corners[3] ) / 4;
394
395 if( IsMirrored() != aIsFlipped )
396 {
397 switch( GetHorizJustify() )
398 {
399 case GR_TEXT_H_ALIGN_LEFT: horizontalAlignment = GR_TEXT_H_ALIGN_RIGHT; break;
400 case GR_TEXT_H_ALIGN_CENTER: horizontalAlignment = GR_TEXT_H_ALIGN_CENTER; break;
401 case GR_TEXT_H_ALIGN_RIGHT: horizontalAlignment = GR_TEXT_H_ALIGN_LEFT; break;
402 case GR_TEXT_H_ALIGN_INDETERMINATE: horizontalAlignment = GR_TEXT_H_ALIGN_INDETERMINATE; break;
403 }
404 }
405
406 wxASSERT_MSG( horizontalAlignment != GR_TEXT_H_ALIGN_INDETERMINATE
407 && verticalAlignment != GR_TEXT_V_ALIGN_INDETERMINATE,
408 wxS( "Indeterminate state legal only in dialogs. Horizontal and vertical alignment "
409 "must be set before calling PCB_TEXTBOX::GetDrawPos." ) );
410
411 if( horizontalAlignment == GR_TEXT_H_ALIGN_INDETERMINATE || verticalAlignment == GR_TEXT_V_ALIGN_INDETERMINATE )
412 {
413 return center;
414 }
415
416 if( horizontalAlignment == GR_TEXT_H_ALIGN_LEFT && verticalAlignment == GR_TEXT_V_ALIGN_TOP )
417 {
418 textAnchor = corners[0];
419 }
420 else if( horizontalAlignment == GR_TEXT_H_ALIGN_CENTER && verticalAlignment == GR_TEXT_V_ALIGN_TOP )
421 {
422 textAnchor = midTop;
423 }
424 else if( horizontalAlignment == GR_TEXT_H_ALIGN_RIGHT && verticalAlignment == GR_TEXT_V_ALIGN_TOP )
425 {
426 textAnchor = corners[1];
427 }
428 else if( horizontalAlignment == GR_TEXT_H_ALIGN_LEFT && verticalAlignment == GR_TEXT_V_ALIGN_CENTER )
429 {
430 textAnchor = midLeft;
431 }
432 else if( horizontalAlignment == GR_TEXT_H_ALIGN_CENTER && verticalAlignment == GR_TEXT_V_ALIGN_CENTER )
433 {
434 textAnchor = center;
435 }
436 else if( horizontalAlignment == GR_TEXT_H_ALIGN_RIGHT && verticalAlignment == GR_TEXT_V_ALIGN_CENTER )
437 {
438 textAnchor = midRight;
439 }
440 else if( horizontalAlignment == GR_TEXT_H_ALIGN_LEFT && verticalAlignment == GR_TEXT_V_ALIGN_BOTTOM )
441 {
442 textAnchor = corners[3];
443 }
444 else if( horizontalAlignment == GR_TEXT_H_ALIGN_CENTER && verticalAlignment == GR_TEXT_V_ALIGN_BOTTOM )
445 {
446 textAnchor = midBottom;
447 }
448 else if( horizontalAlignment == GR_TEXT_H_ALIGN_RIGHT && verticalAlignment == GR_TEXT_V_ALIGN_BOTTOM )
449 {
450 textAnchor = corners[2];
451 }
452
453 int marginLeft = GetMarginLeft();
454 int marginRight = GetMarginRight();
455 int marginTop = GetMarginTop();
456 int marginBottom = GetMarginBottom();
457
458 if( horizontalAlignment == GR_TEXT_H_ALIGN_LEFT )
459 offset.x = marginLeft;
460 else if( horizontalAlignment == GR_TEXT_H_ALIGN_RIGHT )
461 offset.x = -marginRight;
462
463 if( verticalAlignment == GR_TEXT_V_ALIGN_TOP )
464 offset.y = marginTop;
465 else if( verticalAlignment == GR_TEXT_V_ALIGN_BOTTOM )
466 offset.y = -marginBottom;
467
468 RotatePoint( offset, GetDrawRotation() );
469 return textAnchor + offset;
470}
471
472
473double PCB_TEXTBOX::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
474{
475 KIGFX::PCB_PAINTER& painter = static_cast<KIGFX::PCB_PAINTER&>( *aView->GetPainter() );
476 KIGFX::PCB_RENDER_SETTINGS& renderSettings = *painter.GetSettings();
477
478 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
479 {
480 // Hide shadow if the main layer is not shown
481 if( !aView->IsLayerVisibleCached( m_layer ) )
482 return LOD_HIDE;
483
484 // Hide shadow on dimmed tracks
485 if( renderSettings.GetHighContrast() )
486 {
487 if( m_layer != renderSettings.GetPrimaryHighContrastLayer() )
488 return LOD_HIDE;
489 }
490 }
491
492 return LOD_SHOW;
493}
494
495
496std::vector<int> PCB_TEXTBOX::ViewGetLayers() const
497{
500
501 return { GetLayer() };
502}
503
504
505wxString PCB_TEXTBOX::GetShownText( RESOLUTION_CONTEXT aContext, int aDepth ) const
506{
507 const FOOTPRINT* parentFootprint = GetParentFootprint();
508 const BOARD* board = GetBoard();
509
510 std::function<bool( wxString* )> resolver =
511 [&]( wxString* token ) -> bool
512 {
513 if( token->IsSameAs( wxT( "LAYER" ) ) )
514 {
515 *token = GetLayerName();
516 return true;
517 }
518
519 if( parentFootprint && parentFootprint->ResolveTextVar( token, aDepth + 1 ) )
520 return true;
521
522 if( board && board->ResolveTextVar( token, aDepth + 1 ) )
523 return true;
524
525 return false;
526 };
527
528 wxString text = EDA_TEXT::GetShownText( aContext, aDepth );
529
530 if( HasTextVars() && aContext != RAW_VALUE )
531 {
532 text = ResolveTextVars( text, &resolver, aDepth );
533 FinalizeTextVarExpansion( text, aContext );
534 }
535
536 KIFONT::FONT* font = GetDrawFont( nullptr );
537 EDA_ANGLE drawAngle = GetDrawRotation();
538 std::vector<VECTOR2I> corners = GetCornersInSequence( drawAngle );
539 int colWidth = ( corners[1] - corners[0] ).EuclideanNorm();
540
541 if( GetTextAngle().IsHorizontal() )
542 colWidth -= ( GetMarginLeft() + GetMarginRight() );
543 else
544 colWidth -= ( GetMarginTop() + GetMarginBottom() );
545
547
548 return text;
549}
550
551
552bool PCB_TEXTBOX::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
553{
554 return BOARD_ITEM::Matches( UnescapeString( GetText() ), aSearchData );
555}
556
557
558void PCB_TEXTBOX::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
559{
560 // Don't use GetShownText() here; we want to show the user the variable references
561 aList.emplace_back( _( "Text Box" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
562
563 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
564 aList.emplace_back( _( "Status" ), _( "Locked" ) );
565
566 aList.emplace_back( _( "Layer" ), GetLayerName() );
567 aList.emplace_back( _( "Mirror" ), IsMirrored() ? _( "Yes" ) : _( "No" ) );
568 aList.emplace_back( _( "Angle" ), wxString::Format( "%g", GetTextAngle().AsDegrees() ) );
569
570 aList.emplace_back( _( "Font" ), GetFont() ? GetFont()->GetName() : _( "Default" ) );
571
572 if( GetTextThickness() )
573 aList.emplace_back( _( "Text Thickness" ), aFrame->MessageTextFromValue( GetEffectiveTextPenWidth() ) );
574 else
575 aList.emplace_back( _( "Text Thickness" ), _( "Auto" ) );
576
577 aList.emplace_back( _( "Text Width" ), aFrame->MessageTextFromValue( GetTextWidth() ) );
578 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( GetTextHeight() ) );
579
580 aList.emplace_back( _( "Box Width" ), aFrame->MessageTextFromValue( std::abs( GetEnd().x - GetStart().x ) ) );
581
582 aList.emplace_back( _( "Box Height" ), aFrame->MessageTextFromValue( std::abs( GetEnd().y - GetStart().y ) ) );
583
584 m_stroke.GetMsgPanelInfo( aFrame, aList );
585}
586
587
588void PCB_TEXTBOX::Move( const VECTOR2I& aMoveVector )
589{
590 PCB_SHAPE::Move( aMoveVector );
591 EDA_TEXT::Offset( aMoveVector );
592}
593
594
596{
598
599 if( const FOOTPRINT* fp = GetParentFootprint() )
600 {
601 const TRANSFORM_TRS& xf = fp->GetTransform();
602 return { KiROUND( libSize.x * std::abs( xf.GetScaleX() ) ), KiROUND( libSize.y * std::abs( xf.GetScaleY() ) ) };
603 }
604
605 return libSize;
606}
607
608
609void PCB_TEXTBOX::SetTextSize( VECTOR2I aNewSize, bool aEnforceMinTextSize )
610{
611 if( const FOOTPRINT* fp = GetParentFootprint() )
612 {
613 const TRANSFORM_TRS& xf = fp->GetTransform();
614 aNewSize = { KiROUND( aNewSize.x / std::abs( xf.GetScaleX() ) ),
615 KiROUND( aNewSize.y / std::abs( xf.GetScaleY() ) ) };
616 }
617
618 EDA_TEXT::SetTextSize( aNewSize, aEnforceMinTextSize );
619}
620
621
623{
624 int libThickness = EDA_TEXT::GetTextThickness();
625
626 if( const FOOTPRINT* fp = GetParentFootprint() )
627 {
628 const TRANSFORM_TRS& xf = fp->GetTransform();
629 const double factor = ( std::abs( xf.GetScaleX() ) + std::abs( xf.GetScaleY() ) ) * 0.5;
630 return KiROUND( libThickness * factor );
631 }
632
633 return libThickness;
634}
635
636
638{
639 if( const FOOTPRINT* fp = GetParentFootprint() )
640 {
641 const TRANSFORM_TRS& xf = fp->GetTransform();
642 const double factor = ( std::abs( xf.GetScaleX() ) + std::abs( xf.GetScaleY() ) ) * 0.5;
643 aWidth = KiROUND( aWidth / factor );
644 }
645
647}
648
649
650void PCB_TEXTBOX::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
651{
652 // Slide the axis-aligned box, rotation lives in the text angle.
653 const VECTOR2D oldCenter( ( m_start.x + m_end.x ) * 0.5, ( m_start.y + m_end.y ) * 0.5 );
654 VECTOR2D newCenter = oldCenter;
655 RotatePoint( newCenter, VECTOR2D( aRotCentre.x, aRotCentre.y ), aAngle );
656
657 const VECTOR2I delta( KiROUND( newCenter.x - oldCenter.x ), KiROUND( newCenter.y - oldCenter.y ) );
660
662
663 EDA_ANGLE newAbs = ( GetTextAngle() + aAngle ).Normalize();
664 EDA_TEXT::SetTextAngle( newAbs );
665
666 if( const FOOTPRINT* fp = GetParentFootprint() )
667 m_libTextAngle = newAbs - fp->GetOrientation();
668 else
669 m_libTextAngle = newAbs;
670}
671
672
673void PCB_TEXTBOX::Mirror( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
674{
675 Mirror( MIRROR_AXIS( aCentre, aFlipDirection ) );
676}
677
678
679void PCB_TEXTBOX::Mirror( const SEG& aAxis )
680{
681 // the position and justification are mirrored, but not the text itself
682
684 {
685 const VECTOR2I centre( ( m_start.x + m_end.x ) / 2, ( m_start.y + m_end.y ) / 2 );
686 const VECTOR2I delta = aAxis.ReflectPoint( centre ) - centre;
687
690
692 }
693 else
694 {
695 // A polygon is the drawn box already, so its vertices are what gets mirrored.
696 PCB_SHAPE::Mirror( aAxis );
697 }
698
699 const EDA_ANGLE axisAngle = -EDA_ANGLE( aAxis.B - aAxis.A );
700 const EDA_ANGLE newAngle = GetTextAngle().Reflect( axisAngle );
701
702 if( const FOOTPRINT* fp = GetParentFootprint() )
703 SetLibTextAngle( newAngle - fp->GetOrientation() );
704 else
705 SetLibTextAngle( newAngle );
706
708}
709
710
711void PCB_TEXTBOX::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
712{
713 PCB_SHAPE::Flip( aCentre, aFlipDirection );
714
715 // A flip changes the side it is read from, so add a half turn on top of the reflection.
716 const EDA_ANGLE axis = MIRROR_AXIS( aFlipDirection );
717 m_libTextAngle = m_libTextAngle.Reflect( axis ) + ANGLE_180;
718
720
721 if( IsSideSpecific() )
723}
724
725
727{
728 if( const FOOTPRINT* fp = GetParentFootprint(); fp && GetLibraryShape() == SHAPE_T::RECTANGLE )
729 {
730 const TRANSFORM_TRS& xform = fp->GetTransform();
732
733 const VECTOR2I libCenter( ( m_libStart.x + m_libEnd.x ) / 2, ( m_libStart.y + m_libEnd.y ) / 2 );
734 const int libHalfW = std::abs( m_libEnd.x - m_libStart.x ) / 2;
735 const int libHalfH = std::abs( m_libEnd.y - m_libStart.y ) / 2;
736
737 const VECTOR2I newCenter = xform.Apply( libCenter );
738 const int newHalfW = std::abs( KiROUND( libHalfW * xform.GetScaleX() ) );
739 const int newHalfH = std::abs( KiROUND( libHalfH * xform.GetScaleY() ) );
740
741 EDA_SHAPE::SetStart( VECTOR2I( newCenter.x - newHalfW, newCenter.y - newHalfH ) );
742 EDA_SHAPE::SetEnd( VECTOR2I( newCenter.x + newHalfW, newCenter.y + newHalfH ) );
743 }
744 else
745 {
747 }
748
752}
753
754
756{
757 const FOOTPRINT* fp = GetParentFootprint();
758
759 // Only the axis-aligned rectangle case needs the textbox-specific inverse.
760 // Poly textboxes and standalone (non-FP) boxes use the base shape mapping.
761 if( !fp || GetShape() != SHAPE_T::RECTANGLE )
762 {
764 return;
765 }
766
767 const TRANSFORM_TRS& xform = fp->GetTransform();
768
769 const VECTOR2I boardCenter( ( m_start.x + m_end.x ) / 2, ( m_start.y + m_end.y ) / 2 );
770 const int boardHalfW = std::abs( m_end.x - m_start.x ) / 2;
771 const int boardHalfH = std::abs( m_end.y - m_start.y ) / 2;
772
773 const VECTOR2I libCenter = xform.InverseApply( boardCenter );
774 const int libHalfW = std::abs( KiROUND( boardHalfW / xform.GetScaleX() ) );
775 const int libHalfH = std::abs( KiROUND( boardHalfH / xform.GetScaleY() ) );
776
777 m_libStart = VECTOR2I( libCenter.x - libHalfW, libCenter.y - libHalfH );
778 m_libEnd = VECTOR2I( libCenter.x + libHalfW, libCenter.y + libHalfH );
779}
780
781
782void PCB_TEXTBOX::OnFootprintRescaled( double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I& aAnchor,
783 const EDA_ANGLE& aParentRotate )
784{
786}
787
788
790{
791 BOX2I bbox;
792
793 for( const VECTOR2I& pt : GetCorners() )
794 bbox.Merge( pt );
795
796 bbox.Inflate( std::max( 0, GetWidth() ) / 2 );
797 bbox.Normalize();
798
799 return bbox;
800}
801
802
803bool PCB_TEXTBOX::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
804{
806
807 rect.Inflate( aAccuracy );
808
809 return rect.Contains( aPosition );
810}
811
812
813bool PCB_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
814{
815 BOX2I rect = aRect;
816
817 rect.Inflate( aAccuracy );
818
819 if( aContained )
820 return rect.Contains( GetBoundingBox() );
821
822 return rect.Intersects( GetBoundingBox() );
823}
824
825
826bool PCB_TEXTBOX::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
827{
828 return PCB_SHAPE::HitTest( aPoly, aContained );
829}
830
831
832wxString PCB_TEXTBOX::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
833{
834 return wxString::Format( _( "PCB text box '%s' on %s" ),
836 GetLayerName() );
837}
838
839
844
845
847{
848 return new PCB_TEXTBOX( *this );
849}
850
851
853{
854 wxASSERT( aImage->Type() == PCB_TEXTBOX_T );
855
856 std::swap( *( (PCB_TEXTBOX*) this ), *( (PCB_TEXTBOX*) aImage ) );
857}
858
859
860std::shared_ptr<SHAPE> PCB_TEXTBOX::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash,
861 DRC_CONSTRAINT_T aUsage ) const
862{
863 std::shared_ptr<SHAPE_COMPOUND> shape = GetEffectiveTextShape();
864
865 if( PCB_SHAPE::GetStroke().GetWidth() >= 0 )
866 shape->AddShape( PCB_SHAPE::GetEffectiveShape( aLayer, aFlash, aUsage ) );
867
868 return shape;
869}
870
871
873{
874 // Build a PCB_SHAPE type POLYGON of the TEXTBOX, according to the box shape and the textbox rotation
876 dummy.SetWidth( GetBorderWidth() );
877 dummy.SetStroke( GetStroke() );
878 dummy.SetLayer( GetLayer() );
879 std::vector<VECTOR2I> poly = GetCorners(); // Already rotated
880 dummy.SetPolyPoints( poly );
881
882 return dummy;
883}
884
885
886void PCB_TEXTBOX::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, int aClearance, int aMaxError,
887 ERROR_LOC aErrorLoc ) const
888{
890 KIFONT::FONT* font = GetDrawFont( nullptr );
891 int penWidth = GetEffectiveTextPenWidth();
893 wxString shownText = GetShownText( FOR_CANVAS );
894
895 // The polygonal shape of a text can have many basic shapes, so combining these shapes can
896 // be very useful to create a final shape with a lot less vertices to speedup calculations.
897 // Simplify shapes is not usually always efficient, but in this case it is.
898 SHAPE_POLY_SET textShape;
899
900 CALLBACK_GAL callback_gal(
901 empty_opts,
902 // Stroke callback
903 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2 )
904 {
905 TransformOvalToPolygon( textShape, aPt1, aPt2, penWidth, aMaxError, aErrorLoc );
906 },
907 // Triangulation callback
908 [&]( const VECTOR2I& aPt1, const VECTOR2I& aPt2, const VECTOR2I& aPt3 )
909 {
910 textShape.NewOutline();
911
912 for( const VECTOR2I& point : { aPt1, aPt2, aPt3 } )
913 textShape.Append( point.x, point.y );
914 } );
915
916 if( auto* cache = GetRenderCache( font, shownText ) )
917 callback_gal.DrawGlyphs( *cache );
918 else
919 font->Draw( &callback_gal, shownText, GetDrawPos(), attrs, GetFontMetrics() );
920
921 textShape.Simplify();
922
923 if( IsKnockout() )
924 {
925 SHAPE_POLY_SET finalPoly;
926
927 TransformShapeToPolygon( finalPoly, GetLayer(), aClearance, aMaxError, aErrorLoc );
928
929 // A TEXTBOX can be rotated, but TransformShapeToPolygon does not handle the text rotation.
930 // so rotate the finalPoly by the text rotation
931 EDA_ANGLE angle = GetTextAngle();
932
933 if( angle != ANGLE_0 )
934 finalPoly.Rotate( angle, GetCenter() );
935
936 finalPoly.BooleanSubtract( textShape );
937
938 aBuffer.Append( finalPoly );
939 }
940 else
941 {
942 if( aClearance > 0 || aErrorLoc == ERROR_OUTSIDE )
943 {
944 if( aErrorLoc == ERROR_OUTSIDE )
945 aClearance += aMaxError;
946
947 textShape.Inflate( aClearance, CORNER_STRATEGY::ROUND_ALL_CORNERS, aMaxError, true );
948 }
949
950 aBuffer.Append( textShape );
951 }
952}
953
954
955double PCB_TEXTBOX::GetCoverageArea( int aTextMargin ) const
956{
957 SHAPE_POLY_SET poly;
958 TransformTextToPolySet( poly, aTextMargin, ARC_LOW_DEF, ERROR_INSIDE );
959 return polygonArea( poly );
960}
961
962
963void PCB_TEXTBOX::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError,
964 ERROR_LOC aErrorLoc, bool aIgnoreLineWidth ) const
965{
966 // Don't use PCB_SHAPE::TransformShapeToPolygon. We want to treat the textbox as filled even
967 // if there's no background colour.
968
969 int width = GetWidth() + ( 2 * aClearance );
970
972 {
973 std::vector<VECTOR2I> pts = GetRectCorners();
974
975 aBuffer.NewOutline();
976
977 for( const VECTOR2I& pt : pts )
978 aBuffer.Append( pt );
979
980 if( m_borderEnabled && width > 0 )
981 {
982 // Add in segments
983 TransformOvalToPolygon( aBuffer, pts[0], pts[1], width, aMaxError, aErrorLoc );
984 TransformOvalToPolygon( aBuffer, pts[1], pts[2], width, aMaxError, aErrorLoc );
985 TransformOvalToPolygon( aBuffer, pts[2], pts[3], width, aMaxError, aErrorLoc );
986 TransformOvalToPolygon( aBuffer, pts[3], pts[0], width, aMaxError, aErrorLoc );
987 }
988 }
989 else if( GetShape() == SHAPE_T::POLY ) // Non-cardinally-rotated rect
990 {
991 aBuffer.NewOutline();
992
993 const SHAPE_LINE_CHAIN& poly = GetPolyShape().Outline( 0 );
994
995 for( int ii = 0; ii < poly.PointCount(); ++ii )
996 aBuffer.Append( poly.GetPoint( ii ) );
997
998 if( m_borderEnabled && width > 0 )
999 {
1000 for( int ii = 0; ii < poly.SegmentCount(); ++ii )
1001 {
1002 const SEG& seg = poly.GetSegment( ii );
1003 TransformOvalToPolygon( aBuffer, seg.A, seg.B, width, aMaxError, aErrorLoc );
1004 }
1005 }
1006 }
1007}
1008
1009
1011{
1012 return m_borderEnabled;
1013}
1014
1015
1017{
1018 m_borderEnabled = enabled;
1019}
1020
1021
1022void PCB_TEXTBOX::SetBorderWidth( const int aSize )
1023{
1024 m_stroke.SetWidth( aSize );
1025}
1026
1027
1028bool PCB_TEXTBOX::operator==( const BOARD_ITEM& aBoardItem ) const
1029{
1030 if( aBoardItem.Type() != Type() )
1031 return false;
1032
1033 const PCB_TEXTBOX& other = static_cast<const PCB_TEXTBOX&>( aBoardItem );
1034
1035 return *this == other;
1036}
1037
1038
1039bool PCB_TEXTBOX::operator==( const PCB_TEXTBOX& aOther ) const
1040{
1041 return m_borderEnabled == aOther.m_borderEnabled && EDA_TEXT::operator==( aOther )
1042 && PCB_SHAPE::operator==( static_cast<const PCB_SHAPE&>( aOther ) );
1043}
1044
1045
1046double PCB_TEXTBOX::Similarity( const BOARD_ITEM& aBoardItem ) const
1047{
1048 if( aBoardItem.Type() != Type() )
1049 return 0.0;
1050
1051 const PCB_TEXTBOX& other = static_cast<const PCB_TEXTBOX&>( aBoardItem );
1052
1053 double similarity = 1.0;
1054
1055 if( m_borderEnabled != other.m_borderEnabled )
1056 similarity *= 0.9;
1057
1058 if( GetMarginLeft() != other.GetMarginLeft() )
1059 similarity *= 0.9;
1060
1061 if( GetMarginTop() != other.GetMarginTop() )
1062 similarity *= 0.9;
1063
1064 if( GetMarginRight() != other.GetMarginRight() )
1065 similarity *= 0.9;
1066
1067 if( GetMarginBottom() != other.GetMarginBottom() )
1068 similarity *= 0.9;
1069
1070 similarity *= EDA_TEXT::Similarity( other );
1071
1072 return similarity;
1073}
1074
1075
1076static struct PCB_TEXTBOX_DESC
1077{
1079 {
1081
1082 if( lineStyleEnum.Choices().GetCount() == 0 )
1083 {
1084 lineStyleEnum.Map( LINE_STYLE::SOLID, _HKI( "Solid" ) )
1085 .Map( LINE_STYLE::DASH, _HKI( "Dashed" ) )
1086 .Map( LINE_STYLE::DOT, _HKI( "Dotted" ) )
1087 .Map( LINE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
1088 .Map( LINE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
1089 }
1090
1099
1100 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Shape" ) );
1101 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start X" ) );
1102 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Start Y" ) );
1103 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End X" ) );
1104 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "End Y" ) );
1105 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Width" ) );
1106 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Height" ) );
1107 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Width" ) );
1108 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Style" ) );
1109 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Filled" ) );
1110 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Line Color" ) );
1111 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_SHAPE ), _HKI( "Corner Radius" ) );
1112
1113 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Color" ) );
1114
1115 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask" ) );
1116 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( PCB_SHAPE ), _HKI( "Soldermask Margin Override" ) );
1117
1118 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, bool, BOARD_ITEM>( _HKI( "Knockout" ),
1120 _HKI( "Text Properties" ) )
1121 .SetIsCopyable();
1122
1123 const wxString borderProps = _( "Border Properties" );
1124
1125 void ( PCB_TEXTBOX::*lineStyleSetter )( LINE_STYLE ) = &PCB_TEXTBOX::SetLineStyle;
1126 LINE_STYLE ( PCB_TEXTBOX::*lineStyleGetter )() const = &PCB_TEXTBOX::GetLineStyle;
1127
1128 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, bool>( _HKI( "Border" ),
1130 borderProps )
1131 .SetIsCopyable();
1132
1133 propMgr.AddProperty( new PROPERTY_ENUM<PCB_TEXTBOX, LINE_STYLE>( _HKI( "Border Style" ),
1134 lineStyleSetter, lineStyleGetter ),
1135 borderProps )
1136 .SetIsCopyable();
1137
1138 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, int>( _HKI( "Border Width" ),
1140 borderProps )
1141 .SetIsCopyable();
1142
1143 const wxString marginProps = _( "Margins" );
1144
1145 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, int>( _HKI( "Margin Left" ),
1147 marginProps )
1148 .SetIsCopyable();
1149 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, int>( _HKI( "Margin Top" ),
1151 marginProps )
1152 .SetIsCopyable();
1153 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, int>( _HKI( "Margin Right" ),
1155 marginProps )
1156 .SetIsCopyable();
1157 propMgr.AddProperty( new PROPERTY<PCB_TEXTBOX, int>( _HKI( "Margin Bottom" ),
1159 marginProps )
1160 .SetIsCopyable();
1161
1162 propMgr.Mask( TYPE_HASH( PCB_TEXTBOX ), TYPE_HASH( EDA_TEXT ), _HKI( "Hyperlink" ) );
1163 }
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
Definition api_enums.cpp:56
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_OUTSIDE
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
constexpr int ARC_LOW_DEF
Definition base_units.h:143
BITMAPS
A list of all bitmap identifiers.
SEG MIRROR_AXIS(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Definition board_item.h:85
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
Container for design settings for a BOARD object.
bool GetTextUpright(PCB_LAYER_ID aLayer) const
int GetTextThickness(PCB_LAYER_ID aLayer) const
Return the default text thickness from the layer class for the given layer.
bool GetTextItalic(PCB_LAYER_ID aLayer) const
VECTOR2I GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:101
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
Definition board_item.h:441
static double polygonArea(SHAPE_POLY_SET &aPolySet)
Area of aPolySet with every contour closed first, holes subtracted.
PCB_LAYER_ID m_layer
Definition board_item.h:625
virtual bool IsKnockout() const
Definition board_item.h:437
bool IsLocked() const override
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:438
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
const KIFONT::METRICS & GetFontMetrics() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
bool IsSideSpecific() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr size_type GetHeight() const
Definition box2.h:218
EDA_ANGLE Normalize()
Definition eda_angle.h:228
bool IsZero() const
Definition eda_angle.h:135
EDA_ANGLE Reflect(const EDA_ANGLE &aAxisAngle) const
Reflection, over a line with direction aAxisAngle, of the turn this angle stores.
Definition eda_angle.h:331
EDA_ANGLE Normalized() const
Definition eda_angle.h:241
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:484
EDA_ANGLE GetAngle() const
Definition eda_angle.h:557
SHAPE_T m_shape
Definition eda_shape.h:754
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:338
void SetStartX(int x)
Definition eda_shape.h:302
int GetStartY() const
Definition eda_shape.h:285
void SetEndY(int aY)
Definition eda_shape.h:345
int GetEndX() const
Definition eda_shape.h:336
void SetLineStyle(const LINE_STYLE aStyle)
void SetStartY(int y)
Definition eda_shape.h:295
SHAPE_POLY_SET & GetPolyShape()
virtual std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const
SHAPE_T GetShape() const
Definition eda_shape.h:178
int GetEndY() const
Definition eda_shape.h:335
void SetEndX(int aX)
Definition eda_shape.h:352
VECTOR2I m_start
Definition eda_shape.h:769
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
LINE_STYLE GetLineStyle() const
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
virtual void SetShape(SHAPE_T aShape)
Definition eda_shape.h:177
std::vector< VECTOR2I > GetRectCorners() const
int GetStartX() const
Definition eda_shape.h:286
VECTOR2I m_end
Definition eda_shape.h:770
STROKE_PARAMS m_stroke
Definition eda_shape.h:755
virtual void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:288
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual VECTOR2I GetTextSize() const
Definition eda_text.h:301
bool IsItalic() const
Definition eda_text.h:200
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:513
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual int GetTextHeight() const
Definition eda_text.h:307
KIFONT::FONT * GetFont() const
Definition eda_text.h:286
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:395
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:355
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition eda_text.cpp:684
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:425
BOX2I GetTextBox(const RENDER_SETTINGS *aSettings, int aLine=-1) const
Useful in multiline texts to calculate the full text or a line area (for zones filling,...
Definition eda_text.cpp:755
virtual wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition eda_text.h:128
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
virtual void Offset(const VECTOR2I &aOffset)
Definition eda_text.cpp:576
virtual int GetTextWidth() const
Definition eda_text.h:304
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:648
bool HasTextVars() const
Indicates the ShownText has text var references which need to be processed.
Definition eda_text.h:139
EDA_TEXT(const EDA_IU_SCALE &aIuScale, const wxString &aText=wxEmptyString)
Definition eda_text.cpp:98
virtual void ClearBoundingBoxCache()
Definition eda_text.cpp:676
double Similarity(const EDA_TEXT &aOther) const
virtual void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition eda_text.cpp:251
virtual void ClearRenderCache()
Definition eda_text.cpp:670
const TEXT_ATTRIBUTES & GetAttributes() const
Definition eda_text.h:270
bool IsMirrored() const
Definition eda_text.h:229
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
std::shared_ptr< SHAPE_COMPOUND > GetEffectiveTextShape(bool aTriangulate=true, const BOX2I &aBBox=BOX2I(), const EDA_ANGLE &aAngle=ANGLE_0) const
Build a list of segments (SHAPE_SEGMENT) to describe a text shape.
bool IsBold() const
Definition eda_text.h:215
void SetKeepUpright(bool aKeepUpright)
Definition eda_text.cpp:387
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual int GetTextThickness() const
Definition eda_text.h:159
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:269
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
Definition eda_text.cpp:291
bool operator==(const EDA_TEXT &aRhs) const
Definition eda_text.h:444
void SetMultilineAllowed(bool aAllow)
Definition eda_text.cpp:363
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:817
static ENUM_MAP< T > & Instance()
Definition property.h:811
wxPGChoices & Choices()
Definition property.h:862
const TRANSFORM_TRS & GetTransform() const
Definition footprint.h:395
bool ResolveTextVar(wxString *aToken, int aDepth=0) const
Resolve any references to system tokens supported by the component.
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:94
void Draw(KIGFX::GAL *aGal, const wxString &aText, const VECTOR2I &aPosition, const VECTOR2I &aCursor, const TEXT_ATTRIBUTES &aAttributes, const METRICS &aFontMetrics, std::optional< VECTOR2I > aMousePos=std::nullopt, wxString *aActiveUrl=nullptr) const
Draw a string.
Definition font.cpp:243
void LinebreakText(wxString &aText, int aColumnWidth, const VECTOR2I &aGlyphSize, int aThickness, bool aBold, bool aItalic) const
Insert characters into text to ensure that no lines are wider than aColumnWidth.
Definition font.cpp:612
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:94
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
Definition view_item.h:176
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Definition view_item.h:181
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
bool IsLayerVisibleCached(int aLayer) const
Definition view.h:472
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
Definition kiid.h:46
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
virtual void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
VECTOR2I m_libEnd
Definition pcb_shape.h:388
virtual void syncLibCoords()
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:80
PCB_SHAPE(BOARD_ITEM *aParent, KICAD_T aItemType, SHAPE_T aShapeType)
SHAPE_T m_libShape
Definition pcb_shape.h:406
int GetWidth() const override
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition pcb_shape.h:162
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_shape.h:77
SHAPE_T GetLibraryShape() const
Definition pcb_shape.h:236
void SetEnd(const VECTOR2I &aEnd) override
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool operator==(const PCB_SHAPE &aShape) const
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Make a set of SHAPE objects representing the PCB_SHAPE.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
STROKE_PARAMS GetStroke() const override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
Definition pcb_shape.h:195
void SetStart(const VECTOR2I &aStart) override
void SetStroke(const STROKE_PARAMS &aStroke) override
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
VECTOR2I m_libStart
Definition pcb_shape.h:387
VECTOR2I GetPosition() const override
Definition pcb_shape.h:78
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:70
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Test if aPosition is inside or on the boundary of this item.
virtual void swapData(BOARD_ITEM *aImage) override
void SetBorderWidth(const int aSize)
double Similarity(const BOARD_ITEM &aBoardItem) const override
Return a measure of how likely the other object is to represent the same object.
bool IsBorderEnabled() const
Tests whether the border is disabled, as configured by the stroke.
double GetCoverageArea(int aTextMargin) const override
Return the board area this item covers, used to rank candidates under the cursor so a click on a smal...
void SetLibTextAngle(const EDA_ANGLE &aAngle)
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
int GetMarginBottom() const
EDA_ANGLE GetTextAngle() const override
PCB_TEXTBOX(BOARD_ITEM *aParent, KICAD_T aType=PCB_TEXTBOX_T)
int GetTextThickness() const override
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the shape to a closed polygon.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
bool m_borderEnabled
Controls drawing the border (as defined by the stroke members)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void SetBorderEnabled(bool enabled)
Disables the border, this is done by changing the stroke internally.
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
VECTOR2I GetMinSize() const
Return the minimum height needed to contain the textbox's wrapped text content plus margins.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
VECTOR2I GetTextSize() const override
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
void SetShape(SHAPE_T aShape) override
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const override
Compare the item against the search criteria in aSearchData.
VECTOR2I GetDrawPos() const override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void SetMarginTop(int aTop)
void SetLeft(int aVal) override
int GetMarginLeft() const
EDA_ORIENTATION m_libTextAngle
void SetMarginLeft(int aLeft)
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
void SetMarginBottom(int aBottom)
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const override
int GetMarginRight() const
void SetRight(int aVal) override
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
void SetTop(int aVal) override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetMarginTop() const
void SetTextAngle(const EDA_ANGLE &aAngle) override
bool operator==(const PCB_TEXTBOX &aOther) const
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetMarginRight(int aRight)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
int GetLegacyTextMargin() const
void syncLibCoords() override
void SetBottom(int aVal) override
PCB_SHAPE GetPolygonalBoxShape() const
VECTOR2I GetTopLeft() const override
VECTOR2I GetBotRight() const override
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
void CopyFrom(const BOARD_ITEM *aOther) override
int GetBorderWidth() const
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
std::vector< VECTOR2I > GetCorners() const override
Return 4 corners for a rectangle or rotated rectangle (stored as a poly).
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &aSettings, bool aCheckSide) override
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
Definition property.h:388
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Definition seg.h:38
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition seg.cpp:630
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual const SEG GetSegment(int aIndex) const override
int SegmentCount() const
Return the number of segments in this line chain.
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
Simple container to manage line stroke parameters.
EDA_ORIENTATION m_Angle
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
double GetScaleX() const
VECTOR2I Apply(const VECTOR2I &aPoint) const
double GetScaleY() const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void FinalizeTextVarExpansion(wxString &aText, RESOLUTION_CONTEXT aContext)
Definition common.cpp:88
wxString ResolveTextVars(const wxString &aSource, const std::function< bool(wxString *)> *aResolver, int &aDepth)
Multi-pass text variable expansion and math expression evaluation.
Definition common.cpp:333
RESOLUTION_CONTEXT
Definition common.h:91
@ FOR_GUI
Definition common.h:93
@ FOR_CANVAS
Definition common.h:92
@ RAW_VALUE
Definition common.h:98
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
static std::string ToStdString(const wxString &aStr)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:477
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:476
#define PCB_EDIT_FRAME_NAME
SHAPE_T
Definition eda_shape.h:55
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
a few functions useful in geometry calculations.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:180
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:303
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
This file contains miscellaneous commonly used macros and functions.
FLIP_DIRECTION
Definition mirror.h:26
KICOMMON_API wxString EllipsizeMenuText(const wxString &aString)
Ellipsize text (at the end) to be no more than 36 characters.
KICOMMON_API wxString EllipsizeStatusText(wxWindow *aWindow, const wxString &aString)
Ellipsize text (at the end) to be no more than 1/3 of the window width.
KICOMMON_API void UnpackStroke(STROKE_PARAMS &aOutput, const types::StrokeAttributes &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API VECTOR2I UnpackVector2(const types::Vector2 &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackVector2(types::Vector2 &aOutput, const VECTOR2I &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackStroke(types::StrokeAttributes &aOutput, const STROKE_PARAMS &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
void PackTextAttributes(types::TextAttributes &aOutput, const TEXT_ATTRIBUTES &aInput, const EDA_IU_SCALE &aScale)
void UnpackTextAttributes(TEXT_ATTRIBUTES &aOutput, const types::TextAttributes &aInput, const EDA_IU_SCALE &aScale)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
#define _HKI(x)
Definition page_info.cpp:40
static struct PCB_TEXTBOX_DESC _PCB_TEXTBOX_DESC
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
LINE_STYLE
Dashed line types.
KIBIS top(path, &reporter)
VECTOR2I center
int delta
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_H_ALIGN_INDETERMINATE
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_INDETERMINATE
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
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:227
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)