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, 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 <api/serializable.h>
33#include <core/typeinfo.h>
34#include <eda_item_flags.h>
35#include <eda_search_data.h>
36#include <view/view_item.h>
37#include <kiid.h>
38
39enum class BITMAPS : unsigned int;
40
41
43{
44 QUIT,
46};
47
49{
52};
53
54#define IGNORE_PARENT_GROUP false
55
59class UNITS_PROVIDER;
60class EDA_DRAW_FRAME;
61class EDA_GROUP;
62class MSG_PANEL_ITEM;
63class EMBEDDED_FILES;
64
65namespace google { namespace protobuf { class Any; } }
66
67
87typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
88
91
92
97{
98public:
99 virtual ~EDA_ITEM() = default;
100
109 inline KICAD_T Type() const { return m_structType; }
110
111 EDA_ITEM* GetParent() const { return m_parent; }
112 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
113
114 virtual void SetParentGroup( EDA_GROUP* aGroup ) { m_group = aGroup; }
115 virtual EDA_GROUP* GetParentGroup() const { return m_group; }
116
117 KIID GetParentGroupId() const;
118
119 virtual bool IsLocked() const { return false; }
120 virtual void SetLocked( bool aLocked ) {}
121
122 inline bool IsModified() const { return m_flags & IS_CHANGED; }
123 inline bool IsNew() const { return m_flags & IS_NEW; }
124 inline bool IsMoving() const { return m_flags & IS_MOVING; }
125
126 inline bool IsSelected() const { return m_flags & SELECTED; }
127 inline bool IsEntered() const { return m_flags & ENTERED; }
128 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
129
130 inline bool IsRollover() const { return m_isRollover; }
131 inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; }
132
133 inline void SetSelected() { SetFlags( SELECTED ); }
134 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
135
136 inline void ClearSelected() { ClearFlags( SELECTED ); }
138
139 void SetModified();
140
141 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
142 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
144 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
145 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
146
148 {
149 constexpr int mask =
151
152 return m_flags & mask;
153 }
154
155 virtual void ClearEditFlags()
156 {
158 }
159
161 {
164
165 return m_flags & mask;
166 }
167
168 virtual void ClearTempFlags()
169 {
171 }
172
173 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
174
175 void SetIsShownAsBitmap( bool aBitmap )
176 {
177 if( aBitmap )
179 else
181 }
182
183 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
184
191 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
192 {
193 for( KICAD_T scanType : aScanTypes )
194 {
195 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
196 return true;
197 }
198
199 return false;
200 }
201
209 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
210 bool IsForceVisible() const { return m_forceVisible; }
211
219 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
220 {
221 }
222
223 virtual wxString GetFriendlyName() const;
224
232 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
233 {
234 return false; // derived classes should override this function
235 }
236
245 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
246 {
247 return false; // derived classes should override this function
248 }
249
257 virtual const BOX2I GetBoundingBox() const;
258
259 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
260 virtual void SetPosition( const VECTOR2I& aPos ){};
261
266 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
267
275 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
276
289 virtual EDA_ITEM* Clone() const;
290
305 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
306 const std::vector<KICAD_T>& aScanTypes );
307
311 template< class T >
312 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
313 const std::vector<KICAD_T>& scanTypes )
314 {
315 for( const auto& it : aList )
316 {
317 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
318
319 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
320 {
321 return INSPECT_RESULT::QUIT;
322 }
323 }
324
325 return INSPECT_RESULT::CONTINUE;
326 }
327
331 template <class T>
332 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
333 void* testData, const std::vector<KICAD_T>& scanTypes )
334 {
335 for( const auto& it : aList )
336 {
337 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
338
339 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
340 {
341 return INSPECT_RESULT::QUIT;
342 }
343 }
344
345 return INSPECT_RESULT::CONTINUE;
346 }
347
352 wxString GetTypeDesc() const;
353
365 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
366
375 virtual BITMAPS GetMenuImage() const;
376
388 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
389 {
390 return false;
391 }
392
402 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
403
415 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
416 {
417 return false;
418 }
419
426 virtual bool IsReplaceable() const { return false; }
427
434 bool operator<( const EDA_ITEM& aItem ) const;
435
444 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
445
449 EDA_ITEM& operator=( const EDA_ITEM& aItem );
450
451 virtual const BOX2I ViewBBox() const override;
452
453 virtual std::vector<int> ViewGetLayers() const override;
454
455 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
456
457#if defined(DEBUG)
458
468 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
469
470 void ShowDummy( std::ostream& os ) const;
471
479 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
480
481#endif
482
483protected:
484 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
485 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
486 EDA_ITEM( const EDA_ITEM& base );
487
497 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
498
499 EDA_ITEM* findParent( KICAD_T aType ) const;
500
501public:
503
504private:
511
512protected:
518};
519
520
527inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
528
533{
534 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
535 {
536 assert( item1 != nullptr && item2 != nullptr );
537
538 if( item1->m_Uuid == item2->m_Uuid )
539 return item1 < item2;
540
541 return item1->m_Uuid < item2->m_Uuid;
542 }
543};
544
545
552typedef std::vector< EDA_ITEM* > EDA_ITEMS;
553
554typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
555
556#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 set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:46
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:245
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:259
virtual void ClearEditFlags()
Definition: eda_item.h:155
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:329
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:266
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:260
virtual void SetLocked(bool aLocked)
Definition: eda_item.h:120
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:110
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:393
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:444
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:147
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:141
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:144
void SetModified()
Definition: eda_item.cpp:100
const KIID m_Uuid
Definition: eda_item.h:502
bool m_forceVisible
Definition: eda_item.h:516
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:115
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:109
bool IsEntered() const
Definition: eda_item.h:127
void ClearSelected()
Definition: eda_item.h:136
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:320
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:209
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:143
void SetIsRollover(bool aIsRollover)
Definition: eda_item.h:131
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:415
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:513
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:175
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition: eda_item.cpp:353
EDA_ITEM_FLAGS GetTempFlags() const
Definition: eda_item.h:160
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:388
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition: eda_item.h:515
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition: eda_item.h:114
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:312
bool IsSelected() const
Definition: eda_item.h:126
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:219
KIID GetParentGroupId() const
Definition: eda_item.cpp:91
void SetSelected()
Definition: eda_item.h:133
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:191
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:127
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:112
bool IsModified() const
Definition: eda_item.h:122
bool IsShownAsBitmap() const
Definition: eda_item.h:183
void ClearBrightened()
Definition: eda_item.h:137
void SetBrightened()
Definition: eda_item.h:134
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:232
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:402
EDA_ITEM * GetParent() const
Definition: eda_item.h:111
bool m_isRollover
Definition: eda_item.h:517
bool IsRollover() const
Definition: eda_item.h:130
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:118
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:145
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition: eda_item.h:455
bool IsBrightened() const
Definition: eda_item.h:128
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:275
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:346
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:173
virtual bool IsLocked() const
Definition: eda_item.h:119
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:332
EDA_ITEM * m_parent
Owner.
Definition: eda_item.h:514
bool IsForceVisible() const
Definition: eda_item.h:210
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:144
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:237
bool IsMoving() const
Definition: eda_item.h:124
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:510
bool IsNew() const
Definition: eda_item.h:123
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:426
virtual void ClearTempFlags()
Definition: eda_item.h:168
EDA_ITEM * findParent(KICAD_T aType) const
Definition: eda_item.cpp:75
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:361
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
Definition: kiid.h:49
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
Interface for objects that can be serialized to Protobuf messages.
Definition: serializable.h:37
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:527
RECURSE_MODE
Definition: eda_item.h:49
@ RECURSE
Definition: eda_item.h:50
@ NO_RECURSE
Definition: eda_item.h:51
INSPECT_RESULT
Definition: eda_item.h:43
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:552
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition: eda_item.h:554
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition: eda_item.h:90
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:87
#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.
Comparison functor for sorting EDA_ITEM pointers by their UUID.
Definition: eda_item.h:533
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition: eda_item.h:534
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:200
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695