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 <pcb_base_frame.h>
29 #include <board.h>
30 #include <pcb_marker.h>
34 #include <geometry/shape_null.h>
35 #include <widgets/ui_common.h>
36 #include <pgm_base.h>
37 #include <drc/drc_item.h>
38 #include <trigo.h>
39 
40 
42 #define SCALING_FACTOR Millimeter2iu( 0.075 )
43 
44 
45 
46 PCB_MARKER::PCB_MARKER( std::shared_ptr<RC_ITEM> aItem, const wxPoint& aPosition ) :
47  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
48  MARKER_BASE( SCALING_FACTOR, aItem )
49 {
50  if( m_rcItem )
51  m_rcItem->SetParent( this );
52 
53  m_Pos = aPosition;
54 }
55 
56 
57 /* destructor */
59 {
60 }
61 
62 
63 wxString PCB_MARKER::Serialize() const
64 {
65  return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
66  m_rcItem->GetSettingsKey(),
67  m_Pos.x,
68  m_Pos.y,
69  m_rcItem->GetMainItemID().AsString(),
70  m_rcItem->GetAuxItemID().AsString() );
71 }
72 
73 
74 PCB_MARKER* PCB_MARKER::Deserialize( const wxString& data )
75 {
76  wxArrayString props = wxSplit( data, '|' );
77  wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
78  (int) strtol( props[2].c_str(), nullptr, 10 ) );
79 
80  std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( props[0] );
81 
82  if( !drcItem )
83  return nullptr;
84 
85  drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
86 
87  return new PCB_MARKER( drcItem, markerPos );
88 }
89 
90 
91 void PCB_MARKER::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
92 {
93  aList.emplace_back( _( "Type" ), _( "Marker" ) );
94  aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage() );
95 
96  wxString mainText;
97  wxString auxText;
98  EDA_ITEM* mainItem = nullptr;
99  EDA_ITEM* auxItem = nullptr;
100 
101  if( m_rcItem->GetMainItemID() != niluuid )
102  mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
103 
104  if( m_rcItem->GetAuxItemID() != niluuid )
105  auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
106 
107  if( mainItem )
108  mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
109 
110  if( auxItem )
111  auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
112 
113  aList.emplace_back( mainText, auxText );
114 }
115 
116 
117 void PCB_MARKER::Rotate( const wxPoint& aRotCentre, double aAngle )
118 {
119  // Marker geometry isn't user-editable
120 }
121 
122 
123 void PCB_MARKER::Flip( const wxPoint& aCentre, bool aFlipLeftRight )
124 {
125  // Marker geometry isn't user-editable
126 }
127 
128 
129 std::shared_ptr<SHAPE> PCB_MARKER::GetEffectiveShape( PCB_LAYER_ID aLayer ) const
130 {
131  // Markers do not participate in the board geometry space, and therefore have no
132  // effectiven shape.
133  return std::make_shared<SHAPE_NULL>();
134 }
135 
136 
137 wxString PCB_MARKER::GetSelectMenuText( EDA_UNITS aUnits ) const
138 {
139  // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
140  // for menu duty.
141  return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
142 }
143 
144 
146 {
147  return drc_xpm;
148 }
149 
150 
151 void PCB_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
152 {
153  aCount = 2;
154 
155  aLayers[1] = LAYER_MARKER_SHADOWS;
156 
157  if( IsExcluded() )
158  {
159  aLayers[0] = LAYER_DRC_EXCLUSION;
160  return;
161  }
162 
163  BOARD_ITEM_CONTAINER* ancestor = GetParent();
164 
165  while( ancestor->GetParent() )
166  ancestor = ancestor->GetParent();
167 
168  BOARD* board = static_cast<BOARD*>( ancestor );
169 
170  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
171  {
172  default:
173  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
174  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
175  }
176 }
177 
178 
180 {
181  if( IsExcluded() )
182  return LAYER_DRC_EXCLUSION;
183 
184  BOARD_ITEM_CONTAINER* ancestor = GetParent();
185 
186  while( ancestor->GetParent() )
187  ancestor = ancestor->GetParent();
188 
189  BOARD* board = static_cast<BOARD*>( ancestor );
190 
191  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
192  {
193  default:
196  }
197 }
198 
199 
201 {
202  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
203  return colors->GetColor( GetColorLayer() );
204 }
205 
206 
208 {
210 
211  wxPoint pos = m_Pos;
212  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
213  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
214 
215  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
216  int( bbox.GetHeight() * MarkerScale() ) ) );
217 }
218 
219 
221 {
222  EDA_RECT bbox = GetBoundingBox();
223  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
224 }
225 
226 
KIGFX::COLOR4D getColor() const override
Definition: pcb_marker.cpp:200
virtual EDA_ITEM * GetItem(const KIID &aId)
Fetch an item by KIID.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
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:245
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_marker.cpp:220
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:82
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Rotate this object.
Definition: pcb_marker.cpp:117
wxPoint m_Pos
position of the marker
Definition: marker_base.h:123
int GetWidth() const
Definition: eda_rect.h:114
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
wxString Serialize() const
Definition: pcb_marker.cpp:63
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:591
const BITMAP_OPAQUE drc_xpm[1]
Definition: drc.cpp:29
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
Classes used in Pcbnew, CvPcb and GerbView.
Definition: kiid.h:44
PCB_LAYER_ID
A quick note on layer IDs:
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:151
const wxPoint GetOrigin() const
Definition: eda_rect.h:106
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:128
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:129
static PCB_MARKER * Deserialize(const wxString &data)
Definition: pcb_marker.cpp:74
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsExcluded() const
Definition: marker_base.h:94
SEVERITY GetSeverity(int aDRCErrorCode)
GAL_LAYER_ID GetColorLayer() const
Definition: pcb_marker.cpp:179
int GetHeight() const
Definition: eda_rect.h:115
layer for drc markers which have been individually excluded
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
BITMAP_DEF GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_marker.cpp:145
layer for drc markers with SEVERITY_WARNING
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:137
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:123
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
see class PGM_BASE
Board layer functions and definitions.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
PCB_MARKER(std::shared_ptr< RC_ITEM > aItem, const wxPoint &aPosition)
Definition: pcb_marker.cpp:46
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:123
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_marker.cpp:207
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
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:168
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:91
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Definition: pcb_marker.cpp:42
static VRML_COLOR colors[VRML_COLOR_LAST]
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
layer for drc markers with SEVERITY_ERROR
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98