KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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) 2009 Jean-Pierre Charras, [email protected]
5 * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <sch_draw_panel.h>
26#include <trigo.h>
27#include <widgets/msgpanel.h>
28#include <bitmaps.h>
29#include <base_units.h>
30#include <eda_draw_frame.h>
31#include <erc_settings.h>
32#include <sch_marker.h>
33#include <schematic.h>
34#include <widgets/ui_common.h>
35#include <pgm_base.h>
38#include <erc_item.h>
39#include <sch_screen.h>
40
42#define SCALING_FACTOR schIUScale.mmToIU( 0.15 )
43
44
45SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const VECTOR2I& aPos ) :
46 SCH_ITEM( nullptr, SCH_MARKER_T ),
47 MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC )
48{
49 if( m_rcItem )
50 m_rcItem->SetParent( this );
51
52 m_Pos = aPos;
53
54 m_isLegacyMarker = false;
55}
56
57
59{
60 if( m_rcItem )
61 m_rcItem->SetParent( nullptr );
62}
63
64
66{
67 return new SCH_MARKER( *this );
68}
69
70
72{
73 SCH_ITEM::SwapFlags( aItem );
74
75 SCH_MARKER* item = static_cast<SCH_MARKER*>( aItem );
76
77 std::swap( m_isLegacyMarker, item->m_isLegacyMarker );
78 std::swap( m_Pos, item->m_Pos );
79
80 std::swap( m_markerType, item->m_markerType );
81 std::swap( m_excluded, item->m_excluded );
82 std::swap( m_rcItem, item->m_rcItem );
83
84 std::swap( m_scalingFactor, item->m_scalingFactor );
85 std::swap( m_shapeBoundingBox, item->m_shapeBoundingBox );
86
87 std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
88}
89
90
91wxString SCH_MARKER::Serialize() const
92{
93 std::shared_ptr<ERC_ITEM> erc = std::static_pointer_cast<ERC_ITEM>( m_rcItem );
94 wxString sheetSpecificPath, mainItemPath, auxItemPath;
95
96 if( erc->IsSheetSpecific() )
97 sheetSpecificPath = erc->GetSpecificSheetPath().Path().AsString();
98
99 if( erc->MainItemHasSheetPath() )
100 mainItemPath = erc->GetMainItemSheetPath().Path().AsString();
101
102 if( erc->AuxItemHasSheetPath() )
103 auxItemPath = erc->GetAuxItemSheetPath().Path().AsString();
104
105 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s|%s|%s" ), m_rcItem->GetSettingsKey(), m_Pos.x,
106 m_Pos.y, m_rcItem->GetMainItemID().AsString(),
107 m_rcItem->GetAuxItemID().AsString(), sheetSpecificPath, mainItemPath,
108 auxItemPath );
109}
110
111
112SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data )
113{
114 wxArrayString props = wxSplit( data, '|' );
115 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
116 (int) strtol( props[2].c_str(), nullptr, 10 ) );
117
118 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( props[0] );
119
120 if( !ercItem )
121 return nullptr;
122
123 ercItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
124
125 bool isLegacyMarker = true;
126
127 // Deserialize sheet / item specific paths - we are not able to use the file version to determine
128 // if markers are legacy as there could be a file opened with a prior version but which has
129 // new markers - this code is called not just during schematic load, but also to match new
130 // ERC exceptions to exclusions.
131 if( props.size() == 8 )
132 {
133 isLegacyMarker = false;
134
135 SCH_SHEET_LIST sheetPaths = schematic->GetSheets();
136
137 if( !props[5].IsEmpty() )
138 {
139 KIID_PATH sheetSpecificKiidPath( props[5] );
140 std::optional<SCH_SHEET_PATH> sheetSpecificPath =
141 sheetPaths.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true );
142 if( sheetSpecificPath.has_value() )
143 ercItem->SetSheetSpecificPath( sheetSpecificPath.value() );
144 }
145
146 if( !props[6].IsEmpty() )
147 {
148 KIID_PATH mainItemKiidPath( props[6] );
149 std::optional<SCH_SHEET_PATH> mainItemPath =
150 sheetPaths.GetSheetPathByKIIDPath( mainItemKiidPath, true );
151 if( mainItemPath.has_value() )
152 {
153 if( props[7].IsEmpty() )
154 {
155 ercItem->SetItemsSheetPaths( mainItemPath.value() );
156 }
157 else
158 {
159 KIID_PATH auxItemKiidPath( props[7] );
160 std::optional<SCH_SHEET_PATH> auxItemPath =
161 sheetPaths.GetSheetPathByKIIDPath( auxItemKiidPath, true );
162
163 if( auxItemPath.has_value() )
164 ercItem->SetItemsSheetPaths( mainItemPath.value(), auxItemPath.value() );
165 }
166 }
167 }
168 }
169
170 SCH_MARKER* marker = new SCH_MARKER( ercItem, markerPos );
171 marker->SetIsLegacyMarker( isLegacyMarker );
172
173 return marker;
174}
175
176
177#if defined(DEBUG)
178
179void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
180{
181 // for now, make it look like XML:
182 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
183}
184
185#endif
186
187
188void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
189{
190 wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
191
192 // Don't display sheet-specific markers when SCH_SHEET_PATHs do not match
193 std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( GetRCItem() );
194
195 if( ercItem->IsSheetSpecific()
196 && ( ercItem->GetSpecificSheetPath() != Schematic()->CurrentSheet() ) )
197 {
198 aCount = 0;
199 return;
200 }
201
202 aCount = 2;
203
204 if( IsExcluded() )
205 {
206 aLayers[0] = LAYER_ERC_EXCLUSION;
207 }
208 else
209 {
210 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
211 {
212 default:
213 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
214 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
215 }
216 }
217
218 aLayers[1] = LAYER_SELECTION_SHADOWS;
219}
220
221
223{
224 if( IsExcluded() )
225 return LAYER_ERC_EXCLUSION;
226
227 wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
228
229 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
230 {
231 default:
232 case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_ERC_ERR;
233 case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_ERC_WARN;
234 }
235}
236
237
239{
240 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
241 return colors->GetColor( GetColorLayer() );
242}
243
244
246{
247 if( IsExcluded() )
249
250 ERC_ITEM* item = static_cast<ERC_ITEM*>( m_rcItem.get() );
251
252 return Schematic()->ErcSettings().GetSeverity( item->GetErrorCode() );
253}
254
255
256void SCH_MARKER::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
257{
258 PrintMarker( aSettings, aOffset );
259}
260
261
262bool SCH_MARKER::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
263{
264 return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
265}
266
267
269{
270 return GetBoundingBoxMarker();
271}
272
273
274void SCH_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
275{
276 aList.emplace_back( _( "Type" ), _( "Marker" ) );
277 aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
278
279 switch( GetSeverity() )
280 {
282 aList.emplace_back( _( "Severity" ), _( "Ignore" ) );
283 break;
285 aList.emplace_back( _( "Severity" ), _( "Warning" ) );
286 break;
288 aList.emplace_back( _( "Severity" ), _( "Error" ) );
289 break;
290 default:
291 break;
292 }
293
295 {
296 aList.emplace_back( _( "Drawing Sheet" ), wxEmptyString );
297 }
298 else
299 {
300 wxString mainText;
301 wxString auxText;
302 EDA_ITEM* mainItem = nullptr;
303 EDA_ITEM* auxItem = nullptr;
304
305 if( m_rcItem->GetMainItemID() != niluuid )
306 mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
307
308 if( m_rcItem->GetAuxItemID() != niluuid )
309 auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
310
311 if( mainItem )
312 mainText = mainItem->GetItemDescription( aFrame );
313
314 if( auxItem )
315 auxText = auxItem->GetItemDescription( aFrame );
316
317 aList.emplace_back( mainText, auxText );
318 }
319
320 if( IsExcluded() )
321 aList.emplace_back( _( "Excluded" ), m_comment );
322}
323
324
326{
327 return BITMAPS::erc;
328}
329
330
331void SCH_MARKER::Rotate( const VECTOR2I& aCenter )
332{
333 // Marker geometry isn't user-editable
334}
335
336
338{
339 // Marker geometry isn't user-editable
340}
341
342
344{
345 // Marker geometry isn't user-editable
346}
347
348
349bool SCH_MARKER::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
350{
351 return HitTestMarker( aPosition, aAccuracy );
352}
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
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
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 bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:372
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const
Return a user-visible description string of this item.
Definition: eda_item.cpp:108
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:242
SEVERITY GetSeverity(int aErrorCode) const
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Definition: kiid.h:49
void PrintMarker(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset)
Print the shape is the polygon defined in m_Corners (array of VECTOR2Is).
bool IsExcluded() const
Definition: marker_base.h:98
bool HitTestMarker(const VECTOR2I &aHitPosition, int aAccuracy) const
Test if the given VECTOR2I is within the bounds of this object.
Definition: marker_base.cpp:90
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:112
int m_scalingFactor
Definition: marker_base.h:143
wxString m_comment
Definition: marker_base.h:140
const VECTOR2I & GetPos() const
Definition: marker_base.h:88
VECTOR2I m_Pos
position of the marker
Definition: marker_base.h:135
@ MARKER_DRAWING_SHEET
Definition: marker_base.h:56
MARKER_T m_markerType
Definition: marker_base.h:138
bool m_excluded
Definition: marker_base.h:139
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:141
enum MARKER_T GetMarkerType() const
Definition: marker_base.h:96
BOX2I m_shapeBoundingBox
Definition: marker_base.h:145
BOX2I GetBoundingBoxMarker() const
Return the orthogonal, bounding box of this object for display purposes.
int GetErrorCode() const
Definition: rc_item.h:153
Holds all the data relating to one schematic.
Definition: schematic.h:75
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:294
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:165
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
void SwapFlags(SCH_ITEM *aItem)
Swap the non-temp and non-edit flags.
Definition: sch_item.cpp:267
SEVERITY GetSeverity() const override
Definition: sch_marker.cpp:245
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the layers the item is drawn on (which may be more than its "home" layer)
Definition: sch_marker.cpp:188
bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxDat) const override
Compare DRC marker main and auxiliary text against search string.
Definition: sch_marker.cpp:262
wxString Serialize() const
Definition: sch_marker.cpp:91
wxString GetClass() const override
Return the class name.
Definition: sch_marker.h:47
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_marker.cpp:325
bool m_isLegacyMarker
Definition: sch_marker.h:141
void SetIsLegacyMarker(bool isLegacyMarker=true)
Sets this marker as a legacy artifact.
Definition: sch_marker.h:116
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:65
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:222
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_marker.cpp:337
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_marker.cpp:256
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: sch_marker.cpp:349
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:331
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_marker.cpp:71
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_marker.cpp:343
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: sch_marker.cpp:274
KIGFX::COLOR4D getColor() const override
Definition: sch_marker.cpp:238
BOX2I const GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_marker.cpp:268
static SCH_MARKER * Deserialize(SCHEMATIC *schematic, const wxString &data)
Definition: sch_marker.cpp:112
SCH_MARKER(std::shared_ptr< ERC_ITEM > aItem, const VECTOR2I &aPos)
Definition: sch_marker.cpp:45
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
#define _(s)
KIID niluuid(0)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:352
@ LAYER_ERC_WARN
Definition: layer_ids.h:381
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:383
@ LAYER_ERC_ERR
Definition: layer_ids.h:382
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:393
Message panel definition file.
see class PGM_BASE
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: sch_marker.cpp:42
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
@ SCH_MARKER_T
Definition: typeinfo.h:143
Functions to provide common constants and other functions to assist in making a consistent UI.