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-2021 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 <erc_settings.h>
31#include <sch_marker.h>
32#include <schematic.h>
33#include <widgets/ui_common.h>
34#include <pgm_base.h>
37#include <erc_item.h>
38#include <schematic.h>
39#include <sch_screen.h>
40#include <sch_file_versions.h>
41
43#define SCALING_FACTOR schIUScale.mmToIU( 0.15 )
44
45
46SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const VECTOR2I& aPos ) :
47 SCH_ITEM( nullptr, SCH_MARKER_T ),
48 MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC )
49{
50 if( m_rcItem )
51 m_rcItem->SetParent( this );
52
53 m_Pos = aPos;
54
55 m_isLegacyMarker = false;
56}
57
58
60{
61 if( m_rcItem )
62 m_rcItem->SetParent( nullptr );
63}
64
65
67{
68 return new SCH_MARKER( *this );
69}
70
71
73{
74 std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
75}
76
77
78wxString SCH_MARKER::Serialize() const
79{
80 std::shared_ptr<ERC_ITEM> erc = std::static_pointer_cast<ERC_ITEM>( m_rcItem );
81 wxString sheetSpecificPath, mainItemPath, auxItemPath;
82
83 if( erc->IsSheetSpecific() )
84 sheetSpecificPath = erc->GetSpecificSheetPath().Path().AsString();
85
86 if( erc->MainItemHasSheetPath() )
87 mainItemPath = erc->GetMainItemSheetPath().Path().AsString();
88
89 if( erc->AuxItemHasSheetPath() )
90 auxItemPath = erc->GetAuxItemSheetPath().Path().AsString();
91
92 return wxString::Format( wxT( "%s|%d|%d|%s|%s|%s|%s|%s" ), m_rcItem->GetSettingsKey(), m_Pos.x,
93 m_Pos.y, m_rcItem->GetMainItemID().AsString(),
94 m_rcItem->GetAuxItemID().AsString(), sheetSpecificPath, mainItemPath,
95 auxItemPath );
96}
97
98
99SCH_MARKER* SCH_MARKER::Deserialize( SCHEMATIC* schematic, const wxString& data )
100{
101 wxArrayString props = wxSplit( data, '|' );
102 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
103 (int) strtol( props[2].c_str(), nullptr, 10 ) );
104
105 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( props[0] );
106
107 if( !ercItem )
108 return nullptr;
109
110 ercItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
111
112 bool isLegacyMarker = true;
113
114 // Deserialize sheet / item specific paths - we are not able to use the file version to determine
115 // if markers are legacy as there could be a file opened with a prior version but which has
116 // new markers - this code is called not just during schematic load, but also to match new
117 // ERC exceptions to exclusions.
118 if( props.size() == 8 )
119 {
120 isLegacyMarker = false;
121
122 SCH_SHEET_LIST sheetPaths = schematic->GetSheets();
123
124 if( !props[5].IsEmpty() )
125 {
126 KIID_PATH sheetSpecificKiidPath( props[5] );
127 std::optional<SCH_SHEET_PATH> sheetSpecificPath =
128 sheetPaths.GetSheetPathByKIIDPath( sheetSpecificKiidPath, true );
129 if( sheetSpecificPath.has_value() )
130 ercItem->SetSheetSpecificPath( sheetSpecificPath.value() );
131 }
132
133 if( !props[6].IsEmpty() )
134 {
135 KIID_PATH mainItemKiidPath( props[6] );
136 std::optional<SCH_SHEET_PATH> mainItemPath =
137 sheetPaths.GetSheetPathByKIIDPath( mainItemKiidPath, true );
138 if( mainItemPath.has_value() )
139 {
140 if( props[7].IsEmpty() )
141 {
142 ercItem->SetItemsSheetPaths( mainItemPath.value() );
143 }
144 else
145 {
146 KIID_PATH auxItemKiidPath( props[7] );
147 std::optional<SCH_SHEET_PATH> auxItemPath =
148 sheetPaths.GetSheetPathByKIIDPath( auxItemKiidPath, true );
149
150 if( auxItemPath.has_value() )
151 ercItem->SetItemsSheetPaths( mainItemPath.value(), auxItemPath.value() );
152 }
153 }
154 }
155 }
156
157 SCH_MARKER* marker = new SCH_MARKER( ercItem, markerPos );
158 marker->SetIsLegacyMarker( isLegacyMarker );
159
160 return marker;
161}
162
163
164#if defined(DEBUG)
165
166void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
167{
168 // for now, make it look like XML:
169 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
170}
171
172#endif
173
174
175void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
176{
177 wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
178
179 // Don't display sheet-specific markers when SCH_SHEET_PATHs do not match
180 std::shared_ptr<ERC_ITEM> ercItem = std::static_pointer_cast<ERC_ITEM>( GetRCItem() );
181
182 if( ercItem->IsSheetSpecific()
183 && ( ercItem->GetSpecificSheetPath() != Schematic()->CurrentSheet() ) )
184 {
185 aCount = 0;
186 return;
187 }
188
189 aCount = 2;
190
191 if( IsExcluded() )
192 {
193 aLayers[0] = LAYER_ERC_EXCLUSION;
194 }
195 else
196 {
197 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
198 {
199 default:
200 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
201 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
202 }
203 }
204
205 aLayers[1] = LAYER_SELECTION_SHADOWS;
206}
207
208
210{
211 if( IsExcluded() )
212 return LAYER_ERC_EXCLUSION;
213
214 wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
215
216 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
217 {
218 default:
219 case SEVERITY::RPT_SEVERITY_ERROR: return LAYER_ERC_ERR;
220 case SEVERITY::RPT_SEVERITY_WARNING: return LAYER_ERC_WARN;
221 }
222}
223
224
226{
227 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
228 return colors->GetColor( GetColorLayer() );
229}
230
231
233{
234 if( IsExcluded() )
236
237 ERC_ITEM* item = static_cast<ERC_ITEM*>( m_rcItem.get() );
238
239 return Schematic()->ErcSettings().GetSeverity( item->GetErrorCode() );
240}
241
242
243void SCH_MARKER::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
244{
245 PrintMarker( aSettings, aOffset );
246}
247
248
249bool SCH_MARKER::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
250{
251 return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
252}
253
254
256{
257 return GetBoundingBoxMarker();
258}
259
260
261void SCH_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
262{
263 aList.emplace_back( _( "Electrical Rule Check Error" ), m_rcItem->GetErrorMessage() );
264}
265
266
268{
269 return BITMAPS::erc;
270}
271
272
273void SCH_MARKER::Rotate( const VECTOR2I& aCenter )
274{
275 // Marker geometry isn't user-editable
276}
277
278
280{
281 // Marker geometry isn't user-editable
282}
283
284
286{
287 // Marker geometry isn't user-editable
288}
289
290
291bool SCH_MARKER::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
292{
293 return HitTestMarker( aPosition, aAccuracy );
294}
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.
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
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:232
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:97
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:105
const VECTOR2I & GetPos() const
Definition: marker_base.h:87
VECTOR2I m_Pos
position of the marker
Definition: marker_base.h:128
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.
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:216
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:150
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
SEVERITY GetSeverity() const override
Definition: sch_marker.cpp:232
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:175
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:249
wxString Serialize() const
Definition: sch_marker.cpp:78
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:267
bool m_isLegacyMarker
Definition: sch_marker.h:130
void SetIsLegacyMarker(bool isLegacyMarker=true)
Sets this marker as a legacy artifact.
Definition: sch_marker.h:115
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:66
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:209
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_marker.cpp:279
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_marker.cpp:243
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:291
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:273
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_marker.cpp:72
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_marker.cpp:285
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:261
KIGFX::COLOR4D getColor() const override
Definition: sch_marker.cpp:225
BOX2I const GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_marker.cpp:255
static SCH_MARKER * Deserialize(SCHEMATIC *schematic, const wxString &data)
Definition: sch_marker.cpp:99
SCH_MARKER(std::shared_ptr< ERC_ITEM > aItem, const VECTOR2I &aPos)
Definition: sch_marker.cpp:46
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)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:346
@ LAYER_ERC_WARN
Definition: layer_ids.h:375
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:377
@ LAYER_ERC_ERR
Definition: layer_ids.h:376
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:387
Message panel definition file.
see class PGM_BASE
SEVERITY
@ RPT_SEVERITY_EXCLUSION
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: sch_marker.cpp:43
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:115
@ SCH_MARKER_T
Definition: typeinfo.h:140
Functions to provide common constants and other functions to assist in making a consistent UI.