Commit acbe6290 authored by Dick Hollenbeck's avatar Dick Hollenbeck

switch back to original sexpr usage of PTREE, add new DSNLEXER constructor,...

switch back to original sexpr usage of PTREE, add new DSNLEXER constructor, enforce accessors in kicad.exe
parent 0304598a
......@@ -36,6 +36,8 @@
//#define STANDALONE 1 // enable this for stand alone testing.
#define FMT_CLIPBOARD _( "clipboard" )
//-----<DSNLEXER>-------------------------------------------------------------
......@@ -89,7 +91,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
keywordCount( aKeywordCount )
{
STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
wxString( _( "clipboard" ) ) : aSource );
wxString( FMT_CLIPBOARD ) : aSource );
PushReader( stringReader );
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()
{
if( iOwnReaders )
......
......@@ -83,11 +83,7 @@ inline void scanAtom( PTREE* aTree, DSNLEXER* aLexer )
//D(printf( "%s: '%s'\n", __func__, key );)
#if 0
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" );
if( aTree.data().size() )
if( aTree.data().size() ) // sexpr format does not use data()
{
out->Print( 0, " %s%s",
out->Quotes( aTree.data() ).c_str(),
......
......@@ -56,55 +56,61 @@ void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfRef
sheets.GetComponents( refs, false );
static const KEYWORD empty_keywords[1] = {};
DSNLEXER lexer( empty_keywords, 0, aChangedSetOfReferences, FROM_UTF8( __func__ ) );
DSNLEXER lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) );
PTREE doc;
Scan( &doc, &lexer );
try
{
Scan( &doc, &lexer );
#if defined(DEBUG) && 0
STRING_FORMATTER sf;
Format( &sf, 0, 0, doc );
printf( "%s: '%s'\n", __func__, sf.GetString().c_str() );
STRING_FORMATTER sf;
Format( &sf, 0, 0, doc );
printf( "%s: '%s'\n", __func__, sf.GetString().c_str() );
#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 )
{
wxASSERT( ref->first == "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" );
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 ) ); )
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 )
// Search the component in the flat list
for( unsigned ii = 0; ii < refs.GetCount(); ++ii )
{
// 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() )
if( Cmp_KEEPCASE( reference, refs[ii].GetRef() ) == 0 )
{
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 )
OnModify();
......
......@@ -174,7 +174,7 @@ public:
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.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
......@@ -186,6 +186,16 @@ public:
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
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* )
* intializes a DSN lexer and prepares to read from @a aLineReader which
......
......@@ -52,9 +52,9 @@ makes it easy to extract a subset of a ptree.
#include <richio.h>
#include <dsnlexer.h>
typedef boost::property_tree::ptree PTREE;
typedef const PTREE CPTREE;
typedef boost::property_tree::ptree PTREE;
typedef const PTREE CPTREE;
typedef boost::property_tree::ptree_error PTREE_ERROR;
/**
* Function Scan
......
......@@ -51,12 +51,11 @@ TREEPROJECT_ITEM::TREEPROJECT_ITEM( enum TreeFileType type, const wxString& data
m_Type = type;
m_parent = parent;
m_FileName = data;
m_IsRootFile = false; // true only for the root item of the tree (the project name)
m_WasPopulated = false;
m_IsRootFile = false; // true only for the root item of the tree (the project name)
m_IsPopulated = false;
}
// Set the state used in the icon list
void TREEPROJECT_ITEM::SetState( int state )
{
wxImageList* imglist = m_parent->GetImageList();
......@@ -71,8 +70,7 @@ void TREEPROJECT_ITEM::SetState( int state )
}
/* Get the directory containing the file */
wxString TREEPROJECT_ITEM::GetDir() const
const wxString TREEPROJECT_ITEM::GetDir() const
{
if( TREE_DIRECTORY == m_Type )
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 )
{
// 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 )
/*******************************************/
/* 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,
_( "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 )
{
wxString sep = wxFileName().GetPathSeparator();
wxString FullFileName = GetFileName();
wxString fullFileName = GetFileName();
wxTreeItemId id = GetId();
KICAD_MANAGER_FRAME* mainFrame = (KICAD_MANAGER_FRAME*) Pgm().App().GetTopWindow();
AddDelimiterString( FullFileName );
AddDelimiterString( fullFileName );
switch( GetType() )
{
......@@ -205,24 +200,29 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
break;
case TREE_SCHEMA:
mainFrame->Execute( m_parent, EESCHEMA_EXE, FullFileName );
mainFrame->Execute( m_parent, EESCHEMA_EXE, fullFileName );
break;
case TREE_LEGACY_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;
case TREE_GERBER:
mainFrame->Execute( m_parent, GERBVIEW_EXE, FullFileName );
mainFrame->Execute( m_parent, GERBVIEW_EXE, fullFileName );
break;
case TREE_PDF:
OpenPDF( FullFileName );
OpenPDF( fullFileName );
break;
case TREE_NET:
mainFrame->Execute( m_parent, CVPCB_EXE, FullFileName );
mainFrame->Execute( m_parent, CVPCB_EXE, fullFileName );
break;
case TREE_TXT:
......@@ -230,18 +230,16 @@ void TREEPROJECT_ITEM::Activate( TREE_PROJECT_FRAME* prjframe )
wxString editorname = Pgm().GetEditorName();
if( !editorname.IsEmpty() )
mainFrame->Execute( m_parent, editorname, FullFileName );
break;
mainFrame->Execute( m_parent, editorname, fullFileName );
}
break;
case TREE_PAGE_LAYOUT_DESCR:
mainFrame->Execute( m_parent, PL_EDITOR_EXE, FullFileName );
mainFrame->Execute( m_parent, PL_EDITOR_EXE, fullFileName );
break;
default:
OpenFile( FullFileName );
OpenFile( fullFileName );
break;
}
}
/*
* class_treeproject_item.h
*/
#ifndef TREEPROJECT_ITEM_H_
#define TREEPROJECT_ITEM_H_
/** class TREEPROJECT_ITEM
* Handle one item (a file or a directory name) for the tree file
/**
* Class TREEPROJECT_ITEM
* handles one item (a file or a directory name) for the tree file
*/
class TREEPROJECT_ITEM : public wxTreeItemData
{
public:
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;
friend class KICAD_MANAGER_FRAME;
public:
TREEPROJECT_ITEM( TreeFileType type, const wxString& data,
wxTreeCtrl* parent );
TREEPROJECT_ITEM() : m_parent( NULL ) { }
TREEPROJECT_ITEM( const TREEPROJECT_ITEM& src ) :
m_Type( src.m_Type ), m_FileName( src.m_FileName ), m_parent( src.m_parent )
{
SetState( src.m_state );
m_WasPopulated = false;
m_IsPopulated = false;
}
TreeFileType GetType() const
{
return m_Type;
}
TreeFileType GetType() const { return m_Type; }
void SetType( TreeFileType aType ) { m_Type = aType; }
void SetType( TreeFileType aType )
{
m_Type = aType;
}
const wxString& GetFileName() const { return m_FileName; }
void SetFileName( const wxString& name ) { m_FileName = name; }
wxString GetFileName() const
{
return m_FileName;
}
bool IsRootFile() const { return m_IsRootFile; }
void SetRootFile( bool aValue ) { m_IsRootFile = aValue; }
void SetFileName( const wxString& name )
{
m_FileName = name;
}
bool IsPopulated() const { return m_IsPopulated; }
void SetPopulated( bool aValue ) { m_IsPopulated = aValue; }
/**
* @return the path of an item.
* if this item is a directory, returns the stored filename
* if this is a file, returns its path
*/
wxString GetDir() const;
const wxString GetDir() const;
bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void Activate( TREE_PROJECT_FRAME* prjframe );
bool Rename( const wxString& name, bool check = true );
bool Delete( bool check = true );
void Activate( TREE_PROJECT_FRAME* prjframe );
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_
......@@ -83,8 +83,7 @@ TREEPROJECTFILES::TREEPROJECTFILES( TREE_PROJECT_FRAME* parent ) :
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* 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;
if( (myitem2->m_Type == TREE_DIRECTORY) && ( myitem1->m_Type != TREE_DIRECTORY ) )
if( myitem2->GetType() == TREE_DIRECTORY && myitem1->GetType() != TREE_DIRECTORY )
return 1;
if( myitem1->m_IsRootFile && !myitem2->m_IsRootFile )
if( myitem1->IsRootFile() && !myitem2->IsRootFile() )
return -1;
if( myitem2->m_IsRootFile && !myitem1->m_IsRootFile )
if( myitem2->IsRootFile() && !myitem1->IsRootFile() )
return 1;
return myitem1->m_FileName.CmpNoCase( myitem2->m_FileName );
return myitem1->GetFileName().CmpNoCase( myitem2->GetFileName() );
}
......@@ -41,8 +41,8 @@
#include <kicad.h>
static const wxString ZipFileExtension( wxT( "zip" ) );
static const wxString ZipFileWildcard( wxT( "Zip file (*.zip) | *.zip" ) );
#define ZipFileExtension wxT( "zip" )
#define ZipFileWildcard wxT( "Zip file (*.zip) | *.zip" )
void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
......@@ -53,14 +53,17 @@ void KICAD_MANAGER_FRAME::OnFileHistory( wxCommandEvent& event )
if( fn != wxEmptyString )
{
wxCommandEvent cmd( 0, wxID_ANY );
m_ProjectFileName = fn;
SetProjectFileName( fn );
OnLoadProject( cmd );
}
}
void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
{
wxFileName fn = m_ProjectFileName;
wxFileName fn = GetProjectFileName();
fn.SetExt( ZipFileExtension );
wxFileDialog dlg( this, _( "Unzip Project" ), fn.GetPath(),
......@@ -70,8 +73,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
if( dlg.ShowModal() == wxID_CANCEL )
return;
wxString msg;
msg.Printf( _("\nOpen <%s>\n" ), GetChars( dlg.GetPath() ) );
wxString msg = wxString::Format( _("\nOpen <%s>\n" ), GetChars( dlg.GetPath() ) );
PrintMsg( msg );
wxDirDialog dirDlg( this, _( "Target Directory" ), fn.GetPath(),
......@@ -85,6 +87,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
PrintMsg( msg );
wxFileSystem zipfilesys;
zipfilesys.AddHandler( new wxZipFSHandler );
zipfilesys.ChangePathTo( dlg.GetPath() + wxT( "#zip:" ) );
......@@ -94,7 +97,7 @@ void KICAD_MANAGER_FRAME::OnUnarchiveFiles( wxCommandEvent& event )
while( !localfilename.IsEmpty() )
{
zipfile = zipfilesys.OpenFile( localfilename );
if( zipfile == NULL )
if( !zipfile )
{
DisplayError( this, wxT( "Zip file read error" ) );
break;
......@@ -139,7 +142,7 @@ void KICAD_MANAGER_FRAME::OnArchiveFiles( wxCommandEvent& event )
};
wxString msg;
wxFileName fileName = m_ProjectFileName;
wxFileName fileName = GetProjectFileName();
wxString oldPath = wxGetCwd();
fileName.SetExt( wxT( "zip" ) );
......
......@@ -158,15 +158,15 @@ bool PGM_KICAD::OnPgmInit( wxApp* aWxApp )
bool prjloaded = false; // true when the project is loaded
if( App().argc > 1 )
frame->m_ProjectFileName = App().argv[1];
frame->SetProjectFileName( App().argv[1] );
else if( GetFileHistory().GetCount() )
{
// Try to open the last opened project,
// 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 );
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,
ProjectFileExtension );
frame->m_ProjectFileName = namelessProject;
frame->SetProjectFileName( namelessProject.GetFullPath() );
}
if( !prjloaded )
......@@ -218,23 +218,24 @@ void PGM_KICAD::MacOpenFile( const wxString& aFileName )
KICAD_MANAGER_FRAME* frame = (KICAD_MANAGER_FRAME*) GetTopWindow();
wxFileName fn = aFileName;
frame->SetProjectFile( aFileName );
frame->m_ProjectFileName = fn;
wxFileName fn = aFileName;
if( !frame->m_ProjectFileName.FileExists() && m_fileHistory.GetCount() )
if( !fn.FileExists() && m_fileHistory.GetCount() )
{
m_fileHistory.RemoveFileFromHistory( 0 );
return;
}
wxCommandEvent loadEvent;
loadEvent.SetId( wxID_ANY );
frame->OnLoadProject( loadEvent );
wxString title = GetTitle() + wxT( " " ) + GetBuildVersion() +
wxT( " " ) + frame->m_ProjectFileName.GetFullPath();
wxT( " " ) + frame->GetProjectFileName();
if( !fn.IsDirWritable() )
title += _( " [Read Only]" );
......
......@@ -120,28 +120,6 @@ enum id_kicad_frm {
*/
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:
KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& title,
const wxPoint& pos, const wxSize& size );
......@@ -211,7 +189,7 @@ public:
void OnUpdateDefaultPdfBrowser( wxUpdateUIEvent& event );
void OnUpdatePreferredPdfBrowser( wxUpdateUIEvent& event );
void CreateNewProject( const wxString aPrjFullFileName, bool aTemplateSelector );
void CreateNewProject( const wxString& aPrjFullFileName, bool aTemplateSelector );
void LoadSettings( wxConfigBase* aCfg );
......@@ -249,7 +227,32 @@ public:
void OnChangeWatchedPaths(wxCommandEvent& aEvent );
#endif
void SetProjectFileName( const wxString& aFullProjectProFileName );
const wxString GetProjectFileName();
// read only accessors
const wxString SchFileName();
const wxString PcbFileName();
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 );
};
......
......@@ -41,7 +41,6 @@
#include <wildcards_and_files_ext.h>
#include <menus_helpers.h>
#define USE_KIFACE 1
#define TreeFrameWidthEntry wxT( "LeftWinWidth" )
......@@ -125,6 +124,35 @@ wxConfigBase* KICAD_MANAGER_FRAME::config()
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()
{
......@@ -159,7 +187,7 @@ void KICAD_MANAGER_FRAME::OnCloseWindow( wxCloseEvent& Event )
{
int px, py;
UpdateFileHistory( m_ProjectFileName.GetFullPath(), &Pgm().GetFileHistory() );
UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() );
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 )
{
wxFileName legacy_board( m_ProjectFileName );
wxFileName kicad_board( m_ProjectFileName );
wxFileName kicad_board( PcbFileName() );
wxFileName legacy_board( GetProjectFileName() );
legacy_board.SetExt( LegacyPcbFileExtension );
kicad_board.SetExt( KiCadPcbFileExtension );
wxFileName& board = ( !legacy_board.FileExists() || kicad_board.FileExists() ) ?
kicad_board : legacy_board;
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_PCB, false );
if( !frame )
{
......@@ -256,19 +282,15 @@ void KICAD_MANAGER_FRAME::OnRunPcbNew( wxCommandEvent& event )
frame->Show( true );
}
frame->Raise();
#else
Execute( this, PCBNEW_EXE, QuoteFullPath( board ) );
#endif
}
void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
wxFileName fn( m_project_file_name );
fn.SetExt( NetlistFileExtension );
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_CVPCB, false );
if( !frame )
{
......@@ -277,19 +299,15 @@ void KICAD_MANAGER_FRAME::OnRunCvpcb( wxCommandEvent& event )
frame->Show( true );
}
frame->Raise();
#else
Execute( this, CVPCB_EXE, QuoteFullPath( fn ) );
#endif
}
void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
{
wxFileName fn( m_ProjectFileName );
wxFileName fn( m_project_file_name );
fn.SetExt( SchematicFileExtension );
#if USE_KIFACE
KIWAY_PLAYER* frame = Kiway.Player( FRAME_SCH, false );
if( !frame )
{
......@@ -298,20 +316,14 @@ void KICAD_MANAGER_FRAME::OnRunEeschema( wxCommandEvent& event )
frame->Show( true );
}
frame->Raise();
#else
Execute( this, EESCHEMA_EXE, QuoteFullPath( fn ) );
#endif
}
void KICAD_MANAGER_FRAME::OnRunGerbview( wxCommandEvent& event )
{
// Gerbview is called without any file to open, because we do not know
// the list and the name of files to open (if any...).
#if USE_KIFACE && 0
#else
Execute( this, GERBVIEW_EXE, wxEmptyString );
#endif
}
......@@ -392,7 +404,7 @@ void KICAD_MANAGER_FRAME::PrintPrjInfo()
wxString msg = wxString::Format( _(
"Working dir: %s\nProject: %s\n" ),
GetChars( wxGetCwd() ),
GetChars( m_ProjectFileName.GetFullPath() )
GetChars( GetProjectFileName() )
);
PrintMsg( msg );
}
......
......@@ -57,8 +57,8 @@
PARAM_CFG_ARRAY s_KicadManagerParams;
void KICAD_MANAGER_FRAME::CreateNewProject( const wxString aPrjFullFileName,
bool aTemplateSelector = false )
void KICAD_MANAGER_FRAME::CreateNewProject( const wxString& aPrjFullFileName,
bool aTemplateSelector = false )
{
wxString filename;
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
m_ProjectFileName = newProjectName;
SetProjectFileName( newProjectName.GetFullPath() );
// Write settings to project file
// 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 )
{
int style;
wxString title;
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
wxString title;
// this is still a mess, will work on it tomorrow.
ClearMsg();
if( event.GetId() != wxID_ANY )
{
int style;
bool newProject = ( event.GetId() == ID_NEW_PROJECT ) ||
( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE );
if( newProject )
{
title = _( "Create New Project" );
......@@ -207,21 +204,20 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
style = wxFD_OPEN | wxFD_FILE_MUST_EXIST;
}
wxString default_dir = wxGetCwd();
wxFileDialog dlg( this, title, default_dir, wxEmptyString,
ProjectFileWildcard, style );
wxString default_dir = wxGetCwd();
wxFileDialog dlg( this, title, default_dir, wxEmptyString,
ProjectFileWildcard, style );
if( dlg.ShowModal() == wxID_CANCEL )
return;
m_ProjectFileName = dlg.GetPath();
wxFileName pro( dlg.GetPath() );
pro.SetExt( ProjectFileExtension );
if( newProject )
{
m_ProjectFileName.SetExt( ProjectFileExtension );
// Check if the project directory is empty
wxDir directory ( m_ProjectFileName.GetPath() );
wxDir directory( pro.GetPath() );
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
// 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
m_ProjectFileName.RemoveLastDir();
pro.RemoveLastDir();
}
}
if( event.GetId() == ID_NEW_PROJECT )
{
CreateNewProject( m_ProjectFileName.GetFullPath() );
CreateNewProject( pro.GetFullPath() );
}
else if( event.GetId() == ID_NEW_PROJECT_FROM_TEMPLATE )
{
// 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 */
wxString filename = m_ProjectFileName.GetFullName();
// Check if project file exists and if it is not noname.pro
wxString filename = GetProjectFileName();
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(
_( "KiCad project file '%s' not found" ),
GetChars( m_ProjectFileName.GetFullPath() ) );
GetChars( GetProjectFileName() ) );
DisplayError( this, msg );
return;
}
wxSetWorkingDirectory( m_ProjectFileName.GetPath() );
wxSetWorkingDirectory( wxFileName( GetProjectFileName() ).GetPath() );
// was wxGetApp().ReadProjectConfig( m_ProjectFileName.GetFullPath(),
// GeneralGroupName, s_KicadManagerParams, false );
Prj().ConfigLoad( Pgm().SysSearch(), m_ProjectFileName.GetFullPath(),
Prj().ConfigLoad( Pgm().SysSearch(), GetProjectFileName(),
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]" );
SetTitle( title );
UpdateFileHistory( m_ProjectFileName.GetFullPath(), &Pgm().GetFileHistory() );
UpdateFileHistory( GetProjectFileName(), &Pgm().GetFileHistory() );
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,
// so we use it to run the rebuild function.
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_INIT_WATCHED_PATHS );
wxPostEvent( this, cmd);
wxPostEvent( this, cmd );
#endif
PrintPrjInfo();
......@@ -301,12 +300,11 @@ void KICAD_MANAGER_FRAME::OnLoadProject( wxCommandEvent& event )
void KICAD_MANAGER_FRAME::OnSaveProject( wxCommandEvent& event )
{
if( !IsWritable( m_ProjectFileName ) )
if( !wxIsWritable( GetProjectFileName() ) )
return;
// was: wxGetApp().WriteProjectConfig( m_ProjectFileName.GetFullPath(),
// GeneralGroupName, s_KicadManagerParams );
Prj().ConfigSave( Pgm().SysSearch(), m_ProjectFileName.GetFullPath(),
Prj().ConfigSave( Pgm().SysSearch(), GetProjectFileName(),
GeneralGroupName, s_KicadManagerParams );
}
This diff is collapsed.
......@@ -58,7 +58,12 @@ private:
public:
TREE_PROJECT_FRAME( KICAD_MANAGER_FRAME* parent );
~TREE_PROJECT_FRAME();
/**
* Create or modify the tree showing project file names
*/
void ReCreateTreePrj();
#ifdef KICAD_USE_FILES_WATCHER
/**
* Reinit the watched paths
......@@ -162,8 +167,8 @@ private:
bool aRecurse = true );
/**
* function findSubdirTreeItem
* Search for the item in tree project which is the
* Function findSubdirTreeItem
* searches 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.
......
......@@ -45,6 +45,7 @@ endif()
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/pcbnew
${BOOST_INCLUDE}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}
)
......
......@@ -58,7 +58,7 @@ int main( int argc, char** argv )
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
{
......
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