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 <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
67
69{
70#ifndef __WXMAC__
71 if( m_initialized )
72 {
73 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
74 {
75 for( int jj = 0; jj <= ii; jj++ )
76 {
77 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
79 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
81 }
82 }
83 }
84#endif
85}
86
87
89{
92}
93
94
95void PANEL_SETUP_PINMAP::OnMouseEnter( wxMouseEvent& aEvent )
96{
97 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
98 m_btnBackground = btn->GetBackgroundColour();
99
100 btn->SetBackgroundColour(
101 wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_HIGHLIGHT ) );
102}
103
104
105void PANEL_SETUP_PINMAP::OnMouseLeave( wxMouseEvent& aEvent )
106{
107 wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
108 btn->SetBackgroundColour( m_btnBackground );
109}
110
111
113{
114 // Try to know the size of bitmap button used in drc matrix
115 wxBitmapButton* dummy =
116 new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmapBundle( BITMAPS::ercerr ),
117 wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
118 wxSize bitmapSize = dummy->GetSize();
119 delete dummy;
120
121#ifdef __WXMAC__
122 const wxSize text_padding( 2, 1 );
123 const int twiddle = -1;
124#else
125 const wxSize text_padding( 8, 6 );
126 const int twiddle = 1;
127#endif
128
129 wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
130 wxPoint pos( 0, charSize.y * 2 );
131 wxStaticText* text;
132
133 if( !m_initialized )
134 {
135 std::vector<wxStaticText*> labels;
136
137 // Print row labels
138 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
139 {
140 int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
141 text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
142 wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
143 labels.push_back( text );
144
145 int x = text->GetRect().GetRight();
146 pos.x = std::max( pos.x, x );
147 }
148
149 // Right-align
150 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
151 {
152 wxPoint labelPos = labels[ ii ]->GetPosition();
153 labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
154 labelPos.y += twiddle;
155 labels[ ii ]->SetPosition( labelPos );
156 }
157
158 pos.x += 5;
159 }
160 else
161 {
162 pos = m_buttonList[0][0]->GetPosition();
163 }
164
165 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
166 {
167 int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
168
169 for( int jj = 0; jj <= ii; jj++ )
170 {
171 // Add column labels (only once)
173
174 int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
175
176 if( ( ii == jj ) && !m_initialized )
177 {
178 wxPoint textPos( x + KiROUND( bitmapSize.x / 2 ),
179 y - charSize.y * 2 );
180 new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
181
182 wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2 ),
183 y - charSize.y );
184 new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
185 }
186
187 int id = ID_MATRIX_0 + ii + ( jj * PINMAP_TYPE_COUNT );
188 BITMAPS bitmap_butt = BITMAPS::erc_green;
189
190#ifdef __WXMAC__
191 BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
192 wxPoint( x, y ), bitmapSize );
193#else
194 if( m_initialized )
195 {
196 m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
198 m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
200 }
201
202 wxBitmapButton* btn =
203 new wxBitmapButton( m_matrixPanel, id, KiBitmapBundle( bitmap_butt ),
204 wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
205 btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
206 btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
207#endif
208 btn->SetSize( btn->GetSize() + text_padding );
209
210 delete m_buttonList[ii][jj];
211 m_buttonList[ii][jj] = btn;
212 setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
213 }
214 }
215
216 m_initialized = true;
217}
218
219
221{
222 BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
223 wxString tooltip;
224
225 switch( aState )
226 {
227 case PIN_ERROR::OK:
228 bitmap_butt = BITMAPS::erc_green;
229 tooltip = _( "No error or warning" );
230 break;
231
232 case PIN_ERROR::WARNING:
233 bitmap_butt = BITMAPS::ercwarn;
234 tooltip = _( "Generate warning" );
235 break;
236
237 case PIN_ERROR::PP_ERROR:
238 bitmap_butt = BITMAPS::ercerr;
239 tooltip = _( "Generate error" );
240 break;
241
242 default:
243 break;
244 }
245
246 if( !!bitmap_butt )
247 {
248 if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
249 wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
250 else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
251 ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
252
253 aButton->SetToolTip( tooltip );
254 }
255}
256
257
258void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
259{
260 int id = event.GetId();
261 int ii = id - ID_MATRIX_0;
264 wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
265
266 int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
267 level = ( level + 1 ) % 3;
268
269 setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
270
271 m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
272 m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
273}
274
275
277{
278 for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
279 {
280 for( int jj = 0; jj <= ii; jj++ )
281 setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
282 }
283}
284
285
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: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:319
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:54
std::vector< FAB_LAYER_COLOR > dummy
Definition of file extensions used in Kicad.