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 <fctsys.h>
25 #include <gestfich.h>
26 #include <pgm_base.h>
27 #include <sch_edit_frame.h>
28 #include <project.h>
29 #include <kiface_i.h>
30 #include <bitmaps.h>
31 #include <reporter.h>
33 #include <netlist_object.h>
34 #include <lib_pin.h>
35 #include <sch_component.h>
36 #include <connection_graph.h>
37 #include <tools/ee_actions.h>
38 #include <tool/tool_manager.h>
39 #include <panel_setup_pinmap.h>
40 #include <erc.h>
41 #include <id.h>
42 #include <widgets/wx_angle_text.h>
43 
46 
47 
48 bool PANEL_SETUP_PINMAP::m_diagErcTableInit = false; // saved only for the current session
49 
50 // Control identifiers for events
51 #define ID_MATRIX_0 1800
52 
53 
54 BEGIN_EVENT_TABLE( PANEL_SETUP_PINMAP, PANEL_SETUP_PINMAP_BASE )
57  wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::ChangeErrorLevel )
58 END_EVENT_TABLE()
59 
60 
61 PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
62  PANEL_SETUP_PINMAP_BASE( aWindow ),
63  m_buttonList(),
64  m_initialized( false )
65 {
66  m_parent = parent;
67 
68  wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
69  infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
70 
71  ReBuildMatrixPanel();
72 }
73 
74 
75 void PANEL_SETUP_PINMAP::OnResetMatrixClick( wxCommandEvent& aEvent )
76 {
77  memcpy( PinMap, DefaultPinMap, sizeof( PinMap ) );
79 }
80 
81 
83 {
84  // Try to know the size of bitmap button used in drc matrix
85  wxBitmapButton * dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( ercerr_xpm ) );
86  wxSize bitmap_size = dummy->GetSize();
87  delete dummy;
88 
89  if( !m_diagErcTableInit )
90  {
91  memcpy( PinMap, DefaultPinMap, sizeof(DefaultPinMap) );
92  m_diagErcTableInit = true;
93  }
94 
95  wxPoint pos;
96  // Get the current text size using a dummy text.
97  wxStaticText* text = new wxStaticText( m_matrixPanel, -1, CommentERC_V[0], pos );
98  int text_width = text->GetRect().GetWidth();
99  int text_height = text->GetRect().GetHeight();
100 
101  bitmap_size.y = std::max( bitmap_size.y, text_height );
102  delete text;
103 
104  // compute the Y pos interval:
105  pos.y = text_height + ( text_width / 2 );
106 
107  if( !m_initialized )
108  {
109  std::vector<wxStaticText*> labels;
110 
111  // Print row labels
112  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
113  {
114  int y = pos.y + (ii * bitmap_size.y);
115  text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
116  wxPoint( 5, y + ( bitmap_size.y / 2) - (text_height / 2) ) );
117  labels.push_back( text );
118 
119  int x = text->GetRect().GetRight();
120  pos.x = std::max( pos.x, x );
121  }
122 
123  // Right-align
124  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
125  {
126  wxPoint labelPos = labels[ ii ]->GetPosition();
127  labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
128  labels[ ii ]->SetPosition( labelPos );
129  }
130 
131  pos.x += 5;
132  }
133  else
134  pos = m_buttonList[0][0]->GetPosition();
135 
136  for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
137  {
138  int y = pos.y + (ii * bitmap_size.y);
139 
140  for( int jj = 0; jj <= ii; jj++ )
141  {
142  // Add column labels (only once)
143  int diag = PinMap[ii][jj];
144  int x = pos.x + ( jj * ( bitmap_size.x + 4 ) );
145 
146  if( (ii == jj) && !m_initialized )
147  {
148  wxPoint txtpos;
149  txtpos.x = x + (bitmap_size.x / 2);
150  txtpos.y = y - text_height;
151  new WX_ANGLE_TEXT( m_matrixPanel, wxID_ANY, CommentERC_V[ii],
152  txtpos, 450 );
153  }
154 
155  int event_id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
156  BITMAP_DEF bitmap_butt = erc_green_xpm;
157 
158  delete m_buttonList[ii][jj];
159  wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, event_id,
160  KiBitmap( bitmap_butt ), wxPoint( x, y ) );
161  btn->SetSize( btn->GetSize().x + 4, btn->GetSize().y );
162  m_buttonList[ii][jj] = btn;
163  setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
164  }
165  }
166 
167  m_initialized = true;
168 }
169 
170 
171 bool PANEL_SETUP_PINMAP::Show( bool show )
172 {
173  wxPanel::Show( show );
174 
175  // For some reason the angle text doesn't get drawn if the paint events are fired while
176  // it's not the active tab.
177  if( show )
178  {
179  for( wxWindow* win : m_matrixPanel->GetChildren() )
180  {
181  WX_ANGLE_TEXT* angleText = dynamic_cast<WX_ANGLE_TEXT*>( win );
182 
183  if( angleText )
184  angleText->Refresh();
185  }
186  }
187 
188  return true;
189 }
190 
191 
192 void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxBitmapButton *aButton, int aState )
193 {
194  BITMAP_DEF bitmap_butt = nullptr;
195  wxString tooltip;
196 
197  switch( aState )
198  {
199  case OK:
200  bitmap_butt = erc_green_xpm;
201  tooltip = _( "No error or warning" );
202  break;
203 
204  case WAR:
205  bitmap_butt = ercwarn_xpm;
206  tooltip = _( "Generate warning" );
207  break;
208 
209  case ERR:
210  bitmap_butt = ercerr_xpm;
211  tooltip = _( "Generate error" );
212  break;
213 
214  default:
215  break;
216  }
217 
218  if( bitmap_butt )
219  {
220  aButton->SetBitmap( KiBitmap( bitmap_butt ) );
221  aButton->SetToolTip( tooltip );
222  }
223 }
224 
225 
226 void PANEL_SETUP_PINMAP::ChangeErrorLevel( wxCommandEvent& event )
227 {
228  int id = event.GetId();
229  int ii = id - ID_MATRIX_0;
230  int x = ii / ELECTRICAL_PINTYPES_TOTAL;
231  int y = ii % ELECTRICAL_PINTYPES_TOTAL;
232  wxBitmapButton* butt = (wxBitmapButton*) event.GetEventObject();
233 
234  int level = ( PinMap[y][x] + 1 ) % 3;
235 
236  setDRCMatrixButtonState( butt, level );
237 
238  PinMap[y][x] = PinMap[x][y] = level;
239 }
240 
241 
Definition: erc.h:49
PNG memory record (file in memory).
Definition: bitmap_def.h:29
This file is part of the common library TODO brief description.
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
const wxString CommentERC_V[]
void OnResetMatrixClick(wxCommandEvent &aEvent) override
const wxString CommentERC_H[]
Class PANEL_SETUP_PINMAP_BASE.
int PinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Schematic editor (Eeschema) main window.
void ChangeErrorLevel(wxCommandEvent &event)
int DefaultPinMap[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Default Look up table which gives the ERC error level for a pair of connected pins Same as DiagErc,...
#define ID_MATRIX_0
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:80
Definition: erc.h:50
void setDRCMatrixButtonState(wxBitmapButton *aButton, int aState)
Definition of file extensions used in Kicad.
const BITMAP_OPAQUE ercerr_xpm[1]
Definition: ercerr.cpp:24
const BITMAP_OPAQUE erc_green_xpm[1]
Definition: erc_green.cpp:24
see class PGM_BASE
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define _(s)
Definition: 3d_actions.cpp:33
bool Show(bool show) override
const BITMAP_OPAQUE ercwarn_xpm[1]
Definition: ercwarn.cpp:68
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:54
Definition of the NETLIST_OBJECT class.
static bool m_diagErcTableInit