Commit dfb88c64 authored by stambaughw's avatar stambaughw

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.
parent cf752a58
......@@ -38,7 +38,7 @@ int S3D_MASTER:: ReadData()
if( !fn.FileExists() )
{
tmp = wxGetApp().GetLibraryPathList().FindValidPath( fn.GetFullPath() );
tmp = wxGetApp().FindLibraryPath( fn );
if( !tmp )
{
......
......@@ -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<int>( ceil(aScale * m_ZoomScalar) );
......
......@@ -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 );
}
......
......@@ -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() );
......
......@@ -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
*
......
......@@ -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 );
}
......
......@@ -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 )
{
......
......@@ -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 )
{
......
......@@ -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 )
{
......
......@@ -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
{
......
......@@ -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 );
}
......
......@@ -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." ),
......
......@@ -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() );
}
};
/*
......
......@@ -212,7 +212,7 @@ public:
*/
double GetScalingFactor()
{
return (double) m_ZoomScalar / GetZoom();
return (double) m_ZoomScalar / (double) GetZoom();
}
......
......@@ -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();
......
......@@ -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 ) )
{
......
......@@ -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 );
}
......
......@@ -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 )
{
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment