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