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.

366 lines
11 KiB

18 years ago
18 years ago
18 years ago
18 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-2015 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. /**
  25. * @file sch_text.h
  26. * @brief Definitions of the SCH_TEXT class and derivatives for Eeschema.
  27. */
  28. #ifndef CLASS_TEXT_LABEL_H
  29. #define CLASS_TEXT_LABEL_H
  30. #include <macros.h>
  31. #include <eda_text.h>
  32. #include <sch_item_struct.h>
  33. class LINE_READER;
  34. class NETLIST_OBJECT_LIST;
  35. /* Type of SCH_HIERLABEL and SCH_GLOBALLABEL
  36. * mainly used to handle the graphic associated shape
  37. */
  38. typedef enum {
  39. NET_INPUT,
  40. NET_OUTPUT,
  41. NET_BIDI,
  42. NET_TRISTATE,
  43. NET_UNSPECIFIED,
  44. NET_TMAX /* Last value */
  45. } TypeSheetLabel;
  46. extern const char* SheetLabelType[]; /* names of types of labels */
  47. class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
  48. {
  49. protected:
  50. int m_shape;
  51. /// True if not connected to another object if the object derive from SCH_TEXT
  52. /// supports connections.
  53. bool m_isDangling;
  54. /**
  55. * The orientation of text and any associated drawing elements of derived objects.
  56. * 0 is the horizontal and left justified.
  57. * 1 is vertical and top justified.
  58. * 2 is horizontal and right justified. It is the equivalent of the mirrored 0 orentation.
  59. * 3 is veritcal and bottom justifiend. It is the equivalent of the mirrored 1 orentation.
  60. * This is a duplicattion of m_Orient, m_HJustified, and m_VJustified in #EDA_TEXT but is
  61. * easier to handle that 3 parameters when editing and reading and saving files.
  62. */
  63. int m_schematicOrientation;
  64. public:
  65. SCH_TEXT( const wxPoint& pos = wxPoint( 0, 0 ),
  66. const wxString& text = wxEmptyString,
  67. KICAD_T aType = SCH_TEXT_T );
  68. /**
  69. * Copy Constructor
  70. * clones \a aText into a new object. All members are copied as is except
  71. * for the #m_isDangling member which is set to false. This prevents newly
  72. * copied objects derived from #SCH_TEXT from having their connection state
  73. * improperly set.
  74. */
  75. SCH_TEXT( const SCH_TEXT& aText );
  76. ~SCH_TEXT() { }
  77. virtual wxString GetClass() const
  78. {
  79. return wxT( "SCH_TEXT" );
  80. }
  81. /**
  82. * Function IncrementLabel
  83. * increments the label text, if it ends with a number.
  84. * @param aIncrement = the increment value to add to the number
  85. * ending the text
  86. */
  87. void IncrementLabel( int aIncrement );
  88. /**
  89. * Function SetOrientation
  90. * Set m_schematicOrientation, and initialize
  91. * m_orient,m_HJustified and m_VJustified, according to the value of
  92. * m_schematicOrientation (for a text )
  93. * must be called after changing m_schematicOrientation
  94. * @param aSchematicOrientation =
  95. * 0 = normal (horizontal, left justified).
  96. * 1 = up (vertical)
  97. * 2 = (horizontal, right justified). This can be seen as the mirrored position of 0
  98. * 3 = bottom . This can be seen as the mirrored position of up
  99. */
  100. virtual void SetOrientation( int aSchematicOrientation );
  101. int GetOrientation() { return m_schematicOrientation; }
  102. int GetShape() const { return m_shape; }
  103. void SetShape( int aShape ) { m_shape = aShape; }
  104. /**
  105. * Function GetSchematicTextOffset (virtual)
  106. * @return the offset between the SCH_TEXT position and the text itself position
  107. *
  108. * This offset depends on the orientation, the type of text, and the area required to
  109. * draw the associated graphic symbol or to put the text above a wire.
  110. */
  111. virtual wxPoint GetSchematicTextOffset() const;
  112. virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
  113. GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
  114. /**
  115. * Function CreateGraphicShape
  116. * Calculates the graphic shape (a polygon) associated to the text
  117. * @param aPoints A buffer to fill with polygon corners coordinates
  118. * @param Pos Position of the shape, for texts and labels: do nothing
  119. * Mainly for derived classes (SCH_SHEET_PIN and Hierarchical labels)
  120. */
  121. virtual void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
  122. {
  123. aPoints.clear();
  124. }
  125. virtual void SwapData( SCH_ITEM* aItem );
  126. virtual const EDA_RECT GetBoundingBox() const;
  127. virtual bool Save( FILE* aFile ) const;
  128. virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg );
  129. virtual int GetPenSize() const;
  130. // Geometric transforms (used in block operations):
  131. virtual void Move( const wxPoint& aMoveVector )
  132. {
  133. m_Pos += aMoveVector;
  134. }
  135. virtual void MirrorY( int aYaxis_position );
  136. virtual void MirrorX( int aXaxis_position );
  137. virtual void Rotate( wxPoint aPosition );
  138. virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
  139. virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
  140. {
  141. return EDA_ITEM::Replace( aSearchData, m_Text );
  142. }
  143. virtual bool IsReplaceable() const { return true; }
  144. virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList );
  145. virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );
  146. virtual bool IsDangling() const { return m_isDangling; }
  147. virtual bool IsSelectStateChanged( const wxRect& aRect );
  148. virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const;
  149. virtual bool CanIncrementLabel() const { return true; }
  150. virtual wxString GetSelectMenuText() const;
  151. virtual BITMAP_DEF GetMenuImage() const { return add_text_xpm; }
  152. virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
  153. SCH_SHEET_PATH* aSheetPath );
  154. virtual wxPoint GetPosition() const { return m_Pos; }
  155. virtual void SetPosition( const wxPoint& aPosition ) { m_Pos = aPosition; }
  156. virtual bool HitTest( const wxPoint& aPosition, int aAccuracy ) const;
  157. virtual bool HitTest( const EDA_RECT& aRect, bool aContained = false,
  158. int aAccuracy = 0 ) const;
  159. virtual void Plot( PLOTTER* aPlotter );
  160. virtual EDA_ITEM* Clone() const;
  161. void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
  162. #if defined(DEBUG)
  163. void Show( int nestLevel, std::ostream& os ) const; // override
  164. #endif
  165. };
  166. class SCH_LABEL : public SCH_TEXT
  167. {
  168. public:
  169. SCH_LABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
  170. // Do not create a copy constructor. The one generated by the compiler is adequate.
  171. ~SCH_LABEL() { }
  172. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
  173. GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
  174. wxString GetClass() const
  175. {
  176. return wxT( "SCH_LABEL" );
  177. }
  178. void SetOrientation( int aSchematicOrientation );
  179. wxPoint GetSchematicTextOffset() const;
  180. void MirrorX( int aXaxis_position );
  181. void Rotate( wxPoint aPosition );
  182. const EDA_RECT GetBoundingBox() const; // Virtual
  183. bool Save( FILE* aFile ) const;
  184. bool Load( LINE_READER& aLine, wxString& aErrorMsg );
  185. bool IsConnectable() const { return true; }
  186. wxString GetSelectMenuText() const;
  187. BITMAP_DEF GetMenuImage() const { return add_line_label_xpm; }
  188. bool IsReplaceable() const { return true; }
  189. EDA_ITEM* Clone() const;
  190. private:
  191. bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
  192. };
  193. class SCH_GLOBALLABEL : public SCH_TEXT
  194. {
  195. public:
  196. SCH_GLOBALLABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
  197. // Do not create a copy constructor. The one generated by the compiler is adequate.
  198. ~SCH_GLOBALLABEL() { }
  199. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
  200. GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
  201. wxString GetClass() const
  202. {
  203. return wxT( "SCH_GLOBALLABEL" );
  204. }
  205. void SetOrientation( int aSchematicOrientation );
  206. wxPoint GetSchematicTextOffset() const;
  207. bool Save( FILE* aFile ) const;
  208. bool Load( LINE_READER& aLine, wxString& aErrorMsg );
  209. const EDA_RECT GetBoundingBox() const; // Virtual
  210. void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos );
  211. void MirrorY( int aYaxis_position );
  212. void MirrorX( int aXaxis_position );
  213. void Rotate( wxPoint aPosition );
  214. bool IsConnectable() const { return true; }
  215. wxString GetSelectMenuText() const;
  216. BITMAP_DEF GetMenuImage() const { return add_glabel_xpm; }
  217. EDA_ITEM* Clone() const;
  218. private:
  219. bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
  220. };
  221. class SCH_HIERLABEL : public SCH_TEXT
  222. {
  223. public:
  224. SCH_HIERLABEL( const wxPoint& pos = wxPoint( 0, 0 ),
  225. const wxString& text = wxEmptyString,
  226. KICAD_T aType = SCH_HIERARCHICAL_LABEL_T );
  227. // Do not create a copy constructor. The one generated by the compiler is adequate.
  228. ~SCH_HIERLABEL() { }
  229. void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
  230. GR_DRAWMODE draw_mode, EDA_COLOR_T Color = UNSPECIFIED_COLOR );
  231. wxString GetClass() const
  232. {
  233. return wxT( "SCH_HIERLABEL" );
  234. }
  235. void SetOrientation( int aSchematicOrientation );
  236. wxPoint GetSchematicTextOffset() const;
  237. void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos );
  238. bool Save( FILE* aFile ) const;
  239. bool Load( LINE_READER& aLine, wxString& aErrorMsg );
  240. const EDA_RECT GetBoundingBox() const; // Virtual
  241. void MirrorY( int aYaxis_position );
  242. void MirrorX( int aXaxis_position );
  243. void Rotate( wxPoint aPosition );
  244. bool IsConnectable() const { return true; }
  245. wxString GetSelectMenuText() const;
  246. BITMAP_DEF GetMenuImage() const { return add_hierarchical_label_xpm; }
  247. EDA_ITEM* Clone() const;
  248. private:
  249. bool doIsConnected( const wxPoint& aPosition ) const { return m_Pos == aPosition; }
  250. };
  251. #endif /* CLASS_TEXT_LABEL_H */