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 <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
48
52class UNITS_PROVIDER;
53class EDA_DRAW_FRAME;
54class MSG_PANEL_ITEM;
55class EMBEDDED_FILES;
56
57namespace google { namespace protobuf { class Any; } }
58
59
79typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
80
83
84
89{
90public:
91 virtual ~EDA_ITEM() { };
92
101 inline KICAD_T Type() const { return m_structType; }
102
103 EDA_ITEM* GetParent() const { return m_parent; }
104 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
105
106 inline bool IsModified() const { return m_flags & IS_CHANGED; }
107 inline bool IsNew() const { return m_flags & IS_NEW; }
108 inline bool IsMoving() const { return m_flags & IS_MOVING; }
109
110 inline bool IsSelected() const { return m_flags & SELECTED; }
111 inline bool IsEntered() const { return m_flags & ENTERED; }
112 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
113
114 inline bool IsRollover() const
115 {
116 return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
117 }
118
119 inline void SetSelected() { SetFlags( SELECTED ); }
120 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
121
122 inline void ClearSelected() { ClearFlags( SELECTED ); }
124
125 void SetModified();
126
127 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
128 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
130 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
131 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
132
134 {
135 constexpr int mask =
137
138 return m_flags & mask;
139 }
140
141 virtual void ClearEditFlags()
142 {
144 }
145
147 {
148 constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
149
150 return m_flags & mask;
151 }
152
153 virtual void ClearTempFlags()
154 {
156 }
157
158 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
159
160 void SetIsShownAsBitmap( bool aBitmap )
161 {
162 if( aBitmap )
164 else
166 }
167
168 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
169
176 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
177 {
178 for( KICAD_T scanType : aScanTypes )
179 {
180 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
181 return true;
182 }
183
184 return false;
185 }
186
194 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
195 bool IsForceVisible() const { return m_forceVisible; }
196
203 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
204 {
205 }
206
207 virtual wxString GetFriendlyName() const;
208
216 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
217 {
218 return false; // derived classes should override this function
219 }
220
229 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
230 {
231 return false; // derived classes should override this function
232 }
233
241 virtual const BOX2I GetBoundingBox() const;
242
243 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
244 virtual void SetPosition( const VECTOR2I& aPos ){};
245
250 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
251
259 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
260
273 virtual EDA_ITEM* Clone() const;
274
289 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
290 const std::vector<KICAD_T>& aScanTypes );
291
295 template< class T >
296 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
297 const std::vector<KICAD_T>& scanTypes )
298 {
299 for( const auto& it : aList )
300 {
301 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
302 testData,
303 scanTypes ) == INSPECT_RESULT::QUIT )
304 {
305 return INSPECT_RESULT::QUIT;
306 }
307 }
308
309 return INSPECT_RESULT::CONTINUE;
310 }
311
315 template <class T>
316 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
317 void* testData, const std::vector<KICAD_T>& scanTypes )
318 {
319 for( const auto& it : aList )
320 {
321 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
322 testData,
323 scanTypes ) == INSPECT_RESULT::QUIT )
324 {
325 return INSPECT_RESULT::QUIT;
326 }
327 }
328
329 return INSPECT_RESULT::CONTINUE;
330 }
331
335 virtual wxString GetClass() const = 0;
336
341 wxString GetTypeDesc() const;
342
354 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
355
364 virtual BITMAPS GetMenuImage() const;
365
377 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
378 {
379 return false;
380 }
381
391 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
392
404 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
405 {
406 return false;
407 }
408
415 virtual bool IsReplaceable() const { return false; }
416
423 bool operator<( const EDA_ITEM& aItem ) const;
424
433 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
434
438 EDA_ITEM& operator=( const EDA_ITEM& aItem );
439
440 virtual const BOX2I ViewBBox() const override;
441
442 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
443
444 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
445
446#if defined(DEBUG)
447
457 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
458
459 void ShowDummy( std::ostream& os ) const;
460
468 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
469
470#endif
471
472protected:
473 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
474 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
475 EDA_ITEM( const EDA_ITEM& base );
476
486 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
487
488public:
490
491private:
497
498protected:
502};
503
504
511inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
512
517{
518 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
519 {
520 assert( item1 != nullptr && item2 != nullptr );
521
522 if( item1->m_Uuid == item2->m_Uuid )
523 return item1 < item2;
524
525 return item1->m_Uuid < item2->m_Uuid;
526 }
527};
528
529
536typedef std::vector< EDA_ITEM* > EDA_ITEMS;
537
538typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
539
540#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:89
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:229
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
virtual void ClearEditFlags()
Definition: eda_item.h:141
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:261
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:250
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:244
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
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:283
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:323
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:433
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:133
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:111
void SetModified()
Definition: eda_item.cpp:67
const KIID m_Uuid
Definition: eda_item.h:489
bool m_forceVisible
Definition: eda_item.h:501
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
bool IsEntered() const
Definition: eda_item.h:111
void ClearSelected()
Definition: eda_item.h:122
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:252
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:194
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
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:404
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:499
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:160
EDA_ITEM_FLAGS GetTempFlags() const
Definition: eda_item.h:146
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:377
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:296
bool IsSelected() const
Definition: eda_item.h:110
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:203
void SetSelected()
Definition: eda_item.h:119
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:176
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:94
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
bool IsModified() const
Definition: eda_item.h:106
bool IsShownAsBitmap() const
Definition: eda_item.h:168
void ClearBrightened()
Definition: eda_item.h:123
void SetBrightened()
Definition: eda_item.h:120
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:216
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:332
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
bool IsRollover() const
Definition: eda_item.h:114
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:85
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:131
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition: eda_item.h:444
bool IsBrightened() const
Definition: eda_item.h:112
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:259
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:128
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:276
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:158
virtual ~EDA_ITEM()
Definition: eda_item.h:91
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:316
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:500
bool IsForceVisible() const
Definition: eda_item.h:195
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:130
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:189
bool IsMoving() const
Definition: eda_item.h:108
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:496
bool IsNew() const
Definition: eda_item.h:107
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:415
virtual void ClearTempFlags()
Definition: eda_item.h:153
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:291
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
Interface for objects that can be serialized to Protobuf messages.
Definition: serializable.h:36
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:511
INSPECT_RESULT
Definition: eda_item.h:43
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:536
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition: eda_item.h:538
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:82
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:79
#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:517
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition: eda_item.h:518
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:691