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-2017 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_struct.h>
37 
38 
39 class LINE_READER;
41 
42 
43 /* Shape/Type of SCH_HIERLABEL and SCH_GLOBALLABEL
44  * mainly used to handle the graphic associated shape
45  */
52 };
53 
54 
55 extern const char* SheetLabelType[]; /* names of types of labels */
56 
57 
58 class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
59 {
60 protected:
62 
66 
77 
78 public:
79  SCH_TEXT( const wxPoint& pos = wxPoint( 0, 0 ),
80  const wxString& text = wxEmptyString,
81  KICAD_T aType = SCH_TEXT_T );
82 
89  SCH_TEXT( const SCH_TEXT& aText );
90 
91  ~SCH_TEXT() { }
92 
93  virtual wxString GetClass() const override
94  {
95  return wxT( "SCH_TEXT" );
96  }
97 
103  void IncrementLabel( int aIncrement );
104 
115  virtual void SetLabelSpinStyle( int aSpinStyle );
116  int GetLabelSpinStyle() const { return m_spin_style; }
117 
119 
120  void SetShape( PINSHEETLABEL_SHAPE aShape ) { m_shape = aShape; }
121 
128  virtual wxPoint GetSchematicTextOffset() const;
129 
130  virtual void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
131  GR_DRAWMODE draw_mode, COLOR4D Color = COLOR4D::UNSPECIFIED ) override;
132 
140  virtual void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos )
141  {
142  aPoints.clear();
143  }
144 
145  virtual void SwapData( SCH_ITEM* aItem ) override;
146 
147  virtual const EDA_RECT GetBoundingBox() const override;
148 
149  virtual int GetPenSize() const override;
150 
151  // Geometric transforms (used in block operations):
152 
153  virtual void Move( const wxPoint& aMoveVector ) override
154  {
155  EDA_TEXT::Offset( aMoveVector );
156  }
157 
158  virtual void MirrorY( int aYaxis_position ) override;
159 
160  virtual void MirrorX( int aXaxis_position ) override;
161 
162  virtual void Rotate( wxPoint aPosition ) override;
163 
164  virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) override;
165 
166  virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) override
167  {
168  return EDA_ITEM::Replace( aSearchData, m_Text );
169  }
170 
171  virtual bool IsReplaceable() const override { return true; }
172 
173  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
174 
175  virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) override;
176 
177  virtual bool IsDangling() const override { return m_isDangling; }
178 
179  virtual bool IsSelectStateChanged( const wxRect& aRect ) override;
180 
181  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const override;
182 
183  virtual bool CanIncrementLabel() const override { return true; }
184 
185  virtual wxString GetSelectMenuText() const override;
186 
187  virtual BITMAP_DEF GetMenuImage() const override;
188 
189  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
190  SCH_SHEET_PATH* aSheetPath ) override;
191 
192  virtual wxPoint GetPosition() const override { return EDA_TEXT::GetTextPos(); }
193 
194  virtual void SetPosition( const wxPoint& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
195 
196  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
197 
198  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = false,
199  int aAccuracy = 0 ) const override;
200 
201  virtual void Plot( PLOTTER* aPlotter ) override;
202 
203  virtual EDA_ITEM* Clone() const override;
204 
205  void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) override;
206 
207 #if defined(DEBUG)
208  void Show( int nestLevel, std::ostream& os ) const override;
209 #endif
210 };
211 
212 
213 class SCH_LABEL : public SCH_TEXT
214 {
215 public:
216  SCH_LABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
217 
218  // Do not create a copy constructor. The one generated by the compiler is adequate.
219 
221 
222  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
223  GR_DRAWMODE draw_mode, COLOR4D Color = COLOR4D::UNSPECIFIED ) override;
224 
225  wxString GetClass() const override
226  {
227  return wxT( "SCH_LABEL" );
228  }
229 
230  void SetLabelSpinStyle( int aSpinStyle ) override;
231 
232  wxPoint GetSchematicTextOffset() const override;
233 
234  void MirrorX( int aXaxis_position ) override;
235 
236  void Rotate( wxPoint aPosition ) override;
237 
238  const EDA_RECT GetBoundingBox() const override;
239 
240  bool IsConnectable() const override { return true; }
241 
242  bool CanConnect( const SCH_ITEM* aItem ) const override
243  {
244  return aItem->Type() == SCH_LINE_T &&
245  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
246  }
247 
248  wxString GetSelectMenuText() const override;
249 
250  BITMAP_DEF GetMenuImage() const override;
251 
252  bool IsReplaceable() const override { return true; }
253 
254  EDA_ITEM* Clone() const override;
255 
256 private:
257  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
258 };
259 
260 
261 class SCH_GLOBALLABEL : public SCH_TEXT
262 {
263 public:
264  SCH_GLOBALLABEL( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString );
265 
266  // Do not create a copy constructor. The one generated by the compiler is adequate.
267 
269 
270  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
271  GR_DRAWMODE draw_mode, COLOR4D Color = COLOR4D::UNSPECIFIED ) override;
272 
273  wxString GetClass() const override
274  {
275  return wxT( "SCH_GLOBALLABEL" );
276  }
277 
278  void SetLabelSpinStyle( int aSpinStyle ) override;
279 
280  wxPoint GetSchematicTextOffset() const override;
281 
282  const EDA_RECT GetBoundingBox() const override;
283 
284  void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& aPos ) override;
285 
286  void MirrorY( int aYaxis_position ) override;
287 
288  void MirrorX( int aXaxis_position ) override;
289 
290  void Rotate( wxPoint aPosition ) override;
291 
292  bool IsConnectable() const override { return true; }
293 
294  bool CanConnect( const SCH_ITEM* aItem ) const override
295  {
296  return aItem->Type() == SCH_LINE_T &&
297  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
298  }
299 
300  wxString GetSelectMenuText() const override;
301 
302  BITMAP_DEF GetMenuImage() const override;
303 
304  EDA_ITEM* Clone() const override;
305 
306 private:
307  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
308 };
309 
310 
311 class SCH_HIERLABEL : public SCH_TEXT
312 {
313 public:
314  SCH_HIERLABEL( const wxPoint& pos = wxPoint( 0, 0 ),
315  const wxString& text = wxEmptyString,
317 
318  // Do not create a copy constructor. The one generated by the compiler is adequate.
319 
321 
322  void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset,
323  GR_DRAWMODE draw_mode, COLOR4D Color = COLOR4D::UNSPECIFIED ) override;
324 
325  wxString GetClass() const override
326  {
327  return wxT( "SCH_HIERLABEL" );
328  }
329 
330  void SetLabelSpinStyle( int aSpinStyle ) override;
331 
332  wxPoint GetSchematicTextOffset() const override;
333 
334  void CreateGraphicShape( std::vector <wxPoint>& aPoints, const wxPoint& Pos ) override;
335 
336  const EDA_RECT GetBoundingBox() const override;
337 
338  void MirrorY( int aYaxis_position ) override;
339 
340  void MirrorX( int aXaxis_position ) override;
341 
342  void Rotate( wxPoint aPosition ) override;
343 
344  bool IsConnectable() const override { return true; }
345 
346  bool CanConnect( const SCH_ITEM* aItem ) const override
347  {
348  return aItem->Type() == SCH_LINE_T &&
349  ( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
350  }
351 
352  wxString GetSelectMenuText() const override;
353 
354  BITMAP_DEF GetMenuImage() const override;
355 
356  EDA_ITEM* Clone() const override;
357 
358 private:
359  bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; }
360 };
361 
362 #endif /* CLASS_TEXT_LABEL_H */
PINSHEETLABEL_SHAPE GetShape() const
Definition: sch_text.h:118
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:227
void SetShape(PINSHEETLABEL_SHAPE aShape)
Definition: sch_text.h:120
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition: sch_text.cpp:539
wxString m_Text
Definition: eda_text.h:344
bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_text.h:252
virtual bool CanIncrementLabel() const override
Definition: sch_text.h:183
PNG memory record (file in memory).
Definition: bitmap_types.h:41
virtual void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, const wxPoint &offset, GR_DRAWMODE draw_mode, COLOR4D Color=COLOR4D::UNSPECIFIED) override
Function Draw Draw a schematic item.
Definition: sch_text.cpp:345
virtual bool IsDangling() const override
Definition: sch_text.h:177
const wxPoint & GetTextPos() const
Definition: eda_text.h:222
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:242
virtual int GetPenSize() const override
Function GetPenSize virtual pure.
Definition: sch_text.cpp:327
Base schematic object class definition.
bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
virtual bool IsReplaceable() const override
Function IsReplaceable.
Definition: sch_text.h:171
virtual void SetPosition(const wxPoint &aPosition) override
Function SetPosition set the schematic item position to aPosition.
Definition: sch_text.h:194
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: sch_text.cpp:607
bool m_isDangling
True if not connected to another object if the object derive from SCH_TEXT supports connections...
Definition: sch_text.h:65
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData, wxPoint *aFindLocation) override
Function Matches compares the item against the search criteria in aSearchData.
Definition: sch_text.cpp:177
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:278
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:221
int GetLabelSpinStyle() const
Definition: sch_text.h:116
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition of base KiCad text object.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
virtual void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Definition: sch_text.cpp:218
This file contains miscellaneous commonly used macros and functions.
virtual void Move(const wxPoint &aMoveVector) override
Function Move moves the item by aMoveVector to a new position.
Definition: sch_text.h:153
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:112
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:325
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_text.cpp:132
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const override
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_text.cpp:460
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:257
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
const char * SheetLabelType[]
Definition: sch_text.cpp:58
virtual wxString GetSelectMenuText() const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: sch_text.cpp:497
virtual 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:383
virtual const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
Definition: sch_text.cpp:470
Class SCH_SHEET_PATH.
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:225
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
Definition: sch_text.h:240
virtual wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_text.h:192
~SCH_LABEL()
Definition: sch_text.h:220
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:346
Base plotter engine class.
Definition: plotter.h:96
PINSHEETLABEL_SHAPE
Definition: sch_text.h:46
virtual void CreateGraphicShape(std::vector< wxPoint > &aPoints, const wxPoint &Pos)
Calculate the graphic shape (a polygon) associated to the text.
Definition: sch_text.h:140
virtual bool IsSelectStateChanged(const wxRect &aRect) override
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Definition: sch_text.cpp:447
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:273
virtual void Plot(PLOTTER *aPlotter) override
Function Plot plots the schematic item to aPlotter.
Definition: sch_text.cpp:559
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
Definition: sch_text.h:292
virtual bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList) override
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it&#39;s dangling state...
Definition: sch_text.cpp:394
virtual void SwapData(SCH_ITEM *aItem) override
Function SwapData swap the internal data structures aItem with the schematic item.
Definition: sch_text.cpp:312
virtual void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_text.cpp:241
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_text.h:93
SCH_TEXT(const wxPoint &pos=wxPoint(0, 0), const wxString &text=wxEmptyString, KICAD_T aType=SCH_TEXT_T)
Definition: sch_text.cpp:108
virtual BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_text.cpp:505
virtual bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL) override
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: sch_text.h:166
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int m_spin_style
The orientation of text and any associated drawing elements of derived objects.
Definition: sch_text.h:76
~SCH_TEXT()
Definition: sch_text.h:91
virtual wxPoint GetSchematicTextOffset() const
Definition: sch_text.cpp:144
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_text.h:294
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
PINSHEETLABEL_SHAPE m_shape
Definition: sch_text.h:61
virtual void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
Definition: sch_text.cpp:195
bool IsConnectable() const override
Function IsConnectable returns true if the schematic item can connect to another schematic item...
Definition: sch_text.h:344
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
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:307
virtual 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:511
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:359
void IncrementLabel(int aIncrement)
Increment the label text, if it ends with a number.
Definition: sch_text.cpp:138
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39