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 The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef EDA_ITEM_H
24#define EDA_ITEM_H
25
26#include <deque>
27#include <set>
28
29#include <api/serializable.h>
30#include <core/typeinfo.h>
31#include <eda_item_flags.h>
32#include <eda_search_data.h>
33#include <view/view_item.h>
34#include <kiid.h>
35
37
38enum class BITMAPS : unsigned int;
39
40
42{
45};
46
52
53#define IGNORE_PARENT_GROUP false
54
58class UNITS_PROVIDER;
59class EDA_DRAW_FRAME;
60class EDA_GROUP;
61class MSG_PANEL_ITEM;
62class EMBEDDED_FILES;
63
64namespace google { namespace protobuf { class Any; } }
65
66
86typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
87
90
91
96{
97public:
98 virtual ~EDA_ITEM() = default;
99
108 inline KICAD_T Type() const { return m_structType; }
109
110 EDA_ITEM* GetParent() const { return m_parent; }
111 virtual void SetParent( EDA_ITEM* aParent );
112
113 virtual void SetParentGroup( EDA_GROUP* aGroup ) { m_group = aGroup; }
114 virtual EDA_GROUP* GetParentGroup() const { return m_group; }
115
116 KIID GetParentGroupId() const;
117
123 bool HasSelectedAncestorGroup() const;
124
125 virtual bool IsLocked() const { return false; }
126 virtual void SetLocked( bool aLocked ) {}
127
128 inline bool IsModified() const { return m_flags & IS_CHANGED; }
129 inline bool IsNew() const { return m_flags & IS_NEW; }
130 inline bool IsMoving() const { return m_flags & IS_MOVING; }
131
132 inline bool IsSelected() const { return m_flags & SELECTED; }
133 inline bool IsEntered() const { return m_flags & ENTERED; }
134 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
135
136 inline bool IsRollover() const { return m_isRollover; }
137 inline VECTOR2I GetRolloverPos() const { return m_rolloverPos; }
138 inline void SetIsRollover( bool aIsRollover, const VECTOR2I& aMousePos )
139 {
140 m_isRollover = aIsRollover;
141 m_rolloverPos = aMousePos;
142 }
143
144 inline void SetSelected() { SetFlags( SELECTED ); }
145 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
146
147 inline void ClearSelected() { ClearFlags( SELECTED ); }
149
150 void SetModified();
151
152 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
153 void XorFlags( EDA_ITEM_FLAGS aMask ) { 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 =
162
163 return m_flags & mask;
164 }
165
166 virtual void ClearEditFlags()
167 {
169 }
170
172 {
175
176 return m_flags & mask;
177 }
178
179 virtual void ClearTempFlags()
180 {
182 }
183
184 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
185
186 void SetIsShownAsBitmap( bool aBitmap )
187 {
188 if( aBitmap )
190 else
192 }
193
194 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
195
202 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
203 {
204 for( KICAD_T scanType : aScanTypes )
205 {
206 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
207 return true;
208 }
209
210 return false;
211 }
212
220 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
221 bool IsForceVisible() const { return m_forceVisible; }
222
230 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
231 {
232 }
233
234 virtual wxString GetFriendlyName() const;
235
243 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
244 {
245 return false; // derived classes should override this function
246 }
247
256 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
257 {
258 return false; // derived classes should override this function
259 }
260
268 virtual bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
269 {
270 return false; // derived classes should override this function
271 }
272
280 virtual const BOX2I GetBoundingBox() const;
281
282 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
283 virtual void SetPosition( const VECTOR2I& aPos ){};
284
289 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
290
298 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
299
312 virtual EDA_ITEM* Clone() const;
313
328 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
329 const std::vector<KICAD_T>& aScanTypes );
330
334 template< class T >
335 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
336 const std::vector<KICAD_T>& scanTypes )
337 {
338 for( const auto& it : aList )
339 {
340 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
341
342 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
343 {
345 }
346 }
347
349 }
350
354 template <class T>
355 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
356 void* testData, const std::vector<KICAD_T>& scanTypes )
357 {
358 for( const auto& it : aList )
359 {
360 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
361
362 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
363 {
365 }
366 }
367
369 }
370
375 wxString GetTypeDesc() const;
376
388 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
389
390 virtual wxString DisambiguateItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
391 {
392 return GetItemDescription( aUnitsProvider, aFull );
393 }
394
403 virtual BITMAPS GetMenuImage() const;
404
416 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
417 {
418 return false;
419 }
420
430 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
431
443 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
444 {
445 return false;
446 }
447
454 virtual bool IsReplaceable() const { return false; }
455
462 bool operator<( const EDA_ITEM& aItem ) const;
463
472 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
473
477 EDA_ITEM& operator=( const EDA_ITEM& aItem );
478
479 virtual const BOX2I ViewBBox() const override;
480
481 virtual std::vector<int> ViewGetLayers() const override;
482
483 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
484 virtual const std::vector<wxString>* GetEmbeddedFonts() { return nullptr; }
485
486#if defined(DEBUG)
487
497 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
498
499 void ShowDummy( std::ostream& os ) const;
500
508 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
509
510#endif
511
512protected:
513 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
514 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
515 EDA_ITEM( const EDA_ITEM& base );
516
526 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
527
528 EDA_ITEM* findParent( KICAD_T aType ) const;
529
530public:
532
533private:
540
541protected:
545
549};
550
551
558inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
559
564{
565 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
566 {
567 assert( item1 != nullptr && item2 != nullptr );
568
569 if( item1->m_Uuid == item2->m_Uuid )
570 return item1 < item2;
571
572 return item1->m_Uuid < item2->m_Uuid;
573 }
574};
575
576
583typedef std::vector< EDA_ITEM* > EDA_ITEMS;
584
585typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
586
587#endif // EDA_ITEM_H
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
The base class for create windows for drawing purpose.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition eda_item.h:256
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
virtual void ClearEditFlags()
Definition eda_item.h:166
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:353
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition eda_item.h:289
void SetIsRollover(bool aIsRollover, const VECTOR2I &aMousePos)
Definition eda_item.h:138
VECTOR2I GetRolloverPos() const
Definition eda_item.h:137
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:283
virtual void SetLocked(bool aLocked)
Definition eda_item.h:126
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition eda_item.cpp:417
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:472
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:158
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:169
void SetModified()
Definition eda_item.cpp:125
const KIID m_Uuid
Definition eda_item.h:531
bool m_forceVisible
Definition eda_item.h:548
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
bool IsEntered() const
Definition eda_item.h:133
void ClearSelected()
Definition eda_item.h:147
VECTOR2I m_rolloverPos
Definition eda_item.h:546
virtual const std::vector< wxString > * GetEmbeddedFonts()
Definition eda_item.h:484
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition eda_item.cpp:344
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:220
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:154
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:443
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:542
void SetIsShownAsBitmap(bool aBitmap)
Definition eda_item.h:186
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition eda_item.cpp:377
EDA_ITEM_FLAGS GetTempFlags() const
Definition eda_item.h:171
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:416
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition eda_item.h:544
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition eda_item.h:113
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:335
bool IsSelected() const
Definition eda_item.h:132
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:230
KIID GetParentGroupId() const
Definition eda_item.cpp:97
void SetSelected()
Definition eda_item.h:144
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:202
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:152
bool IsModified() const
Definition eda_item.h:128
bool IsShownAsBitmap() const
Definition eda_item.h:194
void ClearBrightened()
Definition eda_item.h:148
void SetBrightened()
Definition eda_item.h:145
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:243
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:426
EDA_ITEM * GetParent() const
Definition eda_item.h:110
bool HasSelectedAncestorGroup() const
Definition eda_item.cpp:106
bool m_isRollover
Definition eda_item.h:547
bool IsRollover() const
Definition eda_item.h:136
virtual ~EDA_ITEM()=default
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:143
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:156
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition eda_item.h:483
bool IsBrightened() const
Definition eda_item.h:134
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition eda_item.h:298
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:153
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition eda_item.cpp:370
virtual bool RenderAsBitmap(double aWorldScale) const
Definition eda_item.h:184
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
virtual bool IsLocked() const
Definition eda_item.h:125
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:355
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:543
bool IsForceVisible() const
Definition eda_item.h:221
virtual bool HitTest(const SHAPE_LINE_CHAIN &aPoly, bool aContained) const
Test if aPoly intersects this item.
Definition eda_item.h:268
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:155
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:261
virtual wxString DisambiguateItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Definition eda_item.h:390
bool IsMoving() const
Definition eda_item.h:130
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition eda_item.h:539
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:37
bool IsNew() const
Definition eda_item.h:129
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition eda_item.h:454
virtual void ClearTempFlags()
Definition eda_item.h:179
EDA_ITEM * findParent(KICAD_T aType) const
Definition eda_item.cpp:73
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition eda_item.cpp:385
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Definition kiid.h:44
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:50
Interface for objects that can be serialized to Protobuf messages.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition eda_item.h:558
RECURSE_MODE
Definition eda_item.h:48
@ RECURSE
Definition eda_item.h:49
@ NO_RECURSE
Definition eda_item.h:50
INSPECT_RESULT
Definition eda_item.h:42
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition eda_item.h:585
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:89
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:86
#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 SELECTION_CANDIDATE
indicates an item is a candidate for selection
#define CONNECTIVITY_CANDIDATE
flag indicating that the structure is connected for connectivity
#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_MOVING
Item being moved.
std::vector< EDA_ITEM * > EDA_ITEMS
Comparison functor for sorting EDA_ITEM pointers by their UUID.
Definition eda_item.h:564
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition eda_item.h:565
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:196
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683