From d96039a1fb1252476bd5c793c0ff6393b05156dc Mon Sep 17 00:00:00 2001 From: stambaughw Date: Thu, 9 Apr 2009 18:39:39 +0000 Subject: [PATCH] Change search path order, wxDC zoom updates, and code clean ups. Add helpers for inserting paths to and removing paths from search list. Moved user defined path before default library paths in search list. Renamed m_Draw_Auxiliary_Axis to DrawAuxiliaryAxis. Changed parameter to fix wxDC set mode from FALSE to GR_COPY. Minor wxDC zoom improvements. --- common/drawframe.cpp | 2 ++ common/drawpanel.cpp | 45 ++++++++++++++++++++++----------------- common/edaappl.cpp | 33 +++++++++++++++++++++++++++- common/projet_config.cpp | 6 ++---- cvpcb/cfg.cpp | 16 +++----------- eeschema/eeconfig.cpp | 16 +++----------- eeschema/files-io.cpp | 4 ++-- include/appl_wxstruct.h | 2 ++ include/class_drawpanel.h | 2 +- pcbnew/onleftclick.cpp | 4 ++-- pcbnew/pcbcfg.cpp | 19 ++++------------- 11 files changed, 78 insertions(+), 71 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 02d2248ff0..24705f4914 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -573,6 +573,7 @@ int WinEDA_DrawFrame::HandleBlockEnd( wxDC* DC ) void WinEDA_DrawFrame::AdjustScrollBars() /*********************************************/ { +#ifndef WX_ZOOM int xUnit, yUnit; wxSize draw_size, panel_size; wxSize scrollbar_number; @@ -652,6 +653,7 @@ void WinEDA_DrawFrame::AdjustScrollBars() screen->m_ScrollbarNumber.y, screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y, TRUE ); +#endif } diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index 8b7d63e7d4..d2ef380421 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -197,13 +197,18 @@ void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC ) GRResetPenAndBrush( DC ); DC->SetBackgroundMode( wxTRANSPARENT ); #ifdef WX_ZOOM - double scale = GetScreen()->GetScalingFactor( ); + 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 ); + DoPrepareDC( *DC ); DC->SetUserScale( scale, scale ); DC->SetLogicalOrigin( origin.x, origin.y ); - DoPrepareDC( *DC ); + + int x, y; + wxPoint logicalPos = GetScreen()->m_Curseur - origin;; + CalcScrolledPosition( logicalPos.x, logicalPos.y, &x, &y ); + Scroll( x, y ); #endif SetBoundaryBox(); } @@ -596,9 +601,10 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) #endif #ifdef WX_ZOOM - BASE_SCREEN* screen = GetScreen(); - screen->Unscale( m_ClipBox.m_Pos ); - screen->Unscale( m_ClipBox.m_Size ); + m_ClipBox.m_Pos.x = paintDC.DeviceToLogicalX( m_ClipBox.m_Pos.x ); + m_ClipBox.m_Pos.y = paintDC.DeviceToLogicalY( m_ClipBox.m_Pos.y ); + m_ClipBox.m_Size.SetWidth( paintDC.DeviceToLogicalXRel( m_ClipBox.m_Size.GetWidth() ) ); + m_ClipBox.m_Size.SetHeight( paintDC.DeviceToLogicalXRel( m_ClipBox.m_Size.GetHeight() ) ); #else PaintClipBox.Offset( org ); m_ClipBox.SetX( PaintClipBox.GetX() ); @@ -627,7 +633,7 @@ void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event ) { wxDCClipper dcclip( paintDC, PaintClipBox ); - ReDraw( &paintDC, TRUE ); + ReDraw( &paintDC, true ); } m_ClipBox = tmp; @@ -658,11 +664,6 @@ void WinEDA_DrawPanel::ReDraw( wxDC* DC, bool erasebg ) g_GhostColor = WHITE; } -#ifdef WX_ZOOM - double scale = Screen->GetScalingFactor( ); - DC->SetUserScale( scale, scale ); -#endif - if( erasebg ) PrepareGraphicContext( DC ); @@ -742,6 +743,13 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC ) size = GetClientSize(); screen->Unscale( size ); +#ifdef WX_ZOOM + org.x = DC->DeviceToLogicalX( org.x ); + org.y = DC->DeviceToLogicalY( org.y ); + size.SetWidth( DC->DeviceToLogicalXRel( size.GetWidth() ) ); + size.SetHeight( DC->DeviceToLogicalXRel( size.GetHeight() ) ); +#endif + if( drawgrid ) { m_Parent->PutOnGrid( &org ); @@ -767,7 +775,7 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC ) } /* Draw axis */ - if( m_Parent->m_Draw_Axis ) + if( m_Parent->m_Draw_Axis ) { /* Draw the Y axis */ GRDashedLine( &m_ClipBox, DC, 0, -screen->ReturnPageSize().y, @@ -778,16 +786,12 @@ void WinEDA_DrawPanel::DrawBackGround( wxDC* DC ) screen->ReturnPageSize().x, 0, 0, Color ); } - /* Draw auxiliary axis */ - if( m_Parent->m_Draw_Auxiliary_Axis ) - { - m_Draw_Auxiliary_Axis( DC, FALSE ); - } + DrawAuxiliaryAxis( DC, GR_COPY ); } /********************************************************************/ -void WinEDA_DrawPanel::m_Draw_Auxiliary_Axis( wxDC* DC, int drawmode ) +void WinEDA_DrawPanel::DrawAuxiliaryAxis( wxDC* DC, int drawmode ) /********************************************************************/ /** m_Draw_Auxiliary_Axis @@ -795,8 +799,9 @@ void WinEDA_DrawPanel::m_Draw_Auxiliary_Axis( wxDC* DC, int drawmode ) * for gerber and excellon files */ { - if( m_Parent->m_Auxiliary_Axis_Position.x == 0 - && m_Parent->m_Auxiliary_Axis_Position.y == 0 ) + if( !m_Parent->m_Draw_Auxiliary_Axis + || ( m_Parent->m_Auxiliary_Axis_Position.x == 0 + && m_Parent->m_Auxiliary_Axis_Position.y == 0 ) ) return; int Color = DARKRED; diff --git a/common/edaappl.cpp b/common/edaappl.cpp index 5d209e647c..a557338fc8 100644 --- a/common/edaappl.cpp +++ b/common/edaappl.cpp @@ -1023,7 +1023,38 @@ wxString WinEDA_App::FindLibraryPath( const wxString& fileName ) if( wxFileName::FileExists( fileName ) ) return fileName; else - return GetLibraryPathList().FindValidPath( fileName ); + return m_libSearchPaths.FindValidPath( fileName ); +} + +void WinEDA_App::RemoveLibraryPath( const wxString& path ) +{ + if( m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) != wxNOT_FOUND ) + { + wxLogDebug( wxT( "Removing path <%s> from library path search list." ), + path.c_str() ); + m_libSearchPaths.Remove( path ); + } +} + +void WinEDA_App::InsertLibraryPath( const wxString& path, size_t index ) +{ + if( wxFileName::DirExists( path ) + && m_libSearchPaths.Index( path, wxFileName::IsCaseSensitive() ) == wxNOT_FOUND ) + { + if( index >= m_libSearchPaths.GetCount() ) + { + wxLogDebug( wxT( "Adding path <%s> to library path search list." ), + path.c_str() ); + m_libSearchPaths.Add( path ); + } + else + { + wxLogDebug( wxT( "Inserting path <%s> in library path search " \ + "list at index position %d." ), + path.c_str(), index ); + m_libSearchPaths.Insert( path, index ); + } + } } diff --git a/common/projet_config.cpp b/common/projet_config.cpp index ebb6920c25..a5c5d5a9e4 100644 --- a/common/projet_config.cpp +++ b/common/projet_config.cpp @@ -60,10 +60,8 @@ bool WinEDA_App::ReCreatePrjConfig( const wxString& fileName, /* Update the library search path list if a new project file is loaded. */ if( m_projectFileName != fn ) { - if( m_libSearchPaths.Index( fn.GetPath() ) != wxNOT_FOUND ) - m_libSearchPaths.Remove( fn.GetPath() ); - - m_libSearchPaths.Insert( fn.GetPath(), 0 ); + RemoveLibraryPath( m_projectFileName.GetPath() ); + InsertLibraryPath( fn.GetPath(), 0 ); m_projectFileName = fn; } diff --git a/cvpcb/cfg.cpp b/cvpcb/cfg.cpp index d7c4107628..73adfb62d7 100644 --- a/cvpcb/cfg.cpp +++ b/cvpcb/cfg.cpp @@ -39,12 +39,7 @@ void Read_Config( const wxString& FileName ) if( fn.GetExt() != ProjectFileExtension ) fn.SetExt( ProjectFileExtension ); - if( wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) != wxNOT_FOUND ) - { - wxLogDebug( wxT( "Removing path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Remove( g_UserLibDirBuffer ); - } + wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer ); wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, ParamCfgList, FALSE ); @@ -52,13 +47,8 @@ void Read_Config( const wxString& FileName ) if( g_NetlistFileExtension.IsEmpty() ) g_NetlistFileExtension = wxT( "net" ); - if( wxFileName::DirExists( g_UserLibDirBuffer ) - && wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) == wxNOT_FOUND ) - { - wxLogDebug( wxT( "Adding path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Add( g_UserLibDirBuffer ); - } + /* User library path takes precedent over default library search paths. */ + wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 ); } diff --git a/eeschema/eeconfig.cpp b/eeschema/eeconfig.cpp index db9d5ce12e..3e9649e95a 100644 --- a/eeschema/eeconfig.cpp +++ b/eeschema/eeconfig.cpp @@ -159,12 +159,7 @@ bool Read_Config( const wxString& CfgFileName, bool ForceRereadConfig ) * extension (.pro). */ fn.SetExt( ProjectFileExtension ); - if( wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) != wxNOT_FOUND ) - { - wxLogDebug( wxT( "Removing path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Remove( g_UserLibDirBuffer ); - } + wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer ); if( !wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, ParamCfgList, ForceRereadConfig ? FALSE : TRUE ) ) @@ -173,13 +168,8 @@ bool Read_Config( const wxString& CfgFileName, bool ForceRereadConfig ) IsRead = FALSE; } - if( wxFileName::DirExists( g_UserLibDirBuffer ) - && wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) == wxNOT_FOUND ) - { - wxLogDebug( wxT( "Adding path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Add( g_UserLibDirBuffer ); - } + /* User library path takes precedent over default library search paths. */ + wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 ); // If the list is void, load the libraries "power.lib" and "device.lib" if( g_LibName_List.GetCount() == 0 ) diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 8b147b5aaf..fc6c6b0bc5 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -153,11 +153,11 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, // Loading the project library cache wxFileName fn = g_RootSheet->m_AssociatedScreen->m_FileName; fn.SetExt( wxT( "cache.lib" ) ); - wxLogDebug( wxT( "Load schematic cache library file <%s>" ), - fn.GetFullPath().c_str() ); if( fn.FileExists() ) { + wxLogDebug( wxT( "Load schematic cache library file <%s>" ), + fn.GetFullPath().c_str() ); msg = wxT( "Load " ) + fn.GetFullPath(); LibraryStruct* LibCache = LoadLibraryName( this, fn.GetFullPath(), fn.GetName() ); diff --git a/include/appl_wxstruct.h b/include/appl_wxstruct.h index 55bedd5534..e7f66eef8f 100644 --- a/include/appl_wxstruct.h +++ b/include/appl_wxstruct.h @@ -137,6 +137,8 @@ public: { return FindLibraryPath( fileName.GetFullPath() ); } + void RemoveLibraryPath( const wxString& path ); + void InsertLibraryPath( const wxString& path, size_t index ); }; /* diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index ab80dc0158..d2e5ecdbdc 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -71,7 +71,7 @@ public: void ReDraw( wxDC* DC, bool erasebg = TRUE ); void PrintPage( wxDC* DC, bool Print_Sheet_Ref, int PrintMask, bool aPrintMirrorMode ); void DrawBackGround( wxDC* DC ); - void m_Draw_Auxiliary_Axis( wxDC* DC, int drawmode ); + void DrawAuxiliaryAxis( wxDC* DC, int drawmode ); void OnEraseBackground( wxEraseEvent& event ); void OnActivate( wxActivateEvent& event ); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 3f16d56d5d..4d58fb784c 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -317,9 +317,9 @@ void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) break; case ID_PCB_PLACE_OFFSET_COORD_BUTT: - DrawPanel->m_Draw_Auxiliary_Axis( DC, GR_XOR ); + DrawPanel->DrawAuxiliaryAxis( DC, GR_XOR ); m_Auxiliary_Axis_Position = GetScreen()->m_Curseur; - DrawPanel->m_Draw_Auxiliary_Axis( DC, GR_COPY ); + DrawPanel->DrawAuxiliaryAxis( DC, GR_COPY ); GetScreen()->SetModify(); break; diff --git a/pcbnew/pcbcfg.cpp b/pcbnew/pcbcfg.cpp index e5959d558f..a4ea1ac135 100644 --- a/pcbnew/pcbcfg.cpp +++ b/pcbnew/pcbcfg.cpp @@ -171,12 +171,7 @@ bool Read_Config( const wxString& projectFileName ) fn.SetExt( ProjectFileExtension ); } - if( wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) != wxNOT_FOUND ) - { - wxLogDebug( wxT( "Removing path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Remove( g_UserLibDirBuffer ); - } + wxGetApp().RemoveLibraryPath( g_UserLibDirBuffer ); /* Init des valeurs par defaut */ g_LibName_List.Clear(); @@ -184,16 +179,10 @@ bool Read_Config( const wxString& projectFileName ) wxGetApp().ReadProjectConfig( fn.GetFullPath(), GROUP, ParamCfgList, FALSE ); + /* User library path takes precedent over default library search paths. */ + wxGetApp().InsertLibraryPath( g_UserLibDirBuffer, 1 ); + /* Traitement des variables particulieres: */ - - if( wxFileName::DirExists( g_UserLibDirBuffer ) - && wxGetApp().GetLibraryPathList().Index( g_UserLibDirBuffer ) == wxNOT_FOUND ) - { - wxLogDebug( wxT( "Adding path <%s> to library path search list." ), - g_UserLibDirBuffer.c_str() ); - wxGetApp().GetLibraryPathList().Add( g_UserLibDirBuffer ); - } - g_DesignSettings.m_TrackWidthHistory[0] = g_DesignSettings.m_CurrentTrackWidth; g_DesignSettings.m_ViaSizeHistory[0] = g_DesignSettings.m_CurrentViaSize;