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 <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 class EDA_DRAW_PANEL;
46 
48  UNKNOWN = 0,
60 };
61 
62 
69 {
70 private:
72  const EDA_ITEM* m_item;
73 
76 
79 
82 
83 public:
84  DANGLING_END_ITEM( DANGLING_END_T aType, const EDA_ITEM* aItem, const wxPoint& aPosition )
85  {
86  m_item = aItem;
87  m_type = aType;
88  m_pos = aPosition;
89  m_parent = aItem;
90  }
91 
93  const wxPoint& aPosition, const EDA_ITEM* aParent )
94  {
95  m_item = aItem;
96  m_type = aType;
97  m_pos = aPosition;
98  m_parent = aParent;
99  }
100 
101  wxPoint GetPosition() const { return m_pos; }
102  const EDA_ITEM* GetItem() const { return m_item; }
103  const EDA_ITEM* GetParent() const { return m_parent; }
104  DANGLING_END_T GetType() const { return m_type; }
105 };
106 
107 
115 class SCH_ITEM : public EDA_ITEM
116 {
117 protected:
121 
123 public:
124  SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
125 
126  SCH_ITEM( const SCH_ITEM& aItem );
127 
128  ~SCH_ITEM();
129 
130  virtual wxString GetClass() const override
131  {
132  return wxT( "SCH_ITEM" );
133  }
134 
141  virtual void SwapData( SCH_ITEM* aItem );
142 
143  SCH_ITEM* Next() const { return static_cast<SCH_ITEM*>( Pnext ); }
144  SCH_ITEM* Back() const { return static_cast<SCH_ITEM*>( Pback ); }
145 
153  virtual bool IsMovableFromAnchorPoint() { return true; }
154 
155  wxPoint& GetStoredPos() { return m_storedPos; }
156  void SetStoredPos( wxPoint aPos ) { m_storedPos = aPos; }
157 
158 
163  SCH_LAYER_ID GetLayer() const { return m_Layer; }
164 
170  void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
171 
176  void ViewGetLayers( int aLayers[], int& aCount ) const override;
177 
182  virtual int GetPenSize() const { return 0; }
183 
195  virtual void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
196  GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) = 0;
197 
203  virtual void Move( const wxPoint& aMoveVector ) = 0;
204 
210  virtual void MirrorY( int aYaxis_position ) = 0;
211 
217  virtual void MirrorX( int aXaxis_position ) = 0;
218 
225  virtual void Rotate( wxPoint aPosition ) = 0;
226 
235  virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
236 
248  virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) {}
249 
263  virtual bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList ) { return false; }
264 
265  virtual bool IsDangling() const { return false; }
266 
267  virtual bool CanConnect( const SCH_ITEM* aItem ) const { return m_Layer == aItem->GetLayer(); }
268 
279  virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
280 
285  virtual bool IsConnectable() const { return false; }
286 
295  virtual void GetConnectionPoints( std::vector< wxPoint >& aPoints ) const { }
296 
304  void ClearConnections() { m_connections.clear(); }
305 
313  bool IsConnected( const wxPoint& aPoint ) const;
314 
315  virtual bool HitTest( const wxPoint& aPosition ) const override
316  {
317  return HitTest( aPosition, 0 );
318  }
319 
328  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy ) const { return false; }
329 
339  virtual bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const
340  {
341  return false;
342  }
343 
344  virtual bool CanIncrementLabel() const { return false; }
345 
352  virtual void Plot( PLOTTER* aPlotter );
353 
364  virtual void GetNetListItem( NETLIST_OBJECT_LIST& aNetListItems,
365  SCH_SHEET_PATH* aSheetPath ) { }
366 
371  virtual wxPoint GetPosition() const = 0;
372 
379  virtual void SetPosition( const wxPoint& aPosition ) = 0;
380 
381  virtual bool operator <( const SCH_ITEM& aItem ) const;
382 
391  static std::string FormatInternalUnits( int aValue );
392 
402  static std::string FormatAngle( double aAngle );
403 
404  static std::string FormatInternalUnits( const wxPoint& aPoint );
405 
406  static std::string FormatInternalUnits( const wxSize& aSize );
407 
408 private:
423  virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
424 };
425 
426 #endif /* SCH_ITEM_STRUCT_H */
SCH_LAYER_ID m_Layer
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 CanConnect(const SCH_ITEM *aItem) 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.
void SetPosition(wxString aStr, const wxString &aDefaultMeasurementUnit, int *aX, int *aY, const wxString &aActualConversion)
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...
void MirrorX(PICKED_ITEMS_LIST &aItemsList, const wxPoint &aMirrorPoint)
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.
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
bool operator<(const COMPONENT &item1, const COMPONENT &item2)
Operator < compares two COMPONENT objects by reference designator.
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 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.
virtual bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it&#39;s dangling state...
wxPoint & GetStoredPos()
DANGLING_END_ITEM(DANGLING_END_T aType, const EDA_ITEM *aItem, const wxPoint &aPosition)
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:550
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.
SCH_LAYER_ID
Eeschema drawing layers.
Class SCH_SHEET_PATH.
DANGLING_END_T GetType() const
void MirrorY(PICKED_ITEMS_LIST &aItemsList, const wxPoint &aMirrorPoint)
DANGLING_END_T
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
Base plotter engine class.
Definition: plotter.h:97
const EDA_ITEM * m_item
A pointer to the connectable object.
virtual bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
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.
Definition: eda_rect.h:44
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
wxPoint m_pos
The position of the connection point.
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
BASE_SCREEN class implementation.
void SetStoredPos(wxPoint aPos)
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
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.
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...