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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <sch_edit_frame.h>
21#include <kiface_base.h>
22#include <bitmaps.h>
24#include <schematic.h>
25#include <connection_graph.h>
26#include <tool/tool_manager.h>
27#include <panel_setup_pinmap.h>
28#include <erc/erc.h>
29#include <id.h>
30#include <wx/bmpbuttn.h>
31#include <wx/statline.h>
32#include <wx/stattext.h>
34
35
36// Control identifiers for events
37#define ID_MATRIX_0 1800
38
39
40// NC is not included in the pin map as it generates errors separately
41#define PINMAP_TYPE_COUNT ( ELECTRICAL_PINTYPES_TOTAL - 1 )
42
43
46 wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
47END_EVENT_TABLE()
48
49
50PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
51 PANEL_SETUP_PINMAP_BASE( aWindow ),
52 m_buttonList(),
53 m_initialized( false )
54{
55 m_parent = parent;
56 m_schematic = &parent->Schematic();
57 m_btnBackground = wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_WINDOW );
58
59 reBuildMatrixPanel();
60}
61
62
64{
65#ifndef __WXMAC__
66 if( m_initialized )
67 {
68 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
69 {
70 for( int jj = 0; jj <= ii; jj++ )
71 {
72 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
74 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
76 }
77 }
78 }
79#endif
80}
81
82
84{
85 m_schematic->ErcSettings().ResetPinMap();
87}
88
89
90void PANEL_SETUP_PINMAP::OnMouseEnter( wxMouseEvent& aEvent )
91{
92 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
93 m_btnBackground = btn->GetBackgroundColour();
94
95 btn->SetBackgroundColour(
96 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 =
111 new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmapBundle( BITMAPS::ercerr ),
112 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
113 wxSize bitmapSize = dummy->GetSize();
114 delete dummy;
115
116#ifdef __WXMAC__
117 const wxSize text_padding( 2, 1 );
118 const int twiddle = -1;
119#else
120 const wxSize text_padding( 8, 6 );
121 const int twiddle = 1;
122#endif
123
124 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
125 wxPoint pos( 0, charSize.y * 2 );
126 wxStaticText* text;
127
128 if( !m_initialized )
129 {
130 std::vector<wxStaticText*> labels;
131
132 // Print row labels
133 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
134 {
135 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
136 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
137 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
138 labels.push_back( text );
139
140 int x = text->GetRect().GetRight();
141 pos.x = std::max( pos.x, x );
142 }
143
144 // Right-align
145 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
146 {
147 wxPoint labelPos = labels[ ii ]->GetPosition();
148 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
149 labelPos.y += twiddle;
150 labels[ ii ]->SetPosition( labelPos );
151 }
152
153 pos.x += 5;
154 }
155 else
156 {
157 pos = m_buttonList[0][0]->GetPosition();
158 }
159
160 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
161 {
162 int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
163
164 for( int jj = 0; jj <= ii; jj++ )
165 {
166 // Add column labels (only once)
167 PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
168
169 int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
170
171 if( ( ii == jj ) && !m_initialized )
172 {
173 wxPoint textPos( x + KiROUND( bitmapSize.x / 2.0 ),
174 y - charSize.y * 2 );
175 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
176
177 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2.0 ),
178 y - charSize.y );
179 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
180 }
181
182 int id = ID_MATRIX_0 + ii + ( jj * PINMAP_TYPE_COUNT );
183 BITMAPS bitmap_butt = BITMAPS::erc_green;
184
185#ifdef __WXMAC__
186 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
187 wxPoint( x, y ), bitmapSize );
188#else
189 if( m_initialized )
190 {
191 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
193 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
195 }
196
197 wxBitmapButton* btn =
198 new wxBitmapButton( m_matrixPanel, id, KiBitmapBundle( bitmap_butt ),
199 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
200 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
201 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
202#endif
203 btn->SetSize( btn->GetSize() + text_padding );
204
205 delete m_buttonList[ii][jj];
206 m_buttonList[ii][jj] = btn;
207 setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
208 }
209 }
210
211 m_initialized = true;
212}
213
214
216{
217 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
218 wxString tooltip;
219
220 switch( aState )
221 {
222 case PIN_ERROR::OK:
223 bitmap_butt = BITMAPS::erc_green;
224 tooltip = _( "No error or warning" );
225 break;
226
228 bitmap_butt = BITMAPS::ercwarn;
229 tooltip = _( "Generate warning" );
230 break;
231
233 bitmap_butt = BITMAPS::ercerr;
234 tooltip = _( "Generate error" );
235 break;
236
237 default:
238 break;
239 }
240
241 if( !!bitmap_butt )
242 {
243 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
244 wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
245 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
246 ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
247
248 aButton->SetToolTip( tooltip );
249 }
250}
251
252
253void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
254{
255 int id = event.GetId();
256 int ii = id - ID_MATRIX_0;
259 wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
260
261 int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
262 level = ( level + 1 ) % 3;
263
264 setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
265
266 m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
267 m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
268}
269
270
272{
273 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
274 {
275 for( int jj = 0; jj <= ii; jj++ )
276 setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
277 }
278}
279
280
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:100
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
BITMAPS
A list of all bitmap identifiers.
@ INVALID_BITMAP
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
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.
Schematic editor (Eeschema) main window.
#define _(s)
const wxString CommentERC_V[]
Definition erc.cpp:93
const wxString CommentERC_H[]
Definition erc.cpp:76
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
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:78
#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:32
#define ELECTRICAL_PINTYPES_TOTAL
Definition pin_type.h:52
std::vector< FAB_LAYER_COLOR > dummy
Definition of file extensions used in Kicad.