Commit 40119534 authored by Dick Hollenbeck's avatar Dick Hollenbeck

Jettison FP_LIB_TABLE::ConvertFromLegacy() into a static function, where it

was used locally.  Then comment it out in favor of a newer strategy for
filling in nicknames in cvpcb. 

Add MODULE* FootprintLoadWithOptionalNickname( const FPID& aFootprintId )
        throw( IO_ERROR, PARSE_ERROR );
from code found elsewhere.
parent d053e561
...@@ -638,164 +638,41 @@ const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString& aString ) ...@@ -638,164 +638,41 @@ const wxString FP_LIB_TABLE::ExpandSubstitutions( const wxString& aString )
bool FP_LIB_TABLE::IsEmpty( bool aIncludeFallback ) bool FP_LIB_TABLE::IsEmpty( bool aIncludeFallback )
{ {
if( !aIncludeFallback || (fallBack == NULL) ) if( !aIncludeFallback || !fallBack )
return rows.empty(); return rows.empty();
return fallBack->IsEmpty() && rows.empty(); return rows.empty() && fallBack->IsEmpty( true );
} }
bool FP_LIB_TABLE::ConvertFromLegacy( SEARCH_STACK& aSStack, NETLIST& aNetList, MODULE* FP_LIB_TABLE::FootprintLoadWithOptionalNickname( const FPID& aFootprintId )
const wxArrayString& aLibNames, REPORTER* aReporter ) throw( IO_ERROR ) throw( IO_ERROR, PARSE_ERROR )
{ {
wxString msg; wxString nickname = aFootprintId.GetLibNickname();
FPID lastFPID; wxString fpname = aFootprintId.GetFootprintName();
COMPONENT* component;
MODULE* module = 0;
bool retv = true;
if( aNetList.IsEmpty() ) if( nickname.size() )
return true;
aNetList.SortByFPID();
wxString libPath;
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
for( unsigned ii = 0; ii < aNetList.GetCount(); ii++ )
{ {
component = aNetList.GetComponent( ii ); return FootprintLoad( nickname, fpname );
}
// The footprint hasn't been assigned yet so ignore it.
if( component->GetFPID().empty() )
continue;
if( component->GetFPID() != lastFPID )
{
module = NULL;
for( unsigned ii = 0; ii < aLibNames.GetCount(); ii++ )
{
wxFileName fn( wxEmptyString, aLibNames[ii], LegacyFootprintLibPathExtension );
libPath = aSStack.FindValidPath( fn.GetFullPath() );
if( !libPath )
{
if( aReporter )
{
msg.Printf( _( "Cannot find footprint library file '%s' in any of the "
"KiCad legacy library search paths.\n" ),
GetChars( fn.GetFullPath() ) );
aReporter->Report( msg );
}
retv = false;
continue;
}
module = pi->FootprintLoad( libPath, component->GetFPID().GetFootprintName() );
if( module ) // nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
{ else
lastFPID = component->GetFPID(); {
break; std::vector<wxString> nicks = GetLogicalLibs();
}
}
}
if( !module ) // Search each library going through libraries alphabetically.
for( unsigned i = 0; i<nicks.size(); ++i )
{ {
if( aReporter ) // FootprintLoad() returns NULL on not found, does not throw exception
{ // unless there's an IO_ERROR.
msg.Printf( _( "Component `%s` footprint '%s' was not found in any legacy " MODULE* ret = FootprintLoad( nicks[i], fpname );
"library.\n" ), if( ret )
GetChars( component->GetReference() ), return ret;
GetChars( component->GetFPID().Format() ) );
aReporter->Report( msg );
}
// Clear the footprint assignment since the old library lookup method is no
// longer valid.
FPID emptyFPID;
component->SetFPID( emptyFPID );
retv = false;
continue;
} }
else
{
wxString libNickname;
FP_LIB_TABLE* cur = this; return NULL;
do
{
cur->ensureIndex();
for( unsigned i = 0; i < cur->rows.size(); i++ )
{
wxString uri = cur->rows[i].GetFullURI( true );
if( wxFileName::GetPathSeparator() == wxChar( '\\' )
&& uri.Find( wxChar( '/' ) ) >= 0 )
{
uri.Replace( wxT( "/"), wxT( "\\" ) );
}
#ifdef __WINDOWS__
if( uri.CmpNoCase( libPath ) )
#else
if( uri == libPath )
#endif
{
libNickname = cur->rows[i].GetNickName();
break;
}
}
} while( ( cur = cur->fallBack ) != 0 && libNickname.IsEmpty() );
if( libNickname.IsEmpty() )
{
if( aReporter )
{
msg.Printf( _( "Component '%s' footprint '%s' legacy library path '%s' "
"was not found in the footprint library table.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().Format() ) );
aReporter->Report( msg );
}
retv = false;
}
else
{
FPID newFPID = lastFPID;
newFPID.SetLibNickname( libNickname );
if( !newFPID.IsValid() )
{
if( aReporter )
{
msg.Printf( _( "Component '%s' FPID '%s' is not valid.\n" ),
GetChars( component->GetReference() ),
GetChars( newFPID.Format() ) );
aReporter->Report( msg );
}
retv = false;
}
else
{
// The footprint name should already be set.
component->SetFPID( newFPID );
}
}
}
} }
return retv;
} }
...@@ -827,17 +704,14 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARS ...@@ -827,17 +704,14 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARS
// The fallback is to create an empty global footprint table for the user to populate. // The fallback is to create an empty global footprint table for the user to populate.
if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) ) if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
{ {
FP_LIB_TABLE emptyTable; FP_LIB_TABLE emptyTable;
FILE_OUTPUTFORMATTER sf( fn.GetFullPath() );
emptyTable.Format( &sf, 0 ); emptyTable.Save( fn.GetFullPath() );
} }
} }
FILE_LINE_READER reader( fn.GetFullPath() ); aTable.Load( fn.GetFullPath() );
FP_LIB_TABLE_LEXER lexer( &reader );
aTable.Parse( &lexer );
return tableExists; return tableExists;
} }
......
...@@ -744,7 +744,7 @@ void WORKSHEET_LAYOUT::SetDefaultLayout() ...@@ -744,7 +744,7 @@ void WORKSHEET_LAYOUT::SetDefaultLayout()
{ {
lp_parser.Parse( this ); lp_parser.Parse( this );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogMessage( ioe.errorText ); wxLogMessage( ioe.errorText );
} }
...@@ -765,7 +765,7 @@ void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append ) ...@@ -765,7 +765,7 @@ void WORKSHEET_LAYOUT::SetPageLayout( const char* aPageLayout, bool Append )
{ {
lp_parser.Parse( this ); lp_parser.Parse( this );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogMessage( ioe.errorText ); wxLogMessage( ioe.errorText );
} }
...@@ -828,7 +828,7 @@ void WORKSHEET_LAYOUT::SetPageLayout( const wxString& aFullFileName, bool Append ...@@ -828,7 +828,7 @@ void WORKSHEET_LAYOUT::SetPageLayout( const wxString& aFullFileName, bool Append
{ {
lp_parser.Parse( this ); lp_parser.Parse( this );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogMessage( ioe.errorText ); wxLogMessage( ioe.errorText );
} }
......
...@@ -490,7 +490,7 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName ) ...@@ -490,7 +490,7 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
footprint = FootprintLibs()->FootprintLoad( FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) ); footprint = FootprintLibs()->FootprintLoad( FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return NULL; return NULL;
......
...@@ -846,7 +846,7 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist() ...@@ -846,7 +846,7 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist()
else else
wxMessageBox( _( "Unknown netlist format." ), wxEmptyString, wxOK | wxICON_ERROR ); wxMessageBox( _( "Unknown netlist format." ), wxEmptyString, wxOK | wxICON_ERROR );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() ); msg = wxString::Format( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
......
...@@ -171,6 +171,164 @@ static bool missingLegacyLibs( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack, ...@@ -171,6 +171,164 @@ static bool missingLegacyLibs( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack,
} }
#if 0
/*
This code block was based on two major assumptions that are no longer true:
1) Footprint library basenames would remain the same.
(But no, basenames have been renamed in the github repo.)
2) *.mod files would still be around and merely reside in the FP_LIB_TABLE.
(But no, they have been converted to *.pretty.)
There is a newer replacement code block in the #else region.
*/
/**
* Function convertFromLegacy
* converts the footprint names in \a aNetList from the legacy format to the #FPID format.
*
* @param aNetList is the #NETLIST object to convert.
* @param aLibNames is the list of legacy footprint library names from the currently loaded
* project.
* @param aReporter is the #REPORTER object to dump messages into.
* @return true if all footprint names were successfully converted to a valid FPID.
*/
static bool convertFromLegacy( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack, NETLIST& aNetList,
const wxArrayString& aLibNames, REPORTER* aReporter = NULL ) throw( IO_ERROR )
{
wxString msg;
FPID lastFPID;
COMPONENT* component;
MODULE* module = 0;
bool retv = true;
if( aNetList.IsEmpty() )
return true;
aNetList.SortByFPID();
wxString libPath;
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
for( unsigned ii = 0; ii < aNetList.GetCount(); ii++ )
{
component = aNetList.GetComponent( ii );
// The footprint hasn't been assigned yet so ignore it.
if( component->GetFPID().empty() )
continue;
if( component->GetFPID() != lastFPID )
{
module = NULL;
for( unsigned ii = 0; ii < aLibNames.GetCount(); ii++ )
{
wxFileName fn( wxEmptyString, aLibNames[ii], LegacyFootprintLibPathExtension );
libPath = aSStack.FindValidPath( fn.GetFullPath() );
if( !libPath )
{
if( aReporter )
{
msg.Printf( _( "Cannot find footprint library file '%s' in any of the "
"KiCad legacy library search paths.\n" ),
GetChars( fn.GetFullPath() ) );
aReporter->Report( msg );
}
retv = false;
continue;
}
module = pi->FootprintLoad( libPath, component->GetFPID().GetFootprintName() );
if( module )
{
lastFPID = component->GetFPID();
break;
}
}
}
if( !module )
{
if( aReporter )
{
msg.Printf( _( "Component '%s' footprint '%s' was not found in any legacy "
"library.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().Format() ) );
aReporter->Report( msg );
}
// Clear the footprint assignment since the old library lookup method is no
// longer valid.
FPID emptyFPID;
component->SetFPID( emptyFPID );
retv = false;
continue;
}
else
{
wxString libNickname;
const FP_LIB_TABLE::ROW* row;
if( ( row = aTbl->FindRowByURI( libPath ) ) != NULL )
libNickname = row->GetNickName();
if( libNickname.IsEmpty() )
{
if( aReporter )
{
msg.Printf( _( "Component '%s' with footprint '%s' and legacy library path '%s' "
"was not found in the footprint library table.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().Format() ),
GetChars( libPath )
);
aReporter->Report( msg );
}
retv = false;
}
else
{
FPID newFPID = lastFPID;
newFPID.SetLibNickname( libNickname );
if( !newFPID.IsValid() )
{
if( aReporter )
{
msg.Printf( _( "Component '%s' FPID '%s' is not valid.\n" ),
GetChars( component->GetReference() ),
GetChars( newFPID.Format() ) );
aReporter->Report( msg );
}
retv = false;
}
else
{
// The footprint name should already be set.
component->SetFPID( newFPID );
}
}
}
}
return retv;
}
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
{ {
COMPONENT* component; COMPONENT* component;
...@@ -242,7 +400,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() ...@@ -242,7 +400,7 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
SEARCH_STACK& search = Prj().SchSearchS(); SEARCH_STACK& search = Prj().SchSearchS();
if( !FootprintLibs()->ConvertFromLegacy( search, m_netlist, m_ModuleLibNames, &reporter ) ) if( !convertFromLegacy( FootprintLibs(), search, m_netlist, m_ModuleLibNames, &reporter ) )
{ {
HTML_MESSAGE_BOX dlg( this, wxEmptyString ); HTML_MESSAGE_BOX dlg( this, wxEmptyString );
...@@ -300,6 +458,193 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() ...@@ -300,6 +458,193 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
return true; return true;
} }
#else // new strategy
/// Return true if the resultant FPID has a certain nickname. The guess
/// is only made if this footprint resides in only one library.
/// @return int - 0 on success, 1 on not found, 2 on ambiguous i.e. multiple matches
static int guessNickname( FP_LIB_TABLE* aTbl, FPID* aFootprintId )
{
if( aFootprintId->GetLibNickname().size() )
return 0;
wxString nick;
wxString fpname = aFootprintId->GetFootprintName();
std::vector<wxString> nicks = aTbl->GetLogicalLibs();
// Search each library going through libraries alphabetically.
for( unsigned libNdx = 0; libNdx<nicks.size(); ++libNdx )
{
wxArrayString fpnames = aTbl->FootprintEnumerate( nicks[libNdx] );
for( unsigned nameNdx = 0; nameNdx<fpnames.size(); ++nameNdx )
{
if( fpname == fpnames[nameNdx] )
{
if( !nick )
nick = nicks[libNdx];
else
return 2; // duplicate, the guess would not be certain
}
}
}
if( nick.size() )
{
aFootprintId->SetLibNickname( nick );
return 0;
}
return 1;
}
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
{
wxString msg;
bool hasMissingNicks = false;
FP_LIB_TABLE* tbl = FootprintLibs();
ReadSchematicNetlist();
if( m_ListCmp == NULL )
return false;
LoadProjectFile( m_NetlistFileName.GetFullPath() );
LoadFootprintFiles();
BuildFOOTPRINTS_LISTBOX();
BuildLIBRARY_LISTBOX();
m_ListCmp->Clear();
m_undefinedComponentCnt = 0;
if( m_netlist.AnyFootprintsLinked() )
{
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
COMPONENT* component = m_netlist.GetComponent( i );
if( component->GetFPID().empty() )
continue;
if( component->GetFPID().IsLegacy() )
hasMissingNicks = true;
}
}
// Check if footprint links were generated before the footprint library table was implemented.
if( hasMissingNicks )
{
msg = wxT(
"Some of the assigned footprints are legacy entries (are missing lib nicknames). "
"Would you like CvPcb to attempt to convert them to the new required FPID format? "
"(If you answer no, then these assignments will be cleared out and you will "
"have to re-assign these footprints yourself.)"
);
if( IsOK( this, msg ) )
{
msg.Clear();
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
COMPONENT* component = m_netlist.GetComponent( i );
if( component->GetFPID().IsLegacy() )
{
int guess = guessNickname( tbl, (FPID*) &component->GetFPID() );
switch( guess )
{
case 0:
DBG(printf("%s: guessed OK ref:%s fpid:%s\n", __func__,
TO_UTF8( component->GetReference() ), component->GetFPID().Format().c_str() );)
m_modified = true;
break;
case 1:
msg += wxString::Format( _(
"Component '%s' footprint '%s' was <b>not found</b> in any library.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().GetFootprintName() )
);
break;
case 2:
msg += wxString::Format( _(
"Component '%s' footprint '%s' was found in <b>multiple</b> libraries.\n" ),
GetChars( component->GetReference() ),
GetChars( component->GetFPID().GetFootprintName() )
);
break;
}
}
}
if( msg.size() )
{
HTML_MESSAGE_BOX dlg( this, wxEmptyString );
dlg.MessageSet( wxT( "The following errors occurred attempting 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();
}
}
else
{
// Clear the legacy footprint assignments.
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
COMPONENT* component = m_netlist.GetComponent( i );
if( component->GetFPID().IsLegacy() )
{
component->SetFPID( FPID() /* empty */ );
m_modified = true;
}
}
}
}
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
COMPONENT* component = m_netlist.GetComponent( i );
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
GetChars( component->GetReference() ),
GetChars( component->GetValue() ),
GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
m_ListCmp->AppendLine( msg );
if( component->GetFPID().empty() )
{
m_undefinedComponentCnt += 1;
continue;
}
}
if( !m_netlist.IsEmpty() )
m_ListCmp->SetSelection( 0, true );
DisplayStatus();
UpdateTitle();
UpdateFileHistory( m_NetlistFileName.GetFullPath() );
return true;
}
#endif
int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName ) int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
{ {
......
...@@ -136,7 +136,7 @@ bool LIB_ALIAS::SaveDoc( OUTPUTFORMATTER& aFormatter ) ...@@ -136,7 +136,7 @@ bool LIB_ALIAS::SaveDoc( OUTPUTFORMATTER& aFormatter )
aFormatter.Print( 0, "$ENDCMP\n" ); aFormatter.Print( 0, "$ENDCMP\n" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
return false; return false;
} }
......
...@@ -731,7 +731,7 @@ bool CMP_LIBRARY::Save( OUTPUTFORMATTER& aFormatter ) ...@@ -731,7 +731,7 @@ bool CMP_LIBRARY::Save( OUTPUTFORMATTER& aFormatter )
aFormatter.Print( 0, "#\n#End Library\n" ); aFormatter.Print( 0, "#\n#End Library\n" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
success = false; success = false;
} }
...@@ -756,7 +756,7 @@ bool CMP_LIBRARY::SaveDocs( OUTPUTFORMATTER& aFormatter ) ...@@ -756,7 +756,7 @@ bool CMP_LIBRARY::SaveDocs( OUTPUTFORMATTER& aFormatter )
aFormatter.Print( 0, "#\n#End Doc Library\n" ); aFormatter.Print( 0, "#\n#End Doc Library\n" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
success = false; success = false;
} }
......
...@@ -249,7 +249,7 @@ void DIALOG_BOM::installPluginsList() ...@@ -249,7 +249,7 @@ void DIALOG_BOM::installPluginsList()
{ {
cfg_parser.Parse(); cfg_parser.Parse();
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
// wxLogMessage( ioe.errorText ); // wxLogMessage( ioe.errorText );
} }
......
...@@ -668,7 +668,7 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) ...@@ -668,7 +668,7 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
{ {
m_TemplateFieldNames.Parse( &lexer ); m_TemplateFieldNames.Parse( &lexer );
} }
catch( IO_ERROR& e ) catch( const IO_ERROR& e )
{ {
// @todo show error msg // @todo show error msg
DBG( printf( "templatefieldnames parsing error: '%s'\n", DBG( printf( "templatefieldnames parsing error: '%s'\n",
......
...@@ -1049,7 +1049,7 @@ bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName ) ...@@ -1049,7 +1049,7 @@ bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
xroot->Format( &formatter, 0 ); xroot->Format( &formatter, 0 );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( NULL, ioe.errorText ); DisplayError( NULL, ioe.errorText );
return false; return false;
......
...@@ -225,14 +225,14 @@ void LIB_EDIT_FRAME::SaveOneSymbol() ...@@ -225,14 +225,14 @@ void LIB_EDIT_FRAME::SaveOneSymbol()
formatter.Print( 0, "ENDDRAW\n" ); formatter.Print( 0, "ENDDRAW\n" );
formatter.Print( 0, "ENDDEF\n" ); formatter.Print( 0, "ENDDEF\n" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
msg.Printf( _( "An error occurred attempting to save symbol file '%s'" ), msg.Printf( _( "An error occurred attempting to save symbol file '%s'" ),
GetChars( fn.GetFullPath() ) ); GetChars( fn.GetFullPath() ) );
DisplayError( this, msg ); DisplayError( this, msg );
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return; return;
......
...@@ -38,6 +38,7 @@ class wxFileName; ...@@ -38,6 +38,7 @@ class wxFileName;
class OUTPUTFORMATTER; class OUTPUTFORMATTER;
class MODULE; class MODULE;
class FP_LIB_TABLE_LEXER; class FP_LIB_TABLE_LEXER;
class FPID;
class NETLIST; class NETLIST;
class REPORTER; class REPORTER;
class SEARCH_STACK; class SEARCH_STACK;
...@@ -455,6 +456,21 @@ public: ...@@ -455,6 +456,21 @@ public:
//-----</PLUGIN API SUBSET, REBASED ON aNickname>--------------------------- //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
/**
* Function FootprintLoadWithOptionalNickname
* loads a footprint having @a aFootprintId with possibly an empty nickname.
*
* @param aFootprintId the [nickname] & fooprint name of the footprint to load.
*
* @return MODULE* - if found caller owns it, else NULL if not found.
*
* @throw IO_ERROR if the library cannot be found or read. No exception
* is thrown in the case where aFootprintName cannot be found.
* @throw PARSE_ERROR if @a aFootprintId is not parsed OK.
*/
MODULE* FootprintLoadWithOptionalNickname( const FPID& aFootprintId )
throw( IO_ERROR, PARSE_ERROR );
/** /**
* Function GetDescription * Function GetDescription
* returns the library desicription from @a aNickname, or an empty string * returns the library desicription from @a aNickname, or an empty string
...@@ -499,19 +515,6 @@ public: ...@@ -499,19 +515,6 @@ public:
*/ */
bool IsEmpty( bool aIncludeFallback = true ); bool IsEmpty( bool aIncludeFallback = true );
/**
* Function ConvertFromLegacy
* converts the footprint names in \a aNetList from the legacy format to the #FPID format.
*
* @param aNetList is the #NETLIST object to convert.
* @param aLibNames is the list of legacy footprint library names from the currently loaded
* project.
* @param aReporter is the #REPORTER object to dump messages into.
* @return true if all footprint names were successfully converted to a valid FPID.
*/
bool ConvertFromLegacy( SEARCH_STACK& aSStack, NETLIST& aNetList,
const wxArrayString& aLibNames, REPORTER* aReporter = NULL ) throw( IO_ERROR );
/** /**
* Function ExpandSubstitutions * Function ExpandSubstitutions
* replaces any environment variable references with their values and is * replaces any environment variable references with their values and is
......
...@@ -153,7 +153,6 @@ public: ...@@ -153,7 +153,6 @@ public:
*/ */
bool IsValid() const { return !nickname.empty() && !footprint.empty(); } bool IsValid() const { return !nickname.empty() && !footprint.empty(); }
/** /**
* Function IsLegacy * Function IsLegacy
* @return true if the #FPID only has the #footprint name defined. * @return true if the #FPID only has the #footprint name defined.
......
...@@ -78,7 +78,7 @@ typedef const PTREE CPTREE; ...@@ -78,7 +78,7 @@ typedef const PTREE CPTREE;
* PTREE doc; * PTREE doc;
* Scan( &doc, &lexer ); * Scan( &doc, &lexer );
* } * }
* catch( IO_ERROR ioe ) * catch( const IO_ERROR& ioe )
* { * {
* fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) ); * fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) );
* } * }
......
...@@ -716,7 +716,7 @@ void DIR_LIB_SOURCE::Test( int argc, char** argv ) ...@@ -716,7 +716,7 @@ void DIR_LIB_SOURCE::Test( int argc, char** argv )
printf( "std::exception\n" ); printf( "std::exception\n" );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
printf( "exception: %s\n", (const char*) ioe.errorText.ToUTF8() ) ); printf( "exception: %s\n", (const char*) ioe.errorText.ToUTF8() ) );
} }
......
...@@ -118,7 +118,7 @@ int main( int argc, char** argv ) ...@@ -118,7 +118,7 @@ int main( int argc, char** argv )
printf( "%*s^\n", ioe.byteIndex>=1 ? ioe.byteIndex-1 : 0, "" ); printf( "%*s^\n", ioe.byteIndex>=1 ? ioe.byteIndex-1 : 0, "" );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
printf( "%s\n", (const char*) ioe.errorText.ToUTF8() ); printf( "%s\n", (const char*) ioe.errorText.ToUTF8() );
} }
......
...@@ -98,7 +98,7 @@ public: ...@@ -98,7 +98,7 @@ public:
m_fileout = new FILE_OUTPUTFORMATTER( aFilename ); m_fileout = new FILE_OUTPUTFORMATTER( aFilename );
m_out = m_fileout; m_out = m_fileout;
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxMessageBox( ioe.errorText, _("Error writing page layout descr file" ) ); wxMessageBox( ioe.errorText, _("Error writing page layout descr file" ) );
} }
...@@ -125,7 +125,7 @@ public: ...@@ -125,7 +125,7 @@ public:
m_writer = new STRING_FORMATTER(); m_writer = new STRING_FORMATTER();
m_out = m_writer; m_out = m_writer;
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxMessageBox( ioe.errorText, _("Error writing page layout descr file" ) ); wxMessageBox( ioe.errorText, _("Error writing page layout descr file" ) );
} }
......
...@@ -66,13 +66,16 @@ bool PCB_CALCULATOR_FRAME::ReadDataFile() ...@@ -66,13 +66,16 @@ bool PCB_CALCULATOR_FRAME::ReadDataFile()
{ {
datafile_parser.Parse( datafile ); datafile_parser.Parse( datafile );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
delete datafile; delete datafile;
ioe.errorText += '\n';
ioe.errorText += _("Data file error.");
wxMessageBox( ioe.errorText ); wxString msg = ioe.errorText;
msg += wxChar('\n');
msg += _("Data file error.");
wxMessageBox( msg );
return false; return false;
} }
...@@ -99,7 +102,7 @@ bool PCB_CALCULATOR_FRAME::WriteDataFile() ...@@ -99,7 +102,7 @@ bool PCB_CALCULATOR_FRAME::WriteDataFile()
while( nestlevel-- ) while( nestlevel-- )
formatter.Print( nestlevel, ")\n" ); formatter.Print( nestlevel, ")\n" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
return false; return false;
} }
......
...@@ -426,7 +426,7 @@ bool DIALOG_NETLIST::verifyFootprints( const wxString& aNetlistFilename, ...@@ -426,7 +426,7 @@ bool DIALOG_NETLIST::verifyFootprints( const wxString& aNetlistFilename,
std::auto_ptr< NETLIST_READER > nlr( netlistReader ); std::auto_ptr< NETLIST_READER > nlr( netlistReader );
netlistReader->LoadNetlist(); netlistReader->LoadNetlist();
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg.Printf( _( "Error loading netlist file:\n%s" ), ioe.errorText.GetData() ); msg.Printf( _( "Error loading netlist file:\n%s" ), ioe.errorText.GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
......
...@@ -403,7 +403,7 @@ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, double aUseThou ) ...@@ -403,7 +403,7 @@ bool Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, double aUseThou )
idfBoard.Finish(); idfBoard.Finish();
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogDebug( wxT( "An error occurred attemping export to IDFv3.\n\nError: %s" ), wxLogDebug( wxT( "An error occurred attemping export to IDFv3.\n\nError: %s" ),
GetChars( ioe.errorText ) ); GetChars( ioe.errorText ) );
......
...@@ -713,7 +713,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool ...@@ -713,7 +713,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool
fprintf( rptfile, "$EndMODULE %s\n\n", TO_UTF8 (Module->GetReference() ) ); fprintf( rptfile, "$EndMODULE %s\n\n", TO_UTF8 (Module->GetReference() ) );
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( NULL, ioe.errorText ); DisplayError( NULL, ioe.errorText );
} }
......
...@@ -404,7 +404,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in ...@@ -404,7 +404,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
SetBoard( loadedBoard ); SetBoard( loadedBoard );
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxString msg = wxString::Format( _( "Error loading board.\n%s" ), wxString msg = wxString::Format( _( "Error loading board.\n%s" ),
ioe.errorText.GetData() ); ioe.errorText.GetData() );
...@@ -692,7 +692,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF ...@@ -692,7 +692,7 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL ); pi->Save( pcbFileName.GetFullPath(), GetBoard(), NULL );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxString msg = wxString::Format( _( "Error saving board.\n%s" ), wxString msg = wxString::Format( _( "Error saving board.\n%s" ),
ioe.errorText.GetData() ); ioe.errorText.GetData() );
......
...@@ -570,7 +570,7 @@ int main( int argc, char** argv ) ...@@ -570,7 +570,7 @@ int main( int argc, char** argv )
printf("[%d]:%s\n", i, TO_UTF8( fps[i] ) ); printf("[%d]:%s\n", i, TO_UTF8( fps[i] ) );
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
printf( "%s\n", TO_UTF8(ioe.errorText) ); printf( "%s\n", TO_UTF8(ioe.errorText) );
} }
......
...@@ -204,7 +204,7 @@ public: ...@@ -204,7 +204,7 @@ public:
* or * or
* IO_MGR::Save(...); * IO_MGR::Save(...);
* } * }
* catch( IO_ERROR ioe ) * catch( const IO_ERROR& ioe )
* { * {
* // grab text from ioe, show in error window. * // grab text from ioe, show in error window.
* } * }
......
/**
* @file ioascii.cpp
* @brief Routines for reading and saving of structures in ASCII file common to Pcbnew and CvPcb.
*/
#include <fctsys.h>
#include <confirm.h>
#include <kicad_string.h>
#include <build_version.h>
#include <wxPcbStruct.h>
#include <richio.h>
#include <macros.h>
#include <pcbcommon.h>
/**
* @todo Fix having to recompile the same file with a different defintion. This is
* what C++ derivation was designed to solve.
*/
#ifdef PCBNEW
#include <zones.h>
#endif
#ifdef CVPCB
#include <cvpcb.h>
#endif
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_pcb_text.h>
#include <class_zone.h>
#include <class_dimension.h>
#include <class_drawsegment.h>
#include <class_mire.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <autorout.h>
#include <pcb_plot_params.h>
/* ASCII format of structures:
*
* Structure PAD:
*
* $PAD
* Sh "name" form DIMVA dimH dV dH East: general form dV, dH = delta size
* Dr. diam dV dH: drill: diameter drilling offsets
* At Type S / N layers: standard, cms, conn, hole, meca.,
* Stack / Normal, 32-bit hexadecimal: occupation layers
* Nm net_code netname
* Po posrefX posrefy: reFX position, Y (0 = east position / anchor)
* $EndPAD
*
* Module Structure
*
* $MODULE namelib
* Po ax ay east layer masquelayer m_TimeCode
* ax ay ord = anchor (position module)
* east = east to 0.1 degree
* layer = layer number
* masquelayer = silkscreen layer for
* m_TimeCode internal use (groups)
* Li <namelib>
*
* Cd <text> description of the component (Component Doc)
* Kw <text> List of key words
*
* Sc schematic timestamp, reference schematic
*
* Op rot90 rot180 placement Options Auto (court rot 90, 180)
* rot90 is about 2x4-bit:
* lsb = cost rot 90, rot court msb = -90;
*
* Tn px py DIMVA dimh East thickness mirror visible "text"
* n = type (0 = ref, val = 1,> 1 = qcq
* Texts POS x, y / anchor and orient module 0
* DIMVA dimh East
* mirror thickness (Normal / Mirror)
* Visible V / I
* DS ox oy fx fy w
* Edge: coord segment ox, oy has fx, fy, on
* was the anchor and orient 0
* thickness w
* DC ox oy fx fy w descr circle (center, 1 point, thickness)
* $PAD
* $EndPAD section pads if available
* $Endmodule
*/
/// Get the length of a string constant, at compile time
#define SZ( x ) (sizeof(x)-1)
static int NbDraw, NbTrack, NbZone, NbMod, NbNets;
static const char delims[] = " =\n\r";
/** Read a list of segments (Tracks, zones)
* @return items count or - count if no end block ($End...) found.
*/
int PCB_BASE_FRAME::ReadListeSegmentDescr( LINE_READER* aReader,
TRACK* insertBeforeMe,
int StructType,
int NumSegm )
{
int shape, width, drill, layer, type, flags, net_code;
int tempStartX, tempStartY;
int tempEndX, tempEndY;
int ii = 0;
TRACK* newTrack;
while( aReader->ReadLine() )
{
char* line = aReader->Line();
int makeType;
unsigned long timeStamp;
if( line[0] == '$' )
{
return ii; // end of segmentlist: OK
}
int arg_count = sscanf( line + 2, " %d %d %d %d %d %d %d", &shape,
&tempStartX, &tempStartY,
&tempEndX, &tempEndY, &width,
&drill );
// Read the 2nd line to determine the exact type, one of:
// PCB_TRACE_T, PCB_VIA_T, or PCB_ZONE_T. The type field in 2nd line
// differentiates between PCB_TRACE_T and PCB_VIA_T. With virtual
// functions in use, it is critical to instantiate the PCB_VIA_T
// exactly.
if( !aReader->ReadLine() )
break;
line = aReader->Line();
if( line[0] == '$' )
break;
// parse the 2nd line first to determine the type of object
sscanf( line + 2, " %d %d %d %lX %X", &layer, &type, &net_code,
&timeStamp, &flags );
if( StructType==PCB_TRACE_T && type==1 )
makeType = PCB_VIA_T;
else
makeType = StructType;
switch( makeType )
{
default:
case PCB_TRACE_T:
newTrack = new TRACK( GetBoard() );
GetBoard()->m_Track.Insert( newTrack, insertBeforeMe );
break;
case PCB_VIA_T:
newTrack = new SEGVIA( GetBoard() );
GetBoard()->m_Track.Insert( newTrack, insertBeforeMe );
break;
case PCB_ZONE_T: // this is now deprecated, but exist in old boards
newTrack = new SEGZONE( GetBoard() );
GetBoard()->m_Zone.Insert( (SEGZONE*) newTrack, (SEGZONE*) insertBeforeMe );
break;
}
newTrack->SetTimeStamp( timeStamp );
newTrack->m_Start.x = tempStartX;
newTrack->m_Start.y = tempStartY;
newTrack->m_End.x = tempEndX;
newTrack->m_End.y = tempEndY;
newTrack->m_Width = width;
newTrack->m_Shape = shape;
if( arg_count < 7 || drill <= 0 )
newTrack->SetDrillDefault();
else
newTrack->SetDrill( drill );
newTrack->SetLayer( layer );
if( makeType == PCB_VIA_T ) // Ensure layers are OK when possible:
{
if( newTrack->GetShape() == VIA_THROUGH )
( (SEGVIA*) newTrack )->SetLayerPair( LAYER_N_FRONT, LAYER_N_BACK );
}
newTrack->SetNet( net_code );
newTrack->SetState( flags, ON );
}
DisplayError( this, _( "Error: Unexpected end of file !" ) );
return -ii;
}
int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader )
{
while( aReader->ReadLine() )
{
char* line = aReader->Line();
char* data = strtok( line, delims );
if( strnicmp( data, "$EndGENERAL", 10 ) == 0 )
break;
if( stricmp( data, "EnabledLayers" ) == 0 )
{
int enabledLayers = 0;
data = strtok( NULL, delims );
sscanf( data, "%X", &enabledLayers );
// layer usage
GetBoard()->SetEnabledLayers( enabledLayers );
// layer visibility equals layer usage, unless overridden later via "VisibleLayers"
GetBoard()->SetVisibleLayers( enabledLayers );
continue;
}
if( stricmp( data, "VisibleLayers" ) == 0 )
{
int visibleLayers = -1;
data = strtok( NULL, delims );
sscanf( data, "%X", &visibleLayers );
GetBoard()->SetVisibleLayers( visibleLayers );
continue;
}
if( strncmp( data, "Ly", 2 ) == 0 ) // Old format for Layer count
{
int Masque_Layer = 1, ii;
data = strtok( NULL, delims );
sscanf( data, "%X", &Masque_Layer );
// Setup layer count
int layer_count = 0;
for( ii = 0; ii < NB_COPPER_LAYERS; ii++ )
{
if( Masque_Layer & 1 )
layer_count++;
Masque_Layer >>= 1;
}
GetBoard()->SetCopperLayerCount( layer_count );
continue;
}
if( stricmp( data, "BoardThickness" ) == 0 )
{
data = strtok( NULL, delims );
GetBoard()->GetDesignSettings().m_BoardThickness = atoi( data );
continue;
}
if( strnicmp( data, "Links", 5 ) == 0 )
{
// Info only, do nothing
continue;
}
if( strnicmp( data, "NoConn", 6 ) == 0 )
{
data = strtok( NULL, delims );
GetBoard()->m_NbNoconnect = atoi( data );
continue;
}
if( strnicmp( data, "Di", 2 ) == 0 )
{
data = strtok( NULL, delims );
int x1 = atoi( data );
data = strtok( NULL, delims );
int y1 = atoi( data );
data = strtok( NULL, delims );
int x2 = atoi( data );
data = strtok( NULL, delims );
int y2 = atoi( data );
EDA_RECT bbbox( wxPoint( x1, y1 ), wxSize( x2-x1, y2-y1 ) );
GetBoard()->SetBoundingBox( bbbox );
continue;
}
// Read the number of segments of type DRAW, TRACK, ZONE
if( stricmp( data, "Ndraw" ) == 0 )
{
data = strtok( NULL, delims );
NbDraw = atoi( data );
continue;
}
if( stricmp( data, "Ntrack" ) == 0 )
{
data = strtok( NULL, delims );
NbTrack = atoi( data );
continue;
}
if( stricmp( data, "Nzone" ) == 0 )
{
data = strtok( NULL, delims );
NbZone = atoi( data );
continue;
}
if( stricmp( data, "Nmodule" ) == 0 )
{
data = strtok( NULL, delims );
NbMod = atoi( data );
continue;
}
if( stricmp( data, "Nnets" ) == 0 )
{
data = strtok( NULL, delims );
NbNets = atoi( data );
continue;
}
}
return 1;
}
int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader )
{
char* data;
NETCLASS* netclass_default = GetBoard()->m_NetClasses.GetDefault();
ZONE_SETTINGS zoneInfo = GetBoard()->GetZoneSettings();
BOARD_DESIGN_SETTINGS bds = GetBoard()->GetDesignSettings();
while( aReader->ReadLine() )
{
char* line = aReader->Line();
if( strnicmp( line, "PcbPlotParams", 13 ) == 0 )
{
PCB_PLOT_PARAMS plot_opts;
PCB_PLOT_PARAMS_PARSER parser( &line[13], aReader->GetSource() );
try
{
plot_opts.Parse( &parser );
}
catch( IO_ERROR& e )
{
wxString msg;
msg.Printf( _( "Error reading PcbPlotParams from %s:\n%s" ),
aReader->GetSource().GetData(),
e.errorText.GetData() );
wxMessageBox( msg, _( "Open Board File" ), wxOK | wxICON_ERROR );
}
GetBoard()->SetPlotOptions( plot_opts );
continue;
}
strtok( line, delims );
data = strtok( NULL, delims );
if( stricmp( line, "$EndSETUP" ) == 0 )
{
// Until such time as the *.brd file does not have the
// global parameters:
// "TrackWidth", "TrackMinWidth", "ViaSize", "ViaDrill",
// "ViaMinSize", and "TrackClearence", put those same global
// values into the default NETCLASS until later board load
// code should override them. *.brd files which have been
// saved with knowledge of NETCLASSes will override these
// defaults, old boards will not.
//
// @todo: I expect that at some point we can remove said global
// parameters from the *.brd file since the ones in the
// default netclass serve the same purpose. If needed
// at all, the global defaults should go into a preferences
// file instead so they are there to start new board
// projects.
GetBoard()->m_NetClasses.GetDefault()->SetParams();
GetBoard()->SetDesignSettings( bds );
GetBoard()->SetZoneSettings( zoneInfo );
return 0;
}
if( stricmp( line, "AuxiliaryAxisOrg" ) == 0 )
{
int gx = 0, gy = 0;
gx = atoi( data );
data = strtok( NULL, delims );
if( data )
gy = atoi( data );
SetOriginAxisPosition( wxPoint( gx, gy ) );
continue;
}
#ifdef PCBNEW
if( stricmp( line, "Layers" ) == 0 )
{
int tmp;
sscanf( data, "%d", &tmp );
GetBoard()->SetCopperLayerCount( tmp );
continue;
}
const int LAYERKEYZ = sizeof("Layer[") - 1;
if( strncmp( line, "Layer[", LAYERKEYZ ) == 0 )
{
// parse:
// Layer[n] <a_Layer_name_with_no_spaces> <LAYER_T>
char* cp = line + LAYERKEYZ;
int layer = atoi( cp );
if( data )
{
wxString layerName = FROM_UTF8( data );
GetBoard()->SetLayerName( layer, layerName );
data = strtok( NULL, " \n\r" );
if( data )
{
LAYER_T type = LAYER::ParseType( data );
GetBoard()->SetLayerType( layer, type );
}
}
continue;
}
if( stricmp( line, "TrackWidth" ) == 0 ) // no more used
{
continue;
}
if( stricmp( line, "TrackWidthList" ) == 0 )
{
int tmp = atoi( data );
GetBoard()->m_TrackWidthList.push_back( tmp );
continue;
}
if( stricmp( line, "TrackClearence" ) == 0 )
{
netclass_default->SetClearance( atoi( data ) );
continue;
}
if( stricmp( line, "TrackMinWidth" ) == 0 )
{
bds.m_TrackMinWidth = atoi( data );
continue;
}
if( stricmp( line, "ZoneClearence" ) == 0 )
{
zoneInfo.m_ZoneClearance = atoi( data );
continue;
}
if( stricmp( line, "DrawSegmWidth" ) == 0 )
{
bds.m_DrawSegmentWidth = atoi( data );
continue;
}
if( stricmp( line, "EdgeSegmWidth" ) == 0 )
{
bds.m_EdgeSegmentWidth = atoi( data );
continue;
}
if( stricmp( line, "ViaSize" ) == 0 ) // no more used
{
continue;
}
if( stricmp( line, "ViaMinSize" ) == 0 )
{
bds.m_ViasMinSize = atoi( data );
continue;
}
if( stricmp( line, "MicroViaSize" ) == 0 ) // Not used
{
continue;
}
if( stricmp( line, "MicroViaMinSize" ) == 0 )
{
bds.m_MicroViasMinSize = atoi( data );
continue;
}
if( stricmp( line, "ViaSizeList" ) == 0 )
{
int tmp = atoi( data );
VIA_DIMENSION via_dim;
via_dim.m_Diameter = tmp;
data = strtok( NULL, " \n\r" );
if( data )
{
tmp = atoi( data );
via_dim.m_Drill = tmp > 0 ? tmp : 0;
}
GetBoard()->m_ViasDimensionsList.push_back( via_dim );
continue;
}
if( stricmp( line, "ViaDrill" ) == 0 )
{
int diameter = atoi( data );
netclass_default->SetViaDrill( diameter );
continue;
}
if( stricmp( line, "ViaMinDrill" ) == 0 )
{
bds.m_ViasMinDrill = atoi( data );
continue;
}
if( stricmp( line, "MicroViaDrill" ) == 0 )
{
int diameter = atoi( data );
netclass_default->SetuViaDrill( diameter );
continue;
}
if( stricmp( line, "MicroViaMinDrill" ) == 0 )
{
int diameter = atoi( data );
bds.m_MicroViasMinDrill = diameter;
continue;
}
if( stricmp( line, "MicroViasAllowed" ) == 0 )
{
bds.m_MicroViasAllowed = atoi( data );
continue;
}
if( stricmp( line, "TextPcbWidth" ) == 0 )
{
bds.m_PcbTextWidth = atoi( data );
continue;
}
if( stricmp( line, "TextPcbSize" ) == 0 )
{
bds.m_PcbTextSize.x = atoi( data );
data = strtok( NULL, delims );
bds.m_PcbTextSize.y = atoi( data );
continue;
}
if( stricmp( line, "EdgeModWidth" ) == 0 )
{
bds.m_ModuleSegmentWidth = atoi( data );
continue;
}
if( stricmp( line, "TextModWidth" ) == 0 )
{
bds.m_ModuleTextWidth = atoi( data );
continue;
}
if( stricmp( line, "TextModSize" ) == 0 )
{
bds.m_ModuleTextSize.x = atoi( data );
data = strtok( NULL, delims );
bds.m_ModuleTextSize.y = atoi( data );
continue;
}
if( stricmp( line, "PadSize" ) == 0 )
{
int x = atoi( data );
data = strtok( NULL, delims );
int y = atoi( data );
bds.m_Pad_Master.SetSize( wxSize( x, y ) );
continue;
}
if( stricmp( line, "PadDrill" ) == 0 )
{
int sz = atoi( data );
bds.m_Pad_Master.SetSize( wxSize( sz, sz ) );
continue;
}
if( stricmp( line, "Pad2MaskClearance" ) == 0 )
{
bds.m_SolderMaskMargin = atoi( data );
continue;
}
if( stricmp( line, "Pad2PasteClearance" ) == 0 )
{
bds.m_SolderPasteMargin = atoi( data );
continue;
}
if( stricmp( line, "Pad2PasteClearanceRatio" ) == 0 )
{
bds.m_SolderPasteMarginRatio = atof( data );
continue;
}
if( stricmp( line, "GridOrigin" ) == 0 )
{
int Ox = 0;
int Oy = 0;
Ox = atoi( data );
data = strtok( NULL, delims );
if ( data )
Oy = atoi( data );
GetScreen()->m_GridOrigin.x = Ox;
GetScreen()->m_GridOrigin.y = Oy;
continue;
}
if( stricmp( line, "VisibleElements" ) == 0 )
{
int visibleElements = strtoul( data, 0, 16 );
bds.SetVisibleElements( visibleElements );
continue;
}
#endif
}
/* Ensure tracks and vias sizes lists are ok:
* Sort lists by by increasing value and remove duplicates
* (the first value is not tested, because it is the netclass value
*/
sort( GetBoard()->m_ViasDimensionsList.begin() + 1, GetBoard()->m_ViasDimensionsList.end() );
sort( GetBoard()->m_TrackWidthList.begin() + 1, GetBoard()->m_TrackWidthList.end() );
for( unsigned ii = 1; ii < GetBoard()->m_ViasDimensionsList.size() - 1; ii++ )
{
if( GetBoard()->m_ViasDimensionsList[ii] == GetBoard()->m_ViasDimensionsList[ii + 1] )
{
GetBoard()->m_ViasDimensionsList.erase( GetBoard()->m_ViasDimensionsList.begin() + ii );
ii--;
}
}
for( unsigned ii = 1; ii < GetBoard()->m_TrackWidthList.size() - 1; ii++ )
{
if( GetBoard()->m_TrackWidthList[ii] == GetBoard()->m_TrackWidthList[ii + 1] )
{
GetBoard()->m_TrackWidthList.erase( GetBoard()->m_TrackWidthList.begin() + ii );
ii--;
}
}
return 1;
}
#ifdef PCBNEW
static int WriteSetup( FILE* aFile, PCB_EDIT_FRAME* aFrame, BOARD* aBoard )
{
const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings();
NETCLASS* netclass_default = aBoard->m_NetClasses.GetDefault();
char text[1024];
fprintf( aFile, "$SETUP\n" );
sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT );
fprintf( aFile, "%s", text );
fprintf( aFile, "Layers %d\n", aBoard->GetCopperLayerCount() );
unsigned layerMask = g_TabAllCopperLayerMask[aBoard->GetCopperLayerCount() - 1];
for( int layer = 0; layerMask; ++layer, layerMask >>= 1 )
{
if( layerMask & 1 )
{
fprintf( aFile, "Layer[%d] %s %s\n", layer,
TO_UTF8( aBoard->GetLayerName( layer ) ),
LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
}
}
// Save current default track width, for compatibility with older Pcbnew version;
fprintf( aFile, "TrackWidth %d\n", aBoard->GetCurrentTrackWidth() );
// Save custom tracks width list (the first is not saved here: this is the netclass value
for( unsigned ii = 1; ii < aBoard->m_TrackWidthList.size(); ii++ )
fprintf( aFile, "TrackWidthList %d\n", aBoard->m_TrackWidthList[ii] );
fprintf( aFile, "TrackClearence %d\n", netclass_default->GetClearance() );
fprintf( aFile, "ZoneClearence %d\n", aBoard->GetZoneSettings().m_ZoneClearance );
fprintf( aFile, "TrackMinWidth %d\n", bds.m_TrackMinWidth );
fprintf( aFile, "DrawSegmWidth %d\n", bds.m_DrawSegmentWidth );
fprintf( aFile, "EdgeSegmWidth %d\n", bds.m_EdgeSegmentWidth );
// Save current default via size, for compatibility with older Pcbnew version;
fprintf( aFile, "ViaSize %d\n", netclass_default->GetViaDiameter() );
fprintf( aFile, "ViaDrill %d\n", netclass_default->GetViaDrill() );
fprintf( aFile, "ViaMinSize %d\n", bds.m_ViasMinSize );
fprintf( aFile, "ViaMinDrill %d\n", bds.m_ViasMinDrill );
// Save custom vias diameters list (the first is not saved here: this is
// the netclass value
for( unsigned ii = 1; ii < aBoard->m_ViasDimensionsList.size(); ii++ )
fprintf( aFile, "ViaSizeList %d %d\n",
aBoard->m_ViasDimensionsList[ii].m_Diameter,
aBoard->m_ViasDimensionsList[ii].m_Drill );
// for old versions compatibility:
fprintf( aFile, "MicroViaSize %d\n", netclass_default->GetuViaDiameter() );
fprintf( aFile, "MicroViaDrill %d\n", netclass_default->GetuViaDrill() );
fprintf( aFile,
"MicroViasAllowed %d\n",
bds.m_MicroViasAllowed );
fprintf( aFile,
"MicroViaMinSize %d\n",
bds.m_MicroViasMinSize );
fprintf( aFile,
"MicroViaMinDrill %d\n",
bds.m_MicroViasMinDrill );
fprintf( aFile, "TextPcbWidth %d\n", bds.m_PcbTextWidth );
fprintf( aFile,
"TextPcbSize %d %d\n",
bds.m_PcbTextSize.x,
bds.m_PcbTextSize.y );
fprintf( aFile, "EdgeModWidth %d\n", bds.m_ModuleSegmentWidth );
fprintf( aFile, "TextModSize %d %d\n", bds.m_ModuleTextSize.x, bds.m_ModuleTextSize.y );
fprintf( aFile, "TextModWidth %d\n", bds.m_ModuleTextWidth );
fprintf( aFile, "PadSize %d %d\n", bds.m_Pad_Master.GetSize().x,
bds.m_Pad_Master.GetSize().y );
fprintf( aFile, "PadDrill %d\n", bds.m_Pad_Master.GetDrillSize().x );
fprintf( aFile,
"Pad2MaskClearance %d\n",
bds.m_SolderMaskMargin );
if( bds.m_SolderPasteMargin != 0 )
fprintf( aFile,
"Pad2PasteClearance %d\n",
bds.m_SolderPasteMargin );
if( bds.m_SolderPasteMarginRatio != 0 )
fprintf( aFile,
"Pad2PasteClearanceRatio %g\n",
bds.m_SolderPasteMarginRatio );
if ( aFrame->GetScreen()->m_GridOrigin != wxPoint( 0, 0 ) )
{
fprintf( aFile,
"GridOrigin %d %d\n",
aFrame->GetScreen()->m_GridOrigin.x,
aFrame->GetScreen()->m_GridOrigin.y );
}
fprintf( aFile,
"AuxiliaryAxisOrg %d %d\n",
aFrame->GetOriginAxisPosition().x,
aFrame->GetOriginAxisPosition().y );
fprintf( aFile, "VisibleElements %X\n", bds.GetVisibleElements() );
STRING_FORMATTER sf;
aBoard->GetPlotOptions().Format( &sf, 0 );
wxString record = FROM_UTF8( sf.GetString().c_str() );
record.Replace( wxT("\n"), wxT(""), true );
record.Replace( wxT(" "), wxT(" "), true);
fprintf( aFile, "PcbPlotParams %s\n", TO_UTF8( record ) );
fprintf( aFile, "$EndSETUP\n\n" );
return 1;
}
#endif
bool PCB_EDIT_FRAME::WriteGeneralDescrPcb( FILE* File )
{
EDA_ITEM* PtStruct = GetBoard()->m_Modules;
int NbModules, NbDrawItem, NbLayers;
// Write copper layer count
NbLayers = GetBoard()->GetCopperLayerCount();
fprintf( File, "$GENERAL\n" );
fprintf( File, "encoding utf-8\n");
fprintf( File, "LayerCount %d\n", NbLayers );
// Write old format for Layer count (for compatibility with old versions of
// pcbnew
fprintf( File,
"Ly %8X\n",
g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS );
fprintf( File, "EnabledLayers %08X\n", GetBoard()->GetEnabledLayers() );
if( GetBoard()->GetEnabledLayers() != GetBoard()->GetVisibleLayers() )
fprintf( File, "VisibleLayers %08X\n", GetBoard()->GetVisibleLayers() );
fprintf( File, "Links %d\n", GetBoard()->GetRatsnestsCount() );
fprintf( File, "NoConn %d\n", GetBoard()->m_NbNoconnect );
// Write board's bounding box info
EDA_RECT bbbox = GetBoard()->ComputeBoundingBox();
fprintf( File, "Di %d %d %d %d\n",
bbbox.GetX(),
bbbox.GetY(),
bbbox.GetRight(),
bbbox.GetBottom() );
// Write segment count for footprints, drawings, track and zones
// Calculate the footprint count
for( NbModules = 0; PtStruct != NULL; PtStruct = PtStruct->Next() )
NbModules++;
PtStruct = GetBoard()->m_Drawings; NbDrawItem = 0;
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
NbDrawItem++;
fprintf( File, "Ndraw %d\n", NbDrawItem );
fprintf( File, "Ntrack %d\n", GetBoard()->GetNumSegmTrack() );
fprintf( File, "Nzone %d\n", GetBoard()->GetNumSegmZone() );
fprintf( File, "BoardThickness %d\n", GetBoard()->GetDesignSettings().m_BoardThickness );
fprintf( File, "Nmodule %d\n", NbModules );
fprintf( File, "Nnets %d\n", GetBoard()->GetNetCount() );
fprintf( File, "$EndGENERAL\n\n" );
return true;
}
/**
* Function WriteSheetDescr
* Save the page information (size, texts, date ..)
* @param aPageSettings The page settings to write to \a aFile.
* @param aTitleBlock The title block information to write to \a aFile.
* @param aFile An open FILE to write info.
*/
static bool WriteSheetDescr( const PAGE_INFO& aPageSettings, const TITLE_BLOCK& aTitleBlock,
FILE* aFile )
{
fprintf( aFile, "$SHEETDESCR\n" );
fprintf( aFile, "Sheet %s %d %d%s\n",
TO_UTF8( aPageSettings.GetType() ),
aPageSettings.GetWidthMils(),
aPageSettings.GetHeightMils(),
!aPageSettings.IsCustom() && aPageSettings.IsPortrait() ?
" portrait" : ""
);
fprintf( aFile, "Title %s\n", EscapedUTF8( aTitleBlock.GetTitle() ).c_str() );
fprintf( aFile, "Date %s\n", EscapedUTF8( aTitleBlock.GetDate() ).c_str() );
fprintf( aFile, "Rev %s\n", EscapedUTF8( aTitleBlock.GetRevision() ).c_str() );
fprintf( aFile, "Comp %s\n", EscapedUTF8( aTitleBlock.GetCompany() ).c_str() );
fprintf( aFile, "Comment1 %s\n", EscapedUTF8( aTitleBlock.GetComment1() ).c_str() );
fprintf( aFile, "Comment2 %s\n", EscapedUTF8( aTitleBlock.GetComment2() ).c_str() );
fprintf( aFile, "Comment3 %s\n", EscapedUTF8( aTitleBlock.GetComment3() ).c_str() );
fprintf( aFile, "Comment4 %s\n", EscapedUTF8( aTitleBlock.GetComment4() ).c_str() );
fprintf( aFile, "$EndSHEETDESCR\n\n" );
return true;
}
#if !defined( USE_NEW_PCBNEW_LOAD )
static bool ReadSheetDescr( BOARD* aBoard, LINE_READER* aReader )
{
char buf[1024];
TITLE_BLOCK tb;
while( aReader->ReadLine() )
{
char* line = aReader->Line();
if( strnicmp( line, "$End", 4 ) == 0 )
{
aBoard->SetTitleBlock( tb );
return true;
}
if( strnicmp( line, "Sheet", 4 ) == 0 )
{
// e.g. "Sheet A3 16535 11700"
// width and height are in 1/1000th of an inch, always
PAGE_INFO page;
char* sname = strtok( line + SZ( "Sheet" ), delims );
if( sname )
{
wxString wname = FROM_UTF8( sname );
if( !page.SetType( wname ) )
{
/* this entire file is soon to be deleted.
m_error.Printf( _( "Unknown sheet type '%s' on line:%d" ),
wname.GetData(), m_reader->LineNumber() );
THROW_IO_ERROR( m_error );
*/
}
char* width = strtok( NULL, delims );
char* height = strtok( NULL, delims );
char* orient = strtok( NULL, delims );
// only keep width and height if page size is "User"
if( wname == PAGE_INFO::Custom )
{
if( width && height )
{
// legacy disk file describes paper in mils
// (1/1000th of an inch)
int w = atoi( width );
int h = atoi( height );
page.SetWidthMils( w );
page.SetHeightMils( h );
}
}
if( orient && !strcmp( orient, "portrait" ) )
{
page.SetPortrait( true );
}
aBoard->SetPageSettings( page );
}
continue;
}
if( strnicmp( line, "Title", 2 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetTitle( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Date", 2 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetDate( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Rev", 2 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetRevision( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Comp", 4 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetCompany( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Comment1", 8 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetComment1( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Comment2", 8 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetComment2( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Comment3", 8 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetComment3( FROM_UTF8( buf ) );
continue;
}
if( strnicmp( line, "Comment4", 8 ) == 0 )
{
ReadDelimitedText( buf, line, 256 );
tb.SetComment4( FROM_UTF8( buf ) );
continue;
}
}
return false;
}
int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append )
{
wxBusyCursor dummy;
// Switch the locale to standard C (needed to read floating point numbers
// like 1.3)
SetLocaleTo_C_standard();
BOARD* board = GetBoard();
board->m_Status_Pcb = 0;
board->m_NetClasses.Clear();
// Put a dollar sign in front, and test for a specific length of characters
// The -1 is to omit the trailing \0 which is included in sizeof() on a
// string.
#define TESTLINE( x ) (strncmp( line, "$" x, sizeof("$" x) - 1 ) == 0)
while( aReader->ReadLine() )
{
char* line = aReader->Line();
// put the more frequent ones at the top
if( TESTLINE( "MODULE" ) )
{
MODULE* module = new MODULE( board );
board->Add( module, ADD_APPEND );
module->ReadDescr( aReader );
continue;
}
if( TESTLINE( "DRAWSEGMENT" ) )
{
DRAWSEGMENT* dseg = new DRAWSEGMENT( board );
board->Add( dseg, ADD_APPEND );
dseg->ReadDrawSegmentDescr( aReader );
continue;
}
if( TESTLINE( "EQUIPOT" ) )
{
NETINFO_ITEM* net = new NETINFO_ITEM( board );
board->m_NetInfo.AppendNet( net );
net->ReadDescr( aReader );
continue;
}
if( TESTLINE( "TEXTPCB" ) )
{
TEXTE_PCB* pcbtxt = new TEXTE_PCB( board );
board->Add( pcbtxt, ADD_APPEND );
pcbtxt->ReadTextePcbDescr( aReader );
continue;
}
if( TESTLINE( "TRACK" ) )
{
#ifdef PCBNEW
TRACK* insertBeforeMe = Append ? NULL : board->m_Track.GetFirst();
ReadListeSegmentDescr( aReader, insertBeforeMe, PCB_TRACE_T, NbTrack );
#endif
continue;
}
if( TESTLINE( "NCLASS" ) )
{
// create an empty NETCLASS without a name.
NETCLASS* netclass = new NETCLASS( board, wxEmptyString );
// fill it from the *.brd file, and establish its name.
netclass->ReadDescr( aReader );
if( !board->m_NetClasses.Add( netclass ) )
{
// Must have been a name conflict, this is a bad board file.
// User may have done a hand edit to the file.
// Delete netclass if board could not take ownership of it.
delete netclass;
// @todo: throw an exception here, this is a bad board file.
}
continue;
}
if( TESTLINE( "CZONE_OUTLINE" ) )
{
ZONE_CONTAINER* zone_descr = new ZONE_CONTAINER( board );
zone_descr->ReadDescr( aReader );
if( zone_descr->GetNumCorners() > 2 ) // should always occur
board->Add( zone_descr );
else
delete zone_descr;
continue;
}
if( TESTLINE( "COTATION" ) )
{
DIMENSION* dim = new DIMENSION( board );
board->Add( dim, ADD_APPEND );
dim->ReadDimensionDescr( aReader );
continue;
}
if( TESTLINE( "PCB_TARGET" ) || TESTLINE( "MIREPCB" ) )
{
PCB_TARGET* t = new PCB_TARGET( board );
board->Add( t, ADD_APPEND );
t->ReadMirePcbDescr( aReader );
continue;
}
if( TESTLINE( "ZONE" ) )
{
#ifdef PCBNEW
SEGZONE* insertBeforeMe = Append ? NULL : board->m_Zone.GetFirst();
ReadListeSegmentDescr( aReader, insertBeforeMe, PCB_ZONE_T, NbZone );
#endif
continue;
}
if( TESTLINE( "GENERAL" ) )
{
ReadGeneralDescrPcb( aReader );
continue;
}
if( TESTLINE( "SHEETDESCR" ) )
{
ReadSheetDescr( board, aReader );
continue;
}
if( TESTLINE( "SETUP" ) )
{
if( !Append )
{
ReadSetup( aReader );
}
else
{
while( aReader->ReadLine() )
{
line = aReader->Line();
if( TESTLINE( "EndSETUP" ) )
break;
}
}
continue;
}
if( TESTLINE( "EndPCB" ) )
break;
}
SetLocaleTo_Default(); // revert to the current locale
board->m_Status_Pcb = 0;
// Build the net info list
board->BuildListOfNets();
board->SynchronizeNetsAndNetClasses();
SetStatusText( wxEmptyString );
BestZoom();
return 1;
}
#endif
#ifdef PCBNEW
/* Save the current PCB in ASCII format
* Returns
* 1 if OK
* 0 if error occurs saving file.
*/
int PCB_EDIT_FRAME::SavePcbFormatAscii( FILE* aFile )
{
bool rc;
GetBoard()->m_Status_Pcb &= ~CONNEXION_OK;
wxBeginBusyCursor();
// Switch the locale to standard C (needed to print floating point numbers
// like 1.3)
LOCALE_IO toggle;
// Writing file header.
fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", LEGACY_BOARD_FILE_VERSION,
TO_UTF8( DateAndTime() ) );
fprintf( aFile, "# Created by Pcbnew%s\n\n", TO_UTF8( GetBuildVersion() ) );
GetBoard()->SynchronizeNetsAndNetClasses();
// Select default Netclass before writing file.
// Useful to save default values in headers
GetBoard()->SetCurrentNetClass( GetBoard()->m_NetClasses.GetDefault()->GetName() );
WriteGeneralDescrPcb( aFile );
WriteSheetDescr( GetBoard()->GetPageSettings(), GetBoard()->GetTitleBlock(), aFile );
WriteSetup( aFile, this, GetBoard() );
rc = GetBoard()->Save( aFile );
wxEndBusyCursor();
if( !rc )
DisplayError( this, wxT( "Unable to save PCB file" ) );
else
SetStatusText( wxEmptyString );
return rc;
}
#endif
/**
* @file item_io.cpp
* @brief Routines for reading and saving of structures in ASCII file common to Pcbnew and CvPcb.
* This is migrationary and temporary while we move the IO_MGR.
*/
#include <fctsys.h>
#include <confirm.h>
#include <kicad_string.h>
#include <build_version.h>
#include <wxPcbStruct.h>
#include <richio.h>
#include <macros.h>
#include <pcbcommon.h>
#include <zones.h>
#ifdef CVPCB
#include <cvpcb.h>
#endif
#include <config.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_pcb_text.h>
#include <class_zone.h>
#include <class_dimension.h>
#include <class_drawsegment.h>
#include <class_mire.h>
#include <pcbnew.h>
#include <pcbnew_id.h>
#include <autorout.h>
#include <3d_struct.h>
#include <trigo.h>
#include <class_edge_mod.h>
#include <pcbnew.h>
#include <drawtxt.h>
#define MAX_WIDTH 10000 // Thickness (in 1 / 10000 ") of maximum reasonable features, text...
#if 1 || !defined(USE_NEW_PCBNEW_SAVE)
bool BOARD::Save( FILE* aFile ) const
{
bool rc = false;
BOARD_ITEM* item;
// save the nets
for( unsigned ii = 0; ii < GetNetCount(); ii++ )
if( !FindNet( ii )->Save( aFile ) )
goto out;
// Saved nets do not include netclass names, so save netclasses after nets.
m_NetClasses.Save( aFile );
// save the modules
for( item = m_Modules; item; item = item->Next() )
if( !item->Save( aFile ) )
goto out;
for( item = m_Drawings; item; item = item->Next() )
{
switch( item->Type() )
{
case PCB_TEXT_T:
case PCB_LINE_T:
case PCB_TARGET_T:
case PCB_DIMENSION_T:
if( !item->Save( aFile ) )
goto out;
break;
default:
// future: throw exception here
#if defined(DEBUG)
printf( "BOARD::Save() ignoring m_Drawings type %d\n", item->Type() );
#endif
break;
}
}
// do not save MARKER_PCBs, they can be regenerated easily
// save the tracks & vias
fprintf( aFile, "$TRACK\n" );
for( item = m_Track; item; item = item->Next() )
{
if( !item->Save( aFile ) )
goto out;
}
fprintf( aFile, "$EndTRACK\n" );
// save the zones
fprintf( aFile, "$ZONE\n" );
for( item = m_Zone; item; item = item->Next() )
{
if( !item->Save( aFile ) )
goto out;
}
fprintf( aFile, "$EndZONE\n" );
// save the zone edges
for( unsigned ii = 0; ii < m_ZoneDescriptorList.size(); ii++ )
{
ZONE_CONTAINER* edge_zone = m_ZoneDescriptorList[ii];
edge_zone->Save( aFile );
}
if( fprintf( aFile, "$EndBOARD\n" ) != sizeof("$EndBOARD\n") - 1 )
goto out;
rc = true; // wrote all OK
out:
return rc;
}
bool DRAWSEGMENT::Save( FILE* aFile ) const
{
if( fprintf( aFile, "$DRAWSEGMENT\n" ) != sizeof("$DRAWSEGMENT\n") - 1 )
return false;
fprintf( aFile, "Po %d %d %d %d %d %d\n",
m_Shape,
m_Start.x, m_Start.y,
m_End.x, m_End.y, m_Width );
if( m_Type != S_CURVE )
{
fprintf( aFile, "De %d %d %g %lX %X\n",
m_Layer, m_Type, GetAngle(),
m_TimeStamp, GetStatus() );
}
else
{
fprintf( aFile, "De %d %d %g %lX %X %d %d %d %d\n",
m_Layer, m_Type, GetAngle(),
m_TimeStamp, GetStatus(),
m_BezierC1.x,m_BezierC1.y,
m_BezierC2.x,m_BezierC2.y);
}
if( fprintf( aFile, "$EndDRAWSEGMENT\n" ) != sizeof("$EndDRAWSEGMENT\n") - 1 )
return false;
return true;
}
/** Note: the old name of class NETINFO_ITEM was EQUIPOT
* so in Save (and read) functions, for compatibility, we use EQUIPOT as
* keyword
*/
bool NETINFO_ITEM::Save( FILE* aFile ) const
{
bool success = false;
fprintf( aFile, "$EQUIPOT\n" );
fprintf( aFile, "Na %d %s\n", GetNet(), EscapedUTF8( m_Netname ).c_str() );
fprintf( aFile, "St %s\n", "~" );
if( fprintf( aFile, "$EndEQUIPOT\n" ) != sizeof("$EndEQUIPOT\n") - 1 )
goto out;
success = true;
out:
return success;
}
bool PCB_TARGET::Save( FILE* aFile ) const
{
bool rc = false;
if( fprintf( aFile, "$PCB_TARGET\n" ) != sizeof("$PCB_TARGET\n")-1 )
goto out;
fprintf( aFile, "Po %X %d %d %d %d %d %8.8lX\n",
m_Shape, m_Layer,
m_Pos.x, m_Pos.y,
m_Size, m_Width, m_TimeStamp );
if( fprintf( aFile, "$EndPCB_TARGET\n" ) != sizeof("$EndPCB_TARGET\n")-1 )
goto out;
rc = true;
out:
return rc;
}
bool ZONE_CONTAINER::Save( FILE* aFile ) const
{
unsigned item_pos;
int ret;
unsigned corners_count = m_Poly->corner.size();
int outline_hatch;
fprintf( aFile, "$CZONE_OUTLINE\n" );
// Save the outline main info
ret = fprintf( aFile, "ZInfo %8.8lX %d %s\n",
m_TimeStamp, GetNet(),
EscapedUTF8( m_Netname ).c_str() );
if( ret < 3 )
return false;
// Save the outline layer info
ret = fprintf( aFile, "ZLayer %d\n", m_Layer );
if( ret < 1 )
return false;
// Save the outline aux info
switch( m_Poly->GetHatchStyle() )
{
default:
case CPolyLine::NO_HATCH:
outline_hatch = 'N';
break;
case CPolyLine::DIAGONAL_EDGE:
outline_hatch = 'E';
break;
case CPolyLine::DIAGONAL_FULL:
outline_hatch = 'F';
break;
}
ret = fprintf( aFile, "ZAux %d %c\n", corners_count, outline_hatch );
if( ret < 2 )
return false;
if( GetPriority() > 0 )
{
ret = fprintf( aFile, "ZPriority %d\n", GetPriority() );
if( ret < 1 )
return false;
}
// Save pad option and clearance
int padConnection;
switch( m_PadConnection )
{
default:
case PAD_IN_ZONE:
padConnection = 'I';
break;
case THERMAL_PAD:
padConnection = 'T';
break;
case PAD_NOT_IN_ZONE:
padConnection = 'X';
break;
}
ret = fprintf( aFile, "ZClearance %d %c\n", m_ZoneClearance, padConnection );
if( ret < 2 )
return false;
ret = fprintf( aFile, "ZMinThickness %d\n", m_ZoneMinThickness );
if( ret < 1 )
return false;
ret = fprintf( aFile,
"ZOptions %d %d %c %d %d\n",
m_FillMode,
m_ArcToSegmentsCount,
m_IsFilled ? 'S' : 'F',
m_ThermalReliefGap,
m_ThermalReliefCopperBridge );
if( ret < 3 )
return false;
ret = fprintf( aFile,
"ZSmoothing %d %d\n",
cornerSmoothingType, cornerRadius );
if( ret < 2 )
return false;
// Save the corner list
for( item_pos = 0; item_pos < corners_count; item_pos++ )
{
ret = fprintf( aFile, "ZCorner %d %d %d\n",
m_Poly->corner[item_pos].x, m_Poly->corner[item_pos].y,
m_Poly->corner[item_pos].end_contour );
if( ret < 3 )
return false;
}
// Save the PolysList
if( m_FilledPolysList.size() )
{
fprintf( aFile, "$POLYSCORNERS\n" );
for( unsigned ii = 0; ii < m_FilledPolysList.size(); ii++ )
{
const CPolyPt* corner = &m_FilledPolysList[ii];
ret = fprintf( aFile,
"%d %d %d %d\n",
corner->x,
corner->y,
corner->end_contour,
corner->utility );
if( ret < 4 )
return false;
}
fprintf( aFile, "$endPOLYSCORNERS\n" );
}
// Save the filling segments list
if( m_FillSegmList.size() )
{
fprintf( aFile, "$FILLSEGMENTS\n" );
for( unsigned ii = 0; ii < m_FillSegmList.size(); ii++ )
{
ret = fprintf( aFile, "%d %d %d %d\n",
m_FillSegmList[ii].m_Start.x, m_FillSegmList[ii].m_Start.y,
m_FillSegmList[ii].m_End.x, m_FillSegmList[ii].m_End.y );
if( ret < 4 )
return false;
}
fprintf( aFile, "$endFILLSEGMENTS\n" );
}
fprintf( aFile, "$endCZONE_OUTLINE\n" );
return true;
}
bool NETCLASSES::Save( FILE* aFile ) const
{
bool result;
// save the default first.
result = m_Default.Save( aFile );
if( result )
{
// the rest will be alphabetical in the *.brd file.
for( const_iterator i = begin(); i!=end(); ++i )
{
NETCLASS* netclass = i->second;
result = netclass->Save( aFile );
if( !result )
break;
}
}
return result;
}
bool NETCLASS::Save( FILE* aFile ) const
{
bool result = true;
fprintf( aFile, "$NCLASS\n" );
fprintf( aFile, "Name %s\n", EscapedUTF8( m_Name ).c_str() );
fprintf( aFile, "Desc %s\n", EscapedUTF8( GetDescription() ).c_str() );
// Write parameters
fprintf( aFile, "Clearance %d\n", GetClearance() );
fprintf( aFile, "TrackWidth %d\n", GetTrackWidth() );
fprintf( aFile, "ViaDia %d\n", GetViaDiameter() );
fprintf( aFile, "ViaDrill %d\n", GetViaDrill() );
fprintf( aFile, "uViaDia %d\n", GetuViaDiameter() );
fprintf( aFile, "uViaDrill %d\n", GetuViaDrill() );
// Write members:
for( const_iterator i = begin(); i!=end(); ++i )
fprintf( aFile, "AddNet %s\n", EscapedUTF8( *i ).c_str() );
fprintf( aFile, "$EndNCLASS\n" );
return result;
}
bool TEXTE_PCB::Save( FILE* aFile ) const
{
if( m_Text.IsEmpty() )
return true;
if( fprintf( aFile, "$TEXTPCB\n" ) != sizeof("$TEXTPCB\n") - 1 )
return false;
const char* style = m_Italic ? "Italic" : "Normal";
wxArrayString* list = wxStringSplit( m_Text, '\n' );
for( unsigned ii = 0; ii < list->Count(); ii++ )
{
wxString txt = list->Item( ii );
if ( ii == 0 )
fprintf( aFile, "Te %s\n", EscapedUTF8( txt ).c_str() );
else
fprintf( aFile, "nl %s\n", EscapedUTF8( txt ).c_str() );
}
delete list;
fprintf( aFile, "Po %d %d %d %d %d %g\n",
m_Pos.x, m_Pos.y, m_Size.x, m_Size.y, m_Thickness, GetOrientation() );
char hJustify = 'L';
switch( m_HJustify )
{
case GR_TEXT_HJUSTIFY_LEFT:
hJustify = 'L';
break;
case GR_TEXT_HJUSTIFY_CENTER:
hJustify = 'C';
break;
case GR_TEXT_HJUSTIFY_RIGHT:
hJustify = 'R';
break;
default:
hJustify = 'C';
break;
}
fprintf( aFile, "De %d %d %lX %s %c\n", m_Layer,
m_Mirror ? 0 : 1,
m_TimeStamp, style, hJustify );
if( fprintf( aFile, "$EndTEXTPCB\n" ) != sizeof("$EndTEXTPCB\n") - 1 )
return false;
return true;
}
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool TEXTE_MODULE::Save( FILE* aFile ) const
{
MODULE* parent = (MODULE*) GetParent();
int orient = m_Orient;
// Due to the Pcbnew history, m_Orient is saved in screen value
// but it is handled as relative to its parent footprint
if( parent )
orient += parent->m_Orient;
int ret = fprintf( aFile, "T%d %d %d %d %d %d %d %c %c %d %c %s\n",
m_Type,
m_Pos0.x, m_Pos0.y,
m_Size.y, m_Size.x,
orient,
m_Thickness,
m_Mirror ? 'M' : 'N', m_NoShow ? 'I' : 'V',
GetLayer(),
m_Italic ? 'I' : 'N',
EscapedUTF8( m_Text ).c_str()
);
return ret > 20;
}
bool EDGE_MODULE::Save( FILE* aFile ) const
{
int ret = -1;
switch( m_Shape )
{
case S_SEGMENT:
ret = fprintf( aFile, "DS %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_Width, m_Layer );
break;
case S_CIRCLE:
ret = fprintf( aFile, "DC %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
m_Width, m_Layer );
break;
case S_ARC:
ret = fprintf( aFile, "DA %d %d %d %d %g %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
GetAngle(),
m_Width, m_Layer );
break;
case S_POLYGON:
ret = fprintf( aFile, "DP %d %d %d %d %d %d %d\n",
m_Start0.x, m_Start0.y,
m_End0.x, m_End0.y,
(int) m_PolyPoints.size(),
m_Width, m_Layer );
for( unsigned i = 0; i<m_PolyPoints.size(); ++i )
fprintf( aFile, "Dl %d %d\n", m_PolyPoints[i].x, m_PolyPoints[i].y );
break;
default:
// future: throw an exception here
#if defined(DEBUG)
printf( "EDGE_MODULE::Save(): unexpected m_Shape: %d\n", m_Shape );
#endif
break;
}
return ret > 5;
}
bool TRACK::Save( FILE* aFile ) const
{
int type = 0;
if( Type() == PCB_VIA_T )
type = 1;
fprintf( aFile, "Po %d %d %d %d %d %d %d\n", m_Shape,
m_Start.x, m_Start.y, m_End.x, m_End.y, m_Width, m_Drill );
fprintf( aFile, "De %d %d %d %lX %X\n",
m_Layer, type, GetNet(),
m_TimeStamp, GetStatus() );
return true;
}
bool DIMENSION::Save( FILE* aFile ) const
{
bool rc = false;
// note: COTATION was the previous name of DIMENSION
// this old keyword is used here for compatibility
const char keyWordLine[] = "$COTATION\n";
const char keyWordLineEnd[] = "$endCOTATION\n";
if( fputs( keyWordLine, aFile ) == EOF )
goto out;
fprintf( aFile, "Ge %d %d %lX\n", m_Shape, m_Layer, m_TimeStamp );
fprintf( aFile, "Va %d\n", m_Value );
if( !m_Text.GetText().IsEmpty() )
fprintf( aFile, "Te %s\n", EscapedUTF8( m_Text.GetText() ).c_str() );
else
fprintf( aFile, "Te \"?\"\n" );
fprintf( aFile, "Po %d %d %d %d %d %g %d\n",
m_Text.m_Pos.x, m_Text.m_Pos.y,
m_Text.m_Size.x, m_Text.m_Size.y,
m_Text.GetThickness(), m_Text.GetOrientation(),
m_Text.m_Mirror ? 0 : 1 );
fprintf( aFile, "Sb %d %d %d %d %d %d\n", S_SEGMENT,
m_crossBarOx, m_crossBarOy,
m_crossBarFx, m_crossBarFy, m_Width );
fprintf( aFile, "Sd %d %d %d %d %d %d\n", S_SEGMENT,
m_featureLineDOx, m_featureLineDOy,
m_featureLineDFx, m_featureLineDFy, m_Width );
fprintf( aFile, "Sg %d %d %d %d %d %d\n", S_SEGMENT,
m_featureLineGOx, m_featureLineGOy,
m_featureLineGFx, m_featureLineGFy, m_Width );
fprintf( aFile, "S1 %d %d %d %d %d %d\n", S_SEGMENT,
m_arrowD1Ox, m_arrowD1Oy,
m_arrowD1Fx, m_arrowD1Fy, m_Width );
fprintf( aFile, "S2 %d %d %d %d %d %d\n", S_SEGMENT,
m_arrowD2Ox, m_arrowD2Oy,
m_arrowD2Fx, m_arrowD2Fy, m_Width );
fprintf( aFile, "S3 %d %d %d %d %d %d\n", S_SEGMENT,
m_arrowG1Ox, m_arrowG1Oy,
m_arrowG1Fx, m_arrowG1Fy, m_Width );
fprintf( aFile, "S4 %d %d %d %d %d %d\n", S_SEGMENT,
m_arrowG2Ox, m_arrowG2Oy,
m_arrowG2Fx, m_arrowG2Fy, m_Width );
if( fputs( keyWordLineEnd, aFile ) == EOF )
goto out;
rc = true;
out:
return rc;
}
bool D_PAD::Save( FILE* aFile ) const
{
int cshape;
const char* texttype;
// check the return values for first and last fprints() in this function
if( fprintf( aFile, "$PAD\n" ) != sizeof("$PAD\n") - 1 )
return false;
switch( m_PadShape )
{
case PAD_CIRCLE:
cshape = 'C'; break;
case PAD_RECT:
cshape = 'R'; break;
case PAD_OVAL:
cshape = 'O'; break;
case PAD_TRAPEZOID:
cshape = 'T'; break;
default:
cshape = 'C';
DisplayError( NULL, _( "Unknown pad shape" ) );
break;
}
fprintf( aFile, "Sh \"%.4s\" %c %d %d %d %d %g\n",
m_Padname, cshape, m_Size.x, m_Size.y,
m_DeltaSize.x, m_DeltaSize.y, m_Orient );
fprintf( aFile, "Dr %d %d %d", m_Drill.x, m_Offset.x, m_Offset.y );
if( m_DrillShape == PAD_OVAL )
{
fprintf( aFile, " %c %d %d", 'O', m_Drill.x, m_Drill.y );
}
fprintf( aFile, "\n" );
switch( GetAttribute() )
{
case PAD_STANDARD:
texttype = "STD"; break;
case PAD_SMD:
texttype = "SMD"; break;
case PAD_CONN:
texttype = "CONN"; break;
case PAD_HOLE_NOT_PLATED:
texttype = "HOLE"; break;
default:
texttype = "STD";
DisplayError( NULL, wxT( "Invalid Pad attribute" ) );
break;
}
fprintf( aFile, "At %s N %8.8X\n", texttype, m_layerMask );
fprintf( aFile, "Ne %d %s\n", GetNet(), EscapedUTF8( m_Netname ).c_str() );
fprintf( aFile, "Po %d %d\n", m_Pos0.x, m_Pos0.y );
if( GetDieLength() != 0 )
fprintf( aFile, "Le %d\n", GetDieLength() );
if( GetLocalSolderMaskMargin() != 0 )
fprintf( aFile, ".SolderMask %d\n", GetLocalSolderMaskMargin() );
if( GetLocalSolderPasteMargin() != 0 )
fprintf( aFile, ".SolderPaste %d\n", GetLocalSolderPasteMargin() );
if( GetLocalSolderPasteMarginRatio() != 0 )
fprintf( aFile, ".SolderPasteRatio %g\n", GetLocalSolderPasteMarginRatio() );
if( GetLocalClearance() != 0 )
fprintf( aFile, ".LocalClearance %d\n", GetLocalClearance() );
if( m_ZoneConnection != UNDEFINED_CONNECTION )
fprintf( aFile, ".ZoneConnection %d\n", m_ZoneConnection );
if( m_ThermalWidth != 0 )
fprintf( aFile, ".ThermalWidth %d\n", m_ThermalWidth );
if( m_ThermalGap != 0 )
fprintf( aFile, ".ThermalGap %d\n", m_ThermalGap );
if( fprintf( aFile, "$EndPAD\n" ) != sizeof("$EndPAD\n") - 1 )
return false;
return true;
}
bool MODULE::Save( FILE* aFile ) const
{
char statusTxt[8];
BOARD_ITEM* item;
bool rc = false;
fprintf( aFile, "$MODULE %s\n", TO_UTF8( m_LibRef ) );
memset( statusTxt, 0, sizeof(statusTxt) );
if( IsLocked() )
statusTxt[0] = 'F';
else
statusTxt[0] = '~';
if( m_ModuleStatus & MODULE_is_PLACED )
statusTxt[1] = 'P';
else
statusTxt[1] = '~';
fprintf( aFile, "Po %d %d %g %d %8.8lX %8.8lX %s\n",
m_Pos.x, m_Pos.y,
GetOrientation(), m_Layer, m_LastEdit_Time,
m_TimeStamp, statusTxt );
fprintf( aFile, "Li %s\n", TO_UTF8( m_LibRef ) );
if( !m_Doc.IsEmpty() )
{
fprintf( aFile, "Cd %s\n", TO_UTF8( m_Doc ) );
}
if( !m_KeyWord.IsEmpty() )
{
fprintf( aFile, "Kw %s\n", TO_UTF8( m_KeyWord ) );
}
fprintf( aFile, "Sc %8.8lX\n", m_TimeStamp );
fprintf( aFile, "AR %s\n", TO_UTF8( m_Path ) );
fprintf( aFile, "Op %X %X 0\n", m_CntRot90, m_CntRot180 );
if( GetLocalSolderMaskMargin() != 0 )
fprintf( aFile, ".SolderMask %d\n", GetLocalSolderMaskMargin() );
if( m_LocalSolderPasteMargin != 0 )
fprintf( aFile, ".SolderPaste %d\n", GetLocalSolderPasteMargin() );
if( GetLocalSolderPasteMarginRatio() != 0 )
fprintf( aFile, ".SolderPasteRatio %g\n", GetLocalSolderPasteMarginRatio() );
if( m_LocalClearance != 0 )
fprintf( aFile, ".LocalClearance %d\n", GetLocalClearance() );
if( m_ZoneConnection != UNDEFINED_CONNECTION )
fprintf( aFile, ".ZoneConnection %d\n", m_ZoneConnection );
if( m_ThermalWidth != 0 )
fprintf( aFile, ".ThermalWidth %d\n", m_ThermalWidth );
if( m_ThermalGap != 0 )
fprintf( aFile, ".ThermalGap %d\n", m_ThermalGap );
// attributes
if( m_Attributs != MOD_DEFAULT )
{
fprintf( aFile, "At " );
if( m_Attributs & MOD_CMS )
fprintf( aFile, "SMD " );
if( m_Attributs & MOD_VIRTUAL )
fprintf( aFile, "VIRTUAL " );
fprintf( aFile, "\n" );
}
// save reference
if( !m_Reference->Save( aFile ) )
goto out;
// save value
if( !m_Value->Save( aFile ) )
goto out;
// save drawing elements
for( item = m_Drawings; item; item = item->Next() )
{
switch( item->Type() )
{
case PCB_MODULE_TEXT_T:
case PCB_MODULE_EDGE_T:
if( !item->Save( aFile ) )
goto out;
break;
default:
#if defined(DEBUG)
printf( "MODULE::Save() ignoring type %d\n", item->Type() );
#endif
break;
}
}
// save the pads
for( item = m_Pads; item; item = item->Next() )
if( !item->Save( aFile ) )
goto out;
Write_3D_Descr( aFile );
fprintf( aFile, "$EndMODULE %s\n", TO_UTF8( m_LibRef ) );
rc = true;
out:
return rc;
}
/* Save the description of 3D MODULE
*/
int MODULE::Write_3D_Descr( FILE* File ) const
{
char buf[512];
for( S3D_MASTER* t3D = m_3D_Drawings; t3D; t3D = t3D->Next() )
{
if( !t3D->m_Shape3DName.IsEmpty() )
{
fprintf( File, "$SHAPE3D\n" );
fprintf( File, "Na %s\n", EscapedUTF8( t3D->m_Shape3DName ).c_str() );
sprintf( buf, "Sc %lf %lf %lf\n",
t3D->m_MatScale.x,
t3D->m_MatScale.y,
t3D->m_MatScale.z );
fprintf( File, "%s", to_point( buf ) );
sprintf( buf, "Of %lf %lf %lf\n",
t3D->m_MatPosition.x,
t3D->m_MatPosition.y,
t3D->m_MatPosition.z );
fprintf( File, "%s", to_point( buf ) );
sprintf( buf, "Ro %lf %lf %lf\n",
t3D->m_MatRotation.x,
t3D->m_MatRotation.y,
t3D->m_MatRotation.z );
fprintf( File, "%s", to_point( buf ) );
fprintf( File, "$EndSHAPE3D\n" );
}
}
return 0;
}
#endif // USE_NEW_PCBNEW_SAVE
#if 1 || !defined(USE_NEW_PCBNEW_LOAD)
/* Read pad from file.
* The 1st line of descr ($PAD) is assumed to be already read
* Syntax:
* $PAD
* Sh "N1" C 550 550 0 0 1800
* Dr 310 0 0
* At STD N 00C0FFFF
* Do 3 "netname"
* Po 6000 -6000
* $EndPAD
*/
int D_PAD::ReadDescr( LINE_READER* aReader )
{
char* Line;
char BufLine[1024], BufCar[256];
char* PtLine;
int nn, ll, dx, dy;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( Line[0] == '$' )
return 0;
PtLine = Line + 3;
/* Decode the first code and read the corresponding data
*/
switch( Line[0] )
{
case 'S': // = Sh
// Read pad name
nn = 0;
while( (*PtLine != '"') && *PtLine )
PtLine++;
if( *PtLine )
PtLine++;
memset( m_Padname, 0, sizeof(m_Padname) );
while( (*PtLine != '"') && *PtLine )
{
if( nn < (int) sizeof(m_Padname) )
{
if( *PtLine > ' ' )
{
m_Padname[nn] = *PtLine; nn++;
}
}
PtLine++;
}
if( *PtLine == '"' )
PtLine++;
nn = sscanf( PtLine, " %s %d %d %d %d %lf",
BufCar, &m_Size.x, &m_Size.y,
&m_DeltaSize.x, &m_DeltaSize.y,
&m_Orient );
ll = 0xFF & BufCar[0];
// Read pad shape
PAD_SHAPE_T shape;
switch( ll )
{
default:
case 'C': shape = PAD_CIRCLE; break;
case 'R': shape = PAD_RECT; break;
case 'O': shape = PAD_OVAL; break;
case 'T': shape = PAD_TRAPEZOID; break;
}
SetShape( shape ); // sets m_boundingRadius = -1
break;
case 'D':
BufCar[0] = 0;
nn = sscanf( PtLine, "%d %d %d %s %d %d", &m_Drill.x,
&m_Offset.x, &m_Offset.y, BufCar, &dx, &dy );
m_Drill.y = m_Drill.x;
m_DrillShape = PAD_CIRCLE;
if( nn >= 6 ) // Drill shape = OVAL ?
{
if( BufCar[0] == 'O' )
{
m_Drill.x = dx;
m_Drill.y = dy;
m_DrillShape = PAD_OVAL;
}
}
break;
case 'A':
nn = sscanf( PtLine, "%s %s %X", BufLine, BufCar,
&m_layerMask );
// BufCar is not used now update attributes
SetAttribute( PAD_STANDARD );
if( strncmp( BufLine, "SMD", 3 ) == 0 )
SetAttribute( PAD_SMD );
if( strncmp( BufLine, "CONN", 4 ) == 0 )
SetAttribute( PAD_CONN );
if( strncmp( BufLine, "HOLE", 4 ) == 0 )
SetAttribute( PAD_HOLE_NOT_PLATED );
break;
case 'N': // Read Netname
int netcode;
nn = sscanf( PtLine, "%d", &netcode );
SetNet( netcode );
// read Netname
ReadDelimitedText( BufLine, PtLine, sizeof(BufLine) );
SetNetname( FROM_UTF8( StrPurge( BufLine ) ) );
break;
case 'P':
nn = sscanf( PtLine, "%d %d", &m_Pos0.x, &m_Pos0.y );
m_Pos = m_Pos0;
break;
case 'L':
int lengthdie;
nn = sscanf( PtLine, "%d", &lengthdie );
SetDieLength( lengthdie );
break;
case '.': // Read specific data
if( strnicmp( Line, ".SolderMask ", 12 ) == 0 )
SetLocalSolderMaskMargin( atoi( Line + 12 ) );
else if( strnicmp( Line, ".SolderPaste ", 13 ) == 0 )
SetLocalSolderPasteMargin( atoi( Line + 13 ) );
else if( strnicmp( Line, ".SolderPasteRatio ", 18 ) == 0 )
SetLocalSolderPasteMarginRatio( atoi( Line + 18 ) );
else if( strnicmp( Line, ".LocalClearance ", 16 ) == 0 )
SetLocalClearance( atoi( Line + 16 ) );
else if( strnicmp( Line, ".ZoneConnection ", 16 ) == 0 )
m_ZoneConnection = (ZoneConnection)atoi( Line + 16 );
else if( strnicmp( Line, ".ThermalWidth ", 14 ) == 0 )
m_ThermalWidth = atoi( Line + 14 );
else if( strnicmp( Line, ".ThermalGap ", 12 ) == 0 )
m_ThermalGap = atoi( Line + 12 );
break;
default:
DisplayError( NULL, wxT( "Err Pad: Id inconnu" ) );
return 1;
}
}
return 2; // error : EOF
}
/* Read 3D module from file. (Ascii)
* The 1st line of descr ($MODULE) is assumed to be already read
* Returns 0 if OK
*/
int MODULE::Read_3D_Descr( LINE_READER* aReader )
{
char* Line = aReader->Line();
char* text = Line + 3;
S3D_MASTER* t3D = m_3D_Drawings;
if( !t3D->m_Shape3DName.IsEmpty() )
{
S3D_MASTER* n3D = new S3D_MASTER( this );
m_3D_Drawings.PushBack( n3D );
t3D = n3D;
}
while( aReader->ReadLine() )
{
Line = aReader->Line();
switch( Line[0] )
{
case '$':
if( Line[1] == 'E' )
return 0;
return 1;
case 'N': // Shape File Name
{
char buf[512];
ReadDelimitedText( buf, text, 512 );
t3D->m_Shape3DName = FROM_UTF8( buf );
break;
}
case 'S': // Scale
sscanf( text, "%lf %lf %lf\n",
&t3D->m_MatScale.x,
&t3D->m_MatScale.y,
&t3D->m_MatScale.z );
break;
case 'O': // Offset
sscanf( text, "%lf %lf %lf\n",
&t3D->m_MatPosition.x,
&t3D->m_MatPosition.y,
&t3D->m_MatPosition.z );
break;
case 'R': // Rotation
sscanf( text, "%lf %lf %lf\n",
&t3D->m_MatRotation.x,
&t3D->m_MatRotation.y,
&t3D->m_MatRotation.z );
break;
default:
break;
}
}
return 1;
}
/* Read a MODULE description
* The first description line ($MODULE) is already read
* @return 0 if no error
*/
int MODULE::ReadDescr( LINE_READER* aReader )
{
char* Line;
char BufLine[256], BufCar1[128], * PtLine;
int itmp1, itmp2;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( Line[0] == '$' )
{
if( Line[1] == 'E' )
break;
if( Line[1] == 'P' )
{
D_PAD* pad = new D_PAD( this );
pad->ReadDescr( aReader );
wxPoint padpos = pad->GetPosition();
RotatePoint( &padpos, m_Orient );
pad->SetPosition( padpos + m_Pos );
m_Pads.PushBack( pad );
continue;
}
if( Line[1] == 'S' )
Read_3D_Descr( aReader );
}
if( strlen( Line ) < 4 )
continue;
PtLine = Line + 3;
/* Decode the first code of the current line and read the
* corresponding data
*/
switch( Line[0] )
{
case 'P':
double orientation;
memset( BufCar1, 0, sizeof(BufCar1) );
sscanf( PtLine, "%d %d %lf %d %lX %lX %s",
&m_Pos.x, &m_Pos.y,
&orientation, &m_Layer,
&m_LastEdit_Time, &m_TimeStamp, BufCar1 );
SetOrientation( orientation );
m_ModuleStatus = 0;
if( BufCar1[0] == 'F' )
SetLocked( true );
if( BufCar1[1] == 'P' )
m_ModuleStatus |= MODULE_is_PLACED;
break;
case 'L': // Li = read the library name of the footprint
*BufLine = 0;
sscanf( PtLine, " %s", BufLine );
m_LibRef = FROM_UTF8( BufLine );
break;
case 'S':
sscanf( PtLine, " %lX", &m_TimeStamp );
break;
case 'O': // (Op)tions for auto placement
itmp1 = itmp2 = 0;
sscanf( PtLine, " %X %X", &itmp1, &itmp2 );
m_CntRot180 = itmp2 & 0x0F;
if( m_CntRot180 > 10 )
m_CntRot180 = 10;
m_CntRot90 = itmp1 & 0x0F;
if( m_CntRot90 > 10 )
m_CntRot90 = 0;
itmp1 = (itmp1 >> 4) & 0x0F;
if( itmp1 > 10 )
itmp1 = 0;
m_CntRot90 |= itmp1 << 4;
break;
case 'A':
if( Line[1] == 't' )
{
// At = (At)tributes of module
if( strstr( PtLine, "SMD" ) )
m_Attributs |= MOD_CMS;
if( strstr( PtLine, "VIRTUAL" ) )
m_Attributs |= MOD_VIRTUAL;
}
if( Line[1] == 'R' )
{
// alternate reference, e.g. /478C2408/478AD1B6
sscanf( PtLine, " %s", BufLine );
m_Path = FROM_UTF8( BufLine );
}
break;
case 'T': /* Read a footprint text description (ref, value, or
* drawing */
TEXTE_MODULE * textm;
sscanf( Line + 1, "%d", &itmp1 );
if( itmp1 == TEXT_is_REFERENCE )
textm = m_Reference;
else if( itmp1 == TEXT_is_VALUE )
textm = m_Value;
else // text is a drawing
{
textm = new TEXTE_MODULE( this );
m_Drawings.PushBack( textm );
}
textm->ReadDescr( aReader );
break;
case 'D': // read a drawing item
EDGE_MODULE * edge;
edge = new EDGE_MODULE( this );
m_Drawings.PushBack( edge );
edge->ReadDescr( aReader );
edge->SetDrawCoord();
break;
case 'C': // read documentation data
m_Doc = FROM_UTF8( StrPurge( PtLine ) );
break;
case 'K': // Read key words
m_KeyWord = FROM_UTF8( StrPurge( PtLine ) );
break;
case '.': // Read specific data
if( strnicmp( Line, ".SolderMask ", 12 ) == 0 )
SetLocalSolderMaskMargin( atoi( Line + 12 ) );
else if( strnicmp( Line, ".SolderPaste ", 13 ) == 0 )
SetLocalSolderPasteMargin( atoi( Line + 13 ) );
else if( strnicmp( Line, ".SolderPasteRatio ", 18 ) == 0 )
SetLocalSolderPasteMarginRatio( atof( Line + 18 ) );
else if( strnicmp( Line, ".LocalClearance ", 16 ) == 0 )
SetLocalClearance( atoi( Line + 16 ) );
else if( strnicmp( Line, ".ZoneConnection ", 16 ) == 0 )
m_ZoneConnection = (ZoneConnection)atoi( Line + 16 );
else if( strnicmp( Line, ".ThermalWidth ", 14 ) == 0 )
m_ThermalWidth = atoi( Line + 14 );
else if( strnicmp( Line, ".ThermalGap ", 12 ) == 0 )
m_ThermalGap = atoi( Line + 12 );
break;
default:
break;
}
}
// Recalculate the bounding box
CalculateBoundingBox();
return 0;
}
/* Read a description line like:
* DS 2600 0 2600 -600 120 21
* this description line is in Line
* EDGE_MODULE type can be:
* - Circle,
* - Segment (line)
* - Arc
* - Polygon
*
*/
int EDGE_MODULE::ReadDescr( LINE_READER* aReader )
{
int ii;
int error = 0;
char* Buf;
char* Line;
Line = aReader->Line();
switch( Line[1] )
{
case 'S':
m_Shape = S_SEGMENT;
break;
case 'C':
m_Shape = S_CIRCLE;
break;
case 'A':
m_Shape = S_ARC;
break;
case 'P':
m_Shape = S_POLYGON;
break;
default:
wxString msg;
msg.Printf( wxT( "Unknown EDGE_MODULE type <%s>" ), Line );
DisplayError( NULL, msg );
error = 1;
break;
}
switch( m_Shape )
{
case S_ARC:
double angle;
sscanf( Line + 3, "%d %d %d %d %lf %d %d",
&m_Start0.x, &m_Start0.y,
&m_End0.x, &m_End0.y,
&angle, &m_Width, &m_Layer );
NORMALIZE_ANGLE_360( angle );
SetAngle( angle );
break;
case S_SEGMENT:
case S_CIRCLE:
sscanf( Line + 3, "%d %d %d %d %d %d",
&m_Start0.x, &m_Start0.y,
&m_End0.x, &m_End0.y,
&m_Width, &m_Layer );
break;
case S_POLYGON:
int pointCount;
sscanf( Line + 3, "%d %d %d %d %d %d %d",
&m_Start0.x, &m_Start0.y,
&m_End0.x, &m_End0.y,
&pointCount, &m_Width, &m_Layer );
m_PolyPoints.clear();
m_PolyPoints.reserve( pointCount );
for( ii = 0; ii<pointCount; ii++ )
{
if( aReader->ReadLine() )
{
Buf = aReader->Line();
if( strncmp( Buf, "Dl", 2 ) != 0 )
{
error = 1;
break;
}
int x;
int y;
sscanf( Buf + 3, "%d %d\n", &x, &y );
m_PolyPoints.push_back( wxPoint( x, y ) );
}
else
{
error = 1;
break;
}
}
break;
default:
sscanf( Line + 3, "%d %d %d %d %d %d",
&m_Start0.x, &m_Start0.y,
&m_End0.x, &m_End0.y,
&m_Width, &m_Layer );
break;
}
// Check for a reasonable width:
if( m_Width <= 1 )
m_Width = 1;
if( m_Width > MAX_WIDTH )
m_Width = MAX_WIDTH;
// Check for a reasonable layer:
// m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints
// can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed.
// @todo: changes use of EDGE_MODULE these footprints and allows only
// m_Layer >= FIRST_NON_COPPER_LAYER
if( (m_Layer < 0) || (m_Layer > LAST_NON_COPPER_LAYER) )
m_Layer = SILKSCREEN_N_FRONT;
return error;
}
bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader )
{
char* Line;
char Text[2048];
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$EndDIMENSION", 4 ) == 0 )
return true;
if( Line[0] == 'V' )
{
sscanf( Line + 2, " %d", &m_Value );
continue;
}
if( Line[0] == 'G' )
{
int layer;
sscanf( Line + 2, " %d %d %lX", &m_Shape, &layer, &m_TimeStamp );
if( layer < FIRST_NO_COPPER_LAYER )
layer = FIRST_NO_COPPER_LAYER;
if( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
SetLayer( layer );
m_Text.SetLayer( layer );
continue;
}
if( Line[0] == 'T' )
{
ReadDelimitedText( Text, Line + 2, sizeof(Text) );
m_Text.m_Text = FROM_UTF8( Text );
continue;
}
if( Line[0] == 'P' )
{
int normal_display = 1;
int orientation;
int thickness;
sscanf( Line + 2, " %d %d %d %d %d %d %d",
&m_Text.m_Pos.x, &m_Text.m_Pos.y,
&m_Text.m_Size.x, &m_Text.m_Size.y,
&thickness, &orientation,
&normal_display );
m_Text.m_Mirror = normal_display ? false : true;
m_Pos = m_Text.m_Pos;
m_Text.SetOrientation( orientation );
m_Text.SetThickness( thickness );
continue;
}
if( Line[0] == 'S' )
{
switch( Line[1] )
{
int Dummy;
case 'b':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_crossBarOx, &m_crossBarOy,
&m_crossBarFx, &m_crossBarFy,
&m_Width );
break;
case 'd':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_featureLineDOx, &m_featureLineDOy,
&m_featureLineDFx, &m_featureLineDFy,
&Dummy );
break;
case 'g':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_featureLineGOx, &m_featureLineGOy,
&m_featureLineGFx, &m_featureLineGFy,
&Dummy );
break;
case '1':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_arrowD1Ox, &m_arrowD1Oy,
&m_arrowD1Fx, &m_arrowD1Fy,
&Dummy );
break;
case '2':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_arrowD2Ox, &m_arrowD2Oy,
&m_arrowD2Fx, &m_arrowD2Fy,
&Dummy );
break;
case '3':
sscanf( Line + 2, " %d %d %d %d %d %d\n",
&Dummy,
&m_arrowG1Ox, &m_arrowG1Oy,
&m_arrowG1Fx, &m_arrowG1Fy,
&Dummy );
break;
case '4':
sscanf( Line + 2, " %d %d %d %d %d %d",
&Dummy,
&m_arrowG2Ox, &m_arrowG2Oy,
&m_arrowG2Fx, &m_arrowG2Fy,
&Dummy );
break;
}
continue;
}
}
return false;
}
bool DRAWSEGMENT::ReadDrawSegmentDescr( LINE_READER* aReader )
{
char* Line;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 )
return true; // End of description
if( Line[0] == 'P' )
{
sscanf( Line + 2, " %d %d %d %d %d %d",
&m_Shape, &m_Start.x, &m_Start.y,
&m_End.x, &m_End.y, &m_Width );
if( m_Width < 0 )
m_Width = 0;
}
if( Line[0] == 'D' )
{
int status;
char* token = 0;
token = strtok( Line," " );
for( int i = 0; (token = strtok( NULL," " )) != NULL; i++ )
{
switch( i )
{
case 0:
sscanf( token,"%d",&m_Layer );
break;
case 1:
sscanf( token,"%d",&m_Type );
break;
case 2:
double angle;
sscanf( token, "%lf", &angle );
SetAngle( angle );
break;
case 3:
sscanf( token,"%lX",&m_TimeStamp );
break;
case 4:
sscanf( token,"%X",&status );
break;
// Bezier Control Points
case 5:
sscanf( token,"%d",&m_BezierC1.x );
break;
case 6:
sscanf( token,"%d",&m_BezierC1.y );
break;
case 7:
sscanf( token,"%d",&m_BezierC2.x );
break;
case 8:
sscanf( token,"%d",&m_BezierC2.y );
break;
default:
break;
}
}
if( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
SetState( status, ON );
}
}
return false;
}
/* Read NETINFO_ITEM from file.
* Returns 0 if OK
* 1 if incomplete reading
*/
int NETINFO_ITEM::ReadDescr( LINE_READER* aReader )
{
char* Line;
char Ltmp[1024];
int tmp;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 )
return 0;
if( strncmp( Line, "Na", 2 ) == 0 )
{
sscanf( Line + 2, " %d", &tmp );
SetNet( tmp );
ReadDelimitedText( Ltmp, Line + 2, sizeof(Ltmp) );
m_Netname = FROM_UTF8( Ltmp );
continue;
}
}
return 1;
}
/* Read the description from the PCB file.
*/
bool PCB_TARGET::ReadMirePcbDescr( LINE_READER* aReader )
{
char* Line;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$End", 4 ) == 0 )
return true;
if( Line[0] == 'P' )
{
sscanf( Line + 2, " %X %d %d %d %d %d %lX",
&m_Shape, &m_Layer,
&m_Pos.x, &m_Pos.y,
&m_Size, &m_Width, &m_TimeStamp );
if( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
}
}
return false;
}
int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader )
{
char* Line, * text;
char netname_buffer[1024];
int ret;
int outline_hatch = CPolyLine::NO_HATCH;
bool error = false, has_corner = false;
netname_buffer[0] = 0;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "ZCorner", 7 ) == 0 ) // new corner found
{
int x;
int y;
int flag;
text = Line + 7;
ret = sscanf( text, "%d %d %d", &x, &y, &flag );
if( ret < 3 )
{
error = true;
}
else
{
if( !has_corner )
m_Poly->Start( m_Layer, x, y, outline_hatch );
else
AppendCorner( wxPoint( x, y ) );
has_corner = true;
if( flag )
m_Poly->Close();
}
}
else if( strnicmp( Line, "ZInfo", 5 ) == 0 ) // general info found
{
int ts;
int netcode;
text = Line + 5;
ret = sscanf( text, "%X %d %s", &ts, &netcode, netname_buffer );
if( ret < 3 )
{
error = true;
}
else
{
SetTimeStamp( ts );
SetNet( netcode );
ReadDelimitedText( netname_buffer, netname_buffer, 1024 );
m_Netname = FROM_UTF8( netname_buffer );
}
}
else if( strnicmp( Line, "ZLayer", 6 ) == 0 ) // layer found
{
int x;
text = Line + 6;
ret = sscanf( text, "%d", &x );
if( ret < 1 )
error = true;
else
m_Layer = x;
}
else if( strnicmp( Line, "ZAux", 4 ) == 0 ) // aux info found
{
int x;
char hopt[10];
text = Line + 4;
ret = sscanf( text, "%d %c", &x, hopt );
if( ret < 2 )
{
error = true;
}
else
{
switch( hopt[0] )
{
case 'n':
case 'N':
outline_hatch = CPolyLine::NO_HATCH;
break;
case 'e':
case 'E':
outline_hatch = CPolyLine::DIAGONAL_EDGE;
break;
case 'f':
case 'F':
outline_hatch = CPolyLine::DIAGONAL_FULL;
break;
}
}
// Set hatch mode later, after reading outlines corners data
}
else if( strnicmp( Line, "ZPriority", 9 ) == 0 )
{
int tmp = 0;
text = Line + 9;
ret = sscanf( text, "%d", &tmp );
if( ret < 1 )
return false;
SetPriority( tmp );
}
else if( strnicmp( Line, "ZSmoothing", 10 ) == 0 )
{
int tempSmoothingType;
int tempCornerRadius;
text = Line + 10;
ret = sscanf( text, "%d %d", &tempSmoothingType, &tempCornerRadius );
if( ret < 2 )
return false;
if( tempSmoothingType >= ZONE_SETTINGS::SMOOTHING_LAST )
return false;
if( tempSmoothingType < 0 )
return false;
cornerSmoothingType = tempSmoothingType;
SetCornerRadius( tempCornerRadius );
}
else if( strnicmp( Line, "ZOptions", 8 ) == 0 ) // Options info found
{
int fillmode = 1;
int arcsegmentcount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF;
char fillstate = 'F';
text = Line + 8;
ret = sscanf( text, "%d %d %c %d %d", &fillmode, &arcsegmentcount, &fillstate,
&m_ThermalReliefGap, &m_ThermalReliefCopperBridge );
if( ret < 1 ) // Must find 1 or more args.
return false;
else
m_FillMode = fillmode ? 1 : 0;
if( arcsegmentcount >= ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF )
m_ArcToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF;
m_IsFilled = (fillstate == 'S') ? true : false;
}
else if( strnicmp( Line, "ZClearance", 10 ) == 0 ) // Clearance and pad options info found
{
int clearance = 200;
char padConnection;
text = Line + 10;
ret = sscanf( text, "%d %1c", &clearance, &padConnection );
if( ret < 2 )
{
error = true;
}
else
{
m_ZoneClearance = clearance;
switch( padConnection )
{
case 'i':
case 'I':
m_PadConnection = PAD_IN_ZONE;
break;
case 't':
case 'T':
m_PadConnection = THERMAL_PAD;
break;
case 'x':
case 'X':
m_PadConnection = PAD_NOT_IN_ZONE;
break;
}
}
}
else if( strnicmp( Line, "ZMinThickness", 13 ) == 0 ) // Min Thickness info found
{
int thickness;
text = Line + 13;
ret = sscanf( text, "%d", &thickness );
if( ret < 1 )
error = true;
else
m_ZoneMinThickness = thickness;
}
else if( strnicmp( Line, "$POLYSCORNERS", 13 ) == 0 ) // Read the PolysList (polygons used for fill areas in the zone)
{
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$endPOLYSCORNERS", 4 ) == 0 )
break;
CPolyPt corner;
int end_contour, utility;
utility = 0;
ret = sscanf( Line,
"%d %d %d %d",
&corner.x,
&corner.y,
&end_contour,
&utility );
if( ret < 4 )
return false;
corner.end_contour = end_contour ? true : false;
corner.utility = utility;
m_FilledPolysList.push_back( corner );
}
}
else if( strnicmp( Line, "$FILLSEGMENTS", 13 ) == 0 )
{
SEGMENT segm;
while( aReader->ReadLine() )
{
Line = aReader->Line();
if( strnicmp( Line, "$endFILLSEGMENTS", 4 ) == 0 )
break;
ret = sscanf( Line,
"%d %d %d %d",
&segm.m_Start.x,
&segm.m_Start.y,
&segm.m_End.x,
&segm.m_End.y );
if( ret < 4 )
return false;
m_FillSegmList.push_back( segm );
}
}
else if( strnicmp( Line, "$end", 4 ) == 0 ) // end of description
{
break;
}
}
if( !IsOnCopperLayer() )
{
m_FillMode = 0;
SetNet( 0 );
}
// Set hatch here, when outlines corners are read
m_Poly->SetHatch( outline_hatch, Mils2iu( m_Poly->GetDefaultHatchPitchMils() ) );
return error ? 0 : 1;
}
bool NETCLASS::ReadDescr( LINE_READER* aReader )
{
bool result = false;
char* line;
char buf[1024];
wxString netname;
while( aReader->ReadLine() )
{
line = aReader->Line();
if( strnicmp( line, "AddNet", 6 ) == 0 )
{
ReadDelimitedText( buf, line + 6, sizeof(buf) );
netname = FROM_UTF8( buf );
Add( netname );
continue;
}
if( strnicmp( line, "$endNCLASS", sizeof( "$endNCLASS" ) - 1 ) == 0 )
{
result = true;
break;
}
if( strnicmp( line, "Clearance", 9 ) == 0 )
{
SetClearance( atoi( line + 9 ) );
continue;
}
if( strnicmp( line, "TrackWidth", 10 ) == 0 )
{
SetTrackWidth( atoi( line + 10 ) );
continue;
}
if( strnicmp( line, "ViaDia", 6 ) == 0 )
{
SetViaDiameter( atoi( line + 6 ) );
continue;
}
if( strnicmp( line, "ViaDrill", 8 ) == 0 )
{
SetViaDrill( atoi( line + 8 ) );
continue;
}
if( strnicmp( line, "uViaDia", 7 ) == 0 )
{
SetuViaDiameter( atoi( line + 7 ) );
continue;
}
if( strnicmp( line, "uViaDrill", 9 ) == 0 )
{
SetuViaDrill( atoi( line + 9 ) );
continue;
}
if( strnicmp( line, "Name", 4 ) == 0 )
{
ReadDelimitedText( buf, line + 4, sizeof(buf) );
m_Name = FROM_UTF8( buf );
continue;
}
if( strnicmp( line, "Desc", 4 ) == 0 )
{
ReadDelimitedText( buf, line + 4, sizeof(buf) );
SetDescription( FROM_UTF8( buf ) );
continue;
}
}
return result;
}
/**
* Function ReadTextePcbDescr
* Read a text description from pcb file.
*
* For a single line text:
*
* $TEXTPCB
* Te "Text example"
* Po 66750 53450 600 800 150 0
* From 24 1 0 Italic
* $EndTEXTPCB
*
* For a multi line text
*
* $TEXTPCB
* Te "Text example"
* Nl "Line 2"
* Po 66750 53450 600 800 150 0
* From 24 1 0 Italic
* $EndTEXTPCB
* Nl "line nn" is a line added to the current text
*/
int TEXTE_PCB::ReadTextePcbDescr( LINE_READER* aReader )
{
char* line;
char text[1024];
char style[256];
while( aReader->ReadLine() )
{
line = aReader->Line();
if( strnicmp( line, "$EndTEXTPCB", 11 ) == 0 )
return 0;
if( strncmp( line, "Te", 2 ) == 0 ) // Text line (first line for multi line texts
{
ReadDelimitedText( text, line + 2, sizeof(text) );
m_Text = FROM_UTF8( text );
continue;
}
if( strncmp( line, "nl", 2 ) == 0 ) // next line of the current text
{
ReadDelimitedText( text, line + 2, sizeof(text) );
m_Text.Append( '\n' );
m_Text += FROM_UTF8( text );
continue;
}
if( strncmp( line, "Po", 2 ) == 0 )
{
double angle;
sscanf( line + 2, " %d %d %d %d %d %lf",
&m_Pos.x, &m_Pos.y, &m_Size.x, &m_Size.y,
&m_Thickness, &angle );
SetOrientation( angle );
// Ensure the text has minimal size to see this text on screen:
if( m_Size.x < 5 )
m_Size.x = 5;
if( m_Size.y < 5 )
m_Size.y = 5;
continue;
}
if( strncmp( line, "De", 2 ) == 0 )
{
style[0] = 0;
int normal_display = 1;
char hJustify = 'c';
sscanf( line + 2, " %d %d %lX %s %c\n", &m_Layer, &normal_display,
&m_TimeStamp, style, &hJustify );
m_Mirror = normal_display ? false : true;
if( m_Layer < FIRST_COPPER_LAYER )
m_Layer = FIRST_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
if( strnicmp( style, "Italic", 6 ) == 0 )
m_Italic = 1;
else
m_Italic = 0;
switch( hJustify )
{
case 'l':
case 'L':
m_HJustify = GR_TEXT_HJUSTIFY_LEFT;
break;
case 'c':
case 'C':
m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
break;
case 'r':
case 'R':
m_HJustify = GR_TEXT_HJUSTIFY_RIGHT;
break;
default:
m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
break;
}
continue;
}
}
// Set a reasonable width:
if( m_Thickness < 1 )
m_Thickness = 1;
m_Thickness = Clamp_Text_PenSize( m_Thickness, m_Size );
return 1;
}
/**
* Function ReadDescr
* Read description from a given line in "*.brd" format.
* @param aReader The line reader object which contains the first line of description.
* @return int - > 0 if success reading else 0.
*/
int TEXTE_MODULE::ReadDescr( LINE_READER* aReader )
{
int success = true;
int type;
char BufCar1[128], BufCar2[128], BufCar3[128];
char* line = aReader->Line();
double angle;
int layer = SILKSCREEN_N_FRONT;
BufCar1[0] = 0;
BufCar2[0] = 0;
BufCar3[0] = 0;
if( sscanf( line + 1, "%d %d %d %d %d %lf %d %s %s %d %s",
&type,
&m_Pos0.x, &m_Pos0.y,
&m_Size.y, &m_Size.x,
&angle, &m_Thickness,
BufCar1, BufCar2, &layer, BufCar3 ) >= 10 )
{
success = true;
SetOrientation( angle );
}
if( (type != TEXT_is_REFERENCE) && (type != TEXT_is_VALUE) )
type = TEXT_is_DIVERS;
m_Type = type;
// Due to the Pcbnew history, .m_Orient is saved in screen value
// but it is handled as relative to its parent footprint
m_Orient -= ( (MODULE*) m_Parent )->m_Orient;
if( BufCar1[0] == 'M' )
m_Mirror = true;
else
m_Mirror = false;
if( BufCar2[0] == 'I' )
m_NoShow = true;
else
m_NoShow = false;
if( BufCar3[0] == 'I' )
m_Italic = true;
else
m_Italic = false;
// Test for a reasonable layer:
if( layer < 0 )
layer = 0;
if( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
if( layer == LAYER_N_BACK )
layer = SILKSCREEN_N_BACK;
else if( layer == LAYER_N_FRONT )
layer = SILKSCREEN_N_FRONT;
SetLayer( layer );
// Calculate the actual position.
SetDrawCoord();
// Search and read the "text" string (a quoted text).
ReadDelimitedText( &m_Text, line );
// Test for a reasonable size:
if( m_Size.x < TEXTS_MIN_SIZE )
m_Size.x = TEXTS_MIN_SIZE;
if( m_Size.y < TEXTS_MIN_SIZE )
m_Size.y = TEXTS_MIN_SIZE;
// Set a reasonable width:
if( m_Thickness < 1 )
m_Thickness = 1;
m_Thickness = Clamp_Text_PenSize( m_Thickness, m_Size );
return success;
}
#endif // USE_NEW_PCBNEW_LOAD
...@@ -199,7 +199,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() ...@@ -199,7 +199,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
return NULL; return NULL;
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return NULL; return NULL;
...@@ -222,7 +222,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() ...@@ -222,7 +222,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
return NULL; return NULL;
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return NULL; return NULL;
...@@ -259,7 +259,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module() ...@@ -259,7 +259,7 @@ MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
return NULL; return NULL;
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return NULL; return NULL;
...@@ -334,7 +334,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule ) ...@@ -334,7 +334,7 @@ void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() ); fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
fclose( fp ); fclose( fp );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return; return;
...@@ -357,7 +357,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath ) ...@@ -357,7 +357,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
pi->FootprintSave( libPath, GetBoard()->m_Modules ); pi->FootprintSave( libPath, GetBoard()->m_Modules );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return false; return false;
...@@ -429,7 +429,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() ...@@ -429,7 +429,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
writable = pi->IsFootprintLibWritable( libPath ); writable = pi->IsFootprintLibWritable( libPath );
exists = true; // no exception was thrown, lib must exist. exists = true; // no exception was thrown, lib must exist.
} }
catch( IO_ERROR ) catch( const IO_ERROR& )
{ {
// ignore, original values of 'writable' and 'exists' are accurate. // ignore, original values of 'writable' and 'exists' are accurate.
} }
...@@ -455,7 +455,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() ...@@ -455,7 +455,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
pi->FootprintLibCreate( libPath ); pi->FootprintLibCreate( libPath );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return wxEmptyString; return wxEmptyString;
...@@ -499,7 +499,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary() ...@@ -499,7 +499,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
{ {
FootprintLibs()->FootprintDelete( nickname, fpname ); FootprintLibs()->FootprintDelete( nickname, fpname );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return false; return false;
...@@ -568,7 +568,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly ) ...@@ -568,7 +568,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
} }
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
} }
...@@ -655,7 +655,7 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary, ...@@ -655,7 +655,7 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary,
// own if the library or footprint is not writable. // own if the library or footprint is not writable.
FootprintLibs()->FootprintSave( aLibrary, aModule ); FootprintLibs()->FootprintSave( aLibrary, aModule );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return false; return false;
......
...@@ -220,7 +220,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, ...@@ -220,7 +220,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
{ {
module = loadFootprint( fpid ); module = loadFootprint( fpid );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
fpid.Format().c_str(), GetChars( ioe.errorText ) ); fpid.Format().c_str(), GetChars( ioe.errorText ) );
...@@ -252,7 +252,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary, ...@@ -252,7 +252,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
{ {
module = loadFootprint( fpid ); module = loadFootprint( fpid );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
fpid.Format().c_str(), GetChars( ioe.errorText ) ); fpid.Format().c_str(), GetChars( ioe.errorText ) );
...@@ -304,7 +304,7 @@ MODULE* PCB_BASE_FRAME::LoadFootprint( const FPID& aFootprintId ) ...@@ -304,7 +304,7 @@ MODULE* PCB_BASE_FRAME::LoadFootprint( const FPID& aFootprintId )
{ {
module = loadFootprint( aFootprintId ); module = loadFootprint( aFootprintId );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ), wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
aFootprintId.Format().c_str(), GetChars( ioe.errorText ) ); aFootprintId.Format().c_str(), GetChars( ioe.errorText ) );
...@@ -321,31 +321,7 @@ MODULE* PCB_BASE_FRAME::loadFootprint( const FPID& aFootprintId ) ...@@ -321,31 +321,7 @@ MODULE* PCB_BASE_FRAME::loadFootprint( const FPID& aFootprintId )
wxCHECK_MSG( fptbl, NULL, wxT( "Cannot look up FPID in NULL FP_LIB_TABLE." ) ); wxCHECK_MSG( fptbl, NULL, wxT( "Cannot look up FPID in NULL FP_LIB_TABLE." ) );
wxString nickname = aFootprintId.GetLibNickname(); return fptbl->FootprintLoadWithOptionalNickname( aFootprintId );
wxString fpname = aFootprintId.GetFootprintName();
if( nickname.size() )
{
return fptbl->FootprintLoad( nickname, fpname );
}
// user did not enter a nickname, just a footprint name, help him out a little:
else
{
std::vector<wxString> nicks = fptbl->GetLogicalLibs();
// Search each library going through libraries alphabetically.
for( unsigned i = 0; i<nicks.size(); ++i )
{
// FootprintLoad() returns NULL on not found, does not throw exception
// unless there's an IO_ERROR.
MODULE* ret = fptbl->FootprintLoad( nicks[i], fpname );
if( ret )
return ret;
}
return NULL;
}
} }
...@@ -557,7 +533,7 @@ void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent ) ...@@ -557,7 +533,7 @@ void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent )
// m is deleted here by auto_ptr. // m is deleted here by auto_ptr.
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( this, ioe.errorText ); DisplayError( this, ioe.errorText );
return; return;
......
...@@ -279,7 +279,7 @@ wxString FOOTPRINT_EDIT_FRAME::getLibPath() ...@@ -279,7 +279,7 @@ wxString FOOTPRINT_EDIT_FRAME::getLibPath()
return row->GetFullURI( true ); return row->GetFullURI( true );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
return wxEmptyString; return wxEmptyString;
} }
...@@ -639,7 +639,7 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() ...@@ -639,7 +639,7 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
if( !writable ) if( !writable )
title += _( " [Read Only]" ); title += _( " [Read Only]" );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
// user may be bewildered as to why after selecting a library it is not showing up // user may be bewildered as to why after selecting a library it is not showing up
// in the title, we could show an error message, but that should have been done at time // in the title, we could show an error message, but that should have been done at time
......
...@@ -82,7 +82,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName, ...@@ -82,7 +82,7 @@ void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
netlistReader->LoadNetlist(); netlistReader->LoadNetlist();
loadFootprints( netlist, aReporter ); loadFootprints( netlist, aReporter );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
msg.Printf( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() ); msg.Printf( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR ); wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
......
...@@ -162,7 +162,7 @@ bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename ) ...@@ -162,7 +162,7 @@ bool PCB_EDIT_FRAME::ExportSpecctraFile( const wxString& aFullFilename )
// if an exception is thrown by FromBOARD or ExportPCB(), then // if an exception is thrown by FromBOARD or ExportPCB(), then
// ~SPECCTRA_DB() will close the file. // ~SPECCTRA_DB() will close the file.
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
ok = false; ok = false;
...@@ -1322,7 +1322,7 @@ bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard, ...@@ -1322,7 +1322,7 @@ bool SPECCTRA_DB::GetBoardPolygonOutlines( BOARD* aBoard,
aHoles.CloseLastContour(); aHoles.CloseLastContour();
} }
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
// Creates a valid polygon outline is not possible. // Creates a valid polygon outline is not possible.
// So uses the board edge cuts bounding box to create a // So uses the board edge cuts bounding box to create a
......
...@@ -102,14 +102,15 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) ...@@ -102,14 +102,15 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event )
db.LoadSESSION( fullFileName ); db.LoadSESSION( fullFileName );
db.FromSESSION( GetBoard() ); db.FromSESSION( GetBoard() );
} }
catch( IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
ioe.errorText += '\n'; wxString msg = ioe.errorText;
ioe.errorText += _("BOARD may be corrupted, do not save it."); msg += '\n';
ioe.errorText += '\n'; msg += _("BOARD may be corrupted, do not save it.");
ioe.errorText += _("Fix problem and try again."); msg += '\n';
msg += _("Fix problem and try again.");
DisplayError( this, ioe.errorText ); DisplayError( this, msg );
return; return;
} }
......
...@@ -63,7 +63,7 @@ int main( int argc, char** argv ) ...@@ -63,7 +63,7 @@ int main( int argc, char** argv )
// db.LoadPCB( filename ); // db.LoadPCB( filename );
db.LoadSESSION( filename ); db.LoadSESSION( filename );
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
fprintf( stderr, "%s\n", TO_UTF8(ioe.errorText) ); fprintf( stderr, "%s\n", TO_UTF8(ioe.errorText) );
failed = true; failed = true;
......
...@@ -83,7 +83,7 @@ int main( int argc, char** argv ) ...@@ -83,7 +83,7 @@ int main( int argc, char** argv )
#endif #endif
} }
catch( IO_ERROR ioe ) catch( const IO_ERROR& ioe )
{ {
fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) ); fprintf( stderr, "%s\n", TO_UTF8( ioe.errorText ) );
} }
......
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