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
|
2018-01-03 19:19:26 +00:00
|
|
|
* Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.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 viewlibs.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <eda_doc.h>
|
|
|
|
|
|
|
|
#include <viewlib_frame.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <dialog_helpers.h>
|
2016-10-21 12:38:08 +00:00
|
|
|
#include <dialog_choose_component.h>
|
2017-03-06 14:50:48 +00:00
|
|
|
#include <cmp_tree_model_adapter.h>
|
2017-09-02 18:12:50 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
wxString dialogTitle;
|
2017-09-15 14:17:44 +00:00
|
|
|
SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
// Container doing search-as-you-type.
|
2017-03-06 14:50:48 +00:00
|
|
|
auto adapter( CMP_TREE_MODEL_ADAPTER::Create( libs ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2017-11-15 10:48:38 +00:00
|
|
|
const auto libNicknames = libs->GetLogicalLibs();
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2017-11-15 10:48:38 +00:00
|
|
|
adapter->AddLibrariesWithProgress( libNicknames, this );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2018-01-03 19:19:26 +00:00
|
|
|
dialogTitle.Printf( _( "Choose Symbol (%d items loaded)" ),
|
2017-03-06 14:50:48 +00:00
|
|
|
adapter->GetComponentsCount() );
|
2018-01-03 02:52:35 +00:00
|
|
|
DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, m_convert, false, false );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
if( dlg.ShowQuasiModal() == wxID_CANCEL )
|
2016-10-21 12:38:08 +00:00
|
|
|
return;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
/// @todo: The unit selection gets reset to 1 by SetSelectedComponent() so the unit
|
|
|
|
/// selection feature of the choose symbol dialog doesn't work.
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID id = dlg.GetSelectedLibId( &m_unit );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( !id.IsValid() || id.GetLibNickname().empty() )
|
2016-10-21 12:38:08 +00:00
|
|
|
return;
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( m_libraryName == id.GetLibNickname() )
|
2016-10-21 12:38:08 +00:00
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
if( m_entryName != id.GetLibItemName() )
|
|
|
|
SetSelectedComponent( id.GetLibItemName() );
|
2016-10-21 12:38:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
m_entryName = id.GetLibItemName();
|
|
|
|
SetSelectedLibrary( id.GetLibNickname() );
|
|
|
|
SetSelectedComponent( id.GetLibItemName() );
|
2016-10-21 12:38:08 +00:00
|
|
|
}
|
2017-09-15 14:17:44 +00:00
|
|
|
|
|
|
|
Zoom_Automatique( false );
|
2016-10-21 12:38:08 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::onSelectNextSymbol( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
|
|
|
|
int ii = m_cmpList->GetSelection();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
// Select the next symbol or stop at the end of the list.
|
|
|
|
if( ii != wxNOT_FOUND || ii != (int)m_cmpList->GetCount() - 1 )
|
|
|
|
ii += 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
m_cmpList->SetSelection( ii );
|
|
|
|
ProcessEvent( evt );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
wxCommandEvent evt( wxEVT_COMMAND_LISTBOX_SELECTED, ID_LIBVIEW_CMP_LIST );
|
|
|
|
int ii = m_cmpList->GetSelection();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
// Select the previous symbol or stop at the beginning of list.
|
|
|
|
if( ii != wxNOT_FOUND && ii != 0 )
|
|
|
|
ii -= 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
m_cmpList->SetSelection( ii );
|
|
|
|
ProcessEvent( evt );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::onViewSymbolDocument( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-09-02 18:12:50 +00:00
|
|
|
LIB_ID id( m_libraryName, m_entryName );
|
|
|
|
LIB_ALIAS* entry = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
if( entry && !entry->GetDocFileName().IsEmpty() )
|
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
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
SEARCH_STACK* lib_search = Prj().SchSearchS();
|
2008-10-01 19:57:10 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
GetAssociatedDocument( this, entry->GetDocFileName(), lib_search );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::onSelectSymbolBodyStyle( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
int id = aEvent.GetId();
|
2010-11-20 21:59:00 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
switch( id )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
default:
|
|
|
|
case ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT:
|
|
|
|
m_convert = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT:
|
|
|
|
m_convert = 2;
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2016-10-21 12:38:08 +00:00
|
|
|
|
|
|
|
m_canvas->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
int ii = m_selpartBox->GetCurrentSelection();
|
2015-02-20 08:17:54 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
if( ii < 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
m_unit = ii + 1;
|
|
|
|
m_canvas->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2016-10-21 12:38:08 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
bool LIB_VIEW_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
2016-10-21 12:38:08 +00:00
|
|
|
void LIB_VIEW_FRAME::DisplayLibInfos()
|
|
|
|
{
|
2017-09-02 18:12:50 +00:00
|
|
|
if( m_libList && !m_libList->IsEmpty() && !m_libraryName.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2017-09-02 18:12:50 +00:00
|
|
|
const SYMBOL_LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRow( m_libraryName );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2018-01-06 09:57:46 +00:00
|
|
|
wxString title = wxString::Format( _( "Symbol Library Browser -- %s" ),
|
2018-01-03 19:19:26 +00:00
|
|
|
row ? row->GetFullURI() : _( "no library selected" ) );
|
2016-10-21 12:38:08 +00:00
|
|
|
SetTitle( title );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2017-09-02 18:12:50 +00:00
|
|
|
LIB_ID id( m_libraryName, m_entryName );
|
2017-11-12 13:23:46 +00:00
|
|
|
LIB_ALIAS* entry = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
entry = Prj().SchSymbolLibTable()->LoadSymbol( id );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e ) {} // ignore, it is handled below
|
2015-02-20 08:17:54 +00:00
|
|
|
|
|
|
|
if( !entry )
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIB_PART* part = entry->GetPart();
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
wxString tmp;
|
|
|
|
|
|
|
|
m_canvas->DrawBackGround( DC );
|
|
|
|
|
|
|
|
if( !entry->IsRoot() )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2015-02-20 08:17:54 +00:00
|
|
|
// Temporarily change the name field text to reflect the alias name.
|
|
|
|
msg = entry->GetName();
|
|
|
|
tmp = part->GetName();
|
|
|
|
|
|
|
|
part->SetName( msg );
|
|
|
|
|
|
|
|
if( m_unit < 1 )
|
|
|
|
m_unit = 1;
|
|
|
|
|
|
|
|
if( m_convert < 1 )
|
|
|
|
m_convert = 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2015-02-20 08:17:54 +00:00
|
|
|
else
|
|
|
|
msg = _( "None" );
|
|
|
|
|
2017-02-19 18:40:26 +00:00
|
|
|
auto opts = PART_DRAW_OPTIONS::Default();
|
|
|
|
opts.show_elec_type = GetShowElectricalType();
|
|
|
|
part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, opts );
|
2015-02-20 08:17:54 +00:00
|
|
|
|
|
|
|
// Redraw the cursor
|
|
|
|
m_canvas->DrawCrossHair( DC );
|
|
|
|
|
|
|
|
if( !tmp.IsEmpty() )
|
|
|
|
part->SetName( tmp );
|
|
|
|
|
|
|
|
ClearMsgPanel();
|
2018-01-03 19:19:26 +00:00
|
|
|
AppendMsgPanel( _( "Name" ), part->GetName(), BLUE, 6 );
|
2015-02-20 08:17:54 +00:00
|
|
|
AppendMsgPanel( _( "Alias" ), msg, RED, 6 );
|
|
|
|
AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 );
|
|
|
|
AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|