Symbol editor: remove duplicate legacy code path
Fixes https://gitlab.com/kicad/code/kicad/issues/7139
This commit is contained in:
parent
e10025db64
commit
65f90f141f
|
@ -59,10 +59,6 @@ enum id_eeschema_frm
|
||||||
/* Library editor horizontal toolbar IDs. */
|
/* Library editor horizontal toolbar IDs. */
|
||||||
ID_LIBEDIT_SELECT_PART_NUMBER,
|
ID_LIBEDIT_SELECT_PART_NUMBER,
|
||||||
|
|
||||||
/* Library editor vertical toolbar IDs. */
|
|
||||||
ID_LIBEDIT_IMPORT_BODY_BUTT,
|
|
||||||
ID_LIBEDIT_EXPORT_BODY_BUTT,
|
|
||||||
|
|
||||||
/* Library viewer horizontal toolbar IDs */
|
/* Library viewer horizontal toolbar IDs */
|
||||||
ID_LIBVIEW_SELECT_PART,
|
ID_LIBVIEW_SELECT_PART,
|
||||||
ID_LIBVIEW_NEXT,
|
ID_LIBVIEW_NEXT,
|
||||||
|
|
|
@ -79,10 +79,6 @@ BEGIN_EVENT_TABLE( SYMBOL_EDIT_FRAME, EDA_DRAW_FRAME )
|
||||||
|
|
||||||
EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, SYMBOL_EDIT_FRAME::OnSelectUnit )
|
EVT_COMBOBOX( ID_LIBEDIT_SELECT_PART_NUMBER, SYMBOL_EDIT_FRAME::OnSelectUnit )
|
||||||
|
|
||||||
// Right vertical toolbar.
|
|
||||||
EVT_TOOL( ID_LIBEDIT_IMPORT_BODY_BUTT, SYMBOL_EDIT_FRAME::OnImportBody )
|
|
||||||
EVT_TOOL( ID_LIBEDIT_EXPORT_BODY_BUTT, SYMBOL_EDIT_FRAME::OnExportBody )
|
|
||||||
|
|
||||||
// menubar commands
|
// menubar commands
|
||||||
EVT_MENU( wxID_EXIT, SYMBOL_EDIT_FRAME::OnExitKiCad )
|
EVT_MENU( wxID_EXIT, SYMBOL_EDIT_FRAME::OnExitKiCad )
|
||||||
EVT_MENU( wxID_CLOSE, SYMBOL_EDIT_FRAME::CloseWindow )
|
EVT_MENU( wxID_CLOSE, SYMBOL_EDIT_FRAME::CloseWindow )
|
||||||
|
@ -487,9 +483,6 @@ void SYMBOL_EDIT_FRAME::setupUIConditions()
|
||||||
mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor,
|
mgr->SetConditions( EE_ACTIONS::placeSymbolAnchor,
|
||||||
EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) );
|
EDIT_TOOL( EE_ACTIONS::placeSymbolAnchor ) );
|
||||||
|
|
||||||
RegisterUIUpdateHandler( ID_LIBEDIT_IMPORT_BODY_BUTT, ENABLE( isEditableCond ) );
|
|
||||||
RegisterUIUpdateHandler( ID_LIBEDIT_EXPORT_BODY_BUTT, ENABLE( haveSymbolCond ) );
|
|
||||||
|
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
#undef ENABLE
|
#undef ENABLE
|
||||||
#undef EDIT_TOOL
|
#undef EDIT_TOOL
|
||||||
|
@ -783,22 +776,6 @@ SYMBOL_LIBRARY_MANAGER& SYMBOL_EDIT_FRAME::GetLibManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::OnImportBody( wxCommandEvent& aEvent )
|
|
||||||
{
|
|
||||||
m_toolManager->DeactivateTool();
|
|
||||||
LoadOneSymbol();
|
|
||||||
m_drawToolBar->ToggleTool( ID_LIBEDIT_IMPORT_BODY_BUTT, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::OnExportBody( wxCommandEvent& aEvent )
|
|
||||||
{
|
|
||||||
m_toolManager->DeactivateTool();
|
|
||||||
SaveOneSymbol();
|
|
||||||
m_drawToolBar->ToggleTool( ID_LIBEDIT_EXPORT_BODY_BUTT, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::OnModify()
|
void SYMBOL_EDIT_FRAME::OnModify()
|
||||||
{
|
{
|
||||||
GetScreen()->SetModify();
|
GetScreen()->SetModify();
|
||||||
|
|
|
@ -116,9 +116,6 @@ public:
|
||||||
// See comments for m_SyncPinEdit.
|
// See comments for m_SyncPinEdit.
|
||||||
bool SynchronizePins();
|
bool SynchronizePins();
|
||||||
|
|
||||||
void OnImportBody( wxCommandEvent& aEvent );
|
|
||||||
void OnExportBody( wxCommandEvent& aEvent );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create or add an existing library to the symbol library table.
|
* Create or add an existing library to the symbol library table.
|
||||||
*/
|
*/
|
||||||
|
@ -422,21 +419,6 @@ private:
|
||||||
bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
|
bool LoadOneLibraryPartAux( LIB_PART* aLibEntry, const wxString& aLibrary, int aUnit,
|
||||||
int aConvert );
|
int aConvert );
|
||||||
|
|
||||||
/**
|
|
||||||
* Read a symbol file (*.sym ) and add graphic items to the current symbol.
|
|
||||||
*
|
|
||||||
* A symbol file *.sym has the same format as a library, and contains only one symbol.
|
|
||||||
*/
|
|
||||||
void LoadOneSymbol();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the current symbol to a symbol file.
|
|
||||||
*
|
|
||||||
* The symbol file format is similar to the standard symbol library file format, but
|
|
||||||
* there is only one symbol. Invisible pins are not saved.
|
|
||||||
*/
|
|
||||||
void SaveOneSymbol();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a dialog asking the user to select a symbol library table.
|
* Display a dialog asking the user to select a symbol library table.
|
||||||
*
|
*
|
||||||
|
|
|
@ -357,167 +357,6 @@ bool SYMBOL_EDIT_FRAME::LoadOneLibraryPartAux( LIB_PART* aEntry, const wxString&
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::LoadOneSymbol()
|
|
||||||
{
|
|
||||||
EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
|
|
||||||
|
|
||||||
// Exit if no library entry is selected or a command is in progress.
|
|
||||||
if( !m_my_part || !EE_CONDITIONS::Idle( selTool->GetSelection() ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
PROJECT& prj = Prj();
|
|
||||||
SEARCH_STACK* search = prj.SchSearchS();
|
|
||||||
|
|
||||||
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
|
|
||||||
|
|
||||||
if( !default_path )
|
|
||||||
default_path = search->LastVisitedPath();
|
|
||||||
|
|
||||||
wxFileDialog dlg( this, _( "Import Symbol" ), default_path,
|
|
||||||
wxEmptyString, SchematicSymbolFileWildcard(),
|
|
||||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxString filename = dlg.GetPath();
|
|
||||||
|
|
||||||
prj.SetRString( PROJECT::SCH_LIB_PATH, filename );
|
|
||||||
|
|
||||||
wxArrayString symbols;
|
|
||||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
||||||
|
|
||||||
wxString msg;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pi->EnumerateSymbolLib( symbols, filename );
|
|
||||||
}
|
|
||||||
catch( const IO_ERROR& ioe )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "Cannot import symbol library \"%s\"." ), filename );
|
|
||||||
DisplayErrorMessage( this, msg, ioe.What() );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( symbols.empty() )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "Symbol library file \"%s\" is empty." ), filename );
|
|
||||||
DisplayError( this, msg );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( symbols.GetCount() > 1 )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "More than one symbol found in symbol file \"%s\"." ), filename );
|
|
||||||
wxMessageBox( msg, _( "Warning" ), wxOK | wxICON_EXCLAMATION, this );
|
|
||||||
}
|
|
||||||
|
|
||||||
LIB_PART* alias = nullptr;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
alias = pi->LoadSymbol( filename, symbols[0] );
|
|
||||||
}
|
|
||||||
catch( const IO_ERROR& )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxCHECK_RET( alias, "Invalid symbol." );
|
|
||||||
|
|
||||||
SaveCopyInUndoList( m_my_part );
|
|
||||||
|
|
||||||
LIB_PART* first = alias;
|
|
||||||
LIB_ITEMS_CONTAINER& drawList = first->GetDrawItems();
|
|
||||||
|
|
||||||
for( LIB_ITEM& item : drawList )
|
|
||||||
{
|
|
||||||
if( item.Type() == LIB_FIELD_T )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( item.GetUnit() )
|
|
||||||
item.SetUnit( m_unit );
|
|
||||||
|
|
||||||
if( item.GetConvert() )
|
|
||||||
item.SetConvert( m_convert );
|
|
||||||
|
|
||||||
item.SetFlags( IS_NEW | SELECTED );
|
|
||||||
|
|
||||||
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
|
|
||||||
|
|
||||||
newItem->SetParent( m_my_part );
|
|
||||||
m_my_part->AddDrawItem( newItem );
|
|
||||||
item.ClearSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_my_part->RemoveDuplicateDrawItems();
|
|
||||||
|
|
||||||
OnModify();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::SaveOneSymbol()
|
|
||||||
{
|
|
||||||
wxCHECK( m_my_part, /* void */ );
|
|
||||||
|
|
||||||
// Export the current part as a symbol (.sym file)
|
|
||||||
// this is the current part without its aliases and doc file
|
|
||||||
// because a .sym file is used to import graphics in a part being edited
|
|
||||||
if( m_my_part->GetDrawItems().empty() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxString msg;
|
|
||||||
PROJECT& prj = Prj();
|
|
||||||
SEARCH_STACK* search = prj.SchSearchS();
|
|
||||||
|
|
||||||
wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH );
|
|
||||||
|
|
||||||
if( !default_path )
|
|
||||||
default_path = search->LastVisitedPath();
|
|
||||||
|
|
||||||
wxFileDialog dlg( this, _( "Export Symbol" ), default_path,
|
|
||||||
m_my_part->GetName() + "." + SchematicSymbolFileExtension,
|
|
||||||
SchematicSymbolFileWildcard(),
|
|
||||||
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
||||||
|
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxFileName fn = dlg.GetPath();
|
|
||||||
|
|
||||||
/* The GTK file chooser doesn't return the file extension added to
|
|
||||||
* file name so add it here. */
|
|
||||||
if( fn.GetExt().IsEmpty() )
|
|
||||||
fn.SetExt( SchematicSymbolFileExtension );
|
|
||||||
|
|
||||||
prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() );
|
|
||||||
|
|
||||||
if( fn.FileExists() && !wxRemoveFile( fn.GetFullPath() ) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
SetStatusText( wxString::Format( _( "Saving symbol in \"%s\"" ), fn.GetPath() ) );
|
|
||||||
|
|
||||||
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_LEGACY ) );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
PROPERTIES nodoc_props; // Doc file is useless for a .sym file
|
|
||||||
nodoc_props[ SCH_LEGACY_PLUGIN::PropNoDocFile ] = "";
|
|
||||||
plugin->CreateSymbolLib( fn.GetFullPath(), &nodoc_props );
|
|
||||||
|
|
||||||
// The part gets flattened by the LIB_PART copy constructor.
|
|
||||||
LIB_PART* saved_part = new LIB_PART( *m_my_part );
|
|
||||||
plugin->SaveSymbol( fn.GetFullPath(), saved_part, &nodoc_props );
|
|
||||||
}
|
|
||||||
catch( const IO_ERROR& ioe )
|
|
||||||
{
|
|
||||||
msg.Printf( _( "An error occurred saving symbol file \"%s\"" ), fn.GetFullPath() );
|
|
||||||
DisplayErrorMessage( this, msg, ioe.What() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SYMBOL_EDIT_FRAME::SaveAll()
|
void SYMBOL_EDIT_FRAME::SaveAll()
|
||||||
{
|
{
|
||||||
saveAllLibraries( false );
|
saveAllLibraries( false );
|
||||||
|
@ -1346,5 +1185,3 @@ void SYMBOL_EDIT_FRAME::DisplaySymbolDatasheet()
|
||||||
AppendMsgPanel( _( "Keywords" ), m_my_part->GetKeyWords() );
|
AppendMsgPanel( _( "Keywords" ), m_my_part->GetKeyWords() );
|
||||||
AppendMsgPanel( _( "Datasheet" ), m_my_part->GetDatasheetField().GetText() );
|
AppendMsgPanel( _( "Datasheet" ), m_my_part->GetDatasheetField().GetText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -65,15 +65,6 @@ void SYMBOL_EDIT_FRAME::ReCreateVToolbar()
|
||||||
m_drawToolBar->Add( EE_ACTIONS::drawSymbolArc, ACTION_TOOLBAR::TOGGLE );
|
m_drawToolBar->Add( EE_ACTIONS::drawSymbolArc, ACTION_TOOLBAR::TOGGLE );
|
||||||
m_drawToolBar->Add( EE_ACTIONS::drawSymbolLines, ACTION_TOOLBAR::TOGGLE );
|
m_drawToolBar->Add( EE_ACTIONS::drawSymbolLines, ACTION_TOOLBAR::TOGGLE );
|
||||||
m_drawToolBar->Add( EE_ACTIONS::placeSymbolAnchor, ACTION_TOOLBAR::TOGGLE );
|
m_drawToolBar->Add( EE_ACTIONS::placeSymbolAnchor, ACTION_TOOLBAR::TOGGLE );
|
||||||
|
|
||||||
m_drawToolBar->AddTool( ID_LIBEDIT_IMPORT_BODY_BUTT, wxEmptyString,
|
|
||||||
KiScaledBitmap( import_xpm, this ),
|
|
||||||
_( "Import existing drawings" ), wxITEM_CHECK );
|
|
||||||
|
|
||||||
m_drawToolBar->AddTool( ID_LIBEDIT_EXPORT_BODY_BUTT, wxEmptyString,
|
|
||||||
KiScaledBitmap( export_xpm, this ),
|
|
||||||
_( "Export current drawing" ), wxITEM_CHECK );
|
|
||||||
|
|
||||||
m_drawToolBar->Add( ACTIONS::deleteTool, ACTION_TOOLBAR::TOGGLE );
|
m_drawToolBar->Add( ACTIONS::deleteTool, ACTION_TOOLBAR::TOGGLE );
|
||||||
|
|
||||||
m_drawToolBar->Realize();
|
m_drawToolBar->Realize();
|
||||||
|
|
Loading…
Reference in New Issue