2012-02-11 09:04:26 +00:00
|
|
|
/**
|
|
|
|
* @file cvpcb/readwrite_dlgs.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <build_version.h>
|
2013-09-14 20:33:22 +00:00
|
|
|
#include <macros.h>
|
|
|
|
#include <fpid.h>
|
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <reporter.h>
|
|
|
|
#include <html_messagebox.h>
|
2012-02-11 09:04:26 +00:00
|
|
|
|
|
|
|
#include <cvpcb.h>
|
|
|
|
#include <cvpcb_mainframe.h>
|
|
|
|
#include <cvstruct.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2012-02-11 09:04:26 +00:00
|
|
|
|
|
|
|
#define titleComponentLibErr _( "Component Library Error" )
|
|
|
|
|
|
|
|
void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
COMPONENT* component;
|
2012-09-26 17:22:48 +00:00
|
|
|
bool hasFootprint = false;
|
|
|
|
int componentIndex;
|
|
|
|
wxString description;
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( m_netlist.IsEmpty() )
|
2012-02-11 09:04:26 +00:00
|
|
|
return;
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// If no component is selected, select the first one
|
|
|
|
if( m_ListCmp->GetFirstSelected() < 0 )
|
2012-02-11 09:04:26 +00:00
|
|
|
{
|
2012-09-26 17:22:48 +00:00
|
|
|
componentIndex = 0;
|
|
|
|
m_ListCmp->SetSelection( componentIndex, true );
|
2012-02-11 09:04:26 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
// iterate over the selection
|
2013-09-14 20:33:22 +00:00
|
|
|
while( m_ListCmp->GetFirstSelected() != -1 )
|
2012-09-26 15:36:48 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
// Get the component for the current iteration
|
2012-09-26 17:22:48 +00:00
|
|
|
componentIndex = m_ListCmp->GetFirstSelected();
|
2013-04-25 16:29:35 +00:00
|
|
|
component = m_netlist.GetComponent( componentIndex );
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
if( component == NULL )
|
|
|
|
return;
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// Check to see if the component has already a footprint set.
|
2013-09-08 18:31:21 +00:00
|
|
|
hasFootprint = !component->GetFPID().empty();
|
2012-09-26 15:36:48 +00:00
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
FPID fpid;
|
|
|
|
|
2013-09-17 15:51:05 +00:00
|
|
|
if( !aFootprintName.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( fpid.Parse( aFootprintName ) < 0,
|
|
|
|
wxString::Format( wxT( "<%s> is not a valid FPID." ),
|
|
|
|
GetChars( aFootprintName ) ) );
|
|
|
|
}
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
component->SetFPID( fpid );
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
// create the new component description
|
|
|
|
description.Printf( CMP_FORMAT, componentIndex + 1,
|
2013-04-25 16:29:35 +00:00
|
|
|
GetChars( component->GetReference() ),
|
|
|
|
GetChars( component->GetValue() ),
|
2013-09-08 18:31:21 +00:00
|
|
|
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
|
2012-09-26 17:22:48 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// If the component hasn't had a footprint associated with it
|
2012-09-26 17:22:48 +00:00
|
|
|
// it now has, so we decrement the count of components without
|
|
|
|
// a footprint assigned.
|
|
|
|
if( !hasFootprint )
|
|
|
|
{
|
|
|
|
hasFootprint = true;
|
|
|
|
m_undefinedComponentCnt -= 1;
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// Set the new description and deselect the processed component
|
2012-09-26 17:22:48 +00:00
|
|
|
m_ListCmp->SetString( componentIndex, description );
|
|
|
|
m_ListCmp->SetSelection( componentIndex, false );
|
2012-09-26 15:36:48 +00:00
|
|
|
}
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// Mark this "session" as modified
|
2012-09-26 15:36:48 +00:00
|
|
|
m_modified = true;
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
// select the next component, if there is one
|
|
|
|
if( componentIndex < (m_ListCmp->GetCount() - 1) )
|
|
|
|
componentIndex++;
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
m_ListCmp->SetSelection( componentIndex, true );
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2012-09-26 17:22:48 +00:00
|
|
|
// update the statusbar
|
|
|
|
DisplayStatus();
|
2012-02-11 09:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
COMPONENT* component;
|
2012-02-11 09:04:26 +00:00
|
|
|
wxString msg;
|
2013-09-14 20:33:22 +00:00
|
|
|
bool isLegacy = true;
|
2012-02-11 09:04:26 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
ReadSchematicNetlist();
|
2012-02-11 09:04:26 +00:00
|
|
|
|
|
|
|
if( m_ListCmp == NULL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
LoadProjectFile( m_NetlistFileName.GetFullPath() );
|
|
|
|
LoadFootprintFiles();
|
|
|
|
BuildFOOTPRINTS_LISTBOX();
|
2013-05-31 17:33:46 +00:00
|
|
|
BuildLIBRARY_LISTBOX();
|
2012-02-11 09:04:26 +00:00
|
|
|
|
|
|
|
m_ListCmp->Clear();
|
|
|
|
m_undefinedComponentCnt = 0;
|
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
if( m_netlist.AnyFootprintsLinked() )
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
component = m_netlist.GetComponent( i );
|
|
|
|
|
|
|
|
if( component->GetFPID().empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( isLegacy )
|
|
|
|
{
|
|
|
|
if( !component->GetFPID().IsLegacy() )
|
|
|
|
isLegacy = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isLegacy = false; // None of the components have footprints assigned.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined( USE_FP_LIB_TABLE )
|
|
|
|
wxString missingLibs;
|
|
|
|
|
|
|
|
// Check if footprint links were generated before the footprint library table was implemented.
|
|
|
|
if( isLegacy )
|
|
|
|
{
|
|
|
|
if( m_footprintLibTable->MissingLegacyLibs( m_ModuleLibNames, &missingLibs ) )
|
|
|
|
{
|
|
|
|
msg = wxT( "The following legacy libraries are defined in the project file "
|
|
|
|
"were not found in the footprint library table:\n\n" ) + missingLibs;
|
|
|
|
msg += wxT( "\nDo you want to update the footprint library table before "
|
|
|
|
"attempting to update the assigned footprints?" );
|
|
|
|
|
|
|
|
if( IsOK( this, msg ) )
|
|
|
|
{
|
|
|
|
wxCommandEvent cmd;
|
|
|
|
|
|
|
|
OnEditFootprintLibraryTable( cmd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = wxT( "Some or all of the assigned footprints contain legacy entries. Would you "
|
|
|
|
"like CvPcb to attempt to convert them to the new footprint library table "
|
|
|
|
"format?" );
|
|
|
|
|
|
|
|
if( IsOK( this, msg ) )
|
|
|
|
{
|
|
|
|
msg.Clear();
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
|
|
|
|
|
|
|
if( !m_footprintLibTable->ConvertFromLegacy( m_netlist, m_ModuleLibNames, &reporter ) )
|
|
|
|
{
|
|
|
|
HTML_MESSAGE_BOX dlg( this, wxEmptyString );
|
|
|
|
|
|
|
|
dlg.MessageSet( wxT( "The following errors occurred attempt to convert the "
|
|
|
|
"footprint assignments:\n\n" ) );
|
|
|
|
dlg.ListSet( msg );
|
|
|
|
dlg.MessageSet( wxT( "\nYou will need to reassign them manually if you want them "
|
|
|
|
"to be updated correctly the next time you import the "
|
|
|
|
"netlist in Pcbnew." ) );
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_modified = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Clear the legacy footprint assignments.
|
|
|
|
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
FPID emptyFPID;
|
|
|
|
component = m_netlist.GetComponent( i );
|
|
|
|
component->SetFPID( emptyFPID );
|
|
|
|
m_modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
|
2012-02-11 09:04:26 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
component = m_netlist.GetComponent( i );
|
|
|
|
|
2012-02-11 09:04:26 +00:00
|
|
|
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
|
2013-04-25 16:29:35 +00:00
|
|
|
GetChars( component->GetReference() ),
|
|
|
|
GetChars( component->GetValue() ),
|
2013-09-08 18:31:21 +00:00
|
|
|
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
|
2013-09-14 20:33:22 +00:00
|
|
|
|
2012-02-11 09:04:26 +00:00
|
|
|
m_ListCmp->AppendLine( msg );
|
|
|
|
|
2013-09-08 18:31:21 +00:00
|
|
|
if( component->GetFPID().empty() )
|
2013-09-14 20:33:22 +00:00
|
|
|
{
|
2012-02-11 09:04:26 +00:00
|
|
|
m_undefinedComponentCnt += 1;
|
2013-09-14 20:33:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-02-11 09:04:26 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( !m_netlist.IsEmpty() )
|
2012-02-11 09:04:26 +00:00
|
|
|
m_ListCmp->SetSelection( 0, true );
|
|
|
|
|
|
|
|
DisplayStatus();
|
|
|
|
|
|
|
|
UpdateTitle();
|
|
|
|
|
|
|
|
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
|
|
if( !aFullFileName.IsEmpty() )
|
|
|
|
{
|
|
|
|
fn = m_NetlistFileName;
|
|
|
|
fn.SetExt( ComponentFileExtension );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-04-29 16:50:10 +00:00
|
|
|
wxFileDialog dlg( this, _( "Save Component Footprint Link File" ), wxEmptyString,
|
|
|
|
_( "Unnamed file" ), ComponentFileWildcard, wxFD_SAVE );
|
2012-02-11 09:04:26 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
|
|
|
|
|
|
|
if( !fn.HasExt() )
|
|
|
|
fn.SetExt( ComponentFileExtension );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !IsWritable( fn.GetFullPath() ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( WriteComponentLinkFile( fn.GetFullPath() ) == 0 )
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
DisplayError( this, _( "Unable to create component footprint link file (.cmp)" ) );
|
2012-02-11 09:04:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg;
|
2012-02-15 16:28:33 +00:00
|
|
|
msg.Printf( _("File %s saved"), GetChars( fn.GetFullPath() ) );
|
2012-02-11 09:04:26 +00:00
|
|
|
SetStatusText( msg );
|
|
|
|
return 1;
|
|
|
|
}
|