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 <[email protected]>
6  * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
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 been found.
61  FR_REPLACE_REFERENCES = 0x4 << 9 // Don't replace in references.
62 };
63 
64 
65 class wxFindReplaceData;
66 class EDA_DRAW_FRAME;
67 class EDA_RECT;
69 
70 
90 typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
91 
93 typedef const INSPECTOR_FUNC& INSPECTOR;
94 
95 
99 class EDA_ITEM : public KIGFX::VIEW_ITEM
100 {
101 public:
102  virtual ~EDA_ITEM() { };
103 
112  inline KICAD_T Type() const { return m_structType; }
113 
114  EDA_ITEM* GetParent() const { return m_parent; }
115  virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
116 
117  inline bool IsModified() const { return m_flags & IS_CHANGED; }
118  inline bool IsNew() const { return m_flags & IS_NEW; }
119  inline bool IsMoving() const { return m_flags & IS_MOVING; }
120  inline bool IsDragging() const { return m_flags & IS_DRAGGING; }
121  inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
122  inline bool IsSelected() const { return m_flags & SELECTED; }
123  inline bool IsEntered() const { return m_flags & ENTERED; }
124  inline bool IsResized() const { return m_flags & IS_RESIZING; }
125  inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
126 
127  inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
128  inline void SetSelected() { SetFlags( SELECTED ); }
129  inline void SetBrightened() { SetFlags( BRIGHTENED ); }
130 
131  inline void ClearSelected() { ClearFlags( SELECTED ); }
132  inline void ClearBrightened() { ClearFlags( BRIGHTENED ); }
133 
134  void SetModified();
135 
136  int GetState( EDA_ITEM_FLAGS type ) const
137  {
138  return m_status & type;
139  }
140 
141  void SetState( EDA_ITEM_FLAGS type, bool state )
142  {
143  if( state )
144  m_status |= type; // state = ON or OFF
145  else
146  m_status &= ~type;
147  }
148 
149  EDA_ITEM_FLAGS GetStatus() const { return m_status; }
150  void SetStatus( EDA_ITEM_FLAGS aStatus ) { m_status = aStatus; }
151 
152  void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
153  void ClearFlags( EDA_ITEM_FLAGS aMask = EDA_ITEM_ALL_FLAGS ) { m_flags &= ~aMask; }
154  EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
155  bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
156 
158  {
159  constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVING | IS_RESIZING | IS_DRAGGING
161 
162  return m_flags & mask;
163  }
164 
166  {
168  DO_NOT_DRAW );
169  }
170 
172  {
174  }
175 
182  virtual bool IsType( const KICAD_T aScanTypes[] ) const
183  {
184  if( aScanTypes[0] == SCH_LOCATE_ANY_T )
185  return true;
186 
187  for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
188  {
189  if( m_structType == *p )
190  return true;
191  }
192 
193  return false;
194  }
195 
203  void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
204 
205  bool IsForceVisible() const { return m_forceVisible; }
206 
213  virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
214  {
215  }
216 
224  virtual bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const
225  {
226  return false; // derived classes should override this function
227  }
228 
237  virtual bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const
238  {
239  return false; // derived classes should override this function
240  }
241 
249  virtual const EDA_RECT GetBoundingBox() const;
250 
251  virtual wxPoint GetPosition() const { return wxPoint(); }
252  virtual void SetPosition( const wxPoint& aPos ) {};
253 
258  virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
259 
272  virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
273 
288  virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
289 
293  template< class T >
294  static SEARCH_RESULT IterateForward( std::deque<T>& aList,
295  INSPECTOR inspector,
296  void* testData,
297  const KICAD_T scanTypes[] )
298  {
299  for( auto it : aList )
300  {
301  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
303  return SEARCH_RESULT::QUIT;
304  }
305 
307  }
308 
312  template <class T>
314  std::vector<T>& aList, INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
315  {
316  for( auto it : aList )
317  {
318  if( static_cast<EDA_ITEM*>( it )->Visit( inspector, testData, scanTypes )
320  return SEARCH_RESULT::QUIT;
321  }
322 
324  }
325 
329  virtual wxString GetClass() const = 0;
330 
341  virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
342 
351  virtual BITMAPS GetMenuImage() const;
352 
364  virtual bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
365  {
366  return false;
367  }
368 
378  static bool Replace( const wxFindReplaceData& aSearchData, wxString& aText );
379 
391  virtual bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData = nullptr )
392  {
393  return false;
394  }
395 
402  virtual bool IsReplaceable() const { return false; }
403 
410  bool operator<( const EDA_ITEM& aItem ) const;
411 
420  static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
421 
425  EDA_ITEM& operator=( const EDA_ITEM& aItem );
426 
427  virtual const BOX2I ViewBBox() const override;
428 
429  virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
430 
431 #if defined(DEBUG)
432 
442  virtual void Show( int nestLevel, std::ostream& os ) const = 0;
443 
444  void ShowDummy( std::ostream& os ) const;
445 
453  static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
454 
455 #endif
456 
457 protected:
458  EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
459  EDA_ITEM( KICAD_T idType );
460  EDA_ITEM( const EDA_ITEM& base );
461 
471  bool Matches( const wxString& aText, const wxFindReplaceData& aSearchData ) const;
472 
473 public:
474  const KIID m_Uuid;
475 
476 protected:
481 
482 private:
488 };
489 
490 
497 inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
498 
499 
506 typedef std::vector< EDA_ITEM* > EDA_ITEMS;
507 
508 #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:478
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:364
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:234
#define STARTPOINT
When a line is selected, these flags indicate which.
void ClearTempFlags()
Definition: eda_item.h:165
bool IsModified() const
Definition: eda_item.h:117
bool IsSelected() const
Definition: eda_item.h:122
#define IS_NEW
New item, just created.
#define IS_RESIZING
Item being resized.
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:252
void ClearSelected()
Definition: eda_item.h:131
bool IsMoving() const
Definition: eda_item.h:119
virtual const wxPoint GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:258
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:155
void SetBrightened()
Definition: eda_item.h:129
#define IS_DRAGGING
Item being dragged.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
virtual ~EDA_ITEM()
Definition: eda_item.h:102
bool IsBrightened() const
Definition: eda_item.h:125
EDA_ITEM_FLAGS m_status
Definition: eda_item.h:477
void SetStatus(EDA_ITEM_FLAGS aStatus)
Definition: eda_item.h:150
std::uint32_t EDA_ITEM_FLAGS
EDA_ITEM_FLAGS GetStatus() const
Definition: eda_item.h:149
#define ENDPOINT
ends. (Used to support dragging.)
virtual wxPoint GetPosition() const
Definition: eda_item.h:251
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:480
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:497
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:93
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:120
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
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:118
void ClearBrightened()
Definition: eda_item.h:132
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:224
#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:141
bool IsEntered() const
Definition: eda_item.h:123
#define IS_MOVING
Item being moved.
void SetSelected()
Definition: eda_item.h:128
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:68
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:266
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:213
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:203
bool IsResized() const
Definition: eda_item.h:124
void SetWireImage()
Definition: eda_item.h:127
bool IsWireImage() const
Definition: eda_item.h:121
#define EDA_ITEM_ALL_FLAGS
EDA_ITEM * GetParent() const
Definition: eda_item.h:114
#define STRUCT_DELETED
flag indication structures to be erased
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:153
#define SELECTED
virtual bool IsType(const KICAD_T aScanTypes[]) const
Check whether the item is one of the listed types.
Definition: eda_item.h:182
int GetState(EDA_ITEM_FLAGS type) const
Definition: eda_item.h:136
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:157
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:420
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:391
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:170
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:243
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:37
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:154
const KIID m_Uuid
Definition: eda_item.h:474
EDA_UNITS
Definition: eda_units.h:38
#define ENTERED
indicates a group has been entered
bool IsForceVisible() const
Definition: eda_item.h:205
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:274
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:402
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 this item.
Definition: eda_item.h:237
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:487
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:294
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:257
void ClearEditFlags()
Definition: eda_item.h:171
SEARCH_RESULT
Definition: eda_item.h:41
bool m_forceVisible
Definition: eda_item.h:479
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:313
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
#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