2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file init.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "gr_basic.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "build_version.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
void CVPCB_MAINFRAME::SetNewPkg( const wxString& package )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
COMPONENT* Component;
|
|
|
|
bool isUndefined = false;
|
|
|
|
int NumCmp;
|
2010-11-07 20:06:07 +00:00
|
|
|
wxString msg;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( m_components.empty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
NumCmp = m_ListCmp->GetSelection();
|
2011-08-24 19:44:05 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( NumCmp < 0 )
|
|
|
|
{
|
|
|
|
NumCmp = 0;
|
2009-05-06 11:55:36 +00:00
|
|
|
m_ListCmp->SetSelection( NumCmp, true );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
Component = &m_components[ NumCmp ];
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( Component == NULL )
|
2009-02-04 15:25:03 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
isUndefined = Component->m_Module.IsEmpty();
|
|
|
|
|
|
|
|
Component->m_Module = package;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
msg.Printf( CMP_FORMAT, NumCmp + 1,
|
2011-08-24 19:44:05 +00:00
|
|
|
GetChars( Component->m_Reference ),
|
|
|
|
GetChars( Component->m_Value ),
|
|
|
|
GetChars( Component->m_Module ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
m_modified = true;
|
|
|
|
|
|
|
|
if( isUndefined )
|
|
|
|
m_undefinedComponentCnt -= 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
m_ListCmp->SetString( NumCmp, msg );
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->SetSelection( NumCmp, FALSE );
|
|
|
|
|
|
|
|
// We activate next component:
|
|
|
|
if( NumCmp < (m_ListCmp->GetCount() - 1) )
|
|
|
|
NumCmp++;
|
2011-08-24 19:44:05 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->SetSelection( NumCmp, TRUE );
|
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
DisplayStatus();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
bool CVPCB_MAINFRAME::ReadNetList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
wxString msg;
|
|
|
|
int error_level;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
error_level = ReadSchematicNetlist();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( error_level < 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-09-30 18:15:37 +00:00
|
|
|
msg.Printf( _( "File <%s> does not appear to be a valid KiCad net list file." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( m_NetlistFileName.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
::wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this );
|
2011-08-24 19:44:05 +00:00
|
|
|
m_NetlistFileName.Clear();
|
|
|
|
UpdateTitle();
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-21 18:27:47 +00:00
|
|
|
LoadComponentFile( m_NetlistFileName.GetFullPath() );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( m_ListCmp == NULL )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
LoadProjectFile( m_NetlistFileName.GetFullPath() );
|
2011-08-24 19:44:05 +00:00
|
|
|
LoadFootprintFiles();
|
2009-08-20 11:44:06 +00:00
|
|
|
BuildFOOTPRINTS_LISTBOX();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->Clear();
|
2009-04-23 15:02:18 +00:00
|
|
|
m_undefinedComponentCnt = 0;
|
2009-05-06 11:55:36 +00:00
|
|
|
|
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( component.m_Reference ),
|
|
|
|
GetChars( component.m_Value ),
|
|
|
|
GetChars( component.m_Module ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->AppendLine( msg );
|
2011-08-24 19:44:05 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( component.m_Module.IsEmpty() )
|
2009-04-23 15:02:18 +00:00
|
|
|
m_undefinedComponentCnt += 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( !m_components.empty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->SetSelection( 0, TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
DisplayStatus();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
UpdateTitle();
|
2011-04-17 17:11:53 +00:00
|
|
|
|
|
|
|
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
int CVPCB_MAINFRAME::SaveNetList( const wxString& aFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( !aFullFileName.IsEmpty() && m_NetlistFileName.IsOk() )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = m_NetlistFileName;
|
2011-08-24 19:44:05 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2011-08-24 19:44:05 +00:00
|
|
|
{
|
|
|
|
wxFileDialog dlg( this, _( "Save Net and Component List" ), wxGetCwd(),
|
|
|
|
wxEmptyString, NetlistFileWildcard, wxFD_SAVE );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( !fn.HasExt() )
|
|
|
|
fn.SetExt( NetlistFileExtension );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
m_NetlistFileName = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !IsWritable( fn.GetFullPath() ) )
|
|
|
|
return 0;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
if( SaveComponentList( fn.GetFullPath() ) == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Unable to create component file (.cmp)" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-24 19:44:05 +00:00
|
|
|
FILE* netlist = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( netlist == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-11-05 19:26:52 +00:00
|
|
|
DisplayError( this, _( "Unable to create net list file" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-21 18:27:47 +00:00
|
|
|
GenNetlistPcbnew( netlist, m_isEESchemaNetlist );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|