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.

202 lines
6.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 The 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_connection.h> // for CONNECTION_TYPE
  29. #include <schematic.h>
  30. class HTML_MESSAGE_BOX;
  31. class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
  32. {
  33. public:
  34. SCH_TEXT( const VECTOR2I& aPos = { 0, 0 }, const wxString& aText = wxEmptyString,
  35. SCH_LAYER_ID aLayer = LAYER_NOTES, KICAD_T aType = SCH_TEXT_T );
  36. SCH_TEXT( const SCH_TEXT& aText );
  37. ~SCH_TEXT() override { }
  38. static bool ClassOf( const EDA_ITEM* aItem )
  39. {
  40. return aItem && SCH_TEXT_T == aItem->Type();
  41. }
  42. wxString GetClass() const override
  43. {
  44. return wxT( "SCH_TEXT" );
  45. }
  46. wxString GetFriendlyName() const override
  47. {
  48. return _( "Text" );
  49. }
  50. KIFONT::FONT* GetDrawFont( const RENDER_SETTINGS* aSettings ) const override;
  51. virtual wxString GetShownText( const SCH_SHEET_PATH* aPath, bool aAllowExtraText,
  52. int aDepth = 0 ) const;
  53. wxString GetShownText( bool aAllowExtraText, int aDepth = 0 ) const override
  54. {
  55. SCHEMATIC* schematic = Schematic();
  56. if( schematic )
  57. return GetShownText( &schematic->CurrentSheet(), aAllowExtraText, aDepth );
  58. else
  59. return GetText();
  60. }
  61. int GetSchTextSize() const { return GetTextWidth(); }
  62. void SetSchTextSize( int aSize ) { SetTextSize( VECTOR2I( aSize, aSize ) ); }
  63. bool IsHypertext() const override
  64. {
  65. return HasHyperlink();
  66. }
  67. void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override;
  68. void SetExcludedFromSim( bool aExclude, const SCH_SHEET_PATH* aInstance = nullptr,
  69. const wxString& aVariantName = wxEmptyString ) override
  70. {
  71. m_excludedFromSim = aExclude;
  72. }
  73. bool GetExcludedFromSim( const SCH_SHEET_PATH* aInstance = nullptr,
  74. const wxString& aVariantName = wxEmptyString ) const override
  75. {
  76. return m_excludedFromSim;
  77. }
  78. /**
  79. * This offset depends on the orientation, the type of text, and the area required to
  80. * draw the associated graphic symbol or to put the text above a wire.
  81. *
  82. * @return the offset between the SCH_TEXT position and the text itself position
  83. */
  84. virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
  85. const BOX2I GetBoundingBox() const override;
  86. bool operator<( const SCH_ITEM& aItem ) const override;
  87. int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
  88. int GetPenWidth() const override;
  89. void Move( const VECTOR2I& aMoveVector ) override
  90. {
  91. EDA_TEXT::Offset( aMoveVector );
  92. }
  93. void NormalizeJustification( bool inverse );
  94. void MirrorHorizontally( int aCenter ) override;
  95. void MirrorVertically( int aCenter ) override;
  96. void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override;
  97. virtual void Rotate90( bool aClockwise );
  98. virtual void MirrorSpinStyle( bool aLeftRight );
  99. void BeginEdit( const VECTOR2I& aStartPoint ) override;
  100. void CalcEdit( const VECTOR2I& aPosition ) override;
  101. bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const override
  102. {
  103. return SCH_ITEM::Matches( GetText(), aSearchData );
  104. }
  105. bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) override
  106. {
  107. return EDA_TEXT::Replace( aSearchData );
  108. }
  109. bool IsReplaceable() const override { return true; }
  110. std::vector<int> ViewGetLayers() const override;
  111. wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override;
  112. BITMAPS GetMenuImage() const override;
  113. VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
  114. void SetPosition( const VECTOR2I& aPosition ) override
  115. {
  116. EDA_TEXT::SetTextPos( aPosition );
  117. }
  118. bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
  119. bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const override;
  120. bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const override;
  121. void Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& aPlotOpts,
  122. int aUnit, int aBodyStyle, const VECTOR2I& aOffset, bool aDimmed ) override;
  123. EDA_ITEM* Clone() const override
  124. {
  125. return new SCH_TEXT( *this );
  126. }
  127. void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
  128. double Similarity( const SCH_ITEM& aItem ) const override;
  129. bool operator==( const SCH_ITEM& aItem ) const override;
  130. #if defined(DEBUG)
  131. void Show( int nestLevel, std::ostream& os ) const override;
  132. #endif
  133. static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
  134. protected:
  135. void swapData( SCH_ITEM* aItem ) override;
  136. const KIFONT::METRICS& getFontMetrics() const override { return GetFontMetrics(); }
  137. /**
  138. * @copydoc SCH_ITEM::compare()
  139. *
  140. * The text specific sort order is as follows:
  141. * - Text string, case insensitive compare.
  142. * - Text horizontal (X) position.
  143. * - Text vertical (Y) position.
  144. * - Text width.
  145. * - Text height.
  146. */
  147. int compare( const SCH_ITEM& aOther, int aCompareFlags = 0 ) const override;
  148. protected:
  149. bool m_excludedFromSim;
  150. };
  151. #endif /* SCH_TEXT_H */