From dfb88c64955a511119c70018fd2e27043ba341fe Mon Sep 17 00:00:00 2001 From: stambaughw Date: Wed, 8 Apr 2009 18:06:22 +0000 Subject: [PATCH] Library search path fixes, library configuration dialog fixes, and code cleaning. Added application method to fix searching for user libraries. Fixed documentation search path bug. Moved auto pan setting from draw frame to draw panel were it is defined. Some minor device context drawing changes. --- 3d-viewer/3d_read_mesh.cpp | 2 +- common/base_screen.cpp | 14 +++---- common/drawframe.cpp | 3 -- common/drawpanel.cpp | 18 +++++++-- common/edaappl.cpp | 20 +++++++++- common/gr_basic.cpp | 14 ++----- cvpcb/autosel.cpp | 2 +- cvpcb/listlib.cpp | 2 +- cvpcb/loadcmp.cpp | 2 +- cvpcb/menucfg.cpp | 13 +++---- eeschema/dialog_eeschema_config.cpp | 53 +++++++++++++-------------- eeschema/eelibs_read_libraryfiles.cpp | 2 +- include/appl_wxstruct.h | 5 +++ include/class_base_screen.h | 2 +- include/class_drawpanel.h | 5 ++- kicad/prjconfig.cpp | 2 +- pcbnew/dialog_setup_libs.cpp | 30 +++++++-------- pcbnew/loadcmp.cpp | 7 ++-- pcbnew/modedit.cpp | 9 ++--- 19 files changed, 109 insertions(+), 96 deletions(-) diff --git a/3d-viewer/3d_read_mesh.cpp b/3d-viewer/3d_read_mesh.cpp index 541ebb7ba3..00d92f98ca 100644 --- a/3d-viewer/3d_read_mesh.cpp +++ b/3d-viewer/3d_read_mesh.cpp @@ -38,7 +38,7 @@ int S3D_MASTER:: ReadData() if( !fn.FileExists() ) { - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullPath() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { diff --git a/common/base_screen.cpp b/common/base_screen.cpp index de2e872785..bca646f9c6 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -55,8 +55,7 @@ BASE_SCREEN::~BASE_SCREEN() /*******************************/ -void -BASE_SCREEN::InitDatas() +void BASE_SCREEN::InitDatas() /*******************************/ { if( m_Center ) @@ -89,15 +88,13 @@ BASE_SCREEN::InitDatas() * internal units used by the schematic screen is 1 mil (0.001"). Override * this in derived classes that require internal units other than 1 mil. */ -int -BASE_SCREEN::GetInternalUnits( void ) +int BASE_SCREEN::GetInternalUnits( void ) { return EESCHEMA_INTERNAL_UNIT; } /************************************/ -wxSize -BASE_SCREEN::ReturnPageSize( void ) +wxSize BASE_SCREEN::ReturnPageSize( void ) /************************************/ { int internal_units = GetInternalUnits(); @@ -113,8 +110,7 @@ BASE_SCREEN::ReturnPageSize( void ) * @param ScreenPos = the screen (in pixel) position co convert */ /******************************************************************/ -wxPoint -BASE_SCREEN::CursorRealPosition( const wxPoint& ScreenPos ) +wxPoint BASE_SCREEN::CursorRealPosition( const wxPoint& ScreenPos ) /******************************************************************/ { wxPoint curpos = ScreenPos; @@ -130,7 +126,7 @@ BASE_SCREEN::CursorRealPosition( const wxPoint& ScreenPos ) * @param the the current scale used to draw items on screen * draw coordinates are user coordinates * GetScalingFactor( ) */ -void BASE_SCREEN::SetScalingFactor(double aScale ) +void BASE_SCREEN::SetScalingFactor(double aScale ) { int zoom = static_cast( ceil(aScale * m_ZoomScalar) ); diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 19f1f3f994..50f6378fea 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -109,9 +109,6 @@ WinEDA_DrawFrame::WinEDA_DrawFrame( wxWindow* father, int idtype, WinEDA_DrawFrame::~WinEDA_DrawFrame() /****************************************/ { - if( DrawPanel ) // Required: in WinEDA3D_DrawFrame, DrawPanel == NULL ! - wxGetApp().m_EDA_Config->Write( wxT( "AutoPAN" ), - DrawPanel->m_AutoPAN_Enable ); } diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index 51f50d3519..8b7d63e7d4 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -73,7 +73,8 @@ WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, ForceCloseManageCurseur = NULL; if( wxGetApp().m_EDA_Config ) - m_AutoPAN_Enable = wxGetApp().m_EDA_Config->Read( wxT( "AutoPAN" ), true ); + m_AutoPAN_Enable = wxGetApp().m_EDA_Config->Read( wxT( "AutoPAN" ), + true ); m_AutoPAN_Request = FALSE; m_Block_Enable = FALSE; @@ -83,6 +84,14 @@ WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, } +WinEDA_DrawPanel::~WinEDA_DrawPanel() +{ + wxASSERT( wxGetApp().m_EDA_Config != NULL ); + + wxGetApp().m_EDA_Config->Write( wxT( "AutoPAN" ), m_AutoPAN_Enable ); +} + + BASE_SCREEN* WinEDA_DrawPanel::GetScreen() { WinEDA_DrawFrame* parentFrame = m_Parent; @@ -189,7 +198,11 @@ void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC ) DC->SetBackgroundMode( wxTRANSPARENT ); #ifdef WX_ZOOM double scale = GetScreen()->GetScalingFactor( ); + wxPoint origin = GetScreen()->m_DrawOrg; + wxLogDebug( wxT( "DC user scale factor: %0.3f, X origin: %d, Y " \ + "origin: %d" ), scale, origin.x, origin.y ); DC->SetUserScale( scale, scale ); + DC->SetLogicalOrigin( origin.x, origin.y ); DoPrepareDC( *DC ); #endif SetBoundaryBox(); @@ -582,13 +595,12 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) ); #endif - PaintClipBox.Offset( org ); - #ifdef WX_ZOOM BASE_SCREEN* screen = GetScreen(); screen->Unscale( m_ClipBox.m_Pos ); screen->Unscale( m_ClipBox.m_Size ); #else + PaintClipBox.Offset( org ); m_ClipBox.SetX( PaintClipBox.GetX() ); m_ClipBox.SetY( PaintClipBox.GetY() ); m_ClipBox.SetWidth( PaintClipBox.GetWidth() ); diff --git a/common/edaappl.cpp b/common/edaappl.cpp index 2b334f11e3..5d209e647c 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -541,14 +541,15 @@ void WinEDA_App::SetDefaultSearchPaths( void ) } /* Add schematic doc file path (library/doc)to search path list. */ + fn.RemoveLastDir(); fn.AppendDir( wxT( "doc") ); + if( fn.IsDirReadable() ) { wxLogDebug( wxT( "Adding <%s> to library search path list" ), fn.GetPath().c_str() ); m_libSearchPaths.Add( fn.GetPath() ); } - fn.RemoveLastDir(); /* Add kicad template file path to search path list. */ fn.RemoveLastDir(); @@ -1009,6 +1010,23 @@ wxString WinEDA_App::GetLibraryFile( const wxString& filename ) } +/** + * Kicad saves user defined library files that are not in the standard + * library search path list with the full file path. Calling the library + * search path list with a user library file will fail. This helper method + * solves that problem. + * + * Returns a wxEmptyString if library file is not found. + */ +wxString WinEDA_App::FindLibraryPath( const wxString& fileName ) +{ + if( wxFileName::FileExists( fileName ) ) + return fileName; + else + return GetLibraryPathList().FindValidPath( fileName ); +} + + /** * Run Python scripts * diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 10ec2c6263..c49317ffdf 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -401,17 +401,9 @@ void GRPutPixel( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int Color ) void GRSPutPixel( EDA_Rect* ClipBox, wxDC* DC, int x, int y, int Color ) /********************************************************************/ { - if( ClipBox ) /* suppression des pixels hors ecran */ - { - if( x < ClipBox->GetX() ) - return; - if( y < ClipBox->GetY() ) - return; - if( x > ( ClipBox->GetRight() ) ) - return; - if( y > ( ClipBox->GetBottom() ) ) - return; - } + if( ClipBox && !ClipBox->Inside( x, y ) ) + return; + GRSetColorPen( DC, Color ); DC->DrawPoint( x, y ); } diff --git a/cvpcb/autosel.cpp b/cvpcb/autosel.cpp index 17c9556bb1..2946da4105 100644 --- a/cvpcb/autosel.cpp +++ b/cvpcb/autosel.cpp @@ -71,7 +71,7 @@ static void auto_associe( WinEDA_CvpcbFrame* frame ) fn = g_ListName_Equ[ii]; fn.SetExt( EquivFileExtension ); - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { diff --git a/cvpcb/listlib.cpp b/cvpcb/listlib.cpp index 799559cb22..e777e1698d 100644 --- a/cvpcb/listlib.cpp +++ b/cvpcb/listlib.cpp @@ -72,7 +72,7 @@ bool listlib() fn = g_LibName_List[ii]; fn.SetExt( ModuleFileExtension ); - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { diff --git a/cvpcb/loadcmp.cpp b/cvpcb/loadcmp.cpp index b6a620399e..503f5d36fb 100644 --- a/cvpcb/loadcmp.cpp +++ b/cvpcb/loadcmp.cpp @@ -42,7 +42,7 @@ MODULE* WinEDA_DisplayFrame::Get_Module( const wxString& CmpName ) fn = g_LibName_List[ii]; fn.SetExt( ModuleFileExtension ); - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { diff --git a/cvpcb/menucfg.cpp b/cvpcb/menucfg.cpp index 247173222a..c673efbb86 100644 --- a/cvpcb/menucfg.cpp +++ b/cvpcb/menucfg.cpp @@ -197,11 +197,7 @@ void KiConfigCvpcbFrame::LibAddFct( wxCommandEvent& event ) wxArrayString Filenames; ii = m_ListLibr->GetSelection(); - if( event.GetId() == ADD_LIB ) /* Ajout apres selection */ - { - ii++; - } - if( ii < 0 ) + if( ii == wxNOT_FOUND && event.GetId() != ADD_LIB ) ii = 0; Update(); @@ -231,9 +227,12 @@ void KiConfigCvpcbFrame::LibAddFct( wxCommandEvent& event ) tmp = fn.GetName(); // Add or insert new library name. - if( g_LibName_List.Index( tmp ) == wxNOT_FOUND ) + if( g_LibName_List.Index( tmp, fn.IsCaseSensitive() ) == wxNOT_FOUND ) { - g_LibName_List.Insert( tmp, ii++ ); + if( event.GetId() == ADD_LIB ) + g_LibName_List.Add( tmp ); + else + g_LibName_List.Insert( tmp, ii++ ); } else { diff --git a/eeschema/dialog_eeschema_config.cpp b/eeschema/dialog_eeschema_config.cpp index 7cfa803d78..073cdfdb95 100644 --- a/eeschema/dialog_eeschema_config.cpp +++ b/eeschema/dialog_eeschema_config.cpp @@ -197,32 +197,23 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) * the selection */ { - int ii; - wxString FullLibName, ShortLibName, Mask; + int ii; + wxString tmp; + wxFileName fn; ii = m_ListLibr->GetSelection(); - if( ii < 0 ) + if( ii == wxNOT_FOUND && event.GetId() != ID_ADD_LIB ) ii = 0; - if( event.GetId() == ID_ADD_LIB ) - { - if( m_ListLibr->GetCount() != 0 ) - ii++; /* Add after selection */ - } - - wxString libpath = m_LibDirCtrl->GetValue(); if ( libpath.IsEmpty() ) libpath = g_RealLibDirBuffer; - Mask = wxT( "*" ) + CompLibFileExtension; - wxFileDialog FilesDialog( this, _( "Library files:" ), libpath, - wxEmptyString, Mask, + wxEmptyString, CompLibFileWildcard, wxFD_DEFAULT_STYLE | wxFD_MULTIPLE ); - int diag = FilesDialog.ShowModal(); - if( diag != wxID_OK ) + if( FilesDialog.ShowModal() != wxID_OK ) return; wxArrayString Filenames; @@ -230,29 +221,35 @@ void DIALOG_EESCHEMA_CONFIG::OnAddOrInsertLibClick( wxCommandEvent& event ) for( unsigned jj = 0; jj < Filenames.GetCount(); jj++ ) { - FullLibName = Filenames[jj]; - ShortLibName = MakeReducedFileName( FullLibName, libpath, CompLibFileExtension ); - if( ShortLibName.IsEmpty() ) //Just in case... - continue; + fn = Filenames[jj]; + + /* If the library path is already in the library search paths + * list, just add the library name to the list. Otherwise, add + * the library name with the full path. */ + if( wxGetApp().GetLibraryPathList().Index( fn.GetPath() ) == wxNOT_FOUND ) + tmp = fn.GetPathWithSep() + fn.GetName(); + else + tmp = fn.GetName(); //Add or insert new library name, if not already in list - #ifdef __WINDOWS__ - bool case_sensitive = false; - #else - bool case_sensitive = true; - #endif - if( m_ListLibr->FindString( ShortLibName, case_sensitive ) == wxNOT_FOUND ) + if( m_ListLibr->FindString( tmp, fn.IsCaseSensitive() ) == wxNOT_FOUND ) { m_LibListChanged = TRUE; - m_ListLibr->Insert( ShortLibName, ii ); + if( event.GetId() == ID_ADD_LIB ) + g_LibName_List.Add( tmp ); + else + g_LibName_List.Insert( tmp, ii++ ); } else { - wxString msg; - msg << wxT( "<" ) << ShortLibName << wxT( "> : " ) << _( "Library already in use" ); + wxString msg = wxT( "<" ) + tmp + wxT( "> : " ) + + _( "Library already in use" ); DisplayError( this, msg ); } } + + m_ListLibr->Clear(); + m_ListLibr->InsertItems( g_LibName_List, 0 ); } diff --git a/eeschema/eelibs_read_libraryfiles.cpp b/eeschema/eelibs_read_libraryfiles.cpp index 363a694684..170751fb3d 100644 --- a/eeschema/eelibs_read_libraryfiles.cpp +++ b/eeschema/eelibs_read_libraryfiles.cpp @@ -140,7 +140,7 @@ void LoadLibraries (WinEDA_DrawFrame* frame) if( !fn.FileExists() ) { - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { msg.Printf( _( "Library file <%s> not found." ), diff --git a/include/appl_wxstruct.h b/include/appl_wxstruct.h index a634eb0112..55bedd5534 100644 --- a/include/appl_wxstruct.h +++ b/include/appl_wxstruct.h @@ -132,6 +132,11 @@ public: void SetTitle( const wxString& title ) { m_Title = title; } wxPathList& GetLibraryPathList() { return m_libSearchPaths; } + wxString FindLibraryPath( const wxString& fileName ); + wxString FindLibraryPath( const wxFileName& fileName ) + { + return FindLibraryPath( fileName.GetFullPath() ); + } }; /* diff --git a/include/class_base_screen.h b/include/class_base_screen.h index a501194142..f5f8f713cf 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -212,7 +212,7 @@ public: */ double GetScalingFactor() { - return (double) m_ZoomScalar / GetZoom(); + return (double) m_ZoomScalar / (double) GetZoom(); } diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index 9037951289..ab80dc0158 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -55,8 +55,9 @@ public: public: // Constructor and destructor - WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, const wxPoint& pos, const wxSize& size ); - ~WinEDA_DrawPanel() { } + WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id, const wxPoint& pos, + const wxSize& size ); + ~WinEDA_DrawPanel(); /****************************/ BASE_SCREEN* GetScreen(); diff --git a/kicad/prjconfig.cpp b/kicad/prjconfig.cpp index 766f4382b7..88a7dfed8d 100644 --- a/kicad/prjconfig.cpp +++ b/kicad/prjconfig.cpp @@ -29,7 +29,7 @@ void WinEDA_MainFrame::CreateNewProject( const wxString PrjFullFileName ) wxFileName newProjectName = PrjFullFileName; // Init default config filename - tmp = wxGetApp().GetLibraryPathList().FindValidPath( wxT( "kicad.pro" ) ); + tmp = wxGetApp().FindLibraryPath( wxT( "kicad.pro" ) ); if( !wxFileName::FileExists( tmp ) ) { diff --git a/pcbnew/dialog_setup_libs.cpp b/pcbnew/dialog_setup_libs.cpp index 7faeb3c287..b4315100e1 100644 --- a/pcbnew/dialog_setup_libs.cpp +++ b/pcbnew/dialog_setup_libs.cpp @@ -461,33 +461,26 @@ void KiConfigPcbnewFrame::LibDelFct( wxCommandEvent& event ) } -/*************************************************************/ +/************************************************************* + * Insert or add a library to the existing library list: + * New library is put in list before (insert) or after (add) + * the selection. + * + *************************************************************/ void KiConfigPcbnewFrame::LibInsertFct( wxCommandEvent& event ) -/*************************************************************/ - -/* Insert or add a library to the existing library list: - * New library is put in list before (insert) or after (add) - * the selection - */ { int ii; wxFileName fn; wxString tmp; ii = m_ListLibr->GetSelection(); - if( ii < 0 ) + if( ii == wxNOT_FOUND && event.GetId() == INSERT_LIB ) ii = 0; - if( event.GetId() == ADD_LIB ) - { - if( g_LibName_List.GetCount() != 0 ) - ii++; /* Add after selection */ - } SetNewOptions(); - g_RealLibDirBuffer.Replace( wxT( "\\" ), wxT( "/" ) ); wxFileDialog FilesDialog( this, _( "Foot Print Library Files" ), - g_RealLibDirBuffer, wxEmptyString, + wxEmptyString, wxEmptyString, ModuleFileWildcard, wxFD_OPEN | wxFD_MULTIPLE ); if( FilesDialog.ShowModal() != wxID_OK ) @@ -509,10 +502,13 @@ void KiConfigPcbnewFrame::LibInsertFct( wxCommandEvent& event ) tmp = fn.GetName(); // Add or insert new library name. - if( g_LibName_List.Index( tmp ) == wxNOT_FOUND ) + if( g_LibName_List.Index( tmp, fn.IsCaseSensitive() ) == wxNOT_FOUND ) { m_LibModified = TRUE; - g_LibName_List.Insert( tmp, ii++ ); + if( event.GetId() == ADD_LIB ) + g_LibName_List.Add( tmp ); + else + g_LibName_List.Insert( tmp, ii++ ); m_ListLibr->Clear(); m_ListLibr->InsertItems( g_LibName_List, 0 ); } diff --git a/pcbnew/loadcmp.cpp b/pcbnew/loadcmp.cpp index e58faaaf66..a64610ba71 100644 --- a/pcbnew/loadcmp.cpp +++ b/pcbnew/loadcmp.cpp @@ -199,9 +199,10 @@ MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( const wxString& aLibraryFullF if ( one_lib ) fn = aLibraryFullFilename; else - fn = wxFileName( wxEmptyString, g_LibName_List[ii], ModuleFileExtension ); + fn = wxFileName( wxEmptyString, g_LibName_List[ii], + ModuleFileExtension ); - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { @@ -352,7 +353,7 @@ wxString WinEDA_BasePcbFrame::Select_1_Module_From_List( else fn = aLibraryFullFilename; - tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + tmp = wxGetApp().FindLibraryPath( fn ); if( !tmp ) { diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 087cede4ad..ff21f2cca9 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -204,8 +204,7 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) { wxFileName fn = wxFileName( wxEmptyString, m_CurrentLib, ModuleFileExtension ); - wxString full_libraryfilename = - wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + wxString full_libraryfilename = wxGetApp().FindLibraryPath( fn ); if( wxFileName::FileExists( full_libraryfilename ) ) Delete_Module_In_Library( full_libraryfilename ); break; @@ -233,7 +232,7 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) { wxFileName fn; fn = wxFileName( wxEmptyString, m_CurrentLib, ModuleFileExtension ); - wxString full_filename = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + wxString full_filename = wxGetApp().FindLibraryPath( fn ); Save_Module_In_Library( full_filename, GetBoard()->m_Modules, true, true, true ); GetScreen()->ClrModify(); @@ -352,9 +351,9 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) { wxFileName fn = wxFileName( wxEmptyString, m_CurrentLib, ModuleFileExtension ); - full_libraryfilename = - wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullName() ); + full_libraryfilename = wxGetApp().FindLibraryPath( fn ); } + GetScreen()->ClearUndoRedoList(); SetCurItem( NULL ); Clear_Pcb( true );