2014-10-19 22:17:43 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-02-20 08:17:54 +00:00
|
|
|
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2015-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
|
2014-10-19 22:17:43 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file selpart.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <confirm.h>
|
2015-02-20 08:17:54 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <sch_base_frame.h>
|
2017-10-06 18:07:43 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <dialog_helpers.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
static void DisplayCmpDocAndKeywords( wxString& aSelection, void* aData )
|
2015-02-20 08:17:54 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
SYMBOL_LIB_TABLE* libs = (SYMBOL_LIB_TABLE*) aData;
|
2015-02-20 08:17:54 +00:00
|
|
|
|
|
|
|
wxASSERT( libs );
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
LIB_ID id;
|
|
|
|
|
|
|
|
if( id.Parse( aSelection ) != -1 )
|
|
|
|
{
|
|
|
|
aSelection = _( "Invalid symbol library indentifier!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_ALIAS* part = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
part = libs->LoadSymbol( id );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
aSelection.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ),
|
2017-10-06 18:07:43 +00:00
|
|
|
id.GetLibItemName().wx_str(), id.GetLibNickname().wx_str() );
|
|
|
|
return;
|
|
|
|
}
|
2015-02-20 08:17:54 +00:00
|
|
|
|
|
|
|
if( !part )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
aSelection = _( "Description: " ) + part->GetDescription() + "\n";
|
|
|
|
aSelection += _( "Key Words: " ) + part->GetKeyWords();
|
2015-02-20 08:17:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString SCH_BASE_FRAME::SelectLibraryFromList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
PROJECT& prj = Prj();
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( prj.SchSymbolLibTable()->IsEmpty() )
|
2009-08-23 14:21:41 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
DisplayError( this, _( "No symbol libraries are loaded." ) );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxArrayString headers;
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
headers.Add( _( "Library" ) );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
std::vector< wxArrayString > itemsToDisplay;
|
|
|
|
std::vector< wxString > libNicknames = prj.SchSymbolLibTable()->GetLogicalLibs();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const auto& name : libNicknames )
|
2017-10-06 18:07:43 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
item.Add( name );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString old_lib_name = prj.GetRString( PROJECT::SCH_LIB_SELECT );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay,
|
|
|
|
old_lib_name );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return wxEmptyString;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString libname = dlg.GetTextSelection();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !libname.empty() )
|
|
|
|
{
|
|
|
|
if( prj.SchSymbolLibTable()->HasLibrary( libname ) )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
prj.SetRString( PROJECT::SCH_LIB_SELECT, libname );
|
2017-10-06 18:07:43 +00:00
|
|
|
else
|
|
|
|
libname = wxEmptyString;
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
return libname;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
bool SCH_BASE_FRAME::DisplayListComponentsInLib( wxString& aLibrary, wxString& aBuffer,
|
|
|
|
wxString& aPreviousChoice )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
wxArrayString nameList;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !aLibrary )
|
2015-02-20 08:17:54 +00:00
|
|
|
aLibrary = SelectLibraryFromList();
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !aLibrary )
|
2015-02-20 08:17:54 +00:00
|
|
|
return false;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Prj().SchSymbolLibTable()->EnumerateSymbolLib( aLibrary, nameList );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error occurred loading symbol library \"%s\"." ), aLibrary );
|
2017-10-06 18:07:43 +00:00
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2017-10-06 18:07:43 +00:00
|
|
|
headers.Add( _( "Library:Symbol" ) );
|
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < nameList.GetCount(); i++ )
|
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
LIB_ID id;
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString item;
|
2017-10-24 23:08:28 +00:00
|
|
|
id.SetLibItemName( nameList[i], false );
|
2017-10-06 18:07:43 +00:00
|
|
|
id.SetLibNickname( aLibrary );
|
|
|
|
item.Add( id.Format() );
|
2013-03-19 01:25:19 +00:00
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Symbol" ), headers, itemsToDisplay, aPreviousChoice,
|
|
|
|
DisplayCmpDocAndKeywords, Prj().SchSymbolLibTable() );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2015-02-20 08:17:54 +00:00
|
|
|
return false;
|
2009-12-15 21:11:05 +00:00
|
|
|
|
2015-02-20 08:17:54 +00:00
|
|
|
aBuffer = dlg.GetTextSelection();
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2015-02-20 08:17:54 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
bool SCH_BASE_FRAME::SelectPartNameToLoad( wxString& aLibrary, wxString& aBufName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-02-20 08:17:54 +00:00
|
|
|
static wxString previousCmpName;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !DisplayListComponentsInLib( aLibrary, aBufName, previousCmpName ) || aBufName.empty() )
|
2015-02-20 08:17:54 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2015-02-20 08:17:54 +00:00
|
|
|
previousCmpName = aBufName;
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|