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 #include <boost/ptr_container/ptr_vector.hpp>
38 
39 class SCH_ITEM;
40 class SCH_SHEET_PATH;
41 class LINE_READER;
42 class SCH_EDIT_FRAME;
43 class wxFindReplaceData;
44 class PLOTTER;
45 class NETLIST_OBJECT;
47 
48 
49 typedef boost::ptr_vector< SCH_ITEM > SCH_ITEMS;
50 typedef SCH_ITEMS::iterator SCH_ITEMS_ITR;
51 typedef std::vector< SCH_ITEMS_ITR > SCH_ITEMS_ITRS;
52 
53 
54 
55 
63 extern const wxString traceFindItem;
64 
65 
67  UNKNOWN = 0,
78 };
79 
80 
87 {
88 private:
90  const EDA_ITEM* m_item;
91 
94 
97 
98 public:
99  DANGLING_END_ITEM( DANGLING_END_T aType, const EDA_ITEM* aItem, const wxPoint& aPosition )
100  {
101  m_item = aItem;
102  m_type = aType;
103  m_pos = aPosition;
104  }
105 
106  wxPoint GetPosition() const { return m_pos; }
107  const EDA_ITEM* GetItem() const { return m_item; }
108  DANGLING_END_T GetType() const { return m_type; }
109 };
110 
111 
119 class SCH_ITEM : public EDA_ITEM
120 {
121 protected:
125 
127 public:
128  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
129 
130  SCH_ITEM( const SCH_ITEM& aItem );
131 
132  ~SCH_ITEM();
133 
134  virtual wxString GetClass() const override
135  {
136  return wxT( "SCH_ITEM" );
137  }
138 
145  virtual void SwapData( SCH_ITEM* aItem );
146 
147  SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
148  SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
149 
157  virtual bool IsMovableFromAnchorPoint() { return true; }
158 
160  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
161 
162 
167  SCH_LAYER_ID GetLayer() const { return m_Layer; }
168 
174  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
175 
180  virtual int GetPenSize() const { return 0; }
181 
193  virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
194  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0;
195 
201  virtual void Move( const wxPoint& aMoveVector ) = 0;
202 
208  virtual void MirrorY( int aYaxis_position ) = 0;
209 
215  virtual void MirrorX( int aXaxis_position ) = 0;
216 
223  virtual void Rotate( wxPoint aPosition ) = 0;
224 
231  virtual bool Save( FILE* aFile ) const = 0;
232 
241  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
242 
254  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
255 
269  virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) { return false; }
270 
271  virtual bool IsDangling() 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 
431 extern bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 );
432 
433 
434 #endif /* SCH_ITEM_STRUCT_H */
SCH_LAYER_ID m_Layer
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:179
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
std::vector< SCH_ITEMS_ITR > SCH_ITEMS_ITRS
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:117
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
SCH_ITEM * Next() const
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
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)
boost::ptr_vector< SCH_ITEM > SCH_ITEMS
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
virtual bool Save(FILE *aFile) const =0
Function Save writes the data structures for this object out to a FILE in "*.sch" format...
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:544
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: plot_common.h:86
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...
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...
SCH_ITEMS::iterator SCH_ITEMS_ITR
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
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.
bool sort_schematic_items(const SCH_ITEM *aItem1, const SCH_ITEM *aItem2)
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...
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:178
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.