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, 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 <tool/tool_manager.h>
31#include <panel_setup_pinmap.h>
32#include <erc/erc.h>
33#include <id.h>
34#include <wx/bmpbuttn.h>
35#include <wx/statline.h>
36#include <wx/stattext.h>
38
39
40// Control identifiers for events
41#define ID_MATRIX_0 1800
42
43
44// NC is not included in the pin map as it generates errors separately
45#define PINMAP_TYPE_COUNT ( ELECTRICAL_PINTYPES_TOTAL - 1 )
46
47
50 wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
51END_EVENT_TABLE()
52
53
54PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
55 PANEL_SETUP_PINMAP_BASE( aWindow ),
56 m_buttonList(),
57 m_initialized( false )
58{
59 m_parent = parent;
60 m_schematic = &parent->Schematic();
61 m_btnBackground = wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_WINDOW );
62
63 reBuildMatrixPanel();
64}
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(
100 wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_HIGHLIGHT ) );
101}
102
103
104void PANEL_SETUP_PINMAP::OnMouseLeave( wxMouseEvent& aEvent )
105{
106 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
107 btn->SetBackgroundColour( m_btnBackground );
108}
109
110
112{
113 // Try to know the size of bitmap button used in drc matrix
114 wxBitmapButton* dummy =
115 new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmapBundle( BITMAPS::ercerr ),
116 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
117 wxSize bitmapSize = dummy->GetSize();
118 delete dummy;
119
120#ifdef __WXMAC__
121 const wxSize text_padding( 2, 1 );
122 const int twiddle = -1;
123#else
124 const wxSize text_padding( 8, 6 );
125 const int twiddle = 1;
126#endif
127
128 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
129 wxPoint pos( 0, charSize.y * 2 );
130 wxStaticText* text;
131
132 if( !m_initialized )
133 {
134 std::vector<wxStaticText*> labels;
135
136 // Print row labels
137 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
138 {
139 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
140 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
141 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
142 labels.push_back( text );
143
144 int x = text->GetRect().GetRight();
145 pos.x = std::max( pos.x, x );
146 }
147
148 // Right-align
149 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
150 {
151 wxPoint labelPos = labels[ ii ]->GetPosition();
152 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
153 labelPos.y += twiddle;
154 labels[ ii ]->SetPosition( labelPos );
155 }
156
157 pos.x += 5;
158 }
159 else
160 {
161 pos = m_buttonList[0][0]->GetPosition();
162 }
163
164 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
165 {
166 int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
167
168 for( int jj = 0; jj <= ii; jj++ )
169 {
170 // Add column labels (only once)
172
173 int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
174
175 if( ( ii == jj ) && !m_initialized )
176 {
177 wxPoint textPos( x + KiROUND( bitmapSize.x / 2 ),
178 y - charSize.y * 2 );
179 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
180
181 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2 ),
182 y - charSize.y );
183 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
184 }
185
186 int id = ID_MATRIX_0 + ii + ( jj * PINMAP_TYPE_COUNT );
187 BITMAPS bitmap_butt = BITMAPS::erc_green;
188
189#ifdef __WXMAC__
190 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
191 wxPoint( x, y ), bitmapSize );
192#else
193 if( m_initialized )
194 {
195 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
197 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
199 }
200
201 wxBitmapButton* btn =
202 new wxBitmapButton( m_matrixPanel, id, KiBitmapBundle( bitmap_butt ),
203 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
204 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
205 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
206#endif
207 btn->SetSize( btn->GetSize() + text_padding );
208
209 delete m_buttonList[ii][jj];
210 m_buttonList[ii][jj] = btn;
211 setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
212 }
213 }
214
215 m_initialized = true;
216}
217
218
220{
221 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
222 wxString tooltip;
223
224 switch( aState )
225 {
226 case PIN_ERROR::OK:
227 bitmap_butt = BITMAPS::erc_green;
228 tooltip = _( "No error or warning" );
229 break;
230
231 case PIN_ERROR::WARNING:
232 bitmap_butt = BITMAPS::ercwarn;
233 tooltip = _( "Generate warning" );
234 break;
235
236 case PIN_ERROR::PP_ERROR:
237 bitmap_butt = BITMAPS::ercerr;
238 tooltip = _( "Generate error" );
239 break;
240
241 default:
242 break;
243 }
244
245 if( !!bitmap_butt )
246 {
247 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
248 wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
249 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
250 ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
251
252 aButton->SetToolTip( tooltip );
253 }
254}
255
256
257void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
258{
259 int id = event.GetId();
260 int ii = id - ID_MATRIX_0;
263 wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
264
265 int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
266 level = ( level + 1 ) % 3;
267
268 setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
269
270 m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
271 m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
272}
273
274
276{
277 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
278 {
279 for( int jj = 0; jj <= ii; jj++ )
280 setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
281 }
282}
283
284
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
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
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:180
void SetPinMapValue(int aFirstType, int aSecondType, PIN_ERROR aValue)
Definition: erc_settings.h:192
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:313
Schematic editor (Eeschema) main window.
#define _(s)
const wxString CommentERC_V[]
Definition: erc.cpp:94
const wxString CommentERC_H[]
Definition: erc.cpp:77
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:107
Common command IDs shared by more than one of the KiCad applications.
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:56
std::vector< FAB_LAYER_COLOR > dummy
Definition of file extensions used in Kicad.