void LIB_EDIT_FRAME::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event ) { PART_LIB* lib = GetCurLib(); event.Enable( lib && !lib->IsReadOnly() && ( lib->IsModified() || GetScreen()->IsModify() ) ); }
void LIB_VIEW_FRAME::ReCreateListLib() { if( !m_libList ) return; m_libList->Clear(); wxArrayString libs = Prj().SchLibs()->GetLibraryNames(); // Remove not allowed libs from main list, if the allowed lib list is not empty if( m_allowedLibs.GetCount() ) { for( unsigned ii = 0; ii < libs.GetCount(); ) { if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND ) libs.RemoveAt( ii ); else ii++; } } // Remove libs which have no power components, if this filter is activated if( m_listPowerCmpOnly ) { for( unsigned ii = 0; ii < libs.GetCount(); ) { PART_LIB* lib = Prj().SchLibs()->FindLibrary( libs[ii] ); if( lib && !lib->HasPowerParts() ) libs.RemoveAt( ii ); else ii++; } } m_libList->Append( libs ); // Search for a previous selection: int index = m_libList->FindString( m_libraryName ); if( index != wxNOT_FOUND ) { m_libList->SetSelection( index, true ); } else { // If not found, clear current library selection because it can be // deleted after a config change. m_libraryName = wxEmptyString; m_entryName = wxEmptyString; m_unit = 1; m_convert = 1; } ReCreateListCmp(); ReCreateHToolbar(); DisplayLibInfos(); m_canvas->Refresh(); }
void LIB_EDIT_FRAME::DisplayLibInfos() { PART_LIB* lib = GetCurLib(); wxString title = wxString::Format( L"Part Library Editor \u2014 %s%s", lib ? lib->GetFullFileName() : _( "no library selected" ), lib && lib->IsReadOnly() ? _( " [Read Only] ") : wxString( wxEmptyString ) ); SetTitle( title ); }
void COMPONENT_TREE_SEARCH_CONTAINER::AddLibrary( PART_LIB& aLib ) { wxArrayString all_aliases; if( m_filter == CMP_FILTER_POWER ) aLib.GetEntryTypePowerNames( all_aliases ); else aLib.GetAliasNames( all_aliases ); AddAliasList( aLib.GetName(), all_aliases, &aLib ); ++m_libraries_added; }
void LIB_VIEW_FRAME::DisplayLibInfos() { PART_LIBS* libs = Prj().SchLibs(); if( libs ) { PART_LIB* lib = libs->FindLibrary( m_libraryName ); wxString title = wxString::Format( "Library Browser \u2014 %s", lib ? lib->GetFullFileName() : "no library selected" ); SetTitle( title ); } }
/* Add a new name to the alias list box * New name cannot be the root name, and must not exists */ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& event ) { wxString aliasname; LIB_PART* component = m_Parent->GetCurPart(); PART_LIB* library = m_Parent->GetCurLib(); if( component == NULL ) return; wxTextEntryDialog dlg( this, _( "New alias:" ), _( "Component Alias" ), aliasname ); if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user aliasname = dlg.GetValue( ); aliasname.Replace( wxT( " " ), wxT( "_" ) ); if( aliasname.IsEmpty() ) return; if( m_PartAliasListCtrl->FindString( aliasname ) != wxNOT_FOUND ) { wxString msg; msg.Printf( _( "Alias or component name <%s> already in use." ), GetChars( aliasname ) ); DisplayError( this, msg ); return; } if( library && library->FindEntry( aliasname ) != NULL ) { wxString msg; msg.Printf( _( "Alias or component name <%s> already exists in library <%s>." ), GetChars( aliasname ), GetChars( library->GetName() ) ); DisplayError( this, msg ); return; } m_PartAliasListCtrl->Append( aliasname ); if( m_Parent->GetAliasName().CmpNoCase( component->GetName() ) == 0 ) m_ButtonDeleteAllAlias->Enable( true ); m_ButtonDeleteOneAlias->Enable( true ); }
double LIB_VIEW_FRAME::BestZoom() { /* Please, note: wxMSW before version 2.9 seems have * problems with zoom values < 1 ( i.e. userscale > 1) and needs to be patched: * edit file <wxWidgets>/src/msw/dc.cpp * search for line static const int VIEWPORT_EXTENT = 1000; * and replace by static const int VIEWPORT_EXTENT = 10000; */ LIB_PART* part = NULL; double bestzoom = 16.0; // default value for bestzoom PART_LIB* lib = Prj().SchLibs()->FindLibrary( m_libraryName ); if( lib ) part = lib->FindPart( m_entryName ); if( !part ) { SetScrollCenterPosition( wxPoint( 0, 0 ) ); return bestzoom; } wxSize size = m_canvas->GetClientSize(); EDA_RECT boundingBox = part->GetBoundingBox( m_unit, m_convert ); // Reserve a 10% margin around component bounding box. double margin_scale_factor = 0.8; double zx =(double) boundingBox.GetWidth() / ( margin_scale_factor * (double)size.x ); double zy = (double) boundingBox.GetHeight() / ( margin_scale_factor * (double)size.y); // Calculates the best zoom bestzoom = std::max( zx, zy ); // keep it >= minimal existing zoom (can happen for very small components // like small power symbols if( bestzoom < GetScreen()->m_ZoomList[0] ) bestzoom = GetScreen()->m_ZoomList[0]; SetScrollCenterPosition( boundingBox.Centre() ); return bestzoom; }
XNODE* NETLIST_EXPORTER_GENERIC::makeLibraries() { XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr for( std::set<void*>::iterator it = m_Libraries.begin(); it!=m_Libraries.end(); ++it ) { PART_LIB* lib = (PART_LIB*) *it; XNODE* xlibrary; xlibs->AddChild( xlibrary = node( wxT( "library" ) ) ); xlibrary->AddAttribute( wxT( "logical" ), lib->GetLogicalName() ); xlibrary->AddChild( node( wxT( "uri" ), lib->GetFullFileName() ) ); // @todo: add more fun stuff here } return xlibs; }
void LIB_VIEW_FRAME::ReCreateListCmp() { if( m_cmpList == NULL ) return; m_cmpList->Clear(); PART_LIB* lib = Prj().SchLibs()->FindLibrary( m_libraryName ); if( !lib ) { m_libraryName = wxEmptyString; m_entryName = wxEmptyString; m_convert = 1; m_unit = 1; return; } wxArrayString nameList; if( m_listPowerCmpOnly ) lib->GetEntryTypePowerNames( nameList ); else lib->GetEntryNames( nameList ); m_cmpList->Append( nameList ); int index = m_cmpList->FindString( m_entryName ); if( index == wxNOT_FOUND ) { m_entryName = wxEmptyString; m_convert = 1; m_unit = 1; } else { m_cmpList->SetSelection( index, true ); } }
void LIB_EDIT_FRAME::EditField( LIB_FIELD* aField ) { wxString newFieldValue; wxString title; wxString caption; wxString oldName; if( aField == NULL ) return; LIB_PART* parent = aField->GetParent(); wxASSERT( parent ); // Editing the component value field is equivalent to creating a new component based // on the current component. Set the dialog message to inform the user. if( aField->GetId() == VALUE ) { caption = _( "Component Name" ); title = _( "Enter a name to create a new component based on this one." ); } else { caption.Printf( _( "Edit Field %s" ), GetChars( aField->GetName() ) ); title.Printf( _( "Enter a new value for the %s field." ), GetChars( aField->GetName().Lower() ) ); } DIALOG_LIB_EDIT_ONE_FIELD dlg( this, caption, aField ); // The dialog may invoke a kiway player for footprint fields // so we must use a quasimodal dialog. if( dlg.ShowQuasiModal() != wxID_OK ) return; newFieldValue = dlg.GetText(); wxString fieldText = aField->GetFullText( m_unit ); /* If the value field is changed, this is equivalent to creating a new component from * the old one. Rename the component and remove any conflicting aliases to prevent name * errors when updating the library. */ if( aField->GetId() == VALUE && newFieldValue != aField->GetText() ) { wxString msg; PART_LIB* lib = GetCurLib(); // Test the current library for name conflicts. if( lib && lib->FindAlias( newFieldValue ) ) { msg.Printf( _( "The name '%s' conflicts with an existing entry in the component library '%s'.\n\n" "Do you wish to replace the current component in the library with this one?" ), GetChars( newFieldValue ), GetChars( lib->GetName() ) ); int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT, this ); if( rsp == wxNO ) return; } // Test the current component for name conflicts. if( parent->HasAlias( newFieldValue ) ) { msg.Printf( _( "The current component already has an alias named '%s'.\n\n" "Do you wish to remove this alias from the component?" ), GetChars( newFieldValue ) ); int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); if( rsp == wxNO ) return; parent->RemoveAlias( newFieldValue ); } parent->SetName( newFieldValue ); // Test the library for any conflicts with the any aliases in the current component. if( parent->GetAliasCount() > 1 && lib && lib->Conflicts( parent ) ) { msg.Printf( _( "The new component contains alias names that conflict with entries in the " "component library '%s'.\n\n" "Do you wish to remove all of the conflicting aliases from this component?" ), GetChars( lib->GetName() ) ); int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); if( rsp == wxNO ) { parent->SetName( fieldText ); return; } wxArrayString aliases = parent->GetAliasNames( false ); for( size_t i = 0; i < aliases.GetCount(); i++ ) { if( lib->FindAlias( aliases[ i ] ) != NULL ) parent->RemoveAlias( aliases[ i ] ); } } if( !parent->HasAlias( m_aliasName ) ) m_aliasName = newFieldValue; } dlg.UpdateField( aField ); if( !aField->InEditMode() ) SaveCopyInUndoList( parent ); m_canvas->Refresh(); OnModify(); UpdateAliasSelectList(); }
XNODE* NETLIST_EXPORTER_GENERIC::makeLibParts() { XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr wxString sLibpart = wxT( "libpart" ); wxString sLib = wxT( "lib" ); wxString sPart = wxT( "part" ); wxString sAliases = wxT( "aliases" ); wxString sAlias = wxT( "alias" ); wxString sPins = wxT( "pins" ); // key for library component pins list wxString sPin = wxT( "pin" ); // key for one library component pin descr wxString sPinNum = wxT( "num" ); // key for one library component pin num wxString sPinName = wxT( "name" ); // key for one library component pin name wxString sPinType = wxT( "type" ); // key for one library component pin electrical type wxString sName = wxT( "name" ); wxString sField = wxT( "field" ); wxString sFields = wxT( "fields" ); wxString sDescr = wxT( "description" ); wxString sDocs = wxT( "docs" ); wxString sFprints = wxT( "footprints" ); wxString sFp = wxT( "fp" ); LIB_PINS pinList; LIB_FIELDS fieldList; m_Libraries.clear(); for( std::set<LIB_PART*>::iterator it = m_LibParts.begin(); it!=m_LibParts.end(); ++it ) { LIB_PART* lcomp = *it; PART_LIB* library = lcomp->GetLib(); m_Libraries.insert( library ); // inserts component's library if unique XNODE* xlibpart; xlibparts->AddChild( xlibpart = node( sLibpart ) ); xlibpart->AddAttribute( sLib, library->GetLogicalName() ); xlibpart->AddAttribute( sPart, lcomp->GetName() ); if( lcomp->GetAliasCount() ) { wxArrayString aliases = lcomp->GetAliasNames( false ); if( aliases.GetCount() ) { XNODE* xaliases = node( sAliases ); xlibpart->AddChild( xaliases ); for( unsigned i=0; i<aliases.GetCount(); ++i ) { xaliases->AddChild( node( sAlias, aliases[i] ) ); } } } //----- show the important properties ------------------------- if( !lcomp->GetAlias( 0 )->GetDescription().IsEmpty() ) xlibpart->AddChild( node( sDescr, lcomp->GetAlias( 0 )->GetDescription() ) ); if( !lcomp->GetAlias( 0 )->GetDocFileName().IsEmpty() ) xlibpart->AddChild( node( sDocs, lcomp->GetAlias( 0 )->GetDocFileName() ) ); // Write the footprint list if( lcomp->GetFootPrints().GetCount() ) { XNODE* xfootprints; xlibpart->AddChild( xfootprints = node( sFprints ) ); for( unsigned i=0; i<lcomp->GetFootPrints().GetCount(); ++i ) { xfootprints->AddChild( node( sFp, lcomp->GetFootPrints()[i] ) ); } } //----- show the fields here ---------------------------------- fieldList.clear(); lcomp->GetFields( fieldList ); XNODE* xfields; xlibpart->AddChild( xfields = node( sFields ) ); for( unsigned i=0; i<fieldList.size(); ++i ) { if( !fieldList[i].GetText().IsEmpty() ) { XNODE* xfield; xfields->AddChild( xfield = node( sField, fieldList[i].GetText() ) ); xfield->AddAttribute( sName, fieldList[i].GetName(false) ); } } //----- show the pins here ------------------------------------ pinList.clear(); lcomp->GetPins( pinList, 0, 0 ); /* we must erase redundant Pins references in pinList * These redundant pins exist because some pins * are found more than one time when a component has * multiple parts per package or has 2 representations (DeMorgan conversion) * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes, * and therefore each pin appears 2 times in the list. * Common pins (VCC, GND) can also be found more than once. */ sort( pinList.begin(), pinList.end(), sortPinsByNumber ); for( int ii = 0; ii < (int)pinList.size()-1; ii++ ) { if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() ) { // 2 pins have the same number, remove the redundant pin at index i+1 pinList.erase(pinList.begin() + ii + 1); ii--; } } if( pinList.size() ) { XNODE* pins; xlibpart->AddChild( pins = node( sPins ) ); for( unsigned i=0; i<pinList.size(); ++i ) { XNODE* pin; pins->AddChild( pin = node( sPin ) ); pin->AddAttribute( sPinNum, pinList[i]->GetNumberString() ); pin->AddAttribute( sPinName, pinList[i]->GetName() ); pin->AddAttribute( sPinType, pinList[i]->GetCanonicalElectricalTypeName() ); // caution: construction work site here, drive slowly } } } return xlibparts; }
void LIB_EDIT_FRAME::CreateNewLibraryPart( wxCommandEvent& event ) { wxString name; if( GetCurPart() && GetScreen()->IsModify() && !IsOK( this, _( "All changes to the current component will be lost!\n\n" "Clear the current component from the screen?" ) ) ) { return; } m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_drawItem = NULL; DIALOG_LIB_NEW_COMPONENT dlg( this ); dlg.SetMinSize( dlg.GetSize() ); if( dlg.ShowModal() == wxID_CANCEL ) return; if( dlg.GetName().IsEmpty() ) { wxMessageBox( _( "This new component has no name and cannot be created. Aborted" ) ); return; } name = dlg.GetName(); name.Replace( " ", "_" ); PART_LIB* lib = GetCurLib(); // Test if there a component with this name already. if( lib && lib->FindAlias( name ) ) { wxString msg = wxString::Format( _( "Part '%s' already exists in library '%s'" ), GetChars( name ), GetChars( lib->GetName() ) ); DisplayError( this, msg ); return; } LIB_PART* new_part = new LIB_PART( name ); SetCurPart( new_part ); m_aliasName = new_part->GetName(); 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 new_part->SetConversion( dlg.GetAlternateBodyStyle() ); SetShowDeMorgan( dlg.GetAlternateBodyStyle() ); 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() ); if( dlg.GetUnitCount() < 2 ) new_part->LockUnits( false ); m_unit = 1; m_convert = 1; DisplayLibInfos(); DisplayCmpDoc(); UpdateAliasSelectList(); UpdatePartSelectList(); m_editPinsPerPartOrConvert = new_part->UnitsLocked() ? true : false; m_lastDrawItem = NULL; GetScreen()->ClearUndoRedoList(); OnModify(); m_canvas->Refresh(); m_mainToolBar->Refresh(); }
void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry; wxArrayString nameList; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_lastDrawItem = NULL; m_drawItem = NULL; LIB_PART *part = GetCurPart(); PART_LIB* lib = GetCurLib(); if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) { DisplayError( this, _( "Please select a component library." ) ); return; } } auto adapter( CMP_TREE_MODEL_ADAPTER::Create( Prj().SchLibs() ) ); wxString name = part ? part->GetName() : wxString( wxEmptyString ); adapter->SetPreselectNode( name, /* aUnit */ 0 ); adapter->ShowUnits( false ); adapter->AddLibrary( *lib ); wxString dialogTitle; dialogTitle.Printf( _( "Delete Component (%u items loaded)" ), adapter->GetComponentsCount() ); DIALOG_CHOOSE_COMPONENT dlg( this, dialogTitle, adapter, m_convert ); if( dlg.ShowModal() == wxID_CANCEL ) { return; } libEntry = dlg.GetSelectedAlias( NULL ); if( !libEntry ) { msg.Printf( _( "Entry '%s' not found in library '%s'." ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); DisplayError( this, msg ); return; } msg.Printf( _( "Delete component '%s' from library '%s' ?" ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); if( !IsOK( this, msg ) ) return; part = GetCurPart(); if( !part || !part->HasAlias( libEntry->GetName() ) ) { lib->RemoveAlias( libEntry ); m_canvas->Refresh(); return; } // If deleting the current entry or removing one of the aliases for // the current entry, sync the changes in the current entry as well. if( GetScreen()->IsModify() && !IsOK( this, _( "The component being deleted has been modified." " All changes will be lost. Discard changes?" ) ) ) { return; } LIB_ALIAS* nextEntry = lib->RemoveAlias( libEntry ); if( nextEntry != NULL ) { if( LoadOneLibraryPartAux( nextEntry, lib ) ) Zoom_Automatique( false ); } else { SetCurPart( NULL ); // delete CurPart m_aliasName.Empty(); } m_canvas->Refresh(); }
bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile ) { wxFileName fn; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); PART_LIB* lib = GetCurLib(); // Just in case the library hasn't been cached yet. lib->GetCount(); if( !lib ) { DisplayError( this, _( "No library specified." ) ); return false; } wxString oldFileName = lib->GetFullFileName(); if( GetScreen()->IsModify() ) { if( IsOK( this, _( "Include last component changes?" ) ) ) { lib->EnableBuffering(); try { SaveOnePart( lib, false ); } catch( ... ) { lib->EnableBuffering( false ); msg.Printf( _( "Unexpected error occured saving part to '%s' symbol library." ), lib->GetName() ); DisplayError( this, msg ); return false; } lib->EnableBuffering( false ); } } if( newFile ) { PROJECT& prj = Prj(); SEARCH_STACK* search = prj.SchSearchS(); // Get a new name for the library wxString default_path = prj.GetRString( PROJECT::SCH_LIB_PATH ); if( !default_path ) default_path = search->LastVisitedPath(); wxFileDialog dlg( this, _( "Part Library Name:" ), default_path, wxEmptyString, SchematicLibraryFileWildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if( dlg.ShowModal() == wxID_CANCEL ) return false; 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( SchematicLibraryFileExtension ); prj.SetRString( PROJECT::SCH_LIB_PATH, fn.GetPath() ); } else { fn = wxFileName( lib->GetFullFileName() ); msg.Printf( _( "Modify library file '%s' ?" ), GetChars( fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) return false; } // Verify the user has write privileges before attempting to save the library file. if( !IsWritable( fn ) ) return false; ClearMsgPanel(); wxFileName libFileName = fn; wxFileName backupFileName = fn; // Rename the old .lib file to .bak. if( libFileName.FileExists() ) { backupFileName.SetExt( "bak" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( libFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { libFileName.MakeAbsolute(); msg = _( "Failed to rename old component library file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } wxFileName docFileName = libFileName; docFileName.SetExt( DOC_EXT ); // Rename .doc file to .bck. if( docFileName.FileExists() ) { backupFileName.SetExt( "bck" ); if( backupFileName.FileExists() ) wxRemoveFile( backupFileName.GetFullPath() ); if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) ) { msg = _( "Failed to save old library document file " ) + backupFileName.GetFullPath(); DisplayError( this, msg ); } } try { lib->SetFileName( fn.GetFullPath() ); lib->Save(); } catch( ... /* IO_ERROR ioe */ ) { lib->SetFileName( oldFileName ); msg.Printf( _( "Failed to create symbol library file '%s'" ), GetChars( docFileName.GetFullPath() ) ); DisplayError( this, msg ); return false; } lib->SetFileName( oldFileName ); msg.Printf( _( "Library file '%s' saved" ), GetChars( fn.GetFullPath() ) ); fn.SetExt( DOC_EXT ); wxString msg1; msg1.Printf( _( "Documentation file '%s' saved" ), GetChars( fn.GetFullPath() ) ); AppendMsgPanel( msg, msg1, BLUE ); UpdateAliasSelectList(); UpdatePartSelectList(); refreshSchematic(); return true; }
void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry = NULL; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); if( GetScreen()->IsModify() && !IsOK( this, _( "The current component is not saved.\n\nDiscard current changes?" ) ) ) return; PART_LIB* lib = GetCurLib(); // No current lib, ask user for the library to use. if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) return; } // Get the name of the current part to preselect it LIB_PART* current_part = GetCurPart(); wxString part_name = current_part ? current_part->GetName() : wxString( wxEmptyString ); wxArrayString dummyHistoryList; int dummyLastUnit; SCHLIB_FILTER filter; filter.LoadFrom( lib->GetName() ); cmp_name = SelectComponentFromLibrary( &filter, dummyHistoryList, dummyLastUnit, true, NULL, NULL, part_name ); if( cmp_name.IsEmpty() ) return; GetScreen()->ClrModify(); m_lastDrawItem = m_drawItem = NULL; // Delete previous library component, if any SetCurPart( NULL ); m_aliasName.Empty(); // Load the new library component libEntry = lib->FindAlias( cmp_name ); PART_LIB* searchLib = lib; if( !libEntry ) { // Not found in the active library: search inside the full list // (can happen when using Viewlib to load a component) libEntry = Prj().SchLibs()->FindLibraryAlias( LIB_ID( wxEmptyString, cmp_name ) ); if( libEntry ) { searchLib = libEntry->GetLib(); // The entry to load is not in the active lib // Ask for a new active lib wxString msg = _( "The selected component is not in the active library." ); msg += "\n\n"; msg += _( "Do you want to change the active library?" ); if( IsOK( this, msg ) ) SelectActiveLibrary( searchLib ); } } if( !libEntry ) { wxString msg = wxString::Format( _( "Part name '%s' not found in library '%s'" ), GetChars( cmp_name ), GetChars( searchLib->GetName() ) ); DisplayError( this, msg ); return; } PART_LIB* old = SetCurLib( searchLib ); LoadComponentFromCurrentLib( libEntry ); SetCurLib( old ); DisplayLibInfos(); }
void LIB_EDIT_FRAME::DeleteOnePart( wxCommandEvent& event ) { wxString cmp_name; LIB_ALIAS* libEntry; wxArrayString nameList; wxString msg; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_lastDrawItem = NULL; m_drawItem = NULL; PART_LIB* lib = GetCurLib(); if( !lib ) { SelectActiveLibrary(); lib = GetCurLib(); if( !lib ) { DisplayError( this, _( "Please select a component library." ) ); return; } } lib->GetAliasNames( nameList ); if( nameList.IsEmpty() ) { msg.Printf( _( "Part library '%s' is empty." ), GetChars( lib->GetName() ) ); wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this ); return; } msg.Printf( _( "Select one of %d components to delete\nfrom library '%s'." ), int( nameList.GetCount() ), GetChars( lib->GetName() ) ); wxSingleChoiceDialog dlg( this, msg, _( "Delete Part" ), nameList ); if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() ) return; libEntry = lib->FindAlias( dlg.GetStringSelection() ); if( !libEntry ) { msg.Printf( _( "Entry '%s' not found in library '%s'." ), GetChars( dlg.GetStringSelection() ), GetChars( lib->GetName() ) ); DisplayError( this, msg ); return; } msg.Printf( _( "Delete component '%s' from library '%s' ?" ), GetChars( libEntry->GetName() ), GetChars( lib->GetName() ) ); if( !IsOK( this, msg ) ) return; LIB_PART* part = GetCurPart(); if( !part || !part->HasAlias( libEntry->GetName() ) ) { lib->RemoveAlias( libEntry ); return; } // If deleting the current entry or removing one of the aliases for // the current entry, sync the changes in the current entry as well. if( GetScreen()->IsModify() && !IsOK( this, _( "The component being deleted has been modified." " All changes will be lost. Discard changes?" ) ) ) { return; } LIB_ALIAS* nextEntry = lib->RemoveAlias( libEntry ); if( nextEntry != NULL ) { if( LoadOneLibraryPartAux( nextEntry, lib ) ) Zoom_Automatique( false ); } else { SetCurPart( NULL ); // delete CurPart m_aliasName.Empty(); } m_canvas->Refresh(); }