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#include <set>
32
33#include <api/serializable.h>
34#include <core/typeinfo.h>
35#include <eda_item_flags.h>
36#include <eda_search_data.h>
37#include <view/view_item.h>
38#include <kiid.h>
39
41
42enum class BITMAPS : unsigned int;
43
44
46{
49};
50
56
57#define IGNORE_PARENT_GROUP false
58
62class UNITS_PROVIDER;
63class EDA_DRAW_FRAME;
64class EDA_GROUP;
65class MSG_PANEL_ITEM;
66class EMBEDDED_FILES;
67
68namespace google { namespace protobuf { class Any; } }
69
70
90typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
91
94
95
100{
101public:
102 virtual ~EDA_ITEM() = default;
103
112 inline KICAD_T Type() const { return m_structType; }
113
114 EDA_ITEM* GetParent() const { return m_parent; }
115 virtual void SetParent( EDA_ITEM* aParent );
116
117 virtual void SetParentGroup( EDA_GROUP* aGroup ) { m_group = aGroup; }
118 virtual EDA_GROUP* GetParentGroup() const { return m_group; }
119
120 KIID GetParentGroupId() const;
121
122 virtual bool IsLocked() const { return false; }
123 virtual void SetLocked( bool aLocked ) {}
124
125 inline bool IsModified() const { return m_flags & IS_CHANGED; }
126 inline bool IsNew() const { return m_flags & IS_NEW; }
127 inline bool IsMoving() const { return m_flags & IS_MOVING; }
128
129 inline bool IsSelected() const { return m_flags & SELECTED; }
130 inline bool IsEntered() const { return m_flags & ENTERED; }
131 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
132
133 inline bool IsRollover() const { return m_isRollover; }
134 inline VECTOR2I GetRolloverPos() const { return m_rolloverPos; }
135 inline void SetIsRollover( bool aIsRollover, const VECTOR2I& aMousePos )
136 {
137 m_isRollover = aIsRollover;
138 m_rolloverPos = aMousePos;
139 }
140
141 inline void SetSelected() { SetFlags( SELECTED ); }
142 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
143
144 inline void ClearSelected() { ClearFlags( SELECTED ); }
146
147 void SetModified();
148
149 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
150 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
152 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
153 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
154
156 {
157 constexpr int mask =
159
160 return m_flags & mask;
161 }
162
163 virtual void ClearEditFlags()
164 {
166 }
167
169 {
172
173 return m_flags & mask;
174 }
175
176 virtual void ClearTempFlags()
177 {
179 }
180
181 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
182
183 void SetIsShownAsBitmap( bool aBitmap )
184 {
185 if( aBitmap )
187 else
189 }
190
191 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
192
199 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
200 {
201 for( KICAD_T scanType : aScanTypes )
202 {
203 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
204 return true;
205 }
206
207 return false;
208 }
209
217 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
218 bool IsForceVisible() const { return m_forceVisible; }
219
227 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
228 {
229 }
230
231 virtual wxString GetFriendlyName() const;
232
240 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
241 {
242 return false; // derived classes should override this function
243 }
244
253 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
254 {
255 return false; // derived classes should override this function
256 }
257
265 virtual bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
266 {
267 return false; // derived classes should override this function
268 }
269
277 virtual const BOX2I GetBoundingBox() const;
278
279 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
280 virtual void SetPosition( const VECTOR2I& aPos ){};
281
286 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
287
295 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
296
309 virtual EDA_ITEM* Clone() const;
310
325 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
326 const std::vector<KICAD_T>& aScanTypes );
327
331 template< class T >
332 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
333 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 {
342 }
343 }
344
346 }
347
351 template <class T>
352 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
353 void* testData, const std::vector<KICAD_T>& scanTypes )
354 {
355 for( const auto& it : aList )
356 {
357 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
358
359 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
360 {
362 }
363 }
364
366 }
367
372 wxString GetTypeDesc() const;
373
385 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
386
387 virtual wxString DisambiguateItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
388 {
389 return GetItemDescription( aUnitsProvider, aFull );
390 }
391
400 virtual BITMAPS GetMenuImage() const;
401
413 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
414 {
415 return false;
416 }
417
427 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
428
440 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
441 {
442 return false;
443 }
444
451 virtual bool IsReplaceable() const { return false; }
452
459 bool operator<( const EDA_ITEM& aItem ) const;
460
469 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
470
474 EDA_ITEM& operator=( const EDA_ITEM& aItem );
475
476 virtual const BOX2I ViewBBox() const override;
477
478 virtual std::vector<int> ViewGetLayers() const override;
479
480 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
481 virtual const std::vector<wxString>* GetEmbeddedFonts() { return nullptr; }
482
483#if defined(DEBUG)
484
494 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
495
496 void ShowDummy( std::ostream& os ) const;
497
505 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
506
507#endif
508
509protected:
510 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
511 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
512 EDA_ITEM( const EDA_ITEM& base );
513
523 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
524
525 EDA_ITEM* findParent( KICAD_T aType ) const;
526
527public:
529
530private:
537
538protected:
542
546};
547
548
555inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
556
561{
562 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
563 {
564 assert( item1 != nullptr && item2 != nullptr );
565
566 if( item1->m_Uuid == item2->m_Uuid )
567 return item1 < item2;
568
569 return item1->m_Uuid < item2->m_Uuid;
570 }
571};
572
573
580typedef std::vector< EDA_ITEM* > EDA_ITEMS;
581
582typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
583
584#endif // EDA_ITEM_H
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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:100
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition eda_item.h:253
virtual VECTOR2I GetPosition() const
Definition eda_item.h:279
virtual void ClearEditFlags()
Definition eda_item.h:163
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:338
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition eda_item.h:286
void SetIsRollover(bool aIsRollover, const VECTOR2I &aMousePos)
Definition eda_item.h:135
VECTOR2I GetRolloverPos() const
Definition eda_item.h:134
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:280
virtual void SetLocked(bool aLocked)
Definition eda_item.h:123
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:120
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition eda_item.cpp:402
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:469
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:155
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:149
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:154
void SetModified()
Definition eda_item.cpp:110
const KIID m_Uuid
Definition eda_item.h:528
bool m_forceVisible
Definition eda_item.h:545
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:118
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
bool IsEntered() const
Definition eda_item.h:130
void ClearSelected()
Definition eda_item.h:144
VECTOR2I m_rolloverPos
Definition eda_item.h:543
virtual const std::vector< wxString > * GetEmbeddedFonts()
Definition eda_item.h:481
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition eda_item.cpp:329
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:217
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:151
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:440
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:539
void SetIsShownAsBitmap(bool aBitmap)
Definition eda_item.h:183
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition eda_item.cpp:362
EDA_ITEM_FLAGS GetTempFlags() const
Definition eda_item.h:168
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:413
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition eda_item.h:541
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition eda_item.h:117
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:332
bool IsSelected() const
Definition eda_item.h:129
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:227
KIID GetParentGroupId() const
Definition eda_item.cpp:101
void SetSelected()
Definition eda_item.h:141
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:199
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:137
bool IsModified() const
Definition eda_item.h:125
bool IsShownAsBitmap() const
Definition eda_item.h:191
void ClearBrightened()
Definition eda_item.h:145
void SetBrightened()
Definition eda_item.h:142
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:240
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:411
EDA_ITEM * GetParent() const
Definition eda_item.h:114
bool m_isRollover
Definition eda_item.h:544
bool IsRollover() const
Definition eda_item.h:133
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:128
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:153
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition eda_item.h:480
bool IsBrightened() const
Definition eda_item.h:131
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition eda_item.h:295
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:150
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition eda_item.cpp:355
virtual bool RenderAsBitmap(double aWorldScale) const
Definition eda_item.h:181
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
virtual bool IsLocked() const
Definition eda_item.h:122
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:352
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:540
bool IsForceVisible() const
Definition eda_item.h:218
virtual bool HitTest(const SHAPE_LINE_CHAIN &aPoly, bool aContained) const
Test if aPoly intersects this item.
Definition eda_item.h:265
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:152
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:246
virtual wxString DisambiguateItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Definition eda_item.h:387
bool IsMoving() const
Definition eda_item.h:127
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition eda_item.h:536
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
bool IsNew() const
Definition eda_item.h:126
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition eda_item.h:451
virtual void ClearTempFlags()
Definition eda_item.h:176
EDA_ITEM * findParent(KICAD_T aType) const
Definition eda_item.cpp:77
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition eda_item.cpp:370
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:86
Definition kiid.h:48
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:54
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:555
RECURSE_MODE
Definition eda_item.h:52
@ RECURSE
Definition eda_item.h:53
@ NO_RECURSE
Definition eda_item.h:54
INSPECT_RESULT
Definition eda_item.h:46
std::set< EDA_ITEM *, CompareByUuid > EDA_ITEM_SET
Definition eda_item.h:582
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:93
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:90
#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:561
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition eda_item.h:562
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:75
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:200
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687