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, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 1992-2019 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 Millimeter2iu( 0.15 )
41 
42 
43 SCH_MARKER::SCH_MARKER( std::shared_ptr<ERC_ITEM> aItem, const wxPoint& 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  return new SCH_MARKER( *this );
57 }
58 
59 
61 {
62  std::swap( *((SCH_MARKER*) this), *((SCH_MARKER*) aItem ) );
63 }
64 
65 
66 wxString SCH_MARKER::Serialize() const
67 {
68  return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
69  m_rcItem->GetSettingsKey(),
70  m_Pos.x,
71  m_Pos.y,
72  m_rcItem->GetMainItemID().AsString(),
73  m_rcItem->GetAuxItemID().AsString() );
74 }
75 
76 
77 SCH_MARKER* SCH_MARKER::Deserialize( const wxString& data )
78 {
79  wxArrayString props = wxSplit( data, '|' );
80  wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
81  (int) strtol( props[2].c_str(), nullptr, 10 ) );
82 
83  std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( props[0] );
84 
85  if( !ercItem )
86  return nullptr;
87 
88  ercItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
89 
90  return new SCH_MARKER( ercItem, markerPos );
91 }
92 
93 
94 #if defined(DEBUG)
95 
96 void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
97 {
98  // for now, make it look like XML:
99  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
100 }
101 
102 #endif
103 
104 
105 void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
106 {
107  aCount = 2;
108 
109  wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
110 
111  switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
112  {
113  default:
114  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
115  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
116  }
117 
118  aLayers[1] = LAYER_SELECTION_SHADOWS;
119 }
120 
121 
123 {
124  if( IsExcluded() )
125  return LAYER_HIDDEN;
126 
127  wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
128 
129  switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
130  {
131  default:
134  }
135 }
136 
137 
139 {
140  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
141  return colors->GetColor( GetColorLayer() );
142 }
143 
144 
145 void SCH_MARKER::Print( const RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
146 {
147  PrintMarker( aSettings, aOffset );
148 }
149 
150 
151 bool SCH_MARKER::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const
152 {
153  return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
154 }
155 
156 
158 {
159  return GetBoundingBoxMarker();
160 }
161 
162 
164 {
165  aList.push_back( MSG_PANEL_ITEM( _( "Electrical Rule Check Error" ),
166  m_rcItem->GetErrorMessage() ) );
167 }
168 
169 
171 {
172  return erc_xpm;
173 }
174 
175 
176 void SCH_MARKER::Rotate( wxPoint aPosition )
177 {
178  // Marker geometry isn't user-editable
179 }
180 
181 
182 void SCH_MARKER::MirrorVertically( int aCenter )
183 {
184  // Marker geometry isn't user-editable
185 }
186 
187 
189 {
190  // Marker geometry isn't user-editable
191 }
192 
193 
194 bool SCH_MARKER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
195 {
196  return HitTestMarker( aPosition, aAccuracy );
197 }
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:163
const wxPoint & GetPos() const
Definition: marker_base.h:84
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:414
EDA_RECT const GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_marker.cpp:157
bool Matches(const wxFindReplaceData &aSearchData, void *aAuxDat) const override
Compare DRC marker main and auxiliary text against search string.
Definition: sch_marker.cpp:151
PNG memory record (file in memory).
Definition: bitmap_def.h:29
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:122
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_marker.cpp:60
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
Implementation of conversion functions that require both schematic and board internal units.
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: sch_marker.cpp:40
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:189
wxPoint m_Pos
position of the marker
Definition: marker_base.h:123
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:97
SCH_MARKER(std::shared_ptr< ERC_ITEM > aItem, const wxPoint &aPos)
Definition: sch_marker.cpp:43
The base class for create windows for drawing purpose.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
const BITMAP_OPAQUE erc_xpm[1]
EDA_RECT GetBoundingBoxMarker() const
Return the orthogonal, bounding box of this object for display purposes.
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_marker.cpp:145
void PrintMarker(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset)
Print the shape is the polygon defined in m_Corners (array of wxPoints).
BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: sch_marker.cpp:170
Definition: kiid.h:44
bool HitTestMarker(const wxPoint &aHitPosition, int aAccuracy) const
Test if the given wxPoint is within the bounds of this object.
Definition: marker_base.cpp:90
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Test if aPosition is contained within or on the bounding box of an item.
Definition: sch_marker.cpp:194
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:128
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:105
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsExcluded() const
Definition: marker_base.h:94
SCH_LAYER_ID
Eeschema drawing layers.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_marker.cpp:182
wxString Serialize() const
Definition: sch_marker.cpp:66
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
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:176
see class PGM_BASE
KIGFX::COLOR4D getColor() const override
Definition: sch_marker.cpp:138
#define _(s)
Definition: 3d_actions.cpp:33
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:54
Handle the component boundary box.
Definition: eda_rect.h:42
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:149
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_marker.cpp:188
Color settings are a bit different than most of the settings objects in that there can be more than o...
wxString GetClass() const override
Return the class name.
Definition: sch_marker.h:45
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:54
Message panel definition file.
static SCH_MARKER * Deserialize(const wxString &data)
Definition: sch_marker.cpp:77
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:196
static VRML_COLOR colors[VRML_COLOR_LAST]
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98