bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, int aUnit, int aConvert ) { LIB_ALIAS* alias = nullptr; try { alias = Prj().SchSymbolLibTable()->LoadSymbol( GetCurLib(), aAliasName ); } catch( const IO_ERROR& ioe ) { wxString msg; msg.Printf( _( "Error occurred loading symbol \"%s\" from library \"%s\"." ), aAliasName, GetCurLib() ); DisplayErrorMessage( this, msg, ioe.What() ); return false; } if( !alias || !LoadOneLibraryPartAux( alias, GetCurLib(), aUnit, aConvert ) ) return false; // Enable synchronized pin edit mode for symbols with interchangeable units m_syncPinEdit = !GetCurPart()->UnitsLocked(); GetScreen()->ClearUndoRedoList(); Zoom_Automatique( false ); SetShowDeMorgan( GetCurPart()->HasConversion() ); if( aUnit > 0 ) UpdatePartSelectList(); return true; }
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::InstallFieldsEditorDialog( wxCommandEvent& event ) { if( m_component == NULL ) return; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB dlg( this, m_component ); int abort = dlg.ShowQuasiModal(); if( abort ) return; UpdateAliasSelectList(); UpdatePartSelectList(); DisplayLibInfos(); Refresh(); }
void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event ) { if( GetScreen()->GetUndoCommandCount() <= 0 ) return; PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); LIB_PART* part = GetCurPart(); ITEM_PICKER wrapper( part, UR_LIBEDIT ); lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToRedoList( lastcmd ); lastcmd = GetScreen()->PopCommandFromUndoList(); wrapper = lastcmd->PopItem(); part = (LIB_PART* ) wrapper.GetItem(); // Do not delete the previous part by calling SetCurPart( part ), // which calls delete <previous part>. // <previous part> is now put in redo list and is owned by this list. // Just set the current part to the part which come from the undo list m_my_part = part; if( !part ) return; if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) ) m_aliasName = part->GetName(); m_drawItem = NULL; UpdateAliasSelectList(); UpdatePartSelectList(); SetShowDeMorgan( part->HasConversion() ); DisplayLibInfos(); DisplayCmpDoc(); OnModify(); m_canvas->Refresh(); }
void LIB_EDIT_FRAME::InstallFieldsEditorDialog( wxCommandEvent& event ) { if( !GetCurPart() ) return; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB dlg( this, GetCurPart() ); // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal // frame. Therefore this dialog as a modal frame parent, MUST be run under // quasimodal mode for the quasimodal frame support to work. So don't use // the QUASIMODAL macros here. if( dlg.ShowQuasiModal() != wxID_OK ) return; UpdateAliasSelectList(); UpdatePartSelectList(); DisplayLibInfos(); Refresh(); }
void LIB_EDIT_FRAME::OnEditComponentProperties( wxCommandEvent& event ) { bool partLocked = GetCurPart()->UnitsLocked(); DIALOG_EDIT_COMPONENT_IN_LIBRARY dlg( this ); if( dlg.ShowModal() == wxID_CANCEL ) return; if( partLocked != GetCurPart()->UnitsLocked() ) { // m_editPinsPerPartOrConvert is set to the better value, if m_UnitSelectionLocked // has changed m_editPinsPerPartOrConvert = GetCurPart()->UnitsLocked() ? true : false; } UpdateAliasSelectList(); UpdatePartSelectList(); DisplayLibInfos(); DisplayCmpDoc(); OnModify(); m_canvas->Refresh(); }
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(); }
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; }
LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, LIB_EDIT_FRAME_NAME ) { m_showAxis = true; // true to draw axis SetShowDeMorgan( false ); m_drawSpecificConvert = true; m_drawSpecificUnit = false; m_hotkeysDescrList = g_Libedit_Hokeys_Descr; m_editPinsPerPartOrConvert = false; m_repeatPinStep = DEFAULT_REPEAT_OFFSET_PIN; m_my_part = NULL; m_tempCopyComponent = NULL; // Delayed initialization if( m_textSize == -1 ) m_textSize = GetDefaultTextSize(); // Initialize grid id to the default value 50 mils: m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; wxIcon icon; icon.CopyFromBitmap( KiBitmap( libedit_icon_xpm ) ); SetIcon( icon ); LoadSettings( config() ); SetScreen( new SCH_SCREEN( aKiway ) ); GetScreen()->m_Center = true; GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax ); SetCrossHairPosition( wxPoint( 0, 0 ) ); // Ensure m_LastGridSizeId is an offset inside the allowed schematic range if( m_LastGridSizeId < ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000 ) m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000 ) m_LastGridSizeId = ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000; SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); if( m_canvas ) m_canvas->SetEnableBlockCommands( true ); ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); // Ensure the current alias name is valid if a part is loaded // Sometimes it is not valid. This is the case // when a part value (the part lib name), or the alias list was modified // during a previous session and the modifications not saved in lib. // Reopen libedit in a new session gives a non valid m_aliasName // because the curr part is reloaded from the library (and this is the unmodified part) // and the old alias name (from the previous edition) can be invalid LIB_PART* part = GetCurPart(); if( part == NULL ) m_aliasName.Empty(); else if( m_aliasName != part->GetName() ) { LIB_ALIAS* alias = part->GetAlias( m_aliasName ); if( !alias ) m_aliasName = part->GetName(); } CreateOptionToolbar(); DisplayLibInfos(); DisplayCmpDoc(); UpdateAliasSelectList(); UpdatePartSelectList(); m_auimgr.SetManagedWindow( this ); EDA_PANEINFO horiz; horiz.HorizontalToolbarPane(); EDA_PANEINFO vert; vert.VerticalToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) ); m_auimgr.AddPane( m_drawToolBar, wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right() ); m_auimgr.AddPane( m_optionsToolBar, wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left() ); m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); m_auimgr.Update(); Raise(); Show( true ); wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE ); wxPostEvent( this, evt ); }
LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : SCH_BASE_FRAME( aKiway, aParent, FRAME_SCH_LIB_EDITOR, _( "Library Editor" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GetLibEditFrameName() ) { wxASSERT( aParent ); m_FrameName = GetLibEditFrameName(); m_showAxis = true; // true to draw axis m_configPath = wxT( "LibraryEditor" ); SetShowDeMorgan( false ); m_drawSpecificConvert = true; m_drawSpecificUnit = false; m_tempCopyComponent = NULL; m_HotkeysZoomAndGridList = s_Libedit_Hokeys_Descr; m_editPinsPerPartOrConvert = false; // Delayed initialization if( m_textSize == -1 ) m_textSize = GetDefaultTextSize(); // Initialize grid id to the default value 50 mils: m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; wxIcon icon; icon.CopyFromBitmap( KiBitmap( libedit_icon_xpm ) ); SetIcon( icon ); SetScreen( new SCH_SCREEN() ); GetScreen()->m_Center = true; SetCrossHairPosition( wxPoint( 0, 0 ) ); LoadSettings( config() ); // Ensure m_LastGridSizeId is an offset inside the allowed schematic range if( m_LastGridSizeId < ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000 ) m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000 ) m_LastGridSizeId = ID_POPUP_GRID_LEVEL_1 - ID_POPUP_GRID_LEVEL_1000; SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); if( m_canvas ) m_canvas->SetEnableBlockCommands( true ); EnsureActiveLibExists(); ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); CreateOptionToolbar(); DisplayLibInfos(); DisplayCmpDoc(); UpdateAliasSelectList(); UpdatePartSelectList(); m_auimgr.SetManagedWindow( this ); EDA_PANEINFO horiz; horiz.HorizontalToolbarPane(); EDA_PANEINFO vert; vert.VerticalToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiz ).Name( wxT( "m_mainToolBar" ) ).Top().Row( 0 ) ); m_auimgr.AddPane( m_drawToolBar, wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right() ); m_auimgr.AddPane( m_optionsToolBar, wxAuiPaneInfo( vert ).Name( wxT( "m_optionsToolBar" ) ).Left() ); m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); m_auimgr.Update(); Show( true ); wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED, ID_ZOOM_PAGE ); wxPostEvent( this, evt ); }