KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_marker.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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <bitmaps.h>
27#include <base_units.h>
28#include <eda_draw_frame.h>
29#include <board.h>
31#include <pcb_marker.h>
32#include <layer_ids.h>
35#include <geometry/shape_null.h>
36#include <widgets/ui_common.h>
37#include <pgm_base.h>
38#include <drc/drc_item.h>
39#include <trigo.h>
40
41
43#define SCALING_FACTOR pcbIUScale.mmToIU( 0.1625 )
44
45
46
47PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const VECTOR2I& aPosition, int aLayer ) :
48 BOARD_ITEM( nullptr, PCB_MARKER_T, F_Cu ), // parent set during BOARD::Add()
50{
51 if( m_rcItem )
52 {
53 m_rcItem->SetParent( this );
54
55 if( aLayer == LAYER_DRAWINGSHEET )
56 {
58 }
59 else
60 {
61 switch( m_rcItem->GetErrorCode() )
62 {
65 break;
66
73 break;
74
75 default:
77 break;
78 }
79
80 SetLayer( ToLAYER_ID( aLayer ) );
81 }
82 }
83
84 m_Pos = aPosition;
85}
86
87
88/* destructor */
90{
91 if( m_rcItem )
92 m_rcItem->SetParent( nullptr );
93}
94
95
96wxString PCB_MARKER::Serialize() const
97{
98 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
99 {
100 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
101 m_rcItem->GetSettingsKey(),
102 m_Pos.x,
103 m_Pos.y,
104 m_rcItem->GetMainItemID().AsString(),
105 LayerName( m_layer ) );
106 }
107 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
108 {
109 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s" ),
110 m_rcItem->GetSettingsKey(),
111 m_Pos.x,
112 m_Pos.y,
113 m_rcItem->GetMainItemID().AsString(),
114 m_rcItem->GetAuxItemID().AsString(),
115 LayerName( m_layer ) );
116 }
117 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
118 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
119 {
120 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
121 m_rcItem->GetSettingsKey(),
122 m_Pos.x,
123 m_Pos.y,
124 // Drawing sheet KIIDs aren't preserved between runs
125 wxEmptyString,
126 wxEmptyString );
127 }
128 else
129 {
130 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
131 m_rcItem->GetSettingsKey(),
132 m_Pos.x,
133 m_Pos.y,
134 m_rcItem->GetMainItemID().AsString(),
135 m_rcItem->GetAuxItemID().AsString() );
136 }
137}
138
139
140PCB_MARKER* PCB_MARKER::Deserialize( const wxString& data )
141{
142 auto getMarkerLayer =
143 []( const wxString& layerName ) -> int
144 {
145 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
146 {
147 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
148 return layer;
149 }
150
151 return F_Cu;
152 };
153
154 wxArrayString props = wxSplit( data, '|' );
155 int markerLayer = F_Cu;
156 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
157 (int) strtol( props[2].c_str(), nullptr, 10 ) );
158
159 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
160
161 if( !drcItem )
162 return nullptr;
163
164 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
165 {
166 drcItem->SetItems( KIID( props[3] ) );
167 markerLayer = getMarkerLayer( props[4] );
168 }
169 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
170 {
171 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
172
173 // Pre-7.0 versions didn't differentiate between layers
174 if( props.size() == 6 )
175 markerLayer = getMarkerLayer( props[5] );
176 }
177 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
178 && props[3].IsEmpty() && props[4].IsEmpty() )
179 {
180 // Note: caller must load our item pointer with the drawing sheet proxy item
181 markerLayer = LAYER_DRAWINGSHEET;
182 }
183 else
184 {
185 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
186 }
187
188 return new PCB_MARKER( drcItem, markerPos, markerLayer );
189}
190
191
192void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
193{
194 aList.emplace_back( _( "Type" ), _( "Marker" ) );
195 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
196
197 switch( GetSeverity() )
198 {
200 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
201 break;
203 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
204 break;
206 aList.emplace_back( _( "Severity" ), _( "Error" ) );
207 break;
208 default:
209 break;
210 }
211
213 {
214 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
215 }
216 else
217 {
218 wxString mainText;
219 wxString auxText;
220 EDA_ITEM* mainItem = nullptr;
221 EDA_ITEM* auxItem = nullptr;
222
223 if( m_rcItem->GetMainItemID() != niluuid )
224 mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
225
226 if( m_rcItem->GetAuxItemID() != niluuid )
227 auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
228
229 if( mainItem )
230 mainText = mainItem->GetItemDescription( aFrame );
231
232 if( auxItem )
233 auxText = auxItem->GetItemDescription( aFrame );
234
235 aList.emplace_back( mainText, auxText );
236 }
237
238 if( IsExcluded() )
239 aList.emplace_back( _( "Excluded" ), m_comment );
240}
241
242
243void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
244{
245 // Marker geometry isn't user-editable
246}
247
248
249void PCB_MARKER::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
250{
251 // Marker geometry isn't user-editable
252}
253
254
255std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
256{
257 // Markers do not participate in the board geometry space, and therefore have no
258 // effectiven shape.
259 return std::make_shared<SHAPE_NULL>();
260}
261
262
263wxString PCB_MARKER::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
264{
265 // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
266 // for menu duty.
267 return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
268}
269
270
272{
273 return BITMAPS::drc;
274}
275
276
278{
279 if( IsExcluded() )
281
282 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
283 DRC_RULE* rule = item->GetViolatingRule();
284
285 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
286 return rule->m_Severity;
287
288 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
289}
290
291
292void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
293{
295 {
296 aCount = 0;
297 return;
298 }
299
300 aCount = 2;
301
302 aLayers[1] = LAYER_MARKER_SHADOWS;
303
304 switch( GetSeverity() )
305 {
306 default:
307 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
308 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
309 case SEVERITY::RPT_SEVERITY_EXCLUSION: aLayers[0] = LAYER_DRC_EXCLUSION; break;
310 }
311}
312
313
315{
316 switch( GetSeverity() )
317 {
318 default:
319 case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_DRC_ERROR;
320 case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_DRC_WARNING;
321 case SEVERITY::RPT_SEVERITY_EXCLUSION: return LAYER_DRC_EXCLUSION;
322 }
323}
324
325
327{
328 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
329 return colors->GetColor( GetColorLayer() );
330}
331
332
333void PCB_MARKER::SetZoom( double aZoomFactor )
334{
335 SetMarkerScale( SCALING_FACTOR * aZoomFactor );
336}
337
338
340{
341 return GetBoundingBoxMarker();
342}
343
344
346{
347 return GetBoundingBox();
348}
349
350
351static struct PCB_MARKER_DESC
352{
354 {
361
362 // Markers cannot be locked and have no user-accessible layer control
364 _HKI( "Layer" ),
365 []( INSPECTABLE* aItem ) { return false; } );
367 _HKI( "Locked" ),
368 []( INSPECTABLE* aItem ) { return false; } );
369 }
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
SEVERITY GetSeverity(int aDRCErrorCode)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
PCB_LAYER_ID m_layer
Definition: board_item.h:388
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:769
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
DRC_RULE * GetViolatingRule() const
Definition: drc_item.h:129
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:330
SEVERITY m_Severity
Definition: drc_rule.h:117
The base class for create windows for drawing purpose.
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:108
Class that other classes need to inherit from, in order to be inspectable.
Definition: inspectable.h:36
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Definition: kiid.h:49
bool IsExcluded() const
Definition: marker_base.h:98
wxString m_comment
Definition: marker_base.h:140
VECTOR2I m_Pos
position of the marker
Definition: marker_base.h:135
@ MARKER_DRAWING_SHEET
Definition: marker_base.h:56
void SetMarkerScale(int aScale)
Definition: marker_base.h:70
void SetMarkerType(enum MARKER_T aMarkerType)
Accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:95
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:141
enum MARKER_T GetMarkerType() const
Definition: marker_base.h:96
BOX2I GetBoundingBoxMarker() const
Return the orthogonal, bounding box of this object for display purposes.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: pcb_marker.cpp:192
wxString Serialize() const
Definition: pcb_marker.cpp:96
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_marker.cpp:249
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_marker.cpp:255
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:271
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:345
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_marker.cpp:339
SEVERITY GetSeverity() const override
Definition: pcb_marker.cpp:277
static PCB_MARKER * Deserialize(const wxString &data)
Definition: pcb_marker.cpp:140
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:314
PCB_MARKER(std::shared_ptr< RC_ITEM > aItem, const VECTOR2I &aPos, int aLayer=F_Cu)
Definition: pcb_marker.cpp:47
KIGFX::COLOR4D getColor() const override
Definition: pcb_marker.cpp:326
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: pcb_marker.cpp:263
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: pcb_marker.cpp:292
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:243
void SetZoom(double aZoomFactor)
Definition: pcb_marker.cpp:333
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
Definition: property_mgr.h:87
void OverrideAvailability(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName, std::function< bool(INSPECTABLE *)> aFunc)
Sets an override availability functor for a base class property of a given derived class.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
int GetErrorCode() const
Definition: rc_item.h:153
#define _HKI(x)
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:48
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:85
@ DRCE_UNRESOLVED_VARIABLE
Definition: drc_item.h:82
@ DRCE_DUPLICATE_FOOTPRINT
Definition: drc_item.h:71
@ DRCE_EXTRA_FOOTPRINT
Definition: drc_item.h:72
@ DRCE_NET_CONFLICT
Definition: drc_item.h:73
@ DRCE_MISSING_FOOTPRINT
Definition: drc_item.h:70
@ DRCE_SCHEMATIC_PARITY_ISSUES
Definition: drc_item.h:74
#define _(s)
KIID niluuid(0)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:148
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:193
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:220
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:239
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:238
@ LAYER_MARKER_SHADOWS
shadows for drc markers
Definition: layer_ids.h:240
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:219
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:138
@ F_Cu
Definition: layer_ids.h:65
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:1022
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: pcb_marker.cpp:43
static struct PCB_MARKER_DESC _PCB_MARKER_DESC
see class PGM_BASE
#define TYPE_HASH(x)
Definition: property.h:67
#define REGISTER_TYPE(x)
Definition: property_mgr.h:366
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: sch_marker.cpp:42
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:99
Functions to provide common constants and other functions to assist in making a consistent UI.