diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 77785078d9..8ccc067972 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -92,6 +92,11 @@ bool LIB_ALIAS::IsRoot() const return name.CmpNoCase( root->GetName() ) == 0; } +CMP_LIBRARY* LIB_ALIAS::GetLibrary() +{ + return root->GetLibrary(); +} + /** * Function SaveDoc diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index adf2a66edf..3430485f03 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -102,6 +102,8 @@ enum id_eeschema_frm ID_POPUP_SCH_GETINFO_MARKER, ID_POPUP_END_RANGE, + ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, + // Unit select context menus command IDs. ID_POPUP_SCH_SELECT_UNIT_CMP, ID_POPUP_SCH_SELECT_UNIT1, diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index e341ee99d3..5fc9ed6af2 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -39,18 +39,57 @@ void LIB_EDIT_FRAME::DisplayLibInfos() /* Function to select the current library (working library) */ -void LIB_EDIT_FRAME::SelectActiveLibrary() +void LIB_EDIT_FRAME::SelectActiveLibrary( CMP_LIBRARY* aLibrary ) { - CMP_LIBRARY* Lib; - - Lib = SelectLibraryFromList( this ); - if( Lib ) + if( aLibrary == NULL ) + aLibrary = SelectLibraryFromList( this ); + if( aLibrary ) { - m_library = Lib; + m_library = aLibrary; } DisplayLibInfos(); } +/* + * function LoadComponentAndSelectLib + * Select the current active library. + * aLibrary = the CMP_LIBRARY aLibrary to select + * aLibEntry = the lib component to load from aLibrary (can be an alias + * return true if OK. + */ +bool LIB_EDIT_FRAME::LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary ) +{ + if( GetScreen()->IsModify() + && !IsOK( this, _( "Current part not saved.\n\nDiscard current changes?" ) ) ) + return false; + + SelectActiveLibrary( aLibrary ); + return LoadComponentFromCurrentLib( aLibEntry ); +} + + +/** + * function LoadComponentFromCurrentLib + * load a lib component from the current active library. + * @param aLibEntry = the lib component to load from aLibrary (can be an alias + * @return true if OK. + */ +bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry ) +{ + if( !LoadOneLibraryPartAux( aLibEntry, m_library ) ) + return false; + + g_EditPinByPinIsOn = m_component->UnitsLocked() ? true : false; + m_HToolBar->ToggleTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, g_EditPinByPinIsOn ); + + GetScreen()->ClearUndoRedoList(); + Zoom_Automatique( false ); + DrawPanel->Refresh(); + SetShowDeMorgan( m_component->HasConversion() ); + m_HToolBar->Refresh(); + + return true; +} /** * Function LoadOneLibraryPart @@ -106,17 +145,8 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) return; } - if( !LoadOneLibraryPartAux( LibEntry, m_library ) ) + if( ! LoadComponentFromCurrentLib( LibEntry ) ) return; - - g_EditPinByPinIsOn = m_component->UnitsLocked() ? true : false; - m_HToolBar->ToggleTool( ID_LIBEDIT_EDIT_PIN_BY_PIN, g_EditPinByPinIsOn ); - - GetScreen()->ClearUndoRedoList(); - Zoom_Automatique( false ); - DrawPanel->Refresh(); - SetShowDeMorgan( m_component->HasConversion() ); - m_HToolBar->Refresh(); } diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index ce09274dda..d415220027 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -222,9 +222,25 @@ private: // General: void SaveOnePartInMemory(); - void SelectActiveLibrary(); + + /** + * function SelectActiveLibrary + * Select the current active library. + * @param aLibrary = the CMP_LIBRARY aLibrary to select, or NULL + * to select from a list + */ + void SelectActiveLibrary( CMP_LIBRARY* aLibrary = NULL); + void SaveActiveLibrary( wxCommandEvent& event ); + /** + * function LoadComponentFromCurrentLib + * load a lib component from the current active library. + * @param aLibEntry = the lib component to load from aLibrary (can be an alias + * @return true if OK. + */ + bool LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry ); + bool LoadOneLibraryPartAux( LIB_ALIAS* LibEntry, CMP_LIBRARY* Library ); void DisplayCmpDoc(); @@ -272,6 +288,15 @@ private: void EditField( wxDC* DC, LIB_FIELD* Field ); public: + /** + * function LoadComponentAndSelectLib + * Select the current active library. + * @param aLibrary = the CMP_LIBRARY aLibrary to select + * @param aLibEntry = the lib component to load from aLibrary (can be an alias + * @return true if OK. + */ + bool LoadComponentAndSelectLib( LIB_ALIAS* aLibEntry, CMP_LIBRARY* aLibrary ); + /* Block commands: */ virtual int ReturnBlockCommand( int aKey ); virtual void HandleBlockPlace( wxDC* DC ); diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index ac312daad3..407a21dbe3 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -299,6 +299,12 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) _( "Unit" ), component_select_unit_xpm ); } + if( !Component->GetFlags() ) + { + ADD_MENUITEM( editmenu, ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, _( "Edit with Libedit" ), + library_xpm ); + } + ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP, _( "Edit Component" ), edit_component_xpm ); diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 9415ec6bd9..e2ab7c938e 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -13,8 +13,6 @@ #include "wxEeschemaStruct.h" #include "general.h" -#include "macros.h" -#include "protos.h" #include "class_library.h" #include "lib_rectangle.h" #include "lib_pin.h" diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 98bd84a56b..769476b2b5 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -22,6 +22,7 @@ #include "class_library.h" #include "wxEeschemaStruct.h" #include "class_sch_screen.h" +#include "sch_component.h" #include "dialog_helpers.h" #include "netlist_control.h" @@ -79,6 +80,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, SCH_EDIT_FRAME::SetLanguage ) EVT_TOOL( ID_TO_LIBRARY, SCH_EDIT_FRAME::OnOpenLibraryEditor ) + EVT_TOOL( ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP, SCH_EDIT_FRAME::OnOpenLibraryEditor ) EVT_TOOL( ID_TO_LIBVIEW, SCH_EDIT_FRAME::OnOpenLibraryViewer ) EVT_TOOL( ID_TO_PCB, SCH_EDIT_FRAME::OnOpenPcbnew ) @@ -707,13 +709,39 @@ void SCH_EDIT_FRAME::OnOpenLibraryViewer( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { + SCH_COMPONENT* component = NULL; + if( event.GetId() == ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP ) + { + SCH_ITEM* item = GetScreen()->GetCurItem(); + if( (item == NULL) || (item->GetFlags() != 0) || + ( item->Type() != SCH_COMPONENT_T ) ) + { + wxMessageBox( _("Error: not a component or no component" ) ); + return; + } + + component = (SCH_COMPONENT*) item; + } + if( m_LibeditFrame ) - m_LibeditFrame->Show( true ); + { + if( m_LibeditFrame->IsIconized() ) + m_LibeditFrame->Iconize( false ); + m_LibeditFrame->Raise(); + } else m_LibeditFrame = new LIB_EDIT_FRAME( this, wxT( "Library Editor" ), wxPoint( -1, -1 ), wxSize( 600, 400 ) ); + if( component ) + { + LIB_ALIAS* entry = CMP_LIBRARY::FindLibraryEntry( component->GetLibName() ); + if( entry == NULL ) // Should not occur + return; + CMP_LIBRARY* library = entry->GetLibrary(); + m_LibeditFrame->LoadComponentAndSelectLib( entry, library ); + } } diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 038af398dc..d6a9e4d38c 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -24,7 +24,7 @@ */ static const int PcbZoomList[] = { - 5, 10, 15, 22, 30, 45, 70, 100, 150, 220, 350, 500, 800, 1200, + 5, 10, 15, 20, 30, 45, 70, 100, 150, 220, 350, 500, 800, 1200, 2000, 3500, 5000, 10000, 20000 };