dialog_global_deletion.cpp 8.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.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
22 23
 */

24
#include <boost/bind.hpp>
25

26 27 28 29 30
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
31
#include <ratsnest_data.h>
32 33 34 35 36 37 38

#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>

#include <dialog_global_deletion.h>
39 40


Dick Hollenbeck's avatar
Dick Hollenbeck committed
41 42
DIALOG_GLOBAL_DELETION::DIALOG_GLOBAL_DELETION( PCB_EDIT_FRAME* parent ) :
    DIALOG_GLOBAL_DELETION_BASE( parent )
43 44
{
    m_Parent = parent;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
45
    m_currentLayer = F_Cu;
46 47 48 49
    m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
    m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
    m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
    m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
50 51
    m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
    m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
52 53
    SetFocus();

54
    GetSizer()->SetSizeHints( this );
55 56 57 58
    Centre();
}


59
void PCB_EDIT_FRAME::InstallPcbGlobalDeleteFrame( const wxPoint& pos )
60 61
{
    DIALOG_GLOBAL_DELETION dlg( this );
62
    dlg.SetCurrentLayer( GetActiveLayer() );
63

64 65 66
    dlg.ShowModal();
}

67

68
void DIALOG_GLOBAL_DELETION::SetCurrentLayer( LAYER_NUM aLayer )
69 70
{
    m_currentLayer = aLayer;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
71
    m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
72 73
}

74

75 76 77 78 79 80 81
void DIALOG_GLOBAL_DELETION::OnCheckDeleteTracks( wxCommandEvent& event )
{
    m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
    m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
    m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
    m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
}
82

83 84 85 86 87 88 89 90

void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
{
    m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
    m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
}


91 92 93 94 95 96 97 98 99 100 101 102
void DIALOG_GLOBAL_DELETION::AcceptPcbDelete( )
{
    bool gen_rastnest = false;

    m_Parent->SetCurItem( NULL );

    if( m_DelAlls->GetValue() )
    {
        m_Parent->Clear_Pcb( true );
    }
    else
    {
103
        if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
104 105
            return;

106
        BOARD*            pcb = m_Parent->GetBoard();
107 108
        PICKED_ITEMS_LIST pickersList;
        ITEM_PICKER       itemPicker( NULL, UR_DELETED );
109 110 111
        BOARD_ITEM*       item;
        BOARD_ITEM*       nextitem;
        RN_DATA*          ratsnest = pcb->GetRatsnest();
112

Dick Hollenbeck's avatar
Dick Hollenbeck committed
113
        LSET layers_filter = LSET().set();
114 115

        if( m_rbLayersOption->GetSelection() != 0 )     // Use current layer only
116
            layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
117

118 119
        if( m_DelZones->GetValue() )
        {
120 121
            int area_index = 0;
            item = pcb->GetArea( area_index );
122

Dick Hollenbeck's avatar
Dick Hollenbeck committed
123
            while( item )
124
            {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
125
                if( layers_filter[item->GetLayer()] )
126 127 128 129
                {
                    itemPicker.SetItem( item );
                    pickersList.PushItem( itemPicker );
                    pcb->Remove( item );
130 131
                    item->ViewRelease();
                    ratsnest->Remove( item );
132 133 134 135 136 137 138 139
                    gen_rastnest = true;
                }
                else
                {
                    area_index++;
                }

                item = pcb->GetArea( area_index );
140 141 142
            }
        }

143 144
        if( m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue() )
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
145
            LSET masque_layer;
146

147
            if( m_DelDrawings->GetValue() )
Dick Hollenbeck's avatar
Dick Hollenbeck committed
148
                 masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
149

150
            if( m_DelBoardEdges->GetValue() )
Dick Hollenbeck's avatar
Dick Hollenbeck committed
151
                 masque_layer.set( Edge_Cuts );
152

153
            masque_layer &= layers_filter;
154

Dick Hollenbeck's avatar
Dick Hollenbeck committed
155
            for( item = pcb->m_Drawings; item; item = nextitem )
156 157
            {
                nextitem = item->Next();
158

Dick Hollenbeck's avatar
Dick Hollenbeck committed
159
                if( item->Type() == PCB_LINE_T  &&  masque_layer[item->GetLayer()] )
160 161 162
                {
                    itemPicker.SetItem( item );
                    pickersList.PushItem( itemPicker );
163
                    item->ViewRelease();
164 165 166 167
                    item->UnLink();
                }
            }
        }
168

169 170
        if( m_DelTexts->GetValue() )
        {
Dick Hollenbeck's avatar
Dick Hollenbeck committed
171
            LSET del_text_layers = layers_filter;
172

Dick Hollenbeck's avatar
Dick Hollenbeck committed
173
            for( item = pcb->m_Drawings; item; item = nextitem )
174
            {
175 176
                nextitem = item->Next();

Dick Hollenbeck's avatar
Dick Hollenbeck committed
177
                if( item->Type() == PCB_TEXT_T  &&  del_text_layers[item->GetLayer()] )
178 179 180
                {
                    itemPicker.SetItem( item );
                    pickersList.PushItem( itemPicker );
181
                    item->ViewRelease();
182 183
                    item->UnLink();
                }
184 185 186 187 188 189 190 191
            }
        }

        if( m_DelModules->GetValue() )
        {
            for( item = pcb->m_Modules; item; item = nextitem )
            {
                nextitem = item->Next();
192

Dick Hollenbeck's avatar
Dick Hollenbeck committed
193
                if( layers_filter[item->GetLayer()] &&
194 195 196 197 198
                    ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
                      ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
                {
                    itemPicker.SetItem( item );
                    pickersList.PushItem( itemPicker );
199 200 201 202
                    static_cast<MODULE*>( item )->RunOnChildren(
                            boost::bind( &KIGFX::VIEW_ITEM::ViewRelease, _1 ) );
                    ratsnest->Remove( item );
                    item->ViewRelease();
203 204 205
                    item->UnLink();
                    gen_rastnest = true;
                }
206 207 208 209 210
            }
        }

        if( m_DelTracks->GetValue() )
        {
211
            STATUS_FLAGS track_mask_filter = 0;
212

213
            if( !m_TrackFilterLocked->GetValue() )
214
                track_mask_filter |= TRACK_LOCKED;
215

216
            if( !m_TrackFilterAR->GetValue() )
217
                track_mask_filter |= TRACK_AR;
218

219
            TRACK* nexttrack;
220

Dick Hollenbeck's avatar
Dick Hollenbeck committed
221
            for( TRACK *track = pcb->m_Track; track; track = nexttrack )
222
            {
223
                nexttrack = track->Next();
224

225
                if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
226
                    continue;
227

228
                if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) == 0 ) &&
229 230 231
                    !m_TrackFilterNormal->GetValue() )
                    continue;

232
                if( ( track->Type() == PCB_VIA_T ) && !m_TrackFilterVias->GetValue() )
233 234
                    continue;

Dick Hollenbeck's avatar
Dick Hollenbeck committed
235
                if( ( track->GetLayerSet() & layers_filter ) == 0 )
236 237
                    continue;

238
                itemPicker.SetItem( track );
239
                pickersList.PushItem( itemPicker );
240 241
                track->ViewRelease();
                ratsnest->Remove( track );
242
                track->UnLink();
243 244 245 246 247 248 249 250 251 252 253 254
                gen_rastnest = true;
            }
        }

        if( pickersList.GetCount() )
            m_Parent->SaveCopyInUndoList( pickersList, UR_DELETED );

        if( m_DelMarkers->GetValue() )
            pcb->DeleteMARKERs();

        if( gen_rastnest )
            m_Parent->Compile_Ratsnest( NULL, true );
255

256 257 258
        if( m_Parent->IsGalCanvasActive() )
            pcb->GetRatsnest()->Recalculate();

259 260
    }

261
    m_Parent->GetCanvas()->Refresh();
262 263 264 265
    m_Parent->OnModify();

    EndModal( 1 );
}