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 #define FMT_IU SCH_ITEM::FormatInternalUnits
55 #define FMT_ANGLE SCH_ITEM::FormatAngle
56 
57 
60 extern const wxString traceFindItem;
61 
62 
64  UNKNOWN = 0,
75 };
76 
77 
84 {
85 private:
87  const EDA_ITEM* m_item;
88 
91 
94 
95 public:
96  DANGLING_END_ITEM( DANGLING_END_T aType, const EDA_ITEM* aItem, const wxPoint& aPosition )
97  {
98  m_item = aItem;
99  m_type = aType;
100  m_pos = aPosition;
101  }
102 
103  wxPoint GetPosition() const { return m_pos; }
104  const EDA_ITEM* GetItem() const { return m_item; }
105  DANGLING_END_T GetType() const { return m_type; }
106 };
107 
108 
116 class SCH_ITEM : public EDA_ITEM
117 {
118 protected:
122 
124 public:
125  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
126 
127  SCH_ITEM( const SCH_ITEM& aItem );
128 
129  ~SCH_ITEM();
130 
131  virtual wxString GetClass() const override
132  {
133  return wxT( "SCH_ITEM" );
134  }
135 
142  virtual void SwapData( SCH_ITEM* aItem );
143 
144  SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
145  SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
146 
154  virtual bool IsMovableFromAnchorPoint() { return true; }
155 
157  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
158 
159 
164  SCH_LAYER_ID GetLayer() const { return m_Layer; }
165 
171  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
172 
177  virtual int GetPenSize() const { return 0; }
178 
190  virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
191  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0;
192 
198  virtual void Move( const wxPoint& aMoveVector ) = 0;
199 
205  virtual void MirrorY( int aYaxis_position ) = 0;
206 
212  virtual void MirrorX( int aXaxis_position ) = 0;
213 
220  virtual void Rotate( wxPoint aPosition ) = 0;
221 
228  virtual bool Save( FILE* aFile ) const = 0;
229 
238  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
239 
251  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
252 
266  virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList ) { return false; }
267 
268  virtual bool IsDangling() const { return false; }
269 
280  virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
281 
286  virtual bool IsConnectable() const { return false; }
287 
296  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
297 
305  void ClearConnections() { m_connections.clear(); }
306 
314  bool IsConnected( const wxPoint& aPoint ) const;
315 
316  virtual bool HitTest( const wxPoint& aPosition ) const override
317  {
318  return HitTest( aPosition, 0 );
319  }
320 
329  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy ) const { return false; }
330 
340  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const
341  {
342  return false;
343  }
344 
345  virtual bool CanIncrementLabel() const { return false; }
346 
353  virtual void Plot( PLOTTER* aPlotter );
354 
365  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
366  SCH_SHEET_PATH* aSheetPath ) { }
367 
372  virtual wxPoint GetPosition() const = 0;
373 
380  virtual void SetPosition( const wxPoint& aPosition ) = 0;
381 
382  virtual bool operator <( const SCH_ITEM& aItem ) const;
383 
392  static std::string FormatInternalUnits( int aValue );
393 
403  static std::string FormatAngle( double aAngle );
404 
405  static std::string FormatInternalUnits( const wxPoint& aPoint );
406 
407  static std::string FormatInternalUnits( const wxSize& aSize );
408 
409 private:
424  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
425 };
426 
427 
428 extern bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 );
429 
430 
431 #endif /* SCH_ITEM_STRUCT_H */
SCH_LAYER_ID m_Layer
const wxString traceFindItem
Flag to enable find item tracing using the WXTRACE environment variable.
EDA_ITEM * Pback
previous in linked list
Definition: base_struct.h:165
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.
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:530
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:151
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:164
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.