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 <view/view_item.h>
35 #include <kiid.h>
36 
37 
38 enum class BITMAPS : unsigned int;
39 
40 
41 enum class SEARCH_RESULT
42 {
43  QUIT,
44  CONTINUE
45 };
46 
47 
52 {
53  // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
54  FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1, // Search the current sheet only.
55  FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2, // Search hidden fields too.
56  FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3, // Search pin name and number.
57  FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4, // Use simple wild card matching (* & ?).
58  FR_SEARCH_WRAP = wxFR_MATCHCASE << 5, // Wrap around the start or end of search.
59  FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7, // Search for a item that has replaceable text.
60  FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8, // Indicates an item with replaceable text has
61  // been found.
62  FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9 // Don't replace in references.
63 };
64 
65 
66 class wxFindReplaceData;
67 class EDA_ITEM;
68 class EDA_DRAW_FRAME;
69 class EDA_RECT;
71 
72 
92 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
93 
95 typedef const INSPECTOR_FUNC& INSPECTOR;
96 
97 
98 // These define are used for the .m_flags and .m_UndoRedoStatus member of the
99 // class EDA_ITEM
100 //
101 // NB: DO NOT ADD FLAGS ANYWHERE BUT AT THE END: THE FLAG-SET IS STORED AS AN INTEGER IN FILES.
102 //
103 #define IS_CHANGED (1 << 0)
104 #define IS_LINKED (1 << 1)
105 #define IN_EDIT (1 << 2)
106 #define IS_MOVED (1 << 3)
107 #define IS_NEW (1 << 4)
108 #define IS_RESIZED (1 << 5)
109 #define IS_DRAGGED (1 << 6)
110 #define IS_DELETED (1 << 7)
111 #define IS_WIRE_IMAGE (1 << 8)
112 #define STARTPOINT (1 << 9)
113 #define ENDPOINT (1 << 10)
114 #define SELECTED (1 << 11)
115 #define TEMP_SELECTED (1 << 12)
116 #define STRUCT_DELETED (1 << 13)
117 #define CANDIDATE (1 << 14)
118 #define SKIP_STRUCT (1 << 15)
119 #define DO_NOT_DRAW (1 << 16)
120 #define IS_PASTED (1 << 17)
121 #define LOCKED (1 << 18)
122 #define UNUSED (1 << 19)
124 #define MALFORMED_F_COURTYARD (1 << 20)
125 #define MALFORMED_B_COURTYARD (1 << 21)
126 #define MALFORMED_COURTYARDS ( MALFORMED_F_COURTYARD | MALFORMED_B_COURTYARD )
127 #define BEGIN_ONPAD (1 << 22)
128 #define END_ONPAD (1 << 23)
129 #define HOLE_PROXY (1 << 24)
130 #define IS_ROLLOVER (1 << 25)
131 #define BRIGHTENED (1 << 26)
132 
133 #define DP_COUPLED (1 << 27)
134 #define UR_TRANSIENT (1 << 28)
136 
137 #define IS_DANGLING (1 << 29)
138 #define ENTERED (1 << 30)
139 
140 // WARNING: if you add flags, you'll probably need to adjust the masks in GetEditFlags() and
141 // ClearTempFlags().
142 
143 #define EDA_ITEM_ALL_FLAGS -1
144 
145 typedef unsigned STATUS_FLAGS;
146 
151 {
152 public:
153  virtual ~EDA_ITEM() { };
154 
163  inline KICAD_T Type() const { return m_structType; }
164 
165  EDA_ITEM* GetParent() const { return m_parent; }
166  virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
167 
168  inline bool IsModified() const { return m_flags & IS_CHANGED; }
169  inline bool IsNew() const { return m_flags & IS_NEW; }
170  inline bool IsMoving() const { return m_flags & IS_MOVED; }
171  inline bool IsDragging() const { return m_flags & IS_DRAGGED; }
172  inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
173  inline bool IsSelected() const { return m_flags & SELECTED; }
174  inline bool IsEntered() const { return m_flags & ENTERED; }
175  inline bool IsResized() const { return m_flags & IS_RESIZED; }
176  inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
177 
178  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
179  inline void SetSelected() { SetFlags( SELECTED ); }
180  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
181 
182  inline void ClearSelected() { ClearFlags( SELECTED ); }
183  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
184 
185  void SetModified();
186 
187  int GetState( int type ) const
188  {
189  return m_status & type;
190  }
191 
192  void SetState( int type, bool state )
193  {
194  if( state )
195  m_status |= type; // state = ON or OFF
196  else
197  m_status &= ~type;
198  }
199 
200  STATUS_FLAGS GetStatus() const { return m_status; }
201  void SetStatus( STATUS_FLAGS aStatus ) { m_status = aStatus; }
202 
203  void SetFlags( STATUS_FLAGS aMask ) { m_flags |= aMask; }
204  void ClearFlags( STATUS_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
205  STATUS_FLAGS GetFlags() const { return m_flags; }
206  bool HasFlag( STATUS_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
207 
209  {
210  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVED | IS_RESIZED | IS_DRAGGED |
212 
213  return m_flags & mask;
214  }
215 
217  {
219  DO_NOT_DRAW );
220  }
221 
223  {
225  }
226 
233  virtual bool IsType( const KICAD_T aScanTypes[] ) const
234  {
235  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
236  return true;
237 
238  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
239  {
240  if( m_structType == *p )
241  return true;
242  }
243 
244  return false;
245  }
246 
254  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
255 
256  bool IsForceVisible() const { return m_forceVisible; }
257 
264  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
265  {
266  }
267 
275  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
276  {
277  return false; // derived classes should override this function
278  }
279 
288  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
289  {
290  return false; // derived classes should override this function
291  }
292 
300  virtual const EDA_RECT GetBoundingBox() const;
301 
302  virtual wxPoint GetPosition() const { return wxPoint(); }
303  virtual void SetPosition( const wxPoint& aPos ) {};
304 
309  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
310 
323  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
324 
339  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
340 
344  template< class T >
345  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
346  INSPECTOR inspector,
347  void* testData,
348  const KICAD_T scanTypes[] )
349  {
350  for( auto it : aList )
351  {
352  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
354  return SEARCH_RESULT::QUIT;
355  }
356 
358  }
359 
363  template <class T>
365  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
366  {
367  for( auto it : aList )
368  {
369  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
371  return SEARCH_RESULT::QUIT;
372  }
373 
375  }
376 
380  virtual wxString GetClass() const = 0;
381 
392  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
393 
402  virtual BITMAPS GetMenuImage() const;
403 
415  virtual bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
416  {
417  return false;
418  }
419 
429  static bool Replace( const wxFindReplaceData& aSearchData, wxString& aText );
430 
442  virtual bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr )
443  {
444  return false;
445  }
446 
453  virtual bool IsReplaceable() const { return false; }
454 
461  bool operator<( const EDA_ITEM& aItem ) const;
462 
471  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
472 
476  EDA_ITEM& operator=( const EDA_ITEM& aItem );
477 
478  virtual const BOX2I ViewBBox() const override;
479 
480  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
481 
482 #if defined(DEBUG)
483 
493  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
494 
495  void ShowDummy( std::ostream& os ) const;
496 
504  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
505 
506 #endif
507 
508 protected:
509  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
510  EDA_ITEM( KICAD_T idType );
511  EDA_ITEM( const EDA_ITEM& base );
512 
522  bool Matches( const wxString& aText, const wxFindReplaceData& aSearchData ) const;
523 
524 public:
525  const KIID m_Uuid;
526 
527 protected:
532 
533 private:
539 };
540 
541 
548 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
549 
550 
557 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
558 
559 #endif // EDA_ITEM_H
void SetModified()
Definition: eda_item.cpp:63
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:529
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:91
#define IS_CHANGED
Item was edited, and modified.
Definition: eda_item.h:103
STATUS_FLAGS GetStatus() const
Definition: eda_item.h:200
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:415
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:169
void ClearTempFlags()
Definition: eda_item.h:216
bool IsModified() const
Definition: eda_item.h:168
bool IsSelected() const
Definition: eda_item.h:173
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:303
void ClearSelected()
Definition: eda_item.h:182
bool IsMoving() const
Definition: eda_item.h:170
virtual const wxPoint GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:309
void SetBrightened()
Definition: eda_item.h:180
virtual ~EDA_ITEM()
Definition: eda_item.h:153
#define IS_RESIZED
Item being resized.
Definition: eda_item.h:108
bool IsBrightened() const
Definition: eda_item.h:176
virtual wxPoint GetPosition() const
Definition: eda_item.h:302
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:115
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:548
BOX2 handles a 2-D bounding box, built on top of an origin point and size vector, both of templated c...
Definition: box2.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:95
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:171
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:166
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:81
STATUS_FLAGS m_status
Definition: eda_item.h:528
bool IsNew() const
Definition: eda_item.h:169
#define EDA_ITEM_ALL_FLAGS
Definition: eda_item.h:143
void ClearBrightened()
Definition: eda_item.h:183
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:275
Definition: kiid.h:44
void SetState(int type, bool state)
Definition: eda_item.h:192
#define BRIGHTENED
item is drawn with a bright contour
Definition: eda_item.h:131
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
Definition: eda_item.h:104
bool IsEntered() const
Definition: eda_item.h:174
VIEW_ITEM class definition.
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:203
void SetSelected()
Definition: eda_item.h:179
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:70
STATUS_FLAGS GetEditFlags() const
Definition: eda_item.h:208
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:199
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:264
#define ENTERED
indicates a group has been entered
Definition: eda_item.h:138
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:254
bool IsResized() const
Definition: eda_item.h:175
#define SELECTED
Definition: eda_item.h:114
void SetWireImage()
Definition: eda_item.h:178
#define CANDIDATE
flag indicating that the structure is connected
Definition: eda_item.h:117
unsigned STATUS_FLAGS
Definition: eda_item.h:145
bool IsWireImage() const
Definition: eda_item.h:172
EDA_ITEM * GetParent() const
Definition: eda_item.h:165
#define DO_NOT_DRAW
Used to disable draw function.
Definition: eda_item.h:119
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:233
#define STRUCT_DELETED
flag indication structures to be erased
Definition: eda_item.h:116
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:557
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:471
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:442
#define IS_MOVED
Item being moved.
Definition: eda_item.h:106
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:143
#define IS_DRAGGED
Item being dragged.
Definition: eda_item.h:109
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:177
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:35
const KIID m_Uuid
Definition: eda_item.h:525
EDA_UNITS
Definition: eda_units.h:38
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
Definition: eda_item.h:120
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: eda_item.h:112
bool IsForceVisible() const
Definition: eda_item.h:256
virtual wxString GetClass() const =0
Return the class name.
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
Definition: eda_item.h:111
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:107
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:206
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:453
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:288
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:150
void SetStatus(STATUS_FLAGS aStatus)
Definition: eda_item.h:201
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:204
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:538
#define ENDPOINT
ends. (Used to support dragging.)
Definition: eda_item.h:113
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:345
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:73
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:118
STATUS_FLAGS m_flags
Definition: eda_item.h:531
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:190
void ClearEditFlags()
Definition: eda_item.h:222
SEARCH_RESULT
Definition: eda_item.h:41
STATUS_FLAGS GetFlags() const
Definition: eda_item.h:205
bool m_forceVisible
Definition: eda_item.h:530
int GetState(int type) const
Definition: eda_item.h:187
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:364
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
bool HasFlag(STATUS_FLAGS aFlag) const
Definition: eda_item.h:206
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:163
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: eda_item.h:51