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 <bitmaps.h>
27 #include <base_units.h>
28 #include <pcb_base_frame.h>
29 #include <class_board.h>
30 #include <class_marker_pcb.h>
34 #include <widgets/ui_common.h>
35 #include <pgm_base.h>
36 #include <drc/drc_item.h>
37 #include <trigo.h>
38 
39 
41 #define SCALING_FACTOR Millimeter2iu( 0.075 )
42 
43 
44 
45 MARKER_PCB::MARKER_PCB( std::shared_ptr<RC_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" ),
65  m_rcItem->GetSettingsKey(),
66  m_Pos.x,
67  m_Pos.y,
68  m_rcItem->GetMainItemID().AsString(),
69  m_rcItem->GetAuxItemID().AsString() );
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  std::shared_ptr<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 void MARKER_PCB::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
91 {
92  aList.emplace_back( _( "Type" ), _( "Marker" ), DARKCYAN );
93  aList.emplace_back( _( "Violation" ), m_rcItem->GetErrorMessage(), RED );
94 
95  wxString mainText;
96  wxString auxText;
97  EDA_ITEM* mainItem = nullptr;
98  EDA_ITEM* auxItem = nullptr;
99 
100  if( m_rcItem->GetMainItemID() != niluuid )
101  mainItem = aFrame->GetItem( m_rcItem->GetMainItemID() );
102 
103  if( m_rcItem->GetAuxItemID() != niluuid )
104  auxItem = aFrame->GetItem( m_rcItem->GetAuxItemID() );
105 
106  if( mainItem )
107  mainText = mainItem->GetSelectMenuText( aFrame->GetUserUnits() );
108 
109  if( auxItem )
110  auxText = auxItem->GetSelectMenuText( aFrame->GetUserUnits() );
111 
112  aList.emplace_back( mainText, auxText, DARKBROWN );
113 }
114 
115 
116 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
117 {
118  RotatePoint( &m_Pos, aRotCentre, aAngle );
119 }
120 
121 
122 void MARKER_PCB::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
123 {
124  if( aFlipLeftRight )
125  m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
126  else
127  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
128 }
129 
130 
131 wxString MARKER_PCB::GetSelectMenuText( EDA_UNITS aUnits ) const
132 {
133  // m_rcItem->GetErrorMessage() could be used instead, but is probably too long
134  // for menu duty.
135  return wxString::Format( _( "Marker (%s)" ), m_rcItem->GetErrorText() );
136 }
137 
138 
140 {
141  return drc_xpm;
142 }
143 
144 
145 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
146 {
147  aCount = 2;
148 
149  aLayers[1] = LAYER_MARKER_SHADOWS;
150 
151  if( IsExcluded() )
152  {
153  aLayers[0] = LAYER_DRC_EXCLUSION;
154  return;
155  }
156 
157  BOARD_ITEM_CONTAINER* ancestor = GetParent();
158 
159  while( ancestor->GetParent() )
160  ancestor = ancestor->GetParent();
161 
162  BOARD* board = static_cast<BOARD*>( ancestor );
163 
164  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
165  {
166  default:
167  case SEVERITY::RPT_SEVERITY_ERROR: aLayers[0] = LAYER_DRC_ERROR; break;
168  case SEVERITY::RPT_SEVERITY_WARNING: aLayers[0] = LAYER_DRC_WARNING; break;
169  }
170 }
171 
172 
174 {
175  if( IsExcluded() )
176  return LAYER_DRC_EXCLUSION;
177 
178  BOARD_ITEM_CONTAINER* ancestor = GetParent();
179 
180  while( ancestor->GetParent() )
181  ancestor = ancestor->GetParent();
182 
183  BOARD* board = static_cast<BOARD*>( ancestor );
184 
185  switch( board->GetDesignSettings().GetSeverity( m_rcItem->GetErrorCode() ) )
186  {
187  default:
190  }
191 }
192 
193 
195 {
196  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
197  return colors->GetColor( GetColorLayer() );
198 }
199 
200 
202 {
204 
205  wxPoint pos = m_Pos;
206  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
207  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
208 
209  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
210  int( bbox.GetHeight() * MarkerScale() ) ) );
211 }
212 
213 
215 {
216  EDA_RECT bbox = GetBoundingBox();
217  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
218 }
219 
220 
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
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:239
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,...
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:61
int GetWidth() const
Definition: eda_rect.h:119
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
const BITMAP_OPAQUE drc_xpm[1]
Definition: drc.cpp:90
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
The base class for create windows for drawing purpose.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Classes used in Pcbnew, CvPcb and GerbView.
Definition: kiid.h:44
Markers used to show a drc problem on boards.
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
std::shared_ptr< RC_ITEM > m_rcItem
Definition: marker_base.h:66
EDA_RECT m_shapeBoundingBox
Definition: marker_base.h:70
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
Functions to provide common constants and other functions to assist in making a consistent UI.
bool IsExcluded() const
Definition: marker_base.h:109
Definition: color4d.h:60
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
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:81
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:201
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
#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...
Definition: eda_item.cpp:123
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
MARKER_PCB(std::shared_ptr< RC_ITEM > aItem, const wxPoint &aPosition)
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
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
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.
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]
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:100