1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef PCB_TABLE_H
#define PCB_TABLE_H
#include <pcb_tablecell.h>
#include <board_item.h>
#include <board_item_container.h>
class PCB_TABLE : public BOARD_ITEM_CONTAINER
{
public:
PCB_TABLE( BOARD_ITEM* aParent, int aLineWidth );
PCB_TABLE( const PCB_TABLE& aTable );
~PCB_TABLE();
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && PCB_TABLE_T == aItem->Type();
}
virtual wxString GetClass() const override
{
return wxT( "PCB_TABLE" );
}
void SetStrokeExternal( bool aDoStroke ) { m_strokeExternal = aDoStroke; }
bool StrokeExternal() const { return m_strokeExternal; }
void SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
bool StrokeHeaderSeparator() const { return m_StrokeHeaderSeparator; }
void SetBorderStroke( const STROKE_PARAMS& aParams ) { m_borderStroke = aParams; }
const STROKE_PARAMS& GetBorderStroke() const { return m_borderStroke; }
void SetBorderWidth( int aWidth ) { m_borderStroke.SetWidth( aWidth ); }
int GetBorderWidth() const { return m_borderStroke.GetWidth(); }
void SetBorderStyle( const LINE_STYLE aStyle ) { m_borderStroke.SetLineStyle( aStyle ); }
LINE_STYLE GetBorderStyle() const
{
if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
return LINE_STYLE::SOLID;
else
return m_borderStroke.GetLineStyle();
}
void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
COLOR4D GetBorderColor() const { return m_borderStroke.GetColor(); }
void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
const STROKE_PARAMS& GetSeparatorsStroke() const { return m_separatorsStroke; }
void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
int GetSeparatorsWidth() const { return m_separatorsStroke.GetWidth(); }
void SetSeparatorsStyle( const LINE_STYLE aStyle ) { m_separatorsStroke.SetLineStyle( aStyle ); }
LINE_STYLE GetSeparatorsStyle() const
{
if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
return LINE_STYLE::SOLID;
else
return m_separatorsStroke.GetLineStyle();
}
void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
COLOR4D GetSeparatorsColor() const { return m_separatorsStroke.GetColor(); }
void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
bool StrokeColumns() const { return m_strokeColumns; }
void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
bool StrokeRows() const { return m_strokeRows; }
void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const override;
void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction, int aDepth = 0 ) const override;
void SetPosition( const VECTOR2I& aPos ) override;
VECTOR2I GetPosition() const override;
VECTOR2I GetEnd() const;
// For property manager:
void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
int GetPositionX() const { return GetPosition().x; }
int GetPositionY() const { return GetPosition().y; }
void SetColCount( int aCount ) { m_colCount = aCount; }
int GetColCount() const { return m_colCount; }
int GetRowCount() const
{
return m_cells.size() / m_colCount;
}
void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
int GetColWidth( int aCol ) const
{
if( m_colWidths.count( aCol ) )
return m_colWidths.at( aCol );
return 0;
}
void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
int GetRowHeight( int aRow ) const
{
if( m_rowHeights.count( aRow ) )
return m_rowHeights.at( aRow );
return 0;
}
PCB_TABLECELL* GetCell( int aRow, int aCol ) const
{
int idx = aRow * m_colCount + aCol;
if( idx < (int) m_cells.size() )
return m_cells[ idx ];
else
return nullptr;
}
std::vector<PCB_TABLECELL*> GetCells() const
{
return m_cells;
}
void AddCell( PCB_TABLECELL* aCell )
{
m_cells.push_back( aCell );
aCell->SetLayer( GetLayer() );
aCell->SetParent( this );
}
void InsertCell( int aIdx, PCB_TABLECELL* aCell )
{
m_cells.insert( m_cells.begin() + aIdx, aCell );
aCell->SetLayer( GetLayer() );
aCell->SetParent( this );
}
void ClearCells()
{
for( PCB_TABLECELL* cell : m_cells )
delete cell;
m_cells.clear();
}
void DeleteMarkedCells()
{
alg::delete_if( m_cells,
[]( PCB_TABLECELL* cell )
{
return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
} );
}
void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
bool aSkipConnectivity = false ) override
{
wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
}
void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
{
wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
}
void Normalize() override;
void Move( const VECTOR2I& aMoveVector ) override;
void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
const BOX2I GetBoundingBox() const override;
void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
const STROKE_PARAMS& aStroke )>& aCallback ) const;
// @copydoc BOARD_ITEM::GetEffectiveShape
std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
FLASHING aFlash = FLASHING::DEFAULT ) const override;
void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
int aMaxError, ERROR_LOC aErrorLoc,
bool aIgnoreLineWidth = false ) const override;
INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
const std::vector<KICAD_T>& aScanTypes ) override;
bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
{
// Symbols are searchable via the child field and pin item text.
return false;
}
wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
BITMAPS GetMenuImage() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
EDA_ITEM* Clone() const override
{
return new PCB_TABLE( *this );
}
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
double Similarity( const BOARD_ITEM& aOther ) const override;
bool operator==( const PCB_TABLE& aOther ) const;
bool operator==( const BOARD_ITEM& aBoardItem ) const override;
static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif
protected:
virtual void swapData( BOARD_ITEM* aImage ) override;
protected:
bool m_strokeExternal;
bool m_StrokeHeaderSeparator;
STROKE_PARAMS m_borderStroke;
bool m_strokeRows;
bool m_strokeColumns;
STROKE_PARAMS m_separatorsStroke;
int m_colCount;
std::map<int, int> m_colWidths;
std::map<int, int> m_rowHeights;
std::vector<PCB_TABLECELL*> m_cells;
};
#endif /* PCB_TABLE_H */
|