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 <drc/drc_rule.h>
41#include <trigo.h>
42#include <properties/property.h>
44
45
47#define SCALING_FACTOR pcbIUScale.mmToIU( 0.1625 )
48
49
50
51PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const VECTOR2I& aPosition, int aLayer ) :
52 BOARD_ITEM( nullptr, PCB_MARKER_T, F_Cu ), // parent set during BOARD::Add()
54 m_pathLength( 0 )
55{
56 if( m_rcItem )
57 {
58 m_rcItem->SetParent( this );
59
60 if( aLayer == LAYER_DRAWINGSHEET )
61 {
63 }
64 else
65 {
66 switch( m_rcItem->GetErrorCode() )
67 {
70 break;
71
80 break;
81
82 default:
84 break;
85 }
86
87 SetLayer( ToLAYER_ID( aLayer ) );
88 }
89 }
90
91 m_Pos = aPosition;
92}
93
94
95/* destructor */
97{
98 if( m_rcItem )
99 m_rcItem->SetParent( nullptr );
100}
101
102
104{
105 if( m_rcItem->GetErrorCode() == DRCE_COPPER_SLIVER
106 || m_rcItem->GetErrorCode() == DRCE_GENERIC_WARNING
107 || m_rcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
108 {
109 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
110 m_rcItem->GetSettingsKey(),
111 m_Pos.x,
112 m_Pos.y,
113 m_rcItem->GetMainItemID().AsString(),
114 LayerName( m_layer ) );
115 }
116 else if( m_rcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
117 {
118 PCB_LAYER_ID layer = m_layer;
119
120 if( m_layer == UNDEFINED_LAYER )
121 layer = F_Cu;
122
123 return wxString::Format( wxT( "%s|%d|%d|%s|%d|%s|%s" ),
124 m_rcItem->GetSettingsKey(),
125 m_Pos.x,
126 m_Pos.y,
127 LayerName( layer ),
129 m_rcItem->GetMainItemID().AsString(),
130 m_rcItem->GetAuxItemID().AsString() );
131 }
132 else if( m_rcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
133 {
134 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s" ),
135 m_rcItem->GetSettingsKey(),
136 m_Pos.x,
137 m_Pos.y,
138 m_rcItem->GetMainItemID().AsString(),
139 m_rcItem->GetAuxItemID().AsString(),
140 LayerName( m_layer ) );
141 }
142 else if( m_rcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
143 && m_rcItem->GetParent()->GetMarkerType() == MARKER_DRAWING_SHEET )
144 {
145 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
146 m_rcItem->GetSettingsKey(),
147 m_Pos.x,
148 m_Pos.y,
149 // Drawing sheet KIIDs aren't preserved between runs
150 wxEmptyString,
151 wxEmptyString );
152 }
153 else
154 {
155 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
156 m_rcItem->GetSettingsKey(),
157 m_Pos.x,
158 m_Pos.y,
159 m_rcItem->GetMainItemID().AsString(),
160 m_rcItem->GetAuxItemID().AsString() );
161 }
162}
163
164
166{
167 auto getMarkerLayer =
168 []( const wxString& layerName ) -> int
169 {
170 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
171 {
172 if( LayerName( ToLAYER_ID( layer ) ) == layerName )
173 return layer;
174 }
175
176 return F_Cu;
177 };
178
179 wxArrayString props = wxSplit( data, '|' );
180 int markerLayer = F_Cu;
181 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
182 (int) strtol( props[2].c_str(), nullptr, 10 ) );
183
184 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
185
186 if( !drcItem )
187 return nullptr;
188
189 if( drcItem->GetErrorCode() == DRCE_COPPER_SLIVER
190 || drcItem->GetErrorCode() == DRCE_GENERIC_WARNING
191 || drcItem->GetErrorCode() == DRCE_GENERIC_ERROR )
192 {
193 drcItem->SetItems( KIID( props[3] ) );
194 markerLayer = getMarkerLayer( props[4] );
195 }
196 else if( drcItem->GetErrorCode() == DRCE_UNCONNECTED_ITEMS )
197 {
198 // Pre-9.0.4 versions didn't have KIIDs as last two properties to allow sorting stability
199 if( props.size() < 6 )
200 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
201 else
202 drcItem->SetItems( KIID( props[5] ), KIID( props[6] ) );
203 }
204 else if( drcItem->GetErrorCode() == DRCE_STARVED_THERMAL )
205 {
206 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
207
208 // Pre-7.0 versions didn't differentiate between layers
209 if( props.size() == 6 )
210 markerLayer = getMarkerLayer( props[5] );
211 }
212 else if( drcItem->GetErrorCode() == DRCE_UNRESOLVED_VARIABLE
213 && props[3].IsEmpty() && props[4].IsEmpty() )
214 {
215 // Note: caller must load our item pointer with the drawing sheet proxy item
216 markerLayer = LAYER_DRAWINGSHEET;
217 }
218 else
219 {
220 drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
221 }
222
223 return new PCB_MARKER( drcItem, markerPos, markerLayer );
224}
225
226
227void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
228{
229 aList.emplace_back( _( "Type" ), _( "Marker" ) );
230 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage( true ) );
231
232 switch( GetSeverity() )
233 {
235 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
236 break;
238 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
239 break;
241 aList.emplace_back( _( "Severity" ), _( "Error" ) );
242 break;
243 default:
244 break;
245 }
246
248 {
249 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
250 }
251 else
252 {
253 wxString mainText;
254 wxString auxText;
255 EDA_ITEM* mainItem = aFrame->ResolveItem( m_rcItem->GetMainItemID() );
256 EDA_ITEM* auxItem = aFrame->ResolveItem( m_rcItem->GetAuxItemID() );
257
258 if( mainItem )
259 mainText = mainItem->GetItemDescription( aFrame, true );
260
261 if( auxItem )
262 auxText = auxItem->GetItemDescription( aFrame, true );
263
264 aList.emplace_back( mainText, auxText );
265 }
266
267 if( IsExcluded() )
268 aList.emplace_back( _( "Excluded" ), m_comment );
269}
270
271
272void PCB_MARKER::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
273{
274 // Marker geometry isn't user-editable
275}
276
277
278void PCB_MARKER::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
279{
280 // Marker geometry isn't user-editable
281}
282
283
284std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
285{
286 // Markers do not participate in the board geometry space, and therefore have no effective shape.
287 return std::make_shared<SHAPE_NULL>();
288}
289
290
292 int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth ) const
293{
294 // Markers do not participate in the board geometry space, and therefore have no shape.
295};
296
297
298wxString PCB_MARKER::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
299{
300 return wxString::Format( _( "Marker (%s)" ), aFull ? m_rcItem->GetErrorMessage( true )
301 : m_rcItem->GetErrorText( true ) );
302}
303
304
306{
307 return BITMAPS::drc;
308}
309
310
312{
313 if( IsExcluded() )
315
316 DRC_ITEM* item = static_cast<DRC_ITEM*>( m_rcItem.get() );
317
318 if( item->GetErrorCode() == DRCE_GENERIC_WARNING )
320 else if( item->GetErrorCode() == DRCE_GENERIC_ERROR )
321 return RPT_SEVERITY_ERROR;
322
323 DRC_RULE* rule = item->GetViolatingRule();
324
325 if( rule && rule->m_Severity != RPT_SEVERITY_UNDEFINED )
326 return rule->m_Severity;
327
328 return GetBoard()->GetDesignSettings().GetSeverity( item->GetErrorCode() );
329}
330
331
332std::vector<int> PCB_MARKER::ViewGetLayers() const
333{
335 return {};
336
337 std::vector<int> layers{ 0, LAYER_MARKER_SHADOWS, LAYER_DRC_SHAPES };
338
339 switch( GetSeverity() )
340 {
341 default:
342 case SEVERITY::RPT_SEVERITY_ERROR: layers[0] = LAYER_DRC_ERROR; break;
343 case SEVERITY::RPT_SEVERITY_WARNING: layers[0] = LAYER_DRC_WARNING; break;
345 }
346
347 return layers;
348}
349
350
361
362
364{
365 return ::GetColorSettings( DEFAULT_THEME )->GetColor( GetColorLayer() );
366}
367
368
369void PCB_MARKER::SetZoom( double aZoomFactor ) const
370{
371 SetMarkerScale( SCALING_FACTOR * aZoomFactor );
372}
373
374
375std::vector<PCB_SHAPE> PCB_MARKER::GetShapes() const
376{
377 STROKE_PARAMS hairline( 1.0 ); // Segments of width 1.0 will get drawn as lines by PCB_PAINTER
378 std::vector<PCB_SHAPE> pathShapes;
379
380 if( m_pathStart == m_pathEnd )
381 {
382 // Add a collision 'X'
383 const int len = KiROUND( 2.5 * MarkerScale() );
384
385 PCB_SHAPE s( nullptr, SHAPE_T::SEGMENT );
386 s.SetStroke( hairline );
387
388 s.SetStart( m_pathStart + VECTOR2I( -len, -len ) );
389 s.SetEnd( m_pathStart + VECTOR2I( len, len ) );
390 pathShapes.push_back( s );
391
392 s.SetStart( m_pathStart + VECTOR2I( -len, len ) );
393 s.SetEnd( m_pathStart + VECTOR2I( len, -len ) );
394 pathShapes.push_back( s );
395 }
396 else
397 {
398 // Add the path
399 for( PCB_SHAPE shape : m_pathShapes )
400 {
401 shape.SetStroke( hairline );
402 pathShapes.push_back( std::move( shape ) );
403 }
404
405 // Draw perpendicular begin/end stops
406 if( pathShapes.size() > 0 )
407 {
408 VECTOR2I V1 = pathShapes[0].GetStart() - pathShapes[0].GetEnd();
409 VECTOR2I V2 = pathShapes.back().GetStart() - pathShapes.back().GetEnd();
410 V1 = V1.Perpendicular().Resize( 2.5 * MarkerScale() );
411 V2 = V2.Perpendicular().Resize( 2.5 * MarkerScale() );
412
413 PCB_SHAPE s( nullptr, SHAPE_T::SEGMENT );
414 s.SetStroke( hairline );
415
416 s.SetStart( m_pathStart + V1 );
417 s.SetEnd( m_pathStart - V1 );
418 pathShapes.push_back( s );
419
420 s.SetStart( m_pathEnd + V2 );
421 s.SetEnd( m_pathEnd - V2 );
422 pathShapes.push_back( s );
423 }
424 }
425
426 // Add shaded areas
427 for( PCB_SHAPE shape : m_pathShapes )
428 {
429 shape.SetWidth( 10 * MarkerScale() );
430 pathShapes.push_back( std::move( shape ) );
431 }
432
433 return pathShapes;
434}
435
436
438{
440
441 for( const PCB_SHAPE& s : m_pathShapes )
442 box.Merge( s.GetBoundingBox() );
443
444 return box;
445}
446
447
449{
450 return GetBoundingBox();
451}
452
453
454static struct PCB_MARKER_DESC
455{
457 {
464
465 // Markers cannot be locked and have no user-accessible layer control
466 propMgr.Mask( TYPE_HASH( PCB_MARKER ), TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) );
467 propMgr.Mask( TYPE_HASH( PCB_MARKER ), TYPE_HASH( BOARD_ITEM ), _HKI( "Locked" ) );
468 }
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
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
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:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
PCB_LAYER_ID m_layer
Definition board_item.h:459
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:285
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:1082
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:160
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:400
SEVERITY m_Severity
Definition drc_rule.h:149
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:154
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
Definition eda_item.cpp:41
void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:178
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:220
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
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.
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition marker_base.h:69
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.
VECTOR2I m_pathEnd
Definition pcb_marker.h:168
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.
VECTOR2I m_pathStart
Definition pcb_marker.h:167
std::vector< PCB_SHAPE > GetShapes() const
std::vector< PCB_SHAPE > m_pathShapes
Definition pcb_marker.h:166
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.
int m_pathLength
Definition pcb_marker.h:169
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition pcb_shape.h:92
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:158
Represent a set of closed polygons.
Simple container to manage line stroke parameters.
constexpr VECTOR2< T > Perpendicular() const
Compute the perpendicular vector.
Definition vector2d.h:314
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:385
@ DRCE_FOOTPRINT_FILTERS
Definition drc_item.h:80
@ DRCE_UNCONNECTED_ITEMS
Definition drc_item.h:40
@ DRCE_STARVED_THERMAL
Definition drc_item.h:50
@ DRCE_SCHEMATIC_FIELDS_PARITY
Definition drc_item.h:118
@ DRCE_GENERIC_ERROR
Definition drc_item.h:91
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
@ DRCE_UNRESOLVED_VARIABLE
Definition drc_item.h:88
@ DRCE_DUPLICATE_FOOTPRINT
Definition drc_item.h:76
@ DRCE_EXTRA_FOOTPRINT
Definition drc_item.h:77
@ DRCE_NET_CONFLICT
Definition drc_item.h:78
@ DRCE_MISSING_FOOTPRINT
Definition drc_item.h:75
@ DRCE_GENERIC_WARNING
Definition drc_item.h:90
@ DRCE_SCHEMATIC_PARITY
Definition drc_item.h:79
#define _(s)
@ SEGMENT
Definition eda_shape.h:45
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:278
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:304
@ LAYER_DRC_SHAPES
Custom shapes for DRC markers.
Definition layer_ids.h:315
@ LAYER_DRC_WARNING
Layer for DRC markers with #SEVERITY_WARNING.
Definition layer_ids.h:301
@ LAYER_MARKER_SHADOWS
Shadows for DRC markers.
Definition layer_ids.h:305
@ LAYER_DRC_ERROR
Layer for DRC markers with #SEVERITY_ERROR.
Definition layer_ids.h:277
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:754
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:74
#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