KiCad PCB EDA Suite
sch_text.h
Go to the documentation of this file.
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-2019 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 
30 #ifndef CLASS_TEXT_LABEL_H
31 #define CLASS_TEXT_LABEL_H
32 
33 
34 #include <macros.h>
35 #include <eda_text.h>
36 #include <sch_item.h>
37 #include <sch_connection.h> // for CONNECTION_TYPE
38 
39 
40 class LINE_READER;
42 
43 
44 /* Shape/Type of SCH_HIERLABEL and SCH_GLOBALLABEL
45  * mainly used to handle the graphic associated shape
46  */
53 };
54 
55 
56 extern const char* SheetLabelType[]; /* names of types of labels */
57 
58 
59 class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
60 {
61 protected:
63 
67 
69 
80 
81 public:
82  SCH_TEXT( const wxPoint& pos = wxPoint( 0, 0 ),
83  const wxString& text = wxEmptyString,
84  KICAD_T aType = SCH_TEXT_T );
85 
92  SCH_TEXT( const SCH_TEXT& aText );
93 
94  ~SCH_TEXT() { }
95 
96  static inline bool ClassOf( const EDA_ITEM* aItem )
97  {
98  return aItem && SCH_TEXT_T == aItem->Type();
99  }
100 
101  virtual wxString GetClass() const override
102  {
103  return wxT( "SCH_TEXT" );
104  }
105 
111  void IncrementLabel( int aIncrement );
112 
123  virtual void SetLabelSpinStyle( int aSpinStyle );
124  int GetLabelSpinStyle() const { return m_spin_style; }
125 
127 
128  void SetShape( PINSHEETLABEL_SHAPE aShape ) { m_shape = aShape; }
129 
136  virtual wxPoint GetSchematicTextOffset() const;
137 
138  void Print( wxDC* DC, const wxPoint& offset ) override;
139 
147  virtual void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
148  {
149  aPoints.clear();
150  }
151 
152  void SwapData( SCH_ITEM* aItem ) override;
153 
154  const EDA_RECT GetBoundingBox() const override;
155 
156  int GetPenSize() const override;
157 
158  // Geometric transforms (used in block operations):
159 
160  void Move( const wxPoint& aMoveVector ) override
161  {
162  EDA_TEXT::Offset( aMoveVector );
163  }
164 
165  void MirrorY( int aYaxis_position ) override;
166  void MirrorX( int aXaxis_position ) override;
167  void Rotate( wxPoint aPosition ) override;
168 
169  bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) override
170  {
171  return SCH_ITEM::Matches( GetText(), aSearchData );
172  }
173 
174  bool Replace( wxFindReplaceData& aSearchData, void* aAuxData ) override
175  {
176  return EDA_TEXT::Replace( aSearchData );
177  }
178 
179  virtual bool IsReplaceable() const override { return true; }
180 
181  void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
182 
183  bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList ) override;
184 
185  bool IsDangling() const override { return m_isDangling; }
186  void SetIsDangling( bool aIsDangling ) { m_isDangling = aIsDangling; }
187 
188  void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
189 
190  bool CanIncrementLabel() const override { return true; }
191 
192  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
193 
194  BITMAP_DEF GetMenuImage() const override;
195 
196  void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems, SCH_SHEET_PATH* aSheetPath ) override;
197 
198  wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
199  void SetPosition( const wxPoint& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
200 
201  bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override;
202  bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
203 
204  void Plot( PLOTTER* aPlotter ) override;
205 
206  EDA_ITEM* Clone() const override;
207 
208  void GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList ) override;
209 
210 #if defined(DEBUG)
211  void Show( int nestLevel, std::ostream& os ) const override;
212 #endif
213 };
214 
215 
216 class SCH_LABEL : public SCH_TEXT
217 {
218 public:
219  SCH_LABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
220 
221  // Do not create a copy constructor. The one generated by the compiler is adequate.
222 
224 
225  static inline bool ClassOf( const EDA_ITEM* aItem )
226  {
227  return aItem && SCH_LABEL_T == aItem->Type();
228  }
229 
230  wxString GetClass() const override
231  {
232  return wxT( "SCH_LABEL" );
233  }
234 
235  bool IsType( const KICAD_T aScanTypes[] ) override ;
236 
237  const EDA_RECT GetBoundingBox() const override;
238 
239  bool IsConnectable() const override { return true; }
240 
241  bool CanConnect( const SCH_ITEM* aItem ) const override
242  {
243  return aItem->Type() == SCH_LINE_T &&
244  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
245  }
246 
247  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
248 
249  BITMAP_DEF GetMenuImage() const override;
250 
251  bool IsReplaceable() const override { return true; }
252 
253  EDA_ITEM* Clone() const override;
254 
255 private:
256  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
257 };
258 
259 
260 class SCH_GLOBALLABEL : public SCH_TEXT
261 {
262 public:
263  SCH_GLOBALLABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
264 
265  // Do not create a copy constructor. The one generated by the compiler is adequate.
266 
268 
269  void Print( wxDC* DC, const wxPoint& offset ) override;
270 
271  static inline bool ClassOf( const EDA_ITEM* aItem )
272  {
273  return aItem && SCH_GLOBAL_LABEL_T == aItem->Type();
274  }
275 
276  wxString GetClass() const override
277  {
278  return wxT( "SCH_GLOBALLABEL" );
279  }
280 
281  void SetLabelSpinStyle( int aSpinStyle ) override;
282 
283  wxPoint GetSchematicTextOffset() const override;
284 
285  const EDA_RECT GetBoundingBox() const override;
286 
287  void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos ) override;
288 
289  bool IsConnectable() const override { return true; }
290 
291  bool CanConnect( const SCH_ITEM* aItem ) const override
292  {
293  return aItem->Type() == SCH_LINE_T &&
294  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
295  }
296 
297  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
298 
299  BITMAP_DEF GetMenuImage() const override;
300 
301  EDA_ITEM* Clone() const override;
302 
303 private:
304  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
305 };
306 
307 
308 class SCH_HIERLABEL : public SCH_TEXT
309 {
310 public:
311  SCH_HIERLABEL( const wxPoint& pos = wxPoint( 0, 0 ),
312  const wxString& text = wxEmptyString,
313  KICAD_T aType = SCH_HIER_LABEL_T );
314 
315  // Do not create a copy constructor. The one generated by the compiler is adequate.
316 
318 
319  void Print( wxDC* DC, const wxPoint& offset ) override;
320 
321  static inline bool ClassOf( const EDA_ITEM* aItem )
322  {
323  return aItem && SCH_HIER_LABEL_T == aItem->Type();
324  }
325 
326  wxString GetClass() const override
327  {
328  return wxT( "SCH_HIERLABEL" );
329  }
330 
331  void SetLabelSpinStyle( int aSpinStyle ) override;
332 
333  wxPoint GetSchematicTextOffset() const override;
334 
335  void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos ) override;
336 
337  const EDA_RECT GetBoundingBox() const override;
338 
339  bool IsConnectable() const override { return true; }
340 
341  bool CanConnect( const SCH_ITEM* aItem ) const override
342  {
343  return aItem->Type() == SCH_LINE_T &&
344  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
345  }
346 
347  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override;
348 
349  BITMAP_DEF GetMenuImage() const override;
350 
351  EDA_ITEM* Clone() const override;
352 
353 private:
354  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
355 };
356 
357 #endif /* CLASS_TEXT_LABEL_H */
bool IsDangling() const override
Definition: sch_text.h:185
SCH_HIERLABEL(const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString, KICAD_T aType=SCH_HIER_LABEL_T)
Definition: sch_text.cpp:1003
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:237
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:724
void Print(wxDC *DC, const wxPoint &offset) override
Function Print Print a schematic item.
Definition: sch_text.cpp:304
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:128
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:990
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_text.h:251
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:241
int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_text.cpp:286
SCH_GLOBALLABEL(const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString)
Definition: sch_text.cpp:730
virtual bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_text.h:179
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections.
Definition: sch_text.h:66
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_text.cpp:489
virtual void SetLabelSpinStyle(int aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:234
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:231
virtual wxPoint GetSchematicTextOffset() const
Definition: sch_text.cpp:149
bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList) override
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_text.cpp:333
bool Matches(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_text.h:169
bool CanIncrementLabel() const override
Definition: sch_text.h:190
CONNECTION_TYPE
void SetIsDangling(bool aIsDangling)
Definition: sch_text.h:186
CONNECTION_TYPE m_connectionType
Definition: sch_text.h:68
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_text.cpp:185
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:996
This file contains miscellaneous commonly used macros and functions.
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
Class EDA_TEXT is a mix-in class (via multiple inheritance) that handles texts such as labels,...
Definition: eda_text.h:109
int GetLabelSpinStyle() const
Definition: sch_text.h:124
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:656
void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_text.h:160
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:326
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:135
void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_text.cpp:412
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:1013
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition.
Definition: sch_text.h:256
wxPoint GetSchematicTextOffset() const override
Definition: sch_text.cpp:746
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:449
const char * SheetLabelType[]
Definition: sch_text.cpp:59
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &aPos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:844
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:937
void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList) override
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
Definition: sch_text.cpp:322
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:1101
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:422
Class SCH_SHEET_PATH.
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:96
bool IsType(const KICAD_T aScanTypes[]) override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_text.cpp:662
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:198
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:230
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_text.h:239
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:1173
void Print(wxDC *DC, const wxPoint &offset) override
Function Print Print a schematic item.
Definition: sch_text.cpp:1056
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:321
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
~SCH_LABEL()
Definition: sch_text.h:223
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:341
void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos) override
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.cpp:1079
Base plotter engine class.
Definition: plotter.h:97
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:271
void SetLabelSpinStyle(int aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:1019
PINSHEETLABEL_SHAPE
Definition: sch_text.h:47
virtual void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos)
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.h:147
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:276
void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_text.cpp:509
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_text.h:289
bool Replace(wxFindReplaceData &aSearchData)
Helper function used in search and replace dialog performs a text replace using the find and replace ...
Definition: eda_text.cpp:159
void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:271
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_text.cpp:201
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:101
SCH_TEXT(const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:109
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:455
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_text.cpp:559
int m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:79
~SCH_TEXT()
Definition: sch_text.h:94
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:291
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_text.cpp:694
const wxPoint & GetTextPos() const
Definition: eda_text.h:232
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:62
bool Replace(wxFindReplaceData &aSearchData, void *aAuxData) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_text.h:174
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:740
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_text.cpp:169
void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_text.h:199
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:718
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:1179
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_text.h:339
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: base_struct.h:493
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
SCH_LABEL(const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString)
Definition: sch_text.cpp:646
void SetLabelSpinStyle(int aSpinStyle) override
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:785
wxPoint GetSchematicTextOffset() const override
Definition: sch_text.cpp:1154
EDA_UNITS_T
Definition: common.h:133
static bool ClassOf(const EDA_ITEM *aItem)
Definition: sch_text.h:225
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition.
Definition: sch_text.h:304
void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath) override
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
Definition: sch_text.cpp:461
void Print(wxDC *DC, const wxPoint &offset) override
Function Print Print a schematic item.
Definition: sch_text.cpp:822
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:126
bool doIsConnected(const wxPoint &aPosition) const override
Function doIsConnected provides the object specific test to see if it is connected to aPosition.
Definition: sch_text.h:354
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
void IncrementLabel(int aIncrement)
Increment the label text, if it ends with a number.
Definition: sch_text.cpp:141