switch back to original sexpr usage of PTREE, add new DSNLEXER constructor, enforce accessors in kicad.exe

This commit is contained in:
Dick Hollenbeck 2014-07-07 14:49:14 -05:00
parent 0304598a71
commit acbe6290c5
17 changed files with 315 additions and 343 deletions

View File

@ -36,6 +36,8 @@
//#define STANDALONE 1 // enable this for stand alone testing. //#define STANDALONE 1 // enable this for stand alone testing.
#define FMT_CLIPBOARD _( "clipboard" )
//-----<DSNLEXER>------------------------------------------------------------- //-----<DSNLEXER>-------------------------------------------------------------
@ -89,7 +91,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
keywordCount( aKeywordCount ) keywordCount( aKeywordCount )
{ {
STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ? STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
wxString( _( "clipboard" ) ) : aSource ); wxString( FMT_CLIPBOARD ) : aSource );
PushReader( stringReader ); PushReader( stringReader );
init(); init();
} }
@ -107,6 +109,20 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
} }
static const KEYWORD empty_keywords[1] = {};
DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
iOwnReaders( true ),
keywords( empty_keywords ),
keywordCount( 0 )
{
STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
wxString( FMT_CLIPBOARD ) : aSource );
PushReader( stringReader );
init();
}
DSNLEXER::~DSNLEXER() DSNLEXER::~DSNLEXER()
{ {
if( iOwnReaders ) if( iOwnReaders )

View File

@ -83,11 +83,7 @@ inline void scanAtom( PTREE* aTree, DSNLEXER* aLexer )
//D(printf( "%s: '%s'\n", __func__, key );) //D(printf( "%s: '%s'\n", __func__, key );)
#if 0
aTree->push_back( PTREE::value_type( key, PTREE() ) ); aTree->push_back( PTREE::value_type( key, PTREE() ) );
#else
aTree->put_value( key );
#endif
} }
@ -194,7 +190,7 @@ static void formatNode( OUTPUTFORMATTER* out, int aNestLevel, int aCtl,
out->Print( aNestLevel, "(%s%s", out->Quotes( aKey ).c_str(), ctl & CTL_OMIT_NL ? "" : "\n" ); out->Print( aNestLevel, "(%s%s", out->Quotes( aKey ).c_str(), ctl & CTL_OMIT_NL ? "" : "\n" );
if( aTree.data().size() ) if( aTree.data().size() ) // sexpr format does not use data()
{ {
out->Print( 0, " %s%s", out->Print( 0, " %s%s",
out->Quotes( aTree.data() ).c_str(), out->Quotes( aTree.data() ).c_str(),

View File

@ -56,55 +56,61 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
sheets.GetComponents( refs, false ); sheets.GetComponents( refs, false );
static const KEYWORD empty_keywords[1] = {}; DSNLEXER lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) );
DSNLEXER lexer( empty_keywords, 0, aChangedSetOfReferences, FROM_UTF8( __func__ ) );
PTREE doc; PTREE doc;
Scan( &doc, &lexer ); try
{
Scan( &doc, &lexer );
#if defined(DEBUG) && 0 #if defined(DEBUG) && 0
STRING_FORMATTER sf; STRING_FORMATTER sf;
Format( &sf, 0, 0, doc ); Format( &sf, 0, 0, doc );
printf( "%s: '%s'\n", __func__, sf.GetString().c_str() ); printf( "%s: '%s'\n", __func__, sf.GetString().c_str() );
#endif #endif
CPTREE& back_anno = doc.get_child( "back_annotation" ); CPTREE& back_anno = doc.get_child( "back_annotation" );
for( PTREE::const_iterator ref = back_anno.begin(); ref != back_anno.end(); ++ref ) for( PTREE::const_iterator ref = back_anno.begin(); ref != back_anno.end(); ++ref )
{
wxASSERT( ref->first == "ref" );
wxString reference = (UTF8&) ref->second.data();
wxString footprint = (UTF8) ref->second.get<std::string>( "fpid" );
// DBG( printf( "%s: ref:%s fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )
// Search the component in the flat list
for( unsigned ii = 0; ii < refs.GetCount(); ++ii )
{ {
if( Cmp_KEEPCASE( reference, refs[ii].GetRef() ) == 0 ) wxASSERT( ref->first == "ref" );
wxString reference = (UTF8&) ref->second.front().first;
wxString footprint = (UTF8&) ref->second.get_child( "fpid" ).front().first;
DBG( printf( "%s: ref:%s fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); )
// Search the component in the flat list
for( unsigned ii = 0; ii < refs.GetCount(); ++ii )
{ {
// We have found a candidate. if( Cmp_KEEPCASE( reference, refs[ii].GetRef() ) == 0 )
// Note: it can be not unique (multiple parts per package)
// So we *do not* stop the search here
SCH_COMPONENT* component = refs[ii].GetComponent();
SCH_FIELD* fpfield = component->GetField( FOOTPRINT );
const wxString& oldfp = fpfield->GetText();
if( !oldfp && fpfield->IsVisible() )
{ {
fpfield->SetVisible( false ); // We have found a candidate.
// Note: it can be not unique (multiple parts per package)
// So we *do not* stop the search here
SCH_COMPONENT* component = refs[ii].GetComponent();
SCH_FIELD* fpfield = component->GetField( FOOTPRINT );
const wxString& oldfp = fpfield->GetText();
if( !oldfp && fpfield->IsVisible() )
{
fpfield->SetVisible( false );
}
// DBG( printf("%s: ref:%s fpid:%s\n", __func__, TO_UTF8( refs[ii].GetRef() ), TO_UTF8( footprint ) );)
if( oldfp != footprint )
isChanged = true;
fpfield->SetText( footprint );
} }
// DBG( printf("%s: ref:%s fpid:%s\n", __func__, TO_UTF8( refs[ii].GetRef() ), TO_UTF8( footprint ) );)
if( oldfp != footprint )
isChanged = true;
fpfield->SetText( footprint );
} }
} }
} }
catch( const PTREE_ERROR& ex )
{
// remap the exception to something the caller is likely to understand.
THROW_IO_ERROR( ex.what() );
}
if( isChanged ) if( isChanged )
OnModify(); OnModify();

View File

@ -174,7 +174,7 @@ public:
FILE* aFile, const wxString& aFileName ); FILE* aFile, const wxString& aFileName );
/** /**
* Constructor ( std::string&*, const wxString& ) * Constructor ( const KEYWORD*, unsigned, const std::string&, const wxString& )
* intializes a DSN lexer and prepares to read from @a aSExpression. * intializes a DSN lexer and prepares to read from @a aSExpression.
* *
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This * @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
@ -186,6 +186,16 @@ public:
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount, DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
const std::string& aSExpression, const wxString& aSource = wxEmptyString ); const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/**
* Constructor ( const std::string&, const wxString& )
* intializes a DSN lexer and prepares to read from @a aSExpression. Use this
* one without a keyword table with the DOM parser in ptree.h.
*
* @param aSExpression is text to feed through a STRING_LINE_READER
* @param aSource is a description of aSExpression, used for error reporting.
*/
DSNLEXER( const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/** /**
* Constructor ( LINE_READER* ) * Constructor ( LINE_READER* )
* intializes a DSN lexer and prepares to read from @a aLineReader which * intializes a DSN lexer and prepares to read from @a aLineReader which

View File

@ -52,9 +52,9 @@ makes it easy to extract a subset of a ptree.
#include <richio.h> #include <richio.h>
#include <dsnlexer.h> #include <dsnlexer.h>
typedef boost::property_tree::ptree PTREE; typedef boost::property_tree::ptree PTREE;
typedef const PTREE CPTREE; typedef const PTREE CPTREE;
typedef boost::property_tree::ptree_error PTREE_ERROR;
/** /**
* Function Scan * Function Scan

View File

@ -51,12 +51,11 @@ TREEPROJECT_ITEM::TREEPROJECT_ITEM( enum TreeFileType type, const wxString& data
m_Type = type; m_Type = type;
m_parent = parent; m_parent = parent;
m_FileName = data; m_FileName = data;
m_IsRootFile = false; // true only for the root item of the tree (the project name) m_IsRootFile = false; // true only for the root item of the tree (the project name)
m_WasPopulated = false; m_IsPopulated = false;
} }
// Set the state used in the icon list
void TREEPROJECT_ITEM::SetState( int state ) void TREEPROJECT_ITEM::SetState( int state )
{ {
wxImageList* imglist = m_parent->GetImageList(); wxImageList* imglist = m_parent->GetImageList();
@ -71,8 +70,7 @@ void TREEPROJECT_ITEM::SetState( int state )
} }
/* Get the directory containing the file */ const wxString TREEPROJECT_ITEM::GetDir() const
wxString TREEPROJECT_ITEM::GetDir() const
{ {
if( TREE_DIRECTORY == m_Type ) if( TREE_DIRECTORY == m_Type )
return m_FileName; return m_FileName;
@ -84,7 +82,6 @@ wxString TREEPROJECT_ITEM::GetDir() const
} }
/* rename the file checking if extension change occurs */
bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check ) bool TREEPROJECT_ITEM::Rename( const wxString& name, bool check )
{ {
// this is broken & unsafe to use on linux. // this is broken & unsafe to use on linux.
@ -145,14 +142,13 @@ type.\n Do you want to continue ?"
} }
/*******************************************/
bool TREEPROJECT_ITEM::Delete( bool check ) bool TREEPROJECT_ITEM::Delete( bool check )
/*******************************************/
/* delete a file */
{ {
wxString msg; wxString msg = wxString::Format( _(
"Do you really want to delete '%s'" ),
GetChars( GetFileName() )
);
msg.Printf( _( "Do you really want to delete <%s>" ), GetChars( GetFileName() ) );
wxMessageDialog dialog( m_parent, msg, wxMessageDialog dialog( m_parent, msg,
_( "Delete File" ), wxYES_NO | wxICON_QUESTION ); _( "Delete File" ), wxYES_NO | wxICON_QUESTION );
@ -184,16 +180,15 @@ bool TREEPROJECT_ITEM::Delete( bool check )
} }
// Called under item activation
void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe ) void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
{ {
wxString sep = wxFileName().GetPathSeparator(); wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName(); wxString fullFileName = GetFileName();
wxTreeItemId id = GetId(); wxTreeItemId id = GetId();
KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) Pgm().App().GetTopWindow(); KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) Pgm().App().GetTopWindow();
AddDelimiterString( FullFileName ); AddDelimiterString( fullFileName );
switch( GetType() ) switch( GetType() )
{ {
@ -205,24 +200,29 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
break; break;
case TREE_SCHEMA: case TREE_SCHEMA:
mainFrame->Execute( m_parent, EESCHEMA_EXE, FullFileName ); mainFrame->Execute( m_parent, EESCHEMA_EXE, fullFileName );
break; break;
case TREE_LEGACY_PCB: case TREE_LEGACY_PCB:
case TREE_SEXP_PCB: case TREE_SEXP_PCB:
mainFrame->Execute( m_parent, PCBNEW_EXE, FullFileName ); {
DBG( printf( "%s: %s\n", __func__, TO_UTF8( fullFileName ) ); )
mainFrame->Execute( m_parent, PCBNEW_EXE, fullFileName );
}
break; break;
case TREE_GERBER: case TREE_GERBER:
mainFrame->Execute( m_parent, GERBVIEW_EXE, FullFileName ); mainFrame->Execute( m_parent, GERBVIEW_EXE, fullFileName );
break; break;
case TREE_PDF: case TREE_PDF:
OpenPDF( FullFileName ); OpenPDF( fullFileName );
break; break;
case TREE_NET: case TREE_NET:
mainFrame->Execute( m_parent, CVPCB_EXE, FullFileName ); mainFrame->Execute( m_parent, CVPCB_EXE, fullFileName );
break; break;
case TREE_TXT: case TREE_TXT:
@ -230,18 +230,16 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
wxString editorname = Pgm().GetEditorName(); wxString editorname = Pgm().GetEditorName();
if( !editorname.IsEmpty() ) if( !editorname.IsEmpty() )
mainFrame->Execute( m_parent, editorname, FullFileName ); mainFrame->Execute( m_parent, editorname, fullFileName );
break;
} }
break;
case TREE_PAGE_LAYOUT_DESCR: case TREE_PAGE_LAYOUT_DESCR:
mainFrame->Execute( m_parent, PL_EDITOR_EXE, FullFileName ); mainFrame->Execute( m_parent, PL_EDITOR_EXE, fullFileName );
break; break;
default: default:
OpenFile( FullFileName ); OpenFile( fullFileName );
break; break;
} }
} }

View File

@ -1,63 +1,60 @@
/* #ifndef TREEPROJECT_ITEM_H_
* class_treeproject_item.h #define TREEPROJECT_ITEM_H_
*/
/**
/** class TREEPROJECT_ITEM * Class TREEPROJECT_ITEM
* Handle one item (a file or a directory name) for the tree file * handles one item (a file or a directory name) for the tree file
*/ */
class TREEPROJECT_ITEM : public wxTreeItemData class TREEPROJECT_ITEM : public wxTreeItemData
{ {
public: friend class KICAD_MANAGER_FRAME;
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
wxString m_FileName; // Filename for a file, or directory name
bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project)
bool m_WasPopulated; // True the name is a directory, and its content was read
private:
wxTreeCtrl* m_parent;
int m_state;
public: public:
TREEPROJECT_ITEM( TreeFileType type, const wxString& data, TREEPROJECT_ITEM( TreeFileType type, const wxString& data,
wxTreeCtrl* parent ); wxTreeCtrl* parent );
TREEPROJECT_ITEM() : m_parent( NULL ) { } TREEPROJECT_ITEM() : m_parent( NULL ) { }
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) : TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) :
m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent ) m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent )
{ {
SetState( src.m_state ); SetState( src.m_state );
m_WasPopulated = false; m_IsPopulated = false;
} }
TreeFileType GetType() const TreeFileType GetType() const { return m_Type; }
{ void SetType( TreeFileType aType ) { m_Type = aType; }
return m_Type;
}
void SetType( TreeFileType aType ) const wxString& GetFileName() const { return m_FileName; }
{ void SetFileName( const wxString& name ) { m_FileName = name; }
m_Type = aType;
}
wxString GetFileName() const bool IsRootFile() const { return m_IsRootFile; }
{ void SetRootFile( bool aValue ) { m_IsRootFile = aValue; }
return m_FileName;
}
void SetFileName( const wxString& name ) bool IsPopulated() const { return m_IsPopulated; }
{ void SetPopulated( bool aValue ) { m_IsPopulated = aValue; }
m_FileName = name;
}
/** /**
* @return the path of an item. * @return the path of an item.
* if this item is a directory, returns the stored filename * if this item is a directory, returns the stored filename
* if this is a file, returns its path * if this is a file, returns its path
*/ */
wxString GetDir() const; const wxString GetDir() const;
bool Rename( const wxString& name, bool check = true ); bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true ); bool Delete( bool check = true );
void Activate( TREE_PROJECT_FRAME* prjframe ); void Activate( TREE_PROJECT_FRAME* prjframe );
void SetState( int state ); void SetState( int state );
private:
TreeFileType m_Type; // = TREE_PROJECT, TREE_DIRECTORY ...
wxString m_FileName; // Filename for a file, or directory name
bool m_IsRootFile; // True if m_Filename is a root schematic (same name as project)
bool m_IsPopulated; // True if the name is a directory, and its content was read
wxTreeCtrl* m_parent;
int m_state;
}; };
#endif // TREEPROJECT_ITEM_H_

View File

@ -83,8 +83,7 @@ TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
TREEPROJECTFILES::~TREEPROJECTFILES() TREEPROJECTFILES::~TREEPROJECTFILES()
{ {
if( m_ImageList ) delete m_ImageList;
delete m_ImageList;
} }
@ -93,16 +92,18 @@ int TREEPROJECTFILES::OnCompareItems( const wxTreeItemId& item1, const wxTreeIte
TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 ); TREEPROJECT_ITEM* myitem1 = (TREEPROJECT_ITEM*) GetItemData( item1 );
TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 ); TREEPROJECT_ITEM* myitem2 = (TREEPROJECT_ITEM*) GetItemData( item2 );
if( (myitem1->m_Type == TREE_DIRECTORY) && ( myitem2->m_Type != TREE_DIRECTORY ) ) if( myitem1->GetType() == TREE_DIRECTORY && myitem2->GetType() != TREE_DIRECTORY )
return -1; return -1;
if( (myitem2->m_Type == TREE_DIRECTORY) && ( myitem1->m_Type != TREE_DIRECTORY ) )
if( myitem2->GetType() == TREE_DIRECTORY && myitem1->GetType() != TREE_DIRECTORY )
return 1; return 1;
if( myitem1->m_IsRootFile && !myitem2->m_IsRootFile ) if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
return -1; return -1;
if( myitem2->m_IsRootFile && !myitem1->m_IsRootFile )
if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
return 1; return 1;
return myitem1->m_FileName.CmpNoCase( myitem2->m_FileName ); return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
} }

View File

@ -41,8 +41,8 @@
#include <kicad.h> #include <kicad.h>
static const wxString ZipFileExtension( wxT( "zip" ) ); #define ZipFileExtension wxT( "zip" )
static const wxString ZipFileWildcard( wxT( "Zip file (*.zip) | *.zip" ) ); #define ZipFileWildcard wxT( "Zip file (*.zip) | *.zip" )
void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
@ -53,14 +53,17 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
if( fn != wxEmptyString ) if( fn != wxEmptyString )
{ {
wxCommandEvent cmd( 0, wxID_ANY ); wxCommandEvent cmd( 0, wxID_ANY );
m_ProjectFileName = fn;
SetProjectFileName( fn );
OnLoadProject( cmd ); OnLoadProject( cmd );
} }
} }
void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
{ {
wxFileName fn = m_ProjectFileName; wxFileName fn = GetProjectFileName();
fn.SetExt( ZipFileExtension ); fn.SetExt( ZipFileExtension );
wxFileDialog dlg( this, _( "Unzip Project" ), fn.GetPath(), wxFileDialog dlg( this, _( "Unzip Project" ), fn.GetPath(),
@ -70,8 +73,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return; return;
wxString msg; wxString msg = wxString::Format( _("\nOpen <%s>\n" ), GetChars( dlg.GetPath() ) );
msg.Printf( _("\nOpen <%s>\n" ), GetChars( dlg.GetPath() ) );
PrintMsg( msg ); PrintMsg( msg );
wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(), wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(),
@ -85,6 +87,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
PrintMsg( msg ); PrintMsg( msg );
wxFileSystem zipfilesys; wxFileSystem zipfilesys;
zipfilesys.AddHandler( new wxZipFSHandler ); zipfilesys.AddHandler( new wxZipFSHandler );
zipfilesys.ChangePathTo( dlg.GetPath() + wxT( "#zip:" ) ); zipfilesys.ChangePathTo( dlg.GetPath() + wxT( "#zip:" ) );
@ -94,7 +97,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
while( !localfilename.IsEmpty() ) while( !localfilename.IsEmpty() )
{ {
zipfile = zipfilesys.OpenFile( localfilename ); zipfile = zipfilesys.OpenFile( localfilename );
if( zipfile == NULL ) if( !zipfile )
{ {
DisplayError( this, wxT( "Zip file read error" ) ); DisplayError( this, wxT( "Zip file read error" ) );
break; break;
@ -139,7 +142,7 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
}; };
wxString msg; wxString msg;
wxFileName fileName = m_ProjectFileName; wxFileName fileName = GetProjectFileName();
wxString oldPath = wxGetCwd(); wxString oldPath = wxGetCwd();
fileName.SetExt( wxT( "zip" ) ); fileName.SetExt( wxT( "zip" ) );

View File

@ -158,15 +158,15 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
bool prjloaded = false; // true when the project is loaded bool prjloaded = false; // true when the project is loaded
if( App().argc > 1 ) if( App().argc > 1 )
frame->m_ProjectFileName = App().argv[1]; frame->SetProjectFileName( App().argv[1] );
else if( GetFileHistory().GetCount() ) else if( GetFileHistory().GetCount() )
{ {
// Try to open the last opened project, // Try to open the last opened project,
// if a project name is not given when starting Kicad // if a project name is not given when starting Kicad
frame->m_ProjectFileName = GetFileHistory().GetHistoryFile( 0 ); frame->SetProjectFileName( GetFileHistory().GetHistoryFile( 0 ) );
if( !frame->m_ProjectFileName.FileExists() ) if( !wxFileExists( frame->GetProjectFileName() ) )
GetFileHistory().RemoveFileFromHistory( 0 ); GetFileHistory().RemoveFileFromHistory( 0 );
else else
{ {
@ -177,12 +177,12 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
} }
} }
if( !frame->m_ProjectFileName.FileExists() ) if( !wxFileExists( frame->GetProjectFileName() ) )
{ {
wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT, wxFileName namelessProject( wxGetCwd(), NAMELESS_PROJECT,
ProjectFileExtension ); ProjectFileExtension );
frame->m_ProjectFileName = namelessProject; frame->SetProjectFileName( namelessProject.GetFullPath() );
} }
if( !prjloaded ) if( !prjloaded )
@ -218,23 +218,24 @@ void PGM_KICAD::MacOpenFile( const wxString& aFileName )
KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) GetTopWindow(); KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) GetTopWindow();
frame->SetProjectFile( aFileName );
wxFileName fn = aFileName; wxFileName fn = aFileName;
frame->m_ProjectFileName = fn; if( !fn.FileExists() && m_fileHistory.GetCount() )
if( !frame->m_ProjectFileName.FileExists() && m_fileHistory.GetCount() )
{ {
m_fileHistory.RemoveFileFromHistory( 0 ); m_fileHistory.RemoveFileFromHistory( 0 );
return; return;
} }
wxCommandEvent loadEvent; wxCommandEvent loadEvent;
loadEvent.SetId( wxID_ANY ); loadEvent.SetId( wxID_ANY );
frame->OnLoadProject( loadEvent ); frame->OnLoadProject( loadEvent );
wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() + wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath(); wxT( " " ) + frame->GetProjectFileName();
if( !fn.IsDirWritable() ) if( !fn.IsDirWritable() )
title += _( " [Read Only]" ); title += _( " [Read Only]" );

View File

@ -120,28 +120,6 @@ enum id_kicad_frm {
*/ */
class KICAD_MANAGER_FRAME : public EDA_BASE_FRAME class KICAD_MANAGER_FRAME : public EDA_BASE_FRAME
{ {
protected:
wxConfigBase* config(); // override EDA_BASE_FRAME virtual
const SEARCH_STACK& sys_search(); // override EDA_BASE_FRAME virtual
wxString help_name(); // override EDA_BASE_FRAME virtual
public:
TREE_PROJECT_FRAME* m_LeftWin;
LAUNCHER_PANEL* m_Launcher;
wxTextCtrl* m_MessagesBox;
wxAuiToolBar* m_VToolBar; // Vertical toolbar (not used)
wxString m_BoardFileName;
wxString m_SchematicRootFileName;
wxFileName m_ProjectFileName;
private:
int m_leftWinWidth;
void language_change( wxCommandEvent& event );
public: public:
KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title, KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
const wxPoint& pos, const wxSize& size ); const wxPoint& pos, const wxSize& size );
@ -211,7 +189,7 @@ public:
void OnUpdateDefaultPdfBrowser( wxUpdateUIEvent& event ); void OnUpdateDefaultPdfBrowser( wxUpdateUIEvent& event );
void OnUpdatePreferredPdfBrowser( wxUpdateUIEvent& event ); void OnUpdatePreferredPdfBrowser( wxUpdateUIEvent& event );
void CreateNewProject( const wxString aPrjFullFileName, bool aTemplateSelector ); void CreateNewProject( const wxString& aPrjFullFileName, bool aTemplateSelector );
void LoadSettings( wxConfigBase* aCfg ); void LoadSettings( wxConfigBase* aCfg );
@ -249,7 +227,32 @@ public:
void OnChangeWatchedPaths(wxCommandEvent& aEvent ); void OnChangeWatchedPaths(wxCommandEvent& aEvent );
#endif #endif
void SetProjectFileName( const wxString& aFullProjectProFileName );
const wxString GetProjectFileName();
// read only accessors
const wxString SchFileName();
const wxString PcbFileName();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
private:
wxConfigBase* config(); // override EDA_BASE_FRAME virtual
const SEARCH_STACK& sys_search(); // override EDA_BASE_FRAME virtual
wxString help_name(); // override EDA_BASE_FRAME virtual
TREE_PROJECT_FRAME* m_LeftWin;
LAUNCHER_PANEL* m_Launcher;
wxTextCtrl* m_MessagesBox;
wxAuiToolBar* m_VToolBar; // Vertical toolbar (not used)
wxFileName m_project_file_name;
int m_leftWinWidth;
void language_change( wxCommandEvent& event );
}; };

View File

@ -41,7 +41,6 @@
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#define USE_KIFACE 1
#define TreeFrameWidthEntry wxT( "LeftWinWidth" ) #define TreeFrameWidthEntry wxT( "LeftWinWidth" )
@ -125,6 +124,35 @@ wxConfigBase* KICAD_MANAGER_FRAME::config()
return ret; return ret;
} }
void KICAD_MANAGER_FRAME::SetProjectFileName( const wxString& aFullProjectProFileName )
{
m_project_file_name = aFullProjectProFileName;
wxASSERT( m_project_file_name.IsAbsolute() );
}
const wxString KICAD_MANAGER_FRAME::GetProjectFileName()
{
return m_project_file_name.GetFullPath();
}
const wxString KICAD_MANAGER_FRAME::SchFileName()
{
wxFileName fn( GetProjectFileName(), SchematicFileExtension );
return fn.GetFullName();
}
const wxString KICAD_MANAGER_FRAME::PcbFileName()
{
wxFileName fn( GetProjectFileName(), PcbFileExtension );
return fn.GetFullName();
}
const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search() const SEARCH_STACK& KICAD_MANAGER_FRAME::sys_search()
{ {
@ -159,7 +187,7 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
int px, py; int px, py;
UpdateFileHistory( m_ProjectFileName.GetFullPath(), &Pgm().GetFileHistory() ); UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() );
if( !IsIconized() ) // save main frame position and size if( !IsIconized() ) // save main frame position and size
{ {
@ -238,16 +266,14 @@ void KICAD_MANAGER_FRAME::OnRunPageLayoutEditor( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event )
{ {
wxFileName legacy_board( m_ProjectFileName ); wxFileName kicad_board( PcbFileName() );
wxFileName kicad_board( m_ProjectFileName );
wxFileName legacy_board( GetProjectFileName() );
legacy_board.SetExt( LegacyPcbFileExtension ); legacy_board.SetExt( LegacyPcbFileExtension );
kicad_board.SetExt( KiCadPcbFileExtension );
wxFileName& board = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ? wxFileName& board = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ?
kicad_board : legacy_board; kicad_board : legacy_board;
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_PCB, false ); KIWAY_PLAYER* frame = Kiway.Player( FRAME_PCB, false );
if( !frame ) if( !frame )
{ {
@ -256,19 +282,15 @@ void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event )
frame->Show( true ); frame->Show( true );
} }
frame->Raise(); frame->Raise();
#else
Execute( this, PCBNEW_EXE, QuoteFullPath( board ) );
#endif
} }
void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
{ {
wxFileName fn( m_ProjectFileName ); wxFileName fn( m_project_file_name );
fn.SetExt( NetlistFileExtension ); fn.SetExt( NetlistFileExtension );
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_CVPCB, false ); KIWAY_PLAYER* frame = Kiway.Player( FRAME_CVPCB, false );
if( !frame ) if( !frame )
{ {
@ -277,19 +299,15 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
frame->Show( true ); frame->Show( true );
} }
frame->Raise(); frame->Raise();
#else
Execute( this, CVPCB_EXE, QuoteFullPath( fn ) );
#endif
} }
void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
{ {
wxFileName fn( m_ProjectFileName ); wxFileName fn( m_project_file_name );
fn.SetExt( SchematicFileExtension ); fn.SetExt( SchematicFileExtension );
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_SCH, false ); KIWAY_PLAYER* frame = Kiway.Player( FRAME_SCH, false );
if( !frame ) if( !frame )
{ {
@ -298,20 +316,14 @@ void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
frame->Show( true ); frame->Show( true );
} }
frame->Raise(); frame->Raise();
#else
Execute( this, EESCHEMA_EXE, QuoteFullPath( fn ) );
#endif
} }
void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event )
{ {
// Gerbview is called without any file to open, because we do not know // Gerbview is called without any file to open, because we do not know
// the list and the name of files to open (if any...). // the list and the name of files to open (if any...).
#if USE_KIFACE && 0
#else
Execute( this, GERBVIEW_EXE, wxEmptyString ); Execute( this, GERBVIEW_EXE, wxEmptyString );
#endif
} }
@ -392,7 +404,7 @@ void KICAD_MANAGER_FRAME::PrintPrjInfo()
wxString msg = wxString::Format( _( wxString msg = wxString::Format( _(
"Working dir: %s\nProject: %s\n" ), "Working dir: %s\nProject: %s\n" ),
GetChars( wxGetCwd() ), GetChars( wxGetCwd() ),
GetChars( m_ProjectFileName.GetFullPath() ) GetChars( GetProjectFileName() )
); );
PrintMsg( msg ); PrintMsg( msg );
} }

View File

@ -57,8 +57,8 @@
PARAM_CFG_ARRAY s_KicadManagerParams; PARAM_CFG_ARRAY s_KicadManagerParams;
void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName, void KICAD_MANAGER_FRAME::CreateNewProject( const wxString& aPrjFullFileName,
bool aTemplateSelector = false ) bool aTemplateSelector = false )
{ {
wxString filename; wxString filename;
wxFileName newProjectName = aPrjFullFileName; wxFileName newProjectName = aPrjFullFileName;
@ -169,15 +169,8 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName,
} }
} }
// Init schematic filename
m_SchematicRootFileName = wxFileName( newProjectName.GetName(),
SchematicFileExtension ).GetFullName();
// Init pcb board filename
m_BoardFileName = wxFileName( newProjectName.GetName(), PcbFileExtension ).GetFullName();
// Init project filename // Init project filename
m_ProjectFileName = newProjectName; SetProjectFileName( newProjectName.GetFullPath() );
// Write settings to project file // Write settings to project file
// was: wxGetApp().WriteProjectConfig( aPrjFullFileName, GeneralGroupName, s_KicadManagerParams ); // was: wxGetApp().WriteProjectConfig( aPrjFullFileName, GeneralGroupName, s_KicadManagerParams );
@ -187,15 +180,19 @@ void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName,
void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
{ {
int style; wxString title;
wxString title;
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) || // this is still a mess, will work on it tomorrow.
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
ClearMsg(); ClearMsg();
if( event.GetId() != wxID_ANY ) if( event.GetId() != wxID_ANY )
{ {
int style;
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
if( newProject ) if( newProject )
{ {
title = _( "Create New Project" ); title = _( "Create New Project" );
@ -207,21 +204,20 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
style = wxFD_OPEN | wxFD_FILE_MUST_EXIST; style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
} }
wxString default_dir = wxGetCwd(); wxString default_dir = wxGetCwd();
wxFileDialog dlg( this, title, default_dir, wxEmptyString, wxFileDialog dlg( this, title, default_dir, wxEmptyString,
ProjectFileWildcard, style ); ProjectFileWildcard, style );
if( dlg.ShowModal() == wxID_CANCEL ) if( dlg.ShowModal() == wxID_CANCEL )
return; return;
m_ProjectFileName = dlg.GetPath(); wxFileName pro( dlg.GetPath() );
pro.SetExt( ProjectFileExtension );
if( newProject ) if( newProject )
{ {
m_ProjectFileName.SetExt( ProjectFileExtension );
// Check if the project directory is empty // Check if the project directory is empty
wxDir directory ( m_ProjectFileName.GetPath() ); wxDir directory( pro.GetPath() );
if( directory.HasFiles() ) if( directory.HasFiles() )
{ {
@ -233,57 +229,59 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
{ {
// Append a new directory with the same name of the project file // Append a new directory with the same name of the project file
// and try to create it // and try to create it
m_ProjectFileName.AppendDir( m_ProjectFileName.GetName() ); pro.AppendDir( pro.GetName() );
if( !wxMkdir( m_ProjectFileName.GetPath() ) ) if( !wxMkdir( pro.GetPath() ) )
// There was a problem, undo // There was a problem, undo
m_ProjectFileName.RemoveLastDir(); pro.RemoveLastDir();
} }
} }
if( event.GetId() == ID_NEW_PROJECT ) if( event.GetId() == ID_NEW_PROJECT )
{ {
CreateNewProject( m_ProjectFileName.GetFullPath() ); CreateNewProject( pro.GetFullPath() );
} }
else if( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE ) else if( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE )
{ {
// Launch the template selector dialog // Launch the template selector dialog
CreateNewProject( m_ProjectFileName.GetFullPath(), true ); CreateNewProject( pro.GetFullPath(), true );
} }
} }
SetProjectFileName( pro.GetFullName() );
} }
wxLogDebug( wxT( "Loading KiCad project file: " ) + m_ProjectFileName.GetFullPath() ); wxLogDebug( wxT( "Loading KiCad project file: " ) + GetProjectFileName() );
/* Check if project file exists and if it is not noname.pro */ // Check if project file exists and if it is not noname.pro
wxString filename = m_ProjectFileName.GetFullName(); wxString filename = GetProjectFileName();
wxString nameless_prj = NAMELESS_PROJECT wxT( ".pro" ); wxString nameless_prj = NAMELESS_PROJECT wxT( ".pro" );
if( !m_ProjectFileName.FileExists() && !filename.IsSameAs( nameless_prj ) ) if( !wxFileExists( GetProjectFileName() ) && !filename.IsSameAs( nameless_prj ) )
{ {
wxString msg = wxString::Format( wxString msg = wxString::Format(
_( "KiCad project file '%s' not found" ), _( "KiCad project file '%s' not found" ),
GetChars( m_ProjectFileName.GetFullPath() ) ); GetChars( GetProjectFileName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
wxSetWorkingDirectory( m_ProjectFileName.GetPath() ); wxSetWorkingDirectory( wxFileName( GetProjectFileName() ).GetPath() );
// was wxGetApp().ReadProjectConfig( m_ProjectFileName.GetFullPath(), // was wxGetApp().ReadProjectConfig( m_ProjectFileName.GetFullPath(),
// GeneralGroupName, s_KicadManagerParams, false ); // GeneralGroupName, s_KicadManagerParams, false );
Prj().ConfigLoad( Pgm().SysSearch(), m_ProjectFileName.GetFullPath(), Prj().ConfigLoad( Pgm().SysSearch(), GetProjectFileName(),
GeneralGroupName, s_KicadManagerParams, false ); GeneralGroupName, s_KicadManagerParams, false );
title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + m_ProjectFileName.GetFullPath(); title = wxT( "KiCad " ) + GetBuildVersion() + wxT( ' ' ) + GetProjectFileName();
if( !m_ProjectFileName.IsDirWritable() ) if( !wxIsWritable( GetProjectFileName() ) )
title += _( " [Read Only]" ); title += _( " [Read Only]" );
SetTitle( title ); SetTitle( title );
UpdateFileHistory( m_ProjectFileName.GetFullPath(), &Pgm().GetFileHistory() ); UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() );
m_LeftWin->ReCreateTreePrj(); m_LeftWin->ReCreateTreePrj();
@ -292,7 +290,8 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
// however this is possible only when the main loop event handler is running, // however this is possible only when the main loop event handler is running,
// so we use it to run the rebuild function. // so we use it to run the rebuild function.
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
wxPostEvent( this, cmd);
wxPostEvent( this, cmd );
#endif #endif
PrintPrjInfo(); PrintPrjInfo();
@ -301,12 +300,11 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event ) void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
{ {
if( !IsWritable( m_ProjectFileName ) ) if( !wxIsWritable( GetProjectFileName() ) )
return; return;
// was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(), // was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(),
// GeneralGroupName, s_KicadManagerParams ); // GeneralGroupName, s_KicadManagerParams );
Prj().ConfigSave( Pgm().SysSearch(), m_ProjectFileName.GetFullPath(), Prj().ConfigSave( Pgm().SysSearch(), GetProjectFileName(),
GeneralGroupName, s_KicadManagerParams ); GeneralGroupName, s_KicadManagerParams );
} }

View File

@ -93,10 +93,10 @@ static const wxChar* s_allowedExtensionsToList[] =
* library as required. * library as required.
*/ */
/* File extension definitions. */ // File extension definitions.
const wxChar TextFileExtension[] = wxT( "txt" ); const wxChar TextFileExtension[] = wxT( "txt" );
/* File wildcard definitions. */ // File wildcard definitions.
const wxChar TextFileWildcard[] = wxT( "Text files (*.txt)|*.txt" ); const wxChar TextFileWildcard[] = wxT( "Text files (*.txt)|*.txt" );
@ -132,11 +132,13 @@ TREE_PROJECT_FRAME::TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ) :
{ {
m_Parent = parent; m_Parent = parent;
m_TreeProject = NULL; m_TreeProject = NULL;
#ifdef KICAD_USE_FILES_WATCHER #ifdef KICAD_USE_FILES_WATCHER
m_watcher = NULL; m_watcher = NULL;
Connect( wxEVT_FSWATCHER, Connect( wxEVT_FSWATCHER,
wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) ); wxFileSystemWatcherEventHandler( TREE_PROJECT_FRAME::OnFileSystemEvent ) );
#endif #endif
/* /*
* Filtering is now inverted: the filters are actually used to _enable_ support * Filtering is now inverted: the filters are actually used to _enable_ support
* for a given file type. * for a given file type.
@ -162,9 +164,7 @@ TREE_PROJECT_FRAME::~TREE_PROJECT_FRAME()
} }
/*****************************************************************************/
void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter ) void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
/*****************************************************************************/
{ {
for( unsigned int i = 0; i < m_filters.size(); i++ ) for( unsigned int i = 0; i < m_filters.size(); i++ )
{ {
@ -177,11 +177,6 @@ void TREE_PROJECT_FRAME::RemoveFilter( const wxString& filter )
} }
/**
* Called by the popup menu in the tree frame
* Creates a new subdirectory inside the current kicad project directory
* the user is prompted to enter a directory name
*/
void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event ) void TREE_PROJECT_FRAME::OnCreateNewDirectory( wxCommandEvent& event )
{ {
// Get the root directory name: // Get the root directory name:
@ -374,16 +369,6 @@ wxString TREE_PROJECT_FRAME::GetFileWildcard( TreeFileType type )
} }
/**
* Function AddItemToTreeProject
* @brief Add filename "name" to the tree \n
* if name is a directory, add the sub directory file names
* @param aName = the filename or the dirctory name to add
* @param aRoot = the wxTreeItemId item where to add sub tree items
* @param aRecurse = true to add file or subdir names to the current tree item
* false to stop file add.
* @return true if the file (or directory) is added.
*/
bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName, bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
wxTreeItemId& aRoot, bool aRecurse ) wxTreeItemId& aRoot, bool aRecurse )
{ {
@ -450,7 +435,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
wxString rootName; wxString rootName;
TREEPROJECT_ITEM* itemData = GetItemIdData( m_root ); TREEPROJECT_ITEM* itemData = GetItemIdData( m_root );
if( itemData ) if( itemData )
rootName = itemData->m_FileName.BeforeLast( '.' ); rootName = itemData->GetFileName().BeforeLast( '.' );
if( fullFileName != rootName ) if( fullFileName != rootName )
{ {
@ -513,7 +498,7 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
if( itemData ) if( itemData )
{ {
if( itemData->m_FileName == aName ) if( itemData->GetFileName() == aName )
{ {
return true; // well, we would have added it, but it is already here! return true; // well, we would have added it, but it is already here!
} }
@ -531,13 +516,13 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
data->SetState( 0 ); data->SetState( 0 );
/* Mark root files (files which have the same aName as the project) */ /* Mark root files (files which have the same aName as the project) */
wxFileName project( m_Parent->m_ProjectFileName ); wxFileName project( m_Parent->GetProjectFileName() );
wxFileName currfile( file ); wxFileName currfile( file );
if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 ) if( currfile.GetName().CmpNoCase( project.GetName() ) == 0 )
data->m_IsRootFile = true; data->SetRootFile( true );
else else
data->m_IsRootFile = false; data->SetRootFile( false );
// This section adds dirs and files found in the subdirs // This section adds dirs and files found in the subdirs
// in this case AddFile is recursive, but for the first level only. // in this case AddFile is recursive, but for the first level only.
@ -546,7 +531,8 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
const wxString sep = wxFileName().GetPathSeparator(); const wxString sep = wxFileName().GetPathSeparator();
wxDir dir( aName ); wxDir dir( aName );
wxString dir_filename; wxString dir_filename;
data->m_WasPopulated = true; // set state to populated
data->SetPopulated( true );
if( dir.GetFirst( &dir_filename ) ) if( dir.GetFirst( &dir_filename ) )
{ {
@ -564,13 +550,9 @@ bool TREE_PROJECT_FRAME::AddItemToTreeProject( const wxString& aName,
} }
/**
* @brief Create or modify the tree showing project file names
*/
void TREE_PROJECT_FRAME::ReCreateTreePrj() void TREE_PROJECT_FRAME::ReCreateTreePrj()
{ {
wxTreeItemId rootcellule; wxTreeItemId rootcellule;
wxFileName fn;
bool prjOpened = false; bool prjOpened = false;
if( !m_TreeProject ) if( !m_TreeProject )
@ -578,15 +560,15 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
else else
m_TreeProject->DeleteAllItems(); m_TreeProject->DeleteAllItems();
if( !m_Parent->m_ProjectFileName.IsOk() ) wxFileName fn = m_Parent->GetProjectFileName();
if( !fn.IsOk() )
{ {
fn.Clear(); fn.Clear();
fn.SetPath( ::wxGetCwd() ); fn.SetPath( ::wxGetCwd() );
fn.SetName( NAMELESS_PROJECT ); fn.SetName( NAMELESS_PROJECT );
fn.SetExt( ProjectFileExtension ); fn.SetExt( ProjectFileExtension );
} }
else
fn = m_Parent->m_ProjectFileName;
prjOpened = fn.FileExists(); prjOpened = fn.FileExists();
@ -625,26 +607,21 @@ void TREE_PROJECT_FRAME::ReCreateTreePrj()
m_TreeProject->Expand( rootcellule ); m_TreeProject->Expand( rootcellule );
/* Sort filenames by alphabetic order */ // Sort filenames by alphabetic order
m_TreeProject->SortChildren( m_root ); m_TreeProject->SortChildren( m_root );
m_Parent->m_ProjectFileName = fn; m_Parent->SetProjectFileName( fn.GetFullPath() );
} }
/**
* @brief Opens *popup* the context menu
*/
/*****************************************************************************/
void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event ) void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
/*****************************************************************************/
{ {
int tree_id; int tree_id;
TREEPROJECT_ITEM* tree_data; TREEPROJECT_ITEM* tree_data;
wxString FullFileName; wxString FullFileName;
wxTreeItemId curr_item = Event.GetItem(); wxTreeItemId curr_item = Event.GetItem();
/* Ensure item is selected (Under Windows right click does not select the item) */ // Ensure item is selected (Under Windows right click does not select the item)
m_TreeProject->SelectItem( curr_item ); m_TreeProject->SelectItem( curr_item );
tree_data = GetSelectedData(); tree_data = GetSelectedData();
@ -696,10 +673,7 @@ void TREE_PROJECT_FRAME::OnRight( wxTreeEvent& Event )
PopupMenu( &popupMenu ); PopupMenu( &popupMenu );
} }
/*
* Called by the popup menu, when right clicking on a file name
* Launch the text editor to open the selected file
*/
void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event ) void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event )
{ {
TREEPROJECT_ITEM* tree_data = GetSelectedData(); TREEPROJECT_ITEM* tree_data = GetSelectedData();
@ -719,10 +693,6 @@ void TREE_PROJECT_FRAME::OnOpenSelectedFileWithTextEditor( wxCommandEvent& event
} }
/* Called via the popup menu, when right clicking on a file name
* or a directory name to delete the selected file or directory
* in the tree project
*/
void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& ) void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
{ {
TREEPROJECT_ITEM* tree_data = GetSelectedData(); TREEPROJECT_ITEM* tree_data = GetSelectedData();
@ -734,10 +704,6 @@ void TREE_PROJECT_FRAME::OnDeleteFile( wxCommandEvent& )
} }
/* Called via the popup menu, when right clicking on a file name
* or a directory name to rename the selected file or directory
* in the tree project
*/
void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& ) void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
{ {
wxTreeItemId curr_item = m_TreeProject->GetSelection(); wxTreeItemId curr_item = m_TreeProject->GetSelection();
@ -746,9 +712,10 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
if( !tree_data ) if( !tree_data )
return; return;
wxString buffer = m_TreeProject->GetItemText( curr_item ); wxString buffer = m_TreeProject->GetItemText( curr_item );
wxString msg; wxString msg = wxString::Format(
msg.Printf( _( "Change filename: <%s>" ), GetChars( tree_data->m_FileName ) ); _( "Change filename: <%s>" ),
GetChars( tree_data->GetFileName() ) );
wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer ); wxTextEntryDialog dlg( this, msg, _( "Change filename" ), buffer );
@ -767,12 +734,7 @@ void TREE_PROJECT_FRAME::OnRenameFile( wxCommandEvent& )
} }
/*
* called on a double click on an item
*/
/*****************************************************************************/
void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event ) void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
/*****************************************************************************/
{ {
wxString FullFileName; wxString FullFileName;
@ -785,13 +747,7 @@ void TREE_PROJECT_FRAME::OnSelect( wxTreeEvent& Event )
} }
/**
* @brief Called when expanding an item of the tree
* populate tree items corresponding to subdirectories not already populated
*/
/*****************************************************************************/
void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event ) void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
/*****************************************************************************/
{ {
wxString FullFileName; wxString FullFileName;
@ -816,7 +772,7 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
if( !itemData || itemData->GetType() != TREE_DIRECTORY ) if( !itemData || itemData->GetType() != TREE_DIRECTORY )
continue; continue;
if( itemData->m_WasPopulated ) if( itemData->IsPopulated() )
continue; continue;
wxString fileName = itemData->GetFileName(); wxString fileName = itemData->GetFileName();
@ -832,10 +788,10 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
} while( dir.GetNext( &dir_filename ) ); } while( dir.GetNext( &dir_filename ) );
} }
itemData->m_WasPopulated = true; // set state to populated itemData->SetPopulated( true ); // set state to populated
subdir_populated = true; subdir_populated = true;
/* Sort filenames by alphabetic order */ // Sort filenames by alphabetic order
m_TreeProject->SortChildren( kid ); m_TreeProject->SortChildren( kid );
} }
@ -850,12 +806,6 @@ void TREE_PROJECT_FRAME::OnExpand( wxTreeEvent& Event )
} }
/**
* Function GetSelectedData
* return the item data from item currently selected (highlighted)
* Note this is not necessary the "clicked" item,
* because when expanding, collapsing an item this item is not selected
*/
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData() TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
{ {
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData
@ -863,25 +813,12 @@ TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetSelectedData()
} }
/**
* Function GetItemIdData
* return the item data corresponding to a wxTreeItemId identifier
* @param aId = the wxTreeItemId identifier.
* @return a TREEPROJECT_ITEM pointer correspondinfg to item id aId
*/
TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId ) TREEPROJECT_ITEM* TREE_PROJECT_FRAME::GetItemIdData( wxTreeItemId aId )
{ {
return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) ); return dynamic_cast<TREEPROJECT_ITEM*>( m_TreeProject->GetItemData( aId ) );
} }
/* Search for the item in tree project which is the
* node of the subdirectory aSubDir
* param aSubDir = the directory to find in tree
* return the opaque reference to the tree item.
* if not found, return an invalid tree item.
* therefore wxTreeItemId::IsOk should be used to test
* the returned value
*/
wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir ) wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
{ {
// If the subdir is the current working directory, return m_root // If the subdir is the current working directory, return m_root
@ -918,14 +855,14 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) ) if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
{ {
if( itemData->m_FileName == aSubDir ) // Found! if( itemData->GetFileName() == aSubDir ) // Found!
{ {
root_id = kid; root_id = kid;
break; break;
} }
// kid is a subdir, push in list to explore it later // kid is a subdir, push in list to explore it later
if( itemData->m_WasPopulated ) if( itemData->IsPopulated() )
subdirs_id.push( kid ); subdirs_id.push( kid );
} }
kid = m_TreeProject->GetNextChild( root_id, cookie ); kid = m_TreeProject->GetNextChild( root_id, cookie );
@ -934,12 +871,9 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
return root_id; return root_id;
} }
#ifdef KICAD_USE_FILES_WATCHER #ifdef KICAD_USE_FILES_WATCHER
/* called when a file or directory is modified/created/deleted void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
* The tree project is modified when a file or directory
* is created/deleted/renamed to reflect the file change
*/
void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
{ {
wxFileName pathModified = event.GetPath(); wxFileName pathModified = event.GetPath();
wxString subdir = pathModified.GetPath(); wxString subdir = pathModified.GetPath();
@ -981,7 +915,7 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
if( itemData && ( itemData->m_FileName == fn ) ) if( itemData && itemData->GetFileName() == fn )
{ {
m_TreeProject->Delete( kid ); m_TreeProject->Delete( kid );
return; return;
@ -991,35 +925,33 @@ wxTreeItemId TREE_PROJECT_FRAME::findSubdirTreeItem( const wxString& aSubDir )
break; break;
case wxFSW_EVENT_RENAME : case wxFSW_EVENT_RENAME :
{
wxFileName newpath = event.GetNewPath();
wxString newfn = newpath.GetFullPath();
while( kid.IsOk() )
{ {
TREEPROJECT_ITEM* itemData = GetItemIdData( kid ); wxFileName newpath = event.GetNewPath();
wxString newfn = newpath.GetFullPath();
if( itemData && ( itemData->m_FileName == fn ) ) while( kid.IsOk() )
{ {
m_TreeProject->Delete( kid ); TREEPROJECT_ITEM* itemData = GetItemIdData( kid );
break;
if( itemData && itemData->GetFileName() == fn )
{
m_TreeProject->Delete( kid );
break;
}
kid = m_TreeProject->GetNextChild( root_id, cookie );
} }
kid = m_TreeProject->GetNextChild( root_id, cookie ); AddItemToTreeProject( newfn, root_id, false );
} }
AddItemToTreeProject( newfn, root_id, false );
}
break; break;
} }
/* Sort filenames by alphabetic order */ // Sort filenames by alphabetic order
m_TreeProject->SortChildren( root_id ); m_TreeProject->SortChildren( root_id );
} }
/* Reinit the watched paths
* Should be called after opening a new project to
* rebuild the list of watched paths.
* Should be called after the main loop event handler is started
*/
void TREE_PROJECT_FRAME::FileWatcherReset() void TREE_PROJECT_FRAME::FileWatcherReset()
{ {
// Prepare file watcher: // Prepare file watcher:
@ -1065,13 +997,14 @@ void TREE_PROJECT_FRAME::FileWatcherReset()
if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) ) if( itemData && ( itemData->GetType() == TREE_DIRECTORY ) )
{ {
watched_path = wxFileName::DirName( itemData->m_FileName ); watched_path = wxFileName::DirName( itemData->GetFileName() );
m_watcher->Add( watched_path ); m_watcher->Add( watched_path );
// if kid is a subdir, push in list to explore it later // if kid is a subdir, push in list to explore it later
if( itemData->m_WasPopulated && m_TreeProject->GetChildrenCount( kid ) ) if( itemData->IsPopulated() && m_TreeProject->GetChildrenCount( kid ) )
subdirs_id.push( kid ); subdirs_id.push( kid );
} }
kid = m_TreeProject->GetNextChild( root_id, cookie ); kid = m_TreeProject->GetNextChild( root_id, cookie );
} }
#endif #endif
@ -1084,14 +1017,6 @@ void TREE_PROJECT_FRAME::FileWatcherReset()
#endif #endif
} }
/* Called by sending a event with id = ID_INIT_WATCHED_PATHS
* rebuild the list of whatched paths
* We are using an event called function to install or reinit a file system watcher
* because a file watcher *needs* a running loop event handler.
* this is noticeable under Linux.
* therefore the safe way to do that is to use the main event loop
* to call m_LeftWin->FileWatcherReset()
*/
void KICAD_MANAGER_FRAME::OnChangeWatchedPaths(wxCommandEvent& aEvent ) void KICAD_MANAGER_FRAME::OnChangeWatchedPaths(wxCommandEvent& aEvent )
{ {
m_LeftWin->FileWatcherReset(); m_LeftWin->FileWatcherReset();

View File

@ -58,7 +58,12 @@ private:
public: public:
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent ); TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
~TREE_PROJECT_FRAME(); ~TREE_PROJECT_FRAME();
/**
* Create or modify the tree showing project file names
*/
void ReCreateTreePrj(); void ReCreateTreePrj();
#ifdef KICAD_USE_FILES_WATCHER #ifdef KICAD_USE_FILES_WATCHER
/** /**
* Reinit the watched paths * Reinit the watched paths
@ -162,8 +167,8 @@ private:
bool aRecurse = true ); bool aRecurse = true );
/** /**
* function findSubdirTreeItem * Function findSubdirTreeItem
* Search for the item in tree project which is the * searches for the item in tree project which is the
* node of the subdirectory aSubDir * node of the subdirectory aSubDir
* @param aSubDir = the directory to find in tree * @param aSubDir = the directory to find in tree
* @return the opaque reference to the tree item. * @return the opaque reference to the tree item.

View File

@ -45,6 +45,7 @@ endif()
include_directories( include_directories(
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/pcbnew ${PROJECT_SOURCE_DIR}/pcbnew
${BOOST_INCLUDE}
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
) )

View File

@ -58,7 +58,7 @@ int main( int argc, char** argv )
static const KEYWORD empty_keywords[1] = {}; static const KEYWORD empty_keywords[1] = {};
DSNLEXER lexer( empty_keywords, 0, fp, wxString( FROM_UTF8( argv[1] ) ) ); DSNLEXER lexer( empty_keywords, 0, fp, FROM_UTF8( argv[1] ) );
try try
{ {