2009-02-04 15:25:03 +00:00
|
|
|
/*******************************************************************/
|
|
|
|
/* CVPCB: Routines de base : */
|
|
|
|
/* lecture Netliste et creation des fenetres composants et modules */
|
|
|
|
/*******************************************************************/
|
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"
|
|
|
|
#include "id.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* routines locales : */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-02-04 15:25:03 +00:00
|
|
|
* - Affecte un module au composant selectionne
|
|
|
|
* - Selectionne le composant suivant
|
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
void WinEDA_CvpcbFrame::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;
|
|
|
|
wxString Line;
|
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();
|
|
|
|
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
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
Line.Printf( CMP_FORMAT, NumCmp + 1,
|
2009-05-06 11:55:36 +00:00
|
|
|
Component->m_Reference.GetData(), Component->m_Value.GetData(),
|
2009-04-23 15:02:18 +00:00
|
|
|
Component->m_Module.GetData() );
|
|
|
|
m_modified = true;
|
|
|
|
|
|
|
|
if( isUndefined )
|
|
|
|
m_undefinedComponentCnt -= 1;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
m_ListCmp->SetString( NumCmp, Line );
|
|
|
|
m_ListCmp->SetSelection( NumCmp, FALSE );
|
|
|
|
|
|
|
|
// We activate next component:
|
|
|
|
if( NumCmp < (m_ListCmp->GetCount() - 1) )
|
|
|
|
NumCmp++;
|
|
|
|
m_ListCmp->SetSelection( NumCmp, TRUE );
|
|
|
|
|
|
|
|
Line.Printf( _( "Components: %d (free: %d)" ),
|
2009-05-06 11:55:36 +00:00
|
|
|
m_components.size(), m_undefinedComponentCnt );
|
2009-02-04 15:25:03 +00:00
|
|
|
SetStatusText( Line, 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
|
|
|
* Lecture de la netliste selon format, ainsi que du fichier des composants
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
bool WinEDA_CvpcbFrame::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
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "File <%s> does not appear to be a valid Kicad net list file." ),
|
2009-04-05 20:49:15 +00:00
|
|
|
m_NetlistFileName.GetFullPath().c_str() );
|
|
|
|
::wxMessageBox( msg, _( "File Error" ), wxOK | wxICON_ERROR, this );
|
|
|
|
return false;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
/* lecture des correspondances */
|
2009-04-23 15:02:18 +00:00
|
|
|
LoadComponentFile( m_NetlistFileName.GetFullPath(), m_components );
|
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() );
|
|
|
|
LoadFootprintFiles( m_ModuleLibNames, m_footprints );
|
2009-02-04 15:25:03 +00:00
|
|
|
BuildFootprintListBox();
|
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-05-06 11:55:36 +00:00
|
|
|
component.m_Reference.GetData(),
|
|
|
|
component.m_Value.GetData(),
|
|
|
|
component.m_Module.GetData() );
|
2009-02-04 15:25:03 +00:00
|
|
|
m_ListCmp->AppendLine( msg );
|
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
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
msg.Printf( _( "Components: %d (free: %d)" ), m_components.size(),
|
2009-04-23 15:02:18 +00:00
|
|
|
m_undefinedComponentCnt );
|
2009-02-04 15:25:03 +00:00
|
|
|
SetStatusText( msg, 1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
/* Mise a jour du titre de la fenetre principale */
|
2009-04-05 20:49:15 +00:00
|
|
|
SetTitle( wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion() +
|
|
|
|
wxT( " " ) + m_NetlistFileName.GetFullPath() );
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
|
|
|
* Sauvegarde des fichiers netliste et cmp
|
2009-02-04 15:25:03 +00:00
|
|
|
* Le nom complet du fichier Netliste doit etre dans FFileName.
|
|
|
|
* Le nom du fichier cmp en est deduit
|
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
int WinEDA_CvpcbFrame::SaveNetList( const wxString& fileName )
|
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
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !fileName && m_NetlistFileName.IsOk() )
|
|
|
|
fn = m_NetlistFileName;
|
|
|
|
else
|
|
|
|
fn = wxFileName( wxGetCwd(), _( "unamed" ), NetExtBuffer );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Save Net and Component List" ), fn.GetPath(),
|
|
|
|
fn.GetFullName(), NetlistFileWildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-02-04 15:25:03 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( SaveComponentList( dlg.GetPath() ) == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Unable to create component file (.cmp)" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
FILE* netlist = wxFopen( dlg.GetPath(), wxT( "wt" ) );
|
|
|
|
|
|
|
|
if( netlist == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
DisplayError( this, _( "Unable to create netlist file" ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
GenNetlistPcbnew( netlist, m_components, m_isEESchemaNetlist,
|
|
|
|
m_rightJustify );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|