KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_barcode.h
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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29
30#ifndef BARCODE_H_
31#define BARCODE_H_
32
33
34#include <board_item.h>
36#include <pcb_text.h>
37
38class LINE_READER;
39class MSG_PANEL_ITEM;
40
41
42enum class BARCODE_T : int
43{
49};
50
51enum class BARCODE_ECC_T : int
52{
53 L = 1, // Low
54 M = 2, // Medium
55 Q = 3, // Quartile
56 H = 4 // High
57};
58
59#ifndef SWIG
62#endif
63
64class PCB_BARCODE : public BOARD_ITEM
65{
66public:
72 PCB_BARCODE( BOARD_ITEM* aParent );
73
77 PCB_BARCODE( const PCB_BARCODE& aOther );
78
85 PCB_BARCODE& operator=( const PCB_BARCODE& aOther );
86
91
97 static inline bool ClassOf( const EDA_ITEM* aItem ) { return aItem && PCB_BARCODE_T == aItem->Type(); }
98
104 VECTOR2I GetPosition() const override;
105 void SetPosition( const VECTOR2I& aPos ) override;
106
112 void SetTextSize( int aTextSize );
113
114 int GetTextSize() const;
115
121 void SetLayer( PCB_LAYER_ID aLayer ) override;
122
126 int GetWidth() const { return m_width; }
127 void SetWidth( int aWidth ) { m_width = aWidth; }
128
132 int GetHeight() const { return m_height; }
133 void SetHeight( int aHeight ) { m_height = aHeight; }
134
138 const VECTOR2I& GetMargin() const { return m_margin; }
139 void SetMargin( const VECTOR2I& aMargin ) { m_margin = aMargin; }
140
146 const SHAPE_POLY_SET& GetPolyShape() const { return m_poly; }
147
151 const SHAPE_POLY_SET& GetSymbolPoly() const { return m_symbolPoly; }
152
156 const SHAPE_POLY_SET& GetTextPoly() const { return m_textPoly; }
157
171 void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
172 int aMaxError, ERROR_LOC aErrorLoc = ERROR_INSIDE,
173 bool ignoreLineWidth = false ) const override;
174
175
176 // @copydoc BOARD_ITEM::GetEffectiveShape
177 virtual std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
178 FLASHING aFlash = FLASHING::DEFAULT ) const override;
179
180 /*
181 * Add two rectangular polygons separately bounding the barcode's symbol and the barcode's text.
182 */
183 void GetBoundingHull( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
184 int aMaxError, ERROR_LOC aErrorLoc = ERROR_INSIDE ) const;
185
192 void ComputeBarcode();
193
200 void ComputeTextPoly();
201
206 void AssembleBarcode();
207
213 void SetText( const wxString& aText );
214 wxString GetText() const;
215 wxString GetShownText() const;
216
220 PCB_TEXT& Text() { return m_text; }
221 const PCB_TEXT& Text() const { return m_text; }
222
232 void Move( const VECTOR2I& offset ) override;
233
241 void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
242
250 void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipLeftRight ) override;
251
252 void StyleFromSettings( const BOARD_DESIGN_SETTINGS& settings, bool aCheckSide ) override;
253
257 VECTOR2I GetCenter() const override { return GetPosition(); }
258
267 void SetRect( const VECTOR2I& aTopLeft, const VECTOR2I& aBotRight );
268
275 void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
276
284 bool HitTest( const VECTOR2I& aPosition, int aAccuracy ) const override;
285
293 bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
294
298 wxString GetClass() const override { return wxT( "BARCODE" ); }
299
300 // Virtual function
306 const BOX2I GetBoundingBox() const override;
307
315 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
316
320 BITMAPS GetMenuImage() const override;
321
327 EDA_ITEM* Clone() const override;
328
329 void swapData( BOARD_ITEM* aImage ) override;
330
334 virtual const BOX2I ViewBBox() const override;
335
342 double Similarity( const BOARD_ITEM& aItem ) const override;
343
344 static int Compare( const PCB_BARCODE* aBarcode, const PCB_BARCODE* aOther );
345
352 bool operator==( const BOARD_ITEM& aItem ) const override;
353
357 BARCODE_T GetKind() const { return m_kind; }
358 void SetKind( BARCODE_T aKind );
359 void SetBarcodeKind( BARCODE_T aKind ); // Includes re-compute
360
361 bool KeepSquare() const
362 {
363 return m_kind == BARCODE_T::QR_CODE
366 }
367
373 void SetErrorCorrection( BARCODE_ECC_T aErrorCorrection );
375 void SetBarcodeErrorCorrection( BARCODE_ECC_T aErrorCorrection ); // Includes re-compute
376
377 void SetBarcodeText( const wxString& aText ) { SetText( aText ); AssembleBarcode(); }
378 void SetShowText( bool aShow ) { m_text.SetVisible( aShow ); AssembleBarcode(); }
379 bool GetShowText() const { return m_text.IsVisible(); }
380
381 void SetBarcodeWidth( int aWidth );
382 void SetBarcodeHeight( int aHeight );
383
384 EDA_ANGLE GetAngle() const { return m_angle; }
385 double GetOrientation() const { return m_angle.AsDegrees(); }
386 void SetOrientation( double aDegrees )
387 {
388 EDA_ANGLE newAngle( aDegrees, DEGREES_T );
389 EDA_ANGLE oldAngle = m_angle;
390
391 if( newAngle != oldAngle )
392 {
393 Rotate( GetPosition(), newAngle - oldAngle );
394 }
395 }
396
397 int GetMarginX() const { return m_margin.x; }
398 int GetMarginY() const { return m_margin.y; }
399
400 void SetMarginX( int aX )
401 {
402 aX = std::max( pcbIUScale.mmToIU( 1 ), aX );
403 m_margin.x = aX;
405 }
406
407 void SetMarginY( int aY )
408 {
409 aY = std::max( pcbIUScale.mmToIU( 1 ), aY );
410 m_margin.y = aY;
412 }
413
414 bool IsKnockout() const override { return BOARD_ITEM::IsKnockout(); }
415 void SetIsKnockout( bool aEnable ) override
416 {
417 BOARD_ITEM::SetIsKnockout( aEnable );
419 }
420
421 const wxString& GetLastError() const { return m_lastError; }
422
423private:
432
437 wxString m_lastError;
438};
439
440#endif // DIMENSION_H_
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
Container for design settings for a BOARD object.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
virtual bool IsKnockout() const
Definition board_item.h:324
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:325
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:99
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:66
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:54
PCB_TEXT & Text()
Access the internal PCB_TEXT object used for showing the human-readable text.
void SetKind(BARCODE_T aKind)
void SetTextSize(int aTextSize)
Change the height of the human-readable text displayed below the barcode.
void ComputeTextPoly()
Generate the internal polygon representation for the human-readable text.
VECTOR2I GetCenter() const override
Get the centre of the barcode (alias for GetPosition).
double GetOrientation() const
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
const VECTOR2I & GetMargin() const
Get the barcode margin (in internal units).
~PCB_BARCODE()
Destructor.
VECTOR2I m_pos
Position of the barcode.
const BOX2I GetBoundingBox() const override
Get the axis-aligned bounding box of the barcode including text.
void SetBarcodeErrorCorrection(BARCODE_ECC_T aErrorCorrection)
void SetRect(const VECTOR2I &aTopLeft, const VECTOR2I &aBotRight)
Set the bounding rectangle of the barcode.
virtual const BOX2I ViewBBox() const override
Get the bbox used for drawing/view culling, may include additional view-only extents.
void SetMargin(const VECTOR2I &aMargin)
SHAPE_POLY_SET m_textPoly
Human-readable text only (cached, centered/positioned)
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.
void SetBarcodeHeight(int aHeight)
wxString m_lastError
void SetShowText(bool aShow)
SHAPE_POLY_SET m_poly
Full geometry (barcode + optional text or knockout)
EDA_ANGLE m_angle
SHAPE_POLY_SET m_symbolPoly
Barcode symbol only (cached, centered at origin)
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 SetWidth(int aWidth)
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
void SetHeight(int aHeight)
void AssembleBarcode()
Assemble the barcode polygon and text polygons into a single polygonal representation.
PCB_BARCODE & operator=(const PCB_BARCODE &aOther)
Copy assignment operator.
VECTOR2I GetPosition() const override
Get the position (center) of the barcode in internal units.
wxString GetText() const
void SetPosition(const VECTOR2I &aPos) override
void SetMarginX(int aX)
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)
BOX2I m_bbox
BBox of m_poly (ie: barcode + text)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate message panel information entries (e.g.
wxString GetClass() const override
Return the class name for display/debugging purposes.
int GetTextSize() const
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.
wxString GetShownText() const
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.
Definition pcb_barcode.h:97
const SHAPE_POLY_SET & GetPolyShape() const
Access the underlying polygonal representation generated for the barcode.
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.
const wxString & GetLastError() const
int m_width
Barcode width.
const SHAPE_POLY_SET & GetTextPoly() const
Access the cached polygon for the human-readable text only (already scaled/placed).
const SHAPE_POLY_SET & GetSymbolPoly() const
Access the cached polygon for the barcode symbol only (no text, no margins/knockout).
int GetMarginY() const
void swapData(BOARD_ITEM *aImage) override
BARCODE_ECC_T GetErrorCorrection() const
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)
const PCB_TEXT & Text() const
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
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipLeftRight) override
Flip the barcode horizontally or vertically around a centre point.
void ComputeBarcode()
Generate the internal polygon representation for the current barcode text, kind and error correction.
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 SetText(const wxString &aText)
Set the barcode content text to encode.
void Move(const VECTOR2I &offset) override
Function Move.
Represent a set of closed polygons.
@ DEGREES_T
Definition eda_angle.h:31
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:184
@ DEFAULT
Flashing follows connectivity.
Definition layer_ids.h:185
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
#define H(x, y, z)
Definition md5_hash.cpp:17
FLIP_DIRECTION
Definition mirror.h:27
BARCODE_ECC_T
Definition pcb_barcode.h:52
BARCODE_T
Definition pcb_barcode.h:43
#define DECLARE_ENUM_TO_WXANY(type)
Definition property.h:787
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:101
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695