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 The 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
27#include <bitmaps.h>
28#include <base_units.h>
29#include <eda_draw_frame.h>
30#include <board.h>
32#include <pcb_marker.h>
33#include <layer_ids.h>
36#include <geometry/shape_null.h>
37#include <widgets/ui_common.h>
38#include <pgm_base.h>
39#include <drc/drc_item.h>
40#include <trigo.h>
41
42
44#define SCALING_FACTOR pcbIUScale.mmToIU( 0.1625 )
45
46
47
48PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const VECTOR2I& aPosition, int aLayer ) :
49 BOARD_ITEM( nullptr, PCB_MARKER_T, F_Cu ), // parent set during BOARD::Add()
51{
52 if( m_rcItem )
53 {
54 m_rcItem->SetParent( this );
55
56 if( aLayer == LAYER_DRAWINGSHEET )
57 {
59 }
60 else
61 {
62 switch( m_rcItem->GetErrorCode() )
63 {
66 break;
67
75 break;
76
77 default:
79 break;
80 }
81
82 SetLayer( ToLAYER_ID( aLayer ) );
83 }
84 }
85
86 m_Pos = aPosition;
87}
88
89
90/* destructor */
92{
93 if( m_rcItem )
94 m_rcItem->SetParent( nullptr );
95}
96
97
99{
100 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER
101 || m_rcItem->GetErrorCode() == DRCE_GENERIC_WARNING
102 || m_rcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
103 {
104 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
105 m_rcItem->GetSettingsKey(),
106 m_Pos.x,
107 m_Pos.y,
108 m_rcItem->GetMainItemID().AsString(),
109 LayerName( m_layer ) );
110 }
111 else if( m_rcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
112 {
113 PCB_LAYER_ID layer = m_layer;
114
115 if( m_layer == UNDEFINED_LAYER )
116 layer = F_Cu;
117
118 return wxString::Format( wxT( "%s|%d|%d|%s|%d|%s|%s" ),
119 m_rcItem->GetSettingsKey(),
120 m_Pos.x,
121 m_Pos.y,
122 LayerName( layer ),
124 m_rcItem->GetMainItemID().AsString(),
125 m_rcItem->GetAuxItemID().AsString() );
126 }
127 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
128 {
129 return wxString::Format( wxT( "%s|%d|%d|%s|%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 LayerName( m_layer ) );
136 }
137 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
138 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
139 {
140 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
141 m_rcItem->GetSettingsKey(),
142 m_Pos.x,
143 m_Pos.y,
144 // Drawing sheet KIIDs aren't preserved between runs
145 wxEmptyString,
146 wxEmptyString );
147 }
148 else
149 {
150 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
151 m_rcItem->GetSettingsKey(),
152 m_Pos.x,
153 m_Pos.y,
154 m_rcItem->GetMainItemID().AsString(),
155 m_rcItem->GetAuxItemID().AsString() );
156 }
157}
158
159
161{
162 auto getMarkerLayer =
163 []( const wxString& layerName ) -> int
164 {
165 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
166 {
167 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
168 return layer;
169 }
170
171 return F_Cu;
172 };
173
174 wxArrayString props = wxSplit( data, '|' );
175 int markerLayer = F_Cu;
176 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
177 (int) strtol( props[2].c_str(), nullptr, 10 ) );
178
179 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
180
181 if( !drcItem )
182 return nullptr;
183
184 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER
185 || drcItem->GetErrorCode() == DRCE_GENERIC_WARNING
186 || drcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
187 {
188 drcItem->SetItems( KIID( props[3] ) );
189 markerLayer = getMarkerLayer( props[4] );
190 }
191 else if( drcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
192 {
193 // Pre-9.0.4 versions didn't have KIIDs as last two properties to allow sorting stability
194 if( props.size() < 6 )
195 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
196 else
197 drcItem->SetItems( KIID( props[5] ), KIID( props[6] ) );
198 }
199 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
200 {
201 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
202
203 // Pre-7.0 versions didn't differentiate between layers
204 if( props.size() == 6 )
205 markerLayer = getMarkerLayer( props[5] );
206 }
207 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
208 && props[3].IsEmpty() && props[4].IsEmpty() )
209 {
210 // Note: caller must load our item pointer with the drawing sheet proxy item
211 markerLayer = LAYER_DRAWINGSHEET;
212 }
213 else
214 {
215 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
216 }
217
218 return new PCB_MARKER( drcItem, markerPos, markerLayer );
219}
220
221
222void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
223{
224 aList.emplace_back( _( "Type" ), _( "Marker" ) );
225 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
226
227 switch( GetSeverity() )
228 {
230 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
231 break;
233 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
234 break;
236 aList.emplace_back( _( "Severity" ), _( "Error" ) );
237 break;
238 default:
239 break;
240 }
241
243 {
244 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
245 }
246 else
247 {
248 wxString mainText;
249 wxString auxText;
250 EDA_ITEM* mainItem = aFrame->ResolveItem( m_rcItem->GetMainItemID() );
251 EDA_ITEM* auxItem = aFrame->ResolveItem( m_rcItem->GetAuxItemID() );
252
253 if( mainItem )
254 mainText = mainItem->GetItemDescription( aFrame, true );
255
256 if( auxItem )
257 auxText = auxItem->GetItemDescription( aFrame, true );
258
259 aList.emplace_back( mainText, auxText );
260 }
261
262 if( IsExcluded() )
263 aList.emplace_back( _( "Excluded" ), m_comment );
264}
265
266
267void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
268{
269 // Marker geometry isn't user-editable
270}
271
272
273void PCB_MARKER::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
274{
275 // Marker geometry isn't user-editable
276}
277
278
279std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
280{
281 // Markers do not participate in the board geometry space, and therefore have no effective shape.
282 return std::make_shared<SHAPE_NULL>();
283}
284
285
287 int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth ) const
288{
289 // Markers do not participate in the board geometry space, and therefore have no shape.
290};
291
292
293wxString PCB_MARKER::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
294{
295 return wxString::Format( _( "Marker (%s)" ), aFull ? m_rcItem->GetErrorMessage()
296 : m_rcItem->GetErrorText() );
297}
298
299
301{
302 return BITMAPS::drc;
303}
304
305
307{
308 if( IsExcluded() )
310
311 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
312
313 if( item->GetErrorCode() == DRCE_GENERIC_WARNING )
315 else if( item->GetErrorCode() == DRCE_GENERIC_ERROR )
316 return RPT_SEVERITY_ERROR;
317
318 DRC_RULE* rule = item->GetViolatingRule();
319
320 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
321 return rule->m_Severity;
322
323 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
324}
325
326
327std::vector<int> PCB_MARKER::ViewGetLayers() const
328{
330 return {};
331
332 std::vector<int> layers{ 0, LAYER_MARKER_SHADOWS, LAYER_DRC_SHAPES };
333
334 switch( GetSeverity() )
335 {
336 default:
337 case SEVERITY::RPT_SEVERITY_ERROR: layers[0] = LAYER_DRC_ERROR; break;
338 case SEVERITY::RPT_SEVERITY_WARNING: layers[0] = LAYER_DRC_WARNING; break;
340 }
341
342 return layers;
343}
344
345
356
357
359{
360 return ::GetColorSettings( DEFAULT_THEME )->GetColor( GetColorLayer() );
361}
362
363
364void PCB_MARKER::SetZoom( double aZoomFactor ) const
365{
366 SetMarkerScale( SCALING_FACTOR * aZoomFactor );
367}
368
369
371{
373
374 for( const PCB_SHAPE& s : m_shapes )
375 box.Merge( s.GetBoundingBox() );
376
377 return box;
378}
379
380
382{
383 return GetBoundingBox();
384}
385
386
387static struct PCB_MARKER_DESC
388{
390 {
397
398 // Markers cannot be locked and have no user-accessible layer control
399 propMgr.Mask( TYPE_HASH( PCB_MARKER ), TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) );
400 propMgr.Mask( TYPE_HASH( PCB_MARKER ), TYPE_HASH( BOARD_ITEM ), _HKI( "Locked" ) );
401 }
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:81
PCB_LAYER_ID m_layer
Definition board_item.h:453
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:280
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1040
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
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:381
SEVERITY m_Severity
Definition drc_rule.h:127
The base class for create windows for drawing purpose.
virtual EDA_ITEM * ResolveItem(const KIID &aId, bool aAllowNullptrReturn=false) const
Fetch an item by KIID.
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:144
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:39
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
Definition kiid.h:49
Marker are mainly used to show a DRC or ERC error or warning.
Definition marker_base.h:49
void SetMarkerScale(int aScale) const
Definition marker_base.h:70
bool IsExcluded() const
Definition marker_base.h:93
wxString m_comment
User supplied comment.
VECTOR2I m_Pos
Position of the marker.
@ MARKER_DRAWING_SHEET
Definition marker_base.h:56
void SetMarkerType(enum MARKER_T aMarkerType)
Accessors to set/get marker type (DRC, ERC, or other)
Definition marker_base.h:90
std::shared_ptr< RC_ITEM > m_rcItem
enum MARKER_T GetMarkerType() const
Definition marker_base.h:91
MARKER_BASE(int aScalingFactor, std::shared_ptr< RC_ITEM > aItem, MARKER_T aType=MARKER_UNSPEC)
BOX2I GetBoundingBoxMarker() const
Return the orthogonal, bounding box of this object for display purposes.
void SetZoom(double aZoomFactor) const
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.
std::vector< PCB_SHAPE > m_shapes
Definition pcb_marker.h:160
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth) const override
Convert the item shape to a closed polygon.
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.
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
std::vector< int > ViewGetLayers() const override
Return the all the layers within the VIEW the object is painted on.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
SEVERITY GetSeverity() const override
static PCB_MARKER * DeserializeFromString(const wxString &data)
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
wxString SerializeToString() const
GAL_LAYER_ID GetColorLayer() const
PCB_MARKER(std::shared_ptr< RC_ITEM > aItem, const VECTOR2I &aPos, int aLayer=F_Cu)
KIGFX::COLOR4D getColor() const override
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
int GetErrorCode() const
Definition rc_item.h:154
Represent a set of closed polygons.
@ 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)
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:184
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition layer_ids.h:228
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:277
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:303
@ LAYER_DRC_SHAPES
Custom shapes for DRC markers.
Definition layer_ids.h:314
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition layer_ids.h:300
@ LAYER_MARKER_SHADOWS
Shadows for DRC markers.
Definition layer_ids.h:304
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition layer_ids.h:276
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
@ F_Cu
Definition layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
FLIP_DIRECTION
Definition mirror.h:27
#define _HKI(x)
Definition page_info.cpp:44
static struct PCB_MARKER_DESC _PCB_MARKER_DESC
see class PGM_BASE
#define TYPE_HASH(x)
Definition property.h:73
#define REGISTER_TYPE(x)
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:
#define DEFAULT_THEME
@ 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.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695