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.

240 lines
7.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 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 SCH_TABLE_H
  24. #define SCH_TABLE_H
  25. #include <sch_tablecell.h>
  26. #include <sch_item.h>
  27. class SCH_TABLE : public SCH_ITEM
  28. {
  29. public:
  30. SCH_TABLE( int aLineWidth = 0 );
  31. SCH_TABLE( const SCH_TABLE& aTable );
  32. ~SCH_TABLE();
  33. static inline bool ClassOf( const EDA_ITEM* aItem )
  34. {
  35. return aItem && SCH_TABLE_T == aItem->Type();
  36. }
  37. virtual wxString GetClass() const override
  38. {
  39. return wxT( "SCH_TABLE" );
  40. }
  41. void SwapData( SCH_ITEM* aItem ) override;
  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( SCH_ITEM* )>& aFunction ) override;
  67. bool operator<( const SCH_ITEM& aItem ) const override;
  68. void SetPosition( const VECTOR2I& aPos ) override;
  69. VECTOR2I GetPosition() const override;
  70. VECTOR2I GetEnd() const;
  71. // For property manager:
  72. void SetPositionX( int x ) { SetPosition( VECTOR2I( x, GetPosition().y ) ); }
  73. void SetPositionY( int y ) { SetPosition( VECTOR2I( GetPosition().x, y ) ); }
  74. int GetPositionX() const { return GetPosition().x; }
  75. int GetPositionY() const { return GetPosition().y; }
  76. void SetColCount( int aCount ) { m_colCount = aCount; }
  77. int GetColCount() const { return m_colCount; }
  78. int GetRowCount() const
  79. {
  80. return m_cells.size() / m_colCount;
  81. }
  82. void SetColWidth( int aCol, int aWidth ) { m_colWidths[aCol] = aWidth; }
  83. int GetColWidth( int aCol ) const
  84. {
  85. if( m_colWidths.count( aCol ) )
  86. return m_colWidths.at( aCol );
  87. return 0;
  88. }
  89. void SetRowHeight( int aRow, int aHeight ) { m_rowHeights[aRow] = aHeight; }
  90. int GetRowHeight( int aRow ) const
  91. {
  92. if( m_rowHeights.count( aRow ) )
  93. return m_rowHeights.at( aRow );
  94. return 0;
  95. }
  96. SCH_TABLECELL* GetCell( int aRow, int aCol ) const
  97. {
  98. int idx = aRow * m_colCount + aCol;
  99. if( idx < (int) m_cells.size() )
  100. return m_cells[ idx ];
  101. else
  102. return nullptr;
  103. }
  104. std::vector<SCH_TABLECELL*> GetCells() const
  105. {
  106. return m_cells;
  107. }
  108. void AddCell( SCH_TABLECELL* aCell )
  109. {
  110. m_cells.push_back( aCell );
  111. aCell->SetParent( this );
  112. }
  113. void InsertCell( int aIdx, SCH_TABLECELL* aCell )
  114. {
  115. m_cells.insert( m_cells.begin() + aIdx, aCell );
  116. aCell->SetParent( this );
  117. }
  118. void ClearCells()
  119. {
  120. for( SCH_TABLECELL* cell : m_cells )
  121. delete cell;
  122. m_cells.clear();
  123. }
  124. void DeleteMarkedCells()
  125. {
  126. alg::delete_if( m_cells,
  127. []( SCH_TABLECELL* cell )
  128. {
  129. return ( cell->GetFlags() & STRUCT_DELETED ) > 0;
  130. } );
  131. }
  132. void Normalize();
  133. void Move( const VECTOR2I& aMoveVector ) override;
  134. void MirrorHorizontally( int aCenter ) override;
  135. void MirrorVertically( int aCenter ) override;
  136. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  137. const BOX2I GetBoundingBox() const override;
  138. INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
  139. const std::vector<KICAD_T>& aScanTypes ) override;
  140. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  141. {
  142. // Symbols are searchable via the child field and pin item text.
  143. return false;
  144. }
  145. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  146. BITMAPS GetMenuImage() const override;
  147. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  148. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  149. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  150. void Print( const SCH_RENDER_SETTINGS* aSettings, int aUnit, int aBodyStyle,
  151. const VECTOR2I& offset, bool aForceNoFill, bool aDimmed ) override;
  152. void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  153. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  154. EDA_ITEM* Clone() const override
  155. {
  156. return new SCH_TABLE( *this );
  157. }
  158. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  159. double Similarity( const SCH_ITEM& aOther ) const override;
  160. bool operator==( const SCH_ITEM& aOther ) const override;
  161. #if defined(DEBUG)
  162. void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
  163. #endif
  164. protected:
  165. bool m_strokeExternal;
  166. bool m_strokeHeader;
  167. STROKE_PARAMS m_borderStroke;
  168. bool m_strokeRows;
  169. bool m_strokeColumns;
  170. STROKE_PARAMS m_separatorsStroke;
  171. int m_colCount;
  172. std::map<int, int> m_colWidths;
  173. std::map<int, int> m_rowHeights;
  174. std::vector<SCH_TABLECELL*> m_cells;
  175. };
  176. #endif /* SCH_TABLE_H */