2020-03-11 21:43:02 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-08-26 07:40:09 +00:00
|
|
|
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-03-11 21:43:02 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sch_edit_frame.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-03-11 21:43:02 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-07-03 21:08:17 +00:00
|
|
|
#include <schematic.h>
|
2020-03-11 21:43:02 +00:00
|
|
|
#include <connection_graph.h>
|
|
|
|
#include <tools/ee_actions.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <panel_setup_pinmap.h>
|
|
|
|
#include <erc.h>
|
|
|
|
#include <id.h>
|
2021-06-03 01:19:20 +00:00
|
|
|
#include <wx/bmpbuttn.h>
|
2020-10-18 19:27:04 +00:00
|
|
|
#include <wx/statline.h>
|
2021-06-03 11:49:49 +00:00
|
|
|
#include <wx/stattext.h>
|
2023-01-03 23:36:13 +00:00
|
|
|
#include <widgets/bitmap_button.h>
|
2020-03-11 21:43:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Control identifiers for events
|
|
|
|
#define ID_MATRIX_0 1800
|
|
|
|
|
|
|
|
|
2023-09-04 16:27:12 +00:00
|
|
|
// NC is not included in the pin map as it generates errors separately
|
|
|
|
#define PINMAP_TYPE_COUNT ( ELECTRICAL_PINTYPES_TOTAL - 1 )
|
|
|
|
|
|
|
|
|
2020-03-11 21:43:02 +00:00
|
|
|
BEGIN_EVENT_TABLE( PANEL_SETUP_PINMAP, PANEL_SETUP_PINMAP_BASE )
|
2023-09-04 16:27:12 +00:00
|
|
|
EVT_COMMAND_RANGE( ID_MATRIX_0, ID_MATRIX_0 + ( PINMAP_TYPE_COUNT * PINMAP_TYPE_COUNT ) - 1,
|
2020-07-04 08:57:05 +00:00
|
|
|
wxEVT_COMMAND_BUTTON_CLICKED, PANEL_SETUP_PINMAP::changeErrorLevel )
|
2020-03-11 21:43:02 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_SETUP_PINMAP::PANEL_SETUP_PINMAP( wxWindow* aWindow, SCH_EDIT_FRAME* parent ) :
|
|
|
|
PANEL_SETUP_PINMAP_BASE( aWindow ),
|
|
|
|
m_buttonList(),
|
|
|
|
m_initialized( false )
|
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
m_parent = parent;
|
|
|
|
m_schematic = &parent->Schematic();
|
2023-01-06 21:30:43 +00:00
|
|
|
m_btnBackground = wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_WINDOW );
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-04 08:57:05 +00:00
|
|
|
reBuildMatrixPanel();
|
2020-03-11 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
2023-01-06 21:30:43 +00:00
|
|
|
PANEL_SETUP_PINMAP::~PANEL_SETUP_PINMAP()
|
|
|
|
{
|
|
|
|
#ifndef __WXMAC__
|
|
|
|
if( m_initialized )
|
|
|
|
{
|
2023-09-04 16:27:12 +00:00
|
|
|
for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
|
2023-01-06 21:30:43 +00:00
|
|
|
{
|
|
|
|
for( int jj = 0; jj <= ii; jj++ )
|
|
|
|
{
|
|
|
|
m_buttonList[ii][jj]->Unbind( wxEVT_ENTER_WINDOW,
|
|
|
|
&PANEL_SETUP_PINMAP::OnMouseLeave, this );
|
|
|
|
m_buttonList[ii][jj]->Unbind( wxEVT_LEAVE_WINDOW,
|
|
|
|
&PANEL_SETUP_PINMAP::OnMouseLeave, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-15 23:08:16 +00:00
|
|
|
void PANEL_SETUP_PINMAP::ResetPanel()
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
m_schematic->ErcSettings().ResetPinMap();
|
2020-07-04 08:57:05 +00:00
|
|
|
reBuildMatrixPanel();
|
2020-03-11 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-06 21:30:43 +00:00
|
|
|
void PANEL_SETUP_PINMAP::OnMouseEnter( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
|
|
|
|
m_btnBackground = btn->GetBackgroundColour();
|
|
|
|
|
|
|
|
btn->SetBackgroundColour( wxSystemSettings::GetColour( wxSystemColour::wxSYS_COLOUR_HIGHLIGHT ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_PINMAP::OnMouseLeave( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxBitmapButton* btn = static_cast<wxBitmapButton*>( aEvent.GetEventObject() );
|
|
|
|
btn->SetBackgroundColour( m_btnBackground );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-04 08:57:05 +00:00
|
|
|
void PANEL_SETUP_PINMAP::reBuildMatrixPanel()
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
|
|
|
// Try to know the size of bitmap button used in drc matrix
|
2023-01-05 00:02:44 +00:00
|
|
|
wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( BITMAPS::ercerr ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBORDER_NONE );
|
2023-01-03 23:36:13 +00:00
|
|
|
wxSize bitmapSize = dummy->GetSize();
|
2020-03-11 21:43:02 +00:00
|
|
|
delete dummy;
|
|
|
|
|
2023-01-05 00:02:44 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
const wxSize text_padding( 2, 1 );
|
|
|
|
const int twiddle = -1;
|
|
|
|
#else
|
2023-01-04 20:47:55 +00:00
|
|
|
const wxSize text_padding( 8, 6 );
|
2023-01-05 00:02:44 +00:00
|
|
|
const int twiddle = 1;
|
|
|
|
#endif
|
2023-01-04 20:47:55 +00:00
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
wxSize charSize = KIUI::GetTextSize( wxS( "X" ), m_matrixPanel );
|
2020-10-18 19:27:04 +00:00
|
|
|
wxPoint pos( 0, charSize.y * 2 );
|
2020-07-08 15:27:53 +00:00
|
|
|
wxStaticText* text;
|
2023-01-04 18:31:41 +00:00
|
|
|
|
|
|
|
if( !m_initialized )
|
|
|
|
{
|
|
|
|
std::vector<wxStaticText*> labels;
|
|
|
|
|
|
|
|
// Print row labels
|
2023-09-04 16:27:12 +00:00
|
|
|
for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
|
2023-01-04 18:31:41 +00:00
|
|
|
{
|
2023-01-04 20:47:55 +00:00
|
|
|
int y = pos.y + ( ii * ( bitmapSize.y + text_padding.y ) );
|
|
|
|
text = new wxStaticText( m_matrixPanel, - 1, CommentERC_H[ii],
|
2023-01-04 18:31:41 +00:00
|
|
|
wxPoint( 5, y + ( bitmapSize.y / 2 ) - ( 12 / 2 ) ) );
|
|
|
|
labels.push_back( text );
|
|
|
|
|
|
|
|
int x = text->GetRect().GetRight();
|
|
|
|
pos.x = std::max( pos.x, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right-align
|
2023-09-04 16:27:12 +00:00
|
|
|
for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
|
2023-01-04 18:31:41 +00:00
|
|
|
{
|
|
|
|
wxPoint labelPos = labels[ ii ]->GetPosition();
|
|
|
|
labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
|
2023-01-05 00:02:44 +00:00
|
|
|
labelPos.y += twiddle;
|
2023-01-04 18:31:41 +00:00
|
|
|
labels[ ii ]->SetPosition( labelPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.x += 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = m_buttonList[0][0]->GetPosition();
|
|
|
|
}
|
|
|
|
|
2023-09-04 16:27:12 +00:00
|
|
|
for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
|
2023-01-04 18:31:41 +00:00
|
|
|
{
|
2023-01-04 20:47:55 +00:00
|
|
|
int y = pos.y + (ii * ( bitmapSize.y + text_padding.y ) );
|
2023-01-04 18:31:41 +00:00
|
|
|
|
|
|
|
for( int jj = 0; jj <= ii; jj++ )
|
|
|
|
{
|
|
|
|
// Add column labels (only once)
|
|
|
|
PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
|
|
|
|
|
2023-01-04 20:47:55 +00:00
|
|
|
int x = pos.x + ( jj * ( bitmapSize.x + text_padding.x ) );
|
2023-01-04 18:31:41 +00:00
|
|
|
|
|
|
|
if( ( ii == jj ) && !m_initialized )
|
|
|
|
{
|
2023-01-04 20:47:55 +00:00
|
|
|
wxPoint textPos( x + KiROUND( bitmapSize.x / 2 ),
|
2023-01-04 18:31:41 +00:00
|
|
|
y - charSize.y * 2 );
|
|
|
|
new wxStaticText( m_matrixPanel, wxID_ANY, CommentERC_V[ii], textPos );
|
|
|
|
|
2023-01-04 20:47:55 +00:00
|
|
|
wxPoint calloutPos( x + KiROUND( bitmapSize.x / 2 ),
|
2023-01-04 18:31:41 +00:00
|
|
|
y - charSize.y );
|
|
|
|
new wxStaticText( m_matrixPanel, wxID_ANY, "|", calloutPos );
|
|
|
|
}
|
|
|
|
|
2023-09-04 16:27:12 +00:00
|
|
|
int id = ID_MATRIX_0 + ii + ( jj * PINMAP_TYPE_COUNT );
|
2023-01-04 18:31:41 +00:00
|
|
|
BITMAPS bitmap_butt = BITMAPS::erc_green;
|
|
|
|
|
2023-01-05 00:02:44 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
BITMAP_BUTTON* btn = new BITMAP_BUTTON( m_matrixPanel, id, KiBitmap( bitmap_butt ),
|
|
|
|
wxPoint( x, y ), bitmapSize );
|
|
|
|
#else
|
2023-01-06 21:30:43 +00:00
|
|
|
if( m_initialized )
|
|
|
|
{
|
|
|
|
m_buttonList[ii][jj]->Unbind(wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
|
|
|
|
m_buttonList[ii][jj]->Unbind(wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
|
|
|
|
}
|
|
|
|
|
2023-01-05 00:02:44 +00:00
|
|
|
wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, id, KiBitmap( bitmap_butt ),
|
|
|
|
wxPoint( x, y ), wxDefaultSize, wxBORDER_NONE );
|
2023-01-06 21:30:43 +00:00
|
|
|
btn->Bind( wxEVT_LEAVE_WINDOW, &PANEL_SETUP_PINMAP::OnMouseLeave, this );
|
|
|
|
btn->Bind( wxEVT_ENTER_WINDOW, &PANEL_SETUP_PINMAP::OnMouseEnter, this );
|
2023-01-05 00:02:44 +00:00
|
|
|
#endif
|
2023-01-04 20:47:55 +00:00
|
|
|
btn->SetSize( btn->GetSize() + text_padding );
|
2023-01-06 21:30:43 +00:00
|
|
|
|
|
|
|
delete m_buttonList[ii][jj];
|
2023-01-04 18:31:41 +00:00
|
|
|
m_buttonList[ii][jj] = btn;
|
|
|
|
setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-11 21:43:02 +00:00
|
|
|
m_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-04 18:31:41 +00:00
|
|
|
void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxWindow *aButton, PIN_ERROR aState )
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS bitmap_butt = BITMAPS::INVALID_BITMAP;
|
2020-03-11 21:43:02 +00:00
|
|
|
wxString tooltip;
|
|
|
|
|
|
|
|
switch( aState )
|
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
case PIN_ERROR::OK:
|
2021-03-08 02:59:07 +00:00
|
|
|
bitmap_butt = BITMAPS::erc_green;
|
2020-03-11 21:43:02 +00:00
|
|
|
tooltip = _( "No error or warning" );
|
|
|
|
break;
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
case PIN_ERROR::WARNING:
|
2021-03-08 02:59:07 +00:00
|
|
|
bitmap_butt = BITMAPS::ercwarn;
|
2020-03-11 21:43:02 +00:00
|
|
|
tooltip = _( "Generate warning" );
|
|
|
|
break;
|
|
|
|
|
2020-07-04 15:51:00 +00:00
|
|
|
case PIN_ERROR::PP_ERROR:
|
2021-03-08 02:59:07 +00:00
|
|
|
bitmap_butt = BITMAPS::ercerr;
|
2020-03-11 21:43:02 +00:00
|
|
|
tooltip = _( "Generate error" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-03-11 01:48:37 +00:00
|
|
|
if( !!bitmap_butt )
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
2023-01-05 00:02:44 +00:00
|
|
|
if( wxBitmapButton* wx_btn = dynamic_cast<wxBitmapButton*>( aButton ) )
|
2023-10-21 18:56:19 +00:00
|
|
|
wx_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
|
2023-01-05 00:02:44 +00:00
|
|
|
else if( BITMAP_BUTTON* ki_btn = dynamic_cast<BITMAP_BUTTON*>( aButton ) )
|
2023-10-21 18:56:19 +00:00
|
|
|
ki_btn->SetBitmap( KiBitmapBundle( bitmap_butt ) );
|
2023-01-04 18:31:41 +00:00
|
|
|
|
2020-03-11 21:43:02 +00:00
|
|
|
aButton->SetToolTip( tooltip );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-04 08:57:05 +00:00
|
|
|
void PANEL_SETUP_PINMAP::changeErrorLevel( wxCommandEvent& event )
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
|
|
|
int id = event.GetId();
|
|
|
|
int ii = id - ID_MATRIX_0;
|
2023-09-04 16:27:12 +00:00
|
|
|
ELECTRICAL_PINTYPE x = static_cast<ELECTRICAL_PINTYPE>( ii / PINMAP_TYPE_COUNT );
|
|
|
|
ELECTRICAL_PINTYPE y = static_cast<ELECTRICAL_PINTYPE>( ii % PINMAP_TYPE_COUNT );
|
2023-01-05 00:02:44 +00:00
|
|
|
wxWindow* butt = static_cast<wxWindow*>( event.GetEventObject() );
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
int level = static_cast<int>( m_schematic->ErcSettings().GetPinMapValue( y, x ) );
|
|
|
|
level = ( level + 1 ) % 3;
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
setDRCMatrixButtonState( butt, static_cast<PIN_ERROR>( level ) );
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
m_schematic->ErcSettings().SetPinMapValue( y, x, static_cast<PIN_ERROR>( level ) );
|
|
|
|
m_schematic->ErcSettings().SetPinMapValue( x, y, static_cast<PIN_ERROR>( level ) );
|
2020-03-11 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-04 08:57:05 +00:00
|
|
|
void PANEL_SETUP_PINMAP::ImportSettingsFrom( PIN_ERROR aPinMap[][ELECTRICAL_PINTYPES_TOTAL] )
|
|
|
|
{
|
2023-09-04 16:27:12 +00:00
|
|
|
for( int ii = 0; ii < PINMAP_TYPE_COUNT; ii++ )
|
2020-07-04 08:57:05 +00:00
|
|
|
{
|
|
|
|
for( int jj = 0; jj <= ii; jj++ )
|
|
|
|
setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|