KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
124 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
126 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
127 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
128
130 {
131 constexpr int mask =
133
134 return m_flags & mask;
135 }
136
138 {
140 }
141
143 {
144 constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
145
146 return m_flags & mask;
147 }
148
150 {
152 }
153
154 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
155
156 void SetIsShownAsBitmap( bool aBitmap )
157 {
158 if( aBitmap )
160 else
162 }
163
164 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
165
172 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
173 {
174 for( KICAD_T scanType : aScanTypes )
175 {
176 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
177 return true;
178 }
179
180 return false;
181 }
182
190 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
191 bool IsForceVisible() const { return m_forceVisible; }
192
199 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
200 {
201 }
202
203 virtual wxString GetFriendlyName() const;
204
212 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
213 {
214 return false; // derived classes should override this function
215 }
216
225 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
226 {
227 return false; // derived classes should override this function
228 }
229
237 virtual const BOX2I GetBoundingBox() const;
238
239 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
240 virtual void SetPosition( const VECTOR2I& aPos ){};
241
246 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
247
255 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
256
269 virtual EDA_ITEM* Clone() const;
270
285 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
286 const std::vector<KICAD_T>& aScanTypes );
287
291 template< class T >
292 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
293 const std::vector<KICAD_T>& scanTypes )
294 {
295 for( const auto& it : aList )
296 {
297 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
298 testData,
299 scanTypes ) == INSPECT_RESULT::QUIT )
300 {
301 return INSPECT_RESULT::QUIT;
302 }
303 }
304
305 return INSPECT_RESULT::CONTINUE;
306 }
307
311 template <class T>
312 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
313 void* testData, const std::vector<KICAD_T>& scanTypes )
314 {
315 for( const auto& it : aList )
316 {
317 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
318 testData,
319 scanTypes ) == INSPECT_RESULT::QUIT )
320 {
321 return INSPECT_RESULT::QUIT;
322 }
323 }
324
325 return INSPECT_RESULT::CONTINUE;
326 }
327
331 virtual wxString GetClass() const = 0;
332
337 wxString GetTypeDesc() const;
338
349 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const;
350
359 virtual BITMAPS GetMenuImage() const;
360
372 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
373 {
374 return false;
375 }
376
386 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
387
399 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
400 {
401 return false;
402 }
403
410 virtual bool IsReplaceable() const { return false; }
411
418 bool operator<( const EDA_ITEM& aItem ) const;
419
428 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
429
433 EDA_ITEM& operator=( const EDA_ITEM& aItem );
434
435 virtual const BOX2I ViewBBox() const override;
436
437 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
438
439#if defined(DEBUG)
440
450 virtual void Show( int nestLevel, std::ostream& os ) const = 0;
451
452 void ShowDummy( std::ostream& os ) const;
453
461 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
462
463#endif
464
465protected:
466 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
467 EDA_ITEM( KICAD_T idType );
468 EDA_ITEM( const EDA_ITEM& base );
469
479 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
480
481public:
483
484protected:
488
489private:
495};
496
497
504inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
505
510{
511 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
512 {
513 assert( item1 != nullptr && item2 != nullptr );
514
515 if( item1->m_Uuid == item2->m_Uuid )
516 return item1 < item2;
517
518 return item1->m_Uuid < item2->m_Uuid;
519 }
520};
521
522
529typedef std::vector< EDA_ITEM* > EDA_ITEMS;
530
531typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
532
533#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
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:225
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:239
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:258
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:246
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:240
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:280
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:320
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:428
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:129
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
void SetModified()
Definition: eda_item.cpp:64
const KIID m_Uuid
Definition: eda_item.h:482
bool m_forceVisible
Definition: eda_item.h:486
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:249
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:190
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:125
void ClearTempFlags()
Definition: eda_item.h:149
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:399
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:487
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:156
EDA_ITEM_FLAGS GetTempFlags() const
Definition: eda_item.h:142
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:372
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:292
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:199
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:172
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:164
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:212
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:329
EDA_ITEM * GetParent() const
Definition: eda_item.h:99
bool IsRollover() const
Definition: eda_item.h:110
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:127
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:255
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:124
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:273
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:154
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:312
void ClearEditFlags()
Definition: eda_item.h:137
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:485
bool IsForceVisible() const
Definition: eda_item.h:191
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:126
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:186
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:494
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:410
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:288
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
Definition: kiid.h:49
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:504
INSPECT_RESULT
Definition: eda_item.h:42
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:529
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition: eda_item.h:531
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.
Comparison functor for sorting EDA_ITEM pointers by their UUID.
Definition: eda_item.h:510
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition: eda_item.h:511
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:187
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588