~kaspar-emanuel/kicad/python-unittest

« back to all changes in this revision

Viewing changes to pcbnew/kicad_plugin.cpp

  • Committer: kaspar
  • Date: 2013-08-15 20:11:34 UTC
  • mfrom: (4242.1.44 kicad)
  • Revision ID: kaspar.emanuel@gmail.com-20130815201134-77ig0ylk3qfohjsb
mergingĀ lp:kicad

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <macros.h>
31
31
#include <3d_struct.h>
32
32
#include <wildcards_and_files_ext.h>
 
33
#include <base_units.h>
33
34
 
34
35
#include <class_board.h>
35
36
#include <class_module.h>
62
63
 */
63
64
static const wxString traceFootprintLibrary( wxT( "KicadFootprintLib" ) );
64
65
 
65
 
// Helper function to print a float number without using scientific notation
66
 
// and no trailing 0
67
 
// We want to avoid scientific notation in S-expr files (not easy to read)
68
 
// for floating numbers.
69
 
// So we cannot always just use the %g or the %f format to print a fp number
70
 
// this helper function uses the %f format when needed, or %g when %f is
71
 
// not well working and then removes trailing 0
72
 
 
73
 
std::string double2str( double aValue )
74
 
{
75
 
    char    buf[50];
76
 
    int     len;
77
 
 
78
 
    if( aValue != 0.0 && fabs( aValue ) <= 0.0001 )
79
 
    {
80
 
        // For these small values, %f works fine,
81
 
        // and %g gives an exponent
82
 
        len = sprintf( buf,  "%.16f", aValue );
83
 
 
84
 
        while( --len > 0 && buf[len] == '0' )
85
 
            buf[len] = '\0';
86
 
 
87
 
        if( buf[len] == '.' )
88
 
            buf[len] = '\0';
89
 
        else
90
 
            ++len;
91
 
    }
92
 
    else
93
 
    {
94
 
        // For these values, %g works fine, and sometimes %f
95
 
        // gives a bad value (try aValue = 1.222222222222, with %.16f format!)
96
 
        len = sprintf( buf, "%.16g", aValue );
97
 
    }
98
 
 
99
 
    return std::string( buf, len );;
100
 
}
101
 
 
102
66
 
103
67
/**
104
68
 * Class FP_CACHE_ITEM
156
120
public:
157
121
    FP_CACHE( PCB_IO* aOwner, const wxString& aLibraryPath );
158
122
 
159
 
    wxString GetPath() const { return m_lib_path.GetPath(); }
160
 
    wxDateTime GetLastModificationTime() const { return m_mod_time; }
161
 
    bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
 
123
    wxString    GetPath() const { return m_lib_path.GetPath(); }
 
124
    wxDateTime  GetLastModificationTime() const { return m_mod_time; }
 
125
    bool        IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
162
126
    MODULE_MAP& GetModules() { return m_modules; }
163
127
 
164
128
    // Most all functions in this class throw IO_ERROR exceptions.  There are no
217
181
        // Allow file output stream to go out of scope to close the file stream before
218
182
        // renaming the file.
219
183
        {
220
 
            wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ),
221
 
                        GetChars( tempFileName ) );
 
184
            // wxLogTrace( traceFootprintLibrary, wxT( "Creating temporary library file %s" ), GetChars( tempFileName ) );
222
185
 
223
186
            FILE_OUTPUTFORMATTER formatter( tempFileName );
224
187
 
254
217
    wxString fpFileName;
255
218
    wxString wildcard = wxT( "*." ) + KiCadFootprintFileExtension;
256
219
 
257
 
    if( !dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) )
258
 
        return;
259
 
 
260
 
    do
 
220
    if( dir.GetFirst( &fpFileName, wildcard, wxDIR_FILES ) )
261
221
    {
262
 
        // reader now owns fp, will close on exception or return
263
 
        FILE_LINE_READER    reader( fpFileName );
264
 
 
265
 
        m_owner->m_parser->SetLineReader( &reader );
266
 
 
267
 
        std::string name = TO_UTF8( fpFileName );
268
 
 
269
 
        m_modules.insert( name, new FP_CACHE_ITEM( (MODULE*) m_owner->m_parser->Parse(), fpFileName ) );
270
 
 
271
 
    } while( dir.GetNext( &fpFileName ) );
272
 
 
273
 
    // Remember the file modification time of library file when the
274
 
    // cache snapshot was made, so that in a networked environment we will
275
 
    // reload the cache as needed.
276
 
    m_mod_time = GetLibModificationTime();
 
222
        do
 
223
        {
 
224
            // prepend the libpath into fullPath
 
225
            wxFileName fullPath( m_lib_path.GetPath(), fpFileName );
 
226
 
 
227
            FILE_LINE_READER    reader( fullPath.GetFullPath() );
 
228
 
 
229
            m_owner->m_parser->SetLineReader( &reader );
 
230
 
 
231
            std::string name = TO_UTF8( fpFileName );
 
232
 
 
233
            m_modules.insert( name, new FP_CACHE_ITEM( (MODULE*) m_owner->m_parser->Parse(), fpFileName ) );
 
234
 
 
235
        } while( dir.GetNext( &fpFileName ) );
 
236
 
 
237
        // Remember the file modification time of library file when the
 
238
        // cache snapshot was made, so that in a networked environment we will
 
239
        // reload the cache as needed.
 
240
        m_mod_time = GetLibModificationTime();
 
241
    }
277
242
}
278
243
 
279
244
 
589
554
 
590
555
    if( aBoard->GetDesignSettings().m_SolderPasteMarginRatio != 0 )
591
556
        m_out->Print( aNestLevel+1, "(pad_to_paste_clearance_ratio %s)\n",
592
 
                      double2str( aBoard->GetDesignSettings().m_SolderPasteMarginRatio ).c_str() );
 
557
                      Double2Str( aBoard->GetDesignSettings().m_SolderPasteMarginRatio ).c_str() );
593
558
 
594
559
    m_out->Print( aNestLevel+1, "(aux_axis_origin %s %s)\n",
595
 
                  FMTIU( aBoard->GetOriginAxisPosition().x ).c_str(),
596
 
                  FMTIU( aBoard->GetOriginAxisPosition().y ).c_str() );
 
560
                  FMTIU( aBoard->GetAuxOrigin().x ).c_str(),
 
561
                  FMTIU( aBoard->GetAuxOrigin().y ).c_str() );
 
562
 
 
563
    if( aBoard->GetGridOrigin().x || aBoard->GetGridOrigin().y )
 
564
        m_out->Print( aNestLevel+1, "(grid_origin %s %s)\n",
 
565
                      FMTIU( aBoard->GetGridOrigin().x ).c_str(),
 
566
                      FMTIU( aBoard->GetGridOrigin().y ).c_str() );
597
567
 
598
568
    m_out->Print( aNestLevel+1, "(visible_elements %X)\n",
599
569
                  aBoard->GetDesignSettings().GetVisibleElements() );
899
869
    m_out->Print( aNestLevel, "(module %s", m_out->Quotew( aModule->GetLibRef() ).c_str() );
900
870
 
901
871
    if( aModule->IsLocked() )
902
 
        m_out->Print( aNestLevel, " locked" );
 
872
        m_out->Print( 0, " locked" );
903
873
 
904
874
    if( aModule->IsPlaced() )
905
 
        m_out->Print( aNestLevel, " placed" );
 
875
        m_out->Print( 0, " placed" );
906
876
 
907
877
    formatLayer( aModule );
908
878
 
949
919
 
950
920
    if( aModule->GetLocalSolderPasteMarginRatio() != 0 )
951
921
        m_out->Print( aNestLevel+1, "(solder_paste_ratio %s)\n",
952
 
                      double2str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
 
922
                      Double2Str( aModule->GetLocalSolderPasteMarginRatio() ).c_str() );
953
923
 
954
924
    if( aModule->GetLocalClearance() != 0 )
955
925
        m_out->Print( aNestLevel+1, "(clearance %s)\n",
1000
970
                          m_out->Quotew( t3D->m_Shape3DName ).c_str() );
1001
971
 
1002
972
            m_out->Print( aNestLevel+2, "(at (xyz %s %s %s))\n",
1003
 
                          double2str( t3D->m_MatPosition.x ).c_str(),
1004
 
                          double2str( t3D->m_MatPosition.y ).c_str(),
1005
 
                          double2str( t3D->m_MatPosition.z ).c_str() );
 
973
                          Double2Str( t3D->m_MatPosition.x ).c_str(),
 
974
                          Double2Str( t3D->m_MatPosition.y ).c_str(),
 
975
                          Double2Str( t3D->m_MatPosition.z ).c_str() );
1006
976
 
1007
977
            m_out->Print( aNestLevel+2, "(scale (xyz %s %s %s))\n",
1008
 
                          double2str( t3D->m_MatScale.x ).c_str(),
1009
 
                          double2str( t3D->m_MatScale.y ).c_str(),
1010
 
                          double2str( t3D->m_MatScale.z ).c_str() );
 
978
                          Double2Str( t3D->m_MatScale.x ).c_str(),
 
979
                          Double2Str( t3D->m_MatScale.y ).c_str(),
 
980
                          Double2Str( t3D->m_MatScale.z ).c_str() );
1011
981
 
1012
982
            m_out->Print( aNestLevel+2, "(rotate (xyz %s %s %s))\n",
1013
 
                          double2str( t3D->m_MatRotation.x ).c_str(),
1014
 
                          double2str( t3D->m_MatRotation.y ).c_str(),
1015
 
                          double2str( t3D->m_MatRotation.z ).c_str() );
 
983
                          Double2Str( t3D->m_MatRotation.x ).c_str(),
 
984
                          Double2Str( t3D->m_MatRotation.y ).c_str(),
 
985
                          Double2Str( t3D->m_MatRotation.z ).c_str() );
1016
986
 
1017
987
            m_out->Print( aNestLevel+1, ")\n" );
1018
988
        }
1186
1156
 
1187
1157
    if( aPad->GetLocalSolderPasteMarginRatio() != 0 )
1188
1158
        m_out->Print( aNestLevel+1, "(solder_paste_margin_ratio %s)\n",
1189
 
                      double2str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
 
1159
                      Double2Str( aPad->GetLocalSolderPasteMarginRatio() ).c_str() );
1190
1160
 
1191
1161
    if( aPad->GetLocalClearance() != 0 )
1192
1162
        m_out->Print( aNestLevel+1, "(clearance %s)\n",