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>
23#include <schematic.h>
24#include <connection_graph.h>
25#include <tool/tool_manager.h>
26#include <panel_setup_pinmap.h>
27#include <erc/erc.h>
28#include <wx/bmpbuttn.h>
29#include <wx/statline.h>
30#include <wx/stattext.h>
32
33
34// Control identifiers for events
35#define ID_MATRIX_0 1800
36
37
38// NC is not included in the pin map as it generates errors separately
39#define PINMAP_TYPE_COUNT ( ELECTRICAL_PINTYPES_TOTAL - 1 )
40
41
44 wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
45END_EVENT_TABLE()
46
47
48PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
49 PANEL_SETUP_PINMAP_BASE( aWindow ),
50 m_buttonList(),
51 m_initialized( false )
52{
53 m_parent = parent;
54 m_schematic = &parent->Schematic();
55 m_btnBackground = wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_WINDOW );
56
57 for( int row = 0; row < PINMAP_TYPE_COUNT; row++ )
58 {
59 for( int col = 0; col <= row; col++ )
60 m_buttonStateList[row][col] = PIN_ERROR::OK;
61 }
62}
63
64
66{
67#ifndef __WXMAC__
68 if( m_initialized )
69 {
70 for( int row = 0; row < PINMAP_TYPE_COUNT; row++ )
71 {
72 for( int col = 0; col <= row; col++ )
73 {
74 m_buttonList[row][col]->Unbind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
75 m_buttonList[row][col]->Unbind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
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( wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_HIGHLIGHT ) );
96}
97
98
99void PANEL_SETUP_PINMAP::OnMouseLeave( wxMouseEvent& aEvent )
100{
101 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
102 btn->SetBackgroundColour( m_btnBackground );
103}
104
105
107{
108 // Try to know the size of bitmap button used in drc matrix
109 wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmapBundle( BITMAPS::ercerr ),
110 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
111 wxSize bitmapSize = dummy->GetSize();
112 delete dummy;
113
114#ifdef __WXMAC__
115 const wxSize text_padding( 2, 1 );
116 const int twiddle = -1;
117#else
118 const wxSize text_padding( 8, 6 );
119 const int twiddle = 1;
120#endif
121
122 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
123 wxPoint pos( 0, charSize.y * 2 );
124 wxStaticText* text;
125
126 if( !m_initialized )
127 {
128 std::vector<wxStaticText*> labels;
129
130 // Print row labels
131 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
132 {
133 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
134 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
135 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
136 labels.push_back( text );
137
138 int x = text->GetRect().GetRight();
139 pos.x = std::max( pos.x, x );
140 }
141
142 // Right-align
143 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
144 {
145 wxPoint labelPos = labels[ ii ]->GetPosition();
146 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
147 labelPos.y += twiddle;
148 labels[ ii ]->SetPosition( labelPos );
149 }
150
151 pos.x += 5;
152 }
153 else
154 {
155 pos = m_buttonList[0][0]->GetPosition();
156 }
157
158 for( int row = 0; row < PINMAP_TYPE_COUNT; row++ )
159 {
160 int y = pos.y + (row * ( bitmapSize.y + text_padding.y ) );
161
162 for( int col = 0; col <= row; col++ )
163 {
164 // Add column labels (only once)
165 PIN_ERROR pin_error_type = m_schematic->ErcSettings().GetPinMapValue( row, col );
166
167 int x = pos.x + ( col * ( bitmapSize.x + text_padding.x ) );
168
169 if( ( row == col ) && !m_initialized )
170 {
171 wxPoint textPos( x + KiROUND( bitmapSize.x / 2.0 ), y - charSize.y * 2 );
172 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[row], textPos );
173
174 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2.0 ), y - charSize.y );
175 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
176 }
177
178 int id = ID_MATRIX_0 + row * PINMAP_TYPE_COUNT + col;
179 BITMAPS bitmap_butt = BITMAPS::erc_green;
180
181#ifdef __WXMAC__
182 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
183 wxPoint( x, y ), bitmapSize );
184#else
185 if( m_initialized )
186 {
187 m_buttonList[row][col]->Unbind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
188 m_buttonList[row][col]->Unbind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
189 }
190
191 wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, id, KiBitmapBundle( bitmap_butt ),
192 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
193 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
194 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
195#endif
196 btn->SetSize( btn->GetSize() + text_padding );
197
198 delete m_buttonList[row][col];
199 m_buttonList[row][col] = btn;
200 setDRCMatrixButtonState( m_buttonList[row][col], pin_error_type );
201 m_buttonStateList[row][col] = pin_error_type;
202 }
203 }
204
205 m_initialized = true;
206}
207
208
210{
211 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
212 wxString tooltip;
213
214 switch( aState )
215 {
216 case PIN_ERROR::OK:
217 bitmap_butt = BITMAPS::erc_green;
218 tooltip = _( "No error or warning" );
219 break;
220
222 bitmap_butt = BITMAPS::ercwarn;
223 tooltip = _( "Generate warning" );
224 break;
225
227 bitmap_butt = BITMAPS::ercerr;
228 tooltip = _( "Generate error" );
229 break;
230
231 default:
232 break;
233 }
234
235 if( !!bitmap_butt )
236 {
237 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
238 wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
239 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
240 ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
241
242 aButton->SetToolTip( tooltip );
243 }
244}
245
246
247void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
248{
249 int ii = event.GetId() - ID_MATRIX_0;
250 int row = ii / PINMAP_TYPE_COUNT;
251 int col = ii % PINMAP_TYPE_COUNT;
252 PIN_ERROR level = static_cast<PIN_ERROR>( ( (int) m_buttonStateList[row][col] + 1 ) % 3 );
253
254 setDRCMatrixButtonState( m_buttonList[row][col], level );
255 m_buttonStateList[row][col] = level;
256}
257
258
260{
262 return true;
263}
264
265
267{
268 ERC_SETTINGS& settings = m_schematic->ErcSettings();
269
270 for( int row = 0; row < PINMAP_TYPE_COUNT; ++row )
271 {
272 for( int col = 0; col <= row; ++col )
273 {
274 settings.SetPinMapValue( row, col, m_buttonStateList[row][col] );
275 settings.SetPinMapValue( col, row, settings.GetPinMapValue( row, col ) );
276 }
277 }
278
279 return true;
280}
281
282
284{
285 for( int row = 0; row < PINMAP_TYPE_COUNT; row++ )
286 {
287 for( int col = 0; col <= row; col++ )
288 {
289 setDRCMatrixButtonState( m_buttonList[row][col], aPinMap[row][col] );
290 m_buttonStateList[row][col] = aPinMap[row][col];
291 }
292 }
293}
294
295
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:982
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Container for ERC settings.
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Class PANEL_SETUP_PINMAP_BASE.
bool TransferDataToWindow() override
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)
PIN_ERROR m_buttonStateList[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
void OnMouseLeave(wxMouseEvent &aEvent)
bool TransferDataFromWindow() override
void ResetPanel() override
Reset the contents of this panel.
Schematic editor (Eeschema) main window.
#define _(s)
const wxString CommentERC_V[]
Definition erc.cpp:290
const wxString CommentERC_H[]
Definition erc.cpp:273
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
#define ELECTRICAL_PINTYPES_TOTAL
Definition pin_type.h:52
std::vector< FAB_LAYER_COLOR > dummy