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
127 bool HasSelectedAncestorGroup() const;
128
129 virtual bool IsLocked() const { return false; }
130 virtual void SetLocked( bool aLocked ) {}
131
132 inline bool IsModified() const { return m_flags & IS_CHANGED; }
133 inline bool IsNew() const { return m_flags & IS_NEW; }
134 inline bool IsMoving() const { return m_flags & IS_MOVING; }
135
136 inline bool IsSelected() const { return m_flags & SELECTED; }
137 inline bool IsEntered() const { return m_flags & ENTERED; }
138 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
139
140 inline bool IsRollover() const { return m_isRollover; }
141 inline VECTOR2I GetRolloverPos() const { return m_rolloverPos; }
142 inline void SetIsRollover( bool aIsRollover, const VECTOR2I& aMousePos )
143 {
144 m_isRollover = aIsRollover;
145 m_rolloverPos = aMousePos;
146 }
147
148 inline void SetSelected() { SetFlags( SELECTED ); }
149 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
150
151 inline void ClearSelected() { ClearFlags( SELECTED ); }
153
154 void SetModified();
155
156 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
157 void XorFlags( EDA_ITEM_FLAGS aMask ) { m_flags ^= aMask; }
159 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
160 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
161
163 {
164 constexpr int mask =
166
167 return m_flags & mask;
168 }
169
170 virtual void ClearEditFlags()
171 {
173 }
174
176 {
179
180 return m_flags & mask;
181 }
182
183 virtual void ClearTempFlags()
184 {
186 }
187
188 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
189
190 void SetIsShownAsBitmap( bool aBitmap )
191 {
192 if( aBitmap )
194 else
196 }
197
198 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
199
206 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
207 {
208 for( KICAD_T scanType : aScanTypes )
209 {
210 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
211 return true;
212 }
213
214 return false;
215 }
216
224 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
225 bool IsForceVisible() const { return m_forceVisible; }
226
234 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
235 {
236 }
237
238 virtual wxString GetFriendlyName() const;
239
247 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
248 {
249 return false; // derived classes should override this function
250 }
251
260 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
261 {
262 return false; // derived classes should override this function
263 }
264
272 virtual bool HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
273 {
274 return false; // derived classes should override this function
275 }
276
284 virtual const BOX2I GetBoundingBox() const;
285
286 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
287 virtual void SetPosition( const VECTOR2I& aPos ){};
288
293 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
294
302 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
303
316 virtual EDA_ITEM* Clone() const;
317
332 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
333 const std::vector<KICAD_T>& aScanTypes );
334
338 template< class T >
339 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
340 const std::vector<KICAD_T>& scanTypes )
341 {
342 for( const auto& it : aList )
343 {
344 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
345
346 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
347 {
349 }
350 }
351
353 }
354
358 template <class T>
359 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
360 void* testData, const std::vector<KICAD_T>& scanTypes )
361 {
362 for( const auto& it : aList )
363 {
364 EDA_ITEM* item = static_cast<EDA_ITEM*>( it );
365
366 if( item && item->Visit( inspector, testData, scanTypes ) == INSPECT_RESULT::QUIT )
367 {
369 }
370 }
371
373 }
374
379 wxString GetTypeDesc() const;
380
392 virtual wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const;
393
394 virtual wxString DisambiguateItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
395 {
396 return GetItemDescription( aUnitsProvider, aFull );
397 }
398
407 virtual BITMAPS GetMenuImage() const;
408
420 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
421 {
422 return false;
423 }
424
434 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
435
447 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
448 {
449 return false;
450 }
451
458 virtual bool IsReplaceable() const { return false; }
459
466 bool operator<( const EDA_ITEM& aItem ) const;
467
476 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
477
481 EDA_ITEM& operator=( const EDA_ITEM& aItem );
482
483 virtual const BOX2I ViewBBox() const override;
484
485 virtual std::vector<int> ViewGetLayers() const override;
486
487 virtual EMBEDDED_FILES* GetEmbeddedFiles() { return nullptr; }
488 virtual const std::vector<wxString>* GetEmbeddedFonts() { return nullptr; }
489
490#if defined(DEBUG)
491
501 virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); };
502
503 void ShowDummy( std::ostream& os ) const;
504
512 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
513
514#endif
515
516protected:
517 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
518 EDA_ITEM( KICAD_T idType, bool isSCH_ITEM = false, bool isBOARD_ITEM = false );
519 EDA_ITEM( const EDA_ITEM& base );
520
530 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
531
532 EDA_ITEM* findParent( KICAD_T aType ) const;
533
534public:
536
537private:
544
545protected:
549
553};
554
555
562inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
563
568{
569 bool operator()(const EDA_ITEM* item1, const EDA_ITEM* item2) const
570 {
571 assert( item1 != nullptr && item2 != nullptr );
572
573 if( item1->m_Uuid == item2->m_Uuid )
574 return item1 < item2;
575
576 return item1->m_Uuid < item2->m_Uuid;
577 }
578};
579
580
587typedef std::vector< EDA_ITEM* > EDA_ITEMS;
588
589typedef std::set< EDA_ITEM*, CompareByUuid > EDA_ITEM_SET;
590
591#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:260
virtual VECTOR2I GetPosition() const
Definition eda_item.h:286
virtual void ClearEditFlags()
Definition eda_item.h:170
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition eda_item.cpp:357
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition() but allows items to return their visual center rather than their anchor.
Definition eda_item.h:293
void SetIsRollover(bool aIsRollover, const VECTOR2I &aMousePos)
Definition eda_item.h:142
VECTOR2I GetRolloverPos() const
Definition eda_item.h:141
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:287
virtual void SetLocked(bool aLocked)
Definition eda_item.h:130
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:139
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition eda_item.cpp:421
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:476
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:162
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:156
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:173
void SetModified()
Definition eda_item.cpp:129
const KIID m_Uuid
Definition eda_item.h:535
bool m_forceVisible
Definition eda_item.h:552
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:137
void ClearSelected()
Definition eda_item.h:151
VECTOR2I m_rolloverPos
Definition eda_item.h:550
virtual const std::vector< wxString > * GetEmbeddedFonts()
Definition eda_item.h:488
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition eda_item.cpp:348
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:224
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:158
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:447
EDA_ITEM_FLAGS m_flags
Definition eda_item.h:546
void SetIsShownAsBitmap(bool aBitmap)
Definition eda_item.h:190
virtual std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition eda_item.cpp:381
EDA_ITEM_FLAGS GetTempFlags() const
Definition eda_item.h:175
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition eda_item.h:420
EDA_GROUP * m_group
The group this item belongs to, if any. No ownership implied.
Definition eda_item.h:548
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:339
bool IsSelected() const
Definition eda_item.h:136
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:234
KIID GetParentGroupId() const
Definition eda_item.cpp:101
void SetSelected()
Definition eda_item.h:148
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:206
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:156
bool IsModified() const
Definition eda_item.h:132
bool IsShownAsBitmap() const
Definition eda_item.h:198
void ClearBrightened()
Definition eda_item.h:152
void SetBrightened()
Definition eda_item.h:149
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:247
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:430
EDA_ITEM * GetParent() const
Definition eda_item.h:114
bool HasSelectedAncestorGroup() const
Definition eda_item.cpp:110
bool m_isRollover
Definition eda_item.h:551
bool IsRollover() const
Definition eda_item.h:140
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:147
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:160
virtual EMBEDDED_FILES * GetEmbeddedFiles()
Definition eda_item.h:487
bool IsBrightened() const
Definition eda_item.h:138
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition eda_item.h:302
void XorFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:157
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition eda_item.cpp:374
virtual bool RenderAsBitmap(double aWorldScale) const
Definition eda_item.h:188
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
virtual bool IsLocked() const
Definition eda_item.h:129
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:359
EDA_ITEM * m_parent
Owner.
Definition eda_item.h:547
bool IsForceVisible() const
Definition eda_item.h:225
virtual bool HitTest(const SHAPE_LINE_CHAIN &aPoly, bool aContained) const
Test if aPoly intersects this item.
Definition eda_item.h:272
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:159
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:265
virtual wxString DisambiguateItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Definition eda_item.h:394
bool IsMoving() const
Definition eda_item.h:134
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition eda_item.h:543
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:133
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition eda_item.h:458
virtual void ClearTempFlags()
Definition eda_item.h:183
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:389
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:562
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:589
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:568
bool operator()(const EDA_ITEM *item1, const EDA_ITEM *item2) const
Definition eda_item.h:569
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