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/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 =
114 new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmapBundle( BITMAPS::ercerr ),
115 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
116 wxSize bitmapSize = dummy->GetSize();
117 delete dummy;
118
119#ifdef __WXMAC__
120 const wxSize text_padding( 2, 1 );
121 const int twiddle = -1;
122#else
123 const wxSize text_padding( 8, 6 );
124 const int twiddle = 1;
125#endif
126
127 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
128 wxPoint pos( 0, charSize.y * 2 );
129 wxStaticText* text;
130
131 if( !m_initialized )
132 {
133 std::vector<wxStaticText*> labels;
134
135 // Print row labels
136 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
137 {
138 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
139 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
140 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
141 labels.push_back( text );
142
143 int x = text->GetRect().GetRight();
144 pos.x = std::max( pos.x, x );
145 }
146
147 // Right-align
148 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
149 {
150 wxPoint labelPos = labels[ ii ]->GetPosition();
151 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
152 labelPos.y += twiddle;
153 labels[ ii ]->SetPosition( labelPos );
154 }
155
156 pos.x += 5;
157 }
158 else
159 {
160 pos = m_buttonList[0][0]->GetPosition();
161 }
162
163 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
164 {
165 int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
166
167 for( int jj = 0; jj <= ii; jj++ )
168 {
169 // Add column labels (only once)
171
172 int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
173
174 if( ( ii == jj ) && !m_initialized )
175 {
176 wxPoint textPos( x + KiROUND( bitmapSize.x / 2 ),
177 y - charSize.y * 2 );
178 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
179
180 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2 ),
181 y - charSize.y );
182 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
183 }
184
185 int id = ID_MATRIX_0 + ii + ( jj * PINMAP_TYPE_COUNT );
186 BITMAPS bitmap_butt = BITMAPS::erc_green;
187
188#ifdef __WXMAC__
189 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
190 wxPoint( x, y ), bitmapSize );
191#else
192 if( m_initialized )
193 {
194 m_buttonList[ii][jj]->Unbind(wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
195 m_buttonList[ii][jj]->Unbind(wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
196 }
197
198 wxBitmapButton* btn =
199 new wxBitmapButton( m_matrixPanel, id, KiBitmapBundle( bitmap_butt ),
200 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
201 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
202 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
203#endif
204 btn->SetSize( btn->GetSize() + text_padding );
205
206 delete m_buttonList[ii][jj];
207 m_buttonList[ii][jj] = btn;
208 setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
209 }
210 }
211
212 m_initialized = true;
213}
214
215
217{
218 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
219 wxString tooltip;
220
221 switch( aState )
222 {
223 case PIN_ERROR::OK:
224 bitmap_butt = BITMAPS::erc_green;
225 tooltip = _( "No error or warning" );
226 break;
227
228 case PIN_ERROR::WARNING:
229 bitmap_butt = BITMAPS::ercwarn;
230 tooltip = _( "Generate warning" );
231 break;
232
233 case PIN_ERROR::PP_ERROR:
234 bitmap_butt = BITMAPS::ercerr;
235 tooltip = _( "Generate error" );
236 break;
237
238 default:
239 break;
240 }
241
242 if( !!bitmap_butt )
243 {
244 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
245 wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
246 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
247 ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
248
249 aButton->SetToolTip( tooltip );
250 }
251}
252
253
254void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
255{
256 int id = event.GetId();
257 int ii = id - ID_MATRIX_0;
260 wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
261
262 int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
263 level = ( level + 1 ) % 3;
264
265 setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
266
267 m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
268 m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
269}
270
271
273{
274 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
275 {
276 for( int jj = 0; jj <= ii; jj++ )
277 setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
278 }
279}
280
281
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
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void ResetPinMap()
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:155
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Definition: erc_settings.h:167
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:321
Schematic editor (Eeschema) main window.
#define _(s)
const wxString CommentERC_V[]
Definition: erc.cpp:92
const wxString CommentERC_H[]
Definition: erc.cpp:75
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:107
KICOMMON_API 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:77
#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:54
std::vector< FAB_LAYER_COLOR > dummy
Definition of file extensions used in Kicad.