KiCad PCB EDA Suite
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
40#define SCALING_FACTOR schIUScale.mmToIU( 0.15 )
41
42
43SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const VECTOR2I& aPos ) :
44 SCH_ITEM( nullptr, SCH_MARKER_T ),
45 MARKER_BASE( SCALING_FACTOR, aItem, MARKER_BASE::MARKER_ERC )
46{
47 if( m_rcItem )
48 m_rcItem->SetParent( this );
49
50 m_Pos = aPos;
51}
52
53
55{
56 if( m_rcItem )
57 m_rcItem->SetParent( nullptr );
58}
59
60
62{
63 return new SCH_MARKER( *this );
64}
65
66
68{
69 std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
70}
71
72
73wxString SCH_MARKER::Serialize() const
74{
75 return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
76 m_rcItem->GetSettingsKey(),
77 m_Pos.x,
78 m_Pos.y,
79 m_rcItem->GetMainItemID().AsString(),
80 m_rcItem->GetAuxItemID().AsString() );
81}
82
83
84SCH_MARKER* SCH_MARKER::Deserialize( const wxString& data )
85{
86 wxArrayString props = wxSplit( data, '|' );
87 VECTOR2I markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
88 (int) strtol( props[2].c_str(), nullptr, 10 ) );
89
90 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( props[0] );
91
92 if( !ercItem )
93 return nullptr;
94
95 ercItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
96
97 return new SCH_MARKER( ercItem, markerPos );
98}
99
100
101#if defined(DEBUG)
102
103void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
104{
105 // for now, make it look like XML:
106 NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
107}
108
109#endif
110
111
112void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
113{
114 aCount = 2;
115
116 wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
117
118 if( IsExcluded() )
119 {
120 aLayers[0] = LAYER_ERC_EXCLUSION;
121 }
122 else
123 {
124 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
125 {
126 default:
127 case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
128 case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
129 }
130 }
131
132 aLayers[1] = LAYER_SELECTION_SHADOWS;
133}
134
135
137{
138 if( IsExcluded() )
139 return LAYER_ERC_EXCLUSION;
140
141 wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
142
143 switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
144 {
145 default:
148 }
149}
150
151
153{
154 COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
155 return colors->GetColor( GetColorLayer() );
156}
157
158
160{
161 if( IsExcluded() )
163
164 ERC_ITEM* item = static_cast<ERC_ITEM*>( m_rcItem.get() );
165
166 return Schematic()->ErcSettings().GetSeverity( item->GetErrorCode() );
167}
168
169
170void SCH_MARKER::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset )
171{
172 PrintMarker( aSettings, aOffset );
173}
174
175
176bool SCH_MARKER::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
177{
178 return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
179}
180
181
183{
184 return GetBoundingBoxMarker();
185}
186
187
188void SCH_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
189{
190 aList.emplace_back( _( "Electrical Rule Check Error" ), m_rcItem->GetErrorMessage() );
191}
192
193
195{
196 return BITMAPS::erc;
197}
198
199
200void SCH_MARKER::Rotate( const VECTOR2I& aCenter )
201{
202 // Marker geometry isn't user-editable
203}
204
205
207{
208 // Marker geometry isn't user-editable
209}
210
211
213{
214 // Marker geometry isn't user-editable
215}
216
217
218bool SCH_MARKER::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
219{
220 return HitTestMarker( aPosition, aAccuracy );
221}
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:384
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:227
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:48
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
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:136
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:179
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
SEVERITY GetSeverity() const override
Definition: sch_marker.cpp:159
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:112
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:176
wxString Serialize() const
Definition: sch_marker.cpp:73
wxString GetClass() const override
Return the class name.
Definition: sch_marker.h:47
static SCH_MARKER * Deserialize(const wxString &data)
Definition: sch_marker.cpp:84
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_marker.cpp:194
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:61
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:136
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_marker.cpp:206
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
Definition: sch_marker.cpp:170
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:218
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:200
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_marker.cpp:67
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_marker.cpp:212
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:188
KIGFX::COLOR4D getColor() const override
Definition: sch_marker.cpp:152
BOX2I const GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_marker.cpp:182
SCH_MARKER(std::shared_ptr< ERC_ITEM > aItem, const VECTOR2I &aPos)
Definition: sch_marker.cpp:43
#define _(s)
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ LAYER_ERC_WARN
Definition: layer_ids.h:369
@ LAYER_ERC_EXCLUSION
Definition: layer_ids.h:371
@ LAYER_ERC_ERR
Definition: layer_ids.h:370
@ LAYER_SELECTION_SHADOWS
Definition: layer_ids.h:381
Message panel definition file.
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_EXCLUSION
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: sch_marker.cpp:40
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
@ SCH_MARKER_T
Definition: typeinfo.h:141
Functions to provide common constants and other functions to assist in making a consistent UI.