KiCad PCB EDA Suite
eda_item.cpp
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) 2015 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <algorithm>
26
27#include <bitmaps.h>
28#include <eda_item.h>
29#include <trace_helpers.h>
30#include <trigo.h>
31#include <i18n_utility.h>
32#include <wx/log.h>
33
34#include <wx/fdrepdlg.h>
35
37 m_status( 0 ),
38 m_parent( parent ),
39 m_forceVisible( false ),
40 m_flags( 0 ),
41 m_structType( idType )
42{ }
43
44
46 m_status( 0 ),
47 m_parent( nullptr ),
48 m_forceVisible( false ),
49 m_flags( 0 ),
50 m_structType( idType )
51{ }
52
53
55 m_Uuid( base.m_Uuid ),
56 m_status( base.m_status ),
57 m_parent( base.m_parent ),
58 m_forceVisible( base.m_forceVisible ),
59 m_flags( base.m_flags ),
60 m_structType( base.m_structType )
61{ }
62
63
65{
67
68 // If this a child object, then the parent modification state also needs to be set.
69 if( m_parent )
71}
72
73
75{
76 // return a zero-sized box per default. derived classes should override
77 // this
78 return BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( 0, 0 ) );
79}
80
81
83{
84 wxCHECK_MSG( false, nullptr, wxT( "Clone not implemented in derived class " ) + GetClass() +
85 wxT( ". Bad programmer!" ) );
86}
87
88
89// see base_struct.h
90// many classes inherit this method, be careful:
91INSPECT_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData,
92 const std::vector<KICAD_T>& aScanTypes )
93{
94#if 0 && defined(DEBUG)
95 std::cout << GetClass().mb_str() << ' ';
96#endif
97
98 if( IsType( aScanTypes ) )
99 {
100 if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
102 }
103
105}
106
107
108wxString EDA_ITEM::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
109{
110 wxFAIL_MSG( wxT( "GetSelectMenuText() was not overridden for schematic item type " ) +
111 GetClass() );
112
113 return wxString( wxT( "Undefined menu text for " ) + GetClass() );
114}
115
116
117bool EDA_ITEM::Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const
118{
119 wxString text = aText;
120 wxString searchText = aSearchData.findString;
121
122 // Don't match if searching for replaceable item and the item doesn't support text replace.
123 if( aSearchData.searchAndReplace && !IsReplaceable() )
124 return false;
125
126 if( !aSearchData.matchCase )
127 {
128 text.MakeUpper();
129 searchText.MakeUpper();
130 }
131
133 {
134 int ii = 0;
135
136 while( ii < (int) text.length() )
137 {
138 int next = text.find( searchText, ii );
139
140 if( next == wxNOT_FOUND )
141 return false;
142
143 ii = next;
144 next += searchText.length();
145
146 bool startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) );
147 bool endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) );
148
149 if( startOK && endOK )
150 return true;
151 else
152 ii++;
153 }
154
155 return false;
156 }
157 else if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WILDCARD )
158 {
159 return text.Matches( searchText );
160 }
161 else
162 {
163 return text.Find( searchText ) != wxNOT_FOUND;
164 }
165}
166
167
168bool EDA_ITEM::Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText )
169{
170 wxString text = aText;
171 wxString searchText = aSearchData.findString;
172 wxString result;
173 bool replaced = false;
174
175 if( !aSearchData.matchCase )
176 {
177 text = text.Upper();
178 searchText = searchText.Upper();
179 }
180
181 int ii = 0;
182
183 while( ii < (int) text.length() )
184 {
185 int next = text.find( searchText, ii );
186
187 if( next == wxNOT_FOUND )
188 {
189 result += aText.Mid( ii, wxString::npos );
190 break;
191 }
192
193 if( next > ii )
194 result += aText.Mid( ii, next - ii );
195
196 ii = next;
197 next += searchText.length();
198
199 bool startOK;
200 bool endOK;
201
203 {
204 startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) );
205 endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) );
206 }
207 else
208 {
209 startOK = true;
210 endOK = true;
211 }
212
213 if( startOK && endOK )
214 {
215 result += aSearchData.replaceString;
216 replaced = true;
217 ii = next;
218 }
219 else
220 {
221 result += aText.GetChar( ii );
222 ii++;
223 }
224 }
225
226 aText = result;
227 return replaced;
228}
229
230
231bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
232{
233 wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
234 GetClass() ) );
235
236 return false;
237}
238
239
241{
242 // do not call initVars()
243
245 m_flags = aItem.m_flags;
246 m_status = aItem.m_status;
247 m_parent = aItem.m_parent;
249
250 return *this;
251}
252
253
255{
256 // Basic fallback
257 return GetBoundingBox();
258}
259
260
261void EDA_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
262{
263 // Basic fallback
264 aCount = 1;
265 aLayers[0] = 0;
266}
267
268
270{
271 return BITMAPS::dummy_item;
272}
273
274
275#if defined( DEBUG )
276
277void EDA_ITEM::ShowDummy( std::ostream& os ) const
278{
279 // XML output:
280 wxString s = GetClass();
281
282 os << '<' << s.Lower().mb_str() << ">"
283 << " Need ::Show() override for this class "
284 << "</" << s.Lower().mb_str() << ">\n";
285}
286
287
288std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os )
289{
290 for( int i = 0; i<nestLevel; ++i )
291 os << " ";
292
293 // number of spaces here controls indent per nest level
294
295 return os;
296}
297
298#endif
299
300
302{
303 //@see EDA_ITEM_DESC for definition of ENUM_MAP<KICAD_T>
304 wxString typeDescr = ENUM_MAP<KICAD_T>::Instance().ToString( Type() );
305
306 return wxGetTranslation( typeDescr );
307}
308
309
310static struct EDA_ITEM_DESC
311{
313 {
315 .Undefined( TYPE_NOT_INIT )
316 .Map( NOT_USED, wxT( "<not used>" ) )
317 .Map( SCREEN_T, _HKI( "Screen" ) )
318
319 .Map( PCB_FOOTPRINT_T, _HKI( "Footprint" ) )
320 .Map( PCB_PAD_T, _HKI( "Pad" ) )
321 .Map( PCB_SHAPE_T, _HKI( "Graphic" ) )
322 .Map( PCB_BITMAP_T, _HKI( "Bitmap" ) )
323 .Map( PCB_TEXT_T, _HKI( "Text" ) )
324 .Map( PCB_TEXTBOX_T, _HKI( "Text Box" ) )
325 .Map( PCB_FP_TEXT_T, _HKI( "Text" ) )
326 .Map( PCB_FP_TEXTBOX_T, _HKI( "Text Box" ) )
327 .Map( PCB_FP_SHAPE_T, _HKI( "Graphic" ) )
328 .Map( PCB_FP_DIM_ALIGNED_T, _HKI( "Dimension" ) )
329 .Map( PCB_FP_DIM_ORTHOGONAL_T, _HKI( "Dimension" ) )
330 .Map( PCB_FP_DIM_CENTER_T, _HKI( "Dimension" ) )
331 .Map( PCB_FP_DIM_RADIAL_T, _HKI( "Dimension" ) )
332 .Map( PCB_FP_DIM_LEADER_T, _HKI( "Leader" ) )
333 .Map( PCB_FP_ZONE_T, _HKI( "Zone" ) )
334 .Map( PCB_TRACE_T, _HKI( "Track" ) )
335 .Map( PCB_ARC_T, _HKI( "Track" ) )
336 .Map( PCB_VIA_T, _HKI( "Via" ) )
337 .Map( PCB_MARKER_T, _HKI( "Marker" ) )
338 .Map( PCB_DIM_ALIGNED_T, _HKI( "Dimension" ) )
339 .Map( PCB_DIM_ORTHOGONAL_T, _HKI( "Dimension" ) )
340 .Map( PCB_DIM_CENTER_T, _HKI( "Dimension" ) )
341 .Map( PCB_DIM_RADIAL_T, _HKI( "Dimension" ) )
342 .Map( PCB_DIM_LEADER_T, _HKI( "Leader" ) )
343 .Map( PCB_TARGET_T, _HKI( "Target" ) )
344 .Map( PCB_ZONE_T, _HKI( "Zone" ) )
345 .Map( PCB_ITEM_LIST_T, _HKI( "ItemList" ) )
346 .Map( PCB_NETINFO_T, _HKI( "NetInfo" ) )
347 .Map( PCB_GROUP_T, _HKI( "Group" ) )
348
349 .Map( SCH_MARKER_T, _HKI( "Marker" ) )
350 .Map( SCH_JUNCTION_T, _HKI( "Junction" ) )
351 .Map( SCH_NO_CONNECT_T, _HKI( "No-Connect Flag" ) )
352 .Map( SCH_BUS_WIRE_ENTRY_T, _HKI( "Wire Entry" ) )
353 .Map( SCH_BUS_BUS_ENTRY_T, _HKI( "Bus Entry" ) )
354 .Map( SCH_LINE_T, _HKI( "Line" ) )
355 .Map( SCH_BITMAP_T, _HKI( "Bitmap" ) )
356 .Map( SCH_TEXT_T, _HKI( "Text" ) )
357 .Map( SCH_TEXTBOX_T, _HKI( "Text Box" ) )
358 .Map( SCH_LABEL_T, _HKI( "Net Label" ) )
359 .Map( SCH_DIRECTIVE_LABEL_T, _HKI( "Directive Label" ) )
360 .Map( SCH_GLOBAL_LABEL_T, _HKI( "Global Label" ) )
361 .Map( SCH_HIER_LABEL_T, _HKI( "Hierarchical Label" ) )
362 .Map( SCH_FIELD_T, _HKI( "Field" ) )
363 .Map( SCH_SYMBOL_T, _HKI( "Symbol" ) )
364 .Map( SCH_PIN_T, _HKI( "Pin" ) )
365 .Map( SCH_SHEET_PIN_T, _HKI( "Sheet Pin" ) )
366 .Map( SCH_SHEET_T, _HKI( "Sheet" ) )
367
368 // Synthetic search tokens don't need to be included...
369 //.Map( SCH_FIELD_LOCATE_REFERENCE_T, _HKI( "Field Locate Reference" ) )
370 //.Map( SCH_FIELD_LOCATE_VALUE_T, _HKI( "Field Locate Value" ) )
371 //.Map( SCH_FIELD_LOCATE_FOOTPRINT_T, _HKI( "Field Locate Footprint" ) )
372
373 .Map( SCH_SCREEN_T, _HKI( "SCH Screen" ) )
374
375 .Map( LIB_SYMBOL_T, _HKI( "Symbol" ) )
376 .Map( LIB_ALIAS_T, _HKI( "Alias" ) )
377 .Map( LIB_SHAPE_T, _HKI( "Graphic" ) )
378 .Map( LIB_TEXT_T, _HKI( "Text" ) )
379 .Map( LIB_TEXTBOX_T, _HKI( "Text Box" ) )
380 .Map( LIB_PIN_T, _HKI( "Pin" ) )
381 .Map( LIB_FIELD_T, _HKI( "Symbol Field" ) )
382
383 .Map( GERBER_LAYOUT_T, _HKI( "Gerber Layout" ) )
384 .Map( GERBER_DRAW_ITEM_T, _HKI( "Draw Item" ) )
385 .Map( GERBER_IMAGE_T, _HKI( "Image" ) );
386
391 }
393
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
BOX2< VECTOR2I > BOX2I
Definition: box2.h:847
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:240
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
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
void SetModified()
Definition: eda_item.cpp:64
bool m_forceVisible
Definition: eda_item.h:497
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
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:495
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:498
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:382
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:183
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
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
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
EDA_ITEM * m_parent
Linked list: Link (parent struct)
Definition: eda_item.h:496
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
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:505
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:420
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
static ENUM_MAP< T > & Instance()
Definition: property.h:512
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:63
void AddProperty(PROPERTY_BASE *aProperty)
Register a property.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:65
#define _HKI(x)
ENUM_TO_WXANY(KICAD_T)
static struct EDA_ITEM_DESC _EDA_ITEM_DESC
INSPECT_RESULT
Definition: eda_item.h:42
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:78
#define IS_CHANGED
Item was edited, and modified.
Some functions to handle hotkeys in KiCad.
#define NO_SETTER(owner, type)
Definition: property.h:623
#define REGISTER_TYPE(x)
Definition: property_mgr.h:248
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
CITER next(CITER it)
Definition: ptree.cpp:126
EDA_SEARCH_MATCH_MODE matchMode
wxString replaceString
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_FP_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:95
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:110
@ SCH_LINE_T
Definition: typeinfo.h:145
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ LIB_SYMBOL_T
Definition: typeinfo.h:197
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:142
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:107
@ LIB_TEXT_T
Definition: typeinfo.h:200
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ LIB_ALIAS_T
Definition: typeinfo.h:198
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:93
@ SCH_SYMBOL_T
Definition: typeinfo.h:155
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:108
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:112
@ LIB_TEXTBOX_T
Definition: typeinfo.h:201
@ SCH_FIELD_T
Definition: typeinfo.h:154
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:153
@ SCH_LABEL_T
Definition: typeinfo.h:150
@ PCB_FP_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:97
@ SCH_SHEET_T
Definition: typeinfo.h:157
@ LIB_SHAPE_T
Definition: typeinfo.h:199
@ SCH_MARKER_T
Definition: typeinfo.h:140
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:113
@ GERBER_DRAW_ITEM_T
Definition: typeinfo.h:214
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:152
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:104
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:144
@ LIB_PIN_T
Definition: typeinfo.h:202
@ SCH_SCREEN_T
Definition: typeinfo.h:185
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:111
@ PCB_FP_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:99
@ PCB_FP_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:96
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:156
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:106
@ SCH_TEXT_T
Definition: typeinfo.h:149
@ LIB_FIELD_T
Definition: typeinfo.h:208
@ PCB_FP_ZONE_T
class ZONE, managed by a footprint
Definition: typeinfo.h:100
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_FP_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:98
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ GERBER_IMAGE_T
Definition: typeinfo.h:215
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:143
@ GERBER_LAYOUT_T
Definition: typeinfo.h:213
@ SCREEN_T
not really an item, used to identify a screen
Definition: typeinfo.h:83
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
@ SCH_BITMAP_T
Definition: typeinfo.h:147
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:103
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:114
@ SCH_TEXTBOX_T
Definition: typeinfo.h:148
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:101
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:109
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:151
@ SCH_JUNCTION_T
Definition: typeinfo.h:141
@ SCH_PIN_T
Definition: typeinfo.h:158
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618