netlist_control.cpp 25.2 KB
Newer Older
1 2 3
/**********************************/
/* Dialog box for netlist outputs */
/**********************************/
4

5 6 7 8 9 10 11 12 13 14
/* Functions relatives to the dialog creating the netlist for pcbnew.
 * The dialo is a notebook with 4 fixed netlist format:
 * PCBNEW ORCADPCB2 CADSTAR and SPICE
 * and up to CUSTOMPANEL_COUNTMAX (see netlist.h) user programmable format
 * calling an external converter with convert an intermediate format to the
 * user specific format.
 * these external converters are refered there as plugins,
 * but there are not really plugins, there are only external binaries
 */

15 16 17 18 19 20 21
#include "fctsys.h"

#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"

22
#include "netlist.h"
23 24 25
#include "protos.h"

// ID for configuration:
26 27
#define CUSTOM_NETLIST_TITLE   wxT( "CustomNetlistTitle" )
#define CUSTOM_NETLIST_COMMAND wxT( "CustomNetlistCommand" )
28

29
/* Loacl variable */
30

31
/* Event id for notebook page buttons: */
32 33
enum id_netlist {
    ID_CREATE_NETLIST = 1550,
34 35 36
    ID_CURRENT_FORMAT_IS_DEFAULT,
    ID_RUN_SIMULATOR,
    ID_SETUP_PLUGIN,
37 38
    ID_VALIDATE_PLUGIN,
    ID_DELETE_PLUGIN,
39
    ID_NETLIST_NOTEBOOK
40 41
};

42
/* panel (notebook page) identifiers */
43
enum panel_netlist_index {
44 45 46 47 48 49
    PANELPCBNEW = 0,    /* Handle Netlist format Pcbnew */
    PANELORCADPCB2,     /* Handle Netlist format OracdPcb2 */
    PANELCADSTAR,       /* Handle Netlist format CadStar */
    PANELSPICE,         /* Handle Netlist format Pspice */
    PANELCUSTOMBASE     /* First auxiliary panel (custom netlists).
                         * others use PANELCUSTOMBASE+1, PANELCUSTOMBASE+2.. */
50 51
};

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
/* Values returned when the netlist dialog is demiss */
enum gen_netlist_diag {
    NET_OK,
    NET_ABORT,
    NET_PLUGIN_CHANGE
};


/****************************************************/
wxString ReturnUserNetlistTypeName( bool first_item )
/****************************************************/

/** Function ReturnUserNetlistTypeName
 * to retrieve user netlist type names
 * @param first = true: return first name of the list, false = return next
 * @return a wxString : name of the type netlist or empty string
 * this function must be called first with "first_item" = true
 * and after with "first_item" = false to get all the other existing netlist names
 */
{
    static int index;
    wxString   name, msg;

    if( first_item )
        index = 0;
    else
        index++;

    msg = CUSTOM_NETLIST_TITLE;
    msg << index + 1;

    if( g_EDA_Appl->m_EDA_Config )
        name = g_EDA_Appl->m_EDA_Config->Read( msg );

    return name;
}


/************************/
/* Class declarations : */
/************************/
93

94
/* wxPanels for creating the NoteBook pages for each netlist format:
95
 */
96
class EDA_NoteBookPage : public wxPanel
97 98
{
public:
99 100 101 102 103 104 105 106 107 108 109 110 111
    int               m_IdNetType;
    wxCheckBox*       m_IsCurrentFormat;
    WinEDA_EnterText* m_CommandStringCtrl;
    WinEDA_EnterText* m_TitleStringCtrl;
    wxButton*         m_ButtonCancel;
    wxBoxSizer*       m_LeftBoxSizer;
    wxBoxSizer*       m_RightBoxSizer;
    wxBoxSizer*       m_RightOptionsBoxSizer;
    wxBoxSizer*       m_LowBoxSizer;

    EDA_NoteBookPage( wxNotebook* parent, const wxString& title,
                      int id_NetType, int idCheckBox, int idCreateFile );
    ~EDA_NoteBookPage() { };
112 113 114
};


115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/* Dialog frame for creating netlists */
class WinEDA_NetlistFrame : public wxDialog
{
public:
    WinEDA_SchematicFrame* m_Parent;
    wxNotebook*            m_NoteBook;
    EDA_NoteBookPage*      m_PanelNetType[4 + CUSTOMPANEL_COUNTMAX];

    wxRadioBox*            m_UseNetNamesInNetlist;

public:

    // Constructor and destructor
    WinEDA_NetlistFrame( WinEDA_SchematicFrame* parent, wxPoint& pos );
    ~WinEDA_NetlistFrame() { };

private:
    void    InstallCustomPages();
    void    InstallPageSpice();
    void    GenNetlist( wxCommandEvent& event );
    void    RunSimulator( wxCommandEvent& event );
    void    NetlistUpdateOpt();
    void    OnCancelClick( wxCommandEvent& event );
    void    SelectNetlistType( wxCommandEvent& event );
    void    SetupPluginData( wxCommandEvent& event );
    void    DeletePluginPanel( wxCommandEvent& event );
    void    ValidatePluginPanel( wxCommandEvent& event );

    void WriteCurrentNetlistSetup( void );

    DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE( WinEDA_NetlistFrame, wxDialog )
EVT_BUTTON( wxID_CANCEL, WinEDA_NetlistFrame::OnCancelClick )
EVT_BUTTON( ID_CREATE_NETLIST, WinEDA_NetlistFrame::GenNetlist )
EVT_BUTTON( ID_SETUP_PLUGIN, WinEDA_NetlistFrame::SetupPluginData )
EVT_BUTTON( ID_DELETE_PLUGIN, WinEDA_NetlistFrame::DeletePluginPanel )
EVT_BUTTON( ID_VALIDATE_PLUGIN, WinEDA_NetlistFrame::ValidatePluginPanel )
EVT_CHECKBOX( ID_CURRENT_FORMAT_IS_DEFAULT, WinEDA_NetlistFrame::SelectNetlistType )
EVT_BUTTON( ID_RUN_SIMULATOR, WinEDA_NetlistFrame::RunSimulator )
END_EVENT_TABLE()


/*********************************************************************/
void InstallNetlistFrame( WinEDA_SchematicFrame* parent, wxPoint& pos )
/*********************************************************************/

/* Installator for the netlist generation dialog box
 */
{
    int ii;
	
	if ( g_NetFormat <  NET_TYPE_PCBNEW )
		g_NetFormat = NET_TYPE_PCBNEW;

    do
    {
        WinEDA_NetlistFrame* frame = new WinEDA_NetlistFrame( parent, pos );

        ii = frame->ShowModal();
        frame->Destroy();
    } while( ii == NET_PLUGIN_CHANGE );

    // If a plugin is removed or added, rebuild and reopen the new dialog
}


/*******************************/
/* Functions for these classes */
/*******************************/


188
/*****************************************************************************/
189 190 191
EDA_NoteBookPage::EDA_NoteBookPage( wxNotebook* parent, const wxString& title,
                                    int id_NetType, int idCheckBox, int idCreateFile ) :
    wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxBORDER_SUNKEN )
192
/*****************************************************************************/
193 194

/** Contructor to create a setup page for one netlist format.
195
 * Used in Netlist format Dialog box creation
196 197 198 199 200
 * @param parent = wxNotebook * parent
 * @param title = title (name) of the notebook page
 * @param id_NetType = netlist type id
 * @param idCheckBox = event ID attached to the "format is default" check box
 * @param idCreateFile = event ID attached to the "create netlist" button
201
 */
202
{
203
    SetFont( *g_DialogFont );
204 205
    m_IdNetType = id_NetType;
    m_CommandStringCtrl = NULL;
206 207
    m_TitleStringCtrl   = NULL;
    m_IsCurrentFormat   = NULL;
208 209
    m_ButtonCancel = NULL;

210
    parent->AddPage( this, title, g_NetFormat == m_IdNetType );
211

212 213 214 215 216 217
    wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
    SetSizer( MainBoxSizer );
    wxBoxSizer* UpperBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    m_LowBoxSizer = new wxBoxSizer( wxVERTICAL );
    MainBoxSizer->Add( UpperBoxSizer, 0, wxGROW | wxALL, 5 );
    MainBoxSizer->Add( m_LowBoxSizer, 0, wxGROW | wxALL, 5 );
218

219 220 221 222 223 224
    m_LeftBoxSizer  = new wxBoxSizer( wxVERTICAL );
    m_RightBoxSizer = new wxBoxSizer( wxVERTICAL );
    m_RightOptionsBoxSizer = new wxBoxSizer( wxVERTICAL );
    UpperBoxSizer->Add( m_LeftBoxSizer, 0, wxGROW | wxALL, 5 );
    UpperBoxSizer->Add( m_RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
    UpperBoxSizer->Add( m_RightOptionsBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
225 226 227

    if( idCheckBox )
    {
228 229
        wxStaticText* text = new wxStaticText( this, -1, _( "Options:" ) );
        m_LeftBoxSizer->Add( text, 0, wxGROW | wxALL, 5 );
230

231 232
        m_IsCurrentFormat = new wxCheckBox( this, idCheckBox, _( "Default format" ) );
        m_LeftBoxSizer->Add( m_IsCurrentFormat, 0, wxGROW | wxALL, 5 );
233 234

        if( g_NetFormat == m_IdNetType )
235
            m_IsCurrentFormat->SetValue( TRUE );
236 237
    }

238 239 240
    /* Create the buttons: Create Neltist or browse Plugin and Cancel
     * and a third button for plugins : Remove or Ok button */
    if( idCreateFile )
241
    {
242 243 244
        wxButton* Button;
        if( idCreateFile == ID_SETUP_PLUGIN )  /* This is the "add plugin" panel */
            Button = new wxButton( this, idCreateFile, _( "&Browse Plugin" ) );
245
        else
246 247 248
            Button = new wxButton( this, idCreateFile, _( "&Netlist" ) );
        Button->SetForegroundColour( *wxRED );
        m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
249 250

        m_ButtonCancel =
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
            Button = new wxButton( this, wxID_CANCEL, _( "&Cancel" ) );
        Button->SetForegroundColour( *wxBLUE );
        m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );

        /* Add special buttons to plugin panels:
         * for panel plugins: added the "delete" button
         * for the last panel (add plugin) a Ok button is added
         */
        if( idCreateFile == ID_SETUP_PLUGIN )   /* This is the "add plugin" panel: add Ok button  */
        {
            Button = new wxButton( this, ID_VALIDATE_PLUGIN, _( "&Ok" ) );
            m_RightOptionsBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
        }
        else if( id_NetType >= PANELCUSTOMBASE )    /* This is a plugin panel: add delete button */
        {
            Button = new wxButton( this, ID_DELETE_PLUGIN, _( "&Delete" ) );
            m_RightOptionsBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
        }
269
    }
270 271
}

272

273
/*************************************************************************************/
274 275 276
WinEDA_NetlistFrame::WinEDA_NetlistFrame( WinEDA_SchematicFrame* parent, wxPoint& framepos ) :
    wxDialog( parent, -1, _( "Netlist" ), framepos,
              wxDefaultSize, DIALOG_STYLE | MAYBE_RESIZE_BORDER )
277
/*************************************************************************************/
278

279
/* Constructor for the netlist generation dialog box
280
 */
281
{
282
    int ii;
283

284
    m_Parent = parent;
285
    SetFont( *g_DialogFont );
286

287
    for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
288 289 290
    {
        m_PanelNetType[ii] = NULL;
    }
291

292
    if( framepos == wxDefaultPosition )
293
        Centre();
294

295 296
    wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );
    SetSizer( GeneralBoxSizer );
297

298
    m_NoteBook = new wxNotebook( this, ID_NETLIST_NOTEBOOK,
299 300 301
                                 wxDefaultPosition, wxDefaultSize );
    m_NoteBook->SetFont( *g_DialogFont );
    GeneralBoxSizer->Add( m_NoteBook, 0, wxGROW | wxALL, 5 );
302

303
    // Add notebook pages:
304 305

    // Add Panel FORMAT PCBNEW
306 307 308 309
    m_PanelNetType[PANELPCBNEW] = new EDA_NoteBookPage( m_NoteBook, wxT(
                                                            "Pcbnew" ), NET_TYPE_PCBNEW,
                                                        ID_CURRENT_FORMAT_IS_DEFAULT,
                                                        ID_CREATE_NETLIST );
310 311

    // Add Panel FORMAT ORCADPCB2
312 313 314 315
    m_PanelNetType[PANELORCADPCB2] = new EDA_NoteBookPage( m_NoteBook, wxT(
                                                               "OrcadPCB2" ), NET_TYPE_ORCADPCB2,
                                                           ID_CURRENT_FORMAT_IS_DEFAULT,
                                                           ID_CREATE_NETLIST );
316 317

    // Add Panel FORMAT CADSTAR
318 319 320 321
    m_PanelNetType[PANELCADSTAR] = new EDA_NoteBookPage( m_NoteBook, wxT(
                                                             "CadStar" ), NET_TYPE_CADSTAR,
                                                         ID_CURRENT_FORMAT_IS_DEFAULT,
                                                         ID_CREATE_NETLIST );
322

323 324
    // Add Panel spice
    InstallPageSpice();
325

326 327 328
    // Add custom panels:
    InstallCustomPages();

329 330
    GetSizer()->Fit( this );
    GetSizer()->SetSizeHints( this );
331 332 333 334
}


/*************************************************/
335
void WinEDA_NetlistFrame::InstallPageSpice()
336
/*************************************************/
337

338
/* Create the spice page
339
 */
340
{
341 342
    wxButton*         Button;
    EDA_NoteBookPage* page;
343

344 345
    page = m_PanelNetType[PANELSPICE] = new EDA_NoteBookPage( m_NoteBook, wxT(
                                                                  "Spice" ), NET_TYPE_SPICE, 0, 0 );
346

347 348
    page->m_IsCurrentFormat = new wxCheckBox( page, ID_CURRENT_FORMAT_IS_DEFAULT,
                                             _( "Default format" ) );
349
    page->m_IsCurrentFormat->SetValue( g_NetFormat == NET_TYPE_SPICE );
350
    page->m_LeftBoxSizer->Add( page->m_IsCurrentFormat, 0, wxGROW | wxALL, 5 );
351

352 353 354 355 356 357 358
    wxString netlist_opt[2] = { _( "Use Net Names" ), _( "Use Net Numbers" ) };
    m_UseNetNamesInNetlist = new wxRadioBox( page, -1, _( "Netlist Options:" ),
                                             wxDefaultPosition, wxDefaultSize,
                                             2, netlist_opt, 1, wxRA_SPECIFY_COLS );
    if( !g_OptNetListUseNames )
        m_UseNetNamesInNetlist->SetSelection( 1 );
    page->m_LeftBoxSizer->Add( m_UseNetNamesInNetlist, 0, wxGROW | wxALL, 5 );
359 360

    page->m_CommandStringCtrl = new WinEDA_EnterText( page,
361 362 363 364 365
                                                      _(
                                                          "Simulator command:" ),
                                                      g_SimulatorCommandLine,
                                                      page->m_LowBoxSizer, wxDefaultSize );

366
    // Add buttons
367 368 369
    Button = new wxButton( page, ID_CREATE_NETLIST, _( "Netlist" ) );
    Button->SetForegroundColour( *wxRED );
    page->m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
370

371 372 373
    Button = new wxButton( page, ID_RUN_SIMULATOR, _( "&Run Simulator" ) );
    Button->SetForegroundColour( wxColour( 0, 100, 0 ) );
    page->m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
374

375 376 377
    Button = new wxButton( page, wxID_CANCEL, _( "&Cancel" ) );
    Button->SetForegroundColour( *wxBLUE );
    page->m_RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
378 379
}

380

381
/*************************************************/
382
void WinEDA_NetlistFrame::InstallCustomPages()
383
/*************************************************/
384

385
/* create the pages for custom netlist format selection:
386
 */
387
{
388 389 390
    int               ii, CustomCount;
    wxString          title, previoustitle, msg;
    EDA_NoteBookPage* CurrPage;
391

392 393
    CustomCount   = CUSTOMPANEL_COUNTMAX;
    previoustitle = wxT( "dummy_title" );
394 395
    for( ii = 0; ii < CustomCount; ii++ )
    {
396
        title = ReturnUserNetlistTypeName( ii == 0 ? true : false );
397 398

        if( title.IsEmpty() && previoustitle.IsEmpty() )
399
            break; // No more panel to install
400

401 402
        /* Install the panel "Add Plugin" after
         * the last initialised panel */
403 404
        previoustitle = title;
        if( title.IsEmpty() )
405 406 407 408 409 410 411 412 413 414 415
            CurrPage =
                m_PanelNetType[PANELCUSTOMBASE + ii] =
                    new EDA_NoteBookPage( m_NoteBook, _( "Add Plugin" ),
                                          NET_TYPE_CUSTOM1 + ii,
                                          ID_CURRENT_FORMAT_IS_DEFAULT, ID_SETUP_PLUGIN );
        else  /* Install a plugin panel */
            CurrPage =
                m_PanelNetType[PANELCUSTOMBASE + ii] =
                    new EDA_NoteBookPage( m_NoteBook, title,
                                          NET_TYPE_CUSTOM1 + ii,
                                          ID_CURRENT_FORMAT_IS_DEFAULT, ID_CREATE_NETLIST );
416 417 418

        msg = CUSTOM_NETLIST_COMMAND;
        msg << ii + 1;
419 420 421 422 423 424 425 426 427 428 429 430
        wxString Command = m_Parent->m_Parent->m_EDA_Config->Read( msg );
        CurrPage->m_CommandStringCtrl =
            new WinEDA_EnterText( CurrPage,
                                  _( "Netlist command:" ), Command,
                                  CurrPage->m_LowBoxSizer,
                                  wxDefaultSize );

        CurrPage->m_TitleStringCtrl =
            new WinEDA_EnterText( CurrPage,
                                  _( "Title:" ), title,
                                  CurrPage->m_LowBoxSizer,
                                  wxDefaultSize );
431
    }
432 433 434 435
}


/***********************************************************/
436
void WinEDA_NetlistFrame::SetupPluginData( wxCommandEvent& event )
437
/***********************************************************/
438

439
/* Browse the plugin files and set the m_CommandStringCtrl field
440
 */
441
{
442 443 444 445 446 447 448 449 450 451 452 453 454
    wxString FullFileName, Mask, Path;

    Mask = wxT( "*" );
    Path = g_EDA_Appl->m_BinDir;
    FullFileName = EDA_FileSelector( _( "Plugin files:" ),
                                     Path,          /* Chemin par defaut */
                                     FullFileName,  /* nom fichier par defaut */
                                     wxEmptyString, /* extension par defaut */
                                     Mask,          /* Masque d'affichage */
                                     this,
                                     wxFD_OPEN,
                                     TRUE
                                     );
455 456 457
    if( FullFileName.IsEmpty() )
        return;

458 459
    EDA_NoteBookPage* CurrPage;
    CurrPage = (EDA_NoteBookPage*) m_NoteBook->GetCurrentPage();
460 461 462
    if( CurrPage == NULL )
        return;

463
    CurrPage->m_CommandStringCtrl->SetValue( FullFileName );
464 465 466 467

    /* Get a title for this page */
    wxString title = CurrPage->m_TitleStringCtrl->GetValue();
    if( title.IsEmpty() )
468 469
        DisplayInfo( this,
                    _(
CHARRAS's avatar
CHARRAS committed
470
                        "Do not forget to choose a title for this netlist control page" ) );
471 472 473 474
}


/*****************************************************************/
475
void WinEDA_NetlistFrame::SelectNetlistType( wxCommandEvent& event )
476
/*****************************************************************/
CHARRAS's avatar
CHARRAS committed
477 478
/* Called when the check box "default format" is clicked
*/
479
{
480 481
    int ii;
    EDA_NoteBookPage* CurrPage;
482

483 484
    for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
        if( m_PanelNetType[ii] )
485
            m_PanelNetType[ii]->m_IsCurrentFormat->SetValue( FALSE );
486

487
    CurrPage = (EDA_NoteBookPage*) m_NoteBook->GetCurrentPage();
488 489
    if( CurrPage == NULL )
        return;
490

491
    g_NetFormat = CurrPage->m_IdNetType;
492
    CurrPage->m_IsCurrentFormat->SetValue( TRUE );
493 494
}

495

496
/***********************************************/
497
void WinEDA_NetlistFrame::NetlistUpdateOpt()
498 499
/***********************************************/
{
500
    int ii;
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516

    g_SimulatorCommandLine =
        m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
    g_NetFormat = NET_TYPE_PCBNEW;

    for( ii = 0; ii < PANELCUSTOMBASE + CUSTOMPANEL_COUNTMAX; ii++ )
    {
        if( m_PanelNetType[ii] == NULL )
            break;
        if( m_PanelNetType[ii]->m_IsCurrentFormat->GetValue() == TRUE )
            g_NetFormat = m_PanelNetType[ii]->m_IdNetType;
    }

    g_OptNetListUseNames = TRUE; // Used for pspice, gnucap
    if( m_UseNetNamesInNetlist->GetSelection() == 1 )
        g_OptNetListUseNames = FALSE;
517 518
}

519

520
/**********************************************************/
521
void WinEDA_NetlistFrame::GenNetlist( wxCommandEvent& event )
522
/**********************************************************/
523 524 525 526 527 528

/** Function GenNetlist
 * Create the netlist file:
 * calcualte the filename with the suitable extentions
 * and run the netlist creator
 */
529
{
530 531 532
    wxString FullFileName, FileExt, Mask;
    wxString msg, Command;
    int      netformat_tmp = g_NetFormat;
533

534
    NetlistUpdateOpt();
535

536
    EDA_NoteBookPage* CurrPage;
537

538
    CurrPage    = (EDA_NoteBookPage*) m_NoteBook->GetCurrentPage();
539 540
    g_NetFormat = CurrPage->m_IdNetType;

541
    /* Calculate the netlist filename */
542 543 544 545 546
    FullFileName = ScreenSch->m_FileName;

    switch( g_NetFormat )
    {
    case NET_TYPE_SPICE:
547
        FileExt = wxT( ".cir" );
548 549 550
        break;

    case NET_TYPE_CADSTAR:
551
        FileExt = wxT( ".frp" );
552 553 554 555 556 557 558
        break;

    default:
        FileExt = g_NetExtBuffer;
        break;
    }

559 560 561 562 563 564 565 566 567 568 569 570
    Mask = wxT( "*" ) + FileExt + wxT( "*" );
    ChangeFileNameExt( FullFileName, FileExt );

    FullFileName = EDA_FileSelector( _( "Netlist files:" ),
                                     wxEmptyString, /* Defaut path */
                                     FullFileName,  /* Defaut filename */
                                     FileExt,       /* Defaut extension */
                                     Mask,          /* Mask for filename selection */
                                     this,
                                     wxFD_SAVE,
                                     TRUE
                                     );
571 572 573 574 575 576
    if( FullFileName.IsEmpty() )
        return;

    m_Parent->MsgPanel->EraseMsgBox();

    ReAnnotatePowerSymbolsOnly();
577
    if( CheckAnnotate( m_Parent, 0 ) )
578
    {
579
        if( !IsOK( this, _( "Must be Annotated, Continue ?" ) ) )
580 581 582 583
            return;
    }

    /* Cleanup the entire hierarchy */
584 585
    EDA_ScreenList ScreenList( NULL );
    for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
586 587
    {
        bool ModifyWires;
588 589
        ModifyWires = screen->SchematicCleanUp( NULL );

590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
        // if wire list has changed, delete the Undo Redo list to avoid
        // pointer problems with deleted data
        if( ModifyWires )
            screen->ClearUndoRedoList();
    }

    m_Parent->BuildNetListBase();
    if( CurrPage->m_CommandStringCtrl )
        g_NetListerCommandLine = CurrPage->m_CommandStringCtrl->GetValue();
    else
        g_NetListerCommandLine.Empty();

    switch( g_NetFormat )
    {
    default:
605
        WriteNetList( m_Parent, FullFileName, TRUE );
606 607 608 609
        break;

    case NET_TYPE_CADSTAR:
    case NET_TYPE_ORCADPCB2:
610
        WriteNetList( m_Parent, FullFileName, FALSE );
611 612 613 614 615

    case NET_TYPE_SPICE:
        g_OptNetListUseNames = TRUE; // Used for pspice, gnucap
        if( m_UseNetNamesInNetlist->GetSelection() == 1 )
            g_OptNetListUseNames = FALSE;
616
        WriteNetList( m_Parent, FullFileName, g_OptNetListUseNames );
617 618
        break;
    }
619

620 621 622
    FreeTabNetList( g_TabObjNet, g_NbrObjNet );
    g_NetFormat = netformat_tmp;

623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
    WriteCurrentNetlistSetup();

    EndModal( NET_OK );
}


/***********************************************************/
void WinEDA_NetlistFrame::OnCancelClick( wxCommandEvent& event )
/***********************************************************/
{
    EndModal( NET_ABORT );
}


/***********************************************************/
void WinEDA_NetlistFrame::RunSimulator( wxCommandEvent& event )
/***********************************************************/
{
    wxString NetlistFullFileName, ExecFile, CommandLine;

    g_SimulatorCommandLine =
        m_PanelNetType[PANELSPICE]->m_CommandStringCtrl->GetValue();
    g_SimulatorCommandLine.Trim( FALSE );
    g_SimulatorCommandLine.Trim( TRUE );
    ExecFile = g_SimulatorCommandLine.BeforeFirst( ' ' );

    CommandLine = g_SimulatorCommandLine.AfterFirst( ' ' );

    /* Calculate the netlist filename */
    NetlistFullFileName = ScreenSch->m_FileName;
    ChangeFileNameExt( NetlistFullFileName, wxT( ".cir" ) );
    AddDelimiterString( NetlistFullFileName );
    CommandLine += wxT( " " ) + NetlistFullFileName;

    ExecuteFile( this, ExecFile, CommandLine );
}


/*********************************************************/
void WinEDA_NetlistFrame::WriteCurrentNetlistSetup( void )
/*********************************************************/

/** Function WriteCurrentNetlistSetup
 * Write the current netlist options setup in the configuration
 */
{
    wxString msg, Command;

671
    NetlistUpdateOpt();
672

673 674 675
    // Update the new titles
    for( int ii = 0; ii < CUSTOMPANEL_COUNTMAX; ii++ )
    {
676
        EDA_NoteBookPage* CurrPage = m_PanelNetType[ii + PANELCUSTOMBASE];
677 678
        if( CurrPage == NULL )
            break;
679
        msg = wxT( "Custom" );
680 681 682 683 684 685 686 687
        msg << ii + 1;
        if( CurrPage->m_TitleStringCtrl )
        {
            wxString title = CurrPage->m_TitleStringCtrl->GetValue();
            if( msg != title ) // Title has changed, Update config
            {
                msg = CUSTOM_NETLIST_TITLE;
                msg << ii + 1;
688
                m_Parent->m_Parent->m_EDA_Config->Write( msg, title );
689 690 691 692 693 694 695 696
            }
        }

        if( CurrPage->m_CommandStringCtrl )
        {
            Command = CurrPage->m_CommandStringCtrl->GetValue();
            msg = CUSTOM_NETLIST_COMMAND;
            msg << ii + 1;
697
            m_Parent->m_Parent->m_EDA_Config->Write( msg, Command );
698 699
        }
    }
700 701
}

702

703 704 705 706 707 708 709
/******************************************************************/
void WinEDA_NetlistFrame::DeletePluginPanel( wxCommandEvent& event )
/******************************************************************/

/** Function DeletePluginPanel
 * Remove a panel relative to a netlist plugin
 */
710
{
711
    EDA_NoteBookPage* CurrPage = (EDA_NoteBookPage*) m_NoteBook->GetCurrentPage();
712

713 714 715 716 717 718 719 720 721 722
    CurrPage->m_CommandStringCtrl->SetValue( wxEmptyString );
    CurrPage->m_TitleStringCtrl->SetValue( wxEmptyString );
    if( CurrPage->m_IsCurrentFormat->IsChecked() )
    {
        CurrPage->m_IsCurrentFormat->SetValue( FALSE );
        m_PanelNetType[PANELPCBNEW]->m_IsCurrentFormat->SetValue( TRUE );
    }
    WriteCurrentNetlistSetup();
    EndModal( NET_PLUGIN_CHANGE );
}
723 724


725 726 727
/******************************************************************/
void WinEDA_NetlistFrame::ValidatePluginPanel( wxCommandEvent& event )
/******************************************************************/
728

729 730 731 732 733
/** Function ValidatePluginPanel
 * Validate the panel info relative to a new netlist plugin
 */
{
    EDA_NoteBookPage* CurrPage = (EDA_NoteBookPage*) m_NoteBook->GetCurrentPage();
734

735 736 737 738 739 740 741 742 743 744
    if( CurrPage->m_CommandStringCtrl->GetValue() == wxEmptyString )
    {
        DisplayError( this, _( "Error. You must provide a command String" ) );
        return;
    }
    if( CurrPage->m_TitleStringCtrl->GetValue() == wxEmptyString )
    {
        DisplayError( this, _( "Error. You must provide a Title" ) );
        return;
    }
745

746 747
    WriteCurrentNetlistSetup();
    EndModal( NET_PLUGIN_CHANGE );
748
}