KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 <dick@softplc.com>
6 * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
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
58class UNITS_PROVIDER;
59class EDA_DRAW_FRAME;
60class MSG_PANEL_ITEM;
61class EMBEDDED_FILES;
62
63namespace google { namespace protobuf { class Any; } }
64
65
85typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
86
89
90
95{
96public:
97 virtual ~EDA_ITEM() { };
98
107 inline KICAD_T Type() const { return m_structType; }
108
109 EDA_ITEM* GetParent() const { return m_parent; }
110 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
111
112 inline bool IsModified() const { return m_flags & IS_CHANGED; }
113 inline bool IsNew() const { return m_flags & IS_NEW; }
114 inline bool IsMoving() const { return m_flags & IS_MOVING; }
115
116 inline bool IsSelected() const { return m_flags & SELECTED; }
117 inline bool IsEntered() const { return m_flags & ENTERED; }
118 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
119
120 inline bool IsRollover() const { return m_isRollover; }
121 inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; }
122
123 inline void SetSelected() { SetFlags( SELECTED ); }
124 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
125
126 inline void ClearSelected() { ClearFlags( SELECTED ); }
128
129 void SetModified();
130
131 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
132 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
134 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
135 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
136
138 {
139 constexpr int mask =
141
142 return m_flags & mask;
143 }
144
145 virtual void ClearEditFlags()
146 {
148 }
149
151 {
152 constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
153
154 return m_flags & mask;
155 }
156
157 virtual void ClearTempFlags()
158 {
160 }
161
162 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
163
164 void SetIsShownAsBitmap( bool aBitmap )
165 {
166 if( aBitmap )
168 else
170 }
171
172 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
173
180 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
181 {
182 for( KICAD_T scanType : aScanTypes )
183 {
184 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
185 return true;
186 }
187
188 return false;
189 }
190
198 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
199 bool IsForceVisible() const { return m_forceVisible; }
200
208 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
209 {
210 }
211
212 virtual wxString GetFriendlyName() const;
213
221 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
222 {
223 return false; // derived classes should override this function
224 }
225
234 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
235 {
236 return false; // derived classes should override this function
237 }
238
246 virtual const BOX2I GetBoundingBox() const;
247
248 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
249 virtual void SetPosition( const VECTOR2I& aPos ){};
250
255 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
256
264 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
265
278 virtual EDA_ITEM* Clone() const;
279
294 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
295 const std::vector<KICAD_T>& aScanTypes );
296
300 template< class T >
301 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
302 const std::vector<KICAD_T>& scanTypes )
303 {
304 for( const auto& it : aList )
305 {
306 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
307
308 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
309 {
310 return INSPECT_RESULT::QUIT;
311 }
312 }
313
314 return INSPECT_RESULT::CONTINUE;
315 }
316
320 template <class T>
321 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
322 void* testData, const std::vector<KICAD_T>& scanTypes )
323 {
324 for( const auto& it : aList )
325 {
326 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
327
328 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
329 {
330 return INSPECT_RESULT::QUIT;
331 }
332 }
333
334 return INSPECT_RESULT::CONTINUE;
335 }
336
340 virtual wxString GetClass() const = 0;
341
346 wxString GetTypeDesc() const;
347
359 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) 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 std::vector<int> ViewGetLayers() const override;
448
449 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
450
451#if defined(DEBUG)
452
462 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
463
464 void ShowDummy( std::ostream& os ) const;
465
473 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
474
475#endif
476
477protected:
478 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
479 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
480 EDA_ITEM( const EDA_ITEM& base );
481
491 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
492
493public:
495
496private:
503
504protected:
509};
510
511
518inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
519
524{
525 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
526 {
527 assert( item1 != nullptr && item2 != nullptr );
528
529 if( item1->m_Uuid == item2->m_Uuid )
530 return item1 < item2;
531
532 return item1->m_Uuid < item2->m_Uuid;
533 }
534};
535
536
543typedef std::vector< EDA_ITEM* > EDA_ITEMS;
544
545typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
546
547#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:95
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:234
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:248
virtual void ClearEditFlags()
Definition: eda_item.h:145
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:300
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:255
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:249
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:81
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:362
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:137
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:131
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:115
void SetModified()
Definition: eda_item.cpp:71
const KIID m_Uuid
Definition: eda_item.h:494
bool m_forceVisible
Definition: eda_item.h:507
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:107
bool IsEntered() const
Definition: eda_item.h:117
void ClearSelected()
Definition: eda_item.h:126
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:291
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:198
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:133
void SetIsRollover(bool aIsRollover)
Definition: eda_item.h:121
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:505
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:164
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition: eda_item.cpp:322
EDA_ITEM_FLAGS GetTempFlags() const
Definition: eda_item.h:150
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:301
bool IsSelected() const
Definition: eda_item.h:116
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:208
void SetSelected()
Definition: eda_item.h:123
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:180
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:98
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:110
bool IsModified() const
Definition: eda_item.h:112
bool IsShownAsBitmap() const
Definition: eda_item.h:172
void ClearBrightened()
Definition: eda_item.h:127
void SetBrightened()
Definition: eda_item.h:124
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:221
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:371
EDA_ITEM * GetParent() const
Definition: eda_item.h:109
bool m_isRollover
Definition: eda_item.h:508
bool IsRollover() const
Definition: eda_item.h:120
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:89
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:135
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition: eda_item.h:449
bool IsBrightened() const
Definition: eda_item.h:118
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:264
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:132
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:315
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:162
virtual ~EDA_ITEM()
Definition: eda_item.h:97
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:321
EDA_ITEM * m_parent
Linked list: Link (parent struct).
Definition: eda_item.h:506
bool IsForceVisible() const
Definition: eda_item.h:199
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:134
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:208
bool IsMoving() const
Definition: eda_item.h:114
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:502
bool IsNew() const
Definition: eda_item.h:113
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:420
virtual void ClearTempFlags()
Definition: eda_item.h:157
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:330
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:518
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:543
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition: eda_item.h:545
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition: eda_item.h:88
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:85
#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_MOVING
Item being moved.
Comparison functor for sorting EDA_ITEM pointers by their UUID.
Definition: eda_item.h:524
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition: eda_item.h:525
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:198
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695