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) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
10  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
11  * Copyright (C) 1992-2012 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 Mils2iu( 3 )
46 
47 
49  BOARD_ITEM( aParent, PCB_MARKER_T ),
50  MARKER_BASE(), m_item( nullptr )
51 {
52  m_Color = WHITE;
54 }
55 
56 
57 MARKER_PCB::MARKER_PCB( EDA_UNITS_T aUnits, int aErrorCode, const wxPoint& aMarkerPos,
58  BOARD_ITEM* aItem, const wxPoint& aPos,
59  BOARD_ITEM* bItem, const wxPoint& bPos ) :
60  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
61  MARKER_BASE( aUnits, aErrorCode, aMarkerPos, aItem, aPos, bItem, bPos ), m_item( nullptr )
62 {
63  m_Color = WHITE;
65 }
66 
67 
68 MARKER_PCB::MARKER_PCB( int aErrorCode, const wxPoint& aMarkerPos,
69  const wxString& aText, const wxPoint& aPos,
70  const wxString& bText, const wxPoint& bPos ) :
71  BOARD_ITEM( nullptr, PCB_MARKER_T ), // parent set during BOARD::Add()
72  MARKER_BASE( aErrorCode, aMarkerPos, aText, aPos, bText, bPos ), m_item( nullptr )
73 {
74  m_Color = WHITE;
76 }
77 
78 
79 /* destructor */
81 {
82 }
83 
84 /* tests to see if this object is on the given layer.
85  * DRC markers are not really on a copper layer, but
86  * MARKER_PCB::IsOnCopperLayer return true if aLayer is a cooper layer,
87  * because this test is often used to locad a marker
88  * param aLayer The layer to test for.
89  * return bool - true if on given layer, else false.
90  */
91 bool MARKER_PCB::IsOnLayer( PCB_LAYER_ID aLayer ) const
92 {
93  return IsCopperLayer( aLayer );
94 }
95 
96 void MARKER_PCB::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
97 {
98  wxString errorTxt, txtA, txtB;
99 
100  aList.emplace_back( MSG_PANEL_ITEM( _( "Type" ), _( "Marker" ), DARKCYAN ) );
101 
102  errorTxt.Printf( _( "ErrType (%d)- %s:" ), m_drc.GetErrorCode(), m_drc.GetErrorText() );
103 
104  aList.emplace_back( MSG_PANEL_ITEM( errorTxt, wxEmptyString, RED ) );
105 
106  txtA.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointA() ), m_drc.GetTextA() );
107 
108  if( m_drc.HasSecondItem() )
109  txtB.Printf( wxT( "%s: %s" ), DRC_ITEM::ShowCoord( aUnits, m_drc.GetPointB() ), m_drc.GetTextB() );
110 
111  aList.emplace_back( MSG_PANEL_ITEM( txtA, txtB, DARKBROWN ) );
112 }
113 
114 
115 void MARKER_PCB::Rotate(const wxPoint& aRotCentre, double aAngle)
116 {
117  RotatePoint( &m_Pos, aRotCentre, aAngle );
118 }
119 
120 
121 void MARKER_PCB::Flip(const wxPoint& aCentre )
122 {
123  m_Pos.y = aCentre.y - (m_Pos.y - aCentre.y);
124 }
125 
126 
128 {
129  return wxString::Format( _( "Marker @(%s, %s)" ),
130  MessageTextFromValue( aUnits, m_Pos.x ),
131  MessageTextFromValue( aUnits, m_Pos.y ) );
132 }
133 
134 
136 {
137  return drc_xpm;
138 }
139 
140 
141 void MARKER_PCB::ViewGetLayers( int aLayers[], int& aCount ) const
142 {
143  aCount = 1;
144  aLayers[0] = LAYER_DRC;
145 }
146 
148 {
149  return EDA_RECT( m_Pos, wxSize( 1300000, 1300000 ) );
150 }
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
PNG memory record (file in memory).
Definition: bitmap_types.h:41
void Flip(const wxPoint &aCentre) override
Function Flip Flip this object, i.e.
bool HasSecondItem() const
Definition: drc_item.h:155
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...
wxString GetErrorText() const
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:36
int GetErrorCode() const
Function GetErrorCode returns the error code.
Definition: drc_item.h:191
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:54
const wxPoint & GetPointB() const
Definition: drc_item.h:220
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:216
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
const BOARD_ITEM * m_item
Pointer to BOARD_ITEM that causes DRC error.
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;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:
#define SCALING_FACTOR
Adjust the actual size of markers, when using default shape.
COLOR4D m_Color
color
Definition: marker_base.h:61
int m_ScalingFactor
Scaling factor for m_Size and m_Corners (can set the physical size)
Definition: marker_base.h:55
Definition: colors.h:60
static wxString ShowCoord(EDA_UNITS_T aUnits, const wxPoint &aPos)
Function ShowCoord formats a coordinate or position to text.
Definition: drc_item.cpp:148
MARKER_PCB(BOARD_ITEM *aParent)
const wxString & GetTextA() const
Definition: drc_item.h:202
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.
const wxPoint & GetPointA() const
Definition: drc_item.h:214
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
const wxString & GetTextB() const
Definition: drc_item.h:208
Message panel definition file.
DRC_ITEM m_drc
Definition: marker_base.h:65
EDA_UNITS_T
Definition: common.h:159