From a562525ec9cbb6c864acc1157c6f785bed3347b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= Date: Wed, 18 Oct 2017 20:09:08 +0200 Subject: [PATCH] Use schematic symbol field to show documentation link. This instead of using the library alias property. But to not break any library. When adding new components to the schematic, copy the value from the library into the Field variable only if the field variable would otherwise be empty. This way, the context menu for showing the docs is more understandable for users, and is also changeable from the schematic without having to modify the actual libraries. Fixed: lp:1723104 --- .../dialogs/dialog_edit_component_in_schematic.cpp | 3 ++- .../dialogs/dialog_edit_libentry_fields_in_lib.cpp | 3 ++- eeschema/getpart.cpp | 12 ++++++++++++ eeschema/onrightclick.cpp | 2 +- eeschema/schedit.cpp | 13 ++++--------- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 0804f8bba1..e9500d8308 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -54,6 +54,7 @@ #endif /* KICAD_SPICE */ #include "common.h" +#include "eda_doc.h" #include @@ -590,7 +591,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::showButtonHandler( wxCommandEvent& even { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); datasheet_uri = resolveUriByEnvVars( datasheet_uri ); - ::wxLaunchDefaultBrowser( datasheet_uri ); + GetAssociatedDocument( this, datasheet_uri ); } else if( fieldNdx == FOOTPRINT ) { diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index d70f05a865..23341a5bdf 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -45,6 +45,7 @@ #include #include +#include "eda_doc.h" #include #ifdef KICAD_SPICE @@ -501,7 +502,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::showButtonHandler( wxCommandEvent& even if( fieldNdx == DATASHEET ) { wxString datasheet_uri = fieldValueTextCtrl->GetValue(); - ::wxLaunchDefaultBrowser( datasheet_uri ); + GetAssociatedDocument( this, datasheet_uri ); } else if( fieldNdx == FOOTPRINT ) { diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index ac7deec23e..8e8401add9 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -254,6 +254,18 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( // Set the component value that can differ from component name in lib, for aliases component->GetField( VALUE )->SetText( sel.Name ); + // If there is no field defined in the component, copy one over from the library + // ( from the .dcm file ) + // This way the Datasheet field will not be empty and can be changed from the schematic + auto libs = Prj().SchLibs(); + if( component->GetField( DATASHEET )->GetText().IsEmpty() ) + { + LIB_ALIAS* entry = libs->FindLibraryAlias( component->GetLibId() ); + + if( entry && !!entry->GetDocFileName() ) + component->GetField( DATASHEET )->SetText( entry->GetDocFileName() ); + } + MSG_PANEL_ITEMS items; component->SetCurrentSheetPath( &GetCurrentSheet() ); diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index e84e44246a..ab2c712e1e 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -397,7 +397,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component, PART_LIBS* msg = AddHotkeyName( _( "Autoplace Fields" ), g_Schematic_Hokeys_Descr, HK_AUTOPLACE_FIELDS ); AddMenuItem( PopMenu, ID_AUTOPLACE_FIELDS, msg, KiBitmap( autoplace_fields_xpm ) ); - if( libEntry && !libEntry->GetDocFileName().IsEmpty() ) + if( !Component->GetFieldText("Datasheet").IsEmpty() ) AddMenuItem( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Open Documentation" ), KiBitmap( datasheet_xpm ) ); } diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 23d4bdafa2..906a129da9 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -302,16 +302,11 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) // Ensure the struct is a component (could be a piece of a component, like Field, text..) if( item && item->Type() == SCH_COMPONENT_T ) { - if( PART_LIBS* libs = Prj().SchLibs() ) + auto text = static_cast( item )->GetFieldText( "Datasheet" ); + + if( !text.IsEmpty() ) { - LIB_ALIAS* entry = libs->FindLibraryAlias( ( (SCH_COMPONENT*) item )->GetLibId() ); - - if( entry && !!entry->GetDocFileName() ) - { - SEARCH_STACK* lib_search = Prj().SchSearchS(); - - GetAssociatedDocument( this, entry->GetDocFileName(), lib_search ); - } + GetAssociatedDocument( this, text ); } } break;