Error reporting for drawing sheet loading.
This commit is contained in:
parent
26b86b3922
commit
080cbbe0dd
|
@ -43,6 +43,7 @@
|
|||
#include <wx/filedlg.h>
|
||||
#include <wx/dcmemory.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <confirm.h>
|
||||
|
||||
#define MAX_PAGE_EXAMPLE_SIZE 200
|
||||
|
||||
|
@ -461,23 +462,23 @@ void DIALOG_PAGES_SETTINGS::OnDateApplyClick( wxCommandEvent& event )
|
|||
bool DIALOG_PAGES_SETTINGS::SavePageSettings()
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
wxString msg;
|
||||
wxString fileName = GetWksFileName();
|
||||
|
||||
if( fileName != BASE_SCREEN::m_DrawingSheetFileName )
|
||||
{
|
||||
wxString fullFileName = DS_DATA_MODEL::ResolvePath( fileName, m_projectPath );
|
||||
|
||||
if( !fullFileName.IsEmpty() && !wxFileExists( fullFileName ) )
|
||||
BASE_SCREEN::m_DrawingSheetFileName = fileName;
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( fullFileName, &msg ) )
|
||||
{
|
||||
wxString msg;
|
||||
msg.Printf( _( "Drawing sheet file '%s' not found." ), fullFileName );
|
||||
wxMessageBox( msg );
|
||||
return false;
|
||||
DisplayErrorMessage( this,
|
||||
wxString::Format( _( "Error loading drawing sheet '%s'." ),
|
||||
fullFileName ),
|
||||
msg );
|
||||
}
|
||||
|
||||
BASE_SCREEN::m_DrawingSheetFileName = fileName;
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( fullFileName );
|
||||
m_localPrjConfigChanged = true;
|
||||
}
|
||||
|
||||
|
@ -776,6 +777,7 @@ void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
|
|||
wxFileName fn = GetWksFileName();
|
||||
wxString name = fn.GetFullName();
|
||||
wxString path;
|
||||
wxString msg;
|
||||
|
||||
if( fn.IsAbsolute() )
|
||||
{
|
||||
|
@ -817,8 +819,15 @@ void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
|
|||
|
||||
std::unique_ptr<DS_DATA_MODEL> ws = std::make_unique<DS_DATA_MODEL>();
|
||||
|
||||
if( ws->LoadDrawingSheet( fileName ) )
|
||||
if( !ws->LoadDrawingSheet( fileName, &msg ) )
|
||||
{
|
||||
DisplayErrorMessage( this,
|
||||
wxString::Format( _( "Error loading drawing sheet '%s'.\n%s" ),
|
||||
fileName ),
|
||||
msg );
|
||||
return;
|
||||
}
|
||||
|
||||
delete m_drawingSheet;
|
||||
|
||||
m_drawingSheet = ws.release();
|
||||
|
@ -827,5 +836,4 @@ void DIALOG_PAGES_SETTINGS::OnWksFileSelection( wxCommandEvent& event )
|
|||
|
||||
GetPageLayoutInfoFromDialog();
|
||||
UpdateDrawingSheetExample();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -959,30 +959,34 @@ void DS_DATA_MODEL::SetPageLayout( const char* aPageLayout, bool Append, const w
|
|||
}
|
||||
|
||||
|
||||
bool DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append )
|
||||
bool DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, wxString* aMsg, bool aAppend )
|
||||
{
|
||||
wxString fullFileName = aFullFileName;
|
||||
|
||||
if( !Append )
|
||||
if( !aAppend )
|
||||
{
|
||||
if( fullFileName.IsEmpty() )
|
||||
if( aFullFileName.IsEmpty() )
|
||||
{
|
||||
SetDefaultLayout();
|
||||
return true; // we assume its fine / default init
|
||||
}
|
||||
|
||||
if( !wxFileExists( fullFileName ) )
|
||||
if( !wxFileExists( aFullFileName ) )
|
||||
{
|
||||
if( aMsg )
|
||||
*aMsg = _( "File not found." );
|
||||
|
||||
SetDefaultLayout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
wxFFile wksFile( fullFileName, wxS( "rb" ) );
|
||||
wxFFile wksFile( aFullFileName, wxS( "rb" ) );
|
||||
|
||||
if( ! wksFile.IsOpened() )
|
||||
{
|
||||
if( !Append )
|
||||
if( aMsg )
|
||||
*aMsg = _( "File could not be opened." );
|
||||
|
||||
if( !aAppend )
|
||||
SetDefaultLayout();
|
||||
|
||||
return false;
|
||||
|
@ -993,23 +997,36 @@ bool DS_DATA_MODEL::LoadDrawingSheet( const wxString& aFullFileName, bool Append
|
|||
|
||||
if( wksFile.Read( buffer.get(), filelen ) != filelen )
|
||||
{
|
||||
if( aMsg )
|
||||
*aMsg = _( "Drawing sheet was not fully read." );
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer[filelen]=0;
|
||||
|
||||
if( ! Append )
|
||||
if( ! aAppend )
|
||||
ClearList();
|
||||
|
||||
DRAWING_SHEET_PARSER parser( buffer.get(), fullFileName );
|
||||
DRAWING_SHEET_PARSER parser( buffer.get(), aFullFileName );
|
||||
|
||||
try
|
||||
{
|
||||
parser.Parse( this );
|
||||
}
|
||||
catch( ... )
|
||||
catch( const IO_ERROR& ioe )
|
||||
{
|
||||
if( aMsg )
|
||||
*aMsg = ioe.What();
|
||||
|
||||
return false;
|
||||
}
|
||||
catch( const std::bad_alloc& )
|
||||
{
|
||||
if( aMsg )
|
||||
*aMsg = _( "Ran out of memory." );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -552,7 +552,7 @@ void DS_DRAW_ITEM_LIST::BuildDrawItemsList( const PAGE_INFO& aPageInfo,
|
|||
|
||||
// Build the basic layout shape, if the layout list is empty
|
||||
if( model.GetCount() == 0 && !model.VoidListAllowed() )
|
||||
model.LoadDrawingSheet();
|
||||
model.LoadDrawingSheet( wxEmptyString, nullptr );
|
||||
|
||||
model.SetupDrawEnvironment( aPageInfo, GetMilsToIUfactor() );
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ bool SCH_EDIT_FRAME::LoadProjectSettings()
|
|||
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
||||
Prj().GetProjectPath() );
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, nullptr ) )
|
||||
ShowInfoBarError( _( "Error loading drawing sheet." ), true );
|
||||
|
||||
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
|
||||
|
|
|
@ -113,11 +113,13 @@ void EESCHEMA_JOBS_HANDLER::InitRenderSettings( SCH_RENDER_SETTINGS* aRenderSett
|
|||
{
|
||||
wxString absolutePath = DS_DATA_MODEL::ResolvePath( path,
|
||||
aSch->Prj().GetProjectPath() );
|
||||
wxString msg;
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath ) )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( absolutePath, &msg ) )
|
||||
{
|
||||
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ),
|
||||
path ),
|
||||
path )
|
||||
+ wxS( "\n" ) + msg + wxS( "\n" ),
|
||||
RPT_SEVERITY_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -149,9 +149,10 @@ public:
|
|||
* @param aFullFileName is the custom drawing sheet file. If empty, load the file defined by
|
||||
* KICAD_WKSFILE and if its not defined, the default internal drawing
|
||||
* sheet.
|
||||
* @param Append if true: do not delete old layout, and load only \a aFullFileName.
|
||||
* @param aMsg [optional] if non-null, will be filled with any error messages.
|
||||
* @param aAppend if true: do not delete old layout, and load only \a aFullFileName.
|
||||
*/
|
||||
bool LoadDrawingSheet( const wxString& aFullFileName = wxEmptyString, bool Append = false );
|
||||
bool LoadDrawingSheet( const wxString& aFullFileName, wxString* aMsg, bool aAppend = false );
|
||||
|
||||
/**
|
||||
* Populate the list from a S expr description stored in a string.
|
||||
|
|
|
@ -235,13 +235,14 @@ bool PL_EDITOR_FRAME::LoadDrawingSheetFile( const wxString& aFullFileName )
|
|||
{
|
||||
if( wxFileExists( aFullFileName ) )
|
||||
{
|
||||
bool loaded = false;
|
||||
wxString msg;
|
||||
|
||||
loaded = DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName );
|
||||
|
||||
if( !loaded )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName, &msg ) )
|
||||
{
|
||||
ShowInfoBarError( _( "Error reading drawing sheet" ), true );
|
||||
DisplayErrorMessage( this,
|
||||
wxString::Format( _( "Error loading drawing sheet '%s'." ),
|
||||
aFullFileName ),
|
||||
msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -282,7 +283,7 @@ bool PL_EDITOR_FRAME::InsertDrawingSheetFile( const wxString& aFullFileName )
|
|||
{
|
||||
const bool append = true;
|
||||
SaveCopyInUndoList();
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName, append );
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( aFullFileName, nullptr, append );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|||
DS_DATA_MODEL::GetTheInstance().AllowVoidList( true );
|
||||
DS_DATA_MODEL::GetTheInstance().ClearList();
|
||||
#else // start with the default KiCad layout
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet();
|
||||
DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( wxEmptyString, nullptr );
|
||||
#endif
|
||||
OnNewDrawingSheet();
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ bool PCB_EDIT_FRAME::LoadProjectSettings()
|
|||
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
||||
Prj().GetProjectPath());
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, nullptr ) )
|
||||
ShowInfoBarError( _( "Error loading drawing sheet." ), true );
|
||||
|
||||
// Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
|
||||
|
|
|
@ -1553,11 +1553,13 @@ void PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet( BOARD* aBrd, const wxString&
|
|||
BASE_SCREEN::m_DrawingSheetFileName = path;
|
||||
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
||||
aBrd->GetProject()->GetProjectPath() );
|
||||
wxString msg;
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
|
||||
{
|
||||
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ) + wxS( "\n" ),
|
||||
path ),
|
||||
m_reporter->Report( wxString::Format( _( "Error loading drawing sheet '%s'." ),
|
||||
path )
|
||||
+ wxS( "\n" ) + msg + wxS( "\n" ),
|
||||
RPT_SEVERITY_ERROR );
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -184,7 +184,7 @@ BOARD* LoadBoard( wxString& aFileName, PCB_IO_MGR::PCB_FILE_T aFormat, bool aSet
|
|||
wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
|
||||
project->GetProjectPath() );
|
||||
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
|
||||
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, nullptr ) )
|
||||
wxFprintf( stderr, _( "Error loading drawing sheet." ) );
|
||||
|
||||
BOARD* brd = PCB_IO_MGR::Load( aFormat, aFileName );
|
||||
|
|
Loading…
Reference in New Issue