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.

273 lines
9.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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 SetStrokeHeaderSeparator( bool aDoStroke ) { m_StrokeHeaderSeparator = aDoStroke; }
  45. bool StrokeHeaderSeparator() const { return m_StrokeHeaderSeparator; }
  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
  52. {
  53. if( m_borderStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
  54. return LINE_STYLE::SOLID;
  55. else
  56. return m_borderStroke.GetLineStyle();
  57. }
  58. void SetBorderColor( const COLOR4D& aColor ) { m_borderStroke.SetColor( aColor ); }
  59. COLOR4D GetBorderColor() const { return m_borderStroke.GetColor(); }
  60. void SetSeparatorsStroke( const STROKE_PARAMS& aParams ) { m_separatorsStroke = aParams; }
  61. const STROKE_PARAMS& GetSeparatorsStroke() const { return m_separatorsStroke; }
  62. void SetSeparatorsWidth( int aWidth ) { m_separatorsStroke.SetWidth( aWidth ); }
  63. int GetSeparatorsWidth() const { return m_separatorsStroke.GetWidth(); }
  64. void SetSeparatorsStyle( const LINE_STYLE aStyle ) { m_separatorsStroke.SetLineStyle( aStyle ); }
  65. LINE_STYLE GetSeparatorsStyle() const
  66. {
  67. if( m_separatorsStroke.GetLineStyle() == LINE_STYLE::DEFAULT )
  68. return LINE_STYLE::SOLID;
  69. else
  70. return m_separatorsStroke.GetLineStyle();
  71. }
  72. void SetSeparatorsColor( const COLOR4D& aColor ) { m_separatorsStroke.SetColor( aColor ); }
  73. COLOR4D GetSeparatorsColor() const { return m_separatorsStroke.GetColor(); }
  74. void SetStrokeColumns( bool aDoStroke ) { m_strokeColumns = aDoStroke; }
  75. bool StrokeColumns() const { return m_strokeColumns; }
  76. void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
  77. bool StrokeRows() const { return m_strokeRows; }
  78. void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
  79. void SetPosition( const VECTOR2I& aPos ) override;
  80. VECTOR2I GetPosition() const override;
  81. VECTOR2I GetEnd() const;
  82. // For property manager:
  83. void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
  84. void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
  85. int GetPositionX() const { return GetPosition().x; }
  86. int GetPositionY() const { return GetPosition().y; }
  87. void SetColCount( int aCount ) { m_colCount = aCount; }
  88. int GetColCount() const { return m_colCount; }
  89. int GetRowCount() const
  90. {
  91. return m_cells.size() / m_colCount;
  92. }
  93. void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
  94. int GetColWidth( int aCol ) const
  95. {
  96. if( m_colWidths.count( aCol ) )
  97. return m_colWidths.at( aCol );
  98. return 0;
  99. }
  100. void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
  101. int GetRowHeight( int aRow ) const
  102. {
  103. if( m_rowHeights.count( aRow ) )
  104. return m_rowHeights.at( aRow );
  105. return 0;
  106. }
  107. PCB_TABLECELL* GetCell( int aRow, int aCol ) const
  108. {
  109. int idx = aRow * m_colCount + aCol;
  110. if( idx < (int) m_cells.size() )
  111. return m_cells[ idx ];
  112. else
  113. return nullptr;
  114. }
  115. std::vector<PCB_TABLECELL*> GetCells() const
  116. {
  117. return m_cells;
  118. }
  119. void AddCell( PCB_TABLECELL* aCell )
  120. {
  121. m_cells.push_back( aCell );
  122. aCell->SetLayer( GetLayer() );
  123. aCell->SetParent( this );
  124. }
  125. void InsertCell( int aIdx, PCB_TABLECELL* aCell )
  126. {
  127. m_cells.insert( m_cells.begin() + aIdx, aCell );
  128. aCell->SetLayer( GetLayer() );
  129. aCell->SetParent( this );
  130. }
  131. void ClearCells()
  132. {
  133. for( PCB_TABLECELL* cell : m_cells )
  134. delete cell;
  135. m_cells.clear();
  136. }
  137. void DeleteMarkedCells()
  138. {
  139. alg::delete_if( m_cells,
  140. []( PCB_TABLECELL* cell )
  141. {
  142. return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
  143. } );
  144. }
  145. void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_MODE::INSERT,
  146. bool aSkipConnectivity = false ) override
  147. {
  148. wxFAIL_MSG( wxT( "Use AddCell()/InsertCell() instead." ) );
  149. }
  150. void Remove( BOARD_ITEM* aItem, REMOVE_MODE aMode = REMOVE_MODE::NORMAL ) override
  151. {
  152. wxFAIL_MSG( wxT( "Use DeleteMarkedCells() instead." ) );
  153. }
  154. void Normalize() override;
  155. void Autosize();
  156. void Move( const VECTOR2I& aMoveVector ) override;
  157. void Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle ) override;
  158. void Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) override;
  159. const BOX2I GetBoundingBox() const override;
  160. void DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
  161. const STROKE_PARAMS& aStroke )>& aCallback ) const;
  162. // @copydoc BOARD_ITEM::GetEffectiveShape
  163. std::shared_ptr<SHAPE> GetEffectiveShape( PCB_LAYER_ID aLayer = UNDEFINED_LAYER,
  164. FLASHING aFlash = FLASHING::DEFAULT ) const override;
  165. void TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance,
  166. int aMaxError, ERROR_LOC aErrorLoc,
  167. bool aIgnoreLineWidth = false ) const override;
  168. INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  169. const std::vector<KICAD_T>& aScanTypes ) override;
  170. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  171. {
  172. // Symbols are searchable via the child field and pin item text.
  173. return false;
  174. }
  175. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  176. BITMAPS GetMenuImage() const override;
  177. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  178. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  179. EDA_ITEM* Clone() const override
  180. {
  181. return new PCB_TABLE( *this );
  182. }
  183. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  184. double Similarity( const BOARD_ITEM& aOther ) const override;
  185. bool operator==( const PCB_TABLE& aOther ) const;
  186. bool operator==( const BOARD_ITEM& aBoardItem ) const override;
  187. static int Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther );
  188. #if defined(DEBUG)
  189. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  190. #endif
  191. protected:
  192. virtual void swapData( BOARD_ITEM* aImage ) override;
  193. protected:
  194. bool m_strokeExternal;
  195. bool m_StrokeHeaderSeparator;
  196. STROKE_PARAMS m_borderStroke;
  197. bool m_strokeRows;
  198. bool m_strokeColumns;
  199. STROKE_PARAMS m_separatorsStroke;
  200. int m_colCount;
  201. std::map<int, int> m_colWidths;
  202. std::map<int, int> m_rowHeights;
  203. std::vector<PCB_TABLECELL*> m_cells;
  204. };
  205. #endif /* PCB_TABLE_H */