KiCad PCB EDA Suite
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
72 break;
73
74 default:
76 break;
77 }
78
79 SetLayer( ToLAYER_ID( aLayer ) );
80 }
81 }
82
83 m_Pos = aPosition;
84}
85
86
87/* destructor */
89{
90 if( m_rcItem )
91 m_rcItem->SetParent( nullptr );
92}
93
94
95wxString PCB_MARKER::Serialize() const
96{
97 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
98 {
99 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
100 m_rcItem->GetSettingsKey(),
101 m_Pos.x,
102 m_Pos.y,
103 m_rcItem->GetMainItemID().AsString(),
104 LayerName( m_layer ) );
105 }
106 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
107 {
108 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s" ),
109 m_rcItem->GetSettingsKey(),
110 m_Pos.x,
111 m_Pos.y,
112 m_rcItem->GetMainItemID().AsString(),
113 m_rcItem->GetAuxItemID().AsString(),
114 LayerName( m_layer ) );
115 }
116 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
117 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
118 {
119 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
120 m_rcItem->GetSettingsKey(),
121 m_Pos.x,
122 m_Pos.y,
123 // Drawing sheet KIIDs aren't preserved between runs
124 wxEmptyString,
125 wxEmptyString );
126 }
127 else
128 {
129 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
130 m_rcItem->GetSettingsKey(),
131 m_Pos.x,
132 m_Pos.y,
133 m_rcItem->GetMainItemID().AsString(),
134 m_rcItem->GetAuxItemID().AsString() );
135 }
136}
137
138
139PCB_MARKER* PCB_MARKER::Deserialize( const wxString& data )
140{
141 auto getMarkerLayer =
142 []( const wxString& layerName ) -> int
143 {
144 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
145 {
146 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
147 return layer;
148 }
149
150 return F_Cu;
151 };
152
153 wxArrayString props = wxSplit( data, '|' );
154 int markerLayer = F_Cu;
155 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
156 (int) strtol( props[2].c_str(), nullptr, 10 ) );
157
158 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
159
160 if( !drcItem )
161 return nullptr;
162
163 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER )
164 {
165 drcItem->SetItems( KIID( props[3] ) );
166 markerLayer = getMarkerLayer( props[4] );
167 }
168 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
169 {
170 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
171
172 // Pre-7.0 versions didn't differentiate between layers
173 if( props.size() == 6 )
174 markerLayer = getMarkerLayer( props[5] );
175 }
176 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
177 && props[3].IsEmpty() && props[4].IsEmpty() )
178 {
179 // Note: caller must load our item pointer with the drawing sheet proxy item
180 markerLayer = LAYER_DRAWINGSHEET;
181 }
182 else
183 {
184 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
185 }
186
187 return new PCB_MARKER( drcItem, markerPos, markerLayer );
188}
189
190
191void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
192{
193 aList.emplace_back( _( "Type" ), _( "Marker" ) );
194 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
195
196 switch( GetSeverity() )
197 {
199 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
200 break;
202 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
203 break;
205 aList.emplace_back( _( "Severity" ), _( "Error" ) );
206 break;
207 default:
208 break;
209 }
210
212 {
213 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
214 }
215 else
216 {
217 wxString mainText;
218 wxString auxText;
219 EDA_ITEM* mainItem = nullptr;
220 EDA_ITEM* auxItem = nullptr;
221
222 if( m_rcItem->GetMainItemID() != niluuid )
223 mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
224
225 if( m_rcItem->GetAuxItemID() != niluuid )
226 auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
227
228 if( mainItem )
229 mainText = mainItem->GetSelectMenuText( aFrame );
230
231 if( auxItem )
232 auxText = auxItem->GetSelectMenuText( aFrame );
233
234 aList.emplace_back( mainText, auxText );
235 }
236}
237
238
239void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
240{
241 // Marker geometry isn't user-editable
242}
243
244
245void PCB_MARKER::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
246{
247 // Marker geometry isn't user-editable
248}
249
250
251std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
252{
253 // Markers do not participate in the board geometry space, and therefore have no
254 // effectiven shape.
255 return std::make_shared<SHAPE_NULL>();
256}
257
258
259wxString PCB_MARKER::GetSelectMenuText( UNITS_PROVIDER* aUnitsProvider ) const
260{
261 // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
262 // for menu duty.
263 return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
264}
265
266
268{
269 return BITMAPS::drc;
270}
271
272
274{
275 if( IsExcluded() )
277
278 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
279 DRC_RULE* rule = item->GetViolatingRule();
280
281 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
282 return rule->m_Severity;
283
284 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
285}
286
287
288void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
289{
291 {
292 aCount = 0;
293 return;
294 }
295
296 aCount = 2;
297
298 aLayers[1] = LAYER_MARKER_SHADOWS;
299
300 switch( GetSeverity() )
301 {
302 default:
303 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
304 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
306 }
307}
308
309
311{
312 switch( GetSeverity() )
313 {
314 default:
318 }
319}
320
321
323{
324 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
325 return colors->GetColor( GetColorLayer() );
326}
327
328
329void PCB_MARKER::SetZoom( double aZoomFactor )
330{
331 SetMarkerScale( SCALING_FACTOR * aZoomFactor );
332}
333
334
336{
337 return GetBoundingBoxMarker();
338}
339
340
342{
343 return GetBoundingBox();
344}
345
346
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:58
PCB_LAYER_ID m_layer
Definition: board_item.h:329
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:214
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:43
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:643
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:128
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:325
SEVERITY m_Severity
Definition: drc_rule.h:115
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 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
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Definition: kiid.h:48
void SetMarkerType(enum TYPEMARKER aMarkerType)
Accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:94
bool IsExcluded() const
Definition: marker_base.h:97
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:95
VECTOR2I m_Pos
position of the marker
Definition: marker_base.h:128
@ MARKER_DRAWING_SHEET
Definition: marker_base.h:55
void SetMarkerScale(int aScale)
Definition: marker_base.h:69
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:133
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:191
wxString Serialize() const
Definition: pcb_marker.cpp:95
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_marker.cpp:245
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:251
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:267
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:341
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_marker.cpp:335
wxString GetSelectMenuText(UNITS_PROVIDER *aUnitsProvider) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: pcb_marker.cpp:259
SEVERITY GetSeverity() const override
Definition: pcb_marker.cpp:273
static PCB_MARKER * Deserialize(const wxString &data)
Definition: pcb_marker.cpp:139
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:310
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:322
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:288
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:239
void SetZoom(double aZoomFactor)
Definition: pcb_marker.cpp:329
int GetErrorCode() const
Definition: rc_item.h:136
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
@ DRCE_STARVED_THERMAL
Definition: drc_item.h:48
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:84
@ DRCE_UNRESOLVED_VARIABLE
Definition: drc_item.h:81
@ 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
#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:147
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:190
@ LAYER_DRAWINGSHEET
drawingsheet frame and titleblock
Definition: layer_ids.h:217
@ LAYER_DRC_EXCLUSION
layer for drc markers which have been individually excluded
Definition: layer_ids.h:236
@ LAYER_DRC_WARNING
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:235
@ LAYER_MARKER_SHADOWS
shadows for drc markers
Definition: layer_ids.h:237
@ LAYER_DRC_ERROR
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:216
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ 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:932
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: pcb_marker.cpp:43
see class PGM_BASE
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
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:104
Functions to provide common constants and other functions to assist in making a consistent UI.