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.

91 lines
2.6 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file clear_gbr_drawlayers.cpp
  26. * @brief erase a given or all draw layers, an free memory relative to the cleared layer(s)
  27. */
  28. #include <confirm.h>
  29. #include <gerbview_frame.h>
  30. #include <gerber_file_image.h>
  31. #include <gerber_file_image_list.h>
  32. #include <view/view.h>
  33. #include <base_screen.h>
  34. #include "widgets/gerbview_layer_widget.h"
  35. #include <tool/tool_manager.h>
  36. bool GERBVIEW_FRAME::Clear_DrawLayers( bool query )
  37. {
  38. if( GetGerberLayout() == nullptr )
  39. return false;
  40. if( query && GetScreen()->IsContentModified() )
  41. {
  42. if( !IsOK( this, _( "Current data will be lost?" ) ) )
  43. return false;
  44. }
  45. if( GetCanvas() )
  46. {
  47. if( m_toolManager )
  48. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  49. GetCanvas()->GetView()->Clear();
  50. // Reinit the drawing-sheet view, cleared by GetView()->Clear():
  51. SetPageSettings( GetPageSettings() );
  52. }
  53. GetImagesList()->DeleteAllImages();
  54. GetGerberLayout()->SetBoundingBox( BOX2I() );
  55. SetActiveLayer( 0 );
  56. ReFillLayerWidget();
  57. syncLayerBox();
  58. return true;
  59. }
  60. void GERBVIEW_FRAME::Erase_Current_DrawLayer( bool query )
  61. {
  62. int layer = GetActiveLayer();
  63. wxString msg;
  64. msg.Printf( _( "Clear layer %d?" ), layer + 1 );
  65. if( query && !IsOK( this, msg ) )
  66. return;
  67. if( m_toolManager )
  68. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  69. RemapLayers( GetImagesList()->RemoveImage( layer ) );
  70. ReFillLayerWidget();
  71. syncLayerBox();
  72. GetCanvas()->Refresh();
  73. }