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-2022 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 <eda_search_data.h>
35#include <view/view_item.h>
36#include <kiid.h>
37
38enum class BITMAPS : unsigned int;
39
40
42{
43 QUIT,
45};
46
47
51class UNITS_PROVIDER;
52class EDA_DRAW_FRAME;
53class MSG_PANEL_ITEM;
54
55
75typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
76
79
80
85{
86public:
87 virtual ~EDA_ITEM() { };
88
97 inline KICAD_T Type() const { return m_structType; }
98
99 EDA_ITEM* GetParent() const { return m_parent; }
100 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
101
102 inline bool IsModified() const { return m_flags & IS_CHANGED; }
103 inline bool IsNew() const { return m_flags & IS_NEW; }
104 inline bool IsMoving() const { return m_flags & IS_MOVING; }
105
106 inline bool IsSelected() const { return m_flags & SELECTED; }
107 inline bool IsEntered() const { return m_flags & ENTERED; }
108 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
109
110 inline bool IsRollover() const
111 {
112 return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
113 }
114
115 inline void SetSelected() { SetFlags( SELECTED ); }
116 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
117
118 inline void ClearSelected() { ClearFlags( SELECTED ); }
120
121 void SetModified();
122
123 int GetState( EDA_ITEM_FLAGS type ) const
124 {
125 return m_status & type;
126 }
127
128 void SetState( EDA_ITEM_FLAGS type, bool state )
129 {
130 if( state )
131 m_status |= type; // state = ON or OFF
132 else
133 m_status &= ~type;
134 }
135
137 void SetStatus( EDA_ITEM_FLAGS aStatus ) { m_status = aStatus; }
138
139 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
140 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
142 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
143 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
144
146 {
147 constexpr int mask =
149
150 return m_flags & mask;
151 }
152
154 {
156 }
157
159 {
161 }
162
163 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
164
165 void SetIsShownAsBitmap( bool aBitmap )
166 {
167 if( aBitmap )
169 else
171 }
172
173 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
174
181 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
182 {
183 for( KICAD_T scanType : aScanTypes )
184 {
185 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
186 return true;
187 }
188
189 return false;
190 }
191
199 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
200
201 bool IsForceVisible() const { return m_forceVisible; }
202
209 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
210 {
211 }
212
213 virtual wxString GetFriendlyName() const;
214
222 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
223 {
224 return false; // derived classes should override this function
225 }
226
235 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
236 {
237 return false; // derived classes should override this function
238 }
239
247 virtual const BOX2I GetBoundingBox() const;
248
249 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
250 virtual void SetPosition( const VECTOR2I& aPos ){};
251
256 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
257
265 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
266
279 virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
280
295 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
296 const std::vector<KICAD_T>& aScanTypes );
297
301 template< class T >
302 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
303 const std::vector<KICAD_T>& scanTypes )
304 {
305 for( const auto& it : aList )
306 {
307 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
308 testData,
309 scanTypes ) == INSPECT_RESULT::QUIT )
310 {
312 }
313 }
314
316 }
317
321 template <class T>
322 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
323 void* testData, const std::vector<KICAD_T>& scanTypes )
324 {
325 for( const auto& it : aList )
326 {
327 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
328 testData,
329 scanTypes ) == INSPECT_RESULT::QUIT )
330 {
332 }
333 }
334
336 }
337
341 virtual wxString GetClass() const = 0;
342
347 wxString GetTypeDesc() const;
348
359 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const;
360
369 virtual BITMAPS GetMenuImage() const;
370
382 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
383 {
384 return false;
385 }
386
396 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
397
409 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
410 {
411 return false;
412 }
413
420 virtual bool IsReplaceable() const { return false; }
421
428 bool operator<( const EDA_ITEM& aItem ) const;
429
438 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
439
443 EDA_ITEM& operator=( const EDA_ITEM& aItem );
444
445 virtual const BOX2I ViewBBox() const override;
446
447 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
448
449#if defined(DEBUG)
450
460 virtual void Show( int nestLevel, std::ostream& os ) const = 0;
461
462 void ShowDummy( std::ostream& os ) const;
463
471 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
472
473#endif
474
475protected:
476 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
477 EDA_ITEM( KICAD_T idType );
478 EDA_ITEM( const EDA_ITEM& base );
479
489 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
490
491public:
493
494protected:
499
500private:
506};
507
508
515inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
516
517
524typedef std::vector< EDA_ITEM* > EDA_ITEMS;
525
526#endif // EDA_ITEM_H
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
void SetStatus(EDA_ITEM_FLAGS aStatus)
Definition: eda_item.h:137
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:235
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:249
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:240
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:256
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:250
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:36
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
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:261
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:301
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:438
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:145
int GetState(EDA_ITEM_FLAGS type) const
Definition: eda_item.h:123
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:139
void SetModified()
Definition: eda_item.cpp:64
const KIID m_Uuid
Definition: eda_item.h:492
bool m_forceVisible
Definition: eda_item.h:497
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
bool IsEntered() const
Definition: eda_item.h:107
void ClearSelected()
Definition: eda_item.h:118
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:231
EDA_ITEM_FLAGS m_status
Definition: eda_item.h:495
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:199
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:141
void ClearTempFlags()
Definition: eda_item.h:153
virtual bool Replace(const EDA_SEARCH_DATA &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:409
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:498
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:165
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
static INSPECT_RESULT IterateForward(std::deque< T > &aList, INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes)
This changes first parameter to avoid the DList and use the main queue instead.
Definition: eda_item.h:302
bool IsSelected() const
Definition: eda_item.h:106
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:209
void SetSelected()
Definition: eda_item.h:115
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:181
virtual INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &aScanTypes)
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
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:108
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
bool IsModified() const
Definition: eda_item.h:102
bool IsShownAsBitmap() const
Definition: eda_item.h:173
void ClearBrightened()
Definition: eda_item.h:119
void SetBrightened()
Definition: eda_item.h:116
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const
Test if aPosition is inside or on the boundary of this item.
Definition: eda_item.h:222
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:310
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
EDA_ITEM_FLAGS GetStatus() const
Definition: eda_item.h:136
bool IsRollover() const
Definition: eda_item.h:110
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:128
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:143
bool IsBrightened() const
Definition: eda_item.h:108
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:265
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:140
virtual wxString GetClass() const =0
Return the class name.
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:254
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:163
virtual ~EDA_ITEM()
Definition: eda_item.h:87
static INSPECT_RESULT IterateForward(std::vector< T > &aList, INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes)
Change first parameter to avoid the DList and use std::vector instead.
Definition: eda_item.h:322
void ClearEditFlags()
Definition: eda_item.h:158
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:496
bool IsForceVisible() const
Definition: eda_item.h:201
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:142
static bool Replace(const EDA_SEARCH_DATA &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:168
bool IsMoving() const
Definition: eda_item.h:104
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:505
bool IsNew() const
Definition: eda_item.h:103
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:420
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:269
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Definition: kiid.h:48
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:515
INSPECT_RESULT
Definition: eda_item.h:42
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:524
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:78
std::function< INSPECT_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:75
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_CHANGED
Item was edited, and modified.
#define BRIGHTENED
item is drawn with a bright contour
#define IS_SHOWN_AS_BITMAP
#define IS_NEW
New item, just created.
#define IS_LINKED
Used in calculation to mark linked items (temporary use)
#define SELECTED
Item was manually selected by the user.
#define SELECTED_BY_DRAG
Item was algorithmically selected as a dragged item.
#define EDA_ITEM_ALL_FLAGS
#define IS_BROKEN
Is a segment just broken by BreakSegment.
#define ENTERED
indicates a group has been entered
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
std::uint32_t EDA_ITEM_FLAGS
#define CANDIDATE
flag indicating that the structure is connected
#define IS_ROLLOVER
Rollover active. Used for hyperlink highlighting.
#define IS_MOVING
Item being moved.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:183
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618