KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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>
39
40
41// Control identifiers for events
42#define ID_MATRIX_0 1800
43
44
48 wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
49END_EVENT_TABLE()
50
51
52PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
53 PANEL_SETUP_PINMAP_BASE( aWindow ),
54 m_buttonList(),
55 m_initialized( false )
56{
57 m_parent = parent;
58 m_schematic = &parent->Schematic();
59 m_btnBackground = wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_WINDOW );
60
61 reBuildMatrixPanel();
62}
63
65{
66#ifndef __WXMAC__
67 if( m_initialized )
68 {
69 for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
70 {
71 for( int jj = 0; jj <= ii; jj++ )
72 {
73 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
75 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
77 }
78 }
79 }
80#endif
81}
82
83
85{
88}
89
90
91void PANEL_SETUP_PINMAP::OnMouseEnter( wxMouseEvent& aEvent )
92{
93 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
94 m_btnBackground = btn->GetBackgroundColour();
95
96 btn->SetBackgroundColour( wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_HIGHLIGHT ) );
97}
98
99
100void PANEL_SETUP_PINMAP::OnMouseLeave( wxMouseEvent& aEvent )
101{
102 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
103 btn->SetBackgroundColour( m_btnBackground );
104}
105
106
108{
109 // Try to know the size of bitmap button used in drc matrix
110 wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( BITMAPS::ercerr ),
111 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
112 wxSize bitmapSize = dummy->GetSize();
113 delete dummy;
114
115#ifdef __WXMAC__
116 const wxSize text_padding( 2, 1 );
117 const int twiddle = -1;
118#else
119 const wxSize text_padding( 8, 6 );
120 const int twiddle = 1;
121#endif
122
123 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
124 wxPoint pos( 0, charSize.y * 2 );
125 wxStaticText* text;
126
127 if( !m_initialized )
128 {
129 std::vector<wxStaticText*> labels;
130
131 // Print row labels
132 for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
133 {
134 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
135 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
136 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
137 labels.push_back( text );
138
139 int x = text->GetRect().GetRight();
140 pos.x = std::max( pos.x, x );
141 }
142
143 // Right-align
144 for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
145 {
146 wxPoint labelPos = labels[ ii ]->GetPosition();
147 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
148 labelPos.y += twiddle;
149 labels[ ii ]->SetPosition( labelPos );
150 }
151
152 pos.x += 5;
153 }
154 else
155 {
156 pos = m_buttonList[0][0]->GetPosition();
157 }
158
159 for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
160 {
161 int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
162
163 for( int jj = 0; jj <= ii; jj++ )
164 {
165 // Add column labels (only once)
167
168 int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
169
170 if( ( ii == jj ) && !m_initialized )
171 {
172 wxPoint textPos( x + KiROUND( bitmapSize.x / 2 ),
173 y - charSize.y * 2 );
174 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
175
176 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2 ),
177 y - charSize.y );
178 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
179 }
180
181 int id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
182 BITMAPS bitmap_butt = BITMAPS::erc_green;
183
184#ifdef __WXMAC__
185 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
186 wxPoint( x, y ), bitmapSize );
187#else
188 if( m_initialized )
189 {
190 m_buttonList[ii][jj]->Unbind(wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
191 m_buttonList[ii][jj]->Unbind(wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
192 }
193
194 wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, id, KiBitmap( bitmap_butt ),
195 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
196 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
197 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
198#endif
199 btn->SetSize( btn->GetSize() + text_padding );
200
201 delete m_buttonList[ii][jj];
202 m_buttonList[ii][jj] = btn;
203 setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
204 }
205 }
206
207 m_initialized = true;
208}
209
210
212{
213 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
214 wxString tooltip;
215
216 switch( aState )
217 {
218 case PIN_ERROR::OK:
219 bitmap_butt = BITMAPS::erc_green;
220 tooltip = _( "No error or warning" );
221 break;
222
223 case PIN_ERROR::WARNING:
224 bitmap_butt = BITMAPS::ercwarn;
225 tooltip = _( "Generate warning" );
226 break;
227
228 case PIN_ERROR::PP_ERROR:
229 bitmap_butt = BITMAPS::ercerr;
230 tooltip = _( "Generate error" );
231 break;
232
233 default:
234 break;
235 }
236
237 if( !!bitmap_butt )
238 {
239 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
240 wx_btn->SetBitmap( KiBitmap( bitmap_butt ) );
241 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
242 ki_btn->SetBitmap( KiBitmap( bitmap_butt ) );
243
244 aButton->SetToolTip( tooltip );
245 }
246}
247
248
249void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
250{
251 int id = event.GetId();
252 int ii = id - ID_MATRIX_0;
253 int x = ii / ELECTRICAL_PINTYPES_TOTAL;
254 int y = ii % ELECTRICAL_PINTYPES_TOTAL;
255 wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
256
257 int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
258 level = ( level + 1 ) % 3;
259
260 setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
261
262 m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
263 m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
264}
265
266
268{
269 for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
270 {
271 for( int jj = 0; jj <= ii; jj++ )
272 setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
273 }
274}
275
276
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:106
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:41
void ResetPinMap()
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:141
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Definition: erc_settings.h:153
Class PANEL_SETUP_PINMAP_BASE.
wxWindow * m_buttonList[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
void changeErrorLevel(wxCommandEvent &event)
void ImportSettingsFrom(PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL])
void setDRCMatrixButtonState(wxWindow *aButton, PIN_ERROR aState)
void OnMouseEnter(wxMouseEvent &aEvent)
void OnMouseLeave(wxMouseEvent &aEvent)
void ResetPanel() override
Reset the contents of this panel.
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:212
Schematic editor (Eeschema) main window.
#define _(s)
const wxString CommentERC_V[]
Definition: erc.cpp:81
const wxString CommentERC_H[]
Definition: erc.cpp:64
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:93
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:70
#define ID_MATRIX_0
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
#define ELECTRICAL_PINTYPES_TOTAL
Definition: pin_type.h:53
std::vector< FAB_LAYER_COLOR > dummy
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:85
Definition of file extensions used in Kicad.