7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 14:50:11 +00:00

FP edit: add 'show datasheet' action that acts on the documentation link

This is already shown in the footprint browser window as a special
item, so allow the 'D' hotkey to access it as well.
This commit is contained in:
John Beard 2024-10-14 23:13:44 +08:00
parent c34ba1a834
commit b092675171
16 changed files with 108 additions and 54 deletions

View File

@ -1069,6 +1069,15 @@ TOOL_ACTION ACTIONS::showProperties( TOOL_ACTION_ARGS()
.Tooltip( _( "Show/hide the properties manager" ) )
.Icon( BITMAPS::tools ) );
TOOL_ACTION ACTIONS::showDatasheet( TOOL_ACTION_ARGS()
.Name( "common.Control.showDatasheet" )
.Scope( AS_GLOBAL )
.DefaultHotkey( 'D' )
.LegacyHotkeyName( "Show Datasheet" )
.FriendlyName( _( "Show Datasheet" ) )
.Tooltip( _( "Open the datasheet in a browser" ) )
.Icon( BITMAPS::datasheet ) );
TOOL_ACTION ACTIONS::updatePcbFromSchematic( TOOL_ACTION_ARGS()
.Name( "common.Control.updatePcbFromSchematic" )
.Scope( AS_GLOBAL )

View File

@ -151,7 +151,7 @@ void SYMBOL_EDIT_FRAME::doReCreateMenuBar()
//
ACTION_MENU* inspectMenu = new ACTION_MENU( false, selTool );
inspectMenu->Add( EE_ACTIONS::showDatasheet );
inspectMenu->Add( ACTIONS::showDatasheet );
inspectMenu->AppendSeparator();
inspectMenu->Add( EE_ACTIONS::checkSymbol );

View File

@ -595,7 +595,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
return m_symbol && !m_symbol->GetDatasheetField().GetText().IsEmpty();
};
mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( EE_ACTIONS::symbolProperties, ENABLE( canEditProperties && haveSymbolCond ) );
mgr->SetConditions( EE_ACTIONS::runERC, ENABLE( haveSymbolCond ) );
mgr->SetConditions( EE_ACTIONS::pinTable, ENABLE( isEditableCond && haveSymbolCond ) );

View File

@ -122,7 +122,7 @@ void SYMBOL_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->Add( EE_ACTIONS::pinTable );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( EE_ACTIONS::showDatasheet );
m_mainToolBar->Add( ACTIONS::showDatasheet );
m_mainToolBar->Add( EE_ACTIONS::checkSymbol );
m_mainToolBar->AddScaledSeparator( this );

View File

@ -394,7 +394,7 @@ void SYMBOL_VIEWER_FRAME::setupUIConditions()
return symbol && !symbol->GetDatasheetField().GetText().IsEmpty();
};
mgr->SetConditions( EE_ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( ACTIONS::showDatasheet, ENABLE( haveDatasheetCond ) );
mgr->SetConditions( EE_ACTIONS::showElectricalTypes, CHECK( electricalTypesShownCondition ) );
mgr->SetConditions( EE_ACTIONS::showPinNumbers, CHECK( pinNumbersShownCondition ) );

View File

@ -76,7 +76,7 @@ void SYMBOL_VIEWER_FRAME::ReCreateHToolbar()
m_mainToolBar->AddControl( m_unitChoice );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( EE_ACTIONS::showDatasheet );
m_mainToolBar->Add( ACTIONS::showDatasheet );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->Add( EE_ACTIONS::addSymbolToSchematic );

View File

@ -75,15 +75,6 @@ TOOL_ACTION EE_ACTIONS::showSimulator( TOOL_ACTION_ARGS()
.Tooltip( _( "Show simulation window for running SPICE or IBIS simulations." ) )
.Icon( BITMAPS::simulator ) );
TOOL_ACTION EE_ACTIONS::showDatasheet( TOOL_ACTION_ARGS()
.Name( "eeschema.InspectionTool.showDatasheet" )
.Scope( AS_GLOBAL )
.DefaultHotkey( 'D' )
.LegacyHotkeyName( "Show Datasheet" )
.FriendlyName( _( "Show Datasheet" ) )
.Tooltip( _( "Open the datasheet in a browser" ) )
.Icon( BITMAPS::datasheet ) );
// EE_POINT_EDITOR
//

View File

@ -151,7 +151,6 @@ public:
static TOOL_ACTION pointEditorRemoveCorner;
/// Inspection and Editing
static TOOL_ACTION showDatasheet;
static TOOL_ACTION runERC;
static TOOL_ACTION annotate;
static TOOL_ACTION incrementAnnotations;

View File

@ -69,7 +69,7 @@ bool EE_INSPECTION_TOOL::Init()
selToolMenu.AddItem( EE_ACTIONS::excludeMarker, EE_CONDITIONS::SingleNonExcludedMarker, 100 );
selToolMenu.AddItem( EE_ACTIONS::showDatasheet,
selToolMenu.AddItem( ACTIONS::showDatasheet,
EE_CONDITIONS::SingleSymbol && EE_CONDITIONS::Idle, 220 );
return true;
@ -600,7 +600,7 @@ void EE_INSPECTION_TOOL::setTransitions()
Go( &EE_INSPECTION_TOOL::RunSimulation, EE_ACTIONS::showSimulator.MakeEvent() );
Go( &EE_INSPECTION_TOOL::ShowBusSyntaxHelp, EE_ACTIONS::showBusSyntaxHelp.MakeEvent() );
Go( &EE_INSPECTION_TOOL::ShowDatasheet, EE_ACTIONS::showDatasheet.MakeEvent() );
Go( &EE_INSPECTION_TOOL::ShowDatasheet, ACTIONS::showDatasheet.MakeEvent() );
// Note 1: tUpdateMessagePanel is called by CrossProbe. So uncomment this line if
// call to CrossProbe is modifiied

View File

@ -205,6 +205,7 @@ public:
static TOOL_ACTION updatePcbFromSchematic;
static TOOL_ACTION updateSchematicFromPcb;
static TOOL_ACTION showProperties;
static TOOL_ACTION showDatasheet;
// Internal
static TOOL_ACTION updateMenu;

View File

@ -1286,6 +1286,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( PCB_ACTIONS::checkFootprint, ENABLE( haveFootprintCond ) );
mgr->SetConditions( PCB_ACTIONS::repairFootprint, ENABLE( haveFootprintCond ) );
mgr->SetConditions( PCB_ACTIONS::cleanupGraphics, ENABLE( haveFootprintCond ) );
mgr->SetConditions( ACTIONS::showDatasheet, ENABLE( haveFootprintCond ) );
auto isArcKeepCenterMode =
[this]( const SELECTION& )

View File

@ -45,6 +45,52 @@ static const wxString DocFormat = wxT(
"</tr>" );
std::optional<wxString> GetFootprintDocumentationURL( const FOOTPRINT& aFootprint )
{
wxString desc = aFootprint.GetLibDescription();
wxString url;
// It is currently common practice to store a documentation link in the description.
size_t idx = desc.find( wxT( "http:" ) );
if( idx == wxString::npos )
idx = desc.find( wxT( "https:" ) );
if( idx == wxString::npos )
return std::nullopt;
int nesting = 0;
for( auto chit = desc.begin() + idx; chit != desc.end(); ++chit )
{
int ch = *chit;
// Break on invalid URI characters
if( ch <= 0x20 || ch >= 0x7F || ch == '"' )
break;
// Check for nesting parentheses, e.g. (Body style from: https://this.url/part.pdf)
if( ch == '(' )
++nesting;
else if( ch == ')' && --nesting < 0 )
break;
url += ch;
}
// Trim trailing punctuation
static wxString punct = wxS( ".,:;" );
if( punct.find( url.Last() ) != wxString::npos )
url = url.Left( url.Length() - 1 );
if( url.IsEmpty() )
return std::nullopt;
return url;
}
class FOOTPRINT_INFO_GENERATOR
{
wxString m_html;
@ -92,39 +138,8 @@ public:
wxString keywords = m_footprint->GetKeywords();
wxString doc;
// It is currently common practice to store a documentation link in the description.
size_t idx = desc.find( wxT( "http:" ) );
if( idx == wxString::npos )
idx = desc.find( wxT( "https:" ) );
if( idx != wxString::npos )
{
int nesting = 0;
for( auto chit = desc.begin() + idx; chit != desc.end(); ++chit )
{
int ch = *chit;
// Break on invalid URI characters
if( ch <= 0x20 || ch >= 0x7F || ch == '"' )
break;
// Check for nesting parentheses, e.g. (Body style from: https://this.url/part.pdf)
if( ch == '(' )
++nesting;
else if( ch == ')' && --nesting < 0 )
break;
doc += ch;
}
// Trim trailing punctuation
static wxString punct = wxS( ".,:;" );
if( punct.find( doc.Last() ) != wxString::npos )
doc = doc.Left( doc.Length() - 1 );
}
if( std::optional<wxString> url = GetFootprintDocumentationURL( *m_footprint ) )
doc = *url;
wxString esc_desc = EscapeHTML( UnescapeString( desc ) );

View File

@ -18,13 +18,15 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GENERATE_FOOTPRINT_INFO_H
#define GENERATE_FOOTPRINT_INFO_H
#pragma once
#include <optional>
#include <wx/string.h>
class LIB_ID;
class FP_LIB_TABLE;
class FOOTPRINT;
class LIB_ID;
/**
* Return an HTML page describing a #LIB_ID in a #FP_LIB_TABLE. This is suitable for inclusion
@ -32,4 +34,12 @@ class FP_LIB_TABLE;
*/
wxString GenerateFootprintInfo( FP_LIB_TABLE* aFpLibTable, LIB_ID const& aLibId );
#endif // GENERATE_FOOTPRINT_INFO_H
/**
* Get a URL to the documentation for a #LIB_ID in a #FP_LIB_TABLE. This is suitable for opening
* in a web browser. Currently, for want of a proper home in the format, this is usually
* found in the "description" field of the footprint.
*
* @return The URL, or std::nullopt if no URL is available.
*/
std::optional<wxString> GetFootprintDocumentationURL( const FOOTPRINT& aFootprint );

View File

@ -200,6 +200,9 @@ void FOOTPRINT_EDIT_FRAME::doReCreateMenuBar()
inspectMenu->AppendSeparator();
inspectMenu->Add( PCB_ACTIONS::checkFootprint );
inspectMenu->AppendSeparator();
inspectMenu->Add( PCB_ACTIONS::showDatasheet );
//-- Tools menu --------------------------------------------------------
//

View File

@ -29,7 +29,9 @@
#include <tool/tool_manager.h>
#include <tool/library_editor_control.h>
#include <tools/pcb_actions.h>
#include <eda_doc.h>
#include <footprint_edit_frame.h>
#include <generate_footprint_info.h>
#include <pcbnew_id.h>
#include <confirm.h>
#include <kidialog.h>
@ -678,6 +680,27 @@ int FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor( const TOOL_EVENT& aEvent )
}
int FOOTPRINT_EDITOR_CONTROL::ShowDatasheet( const TOOL_EVENT& aEvent )
{
if( FOOTPRINT* footprint = m_frame->GetBoard()->GetFirstFootprint() )
{
std::optional<wxString> url = GetFootprintDocumentationURL( *footprint );
if( !url.has_value() )
{
frame()->ShowInfoBarMsg( _( "No datasheet found in the footprint." ) );
}
else
{
// Only absolute URLs are supported
SEARCH_STACK* searchStack = nullptr;
GetAssociatedDocument( m_frame, *url, &m_frame->Prj(), searchStack, footprint );
}
}
return 0;
}
int FOOTPRINT_EDITOR_CONTROL::EditFootprint( const TOOL_EVENT& aEvent )
{
m_frame->LoadFootprintFromLibrary( m_frame->GetLibTree()->GetSelectedLibId() );
@ -855,6 +878,7 @@ void FOOTPRINT_EDITOR_CONTROL::setTransitions()
Go( &FOOTPRINT_EDITOR_CONTROL::OpenWithTextEditor, ACTIONS::openWithTextEditor.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::OpenDirectory, ACTIONS::openDirectory.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::ShowDatasheet, ACTIONS::showDatasheet.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::EditTextAndGraphics, PCB_ACTIONS::editTextAndGraphics.MakeEvent() );
Go( &FOOTPRINT_EDITOR_CONTROL::CleanupGraphics, PCB_ACTIONS::cleanupGraphics.MakeEvent() );

View File

@ -64,6 +64,7 @@ public:
int ExportFootprint( const TOOL_EVENT& aEvent );
int OpenDirectory( const TOOL_EVENT& aEvent );
int OpenWithTextEditor( const TOOL_EVENT& aEvent );
int ShowDatasheet( const TOOL_EVENT& aEvent );
int ToggleLayersManager( const TOOL_EVENT& aEvent );
int ToggleProperties( const TOOL_EVENT& aEvent );