Commit 3802629a authored by unknown's avatar unknown Committed by jean-pierre charras

Fix kicad_plugin.cpp coding style fully broken by commit 4887 (patch from...

Fix kicad_plugin.cpp coding style fully broken by commit 4887 (patch from Orson, AKA maciej suminski).
parent 0d5c7f44
......@@ -91,28 +91,17 @@ class FP_CACHE_ITEM
public:
FP_CACHE_ITEM( MODULE* aModule, const wxFileName& aFileName );
wxString GetName() const
{
return m_file_name.GetDirs().Last();
}
wxFileName GetFileName() const
{
return m_file_name;
}
wxString GetName() const { return m_file_name.GetDirs().Last(); }
wxFileName GetFileName() const { return m_file_name; }
/// Tell if the disk content or the lib_path has changed.
bool IsModified() const;
MODULE* GetModule() const
{
return m_module.get();
}
void UpdateModificationTime()
{
m_mod_time = m_file_name.GetModificationTime();
}
MODULE* GetModule() const { return m_module.get(); }
void UpdateModificationTime() { m_mod_time = m_file_name.GetModificationTime(); }
};
FP_CACHE_ITEM::FP_CACHE_ITEM( MODULE* aModule, const wxFileName& aFileName ) :
m_module( aModule )
{
......@@ -124,24 +113,27 @@ FP_CACHE_ITEM::FP_CACHE_ITEM( MODULE* aModule, const wxFileName& aFileName ) :
m_mod_time.Now();
}
bool FP_CACHE_ITEM::IsModified() const
{
if( !m_file_name.FileExists() )
return false;
wxLogTrace( traceFootprintLibrary, wxT( "File '%s', m_mod_time %s-%s, file mod time: %s-%s." ),
GetChars( m_file_name.GetFullPath() ), GetChars( m_mod_time.FormatDate() ),
GetChars( m_mod_time.FormatTime() ),
GetChars( m_file_name.GetFullPath() ),
GetChars( m_mod_time.FormatDate() ), GetChars( m_mod_time.FormatTime() ),
GetChars( m_file_name.GetModificationTime().FormatDate() ),
GetChars( m_file_name.GetModificationTime().FormatTime() ) );
return m_file_name.GetModificationTime() != m_mod_time;
}
typedef boost::ptr_map<std::string, FP_CACHE_ITEM> MODULE_MAP;
typedef boost::ptr_map< std::string, FP_CACHE_ITEM > MODULE_MAP;
typedef MODULE_MAP::iterator MODULE_ITER;
typedef MODULE_MAP::const_iterator MODULE_CITER;
class FP_CACHE
{
PCB_IO* m_owner; /// Plugin object that owns the cache.
......@@ -152,22 +144,10 @@ class FP_CACHE
public:
FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath );
wxString GetPath() const
{
return m_lib_path.GetPath();
}
wxDateTime GetLastModificationTime() const
{
return m_mod_time;
}
bool IsWritable() const
{
return m_lib_path.IsOk() && m_lib_path.IsDirWritable();
}
MODULE_MAP& GetModules()
{
return m_modules;
}
wxString GetPath() const { return m_lib_path.GetPath(); }
wxDateTime GetLastModificationTime() const { return m_mod_time; }
bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
MODULE_MAP& GetModules() { return m_modules; }
// Most all functions in this class throw IO_ERROR exceptions. There are no
// error codes nor user interface calls from here, nor in any PLUGIN.
......@@ -211,30 +191,31 @@ public:
bool IsPath( const wxString& aPath ) const;
};
FP_CACHE::FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath )
{
m_owner = aOwner;
m_lib_path.SetPath( aLibraryPath );
}
wxDateTime FP_CACHE::GetLibModificationTime() const
{
return m_lib_path.GetModificationTime();
}
void FP_CACHE::Save()
{
if( !m_lib_path.DirExists() && !m_lib_path.Mkdir() )
{
THROW_IO_ERROR(
wxString::Format( _( "Cannot create footprint library path '%s'" ),
THROW_IO_ERROR( wxString::Format( _( "Cannot create footprint library path '%s'" ),
m_lib_path.GetPath().GetData() ) );
}
if( !m_lib_path.IsDirWritable() )
{
THROW_IO_ERROR(
wxString::Format( _( "Footprint library path '%s' is read only" ),
THROW_IO_ERROR( wxString::Format( _( "Footprint library path '%s' is read only" ),
GetChars( m_lib_path.GetPath() ) ) );
}
......@@ -265,7 +246,9 @@ void FP_CACHE::Save()
{
wxString msg = wxString::Format(
_( "Cannot rename temporary file '%s' to footprint library file '%s'" ),
GetChars( tempFileName ), GetChars( fn.GetFullPath() ) );
GetChars( tempFileName ),
GetChars( fn.GetFullPath() )
);
THROW_IO_ERROR( msg );
}
......@@ -274,14 +257,17 @@ void FP_CACHE::Save()
}
}
void FP_CACHE::Load()
{
wxDir dir( m_lib_path.GetPath() );
if( !dir.IsOpened() )
{
wxString msg = wxString::Format( _( "Footprint library path '%s' does not exist" ),
GetChars( m_lib_path.GetPath() ) );
wxString msg = wxString::Format(
_( "Footprint library path '%s' does not exist" ),
GetChars( m_lib_path.GetPath() )
);
THROW_IO_ERROR( msg );
}
......@@ -316,6 +302,7 @@ void FP_CACHE::Load()
}
}
void FP_CACHE::Remove( const wxString& aFootprintName )
{
......@@ -325,8 +312,11 @@ void FP_CACHE::Remove( const wxString& aFootprintName )
if( it == m_modules.end() )
{
wxString msg = wxString::Format( _( "library '%s' has no footprint '%s' to delete" ),
GetChars( m_lib_path.GetPath() ), GetChars( aFootprintName ) );
wxString msg = wxString::Format(
_( "library '%s' has no footprint '%s' to delete" ),
GetChars( m_lib_path.GetPath() ),
GetChars( aFootprintName )
);
THROW_IO_ERROR( msg );
}
......@@ -336,6 +326,7 @@ void FP_CACHE::Remove( const wxString& aFootprintName )
wxRemoveFile( fullPath );
}
bool FP_CACHE::IsPath( const wxString& aPath ) const
{
// Converts path separators to native path separators
......@@ -345,6 +336,7 @@ bool FP_CACHE::IsPath( const wxString& aPath ) const
return m_lib_path == newPath;
}
bool FP_CACHE::IsModified( const wxString& aLibPath, const wxString& aFootprintName ) const
{
// The library is modified if the library path got deleted or changed.
......@@ -378,7 +370,8 @@ bool FP_CACHE::IsModified( const wxString& aLibPath, const wxString& aFootprintN
return true;
}
}
} else
}
else
{
MODULE_CITER it = m_modules.find( TO_UTF8( aFootprintName ) );
......@@ -389,6 +382,7 @@ bool FP_CACHE::IsModified( const wxString& aLibPath, const wxString& aFootprintN
return false;
}
void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
......@@ -412,6 +406,7 @@ void PCB_IO::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* a
m_out->Print( 0, ")\n" );
}
BOARD_ITEM* PCB_IO::Parse( const wxString& aClipboardSourceInput ) throw( PARSE_ERROR, IO_ERROR )
{
std::string input = TO_UTF8( aClipboardSourceInput );
......@@ -423,18 +418,20 @@ BOARD_ITEM* PCB_IO::Parse( const wxString& aClipboardSourceInput ) throw( PARSE_
return m_parser->Parse();
}
void PCB_IO::Format( BOARD_ITEM* aItem, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::Format( BOARD_ITEM* aItem, int aNestLevel ) const
throw( IO_ERROR )
{
LOCALE_IO toggle; // public API function, perform anything convenient for caller
switch (aItem->Type())
switch( aItem->Type() )
{
case PCB_T:
format( (BOARD*) aItem, aNestLevel );
break;
case PCB_DIMENSION_T:
format( (DIMENSION*) aItem, aNestLevel );
format( ( DIMENSION*) aItem, aNestLevel );
break;
case PCB_LINE_T:
......@@ -479,6 +476,7 @@ void PCB_IO::Format( BOARD_ITEM* aItem, int aNestLevel ) const throw( IO_ERROR )
}
}
void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
{
if( m_ctl & CTL_STD_LAYER_NAMES )
......@@ -487,34 +485,37 @@ void PCB_IO::formatLayer( const BOARD_ITEM* aItem ) const
// English layer names should never need quoting.
m_out->Print( 0, " (layer %s)", TO_UTF8( BOARD::GetStandardLayerName( layer ) ) );
} else
}
else
m_out->Print( 0, " (layer %s)", m_out->Quotew( aItem->GetLayerName() ).c_str() );
}
void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const
throw( IO_ERROR )
{
const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel, "(general\n" );
m_out->Print( aNestLevel + 1, "(links %d)\n", aBoard->GetRatsnestsCount() );
m_out->Print( aNestLevel + 1, "(no_connects %d)\n", aBoard->GetUnconnectedNetCount() );
m_out->Print( aNestLevel+1, "(links %d)\n", aBoard->GetRatsnestsCount() );
m_out->Print( aNestLevel+1, "(no_connects %d)\n", aBoard->GetUnconnectedNetCount() );
// Write Bounding box info
m_out->Print( aNestLevel + 1, "(area %s %s %s %s)\n",
m_out->Print( aNestLevel+1, "(area %s %s %s %s)\n",
FMTIU( aBoard->GetBoundingBox().GetX() ).c_str(),
FMTIU( aBoard->GetBoundingBox().GetY() ).c_str(),
FMTIU( aBoard->GetBoundingBox().GetRight() ).c_str(),
FMTIU( aBoard->GetBoundingBox().GetBottom() ).c_str() );
m_out->Print( aNestLevel + 1, "(thickness %s)\n",
m_out->Print( aNestLevel+1, "(thickness %s)\n",
FMTIU( dsnSettings.GetBoardThickness() ).c_str() );
m_out->Print( aNestLevel + 1, "(drawings %d)\n", aBoard->m_Drawings.GetCount() );
m_out->Print( aNestLevel + 1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
m_out->Print( aNestLevel + 1, "(zones %d)\n", aBoard->GetNumSegmZone() );
m_out->Print( aNestLevel + 1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
m_out->Print( aNestLevel + 1, "(nets %d)\n", (int) m_mapping->GetSize() );
m_out->Print( aNestLevel+1, "(drawings %d)\n", aBoard->m_Drawings.GetCount() );
m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() );
m_out->Print( aNestLevel+1, "(zones %d)\n", aBoard->GetNumSegmZone() );
m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() );
m_out->Print( aNestLevel+1, "(nets %d)\n", (int) m_mapping->GetSize() );
m_out->Print( aNestLevel, ")\n\n" );
aBoard->GetPageSettings().Format( m_out, aNestLevel, m_ctl );
......@@ -524,16 +525,16 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( aNestLevel, "(layers\n" );
// Save only the used copper layers from front to back.
for( LAYER_NUM layer = LAST_COPPER_LAYER; layer >= FIRST_COPPER_LAYER; --layer )
for( LAYER_NUM layer = LAST_COPPER_LAYER; layer >= FIRST_COPPER_LAYER; --layer)
{
LAYER_MSK mask = GetLayerMask( layer );
if( mask & aBoard->GetEnabledLayers() )
{
m_out->Print( aNestLevel + 1, "(%d %s %s", layer,
m_out->Print( aNestLevel+1, "(%d %s %s", layer,
m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str(),
LAYER::ShowType( aBoard->GetLayerType( layer ) ) );
if( ! ( aBoard->GetVisibleLayers() & mask ) )
if( !( aBoard->GetVisibleLayers() & mask ) )
m_out->Print( 0, " hide" );
m_out->Print( 0, ")\n" );
......@@ -541,15 +542,15 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
}
// Save used non-copper layers in the order they are defined.
for( LAYER_NUM layer = FIRST_NON_COPPER_LAYER; layer <= LAST_NON_COPPER_LAYER; ++layer )
for( LAYER_NUM layer = FIRST_NON_COPPER_LAYER; layer <= LAST_NON_COPPER_LAYER; ++layer)
{
LAYER_MSK mask = GetLayerMask( layer );
if( mask & aBoard->GetEnabledLayers() )
{
m_out->Print( aNestLevel + 1, "(%d %s user", layer,
m_out->Print( aNestLevel+1, "(%d %s user", layer,
m_out->Quotew( aBoard->GetLayerName( layer ) ).c_str() );
if( ! ( aBoard->GetVisibleLayers() & mask ) )
if( !( aBoard->GetVisibleLayers() & mask ) )
m_out->Print( 0, " hide" );
m_out->Print( 0, ")\n" );
......@@ -562,110 +563,111 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( aNestLevel, "(setup\n" );
// Save current default track width, for compatibility with older Pcbnew version;
m_out->Print( aNestLevel + 1, "(last_trace_width %s)\n",
m_out->Print( aNestLevel+1, "(last_trace_width %s)\n",
FMTIU( dsnSettings.GetCurrentTrackWidth() ).c_str() );
// Save custom tracks width list (the first is not saved here: this is the netclass value
for( unsigned ii = 1; ii < dsnSettings.m_TrackWidthList.size(); ii++ )
m_out->Print( aNestLevel + 1, "(user_trace_width %s)\n",
m_out->Print( aNestLevel+1, "(user_trace_width %s)\n",
FMTIU( dsnSettings.m_TrackWidthList[ii] ).c_str() );
m_out->Print( aNestLevel + 1, "(trace_clearance %s)\n",
m_out->Print( aNestLevel+1, "(trace_clearance %s)\n",
FMTIU( dsnSettings.GetDefault()->GetClearance() ).c_str() );
// ZONE_SETTINGS
m_out->Print( aNestLevel + 1, "(zone_clearance %s)\n",
m_out->Print( aNestLevel+1, "(zone_clearance %s)\n",
FMTIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() );
m_out->Print( aNestLevel + 1, "(zone_45_only %s)\n",
m_out->Print( aNestLevel+1, "(zone_45_only %s)\n",
aBoard->GetZoneSettings().m_Zone_45_Only ? "yes" : "no" );
m_out->Print( aNestLevel + 1, "(trace_min %s)\n",
m_out->Print( aNestLevel+1, "(trace_min %s)\n",
FMTIU( dsnSettings.m_TrackMinWidth ).c_str() );
m_out->Print( aNestLevel + 1, "(segment_width %s)\n",
m_out->Print( aNestLevel+1, "(segment_width %s)\n",
FMTIU( dsnSettings.m_DrawSegmentWidth ).c_str() );
m_out->Print( aNestLevel + 1, "(edge_width %s)\n",
m_out->Print( aNestLevel+1, "(edge_width %s)\n",
FMTIU( dsnSettings.m_EdgeSegmentWidth ).c_str() );
// Save current default via size, for compatibility with older Pcbnew version;
m_out->Print( aNestLevel + 1, "(via_size %s)\n",
m_out->Print( aNestLevel+1, "(via_size %s)\n",
FMTIU( dsnSettings.GetDefault()->GetViaDiameter() ).c_str() );
m_out->Print( aNestLevel + 1, "(via_drill %s)\n",
m_out->Print( aNestLevel+1, "(via_drill %s)\n",
FMTIU( dsnSettings.GetDefault()->GetViaDrill() ).c_str() );
m_out->Print( aNestLevel + 1, "(via_min_size %s)\n",
m_out->Print( aNestLevel+1, "(via_min_size %s)\n",
FMTIU( dsnSettings.m_ViasMinSize ).c_str() );
m_out->Print( aNestLevel + 1, "(via_min_drill %s)\n",
m_out->Print( aNestLevel+1, "(via_min_drill %s)\n",
FMTIU( dsnSettings.m_ViasMinDrill ).c_str() );
// Save custom vias diameters list (the first is not saved here: this is
// the netclass value
for( unsigned ii = 1; ii < dsnSettings.m_ViasDimensionsList.size(); ii++ )
m_out->Print( aNestLevel + 1, "(user_via %s %s)\n",
m_out->Print( aNestLevel+1, "(user_via %s %s)\n",
FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Diameter ).c_str(),
FMTIU( dsnSettings.m_ViasDimensionsList[ii].m_Drill ).c_str() );
// for old versions compatibility:
if( dsnSettings.m_BlindBuriedViaAllowed )
m_out->Print( aNestLevel + 1, "(blind_buried_vias_allowed yes)\n" );
m_out->Print( aNestLevel+1, "(blind_buried_vias_allowed yes)\n" );
m_out->Print( aNestLevel + 1, "(uvia_size %s)\n",
m_out->Print( aNestLevel+1, "(uvia_size %s)\n",
FMTIU( dsnSettings.GetDefault()->GetuViaDiameter() ).c_str() );
m_out->Print( aNestLevel + 1, "(uvia_drill %s)\n",
m_out->Print( aNestLevel+1, "(uvia_drill %s)\n",
FMTIU( dsnSettings.GetDefault()->GetuViaDrill() ).c_str() );
m_out->Print( aNestLevel + 1, "(uvias_allowed %s)\n",
m_out->Print( aNestLevel+1, "(uvias_allowed %s)\n",
( dsnSettings.m_MicroViasAllowed ) ? "yes" : "no" );
m_out->Print( aNestLevel + 1, "(uvia_min_size %s)\n",
m_out->Print( aNestLevel+1, "(uvia_min_size %s)\n",
FMTIU( dsnSettings.m_MicroViasMinSize ).c_str() );
m_out->Print( aNestLevel + 1, "(uvia_min_drill %s)\n",
m_out->Print( aNestLevel+1, "(uvia_min_drill %s)\n",
FMTIU( dsnSettings.m_MicroViasMinDrill ).c_str() );
m_out->Print( aNestLevel + 1, "(pcb_text_width %s)\n",
m_out->Print( aNestLevel+1, "(pcb_text_width %s)\n",
FMTIU( dsnSettings.m_PcbTextWidth ).c_str() );
m_out->Print( aNestLevel + 1, "(pcb_text_size %s %s)\n",
m_out->Print( aNestLevel+1, "(pcb_text_size %s %s)\n",
FMTIU( dsnSettings.m_PcbTextSize.x ).c_str(),
FMTIU( dsnSettings.m_PcbTextSize.y ).c_str() );
m_out->Print( aNestLevel + 1, "(mod_edge_width %s)\n",
m_out->Print( aNestLevel+1, "(mod_edge_width %s)\n",
FMTIU( dsnSettings.m_ModuleSegmentWidth ).c_str() );
m_out->Print( aNestLevel + 1, "(mod_text_size %s %s)\n",
m_out->Print( aNestLevel+1, "(mod_text_size %s %s)\n",
FMTIU( dsnSettings.m_ModuleTextSize.x ).c_str(),
FMTIU( dsnSettings.m_ModuleTextSize.y ).c_str() );
m_out->Print( aNestLevel + 1, "(mod_text_width %s)\n",
m_out->Print( aNestLevel+1, "(mod_text_width %s)\n",
FMTIU( dsnSettings.m_ModuleTextWidth ).c_str() );
m_out->Print( aNestLevel + 1, "(pad_size %s %s)\n",
m_out->Print( aNestLevel+1, "(pad_size %s %s)\n",
FMTIU( dsnSettings.m_Pad_Master.GetSize().x ).c_str(),
FMTIU( dsnSettings.m_Pad_Master.GetSize().y ).c_str() );
m_out->Print( aNestLevel + 1, "(pad_drill %s)\n",
m_out->Print( aNestLevel+1, "(pad_drill %s)\n",
FMTIU( dsnSettings.m_Pad_Master.GetDrillSize().x ).c_str() );
m_out->Print( aNestLevel + 1, "(pad_to_mask_clearance %s)\n",
m_out->Print( aNestLevel+1, "(pad_to_mask_clearance %s)\n",
FMTIU( dsnSettings.m_SolderMaskMargin ).c_str() );
if( dsnSettings.m_SolderMaskMinWidth )
m_out->Print( aNestLevel + 1, "(solder_mask_min_width %s)\n",
m_out->Print( aNestLevel+1, "(solder_mask_min_width %s)\n",
FMTIU( dsnSettings.m_SolderMaskMinWidth ).c_str() );
if( dsnSettings.m_SolderPasteMargin != 0 )
m_out->Print( aNestLevel + 1, "(pad_to_paste_clearance %s)\n",
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance %s)\n",
FMTIU( dsnSettings.m_SolderPasteMargin ).c_str() );
if( dsnSettings.m_SolderPasteMarginRatio != 0 )
m_out->Print( aNestLevel + 1, "(pad_to_paste_clearance_ratio %s)\n",
m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
Double2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
m_out->Print( aNestLevel + 1, "(aux_axis_origin %s %s)\n",
m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
FMTIU( aBoard->GetAuxOrigin().x ).c_str(),
FMTIU( aBoard->GetAuxOrigin().y ).c_str() );
if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
m_out->Print( aNestLevel + 1, "(grid_origin %s %s)\n",
m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
FMTIU( aBoard->GetGridOrigin().x ).c_str(),
FMTIU( aBoard->GetGridOrigin().y ).c_str() );
m_out->Print( aNestLevel + 1, "(visible_elements %X)\n", dsnSettings.GetVisibleElements() );
m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
dsnSettings.GetVisibleElements() );
aBoard->GetPlotOptions().Format( m_out, aNestLevel + 1 );
aBoard->GetPlotOptions().Format( m_out, aNestLevel+1 );
m_out->Print( aNestLevel, ")\n\n" );
......@@ -673,7 +675,8 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end();
net != netEnd; ++net )
{
m_out->Print( aNestLevel, "(net %d %s)\n", m_mapping->Translate( net->GetNet() ),
m_out->Print( aNestLevel, "(net %d %s)\n",
m_mapping->Translate( net->GetNet() ),
m_out->Quotew( net->GetNetname() ).c_str() );
}
......@@ -686,7 +689,8 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
// Save the rest of the net classes alphabetically.
for( NETCLASSES::const_iterator it = dsnSettings.m_NetClasses.begin();
it != dsnSettings.m_NetClasses.end(); ++it )
it != dsnSettings.m_NetClasses.end();
++it )
{
NETCLASS netclass = *it->second;
filterNetClass( *aBoard, netclass ); // Remove empty nets (from a copy of a netclass)
......@@ -724,7 +728,9 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const throw( IO_ERROR )
Format( aBoard->GetArea( i ), aNestLevel );
}
void PCB_IO::format( DIMENSION* aDimension, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( DIMENSION* aDimension, int aNestLevel ) const
throw( IO_ERROR )
{
m_out->Print( aNestLevel, "(dimension %s (width %s)",
FMT_IU( aDimension->GetValue() ).c_str(),
......@@ -784,11 +790,13 @@ void PCB_IO::format( DIMENSION* aDimension, int aNestLevel ) const throw( IO_ERR
m_out->Print( aNestLevel, ")\n" );
}
void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const
throw( IO_ERROR )
{
unsigned i;
switch (aSegment->GetShape())
switch( aSegment->GetShape() )
{
case S_SEGMENT: // Line
m_out->Print( aNestLevel, "(gr_line (start %s) (end %s)",
......@@ -806,14 +814,14 @@ void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const throw( IO_ERR
FMT_IU( aSegment->GetEnd() ).c_str() );
break;
case S_ARC:// Arc
case S_ARC: // Arc
m_out->Print( aNestLevel, "(gr_arc (start %s) (end %s) (angle %s)",
FMT_IU( aSegment->GetStart() ).c_str(),
FMT_IU( aSegment->GetEnd() ).c_str(),
FMT_ANGLE( aSegment->GetAngle() ).c_str() );
break;
case S_POLYGON:// Polygon
case S_POLYGON: // Polygon
m_out->Print( aNestLevel, "(gr_poly (pts" );
for( i = 0; i < aSegment->GetPolyPoints().size(); ++i )
......@@ -822,7 +830,7 @@ void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const throw( IO_ERR
m_out->Print( 0, ")" );
break;
case S_CURVE:// Bezier curve
case S_CURVE: // Bezier curve
m_out->Print( aNestLevel, "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
FMT_IU( aSegment->GetStart() ).c_str(),
FMT_IU( aSegment->GetBezControl1() ).c_str(),
......@@ -848,9 +856,11 @@ void PCB_IO::format( DRAWSEGMENT* aSegment, int aNestLevel ) const throw( IO_ERR
m_out->Print( 0, ")\n" );
}
void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const
throw( IO_ERROR )
{
switch (aModuleDrawing->GetShape())
switch( aModuleDrawing->GetShape() )
{
case S_SEGMENT: // Line
m_out->Print( aNestLevel, "(fp_line (start %s) (end %s)",
......@@ -864,14 +874,14 @@ void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const throw(
FMT_IU( aModuleDrawing->GetEnd0() ).c_str() );
break;
case S_ARC:// Arc
case S_ARC: // Arc
m_out->Print( aNestLevel, "(fp_arc (start %s) (end %s) (angle %s)",
FMT_IU( aModuleDrawing->GetStart0() ).c_str(),
FMT_IU( aModuleDrawing->GetEnd0() ).c_str(),
FMT_ANGLE( aModuleDrawing->GetAngle() ).c_str() );
break;
case S_POLYGON:// Polygon
case S_POLYGON: // Polygon
m_out->Print( aNestLevel, "(fp_poly (pts" );
for( unsigned i = 0; i < aModuleDrawing->GetPolyPoints().size(); ++i )
......@@ -920,7 +930,9 @@ void PCB_IO::format( EDGE_MODULE* aModuleDrawing, int aNestLevel ) const throw(
m_out->Print( 0, ")\n" );
}
void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const
throw( IO_ERROR )
{
m_out->Print( aNestLevel, "(target %s (at %s) (size %s)",
( aTarget->GetShape() ) ? "x" : "plus",
......@@ -938,22 +950,25 @@ void PCB_IO::format( PCB_TARGET* aTarget, int aNestLevel ) const throw( IO_ERROR
m_out->Print( 0, ")\n" );
}
void PCB_IO::format( MODULE* aModule, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
throw( IO_ERROR )
{
if( ! ( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
{
const wxArrayString* initial_comments = aModule->GetInitialComments();
if( initial_comments )
{
for( unsigned i = 0; i < initial_comments->GetCount(); ++i )
m_out->Print( aNestLevel, "%s\n", TO_UTF8( ( *initial_comments )[i] ) );
for( unsigned i=0; i<initial_comments->GetCount(); ++i )
m_out->Print( aNestLevel, "%s\n", TO_UTF8( (*initial_comments)[i] ) );
m_out->Print( 0, "\n" ); // improve readability?
}
}
m_out->Print( aNestLevel, "(module %s", m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
m_out->Print( aNestLevel, "(module %s",
m_out->Quotes( aModule->GetFPID().Format() ).c_str() );
if( aModule->IsLocked() )
m_out->Print( 0, " locked" );
......@@ -963,16 +978,17 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const throw( IO_ERROR )
formatLayer( aModule );
if( ! ( m_ctl & CTL_OMIT_TSTAMPS ) )
if( !( m_ctl & CTL_OMIT_TSTAMPS ) )
{
m_out->Print( 0, " (tedit %lX) (tstamp %lX)\n", aModule->GetLastEditTime(),
aModule->GetTimeStamp() );
} else
m_out->Print( 0, " (tedit %lX) (tstamp %lX)\n",
aModule->GetLastEditTime(), aModule->GetTimeStamp() );
}
else
m_out->Print( 0, "\n" );
if( ! ( m_ctl & CTL_OMIT_AT ) )
if( !( m_ctl & CTL_OMIT_AT ) )
{
m_out->Print( aNestLevel + 1, "(at %s", FMT_IU( aModule->GetPosition() ).c_str() );
m_out->Print( aNestLevel+1, "(at %s", FMT_IU( aModule->GetPosition() ).c_str() );
if( aModule->GetOrientation() != 0.0 )
m_out->Print( 0, " %s", FMT_ANGLE( aModule->GetOrientation() ).c_str() );
......@@ -981,53 +997,54 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const throw( IO_ERROR )
}
if( !aModule->GetDescription().IsEmpty() )
m_out->Print( aNestLevel + 1, "(descr %s)\n",
m_out->Print( aNestLevel+1, "(descr %s)\n",
m_out->Quotew( aModule->GetDescription() ).c_str() );
if( !aModule->GetKeywords().IsEmpty() )
m_out->Print( aNestLevel + 1, "(tags %s)\n",
m_out->Print( aNestLevel+1, "(tags %s)\n",
m_out->Quotew( aModule->GetKeywords() ).c_str() );
if( ! ( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
m_out->Print( aNestLevel + 1, "(path %s)\n", m_out->Quotew( aModule->GetPath() ).c_str() );
if( !( m_ctl & CTL_OMIT_PATH ) && !!aModule->GetPath() )
m_out->Print( aNestLevel+1, "(path %s)\n",
m_out->Quotew( aModule->GetPath() ).c_str() );
if( aModule->GetPlacementCost90() != 0 )
m_out->Print( aNestLevel + 1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
m_out->Print( aNestLevel+1, "(autoplace_cost90 %d)\n", aModule->GetPlacementCost90() );
if( aModule->GetPlacementCost180() != 0 )
m_out->Print( aNestLevel + 1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
m_out->Print( aNestLevel+1, "(autoplace_cost180 %d)\n", aModule->GetPlacementCost180() );
if( aModule->GetLocalSolderMaskMargin() != 0 )
m_out->Print( aNestLevel + 1, "(solder_mask_margin %s)\n",
m_out->Print( aNestLevel+1, "(solder_mask_margin %s)\n",
FMT_IU( aModule->GetLocalSolderMaskMargin() ).c_str() );
if( aModule->GetLocalSolderPasteMargin() != 0 )
m_out->Print( aNestLevel + 1, "(solder_paste_margin %s)\n",
m_out->Print( aNestLevel+1, "(solder_paste_margin %s)\n",
FMT_IU( aModule->GetLocalSolderPasteMargin() ).c_str() );
if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
m_out->Print( aNestLevel + 1, "(solder_paste_ratio %s)\n",
m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
if( aModule->GetLocalClearance() != 0 )
m_out->Print( aNestLevel + 1, "(clearance %s)\n",
m_out->Print( aNestLevel+1, "(clearance %s)\n",
FMT_IU( aModule->GetLocalClearance() ).c_str() );
if( aModule->GetZoneConnection() != UNDEFINED_CONNECTION )
m_out->Print( aNestLevel + 1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
m_out->Print( aNestLevel+1, "(zone_connect %d)\n", aModule->GetZoneConnection() );
if( aModule->GetThermalWidth() != 0 )
m_out->Print( aNestLevel + 1, "(thermal_width %s)\n",
m_out->Print( aNestLevel+1, "(thermal_width %s)\n",
FMT_IU( aModule->GetThermalWidth() ).c_str() );
if( aModule->GetThermalGap() != 0 )
m_out->Print( aNestLevel + 1, "(thermal_gap %s)\n",
m_out->Print( aNestLevel+1, "(thermal_gap %s)\n",
FMT_IU( aModule->GetThermalGap() ).c_str() );
// Attributes
if( aModule->GetAttributes() != MOD_DEFAULT )
{
m_out->Print( aNestLevel + 1, "(attr" );
m_out->Print( aNestLevel+1, "(attr" );
if( aModule->GetAttributes() & MOD_CMS )
m_out->Print( 0, " smd" );
......@@ -1038,48 +1055,50 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( 0, ")\n" );
}
Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel + 1 );
Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel + 1 );
Format( (BOARD_ITEM*) &aModule->Reference(), aNestLevel+1 );
Format( (BOARD_ITEM*) &aModule->Value(), aNestLevel+1 );
// Save drawing elements.
for( BOARD_ITEM* gr = aModule->GraphicalItems(); gr; gr = gr->Next() )
Format( gr, aNestLevel + 1 );
Format( gr, aNestLevel+1 );
// Save pads.
for( D_PAD* pad = aModule->Pads(); pad; pad = pad->Next() )
format( pad, aNestLevel + 1 );
format( pad, aNestLevel+1 );
// Save 3D info.
for( S3D_MASTER* t3D = aModule->Models(); t3D; t3D = t3D->Next() )
{
if( !t3D->GetShape3DName().IsEmpty() )
{
m_out->Print( aNestLevel + 1, "(model %s\n",
m_out->Print( aNestLevel+1, "(model %s\n",
m_out->Quotew( t3D->GetShape3DName() ).c_str() );
m_out->Print( aNestLevel + 2, "(at (xyz %s %s %s))\n",
m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n",
Double2Str( t3D->m_MatPosition.x ).c_str(),
Double2Str( t3D->m_MatPosition.y ).c_str(),
Double2Str( t3D->m_MatPosition.z ).c_str() );
m_out->Print( aNestLevel + 2, "(scale (xyz %s %s %s))\n",
m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
Double2Str( t3D->m_MatScale.x ).c_str(),
Double2Str( t3D->m_MatScale.y ).c_str(),
Double2Str( t3D->m_MatScale.z ).c_str() );
m_out->Print( aNestLevel + 2, "(rotate (xyz %s %s %s))\n",
m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
Double2Str( t3D->m_MatRotation.x ).c_str(),
Double2Str( t3D->m_MatRotation.y ).c_str(),
Double2Str( t3D->m_MatRotation.z ).c_str() );
m_out->Print( aNestLevel + 1, ")\n" );
m_out->Print( aNestLevel+1, ")\n" );
}
}
m_out->Print( aNestLevel, ")\n" );
}
void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const
throw( IO_ERROR )
{
std::string output;
......@@ -1099,38 +1118,35 @@ void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const throw( I
{
output += " *.Cu";
aLayerMask &= ~ALL_CU_LAYERS; // clear bits, so they are not output again below
} else if( ( aLayerMask & cuMask ) == ( LAYER_BACK | LAYER_FRONT ) )
}
else if( ( aLayerMask & cuMask ) == (LAYER_BACK | LAYER_FRONT) )
{
output += " F&B.Cu";
aLayerMask &= ~ ( LAYER_BACK | LAYER_FRONT );
aLayerMask &= ~(LAYER_BACK | LAYER_FRONT);
}
if( ( aLayerMask & ( ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT ) )
== ( ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT ) )
if( ( aLayerMask & (ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT)) == (ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT) )
{
output += " *.Adhes";
aLayerMask &= ~ ( ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT );
aLayerMask &= ~(ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT);
}
if( ( aLayerMask & ( SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT ) )
== ( SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT ) )
if( ( aLayerMask & (SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT)) == (SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT) )
{
output += " *.Paste";
aLayerMask &= ~ ( SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT );
aLayerMask &= ~(SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT);
}
if( ( aLayerMask & ( SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT ) )
== ( SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT ) )
if( ( aLayerMask & (SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT)) == (SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT) )
{
output += " *.SilkS";
aLayerMask &= ~ ( SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT );
aLayerMask &= ~(SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT);
}
if( ( aLayerMask & ( SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT ) )
== ( SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT ) )
if( ( aLayerMask & (SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT)) == (SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT) )
{
output += " *.Mask";
aLayerMask &= ~ ( SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT );
aLayerMask &= ~(SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT);
}
// output any individual layers not handled in wildcard combos above
......@@ -1144,11 +1160,10 @@ void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const throw( I
{
if( aLayerMask & GetLayerMask( layer ) )
{
if( m_board && ! ( m_ctl & CTL_STD_LAYER_NAMES ) )
if( m_board && !( m_ctl & CTL_STD_LAYER_NAMES ) )
layerName = m_board->GetLayerName( layer );
else
// I am being called from FootprintSave()
else // I am being called from FootprintSave()
layerName = BOARD::GetStandardLayerName( layer );
output += ' ';
......@@ -1159,53 +1174,40 @@ void PCB_IO::formatLayers( LAYER_MSK aLayerMask, int aNestLevel ) const throw( I
m_out->Print( aNestLevel, "%s)", output.c_str() );
}
void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const
throw( IO_ERROR )
{
const char* shape;
switch (aPad->GetShape())
switch( aPad->GetShape() )
{
case PAD_CIRCLE:
shape = "circle";
break;
case PAD_RECT:
shape = "rect";
break;
case PAD_OVAL:
shape = "oval";
break;
case PAD_TRAPEZOID:
shape = "trapezoid";
break;
case PAD_CIRCLE: shape = "circle"; break;
case PAD_RECT: shape = "rect"; break;
case PAD_OVAL: shape = "oval"; break;
case PAD_TRAPEZOID: shape = "trapezoid"; break;
default:
THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d" ), aPad->GetShape() ) );
THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"), aPad->GetShape() ) );
}
const char* type;
switch (aPad->GetAttribute())
switch( aPad->GetAttribute() )
{
case PAD_STANDARD:
type = "thru_hole";
break;
case PAD_SMD:
type = "smd";
break;
case PAD_CONN:
type = "connect";
break;
case PAD_HOLE_NOT_PLATED:
type = "np_thru_hole";
break;
case PAD_STANDARD: type = "thru_hole"; break;
case PAD_SMD: type = "smd"; break;
case PAD_CONN: type = "connect"; break;
case PAD_HOLE_NOT_PLATED: type = "np_thru_hole"; break;
default:
THROW_IO_ERROR(
wxString::Format( _( "unknown pad attribute: %d" ), aPad->GetAttribute() ) );
THROW_IO_ERROR( wxString::Format( _( "unknown pad attribute: %d" ),
aPad->GetAttribute() ) );
}
m_out->Print( aNestLevel, "(pad %s %s %s", m_out->Quotew( aPad->GetPadName() ).c_str(), type,
shape );
m_out->Print( aNestLevel, "(pad %s %s %s",
m_out->Quotew( aPad->GetPadName() ).c_str(),
type, shape );
m_out->Print( 0, " (at %s", FMT_IU( aPad->GetPos0() ).c_str() );
if( aPad->GetOrientation() != 0.0 )
......@@ -1214,14 +1216,14 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( 0, ")" );
m_out->Print( 0, " (size %s)", FMT_IU( aPad->GetSize() ).c_str() );
if( ( aPad->GetDelta().GetWidth() ) != 0 || ( aPad->GetDelta().GetHeight() != 0 ) )
if( (aPad->GetDelta().GetWidth()) != 0 || (aPad->GetDelta().GetHeight() != 0 ) )
m_out->Print( 0, " (rect_delta %s )", FMT_IU( aPad->GetDelta() ).c_str() );
wxSize sz = aPad->GetDrillSize();
wxPoint shapeoffset = aPad->GetOffset();
if( ( sz.GetWidth() > 0 ) || ( sz.GetHeight() > 0 ) || ( shapeoffset.x != 0 )
|| ( shapeoffset.y != 0 ) )
if( (sz.GetWidth() > 0) || (sz.GetHeight() > 0) ||
(shapeoffset.x != 0) || (shapeoffset.y != 0) )
{
m_out->Print( 0, " (drill" );
......@@ -1234,7 +1236,7 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const throw( IO_ERROR )
if( sz.GetHeight() > 0 && sz.GetWidth() != sz.GetHeight() )
m_out->Print( 0, " %s", FMT_IU( sz.GetHeight() ).c_str() );
if( ( shapeoffset.x != 0 ) || ( shapeoffset.y != 0 ) )
if( (shapeoffset.x != 0) || (shapeoffset.y != 0) )
m_out->Print( 0, " (offset %s)", FMT_IU( aPad->GetOffset() ).c_str() );
m_out->Print( 0, ")" );
......@@ -1245,7 +1247,7 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const throw( IO_ERROR )
std::string output;
// Unconnected pad is default net so don't save it.
if( ! ( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
if( !( m_ctl & CTL_OMIT_NETS ) && aPad->GetNetCode() != NETINFO_LIST::UNCONNECTED )
StrPrintf( &output, " (net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
m_out->Quotew( aPad->GetNetname() ).c_str() );
......@@ -1277,15 +1279,18 @@ void PCB_IO::format( D_PAD* aPad, int aNestLevel ) const throw( IO_ERROR )
if( output.size() )
{
m_out->Print( 0, "\n" );
m_out->Print( aNestLevel + 1, "%s", output.c_str() + 1 ); // +1 skips 1st space on 1st element
m_out->Print( aNestLevel+1, "%s", output.c_str()+1 ); // +1 skips 1st space on 1st element
}
m_out->Print( 0, ")\n" );
}
void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const
throw( IO_ERROR )
{
m_out->Print( aNestLevel, "(gr_text %s (at %s", m_out->Quotew( aText->GetText() ).c_str(),
m_out->Print( aNestLevel, "(gr_text %s (at %s",
m_out->Quotew( aText->GetText() ).c_str(),
FMT_IU( aText->GetTextPosition() ).c_str() );
if( aText->GetOrientation() != 0.0 )
......@@ -1305,22 +1310,19 @@ void PCB_IO::format( TEXTE_PCB* aText, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( aNestLevel, ")\n" );
}
void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const
throw( IO_ERROR )
{
MODULE* parent = (MODULE*) aText->GetParent();
double orient = aText->GetOrientation();
wxString type;
switch (aText->GetType())
switch( aText->GetType() )
{
case TEXTE_MODULE::TEXT_is_REFERENCE:
type = wxT( "reference" );
break;
case TEXTE_MODULE::TEXT_is_VALUE:
type = wxT( "value" );
break;
default:
type = wxT( "user" );
case TEXTE_MODULE::TEXT_is_REFERENCE: type = wxT( "reference" ); break;
case TEXTE_MODULE::TEXT_is_VALUE: type = wxT( "value" ); break;
default: type = wxT( "user" );
}
// Due to the Pcbnew history, m_Orient is saved in screen value
......@@ -1328,7 +1330,8 @@ void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const throw( IO_ERROR
if( parent )
orient += parent->GetOrientation();
m_out->Print( aNestLevel, "(fp_text %s %s (at %s", m_out->Quotew( type ).c_str(),
m_out->Print( aNestLevel, "(fp_text %s %s (at %s",
m_out->Quotew( type ).c_str(),
m_out->Quotew( aText->GetText() ).c_str(),
FMT_IU( aText->GetPos0() ).c_str() );
......@@ -1348,23 +1351,25 @@ void PCB_IO::format( TEXTE_MODULE* aText, int aNestLevel ) const throw( IO_ERROR
m_out->Print( aNestLevel, ")\n" );
}
void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const
throw( IO_ERROR )
{
if( aTrack->Type() == PCB_VIA_T )
{
LAYER_NUM layer1, layer2;
const VIA* via = static_cast<const VIA*>( aTrack );
const VIA* via = static_cast<const VIA*>(aTrack);
BOARD* board = (BOARD*) via->GetParent();
wxCHECK_RET( board != 0,
wxT( "Via " ) + via->GetSelectMenuText() + wxT( " has no parent." ) );
wxCHECK_RET( board != 0, wxT( "Via " ) + via->GetSelectMenuText() +
wxT( " has no parent." ) );
m_out->Print( aNestLevel, "(via" );
via->LayerPair( &layer1, &layer2 );
switch (via->GetViaType())
switch( via->GetViaType() )
{
case VIA_THROUGH: // Default shape not saved.
break;
......@@ -1391,7 +1396,8 @@ void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( 0, " (layers %s %s)",
m_out->Quotew( m_board->GetLayerName( layer1 ) ).c_str(),
m_out->Quotew( m_board->GetLayerName( layer2 ) ).c_str() );
} else
}
else
{
m_out->Print( aNestLevel, "(segment (start %s) (end %s) (width %s)",
FMT_IU( aTrack->GetStart() ).c_str(), FMT_IU( aTrack->GetEnd() ).c_str(),
......@@ -1411,14 +1417,16 @@ void PCB_IO::format( TRACK* aTrack, int aNestLevel ) const throw( IO_ERROR )
m_out->Print( 0, ")\n" );
}
void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERROR )
void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const
throw( IO_ERROR )
{
// Save the NET info; For keepout zones, net code and net name are irrelevant
// so be sure a dummy value is stored, just for ZONE_CONTAINER compatibility
// (perhaps netcode and netname should be not stored)
m_out->Print( aNestLevel, "(zone (net %d) (net_name %s)",
aZone->GetIsKeepout() ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
m_out->Quotew( aZone->GetIsKeepout() ? wxT( "" ) : aZone->GetNetname() ).c_str() );
m_out->Quotew( aZone->GetIsKeepout() ? wxT("") : aZone->GetNetname() ).c_str() );
formatLayer( aZone );
......@@ -1427,29 +1435,23 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
// Save the outline aux info
std::string hatch;
switch (aZone->GetHatchStyle())
switch( aZone->GetHatchStyle() )
{
default:
case CPolyLine::NO_HATCH:
hatch = "none";
break;
case CPolyLine::DIAGONAL_EDGE:
hatch = "edge";
break;
case CPolyLine::DIAGONAL_FULL:
hatch = "full";
break;
case CPolyLine::NO_HATCH: hatch = "none"; break;
case CPolyLine::DIAGONAL_EDGE: hatch = "edge"; break;
case CPolyLine::DIAGONAL_FULL: hatch = "full"; break;
}
m_out->Print( 0, " (hatch %s %s)\n", hatch.c_str(),
FMT_IU( aZone->Outline()->GetHatchPitch() ).c_str() );
if( aZone->GetPriority() > 0 )
m_out->Print( aNestLevel + 1, "(priority %d)\n", aZone->GetPriority() );
m_out->Print( aNestLevel+1, "(priority %d)\n", aZone->GetPriority() );
m_out->Print( aNestLevel + 1, "(connect_pads" );
m_out->Print( aNestLevel+1, "(connect_pads" );
switch (aZone->GetPadConnection())
switch( aZone->GetPadConnection() )
{
default:
case THERMAL_PAD: // Default option not saved or loaded.
......@@ -1471,18 +1473,18 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
m_out->Print( 0, " (clearance %s))\n",
FMT_IU( aZone->GetZoneClearance() ).c_str() );
m_out->Print( aNestLevel + 1, "(min_thickness %s)\n",
m_out->Print( aNestLevel+1, "(min_thickness %s)\n",
FMT_IU( aZone->GetMinThickness() ).c_str() );
if( aZone->GetIsKeepout() )
{
m_out->Print( aNestLevel + 1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
m_out->Print( aNestLevel+1, "(keepout (tracks %s) (vias %s) (copperpour %s))\n",
aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed" );
}
m_out->Print( aNestLevel + 1, "(fill" );
m_out->Print( aNestLevel+1, "(fill" );
// Default is not filled.
if( aZone->IsFilled() )
......@@ -1501,7 +1503,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
{
m_out->Print( 0, " (smoothing" );
switch (aZone->GetCornerSmoothingType())
switch( aZone->GetCornerSmoothingType() )
{
case ZONE_SETTINGS::SMOOTHING_CHAMFER:
m_out->Print( 0, " chamfer" );
......@@ -1512,8 +1514,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
break;
default:
THROW_IO_ERROR(
wxString::Format( _( "unknown zone corner smoothing type %d" ),
THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
aZone->GetCornerSmoothingType() ) );
}
m_out->Print( 0, ")" );
......@@ -1530,13 +1531,13 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
if( cv.GetCornersCount() )
{
m_out->Print( aNestLevel + 1, "(polygon\n" );
m_out->Print( aNestLevel + 2, "(pts\n" );
m_out->Print( aNestLevel+1, "(polygon\n");
m_out->Print( aNestLevel+2, "(pts\n" );
for( unsigned it = 0; it < cv.GetCornersCount(); ++it )
{
if( newLine == 0 )
m_out->Print( aNestLevel + 3, "(xy %s %s)",
m_out->Print( aNestLevel+3, "(xy %s %s)",
FMT_IU( cv.GetX( it ) ).c_str(), FMT_IU( cv.GetY( it ) ).c_str() );
else
m_out->Print( 0, " (xy %s %s)",
......@@ -1569,7 +1570,7 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
}
}
m_out->Print( aNestLevel + 1, ")\n" );
m_out->Print( aNestLevel+1, ")\n" );
}
// Save the PolysList
......@@ -1578,13 +1579,13 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
if( fv.GetCornersCount() )
{
m_out->Print( aNestLevel + 1, "(filled_polygon\n" );
m_out->Print( aNestLevel + 2, "(pts\n" );
m_out->Print( aNestLevel+1, "(filled_polygon\n" );
m_out->Print( aNestLevel+2, "(pts\n" );
for( unsigned it = 0; it < fv.GetCornersCount(); ++it )
{
if( newLine == 0 )
m_out->Print( aNestLevel + 3, "(xy %s %s)",
m_out->Print( aNestLevel+3, "(xy %s %s)",
FMT_IU( fv.GetX( it ) ).c_str(), FMT_IU( fv.GetY( it ) ).c_str() );
else
m_out->Print( 0, " (xy %s %s)",
......@@ -1617,37 +1618,41 @@ void PCB_IO::format( ZONE_CONTAINER* aZone, int aNestLevel ) const throw( IO_ERR
}
}
m_out->Print( aNestLevel + 1, ")\n" );
m_out->Print( aNestLevel+1, ")\n" );
}
// Save the filling segments list
const std::vector<SEGMENT>& segs = aZone->FillSegments();
const std::vector< SEGMENT >& segs = aZone->FillSegments();
if( segs.size() )
{
m_out->Print( aNestLevel + 1, "(fill_segments\n" );
m_out->Print( aNestLevel+1, "(fill_segments\n" );
for( std::vector<SEGMENT>::const_iterator it = segs.begin(); it != segs.end(); ++it )
for( std::vector< SEGMENT >::const_iterator it = segs.begin(); it != segs.end(); ++it )
{
m_out->Print( aNestLevel + 2, "(pts (xy %s) (xy %s))\n",
m_out->Print( aNestLevel+2, "(pts (xy %s) (xy %s))\n",
FMT_IU( it->m_Start ).c_str(),
FMT_IU( it->m_End ).c_str() );
}
m_out->Print( aNestLevel + 1, ")\n" );
m_out->Print( aNestLevel+1, ")\n" );
}
m_out->Print( aNestLevel, ")\n" );
}
PCB_IO::PCB_IO( int aControlFlags ) :
m_cache( 0 ), m_ctl( aControlFlags ), m_parser( new PCB_PARSER() ),
m_cache( 0 ),
m_ctl( aControlFlags ),
m_parser( new PCB_PARSER() ),
m_mapping( new NETINFO_MAPPING() )
{
init( 0 );
m_out = &m_sf;
}
PCB_IO::~PCB_IO()
{
delete m_cache;
......@@ -1655,6 +1660,7 @@ PCB_IO::~PCB_IO()
delete m_mapping;
}
BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
{
FILE_LINE_READER reader( aFileName );
......@@ -1674,12 +1680,14 @@ BOARD* PCB_IO::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPER
return board;
}
void PCB_IO::init( const PROPERTIES* aProperties )
{
m_board = NULL;
m_props = aProperties;
}
void PCB_IO::cacheLib( const wxString& aLibraryPath, const wxString& aFootprintName )
{
if( !m_cache || m_cache->IsModified( aLibraryPath, aFootprintName ) )
......@@ -1691,6 +1699,7 @@ void PCB_IO::cacheLib( const wxString& aLibraryPath, const wxString& aFootprintN
}
}
wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
......@@ -1700,8 +1709,7 @@ wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
if( !dir.IsOpened() )
{
THROW_IO_ERROR(
wxString::Format( _( "footprint library path '%s' does not exist" ),
THROW_IO_ERROR( wxString::Format( _( "footprint library path '%s' does not exist" ),
GetChars( aLibraryPath ) ) );
}
......@@ -1712,6 +1720,7 @@ wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
const MODULE_MAP& mods = m_cache->GetModules();
for( MODULE_CITER it = mods.begin(); it != mods.end(); ++it )
{
ret.Add( FROM_UTF8( it->first.c_str() ) );
......@@ -1726,13 +1735,14 @@ wxArrayString PCB_IO::FootprintEnumerate( const wxString& aLibraryPath,
{
wxFileName fn( aLibraryPath, fpFileName );
ret.Add( fn.GetName() );
}while( dir.GetNext( &fpFileName ) );
} while( dir.GetNext( &fpFileName ) );
}
#endif
return ret;
}
MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties )
{
......@@ -1755,6 +1765,7 @@ MODULE* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFo
return new MODULE( *it->second->GetModule() );
}
void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
const PROPERTIES* aProperties )
{
......@@ -1770,8 +1781,10 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootpri
if( !m_cache->IsWritable() )
{
wxString msg = wxString::Format( _( "Library '%s' is read only" ),
GetChars( aLibraryPath ) );
wxString msg = wxString::Format(
_( "Library '%s' is read only" ),
GetChars( aLibraryPath )
);
THROW_IO_ERROR( msg );
}
......@@ -1781,20 +1794,17 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootpri
MODULE_MAP& mods = m_cache->GetModules();
// Quietly overwrite module and delete module file from path for any by same name.
wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetFootprintName(),
KiCadFootprintFileExtension );
wxFileName fn( aLibraryPath, aFootprint->GetFPID().GetFootprintName(), KiCadFootprintFileExtension );
if( !fn.IsOk() )
{
THROW_IO_ERROR(
wxString::Format( _( "Footprint file name '%s' is not valid." ),
THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
GetChars( fn.GetFullPath() ) ) );
}
if( fn.FileExists() && !fn.IsFileWritable() )
{
THROW_IO_ERROR(
wxString::Format( _( "user does not have write permission to delete file '%s' " ),
THROW_IO_ERROR( wxString::Format( _( "user does not have write permission to delete file '%s' " ),
GetChars( fn.GetFullPath() ) ) );
}
......@@ -1826,8 +1836,8 @@ void PCB_IO::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootpri
m_cache->Save();
}
void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
const PROPERTIES* aProperties )
void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
......@@ -1837,19 +1847,19 @@ void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFoo
if( !m_cache->IsWritable() )
{
THROW_IO_ERROR(
wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) );
THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ),
aLibraryPath.GetData() ) );
}
m_cache->Remove( aFootprintName );
}
void PCB_IO::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
if( wxDir::Exists( aLibraryPath ) )
{
THROW_IO_ERROR(
wxString::Format( _( "cannot overwrite library path '%s'" ),
THROW_IO_ERROR( wxString::Format( _( "cannot overwrite library path '%s'" ),
aLibraryPath.GetData() ) );
}
......@@ -1862,6 +1872,7 @@ void PCB_IO::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES*
m_cache->Save();
}
bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
wxFileName fn;
......@@ -1873,8 +1884,7 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( !fn.IsDirWritable() )
{
THROW_IO_ERROR(
wxString::Format( _( "user does not have permission to delete directory '%s'" ),
THROW_IO_ERROR( wxString::Format( _( "user does not have permission to delete directory '%s'" ),
aLibraryPath.GetData() ) );
}
......@@ -1882,8 +1892,7 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( dir.HasSubDirs() )
{
THROW_IO_ERROR(
wxString::Format( _( "library directory '%s' has unexpected sub-directories" ),
THROW_IO_ERROR( wxString::Format( _( "library directory '%s' has unexpected sub-directories" ),
aLibraryPath.GetData() ) );
}
......@@ -1902,9 +1911,7 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
if( tmp.GetExt() != KiCadFootprintFileExtension )
{
THROW_IO_ERROR(
wxString::Format(
_( "unexpected file '%s' was found in library path '%s'" ),
THROW_IO_ERROR( wxString::Format( _( "unexpected file '%s' was found in library path '%s'" ),
files[i].GetData(), aLibraryPath.GetData() ) );
}
}
......@@ -1922,8 +1929,7 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
// we don't want that. we want bare metal portability with no UI here.
if( !wxRmdir( aLibraryPath ) )
{
THROW_IO_ERROR(
wxString::Format( _( "footprint library '%s' cannot be deleted" ),
THROW_IO_ERROR( wxString::Format( _( "footprint library '%s' cannot be deleted" ),
aLibraryPath.GetData() ) );
}
......@@ -1943,6 +1949,7 @@ bool PCB_IO::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES*
return true;
}
bool PCB_IO::IsFootprintLibWritable( const wxString& aLibraryPath )
{
LOCALE_IO toggle;
......
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