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 <trigo.h>
34 #include <msgpanel.h>
35 #include <bitmaps.h>
36 #include <base_units.h>
37 #include <pcbnew.h>
38 #include <class_marker_pcb.h>
40 
41 
43 #define SCALING_FACTOR Millimeter2iu( 0.1 )
44 
46  BOARD_ITEM( aParent, PCB_MARKER_T ),
47  MARKER_BASE( SCALING_FACTOR ), m_item( nullptr )
48 {
49  m_Color = WHITE;
50 }
51 
52 
53 MARKER_PCB::MARKER_PCB( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
54  BOARD_ITEM* aItem, const wxPoint& aPos,
55  BOARD_ITEM* bItem, const wxPoint& bPos ) :
56  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
57  MARKER_BASE( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos, SCALING_FACTOR ), m_item( nullptr )
58 {
59  m_Color = WHITE;
60 }
61 
62 
63 MARKER_PCB::MARKER_PCB( int aErrorCode, const wxPoint& aMarkerPos,
64  const wxString& aText, const wxPoint& aPos,
65  const wxString& bText, const wxPoint& bPos ) :
66  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
67  MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos, bText, bPos, SCALING_FACTOR ), m_item( nullptr )
68 {
69  m_Color = WHITE;
70 }
71 
72 
73 /* destructor */
75 {
76 }
77 
78 /* tests to see if this object is on the given layer.
79  * DRC markers are not really on a copper layer, but
80  * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
81  * because this test is often used to locad a marker
82  * param aLayer The layer to test for.
83  * return bool - true if on given layer, else false.
84  */
85 bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
86 {
87  return IsCopperLayer( aLayer );
88 }
89 
90 void MARKER_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
91 {
92  wxString errorTxt, txtA, txtB;
93 
94  aList.emplace_back( MSG_PANEL_ITEM( _( "Type" ), _( "Marker" ), DARKCYAN ) );
95 
96  errorTxt.Printf( _( "ErrType (%d)- %s:" ), m_drc.GetErrorCode(), m_drc.GetErrorText() );
97 
98  aList.emplace_back( MSG_PANEL_ITEM( errorTxt, wxEmptyString, RED ) );
99 
100  txtA.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointA() ), m_drc.GetTextA() );
101 
102  if( m_drc.HasSecondItem() )
103  txtB.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointB() ), m_drc.GetTextB() );
104 
105  aList.emplace_back( MSG_PANEL_ITEM( txtA, txtB, DARKBROWN ) );
106 }
107 
108 
109 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
110 {
111  RotatePoint( &m_Pos, aRotCentre, aAngle );
112 }
113 
114 
115 void MARKER_PCB::Flip(const wxPoint& aCentre, bool aFlipLeftRight )
116 {
117  if( aFlipLeftRight )
118  m_Pos.x = aCentre.x - ( m_Pos.x - aCentre.x );
119  else
120  m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y );
121 }
122 
123 
125 {
126  return wxString::Format( _( "Marker @(%s, %s)" ),
127  MessageTextFromValue( aUnits, m_Pos.x ),
128  MessageTextFromValue( aUnits, m_Pos.y ) );
129 }
130 
131 
132 BITMAP_DEF MARKER_PCB::GetMenuImage() const
133 {
134  return drc_xpm;
135 }
136 
137 
138 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
139 {
140  aCount = 1;
141  aLayers[0] = LAYER_DRC;
142 }
143 
145 {
147 
148  wxPoint pos = m_Pos;
149  pos.x += int( bbox.GetOrigin().x * MarkerScale() );
150  pos.y += int( bbox.GetOrigin().y * MarkerScale() );
151 
152  return EDA_RECT( pos, wxSize( int( bbox.GetWidth() * MarkerScale() ),
153  int( bbox.GetHeight() * MarkerScale() ) ) );
154 }
155 
156 
158 {
159  EDA_RECT bbox = GetBoundingBox();
160  return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) );
161 }
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
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:232
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:229
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:203
const wxString & GetTextA() const
Definition: drc_item.h:214
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
#define _(s)
int GetHeight() const
Definition: eda_rect.h:118
const wxPoint & GetPointA() const
Definition: drc_item.h:226
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:176
MARKER_PCB(BOARD_ITEM *aParent)
bool HasSecondItem() const
Definition: drc_item.h:167
const wxString & GetTextB() const
Definition: drc_item.h:220
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:97
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
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Function Flip Flip this object, i.e.
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:154