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 <trigo.h>
29 #include <msgpanel.h>
30 #include <bitmaps.h>
31 #include <base_units.h>
32 #include <class_board.h>
33 #include <class_board_item.h>
34 #include <class_marker_pcb.h>
38 #include <widgets/ui_common.h>
39 #include <pgm_base.h>
40 #include <drc/drc_item.h>
41 
42 
44 #define SCALING_FACTOR Millimeter2iu( 0.1 )
45 
46 
47 MARKER_PCB::MARKER_PCB( DRC_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 MARKER_PCB::Serialize() const
65 {
66  return wxString::Format( wxT( "%s|%d|%d|%s|%s" ),
68  m_Pos.x,
69  m_Pos.y,
72 }
73 
74 
75 MARKER_PCB* MARKER_PCB::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  DRC_ITEM* drcItem = new DRC_ITEM( props[0] );
82  drcItem->SetItems( KIID( props[3] ), KIID( props[4] ) );
83 
84  return new MARKER_PCB( drcItem, markerPos );
85 }
86 
87 
88 /* tests to see if this object is on the given layer.
89  * DRC markers are not really on a copper layer, but
90  * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
91  * because this test is often used to locad a marker
92  * param aLayer The layer to test for.
93  * return bool - true if on given layer, else false.
94  */
95 bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
96 {
97  return IsCopperLayer( aLayer );
98 }
99 
100 
101 void MARKER_PCB::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
102 {
103  aList.emplace_back( _( "Type" ), _( "Marker" ), DARKCYAN );
104  aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage(), RED );
105 
106  wxString mainText;
107  wxString auxText;
108  EDA_ITEM* mainItem = nullptr;
109  EDA_ITEM* auxItem = nullptr;
110 
111  if( m_rcItem->GetMainItemID() != niluuid )
112  mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
113 
114  if( m_rcItem->GetAuxItemID() != niluuid )
115  auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
116 
117  if( mainItem )
118  mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
119 
120  if( auxItem )
121  auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
122 
123  aList.emplace_back( mainText, auxText, DARKBROWN );
124 }
125 
126 
127 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
128 {
129  RotatePoint( &m_Pos, aRotCentre, aAngle );
130 }
131 
132 
133 void MARKER_PCB::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
134 {
135  if( aFlipLeftRight )
136  m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
137  else
138  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
139 }
140 
141 
142 wxString MARKER_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
143 {
144  // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
145  // for menu duty.
146  return wxString::Format( _( "Marker (%s)" ),
148 }
149 
150 
152 {
153  return drc_xpm;
154 }
155 
156 
157 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
158 {
159  aCount = 1;
160 
161  BOARD_ITEM_CONTAINER* ancestor = GetParent();
162 
163  while( ancestor->GetParent() )
164  ancestor = ancestor->GetParent();
165 
166  BOARD* board = static_cast<BOARD*>( ancestor );
167 
168  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
169  {
170  default:
171  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
172  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
173  }
174 }
175 
176 
178 {
179  if( IsExcluded() )
180  return LAYER_AUX_ITEMS;
181 
182  BOARD_ITEM_CONTAINER* ancestor = GetParent();
183 
184  while( ancestor->GetParent() )
185  ancestor = ancestor->GetParent();
186 
187  BOARD* board = static_cast<BOARD*>( ancestor );
188 
189  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
190  {
191  default:
194  }
195 }
196 
197 
199 {
200  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
201  return colors->GetColor( GetColorLayer() );
202 }
203 
204 
206 {
208 
209  wxPoint pos = m_Pos;
210  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
211  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
212 
213  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
214  int( bbox.GetHeight() * MarkerScale() ) ) );
215 }
216 
217 
219 {
220  EDA_RECT bbox = GetBoundingBox();
221  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
222 }
223 
224 
EDA_UNITS
Definition: common.h:196
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:521
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,...
Classes BOARD_ITEM and BOARD_CONNECTED_ITEM.
MARKER_PCB(DRC_ITEM *aItem, const wxPoint &aPosition)
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:157
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:542
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
void SetParent(MARKER_BASE *aMarker)
Definition: rc_item.h:126
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...
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:
Auxiliary items (guides, rule, etc)
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:124
int GetErrorCode() const
Definition: rc_item.h:138
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsExcluded() const
Definition: marker_base.h:108
Definition: colors.h:60
int GetHeight() const
Definition: eda_rect.h:120
KIGFX::COLOR4D getColor() const override
layer for drc markers with SEVERITY_WARNING
virtual wxString GetErrorText(int aCode=-1, bool aTranslate=true) const =0
Function GetErrorText returns the string form of a RC error code.
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:181
#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:163
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]
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:123
Abstract interface for BOARD_ITEMs capable of storing other items inside.
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr)
Definition: rc_item.h:109
int GetSeverity(int aDRCErrorCode)
Message panel definition file.
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:40