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
74 break;
75
76 default:
78 break;
79 }
80
81 SetLayer( ToLAYER_ID( aLayer ) );
82 }
83 }
84
85 m_Pos = aPosition;
86}
87
88
89/* destructor */
91{
92 if( m_rcItem )
93 m_rcItem->SetParent( nullptr );
94}
95
96
98{
99 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER
100 || m_rcItem->GetErrorCode() == DRCE_GENERIC_WARNING
101 || m_rcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
102 {
103 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
104 m_rcItem->GetSettingsKey(),
105 m_Pos.x,
106 m_Pos.y,
107 m_rcItem->GetMainItemID().AsString(),
108 LayerName( m_layer ) );
109 }
110 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
111 {
112 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s" ),
113 m_rcItem->GetSettingsKey(),
114 m_Pos.x,
115 m_Pos.y,
116 m_rcItem->GetMainItemID().AsString(),
117 m_rcItem->GetAuxItemID().AsString(),
118 LayerName( m_layer ) );
119 }
120 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
121 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
122 {
123 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
124 m_rcItem->GetSettingsKey(),
125 m_Pos.x,
126 m_Pos.y,
127 // Drawing sheet KIIDs aren't preserved between runs
128 wxEmptyString,
129 wxEmptyString );
130 }
131 else
132 {
133 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
134 m_rcItem->GetSettingsKey(),
135 m_Pos.x,
136 m_Pos.y,
137 m_rcItem->GetMainItemID().AsString(),
138 m_rcItem->GetAuxItemID().AsString() );
139 }
140}
141
142
144{
145 auto getMarkerLayer =
146 []( const wxString& layerName ) -> int
147 {
148 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
149 {
150 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
151 return layer;
152 }
153
154 return F_Cu;
155 };
156
157 wxArrayString props = wxSplit( data, '|' );
158 int markerLayer = F_Cu;
159 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
160 (int) strtol( props[2].c_str(), nullptr, 10 ) );
161
162 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
163
164 if( !drcItem )
165 return nullptr;
166
167 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER
168 || drcItem->GetErrorCode() == DRCE_GENERIC_WARNING
169 || drcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
170 {
171 drcItem->SetItems( KIID( props[3] ) );
172 markerLayer = getMarkerLayer( props[4] );
173 }
174 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
175 {
176 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
177
178 // Pre-7.0 versions didn't differentiate between layers
179 if( props.size() == 6 )
180 markerLayer = getMarkerLayer( props[5] );
181 }
182 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
183 && props[3].IsEmpty() && props[4].IsEmpty() )
184 {
185 // Note: caller must load our item pointer with the drawing sheet proxy item
186 markerLayer = LAYER_DRAWINGSHEET;
187 }
188 else
189 {
190 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
191 }
192
193 return new PCB_MARKER( drcItem, markerPos, markerLayer );
194}
195
196
197void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
198{
199 aList.emplace_back( _( "Type" ), _( "Marker" ) );
200 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
201
202 switch( GetSeverity() )
203 {
205 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
206 break;
208 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
209 break;
211 aList.emplace_back( _( "Severity" ), _( "Error" ) );
212 break;
213 default:
214 break;
215 }
216
218 {
219 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
220 }
221 else
222 {
223 wxString mainText;
224 wxString auxText;
225 EDA_ITEM* mainItem = nullptr;
226 EDA_ITEM* auxItem = nullptr;
227
228 if( m_rcItem->GetMainItemID() != niluuid )
229 mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
230
231 if( m_rcItem->GetAuxItemID() != niluuid )
232 auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
233
234 if( mainItem )
235 mainText = mainItem->GetItemDescription( aFrame, true );
236
237 if( auxItem )
238 auxText = auxItem->GetItemDescription( aFrame, true );
239
240 aList.emplace_back( mainText, auxText );
241 }
242
243 if( IsExcluded() )
244 aList.emplace_back( _( "Excluded" ), m_comment );
245}
246
247
248void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
249{
250 // Marker geometry isn't user-editable
251}
252
253
254void PCB_MARKER::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
255{
256 // Marker geometry isn't user-editable
257}
258
259
260std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
261{
262 // Markers do not participate in the board geometry space, and therefore have no
263 // effectiven shape.
264 return std::make_shared<SHAPE_NULL>();
265}
266
267
268wxString PCB_MARKER::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
269{
270 return wxString::Format( _( "Marker (%s)" ),
271 aFull ? m_rcItem->GetErrorMessage() : m_rcItem->GetErrorText() );
272}
273
274
276{
277 return BITMAPS::drc;
278}
279
280
282{
283 if( IsExcluded() )
285
286 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
287
288 if( item->GetErrorCode() == DRCE_GENERIC_WARNING )
290 else if( item->GetErrorCode() == DRCE_GENERIC_ERROR )
291 return RPT_SEVERITY_ERROR;
292
293 DRC_RULE* rule = item->GetViolatingRule();
294
295 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
296 return rule->m_Severity;
297
298 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
299}
300
301
302std::vector<int> PCB_MARKER::ViewGetLayers() const
303{
305 {
306 return {};
307 }
308
309 std::vector<int> layers{ 0, LAYER_MARKER_SHADOWS, LAYER_DRC_SHAPE1, LAYER_DRC_SHAPE2 };
310
311 switch( GetSeverity() )
312 {
313 default:
314 case SEVERITY::RPT_SEVERITY_ERROR: layers[0] = LAYER_DRC_ERROR; break;
315 case SEVERITY::RPT_SEVERITY_WARNING: layers[0] = LAYER_DRC_WARNING; break;
316 case SEVERITY::RPT_SEVERITY_EXCLUSION: layers[0] = LAYER_DRC_EXCLUSION; break;
317 }
318
319 return layers;
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{
351
352 for( auto& s : m_shapes1 )
353 box.Merge( s.GetBoundingBox() );
354
355 return box;
356}
357
358
360{
361 return GetBoundingBox();
362}
363
364
365static struct PCB_MARKER_DESC
366{
368 {
375
376 // Markers cannot be locked and have no user-accessible layer control
378 _HKI( "Layer" ),
379 []( INSPECTABLE* aItem ) { return false; } );
381 _HKI( "Locked" ),
382 []( INSPECTABLE* aItem ) { return false; } );
383 }
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:436
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
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:895
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:658
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:152
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:382
SEVERITY m_Severity
Definition: drc_rule.h:122
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:111
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:145
VECTOR2I m_Pos
position of the marker
Definition: marker_base.h:140
@ 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:146
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:197
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:260
std::vector< PCB_SHAPE > m_shapes1
Definition: pcb_marker.h:155
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:275
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:359
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
Definition: pcb_marker.cpp:302
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:281
static PCB_MARKER * DeserializeFromString(const wxString &data)
Definition: pcb_marker.cpp:143
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_marker.cpp:254
wxString SerializeToString() const
Definition: pcb_marker.cpp:97
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:268
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:248
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_FOOTPRINT_FILTERS
Definition: drc_item.h:79
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:49
@ DRCE_GENERIC_ERROR
Definition: drc_item.h:90
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:92
@ DRCE_UNRESOLVED_VARIABLE
Definition: drc_item.h:87
@ DRCE_DUPLICATE_FOOTPRINT
Definition: drc_item.h:75
@ DRCE_EXTRA_FOOTPRINT
Definition: drc_item.h:76
@ DRCE_NET_CONFLICT
Definition: drc_item.h:77
@ DRCE_MISSING_FOOTPRINT
Definition: drc_item.h:74
@ DRCE_GENERIC_WARNING
Definition: drc_item.h:89
@ DRCE_SCHEMATIC_PARITY
Definition: drc_item.h:78
#define _(s)
KIID niluuid(0)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:31
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:147
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:191
@ LAYER_DRC_SHAPE1
Custom shape for DRC marker.
Definition: layer_ids.h:245
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:218
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:237
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:236
@ LAYER_DRC_SHAPE2
Custom shape for DRC marker.
Definition: layer_ids.h:246
@ LAYER_MARKER_SHADOWS
shadows for drc markers
Definition: layer_ids.h:238
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:217
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:135
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:820
FLIP_DIRECTION
Definition: mirror.h:27
#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:1060
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.