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 
91 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
92 
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 LOCKED (1 << 18)
121 #define UNUSED (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 #define ENTERED (1 << 30)
137 
138 // WARNING: if you add flags, you'll probably need to adjust the masks in GetEditFlags() and
139 // ClearTempFlags().
140 
141 #define EDA_ITEM_ALL_FLAGS -1
142 
143 typedef unsigned STATUS_FLAGS;
144 
149 {
150 public:
151  virtual ~EDA_ITEM() { };
152 
161  inline KICAD_T Type() const { return m_structType; }
162 
163  EDA_ITEM* GetParent() const { return m_parent; }
164  virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
165 
166  inline bool IsModified() const { return m_flags & IS_CHANGED; }
167  inline bool IsNew() const { return m_flags & IS_NEW; }
168  inline bool IsMoving() const { return m_flags & IS_MOVED; }
169  inline bool IsDragging() const { return m_flags & IS_DRAGGED; }
170  inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
171  inline bool IsSelected() const { return m_flags & SELECTED; }
172  inline bool IsEntered() const { return m_flags & ENTERED; }
173  inline bool IsResized() const { return m_flags & IS_RESIZED; }
174  inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
175 
176  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
177  inline void SetSelected() { SetFlags( SELECTED ); }
178  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
179 
180  inline void ClearSelected() { ClearFlags( SELECTED ); }
181  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
182 
183  void SetModified();
184 
185  int GetState( int type ) const
186  {
187  return m_status & type;
188  }
189 
190  void SetState( int type, int state )
191  {
192  if( state )
193  m_status |= type; // state = ON or OFF
194  else
195  m_status &= ~type;
196  }
197 
198  STATUS_FLAGS GetStatus() const { return m_status; }
199  void SetStatus( STATUS_FLAGS aStatus ) { m_status = aStatus; }
200 
201  void SetFlags( STATUS_FLAGS aMask ) { m_flags |= aMask; }
202  void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
203  STATUS_FLAGS GetFlags() const { return m_flags; }
204  bool HasFlag( STATUS_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
205 
207  {
208  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVED | IS_RESIZED | IS_DRAGGED |
210 
211  return m_flags & mask;
212  }
213 
215  {
217  DO_NOT_DRAW );
218  }
219 
221  {
223  }
224 
231  virtual bool IsType( const KICAD_T aScanTypes[] ) const
232  {
233  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
234  return true;
235 
236  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
237  {
238  if( m_structType == *p )
239  return true;
240  }
241 
242  return false;
243  }
244 
252  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
253 
254  bool IsForceVisible() const { return m_forceVisible; }
255 
262  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
263  {
264  }
265 
273  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
274  {
275  return false; // derived classes should override this function
276  }
277 
286  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
287  {
288  return false; // derived classes should override this function
289  }
290 
298  virtual const EDA_RECT GetBoundingBox() const;
299 
300  virtual wxPoint GetPosition() const { return wxPoint(); }
301  virtual void SetPosition( const wxPoint& aPos ) {};
302 
307  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
308 
321  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
322 
337  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
338 
342  template< class T >
343  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
344  INSPECTOR inspector,
345  void* testData,
346  const KICAD_T scanTypes[] )
347  {
348  for( auto it : aList )
349  {
350  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
352  return SEARCH_RESULT::QUIT;
353  }
354 
356  }
357 
361  template <class T>
363  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
364  {
365  for( auto it : aList )
366  {
367  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
369  return SEARCH_RESULT::QUIT;
370  }
371 
373  }
374 
378  virtual wxString GetClass() const = 0;
379 
390  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
391 
400  virtual BITMAP_DEF GetMenuImage() const;
401 
413  virtual bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
414  {
415  return false;
416  }
417 
427  static bool Replace( const wxFindReplaceData& aSearchData, wxString& aText );
428 
440  virtual bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr )
441  {
442  return false;
443  }
444 
451  virtual bool IsReplaceable() const { return false; }
452 
459  bool operator<( const EDA_ITEM& aItem ) const;
460 
469  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
470 
474  EDA_ITEM& operator=( const EDA_ITEM& aItem );
475 
476  virtual const BOX2I ViewBBox() const override;
477 
478  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
479 
480 #if defined(DEBUG)
481 
491  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
492 
493  void ShowDummy( std::ostream& os ) const;
494 
502  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
503 
504 #endif
505 
506 protected:
507  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
508  EDA_ITEM( KICAD_T idType );
509  EDA_ITEM( const EDA_ITEM& base );
510 
520  bool Matches( const wxString& aText, const wxFindReplaceData& aSearchData ) const;
521 
522 public:
523  const KIID m_Uuid;
524 
525 protected:
530 
531 private:
537 };
538 
539 
546 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
547 
548 
555 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
556 
557 #endif // EDA_ITEM_H
void SetModified()
Definition: eda_item.cpp:79
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:527
virtual SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition: eda_item.cpp:107
#define IS_CHANGED
Item was edited, and modified.
Definition: eda_item.h:102
STATUS_FLAGS GetStatus() const
Definition: eda_item.h:198
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:413
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:214
bool IsModified() const
Definition: eda_item.h:166
bool IsSelected() const
Definition: eda_item.h:171
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:301
void ClearSelected()
Definition: eda_item.h:180
bool IsMoving() const
Definition: eda_item.h:168
virtual const wxPoint GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:307
void SetBrightened()
Definition: eda_item.h:178
virtual ~EDA_ITEM()
Definition: eda_item.h:151
#define IS_RESIZED
Item being resized.
Definition: eda_item.h:107
bool IsBrightened() const
Definition: eda_item.h:174
virtual wxPoint GetPosition() const
Definition: eda_item.h:300
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
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)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:546
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:94
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
bool IsDragging() const
Definition: eda_item.h:169
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:164
virtual EDA_ITEM * Clone() const
Create 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:526
bool IsNew() const
Definition: eda_item.h:167
#define EDA_ITEM_ALL_FLAGS
Definition: eda_item.h:141
void ClearBrightened()
Definition: eda_item.h:181
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is contained within or on the bounding box of an item.
Definition: eda_item.h:273
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
bool IsEntered() const
Definition: eda_item.h:172
VIEW_ITEM class definition.
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:201
void SetSelected()
Definition: eda_item.h:177
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Used to inspect and possibly collect the (search) results of iterating over a list or tree of KICAD_T...
Definition: eda_item.h:69
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:206
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return 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)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: eda_item.h:262
#define ENTERED
indicates a group has been entered
Definition: eda_item.h:136
void SetForceVisible(bool aEnable)
Set and clear force visible flag used to force the item to be drawn even if it's draw attribute is se...
Definition: eda_item.h:252
bool IsResized() const
Definition: eda_item.h:173
#define SELECTED
Definition: eda_item.h:113
void SetWireImage()
Definition: eda_item.h:176
#define CANDIDATE
flag indicating that the structure is connected
Definition: eda_item.h:116
unsigned STATUS_FLAGS
Definition: eda_item.h:143
bool IsWireImage() const
Definition: eda_item.h:170
EDA_ITEM * GetParent() const
Definition: eda_item.h:163
#define DO_NOT_DRAW
Used to disable draw function.
Definition: eda_item.h:118
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:231
#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:555
static bool Sort(const EDA_ITEM *aLeft, const EDA_ITEM *aRight)
Helper function to be used by the C++ STL sort algorithm for sorting a STL container of EDA_ITEM poin...
Definition: eda_item.h:469
virtual bool Replace(const wxFindReplaceData &aSearchData, void *aAuxData=nullptr)
Perform a text replace using the find and replace criteria in aSearchData on items that support text ...
Definition: eda_item.h:440
#define IS_MOVED
Item being moved.
Definition: eda_item.h:105
static bool Replace(const wxFindReplaceData &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:159
#define IS_DRAGGED
Item being dragged.
Definition: eda_item.h:108
EDA_ITEM & operator=(const EDA_ITEM &aItem)
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:523
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:254
virtual wxString GetClass() const =0
Return the class name.
void SetState(int type, int state)
Definition: eda_item.h:190
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
Definition: eda_item.h:110
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:123
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:451
Handle the component boundary box.
Definition: eda_rect.h:42
virtual bool HitTest(const EDA_RECT &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects or is contained within the bounding box of an item.
Definition: eda_item.h:286
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:199
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:202
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:536
#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[])
This changes first parameter to avoid the DList and use the main queue instead.
Definition: eda_item.h:343
virtual const EDA_RECT GetBoundingBox() const
Return 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
STATUS_FLAGS m_flags
Definition: eda_item.h:529
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:206
void ClearEditFlags()
Definition: eda_item.h:220
SEARCH_RESULT
Definition: eda_item.h:40
STATUS_FLAGS GetFlags() const
Definition: eda_item.h:203
bool m_forceVisible
Definition: eda_item.h:528
virtual BITMAP_DEF GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:221
int GetState(int type) const
Definition: eda_item.h:185
static SEARCH_RESULT IterateForward(std::vector< T > &aList, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Change first parameter to avoid the DList and use std::vector instead.
Definition: eda_item.h:362
#define IS_NEW
New item, just created.
Definition: eda_item.h:106
bool HasFlag(STATUS_FLAGS aFlag) const
Definition: eda_item.h:204
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: eda_item.h:50