KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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_parent( parent ),
38 m_forceVisible( false ),
39 m_flags( 0 ),
40 m_structType( idType )
41{ }
42
43
45 m_parent( nullptr ),
46 m_forceVisible( false ),
47 m_flags( 0 ),
48 m_structType( idType )
49{ }
50
51
53 m_Uuid( base.m_Uuid ),
54 m_parent( base.m_parent ),
55 m_forceVisible( base.m_forceVisible ),
56 m_flags( base.m_flags ),
57 m_structType( base.m_structType )
58{
60}
61
62
64{
66
67 // If this a child object, then the parent modification state also needs to be set.
68 if( m_parent )
70}
71
72
74{
75 // return a zero-sized box per default. derived classes should override
76 // this
77 return BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( 0, 0 ) );
78}
79
80
82{
83 wxCHECK_MSG( false, nullptr, wxT( "Clone not implemented in derived class " ) + GetClass() +
84 wxT( ". Bad programmer!" ) );
85}
86
87
88// see base_struct.h
89// many classes inherit this method, be careful:
90INSPECT_RESULT EDA_ITEM::Visit( INSPECTOR inspector, void* testData,
91 const std::vector<KICAD_T>& aScanTypes )
92{
93#if 0 && defined(DEBUG)
94 std::cout << GetClass().mb_str() << ' ';
95#endif
96
97 if( IsType( aScanTypes ) )
98 {
99 if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
100 return INSPECT_RESULT::QUIT;
101 }
102
103 return INSPECT_RESULT::CONTINUE;
104}
105
106
107wxString EDA_ITEM::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
108{
109 wxFAIL_MSG( wxT( "GetItemDescription() was not overridden for schematic item type " ) +
110 GetClass() );
111
112 return wxString( wxT( "Undefined item description for " ) + GetClass() );
113}
114
115
116bool EDA_ITEM::Matches( const wxString& aText, const EDA_SEARCH_DATA& aSearchData ) const
117{
118 wxString text = aText;
119 wxString searchText = aSearchData.findString;
120
121 // Don't match if searching for replaceable item and the item doesn't support text replace.
122 if( aSearchData.searchAndReplace && !IsReplaceable() )
123 return false;
124
125 if( !aSearchData.matchCase )
126 {
127 text.MakeUpper();
128 searchText.MakeUpper();
129 }
130
131 if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD )
132 {
133 int ii = 0;
134
135 while( ii < (int) text.length() )
136 {
137 int next = text.find( searchText, ii );
138
139 if( next == wxNOT_FOUND )
140 return false;
141
142 ii = next;
143 next += searchText.length();
144
145 bool startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) );
146 bool endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) );
147
148 if( startOK && endOK )
149 return true;
150 else
151 ii++;
152 }
153
154 return false;
155 }
156 else if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WILDCARD )
157 {
158 return text.Matches( searchText );
159 }
160 else
161 {
162 return text.Find( searchText ) != wxNOT_FOUND;
163 }
164}
165
166
167bool EDA_ITEM::Replace( const EDA_SEARCH_DATA& aSearchData, wxString& aText )
168{
169 wxString text = aText;
170 wxString searchText = aSearchData.findString;
171 wxString result;
172 bool replaced = false;
173
174 if( !aSearchData.matchCase )
175 {
176 text = text.Upper();
177 searchText = searchText.Upper();
178 }
179
180 int ii = 0;
181
182 while( ii < (int) text.length() )
183 {
184 int next = text.find( searchText, ii );
185
186 if( next == wxNOT_FOUND )
187 {
188 result += aText.Mid( ii, wxString::npos );
189 break;
190 }
191
192 if( next > ii )
193 result += aText.Mid( ii, next - ii );
194
195 ii = next;
196 next += searchText.length();
197
198 bool startOK;
199 bool endOK;
200
201 if( aSearchData.matchMode == EDA_SEARCH_MATCH_MODE::WHOLEWORD )
202 {
203 startOK = ( ii == 0 || !wxIsalnum( text.GetChar( ii - 1 ) ) );
204 endOK = ( next == (int) text.length() || !wxIsalnum( text.GetChar( next ) ) );
205 }
206 else
207 {
208 startOK = true;
209 endOK = true;
210 }
211
212 if( startOK && endOK )
213 {
214 result += aSearchData.replaceString;
215 replaced = true;
216 ii = next;
217 }
218 else
219 {
220 result += aText.GetChar( ii );
221 ii++;
222 }
223 }
224
225 aText = result;
226 return replaced;
227}
228
229
230bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const
231{
232 wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ),
233 GetClass() ) );
234
235 return false;
236}
237
238
240{
241 // do not call initVars()
242
244 m_flags = aItem.m_flags;
245 m_parent = aItem.m_parent;
247
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
301wxString EDA_ITEM::GetTypeDesc() const
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
311{
312 return GetTypeDesc();
313}
314
315
316static struct EDA_ITEM_DESC
317{
319 {
321 .Undefined( TYPE_NOT_INIT )
322 .Map( NOT_USED, wxT( "<not used>" ) )
323 .Map( SCREEN_T, _HKI( "Screen" ) )
324
325 .Map( PCB_FOOTPRINT_T, _HKI( "Footprint" ) )
326 .Map( PCB_PAD_T, _HKI( "Pad" ) )
327 .Map( PCB_SHAPE_T, _HKI( "Graphic" ) )
328 .Map( PCB_BITMAP_T, _HKI( "Bitmap" ) )
329 .Map( PCB_TEXT_T, _HKI( "Text" ) )
330 .Map( PCB_TEXTBOX_T, _HKI( "Text Box" ) )
331 .Map( PCB_TRACE_T, _HKI( "Track" ) )
332 .Map( PCB_ARC_T, _HKI( "Track" ) )
333 .Map( PCB_VIA_T, _HKI( "Via" ) )
334 .Map( PCB_MARKER_T, _HKI( "Marker" ) )
335 .Map( PCB_DIM_ALIGNED_T, _HKI( "Dimension" ) )
336 .Map( PCB_DIM_ORTHOGONAL_T, _HKI( "Dimension" ) )
337 .Map( PCB_DIM_CENTER_T, _HKI( "Dimension" ) )
338 .Map( PCB_DIM_RADIAL_T, _HKI( "Dimension" ) )
339 .Map( PCB_DIM_LEADER_T, _HKI( "Leader" ) )
340 .Map( PCB_TARGET_T, _HKI( "Target" ) )
341 .Map( PCB_ZONE_T, _HKI( "Zone" ) )
342 .Map( PCB_ITEM_LIST_T, _HKI( "ItemList" ) )
343 .Map( PCB_NETINFO_T, _HKI( "NetInfo" ) )
344 .Map( PCB_GROUP_T, _HKI( "Group" ) )
345
346 .Map( SCH_MARKER_T, _HKI( "Marker" ) )
347 .Map( SCH_JUNCTION_T, _HKI( "Junction" ) )
348 .Map( SCH_NO_CONNECT_T, _HKI( "No-Connect Flag" ) )
349 .Map( SCH_BUS_WIRE_ENTRY_T, _HKI( "Wire Entry" ) )
350 .Map( SCH_BUS_BUS_ENTRY_T, _HKI( "Bus Entry" ) )
351 .Map( SCH_LINE_T, _HKI( "Line" ) )
352 .Map( SCH_BITMAP_T, _HKI( "Bitmap" ) )
353 .Map( SCH_TEXT_T, _HKI( "Text" ) )
354 .Map( SCH_TEXTBOX_T, _HKI( "Text Box" ) )
355 .Map( SCH_LABEL_T, _HKI( "Net Label" ) )
356 .Map( SCH_DIRECTIVE_LABEL_T, _HKI( "Directive Label" ) )
357 .Map( SCH_GLOBAL_LABEL_T, _HKI( "Global Label" ) )
358 .Map( SCH_HIER_LABEL_T, _HKI( "Hierarchical Label" ) )
359 .Map( SCH_FIELD_T, _HKI( "Field" ) )
360 .Map( SCH_SYMBOL_T, _HKI( "Symbol" ) )
361 .Map( SCH_PIN_T, _HKI( "Pin" ) )
362 .Map( SCH_SHEET_PIN_T, _HKI( "Sheet Pin" ) )
363 .Map( SCH_SHEET_T, _HKI( "Sheet" ) )
364
365 // Synthetic search tokens don't need to be included...
366 //.Map( SCH_FIELD_LOCATE_REFERENCE_T, _HKI( "Field Locate Reference" ) )
367 //.Map( SCH_FIELD_LOCATE_VALUE_T, _HKI( "Field Locate Value" ) )
368 //.Map( SCH_FIELD_LOCATE_FOOTPRINT_T, _HKI( "Field Locate Footprint" ) )
369
370 .Map( SCH_SCREEN_T, _HKI( "SCH Screen" ) )
371
372 .Map( LIB_SYMBOL_T, _HKI( "Symbol" ) )
373 .Map( LIB_SHAPE_T, _HKI( "Graphic" ) )
374 .Map( LIB_TEXT_T, _HKI( "Text" ) )
375 .Map( LIB_TEXTBOX_T, _HKI( "Text Box" ) )
376 .Map( LIB_PIN_T, _HKI( "Pin" ) )
377 .Map( LIB_FIELD_T, _HKI( "Symbol Field" ) )
378
379 .Map( GERBER_LAYOUT_T, _HKI( "Gerber Layout" ) )
380 .Map( GERBER_DRAW_ITEM_T, _HKI( "Draw Item" ) )
381 .Map( GERBER_IMAGE_T, _HKI( "Image" ) );
382
385
386 propMgr.AddProperty( new PROPERTY_ENUM<EDA_ITEM, KICAD_T>( wxS( "Type" ),
389 }
391
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:239
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:73
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
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:301
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:123
void SetModified()
Definition: eda_item.cpp:63
bool m_forceVisible
Definition: eda_item.h:479
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:230
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:480
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:365
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition: eda_item.h:165
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:90
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:107
virtual wxString GetFriendlyName() const
Definition: eda_item.cpp:310
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:81
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:478
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:167
KICAD_T m_structType
Run time identification, keep private so it can never be changed after a ctor sets it.
Definition: eda_item.h:487
virtual bool IsReplaceable() const
Override this method in any derived object that supports test find and replace.
Definition: eda_item.h:403
virtual BITMAPS GetMenuImage() const
Return a pointer to an image to be used in menus.
Definition: eda_item.cpp:269
static ENUM_MAP< T > & Instance()
Definition: property.h:627
void SetForcedTransparency(double aForcedTransparency)
Definition: view_item.h:145
double GetForcedTransparency() const
Definition: view_item.h:150
PROPERTY_BASE & SetIsHiddenFromPropertiesManager(bool aHide=true)
Definition: property.h:284
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:74
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:76
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
#define _HKI(x)
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:738
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:729
#define REGISTER_TYPE(x)
Definition: property_mgr.h:328
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_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:101
@ SCH_LINE_T
Definition: typeinfo.h:136
@ LIB_SYMBOL_T
Definition: typeinfo.h:188
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:133
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:98
@ LIB_TEXT_T
Definition: typeinfo.h:190
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:93
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ SCH_SYMBOL_T
Definition: typeinfo.h:146
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:99
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:106
@ 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:103
@ LIB_TEXTBOX_T
Definition: typeinfo.h:191
@ SCH_FIELD_T
Definition: typeinfo.h:145
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:144
@ SCH_LABEL_T
Definition: typeinfo.h:141
@ SCH_SHEET_T
Definition: typeinfo.h:148
@ LIB_SHAPE_T
Definition: typeinfo.h:189
@ SCH_MARKER_T
Definition: typeinfo.h:131
@ PCB_ITEM_LIST_T
class BOARD_ITEM_LIST, a list of board items
Definition: typeinfo.h:104
@ GERBER_DRAW_ITEM_T
Definition: typeinfo.h:204
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:143
@ 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:95
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:135
@ LIB_PIN_T
Definition: typeinfo.h:192
@ SCH_SCREEN_T
Definition: typeinfo.h:176
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:102
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:147
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:97
@ SCH_TEXT_T
Definition: typeinfo.h:140
@ LIB_FIELD_T
Definition: typeinfo.h:198
@ PCB_BITMAP_T
class PCB_BITMAP, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ GERBER_IMAGE_T
Definition: typeinfo.h:205
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:134
@ GERBER_LAYOUT_T
Definition: typeinfo.h:203
@ SCREEN_T
not really an item, used to identify a screen
Definition: typeinfo.h:83
@ SCH_BITMAP_T
Definition: typeinfo.h:138
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:94
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:105
@ SCH_TEXTBOX_T
Definition: typeinfo.h:139
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:92
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:100
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:142
@ SCH_JUNCTION_T
Definition: typeinfo.h:132
@ SCH_PIN_T
Definition: typeinfo.h:149
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588