39#include <api/board/board_types.pb.h>
140 if( addToParentGroup )
142 wxCHECK_MSG( aCommit, dupe,
"Must supply a commit to update parent group" );
147 group->AddItem( dupe );
160 table.mutable_id()->set_value(
m_Uuid.AsStdString() );
162 table.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
163 : kiapi::common::types::LockedState::LS_UNLOCKED );
174 cell->Serialize( *
table.add_cells() );
180 table.set_row_separators(
m_strokeRows ? types::TSM_ENABLED : types::TSM_DISABLED );
185 table.mutable_parent()->set_value( parent->m_Uuid.AsStdString() );
187 table.mutable_parent()->set_value(
board->m_Uuid.AsStdString() );
191 if( !aContainer.PackFrom(
table ) )
192 wxFAIL_MSG( wxT(
"Failed to pack PCB_TABLE" ) );
201 if( !aContainer.UnpackTo( &
table ) )
204 if(
table.column_count() < 1 )
209 SetLocked(
table.locked() == kiapi::common::types::LockedState::LS_LOCKED );
218 for(
int i = 0; i <
table.column_widths_size() && i <
table.column_count(); ++i )
221 for(
const types::TableCell& protoCell :
table.cells() )
238 for(
int i = 0; i <
table.row_heights_size() && i < rowCount; ++i )
244 if(
table.has_border_stroke() )
250 if(
table.has_separators_stroke() )
261 wxCHECK_RET( aImage !=
nullptr && aImage->
Type() ==
Type(), wxT(
"Cannot swap data with invalid table." ) );
282 cell->SetParent(
this );
293 const size_t wanted =
static_cast<size_t>( aRows ) *
static_cast<size_t>( aCols );
297 while(
m_cells.size() > wanted )
303 while(
m_cells.size() < wanted )
313 cell->SetLayer( aLayer );
328 return m_cells[0]->GetPosition();
359 if(
m_cells[0]->GetColSpan() > 1 )
361 for(
int ii = 1; ii <
m_cells[0]->GetColSpan(); ++ii )
365 if(
m_cells[0]->GetRowSpan() > 1 )
367 for(
int ii = 1; ii <
m_cells[0]->GetRowSpan(); ++ii )
371 VECTOR2I localCell0Center( cell0Width / 2, cell0Height / 2 );
377 cell->Rotate( stableCenter, -cellAngle );
380 VECTOR2I unrotatedOrigin = stableCenter -
VECTOR2I( cell0Width / 2, cell0Height / 2 );
382 int y = unrotatedOrigin.
y;
386 int x = unrotatedOrigin.
x;
398 int cellWidth = colWidth;
399 int cellHeight = rowHeight;
403 for(
int ii = col + 1; ii < col + cell->
GetColSpan(); ++ii )
406 for(
int ii = row + 1; ii < row + cell->
GetRowSpan(); ++ii )
434 cell->Rotate( stableCenter, cellAngle );
440 if( newCenter != stableCenter )
452 std::vector<std::vector<BOX2I>> extents;
456 extents.push_back( std::vector<BOX2I>() );
466 extents[row].push_back( textPoly.
BBox() );
478 colWidth = std::max<int>( colWidth, extents[row][col].GetWidth() + ( margins * 1.5 ) );
484 std::vector<int> needed;
494 rowHeight = std::max( rowHeight, (
int) extents[row][col].GetHeight() + margins );
497 needed.push_back( rowHeight );
507 for(
int row = 0; row < static_cast<int>( aNeeded.size() ); ++row )
515 cell->Move( aMoveVector );
525 cell->Rotate( aRotCentre, aAngle );
534 cell->OnFootprintTransformed();
542 cell->OnFootprintRescaled( aRatioX, aRatioY, aLinearFactor, aAnchor, aParentRotate );
546static void mirrorCellColumns( std::vector<PCB_TABLECELL*>& aCells,
int aRowCount,
int aColCount )
548 const std::vector<PCB_TABLECELL*> oldCells = aCells;
550 for(
int row = 0; row < aRowCount; ++row )
552 const int rowOffset = row * aColCount;
554 for(
int col = 0; col < aColCount; )
556 const int span = std::clamp( oldCells[rowOffset + col]->GetColSpan(), 1, aColCount - col );
558 for(
int ii = 0; ii < span; ++ii )
559 aCells[rowOffset + aColCount - col - span + ii] = oldCells[rowOffset + col + ii];
574 cell->Flip( aCentre, aFlipDirection );
580 std::map<int, int> newColWidths;
597 targetPos.
x = 2 * aCentre.
x - originalBBox.
GetRight();
598 targetPos.
y = originalBBox.
GetTop();
602 targetPos.
x = originalBBox.
GetLeft();
603 targetPos.
y = 2 * aCentre.
y - originalBBox.
GetBottom();
614 cell->Flip( tableOrigin, aFlipDirection );
620 std::map<int, int> newColWidths;
643 std::map<PCB_TABLECELL*, PCB_LAYER_ID> origCellLayers;
644 std::map<PCB_TABLECELL*, bool> origMirrorSettings;
648 origCellLayers[cell] = cell->GetLayer();
649 origMirrorSettings[cell] = cell->IsMirrored();
661 cell->SetLayer( origCellLayers[cell] );
662 cell->SetMirrored( origMirrorSettings[cell] );
674 cell->RunOnChildren( aFunction, aMode );
684 bbox.
Merge( cell->GetBoundingBox() );
737 if( corners.size() == 4 )
738 aCallback( corners[1], corners[2], stroke );
763 if( corners.size() == 4 )
764 aCallback( corners[2], corners[3], stroke );
786 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
788 std::vector<VECTOR2I> pts;
790 pts.emplace_back( topLeft[3] );
791 pts.emplace_back( topRight[2] );
792 pts.emplace_back( bottomRight[2] );
793 pts.emplace_back( bottomLeft[3] );
808 ERROR_LOC aErrorLoc,
bool aIgnoreLineWidth )
const
810 int gap = aClearance;
819 cell->TransformShapeToPolygon( aBuffer, aLayer, gap, aMaxError, aErrorLoc,
false );
830 [&aBuffer, aMaxError, aErrorLoc, aRenderSettings](
const VECTOR2I& ptA,
const VECTOR2I& ptB,
845 if( currSettings ==
nullptr )
846 currSettings = &defaultRenderSettings;
861 cell->TransformTextToPolySet( aBuffer, 0, aMaxError,
ERROR_INSIDE );
867 int aClearance,
int aMaxError,
ERROR_LOC aErrorLoc,
870 if( aClearance <= 0 )
884 for(
KICAD_T scanType : aScanTypes )
908 return wxString::Format(
_(
"%d column table" ),
m_colCount );
922 rect.Inflate( aAccuracy );
924 return rect.Contains( aPosition );
932 rect.Inflate( aAccuracy );
950 aList.emplace_back(
_(
"Table" ), wxString::Format(
_(
"%d Columns" ),
m_colCount ) );
958 if( ( diff = (
int) aTable->
GetCells().size() - (
int) aOther->
GetCells().size() ) != 0 )
964 for(
int col = 0; col < aTable->
GetColCount(); ++col )
973 for(
int row = 0; row < aTable->
GetRowCount(); ++row )
979 for(
int row = 0; row < aTable->
GetRowCount(); ++row )
981 for(
int col = 0; col < aTable->
GetColCount(); ++col )
986 if( ( diff = cell->PCB_SHAPE::Compare( other ) ) != 0 )
989 if( ( diff = cell->EDA_TEXT::Compare( other ) ) != 0 )
1005 return *
this == other;
1038 for(
int ii = 0; ii < (int)
m_cells.size(); ++ii )
1058 double similarity = 1.0;
1084 for(
int ii = 0; ii < (int)
m_cells.size(); ++ii )
1097 if( lineStyleEnum.
Choices().GetCount() == 0 )
1121 const wxString tableProps =
_(
"Table Properties" );
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.
#define DEFAULT_LINE_WIDTH
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD_ITEM_CONTAINER(BOARD_ITEM *aParent, KICAD_T aType)
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 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)
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Information pertinent to a Pcbnew printed circuit board.
void CacheChildrenById(const BOARD_ITEM &aParent)
void UncacheChildrenById(const BOARD_ITEM &aParent)
constexpr const Vec & GetPosition() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec GetCenter() const
constexpr coord_type GetLeft() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
The base class for create windows for drawing purpose.
A set of EDA_ITEMs (i.e., without duplicates).
virtual EDA_GROUP * GetParentGroup() const
KICAD_T Type() const
Returns the type of object.
std::map< wxString, wxString > m_customProperties
virtual void SetParent(EDA_ITEM *aParent)
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
virtual EDA_ANGLE GetDrawRotation() const
virtual void ClearRenderCache()
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
A color representation with 4 components: red, green, blue, alpha.
PCB specific render settings.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
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 SetPosition(const VECTOR2I &aPos) override
void SetEnd(const VECTOR2I &aEnd) override
VECTOR2I GetPosition() const override
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const override
Create a copy of this BOARD_ITEM.
void OnFootprintTransformed() override
Hook for items inside a footprint to refresh after the FP transform changes (translate,...
STROKE_PARAMS m_separatorsStroke
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void TransformGraphicItemsToPolySet(SHAPE_POLY_SET &aBuffer, int aMaxError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings) const
Convert graphic items (segments and texts) to a set of polygonal shapes.
std::vector< PCB_TABLECELL * > m_cells
void SetColWidth(int aCol, int aWidth)
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
double ViewGetLOD(int aLayer, const KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
bool StrokeHeaderSeparator() const
bool StrokeColumns() const
void SetBorderStyle(const LINE_STYLE aStyle)
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.
virtual void setAutosizedRowHeights(const std::vector< int > &aNeeded)
Give each row the height Autosize measured its text to need, margins included.
void SetStrokeHeaderSeparator(bool aDoStroke)
void SetSeparatorsColor(const COLOR4D &aColor)
STROKE_PARAMS m_borderStroke
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void ResizeCells(int aRows, int aCols)
Grow or shrink to aRows x aCols, keeping the cells that already exist.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool StrokeExternal() const
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
int GetSeparatorsWidth() const
void OnFootprintRescaled(double aRatioX, double aRatioY, double aLinearFactor, const VECTOR2I &aAnchor, const EDA_ANGLE &aParentRotate) override
Apply a parent footprint scale to this item.
void SetStrokeExternal(bool aDoStroke)
PCB_TABLECELL * GetCell(int aRow, int aCol) const
std::vector< PCB_TABLECELL * > GetCells() const
int GetBorderWidth() const
COLOR4D GetBorderColor() const
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const override
Convert the TABLE shape to a polyset.
bool operator==(const PCB_TABLE &aOther) const
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
void SetStrokeColumns(bool aDoStroke)
const STROKE_PARAMS & GetSeparatorsStroke() const
std::map< int, int > m_colWidths
virtual void swapData(BOARD_ITEM *aImage) override
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
void AddCell(PCB_TABLECELL *aCell)
const STROKE_PARAMS & GetBorderStroke() const
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void SetStrokeRows(bool aDoStroke)
bool m_StrokeHeaderSeparator
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
void Mirror(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Mirror this object relative to a given horizontal axis the layer is not changed.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
LINE_STYLE GetBorderStyle() const
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
void SetColCount(int aCount)
int GetColWidth(int aCol) const
VECTOR2I GetPosition() const override
void SetSeparatorsWidth(int aWidth)
COLOR4D GetSeparatorsColor() const
void CopyFrom(const BOARD_ITEM *aOther) override
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
LINE_STYLE GetSeparatorsStyle() const
void SetBorderColor(const COLOR4D &aColor)
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
void SetSeparatorsStyle(const LINE_STYLE aStyle)
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 SetRowHeight(int aRow, int aHeight)
void SetPosition(const VECTOR2I &aPos) override
void SetBorderWidth(int aWidth)
int GetRowHeight(int aRow) const
std::map< int, int > m_rowHeights
int GetMarginBottom() const
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).
VECTOR2I GetDrawPos() const override
int GetMarginLeft() const
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const override
int GetMarginRight() const
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.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Simple container to manage line stroke parameters.
LINE_STYLE GetLineStyle() const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
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.
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
static bool empty(const wxTextEntryBase *aCtrl)
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_180
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
a few functions useful in geometry calculations.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
PCB_LAYER_ID
A quick note on layer IDs:
@ LEFT_RIGHT
Flip left to right (around the Y axis)
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
bool ShapeHitTest(const SHAPE_LINE_CHAIN &aHitter, const SHAPE &aHittee, bool aHitteeContained)
Perform a shape-to-shape hit test.
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 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)
static void mirrorCellColumns(std::vector< PCB_TABLECELL * > &aCells, int aRowCount, int aColCount)
static struct PCB_TABLE_DESC _PCB_TABLE_DESC
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
@ PT_SIZE
Size expressed in distance units (mm/inch)
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
constexpr double correction
LINE_STYLE
Dashed line types.
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.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
VECTOR2< int32_t > VECTOR2I
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)