KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_barcode.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) 2020 Thomas Pointhuber <[email protected]>
5 * Copyright (C) 2020 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <core/type_helpers.h>
22#include <bitmaps.h>
23#include <gr_basic.h>
24#include <macros.h>
25#include <pcb_edit_frame.h>
26#include <richio.h>
27#include <trigo.h>
28
29#include <base_units.h>
30#include <api/api_enums.h>
31#include <api/board/board_types.pb.h>
32#include <pcb_barcode.h>
33#include <board.h>
34#include <footprint.h>
36#include <pcb_text.h>
37#include <view/view.h>
38#include <math/util.h> // for KiROUND
40#include <wx/log.h>
41#include <pgm_base.h>
44#include <scoped_set_reset.h>
45#include <stdexcept>
46#include <utility>
47#include <algorithm>
48#include <api/api_utils.h>
49#include <footprint.h>
50
51#include <backend/zint.h>
53#include <hash.h>
54#include <google/protobuf/any.pb.h>
55#include <properties/property.h>
57
58constexpr int ECI_UTF8 = 26;
59
61 BOARD_ITEM( aParent, PCB_BARCODE_T ),
62 m_width( pcbIUScale.mmToIU( 40 ) ),
63 m_height( pcbIUScale.mmToIU( 40 ) ),
64 m_libPos( 0, 0 ),
65 m_text( this ),
69{
71}
72
73
77
78
80 BOARD_ITEM( aOther ),
81 m_width( aOther.m_width ),
82 m_height( aOther.m_height ),
83 m_libPos( aOther.m_libPos ),
84 m_margin( aOther.m_margin ),
85 m_text( aOther.m_text ),
86 m_kind( aOther.m_kind ),
87 m_libAngle( aOther.m_libAngle ),
89{
90 m_text.SetParent( this );
91}
92
93
95{
96 if( this != &aOther )
97 {
98 BOARD_ITEM::operator=( aOther );
99
100 m_width = aOther.m_width;
101 m_height = aOther.m_height;
102 m_libPos = aOther.m_libPos;
103 m_margin = aOther.m_margin;
104 m_text = aOther.m_text;
105 m_kind = aOther.m_kind;
106 m_libAngle = aOther.m_libAngle;
108
109 m_cache.reset();
110
111 m_text.SetParent( this );
112 }
113
114 return *this;
115}
116
117
119{
120 VECTOR2I delta = aPos - GetPosition();
121 Move( delta );
122}
123
124
126{
127 if( const FOOTPRINT* fp = GetParentFootprint() )
128 return fp->GetTransform().Apply( m_libPos );
129
130 return m_libPos;
131}
132
133
135{
136 if( const FOOTPRINT* fp = GetParentFootprint() )
137 return ( m_libAngle + fp->GetOrientation() ).GetAngle();
138
139 return m_libAngle.GetAngle();
140}
141
142
143void PCB_BARCODE::SetText( const wxString& aNewText )
144{
145 m_text.SetText( aNewText );
146}
147
148
149wxString PCB_BARCODE::GetText() const
150{
151 return m_text.GetText();
152}
153
154
156{
157 return m_text.GetShownText( aContext );
158}
159
160
161void PCB_BARCODE::Serialize( google::protobuf::Any& aContainer ) const
162{
163 using namespace kiapi::board::types;
164
165 Barcode barcode;
166
167 barcode.mutable_id()->set_value( m_Uuid.AsStdString() );
168 barcode.set_text( GetText().ToUTF8() );
169
170 switch( m_kind )
171 {
172 case BARCODE_T::CODE_39: barcode.set_kind( BK_CODE_39 ); break;
173 case BARCODE_T::CODE_128: barcode.set_kind( BK_CODE_128 ); break;
174 case BARCODE_T::DATA_MATRIX: barcode.set_kind( BK_DATA_MATRIX ); break;
175 case BARCODE_T::QR_CODE: barcode.set_kind( BK_QR_CODE ); break;
176 case BARCODE_T::MICRO_QR_CODE: barcode.set_kind( BK_MICRO_QR_CODE ); break;
177 }
178
179 switch( m_errorCorrection )
180 {
181 case BARCODE_ECC_T::L: barcode.set_error_correction( BEC_L ); break;
182 case BARCODE_ECC_T::M: barcode.set_error_correction( BEC_M ); break;
183 case BARCODE_ECC_T::Q: barcode.set_error_correction( BEC_Q ); break;
184 case BARCODE_ECC_T::H: barcode.set_error_correction( BEC_H ); break;
185 }
186
187 kiapi::common::PackVector2( *barcode.mutable_position(), GetPosition() );
188 barcode.mutable_orientation()->set_value_degrees( GetAngle().AsDegrees() );
189
190 if( FOOTPRINT* parent = GetParentFootprint() )
191 barcode.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
192 else if( const BOARD* board = GetBoard() )
193 barcode.mutable_parent()->set_value( board->m_Uuid.AsStdString() );
194
195 barcode.set_layer( ToProtoEnum<PCB_LAYER_ID, BoardLayer>( GetLayer() ) );
196
197 barcode.mutable_width()->set_value_nm( m_width );
198 barcode.mutable_height()->set_value_nm( m_height );
199
200 barcode.set_show_text( m_text.IsVisible() );
201 barcode.mutable_text_height()->set_value_nm( m_text.GetTextHeight() );
202
203 barcode.set_knockout( IsKnockout() );
204 kiapi::common::PackVector2( *barcode.mutable_knockout_margin(), m_margin );
205
206 barcode.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
207 : kiapi::common::types::LockedState::LS_UNLOCKED );
208
209 kiapi::common::PackCustomProperties( barcode.mutable_custom_properties(), *this );
210
211 if( !aContainer.PackFrom( barcode ) )
212 wxFAIL_MSG( wxT( "Failed to pack PCB_BARCODE" ) );
213}
214
215
216bool PCB_BARCODE::Deserialize( const google::protobuf::Any& aContainer )
217{
218 using namespace kiapi::board::types;
219
220 Barcode barcode;
221
222 if( !aContainer.UnpackTo( &barcode ) )
223 return false;
224
225 SetUuidDirect( KIID( barcode.id().value() ) );
226 SetText( wxString::FromUTF8( barcode.text() ) );
227
228 switch( barcode.kind() )
229 {
230 case BK_CODE_39: SetKind( BARCODE_T::CODE_39 ); break;
231 case BK_CODE_128: SetKind( BARCODE_T::CODE_128 ); break;
232 case BK_DATA_MATRIX: SetKind( BARCODE_T::DATA_MATRIX ); break;
233 case BK_QR_CODE: SetKind( BARCODE_T::QR_CODE ); break;
234 case BK_MICRO_QR_CODE: SetKind( BARCODE_T::MICRO_QR_CODE ); break;
235 default: SetKind( BARCODE_T::QR_CODE ); break;
236 }
237
238 switch( barcode.error_correction() )
239 {
240 case BEC_L: SetErrorCorrection( BARCODE_ECC_T::L ); break;
241 case BEC_M: SetErrorCorrection( BARCODE_ECC_T::M ); break;
242 case BEC_Q: SetErrorCorrection( BARCODE_ECC_T::Q ); break;
243 case BEC_H: SetErrorCorrection( BARCODE_ECC_T::H ); break;
244 default: SetErrorCorrection( BARCODE_ECC_T::L ); break;
245 }
246
247 SetPosition( kiapi::common::UnpackVector2( barcode.position() ) );
248
249 EDA_ANGLE newAngle( barcode.orientation().value_degrees(), DEGREES_T );
250
251 if( const FOOTPRINT* fp = GetParentFootprint() )
252 m_libAngle = newAngle - fp->GetOrientation();
253 else
254 m_libAngle = newAngle;
255
257
258 m_width = barcode.width().value_nm();
259 m_height = barcode.height().value_nm();
260
261 m_text.SetLayer( m_layer );
262 m_text.SetVisible( barcode.show_text() );
263
264 if( barcode.has_text_height() )
265 {
266 int textSize = std::max( 1, static_cast<int>( barcode.text_height().value_nm() ) );
267 m_text.SetTextSize( VECTOR2I( textSize, textSize ) );
268 m_text.SetTextThickness( std::max( 1, GetPenSizeForNormal( m_text.GetTextHeight() ) ) );
269 }
270
271 m_margin = kiapi::common::UnpackVector2( barcode.knockout_margin() );
272 BOARD_ITEM::SetIsKnockout( barcode.knockout() );
273 SetLocked( barcode.locked() == kiapi::common::types::LockedState::LS_LOCKED );
274
275 kiapi::common::UnpackCustomProperties( barcode.custom_properties(), *this );
276
278
279 return true;
280}
281
282
284{
285 m_layer = aLayer;
286 m_text.SetLayer( aLayer );
288}
289
290
291void PCB_BARCODE::SetTextSize( int aTextSize )
292{
293 m_text.SetTextSize( VECTOR2I( std::max( 1, aTextSize ), std::max( 1, aTextSize ) ) );
294 m_text.SetTextThickness( std::max( 1, GetPenSizeForNormal( m_text.GetTextHeight() ) ) );
296}
297
298
300{
301 return m_text.GetTextHeight();
302}
303
304
305void PCB_BARCODE::Move( const VECTOR2I& offset )
306{
307 if( const FOOTPRINT* fp = GetParentFootprint() )
308 {
309 const TRANSFORM_TRS& xform = fp->GetTransform();
310 VECTOR2I libOffset = xform.InverseApply( offset ) - xform.InverseApply( VECTOR2I( 0, 0 ) );
311 m_libPos += libOffset;
312 }
313 else
314 {
315 m_libPos += offset;
316 }
317
318 // m_text is intentionally not moved, ComputeTextPoly repositions it
319 // under the symbol on the next AssembleBarcode.
320}
321
322
323void PCB_BARCODE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
324{
325 VECTOR2I boardPos = GetPosition();
326 RotatePoint( boardPos, aRotCentre, aAngle );
327
328 if( const FOOTPRINT* fp = GetParentFootprint() )
329 m_libPos = fp->GetTransform().InverseApply( boardPos );
330 else
331 m_libPos = boardPos;
332
333 m_libAngle += aAngle;
334
336}
337
338
339void PCB_BARCODE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
340{
341 // The position mirrors in the library or board frame depending on if this in a FP.
342 const FOOTPRINT* fp = GetParentFootprint();
343 const VECTOR2I libCentre = fp ? fp->GetTransform().InverseApply( aCentre ) : aCentre;
344 const EDA_ANGLE axis = MIRROR_AXIS( aFlipDirection );
345
346 MIRROR( m_libPos, libCentre, aFlipDirection );
347
348 // A flip changes the side, so that's a half turn on top of the reflection.
349 m_libAngle = m_libAngle.Reflect( axis ) + ANGLE_180;
350
353}
354
355
356void PCB_BARCODE::OnFootprintRescaled( double /* aRatioX */, double /* aRatioY */, double /* aLinearFactor */,
357 const VECTOR2I& /* aAnchor */, const EDA_ANGLE& /* aParentRotate */ )
358{
359 // Board values derive on read, AssembleBarcode rebuilds on next access.
360}
361
362
363void PCB_BARCODE::StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide )
364{
365 SetTextSize( settings.GetTextSize( GetLayer() ).y );
366}
367
368
370{
371 const VECTOR2I pos = GetPosition();
372 const EDA_ANGLE angle = GetAngle();
373
374 return hash_val( GetShownText( FOR_CANVAS ), m_width, m_height, pos.x, pos.y, m_margin.x, m_margin.y,
375 static_cast<int>( m_kind ), angle.AsDegrees(), static_cast<int>( m_errorCorrection ),
376 m_text.IsVisible(), m_text.GetTextHeight(), IsKnockout(), static_cast<int>( m_layer ) );
377}
378
379
381{
382 size_t key = computeCacheKey();
383
384 if( m_cache && m_cache->keyHash == key )
385 return;
386
387 if( !m_cache )
388 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
389
391
392 const VECTOR2I pos = GetPosition();
393
394 // Scale the symbol polygon to the desired barcode width/height and center it at pos.
395 rescaleSymbolPoly( pos - VECTOR2I( m_width / 2, m_height / 2 ), pos + VECTOR2I( m_width / 2, m_height / 2 ) );
396
398
399 // Build full m_poly from symbol + optional text, then apply knockout if requested
400 m_cache->poly.RemoveAllContours();
401 m_cache->poly.Append( m_cache->symbolPoly );
402
403 if( m_text.IsVisible() && m_cache->textPoly.OutlineCount() )
404 m_cache->poly.Append( m_cache->textPoly );
405
406 m_cache->poly.Fracture();
407
408 if( IsKnockout() )
409 {
410 // Enforce minimum margin: at least 10% of the smallest side of the barcode, rounded up
411 // to the nearest 0.1 mm. Use this as a lower bound for both axes.
412 int minSide = std::min( m_width, m_height );
413 int tenPercent = ( minSide + 9 ) / 10; // ceil(minSide * 0.1)
414 int step01mm = std::max( 1, pcbIUScale.mmToIU( 0.1 ) );
415 int tenPercentRounded = ( ( tenPercent + step01mm - 1 ) / step01mm ) * step01mm;
416
417 // Build inversion rectangle based on the local bbox of the current combined geometry
418 BOX2I bbox = m_cache->poly.BBox();
419 bbox.Inflate( std::max( m_margin.x, tenPercentRounded ), std::max( m_margin.y, tenPercentRounded ) );
420
422 rect.Append( bbox.GetLeft(), bbox.GetTop() );
423 rect.Append( bbox.GetRight(), bbox.GetTop() );
424 rect.Append( bbox.GetRight(), bbox.GetBottom() );
425 rect.Append( bbox.GetLeft(), bbox.GetBottom() );
426 rect.SetClosed( true );
427
429 ko.AddOutline( rect );
430 ko.BooleanSubtract( m_cache->poly );
431 ko.Fracture();
432 m_cache->poly = std::move( ko );
433 }
434
436 m_cache->poly.Mirror( pos, FLIP_DIRECTION::LEFT_RIGHT );
437
438 const EDA_ANGLE angle = GetAngle();
439
440 if( !angle.IsZero() )
441 m_cache->poly.Rotate( angle, pos );
442
443 m_cache->poly.CacheTriangulation();
444 m_cache->bbox = m_cache->poly.BBox();
445 m_cache->keyHash = key;
446}
447
448
450{
451 if( !m_cache )
452 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
453
454 m_cache->textPoly.RemoveAllContours();
455
456 if( !m_text.IsVisible() )
457 return;
458
459 SHAPE_POLY_SET textPoly;
460 m_text.TransformTextToPolySet( textPoly, 0, GetMaxError(), ERROR_INSIDE );
461
462 if( textPoly.OutlineCount() == 0 )
463 return;
464
465 // PCB_TEXT::GetDrawRotation now includes the parent FP orientation, so
466 // TransformTextToPolySet rendered the glyphs already rotated by the FP
467 // angle. The final AssembleBarcode rotation (m_cache->poly.Rotate by
468 // GetAngle = lib_angle + FP_orient) would then rotate the glyphs a
469 // second time, producing twice the intended visual rotation. Undo the
470 // m_text-side rotation here so the glyph-orientation contribution is
471 // only the lib_angle, and the final poly rotation applies the FP-orient
472 // part uniformly with the symbol.
473 if( const FOOTPRINT* fp = GetParentFootprint() )
474 {
475 EDA_ANGLE fpOrient = fp->GetOrientation();
476
477 if( !fpOrient.IsZero() )
478 textPoly.Rotate( -fpOrient, m_text.GetTextPos() );
479 }
480
481 if( m_cache->symbolPoly.OutlineCount() == 0 )
482 return;
483
484 BOX2I textBBox = textPoly.BBox();
485 BOX2I symbolBBox = m_cache->symbolPoly.BBox();
486 VECTOR2I textPos;
487 int textOffset = pcbIUScale.mmToIU( 1 );
488 textPos.x = symbolBBox.GetCenter().x - textBBox.GetCenter().x;
489 textPos.y = symbolBBox.GetBottom() - textBBox.GetTop() + textOffset;
490
491 textPoly.Move( textPos );
492
493 m_cache->textPoly = std::move( textPoly );
494 m_cache->textPoly.CacheTriangulation();
495}
496
497
499{
500 if( !m_cache )
501 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
502
503 m_cache->symbolPoly.RemoveAllContours();
504 m_cache->lastError.clear();
505
506 std::unique_ptr<zint_symbol, decltype( &ZBarcode_Delete )> symbol( ZBarcode_Create(), &ZBarcode_Delete );
507
508 if( !symbol )
509 {
510 wxLogError( wxT( "Zint: failed to allocate symbol" ) );
511 return;
512 }
513
514 symbol->input_mode = UNICODE_MODE;
515 symbol->show_hrt = 0; // do not show HRT
516
517 switch( m_kind )
518 {
520 symbol->symbology = BARCODE_CODE39;
521 break;
523 symbol->symbology = BARCODE_CODE128;
524 break;
526 symbol->symbology = BARCODE_QRCODE;
527 symbol->option_1 = to_underlying( m_errorCorrection );
528 break;
530 symbol->symbology = BARCODE_MICROQR;
531 symbol->option_1 = to_underlying( m_errorCorrection );
532 break;
534 symbol->symbology = BARCODE_DATAMATRIX;
535 break;
536 default:
537 wxLogError( wxT( "Zint: invalid barcode type" ) );
538 return;
539 }
540
541 wxString text = GetShownText( FOR_CANVAS );
542 wxScopedCharBuffer utf8Text = text.ToUTF8();
543 size_t length = utf8Text.length();
544 unsigned char* dataPtr = reinterpret_cast<unsigned char*>( utf8Text.data() );
545
546 if( text.empty() )
547 return;
548
549 if( ( m_kind == BARCODE_T::QR_CODE || m_kind == BARCODE_T::DATA_MATRIX ) && !text.IsAscii() )
550 {
551 symbol->eci = ECI_UTF8;
552 }
553
554 if( ZBarcode_Encode( symbol.get(), dataPtr, length ) >= ZINT_ERROR )
555 {
556 if( !text.IsAscii() )
557 {
558 m_cache->lastError = _( "This barcode type does not support international "
559 "characters. Use QR Code or Data Matrix instead." );
560 }
561 else
562 {
563 m_cache->lastError = wxString::FromUTF8( symbol->errtxt );
564 }
565 return;
566 }
567
568 if( ZBarcode_Buffer_Vector( symbol.get(), 0 ) >= ZINT_ERROR )
569 {
570 m_cache->lastError = wxString::FromUTF8( symbol->errtxt );
571 return;
572 }
573
574 for( zint_vector_rect* rect = symbol->vector->rectangles; rect != nullptr; rect = rect->next )
575 {
576 // Round using absolute edges to avoid cumulative rounding drift across modules.
577 int x1 = KiROUND( rect->x * symbol->scale );
578 int x2 = KiROUND( ( rect->x + rect->width ) * symbol->scale );
579 int y1 = KiROUND( rect->y * symbol->scale );
580 int y2 = KiROUND( ( rect->y + rect->height ) * symbol->scale );
581
582 SHAPE_LINE_CHAIN shapeline;
583 shapeline.Append( x1, y1 );
584 shapeline.Append( x2, y1 );
585 shapeline.Append( x2, y2 );
586 shapeline.Append( x1, y2 );
587 shapeline.SetClosed( true );
588
589 m_cache->symbolPoly.AddOutline( shapeline );
590 }
591
592 for( zint_vector_hexagon* hex = symbol->vector->hexagons; hex != nullptr; hex = hex->next )
593 {
594 // Compute vertices from center using minimal-diameter (inscribed circle) radius.
595 double r = hex->diameter / 2.0; // minimal radius
596 double cx = hex->x;
597 double cy = hex->y;
598
599 // Base orientation has apex at top; hex->rotation rotates by 0/90/180/270 degrees.
600 double baseAngles[6] = { 90.0, 30.0, -30.0, -90.0, -150.0, 150.0 };
601 double rot = static_cast<double>( hex->rotation );
602
603 SHAPE_LINE_CHAIN poly;
604
605 for( int k = 0; k < 6; ++k )
606 {
607 double ang = ( baseAngles[k] + rot ) * M_PI / 180.0;
608 int vx = KiROUND( cx + r * cos( ang ) );
609 int vy = KiROUND( cy + r * sin( ang ) );
610 poly.Append( vx, vy );
611 }
612 poly.SetClosed( true );
613
614 m_cache->symbolPoly.AddOutline( poly );
615 }
616
617 // Set the position of the barcode to the center of the symbol polygon
618 if( m_cache->symbolPoly.OutlineCount() > 0 )
619 {
620 VECTOR2I pos = m_cache->symbolPoly.BBox().GetCenter();
621 m_cache->symbolPoly.Move( -pos );
622 }
623
624 m_cache->symbolPoly.CacheTriangulation();
625}
626
627
628void PCB_BARCODE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
629{
630 FOOTPRINT* parentFP = GetParentFootprint();
631
632 if( parentFP && aFrame->GetName() == PCB_EDIT_FRAME_NAME )
633 aList.emplace_back( _( "Footprint" ), parentFP->GetReference() );
634
635 aList.emplace_back( _( "Barcode" ), ENUM_MAP<BARCODE_T>::Instance().ToString( m_kind ) );
636
637 // Don't use GetShownText() here; we want to show the user the variable references
638 aList.emplace_back( _( "Text" ), KIUI::EllipsizeStatusText( aFrame, GetText() ) );
639
640 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
641 aList.emplace_back( _( "Status" ), _( "Locked" ) );
642
643 aList.emplace_back( _( "Layer" ), GetLayerName() );
644
645 aList.emplace_back( _( "Angle" ), wxString::Format( wxT( "%g" ), GetAngle().AsDegrees() ) );
646
647 aList.emplace_back( _( "Text Height" ), aFrame->MessageTextFromValue( m_text.GetTextHeight() ) );
648}
649
650
651bool PCB_BARCODE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
652{
654
655 if( !GetBoundingBox().Contains( aPosition ) )
656 return false;
657
658 SHAPE_POLY_SET hulls;
659
661
662 return hulls.Collide( aPosition );
663}
664
665
666bool PCB_BARCODE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
667{
668 BOX2I arect = aRect;
669 arect.Inflate( aAccuracy );
670
672
673 if( aAccuracy )
674 rect.Inflate( aAccuracy );
675
676 if( aContained )
677 return arect.Contains( rect );
678
679 return arect.Intersects( rect );
680}
681
682
683void PCB_BARCODE::rescaleSymbolPoly( const VECTOR2I& aTopLeft, const VECTOR2I& aBotRight ) const
684{
685 // Rescale only the symbol polygon to the requested rectangle
686 BOX2I bbox = m_cache->symbolPoly.BBox();
687 int oldW = bbox.GetWidth();
688 int oldH = bbox.GetHeight();
689
690 VECTOR2I newPosition = ( aTopLeft + aBotRight ) / 2;
691 int newW = aBotRight.x - aTopLeft.x;
692 int newH = aBotRight.y - aTopLeft.y;
693 // Guard against zero/negative sizes from interactive edits; enforce a tiny minimum
694 int minIU = std::max( 1, pcbIUScale.mmToIU( 0.01 ) );
695 newW = std::max( newW, minIU );
696 newH = std::max( newH, minIU );
697
698 double scaleX = oldW ? static_cast<double>( newW ) / oldW : 1.0;
699 double scaleY = oldH ? static_cast<double>( newH ) / oldH : 1.0;
700
701 VECTOR2I oldCenter = bbox.GetCenter();
702 m_cache->symbolPoly.Scale( scaleX, scaleY, oldCenter );
703
704 // After scaling, move the symbol polygon to be centered at the new position
705 VECTOR2I newCenter = m_cache->symbolPoly.BBox().GetCenter();
706 VECTOR2I delta = newPosition - newCenter;
707
708 if( delta != VECTOR2I( 0, 0 ) )
709 m_cache->symbolPoly.Move( delta );
710}
711
712
714{
716 return m_cache->bbox;
717}
718
719
720wxString PCB_BARCODE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
721{
722 return wxString::Format( _( "Barcode '%s' on %s" ), GetText(), GetLayerName() );
723}
724
725
730
731
733{
735 return m_cache->bbox;
736}
737
738
739double PCB_BARCODE::ViewGetLOD( int aLayer, const KIGFX::VIEW* aView ) const
740{
741 // Hide the locked shadow when the barcode's own layer is not shown
742 if( aLayer == LAYER_LOCKED_ITEM_SHADOW && !aView->IsLayerVisibleCached( m_layer ) )
743 return LOD_HIDE;
744
745 if( FOOTPRINT* parent = GetParentFootprint() )
746 {
747 PCB_LAYER_ID checkLayer = m_layer;
748
749 if( !IsFrontLayer( checkLayer ) && !IsBackLayer( checkLayer ) )
750 checkLayer = parent->GetLayer();
751
752 if( IsFrontLayer( checkLayer ) && !aView->IsLayerVisibleCached( LAYER_FOOTPRINTS_FR ) )
753 return LOD_HIDE;
754
755 if( IsBackLayer( checkLayer ) && !aView->IsLayerVisibleCached( LAYER_FOOTPRINTS_BK ) )
756 return LOD_HIDE;
757 }
758
759 return LOD_SHOW;
760}
761
762
764 int aClearance, int aMaxError,
765 ERROR_LOC aErrorLoc, bool ignoreLineWidth ) const
766{
767 if( aLayer != m_layer && aLayer != UNDEFINED_LAYER )
768 return;
769
771
772 if( aClearance == 0 )
773 {
774 aBuffer.Append( m_cache->poly );
775 }
776 else
777 {
778 SHAPE_POLY_SET poly = m_cache->poly;
779 poly.Inflate( aClearance, CORNER_STRATEGY::CHAMFER_ACUTE_CORNERS, aMaxError, aErrorLoc );
780 aBuffer.Append( poly );
781 }
782}
783
784
786{
787 SHAPE_POLY_SET poly;
788 TransformShapeToPolygon( poly, aLayer, 0, 0, ERROR_INSIDE, true );
789
790 return std::make_shared<SHAPE_POLY_SET>( std::move( poly ) );
791}
792
793
794void PCB_BARCODE::GetBoundingHull( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
795 int aMaxError, ERROR_LOC aErrorLoc ) const
796{
798
799 auto getBoundingHull =
800 [this]( SHAPE_POLY_SET& aLocBuffer, const SHAPE_POLY_SET& aSource, int aLocClearance )
801 {
802 BOX2I rect = aSource.BBox( aLocClearance );
803 VECTOR2I corners[4];
804
805 corners[0].x = rect.GetOrigin().x;
806 corners[0].y = rect.GetOrigin().y;
807 corners[1].y = corners[0].y;
808 corners[1].x = rect.GetRight();
809 corners[2].x = corners[1].x;
810 corners[2].y = rect.GetBottom();
811 corners[3].y = corners[2].y;
812 corners[3].x = corners[0].x;
813
814 aLocBuffer.NewOutline();
815
816 const VECTOR2I pos = GetPosition();
817 const EDA_ANGLE angle = GetAngle();
818
819 for( VECTOR2I& corner : corners )
820 {
821 RotatePoint( corner, pos, angle );
822 aLocBuffer.Append( corner.x, corner.y );
823 }
824 };
825
826 if( aLayer == m_layer || aLayer == UNDEFINED_LAYER )
827 {
828 getBoundingHull( aBuffer, m_cache->symbolPoly, aClearance );
829 getBoundingHull( aBuffer, m_cache->textPoly, aClearance );
830 }
831}
832
833
835{
836 // Micro QR codes do not support High (H) error correction level
837 if( m_kind == BARCODE_T::MICRO_QR_CODE && aErrorCorrection == BARCODE_ECC_T::H )
839 else
840 m_errorCorrection = aErrorCorrection;
841 // Don't auto-compute here as it may be called during loading
842}
843
844
846{
847 m_kind = aKind;
848
849 // When switching to Micro QR, validate and adjust ECC if needed
852
853 // Don't auto-compute here as it may be called during loading
854}
855
856
858{
859 SetErrorCorrection( aErrorCorrection );
861}
862
863
865{
866 m_width = aWidth;
867
868 if( KeepSquare() )
869 m_height = aWidth;
870
872}
873
874
876{
877 m_height = aHeight;
878
879 if( KeepSquare() )
880 m_width = aHeight;
881
883}
884
885
887{
888 SetKind( aKind );
890}
891
892
894{
895 PCB_BARCODE* item = new PCB_BARCODE( *this );
896 item->CopyFrom( this );
897 return item;
898}
899
900
902{
903 wxCHECK_RET( aImage && aImage->Type() == PCB_BARCODE_T,
904 wxT( "Cannot swap data with non-barcode item." ) );
905
906 PCB_BARCODE* other = static_cast<PCB_BARCODE*>( aImage );
907
908 std::swap( m_layer, other->m_layer );
909 std::swap( m_isKnockout, other->m_isKnockout );
910 std::swap( m_isLocked, other->m_isLocked );
911 std::swap( m_width, other->m_width );
912 std::swap( m_height, other->m_height );
913 std::swap( m_libPos, other->m_libPos );
914 std::swap( m_margin, other->m_margin );
915 std::swap( m_text, other->m_text );
916 std::swap( m_kind, other->m_kind );
917 std::swap( m_libAngle, other->m_libAngle );
918 std::swap( m_errorCorrection, other->m_errorCorrection );
919 std::swap( m_cache, other->m_cache );
920 std::swap( m_customProperties, other->m_customProperties );
921
922 m_text.SetParent( this );
923 other->m_text.SetParent( other );
924}
925
926double PCB_BARCODE::Similarity( const BOARD_ITEM& aItem ) const
927{
928 if( !ClassOf( &aItem ) )
929 return 0.0;
930
931 const PCB_BARCODE* other = static_cast<const PCB_BARCODE*>( &aItem );
932
933 // Compare text, width, height, text height, position, and kind
934 double similarity = 0.0;
935 const double weight = 1.0 / 6.0;
936
937 if( GetText() == other->GetText() )
938 similarity += weight;
939 if( m_width == other->m_width )
940 similarity += weight;
941 if( m_height == other->m_height )
942 similarity += weight;
943 if( GetTextSize() == other->GetTextSize() )
944 similarity += weight;
945 if( GetPosition() == other->GetPosition() )
946 similarity += weight;
947 if( m_kind == other->m_kind )
948 similarity += weight;
949
950 return similarity;
951}
952
953int PCB_BARCODE::Compare( const PCB_BARCODE* aBarcode, const PCB_BARCODE* aOther )
954{
955 int diff;
956
957 if( ( diff = aBarcode->GetPosition().x - aOther->GetPosition().x ) != 0 )
958 return diff;
959
960 if( ( diff = aBarcode->GetPosition().y - aOther->GetPosition().y ) != 0 )
961 return diff;
962
963 if( ( diff = aBarcode->GetText().Cmp( aOther->GetText() ) ) != 0 )
964 return diff;
965
966 if( ( diff = aBarcode->GetWidth() - aOther->GetWidth() ) != 0 )
967 return diff;
968
969 if( ( diff = aBarcode->GetHeight() - aOther->GetHeight() ) != 0 )
970 return diff;
971
972 if( ( diff = aBarcode->GetTextSize() - aOther->GetTextSize() ) != 0 )
973 return diff;
974
975 if( ( diff = (int) aBarcode->GetKind() - (int) aOther->GetKind() ) != 0 )
976 return diff;
977
978 if( ( diff = aBarcode->GetAngle().AsTenthsOfADegree() - aOther->GetAngle().AsTenthsOfADegree() ) != 0 )
979 return diff;
980
981 if( ( diff = (int) aBarcode->GetErrorCorrection() - (int) aOther->GetErrorCorrection() ) != 0 )
982 return diff;
983
984 return 0;
985}
986
987
988bool PCB_BARCODE::operator==( const BOARD_ITEM& aItem ) const
989{
990 if( !ClassOf( &aItem ) )
991 return false;
992
993 const PCB_BARCODE& other = static_cast<const PCB_BARCODE&>( aItem );
994
995 return *this == other;
996}
997
998
999bool PCB_BARCODE::operator==( const PCB_BARCODE& aOther ) const
1000{
1001 // Compare text, width, height, text height, position, and kind
1002 return ( GetText() == aOther.GetText()
1003 && m_width == aOther.m_width
1004 && m_height == aOther.m_height
1005 && GetTextSize() == aOther.GetTextSize()
1006 && GetPosition() == aOther.GetPosition()
1007 && m_kind == aOther.m_kind );
1008}
1009
1010// ---- Property registration ----
1011static struct PCB_BARCODE_DESC
1012{
1014 {
1018
1019 const wxString groupBarcode = _HKI( "Barcode Properties" );
1020
1022 if( kindMap.Choices().GetCount() == 0 )
1023 {
1024 kindMap.Undefined( BARCODE_T::QR_CODE );
1025 kindMap.Map( BARCODE_T::CODE_39, _HKI( "CODE_39" ) )
1026 .Map( BARCODE_T::CODE_128, _HKI( "CODE_128" ) )
1027 .Map( BARCODE_T::DATA_MATRIX, _HKI( "DATA_MATRIX" ) )
1028 .Map( BARCODE_T::QR_CODE, _HKI( "QR_CODE" ) )
1029 .Map( BARCODE_T::MICRO_QR_CODE, _HKI( "MICRO_QR_CODE" ) );
1030 }
1031
1033 if( eccMap.Choices().GetCount() == 0 )
1034 {
1035 eccMap.Undefined( BARCODE_ECC_T::L );
1036 eccMap.Map( BARCODE_ECC_T::L, _HKI( "L (Low)" ) )
1037 .Map( BARCODE_ECC_T::M, _HKI( "M (Medium)" ) )
1038 .Map( BARCODE_ECC_T::Q, _HKI( "Q (Quartile)" ) )
1039 .Map( BARCODE_ECC_T::H, _HKI( "H (High)" ) );
1040 }
1041
1042 auto hasKnockout =
1043 []( INSPECTABLE* aItem ) -> bool
1044 {
1045 if( PCB_BARCODE* bc = dynamic_cast<PCB_BARCODE*>( aItem ) )
1046 return bc->IsKnockout();
1047 return false;
1048 };
1049
1050 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, wxString>( _HKI( "Text" ),
1052 groupBarcode );
1053
1054 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, bool>( _HKI( "Show Text" ),
1056 groupBarcode )
1057 .SetIsCopyable();
1058
1059 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, int>( _HKI( "Text Size" ),
1061 groupBarcode );
1062
1063 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, int>( _HKI( "Width" ),
1065 groupBarcode )
1066 .SetIsCopyable();
1067
1068 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, int>( _HKI( "Height" ),
1070 groupBarcode )
1071 .SetIsCopyable();
1072
1073 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, double>( _HKI( "Orientation" ),
1075 groupBarcode );
1076
1077 propMgr.AddProperty( new PROPERTY_ENUM<PCB_BARCODE, BARCODE_T>( _HKI( "Barcode Type" ),
1079 groupBarcode );
1080
1081 propMgr.AddProperty( new PROPERTY_ENUM<PCB_BARCODE, BARCODE_ECC_T>( _HKI( "Error Correction" ),
1083 groupBarcode )
1084 .SetAvailableFunc( []( INSPECTABLE* aItem ) -> bool
1085 {
1086 if( PCB_BARCODE* bc = dynamic_cast<PCB_BARCODE*>( aItem ) )
1087 {
1088 return bc->GetKind() == BARCODE_T::QR_CODE
1089 || bc->GetKind() == BARCODE_T::MICRO_QR_CODE;
1090 }
1091
1092 return false;
1093 } )
1094 .SetChoicesFunc( []( INSPECTABLE* aItem )
1095 {
1096 PCB_BARCODE* barcode = static_cast<PCB_BARCODE*>( aItem );
1097 wxPGChoices choices;
1098
1099 choices.Add( _( "L (Low)" ), static_cast<int>( BARCODE_ECC_T::L ) );
1100 choices.Add( _( "M (Medium)" ), static_cast<int>( BARCODE_ECC_T::M ) );
1101 choices.Add( _( "Q (Quartile)" ), static_cast<int>( BARCODE_ECC_T::Q ) );
1102
1103 // Only QR_CODE has High
1104 if( barcode->GetKind() == BARCODE_T::QR_CODE )
1105 choices.Add( _( "H (High)" ), static_cast<int>( BARCODE_ECC_T::H ) );
1106
1107 return choices;
1108 } );
1109
1110 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, bool>( _HKI( "Knockout" ),
1112 groupBarcode )
1113 .SetIsCopyable();
1114
1115 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, int>( _HKI( "Margin X" ),
1117 groupBarcode )
1118 .SetAvailableFunc( hasKnockout );
1119
1120 propMgr.AddProperty( new PROPERTY<PCB_BARCODE, int>( _HKI( "Margin Y" ),
1122 groupBarcode )
1123 .SetAvailableFunc( hasKnockout );
1124 }
1126
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.
VECTOR2I GetTextSize(PCB_LAYER_ID aLayer) const
Return the default text size from the layer class for the given layer.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
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
bool m_isKnockout
Definition board_item.h:626
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
PCB_LAYER_ID m_layer
Definition board_item.h:625
bool m_isLocked
Definition board_item.h:627
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
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
virtual void CopyFrom(const BOARD_ITEM *aOther)
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
Definition board_item.h:118
bool IsSideSpecific() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
int GetMaxError() const
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 size_type GetWidth() const
Definition box2.h:217
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:171
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:314
constexpr coord_type GetBottom() const
Definition box2.h:225
int AsTenthsOfADegree() const
Definition eda_angle.h:117
double AsDegrees() const
Definition eda_angle.h:115
bool IsZero() const
Definition eda_angle.h:135
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
std::map< wxString, wxString > m_customProperties
Definition eda_item.h:617
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:84
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:817
static ENUM_MAP< T > & Instance()
Definition property.h:811
ENUM_MAP & Undefined(T aValue)
Definition property.h:824
wxPGChoices & Choices()
Definition property.h:862
const TRANSFORM_TRS & GetTransform() const
Definition footprint.h:395
const wxString & GetReference() const
Definition footprint.h:793
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
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
Definition kiid.h:46
void SetKind(BARCODE_T aKind)
void SetTextSize(int aTextSize)
Change the height of the human-readable text displayed below the barcode.
double GetOrientation() const
std::unique_ptr< PCB_BARCODE_CACHE > m_cache
~PCB_BARCODE()
Destructor.
const BOX2I GetBoundingBox() const override
Get the axis-aligned bounding box of the barcode including text.
void SetBarcodeErrorCorrection(BARCODE_ECC_T aErrorCorrection)
virtual const BOX2I ViewBBox() const override
Get the bbox used for drawing/view culling, may include additional view-only extents.
EDA_ITEM * Clone() const override
Create a copy of this item.
void SetErrorCorrection(BARCODE_ECC_T aErrorCorrection)
Set the error correction level used for QR codes.
wxString GetShownText(RESOLUTION_CONTEXT aContext) const
void SetBarcodeHeight(int aHeight)
void SetShowText(bool aShow)
void SetMarginY(int aY)
void StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
bool KeepSquare() const
void SetBarcodeText(const wxString &aText)
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Produce a short human-readable description of the item for UI lists.
void AssembleBarcode() const
Assemble the barcode polygon and text polygons into a single polygonal representation.
void SetBarcodeKind(BARCODE_T aKind)
void GetBoundingHull(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Add two rectangular polygons separately bounding the barcode's symbol and the barcode's text.
PCB_BARCODE & operator=(const PCB_BARCODE &aOther)
Copy assignment operator.
VECTOR2I GetPosition() const override
Get the position (center) of the barcode in internal units.
void ComputeTextPoly() const
Generate the internal polygon representation for the human-readable text.
wxString GetText() const
void SetPosition(const VECTOR2I &aPos) override
void SetMarginX(int aX)
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
void SetOrientation(double aDegrees)
double Similarity(const BOARD_ITEM &aItem) const override
Compute a simple similarity score between this barcode and another board item.
int m_height
Barcode height.
PCB_TEXT m_text
void SetLayer(PCB_LAYER_ID aLayer) override
Set the drawing layer for the barcode and its text.
bool operator==(const BOARD_ITEM &aItem) const override
Equality comparison operator for board-level deduplication.
VECTOR2I m_margin
Margin around the barcode (only valid for knockout)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate message panel information entries (e.g.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
int GetTextSize() const
void ComputeBarcode() const
Generate the internal polygon representation for the current barcode text, kind and error correction.
void SetBarcodeWidth(int aWidth)
bool IsKnockout() const override
int GetHeight() const
Get the barcode height (in internal units).
BITMAPS GetMenuImage() const override
Icon to show in context menus/toolbars for this item type.
size_t computeCacheKey() const
Compute a hash of all cache-key inputs (shown text + geometry parameters + layer).
BARCODE_ECC_T m_errorCorrection
Error correction level for QR codes.
void SetIsKnockout(bool aEnable) override
static bool ClassOf(const EDA_ITEM *aItem)
Type-check helper.
void rescaleSymbolPoly(const VECTOR2I &aTopLeft, const VECTOR2I &aBotRight) const
Scale and translate the symbol polygon to fill the given bounding rectangle.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy) const override
Hit-test a point against the barcode (text and symbol area).
PCB_BARCODE(BOARD_ITEM *aParent)
Construct a PCB_BARCODE.
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
int m_width
Barcode width.
VECTOR2I m_libPos
Position, FP-relative when in a footprint, board absolute otherwise.
int GetMarginY() const
void swapData(BOARD_ITEM *aImage) override
BARCODE_ECC_T GetErrorCorrection() const
EDA_ORIENTATION m_libAngle
Angle, FP-relative when in a footprint, board absolute otherwise.
bool GetShowText() const
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate the barcode around a given centre by the given angle.
int GetMarginX() const
BARCODE_T m_kind
static int Compare(const PCB_BARCODE *aBarcode, const PCB_BARCODE *aOther)
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the barcode (text + symbol shapes) to polygonal geometry suitable for filling/collision tests...
EDA_ANGLE GetAngle() const
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 Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipLeftRight) override
Flip the barcode horizontally or vertically around a centre point.
BARCODE_T GetKind() const
Returns the type of the barcode (QR, CODE_39, etc.).
int GetWidth() const
Get the barcode width (in internal units).
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
void SetText(const wxString &aText)
Set the barcode content text to encode.
void Move(const VECTOR2I &offset) override
Move the barcode and its text by the given offset.
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
Definition property.h:275
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.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the 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.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
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)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
VECTOR2I InverseApply(const VECTOR2I &aPoint) const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
RESOLUTION_CONTEXT
Definition common.h:91
@ FOR_CANVAS
Definition common.h:92
@ CHAMFER_ACUTE_CORNERS
Acute angles are chamfered.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:476
#define PCB_EDIT_FRAME_NAME
int GetPenSizeForNormal(int aTextSize)
Definition gr_text.cpp:58
static constexpr std::size_t hash_val(const Types &... args)
Definition hash.h:48
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:847
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
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Dwgs_User
Definition layer_ids.h:103
@ UNDEFINED_LAYER
Definition layer_ids.h:57
This file contains miscellaneous commonly used macros and functions.
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:44
FLIP_DIRECTION
Definition mirror.h:26
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:27
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 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 UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
#define _HKI(x)
Definition page_info.cpp:40
static struct PCB_BARCODE_DESC _PCB_BARCODE_DESC
constexpr int ECI_UTF8
BARCODE class definition.
BARCODE_ECC_T
Definition pcb_barcode.h:49
BARCODE_T
Definition pcb_barcode.h:40
see class PGM_BASE
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define IMPLEMENT_ENUM_TO_WXANY(type)
Definition property.h:916
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
int delta
#define M_PI
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
constexpr auto to_underlying(E e) noexcept
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)