KiCad PCB EDA Suite
class_marker_pcb.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 <fctsys.h>
27 #include <gr_basic.h>
28 #include <bitmaps.h>
29 #include <base_units.h>
30 #include <pcb_base_frame.h>
31 #include <class_board.h>
32 #include <class_marker_pcb.h>
36 #include <widgets/ui_common.h>
37 #include <pgm_base.h>
38 #include <drc/drc_item.h>
39 
40 
42 #define SCALING_FACTOR Millimeter2iu( 0.1 )
43 
44 
45 MARKER_PCB::MARKER_PCB( DRC_ITEM* aItem, const wxPoint& aPosition ) :
46  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
47  MARKER_BASE( SCALING_FACTOR, aItem )
48 {
49  if( m_rcItem )
50  m_rcItem->SetParent( this );
51 
52  m_Pos = aPosition;
53 }
54 
55 
56 /* destructor */
58 {
59 }
60 
61 
62 wxString MARKER_PCB::Serialize() const
63 {
64  return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
66  m_Pos.x,
67  m_Pos.y,
70 }
71 
72 
73 MARKER_PCB* MARKER_PCB::Deserialize( const wxString& data )
74 {
75  wxArrayString props = wxSplit( data, '|' );
76  wxPoint markerPos( (int) strtol( props[1].c_str(), nullptr, 10 ),
77  (int) strtol( props[2].c_str(), nullptr, 10 ) );
78 
79  DRC_ITEM* drcItem = DRC_ITEM::Create( props[0] );
80 
81  if( !drcItem )
82  return nullptr;
83 
84  drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
85 
86  return new MARKER_PCB( drcItem, markerPos );
87 }
88 
89 
90 /* tests to see if this object is on the given layer.
91  * DRC markers are not really on a copper layer, but
92  * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
93  * because this test is often used to locad a marker
94  * param aLayer The layer to test for.
95  * return bool - true if on given layer, else false.
96  */
97 bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
98 {
99  return IsCopperLayer( aLayer );
100 }
101 
102 
103 void MARKER_PCB::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
104 {
105  aList.emplace_back( _( "Type" ), _( "Marker" ), DARKCYAN );
106  aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage(), RED );
107 
108  wxString mainText;
109  wxString auxText;
110  EDA_ITEM* mainItem = nullptr;
111  EDA_ITEM* auxItem = nullptr;
112 
113  if( m_rcItem->GetMainItemID() != niluuid )
114  mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
115 
116  if( m_rcItem->GetAuxItemID() != niluuid )
117  auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
118 
119  if( mainItem )
120  mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
121 
122  if( auxItem )
123  auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
124 
125  aList.emplace_back( mainText, auxText, DARKBROWN );
126 }
127 
128 
129 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
130 {
131  RotatePoint( &m_Pos, aRotCentre, aAngle );
132 }
133 
134 
135 void MARKER_PCB::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
136 {
137  if( aFlipLeftRight )
138  m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
139  else
140  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
141 }
142 
143 
144 wxString MARKER_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
145 {
146  // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
147  // for menu duty.
148  return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
149 }
150 
151 
153 {
154  return drc_xpm;
155 }
156 
157 
158 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
159 {
160  aCount = 1;
161 
162  if( IsExcluded() )
163  {
164  aLayers[0] = LAYER_DRC_EXCLUSION;
165  return;
166  }
167 
168  BOARD_ITEM_CONTAINER* ancestor = GetParent();
169 
170  while( ancestor->GetParent() )
171  ancestor = ancestor->GetParent();
172 
173  BOARD* board = static_cast<BOARD*>( ancestor );
174 
175  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
176  {
177  default:
178  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
179  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
180  }
181 }
182 
183 
185 {
186  if( IsExcluded() )
187  return LAYER_DRC_EXCLUSION;
188 
189  BOARD_ITEM_CONTAINER* ancestor = GetParent();
190 
191  while( ancestor->GetParent() )
192  ancestor = ancestor->GetParent();
193 
194  BOARD* board = static_cast<BOARD*>( ancestor );
195 
196  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
197  {
198  default:
201  }
202 }
203 
204 
206 {
207  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
208  return colors->GetColor( GetColorLayer() );
209 }
210 
211 
213 {
215 
216  wxPoint pos = m_Pos;
217  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
218  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
219 
220  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
221  int( bbox.GetHeight() * MarkerScale() ) ) );
222 }
223 
224 
226 {
227  EDA_RECT bbox = GetBoundingBox();
228  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
229 }
230 
231 
EDA_UNITS
Definition: common.h:198
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
virtual EDA_ITEM * GetItem(const KIID &aId)
Fetch an item by KIID.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:522
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
PNG memory record (file in memory).
Definition: bitmap_def.h:29
Implementation of conversion functions that require both schematic and board internal units.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
MARKER_PCB(DRC_ITEM *aItem, const wxPoint &aPosition)
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
GAL_LAYER_ID GetColorLayer() const
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
wxPoint m_Pos
position of the marker
Definition: marker_base.h:59
int GetWidth() const
Definition: eda_rect.h:119
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
wxString AsString() const
Definition: common.cpp:165
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:553
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:144
The base class for create windows for drawing purpose.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
wxString GetErrorText() const
Definition: rc_item.h:165
Classes used in Pcbnew, CvPcb and GerbView.
RC_ITEM * m_rcItem
Definition: marker_base.h:64
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Definition: common.h:68
Markers used to show a drc problem on boards.
PCB_LAYER_ID
A quick note on layer IDs:
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
EDA_RECT m_shapeBoundingBox
Definition: marker_base.h:68
KIID niluuid(0)
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
KIID GetAuxItemID() const
Definition: rc_item.h:140
int GetErrorCode() const
Definition: rc_item.h:156
Functions to provide common constants and other functions to assist in making a consistent UI.
static DRC_ITEM * Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
bool IsExcluded() const
Definition: marker_base.h:108
Definition: color4d.h:59
int GetHeight() const
Definition: eda_rect.h:120
KIGFX::COLOR4D getColor() const override
layer for drc markers which have been individually excluded
layer for drc markers with SEVERITY_WARNING
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition: marker_base.h:80
const BOX2I ViewBBox() const override
Function ViewBBox() returns the bounding box of the item covering all its layers.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
see class PGM_BASE
void Rotate(const wxPoint &aRotCentre, double aAngle) override
Function Rotate Rotate this object.
Board layer functions and definitions.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
#define _(s)
Definition: 3d_actions.cpp:33
virtual wxString GetSelectMenuText(EDA_UNITS aUnits) const
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
static MARKER_PCB * Deserialize(const wxString &data)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
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: base_struct.h:159
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...
wxString Serialize() const
const BITMAP_OPAQUE drc_xpm[1]
wxString GetSettingsKey() const
Definition: rc_item.h:170
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
KIID GetMainItemID() const
Definition: rc_item.h:139
Abstract interface for BOARD_ITEMs capable of storing other items inside.
int GetSeverity(int aDRCErrorCode)
BOARD_ITEM_CONTAINER * GetParent() const
static VRML_COLOR colors[VRML_COLOR_LAST]
virtual wxString GetErrorMessage() const
Function GetErrorMessage returns the error message of a RC_ITEM.
Definition: rc_item.cpp:36
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
layer for drc markers with SEVERITY_ERROR
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99