/* * This program source code file is part of KiCad, a free EDA CAD application. * * 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include TOOL_ACTION EE_ACTIONS::showDatasheet( "eeschema.InspectionTool.showDatasheet", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SHOW_COMPONENT_DATASHEET ), _( "Show Datasheet" ), _( "Opens the datasheet in a browser" ), datasheet_xpm ); TOOL_ACTION EE_ACTIONS::showMarkerInfo( "eeschema.InspectionTool.showMarkerInfo", AS_GLOBAL, 0, _( "Show Marker Info" ), _( "Display the marker's info in a dialog" ), info_xpm ); EE_INSPECTION_TOOL::EE_INSPECTION_TOOL() : EE_TOOL_BASE( "eeschema.InspectionTool" ) { } bool EE_INSPECTION_TOOL::Init() { EE_TOOL_BASE::Init(); auto singleMarkerCondition = SELECTION_CONDITIONS::OnlyType( SCH_MARKER_T ) && SELECTION_CONDITIONS::Count( 1 ); // Add inspection actions to the selection tool menu // CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu(); selToolMenu.AddItem( EE_ACTIONS::showDatasheet, EE_CONDITIONS::SingleSymbol && EE_CONDITIONS::Idle, 400 ); selToolMenu.AddItem( EE_ACTIONS::showMarkerInfo, singleMarkerCondition && EE_CONDITIONS::Idle, 400 ); return true; } int EE_INSPECTION_TOOL::ShowDatasheet( const TOOL_EVENT& aEvent ) { SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); if( selection.Empty() ) return 0; SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front(); wxString datasheet = component->GetField( DATASHEET )->GetText(); if( !datasheet.IsEmpty() ) GetAssociatedDocument( m_frame, datasheet ); return 0; } int EE_INSPECTION_TOOL::ShowMarkerInfo( const TOOL_EVENT& aEvent ) { SELECTION& selection = m_selectionTool->GetSelection(); if( selection.Empty() ) return 0; SCH_MARKER* marker = dynamic_cast( selection.Front() ); if( marker ) marker->DisplayMarkerInfo( m_frame ); return 0; } int EE_INSPECTION_TOOL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); SELECTION& selection = selTool->GetSelection(); if( selection.GetSize() == 1 ) { EDA_ITEM* item = (EDA_ITEM*) selection.Front(); MSG_PANEL_ITEMS msgItems; item->GetMsgPanelInfo( m_frame->GetUserUnits(), msgItems ); m_frame->SetMsgPanel( msgItems ); } else { m_frame->ClearMsgPanel(); } return 0; } void EE_INSPECTION_TOOL::setTransitions() { Go( &EE_INSPECTION_TOOL::ShowDatasheet, EE_ACTIONS::showDatasheet.MakeEvent() ); Go( &EE_INSPECTION_TOOL::ShowMarkerInfo, EE_ACTIONS::showMarkerInfo.MakeEvent() ); Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::SelectedEvent ); Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::UnselectedEvent ); Go( &EE_INSPECTION_TOOL::UpdateMessagePanel, EVENTS::ClearedEvent ); }