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 <sch_edit_frame.h>
25 #include <kiface_base.h>
26 #include <bitmaps.h>
28 #include <schematic.h>
29 #include <connection_graph.h>
30 #include <tools/ee_actions.h>
31 #include <tool/tool_manager.h>
32 #include <panel_setup_pinmap.h>
33 #include <erc.h>
34 #include <id.h>
35 #include <wx/bmpbuttn.h>
36 #include <wx/statline.h>
37 #include <wx/stattext.h>
38 
39 
40 // Control identifiers for events
41 #define ID_MATRIX_0 1800
42 
43 
44 BEGIN_EVENT_TABLE( PANEL_SETUP_PINMAP, PANEL_SETUP_PINMAP_BASE )
47  wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
48 END_EVENT_TABLE()
49 
50 
51 PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
52  PANEL_SETUP_PINMAP_BASE( aWindow ),
53  m_buttonList(),
54  m_initialized( false )
55 {
56  m_parent = parent;
57  m_schematic = &parent->Schematic();
58 
59  reBuildMatrixPanel();
60 }
61 
62 
64 {
67 }
68 
69 
71 {
72  // Try to know the size of bitmap button used in drc matrix
73  wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( BITMAPS::ercerr ) );
74  wxSize bmapSize = dummy->GetSize();
75  delete dummy;
76 
77  wxSize charSize = KIUI::GetTextSize( "X", m_matrixPanel );
78  wxPoint pos( 0, charSize.y * 2 );
79  wxStaticText* text;
80 
81 #ifdef __WXMAC__
82  bmapSize.y += 2;
83  charSize.y += 2;
84 #endif
85 
86  if( !m_initialized )
87  {
88  std::vector<wxStaticText*> labels;
89 
90  // Print row labels
91  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
92  {
93  int y = pos.y + (ii * bmapSize.y);
94  text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
95  wxPoint( 5, y + ( bmapSize.y / 2 ) - ( 12 / 2 ) ) );
96  labels.push_back( text );
97 
98  int x = text->GetRect().GetRight();
99  pos.x = std::max( pos.x, x );
100  }
101 
102  // Right-align
103  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
104  {
105  wxPoint labelPos = labels[ ii ]->GetPosition();
106  labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
107  labels[ ii ]->SetPosition( labelPos );
108  }
109 
110  pos.x += 5;
111  }
112  else
113  {
114  pos = m_buttonList[0][0]->GetPosition();
115  }
116 
117  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
118  {
119  int y = pos.y + (ii * bmapSize.y);
120 
121  for( int jj = 0; jj <= ii; jj++ )
122  {
123  // Add column labels (only once)
124  PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
125 
126  int x = pos.x + ( jj * ( bmapSize.x + 2 ) );
127 
128  if( ( ii == jj ) && !m_initialized )
129  {
130  wxPoint textPos( x + KiROUND( bmapSize.x / 2 ) - KiROUND( charSize.x ),
131  y - charSize.y * 2 );
132  new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
133 
134  wxPoint calloutPos( x + KiROUND( bmapSize.x / 2 ) - KiROUND( charSize.x / 2 ),
135  y - charSize.y );
136  new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
137  }
138 
139  int event_id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
140  BITMAPS bitmap_butt = BITMAPS::erc_green;
141 
142  delete m_buttonList[ii][jj];
143  wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, event_id,
144  KiBitmap( bitmap_butt ), wxPoint( x, y ) );
145 
146 #ifdef __WXMAC__
147  btn->SetSize( btn->GetSize().x - 1, btn->GetSize().y );
148 #else
149  btn->SetSize( btn->GetSize().x + 4, btn->GetSize().y );
150 #endif
151  m_buttonList[ii][jj] = btn;
152  setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
153  }
154  }
155 
156  m_initialized = true;
157 }
158 
159 
160 void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxBitmapButton *aButton, PIN_ERROR aState )
161 {
162  BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
163  wxString tooltip;
164 
165  switch( aState )
166  {
167  case PIN_ERROR::OK:
168  bitmap_butt = BITMAPS::erc_green;
169  tooltip = _( "No error or warning" );
170  break;
171 
172  case PIN_ERROR::WARNING:
173  bitmap_butt = BITMAPS::ercwarn;
174  tooltip = _( "Generate warning" );
175  break;
176 
177  case PIN_ERROR::PP_ERROR:
178  bitmap_butt = BITMAPS::ercerr;
179  tooltip = _( "Generate error" );
180  break;
181 
182  default:
183  break;
184  }
185 
186  if( !!bitmap_butt )
187  {
188  aButton->SetBitmap( KiBitmap( bitmap_butt ) );
189  aButton->SetToolTip( tooltip );
190  }
191 }
192 
193 
194 void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
195 {
196  int id = event.GetId();
197  int ii = id - ID_MATRIX_0;
198  int x = ii / ELECTRICAL_PINTYPES_TOTAL;
199  int y = ii % ELECTRICAL_PINTYPES_TOTAL;
200  wxBitmapButton* butt = (wxBitmapButton*) event.GetEventObject();
201 
202  int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
203  level = ( level + 1 ) % 3;
204 
205  setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
206 
207  m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
208  m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
209 }
210 
211 
213 {
214  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
215  {
216  for( int jj = 0; jj <= ii; jj++ )
217  setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
218  }
219 }
220 
221 
void ResetPanel() override
Reset the contents of this panel.
void setDRCMatrixButtonState(wxBitmapButton *aButton, PIN_ERROR aState)
Class PANEL_SETUP_PINMAP_BASE.
const wxString CommentERC_H[]
Definition: erc.cpp:57
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:85
Schematic editor (Eeschema) main window.
void ResetPinMap()
#define ID_MATRIX_0
void ImportSettingsFrom(PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL])
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
wxBitmapButton * m_buttonList[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
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:67
Definition of file extensions used in Kicad.
#define _(s)
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
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:32
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Definition: erc_settings.h:146
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:73
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:134
void changeErrorLevel(wxCommandEvent &event)
const wxString CommentERC_V[]
Definition: erc.cpp:74
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:174
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:53