void LIB_EDIT_FRAME::emptyScreen() { SetCurLib( wxEmptyString ); SetCurPart( nullptr ); SetScreen( m_dummyScreen ); m_dummyScreen->ClearUndoRedoList(); m_toolManager->RunAction( "common.Control.zoomFitScreen", true ); Refresh(); }
void LIB_EDIT_FRAME::RestoreComponent() { if( m_tempCopyComponent ) { // transfer ownership to CurPart SetCurPart( m_tempCopyComponent ); m_tempCopyComponent = NULL; } }
bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, PART_LIB* aLibrary ) { wxString msg, rootName; if( !aEntry || !aLibrary ) return false; if( aEntry->GetName().IsEmpty() ) { wxLogWarning( "Entry in library <%s> has empty name field.", GetChars( aLibrary->GetName() ) ); return false; } wxString cmpName = m_aliasName = aEntry->GetName(); LIB_PART* lib_part = aEntry->GetPart(); wxASSERT( lib_part ); wxLogDebug( "\"<%s>\" is alias of \"<%s>\"", GetChars( cmpName ), GetChars( lib_part->GetName() ) ); LIB_PART* part = new LIB_PART( *lib_part ); // clone it and own it. SetCurPart( part ); m_aliasName = aEntry->GetName(); m_unit = 1; m_convert = 1; m_showDeMorgan = false; if( part->HasConversion() ) m_showDeMorgan = true; GetScreen()->ClrModify(); DisplayLibInfos(); UpdateAliasSelectList(); UpdatePartSelectList(); // Display the document information based on the entry selected just in // case the entry is an alias. DisplayCmpDoc(); return true; }
bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& aLibrary, int aUnit, int aConvert ) { wxString msg, rootName; if( !aEntry || aLibrary.empty() ) return false; if( aEntry->GetName().IsEmpty() ) { wxLogWarning( "Symbol in library \"%s\" has empty name field.", aLibrary ); return false; } LIB_PART* lib_part = m_libMgr->GetBufferedPart( aEntry->GetName(), aLibrary ); wxASSERT( lib_part ); m_unit = aUnit > 0 ? aUnit : 1; m_convert = aConvert > 0 ? aConvert : 1; // The buffered screen for the part SCH_SCREEN* part_screen = m_libMgr->GetScreen( lib_part->GetName(), aLibrary ); const SCH_SCREEN* curr_screen = GetScreen(); // Before we set the frame screen, transfer any settings from the current // screen that we want to keep to the incoming (buffered) part's screen // which could be out of date relative to the current screen. if( curr_screen ) synchronizeLibEditScreenSettings( *curr_screen, *part_screen ); SetScreen( part_screen ); SetCurPart( new LIB_PART( *lib_part ) ); SetCurLib( aLibrary ); Zoom_Automatique( false ); updateTitle(); UpdatePartSelectList(); // Display the document information based on the entry selected just in // case the entry is an alias. DisplayCmpDoc(); Refresh(); return true; }
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(); }
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(); }