KiCad PCB EDA Suite
class_marker_pcb.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
10  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
11  * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, you may find one here:
25  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
26  * or you may search the http://www.gnu.org website for the version 2 license,
27  * or you may write to the Free Software Foundation, Inc.,
28  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29  */
30 
31 #include <fctsys.h>
32 #include <gr_basic.h>
33 #include <class_drawpanel.h>
34 #include <trigo.h>
35 #include <msgpanel.h>
36 #include <bitmaps.h>
37 #include <base_units.h>
38 
39 #include <pcbnew.h>
40 #include <class_marker_pcb.h>
42 
43 
45 #define SCALING_FACTOR Millimeter2iu( 0.1 )
46 
48  BOARD_ITEM( aParent, PCB_MARKER_T ),
49  MARKER_BASE( SCALING_FACTOR ), m_item( nullptr )
50 {
51  m_Color = WHITE;
52 }
53 
54 
55 MARKER_PCB::MARKER_PCB( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
56  BOARD_ITEM* aItem, const wxPoint& aPos,
57  BOARD_ITEM* bItem, const wxPoint& bPos ) :
58  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
59  MARKER_BASE( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos, SCALING_FACTOR ), m_item( nullptr )
60 {
61  m_Color = WHITE;
62 }
63 
64 
65 MARKER_PCB::MARKER_PCB( int aErrorCode, const wxPoint& aMarkerPos,
66  const wxString& aText, const wxPoint& aPos,
67  const wxString& bText, const wxPoint& bPos ) :
68  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
69  MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos, bText, bPos, SCALING_FACTOR ), m_item( nullptr )
70 {
71  m_Color = WHITE;
72 }
73 
74 
75 /* destructor */
77 {
78 }
79 
80 /* tests to see if this object is on the given layer.
81  * DRC markers are not really on a copper layer, but
82  * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
83  * because this test is often used to locad a marker
84  * param aLayer The layer to test for.
85  * return bool - true if on given layer, else false.
86  */
87 bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
88 {
89  return IsCopperLayer( aLayer );
90 }
91 
92 void MARKER_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
93 {
94  wxString errorTxt, txtA, txtB;
95 
96  aList.emplace_back( MSG_PANEL_ITEM( _( "Type" ), _( "Marker" ), DARKCYAN ) );
97 
98  errorTxt.Printf( _( "ErrType (%d)- %s:" ), m_drc.GetErrorCode(), m_drc.GetErrorText() );
99 
100  aList.emplace_back( MSG_PANEL_ITEM( errorTxt, wxEmptyString, RED ) );
101 
102  txtA.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointA() ), m_drc.GetTextA() );
103 
104  if( m_drc.HasSecondItem() )
105  txtB.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointB() ), m_drc.GetTextB() );
106 
107  aList.emplace_back( MSG_PANEL_ITEM( txtA, txtB, DARKBROWN ) );
108 }
109 
110 
111 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
112 {
113  RotatePoint( &m_Pos, aRotCentre, aAngle );
114 }
115 
116 
117 void MARKER_PCB::Flip(const wxPoint& aCentre )
118 {
119  m_Pos.y = aCentre.y - (m_Pos.y - aCentre.y);
120 }
121 
122 
124 {
125  return wxString::Format( _( "Marker @(%s, %s)" ),
126  MessageTextFromValue( aUnits, m_Pos.x ),
127  MessageTextFromValue( aUnits, m_Pos.y ) );
128 }
129 
130 
131 BITMAP_DEF MARKER_PCB::GetMenuImage() const
132 {
133  return drc_xpm;
134 }
135 
136 
137 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
138 {
139  aCount = 1;
140  aLayers[0] = LAYER_DRC;
141 }
142 
144 {
146 
147  wxPoint pos = m_Pos;
148  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
149  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
150 
151  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
152  int( bbox.GetHeight() * MarkerScale() ) ) );
153 }
154 
155 
157 {
158  EDA_RECT bbox = GetBoundingBox();
159  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
160 }
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
BOX2< VECTOR2I > BOX2I
Definition: box2.h:520
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
Implementation of conversion functions that require both schematic and board internal units.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
BITMAP_DEF GetMenuImage() const override
Function GetMenuImage returns a pointer to an image to be used in menus.
const wxPoint & GetPointB() const
Definition: drc_item.h:220
wxPoint m_Pos
position of the marker
Definition: marker_base.h:54
int GetWidth() const
Definition: eda_rect.h:117
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
wxString MessageTextFromValue(EDA_UNITS_T aUnits, int aValue, bool aUseMils)
Definition: base_units.cpp:125
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Function IsOnLayer tests to see if this object is on the given layer.
Markers used to show a drc problem on boards.
PCB_LAYER_ID
A quick note on layer IDs:
int GetErrorCode() const
Function GetErrorCode returns the error code.
Definition: drc_item.h:191
const wxString & GetTextA() const
Definition: drc_item.h:202
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
#define SCALING_FACTOR
Factor to convert the maker unit shape to internal units:
COLOR4D m_Color
color
Definition: marker_base.h:61
Definition: colors.h:60
EDA_RECT m_ShapeBoundingBox
Bounding box of the graphic symbol, relative to the position of the shape, in marker shape units.
Definition: marker_base.h:62
int GetHeight() const
Definition: eda_rect.h:118
const wxPoint & GetPointA() const
Definition: drc_item.h:214
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:152
MARKER_PCB(BOARD_ITEM *aParent)
bool HasSecondItem() const
Definition: drc_item.h:155
const wxString & GetTextB() const
Definition: drc_item.h:208
int MarkerScale() const
The scaling factor to convert polygonal shape coordinates to internal units.
Definition: marker_base.h:123
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
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
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
Definition: colors.h:49
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
Message panel definition file.
DRC_ITEM m_drc
Definition: marker_base.h:64
EDA_UNITS_T
Definition: common.h:160