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
97{
98 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER
99 || m_rcItem->GetErrorCode() == DRCE_GENERIC_WARNING
100 || m_rcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
101 {
102 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
103 m_rcItem->GetSettingsKey(),
104 m_Pos.x,
105 m_Pos.y,
106 m_rcItem->GetMainItemID().AsString(),
107 LayerName( m_layer ) );
108 }
109 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
110 {
111 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s" ),
112 m_rcItem->GetSettingsKey(),
113 m_Pos.x,
114 m_Pos.y,
115 m_rcItem->GetMainItemID().AsString(),
116 m_rcItem->GetAuxItemID().AsString(),
117 LayerName( m_layer ) );
118 }
119 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
120 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
121 {
122 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
123 m_rcItem->GetSettingsKey(),
124 m_Pos.x,
125 m_Pos.y,
126 // Drawing sheet KIIDs aren't preserved between runs
127 wxEmptyString,
128 wxEmptyString );
129 }
130 else
131 {
132 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
133 m_rcItem->GetSettingsKey(),
134 m_Pos.x,
135 m_Pos.y,
136 m_rcItem->GetMainItemID().AsString(),
137 m_rcItem->GetAuxItemID().AsString() );
138 }
139}
140
141
143{
144 auto getMarkerLayer =
145 []( const wxString& layerName ) -> int
146 {
147 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
148 {
149 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
150 return layer;
151 }
152
153 return F_Cu;
154 };
155
156 wxArrayString props = wxSplit( data, '|' );
157 int markerLayer = F_Cu;
158 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
159 (int) strtol( props[2].c_str(), nullptr, 10 ) );
160
161 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
162
163 if( !drcItem )
164 return nullptr;
165
166 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER
167 || drcItem->GetErrorCode() == DRCE_GENERIC_WARNING
168 || drcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
169 {
170 drcItem->SetItems( KIID( props[3] ) );
171 markerLayer = getMarkerLayer( props[4] );
172 }
173 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
174 {
175 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
176
177 // Pre-7.0 versions didn't differentiate between layers
178 if( props.size() == 6 )
179 markerLayer = getMarkerLayer( props[5] );
180 }
181 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
182 && props[3].IsEmpty() && props[4].IsEmpty() )
183 {
184 // Note: caller must load our item pointer with the drawing sheet proxy item
185 markerLayer = LAYER_DRAWINGSHEET;
186 }
187 else
188 {
189 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
190 }
191
192 return new PCB_MARKER( drcItem, markerPos, markerLayer );
193}
194
195
196void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
197{
198 aList.emplace_back( _( "Type" ), _( "Marker" ) );
199 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
200
201 switch( GetSeverity() )
202 {
204 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
205 break;
207 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
208 break;
210 aList.emplace_back( _( "Severity" ), _( "Error" ) );
211 break;
212 default:
213 break;
214 }
215
217 {
218 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
219 }
220 else
221 {
222 wxString mainText;
223 wxString auxText;
224 EDA_ITEM* mainItem = nullptr;
225 EDA_ITEM* auxItem = nullptr;
226
227 if( m_rcItem->GetMainItemID() != niluuid )
228 mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
229
230 if( m_rcItem->GetAuxItemID() != niluuid )
231 auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
232
233 if( mainItem )
234 mainText = mainItem->GetItemDescription( aFrame, true );
235
236 if( auxItem )
237 auxText = auxItem->GetItemDescription( aFrame, true );
238
239 aList.emplace_back( mainText, auxText );
240 }
241
242 if( IsExcluded() )
243 aList.emplace_back( _( "Excluded" ), m_comment );
244}
245
246
247void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
248{
249 // Marker geometry isn't user-editable
250}
251
252
253void PCB_MARKER::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
254{
255 // Marker geometry isn't user-editable
256}
257
258
259std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
260{
261 // Markers do not participate in the board geometry space, and therefore have no
262 // effectiven shape.
263 return std::make_shared<SHAPE_NULL>();
264}
265
266
267wxString PCB_MARKER::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
268{
269 return wxString::Format( _( "Marker (%s)" ),
270 aFull ? m_rcItem->GetErrorMessage() : m_rcItem->GetErrorText() );
271}
272
273
275{
276 return BITMAPS::drc;
277}
278
279
281{
282 if( IsExcluded() )
284
285 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
286
287 if( item->GetErrorCode() == DRCE_GENERIC_WARNING )
289 else if( item->GetErrorCode() == DRCE_GENERIC_ERROR )
290 return RPT_SEVERITY_ERROR;
291
292 DRC_RULE* rule = item->GetViolatingRule();
293
294 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
295 return rule->m_Severity;
296
297 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
298}
299
300
301void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
302{
304 {
305 aCount = 0;
306 return;
307 }
308
309 aCount = 2;
310
311 aLayers[1] = LAYER_MARKER_SHADOWS;
312
313 switch( GetSeverity() )
314 {
315 default:
316 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
317 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
318 case SEVERITY::RPT_SEVERITY_EXCLUSION: aLayers[0] = LAYER_DRC_EXCLUSION; break;
319 }
320}
321
322
324{
325 switch( GetSeverity() )
326 {
327 default:
328 case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_DRC_ERROR;
329 case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_DRC_WARNING;
330 case SEVERITY::RPT_SEVERITY_EXCLUSION: return LAYER_DRC_EXCLUSION;
331 }
332}
333
334
336{
338 return colors->GetColor( GetColorLayer() );
339}
340
341
342void PCB_MARKER::SetZoom( double aZoomFactor )
343{
344 SetMarkerScale( SCALING_FACTOR * aZoomFactor );
345}
346
347
349{
350 return GetBoundingBoxMarker();
351}
352
353
355{
356 return GetBoundingBox();
357}
358
359
360static struct PCB_MARKER_DESC
361{
363 {
370
371 // Markers cannot be locked and have no user-accessible layer control
373 _HKI( "Layer" ),
374 []( INSPECTABLE* aItem ) { return false; } );
376 _HKI( "Locked" ),
377 []( INSPECTABLE* aItem ) { return false; } );
378 }
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:79
PCB_LAYER_ID m_layer
Definition: board_item.h:409
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:276
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:874
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:145
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:352
SEVERITY m_Severity
Definition: drc_rule.h:118
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:89
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) 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:196
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_marker.cpp:253
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:259
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:274
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:354
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_marker.cpp:348
SEVERITY GetSeverity() const override
Definition: pcb_marker.cpp:280
static PCB_MARKER * DeserializeFromString(const wxString &data)
Definition: pcb_marker.cpp:142
wxString SerializeToString() const
Definition: pcb_marker.cpp:96
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:323
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:335
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
Definition: pcb_marker.cpp:267
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:301
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:247
void SetZoom(double aZoomFactor)
Definition: pcb_marker.cpp:342
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
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
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
#define _HKI(x)
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:48
@ DRCE_GENERIC_ERROR
Definition: drc_item.h:86
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:88
@ DRCE_UNRESOLVED_VARIABLE
Definition: drc_item.h:83
@ DRCE_DUPLICATE_FOOTPRINT
Definition: drc_item.h:72
@ DRCE_EXTRA_FOOTPRINT
Definition: drc_item.h:73
@ DRCE_NET_CONFLICT
Definition: drc_item.h:74
@ DRCE_MISSING_FOOTPRINT
Definition: drc_item.h:71
@ DRCE_GENERIC_WARNING
Definition: drc_item.h:85
@ DRCE_SCHEMATIC_PARITY_ISSUES
Definition: drc_item.h:75
#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:149
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:194
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:221
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:240
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:239
@ LAYER_MARKER_SHADOWS
shadows for drc markers
Definition: layer_ids.h:241
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:220
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:875
#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
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define TYPE_HASH(x)
Definition: property.h:71
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
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
@ 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.