dialog_drc.cpp 16.9 KB
Newer Older
1 2 3
/**
 * @file dialog_drc.cpp
 */
plyatov's avatar
plyatov committed
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2011 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
plyatov's avatar
plyatov committed
28

29 30 31
#include <fctsys.h>
#include <dialog_drc.h>
#include <wxPcbStruct.h>
32
#include <base_units.h>
33
#include <class_board_design_settings.h>
plyatov's avatar
plyatov committed
34

35 36 37 38 39 40

// dialog should remember its previous screen position and size
wxPoint DIALOG_DRC_CONTROL::s_LastPos( -1, -1 );
wxSize  DIALOG_DRC_CONTROL::s_LastSize;


41 42
/* class DIALOG_DRC_CONTROL: a dialog to set DRC parameters (clearance, min cooper size)
 * and run DRC tests
dickelbeck's avatar
dickelbeck committed
43
 */
44

45
DIALOG_DRC_CONTROL::DIALOG_DRC_CONTROL( DRC* aTester, PCB_EDIT_FRAME* parent ) :
46
    DIALOG_DRC_CONTROL_BASE( parent )
plyatov's avatar
plyatov committed
47
{
48
    m_tester = aTester;
g_harland's avatar
g_harland committed
49
    m_Parent = parent;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
50
    m_BrdSettings = m_Parent->GetBoard()->GetDesignSettings();
plyatov's avatar
plyatov committed
51

52
    InitValues();
53
    if( GetSizer() )
54
    {
55
        GetSizer()->SetSizeHints( this );
56
    }
57

charras's avatar
charras committed
58
    Centre();
59 60 61 62 63 64 65 66
}


bool DIALOG_DRC_CONTROL::Show( bool show )
{
    bool ret;

    if( show )
67
    {
68 69 70 71 72 73 74 75
        ret = DIALOG_DRC_CONTROL_BASE::Show( show );

        if( s_LastPos.x != -1 )
        {
            SetSize( s_LastPos.x, s_LastPos.y, s_LastSize.x, s_LastSize.y, 0 );
        }
        else
        {
76
            // Do nothing: last position not yet saved.
77
        }
78
    }
79 80 81 82 83 84 85 86 87
    else
    {
        // Save the dialog's position before hiding
        s_LastPos  = GetPosition();
        s_LastSize = GetSize();
        ret = DIALOG_DRC_CONTROL_BASE::Show( show );
    }

    return ret;
plyatov's avatar
plyatov committed
88 89 90
}


91

92
void DIALOG_DRC_CONTROL::InitValues()
dickelbeck's avatar
dickelbeck committed
93 94
{
    // Connect events and objects
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    m_ClearanceListBox->Connect( ID_CLEARANCE_LIST, wxEVT_LEFT_DCLICK,
                                 wxMouseEventHandler(
                                     DIALOG_DRC_CONTROL::OnLeftDClickClearance ), NULL, this );
    m_ClearanceListBox->Connect( ID_CLEARANCE_LIST, wxEVT_RIGHT_UP,
                                 wxMouseEventHandler(
                                     DIALOG_DRC_CONTROL::OnRightUpClearance ), NULL, this );
    m_UnconnectedListBox->Connect( ID_UNCONNECTED_LIST, wxEVT_LEFT_DCLICK,
                                   wxMouseEventHandler( DIALOG_DRC_CONTROL::
                                                        OnLeftDClickUnconnected ), NULL, this );
    m_UnconnectedListBox->Connect( ID_UNCONNECTED_LIST, wxEVT_RIGHT_UP,
                                   wxMouseEventHandler(
                                       DIALOG_DRC_CONTROL::OnRightUpUnconnected ), NULL, this );

    AddUnitSymbol( *m_TrackMinWidthTitle );
    AddUnitSymbol( *m_ViaMinTitle );
    AddUnitSymbol( *m_MicroViaMinTitle );
111 112

    /* this looks terrible! does not fit into text field, do it in wxformbuilder instead
113
    m_SetClearance->SetValue( _("Netclasses values"));
114
    */
115 116

    Layout();      // adding the units above expanded Clearance text, now resize.
plyatov's avatar
plyatov committed
117

118 119 120 121
    // Set the initial "enabled" status of the browse button and the text
    // field for report name
    wxCommandEvent junk;
    OnReportCheckBoxClicked( junk );
plyatov's avatar
plyatov committed
122

123
    SetFocus();
plyatov's avatar
plyatov committed
124

125 126 127
    // deselect the existing text, seems SetFocus() wants to emulate
    // Microsoft and select all text, which is not desireable here.
//    m_SetClearance->SetSelection(0,0);
plyatov's avatar
plyatov committed
128
}
dickelbeck's avatar
dickelbeck committed
129

130 131 132 133
/* accept DRC parameters (min clearance value and min sizes
*/
void DIALOG_DRC_CONTROL::SetDrcParmeters( )
{
134 135 136
     m_BrdSettings.m_TrackMinWidth = ReturnValueFromTextCtrl( *m_SetTrackMinWidthCtrl );
     m_BrdSettings.m_ViasMinSize = ReturnValueFromTextCtrl( *m_SetViaMinSizeCtrl );
     m_BrdSettings.m_MicroViasMinSize = ReturnValueFromTextCtrl( *m_SetMicroViakMinSizeCtrl );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
137 138

     m_Parent->GetBoard()->SetDesignSettings( m_BrdSettings );
139 140
}

dickelbeck's avatar
dickelbeck committed
141

142 143 144 145
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DRC_RUN
 */

146
void DIALOG_DRC_CONTROL::OnStartdrcClick( wxCommandEvent& event )
147
{
dickelbeck's avatar
dickelbeck committed
148
    wxString reportName;
dickelbeck's avatar
dickelbeck committed
149

dickelbeck's avatar
dickelbeck committed
150 151 152
    if( m_CreateRptCtrl->IsChecked() )      // Create a file rpt
    {
        reportName = m_RptFilenameCtrl->GetValue();
153

dickelbeck's avatar
dickelbeck committed
154 155 156 157 158
        if( reportName.IsEmpty() )
        {
            wxCommandEvent junk;
            OnButtonBrowseRptFileClick( junk );
        }
159

dickelbeck's avatar
dickelbeck committed
160 161 162
        reportName = m_RptFilenameCtrl->GetValue();
    }

Dick Hollenbeck's avatar
Dick Hollenbeck committed
163
    SetDrcParmeters();
dickelbeck's avatar
dickelbeck committed
164

165 166 167 168 169
    m_tester->SetSettings( true,        // Pad to pad DRC test enabled
                          true,         // unconnected pdas DRC test enabled
                          true,         // DRC test for zones enabled
                          reportName, m_CreateRptCtrl->IsChecked() );

dickelbeck's avatar
dickelbeck committed
170
    DelDRCMarkers();
dickelbeck's avatar
dickelbeck committed
171

dickelbeck's avatar
dickelbeck committed
172
    wxBeginBusyCursor();
dickelbeck's avatar
dickelbeck committed
173

dickelbeck's avatar
dickelbeck committed
174
    // run all the tests, with no UI at this time.
175
    m_Messages->Clear();
176 177
    wxSafeYield();                          // Allows time slice to refresh the m_Messages window
    m_tester->m_pcb->m_Status_Pcb = 0;      // Force full connectivity and ratsnest recalculations
178
    m_tester->RunTests(m_Messages);
dickelbeck's avatar
dickelbeck committed
179

dickelbeck's avatar
dickelbeck committed
180
#if wxCHECK_VERSION( 2, 8, 0 )
181
    m_Notebook->ChangeSelection( 0 );       // display the 1at tab "...Markers ..."
dickelbeck's avatar
dickelbeck committed
182
#else
183
    m_Notebook->SetSelection( 0 );          // display the 1at tab "... Markers..."
dickelbeck's avatar
dickelbeck committed
184
#endif
dickelbeck's avatar
dickelbeck committed
185 186 187


    // Generate the report
dickelbeck's avatar
dickelbeck committed
188 189 190
    if( !reportName.IsEmpty() )
    {
        FILE* fp = wxFopen( reportName, wxT( "w" ) );
dickelbeck's avatar
dickelbeck committed
191
        writeReport( fp );
192
        fclose( fp );
dickelbeck's avatar
dickelbeck committed
193

194
        wxString        msg;
195
        msg.Printf( _( "Report file \"%s\" created" ), GetChars( reportName ) );
dickelbeck's avatar
dickelbeck committed
196

197
        wxString        caption( _( "Disk File Report Completed" ) );
dickelbeck's avatar
dickelbeck committed
198
        wxMessageDialog popupWindow( this, msg, caption );
dickelbeck's avatar
dickelbeck committed
199

dickelbeck's avatar
dickelbeck committed
200
        popupWindow.ShowModal();
dickelbeck's avatar
dickelbeck committed
201
    }
dickelbeck's avatar
dickelbeck committed
202

dickelbeck's avatar
dickelbeck committed
203
    wxEndBusyCursor();
dickelbeck's avatar
dickelbeck committed
204

dickelbeck's avatar
dickelbeck committed
205
    RedrawDrawPanel();
206 207
}

dickelbeck's avatar
dickelbeck committed
208

209 210 211 212
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_ERASE_DRC_MARKERS
 */

213
void DIALOG_DRC_CONTROL::OnDeleteAllClick( wxCommandEvent& event )
214
{
dickelbeck's avatar
dickelbeck committed
215 216
    DelDRCMarkers();
    RedrawDrawPanel();
217 218
}

dickelbeck's avatar
dickelbeck committed
219

220 221 222 223
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_LIST_UNCONNECTED_PADS
 */

224
void DIALOG_DRC_CONTROL::OnListUnconnectedClick( wxCommandEvent& event )
225
{
dickelbeck's avatar
dickelbeck committed
226
    wxString reportName;
dickelbeck's avatar
dickelbeck committed
227

dickelbeck's avatar
dickelbeck committed
228 229 230 231 232 233 234 235 236 237 238 239 240
    if( m_CreateRptCtrl->IsChecked() )      // Create a file rpt
    {
        reportName = m_RptFilenameCtrl->GetValue();

        if( reportName.IsEmpty() )
        {
            wxCommandEvent junk;
            OnButtonBrowseRptFileClick( junk );
        }

        reportName = m_RptFilenameCtrl->GetValue();
    }

Dick Hollenbeck's avatar
Dick Hollenbeck committed
241
    SetDrcParmeters();
dickelbeck's avatar
dickelbeck committed
242

243 244 245 246
    m_tester->SetSettings( true,        // Pad to pad DRC test enabled
                          true,         // unconnected pdas DRC test enabled
                          true,         // DRC test for zones enabled
                          reportName, m_CreateRptCtrl->IsChecked() );
dickelbeck's avatar
dickelbeck committed
247

dickelbeck's avatar
dickelbeck committed
248
    DelDRCMarkers();
dickelbeck's avatar
dickelbeck committed
249

dickelbeck's avatar
dickelbeck committed
250
    wxBeginBusyCursor();
dickelbeck's avatar
dickelbeck committed
251

252
    m_Messages->Clear();
dickelbeck's avatar
dickelbeck committed
253 254
    m_tester->ListUnconnectedPads();

dickelbeck's avatar
dickelbeck committed
255
#if wxCHECK_VERSION( 2, 8, 0 )
256
    m_Notebook->ChangeSelection( 1 );       // display the 2nd tab "Unconnected..."
dickelbeck's avatar
dickelbeck committed
257
#else
258
    m_Notebook->SetSelection( 1 );          // display the 2nd tab "Unconnected..."
dickelbeck's avatar
dickelbeck committed
259
#endif
dickelbeck's avatar
dickelbeck committed
260 261

    // Generate the report
dickelbeck's avatar
dickelbeck committed
262 263 264
    if( !reportName.IsEmpty() )
    {
        FILE* fp = wxFopen( reportName, wxT( "w" ) );
dickelbeck's avatar
dickelbeck committed
265
        writeReport( fp );
266
        fclose( fp );
dickelbeck's avatar
dickelbeck committed
267

268
        wxString        msg;
269
        msg.Printf( _( "Report file \"%s\" created" ), GetChars( reportName ) );
270
        wxString        caption( _( "Disk File Report Completed" ) );
dickelbeck's avatar
dickelbeck committed
271 272
        wxMessageDialog popupWindow( this, msg, caption );
        popupWindow.ShowModal();
dickelbeck's avatar
dickelbeck committed
273
    }
dickelbeck's avatar
dickelbeck committed
274

dickelbeck's avatar
dickelbeck committed
275
    wxEndBusyCursor();
dickelbeck's avatar
dickelbeck committed
276

dickelbeck's avatar
dickelbeck committed
277
    /* there is currently nothing visible on the DrawPanel for unconnected pads
278 279
     *  RedrawDrawPanel();
     */
280 281
}

282

283 284 285 286
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_BROWSE_RPT_FILE
 */

287
void DIALOG_DRC_CONTROL::OnButtonBrowseRptFileClick( wxCommandEvent& event )
288
{
289 290 291
    wxFileName fn;
    wxString   wildcard( _( "DRC report files (.rpt)|*.rpt" ) );
    wxString   Ext( wxT( "rpt" ) );
292

293
    fn = m_Parent->GetScreen()->GetFileName() + wxT( "-drc" );
294 295 296 297 298 299 300
    fn.SetExt( Ext );

    wxFileDialog dlg( this, _( "Save DRC Report File" ), wxEmptyString,
                      fn.GetFullName(), wildcard,
                      wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR );

    if( dlg.ShowModal() == wxID_CANCEL )
g_harland's avatar
g_harland committed
301 302
        return;

303
    m_RptFilenameCtrl->SetValue( dlg.GetPath() );
304 305
}

306 307

/*!
dickelbeck's avatar
dickelbeck committed
308
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK
309 310
 */

311
void DIALOG_DRC_CONTROL::OnOkClick( wxCommandEvent& event )
312
{
dickelbeck's avatar
dickelbeck committed
313
    SetReturnCode( wxID_OK );
Dick Hollenbeck's avatar
Dick Hollenbeck committed
314
    SetDrcParmeters();
315

dickelbeck's avatar
dickelbeck committed
316
    m_tester->DestroyDialog( wxID_OK );
dickelbeck's avatar
dickelbeck committed
317
}
318 319


dickelbeck's avatar
dickelbeck committed
320 321 322
/*!
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
 */
323

324
void DIALOG_DRC_CONTROL::OnCancelClick( wxCommandEvent& event )
dickelbeck's avatar
dickelbeck committed
325
{
dickelbeck's avatar
dickelbeck committed
326
    SetReturnCode( wxID_CANCEL );
327

dickelbeck's avatar
dickelbeck committed
328
    m_tester->DestroyDialog( wxID_CANCEL );
dickelbeck's avatar
dickelbeck committed
329 330 331 332 333 334
}


/*!
 * wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_CHECKBOX1
 */
335

336
void DIALOG_DRC_CONTROL::OnReportCheckBoxClicked( wxCommandEvent& event )
dickelbeck's avatar
dickelbeck committed
337 338 339
{
    if( m_CreateRptCtrl->IsChecked() )
    {
340 341
        m_RptFilenameCtrl->Enable( true );
        m_BrowseButton->Enable( true );
dickelbeck's avatar
dickelbeck committed
342
    }
343 344
    else
    {
345 346
        m_RptFilenameCtrl->Enable( false );
        m_BrowseButton->Enable( false );
347 348 349
    }
}

g_harland's avatar
g_harland committed
350 351

/*!
dickelbeck's avatar
dickelbeck committed
352
 * wxEVT_LEFT_DCLICK event handler for ID_CLEARANCE_LIST
g_harland's avatar
g_harland committed
353 354
 */

355
void DIALOG_DRC_CONTROL::OnLeftDClickClearance( wxMouseEvent& event )
g_harland's avatar
g_harland committed
356
{
dickelbeck's avatar
dickelbeck committed
357 358 359
    event.Skip();

    // I am assuming that the double click actually changed the selected item.
dickelbeck's avatar
dickelbeck committed
360
    // please verify this.
dickelbeck's avatar
dickelbeck committed
361 362 363 364
    int selection = m_ClearanceListBox->GetSelection();

    if( selection != wxNOT_FOUND )
    {
dickelbeck's avatar
dickelbeck committed
365
        // Find the selected MARKER in the PCB, position cursor there.
dickelbeck's avatar
dickelbeck committed
366 367 368 369
        // Then close the dialog.
        const DRC_ITEM* item = m_ClearanceListBox->GetItem( selection );
        if( item )
        {
dickelbeck's avatar
dickelbeck committed
370
            /*
371 372 373 374
             *  // after the goto, process a button OK command later.
             *  wxCommandEvent  cmd( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK );
             *  ::wxPostEvent( GetEventHandler(), cmd );
             */
dickelbeck's avatar
dickelbeck committed
375

376
            m_Parent->CursorGoto( item->GetPointA() );
dickelbeck's avatar
dickelbeck committed
377

378
            // turn control over to m_Parent, hide this DIALOG_DRC_CONTROL window,
dickelbeck's avatar
dickelbeck committed
379
            // no destruction so we can preserve listbox cursor
380
            Show( false );
dickelbeck's avatar
dickelbeck committed
381

dickelbeck's avatar
dickelbeck committed
382
            event.StopPropagation();    // still get the popup window.
dickelbeck's avatar
dickelbeck committed
383
        }
dickelbeck's avatar
dickelbeck committed
384 385 386 387
    }
}


388
void DIALOG_DRC_CONTROL::OnPopupMenu( wxCommandEvent& event )
dickelbeck's avatar
dickelbeck committed
389
{
390
    int             source = event.GetId();
dickelbeck's avatar
dickelbeck committed
391

dickelbeck's avatar
dickelbeck committed
392 393
    const DRC_ITEM* item = 0;
    wxPoint         pos;
dickelbeck's avatar
dickelbeck committed
394

395
    int             selection;
dickelbeck's avatar
dickelbeck committed
396 397 398 399 400 401 402 403

    switch( source )
    {
    case ID_POPUP_UNCONNECTED_A:
        selection = m_UnconnectedListBox->GetSelection();
        item = m_UnconnectedListBox->GetItem( selection );
        pos  = item->GetPointA();
        break;
404

dickelbeck's avatar
dickelbeck committed
405 406 407 408 409
    case ID_POPUP_UNCONNECTED_B:
        selection = m_UnconnectedListBox->GetSelection();
        item = m_UnconnectedListBox->GetItem( selection );
        pos  = item->GetPointB();
        break;
410

dickelbeck's avatar
dickelbeck committed
411 412 413 414 415
    case ID_POPUP_MARKERS_A:
        selection = m_ClearanceListBox->GetSelection();
        item = m_ClearanceListBox->GetItem( selection );
        pos  = item->GetPointA();
        break;
416

dickelbeck's avatar
dickelbeck committed
417 418 419 420 421 422 423 424 425 426
    case ID_POPUP_MARKERS_B:
        selection = m_ClearanceListBox->GetSelection();
        item = m_ClearanceListBox->GetItem( selection );
        pos  = item->GetPointB();
        break;
    }

    if( item )
    {
        m_Parent->CursorGoto( pos );
427
        Show( false );
dickelbeck's avatar
dickelbeck committed
428 429 430 431
    }
}


dickelbeck's avatar
dickelbeck committed
432 433 434 435
/*!
 * wxEVT_RIGHT_UP event handler for ID_CLEARANCE_LIST
 */

436
void DIALOG_DRC_CONTROL::OnRightUpUnconnected( wxMouseEvent& event )
dickelbeck's avatar
dickelbeck committed
437 438
{
    event.Skip();
dickelbeck's avatar
dickelbeck committed
439 440

    // popup menu to go to either of the items listed in the DRC_ITEM.
dickelbeck's avatar
dickelbeck committed
441

dickelbeck's avatar
dickelbeck committed
442
    int selection = m_UnconnectedListBox->GetSelection();
dickelbeck's avatar
dickelbeck committed
443

dickelbeck's avatar
dickelbeck committed
444 445 446 447 448
    if( selection != wxNOT_FOUND )
    {
        wxMenu          menu;
        wxMenuItem*     mItem;
        const DRC_ITEM* dItem = m_UnconnectedListBox->GetItem( selection );
dickelbeck's avatar
dickelbeck committed
449

450
        mItem = new wxMenuItem( &menu, ID_POPUP_UNCONNECTED_A, dItem->GetTextA() );
dickelbeck's avatar
dickelbeck committed
451
        menu.Append( mItem );
dickelbeck's avatar
dickelbeck committed
452 453 454

        if( dItem->HasSecondItem() )
        {
455
            mItem = new wxMenuItem( &menu, ID_POPUP_UNCONNECTED_B, dItem->GetTextB() );
dickelbeck's avatar
dickelbeck committed
456 457
            menu.Append( mItem );
        }
dickelbeck's avatar
dickelbeck committed
458 459 460

        PopupMenu( &menu );
    }
dickelbeck's avatar
dickelbeck committed
461 462 463 464 465 466 467
}


/*!
 * wxEVT_RIGHT_UP event handler for ID_CLEARANCE_LIST
 */

468
void DIALOG_DRC_CONTROL::OnRightUpClearance( wxMouseEvent& event )
dickelbeck's avatar
dickelbeck committed
469
{
g_harland's avatar
g_harland committed
470
    event.Skip();
dickelbeck's avatar
dickelbeck committed
471 472

    // popup menu to go to either of the items listed in the DRC_ITEM.
dickelbeck's avatar
dickelbeck committed
473

dickelbeck's avatar
dickelbeck committed
474
    int selection = m_ClearanceListBox->GetSelection();
dickelbeck's avatar
dickelbeck committed
475

dickelbeck's avatar
dickelbeck committed
476 477 478 479 480
    if( selection != wxNOT_FOUND )
    {
        wxMenu          menu;
        wxMenuItem*     mItem;
        const DRC_ITEM* dItem = m_ClearanceListBox->GetItem( selection );
dickelbeck's avatar
dickelbeck committed
481

482
        mItem = new wxMenuItem( &menu, ID_POPUP_MARKERS_A, dItem->GetTextA() );
dickelbeck's avatar
dickelbeck committed
483
        menu.Append( mItem );
dickelbeck's avatar
dickelbeck committed
484 485 486

        if( dItem->HasSecondItem() )
        {
487
            mItem = new wxMenuItem( &menu, ID_POPUP_MARKERS_B, dItem->GetTextB() );
dickelbeck's avatar
dickelbeck committed
488 489
            menu.Append( mItem );
        }
dickelbeck's avatar
dickelbeck committed
490 491 492

        PopupMenu( &menu );
    }
g_harland's avatar
g_harland committed
493
}
dickelbeck's avatar
dickelbeck committed
494 495 496 497 498 499


/*!
 * wxEVT_LEFT_DCLICK event handler for ID_UNCONNECTED_LIST
 */

500
void DIALOG_DRC_CONTROL::OnLeftDClickUnconnected( wxMouseEvent& event )
dickelbeck's avatar
dickelbeck committed
501
{
dickelbeck's avatar
dickelbeck committed
502 503 504
    event.Skip();

    // I am assuming that the double click actually changed the selected item.
dickelbeck's avatar
dickelbeck committed
505
    // please verify this.
dickelbeck's avatar
dickelbeck committed
506 507 508 509
    int selection = m_UnconnectedListBox->GetSelection();

    if( selection != wxNOT_FOUND )
    {
dickelbeck's avatar
dickelbeck committed
510
        // Find the selected DRC_ITEM in the listbox, position cursor there,
dickelbeck's avatar
dickelbeck committed
511 512
        // at the first of the two pads.
        // Then hide the dialog.
dickelbeck's avatar
dickelbeck committed
513 514 515
        const DRC_ITEM* item = m_UnconnectedListBox->GetItem( selection );
        if( item )
        {
516
            m_Parent->CursorGoto( item->GetPointA() );
dickelbeck's avatar
dickelbeck committed
517

518
            Show( false );
dickelbeck's avatar
dickelbeck committed
519

dickelbeck's avatar
dickelbeck committed
520
            // intermittently, still get the popup window, even with this.
dickelbeck's avatar
dickelbeck committed
521
            event.StopPropagation();
dickelbeck's avatar
dickelbeck committed
522
        }
dickelbeck's avatar
dickelbeck committed
523 524 525 526
    }
}


527
void DIALOG_DRC_CONTROL::OnMarkerSelectionEvent( wxCommandEvent& event )
dickelbeck's avatar
dickelbeck committed
528 529
{
    int selection = event.GetSelection();
dickelbeck's avatar
dickelbeck committed
530

dickelbeck's avatar
dickelbeck committed
531 532 533
    if( selection != wxNOT_FOUND )
    {
        // until a MARKER is selected, this button is not enabled.
534
        m_DeleteCurrentMarkerButton->Enable( true );
dickelbeck's avatar
dickelbeck committed
535
    }
dickelbeck's avatar
dickelbeck committed
536

dickelbeck's avatar
dickelbeck committed
537 538 539
    event.Skip();
}

540

541
void DIALOG_DRC_CONTROL::OnUnconnectedSelectionEvent( wxCommandEvent& event )
dickelbeck's avatar
dickelbeck committed
542 543
{
    int selection = event.GetSelection();
dickelbeck's avatar
dickelbeck committed
544

dickelbeck's avatar
dickelbeck committed
545 546
    if( selection != wxNOT_FOUND )
    {
dickelbeck's avatar
dickelbeck committed
547
        // until a MARKER is selected, this button is not enabled.
548
        m_DeleteCurrentMarkerButton->Enable( true );
dickelbeck's avatar
dickelbeck committed
549
    }
dickelbeck's avatar
dickelbeck committed
550

dickelbeck's avatar
dickelbeck committed
551 552 553
    event.Skip();
}

554

555
void DIALOG_DRC_CONTROL::RedrawDrawPanel()
dickelbeck's avatar
dickelbeck committed
556
{
557
    m_Parent->GetCanvas()->Refresh();
dickelbeck's avatar
dickelbeck committed
558
}
dickelbeck's avatar
dickelbeck committed
559 560


561
void DIALOG_DRC_CONTROL::DelDRCMarkers()
dickelbeck's avatar
dickelbeck committed
562
{
563
    m_Parent->SetCurItem( NULL );           // clear curr item, because it could be a DRC marker
dickelbeck's avatar
dickelbeck committed
564 565
    m_ClearanceListBox->DeleteAllItems();
    m_UnconnectedListBox->DeleteAllItems();
dickelbeck's avatar
dickelbeck committed
566 567 568
}


569
void DIALOG_DRC_CONTROL::writeReport( FILE* fp )
dickelbeck's avatar
dickelbeck committed
570 571 572 573
{
    int count;

    fprintf( fp, "** Drc report for %s **\n",
574
             TO_UTF8( m_Parent->GetScreen()->GetFileName() ) );
dickelbeck's avatar
dickelbeck committed
575 576

    wxDateTime now = wxDateTime::Now();
dickelbeck's avatar
dickelbeck committed
577

578
    fprintf( fp, "** Created on %s **\n", TO_UTF8( now.Format( wxT( "%F %T" ) ) ) );
dickelbeck's avatar
dickelbeck committed
579 580 581 582

    count = m_ClearanceListBox->GetItemCount();

    fprintf( fp, "\n** Found %d DRC errors **\n", count );
dickelbeck's avatar
dickelbeck committed
583

584
    for( int i = 0;  i<count;  ++i )
585
        fprintf( fp, "%s", TO_UTF8( m_ClearanceListBox->GetItem( i )->ShowReport()) );
dickelbeck's avatar
dickelbeck committed
586 587 588 589

    count = m_UnconnectedListBox->GetItemCount();

    fprintf( fp, "\n** Found %d unconnected pads **\n", count );
dickelbeck's avatar
dickelbeck committed
590

591
    for( int i = 0;  i<count;  ++i )
592
        fprintf( fp, "%s", TO_UTF8( m_UnconnectedListBox->GetItem( i )->ShowReport() ) );
dickelbeck's avatar
dickelbeck committed
593

dickelbeck's avatar
dickelbeck committed
594 595 596
    fprintf( fp, "\n** End of Report **\n" );
}

dickelbeck's avatar
dickelbeck committed
597

598
/*!
dickelbeck's avatar
dickelbeck committed
599
 * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_DELETE_ONE
600 601
 */

602
void DIALOG_DRC_CONTROL::OnDeleteOneClick( wxCommandEvent& event )
603
{
dickelbeck's avatar
dickelbeck committed
604
    int selectedIndex;
605
    int curTab = m_Notebook->GetSelection();
dickelbeck's avatar
dickelbeck committed
606 607 608 609

    if( curTab == 0 )
    {
        selectedIndex = m_ClearanceListBox->GetSelection();
610

dickelbeck's avatar
dickelbeck committed
611 612 613
        if( selectedIndex != wxNOT_FOUND )
        {
            m_ClearanceListBox->DeleteItem( selectedIndex );
dickelbeck's avatar
dickelbeck committed
614

dickelbeck's avatar
dickelbeck committed
615
            // redraw the pcb
dickelbeck's avatar
dickelbeck committed
616
            RedrawDrawPanel();
dickelbeck's avatar
dickelbeck committed
617 618 619 620 621
        }
    }
    else if( curTab == 1 )
    {
        selectedIndex = m_UnconnectedListBox->GetSelection();
622

dickelbeck's avatar
dickelbeck committed
623 624 625
        if( selectedIndex != wxNOT_FOUND )
        {
            m_UnconnectedListBox->DeleteItem( selectedIndex );
dickelbeck's avatar
dickelbeck committed
626 627

            /* these unconnected DRC_ITEMs are not currently visible on the pcb
628 629
             *  RedrawDrawPanel();
             */
dickelbeck's avatar
dickelbeck committed
630 631
        }
    }
632
}