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 <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 #if defined(DEBUG)
67 
68 void SCH_MARKER::Show( int nestLevel, std::ostream& os ) const
69 {
70  // for now, make it look like XML:
71  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << GetPos() << "/>\n";
72 }
73 
74 #endif
75 
76 
77 void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
78 {
79  aCount = 2;
80 
81  wxCHECK_RET( Schematic(), "No SCHEMATIC set for SCH_MARKER!" );
82 
83  switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
84  {
85  default:
86  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_ERC_ERR; break;
87  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_ERC_WARN; break;
88  }
89 
90  aLayers[1] = LAYER_SELECTION_SHADOWS;
91 }
92 
93 
95 {
96  if( IsExcluded() )
97  return LAYER_HIDDEN;
98 
99  wxCHECK_MSG( Schematic(), LAYER_ERC_ERR, "No SCHEMATIC set for SCH_MARKER!" );
100 
101  switch( Schematic()->ErcSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
102  {
103  default:
106  }
107 }
108 
109 
111 {
112  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
113  return colors->GetColor( GetColorLayer() );
114 }
115 
116 
117 void SCH_MARKER::Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset )
118 {
119  PrintMarker( aSettings, aOffset );
120 }
121 
122 
123 bool SCH_MARKER::Matches( wxFindReplaceData& aSearchData, void* aAuxData )
124 {
125  return SCH_ITEM::Matches( m_rcItem->GetErrorMessage(), aSearchData );
126 }
127 
128 
130 {
131  return GetBoundingBoxMarker();
132 }
133 
134 
136 {
137  aList.push_back( MSG_PANEL_ITEM( _( "Electronics Rule Check Error" ),
138  m_rcItem->GetErrorMessage(), DARKRED ) );
139 }
140 
141 
143 {
144  return erc_xpm;
145 }
146 
147 
148 void SCH_MARKER::Rotate( wxPoint aPosition )
149 {
150  RotatePoint( &m_Pos, aPosition, 900 );
151 }
152 
153 
154 void SCH_MARKER::MirrorX( int aXaxis_position )
155 {
156  m_Pos.y -= aXaxis_position;
157  m_Pos.y = -m_Pos.y;
158  m_Pos.y += aXaxis_position;
159 }
160 
161 
162 void SCH_MARKER::MirrorY( int aYaxis_position )
163 {
164  m_Pos.x -= aYaxis_position;
165  m_Pos.x = -m_Pos.x;
166  m_Pos.x += aYaxis_position;
167 }
168 
169 
170 bool SCH_MARKER::HitTest( const wxPoint& aPosition, int aAccuracy ) const
171 {
172  return HitTestMarker( aPosition, aAccuracy );
173 }
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
Definition: sch_marker.cpp:135
const wxPoint & GetPos() const
Function GetPos.
Definition: marker_base.h:99
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
Definition: sch_marker.cpp:154
EDA_RECT const GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_marker.cpp:129
PNG memory record (file in memory).
Definition: bitmap_def.h:29
SCH_LAYER_ID GetColorLayer() const
Definition: sch_marker.cpp:94
void SwapData(SCH_ITEM *aItem) override
Swap the internal data structures aItem with the schematic item.
Definition: sch_marker.cpp:60
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
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
wxPoint m_Pos
position of the marker
Definition: marker_base.h:61
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
SCH_MARKER(std::shared_ptr< ERC_ITEM > aItem, const wxPoint &aPos)
Definition: sch_marker.cpp:43
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
The base class for create windows for drawing purpose.
const BITMAP_OPAQUE erc_xpm[1]
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
EDA_RECT GetBoundingBoxMarker() const
Function GetBoundingBoxMarker returns the orthogonal, bounding box of this object for display purpose...
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
Definition: sch_marker.cpp:162
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
Definition: sch_marker.cpp:142
bool Matches(wxFindReplaceData &aSearchData, void *aAuxDat) override
Compare DRC marker main and auxiliary text against search string.
Definition: sch_marker.cpp:123
bool HitTestMarker(const wxPoint &aHitPosition, int aAccuracy) const
Tests if the given wxPoint is within the bounds of this object.
Definition: marker_base.cpp:89
void Print(RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Definition: sch_marker.cpp:117
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_marker.cpp:170
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:66
void PrintMarker(RENDER_SETTINGS *aSettings, const wxPoint &aOffset)
Function PrintMarker Prints the shape is the polygon defined in m_Corners (array of wxPoints).
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:77
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsExcluded() const
Definition: marker_base.h:109
SCH_LAYER_ID
Eeschema drawing layers.
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_marker.cpp:148
see class PGM_BASE
KIGFX::COLOR4D getColor() const override
Definition: sch_marker.cpp:110
#define _(s)
Definition: 3d_actions.cpp:33
EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definition: sch_marker.cpp:54
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:147
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:103
Color settings are a bit different than most of the settings objects in that there can be more than o...
wxString GetClass() const override
Function GetClass returns 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.
virtual bool Matches(wxFindReplaceData &aSearchData, void *aAuxData)
Function Matches compares the item against the search criteria in aSearchData.
Definition: eda_item.h:446
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
static VRML_COLOR colors[VRML_COLOR_LAST]
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100