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.

170 lines
5.4 KiB

7 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef SCH_TEXT_H
  25. #define SCH_TEXT_H
  26. #include <eda_text.h>
  27. #include <sch_item.h>
  28. #include <sch_field.h>
  29. #include <sch_connection.h> // for CONNECTION_TYPE
  30. #include <schematic.h>
  31. class HTML_MESSAGE_BOX;
  32. class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
  33. {
  34. public:
  35. SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
  36. KICAD_T aType = SCH_TEXT_T );
  37. SCH_TEXT( const SCH_TEXT& aText );
  38. ~SCH_TEXT() { }
  39. static inline bool ClassOf( const EDA_ITEM* aItem )
  40. {
  41. return aItem && SCH_TEXT_T == aItem->Type();
  42. }
  43. virtual wxString GetClass() const override
  44. {
  45. return wxT( "SCH_TEXT" );
  46. }
  47. virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
  48. int aDepth = 0 ) const;
  49. wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
  50. {
  51. SCHEMATIC* schematic = Schematic();
  52. if( schematic )
  53. return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
  54. else
  55. return GetText();
  56. }
  57. int GetSchTextSize() const { return GetTextWidth(); }
  58. void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
  59. bool IsHypertext() const override
  60. {
  61. return HasHyperlink();
  62. }
  63. void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
  64. void SetExcludedFromSim( bool aExclude ) override { m_excludedFromSim = aExclude; }
  65. bool GetExcludedFromSim() const override { return m_excludedFromSim; }
  66. /**
  67. * This offset depends on the orientation, the type of text, and the area required to
  68. * draw the associated graphic symbol or to put the text above a wire.
  69. *
  70. * @return the offset between the SCH_TEXT position and the text itself position
  71. */
  72. virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
  73. void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
  74. void SwapData( SCH_ITEM* aItem ) override;
  75. const BOX2I GetBoundingBox() const override;
  76. bool operator<( const SCH_ITEM& aItem ) const override;
  77. int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
  78. int GetPenWidth() const override;
  79. void Move( const VECTOR2I& aMoveVector ) override
  80. {
  81. EDA_TEXT::Offset( aMoveVector );
  82. }
  83. void MirrorHorizontally( int aCenter ) override;
  84. void MirrorVertically( int aCenter ) override;
  85. void Rotate( const VECTOR2I& aCenter ) override;
  86. virtual void Rotate90( bool aClockwise );
  87. virtual void MirrorSpinStyle( bool aLeftRight );
  88. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  89. {
  90. return SCH_ITEM::Matches( GetText(), aSearchData );
  91. }
  92. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
  93. {
  94. return EDA_TEXT::Replace( aSearchData );
  95. }
  96. virtual bool IsReplaceable() const override { return true; }
  97. void ViewGetLayers( int aLayers[], int& aCount ) const override;
  98. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override;
  99. BITMAPS GetMenuImage() const override;
  100. VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
  101. void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
  102. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  103. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  104. void Plot( PLOTTER* aPlotter, bool aBackground,
  105. const SCH_PLOT_SETTINGS& aPlotSettings ) const override;
  106. EDA_ITEM* Clone() const override
  107. {
  108. return new SCH_TEXT( *this );
  109. }
  110. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  111. virtual double Similarity( const SCH_ITEM& aItem ) const override;
  112. virtual bool operator==( const SCH_ITEM& aItem ) const override;
  113. #if defined(DEBUG)
  114. void Show( int nestLevel, std::ostream& os ) const override;
  115. #endif
  116. static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
  117. protected:
  118. KIFONT::FONT* getDrawFont() const override;
  119. const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
  120. protected:
  121. bool m_excludedFromSim;
  122. };
  123. #endif /* SCH_TEXT_H */