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.

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