KiCad PCB EDA Suite
pcb_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) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <bitmaps.h>
27 #include <base_units.h>
28 #include <eda_draw_frame.h>
29 #include <board.h>
30 #include <board_design_settings.h>
31 #include <pcb_marker.h>
32 #include <layer_ids.h>
35 #include <geometry/shape_null.h>
36 #include <widgets/ui_common.h>
37 #include <pgm_base.h>
38 #include <drc/drc_item.h>
39 #include <trigo.h>
40 
41 
43 #define SCALING_FACTOR Millimeter2iu( 0.075 )
44 
45 
46 
47 PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const wxPoint& aPosition ) :
48  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
49  MARKER_BASE( SCALING_FACTOR, aItem )
50 {
51  if( m_rcItem )
52  m_rcItem->SetParent( this );
53 
54  m_Pos = aPosition;
55 }
56 
57 
58 /* destructor */
60 {
61 }
62 
63 
64 wxString PCB_MARKER::Serialize() const
65 {
66  return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
67  m_rcItem->GetSettingsKey(),
68  m_Pos.x,
69  m_Pos.y,
70  m_rcItem->GetMainItemID().AsString(),
71  m_rcItem->GetAuxItemID().AsString() );
72 }
73 
74 
75 PCB_MARKER* PCB_MARKER::Deserialize( const wxString& data )
76 {
77  wxArrayString props = wxSplit( data, '|' );
78  wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
79  (int) strtol( props[2].c_str(), nullptr, 10 ) );
80 
81  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
82 
83  if( !drcItem )
84  return nullptr;
85 
86  drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
87 
88  return new PCB_MARKER( drcItem, markerPos );
89 }
90 
91 
92 void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
93 {
94  aList.emplace_back( _( "Type" ), _( "Marker" ) );
95  aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
96 
97  wxString mainText;
98  wxString auxText;
99  EDA_ITEM* mainItem = nullptr;
100  EDA_ITEM* auxItem = nullptr;
101 
102  if( m_rcItem->GetMainItemID() != niluuid )
103  mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
104 
105  if( m_rcItem->GetAuxItemID() != niluuid )
106  auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
107 
108  if( mainItem )
109  mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
110 
111  if( auxItem )
112  auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
113 
114  aList.emplace_back( mainText, auxText );
115 }
116 
117 
118 void PCB_MARKER::Rotate( const wxPoint& aRotCentre, double aAngle )
119 {
120  // Marker geometry isn't user-editable
121 }
122 
123 
124 void PCB_MARKER::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
125 {
126  // Marker geometry isn't user-editable
127 }
128 
129 
130 std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
131 {
132  // Markers do not participate in the board geometry space, and therefore have no
133  // effectiven shape.
134  return std::make_shared<SHAPE_NULL>();
135 }
136 
137 
138 wxString PCB_MARKER::GetSelectMenuText( EDA_UNITS aUnits ) const
139 {
140  // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
141  // for menu duty.
142  return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
143 }
144 
145 
147 {
148  return BITMAPS::drc;
149 }
150 
151 
152 void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
153 {
154  aCount = 2;
155 
156  aLayers[1] = LAYER_MARKER_SHADOWS;
157 
158  if( IsExcluded() )
159  {
160  aLayers[0] = LAYER_DRC_EXCLUSION;
161  return;
162  }
163 
164  BOARD_ITEM_CONTAINER* ancestor = GetParent();
165 
166  while( ancestor->GetParent() )
167  ancestor = ancestor->GetParent();
168 
169  BOARD* board = static_cast<BOARD*>( ancestor );
170 
171  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
172  {
173  default:
174  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
175  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
176  }
177 }
178 
179 
181 {
182  if( IsExcluded() )
183  return LAYER_DRC_EXCLUSION;
184 
185  BOARD_ITEM_CONTAINER* ancestor = GetParent();
186 
187  while( ancestor->GetParent() )
188  ancestor = ancestor->GetParent();
189 
190  BOARD* board = static_cast<BOARD*>( ancestor );
191 
192  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
193  {
194  default:
197  }
198 }
199 
200 
202 {
203  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
204  return colors->GetColor( GetColorLayer() );
205 }
206 
207 
209 {
211 
212  wxPoint pos = m_Pos;
213  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
214  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
215 
216  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
217  int( bbox.GetHeight() * MarkerScale() ) ) );
218 }
219 
220 
222 {
223  EDA_RECT bbox = GetBoundingBox();
224  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
225 }
226 
227 
KIGFX::COLOR4D getColor() const override
Definition: pcb_marker.cpp:201
BOX2< VECTOR2I > BOX2I
Definition: box2.h:506
KIID niluuid(0)
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:254
layer for drc markers with SEVERITY_ERROR
Definition: layer_ids.h:211
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:146
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:221
Implementation of conversion functions that require both schematic and board internal units.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:118
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:184
wxPoint m_Pos
position of the marker
Definition: marker_base.h:123
int GetWidth() const
Definition: eda_rect.h:109
wxString Serialize() const
Definition: pcb_marker.cpp:64
The base class for create windows for drawing purpose.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:589
Definition: kiid.h:44
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: pcb_marker.cpp:152
const wxPoint GetOrigin() const
Definition: eda_rect.h:101
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:128
shadows for drc markers
Definition: layer_ids.h:232
EDA_RECT m_shapeBoundingBox
Definition: marker_base.h:132
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: pcb_marker.cpp:130
static PCB_MARKER * Deserialize(const wxString &data)
Definition: pcb_marker.cpp:75
Functions to provide common constants and other functions to assist in making a consistent UI.
#define _(s)
bool IsExcluded() const
Definition: marker_base.h:94
SEVERITY GetSeverity(int aDRCErrorCode)
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:180
int GetHeight() const
Definition: eda_rect.h:110
virtual EDA_ITEM * GetItem(const KIID &aId) const
Fetch an item by KIID.
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
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: pcb_marker.cpp:138
EDA_UNITS
Definition: eda_units.h:38
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition: marker_base.h:66
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_marker.cpp:124
COLOR4D GetColor(int aLayer) const
class PCB_MARKER, a marker used to show something
Definition: typeinfo.h:98
see class PGM_BASE
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
layer for drc markers which have been individually excluded
Definition: layer_ids.h:231
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
PCB_MARKER(std::shared_ptr< RC_ITEM > aItem, const wxPoint &aPosition)
Definition: pcb_marker.cpp:47
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Return the text to display to be used in the selection clarification context menu when multiple items...
Definition: eda_item.cpp:109
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_marker.cpp:208
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:100
layer for drc markers with SEVERITY_WARNING
Definition: layer_ids.h:230
Color settings are a bit different than most of the settings objects in that there can be more than o...
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
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: pcb_marker.cpp:92
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: pcb_marker.cpp:43
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103