2011-10-28 13:43:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-02-03 14:29:41 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2020-02-13 13:39:52 +00:00
|
|
|
* Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-28 13:43:37 +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
|
|
|
|
*/
|
|
|
|
|
* 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 <pgm_base.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <confirm.h>
|
2020-12-25 11:55:45 +00:00
|
|
|
#include <kiway.h>
|
2020-08-31 15:06:23 +00:00
|
|
|
#include <widgets/infobar.h>
|
2019-05-10 22:25:54 +00:00
|
|
|
#include <tools/ee_actions.h>
|
2020-12-12 03:13:52 +00:00
|
|
|
#include <tools/symbol_editor_drawing_tools.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2019-11-06 19:15:42 +00:00
|
|
|
#include <class_libentry.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <template_fieldnames.h>
|
2012-09-28 17:47:41 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2017-09-15 14:17:44 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_library_manager.h>
|
2018-07-27 20:47:51 +00:00
|
|
|
#include <symbol_tree_pane.h>
|
|
|
|
#include <widgets/lib_tree.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/legacy/sch_legacy_plugin.h>
|
|
|
|
#include <sch_plugins/kicad/sch_sexpr_plugin.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialogs/dialog_lib_new_component.h>
|
2018-07-24 21:16:59 +00:00
|
|
|
#include <dialog_helpers.h>
|
2019-04-08 00:11:06 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2020-12-29 18:59:48 +00:00
|
|
|
/**
|
|
|
|
* Helper control to inquire user what to do on library save as operation.
|
|
|
|
*/
|
|
|
|
class SAVE_AS_HELPER : public wxPanel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SAVE_AS_HELPER( wxWindow* aParent ) :
|
|
|
|
wxPanel( aParent )
|
|
|
|
{
|
|
|
|
m_simpleSaveAs = new wxRadioButton( this, wxID_ANY, _( "Normal save as operation" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
|
|
|
|
m_simpleSaveAs->SetToolTip( _( "Do not perform any additional operations after saving "
|
|
|
|
"library." ) );
|
|
|
|
m_replaceTableEntry = new wxRadioButton( this, wxID_ANY,
|
|
|
|
_( "Replace library table entry" ) );
|
2021-01-12 21:05:25 +00:00
|
|
|
m_replaceTableEntry->SetToolTip( _( "Replace symbol library table entry with new library."
|
|
|
|
"\n\nThe original library will no longer be available "
|
2020-12-29 18:59:48 +00:00
|
|
|
"for use." ) );
|
|
|
|
m_addGlobalTableEntry = new wxRadioButton( this, wxID_ANY,
|
|
|
|
_( "Add new global library table entry" ) );
|
|
|
|
m_addGlobalTableEntry->SetToolTip( _( "Add new entry to the global symbol library table."
|
|
|
|
"\n\nThe symbol library table nickname is suffixed "
|
|
|
|
"with\nan integer to ensure no duplicate table "
|
|
|
|
"entries." ) );
|
|
|
|
m_addProjectTableEntry = new wxRadioButton( this, wxID_ANY,
|
|
|
|
_( "Add new project library table entry" ) );
|
|
|
|
m_addProjectTableEntry->SetToolTip( _( "Add new entry to the project symbol library table."
|
|
|
|
"\n\nThe symbol library table nickname is suffixed "
|
|
|
|
"with\nan integer to ensure no duplicate table "
|
|
|
|
"entries." ) );
|
|
|
|
|
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
sizer->Add( m_simpleSaveAs, 0, wxLEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
sizer->Add( m_replaceTableEntry, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
sizer->Add( m_addGlobalTableEntry, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
sizer->Add( m_addProjectTableEntry, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
|
|
|
|
SetSizerAndFit( sizer );
|
|
|
|
}
|
|
|
|
|
|
|
|
enum SAH_TYPE
|
|
|
|
{
|
|
|
|
UNDEFINED = -1,
|
|
|
|
NORMAL_SAVE_AS,
|
|
|
|
REPLACE_TABLE_ENTRY,
|
|
|
|
ADD_GLOBAL_TABLE_ENTRY,
|
|
|
|
ADD_PROJECT_TABLE_ENTRY
|
|
|
|
};
|
|
|
|
|
|
|
|
SAH_TYPE GetOption() const
|
|
|
|
{
|
|
|
|
if( m_simpleSaveAs->GetValue() )
|
|
|
|
return SAH_TYPE::NORMAL_SAVE_AS;
|
|
|
|
else if( m_replaceTableEntry->GetValue() )
|
|
|
|
return SAH_TYPE::REPLACE_TABLE_ENTRY;
|
|
|
|
else if( m_addGlobalTableEntry->GetValue() )
|
|
|
|
return ADD_GLOBAL_TABLE_ENTRY;
|
|
|
|
else if( m_addProjectTableEntry->GetValue() )
|
|
|
|
return ADD_PROJECT_TABLE_ENTRY;
|
|
|
|
else
|
|
|
|
return UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new panel to add to a wxFileDialog object.
|
|
|
|
*
|
|
|
|
* The caller owns the created object and is responsible for deleting it.
|
|
|
|
*
|
|
|
|
* @param aParent is the parent window that will own the created object.
|
|
|
|
* @return the newly created panel to add to the wxFileDialog.
|
|
|
|
*/
|
|
|
|
static wxWindow* Create( wxWindow* aParent )
|
|
|
|
{
|
|
|
|
wxCHECK( aParent, nullptr );
|
|
|
|
|
|
|
|
return new SAVE_AS_HELPER( aParent );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxRadioButton* m_simpleSaveAs;
|
|
|
|
wxRadioButton* m_replaceTableEntry;
|
|
|
|
wxRadioButton* m_addGlobalTableEntry;
|
|
|
|
wxRadioButton* m_addProjectTableEntry;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::updateTitle()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString lib = GetCurLib();
|
2020-04-13 20:02:35 +00:00
|
|
|
wxString title;
|
2017-10-06 18:07:43 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
2020-09-02 13:22:55 +00:00
|
|
|
title += wxString::Format( _( "%s from schematic" ), m_reference );
|
2020-04-13 20:02:35 +00:00
|
|
|
title += wxT( " \u2014 " );
|
2020-08-31 15:06:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( GetCurPart() )
|
2020-04-13 20:02:35 +00:00
|
|
|
title += GetCurPart()->GetLibId().Format() + wxT( " \u2014 " ) ;
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
if( GetCurPart() && m_libMgr && m_libMgr->IsLibraryReadOnly( GetCurLib() ) )
|
2020-04-13 20:02:35 +00:00
|
|
|
title += _( "[Read Only Library]" ) + wxT( " \u2014 " );
|
2020-08-31 15:06:23 +00:00
|
|
|
}
|
2020-05-16 21:25:13 +00:00
|
|
|
|
2020-04-13 20:02:35 +00:00
|
|
|
title += _( "Symbol Editor" );
|
2016-09-26 17:15:33 +00:00
|
|
|
SetTitle( title );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SelectActiveLibrary( const wxString& aLibrary )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
wxString selectedLib = aLibrary;
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( selectedLib.empty() )
|
|
|
|
selectedLib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !selectedLib.empty() )
|
|
|
|
SetCurLib( selectedLib );
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2018-10-05 12:55:34 +00:00
|
|
|
updateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
wxString SYMBOL_EDIT_FRAME::SelectLibraryFromList()
|
2019-05-10 19:57:24 +00:00
|
|
|
{
|
|
|
|
PROJECT& prj = Prj();
|
|
|
|
|
|
|
|
if( prj.SchSymbolLibTable()->IsEmpty() )
|
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
ShowInfoBarError( _( "No symbol libraries are loaded." ) );
|
2019-05-10 19:57:24 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString headers;
|
|
|
|
|
|
|
|
headers.Add( _( "Library" ) );
|
|
|
|
|
|
|
|
std::vector< wxArrayString > itemsToDisplay;
|
|
|
|
std::vector< wxString > libNicknames = prj.SchSymbolLibTable()->GetLogicalLibs();
|
|
|
|
|
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
2020-07-07 10:17:30 +00:00
|
|
|
for( const wxString& name : libNicknames )
|
2019-05-10 19:57:24 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
|
|
|
|
item.Add( name );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
wxString oldLibName = prj.GetRString( PROJECT::SCH_LIB_SELECT );
|
2019-05-10 19:57:24 +00:00
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Symbol Library" ), headers, itemsToDisplay, oldLibName );
|
2019-05-10 19:57:24 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
wxString libName = dlg.GetTextSelection();
|
2019-05-10 19:57:24 +00:00
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
if( !libName.empty() )
|
2019-05-10 19:57:24 +00:00
|
|
|
{
|
2019-12-02 21:52:14 +00:00
|
|
|
if( prj.SchSymbolLibTable()->HasLibrary( libName ) )
|
|
|
|
prj.SetRString( PROJECT::SCH_LIB_SELECT, libName );
|
2019-05-10 19:57:24 +00:00
|
|
|
else
|
2019-12-02 21:52:14 +00:00
|
|
|
libName = wxEmptyString;
|
2019-05-10 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
return libName;
|
2019-05-10 19:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveCurrentPart()
|
2011-05-28 18:51:32 +00:00
|
|
|
{
|
2018-08-11 20:46:03 +00:00
|
|
|
if( GetCurPart() )
|
2018-07-10 14:33:04 +00:00
|
|
|
{
|
2018-08-11 20:46:03 +00:00
|
|
|
LIB_ID libId = GetCurPart()->GetLibId();
|
|
|
|
const wxString& libName = libId.GetLibNickname();
|
|
|
|
const wxString& partName = libId.GetLibItemName();
|
|
|
|
|
|
|
|
if( m_libMgr->FlushPart( partName, libName ) )
|
|
|
|
{
|
|
|
|
m_libMgr->ClearPartModified( partName, libName );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 14:33:04 +00:00
|
|
|
|
2018-08-11 20:46:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbolAndSelectLib( const LIB_ID& aLibId, int aUnit, int aConvert )
|
2018-08-11 20:46:03 +00:00
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
if( GetCurPart() && GetCurPart()->GetLibId() == aLibId
|
|
|
|
&& GetUnit() == aUnit && GetConvert() == aConvert )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-11 20:46:03 +00:00
|
|
|
if( GetScreen()->IsModify() && GetCurPart() )
|
|
|
|
{
|
2019-06-17 15:59:39 +00:00
|
|
|
if( !HandleUnsavedChanges( this, _( "The current symbol has been modified. "
|
|
|
|
"Save changes?" ),
|
2018-08-11 20:46:03 +00:00
|
|
|
[&]()->bool { return saveCurrentPart(); } ) )
|
|
|
|
{
|
2018-07-10 14:33:04 +00:00
|
|
|
return false;
|
2018-08-11 20:46:03 +00:00
|
|
|
}
|
2018-07-10 14:33:04 +00:00
|
|
|
}
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
SelectActiveLibrary( aLibId.GetLibNickname() );
|
2020-11-15 16:08:31 +00:00
|
|
|
return LoadSymbolFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert );
|
2011-05-28 18:51:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib( const wxString& aAliasName, int aUnit,
|
|
|
|
int aConvert )
|
2011-05-28 18:51:32 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* alias = nullptr;
|
2017-10-06 18:07:43 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ),
|
2017-10-06 18:07:43 +00:00
|
|
|
aAliasName, GetCurLib() );
|
|
|
|
DisplayErrorMessage( this, msg, ioe.What() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-08 21:26:01 +00:00
|
|
|
if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib(), aUnit, aConvert ) )
|
2011-05-28 18:51:32 +00:00
|
|
|
return false;
|
|
|
|
|
2018-01-23 11:15:19 +00:00
|
|
|
// Enable synchronized pin edit mode for symbols with interchangeable units
|
2019-05-11 14:38:05 +00:00
|
|
|
m_SyncPinEdit = !GetCurPart()->UnitsLocked();
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
ClearUndoRedoList();
|
2019-06-04 12:46:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
|
2019-11-06 19:15:42 +00:00
|
|
|
SetShowDeMorgan( GetCurPart()->Flatten()->HasConversion() );
|
2011-05-28 18:51:32 +00:00
|
|
|
|
2017-07-19 17:34:55 +00:00
|
|
|
if( aUnit > 0 )
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2017-07-19 17:34:55 +00:00
|
|
|
|
2011-05-28 18:51:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::LoadOneLibraryPartAux( LIB_PART* aEntry, const wxString& aLibrary,
|
|
|
|
int aUnit, int aConvert )
|
2007-05-06 16:03:28 +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
|
|
|
wxString msg, rootName;
|
2020-08-31 15:06:23 +00:00
|
|
|
bool rebuildMenuAndToolbar = false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( !aEntry || aLibrary.empty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( aEntry->GetName().IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
wxLogWarning( "Symbol in library \"%s\" has empty name field.", aLibrary );
|
2009-08-27 11:41:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-03 14:32:35 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
// Symbols from the schematic are edited in place and not managed by the library manager.
|
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
|
|
|
delete m_my_part;
|
|
|
|
m_my_part = nullptr;
|
|
|
|
|
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
delete screen;
|
|
|
|
SetScreen( m_dummyScreen );
|
|
|
|
m_isSymbolFromSchematic = false;
|
|
|
|
rebuildMenuAndToolbar = true;
|
|
|
|
}
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
LIB_PART* lib_part = m_libMgr->GetBufferedPart( aEntry->GetName(), aLibrary );
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( lib_part, false );
|
2018-09-04 18:49:49 +00:00
|
|
|
|
2018-11-08 21:26:01 +00:00
|
|
|
m_unit = aUnit > 0 ? aUnit : 1;
|
|
|
|
m_convert = aConvert > 0 ? aConvert : 1;
|
2018-09-04 18:49:49 +00:00
|
|
|
|
2019-02-08 14:34:53 +00:00
|
|
|
// The buffered screen for the part
|
|
|
|
SCH_SCREEN* part_screen = m_libMgr->GetScreen( lib_part->GetName(), aLibrary );
|
|
|
|
|
|
|
|
SetScreen( part_screen );
|
2020-12-08 15:27:50 +00:00
|
|
|
SetCurPart( new LIB_PART( *lib_part ), true );
|
2017-11-12 17:55:20 +00:00
|
|
|
SetCurLib( aLibrary );
|
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
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
if( rebuildMenuAndToolbar )
|
|
|
|
{
|
|
|
|
ReCreateMenuBar();
|
|
|
|
ReCreateHToolbar();
|
|
|
|
GetInfoBar()->Dismiss();
|
|
|
|
}
|
|
|
|
|
2018-10-05 12:55:34 +00:00
|
|
|
updateTitle();
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2019-12-13 21:51:59 +00:00
|
|
|
SetShowDeMorgan( GetCurPart()->HasConversion() );
|
2009-09-14 13:24:17 +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
|
|
|
// Display the document information based on the entry selected just in
|
|
|
|
// case the entry is an alias.
|
2020-11-15 16:08:31 +00:00
|
|
|
DisplaySymbolDatasheet();
|
2017-11-13 10:38:20 +00:00
|
|
|
Refresh();
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveAll()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2018-02-16 10:27:43 +00:00
|
|
|
saveAllLibraries( false );
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::CreateNewPart()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2019-05-10 22:24:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
wxArrayString rootSymbols;
|
2017-11-13 11:30:03 +00:00
|
|
|
wxString lib = getTargetLib();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
{
|
|
|
|
lib = SelectLibraryFromList();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
m_libMgr->GetRootSymbolNames( lib, rootSymbols );
|
|
|
|
|
2020-11-03 23:02:38 +00:00
|
|
|
rootSymbols.Sort();
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
DIALOG_LIB_NEW_COMPONENT dlg( this, &rootSymbols );
|
2017-11-12 17:55:20 +00:00
|
|
|
dlg.SetMinSize( dlg.GetSize() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( dlg.GetName().IsEmpty() )
|
|
|
|
{
|
|
|
|
wxMessageBox( _( "This new symbol has no name and cannot be created." ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString name = dlg.GetName();
|
2018-04-15 08:06:53 +00:00
|
|
|
// Currently, symbol names cannot include a space, that breaks libraries:
|
2017-11-12 17:55:20 +00:00
|
|
|
name.Replace( " ", "_" );
|
|
|
|
|
|
|
|
// Test if there is a component with this name already.
|
|
|
|
if( !lib.empty() && m_libMgr->PartExists( name, lib ) )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol \"%s\" already exists in library \"%s\"" ),
|
2017-11-12 17:55:20 +00:00
|
|
|
name, lib );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-13 11:34:37 +00:00
|
|
|
LIB_PART new_part( name ); // do not create part on the heap, it will be buffered soon
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString parentSymbolName = dlg.GetParentSymbolName();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( parentSymbolName.IsEmpty() )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
new_part.GetReferenceField().SetText( dlg.GetReference() );
|
|
|
|
new_part.SetUnitCount( dlg.GetUnitCount() );
|
|
|
|
|
|
|
|
// Initialize new_part.m_TextInside member:
|
|
|
|
// if 0, pin text is outside the body (on the pin)
|
|
|
|
// if > 0, pin text is inside the body
|
|
|
|
|
|
|
|
if( dlg.GetPinNameInside() )
|
|
|
|
{
|
|
|
|
new_part.SetPinNameOffset( dlg.GetPinTextPosition() );
|
|
|
|
|
|
|
|
if( new_part.GetPinNameOffset() == 0 )
|
|
|
|
new_part.SetPinNameOffset( 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_part.SetPinNameOffset( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
( dlg.GetPowerSymbol() ) ? new_part.SetPower() : new_part.SetNormal();
|
|
|
|
new_part.SetShowPinNumbers( dlg.GetShowPinNumber() );
|
|
|
|
new_part.SetShowPinNames( dlg.GetShowPinName() );
|
|
|
|
new_part.LockUnits( dlg.GetLockItems() );
|
2020-09-09 13:03:37 +00:00
|
|
|
new_part.SetIncludeInBom( dlg.GetIncludeInBom() );
|
|
|
|
new_part.SetIncludeOnBoard( dlg.GetIncludeOnBoard() );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
if( dlg.GetUnitCount() < 2 )
|
|
|
|
new_part.LockUnits( false );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
new_part.SetConversion( dlg.GetAlternateBodyStyle() );
|
|
|
|
// must be called after loadPart, that calls SetShowDeMorgan, but
|
|
|
|
// because the symbol is empty,it looks like it has no alternate body
|
|
|
|
SetShowDeMorgan( dlg.GetAlternateBodyStyle() );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* parent = m_libMgr->GetAlias( parentSymbolName, lib );
|
|
|
|
wxCHECK( parent, /* void */ );
|
|
|
|
new_part.SetParent( parent );
|
2020-05-30 14:33:05 +00:00
|
|
|
|
|
|
|
// Inherit the parent mandatory field attributes.
|
|
|
|
for( int id=0; id<MANDATORY_FIELDS; ++id )
|
|
|
|
{
|
|
|
|
LIB_FIELD* field = new_part.GetField( id );
|
|
|
|
|
|
|
|
// the MANDATORY_FIELDS are exactly that in RAM.
|
|
|
|
wxCHECK( field, /* void */ );
|
|
|
|
|
|
|
|
LIB_FIELD* parentField = parent->GetField( id );
|
|
|
|
|
|
|
|
wxCHECK( parentField, /* void */ );
|
|
|
|
|
|
|
|
*field = *parentField;
|
|
|
|
|
2020-11-11 17:33:53 +00:00
|
|
|
switch( id )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
case REFERENCE_FIELD:
|
2020-11-11 17:33:53 +00:00
|
|
|
// parent's reference already copied
|
|
|
|
break;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
case VALUE_FIELD:
|
2020-05-30 14:33:05 +00:00
|
|
|
field->SetText( name );
|
2020-11-11 17:33:53 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
case DATASHEET_FIELD:
|
2020-11-11 17:33:53 +00:00
|
|
|
// - footprint might be the same as parent, but might not
|
|
|
|
// - datasheet is most likely different
|
|
|
|
// - probably best to play it safe and copy neither
|
|
|
|
field->SetText( wxEmptyString );
|
|
|
|
break;
|
|
|
|
}
|
2020-05-30 14:33:05 +00:00
|
|
|
|
|
|
|
field->SetParent( &new_part );
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 11:34:37 +00:00
|
|
|
m_libMgr->UpdatePart( &new_part, lib );
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2019-06-05 22:29:59 +00:00
|
|
|
LoadPart( name, lib, 1 );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Save()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
if( getTargetPart() == m_my_part )
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
if( IsSymbolFromSchematic() )
|
|
|
|
{
|
|
|
|
SCH_EDIT_FRAME* schframe = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
|
2020-12-11 22:44:10 +00:00
|
|
|
|
2020-12-25 11:55:45 +00:00
|
|
|
if( schframe )
|
|
|
|
{
|
|
|
|
schframe->UpdateSymbolFromEditor( *m_my_part );
|
|
|
|
GetScreen()->ClrModify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveCurrentPart();
|
|
|
|
}
|
2020-05-16 21:25:13 +00:00
|
|
|
}
|
2020-12-25 11:55:45 +00:00
|
|
|
else if( !getTargetLibId().GetLibNickname().empty() )
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
2021-01-13 02:12:59 +00:00
|
|
|
LIB_ID libId = getTargetLibId();
|
2020-12-25 11:55:45 +00:00
|
|
|
const wxString& libName = libId.GetLibNickname();
|
|
|
|
|
|
|
|
if( m_libMgr->IsLibraryReadOnly( libName ) )
|
|
|
|
{
|
2020-12-27 16:28:52 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol library '%s' is not writeable." ),
|
|
|
|
libName );
|
2020-12-25 11:55:45 +00:00
|
|
|
wxString msg2 = _( "You must save to a different location." );
|
|
|
|
|
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) == wxID_OK )
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveLibrary( libName, false );
|
|
|
|
}
|
2018-07-27 10:46:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2018-07-27 10:46:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-27 16:28:52 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::SaveLibraryAs()
|
2018-07-27 10:46:09 +00:00
|
|
|
{
|
2020-12-27 16:28:52 +00:00
|
|
|
wxCHECK( !getTargetLibId().GetLibNickname().empty(), /* void */ );
|
2018-07-27 10:46:09 +00:00
|
|
|
|
2020-12-27 16:28:52 +00:00
|
|
|
const wxString& libName = getTargetLibId().GetLibNickname();
|
|
|
|
|
|
|
|
saveLibrary( libName, true );
|
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SYMBOL_EDIT_FRAME::SaveSymbolAs()
|
|
|
|
{
|
|
|
|
wxCHECK( getTargetLibId().IsValid(), /* void */ );
|
|
|
|
|
|
|
|
savePartAs();
|
2017-11-13 22:13:10 +00:00
|
|
|
|
2019-11-26 21:38:57 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::savePartAs()
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
LIB_PART* part = getTargetPart();
|
2018-07-24 21:16:59 +00:00
|
|
|
|
|
|
|
if( part )
|
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
LIB_ID old_lib_id = part->GetLibId();
|
|
|
|
wxString old_name = old_lib_id.GetLibItemName();
|
|
|
|
wxString old_lib = old_lib_id.GetLibNickname();
|
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE* tbl = Prj().SchSymbolLibTable();
|
|
|
|
wxArrayString headers;
|
2018-07-24 21:16:59 +00:00
|
|
|
std::vector< wxArrayString > itemsToDisplay;
|
2020-12-25 11:55:45 +00:00
|
|
|
std::vector< wxString > libNicknames = tbl->GetLogicalLibs();
|
2018-07-24 21:16:59 +00:00
|
|
|
|
2019-12-02 23:33:45 +00:00
|
|
|
headers.Add( _( "Nickname" ) );
|
|
|
|
headers.Add( _( "Description" ) );
|
|
|
|
|
2020-12-25 11:55:45 +00:00
|
|
|
for( const wxString& name : libNicknames )
|
2018-07-24 21:16:59 +00:00
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( name );
|
|
|
|
item.Add( tbl->GetDescription( name ) );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
|
2019-12-02 21:52:14 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Save Copy of Symbol" ), headers, itemsToDisplay, old_lib );
|
2018-07-24 21:16:59 +00:00
|
|
|
dlg.SetListLabel( _( "Save in library:" ) );
|
|
|
|
dlg.SetOKLabel( _( "Save" ) );
|
|
|
|
|
|
|
|
wxBoxSizer* bNameSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
|
|
|
wxStaticText* label = new wxStaticText( &dlg, wxID_ANY, _( "Name:" ),
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
bNameSizer->Add( label, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
|
|
|
|
|
|
|
|
wxTextCtrl* nameTextCtrl = new wxTextCtrl( &dlg, wxID_ANY, old_name,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
bNameSizer->Add( nameTextCtrl, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
|
|
|
|
|
|
wxSizer* mainSizer = dlg.GetSizer();
|
|
|
|
mainSizer->Prepend( bNameSizer, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
|
|
|
|
|
|
|
|
// Move nameTextCtrl to the head of the tab-order
|
|
|
|
if( dlg.GetChildren().DeleteObject( nameTextCtrl ) )
|
|
|
|
dlg.GetChildren().Insert( nameTextCtrl );
|
|
|
|
|
|
|
|
dlg.SetInitialFocus( nameTextCtrl );
|
|
|
|
|
|
|
|
dlg.Layout();
|
|
|
|
mainSizer->Fit( &dlg );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return; // canceled by user
|
|
|
|
|
|
|
|
wxString new_lib = dlg.GetTextSelection();
|
|
|
|
|
|
|
|
if( new_lib.IsEmpty() )
|
|
|
|
{
|
2019-12-12 15:44:53 +00:00
|
|
|
DisplayError( this, _( "No library specified. Symbol could not be saved." ) );
|
2018-07-24 21:16:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-13 21:51:59 +00:00
|
|
|
// @todo Either check the selecteced library to see if the parent symbol name is in
|
|
|
|
// the new library and/or copy the parent symbol as well. This is the lazy
|
|
|
|
// solution to ensure derived parts do not get orphaned.
|
|
|
|
if( part->IsAlias() && new_lib != old_lib )
|
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
DisplayError( this, _( "Derived symbols must be saved in the same library as their "
|
|
|
|
"parent symbol." ) );
|
2019-12-13 21:51:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-24 21:16:59 +00:00
|
|
|
wxString new_name = nameTextCtrl->GetValue();
|
|
|
|
new_name.Trim( true );
|
|
|
|
new_name.Trim( false );
|
|
|
|
new_name.Replace( " ", "_" );
|
|
|
|
|
|
|
|
if( new_name.IsEmpty() )
|
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
// This is effectively a cancel. No need to nag the user about it.
|
2018-07-24 21:16:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test if there is a component with this name already.
|
|
|
|
if( m_libMgr->PartExists( new_name, new_lib ) )
|
|
|
|
{
|
2020-12-25 11:55:45 +00:00
|
|
|
wxString msg = wxString::Format( _( "Symbol '%s' already exists in library '%s'" ),
|
|
|
|
new_name,
|
|
|
|
new_lib );
|
2018-07-24 21:16:59 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_PART new_part( *part );
|
|
|
|
new_part.SetName( new_name );
|
|
|
|
|
|
|
|
m_libMgr->UpdatePart( &new_part, new_lib );
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( new_lib, new_part.GetName() ) );
|
2019-12-13 21:51:59 +00:00
|
|
|
LoadPart( new_name, new_lib, m_unit );
|
2018-07-24 21:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::UpdateAfterSymbolProperties( wxString* aOldName )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( m_my_part, /* void */ );
|
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString lib = GetCurLib();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-22 15:39:34 +00:00
|
|
|
if( !lib.IsEmpty() && aOldName && *aOldName != m_my_part->GetName() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-11 14:38:05 +00:00
|
|
|
// Test the current library for name conflicts
|
2020-11-22 15:39:34 +00:00
|
|
|
if( m_libMgr->PartExists( m_my_part->GetName(), lib ) )
|
2019-05-11 14:38:05 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "The name '%s' conflicts with an existing entry in the library '%s'." ),
|
2019-11-06 19:15:42 +00:00
|
|
|
m_my_part->GetName(),
|
2019-05-11 14:38:05 +00:00
|
|
|
lib );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-11 14:38:05 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
2019-11-06 19:15:42 +00:00
|
|
|
m_my_part->SetName( *aOldName );
|
2019-05-11 14:38:05 +00:00
|
|
|
}
|
|
|
|
else
|
2020-07-16 00:08:31 +00:00
|
|
|
{
|
2019-12-13 21:51:59 +00:00
|
|
|
m_libMgr->UpdatePartAfterRename( m_my_part, *aOldName, lib );
|
2020-07-16 00:08:31 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-07-16 00:08:31 +00:00
|
|
|
// Reselect the renamed part
|
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, m_my_part->GetName() ) );
|
|
|
|
}
|
2019-05-11 14:38:05 +00:00
|
|
|
|
|
|
|
RebuildSymbolUnitsList();
|
2019-11-06 19:15:42 +00:00
|
|
|
SetShowDeMorgan( GetCurPart()->Flatten()->HasConversion() );
|
2019-05-11 14:38:05 +00:00
|
|
|
updateTitle();
|
2020-11-15 16:08:31 +00:00
|
|
|
DisplaySymbolDatasheet();
|
2019-05-11 14:38:05 +00:00
|
|
|
|
|
|
|
RebuildView();
|
|
|
|
OnModify();
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::DeletePartFromLibrary()
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
LIB_ID libId = getTargetLibId();
|
|
|
|
|
|
|
|
if( m_libMgr->IsPartModified( libId.GetLibItemName(), libId.GetLibNickname() )
|
2019-12-12 15:44:53 +00:00
|
|
|
&& !IsOK( this, _( wxString::Format( "The symbol \"%s\" has been modified\n"
|
2019-06-05 22:29:59 +00:00
|
|
|
"Do you want to remove it from the library?",
|
|
|
|
libId.GetUniStringLibItemName() ) ) ) )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-12 15:44:53 +00:00
|
|
|
if( m_libMgr->HasDerivedSymbols( libId.GetLibItemName(), libId.GetLibNickname() ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "The symbol \"%s\" is used to derive other symbols.\n"
|
|
|
|
"Deleting this symbol will delete all of the symbols derived from it.\n\n"
|
|
|
|
"Do you wish to delete this symbol and all of it's derivatives?" ),
|
|
|
|
libId.GetLibItemName().wx_str() );
|
|
|
|
|
|
|
|
wxMessageDialog::ButtonLabel yesButtonLabel( _( "Delete Symbol" ) );
|
|
|
|
wxMessageDialog::ButtonLabel noButtonLabel( _( "Keep Symbol" ) );
|
|
|
|
|
|
|
|
wxMessageDialog dlg( this, msg, _( "Warning" ),
|
|
|
|
wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION | wxCENTER );
|
|
|
|
dlg.SetYesNoLabels( yesButtonLabel, noButtonLabel );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_NO )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
if( isCurrentPart( libId ) )
|
|
|
|
emptyScreen();
|
|
|
|
|
|
|
|
m_libMgr->RemovePart( libId.GetLibItemName(), libId.GetLibNickname() );
|
2018-10-16 15:50:29 +00:00
|
|
|
|
2019-12-02 20:24:16 +00:00
|
|
|
m_treePane->GetLibTree()->RefreshLibTree();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::CopyPartToClipboard()
|
2017-11-13 19:39:36 +00:00
|
|
|
{
|
2018-08-29 20:53:41 +00:00
|
|
|
int dummyUnit;
|
|
|
|
LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit );
|
|
|
|
LIB_PART* part = m_libMgr->GetBufferedPart( libId.GetLibItemName(), libId.GetLibNickname() );
|
|
|
|
|
|
|
|
if( !part )
|
|
|
|
return;
|
|
|
|
|
2020-07-16 00:57:17 +00:00
|
|
|
std::unique_ptr< LIB_PART> tmp = part->Flatten();
|
2019-04-08 00:11:06 +00:00
|
|
|
STRING_FORMATTER formatter;
|
2020-07-16 00:57:17 +00:00
|
|
|
SCH_SEXPR_PLUGIN::FormatPart( tmp.get(), formatter );
|
2019-04-08 00:11:06 +00:00
|
|
|
|
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock || !clipboard->IsOpened() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto data = new wxTextDataObject( wxString( formatter.GetString().c_str(), wxConvUTF8 ) );
|
|
|
|
clipboard->SetData( data );
|
|
|
|
|
|
|
|
clipboard->Flush();
|
2018-08-29 20:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::DuplicatePart( bool aFromClipboard )
|
2018-08-29 20:53:41 +00:00
|
|
|
{
|
|
|
|
int dummyUnit;
|
|
|
|
LIB_ID libId = m_treePane->GetLibTree()->GetSelectedLibId( &dummyUnit );
|
2017-11-13 19:39:36 +00:00
|
|
|
wxString lib = libId.GetLibNickname();
|
|
|
|
|
|
|
|
if( !m_libMgr->LibraryExists( lib ) )
|
|
|
|
return;
|
|
|
|
|
2018-08-29 20:53:41 +00:00
|
|
|
LIB_PART* srcPart = nullptr;
|
2019-04-08 00:11:06 +00:00
|
|
|
LIB_PART* newPart = nullptr;
|
2018-08-29 20:53:41 +00:00
|
|
|
|
2019-06-05 22:29:59 +00:00
|
|
|
if( aFromClipboard )
|
2019-04-08 00:11:06 +00:00
|
|
|
{
|
|
|
|
auto clipboard = wxTheClipboard;
|
|
|
|
wxClipboardLocker clipboardLock( clipboard );
|
|
|
|
|
|
|
|
if( !clipboardLock || ! clipboard->IsSupported( wxDF_TEXT ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxTextDataObject data;
|
|
|
|
clipboard->GetData( data );
|
|
|
|
wxString partSource = data.GetText();
|
|
|
|
|
|
|
|
STRING_LINE_READER reader( TO_UTF8( partSource ), "Clipboard" );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-07-16 00:23:10 +00:00
|
|
|
newPart = SCH_SEXPR_PLUGIN::ParsePart( reader );
|
2019-04-08 00:11:06 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR& e )
|
|
|
|
{
|
2020-10-16 00:39:55 +00:00
|
|
|
wxLogMessage( "Can not paste: %s", e.Problem() );
|
2019-04-08 00:11:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 20:53:41 +00:00
|
|
|
else
|
2019-06-05 22:29:59 +00:00
|
|
|
{
|
|
|
|
srcPart = m_libMgr->GetBufferedPart( libId.GetLibItemName(), lib );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
wxCHECK( srcPart, /* void */ );
|
|
|
|
|
2019-06-05 22:29:59 +00:00
|
|
|
newPart = new LIB_PART( *srcPart );
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Derive from same parent.
|
|
|
|
if( srcPart->IsAlias() )
|
|
|
|
{
|
|
|
|
std::shared_ptr< LIB_PART > srcParent = srcPart->GetParent().lock();
|
|
|
|
|
|
|
|
wxCHECK( srcParent, /* void */ );
|
|
|
|
|
|
|
|
newPart->SetParent( srcParent.get() );
|
|
|
|
}
|
2019-06-05 22:29:59 +00:00
|
|
|
}
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2019-04-08 00:11:06 +00:00
|
|
|
if( !newPart )
|
2017-11-13 19:39:36 +00:00
|
|
|
return;
|
|
|
|
|
2020-03-30 16:23:21 +00:00
|
|
|
ensureUniqueName( newPart, lib );
|
2019-04-08 00:11:06 +00:00
|
|
|
m_libMgr->UpdatePart( newPart, lib );
|
2020-12-21 17:21:01 +00:00
|
|
|
|
|
|
|
LoadOneLibraryPartAux( newPart, lib, GetUnit(), GetConvert() );
|
|
|
|
|
2018-08-25 12:21:09 +00:00
|
|
|
SyncLibraries( false );
|
2019-04-08 00:11:06 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( LIB_ID( lib, newPart->GetName() ) );
|
|
|
|
|
|
|
|
delete newPart;
|
2017-11-13 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::ensureUniqueName( LIB_PART* aPart, const wxString& aLibrary )
|
2017-11-13 19:39:36 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxCHECK( aPart, /* void */ );
|
|
|
|
|
2019-12-17 16:09:59 +00:00
|
|
|
int i = 1;
|
2020-03-30 16:23:21 +00:00
|
|
|
wxString newName = aPart->GetName();
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2019-12-16 15:11:06 +00:00
|
|
|
// Append a number to the name until the name is unique in the library.
|
2020-03-30 16:23:21 +00:00
|
|
|
while( m_libMgr->PartExists( newName, aLibrary ) )
|
|
|
|
newName.Printf( "%s_%d", aPart->GetName(), i++ );
|
2017-11-13 19:39:36 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
aPart->SetName( newName );
|
2017-11-13 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::Revert( bool aConfirm )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
LIB_ID libId = getTargetLibId();
|
2018-07-27 10:46:09 +00:00
|
|
|
const wxString& libName = libId.GetLibNickname();
|
2019-11-06 19:15:42 +00:00
|
|
|
|
|
|
|
// Empty if this is the library itself that is selected.
|
|
|
|
const wxString& partName = libId.GetLibItemName();
|
2018-07-27 10:46:09 +00:00
|
|
|
|
2018-11-20 20:11:05 +00:00
|
|
|
wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ),
|
|
|
|
partName.IsEmpty() ? libName : partName );
|
2018-10-03 21:44:17 +00:00
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
if( aConfirm && !ConfirmRevertDialog( this, msg ) )
|
2018-07-27 10:46:09 +00:00
|
|
|
return;
|
|
|
|
|
2018-11-20 20:14:00 +00:00
|
|
|
bool reload_currentPart = false;
|
2018-08-19 08:25:12 +00:00
|
|
|
wxString curr_partName = partName;
|
|
|
|
|
2018-11-20 20:14:00 +00:00
|
|
|
if( GetCurPart() )
|
2018-08-19 08:25:12 +00:00
|
|
|
{
|
2018-11-20 20:14:00 +00:00
|
|
|
// the library itself is reverted: the current part will be reloaded only if it is
|
|
|
|
// owned by this library
|
|
|
|
if( partName.IsEmpty() )
|
|
|
|
{
|
|
|
|
LIB_ID curr_libId = GetCurPart()->GetLibId();
|
|
|
|
reload_currentPart = libName == curr_libId.GetLibNickname();
|
2018-08-19 08:25:12 +00:00
|
|
|
|
2018-11-20 20:14:00 +00:00
|
|
|
if( reload_currentPart )
|
|
|
|
curr_partName = curr_libId.GetLibItemName();
|
|
|
|
}
|
|
|
|
else
|
2019-11-06 19:15:42 +00:00
|
|
|
{
|
2018-11-20 20:14:00 +00:00
|
|
|
reload_currentPart = isCurrentPart( libId );
|
2019-11-06 19:15:42 +00:00
|
|
|
}
|
2018-08-19 08:25:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
int unit = m_unit;
|
|
|
|
|
2018-08-19 08:25:12 +00:00
|
|
|
if( reload_currentPart )
|
2017-11-12 17:55:20 +00:00
|
|
|
emptyScreen();
|
|
|
|
|
2018-07-27 10:46:09 +00:00
|
|
|
if( partName.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_libMgr->RevertLibrary( libName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
libId = m_libMgr->RevertPart( libId.GetLibItemName(), libId.GetLibNickname() );
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
m_treePane->GetLibTree()->SelectLibId( libId );
|
2018-07-27 10:46:09 +00:00
|
|
|
m_libMgr->ClearPartModified( libId.GetLibItemName(), libId.GetLibNickname() );
|
|
|
|
}
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2018-08-19 08:25:12 +00:00
|
|
|
if( reload_currentPart && m_libMgr->PartExists( curr_partName, libName ) )
|
2019-06-05 22:29:59 +00:00
|
|
|
LoadPart( curr_partName, libName, unit );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2018-07-27 10:46:09 +00:00
|
|
|
m_treePane->Refresh();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::RevertAll()
|
2019-06-13 11:44:12 +00:00
|
|
|
{
|
|
|
|
wxCHECK_RET( m_libMgr, "Library manager object not created." );
|
|
|
|
|
|
|
|
Revert( false );
|
|
|
|
m_libMgr->RevertAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::LoadPart( const wxString& aAlias, const wxString& aLibrary, int aUnit )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
LIB_PART* part = m_libMgr->GetBufferedPart( aAlias, aLibrary );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !part )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( _( "Symbol name \"%s\" not found in library \"%s\"" ), aAlias, aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-08 09:48:33 +00:00
|
|
|
// Optimize default edit options for this symbol
|
|
|
|
// Usually if units are locked, graphic items are specific to each unit
|
|
|
|
// and if units are interchangeable, graphic items are common to units
|
2020-12-12 03:13:52 +00:00
|
|
|
SYMBOL_EDITOR_DRAWING_TOOLS* tools = GetToolManager()->GetTool<SYMBOL_EDITOR_DRAWING_TOOLS>();
|
2020-05-23 15:50:08 +00:00
|
|
|
tools->SetDrawSpecificUnit( part->UnitsLocked() );
|
2018-01-08 09:48:33 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LoadOneLibraryPartAux( part, aLibrary, aUnit, 0 );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-08-27 11:41:56 +00:00
|
|
|
wxString msg;
|
2020-12-29 18:59:48 +00:00
|
|
|
SAVE_AS_HELPER::SAH_TYPE type = SAVE_AS_HELPER::SAH_TYPE::UNDEFINED;
|
2020-04-16 16:43:50 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T fileType = SCH_IO_MGR::SCH_FILE_T::SCH_KICAD;
|
2017-10-06 18:07:43 +00:00
|
|
|
PROJECT& prj = Prj();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2019-05-10 22:24:02 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::cancelInteractive, true );
|
2009-09-14 13:24:17 +00:00
|
|
|
|
2017-11-13 09:55:05 +00:00
|
|
|
if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
|
2009-09-14 13:24:17 +00:00
|
|
|
{
|
2020-08-31 13:19:57 +00:00
|
|
|
ShowInfoBarError( _( "No library specified." ) );
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-09-14 13:24:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
if( aNewFile )
|
* 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-11-13 09:55:05 +00:00
|
|
|
SEARCH_STACK* search = prj.SchSearchS();
|
* 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
|
|
|
|
|
|
|
// Get a new name for the library
|
2014-06-10 15:56:43 +00:00
|
|
|
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
|
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
|
|
|
|
2014-06-10 15:56:43 +00:00
|
|
|
if( !default_path )
|
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
|
|
|
default_path = search->LastVisitedPath();
|
* 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-11-13 09:55:05 +00:00
|
|
|
fn.SetName( aLibrary );
|
2020-04-16 16:43:50 +00:00
|
|
|
fn.SetExt( KiCadSymbolLibFileExtension );
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString wildcards = KiCadSymbolLibFileWildcard();
|
2020-02-13 13:39:52 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
wxFileDialog dlg( this, wxString::Format( _( "Save Library \"%s\" As..." ), aLibrary ),
|
2020-02-13 13:39:52 +00:00
|
|
|
default_path, fn.GetFullName(), wildcards,
|
2010-03-18 20:35:29 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2020-12-29 18:59:48 +00:00
|
|
|
dlg.SetExtraControlCreator( &SAVE_AS_HELPER::Create );
|
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2010-03-18 20:35:29 +00:00
|
|
|
fn = dlg.GetPath();
|
|
|
|
|
2020-07-18 14:25:29 +00:00
|
|
|
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
|
|
|
|
|
2020-05-15 13:25:11 +00:00
|
|
|
if( fn.GetExt().IsEmpty() )
|
2020-02-13 13:39:52 +00:00
|
|
|
fn.SetExt( KiCadSymbolLibFileExtension );
|
2020-12-29 18:59:48 +00:00
|
|
|
|
|
|
|
const SAVE_AS_HELPER* sah = dynamic_cast<const SAVE_AS_HELPER*>( dlg.GetExtraControl() );
|
|
|
|
wxCHECK( sah, false );
|
|
|
|
|
|
|
|
type = sah->GetOption();
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-13 09:55:05 +00:00
|
|
|
fn = prj.SchSymbolLibTable()->GetFullURI( aLibrary );
|
2020-04-16 16:43:50 +00:00
|
|
|
fileType = SCH_IO_MGR::GuessPluginTypeFromLibPath( fn.GetFullPath() );
|
2010-03-18 20:35:29 +00:00
|
|
|
}
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2017-01-27 15:56:36 +00:00
|
|
|
// Verify the user has write privileges before attempting to save the library file.
|
2020-06-04 17:25:36 +00:00
|
|
|
if( !aNewFile && m_libMgr->IsLibraryReadOnly( aLibrary ) )
|
2013-02-07 17:35:37 +00:00
|
|
|
return false;
|
2011-08-12 17:43:16 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
ClearMsgPanel();
|
2009-01-29 14:26:20 +00:00
|
|
|
|
2020-05-16 21:25:13 +00:00
|
|
|
// Copy .kicad_symb file to .bak.
|
2017-11-13 14:15:10 +00:00
|
|
|
if( !backupFile( fn, "bak" ) )
|
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !m_libMgr->SaveLibrary( aLibrary, fn.GetFullPath(), fileType ) )
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Failed to save changes to symbol library file \"%s\"" ),
|
2017-11-13 14:15:10 +00:00
|
|
|
fn.GetFullPath() );
|
2017-11-13 13:58:39 +00:00
|
|
|
DisplayErrorMessage( this, _( "Error saving library" ), msg );
|
|
|
|
return false;
|
2011-11-11 20:10:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 22:13:10 +00:00
|
|
|
if( !aNewFile )
|
2020-12-29 18:59:48 +00:00
|
|
|
{
|
2017-11-13 22:13:10 +00:00
|
|
|
m_libMgr->ClearLibraryModified( aLibrary );
|
2020-12-29 18:59:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool resyncLibTree = false;
|
|
|
|
wxString originalLibNickname = getTargetLib();
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case SAVE_AS_HELPER::SAH_TYPE::REPLACE_TABLE_ENTRY:
|
|
|
|
resyncLibTree = replaceLibTableEntry( originalLibNickname, fn.GetFullPath() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAVE_AS_HELPER::SAH_TYPE::ADD_GLOBAL_TABLE_ENTRY:
|
|
|
|
resyncLibTree = addLibTableEntry( fn.GetFullPath() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAVE_AS_HELPER::SAH_TYPE::ADD_PROJECT_TABLE_ENTRY:
|
|
|
|
resyncLibTree = addLibTableEntry( fn.GetFullPath(), PROJECT_LIB_TABLE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAVE_AS_HELPER::SAH_TYPE::NORMAL_SAVE_AS:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( resyncLibTree )
|
|
|
|
{
|
|
|
|
FreezeSearchTree();
|
|
|
|
SyncLibraries( true );
|
|
|
|
ThawSearchTree();
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 22:13:10 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
ClearMsgPanel();
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Symbol library file \"%s\" saved" ), fn.GetFullPath() );
|
2019-05-06 12:32:51 +00:00
|
|
|
RebuildSymbolUnitsList();
|
2017-03-04 19:49:55 +00:00
|
|
|
|
2013-02-07 17:35:37 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
bool SYMBOL_EDIT_FRAME::saveAllLibraries( bool aRequireConfirmation )
|
2017-11-13 09:55:05 +00:00
|
|
|
{
|
2020-12-11 22:44:10 +00:00
|
|
|
wxString msg, msg2;
|
|
|
|
bool doSave = true;
|
|
|
|
int dirtyCount = 0;
|
|
|
|
bool applyToAll = false;
|
|
|
|
bool retv = true;
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2017-11-13 09:55:05 +00:00
|
|
|
{
|
2018-08-01 13:36:42 +00:00
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
|
|
|
dirtyCount++;
|
|
|
|
}
|
2017-11-13 09:55:05 +00:00
|
|
|
|
2020-12-11 22:44:10 +00:00
|
|
|
for( const wxString& libNickname : m_libMgr->GetLibraryNames() )
|
2018-08-01 13:36:42 +00:00
|
|
|
{
|
|
|
|
if( m_libMgr->IsLibraryModified( libNickname ) )
|
2018-02-16 10:27:43 +00:00
|
|
|
{
|
2018-08-01 13:36:42 +00:00
|
|
|
if( aRequireConfirmation && !applyToAll )
|
|
|
|
{
|
2020-10-22 11:48:28 +00:00
|
|
|
msg.Printf( _( "Save changes to \"%s\" before closing?" ), libNickname );
|
2018-08-01 13:36:42 +00:00
|
|
|
|
2018-08-01 23:06:12 +00:00
|
|
|
switch( UnsavedChangesDialog( this, msg, dirtyCount > 1 ? &applyToAll : nullptr ) )
|
2018-08-01 13:36:42 +00:00
|
|
|
{
|
|
|
|
case wxID_YES: doSave = true; break;
|
|
|
|
case wxID_NO: doSave = false; break;
|
|
|
|
default:
|
|
|
|
case wxID_CANCEL: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( doSave )
|
|
|
|
{
|
2018-08-01 23:06:12 +00:00
|
|
|
// If saving under existing name fails then do a Save As..., and if that
|
|
|
|
// fails then cancel close action.
|
2020-12-11 22:44:10 +00:00
|
|
|
|
|
|
|
if( !m_libMgr->IsLibraryReadOnly( libNickname ) )
|
2020-10-22 11:48:28 +00:00
|
|
|
{
|
2020-12-11 22:44:10 +00:00
|
|
|
if( saveLibrary( libNickname, false ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Symbol library '%s' is not writeable." ), libNickname );
|
|
|
|
msg2 = _( "You must save to a different location." );
|
|
|
|
|
|
|
|
if( dirtyCount == 1 )
|
|
|
|
{
|
|
|
|
if( OKOrCancelDialog( this, _( "Warning" ), msg, msg2 ) != wxID_OK )
|
|
|
|
{
|
|
|
|
retv = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_infoBar->Dismiss();
|
|
|
|
m_infoBar->ShowMessageFor( msg + wxS( " " ) + msg2,
|
|
|
|
2000, wxICON_EXCLAMATION );
|
|
|
|
|
|
|
|
while( m_infoBar->IsShown() )
|
|
|
|
wxSafeYield();
|
|
|
|
|
|
|
|
retv = false;
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-22 11:48:28 +00:00
|
|
|
}
|
2020-05-16 21:25:13 +00:00
|
|
|
|
|
|
|
if( !saveLibrary( libNickname, true ) )
|
2020-10-29 12:22:38 +00:00
|
|
|
retv = false;
|
2018-08-01 13:36:42 +00:00
|
|
|
}
|
2017-11-13 09:55:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 12:22:38 +00:00
|
|
|
return retv;
|
2017-11-13 09:55:05 +00:00
|
|
|
}
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
void SYMBOL_EDIT_FRAME::DisplaySymbolDatasheet()
|
2020-10-31 01:27:16 +00:00
|
|
|
{
|
|
|
|
EDA_DRAW_FRAME::ClearMsgPanel();
|
|
|
|
|
|
|
|
if( !m_my_part )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString msg = m_my_part->GetName();
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Name" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
if( m_my_part->IsAlias() )
|
|
|
|
{
|
|
|
|
PART_SPTR parent = m_my_part->GetParent().lock();
|
|
|
|
|
|
|
|
msg = parent ? parent->GetName() : _( "Undefined!" );
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Parent" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" );
|
|
|
|
msg = UnitLetter[m_unit];
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Unit" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
if( m_convert > 1 )
|
|
|
|
msg = _( "Convert" );
|
|
|
|
else
|
|
|
|
msg = _( "Normal" );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Body" ), msg, 8 );
|
2020-10-31 01:27:16 +00:00
|
|
|
|
|
|
|
if( m_my_part->IsPower() )
|
|
|
|
msg = _( "Power Symbol" );
|
|
|
|
else
|
|
|
|
msg = _( "Symbol" );
|
|
|
|
|
2020-11-18 15:36:47 +00:00
|
|
|
AppendMsgPanel( _( "Type" ), msg, 8 );
|
|
|
|
AppendMsgPanel( _( "Description" ), m_my_part->GetDescription(), 8 );
|
|
|
|
AppendMsgPanel( _( "Keywords" ), m_my_part->GetKeyWords() );
|
|
|
|
AppendMsgPanel( _( "Datasheet" ), m_my_part->GetDatasheetField().GetText() );
|
2020-10-31 01:27:16 +00:00
|
|
|
}
|