KiCad PCB EDA Suite
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 <core/typeinfo.h>
33#include <eda_item_flags.h>
34#include <eda_search_data.h>
35#include <view/view_item.h>
36#include <kiid.h>
37#include <units_provider.h>
38
39enum class BITMAPS : unsigned int;
40
41
43{
44 QUIT,
46};
47
48
53{
54 // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
55 FR_CURRENT_SHEET_ONLY = 0x4 << 1, // Search the current sheet only.
56 FR_SEARCH_ALL_FIELDS = 0x4 << 2, // Search hidden fields too.
57 FR_SEARCH_ALL_PINS = 0x4 << 3, // Search pin name and number.
58 FR_MATCH_WILDCARD = 0x4 << 4, // Use simple wild card matching (* & ?).
59 FR_SEARCH_WRAP = 0x4 << 5, // Wrap around the start or end of search.
60 FR_SEARCH_REPLACE = 0x4 << 7, // Search for a item that has replaceable text.
61 FR_REPLACE_ITEM_FOUND = 0x4 << 8, // Indicates an item with replaceable text has been found.
62 FR_REPLACE_REFERENCES = 0x4 << 9 // Don't replace in references.
63};
64
65class wxFindReplaceData;
66class EDA_DRAW_FRAME;
67class MSG_PANEL_ITEM;
68
69
89typedef std::function< INSPECT_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
90
93
94
99{
100public:
101 virtual ~EDA_ITEM() { };
102
111 inline KICAD_T Type() const { return m_structType; }
112
113 EDA_ITEM* GetParent() const { return m_parent; }
114 virtual void SetParent( EDA_ITEM* aParent ) { m_parent = aParent; }
115
116 inline bool IsModified() const { return m_flags & IS_CHANGED; }
117 inline bool IsNew() const { return m_flags & IS_NEW; }
118 inline bool IsMoving() const { return m_flags & IS_MOVING; }
119 inline bool IsDragging() const { return m_flags & IS_DRAGGING; }
120 inline bool IsWireImage() const { return m_flags & IS_WIRE_IMAGE; }
121 inline bool IsSelected() const { return m_flags & SELECTED; }
122 inline bool IsEntered() const { return m_flags & ENTERED; }
123 inline bool IsResized() const { return m_flags & IS_RESIZING; }
124 inline bool IsBrightened() const { return m_flags & BRIGHTENED; }
125
126 inline bool IsRollover() const
127 {
128 return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER;
129 }
130
131 inline void SetWireImage() { SetFlags( IS_WIRE_IMAGE ); }
132 inline void SetSelected() { SetFlags( SELECTED ); }
133 inline void SetBrightened() { SetFlags( BRIGHTENED ); }
134
135 inline void ClearSelected() { ClearFlags( SELECTED ); }
137
138 void SetModified();
139
140 int GetState( EDA_ITEM_FLAGS type ) const
141 {
142 return m_status & type;
143 }
144
145 void SetState( EDA_ITEM_FLAGS type, bool state )
146 {
147 if( state )
148 m_status |= type; // state = ON or OFF
149 else
150 m_status &= ~type;
151 }
152
154 void SetStatus( EDA_ITEM_FLAGS aStatus ) { m_status = aStatus; }
155
156 void SetFlags( EDA_ITEM_FLAGS aMask ) { m_flags |= aMask; }
158 EDA_ITEM_FLAGS GetFlags() const { return m_flags; }
159 bool HasFlag( EDA_ITEM_FLAGS aFlag ) const { return ( m_flags & aFlag ) == aFlag; }
160
162 {
163 constexpr int mask = ( IS_NEW | IS_PASTED | IS_MOVING | IS_RESIZING | IS_DRAGGING
165
166 return m_flags & mask;
167 }
168
170 {
172 }
173
175 {
177 }
178
179 virtual bool RenderAsBitmap( double aWorldScale ) const { return false; }
180
181 void SetIsShownAsBitmap( bool aBitmap )
182 {
183 if( aBitmap )
185 else
187 }
188
189 inline bool IsShownAsBitmap() const { return m_flags & IS_SHOWN_AS_BITMAP; }
190
197 virtual bool IsType( const std::vector<KICAD_T>& aScanTypes ) const
198 {
199 for( KICAD_T scanType : aScanTypes )
200 {
201 if( scanType == SCH_LOCATE_ANY_T || scanType == m_structType )
202 return true;
203 }
204
205 return false;
206 }
207
215 void SetForceVisible( bool aEnable ) { m_forceVisible = aEnable; }
216
217 bool IsForceVisible() const { return m_forceVisible; }
218
225 virtual void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
226 {
227 }
228
236 virtual bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const
237 {
238 return false; // derived classes should override this function
239 }
240
249 virtual bool HitTest( const BOX2I& aRect, bool aContained, int aAccuracy = 0 ) const
250 {
251 return false; // derived classes should override this function
252 }
253
261 virtual const BOX2I GetBoundingBox() const;
262
263 virtual VECTOR2I GetPosition() const { return VECTOR2I(); }
264 virtual void SetPosition( const VECTOR2I& aPos ){};
265
270 virtual const VECTOR2I GetFocusPosition() const { return GetPosition(); }
271
279 virtual VECTOR2I GetSortPosition() const { return GetPosition(); }
280
293 virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
294
309 virtual INSPECT_RESULT Visit( INSPECTOR inspector, void* testData,
310 const std::vector<KICAD_T>& aScanTypes );
311
315 template< class T >
316 static INSPECT_RESULT IterateForward( std::deque<T>& aList, INSPECTOR inspector, void* testData,
317 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 {
326 }
327 }
328
330 }
331
335 template <class T>
336 static INSPECT_RESULT IterateForward( std::vector<T>& aList, INSPECTOR inspector,
337 void* testData, const std::vector<KICAD_T>& scanTypes )
338 {
339 for( const auto& it : aList )
340 {
341 if( static_cast<EDA_ITEM*>( it )->Visit( inspector,
342 testData,
343 scanTypes ) == INSPECT_RESULT::QUIT )
344 {
346 }
347 }
348
350 }
351
355 virtual wxString GetClass() const = 0;
356
361 wxString GetTypeDesc();
362
373 virtual wxString GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const;
374
383 virtual BITMAPS GetMenuImage() const;
384
396 virtual bool Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
397 {
398 return false;
399 }
400
410 static bool Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText );
411
423 virtual bool Replace( const EDA_SEARCH_DATA& aSearchData, void* aAuxData = nullptr )
424 {
425 return false;
426 }
427
434 virtual bool IsReplaceable() const { return false; }
435
442 bool operator<( const EDA_ITEM& aItem ) const;
443
452 static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
453
457 EDA_ITEM& operator=( const EDA_ITEM& aItem );
458
459 virtual const BOX2I ViewBBox() const override;
460
461 virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
462
463#if defined(DEBUG)
464
474 virtual void Show( int nestLevel, std::ostream& os ) const = 0;
475
476 void ShowDummy( std::ostream& os ) const;
477
485 static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
486
487#endif
488
489protected:
490 EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
491 EDA_ITEM( KICAD_T idType );
492 EDA_ITEM( const EDA_ITEM& base );
493
503 bool Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const;
504
505public:
507
508protected:
513
514private:
520};
521
522
529inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
530
531
538typedef std::vector< EDA_ITEM* > EDA_ITEMS;
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:99
void SetStatus(EDA_ITEM_FLAGS aStatus)
Definition: eda_item.h:154
virtual bool HitTest(const BOX2I &aRect, bool aContained, int aAccuracy=0) const
Test if aRect intersects this item.
Definition: eda_item.h:249
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:263
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:240
virtual const VECTOR2I GetFocusPosition() const
Similar to GetPosition, but allows items to return their visual center rather than their anchor.
Definition: eda_item.h:270
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:264
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType)
Definition: eda_item.cpp:36
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:261
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:452
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:161
int GetState(EDA_ITEM_FLAGS type) const
Definition: eda_item.h:140
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:156
void SetWireImage()
Definition: eda_item.h:131
void SetModified()
Definition: eda_item.cpp:64
const KIID m_Uuid
Definition: eda_item.h:506
bool m_forceVisible
Definition: eda_item.h:511
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:111
bool IsEntered() const
Definition: eda_item.h:122
void ClearSelected()
Definition: eda_item.h:135
bool operator<(const EDA_ITEM &aItem) const
Test if another item is less than this object.
Definition: eda_item.cpp:231
EDA_ITEM_FLAGS m_status
Definition: eda_item.h:509
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:215
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:157
void ClearTempFlags()
Definition: eda_item.h:169
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:423
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:512
void SetIsShownAsBitmap(bool aBitmap)
Definition: eda_item.h:181
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:396
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:316
bool IsSelected() const
Definition: eda_item.h:121
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:225
void SetSelected()
Definition: eda_item.h:132
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:197
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 void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:114
bool IsModified() const
Definition: eda_item.h:116
bool IsShownAsBitmap() const
Definition: eda_item.h:189
bool IsWireImage() const
Definition: eda_item.h:120
void ClearBrightened()
Definition: eda_item.h:136
void SetBrightened()
Definition: eda_item.h:133
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:236
EDA_ITEM * GetParent() const
Definition: eda_item.h:113
EDA_ITEM_FLAGS GetStatus() const
Definition: eda_item.h:153
bool IsRollover() const
Definition: eda_item.h:126
void SetState(EDA_ITEM_FLAGS type, bool state)
Definition: eda_item.h:145
wxString GetTypeDesc()
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:301
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:159
bool IsBrightened() const
Definition: eda_item.h:124
virtual VECTOR2I GetSortPosition() const
Return the coordinates that should be used for sorting this element visually compared to other elemen...
Definition: eda_item.h:279
bool IsDragging() const
Definition: eda_item.h:119
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:254
virtual bool RenderAsBitmap(double aWorldScale) const
Definition: eda_item.h:179
virtual ~EDA_ITEM()
Definition: eda_item.h:101
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:336
void ClearEditFlags()
Definition: eda_item.h:174
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:510
bool IsForceVisible() const
Definition: eda_item.h:217
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:158
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:168
bool IsMoving() const
Definition: eda_item.h:118
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:519
bool IsNew() const
Definition: eda_item.h:117
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:434
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:269
virtual wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:108
bool IsResized() const
Definition: eda_item.h:123
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Definition: kiid.h:47
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
EDA_ITEM * new_clone(const EDA_ITEM &aItem)
Provide cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
Definition: eda_item.h:529
INSPECT_RESULT
Definition: eda_item.h:43
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:538
FIND_REPLACE_FLAGS
Additional flag values wxFindReplaceData::m_Flags.
Definition: eda_item.h:53
@ FR_CURRENT_SHEET_ONLY
Definition: eda_item.h:55
@ FR_MATCH_WILDCARD
Definition: eda_item.h:58
@ FR_SEARCH_ALL_PINS
Definition: eda_item.h:57
@ FR_REPLACE_ITEM_FOUND
Definition: eda_item.h:61
@ FR_SEARCH_WRAP
Definition: eda_item.h:59
@ FR_SEARCH_REPLACE
Definition: eda_item.h:60
@ FR_SEARCH_ALL_FIELDS
Definition: eda_item.h:56
@ FR_REPLACE_REFERENCES
Definition: eda_item.h:62
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:92
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:89
#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_DRAGGING
Item being dragged.
#define IS_WIRE_IMAGE
Item to be drawn as wireframe while editing.
#define DO_NOT_DRAW
Used to disable draw function.
#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.
#define IS_RESIZING
Item being resized.
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:182
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618