KiCad PCB EDA Suite
eda_item.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) 2013-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008-2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef EDA_ITEM_H
28 #define EDA_ITEM_H
29 
30 #include <deque>
31 
32 #include <core/typeinfo.h>
33 #include <wx/fdrepdlg.h>
34 #include <bitmap_types.h>
35 #include <view/view_item.h>
36 #include <kiid.h>
37 
38 
39 
40 enum class SEARCH_RESULT
41 {
42  QUIT,
43  CONTINUE
44 };
45 
46 
51 {
52  // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
53  FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1, // Search the current sheet only.
54  FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2, // Search hidden fields too.
55  FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3, // Search pin name and number.
56  FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4, // Use simple wild card matching (* & ?).
57  FR_SEARCH_WRAP = wxFR_MATCHCASE << 5, // Wrap around the start or end of search.
58  FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7, // Search for a item that has replaceable text.
59  FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8, // Indicates an item with replaceable text has
60  // been found.
61  FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9 // Don't replace in references.
62 };
63 
64 
65 class wxFindReplaceData;
66 class EDA_ITEM;
67 class EDA_DRAW_FRAME;
68 class EDA_RECT;
70 
71 
92 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
93 
94 typedef const INSPECTOR_FUNC& INSPECTOR;
95 
96 
97 // These define are used for the .m_flags and .m_UndoRedoStatus member of the
98 // class EDA_ITEM
99 //
100 // NB: DO NOT ADD FLAGS ANYWHERE BUT AT THE END: THE FLAG-SET IS STORED AS AN INTEGER IN FILES.
101 //
102 #define IS_CHANGED (1 << 0)
103 #define IS_LINKED (1 << 1)
104 #define IN_EDIT (1 << 2)
105 #define IS_MOVED (1 << 3)
106 #define IS_NEW (1 << 4)
107 #define IS_RESIZED (1 << 5)
108 #define IS_DRAGGED (1 << 6)
109 #define IS_DELETED (1 << 7)
110 #define IS_WIRE_IMAGE (1 << 8)
111 #define STARTPOINT (1 << 9)
112 #define ENDPOINT (1 << 10)
113 #define SELECTED (1 << 11)
114 #define TEMP_SELECTED (1 << 12)
115 #define STRUCT_DELETED (1 << 13)
116 #define CANDIDATE (1 << 14)
117 #define SKIP_STRUCT (1 << 15)
118 #define DO_NOT_DRAW (1 << 16)
119 #define IS_PASTED (1 << 17)
120 #define TRACK_LOCKED (1 << 18)
121 #define TRACK_AR (1 << 19)
122 #define MALFORMED_F_COURTYARD (1 << 20)
123 #define MALFORMED_B_COURTYARD (1 << 21)
124 #define MALFORMED_COURTYARDS ( MALFORMED_F_COURTYARD | MALFORMED_B_COURTYARD )
125 #define BEGIN_ONPAD (1 << 22)
126 #define END_ONPAD (1 << 23)
127 #define HOLE_PROXY (1 << 24)
128 #define IS_ROLLOVER (1 << 25)
129 #define BRIGHTENED (1 << 26)
130 
131 #define DP_COUPLED (1 << 27)
132 #define UR_TRANSIENT (1 << 28)
134 
135 #define IS_DANGLING (1 << 29)
136 
137 // WARNING: if you add flags, you'll probably need to adjust the masks in GetEditFlags() and
138 // ClearTempFlags().
139 
140 #define EDA_ITEM_ALL_FLAGS -1
141 
142 typedef unsigned STATUS_FLAGS;
143 
149 {
150 public:
151  const KIID m_Uuid;
152 
153 private:
159 
160 protected:
165 
166 protected:
167  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
168  EDA_ITEM( KICAD_T idType );
169  EDA_ITEM( const EDA_ITEM& base );
170 
171 public:
172  virtual ~EDA_ITEM() { };
173 
181  inline KICAD_T Type() const { return m_structType; }
182 
183  EDA_ITEM* GetParent() const { return m_parent; }
184  virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
185 
186  inline bool IsModified() const { return m_flags & IS_CHANGED; }
187  inline bool IsNew() const { return m_flags & IS_NEW; }
188  inline bool IsMoving() const { return m_flags & IS_MOVED; }
189  inline bool IsDragging() const { return m_flags & IS_DRAGGED; }
190  inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
191  inline bool IsSelected() const { return m_flags & SELECTED; }
192  inline bool IsResized() const { return m_flags & IS_RESIZED; }
193  inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
194 
195  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
196  inline void SetSelected() { SetFlags( SELECTED ); }
197  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
198 
199  inline void ClearSelected() { ClearFlags( SELECTED ); }
200  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
201 
202  void SetModified();
203 
204  int GetState( int type ) const
205  {
206  return m_status & type;
207  }
208 
209  void SetState( int type, int state )
210  {
211  if( state )
212  m_status |= type; // state = ON or OFF
213  else
214  m_status &= ~type;
215  }
216 
217  STATUS_FLAGS GetStatus() const { return m_status; }
218  void SetStatus( STATUS_FLAGS aStatus ) { m_status = aStatus; }
219 
220  void SetFlags( STATUS_FLAGS aMask ) { m_flags |= aMask; }
221  void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
222  STATUS_FLAGS GetFlags() const { return m_flags; }
223  bool HasFlag( STATUS_FLAGS aFlag ) { return ( m_flags & aFlag ) == aFlag; }
224 
226  {
227  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVED | IS_RESIZED | IS_DRAGGED |
229 
230  return m_flags & mask;
231  }
232 
234  {
236  DO_NOT_DRAW );
237  }
238 
240  {
242  }
243 
250  virtual bool IsType( const KICAD_T aScanTypes[] ) const
251  {
252  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
253  return true;
254 
255  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
256  {
257  if( m_structType == *p )
258  return true;
259  }
260 
261  return false;
262  }
263 
272  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
273 
274  bool IsForceVisible() const { return m_forceVisible; }
275 
283  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
284  {
285  }
286 
295  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
296  {
297  return false; // derived classes should override this function
298  }
299 
309  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
310  {
311  return false; // derived classes should override this function
312  }
313 
323  virtual const EDA_RECT GetBoundingBox() const;
324 
325  virtual wxPoint GetPosition() const { return wxPoint(); }
326  virtual void SetPosition( const wxPoint& aPos ) {};
327 
333  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
334 
348  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
349 
364  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
365 
371  template< class T >
372  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
373  INSPECTOR inspector,
374  void* testData,
375  const KICAD_T scanTypes[] )
376  {
377  for( auto it : aList )
378  {
379  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
381  return SEARCH_RESULT::QUIT;
382  }
383 
385  }
386 
392  template <class T>
394  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
395  {
396  for( auto it : aList )
397  {
398  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
400  return SEARCH_RESULT::QUIT;
401  }
402 
404  }
405 
411  virtual wxString GetClass() const = 0;
412 
422  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
423 
431  virtual BITMAP_DEF GetMenuImage() const;
432 
446  virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData )
447  {
448  return false;
449  }
450 
463  static bool Replace( wxFindReplaceData& aSearchData, wxString& aText );
464 
478  virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
479 
490  virtual bool IsReplaceable() const { return false; }
491 
498  bool operator<( const EDA_ITEM& aItem ) const;
499 
509  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
510 
515  EDA_ITEM& operator=( const EDA_ITEM& aItem );
516 
517  virtual const BOX2I ViewBBox() const override;
518 
519  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
520 
521 #if defined(DEBUG)
522 
530  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
531  // pure virtual so compiler warns if somebody mucks up a derived declaration
532 
533  void ShowDummy( std::ostream& os ) const;
534 
542  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
543 
544 #endif
545 
546 protected:
556  bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
557 };
558 
559 
567 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
568 
569 
576 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
577 
578 #endif // EDA_ITEM_H
void SetModified()
Definition: eda_item.cpp:79
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:162
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
Definition: eda_item.cpp:107
#define IS_CHANGED
std::function passed to nested users by ref, avoids copying std::function
Definition: eda_item.h:102
STATUS_FLAGS GetStatus() const
Definition: eda_item.h:217
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:185
PNG memory record (file in memory).
Definition: bitmap_def.h:29
void ClearTempFlags()
Definition: eda_item.h:233
bool IsModified() const
Definition: eda_item.h:186
bool IsSelected() const
Definition: eda_item.h:191
static bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
Definition: eda_item.cpp:159
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:326
void ClearSelected()
Definition: eda_item.h:199
bool IsMoving() const
Definition: eda_item.h:188
virtual const wxPoint GetFocusPosition() const
Function GetFocusPosition similar to GetPosition, but allows items to return their visual center rath...
Definition: eda_item.h:333
void SetBrightened()
Definition: eda_item.h:197
virtual ~EDA_ITEM()
Definition: eda_item.h:172
#define IS_RESIZED
Item being resized.
Definition: eda_item.h:107
bool IsBrightened() const
Definition: eda_item.h:193
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
The base class for create windows for drawing purpose.
#define TEMP_SELECTED
flag indicating that the structure has already selected
Definition: eda_item.h:114
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Function new_clone provides cloning capabilities for all Boost pointer containers of EDA_ITEM pointer...
Definition: eda_item.h:567
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
bool IsDragging() const
Definition: eda_item.h:189
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:184
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:97
STATUS_FLAGS m_status
Definition: eda_item.h:161
bool IsNew() const
Definition: eda_item.h:187
#define EDA_ITEM_ALL_FLAGS
Definition: eda_item.h:140
void ClearBrightened()
Definition: eda_item.h:200
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:295
Definition: kiid.h:44
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:129
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: eda_item.h:103
VIEW_ITEM class definition.
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:220
#define NULL
void SetSelected()
Definition: eda_item.h:196
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: eda_item.h:69
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:225
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Definition: eda_item.cpp:214
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: eda_item.h:283
void SetForceVisible(bool aEnable)
Function SetForceVisible is used to set and cleag force visible flag used to force the item to be dra...
Definition: eda_item.h:272
bool IsResized() const
Definition: eda_item.h:192
#define SELECTED
Definition: eda_item.h:113
void SetWireImage()
Definition: eda_item.h:195
#define CANDIDATE
flag indicating that the structure is connected
Definition: eda_item.h:116
unsigned STATUS_FLAGS
Definition: eda_item.h:142
bool IsWireImage() const
Definition: eda_item.h:190
EDA_ITEM * GetParent() const
Definition: eda_item.h:183
#define DO_NOT_DRAW
Used to disable draw function.
Definition: eda_item.h:118
virtual bool IsType(const KICAD_T aScanTypes[]) const
Function IsType Checks whether the item is one of the listed types.
Definition: eda_item.h:250
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:115
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:576
static bool Sort(const EDA_ITEM *aLeft, const EDA_ITEM *aRight)
Function Sort is a helper function to be used by the C++ STL sort algorithm for sorting a STL contain...
Definition: eda_item.h:509
#define IS_MOVED
Item being moved.
Definition: eda_item.h:105
#define IS_DRAGGED
Item being dragged.
Definition: eda_item.h:108
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Operator assignment is used to assign the members of aItem to another object.
Definition: eda_item.cpp:193
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:51
const KIID m_Uuid
Definition: eda_item.h:151
EDA_UNITS
Definition: eda_units.h:38
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
Definition: eda_item.h:119
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: eda_item.h:111
bool IsForceVisible() const
Definition: eda_item.h:274
virtual wxString GetClass() const =0
Function GetClass returns the class name.
void SetState(int type, int state)
Definition: eda_item.h:209
virtual bool Replace(wxFindReplaceData &aSearchData, void *aAuxData=NULL)
Function Replace performs a text replace using the find and replace criteria in aSearchData on items ...
Definition: eda_item.h:478
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
Definition: eda_item.h:110
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: eda_item.cpp:123
virtual bool IsReplaceable() const
Function IsReplaceable.
Definition: eda_item.h:490
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
virtual bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const
Function HitTest tests if aRect intersects or is contained within the bounding box of an item.
Definition: eda_item.h:309
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
void SetStatus(STATUS_FLAGS aStatus)
Definition: eda_item.h:218
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:221
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:158
#define ENDPOINT
ends. (Used to support dragging.)
Definition: eda_item.h:112
static SEARCH_RESULT IterateForward(std::deque< T > &aList, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
Definition: eda_item.h:372
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: eda_item.cpp:89
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: eda_item.h:117
bool HasFlag(STATUS_FLAGS aFlag)
Definition: eda_item.h:223
STATUS_FLAGS m_flags
Definition: eda_item.h:164
virtual const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
Definition: eda_item.cpp:206
void ClearEditFlags()
Definition: eda_item.h:239
SEARCH_RESULT
Definition: eda_item.h:40
STATUS_FLAGS GetFlags() const
Definition: eda_item.h:222
bool m_forceVisible
Definition: eda_item.h:163
virtual BITMAP_DEF GetMenuImage() const
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: eda_item.cpp:221
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: eda_item.h:446
int GetState(int type) const
Definition: eda_item.h:204
static SEARCH_RESULT IterateForward(std::vector< T > &aList, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T )
Definition: eda_item.h:393
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: eda_item.h:50