You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

265 lines
8.1 KiB

12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <boost/bind.hpp>
  24. #include <fctsys.h>
  25. #include <class_drawpanel.h>
  26. #include <confirm.h>
  27. #include <pcbnew.h>
  28. #include <wxPcbStruct.h>
  29. #include <ratsnest_data.h>
  30. #include <class_board.h>
  31. #include <class_module.h>
  32. #include <class_track.h>
  33. #include <class_zone.h>
  34. #include <dialog_global_deletion.h>
  35. DIALOG_GLOBAL_DELETION::DIALOG_GLOBAL_DELETION( PCB_EDIT_FRAME* parent ) :
  36. DIALOG_GLOBAL_DELETION_BASE( parent )
  37. {
  38. m_Parent = parent;
  39. m_currentLayer = F_Cu;
  40. m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
  41. m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
  42. m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
  43. m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
  44. m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
  45. m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
  46. SetFocus();
  47. GetSizer()->SetSizeHints( this );
  48. Centre();
  49. }
  50. void PCB_EDIT_FRAME::InstallPcbGlobalDeleteFrame( const wxPoint& pos )
  51. {
  52. DIALOG_GLOBAL_DELETION dlg( this );
  53. dlg.SetCurrentLayer( GetActiveLayer() );
  54. dlg.ShowModal();
  55. }
  56. void DIALOG_GLOBAL_DELETION::SetCurrentLayer( LAYER_NUM aLayer )
  57. {
  58. m_currentLayer = aLayer;
  59. m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
  60. }
  61. void DIALOG_GLOBAL_DELETION::OnCheckDeleteTracks( wxCommandEvent& event )
  62. {
  63. m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
  64. m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
  65. m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
  66. m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
  67. }
  68. void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
  69. {
  70. m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
  71. m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
  72. }
  73. void DIALOG_GLOBAL_DELETION::AcceptPcbDelete( )
  74. {
  75. bool gen_rastnest = false;
  76. m_Parent->SetCurItem( NULL );
  77. if( m_DelAlls->GetValue() )
  78. {
  79. m_Parent->Clear_Pcb( true );
  80. }
  81. else
  82. {
  83. if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
  84. return;
  85. BOARD* pcb = m_Parent->GetBoard();
  86. PICKED_ITEMS_LIST pickersList;
  87. ITEM_PICKER itemPicker( NULL, UR_DELETED );
  88. BOARD_ITEM* item;
  89. BOARD_ITEM* nextitem;
  90. RN_DATA* ratsnest = pcb->GetRatsnest();
  91. LSET layers_filter = LSET().set();
  92. if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
  93. layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
  94. if( m_DelZones->GetValue() )
  95. {
  96. int area_index = 0;
  97. item = pcb->GetArea( area_index );
  98. while( item )
  99. {
  100. if( layers_filter[item->GetLayer()] )
  101. {
  102. itemPicker.SetItem( item );
  103. pickersList.PushItem( itemPicker );
  104. pcb->Remove( item );
  105. item->ViewRelease();
  106. ratsnest->Remove( item );
  107. gen_rastnest = true;
  108. }
  109. else
  110. {
  111. area_index++;
  112. }
  113. item = pcb->GetArea( area_index );
  114. }
  115. }
  116. if( m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue() )
  117. {
  118. LSET masque_layer;
  119. if( m_DelDrawings->GetValue() )
  120. masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
  121. if( m_DelBoardEdges->GetValue() )
  122. masque_layer.set( Edge_Cuts );
  123. masque_layer &= layers_filter;
  124. for( item = pcb->m_Drawings; item; item = nextitem )
  125. {
  126. nextitem = item->Next();
  127. if( item->Type() == PCB_LINE_T && masque_layer[item->GetLayer()] )
  128. {
  129. itemPicker.SetItem( item );
  130. pickersList.PushItem( itemPicker );
  131. item->ViewRelease();
  132. item->UnLink();
  133. }
  134. }
  135. }
  136. if( m_DelTexts->GetValue() )
  137. {
  138. LSET del_text_layers = layers_filter;
  139. for( item = pcb->m_Drawings; item; item = nextitem )
  140. {
  141. nextitem = item->Next();
  142. if( item->Type() == PCB_TEXT_T && del_text_layers[item->GetLayer()] )
  143. {
  144. itemPicker.SetItem( item );
  145. pickersList.PushItem( itemPicker );
  146. item->ViewRelease();
  147. item->UnLink();
  148. }
  149. }
  150. }
  151. if( m_DelModules->GetValue() )
  152. {
  153. for( item = pcb->m_Modules; item; item = nextitem )
  154. {
  155. nextitem = item->Next();
  156. if( layers_filter[item->GetLayer()] &&
  157. ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
  158. ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
  159. {
  160. itemPicker.SetItem( item );
  161. pickersList.PushItem( itemPicker );
  162. static_cast<MODULE*>( item )->RunOnChildren(
  163. boost::bind( &KIGFX::VIEW_ITEM::ViewRelease, _1 ) );
  164. ratsnest->Remove( item );
  165. item->ViewRelease();
  166. item->UnLink();
  167. gen_rastnest = true;
  168. }
  169. }
  170. }
  171. if( m_DelTracks->GetValue() )
  172. {
  173. STATUS_FLAGS track_mask_filter = 0;
  174. if( !m_TrackFilterLocked->GetValue() )
  175. track_mask_filter |= TRACK_LOCKED;
  176. if( !m_TrackFilterAR->GetValue() )
  177. track_mask_filter |= TRACK_AR;
  178. TRACK* nexttrack;
  179. for( TRACK *track = pcb->m_Track; track; track = nexttrack )
  180. {
  181. nexttrack = track->Next();
  182. if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
  183. continue;
  184. if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) == 0 ) &&
  185. !m_TrackFilterNormal->GetValue() )
  186. continue;
  187. if( ( track->Type() == PCB_VIA_T ) && !m_TrackFilterVias->GetValue() )
  188. continue;
  189. if( ( track->GetLayerSet() & layers_filter ) == 0 )
  190. continue;
  191. itemPicker.SetItem( track );
  192. pickersList.PushItem( itemPicker );
  193. track->ViewRelease();
  194. ratsnest->Remove( track );
  195. track->UnLink();
  196. gen_rastnest = true;
  197. }
  198. }
  199. if( pickersList.GetCount() )
  200. m_Parent->SaveCopyInUndoList( pickersList, UR_DELETED );
  201. if( m_DelMarkers->GetValue() )
  202. pcb->DeleteMARKERs();
  203. if( gen_rastnest )
  204. m_Parent->Compile_Ratsnest( NULL, true );
  205. if( m_Parent->IsGalCanvasActive() )
  206. pcb->GetRatsnest()->Recalculate();
  207. }
  208. m_Parent->GetCanvas()->Refresh();
  209. m_Parent->OnModify();
  210. EndModal( 1 );
  211. }