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;
55
56namespace google { namespace protobuf { class Any; } }
57
58
78typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
79
82
83
88{
89public:
90 virtual ~EDA_ITEM() { };
91
100 inline KICAD_T Type() const { return m_structType; }
101
102 EDA_ITEM* GetParent() const { return m_parent; }
103 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
104
105 inline bool IsModified() const { return m_flags & IS_CHANGED; }
106 inline bool IsNew() const { return m_flags & IS_NEW; }
107 inline bool IsMoving() const { return m_flags & IS_MOVING; }
108
109 inline bool IsSelected() const { return m_flags & SELECTED; }
110 inline bool IsEntered() const { return m_flags & ENTERED; }
111 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
112
113 inline bool IsRollover() const
114 {
115 return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
116 }
117
118 inline void SetSelected() { SetFlags( SELECTED ); }
119 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
120
121 inline void ClearSelected() { ClearFlags( SELECTED ); }
123
124 void SetModified();
125
126 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
127 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
129 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
130 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
131
133 {
134 constexpr int mask =
136
137 return m_flags & mask;
138 }
139
140 virtual void ClearEditFlags()
141 {
143 }
144
146 {
147 constexpr int mask = ( CANDIDATE | SELECTED_BY_DRAG | IS_LINKED | SKIP_STRUCT );
148
149 return m_flags & mask;
150 }
151
152 virtual void ClearTempFlags()
153 {
155 }
156
157 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
158
159 void SetIsShownAsBitmap( bool aBitmap )
160 {
161 if( aBitmap )
163 else
165 }
166
167 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
168
175 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
176 {
177 for( KICAD_T scanType : aScanTypes )
178 {
179 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
180 return true;
181 }
182
183 return false;
184 }
185
193 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
194 bool IsForceVisible() const { return m_forceVisible; }
195
202 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
203 {
204 }
205
206 virtual wxString GetFriendlyName() const;
207
215 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
216 {
217 return false; // derived classes should override this function
218 }
219
228 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
229 {
230 return false; // derived classes should override this function
231 }
232
240 virtual const BOX2I GetBoundingBox() const;
241
242 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
243 virtual void SetPosition( const VECTOR2I& aPos ){};
244
249 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
250
258 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
259
272 virtual EDA_ITEM* Clone() const;
273
288 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
289 const std::vector<KICAD_T>& aScanTypes );
290
294 template< class T >
295 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
296 const std::vector<KICAD_T>& scanTypes )
297 {
298 for( const auto& it : aList )
299 {
300 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
301 testData,
302 scanTypes ) == INSPECT_RESULT::QUIT )
303 {
304 return INSPECT_RESULT::QUIT;
305 }
306 }
307
308 return INSPECT_RESULT::CONTINUE;
309 }
310
314 template <class T>
315 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
316 void* testData, const std::vector<KICAD_T>& scanTypes )
317 {
318 for( const auto& it : aList )
319 {
320 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
321 testData,
322 scanTypes ) == INSPECT_RESULT::QUIT )
323 {
324 return INSPECT_RESULT::QUIT;
325 }
326 }
327
328 return INSPECT_RESULT::CONTINUE;
329 }
330
334 virtual wxString GetClass() const = 0;
335
340 wxString GetTypeDesc() const;
341
352 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const;
353
362 virtual BITMAPS GetMenuImage() const;
363
375 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
376 {
377 return false;
378 }
379
389 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
390
402 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
403 {
404 return false;
405 }
406
413 virtual bool IsReplaceable() const { return false; }
414
421 bool operator<( const EDA_ITEM& aItem ) const;
422
431 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
432
436 EDA_ITEM& operator=( const EDA_ITEM& aItem );
437
438 virtual const BOX2I ViewBBox() const override;
439
440 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
441
442#if defined(DEBUG)
443
453 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
454
455 void ShowDummy( std::ostream& os ) const;
456
464 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
465
466#endif
467
468protected:
469 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
470 EDA_ITEM( KICAD_T idType );
471 EDA_ITEM( const EDA_ITEM& base );
472
482 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
483
484public:
486
487protected:
491
492private:
498};
499
500
507inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
508
513{
514 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
515 {
516 assert( item1 != nullptr && item2 != nullptr );
517
518 if( item1->m_Uuid == item2->m_Uuid )
519 return item1 < item2;
520
521 return item1->m_Uuid < item2->m_Uuid;
522 }
523};
524
525
532typedef std::vector< EDA_ITEM* > EDA_ITEMS;
533
534typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
535
536#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:88
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:228
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:242
virtual void ClearEditFlags()
Definition: eda_item.h:140
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:249
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:243
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:431
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:132
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:126
void SetModified()
Definition: eda_item.cpp:64
const KIID m_Uuid
Definition: eda_item.h:485
bool m_forceVisible
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
bool IsEntered() const
Definition: eda_item.h:110
void ClearSelected()
Definition: eda_item.h:121
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:193
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:128
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:402
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:490
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:159
EDA_ITEM_FLAGS GetTempFlags() const
Definition: eda_item.h:145
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:375
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:295
bool IsSelected() const
Definition: eda_item.h:109
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:202
void SetSelected()
Definition: eda_item.h:118
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:175
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:103
bool IsModified() const
Definition: eda_item.h:105
bool IsShownAsBitmap() const
Definition: eda_item.h:167
void ClearBrightened()
Definition: eda_item.h:122
void SetBrightened()
Definition: eda_item.h:119
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:215
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:329
EDA_ITEM * GetParent() const
Definition: eda_item.h:102
bool IsRollover() const
Definition: eda_item.h:113
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:130
bool IsBrightened() const
Definition: eda_item.h:111
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:258
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
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:157
virtual ~EDA_ITEM()
Definition: eda_item.h:90
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:315
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:488
bool IsForceVisible() const
Definition: eda_item.h:194
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:129
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:107
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:497
bool IsNew() const
Definition: eda_item.h:106
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:413
virtual void ClearTempFlags()
Definition: eda_item.h:152
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
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:507
INSPECT_RESULT
Definition: eda_item.h:43
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:532
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition: eda_item.h:534
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:81
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:78
#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:513
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition: eda_item.h:514
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< int > VECTOR2I
Definition: vector2d.h:588