KiCad PCB EDA Suite
sch_item_struct.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2004-2017 KiCad Developers, see change_log.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 SCH_ITEM_STRUCT_H
31 #define SCH_ITEM_STRUCT_H
32 
33 #include <vector>
34 #include <class_base_screen.h>
35 #include <general.h>
36 
37 class SCH_ITEM;
38 class SCH_SHEET_PATH;
39 class LINE_READER;
40 class SCH_EDIT_FRAME;
41 class wxFindReplaceData;
42 class PLOTTER;
43 class NETLIST_OBJECT;
45 
46 
54 extern const wxString traceFindItem;
55 
56 
58  UNKNOWN = 0,
70 };
71 
72 
79 {
80 private:
82  const EDA_ITEM* m_item;
83 
86 
89 
92 
93 public:
94  DANGLING_END_ITEM( DANGLING_END_T aType, const EDA_ITEM* aItem, const wxPoint& aPosition )
95  {
96  m_item = aItem;
97  m_type = aType;
98  m_pos = aPosition;
99  m_parent = aItem;
100  }
101 
103  const wxPoint& aPosition, const EDA_ITEM* aParent )
104  {
105  m_item = aItem;
106  m_type = aType;
107  m_pos = aPosition;
108  m_parent = aParent;
109  }
110 
111  wxPoint GetPosition() const { return m_pos; }
112  const EDA_ITEM* GetItem() const { return m_item; }
113  const EDA_ITEM* GetParent() const { return m_parent; }
114  DANGLING_END_T GetType() const { return m_type; }
115 };
116 
117 
125 class SCH_ITEM : public EDA_ITEM
126 {
127 protected:
131 
133 public:
134  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
135 
136  SCH_ITEM( const SCH_ITEM& aItem );
137 
138  ~SCH_ITEM();
139 
140  virtual wxString GetClass() const override
141  {
142  return wxT( "SCH_ITEM" );
143  }
144 
151  virtual void SwapData( SCH_ITEM* aItem );
152 
153  SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
154  SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
155 
163  virtual bool IsMovableFromAnchorPoint() { return true; }
164 
166  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
167 
168 
173  SCH_LAYER_ID GetLayer() const { return m_Layer; }
174 
180  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
181 
186  virtual int GetPenSize() const { return 0; }
187 
199  virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
200  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0;
201 
207  virtual void Move( const wxPoint& aMoveVector ) = 0;
208 
214  virtual void MirrorY( int aYaxis_position ) = 0;
215 
221  virtual void MirrorX( int aXaxis_position ) = 0;
222 
229  virtual void Rotate( wxPoint aPosition ) = 0;
230 
239  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
240 
252  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
253 
267  virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) { return false; }
268 
269  virtual bool IsDangling() const { return false; }
270 
271  virtual bool IsUnconnected() const { return false; }
272 
283  virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
284 
289  virtual bool IsConnectable() const { return false; }
290 
299  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
300 
308  void ClearConnections() { m_connections.clear(); }
309 
317  bool IsConnected( const wxPoint& aPoint ) const;
318 
319  virtual bool HitTest( const wxPoint& aPosition ) const override
320  {
321  return HitTest( aPosition, 0 );
322  }
323 
332  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy ) const { return false; }
333 
343  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const
344  {
345  return false;
346  }
347 
348  virtual bool CanIncrementLabel() const { return false; }
349 
356  virtual void Plot( PLOTTER* aPlotter );
357 
368  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
369  SCH_SHEET_PATH* aSheetPath ) { }
370 
375  virtual wxPoint GetPosition() const = 0;
376 
383  virtual void SetPosition( const wxPoint& aPosition ) = 0;
384 
385  virtual bool operator <( const SCH_ITEM& aItem ) const;
386 
395  static std::string FormatInternalUnits( int aValue );
396 
406  static std::string FormatAngle( double aAngle );
407 
408  static std::string FormatInternalUnits( const wxPoint& aPoint );
409 
410  static std::string FormatInternalUnits( const wxSize& aSize );
411 
412 private:
427  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
428 };
429 
430 #endif /* SCH_ITEM_STRUCT_H */
SCH_LAYER_ID m_Layer
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:192
virtual bool CanIncrementLabel() const
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
wxPoint GetPosition() const
virtual bool Load(LINE_READER &aLine, wxString &aErrorMsg)
Function Load reads a schematic item from aLine in a .sch file.
virtual bool IsMovableFromAnchorPoint()
Virtual function IsMovableFromAnchorPoint.
virtual void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList)
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points...
virtual bool operator<(const SCH_ITEM &aItem) const
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
EDA_ITEMS m_connections
List of items connected to this item.
const EDA_ITEM * GetItem() const
Schematic editor (Eeschema) main window.
Definition: schframe.h:118
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
SCH_ITEM * Next() const
DANGLING_END_ITEM(DANGLING_END_T aType, const EDA_ITEM *aItem, const wxPoint &aPosition, const EDA_ITEM *aParent)
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
SCH_ITEM * Back() const
virtual bool doIsConnected(const wxPoint &aPosition) const
Function doIsConnected provides the object specific test to see if it is connected to aPosition...
virtual void Rotate(wxPoint aPosition)=0
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
virtual bool HitTest(const EDA_RECT &aRect, bool aContained=false, int aAccuracy=0) const
Function HitTest tests if aRect intersects or is contained within the bounding box of an item...
DANGLING_END_T m_type
The type of connection of m_item.
wxPoint & GetStoredPos()
virtual wxPoint GetPosition() const =0
Function GetPosition.
const wxString traceFindItem
Flag to enable finding schematic item debug output.
DANGLING_END_ITEM(DANGLING_END_T aType, const EDA_ITEM *aItem, const wxPoint &aPosition)
virtual void SwapData(SCH_ITEM *aItem)
Function SwapData swap the internal data structures aItem with the schematic item.
virtual void SetPosition(const wxPoint &aPosition)=0
Function SetPosition set the schematic item position to aPosition.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:557
virtual bool IsConnectable() const
Function IsConnectable returns true if the schematic item can connect to another schematic item...
void SetLayer(SCH_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
static std::string FormatAngle(double aAngle)
Function FormatAngle converts aAngle from board units to a string appropriate for writing to file...
SCH_LAYER_ID
Eeschema drawing layers.
virtual void MirrorX(int aXaxis_position)=0
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
Class SCH_SHEET_PATH.
virtual void MirrorY(int aYaxis_position)=0
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
DANGLING_END_T GetType() const
DANGLING_END_T
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
virtual void Plot(PLOTTER *aPlotter)
Function Plot plots the schematic item to aPlotter.
Base plotter engine class.
Definition: class_plotter.h:96
const EDA_ITEM * m_item
A pointer to the connectable object.
BASE_SCREEN class implementation.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
virtual bool IsUnconnected() const
bool IsConnected(const wxPoint &aPoint) const
Function IsConnected tests the item to see if it is connected to aPoint.
void ClearConnections()
Function ClearConnections clears all of the connection items from the list.
virtual bool IsSelectStateChanged(const wxRect &aRect)
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Class EDA_RECT handles the component boundary box.
static std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from schematic internal units to a string appropriate fo...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
wxPoint m_pos
The position of the connection point.
virtual bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
virtual wxString GetClass() const override
Function GetClass returns the class name.
wxPoint m_storedPos
a temporary variable used in some move commands to store a initial pos (of the item or mouse cursor) ...
Class DANGLING_END_ITEM is a helper class used to store the state of schematic items that can be conn...
const EDA_ITEM * GetParent() const
void SetStoredPos(wxPoint aPos)
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
virtual void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)=0
Function Draw Draw a schematic item.
EDA_ITEM * Pnext
next in linked list
Definition: base_struct.h:191
const EDA_ITEM * m_parent
A pointer to the parent object (in the case of pins)
virtual bool IsDangling() const
virtual int GetPenSize() const
Function GetPenSize virtual pure.
SCH_ITEM(EDA_ITEM *aParent, KICAD_T aType)
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
virtual void GetNetListItem(NETLIST_OBJECT_LIST &aNetListItems, SCH_SHEET_PATH *aSheetPath)
Function GetNetListItem creates a new NETLIST_OBJECT for the schematic object and adds it to aNetList...
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.