2020-03-11 21:43:02 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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 <fctsys.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <reporter.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <netlist_object.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>
|
|
|
|
#include <widgets/wx_angle_text.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Control identifiers for events
|
|
|
|
#define ID_MATRIX_0 1800
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE( PANEL_SETUP_PINMAP, PANEL_SETUP_PINMAP_BASE )
|
|
|
|
EVT_COMMAND_RANGE( ID_MATRIX_0,
|
|
|
|
ID_MATRIX_0 + ( ELECTRICAL_PINTYPES_TOTAL * ELECTRICAL_PINTYPES_TOTAL ) - 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();
|
2020-03-11 21:43:02 +00:00
|
|
|
|
|
|
|
wxFont infoFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
|
|
|
|
infoFont.SetSymbolicSize( wxFONTSIZE_SMALL );
|
|
|
|
|
2020-07-04 08:57:05 +00:00
|
|
|
reBuildMatrixPanel();
|
2020-03-11 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_SETUP_PINMAP::OnResetMatrixClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2020-07-08 15:27:53 +00:00
|
|
|
wxBitmapButton* dummy = new wxBitmapButton( m_matrixPanel, wxID_ANY, KiBitmap( ercerr_xpm ) );
|
|
|
|
wxSize bmapSize = dummy->GetSize();
|
2020-03-11 21:43:02 +00:00
|
|
|
delete dummy;
|
|
|
|
|
|
|
|
wxPoint pos;
|
2020-07-08 15:27:53 +00:00
|
|
|
// Get the text size for the angled text
|
|
|
|
EDA_RECT bbox = WX_ANGLE_TEXT::GetBoundingBox( m_matrixPanel, CommentERC_V[0], 450 );
|
|
|
|
wxSize txtSize = WX_ANGLE_TEXT::GetTextSize( m_matrixPanel, CommentERC_V[0] );
|
2020-07-07 22:09:48 +00:00
|
|
|
|
2020-07-08 15:27:53 +00:00
|
|
|
bmapSize.y = std::max( bmapSize.y, txtSize.y );
|
2020-03-11 21:43:02 +00:00
|
|
|
|
|
|
|
// compute the Y pos interval:
|
2020-07-07 22:09:48 +00:00
|
|
|
pos.y = bbox.GetHeight();
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-08 15:27:53 +00:00
|
|
|
wxStaticText* text;
|
|
|
|
|
2020-03-11 21:43:02 +00:00
|
|
|
if( !m_initialized )
|
|
|
|
{
|
|
|
|
std::vector<wxStaticText*> labels;
|
|
|
|
|
|
|
|
// Print row labels
|
|
|
|
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
|
|
|
|
{
|
2020-07-08 15:27:53 +00:00
|
|
|
int y = pos.y + (ii * bmapSize.y);
|
2020-03-11 21:43:02 +00:00
|
|
|
text = new wxStaticText( m_matrixPanel, -1, CommentERC_H[ii],
|
2020-07-08 15:27:53 +00:00
|
|
|
wxPoint( 5, y + ( bmapSize.y / 2 ) - ( txtSize.y / 2 ) ) );
|
2020-03-11 21:43:02 +00:00
|
|
|
labels.push_back( text );
|
|
|
|
|
|
|
|
int x = text->GetRect().GetRight();
|
|
|
|
pos.x = std::max( pos.x, x );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Right-align
|
|
|
|
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
|
|
|
|
{
|
|
|
|
wxPoint labelPos = labels[ ii ]->GetPosition();
|
|
|
|
labelPos.x = pos.x - labels[ ii ]->GetRect().GetWidth();
|
|
|
|
labels[ ii ]->SetPosition( labelPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.x += 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pos = m_buttonList[0][0]->GetPosition();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
|
|
|
|
{
|
2020-07-08 15:27:53 +00:00
|
|
|
int y = pos.y + (ii * bmapSize.y);
|
2020-03-11 21:43:02 +00:00
|
|
|
|
|
|
|
for( int jj = 0; jj <= ii; jj++ )
|
|
|
|
{
|
|
|
|
// Add column labels (only once)
|
2020-07-03 21:08:17 +00:00
|
|
|
PIN_ERROR diag = m_schematic->ErcSettings().GetPinMapValue( ii, jj );
|
|
|
|
|
2020-07-08 15:27:53 +00:00
|
|
|
int x = pos.x + ( jj * ( bmapSize.x + 4 ) );
|
2020-03-11 21:43:02 +00:00
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
if( ( ii == jj ) && !m_initialized )
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
|
|
|
wxPoint txtpos;
|
2020-07-08 15:27:53 +00:00
|
|
|
txtpos.x = x + ( bmapSize.x / 2 );
|
|
|
|
txtpos.y = y - txtSize.y;
|
2020-07-03 21:08:17 +00:00
|
|
|
new WX_ANGLE_TEXT( m_matrixPanel, wxID_ANY, CommentERC_V[ii], txtpos, 450 );
|
2020-03-11 21:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int event_id = ID_MATRIX_0 + ii + ( jj * ELECTRICAL_PINTYPES_TOTAL );
|
|
|
|
BITMAP_DEF bitmap_butt = erc_green_xpm;
|
|
|
|
|
|
|
|
delete m_buttonList[ii][jj];
|
|
|
|
wxBitmapButton* btn = new wxBitmapButton( m_matrixPanel, event_id,
|
|
|
|
KiBitmap( bitmap_butt ), wxPoint( x, y ) );
|
|
|
|
btn->SetSize( btn->GetSize().x + 4, btn->GetSize().y );
|
|
|
|
m_buttonList[ii][jj] = btn;
|
|
|
|
setDRCMatrixButtonState( m_buttonList[ii][jj], diag );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_SETUP_PINMAP::Show( bool show )
|
|
|
|
{
|
|
|
|
wxPanel::Show( show );
|
|
|
|
|
|
|
|
// For some reason the angle text doesn't get drawn if the paint events are fired while
|
|
|
|
// it's not the active tab.
|
|
|
|
if( show )
|
|
|
|
{
|
|
|
|
for( wxWindow* win : m_matrixPanel->GetChildren() )
|
|
|
|
{
|
|
|
|
WX_ANGLE_TEXT* angleText = dynamic_cast<WX_ANGLE_TEXT*>( win );
|
|
|
|
|
|
|
|
if( angleText )
|
|
|
|
angleText->Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
void PANEL_SETUP_PINMAP::setDRCMatrixButtonState( wxBitmapButton *aButton, PIN_ERROR aState )
|
2020-03-11 21:43:02 +00:00
|
|
|
{
|
|
|
|
BITMAP_DEF bitmap_butt = nullptr;
|
|
|
|
wxString tooltip;
|
|
|
|
|
|
|
|
switch( aState )
|
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
case PIN_ERROR::OK:
|
2020-03-11 21:43:02 +00:00
|
|
|
bitmap_butt = erc_green_xpm;
|
|
|
|
tooltip = _( "No error or warning" );
|
|
|
|
break;
|
|
|
|
|
2020-07-03 21:08:17 +00:00
|
|
|
case PIN_ERROR::WARNING:
|
2020-03-11 21:43:02 +00:00
|
|
|
bitmap_butt = ercwarn_xpm;
|
|
|
|
tooltip = _( "Generate warning" );
|
|
|
|
break;
|
|
|
|
|
2020-07-04 15:51:00 +00:00
|
|
|
case PIN_ERROR::PP_ERROR:
|
2020-03-11 21:43:02 +00:00
|
|
|
bitmap_butt = ercerr_xpm;
|
|
|
|
tooltip = _( "Generate error" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bitmap_butt )
|
|
|
|
{
|
|
|
|
aButton->SetBitmap( KiBitmap( bitmap_butt ) );
|
|
|
|
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;
|
|
|
|
int x = ii / ELECTRICAL_PINTYPES_TOTAL;
|
|
|
|
int y = ii % ELECTRICAL_PINTYPES_TOTAL;
|
|
|
|
wxBitmapButton* butt = (wxBitmapButton*) event.GetEventObject();
|
|
|
|
|
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] )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < ELECTRICAL_PINTYPES_TOTAL; ii++ )
|
|
|
|
{
|
|
|
|
for( int jj = 0; jj <= ii; jj++ )
|
|
|
|
setDRCMatrixButtonState( m_buttonList[ii][jj], aPinMap[ii][jj] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|