KiCad PCB EDA Suite
panel_setup_pinmap.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) 2020 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include <pgm_base.h>
25 #include <sch_edit_frame.h>
26 #include <kiface_i.h>
27 #include <bitmaps.h>
29 #include <schematic.h>
30 #include <connection_graph.h>
31 #include <tools/ee_actions.h>
32 #include <tool/tool_manager.h>
33 #include <panel_setup_pinmap.h>
34 #include <erc.h>
35 #include <id.h>
36 #include <wx/statline.h>
37 
38 
39 // Control identifiers for events
40 #define ID_MATRIX_0 1800
41 
42 
43 BEGIN_EVENT_TABLE( PANEL_SETUP_PINMAP, PANEL_SETUP_PINMAP_BASE )
46  wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
47 END_EVENT_TABLE()
48 
49 
50 PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
51  PANEL_SETUP_PINMAP_BASE( aWindow ),
52  m_buttonList(),
53  m_initialized( false )
54 {
55  m_parent = parent;
56  m_schematic = &parent->Schematic();
57 
58  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
59  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
60 
61  reBuildMatrixPanel();
62 }
63 
64 
66 {
69 }
70 
71 
73 {
74  // Try to know the size of bitmap button used in drc matrix
75  wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( ercerr_xpm ) );
76  wxSize bmapSize = dummy->GetSize();
77  delete dummy;
78 
79  wxSize charSize = KIUI::GetTextSize( "X", m_matrixPanel );
80  wxPoint pos( 0, charSize.y * 2 );
81  wxStaticText* text;
82 
83  if( !m_initialized )
84  {
85  std::vector<wxStaticText*> labels;
86 
87  // Print row labels
88  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
89  {
90  int y = pos.y + (ii * bmapSize.y);
91  text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
92  wxPoint( 5, y + ( bmapSize.y / 2 ) - ( 12 / 2 ) ) );
93  labels.push_back( text );
94 
95  int x = text->GetRect().GetRight();
96  pos.x = std::max( pos.x, x );
97  }
98 
99  // Right-align
100  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
101  {
102  wxPoint labelPos = labels[ ii ]->GetPosition();
103  labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
104  labels[ ii ]->SetPosition( labelPos );
105  }
106 
107  pos.x += 5;
108  }
109  else
110  pos = m_buttonList[0][0]->GetPosition();
111 
112  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
113  {
114  int y = pos.y + (ii * bmapSize.y);
115 
116  for( int jj = 0; jj <= ii; jj++ )
117  {
118  // Add column labels (only once)
119  PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
120 
121  int x = pos.x + ( jj * ( bmapSize.x + 4 ) );
122 
123  if( ( ii == jj ) && !m_initialized )
124  {
125  wxPoint textPos( x + KiROUND( bmapSize.x / 2 ) - KiROUND( charSize.x / 2 ),
126  y - charSize.y * 2 );
127  new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
128 
129  wxPoint calloutPos( x + KiROUND( bmapSize.x / 2 ) - 2,
130  y - charSize.y );
131  new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
132  }
133 
134  int event_id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
135  BITMAP_DEF bitmap_butt = erc_green_xpm;
136 
137  delete m_buttonList[ii][jj];
138  wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, event_id,
139  KiBitmap( bitmap_butt ), wxPoint( x, y ) );
140 
141  // On the mac, the button sizes are reliably 4 pixels smaller (maybe due to corner rounding)
142  // than can be displayed by the bitmap
143 #ifdef __WXMAC__
144  btn->SetSize( btn->GetSize().x + 8, btn->GetSize().y + 4 );
145 #else
146  btn->SetSize( btn->GetSize().x + 4, btn->GetSize().y );
147 #endif
148  m_buttonList[ii][jj] = btn;
149  setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
150  }
151  }
152 
153  m_initialized = true;
154 }
155 
156 
157 void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxBitmapButton *aButton, PIN_ERROR aState )
158 {
159  BITMAP_DEF bitmap_butt = nullptr;
160  wxString tooltip;
161 
162  switch( aState )
163  {
164  case PIN_ERROR::OK:
165  bitmap_butt = erc_green_xpm;
166  tooltip = _( "No error or warning" );
167  break;
168 
169  case PIN_ERROR::WARNING:
170  bitmap_butt = ercwarn_xpm;
171  tooltip = _( "Generate warning" );
172  break;
173 
174  case PIN_ERROR::PP_ERROR:
175  bitmap_butt = ercerr_xpm;
176  tooltip = _( "Generate error" );
177  break;
178 
179  default:
180  break;
181  }
182 
183  if( bitmap_butt )
184  {
185  aButton->SetBitmap( KiBitmap( bitmap_butt ) );
186  aButton->SetToolTip( tooltip );
187  }
188 }
189 
190 
191 void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
192 {
193  int id = event.GetId();
194  int ii = id - ID_MATRIX_0;
195  int x = ii / ELECTRICAL_PINTYPES_TOTAL;
196  int y = ii % ELECTRICAL_PINTYPES_TOTAL;
197  wxBitmapButton* butt = (wxBitmapButton*) event.GetEventObject();
198 
199  int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
200  level = ( level + 1 ) % 3;
201 
202  setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
203 
204  m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
205  m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
206 }
207 
208 
210 {
211  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
212  {
213  for( int jj = 0; jj <= ii; jj++ )
214  setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
215  }
216 }
217 
218 
void ResetPanel() override
Reset the contents of this panel.
PNG memory record (file in memory).
Definition: bitmap_def.h:29
const wxString CommentERC_V[]
void setDRCMatrixButtonState(wxBitmapButton *aButton, PIN_ERROR aState)
const wxString CommentERC_H[]
Class PANEL_SETUP_PINMAP_BASE.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:84
Schematic editor (Eeschema) main window.
void ResetPinMap()
#define ID_MATRIX_0
void ImportSettingsFrom(PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL])
wxBitmapButton * m_buttonList[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:58
Definition of file extensions used in Kicad.
const BITMAP_OPAQUE ercerr_xpm[1]
Definition: ercerr.cpp:50
const BITMAP_OPAQUE erc_green_xpm[1]
Definition: erc_green.cpp:23
EVT_COMMAND_RANGE(ID_MATRIX_0, ID_MATRIX_0+(ELECTRICAL_PINTYPES_TOTAL *ELECTRICAL_PINTYPES_TOTAL) - 1, wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel) PANEL_SETUP_PINMAP
see class PGM_BASE
#define _(s)
Definition: 3d_actions.cpp:33
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Definition: erc_settings.h:145
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:133
void changeErrorLevel(wxCommandEvent &event)
const BITMAP_OPAQUE ercwarn_xpm[1]
Definition: ercwarn.cpp:47
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:132
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:52