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.

141 lines
4.2 KiB

5 years ago
5 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2021 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 pcbnew/initpcb.cpp
  26. */
  27. #include <confirm.h>
  28. #include <pcb_edit_frame.h>
  29. #include <project.h>
  30. #include <project/net_settings.h>
  31. #include <project/project_file.h>
  32. #include <board.h>
  33. #include <board_design_settings.h>
  34. #include <pcbnew.h>
  35. #include <footprint_edit_frame.h>
  36. #include <widgets/appearance_controls.h>
  37. bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery, bool aFinal )
  38. {
  39. if( GetBoard() == nullptr )
  40. return false;
  41. if( aQuery && !GetBoard()->IsEmpty() )
  42. {
  43. if( !IsOK( this, _( "Current Board will be lost and this operation cannot be undone. "
  44. "Continue?" ) ) )
  45. {
  46. return false;
  47. }
  48. }
  49. // Release the lock file, if exists
  50. ReleaseFile();
  51. // Clear undo and redo lists because we want a full deletion
  52. ClearUndoRedoList();
  53. GetScreen()->SetContentModified( false );
  54. if( !aFinal )
  55. {
  56. // delete the old BOARD and create a new BOARD so that the default
  57. // layer names are put into the BOARD.
  58. SetBoard( new BOARD() );
  59. // clear filename, to avoid overwriting an old file
  60. GetBoard()->SetFileName( wxEmptyString );
  61. GetScreen()->InitDataPoints( GetPageSizeIU() );
  62. GetBoard()->ResetNetHighLight();
  63. // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
  64. GetBoard()->SetEnabledLayers( LSET().set() );
  65. // Default copper layers count set to 2: double layer board
  66. GetBoard()->SetCopperLayerCount( 2 );
  67. // Update display (some options depend on the board setup)
  68. GetBoard()->SetVisibleLayers( LSET().set() );
  69. ReCreateLayerBox();
  70. ReCreateAuxiliaryToolbar();
  71. m_appearancePanel->OnBoardChanged();
  72. UpdateTitle();
  73. Zoom_Automatique( false );
  74. }
  75. return true;
  76. }
  77. bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery )
  78. {
  79. if( GetBoard() == nullptr )
  80. return false;
  81. bool is_last_fp_from_brd = IsCurrentFPFromBoard();
  82. if( aQuery && IsContentModified() )
  83. {
  84. wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
  85. if( !HandleUnsavedChanges(
  86. this, _( "The current footprint has been modified. Save changes?" ),
  87. [&]() -> bool
  88. {
  89. return SaveFootprint( GetBoard()->Footprints().front() );
  90. } ) )
  91. {
  92. return false;
  93. }
  94. }
  95. if( is_last_fp_from_brd )
  96. m_boardFootprintUuids.clear();
  97. // Clear undo and redo lists because we want a full deletion
  98. ClearUndoRedoList();
  99. GetScreen()->SetContentModified( false );
  100. BOARD* board = new BOARD;
  101. board->GetDesignSettings() = GetDesignSettings();
  102. board->SynchronizeNetsAndNetClasses( true );
  103. SetBoard( board );
  104. // This board will only be used to hold a footprint for editing
  105. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  106. // clear filename, to avoid overwriting an old file
  107. GetBoard()->SetFileName( wxEmptyString );
  108. GetScreen()->InitDataPoints( GetPageSizeIU() );
  109. return true;
  110. }