diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 408d539fdf..a8faa82804 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -3131,1091 +3131,6 @@ void LEGACY_PLUGIN::SaveModule3D( const MODULE* me ) const } -#if 0 - -//-------------------------------------------------------- - - -static inline const char* ShowVertJustify( EDA_TEXT_VJUSTIFY_T vertical ) -{ - const char* rs; - switch( vertical ) - { - case GR_TEXT_VJUSTIFY_TOP: rs = "T"; break; - case GR_TEXT_VJUSTIFY_CENTER: rs = "C"; break; - case GR_TEXT_VJUSTIFY_BOTTOM: rs = "B"; break; - default: rs = "?"; break; - } - return rs; -} - - -static inline const char* ShowHorizJustify( EDA_TEXT_HJUSTIFY_T horizontal ) -{ - const char* rs; - switch( horizontal ) - { - case GR_TEXT_HJUSTIFY_LEFT: rs = "L"; break; - case GR_TEXT_HJUSTIFY_CENTER: rs = "C"; break; - case GR_TEXT_HJUSTIFY_RIGHT: rs = "R"; break; - default: rs = "?"; break; - } - return rs; -} - - -#define SPBUFZ 50 // wire all usages of this together. - -int LEGACY_PLUGIN::biuSprintf( char* buf, BIU aValue ) const -{ - double engUnits = biuToDisk * aValue; - int len; - - if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) - { - len = snprintf( buf, SPBUFZ, "%.10f", engUnits ); - - while( --len > 0 && buf[len] == '0' ) - buf[len] = '\0'; - - ++len; - } - else - { - // The %.10g is about optimal since we are dealing with a bounded - // range on aValue, and we can be sure that there will never - // be a reason to have more than 6 digits to the right of the - // decimal point because we are converting from integer - // (signed whole numbers) nanometers to mm. A value of - // 0.000001 is one nanometer, the smallest positive nonzero value - // that we can ever have here. If you ever see a board file with - // more digits to the right of the decimal point than 6, this is a - // possibly a bug in a formatting string nearby. - len = snprintf( buf, SPBUFZ, "%.10g", engUnits ); - } - return len; -} - - -std::string LEGACY_PLUGIN::fmtBIU( BIU aValue ) const -{ - char temp[SPBUFZ]; - - int len = biuSprintf( temp, aValue ); - - return std::string( temp, len ); -} - - -std::string LEGACY_PLUGIN::fmtDEG( double aAngle ) const -{ - char temp[50]; - - // @todo a hook site to convert from tenths degrees to degrees for BOARD_FORMAT_VERSION 2. - - // MINGW: snprintf() comes from gcc folks, sprintf() comes from Microsoft. - int len = snprintf( temp, sizeof( temp ), "%.10g", aAngle ); - - return std::string( temp, len ); -} - - -std::string LEGACY_PLUGIN::fmtBIUPair( BIU first, BIU second ) const -{ - char temp[2*SPBUFZ+2]; - char* cp = temp; - - cp += biuSprintf( cp, first ); - - *cp++ = ' '; - - cp += biuSprintf( cp, second ); - - return std::string( temp, cp - temp ); -} - -void LEGACY_PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( aProperties ); - - FILE* fp = wxFopen( aFileName, wxT( "w" ) ); - if( !fp ) - { - m_error.Printf( _( "Unable to open file '%s'" ), aFileName.GetData() ); - THROW_IO_ERROR( m_error ); - } - - m_filename = aFileName; - - // wxf now owns fp, will close on exception or return - wxFFile wxf( fp ); - - m_fp = fp; // member function accessibility - - wxString header = wxString::Format( - wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by Pcbnew%s\n\n" ), - LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(), - GetBuildVersion().GetData() ); - - // save a file header, if caller provided one (with trailing \n hopefully). - fprintf( m_fp, "%s", TO_UTF8( header ) ); - - SaveBOARD( aBoard ); -} - - -wxString LEGACY_PLUGIN::writeError() const -{ - return wxString::Format( _( "error writing to file '%s'" ), m_filename.GetData() ); -} - -#define CHECK_WRITE_ERROR() \ -do { \ - if( ferror( m_fp ) ) \ - { \ - THROW_IO_ERROR( writeError() ); \ - } \ -} while(0) - - -// With the advent of the LSET expansion it was agreed to abort the legacy save since -// we'd have to expand the old format in order to suppor the new LAYER_IDs. - -void LEGACY_PLUGIN::SaveBOARD( const BOARD* aBoard ) const -{ - m_mapping->SetBoard( aBoard ); - - saveGENERAL( aBoard ); - - saveSHEET( aBoard ); - - saveSETUP( aBoard ); - - saveBOARD_ITEMS( aBoard ); -} - - -void LEGACY_PLUGIN::saveGENERAL( const BOARD* aBoard ) const -{ - fprintf( m_fp, "$GENERAL\n" ); - fprintf( m_fp, "encoding utf-8\n" ); - - // tell folks the units used within the file, as early as possible here. - fprintf( m_fp, "Units mm\n" ); - - // Write copper layer count - fprintf( m_fp, "LayerCount %d\n", aBoard->GetCopperLayerCount() ); - - /* No, EnabledLayers has this information, plus g_TabAllCopperLayerMask is - global and globals are not allowed in a plugin. - fprintf( m_fp, - "Ly %8X\n", - g_TabAllCopperLayerMask[NbLayers - 1] | ALL_NO_CU_LAYERS ); - */ - - fprintf( m_fp, "EnabledLayers %08X\n", aBoard->GetEnabledLayers() ); - - if( aBoard->GetEnabledLayers() != aBoard->GetVisibleLayers() ) - fprintf( m_fp, "VisibleLayers %08X\n", aBoard->GetVisibleLayers() ); - - fprintf( m_fp, "Links %d\n", aBoard->GetRatsnestsCount() ); - fprintf( m_fp, "NoConn %d\n", aBoard->GetUnconnectedNetCount() ); - - // Write Bounding box info - EDA_RECT bbbox = ((BOARD*)aBoard)->ComputeBoundingBox(); - - fprintf( m_fp, "Di %s %s\n", - fmtBIUPair( bbbox.GetX(), bbbox.GetY() ).c_str(), - fmtBIUPair( bbbox.GetRight(), bbbox.GetBottom() ).c_str() ); - - fprintf( m_fp, "Ndraw %d\n", aBoard->m_Drawings.GetCount() ); - fprintf( m_fp, "Ntrack %d\n", aBoard->GetNumSegmTrack() ); - fprintf( m_fp, "Nzone %d\n", aBoard->GetNumSegmZone() ); - fprintf( m_fp, "BoardThickness %s\n", fmtBIU( aBoard->GetDesignSettings().GetBoardThickness() ).c_str() ); - fprintf( m_fp, "Nmodule %d\n", aBoard->m_Modules.GetCount() ); - fprintf( m_fp, "Nnets %d\n", m_mapping->GetSize() ); - fprintf( m_fp, "$EndGENERAL\n\n" ); -} - - -void LEGACY_PLUGIN::saveSHEET( const BOARD* aBoard ) const -{ - const PAGE_INFO& pageInfo = aBoard->GetPageSettings(); - const TITLE_BLOCK& tb = ((BOARD*)aBoard)->GetTitleBlock(); - - fprintf( m_fp, "$SHEETDESCR\n" ); - - // paper is described in mils - fprintf( m_fp, "Sheet %s %d %d%s\n", - TO_UTF8( pageInfo.GetType() ), - pageInfo.GetWidthMils(), - pageInfo.GetHeightMils(), - !pageInfo.IsCustom() && pageInfo.IsPortrait() ? - " portrait" : "" - ); - - fprintf( m_fp, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() ); - fprintf( m_fp, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() ); - fprintf( m_fp, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() ); - fprintf( m_fp, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() ); - fprintf( m_fp, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() ); - fprintf( m_fp, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() ); - fprintf( m_fp, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() ); - fprintf( m_fp, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() ); - fprintf( m_fp, "$EndSHEETDESCR\n\n" ); -} - - -void LEGACY_PLUGIN::saveSETUP( const BOARD* aBoard ) const -{ - const BOARD_DESIGN_SETTINGS& bds = aBoard->GetDesignSettings(); - NETCLASSPTR netclass_default = bds.GetDefault(); - - fprintf( m_fp, "$SETUP\n" ); - - /* Internal units are nobody's business, they are internal. - Units used in the file are now in the "Units" attribute of $GENERAL. - fprintf( m_fp,, "InternalUnit %f INCH\n", 1.0 / PCB_LEGACY_INTERNAL_UNIT ); - */ - - fprintf( m_fp, "Layers %d\n", aBoard->GetCopperLayerCount() ); - - unsigned layerMask = ALL_CU_LAYERS & aBoard->GetEnabledLayers(); - - for( LAYER_NUM layer = FIRST_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) - { - if( layerMask & MASK( layer ) ) - { - fprintf( m_fp, "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( m_fp, "TrackWidth %s\n", - fmtBIU( aBoard->GetDesignSettings().GetCurrentTrackWidth() ).c_str() ); - - // Save custom tracks width list (the first is not saved here: this is the netclass value - for( unsigned ii = 1; ii < aBoard->GetDesignSettings().m_TrackWidthList.size(); ii++ ) - fprintf( m_fp, "TrackWidthList %s\n", fmtBIU( aBoard->GetDesignSettings().m_TrackWidthList[ii] ).c_str() ); - - fprintf( m_fp, "TrackClearence %s\n", fmtBIU( netclass_default->GetClearance() ).c_str() ); - - // ZONE_SETTINGS - fprintf( m_fp, "ZoneClearence %s\n", fmtBIU( aBoard->GetZoneSettings().m_ZoneClearance ).c_str() ); - fprintf( m_fp, "Zone_45_Only %d\n", aBoard->GetZoneSettings().m_Zone_45_Only ); - - fprintf( m_fp, "TrackMinWidth %s\n", fmtBIU( bds.m_TrackMinWidth ).c_str() ); - - fprintf( m_fp, "DrawSegmWidth %s\n", fmtBIU( bds.m_DrawSegmentWidth ).c_str() ); - fprintf( m_fp, "EdgeSegmWidth %s\n", fmtBIU( bds.m_EdgeSegmentWidth ).c_str() ); - - // Save current default via size, for compatibility with older Pcbnew version; - fprintf( m_fp, "ViaSize %s\n", fmtBIU( netclass_default->GetViaDiameter() ).c_str() ); - fprintf( m_fp, "ViaDrill %s\n", fmtBIU( netclass_default->GetViaDrill() ).c_str() ); - fprintf( m_fp, "ViaMinSize %s\n", fmtBIU( bds.m_ViasMinSize ).c_str() ); - fprintf( m_fp, "ViaMinDrill %s\n", fmtBIU( bds.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 < aBoard->GetDesignSettings().m_ViasDimensionsList.size(); ii++ ) - fprintf( m_fp, "ViaSizeList %s %s\n", - fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Diameter ).c_str(), - fmtBIU( aBoard->GetDesignSettings().m_ViasDimensionsList[ii].m_Drill ).c_str() ); - - // for old versions compatibility: - fprintf( m_fp, "MicroViaSize %s\n", fmtBIU( netclass_default->GetuViaDiameter() ).c_str() ); - fprintf( m_fp, "MicroViaDrill %s\n", fmtBIU( netclass_default->GetuViaDrill() ).c_str() ); - fprintf( m_fp, "MicroViasAllowed %s\n", fmtBIU( bds.m_MicroViasAllowed ).c_str() ); - fprintf( m_fp, "MicroViaMinSize %s\n", fmtBIU( bds.m_MicroViasMinSize ).c_str() ); - fprintf( m_fp, "MicroViaMinDrill %s\n", fmtBIU( bds.m_MicroViasMinDrill ).c_str() ); - - fprintf( m_fp, "TextPcbWidth %s\n", fmtBIU( bds.m_PcbTextWidth ).c_str() ); - fprintf( m_fp, "TextPcbSize %s\n", fmtBIUSize( bds.m_PcbTextSize ).c_str() ); - - fprintf( m_fp, "EdgeModWidth %s\n", fmtBIU( bds.m_ModuleSegmentWidth ).c_str() ); - fprintf( m_fp, "TextModSize %s\n", fmtBIUSize( bds.m_ModuleTextSize ).c_str() ); - fprintf( m_fp, "TextModWidth %s\n", fmtBIU( bds.m_ModuleTextWidth ).c_str() ); - - fprintf( m_fp, "PadSize %s\n", fmtBIUSize( bds.m_Pad_Master.GetSize() ).c_str() ); - fprintf( m_fp, "PadDrill %s\n", fmtBIU( bds.m_Pad_Master.GetDrillSize().x ).c_str() ); - - fprintf( m_fp, "Pad2MaskClearance %s\n", fmtBIU( bds.m_SolderMaskMargin ).c_str() ); - fprintf( m_fp, "SolderMaskMinWidth %s\n", fmtBIU( bds.m_SolderMaskMinWidth ).c_str() ); - - if( bds.m_SolderPasteMargin != 0 ) - fprintf( m_fp, "Pad2PasteClearance %s\n", fmtBIU( bds.m_SolderPasteMargin ).c_str() ); - - if( bds.m_SolderPasteMarginRatio != 0 ) - fprintf( m_fp, "Pad2PasteClearanceRatio %g\n", bds.m_SolderPasteMarginRatio ); - - fprintf( m_fp, "GridOrigin %s\n", fmtBIUPoint( aBoard->GetGridOrigin() ).c_str() ); - fprintf( m_fp, "AuxiliaryAxisOrg %s\n", fmtBIUPoint( aBoard->GetAuxOrigin() ).c_str() ); - - fprintf( m_fp, "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( m_fp, "PcbPlotParams %s\n", TO_UTF8( record ) ); - } - - fprintf( m_fp, "$EndSETUP\n\n" ); -} - - -void LEGACY_PLUGIN::saveBOARD_ITEMS( const BOARD* aBoard ) const -{ - // save the nets - for( NETINFO_MAPPING::iterator net = m_mapping->begin(), netEnd = m_mapping->end(); - net != netEnd; ++net ) - { - saveNETINFO_ITEM( *net ); - } - - // Saved nets do not include netclass names, so save netclasses after nets. - saveNETCLASSES( &aBoard->GetDesignSettings().m_NetClasses ); - - // save the modules - for( MODULE* m = aBoard->m_Modules; m; m = (MODULE*) m->Next() ) - saveMODULE( m ); - - // save the graphics owned by the board (not owned by a module) - for( BOARD_ITEM* gr = aBoard->m_Drawings; gr; gr = gr->Next() ) - { - switch( gr->Type() ) - { - case PCB_TEXT_T: - savePCB_TEXT( (TEXTE_PCB*) gr ); - break; - case PCB_LINE_T: - savePCB_LINE( (DRAWSEGMENT*) gr ); - break; - case PCB_TARGET_T: - savePCB_TARGET( (PCB_TARGET*) gr ); - break; - case PCB_DIMENSION_T: - saveDIMENSION( (DIMENSION*) gr ); - break; - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) ); - } - } - - // do not save MARKER_PCBs, they can be regenerated easily - - // save the tracks & vias - fprintf( m_fp, "$TRACK\n" ); - for( TRACK* track = aBoard->m_Track; track; track = track->Next() ) - saveTRACK( track ); - fprintf( m_fp, "$EndTRACK\n" ); - - // save the old obsolete zones which were done by segments (tracks) - fprintf( m_fp, "$ZONE\n" ); - for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() ) - saveTRACK( zone ); - fprintf( m_fp, "$EndZONE\n" ); - - // save the polygon (which are the newer technology) zones - for( int i=0; i < aBoard->GetAreaCount(); ++i ) - saveZONE_CONTAINER( aBoard->GetArea( i ) ); - - fprintf( m_fp, "$EndBOARD\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const -{ - fprintf( m_fp, "$EQUIPOT\n" ); - fprintf( m_fp, "Na %d %s\n", m_mapping->Translate( aNet->GetNet() ), - EscapedUTF8( aNet->GetNetname() ).c_str() ); - fprintf( m_fp, "St %s\n", "~" ); - fprintf( m_fp, "$EndEQUIPOT\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETCLASSES( const NETCLASSES* aNetClasses ) const -{ - // save the default first. - saveNETCLASS( aNetClasses->GetDefault() ); - - // the rest will be alphabetical in the *.brd file. - for( NETCLASSES::const_iterator it = aNetClasses->begin(); it != aNetClasses->end(); ++it ) - { - NETCLASSPTR netclass = it->second; - saveNETCLASS( netclass ); - } - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveNETCLASS( const NETCLASSPTR nc ) const -{ - fprintf( m_fp, "$NCLASS\n" ); - fprintf( m_fp, "Name %s\n", EscapedUTF8( nc->GetName() ).c_str() ); - fprintf( m_fp, "Desc %s\n", EscapedUTF8( nc->GetDescription() ).c_str() ); - - fprintf( m_fp, "Clearance %s\n", fmtBIU( nc->GetClearance() ).c_str() ); - fprintf( m_fp, "TrackWidth %s\n", fmtBIU( nc->GetTrackWidth() ).c_str() ); - - fprintf( m_fp, "ViaDia %s\n", fmtBIU( nc->GetViaDiameter() ).c_str() ); - fprintf( m_fp, "ViaDrill %s\n", fmtBIU( nc->GetViaDrill() ).c_str() ); - - fprintf( m_fp, "uViaDia %s\n", fmtBIU( nc->GetuViaDiameter() ).c_str() ); - fprintf( m_fp, "uViaDrill %s\n", fmtBIU( nc->GetuViaDrill() ).c_str() ); - - for( NETCLASS::const_iterator it = nc->begin(); it!=nc->end(); ++it ) - fprintf( m_fp, "AddNet %s\n", EscapedUTF8( *it ).c_str() ); - - fprintf( m_fp, "$EndNCLASS\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE_TEXT( const TEXTE_MODULE* me ) const -{ - MODULE* parent = (MODULE*) me->GetParent(); - double orient = me->GetOrientation(); - - // 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->GetOrientation(); - - wxString txt = me->GetText(); - - fprintf( m_fp, "T%d %s %s %s %s %c %c %d %c %s", - me->GetType(), - fmtBIUPoint( me->GetPos0() ).c_str(), // m_Pos0.x, m_Pos0.y, - - // legacy has goofed reversed order: ( y, x ) - fmtBIUPair( me->GetSize().y, me->GetSize().x ).c_str(), - - fmtDEG( orient ).c_str(), - fmtBIU( me->GetThickness() ).c_str(), // m_Thickness, - me->IsMirrored() ? 'M' : 'N', - me->IsVisible() ? 'V' : 'I', - me->GetLayer(), - me->IsItalic() ? 'I' : 'N', - EscapedUTF8( txt ).c_str() - ); - - if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER || - me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER ) - { - fprintf( m_fp, " %s %s\n", - ShowHorizJustify( me->GetHorizJustify() ), - ShowVertJustify( me->GetVertJustify() ) - ); - } - else - fprintf( m_fp, "\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE_EDGE( const EDGE_MODULE* me ) const -{ - switch( me->GetShape() ) - { - case S_SEGMENT: - fprintf( m_fp, "DS %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_CIRCLE: - fprintf( m_fp, "DC %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_ARC: - fprintf( m_fp, "DA %s %s %s %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - fmtDEG( me->GetAngle() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - break; - - case S_POLYGON: - { - const std::vector& polyPoints = me->GetPolyPoints(); - - fprintf( m_fp, "DP %s %s %d %s %d\n", - fmtBIUPoint( me->m_Start0 ).c_str(), - fmtBIUPoint( me->m_End0 ).c_str(), - (int) polyPoints.size(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetLayer() ); - - for( unsigned i = 0; iGetShape() ) ); - } - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePAD( const D_PAD* me ) const -{ - fprintf( m_fp, "$PAD\n" ); - - int cshape; - - switch( me->GetShape() ) - { - case PAD_SHAPE_CIRCLE: cshape = 'C'; break; - case PAD_SHAPE_RECT: cshape = 'R'; break; - case PAD_SHAPE_OVAL: cshape = 'O'; break; - case PAD_SHAPE_TRAPEZOID: cshape = 'T'; break; - - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_FORMAT, me->GetShape() ) ); - } - -#if BOARD_FORMAT_VERSION == 1 // saving mode is a compile time option - - wxString wpadname = me->GetPadName(); // universal character set padname - std::string spadname; - - for( unsigned i = 0; wpadname.size(); ++i ) - { - // truncate from universal character down to 8 bit foreign jibber - // jabber byte. This basically duplicates what was done in the old - // BOARD_FORMAT_VERSION 1 code. Any characters that were in the 8 bit - // character space were OK. - spadname += (char) wpadname[i]; - } - - fprintf( m_fp, "Sh \"%s\" %c %s %s %s\n", - spadname.c_str(), // probably ASCII, but possibly jibber jabber -#else - - fprintf( m_fp, "Sh %s %c %s %s %s\n", - // legacy VERSION 2 simply uses UTF8, wrapped in quotes, - // and 99.99 % of the time there is no difference between 1 & 2, - // since ASCII is a subset of UTF8. But if they were not using - // ASCII pad names, then there is a difference in the file. - EscapedUTF8( me->GetPadName() ).c_str(), -#endif - cshape, - fmtBIUSize( me->GetSize() ).c_str(), - fmtBIUSize( me->GetDelta() ).c_str(), - fmtDEG( me->GetOrientation() ).c_str() ); - - fprintf( m_fp, "Dr %s %s", - fmtBIU( me->GetDrillSize().x ).c_str(), - fmtBIUPoint( me->GetOffset() ).c_str() ); - - if( me->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) - { - fprintf( m_fp, " %c %s", 'O', fmtBIUSize( me->GetDrillSize() ).c_str() ); - } - - fprintf( m_fp, "\n" ); - - const char* texttype; - - switch( me->GetAttribute() ) - { - case PAD_ATTRIB_STANDARD: texttype = "STD"; break; - case PAD_ATTRIB_SMD: texttype = "SMD"; break; - case PAD_ATTRIB_CONN: texttype = "CONN"; break; - case PAD_ATTRIB_HOLE_NOT_PLATED: texttype = "HOLE"; break; - - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_PAD_ATTRIBUTE, me->GetAttribute() ) ); - } - - fprintf( m_fp, "At %s N %08X\n", texttype, me->GetLayerSet() ); - - fprintf( m_fp, "Ne %d %s\n", m_mapping->Translate( me->GetNetCode() ), - EscapedUTF8( me->GetNetname() ).c_str() ); - - fprintf( m_fp, "Po %s\n", fmtBIUPoint( me->GetPos0() ).c_str() ); - - if( me->GetPadToDieLength() != 0 ) - fprintf( m_fp, "Le %s\n", fmtBIU( me->GetPadToDieLength() ).c_str() ); - - if( me->GetLocalSolderMaskMargin() != 0 ) - fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() ); - - if( me->GetLocalSolderPasteMargin() != 0 ) - fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() ); - - double ratio = me->GetLocalSolderPasteMarginRatio(); - if( ratio != 0.0 ) - fprintf( m_fp, ".SolderPasteRatio %g\n", ratio ); - - if( me->GetLocalClearance() != 0 ) - fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() ); - - if( me->GetZoneConnection() != PAD_ZONE_CONN_INHERITED ) - fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() ); - - if( me->GetThermalWidth() != 0 ) - fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() ); - - if( me->GetThermalGap() != 0 ) - fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() ); - - fprintf( m_fp, "$EndPAD\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveMODULE( const MODULE* me ) const -{ - char statusTxt[3]; - double orient = me->GetOrientation(); - - // Do not save full FPID. Only the footprint name. The legacy file format should - // never support FPIDs. - fprintf( m_fp, "$MODULE %s\n", me->GetFPID().GetFootprintName().c_str() ); - - statusTxt[0] = me->IsLocked() ? 'F' : '~'; - statusTxt[1] = me->IsPlaced() ? 'P' : '~'; - statusTxt[2] = '\0'; - - fprintf( m_fp, "Po %s %s %d %08lX %08lX %s\n", - fmtBIUPoint( me->GetPosition() ).c_str(), // m_Pos.x, m_Pos.y, - fmtDEG( orient ).c_str(), - me->GetLayer(), - me->GetLastEditTime(), - me->GetTimeStamp(), - statusTxt ); - - fprintf( m_fp, "Li %s\n", me->GetFPID().GetFootprintName().c_str() ); - - if( !me->GetDescription().IsEmpty() ) - { - fprintf( m_fp, "Cd %s\n", TO_UTF8( me->GetDescription() ) ); - } - - if( !me->GetKeywords().IsEmpty() ) - { - fprintf( m_fp, "Kw %s\n", TO_UTF8( me->GetKeywords() ) ); - } - - fprintf( m_fp, "Sc %lX\n", me->GetTimeStamp() ); - fprintf( m_fp, "AR %s\n", TO_UTF8( me->GetPath() ) ); - fprintf( m_fp, "Op %X %X 0\n", me->GetPlacementCost90(), me->GetPlacementCost180() ); - - if( me->GetLocalSolderMaskMargin() != 0 ) - fprintf( m_fp, ".SolderMask %s\n", fmtBIU( me->GetLocalSolderMaskMargin() ).c_str() ); - - if( me->GetLocalSolderPasteMargin() != 0 ) - fprintf( m_fp, ".SolderPaste %s\n", fmtBIU( me->GetLocalSolderPasteMargin() ).c_str() ); - - double ratio = me->GetLocalSolderPasteMarginRatio(); - if( ratio != 0.0 ) - fprintf( m_fp, ".SolderPasteRatio %g\n", ratio ); - - if( me->GetLocalClearance() != 0 ) - fprintf( m_fp, ".LocalClearance %s\n", fmtBIU( me->GetLocalClearance( ) ).c_str() ); - - if( me->GetZoneConnection() != PAD_ZONE_CONN_INHERITED ) - fprintf( m_fp, ".ZoneConnection %d\n", me->GetZoneConnection() ); - - if( me->GetThermalWidth() != 0 ) - fprintf( m_fp, ".ThermalWidth %s\n", fmtBIU( me->GetThermalWidth() ).c_str() ); - - if( me->GetThermalGap() != 0 ) - fprintf( m_fp, ".ThermalGap %s\n", fmtBIU( me->GetThermalGap() ).c_str() ); - - // attributes - if( me->GetAttributes() != MOD_DEFAULT ) - { - fprintf( m_fp, "At" ); - - if( me->GetAttributes() & MOD_CMS ) - fprintf( m_fp, " SMD" ); - - if( me->GetAttributes() & MOD_VIRTUAL ) - fprintf( m_fp, " VIRTUAL" ); - - fprintf( m_fp, "\n" ); - } - - saveMODULE_TEXT( &me->Reference() ); - - saveMODULE_TEXT( &me->Value() ); - - // save drawing elements - for( BOARD_ITEM* gr = me->GraphicalItems(); gr; gr = gr->Next() ) - { - switch( gr->Type() ) - { - case PCB_MODULE_TEXT_T: - saveMODULE_TEXT( static_cast( gr )); - break; - case PCB_MODULE_EDGE_T: - saveMODULE_EDGE( static_cast( gr )); - break; - default: - THROW_IO_ERROR( wxString::Format( UNKNOWN_GRAPHIC_FORMAT, gr->Type() ) ); - } - } - - for( D_PAD* pad = me->Pads(); pad; pad = pad->Next() ) - savePAD( pad ); - - SaveModule3D( me ); - - fprintf( m_fp, "$EndMODULE %s\n", me->GetFPID().GetFootprintName().c_str() ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_TARGET( const PCB_TARGET* me ) const -{ - fprintf( m_fp, "$PCB_TARGET\n" ); - - fprintf( m_fp, "Po %X %d %s %s %s %lX\n", - me->GetShape(), - me->GetLayer(), - fmtBIUPoint( me->GetPosition() ).c_str(), - fmtBIU( me->GetSize() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - me->GetTimeStamp() - ); - - fprintf( m_fp, "$EndPCB_TARGET\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_LINE( const DRAWSEGMENT* me ) const -{ - fprintf( m_fp, "$DRAWSEGMENT\n" ); - - fprintf( m_fp, "Po %d %s %s %s\n", - me->GetShape(), - fmtBIUPoint( me->GetStart() ).c_str(), - fmtBIUPoint( me->GetEnd() ).c_str(), - fmtBIU( me->GetWidth() ).c_str() - ); - - if( me->GetType() != S_CURVE ) - { - fprintf( m_fp, "De %d %d %s %lX %X\n", - me->GetLayer(), - me->GetType(), - fmtDEG( me->GetAngle() ).c_str(), - me->GetTimeStamp(), - me->GetStatus() - ); - } - else - { - fprintf( m_fp, "De %d %d %s %lX %X %s %s\n", - me->GetLayer(), - me->GetType(), - fmtDEG( me->GetAngle() ).c_str(), - me->GetTimeStamp(), - me->GetStatus(), - fmtBIUPoint( me->GetBezControl1() ).c_str(), - fmtBIUPoint( me->GetBezControl2() ).c_str() - ); - } - - fprintf( m_fp, "$EndDRAWSEGMENT\n" ); -} - - -void LEGACY_PLUGIN::saveTRACK( const TRACK* me ) const -{ - int type = 0; - VIATYPE_T viatype = VIA_NOT_DEFINED; - int drill = UNDEFINED_DRILL_DIAMETER; - - if( me->Type() == PCB_VIA_T ) - { - const VIA *via = static_cast(me); - type = 1; - viatype = via->GetViaType(); - drill = via->GetDrill(); - } - - fprintf(m_fp, "Po %d %s %s %s %s\n", - viatype, - fmtBIUPoint( me->GetStart() ).c_str(), - fmtBIUPoint( me->GetEnd() ).c_str(), - fmtBIU( me->GetWidth() ).c_str(), - drill == UNDEFINED_DRILL_DIAMETER ? - "-1" : fmtBIU( drill ).c_str() ); - - fprintf(m_fp, "De %d %d %d %lX %X\n", - me->GetLayer(), type, m_mapping->Translate( me->GetNetCode() ), - me->GetTimeStamp(), me->GetStatus() ); -} - - -void LEGACY_PLUGIN::saveZONE_CONTAINER( const ZONE_CONTAINER* me ) const -{ - fprintf( m_fp, "$CZONE_OUTLINE\n" ); - - // Save the outline main info - // For keepout zones, net code and net name are irrelevant, so we store a dummy value - // just for ZONE_CONTAINER compatibility - fprintf( m_fp, "ZInfo %lX %d %s\n", - me->GetTimeStamp(), - me->GetIsKeepout() ? 0 : m_mapping->Translate( me->GetNetCode() ), - EscapedUTF8( me->GetIsKeepout() ? wxT("") : me->GetNetname() ).c_str() ); - - // Save the outline layer info - fprintf( m_fp, "ZLayer %d\n", me->GetLayer() ); - - // Save the outline aux info - int outline_hatch; - - switch( me->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; - } - - fprintf( m_fp, "ZAux %d %c\n", me->GetNumCorners(), outline_hatch ); - - if( me->GetPriority() > 0 ) - fprintf( m_fp, "ZPriority %d\n", me->GetPriority() ); - - // Save pad option and clearance - char padoption; - - switch( me->GetPadConnection() ) - { - default: - case PAD_ZONE_CONN_FULL: padoption = 'I'; break; - case PAD_ZONE_CONN_THERMAL: padoption = 'T'; break; - case PAD_ZONE_CONN_THT_THERMAL: padoption = 'H'; break; // H is for 'hole' since it reliefs holes only - case PAD_ZONE_CONN_NONE: padoption = 'X'; break; - } - - fprintf( m_fp, "ZClearance %s %c\n", - fmtBIU( me->GetZoneClearance() ).c_str(), - padoption ); - - fprintf( m_fp, "ZMinThickness %s\n", fmtBIU( me->GetMinThickness() ).c_str() ); - - fprintf( m_fp, "ZOptions %d %d %c %s %s\n", - me->GetFillMode(), - me->GetArcSegmentCount(), - me->IsFilled() ? 'S' : 'F', - fmtBIU( me->GetThermalReliefGap() ).c_str(), - fmtBIU( me->GetThermalReliefCopperBridge() ).c_str() ); - - if( me->GetIsKeepout() ) - { - fprintf( m_fp, "ZKeepout tracks %c vias %c copperpour %c\n", - me->GetDoNotAllowTracks() ? 'N' : 'Y', - me->GetDoNotAllowVias() ? 'N' : 'Y', - me->GetDoNotAllowCopperPour() ? 'N' : 'Y' ); - } - - fprintf( m_fp, "ZSmoothing %d %s\n", - me->GetCornerSmoothingType(), - fmtBIU( me->GetCornerRadius() ).c_str() ); - - // Save the corner list - const CPOLYGONS_LIST& cv = me->Outline()->m_CornersList; - - for( unsigned it = 0; it < cv.GetCornersCount(); ++it ) - { - fprintf( m_fp, "ZCorner %s %d\n", - fmtBIUPair( cv.GetX( it ), cv.GetY( it ) ).c_str(), - cv.IsEndContour( it ) ); - } - - // Save the PolysList - const CPOLYGONS_LIST& fv = me->GetFilledPolysList(); - if( fv.GetCornersCount() ) - { - fprintf( m_fp, "$POLYSCORNERS\n" ); - - for( unsigned it = 0; it < fv.GetCornersCount(); ++it ) - { - fprintf( m_fp, "%s %d %d\n", - fmtBIUPair( fv.GetX( it ), fv.GetY( it ) ).c_str(), - fv.IsEndContour( it ), - fv.GetUtility( it ) ); - } - - fprintf( m_fp, "$endPOLYSCORNERS\n" ); - } - - typedef std::vector< SEGMENT > SEGMENTS; - - // Save the filling segments list - const SEGMENTS& segs = me->FillSegments(); - - if( segs.size() ) - { - fprintf( m_fp, "$FILLSEGMENTS\n" ); - - for( SEGMENTS::const_iterator it = segs.begin(); it != segs.end(); ++it ) - { - fprintf( m_fp, "%s %s\n", - fmtBIUPoint( it->m_Start ).c_str(), - fmtBIUPoint( it->m_End ).c_str() ); - } - - fprintf( m_fp, "$endFILLSEGMENTS\n" ); - } - - fprintf( m_fp, "$endCZONE_OUTLINE\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::saveDIMENSION( const DIMENSION* me ) const -{ - // note: COTATION was the previous name of DIMENSION - // this old keyword is used here for compatibility - fprintf( m_fp, "$COTATION\n" ); - - fprintf( m_fp, "Ge %d %d %lX\n", me->GetShape(), me->GetLayer(), me->GetTimeStamp() ); - - fprintf( m_fp, "Va %s\n", fmtBIU( me->GetValue() ).c_str() ); - - if( !me->GetText().IsEmpty() ) - fprintf( m_fp, "Te %s\n", EscapedUTF8( me->GetText() ).c_str() ); - else - fprintf( m_fp, "Te \"?\"\n" ); - - fprintf( m_fp, "Po %s %s %s %s %d\n", - fmtBIUPoint( me->Text().GetTextPosition() ).c_str(), - fmtBIUSize( me->Text().GetSize() ).c_str(), - fmtBIU( me->Text().GetThickness() ).c_str(), - fmtDEG( me->Text().GetOrientation() ).c_str(), - me->Text().IsMirrored() ? 0 : 1 // strange but true - ); - - fprintf( m_fp, "Sb %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "Sd %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_featureLineDO.x, me->m_featureLineDO.y ).c_str(), - fmtBIUPair( me->m_featureLineDF.x, me->m_featureLineDF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "Sg %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_featureLineGO.x, me->m_featureLineGO.y ).c_str(), - fmtBIUPair( me->m_featureLineGF.x, me->m_featureLineGF.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S1 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIUPair( me->m_arrowD1F.x, me->m_arrowD1F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S2 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarF.x, me->m_crossBarF.y ).c_str(), - fmtBIUPair( me->m_arrowD2F.x, me->m_arrowD2F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S3 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_arrowG1F.x, me->m_arrowG1F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "S4 %d %s %s %s\n", S_SEGMENT, - fmtBIUPair( me->m_crossBarO.x, me->m_crossBarO.y ).c_str(), - fmtBIUPair( me->m_arrowG2F.x, me->m_arrowG2F.y ).c_str(), - fmtBIU( me->GetWidth() ).c_str() ); - - fprintf( m_fp, "$endCOTATION\n" ); - - CHECK_WRITE_ERROR(); -} - - -void LEGACY_PLUGIN::savePCB_TEXT( const TEXTE_PCB* me ) const -{ - if( me->GetText().IsEmpty() ) - return; - - fprintf( m_fp, "$TEXTPCB\n" ); - - wxArrayString* list = wxStringSplit( me->GetText(), '\n' ); - - for( unsigned ii = 0; ii < list->Count(); ii++ ) - { - wxString txt = list->Item( ii ); - - if ( ii == 0 ) - fprintf( m_fp, "Te %s\n", EscapedUTF8( txt ).c_str() ); - else - fprintf( m_fp, "nl %s\n", EscapedUTF8( txt ).c_str() ); - } - - delete list; - - fprintf( m_fp, "Po %s %s %s %s\n", - fmtBIUPoint( me->GetTextPosition() ).c_str(), - fmtBIUSize( me->GetSize() ).c_str(), - fmtBIU( me->GetThickness() ).c_str(), - fmtDEG( me->GetOrientation() ).c_str() ); - - fprintf( m_fp, "De %d %d %lX %s", - me->GetLayer(), - !me->IsMirrored(), - me->GetTimeStamp(), - me->IsItalic() ? "Italic" : "Normal" ); - - if( me->GetHorizJustify() != GR_TEXT_HJUSTIFY_CENTER || - me->GetVertJustify() != GR_TEXT_VJUSTIFY_CENTER ) - { - fprintf( m_fp, " %s %s\n", - ShowHorizJustify( me->GetHorizJustify() ), - ShowVertJustify( me->GetVertJustify() ) - ); - } - else - fprintf( m_fp, "\n" ); - - fprintf( m_fp, "$EndTEXTPCB\n" ); -} - -#endif // NO LEGACY_PLUGIN::Save() - - //------------------------------------------------- /* @@ -4482,96 +3397,6 @@ void LP_CACHE::LoadModules( LINE_READER* aReader ) } -#if 0 -void LP_CACHE::Save() -{ - if( !m_writable ) - { - THROW_IO_ERROR( wxString::Format( - _( "Legacy library file '%s' is read only" ), m_lib_path.GetData() ) ); - } - - wxString tempFileName; - - // a block {} scope to fire wxFFile wxf()'s destructor - { - // CreateTempFileName works better with an absolute path - wxFileName abs_lib_name( m_lib_path ); - - abs_lib_name.MakeAbsolute(); - tempFileName = wxFileName::CreateTempFileName( abs_lib_name.GetFullPath() ); - - //wxLogDebug( wxT( "tempFileName:'%s' m_lib_path:'%s'\n" ), TO_UTF8( tempFileName ), TO_UTF8( m_lib_path ) ); - - FILE* fp = wxFopen( tempFileName, wxT( "w" ) ); - if( !fp ) - { - THROW_IO_ERROR( wxString::Format( - _( "Unable to open or create legacy library file '%s'" ), - m_lib_path.GetData() ) ); - } - - // wxf now owns fp, will close on exception or exit from - // this block {} scope - wxFFile wxf( fp ); - - SaveHeader( fp ); - SaveIndex( fp ); - SaveModules( fp ); - SaveEndOfFile( fp ); - } - - // fp is now closed here, and that seems proper before trying to rename - // the temporary file to m_lib_path. - - wxRemove( m_lib_path ); // it is not an error if this does not exist - - // Even on linux you can see an _intermittent_ error when calling wxRename(), - // and it is fully inexplicable. See if this dodges the error. - wxMilliSleep( 250L ); - - if( !wxRenameFile( tempFileName, m_lib_path ) ) - { - THROW_IO_ERROR( wxString::Format( - _( "Unable to rename tempfile '%s' to library file '%s'" ), - tempFileName.GetData(), - m_lib_path.GetData() ) ); - } -} - - -void LP_CACHE::SaveHeader( FILE* aFile ) -{ - fprintf( aFile, "%s %s\n", FOOTPRINT_LIBRARY_HEADER, TO_UTF8( DateAndTime() ) ); - fprintf( aFile, "# encoding utf-8\n" ); - fprintf( aFile, "Units mm\n" ); -} - - -void LP_CACHE::SaveIndex( FILE* aFile ) -{ - fprintf( aFile, "$INDEX\n" ); - - for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it ) - { - fprintf( aFile, "%s\n", it->first.c_str() ); - } - - fprintf( aFile, "$EndINDEX\n" ); -} - - -void LP_CACHE::SaveModules( FILE* aFile ) -{ - m_owner->SetFilePtr( aFile ); - - for( MODULE_CITER it = m_modules.begin(); it != m_modules.end(); ++it ) - { - m_owner->saveMODULE( it->second ); - } -} -#endif - void LEGACY_PLUGIN::cacheLib( const wxString& aLibraryPath ) { if( !m_cache || m_cache->m_lib_path != aLibraryPath || @@ -4635,104 +3460,6 @@ MODULE* LEGACY_PLUGIN::FootprintLoad( const wxString& aLibraryPath, } -#if 0 // omit FootprintSave() - -void LEGACY_PLUGIN::FootprintSave( const wxString& aLibraryPath, - const MODULE* aFootprint, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( aProperties ); - - cacheLib( aLibraryPath ); - - if( !m_cache->m_writable ) - { - THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); - } - - std::string footprintName = aFootprint->GetFPID().GetFootprintName(); - - MODULE_MAP& mods = m_cache->m_modules; - - // quietly overwrite any by same name. - MODULE_CITER it = mods.find( footprintName ); - if( it != mods.end() ) - { - mods.erase( footprintName ); - } - - // I need my own copy for the cache - MODULE* my_module = new MODULE( *aFootprint ); - - // and it's time stamp must be 0, it should have no parent, orientation should - // be zero, and it should be on the front layer. - - my_module->SetTimeStamp( 0 ); - my_module->SetParent( 0 ); - - my_module->SetOrientation( 0 ); - - if( my_module->GetLayer() != F_Cu ) - my_module->Flip( my_module->GetPosition() ); - - mods.insert( footprintName, my_module ); - - m_cache->Save(); -} - - -void LEGACY_PLUGIN::FootprintDelete( const wxString& aLibraryPath, - const wxString& aFootprintName, const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; // toggles on, then off, the C locale. - - init( NULL ); - - cacheLib( aLibraryPath ); - - if( !m_cache->m_writable ) - { - THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only" ), aLibraryPath.GetData() ) ); - } - - std::string footprintName = TO_UTF8( aFootprintName ); - - size_t erasedCount = m_cache->m_modules.erase( footprintName ); - - if( erasedCount != 1 ) - { - THROW_IO_ERROR( wxString::Format( - _( "library '%s' has no footprint '%s' to delete" ), - aLibraryPath.GetData(), aFootprintName.GetData() ) ); - } - - m_cache->Save(); -} - - -void LEGACY_PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) -{ - if( wxFileExists( aLibraryPath ) ) - { - THROW_IO_ERROR( wxString::Format( - _( "library '%s' already exists, will not create a new" ), - aLibraryPath.GetData() ) ); - } - - LOCALE_IO toggle; - - init( NULL ); - - delete m_cache; - m_cache = new LP_CACHE( this, aLibraryPath ); - m_cache->Save(); - m_cache->Load(); // update m_writable and m_mod_time -} - -#endif // omit FootprintSave() - - bool LEGACY_PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { wxFileName fn = aLibraryPath; diff --git a/pcbnew/legacy_plugin.h b/pcbnew/legacy_plugin.h index 18e05199ce..2216438f9a 100644 --- a/pcbnew/legacy_plugin.h +++ b/pcbnew/legacy_plugin.h @@ -79,16 +79,6 @@ public: BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL ); - /* we let go of "save" support when the number of CU layers were expanded from 16 to 32. - void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL ); - - void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, - const PROPERTIES* aProperties = NULL ); - void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL ); - - void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ); - */ - wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL); MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName, @@ -125,7 +115,6 @@ protected: LINE_READER* m_reader; ///< no ownership here. FILE* m_fp; ///< no ownership here. - wxString m_filename; ///< for saves only, name is in m_reader for loads wxString m_field; ///< reused to stuff MODULE fields. int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing? @@ -222,76 +211,6 @@ protected: //-------------------------------------------------- - - //---------------------------------------------------------- -#if 0 - /** - * Function writeError - * returns an error message wxString containing the filename being - * currently written. - */ - wxString writeError() const; - - /// encapsulate the BIU formatting tricks in one place. - int biuSprintf( char* buf, BIU aValue ) const; - - /** - * Function fmtBIU - * converts a BIU to engineering units by scaling and formatting to ASCII. - * This function is the complement of biuParse(). One has to know what the - * other is doing. - */ - std::string fmtBIU( BIU aValue ) const; - - std::string fmtBIUPair( BIU first, BIU second ) const; - - std::string fmtBIUPoint( const wxPoint& aPoint ) const - { - return fmtBIUPair( aPoint.x, aPoint.y ); - } - - std::string fmtBIUSize( const wxSize& aSize ) const - { - return fmtBIUPair( aSize.x, aSize.y ); - } - - /** - * Function fmtDEG - * formats an angle in a way particular to a board file format. This function - * is the opposite or complement of degParse(). One has to know what the - * other is doing. - */ - std::string fmtDEG( double aAngle ) const; - - void saveGENERAL( const BOARD* aBoard ) const; - void saveSHEET( const BOARD* aBoard ) const; - void saveSETUP( const BOARD* aBoard ) const; - void saveBOARD_ITEMS( const BOARD* aBoard ) const; - - void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const; - void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const; - void savePAD( const D_PAD* aPad ) const; - - void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const; - void saveNETCLASSES( const NETCLASSES* aNetClasses ) const; - void saveNETCLASS( const boost::shared_ptr aNetclass ) const; - - void savePCB_TEXT( const TEXTE_PCB* aText ) const; - void savePCB_TARGET( const PCB_TARGET* aTarget ) const; - void savePCB_LINE( const DRAWSEGMENT* aStroke ) const; - void saveDIMENSION( const DIMENSION* aDimension ) const; - void saveTRACK( const TRACK* aTrack ) const; - void saveBOARD( const BOARD* aBoard ) const; - - /** - * Function saveZONE_CONTAINER - * saves the new polygon zones. - */ - void saveZONE_CONTAINER( const ZONE_CONTAINER* aZone ) const; - - //--------------------------------------------------------- -#endif - /// we only cache one footprint library for now, this determines which one. void cacheLib( const wxString& aLibraryPath ); };