~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to cvpcb/readwrite_dlgs.cpp

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    COMPONENT* component;
50
50
    bool       hasFootprint = false;
51
51
    int        componentIndex;
52
 
    wxString   description;
53
52
 
54
53
    if( m_netlist.IsEmpty() )
55
54
        return;
56
55
 
57
56
    // If no component is selected, select the first one
58
 
    if( m_ListCmp->GetFirstSelected() < 0 )
 
57
    if( m_compListBox->GetFirstSelected() < 0 )
59
58
    {
60
59
        componentIndex = 0;
61
 
        m_ListCmp->SetSelection( componentIndex, true );
 
60
        m_compListBox->SetSelection( componentIndex, true );
62
61
    }
63
62
 
64
63
    // iterate over the selection
65
 
    while( m_ListCmp->GetFirstSelected() != -1 )
 
64
    while( m_compListBox->GetFirstSelected() != -1 )
66
65
    {
67
66
        // Get the component for the current iteration
68
 
        componentIndex = m_ListCmp->GetFirstSelected();
 
67
        componentIndex = m_compListBox->GetFirstSelected();
69
68
        component = m_netlist.GetComponent( componentIndex );
70
69
 
71
70
        if( component == NULL )
86
85
        component->SetFPID( fpid );
87
86
 
88
87
        // create the new component description
89
 
        description.Printf( CMP_FORMAT, componentIndex + 1,
 
88
        wxString   description = wxString::Format( CMP_FORMAT, componentIndex + 1,
90
89
                            GetChars( component->GetReference() ),
91
90
                            GetChars( component->GetValue() ),
92
91
                            GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
101
100
        }
102
101
 
103
102
        // Set the new description and deselect the processed component
104
 
        m_ListCmp->SetString( componentIndex, description );
105
 
        m_ListCmp->SetSelection( componentIndex, false );
 
103
        m_compListBox->SetString( componentIndex, description );
 
104
        m_compListBox->SetSelection( componentIndex, false );
106
105
    }
107
106
 
108
107
    // Mark this "session" as modified
109
108
    m_modified = true;
110
109
 
111
110
    // select the next component, if there is one
112
 
    if( componentIndex < (m_ListCmp->GetCount() - 1) )
 
111
    if( componentIndex < (m_compListBox->GetCount() - 1) )
113
112
        componentIndex++;
114
113
 
115
 
    m_ListCmp->SetSelection( componentIndex, true );
 
114
    m_compListBox->SetSelection( componentIndex, true );
116
115
 
117
116
    // update the statusbar
118
117
    DisplayStatus();
119
118
}
120
119
 
121
120
 
122
 
#if 0
123
 
 
124
 
    /*
125
 
 
126
 
    This code block was based on two major assumptions that are no longer true:
127
 
    1) Footprint library basenames would remain the same.
128
 
    (But no, basenames have been renamed in the github repo.)
129
 
    2) *.mod files would still be around and merely reside in the FP_LIB_TABLE.
130
 
    (But no, they have been converted to *.pretty.)
131
 
 
132
 
    There is a newer replacement code block in the #else region.
133
 
 
134
 
    */
135
 
 
136
 
/**
137
 
 * Function missingLegacyLibs
138
 
 * tests the list of \a aLibNames by URI to determine if any of them are missing from
139
 
 * the #FP_LIB_TABLE.
140
 
 *
141
 
 * @note The missing legacy footprint library test is performed by using old library
142
 
 *       file path lookup method.  If the library is found, it is compared against all
143
 
 *       of the URIs in the table rather than the nickname.  This was done because the
144
 
 *       user could change the nicknames from the default table.  Using the full path
145
 
 *       is more reliable.
146
 
 *
147
 
 * @param aLibNames is the list of legacy library names.
148
 
 * @param aErrorMsg is a pointer to a wxString object to store the URIs of any missing
149
 
 *                  legacy library paths.  Can be NULL.
150
 
 * @return true if there are missing legacy libraries.  Otherwise false.
151
 
 */
152
 
static bool missingLegacyLibs( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack,
153
 
        const wxArrayString& aLibNames, wxString* aErrorMsg )
154
 
{
155
 
    bool missing = false;
156
 
 
157
 
    for( unsigned i = 0;  i < aLibNames.GetCount();  i++ )
158
 
    {
159
 
        wxFileName  fn( wxEmptyString, aLibNames[i], LegacyFootprintLibPathExtension );
160
 
 
161
 
        wxString    legacyLibPath = aSStack.FindValidPath( fn.GetFullPath() );
162
 
 
163
 
        /*
164
 
        if( legacyLibPath.IsEmpty() )
165
 
            continue;
166
 
        */
167
 
 
168
 
        if( !aTbl->FindRowByURI( legacyLibPath ) )
169
 
        {
170
 
            missing = true;
171
 
 
172
 
            if( aErrorMsg )
173
 
            {
174
 
                *aErrorMsg += wxChar( '"' );
175
 
 
176
 
                if( !legacyLibPath )
177
 
                    *aErrorMsg += !legacyLibPath ? aLibNames[i] : legacyLibPath;
178
 
 
179
 
                *aErrorMsg += wxT( "\"\n" );
180
 
            }
181
 
        }
182
 
    }
183
 
 
184
 
    return missing;
185
 
}
186
 
 
187
 
 
188
 
/**
189
 
 * Function convertFromLegacy
190
 
 * converts the footprint names in \a aNetList from the legacy format to the #FPID format.
191
 
 *
192
 
 * @param aNetList is the #NETLIST object to convert.
193
 
 * @param aLibNames is the list of legacy footprint library names from the currently loaded
194
 
 *                  project.
195
 
 * @param aReporter is the #REPORTER object to dump messages into.
196
 
 * @return true if all footprint names were successfully converted to a valid FPID.
197
 
 */
198
 
static bool convertFromLegacy( FP_LIB_TABLE* aTbl, SEARCH_STACK& aSStack, NETLIST& aNetList,
199
 
        const wxArrayString& aLibNames, REPORTER* aReporter = NULL ) throw( IO_ERROR )
200
 
{
201
 
    wxString   msg;
202
 
    FPID       lastFPID;
203
 
    COMPONENT* component;
204
 
    MODULE*    module = 0;
205
 
    bool       retv = true;
206
 
 
207
 
    if( aNetList.IsEmpty() )
208
 
        return true;
209
 
 
210
 
    aNetList.SortByFPID();
211
 
 
212
 
    wxString   libPath;
213
 
 
214
 
    PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
215
 
 
216
 
    for( unsigned ii = 0; ii < aNetList.GetCount(); ii++ )
217
 
    {
218
 
        component = aNetList.GetComponent( ii );
219
 
 
220
 
        // The footprint hasn't been assigned yet so ignore it.
221
 
        if( component->GetFPID().empty() )
222
 
            continue;
223
 
 
224
 
        if( component->GetFPID() != lastFPID )
225
 
        {
226
 
            module = NULL;
227
 
 
228
 
            for( unsigned ii = 0; ii < aLibNames.GetCount(); ii++ )
229
 
            {
230
 
                wxFileName fn( wxEmptyString, aLibNames[ii], LegacyFootprintLibPathExtension );
231
 
 
232
 
                libPath = aSStack.FindValidPath( fn.GetFullPath() );
233
 
 
234
 
                if( !libPath )
235
 
                {
236
 
                    if( aReporter )
237
 
                    {
238
 
                        msg.Printf( _( "Cannot find footprint library file '%s' in any of the "
239
 
                                       "KiCad legacy library search paths.\n" ),
240
 
                                    GetChars( fn.GetFullPath() ) );
241
 
                        aReporter->Report( msg );
242
 
                    }
243
 
 
244
 
                    retv = false;
245
 
                    continue;
246
 
                }
247
 
 
248
 
                module = pi->FootprintLoad( libPath, component->GetFPID().GetFootprintName() );
249
 
 
250
 
                if( module )
251
 
                {
252
 
                    lastFPID = component->GetFPID();
253
 
                    break;
254
 
                }
255
 
            }
256
 
        }
257
 
 
258
 
        if( !module )
259
 
        {
260
 
            if( aReporter )
261
 
            {
262
 
                msg.Printf( _( "Component '%s' footprint '%s' was not found in any legacy "
263
 
                               "library.\n" ),
264
 
                            GetChars( component->GetReference() ),
265
 
                            GetChars( component->GetFPID().Format() ) );
266
 
                aReporter->Report( msg );
267
 
            }
268
 
 
269
 
            // Clear the footprint assignment since the old library lookup method is no
270
 
            // longer valid.
271
 
            FPID emptyFPID;
272
 
 
273
 
            component->SetFPID( emptyFPID );
274
 
            retv = false;
275
 
            continue;
276
 
        }
277
 
        else
278
 
        {
279
 
            wxString    libNickname;
280
 
 
281
 
            const FP_LIB_TABLE::ROW* row;
282
 
 
283
 
            if( ( row = aTbl->FindRowByURI( libPath ) ) != NULL )
284
 
                libNickname = row->GetNickName();
285
 
 
286
 
            if( libNickname.IsEmpty() )
287
 
            {
288
 
                if( aReporter )
289
 
                {
290
 
                    msg.Printf( _( "Component '%s' with footprint '%s' and legacy library path '%s' "
291
 
                                   "was not found in the footprint library table.\n" ),
292
 
                                GetChars( component->GetReference() ),
293
 
                                GetChars( component->GetFPID().Format() ),
294
 
                                GetChars( libPath )
295
 
                                );
296
 
                    aReporter->Report( msg );
297
 
                }
298
 
 
299
 
                retv = false;
300
 
            }
301
 
            else
302
 
            {
303
 
                FPID newFPID = lastFPID;
304
 
                newFPID.SetLibNickname( libNickname );
305
 
 
306
 
                if( !newFPID.IsValid() )
307
 
                {
308
 
                    if( aReporter )
309
 
                    {
310
 
                        msg.Printf( _( "Component '%s' FPID '%s' is not valid.\n" ),
311
 
                                    GetChars( component->GetReference() ),
312
 
                                    GetChars( newFPID.Format() ) );
313
 
                        aReporter->Report( msg );
314
 
                    }
315
 
 
316
 
                    retv = false;
317
 
                }
318
 
                else
319
 
                {
320
 
                    // The footprint name should already be set.
321
 
                    component->SetFPID( newFPID );
322
 
                }
323
 
            }
324
 
        }
325
 
    }
326
 
 
327
 
    return retv;
328
 
}
329
 
 
330
 
 
331
 
bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
332
 
{
333
 
    COMPONENT* component;
334
 
    wxString   msg;
335
 
    bool       isLegacy = true;
336
 
 
337
 
    ReadSchematicNetlist();
338
 
 
339
 
    if( m_ListCmp == NULL )
340
 
        return false;
341
 
 
342
 
    LoadProjectFile( m_NetlistFileName.GetFullPath() );
343
 
    LoadFootprintFiles();
344
 
    BuildFOOTPRINTS_LISTBOX();
345
 
    BuildLIBRARY_LISTBOX();
346
 
 
347
 
    m_ListCmp->Clear();
348
 
    m_undefinedComponentCnt = 0;
349
 
 
350
 
    if( m_netlist.AnyFootprintsLinked() )
351
 
    {
352
 
        for( unsigned i = 0;  i < m_netlist.GetCount();  i++ )
353
 
        {
354
 
            component = m_netlist.GetComponent( i );
355
 
 
356
 
            if( component->GetFPID().empty() )
357
 
                continue;
358
 
 
359
 
            if( isLegacy )
360
 
            {
361
 
                if( !component->GetFPID().IsLegacy() )
362
 
                    isLegacy = false;
363
 
            }
364
 
        }
365
 
    }
366
 
    else
367
 
    {
368
 
        isLegacy = false;  // None of the components have footprints assigned.
369
 
    }
370
 
 
371
 
    wxString missingLibs;
372
 
 
373
 
    // Check if footprint links were generated before the footprint library table was implemented.
374
 
    if( isLegacy )
375
 
    {
376
 
        if( missingLegacyLibs( FootprintLibs(), Prj().PcbSearchS(), m_ModuleLibNames, &missingLibs ) )
377
 
        {
378
 
            msg = wxT( "The following legacy libraries are defined in the project file "
379
 
                       "but were not found in the footprint library table:\n\n" ) + missingLibs;
380
 
            msg += wxT( "\nDo you want to update the footprint library table before "
381
 
                        "attempting to update the assigned footprints?" );
382
 
 
383
 
            if( IsOK( this, msg ) )
384
 
            {
385
 
                wxCommandEvent cmd;
386
 
 
387
 
                OnEditFootprintLibraryTable( cmd );
388
 
            }
389
 
        }
390
 
 
391
 
        msg = wxT( "Some or all of the assigned footprints contain legacy entries.  Would you "
392
 
                   "like CvPcb to attempt to convert them to the new footprint library table "
393
 
                   "format?" );
394
 
 
395
 
        if( IsOK( this, msg ) )
396
 
        {
397
 
            msg.Clear();
398
 
            WX_STRING_REPORTER reporter( &msg );
399
 
 
400
 
            SEARCH_STACK&   search = Prj().SchSearchS();
401
 
 
402
 
            if( !convertFromLegacy( FootprintLibs(), search, m_netlist, m_ModuleLibNames, &reporter ) )
403
 
            {
404
 
                HTML_MESSAGE_BOX dlg( this, wxEmptyString );
405
 
 
406
 
                dlg.MessageSet( wxT( "The following errors occurred attempting to convert the "
407
 
                                     "footprint assignments:\n\n" ) );
408
 
                dlg.ListSet( msg );
409
 
                dlg.MessageSet( wxT( "\nYou will need to reassign them manually if you want them "
410
 
                                     "to be updated correctly the next time you import the "
411
 
                                     "netlist in Pcbnew." ) );
412
 
                dlg.ShowModal();
413
 
            }
414
 
 
415
 
            m_modified = true;
416
 
        }
417
 
        else
418
 
        {
419
 
            // Clear the legacy footprint assignments.
420
 
            for( unsigned i = 0;  i < m_netlist.GetCount();  i++ )
421
 
            {
422
 
                FPID emptyFPID;
423
 
                component = m_netlist.GetComponent( i );
424
 
                component->SetFPID( emptyFPID );
425
 
                m_modified = true;
426
 
            }
427
 
        }
428
 
    }
429
 
 
430
 
    for( unsigned i = 0;  i < m_netlist.GetCount();  i++ )
431
 
    {
432
 
        component = m_netlist.GetComponent( i );
433
 
 
434
 
        msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
435
 
                    GetChars( component->GetReference() ),
436
 
                    GetChars( component->GetValue() ),
437
 
                    GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
438
 
 
439
 
        m_ListCmp->AppendLine( msg );
440
 
 
441
 
        if( component->GetFPID().empty() )
442
 
        {
443
 
            m_undefinedComponentCnt += 1;
444
 
            continue;
445
 
        }
446
 
    }
447
 
 
448
 
    if( !m_netlist.IsEmpty() )
449
 
        m_ListCmp->SetSelection( 0, true );
450
 
 
451
 
    DisplayStatus();
452
 
 
453
 
    UpdateTitle();
454
 
 
455
 
    UpdateFileHistory( m_NetlistFileName.GetFullPath() );
456
 
 
457
 
    return true;
458
 
}
459
 
 
460
 
#else   // new strategy
461
 
 
462
121
/// Return true if the resultant FPID has a certain nickname.  The guess
463
122
/// is only made if this footprint resides in only one library.
464
123
/// @return int - 0 on success, 1 on not found, 2 on ambiguous i.e. multiple matches
503
162
{
504
163
    wxString        msg;
505
164
    bool            hasMissingNicks = false;
506
 
    FP_LIB_TABLE*   tbl = FootprintLibs();
507
165
 
508
166
    ReadSchematicNetlist();
509
167
 
510
 
    if( m_ListCmp == NULL )
 
168
    if( m_compListBox == NULL )
511
169
        return false;
512
170
 
513
171
    LoadProjectFile( m_NetlistFileName.GetFullPath() );
514
172
    LoadFootprintFiles();
 
173
 
515
174
    BuildFOOTPRINTS_LISTBOX();
516
175
    BuildLIBRARY_LISTBOX();
517
176
 
518
 
    m_ListCmp->Clear();
 
177
    m_compListBox->Clear();
519
178
    m_undefinedComponentCnt = 0;
520
179
 
521
180
    if( m_netlist.AnyFootprintsLinked() )
554
213
 
555
214
                    if( component->GetFPID().IsLegacy() )
556
215
                    {
 
216
                        // get this first here, it's possibly obsoleted if we get it too soon.
 
217
                        FP_LIB_TABLE*   tbl = Prj().PcbFootprintLibs();
 
218
 
557
219
                        int guess = guessNickname( tbl, (FPID*) &component->GetFPID() );
558
220
 
559
221
                        switch( guess )
632
294
    {
633
295
        COMPONENT* component = m_netlist.GetComponent( i );
634
296
 
635
 
        msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
 
297
        msg.Printf( CMP_FORMAT, m_compListBox->GetCount() + 1,
636
298
                    GetChars( component->GetReference() ),
637
299
                    GetChars( component->GetValue() ),
638
300
                    GetChars( FROM_UTF8( component->GetFPID().Format().c_str() ) ) );
639
301
 
640
 
        m_ListCmp->AppendLine( msg );
 
302
        m_compListBox->AppendLine( msg );
641
303
 
642
304
        if( component->GetFPID().empty() )
643
305
        {
647
309
    }
648
310
 
649
311
    if( !m_netlist.IsEmpty() )
650
 
        m_ListCmp->SetSelection( 0, true );
 
312
        m_compListBox->SetSelection( 0, true );
651
313
 
652
314
    DisplayStatus();
653
315
 
659
321
}
660
322
 
661
323
 
662
 
#endif
663
 
 
664
 
 
665
324
int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
666
325
{
667
326
    wxFileName fn;
685
344
            fn.SetExt( ComponentFileExtension );
686
345
 
687
346
        // Save the project specific footprint library table.
688
 
        if( !FootprintLibs()->IsEmpty( false ) )
 
347
        if( !Prj().PcbFootprintLibs()->IsEmpty( false ) )
689
348
        {
690
349
            wxString fp_lib_tbl = Prj().FootprintLibTblName();
691
350
 
695
354
            {
696
355
                try
697
356
                {
698
 
                    FootprintLibs()->Save( fp_lib_tbl );
 
357
                    Prj().PcbFootprintLibs()->Save( fp_lib_tbl );
699
358
                }
700
359
                catch( const IO_ERROR& ioe )
701
360
                {
720
379
        return 0;
721
380
    }
722
381
 
723
 
    wxString msg;
724
 
    msg.Printf( _("File %s saved"), GetChars( fn.GetFullPath() ) );
 
382
    wxString msg = wxString::Format( _("File %s saved"), GetChars( fn.GetFullPath() ) );
725
383
    SetStatusText( msg );
726
384
    return 1;
727
385
}