31#include <api/board/board_types.pb.h>
51#include <backend/zint.h>
54#include <google/protobuf/any.pb.h>
128 return fp->GetTransform().Apply(
m_libPos );
137 return (
m_libAngle + fp->GetOrientation() ).GetAngle();
145 m_text.SetText( aNewText );
157 return m_text.GetShownText( aContext );
167 barcode.mutable_id()->set_value(
m_Uuid.AsStdString() );
168 barcode.set_text(
GetText().ToUTF8() );
188 barcode.mutable_orientation()->set_value_degrees(
GetAngle().AsDegrees() );
191 barcode.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
193 barcode.mutable_parent()->set_value(
board->m_Uuid.AsStdString() );
197 barcode.mutable_width()->set_value_nm(
m_width );
198 barcode.mutable_height()->set_value_nm(
m_height );
200 barcode.set_show_text(
m_text.IsVisible() );
201 barcode.mutable_text_height()->set_value_nm(
m_text.GetTextHeight() );
206 barcode.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
207 : kiapi::common::types::LockedState::LS_UNLOCKED );
211 if( !aContainer.PackFrom( barcode ) )
212 wxFAIL_MSG( wxT(
"Failed to pack PCB_BARCODE" ) );
222 if( !aContainer.UnpackTo( &barcode ) )
226 SetText( wxString::FromUTF8( barcode.text() ) );
228 switch( barcode.kind() )
238 switch( barcode.error_correction() )
258 m_width = barcode.width().value_nm();
259 m_height = barcode.height().value_nm();
262 m_text.SetVisible( barcode.show_text() );
264 if( barcode.has_text_height() )
266 int textSize = std::max( 1,
static_cast<int>( barcode.text_height().value_nm() ) );
273 SetLocked( barcode.locked() == kiapi::common::types::LockedState::LS_LOCKED );
286 m_text.SetLayer( aLayer );
293 m_text.SetTextSize(
VECTOR2I( std::max( 1, aTextSize ), std::max( 1, aTextSize ) ) );
301 return m_text.GetTextHeight();
329 m_libPos = fp->GetTransform().InverseApply( boardPos );
388 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
400 m_cache->poly.RemoveAllContours();
413 int tenPercent = ( minSide + 9 ) / 10;
414 int step01mm = std::max( 1,
pcbIUScale.mmToIU( 0.1 ) );
415 int tenPercentRounded = ( ( tenPercent + step01mm - 1 ) / step01mm ) * step01mm;
426 rect.SetClosed(
true );
432 m_cache->poly = std::move( ko );
441 m_cache->poly.Rotate( angle, pos );
443 m_cache->poly.CacheTriangulation();
452 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
454 m_cache->textPoly.RemoveAllContours();
475 EDA_ANGLE fpOrient = fp->GetOrientation();
481 if(
m_cache->symbolPoly.OutlineCount() == 0 )
491 textPoly.
Move( textPos );
493 m_cache->textPoly = std::move( textPoly );
494 m_cache->textPoly.CacheTriangulation();
501 m_cache = std::make_unique<PCB_BARCODE_CACHE>();
503 m_cache->symbolPoly.RemoveAllContours();
506 std::unique_ptr<zint_symbol,
decltype( &ZBarcode_Delete )> symbol( ZBarcode_Create(), &ZBarcode_Delete );
510 wxLogError( wxT(
"Zint: failed to allocate symbol" ) );
514 symbol->input_mode = UNICODE_MODE;
515 symbol->show_hrt = 0;
520 symbol->symbology = BARCODE_CODE39;
523 symbol->symbology = BARCODE_CODE128;
526 symbol->symbology = BARCODE_QRCODE;
530 symbol->symbology = BARCODE_MICROQR;
534 symbol->symbology = BARCODE_DATAMATRIX;
537 wxLogError( wxT(
"Zint: invalid barcode type" ) );
542 wxScopedCharBuffer utf8Text =
text.ToUTF8();
543 size_t length = utf8Text.length();
544 unsigned char* dataPtr =
reinterpret_cast<unsigned char*
>( utf8Text.data() );
554 if( ZBarcode_Encode( symbol.get(), dataPtr, length ) >= ZINT_ERROR )
556 if( !
text.IsAscii() )
558 m_cache->lastError =
_(
"This barcode type does not support international "
559 "characters. Use QR Code or Data Matrix instead." );
563 m_cache->lastError = wxString::FromUTF8( symbol->errtxt );
568 if( ZBarcode_Buffer_Vector( symbol.get(), 0 ) >= ZINT_ERROR )
570 m_cache->lastError = wxString::FromUTF8( symbol->errtxt );
574 for( zint_vector_rect*
rect = symbol->vector->rectangles;
rect !=
nullptr;
rect =
rect->next )
583 shapeline.
Append( x1, y1 );
584 shapeline.
Append( x2, y1 );
585 shapeline.
Append( x2, y2 );
586 shapeline.
Append( x1, y2 );
589 m_cache->symbolPoly.AddOutline( shapeline );
592 for( zint_vector_hexagon* hex = symbol->vector->hexagons; hex !=
nullptr; hex = hex->next )
595 double r = hex->diameter / 2.0;
600 double baseAngles[6] = { 90.0, 30.0, -30.0, -90.0, -150.0, 150.0 };
601 double rot =
static_cast<double>( hex->rotation );
605 for(
int k = 0; k < 6; ++k )
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 ) );
614 m_cache->symbolPoly.AddOutline( poly );
618 if(
m_cache->symbolPoly.OutlineCount() > 0 )
621 m_cache->symbolPoly.Move( -pos );
624 m_cache->symbolPoly.CacheTriangulation();
633 aList.emplace_back(
_(
"Footprint" ), parentFP->
GetReference() );
641 aList.emplace_back(
_(
"Status" ),
_(
"Locked" ) );
645 aList.emplace_back(
_(
"Angle" ), wxString::Format( wxT(
"%g" ),
GetAngle().AsDegrees() ) );
662 return hulls.
Collide( aPosition );
674 rect.Inflate( aAccuracy );
690 VECTOR2I newPosition = ( aTopLeft + aBotRight ) / 2;
691 int newW = aBotRight.
x - aTopLeft.
x;
692 int newH = aBotRight.
y - aTopLeft.
y;
694 int minIU = std::max( 1,
pcbIUScale.mmToIU( 0.01 ) );
695 newW = std::max( newW, minIU );
696 newH = std::max( newH, minIU );
698 double scaleX = oldW ?
static_cast<double>( newW ) / oldW : 1.0;
699 double scaleY = oldH ?
static_cast<double>( newH ) / oldH : 1.0;
702 m_cache->symbolPoly.Scale( scaleX, scaleY, oldCenter );
750 checkLayer = parent->GetLayer();
764 int aClearance,
int aMaxError,
765 ERROR_LOC aErrorLoc,
bool ignoreLineWidth )
const
772 if( aClearance == 0 )
790 return std::make_shared<SHAPE_POLY_SET>( std::move( poly ) );
795 int aMaxError,
ERROR_LOC aErrorLoc )
const
799 auto getBoundingHull =
802 BOX2I rect = aSource.BBox( aLocClearance );
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;
822 aLocBuffer.
Append( corner.x, corner.y );
828 getBoundingHull( aBuffer,
m_cache->symbolPoly, aClearance );
829 getBoundingHull( aBuffer,
m_cache->textPoly, aClearance );
904 wxT(
"Cannot swap data with non-barcode item." ) );
934 double similarity = 0.0;
935 const double weight = 1.0 / 6.0;
938 similarity += weight;
940 similarity += weight;
942 similarity += weight;
944 similarity += weight;
946 similarity += weight;
948 similarity += weight;
963 if( ( diff = aBarcode->
GetText().Cmp( aOther->
GetText() ) ) != 0 )
975 if( ( diff = (
int) aBarcode->
GetKind() - (
int) aOther->
GetKind() ) != 0 )
995 return *
this == other;
1019 const wxString groupBarcode =
_HKI(
"Barcode Properties" );
1022 if( kindMap.
Choices().GetCount() == 0 )
1033 if( eccMap.
Choices().GetCount() == 0 )
1046 return bc->IsKnockout();
1097 wxPGChoices choices;
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
constexpr int ARC_LOW_DEF
BITMAPS
A list of all bitmap identifiers.
SEG MIRROR_AXIS(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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...
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
void SetLocked(bool aLocked) override
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetIsKnockout(bool aKnockout)
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)
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.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr const Vec GetCenter() const
constexpr size_type GetHeight() const
constexpr coord_type GetLeft() const
constexpr bool Contains(const Vec &aPoint) const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
int AsTenthsOfADegree() const
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
std::map< wxString, wxString > m_customProperties
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
ENUM_MAP & Undefined(T aValue)
Class that other classes need to inherit from, in order to be inspectable.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisibleCached(int aLayer) const
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 StyleFromSettings(const BOARD_DESIGN_SETTINGS &settings, bool aCheckSide) override
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.
void SetPosition(const VECTOR2I &aPos) override
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.
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.
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.
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.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate the barcode around a given centre by the given angle.
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.
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
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.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
@ CHAMFER_ACUTE_CORNERS
Acute angles are chamfered.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_180
#define PCB_EDIT_FRAME_NAME
int GetPenSizeForNormal(int aTextSize)
static constexpr std::size_t hash_val(const Types &... args)
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
PCB_LAYER_ID
A quick note on layer IDs:
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.
@ LEFT_RIGHT
Flip left to right (around the Y axis)
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)
static struct PCB_BARCODE_DESC _PCB_BARCODE_DESC
BARCODE class definition.
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
#define IMPLEMENT_ENUM_TO_WXANY(type)
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
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.
constexpr auto to_underlying(E e) noexcept
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
VECTOR2< int32_t > VECTOR2I
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)