You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
8.8 KiB

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