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 <eda_item_flags.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 = 0x4 << 1, // Search the current sheet only.
55  FR_SEARCH_ALL_FIELDS = 0x4 << 2, // Search hidden fields too.
56  FR_SEARCH_ALL_PINS = 0x4 << 3, // Search pin name and number.
57  FR_MATCH_WILDCARD = 0x4 << 4, // Use simple wild card matching (* & ?).
58  FR_SEARCH_WRAP = 0x4 << 5, // Wrap around the start or end of search.
59  FR_SEARCH_REPLACE = 0x4 << 7, // Search for a item that has replaceable text.
60  FR_REPLACE_ITEM_FOUND = 0x4 << 8, // Indicates an item with replaceable text has
61  // been found.
62  FR_REPLACE_REFERENCES = 0x4 << 9 // Don't replace in references.
63 };
64 
65 
66 class wxFindReplaceData;
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 
101 {
102 public:
103  virtual ~EDA_ITEM() { };
104 
113  inline KICAD_T Type() const { return m_structType; }
114 
115  EDA_ITEM* GetParent() const { return m_parent; }
116  virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
117 
118  inline bool IsModified() const { return m_flags & IS_CHANGED; }
119  inline bool IsNew() const { return m_flags & IS_NEW; }
120  inline bool IsMoving() const { return m_flags & IS_MOVING; }
121  inline bool IsDragging() const { return m_flags & IS_DRAGGING; }
122  inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
123  inline bool IsSelected() const { return m_flags & SELECTED; }
124  inline bool IsEntered() const { return m_flags & ENTERED; }
125  inline bool IsResized() const { return m_flags & IS_RESIZING; }
126  inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
127 
128  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
129  inline void SetSelected() { SetFlags( SELECTED ); }
130  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
131 
132  inline void ClearSelected() { ClearFlags( SELECTED ); }
133  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
134 
135  void SetModified();
136 
137  int GetState( EDA_ITEM_FLAGS type ) const
138  {
139  return m_status & type;
140  }
141 
142  void SetState( EDA_ITEM_FLAGS type, bool state )
143  {
144  if( state )
145  m_status |= type; // state = ON or OFF
146  else
147  m_status &= ~type;
148  }
149 
150  EDA_ITEM_FLAGS GetStatus() const { return m_status; }
151  void SetStatus( EDA_ITEM_FLAGS aStatus ) { m_status = aStatus; }
152 
153  void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
154  void ClearFlags( EDA_ITEM_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
155  EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
156  bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
157 
159  {
160  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVING | IS_RESIZING | IS_DRAGGING
162 
163  return m_flags & mask;
164  }
165 
167  {
169  DO_NOT_DRAW );
170  }
171 
173  {
175  }
176 
183  virtual bool IsType( const KICAD_T aScanTypes[] ) const
184  {
185  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
186  return true;
187 
188  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
189  {
190  if( m_structType == *p )
191  return true;
192  }
193 
194  return false;
195  }
196 
204  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
205 
206  bool IsForceVisible() const { return m_forceVisible; }
207 
214  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
215  {
216  }
217 
225  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
226  {
227  return false; // derived classes should override this function
228  }
229 
238  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
239  {
240  return false; // derived classes should override this function
241  }
242 
250  virtual const EDA_RECT GetBoundingBox() const;
251 
252  virtual wxPoint GetPosition() const { return wxPoint(); }
253  virtual void SetPosition( const wxPoint& aPos ) {};
254 
259  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
260 
273  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
274 
289  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
290 
294  template< class T >
295  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
296  INSPECTOR inspector,
297  void* testData,
298  const KICAD_T scanTypes[] )
299  {
300  for( auto it : aList )
301  {
302  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
304  return SEARCH_RESULT::QUIT;
305  }
306 
308  }
309 
313  template <class T>
315  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
316  {
317  for( auto it : aList )
318  {
319  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
321  return SEARCH_RESULT::QUIT;
322  }
323 
325  }
326 
330  virtual wxString GetClass() const = 0;
331 
342  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
343 
352  virtual BITMAPS GetMenuImage() const;
353 
365  virtual bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
366  {
367  return false;
368  }
369 
379  static bool Replace( const wxFindReplaceData& aSearchData, wxString& aText );
380 
392  virtual bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr )
393  {
394  return false;
395  }
396 
403  virtual bool IsReplaceable() const { return false; }
404 
411  bool operator<( const EDA_ITEM& aItem ) const;
412 
421  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
422 
426  EDA_ITEM& operator=( const EDA_ITEM& aItem );
427 
428  virtual const BOX2I ViewBBox() const override;
429 
430  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
431 
432 #if defined(DEBUG)
433 
443  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
444 
445  void ShowDummy( std::ostream& os ) const;
446 
454  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
455 
456 #endif
457 
458 protected:
459  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
460  EDA_ITEM( KICAD_T idType );
461  EDA_ITEM( const EDA_ITEM& base );
462 
472  bool Matches( const wxString& aText, const wxFindReplaceData& aSearchData ) const;
473 
474 public:
475  const KIID m_Uuid;
476 
477 protected:
482 
483 private:
489 };
490 
491 
498 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
499 
500 
507 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
508 
509 #endif // EDA_ITEM_H
#define IS_CHANGED
Item was edited, and modified.
void SetModified()
Definition: eda_item.cpp:65
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:479
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:93
#define DO_NOT_DRAW
Used to disable draw function.
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:365
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:171
#define STARTPOINT
When a line is selected, these flags indicate which.
void ClearTempFlags()
Definition: eda_item.h:166
bool IsModified() const
Definition: eda_item.h:118
bool IsSelected() const
Definition: eda_item.h:123
#define IS_NEW
New item, just created.
#define IS_RESIZING
Item being resized.
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
void ClearSelected()
Definition: eda_item.h:132
bool IsMoving() const
Definition: eda_item.h:120
virtual const wxPoint GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:259
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:156
void SetBrightened()
Definition: eda_item.h:130
#define IS_DRAGGING
Item being dragged.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
virtual ~EDA_ITEM()
Definition: eda_item.h:103
bool IsBrightened() const
Definition: eda_item.h:126
EDA_ITEM_FLAGS m_status
Definition: eda_item.h:478
void SetStatus(EDA_ITEM_FLAGS aStatus)
Definition: eda_item.h:151
std::uint32_t EDA_ITEM_FLAGS
EDA_ITEM_FLAGS GetStatus() const
Definition: eda_item.h:150
#define ENDPOINT
ends. (Used to support dragging.)
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:481
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
The base class for create windows for drawing purpose.
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:498
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:41
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:121
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
bool IsNew() const
Definition: eda_item.h:119
void ClearBrightened()
Definition: eda_item.h:133
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:225
#define CANDIDATE
flag indicating that the structure is connected
Definition: kiid.h:44
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:142
bool IsEntered() const
Definition: eda_item.h:124
#define IS_MOVING
Item being moved.
void SetSelected()
Definition: eda_item.h:129
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
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:203
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:214
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:204
bool IsResized() const
Definition: eda_item.h:125
void SetWireImage()
Definition: eda_item.h:128
bool IsWireImage() const
Definition: eda_item.h:122
#define EDA_ITEM_ALL_FLAGS
EDA_ITEM * GetParent() const
Definition: eda_item.h:115
#define STRUCT_DELETED
flag indication structures to be erased
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
#define SELECTED
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:183
int GetState(EDA_ITEM_FLAGS type) const
Definition: eda_item.h:137
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:507
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
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:421
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:392
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:145
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:180
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:37
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:155
const KIID m_Uuid
Definition: eda_item.h:475
EDA_UNITS
Definition: eda_units.h:38
#define ENTERED
indicates a group has been entered
bool IsForceVisible() const
Definition: eda_item.h:206
virtual wxString GetClass() const =0
Return the class name.
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define TEMP_SELECTED
flag indicating that the structure has already selected
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
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:109
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:211
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:403
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:238
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:488
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:295
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:194
void ClearEditFlags()
Definition: eda_item.h:172
SEARCH_RESULT
Definition: eda_item.h:41
bool m_forceVisible
Definition: eda_item.h:480
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:314
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
#define BRIGHTENED
item is drawn with a bright contour
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: eda_item.h:51