From f1e5be9a6761bc65083f3ebe59896cfccf2e754d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 19 Feb 2012 20:53:11 +0100 Subject: [PATCH] Fix @JP messages (no bugs, just comment lines) Eeschema: Viewlib is now accessible from Libedit (to browse libs or load a component to edit) Libedit: uses now the same dialog as the schematic editor to load a component Some code cleaning. --- common/dialogs/dialog_get_component.cpp | 6 +- eeschema/dialogs/dialog_lib_new_component.fbp | 1402 ++++++++--------- eeschema/getpart.cpp | 230 +-- eeschema/libedit.cpp | 38 +- eeschema/libeditframe.cpp | 1 + eeschema/sch_base_frame.cpp | 31 + eeschema/schframe.cpp | 20 - eeschema/tool_lib.cpp | 4 + eeschema/viewlib_frame.cpp | 2 +- include/dialog_get_component.h | 15 + include/sch_base_frame.h | 58 +- include/wxEeschemaStruct.h | 10 - pcbnew/block_module_editor.cpp | 30 +- pcbnew/loadcmp.cpp | 4 +- pcbnew/modedit.cpp | 134 +- 15 files changed, 1020 insertions(+), 965 deletions(-) diff --git a/common/dialogs/dialog_get_component.cpp b/common/dialogs/dialog_get_component.cpp index 10567168b1..eb9f6d6a40 100644 --- a/common/dialogs/dialog_get_component.cpp +++ b/common/dialogs/dialog_get_component.cpp @@ -3,7 +3,6 @@ /*********************************/ #include -//#include "gr_basic.h" #include #include #include @@ -46,6 +45,7 @@ void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList ) { SetFocus(); m_GetExtraFunction = false; + m_selectionIsKeyword = false; m_historyList->Append( aHistoryList ); if( !m_auxToolSelector ) { @@ -63,6 +63,7 @@ void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event ) void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event ) { + m_selectionIsKeyword = false; switch( event.GetId() ) { case ID_SEL_BY_LISTBOX: @@ -74,7 +75,8 @@ void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event ) break; case ID_ACCEPT_KEYWORD: - m_Text = wxT( "= " ) + m_textCmpNameCtrl->GetValue(); + m_selectionIsKeyword = true; + m_Text = m_textCmpNameCtrl->GetValue(); break; case ID_LIST_ALL: diff --git a/eeschema/dialogs/dialog_lib_new_component.fbp b/eeschema/dialogs/dialog_lib_new_component.fbp index 2deef27ad0..21b0b26092 100644 --- a/eeschema/dialogs/dialog_lib_new_component.fbp +++ b/eeschema/dialogs/dialog_lib_new_component.fbp @@ -1,8 +1,8 @@ - + - + C++ 1 UTF-8 @@ -12,66 +12,66 @@ none 1 dialog_lib_new_component - + . - + 1 1 0 - + wxBOTH - + 1 - - - + + + 0 wxID_ANY - - + + DIALOG_LIB_NEW_COMPONENT_BASE - - + + wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER - + Component Properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + mainSizer wxHORIZONTAL none @@ -80,7 +80,7 @@ wxALL|wxEXPAND 1 - + bSizer5 wxVERTICAL none @@ -89,50 +89,50 @@ wxALIGN_LEFT 0 - - + + 1 - + ,90,92,-1,70,0 0 wxID_ANY General Settings - - + + m_staticText6 protected - - - - - - - - + + + + + + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -140,7 +140,7 @@ wxALL|wxEXPAND 0 - + bSizer2 wxHORIZONTAL none @@ -159,50 +159,50 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY Component &name: - - + + m_staticText2 protected - - - - + + + + This is the component name in library, and also the default component value when loaded in the schematic. - - - + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -220,54 +220,54 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY - + 0 - + m_textName protected - + 100,-1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -287,7 +287,7 @@ wxALL|wxEXPAND 0 - + bSizer3 wxHORIZONTAL none @@ -306,50 +306,50 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY Default &reference designator: - - + + m_staticText3 protected - - - - + + + + This is the reference used in schematic for annotation. Do not use digits in reference. - - - + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -367,54 +367,54 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY - + 0 - + m_textReference protected - + 100,-1 - - - + + + U - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -434,7 +434,7 @@ wxALL|wxEXPAND 0 - + bSizer4 wxHORIZONTAL none @@ -453,50 +453,50 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY Number of &parts per package: - - + + m_staticText4 protected - - - - + + + + This is the number of parts in this component package. A 74LS00 gate has 4 parts per packages. - - - + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -514,54 +514,54 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY 0 26 - + 1 - + m_spinPartCount protected - + 100,-1 wxSP_ARROW_KEYS - - + + 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -581,7 +581,7 @@ wxALL|wxEXPAND 0 - + bSizer7 wxHORIZONTAL none @@ -600,51 +600,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 0 - + 1 - - + + 0 wxID_ANY Create component with &alternate body style (DeMorgan) - - + + m_checkHasConversion protected - - - - + + + + Check this option for components that have a De Morgan representation. This is usual for gates. - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -654,7 +654,7 @@ wxALL|wxEXPAND 0 - + bSizer8 wxHORIZONTAL none @@ -673,51 +673,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 0 - + 1 - - + + 0 wxID_ANY Create component as power &symbol - - + + m_checkIsPowerSymbol protected - - - - + + + + Check this option for power symbols. Power symbols have specific properties for Eeschema: - Value cannot be edited (to avoid mistakes) because this is the pin name that is important for a power symbol - Reference is updated automatically when a netlist is created (no need to run Annotate) - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -727,7 +727,7 @@ wxALL|wxEXPAND 0 - + bSizer9 wxHORIZONTAL none @@ -746,51 +746,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 0 - + 1 - - + + 0 wxID_ANY Parts in package locked (cannot be swapped) - - + + m_checkLockItems protected - - - - + + + + Check this option if Eeschema cannot change parts selections inside a given package This happens when parts are different in this package. When this option is not checked, Eeschema automatically choose the parts in packages to minimize packages count - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -810,50 +810,50 @@ wxALIGN_LEFT|wxBOTTOM 0 - - + + 1 - + ,90,92,-1,70,0 0 wxID_ANY Global Pin Settings - - + + m_staticText7 protected - - - - - - - - + + + + + + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -861,7 +861,7 @@ wxALL|wxEXPAND 1 - + bSizer6 wxHORIZONTAL none @@ -880,50 +880,50 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY Pin text position &offset: - - + + m_staticText41 protected - - - - + + + + Margin (in 0.001 inches) between a pin name position and the component body. A value from 10 to 40 is usually good. - - - + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -941,54 +941,54 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - - + + 1 - - + + 0 wxID_ANY 40 100 - + 1 - + m_spinPinTextPosition protected - + 100,-1 wxSP_ARROW_KEYS - - + + 40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -996,50 +996,50 @@ wxALIGN_CENTER_VERTICAL 0 - - + + 1 - - + + 0 wxID_ANY mils - - + + m_staticText5 protected - + 30,-1 - - - - - - + + + + + + -1 - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -1049,7 +1049,7 @@ wxALL|wxEXPAND 0 - + bSizer10 wxHORIZONTAL none @@ -1068,51 +1068,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 - + 1 - - + + 0 wxID_ANY Show pin n&umber text - - + + m_checkShowPinNumber protected - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1122,7 +1122,7 @@ wxALL|wxEXPAND 0 - + bSizer12 wxHORIZONTAL none @@ -1141,51 +1141,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 - + 1 - - + + 0 wxID_ANY Show pin name te&xt - - + + m_checkShowPinName protected - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1195,7 +1195,7 @@ wxEXPAND 1 - + bSizer121 wxHORIZONTAL none @@ -1214,51 +1214,51 @@ wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 - + 1 - - + + 0 wxID_ANY Pin name &inside - - + + m_checkShowPinNameInside protected - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1286,17 +1286,17 @@ 1 0 0 - + m_sdbSizer protected - - - - - - - - + + + + + + + + diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 5299456376..1f16b3d621 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -48,7 +49,7 @@ #include -wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) +wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void ) { wxSemaphore semaphore( 0, 1 ); wxString cmpname; @@ -60,6 +61,12 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) m_ViewlibFrame = NULL; } + if( m_LibeditFrame && m_LibeditFrame->m_ViewlibFrame ) + { + m_LibeditFrame->m_ViewlibFrame->Destroy(); + m_LibeditFrame->m_ViewlibFrame = NULL; + } + m_ViewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore ); // Show the library viewer frame until it is closed while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event @@ -74,36 +81,38 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) return cmpname; } - /* - * load from a library and place a component - * if libname != "", search in lib "libname" - * else search in all loaded libs + * Function SelectComponentFromLib + * Calls the library viewer to select component to import into schematic. + * if the library viewer is currently running, it is closed and reopened + * in modal mode. + * param aLibname = the lib name or an empty string. + * if aLibname is empty, the full list of libraries is used + * param aList = list of previously loaded components + * param aUseLibBrowser = bool to call the library viewer to select the component + * param aUnit = a point to int to return the selected unit (if any) + * param aConvert = a point to int to return the selected De Morgan shape (if any) + * + * return the component name */ -SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, - const wxString& libname, - wxArrayString& HistoryList, - bool UseLibBrowser ) +wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname, + wxArrayString& aHistoryList, + bool aUseLibBrowser, + int* aUnit, + int* aConvert ) { int CmpCount = 0; - int unit = 1; - int convert = 1; - LIB_COMPONENT* Entry = NULL; - SCH_COMPONENT* component = NULL; - CMP_LIBRARY* Library = NULL; - wxString Name, keys, msg; - bool AllowWildSeach = true; - static wxString lastCommponentName; + LIB_COMPONENT* libEntry = NULL; + CMP_LIBRARY* currLibrary = NULL; + wxString cmpName, keys, msg; + bool allowWildSeach = true; - m_itemToRepeat = NULL; - m_canvas->SetIgnoreMouseEvents( true ); - - if( !libname.IsEmpty() ) + if( !aLibname.IsEmpty() ) { - Library = CMP_LIBRARY::FindLibrary( libname ); + currLibrary = CMP_LIBRARY::FindLibrary( aLibname ); - if( Library != NULL ) - CmpCount = Library->GetCount(); + if( currLibrary != NULL ) + CmpCount = currLibrary->GetCount(); } else { @@ -116,27 +125,106 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, /* Ask for a component name or key words */ msg.Printf( _( "component selection (%d items loaded):" ), CmpCount ); - DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList, - msg, UseLibBrowser ); - dlg.SetComponentName( lastCommponentName ); + DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), aHistoryList, + msg, aUseLibBrowser ); + if( aHistoryList.GetCount() ) + dlg.SetComponentName( aHistoryList[0] ); if ( dlg.ShowModal() == wxID_CANCEL ) - { - m_canvas->SetIgnoreMouseEvents( false ); - m_canvas->MoveCursorToCrossHair(); - return NULL; - } + return wxEmptyString; if( dlg.m_GetExtraFunction ) { - Name = SelectFromLibBrowser(); - unit = m_ViewlibFrame->GetUnit(); - convert = m_ViewlibFrame->GetConvert(); + cmpName = SelectComponentFromLibBrowser(); + if( aUnit ) + *aUnit = m_ViewlibFrame->GetUnit(); + if( aConvert ) + *aConvert = m_ViewlibFrame->GetConvert(); + if( !cmpName.IsEmpty() ) + AddHistoryComponentName( aHistoryList, cmpName ); + return cmpName; } else + cmpName = dlg.GetComponentName(); + + if( cmpName.IsEmpty() ) + return wxEmptyString; + +#ifndef KICAD_KEEPCASE + cmpName.MakeUpper(); +#endif + + if( dlg.IsKeyword() ) { - Name = dlg.GetComponentName(); + allowWildSeach = false; + keys = cmpName; + cmpName = DataBaseGetName( this, keys, cmpName ); + + if( cmpName.IsEmpty() ) + return wxEmptyString; + } + else if( cmpName == wxT( "*" ) ) + { + allowWildSeach = false; + + if( GetNameOfPartToLoad( this, currLibrary, cmpName ) == 0 ) + return wxEmptyString; } + else if( cmpName.Contains( wxT( "?" ) ) || cmpName.Contains( wxT( "*" ) ) ) + { + allowWildSeach = false; + cmpName = DataBaseGetName( this, keys, cmpName ); + + if( cmpName.IsEmpty() ) + return wxEmptyString; + } + + libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname ); + + if( ( libEntry == NULL ) && allowWildSeach ) /* Search with wildcard */ + { + allowWildSeach = false; + wxString wildname = wxChar( '*' ) + cmpName + wxChar( '*' ); + cmpName = wildname; + cmpName = DataBaseGetName( this, keys, cmpName ); + + if( !cmpName.IsEmpty() ) + libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname ); + + if( libEntry == NULL ) + return wxEmptyString; + } + + if( libEntry == NULL ) + { + msg = _( "Failed to find part " ) + cmpName + _( " in library" ); + DisplayError( this, msg ); + return wxEmptyString; + } + + AddHistoryComponentName( aHistoryList, cmpName ); + return cmpName; +} + + +/* + * load from a library and place a component + * if libname != "", search in lib "libname" + * else search in all loaded libs + */ +SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC, + const wxString& aLibname, + wxArrayString& aHistoryList, + bool aUseLibBrowser ) +{ + int unit = 1; + int convert = 1; + + m_itemToRepeat = NULL; + m_canvas->SetIgnoreMouseEvents( true ); + + wxString Name = SelectComponentFromLibrary( aLibname, aHistoryList, aUseLibBrowser, + &unit, &convert ); if( Name.IsEmpty() ) { @@ -149,76 +237,20 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, Name.MakeUpper(); #endif - if( Name.GetChar( 0 ) == '=' ) - { - AllowWildSeach = false; - keys = Name.AfterFirst( '=' ); - Name = DataBaseGetName( this, keys, Name ); - - if( Name.IsEmpty() ) - { - m_canvas->SetIgnoreMouseEvents( false ); - m_canvas->MoveCursorToCrossHair(); - return NULL; - } - } - else if( Name == wxT( "*" ) ) - { - AllowWildSeach = false; - - if( GetNameOfPartToLoad( this, Library, Name ) == 0 ) - { - m_canvas->SetIgnoreMouseEvents( false ); - m_canvas->MoveCursorToCrossHair(); - return NULL; - } - } - else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) ) - { - AllowWildSeach = false; - Name = DataBaseGetName( this, keys, Name ); - - if( Name.IsEmpty() ) - { - m_canvas->SetIgnoreMouseEvents( false ); - m_canvas->MoveCursorToCrossHair(); - return NULL; - } - } - - Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); - - if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */ - { - AllowWildSeach = false; - wxString wildname = wxChar( '*' ) + Name + wxChar( '*' ); - Name = wildname; - Name = DataBaseGetName( this, keys, Name ); - - if( !Name.IsEmpty() ) - Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); - - if( Entry == NULL ) - { - m_canvas->SetIgnoreMouseEvents( false ); - m_canvas->MoveCursorToCrossHair(); - return NULL; - } - } + LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( Name, aLibname ); m_canvas->SetIgnoreMouseEvents( false ); m_canvas->MoveCursorToCrossHair(); if( Entry == NULL ) { - msg = _( "Failed to find part " ) + Name + _( " in library" ); - DisplayError( this, msg ); + wxString msg; + msg.Printf( _( "Failed to find part <%s> in library" ), GetChars( Name ) ); + wxMessageBox( msg ); return NULL; } - lastCommponentName = Name; - AddHistoryComponentName( HistoryList, Name ); - + SCH_COMPONENT* component; component = new SCH_COMPONENT( *Entry, m_CurrentSheet, unit, convert, GetScreen()->GetCrossHairPosition(), true ); @@ -230,10 +262,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, // Set the component value that can differ from component name in lib, for aliases component->GetField( VALUE )->m_Text = Name; component->DisplayInfo( this ); - component->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); + component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); component->SetFlags( IS_NEW ); - MoveItem( (SCH_ITEM*) component, DC ); + MoveItem( (SCH_ITEM*) component, aDC ); return component; } diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 8321bbe3f8..e21f9c0778 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -113,10 +113,9 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry ) void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) { - int i; wxString msg; wxString CmpName; - LIB_ALIAS* LibEntry = NULL; + LIB_ALIAS* libEntry = NULL; m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); @@ -133,9 +132,10 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) return; } - i = GetNameOfPartToLoad( this, m_library, CmpName ); + wxArrayString historyList; + CmpName = SelectComponentFromLibrary( m_library->GetName(), historyList, true, NULL, NULL ); - if( i == 0 ) + if( CmpName.IsEmpty() ) return; GetScreen()->ClrModify(); @@ -149,19 +149,39 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) } /* Load the new library component */ - LibEntry = m_library->FindEntry( CmpName ); + libEntry = m_library->FindEntry( CmpName ); + CMP_LIBRARY* searchLib = m_library; + if( libEntry == NULL ) + { // Not found in the active library: search inside the full list + // (can happen when using Viewlib to load a component) + libEntry = CMP_LIBRARY::FindLibraryEntry( CmpName ); + if( libEntry ) + { + searchLib = libEntry->GetLibrary(); + // The entry to load is not in the active lib + // Ask for a new active lib + wxString msg; + msg << _("The selected component is not in the active library"); + msg << wxT("\n\n"); + msg << _("Do you want to change the active library?"); + if( IsOK( this, msg ) ) + SelectActiveLibrary( searchLib ); + } + } - if( LibEntry == NULL ) + if( libEntry == NULL ) { msg.Printf( _( "Component name \"%s\" not found in library \"%s\"." ), GetChars( CmpName ), - GetChars( m_library->GetName() ) ); + GetChars( searchLib->GetName() ) ); DisplayError( this, msg ); return; } - if( ! LoadComponentFromCurrentLib( LibEntry ) ) - return; + EXCHG( searchLib, m_library ); + LoadComponentFromCurrentLib( libEntry ); + EXCHG( searchLib, m_library ); + DisplayLibInfos(); } diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index e7d3d649f2..7d12b81505 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::SaveActiveLibrary ) EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, LIB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_LIBEDIT_DELETE_PART, LIB_EDIT_FRAME::DeleteOnePart ) + EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer ) EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart ) EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting ) diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 9cc0492977..2954e054e7 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -23,6 +23,37 @@ */ #include +#include +#include + +SCH_BASE_FRAME::SCH_BASE_FRAME( wxWindow* aParent, + id_drawframe aWindowType, + const wxString& aTitle, + const wxPoint& aPosition, const wxSize& aSize, + long aStyle ) : + EDA_DRAW_FRAME( aParent, aWindowType, aTitle, aPosition, aSize, aStyle ) +{ + m_ViewlibFrame = NULL; + m_LibeditFrame = NULL; +} + + +void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event ) +{ + if( m_ViewlibFrame ) + { + m_ViewlibFrame->Show( true ); + return; + } + + if( m_LibeditFrame && m_LibeditFrame->m_ViewlibFrame ) + { + m_LibeditFrame->m_ViewlibFrame->Show( true ); + return; + } + + m_ViewlibFrame = new LIB_VIEW_FRAME( this ); +} SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 6df0205af3..e0efa4fd90 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -27,10 +27,6 @@ * @file schframe.cpp */ -#ifdef __GNUG__ -#pragma implementation -#endif - #include #include #include @@ -193,8 +189,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father, m_showBorderAndTitleBlock = true; // true to show sheet references m_CurrentSheet = new SCH_SHEET_PATH(); m_TextFieldSize = DEFAULT_SIZE_TEXT; - m_LibeditFrame = NULL; // Component editor frame. - m_ViewlibFrame = NULL; // Frame for browsing component libraries m_DefaultSchematicFileName = NAMELESS_PROJECT; m_DefaultSchematicFileName += wxT( ".sch" ); m_showAllPins = false; @@ -776,20 +770,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) } } - -void SCH_EDIT_FRAME::OnOpenLibraryViewer( wxCommandEvent& event ) -{ - if( m_ViewlibFrame ) - { - m_ViewlibFrame->Show( true ); - } - else - { - m_ViewlibFrame = new LIB_VIEW_FRAME( this ); - } -} - - void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) { SCH_COMPONENT* component = NULL; diff --git a/eeschema/tool_lib.cpp b/eeschema/tool_lib.cpp index 2ac7e14213..a2f58c56f0 100644 --- a/eeschema/tool_lib.cpp +++ b/eeschema/tool_lib.cpp @@ -118,6 +118,10 @@ void LIB_EDIT_FRAME::ReCreateHToolbar() m_mainToolBar->AddTool( ID_LIBEDIT_DELETE_PART, wxEmptyString, KiBitmap( delete_xpm ), _( "Delete component in current library" ) ); + m_mainToolBar->AddSeparator(); + m_mainToolBar->AddTool( ID_TO_LIBVIEW, wxEmptyString, KiBitmap( library_browse_xpm ), + HELP_RUN_LIB_VIEWER ); + m_mainToolBar->AddSeparator(); m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString, KiBitmap( new_component_xpm ), _( "Create a new component" ) ); diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 0400f388ce..80fae3b41e 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -255,7 +255,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library, wxSemaph LIB_VIEW_FRAME::~LIB_VIEW_FRAME() { - SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) wxGetApp().GetTopWindow(); + SCH_BASE_FRAME* frame = (SCH_BASE_FRAME*) GetParent(); frame->SetLibraryViewerWindow( NULL ); } diff --git a/include/dialog_get_component.h b/include/dialog_get_component.h index 5a1dbaffcc..41fe3966ec 100644 --- a/include/dialog_get_component.h +++ b/include/dialog_get_component.h @@ -19,6 +19,7 @@ class DIALOG_GET_COMPONENT : public DIALOG_GET_COMPONENT_BASE private: bool m_auxToolSelector; wxString m_Text; + bool m_selectionIsKeyword; public: bool m_GetExtraFunction; @@ -30,7 +31,21 @@ public: bool show_extra_tool ); ~DIALOG_GET_COMPONENT() {}; + /** + * Function GetComponentName + * @return the selection (name or keyword) + */ wxString GetComponentName( void ); + + /** + * Function IsKeyword + * @return true if the returned string is a keyword + */ + bool IsKeyword( void ) + { + return m_selectionIsKeyword; + } + void SetComponentName( const wxString& name ); private: diff --git a/include/sch_base_frame.h b/include/sch_base_frame.h index d8cd707f29..33f02c9c9b 100644 --- a/include/sch_base_frame.h +++ b/include/sch_base_frame.h @@ -29,6 +29,8 @@ class PAGE_INFO; class TITLE_BLOCK; +class LIB_VIEW_FRAME; +class LIB_EDIT_FRAME; /** @@ -43,18 +45,27 @@ class TITLE_BLOCK; */ class SCH_BASE_FRAME : public EDA_DRAW_FRAME { +protected: + LIB_VIEW_FRAME* m_ViewlibFrame; // A library viewer, common to SCH_EDIT_FRAME + // and LIB_EDIT_FRAME. + // has no meaning to LIB_VIEW_FRAME + LIB_EDIT_FRAME* m_LibeditFrame; // the library editor. + // Is used mainly in SCH_EDIT_FRAME + // but is defined here because some functions + // need to know if a library editor or a libray + // viewer is currently opened + public: SCH_BASE_FRAME( wxWindow* aParent, id_drawframe aWindowType, const wxString& aTitle, const wxPoint& aPosition, const wxSize& aSize, - long aStyle = KICAD_DEFAULT_DRAWFRAME_STYLE ) : - EDA_DRAW_FRAME( aParent, aWindowType, aTitle, aPosition, aSize, aStyle ) - { - } + long aStyle = KICAD_DEFAULT_DRAWFRAME_STYLE ); SCH_SCREEN* GetScreen() const; // overload EDA_DRAW_FRAME + void SetLibraryViewerWindow( LIB_VIEW_FRAME* aFrame ) { m_ViewlibFrame = aFrame; } + void SetPageSettings( const PAGE_INFO& aPageSettings ); // overload EDA_DRAW_FRAME const PAGE_INFO& GetPageSettings () const; // overload EDA_DRAW_FRAME const wxSize GetPageSizeIU() const; // overload EDA_DRAW_FRAME @@ -64,6 +75,45 @@ public: const TITLE_BLOCK& GetTitleBlock() const; // overload EDA_DRAW_FRAME void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ); // overload EDA_DRAW_FRAME + +protected: + + /** + * Function SelectComponentFromLibBrowser + * Calls the library viewer to select component to import into schematic. + * if the library viewer is currently running, it is closed and reopened + * in modal mode. + * @return the component name + */ + wxString SelectComponentFromLibBrowser( void ); + + /** + * Function SelectComponentFromLib + * Calls the library viewer to select component to import into schematic. + * if the library viewer is currently running, it is closed and reopened + * in modal mode. + * @param aLibname = the lib name or an empty string. + * if aLibname is empty, the full list of libraries is used + * @param aHistoryList = list of previously loaded components + * @param aUseLibBrowser = bool to call the library viewer to select the component + * @param aUnit = a point to int to return the selected unit (if any) + * @param aConvert = a point to int to return the selected De Morgan shape (if any) + * + * @return the component name + */ + wxString SelectComponentFromLibrary( const wxString& aLibname, + wxArrayString& aHistoryList, + bool aUseLibBrowser, + int* aUnit, + int* aConvert ); + + /** + * Function OnOpenLibraryViewer + * Open the library viewer only to browse library contents. + * If the viewed is already opened from this, raise the viewer + * If the viewed is already opened from an other window, close it and reopen + */ + void OnOpenLibraryViewer( wxCommandEvent& event ); }; #endif // SCH_BASE_FRAME_H_ diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index bc69b0eb7c..5a18e53dd1 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -114,8 +114,6 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME { private: SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on. - LIB_VIEW_FRAME* m_ViewlibFrame; - LIB_EDIT_FRAME* m_LibeditFrame; wxString m_DefaultSchematicFileName; int m_TextFieldSize; PARAM_CFG_ARRAY m_projectFileParams; @@ -204,8 +202,6 @@ public: void SetLibraryEditorWindow( LIB_EDIT_FRAME* aFrame ) { m_LibeditFrame = aFrame; } - void SetLibraryViewerWindow( LIB_VIEW_FRAME* aFrame ) { m_ViewlibFrame = aFrame; } - bool GetShowAllPins() const { return m_showAllPins; } void SetShowAllPins( bool aEnable ) { m_showAllPins = aEnable; } @@ -746,7 +742,6 @@ private: void OnLoadProject( wxCommandEvent& event ); void OnOpenPcbnew( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event ); - void OnOpenLibraryViewer( wxCommandEvent& event ); void OnOpenLibraryEditor( wxCommandEvent& event ); void OnSetOptions( wxCommandEvent& event ); void OnCancelCurrentCommand( wxCommandEvent& aEvent ); @@ -874,11 +869,6 @@ private: SCH_SHEET* CreateSheet( wxDC* DC ); void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC ); - /** - * Use the component viewer to select component to import into schematic. - */ - wxString SelectFromLibBrowser( void ); - public: /** * Function EditSheet diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index feb32b1ee7..650e82d0d6 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -56,7 +56,13 @@ #define BLOCK_COLOR BROWN +// Functions defined here, but used also in other files +// These 2 functions are used in modedit to rotate or mirror the whole footprint +// so they are called with force_all = true +void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false ); +void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false ); +// Local functions: static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ); @@ -64,8 +70,6 @@ static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ); static void ClearMarkItems( MODULE* module ); static void CopyMarkedItems( MODULE* module, wxPoint offset ); static void MoveMarkedItems( MODULE* module, wxPoint offset ); -static void MirrorMarkedItems( MODULE* module, wxPoint offset ); -static void RotateMarkedItems( MODULE* module, wxPoint offset ); static void DeleteMarkedItems( MODULE* module ); @@ -521,8 +525,10 @@ void DeleteMarkedItems( MODULE* module ) /** Mirror marked items, refer to a Vertical axis at position offset + * Note: because this function is used in global transform, + * if force_all is true, all items will be mirrored */ -void MirrorMarkedItems( MODULE* module, wxPoint offset ) +void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all ) { #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x; wxPoint tmp; @@ -533,9 +539,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() ) { - // @JP why allow some pads to stay behind? Do not understand - // why this test is here. - if( !pad->IsSelected() ) + // Skip pads not selected, i.e. not inside the block to mirror: + if( !pad->IsSelected() && !force_all ) continue; tmp = pad->GetPosition(); @@ -557,7 +562,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() ) { - if( !item->IsSelected() ) // @JP why allow some graphics to stay behind? + // Skip items not selected, i.e. not inside the block to mirror: + if( !item->IsSelected() && !force_all ) continue; switch( item->Type() ) @@ -600,9 +606,11 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) } -/** Rotate marked items, refer to a Vertical axis at position offset +/** Rotate marked items, refer to a rotation point at position offset + * Note: because this function is used in global transform, + * if force_all is true, all items will be rotated */ -void RotateMarkedItems( MODULE* module, wxPoint offset ) +void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all ) { #define ROTATE( z ) RotatePoint( (&z), offset, 900 ) @@ -611,7 +619,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset ) for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() ) { - if( !pad->IsSelected() ) + if( !pad->IsSelected() && !force_all ) continue; wxPoint pos = pad->GetPosition(); @@ -624,7 +632,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset ) for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() ) { - if( !item->IsSelected() ) + if( !item->IsSelected() && !force_all) continue; switch( item->Type() ) diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index 02d858e013..b533e099a3 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -178,10 +178,10 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, moduleName.MakeUpper(); - if( moduleName[0] == '=' ) // Selection by keywords + if( dlg.IsKeyword() ) // Selection by keywords { AllowWildSeach = false; - keys = moduleName.AfterFirst( '=' ); + keys = moduleName; moduleName = Select_1_Module_From_List( this, aLibrary, wxEmptyString, keys ); if( moduleName.IsEmpty() ) /* Cancel command */ diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 3380461e47..ee9e1c2f5d 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -28,6 +28,12 @@ #include +// Functions defined in block_module_editor, but used here +// These 2 functions are used in modedit to rotate or mirror the whole footprint +// so they are called with force_all = true +void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false ); +void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false ); + BOARD_ITEM* FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay( int aHotKeyCode ) { @@ -724,141 +730,57 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform ) { - D_PAD* pad = module->m_Pads; - EDA_ITEM* item = module->m_Drawings; - TEXTE_MODULE* textmod; - EDGE_MODULE* edgemod; - wxPoint pt; - wxSize size; - double angle = 900; // Necessary +- 900 (+- 90 degrees) ) + TEXTE_MODULE* textmod; + wxPoint pos; + double angle = 900; // Necessary +- 900 (+- 90 degrees). + // Be prudent: because RotateMarkedItems is used to rotate some items + // used the same value as RotateMarkedItems switch( transform ) { case ID_MODEDIT_MODULE_ROTATE: - module->SetOrientation( angle ); + #define ROTATE( z ) RotatePoint( (&z), angle ) + RotateMarkedItems( module, wxPoint(0,0), true ); - for( ; pad; pad = pad->Next() ) - { - pad->SetPos0( pad->GetPosition() ); - pad->SetOrientation( pad->GetOrientation() - angle ); - - pt = pad->GetOffset(); - RotatePoint( &pt, angle ); - pad->SetOffset( pt ); - - size = pad->GetSize(); - EXCHG( size.x, size.y ); - pad->SetSize( size ); - - size = pad->GetDelta(); - RotatePoint( &size.x, &size.y, -angle ); - pad->SetDelta( size ); - } - - module->m_Reference->SetPos0( module->m_Reference->m_Pos ); + pos = module->m_Reference->GetPosition(); + ROTATE( pos ); + module->m_Reference->SetPosition( pos ); + module->m_Reference->SetPos0( module->m_Reference->GetPosition() ); module->m_Reference->m_Orient += angle; if( module->m_Reference->m_Orient >= 1800 ) module->m_Reference->m_Orient -= 1800; + pos = module->m_Value->GetPosition(); + ROTATE( pos ); + module->m_Value->SetPosition( pos ); module->m_Value->SetPos0( module->m_Value->m_Pos ); module->m_Value->m_Orient += angle; if( module->m_Value->m_Orient >= 1800 ) module->m_Value->m_Orient -= 1800; - for( ; item != NULL; item = item->Next() ) - { - if( item->Type() == PCB_MODULE_EDGE_T ) - { - edgemod = (EDGE_MODULE*) item; - edgemod->SetStart0( edgemod->GetStart() ); - edgemod->SetEnd0( edgemod->GetEnd() ); - } - - else if( item->Type() == PCB_MODULE_TEXT_T ) - { - textmod = (TEXTE_MODULE*) item; - textmod->SetPos0( textmod->m_Pos ); - } - } - - module->m_Orient = 0; break; case ID_MODEDIT_MODULE_MIRROR: - for( ; pad; pad = pad->Next() ) - { - pad->SetY( -pad->GetPosition().y ); - - pt = pad->GetPos0(); - NEGATE( pt.y ); - pad->SetPos0( pt ); - - pt = pad->GetOffset(); - NEGATE( pt.y ); - pad->SetOffset( pt ); - - size = pad->GetDelta(); - NEGATE( size.y ); - pad->SetDelta( size ); - - if( pad->GetOrientation() ) - pad->SetOrientation( 3600 - pad->GetOrientation() ); - } - - // Reverse mirror of reference. + // Mirror reference. textmod = module->m_Reference; - NEGATE( textmod->m_Pos.y ); - NEGATE( textmod->m_Pos0.y ); + NEGATE( textmod->m_Pos.x ); + NEGATE( textmod->m_Pos0.x ); if( textmod->m_Orient ) textmod->m_Orient = 3600 - textmod->m_Orient; - // Reverse mirror of value. + // Mirror value. textmod = module->m_Value; - NEGATE( textmod->m_Pos.y ); - NEGATE( textmod->m_Pos0.y ); + NEGATE( textmod->m_Pos.x ); + NEGATE( textmod->m_Pos0.x ); if( textmod->m_Orient ) textmod->m_Orient = 3600 - textmod->m_Orient; - // Reverse mirror of footprints. - item = module->m_Drawings; - - for( ; item; item = item->Next() ) - { - switch( item->Type() ) - { - case PCB_MODULE_EDGE_T: - edgemod = (EDGE_MODULE*) item; - - edgemod->SetStartY( -edgemod->GetStart().y ); - edgemod->SetEndY( -edgemod->GetEnd().y ); - - // Invert local coordinates - NEGATE( edgemod->m_Start0.y ); - NEGATE( edgemod->m_End0.y ); - edgemod->SetAngle( -edgemod->GetAngle() ); - break; - - case PCB_MODULE_TEXT_T: - // Reverse mirror position and mirror. - textmod = (TEXTE_MODULE*) item; - NEGATE( textmod->m_Pos.y ); - NEGATE( textmod->m_Pos0.y ); - - if( textmod->m_Orient ) - textmod->m_Orient = 3600 - textmod->m_Orient; - - break; - - default: - DisplayError( this, wxT( "Draw type undefined" ) ); - break; - } - } - + // Mirror pads and graphic items of the footprint: + MirrorMarkedItems( module, wxPoint(0,0), true ); break; default: