New format top level schematic files were not detected if they had a significant number of libraries.

The "Sheet 1" string can now be further down in the file than the original 20 line search could detect.
This commit is contained in:
dickelbeck 2009-10-26 21:25:23 +00:00
parent 29f5fbb7ad
commit 9689f496ee
1 changed files with 22 additions and 13 deletions

View File

@ -15,6 +15,7 @@
#include "gestfich.h" #include "gestfich.h"
#include "appl_wxstruct.h" #include "appl_wxstruct.h"
#include "bitmaps.h" #include "bitmaps.h"
#include "macros.h"
#include "kicad.h" #include "kicad.h"
@ -156,14 +157,14 @@ WinEDA_PrjFrame::WinEDA_PrjFrame( WinEDA_MainFrame* parent,
// ID_PROJECT_NEWPY // ID_PROJECT_NEWPY
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
item = new wxMenuItem( menu, item = new wxMenuItem( menu,
ID_PROJECT_NEWPY, ID_PROJECT_NEWPY,
_( "New P&ython Script" ), _( "New P&ython Script" ),
_( "Create a New Python Script" ) ); _( "Create a New Python Script" ) );
item->SetBitmap( new_python_xpm ); item->SetBitmap( new_python_xpm );
menu->Append( item ); menu->Append( item );
#endif /* KICAD_PYTHON */ #endif /* KICAD_PYTHON */
// ID_PROJECT_NEWTXT // ID_PROJECT_NEWTXT
@ -306,10 +307,13 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
wxTreeItemId moved = m_TreeProject->GetSelection(); wxTreeItemId moved = m_TreeProject->GetSelection();
TreePrjItemData* source_data = GetSelectedData(); TreePrjItemData* source_data = GetSelectedData();
wxTreeItemId dest = event.GetItem(); wxTreeItemId dest = event.GetItem();
if( !dest.IsOk() ) if( !dest.IsOk() )
return; // Cancelled ... return; // Cancelled ...
TreePrjItemData* destData = TreePrjItemData* destData =
dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) ); dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) );
if( !destData ) if( !destData )
return; return;
@ -325,6 +329,7 @@ void WinEDA_PrjFrame::OnDragEnd( wxTreeEvent& event )
// Select the right destData: // Select the right destData:
destData = destData =
dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) ); dynamic_cast<TreePrjItemData*>( m_TreeProject->GetItemData( dest ) );
if( !destData ) if( !destData )
return; return;
} }
@ -588,19 +593,19 @@ void WinEDA_PrjFrame::NewFile( const wxString& name,
{ {
wxFile( name, wxFile::write ); wxFile( name, wxFile::write );
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewFile" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewFile" ),
PyHandler::Convert( name ) ); PyHandler::Convert( name ) );
#endif /* KICAD_PYTHON */ #endif /* KICAD_PYTHON */
} }
else else
{ {
wxMkdir( name ); wxMkdir( name );
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewDirectory" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::NewDirectory" ),
PyHandler::Convert( name ) ); PyHandler::Convert( name ) );
#endif /* KICAD_PYTHON */ #endif /* KICAD_PYTHON */
} }
AddFile( name, root ); AddFile( name, root );
@ -737,6 +742,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
addFile = true; addFile = true;
if( i==0 ) if( i==0 )
isSchematic = true; isSchematic = true;
break;
} }
} }
@ -762,7 +768,9 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
} }
addFile = false; addFile = false;
for( int i = 0; i<20; ++i )
// check the first 100 lines for the "Sheet 1" string
for( int i = 0; i<100; ++i )
{ {
if( !fgets( line, sizeof(line), fp ) ) if( !fgets( line, sizeof(line), fp ) )
break; break;
@ -833,15 +841,15 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
data->m_IsRootFile = false; data->m_IsRootFile = false;
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::TreeAddFile" ),
PyHandler::Convert( name ) ); PyHandler::Convert( name ) );
#endif /* KICAD_YTHON */ #endif /* KICAD_YTHON */
// When enabled This section adds dirs and files found in the subdirs // When enabled This section adds dirs and files found in the subdirs
// in this case AddFile is recursive. // in this case AddFile is recursive.
#ifdef ADD_FILES_IN_SUBDIRS #ifdef ADD_FILES_IN_SUBDIRS
if( TREE_DIRECTORY == type ) if( TREE_DIRECTORY == type )
{ {
const wxString sep = wxFileName().GetPathSeparator(); const wxString sep = wxFileName().GetPathSeparator();
@ -859,7 +867,7 @@ bool WinEDA_PrjFrame::AddFile( const wxString& name, wxTreeItemId& root )
/* Sort filenames by alphabetic order */ /* Sort filenames by alphabetic order */
m_TreeProject->SortChildren( cellule ); m_TreeProject->SortChildren( cellule );
} }
#endif /* ADD_FILES_IN_SUBDIRS */ #endif /* ADD_FILES_IN_SUBDIRS */
return true; return true;
@ -932,6 +940,7 @@ void WinEDA_PrjFrame::ReCreateTreePrj()
if( filename != fn.GetFullName() ) if( filename != fn.GetFullName() )
AddFile( dir.GetName() + wxFileName::GetPathSeparator() + AddFile( dir.GetName() + wxFileName::GetPathSeparator() +
filename, m_root ); filename, m_root );
cont = dir.GetNext( &filename ); cont = dir.GetNext( &filename );
} }
} }
@ -1036,10 +1045,10 @@ void WinEDA_PrjFrame::OnTxtEdit( wxCommandEvent& event )
if( !editorname.IsEmpty() ) if( !editorname.IsEmpty() )
{ {
#ifdef KICAD_PYTHON #ifdef KICAD_PYTHON
PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ), PyHandler::GetInstance()->TriggerEvent( wxT( "kicad::EditScript" ),
PyHandler::Convert( FullFileName ) ); PyHandler::Convert( FullFileName ) );
#endif #endif
ExecuteFile( this, editorname, FullFileName ); ExecuteFile( this, editorname, FullFileName );
} }