2019-04-29 20:38:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2019-04-29 20:38:05 +00:00
|
|
|
* Copyright (C) 2019 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 <sch_component.h>
|
2019-06-01 15:28:39 +00:00
|
|
|
#include <id.h>
|
2019-06-01 18:36:49 +00:00
|
|
|
#include <kiway.h>
|
2019-04-29 20:38:05 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <tool/conditional_menu.h>
|
|
|
|
#include <tool/selection_conditions.h>
|
2019-06-08 21:48:22 +00:00
|
|
|
#include <tools/ee_actions.h>
|
|
|
|
#include <tools/ee_inspection_tool.h>
|
|
|
|
#include <tools/ee_selection_tool.h>
|
|
|
|
#include <tools/ee_selection.h>
|
2019-06-01 18:36:49 +00:00
|
|
|
#include <search_stack.h>
|
|
|
|
#include <sim/sim_plot_frame.h>
|
2019-04-29 20:38:05 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-06-01 18:36:49 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2019-12-19 14:05:46 +00:00
|
|
|
#include <lib_view_frame.h>
|
2019-04-29 20:38:05 +00:00
|
|
|
#include <eda_doc.h>
|
2019-06-01 15:28:39 +00:00
|
|
|
#include <invoke_sch_dialog.h>
|
2019-06-01 18:36:49 +00:00
|
|
|
#include <project.h>
|
2019-06-02 18:58:09 +00:00
|
|
|
#include <dialogs/dialog_display_info_HTML_base.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-04-29 20:38:05 +00:00
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_INSPECTION_TOOL::EE_INSPECTION_TOOL()
|
2019-05-12 11:49:58 +00:00
|
|
|
: EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.InspectionTool" )
|
2019-04-29 20:38:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_INSPECTION_TOOL::Init()
|
2019-04-29 20:38:05 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-04-29 20:38:05 +00:00
|
|
|
|
|
|
|
auto singleMarkerCondition = SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T )
|
2019-05-02 10:59:36 +00:00
|
|
|
&& SELECTION_CONDITIONS::Count( 1 );
|
2019-04-29 20:38:05 +00:00
|
|
|
|
|
|
|
// Add inspection actions to the selection tool menu
|
|
|
|
//
|
|
|
|
CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
|
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
selToolMenu.AddItem( EE_ACTIONS::showDatasheet, EE_CONDITIONS::SingleSymbol && EE_CONDITIONS::Idle, 220 );
|
2019-04-29 20:38:05 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
int EE_INSPECTION_TOOL::RunERC( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-02 18:58:09 +00:00
|
|
|
if( m_frame->IsType( FRAME_SCH_LIB_EDITOR ) )
|
|
|
|
{
|
|
|
|
checkPart( static_cast<LIB_EDIT_FRAME*>( m_frame )->GetCurPart() );
|
|
|
|
}
|
|
|
|
else if( m_frame->IsType( FRAME_SCH ) )
|
|
|
|
{
|
|
|
|
wxWindow* erc = wxWindow::FindWindowById( ID_DIALOG_ERC, m_frame );
|
2019-06-01 15:28:39 +00:00
|
|
|
|
2019-06-02 18:58:09 +00:00
|
|
|
if( erc )
|
2020-04-08 08:03:51 +00:00
|
|
|
{
|
|
|
|
// Needed at least on Windows. Raise() is not enough
|
|
|
|
erc->Show( true );
|
2019-06-02 18:58:09 +00:00
|
|
|
// Bring it to the top if already open. Dual monitor users need this.
|
|
|
|
erc->Raise();
|
2020-04-08 08:03:51 +00:00
|
|
|
}
|
2019-06-02 18:58:09 +00:00
|
|
|
else
|
|
|
|
InvokeDialogERC( static_cast<SCH_EDIT_FRAME*>( m_frame ) );
|
|
|
|
}
|
2019-06-01 15:28:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-02 18:58:09 +00:00
|
|
|
// helper function to sort pins by pin num
|
|
|
|
bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst )
|
|
|
|
{
|
|
|
|
// Use number as primary key
|
|
|
|
int test = ref->GetNumber().Cmp( tst->GetNumber() );
|
|
|
|
|
|
|
|
// Use DeMorgan variant as secondary key
|
|
|
|
if( test == 0 )
|
|
|
|
test = ref->GetConvert() - tst->GetConvert();
|
|
|
|
|
|
|
|
// Use unit as tertiary key
|
|
|
|
if( test == 0 )
|
|
|
|
test = ref->GetUnit() - tst->GetUnit();
|
|
|
|
|
|
|
|
return test < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart )
|
|
|
|
{
|
|
|
|
if( !aPart )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
wxRealPoint curr_grid_size = m_frame->GetScreen()->GetGridSize();
|
|
|
|
const int min_grid_size = 25;
|
|
|
|
const int grid_size = KiROUND( curr_grid_size.x );
|
|
|
|
const int clamped_grid_size = ( grid_size < min_grid_size ) ? min_grid_size : grid_size;
|
|
|
|
LIB_PINS pinList;
|
|
|
|
|
|
|
|
aPart->GetPins( pinList );
|
|
|
|
|
|
|
|
if( pinList.empty() )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( m_frame, _( "No pins!" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort pins by pin num, so 2 duplicate pins
|
|
|
|
// (pins with the same number) will be consecutive in list
|
|
|
|
sort( pinList.begin(), pinList.end(), sort_by_pin_number );
|
|
|
|
|
|
|
|
// Test for duplicates:
|
|
|
|
DIALOG_DISPLAY_HTML_TEXT_BASE error_display( m_frame, wxID_ANY, _( "Marker Information" ),
|
|
|
|
wxDefaultPosition, wxSize( 750, 600 ) );
|
|
|
|
|
2020-02-27 23:06:48 +00:00
|
|
|
std::vector<wxString> messages;
|
|
|
|
|
2019-06-02 18:58:09 +00:00
|
|
|
int dup_error = 0;
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < pinList.size(); ii++ )
|
|
|
|
{
|
|
|
|
LIB_PIN* pin = pinList[ii - 1];
|
|
|
|
LIB_PIN* next = pinList[ii];
|
|
|
|
|
|
|
|
if( pin->GetNumber() != next->GetNumber() || pin->GetConvert() != next->GetConvert() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dup_error++;
|
|
|
|
|
2019-06-15 00:29:42 +00:00
|
|
|
/* TODO I dare someone to find a way to make happy translators on this thing! Lorenzo */
|
2019-06-02 18:58:09 +00:00
|
|
|
|
|
|
|
msg = wxString::Format( _( "<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>"
|
|
|
|
" conflicts with pin %s \"%s\" at location <b>(%.3f, %.3f)</b>" ),
|
|
|
|
next->GetNumber(),
|
|
|
|
next->GetName(),
|
|
|
|
next->GetPosition().x / 1000.0, -next->GetPosition().y / 1000.0,
|
|
|
|
pin->GetNumber(),
|
|
|
|
pin->GetName(),
|
|
|
|
pin->GetPosition().x / 1000.0, -pin->GetPosition().y / 1000.0 );
|
|
|
|
|
|
|
|
if( aPart->GetUnitCount() > 1 )
|
|
|
|
{
|
|
|
|
msg += wxString::Format( _( " in units %c and %c" ),
|
|
|
|
'A' + next->GetUnit() - 1,
|
|
|
|
'A' + pin->GetUnit() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aPart->HasConversion() )
|
|
|
|
{
|
|
|
|
if( next->GetConvert() )
|
|
|
|
msg += _( " of converted" );
|
|
|
|
else
|
|
|
|
msg += _( " of normal" );
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += wxT( ".<br>" );
|
|
|
|
|
2020-02-27 23:06:48 +00:00
|
|
|
messages.push_back( msg );
|
2019-06-02 18:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test for off grid pins:
|
|
|
|
int offgrid_error = 0;
|
|
|
|
|
|
|
|
for( LIB_PIN* pin : pinList )
|
|
|
|
{
|
|
|
|
if( ( (pin->GetPosition().x % clamped_grid_size) == 0 ) &&
|
|
|
|
( (pin->GetPosition().y % clamped_grid_size) == 0 ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// "pin" is off grid here.
|
|
|
|
offgrid_error++;
|
|
|
|
|
|
|
|
msg = wxString::Format( _( "<b>Off grid pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>" ),
|
|
|
|
pin->GetNumber(),
|
|
|
|
pin->GetName(),
|
|
|
|
pin->GetPosition().x / 1000.0, -pin->GetPosition().y / 1000.0 );
|
|
|
|
|
|
|
|
if( aPart->GetUnitCount() > 1 )
|
|
|
|
msg += wxString::Format( _( " in symbol %c" ), 'A' + pin->GetUnit() - 1 );
|
|
|
|
|
|
|
|
if( aPart->HasConversion() )
|
|
|
|
{
|
|
|
|
if( pin->GetConvert() )
|
|
|
|
msg += _( " of converted" );
|
|
|
|
else
|
|
|
|
msg += _( " of normal" );
|
|
|
|
}
|
|
|
|
|
|
|
|
msg += wxT( ".<br>" );
|
2020-02-27 23:06:48 +00:00
|
|
|
messages.push_back( msg );
|
2019-06-02 18:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !dup_error && !offgrid_error )
|
|
|
|
DisplayInfoMessage( m_frame, _( "No off grid or duplicate pins were found." ) );
|
|
|
|
else
|
2020-02-27 23:06:48 +00:00
|
|
|
{
|
|
|
|
wxColour bgcolor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
|
|
|
|
wxColour fgcolor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
|
|
|
|
wxString outmsg = wxString::Format( "<html><body bgcolor='%s' text='%s'>",
|
|
|
|
bgcolor.GetAsString( wxC2S_HTML_SYNTAX ),
|
|
|
|
fgcolor.GetAsString( wxC2S_HTML_SYNTAX ) );
|
|
|
|
|
2020-02-28 00:06:52 +00:00
|
|
|
for( auto& msgPart : messages )
|
|
|
|
outmsg += msgPart;
|
2020-02-27 23:06:48 +00:00
|
|
|
|
|
|
|
outmsg += "</body></html>";
|
|
|
|
|
|
|
|
error_display.m_htmlWindow->SetPage( outmsg );
|
2019-06-02 18:58:09 +00:00
|
|
|
error_display.ShowModal();
|
2020-02-27 23:06:48 +00:00
|
|
|
}
|
2019-06-02 18:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
int EE_INSPECTION_TOOL::RunSimulation( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
#ifdef KICAD_SPICE
|
|
|
|
SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, true );
|
|
|
|
simFrame->Show( true );
|
|
|
|
|
|
|
|
// On Windows, Raise() does not bring the window on screen, when iconized
|
|
|
|
if( simFrame->IsIconized() )
|
|
|
|
simFrame->Iconize( false );
|
|
|
|
|
|
|
|
simFrame->Raise();
|
|
|
|
#endif /* KICAD_SPICE */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent )
|
2019-04-29 20:38:05 +00:00
|
|
|
{
|
2019-06-01 18:36:49 +00:00
|
|
|
wxString datasheet;
|
2019-04-29 20:38:05 +00:00
|
|
|
|
2019-06-02 18:58:09 +00:00
|
|
|
if( m_frame->IsType( FRAME_SCH_LIB_EDITOR ) )
|
2019-06-01 18:36:49 +00:00
|
|
|
{
|
2019-06-02 18:58:09 +00:00
|
|
|
LIB_PART* part = static_cast<LIB_EDIT_FRAME*>( m_frame )->GetCurPart();
|
2019-06-01 18:36:49 +00:00
|
|
|
|
|
|
|
if( !part )
|
|
|
|
return 0;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
datasheet = part->GetDocFileName();
|
2019-06-01 18:36:49 +00:00
|
|
|
}
|
2019-06-02 18:58:09 +00:00
|
|
|
else if( m_frame->IsType( FRAME_SCH_VIEWER ) || m_frame->IsType( FRAME_SCH_VIEWER_MODAL ) )
|
2019-06-01 18:36:49 +00:00
|
|
|
{
|
2019-11-07 14:09:24 +00:00
|
|
|
LIB_PART* entry = static_cast<LIB_VIEW_FRAME*>( m_frame )->GetSelectedSymbol();
|
2019-04-29 20:38:05 +00:00
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
if( !entry )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
datasheet = entry->GetDocFileName();
|
|
|
|
}
|
2019-06-02 18:58:09 +00:00
|
|
|
else if( m_frame->IsType( FRAME_SCH ) )
|
2019-06-01 18:36:49 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly );
|
2019-04-29 20:38:05 +00:00
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
if( selection.Empty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front();
|
|
|
|
|
|
|
|
datasheet = component->GetField( DATASHEET )->GetText();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !datasheet.IsEmpty() && datasheet != wxT( "~" ) )
|
2020-04-05 19:51:48 +00:00
|
|
|
GetAssociatedDocument( m_frame, datasheet, &m_frame->Prj() );
|
2019-04-29 20:38:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_INSPECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
|
2019-04-30 18:36:11 +00:00
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
2019-04-30 18:36:11 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
2019-05-06 12:32:51 +00:00
|
|
|
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
|
2019-04-30 18:36:11 +00:00
|
|
|
|
|
|
|
MSG_PANEL_ITEMS msgItems;
|
|
|
|
item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems );
|
|
|
|
m_frame->SetMsgPanel( msgItems );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_frame->ClearMsgPanel();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_INSPECTION_TOOL::setTransitions()
|
2019-04-29 20:38:05 +00:00
|
|
|
{
|
2019-06-01 15:28:39 +00:00
|
|
|
Go( &EE_INSPECTION_TOOL::RunERC, EE_ACTIONS::runERC.MakeEvent() );
|
2019-06-01 18:36:49 +00:00
|
|
|
Go( &EE_INSPECTION_TOOL::RunSimulation, EE_ACTIONS::runSimulation.MakeEvent() );
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_INSPECTION_TOOL::ShowDatasheet, EE_ACTIONS::showDatasheet.MakeEvent() );
|
2019-04-30 18:36:11 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedEvent );
|
|
|
|
Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::UnselectedEvent );
|
|
|
|
Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::ClearedEvent );
|
2019-06-10 22:42:02 +00:00
|
|
|
Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedItemsModified );
|
2019-04-29 20:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|