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.

175 lines
5.6 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-2023 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. #include <confirm.h>
  25. #include <pcb_edit_frame.h>
  26. #include <project.h>
  27. #include <tool/tool_manager.h>
  28. #include <project/net_settings.h>
  29. #include <project/project_file.h>
  30. #include <board.h>
  31. #include <board_design_settings.h>
  32. #include <footprint_editor_settings.h>
  33. #include <footprint_edit_frame.h>
  34. #include <widgets/appearance_controls.h>
  35. #include <drc/drc_item.h>
  36. bool PCB_EDIT_FRAME::Clear_Pcb( bool doAskAboutUnsavedChanges, bool aFinal )
  37. {
  38. if( GetBoard() == nullptr )
  39. return false;
  40. if( doAskAboutUnsavedChanges && !GetBoard()->IsEmpty() )
  41. {
  42. if( !IsOK( this, _( "Current Board will be lost and this operation cannot be undone. "
  43. "Continue?" ) ) )
  44. {
  45. return false;
  46. }
  47. }
  48. // Release the lock file, if exists
  49. ReleaseFile();
  50. // Clear undo and redo lists because we want a full deletion
  51. ClearUndoRedoList();
  52. GetScreen()->SetContentModified( false );
  53. if( !aFinal )
  54. {
  55. // delete the old BOARD and create a new BOARD so that the default
  56. // layer names are put into the BOARD.
  57. SetBoard( new BOARD() );
  58. // clear filename, to avoid overwriting an old file
  59. GetBoard()->SetFileName( wxEmptyString );
  60. GetScreen()->InitDataPoints( GetPageSizeIU() );
  61. GetBoard()->ResetNetHighLight();
  62. // Enable all layers (SetCopperLayerCount() will adjust the copper layers enabled)
  63. GetBoard()->SetEnabledLayers( LSET().set() );
  64. // Default copper layers count set to 2: double layer board
  65. GetBoard()->SetCopperLayerCount( 2 );
  66. // Update display (some options depend on the board setup)
  67. GetBoard()->SetVisibleLayers( LSET().set() );
  68. ReCreateLayerBox();
  69. ReCreateAuxiliaryToolbar();
  70. m_appearancePanel->OnBoardChanged();
  71. UpdateTitle();
  72. Zoom_Automatique( false );
  73. }
  74. else if( m_isClosing )
  75. {
  76. if( m_toolManager )
  77. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  78. // Clear the view so we don't attempt redraws (particularly of the RATSNEST_VIEW_ITEM,
  79. // which causes all manner of grief).
  80. GetCanvas()->GetView()->Clear();
  81. }
  82. return true;
  83. }
  84. bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool doAskAboutUnsavedChanges )
  85. {
  86. if( GetBoard() == nullptr )
  87. return false;
  88. bool is_last_fp_from_brd = IsCurrentFPFromBoard();
  89. if( doAskAboutUnsavedChanges && IsContentModified() )
  90. {
  91. wxSafeYield( this, true ); // Allow frame to come to front before showing warning.
  92. if( !HandleUnsavedChanges(
  93. this, _( "The current footprint has been modified. Save changes?" ),
  94. [&]() -> bool
  95. {
  96. return SaveFootprint( GetBoard()->Footprints().front() );
  97. } ) )
  98. {
  99. return false;
  100. }
  101. }
  102. if( is_last_fp_from_brd )
  103. m_boardFootprintUuids.clear();
  104. // Clear undo and redo lists because we want a full deletion
  105. ClearUndoRedoList();
  106. GetScreen()->SetContentModified( false );
  107. if( !m_isClosing )
  108. {
  109. SetBoard( new BOARD );
  110. if( FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings() )
  111. GetBoard()->GetDesignSettings() = cfg->m_DesignSettings;
  112. GetBoard()->SynchronizeNetsAndNetClasses( true );
  113. // This board will only be used to hold a footprint for editing
  114. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  115. // Setup our own severities for the Footprint Checker.
  116. // These are not (at present) user-editable.
  117. std::map<int, SEVERITY>& drcSeverities = GetBoard()->GetDesignSettings().m_DRCSeverities;
  118. for( int errorCode = DRCE_FIRST; errorCode <= DRCE_LAST; ++errorCode )
  119. drcSeverities[ errorCode ] = RPT_SEVERITY_ERROR;
  120. drcSeverities[ DRCE_DRILLED_HOLES_COLOCATED ] = RPT_SEVERITY_WARNING;
  121. drcSeverities[ DRCE_DRILLED_HOLES_TOO_CLOSE ] = RPT_SEVERITY_WARNING;
  122. drcSeverities[ DRCE_PADSTACK ] = RPT_SEVERITY_WARNING;
  123. drcSeverities[ DRCE_FOOTPRINT_TYPE_MISMATCH ] = RPT_SEVERITY_WARNING;
  124. // clear filename, to avoid overwriting an old file
  125. GetBoard()->SetFileName( wxEmptyString );
  126. GetScreen()->InitDataPoints( GetPageSizeIU() );
  127. }
  128. else
  129. {
  130. if( m_toolManager )
  131. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  132. // Clear the view so we don't attempt redraws
  133. GetCanvas()->GetView()->Clear();
  134. }
  135. return true;
  136. }