LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aLibraryName ) : SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_STYLE_MODAL : LIB_VIEW_STYLE, aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_NAME_MODAL : LIB_VIEW_NAME ), m_libList( nullptr ), m_cmpList( nullptr ), m_previewItem( nullptr ) { wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL ); if( aFrameType == FRAME_SCH_VIEWER_MODAL ) SetModal( true ); // Force the frame name used in config. the lib viewer frame has a name // depending on aFrameType (needed to identify the frame by wxWidgets), // but only one configuration is preferable. m_configFrameName = LIB_VIEW_NAME; // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) ); SetIcon( icon ); m_hotkeysDescrList = g_Viewlib_Hotkeys_Descr; m_libListWidth = 200; m_cmpListWidth = 300; m_listPowerCmpOnly = false; SetShowElectricalType( true ); // Initialize grid id to the default value (50 mils): m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; SetScreen( new SCH_SCREEN( aKiway ) ); GetScreen()->m_Center = true; // Axis origin centered on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); // Menu bar is not mandatory: uncomment/comment the next line // to add/remove the menubar ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL | wxNO_BORDER ); m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL | wxNO_BORDER ); if( aLibraryName.empty() ) { ReCreateListLib(); } else { m_libraryName = aLibraryName; m_entryName.Clear(); m_unit = 1; m_convert = 1; } m_selection_changed = false; DisplayLibInfos(); m_auimgr.SetManagedWindow( this ); m_auimgr.SetArtProvider( new EDA_DOCKART( this ) ); // Manage main toolbar m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(3) .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_libListWidth, -1 ) ); m_auimgr.AddPane( m_cmpList, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1) .CaptionVisible( false ).MinSize( 80, -1 ).BestSize( m_cmpListWidth, -1 ) ); m_auimgr.AddPane( m_canvas->GetWindow(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); m_auimgr.GetPane( m_libList ).Show( aLibraryName.empty() ); m_auimgr.Update(); setupTools(); GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); GetToolManager()->RunAction( "common.Control.zoomFitScreen", true ); if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame { Raise(); Show( true ); } SyncView(); GetGalCanvas()->GetViewControls()->SetSnapping( true ); GetGalCanvas()->GetGAL()->SetAxesEnabled( true ); GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); // Set the working/draw area size to display a symbol to a reasonable value: // A 450mm x 450mm with a origin at the area center looks like a large working area double max_size_x = Millimeter2iu( 450 ); double max_size_y = Millimeter2iu( 450 ); BOX2D bbox; bbox.SetOrigin( -max_size_x /2, -max_size_y/2 ); bbox.SetSize( max_size_x, max_size_y ); GetCanvas()->GetView()->SetBoundary( bbox ); }
void LIB_VIEW_FRAME::SelectCurrentLibrary() { CMP_LIBRARY* Lib; Lib = SelectLibraryFromList( this ); if( Lib ) { m_entryName.Empty(); m_libraryName = Lib->GetName(); DisplayLibInfos(); if( m_LibList ) { ReCreateListCmp(); m_canvas->Refresh(); DisplayLibInfos(); ReCreateHToolbar(); int id = m_LibList->FindString( m_libraryName.GetData() ); if( id >= 0 ) m_LibList->SetSelection( id ); } } }
/* Routine to view one selected library content. */ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) { if( m_libraryName.IsEmpty() ) return; int selection = m_FootprintList->FindString( m_footprintName ); if( aMode == NEXT_PART ) { if( selection != wxNOT_FOUND && selection < (int)m_FootprintList->GetCount()-1 ) selection++; } if( aMode == PREVIOUS_PART ) { if( selection != wxNOT_FOUND && selection > 0) selection--; } if( selection != wxNOT_FOUND ) { m_footprintName = m_FootprintList->GetString( selection ); SetCurItem( NULL ); // Delete the current footprint GetBoard()->m_Modules.DeleteAll(); GetModuleLibrary( m_libraryName + wxT(".") + LegacyFootprintLibPathExtension, m_footprintName, true ); Update3D_Frame(); } DisplayLibInfos(); Zoom_Automatique( false ); m_canvas->Refresh( ); }
void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event ) { wxString msg; if( g_LibraryNames.GetCount() == 0 ) return; EDA_LIST_DIALOG dlg( this, _( "Select Current Library:" ), g_LibraryNames, m_libraryName ); if( dlg.ShowModal() != wxID_OK ) return; if( m_libraryName == dlg.GetTextSelection() ) return; m_libraryName = dlg.GetTextSelection(); m_footprintName.Empty(); DisplayLibInfos(); ReCreateFootprintList(); int id = m_LibList->FindString( m_libraryName ); if( id >= 0 ) m_LibList->SetSelection( id ); }
void LIB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { if( GetScreen() == NULL ) return; m_canvas->DrawBackGround( DC ); RedrawComponent( DC, wxPoint( 0, 0 ) ); #ifdef USE_WX_OVERLAY if( IsShown() ) { m_overlay.Reset(); wxDCOverlay overlaydc( m_overlay, (wxWindowDC*)DC ); overlaydc.Clear(); } #endif if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); m_canvas->DrawCrossHair( DC ); DisplayLibInfos(); UpdateStatusBar(); }
void LIB_VIEW_FRAME::ReCreateListLib() { if( m_libList == NULL ) return; m_libList->Clear(); m_libList->Append( CMP_LIBRARY::GetLibraryNames() ); // 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_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_VIEW_FRAME::OnActivate( wxActivateEvent& event ) { EDA_DRAW_FRAME::OnActivate( event ); if( m_libList ) ReCreateListLib(); DisplayLibInfos(); }
void LIB_VIEW_FRAME::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag ) { int NumOfParts = 0; LIB_ALIAS* LibEntry; wxString CmpName; if( Lib ) NumOfParts = Lib->GetCount(); if( NumOfParts == 0 ) { DisplayError( this, wxT( "No library or library is empty!" ) ); return; } if( Lib == NULL ) return; if( Flag == NEW_PART ) { DisplayComponentsNamesInLib( this, Lib, CmpName, m_entryName ); } if( Flag == NEXT_PART ) { LibEntry = Lib->GetNextEntry( m_entryName ); if( LibEntry ) CmpName = LibEntry->GetName(); } if( Flag == PREVIOUS_PART ) { LibEntry = Lib->GetPreviousEntry( m_entryName ); if( LibEntry ) CmpName = LibEntry->GetName(); } m_unit = 1; m_convert = 1; LibEntry = Lib->FindEntry( CmpName ); m_entryName = CmpName; DisplayLibInfos(); Zoom_Automatique( false ); m_canvas->Refresh( ); if( m_CmpList ) { int id = m_CmpList->FindString( m_entryName.GetData() ); if( id >= 0 ) m_CmpList->SetSelection( id ); } ReCreateHToolbar(); }
void LIB_EDIT_FRAME::OnImportPart( wxCommandEvent& event ) { m_lastDrawItem = NULL; wxFileDialog dlg( this, _( "Import Component" ), m_lastLibImportPath, m_mruPath, SchematicLibraryFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST ); if( dlg.ShowModal() == wxID_CANCEL ) return; wxFileName fn = dlg.GetPath(); m_mruPath = fn.GetPath(); std::auto_ptr<PART_LIB> lib; try { std::auto_ptr<PART_LIB> new_lib( PART_LIB::LoadLibrary( fn.GetFullPath() ) ); lib = new_lib; } catch( const IO_ERROR& ioe ) { wxString msg = wxString::Format( _( "Unable to import library '%s'. Error:\n" "%s" ), GetChars( fn.GetFullPath() ) ); DisplayError( this, msg ); return; } LIB_ALIAS* entry = lib->GetFirstEntry(); if( !entry ) { wxString msg = wxString::Format( _( "Part library file '%s' is empty." ), GetChars( fn.GetFullPath() ) ); DisplayError( this, msg ); return; } if( LoadOneLibraryPartAux( entry, lib.get() ) ) { fn = dlg.GetPath(); m_lastLibImportPath = fn.GetPath(); DisplayLibInfos(); GetScreen()->ClearUndoRedoList(); m_canvas->Refresh(); } }
void LIB_EDIT_FRAME::SelectActiveLibrary( PART_LIB* aLibrary ) { if( !aLibrary ) aLibrary = SelectLibraryFromList(); if( aLibrary ) { SetCurLib( aLibrary ); } DisplayLibInfos(); }
void WinEDA_ViewlibFrame::SelectCurrentLibrary(void) { LibraryStruct * Lib; Lib = SelectLibraryFromList(this); if ( Lib ) { g_CurrentViewComponentName.Empty(); g_CurrentViewLibraryName = Lib->m_Name; DisplayLibInfos(); if ( m_LibList ) { ReCreateListCmp(); ReDrawPanel(); DisplayLibInfos(); ReCreateHToolbar(); int id = m_LibList->FindString(g_CurrentViewLibraryName.GetData()); if ( id >= 0 ) m_LibList->SetSelection(id); } } }
void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event ) { EDA_DRAW_FRAME::OnActivate( event ); bool changed = m_libList ? ReCreateListLib() : false; if (changed) m_selection_changed = true; updatePreviewSymbol(); DisplayLibInfos(); }
void LIB_VIEW_FRAME::SetSelectedLibrary( const wxString& aLibraryName ) { if( m_libraryName == aLibraryName ) return; m_libraryName = aLibraryName; ReCreateListCmp(); m_canvas->Refresh(); DisplayLibInfos(); // Ensure the corresponding line in m_libList is selected // (which is not necessary the case if SetSelectedLibrary is called // by another caller than ClickOnLibList. m_libList->SetStringSelection( m_libraryName, 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; }
void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName ) { if( m_entryName.CmpNoCase( aComponentName ) != 0 ) { m_entryName = aComponentName; // Ensure the corresponding line in m_cmpList is selected // (which is not necessarily the case if SetSelectedComponent is called // by another caller than ClickOnCmpList. m_cmpList->SetStringSelection( aComponentName, true ); DisplayLibInfos(); m_unit = 1; m_convert = 1; Zoom_Automatique( false ); ReCreateHToolbar(); m_canvas->Refresh(); } }
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_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName ) { if( m_entryName != aComponentName ) { m_entryName = aComponentName; // Ensure the corresponding line in m_cmpList is selected // (which is not necessarily the case if SetSelectedComponent is called // by another caller than ClickOnCmpList. m_cmpList->SetStringSelection( aComponentName, true ); DisplayLibInfos(); if( m_selection_changed ) { m_unit = 1; m_convert = 1; m_selection_changed = false; } updatePreviewSymbol(); Zoom_Automatique( false ); } }
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(); }
LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, PART_LIB* aLibrary ) : SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType==FRAME_SCH_VIEWER_MODAL ? #ifdef __WINDOWS__ KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP #else aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP #endif : KICAD_DEFAULT_DRAWFRAME_STYLE, aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_FRAME_NAME_MODAL : LIB_VIEW_FRAME_NAME ) { wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL ); if( aFrameType == FRAME_SCH_VIEWER_MODAL ) SetModal( true ); // Force the frame name used in config. the lib viewer frame has a name // depending on aFrameType (needed to identify the frame by wxWidgets), // but only one configuration is preferable. m_configFrameName = LIB_VIEW_FRAME_NAME; // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) ); SetIcon( icon ); m_hotkeysDescrList = g_Viewlib_Hokeys_Descr; m_cmpList = NULL; m_libList = NULL; m_listPowerCmpOnly = false; SetScreen( new SCH_SCREEN( aKiway ) ); GetScreen()->m_Center = true; // Axis origin centered on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); // Initialize grid id to the default value (50 mils): m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); // Menu bar is not mandatory: uncomment/comment the next line // to add/remove the menubar ReCreateMenuBar(); ReCreateHToolbar(); ReCreateVToolbar(); if( !aLibrary ) { // Creates the libraries window display m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ), wxSize(m_libListWidth, -1), 0, NULL, wxLB_HSCROLL ); } else { m_libraryName = aLibrary->GetName(); m_entryName.Clear(); m_unit = 1; m_convert = 1; m_libListWidth = 0; } // Creates the component window display m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxPoint( 0, 0 ), wxSize(m_cmpListWidth, -1), 0, NULL, wxLB_HSCROLL ); if( m_libList ) ReCreateListLib(); DisplayLibInfos(); m_auimgr.SetManagedWindow( this ); EDA_PANEINFO horiz; horiz.HorizontalToolbarPane(); EDA_PANEINFO vert; vert.VerticalToolbarPane(); EDA_PANEINFO info; info.InfoToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); // Manage main toolbal m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) ); // Manage the left window (list of libraries) if( m_libList ) m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ). Left().Row( 0 ) ); // Manage the list of components) m_auimgr.AddPane( m_cmpList, wxAuiPaneInfo( info ).Name( wxT( "m_cmpList" ) ). Left().Row( 1 ) ); // Manage the draw panel m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); // Manage the message panel m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); /* Now the minimum windows are fixed, set library list * and component list of the previous values from last viewlib use */ if( m_libList ) { m_auimgr.GetPane( m_libList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_libList ).BestSize( wxSize(m_libListWidth, -1) ); } m_auimgr.GetPane( m_cmpList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_cmpList ).BestSize(wxSize(m_cmpListWidth, -1) ); m_auimgr.Update(); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetZoom( BestZoom() ); #else Zoom_Automatique( false ); #endif if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame { Raise(); Show( true ); } }
LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, CMP_LIBRARY* aLibrary ) : SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ), wxDefaultPosition, wxDefaultSize, aFrameType==FRAME_SCH_VIEWER ? KICAD_DEFAULT_DRAWFRAME_STYLE : KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT, GetLibViewerFrameName() ) { wxASSERT( aFrameType==FRAME_SCH_VIEWER || aFrameType==FRAME_SCH_VIEWER_MODAL ); if( aFrameType == FRAME_SCH_VIEWER_MODAL ) SetModal( true ); wxAcceleratorTable table( ACCEL_TABLE_CNT, accels ); m_FrameName = GetLibViewerFrameName(); m_configPath = wxT( "LibraryViewer" ); // Give an icon wxIcon icon; icon.CopyFromBitmap( KiBitmap( library_browse_xpm ) ); SetIcon( icon ); m_HotkeysZoomAndGridList = s_Viewlib_Hokeys_Descr; m_cmpList = NULL; m_libList = NULL; SetScreen( new SCH_SCREEN() ); GetScreen()->m_Center = true; // Axis origin centered on screen. LoadSettings( config() ); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); // Initialize grid id to the default value (50 mils): m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); ReCreateHToolbar(); ReCreateVToolbar(); wxSize size = GetClientSize(); size.y -= m_MsgFrameHeight + 2; wxPoint win_pos( 0, 0 ); if( !aLibrary ) { // Creates the libraries window display m_libList = new wxListBox( this, ID_LIBVIEW_LIB_LIST, wxPoint( 0, 0 ), wxSize(m_libListWidth, -1), 0, NULL, wxLB_HSCROLL ); } else { m_libraryName = aLibrary->GetName(); m_entryName.Clear(); m_unit = 1; m_convert = 1; m_libListWidth = 0; } // Creates the component window display win_pos.x = m_libListWidth; m_cmpList = new wxListBox( this, ID_LIBVIEW_CMP_LIST, wxPoint( 0, 0 ), wxSize(m_cmpListWidth, -1), 0, NULL, wxLB_HSCROLL ); if( m_libList ) ReCreateListLib(); DisplayLibInfos(); if( m_canvas ) m_canvas->SetAcceleratorTable( table ); m_auimgr.SetManagedWindow( this ); EDA_PANEINFO horiz; horiz.HorizontalToolbarPane(); EDA_PANEINFO vert; vert.VerticalToolbarPane(); EDA_PANEINFO info; info.InfoToolbarPane(); EDA_PANEINFO mesg; mesg.MessageToolbarPane(); // Manage main toolbal m_auimgr.AddPane( m_mainToolBar, wxAuiPaneInfo( horiz ).Name( wxT ("m_mainToolBar" ) ).Top().Row( 0 ) ); // Manage the left window (list of libraries) if( m_libList ) m_auimgr.AddPane( m_libList, wxAuiPaneInfo( info ).Name( wxT( "m_libList" ) ). Left().Row( 0 ) ); // Manage the list of components) m_auimgr.AddPane( m_cmpList, wxAuiPaneInfo( info ).Name( wxT( "m_cmpList" ) ). Left().Row( 1 ) ); // Manage the draw panel m_auimgr.AddPane( m_canvas, wxAuiPaneInfo().Name( wxT( "DrawFrame" ) ).CentrePane() ); // Manage the message panel m_auimgr.AddPane( m_messagePanel, wxAuiPaneInfo( mesg ).Name( wxT( "MsgPanel" ) ).Bottom().Layer(10) ); /* Now the minimum windows are fixed, set library list * and component list of the previous values from last viewlib use */ if( m_libList ) { m_auimgr.GetPane( m_libList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_libList ).BestSize( wxSize(m_libListWidth, -1) ); } m_auimgr.GetPane( m_cmpList ).MinSize( wxSize( 80, -1) ); m_auimgr.GetPane( m_cmpList ).BestSize(wxSize(m_cmpListWidth, -1) ); m_auimgr.Update(); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetZoom( BestZoom() ); #else Zoom_Automatique( false ); #endif Show( 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, 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 ); }
void WinEDA_ViewlibFrame::ViewOneLibraryContent(LibraryStruct *Lib, int Flag) { int NumOfParts = 0; EDA_LibComponentStruct *LibEntry, * PreviousLibEntry; wxString CmpName; wxClientDC dc(DrawPanel); DrawPanel->PrepareGraphicContext(&dc); if (Lib) NumOfParts = Lib->m_NumOfParts; if (NumOfParts == 0) { DisplayError(this, wxT("No Library or Library is empty!")); return; } if ( Lib == NULL ) return; PQCompFunc((PQCompFuncType) LibraryEntryCompare); LibEntry = (EDA_LibComponentStruct *) PQFirst(&Lib->m_Entries, FALSE); if( Flag == NEW_PART ) { DisplayComponentsNamesInLib(this, Lib, CmpName, g_CurrentViewComponentName); } if( Flag == NEXT_PART ) { LibEntry = (EDA_LibComponentStruct *) PQFirst(&Lib->m_Entries, FALSE); while ( LibEntry ) { if( LibEntry->m_Name.m_Text == g_CurrentViewComponentName ) { LibEntry = (EDA_LibComponentStruct *) PQNext(Lib->m_Entries, LibEntry, NULL); break; } LibEntry = (EDA_LibComponentStruct *) PQNext(Lib->m_Entries, LibEntry, NULL); } if(LibEntry == NULL) LibEntry = (EDA_LibComponentStruct *) PQFirst(&Lib->m_Entries, FALSE); if( LibEntry ) CmpName = LibEntry->m_Name.m_Text; } if( Flag == PREVIOUS_PART ) { PreviousLibEntry = NULL; LibEntry = (EDA_LibComponentStruct *) PQFirst(&Lib->m_Entries, FALSE); while ( LibEntry ) { if( LibEntry->m_Name.m_Text == g_CurrentViewComponentName ) { if( PreviousLibEntry ) break; /* else : pointage sur 1er element : balayage de la liste et Previous pointera dernier element */ } PreviousLibEntry = LibEntry; LibEntry = (EDA_LibComponentStruct *) PQNext(Lib->m_Entries, LibEntry, NULL); } if( PreviousLibEntry ) CmpName = PreviousLibEntry->m_Name.m_Text; } g_ViewUnit = 1; g_ViewConvert = 1; LibEntry = FindLibPart(CmpName,Lib->m_Name, FIND_ALIAS); g_CurrentViewComponentName = CmpName; DisplayLibInfos(); Zoom_Automatique(FALSE); RedrawActiveWindow(&dc, TRUE); if ( m_CmpList ) { int id = m_CmpList->FindString(g_CurrentViewComponentName.GetData()); if ( id >= 0 ) m_CmpList->SetSelection(id); } ReCreateHToolbar(); }
bool LIB_VIEW_FRAME::ReCreateListLib() { if( !m_libList ) return false; m_libList->Clear(); std::vector< wxString > libs = Prj().SchSymbolLibTable()->GetLogicalLibs(); // 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.size(); ) { if( m_allowedLibs.Index( libs[ii] ) == wxNOT_FOUND ) libs.erase( libs.begin() + ii ); else ii++; } } // Remove libs which have no power components, if this filter is activated if( m_listPowerCmpOnly ) { for( unsigned ii = 0; ii < libs.size(); ) { wxArrayString aliasNames; Prj().SchSymbolLibTable()->EnumerateSymbolLib( libs[ii], aliasNames, true ); if( aliasNames.IsEmpty() ) libs.erase( libs.begin() + ii ); else ii++; } } if( libs.empty() ) return true; wxArrayString libNames; for( const auto& name : libs ) libNames.Add( name ); m_libList->Append( libNames ); // 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 = libs[0]; m_entryName = wxEmptyString; m_unit = 1; m_convert = 1; } bool cmp_changed = ReCreateListCmp(); DisplayLibInfos(); m_canvas->Refresh(); return cmp_changed; }
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(); }
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 ); }
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(); }