2017-11-23 16:20:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2017 CERN
|
2018-10-01 07:00:59 +00:00
|
|
|
* Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-11-23 16:20:27 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
#include <cstdint>
|
|
|
|
#include <thread>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <board_commit.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2020-10-16 11:20:37 +00:00
|
|
|
#include <widgets/infobar.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <widgets/wx_progress_reporters.h>
|
2019-07-14 11:06:30 +00:00
|
|
|
#include <wx/event.h>
|
2020-10-16 11:20:37 +00:00
|
|
|
#include <wx/hyperlink.h>
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include "pcb_actions.h"
|
|
|
|
#include "zone_filler_tool.h"
|
2017-11-30 16:22:45 +00:00
|
|
|
#include "zone_filler.h"
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2019-06-09 21:57:23 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
ZONE_FILLER_TOOL::ZONE_FILLER_TOOL() :
|
2021-06-16 15:11:17 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.ZoneFiller" ),
|
|
|
|
m_fillInProgress( false )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZONE_FILLER_TOOL::~ZONE_FILLER_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_FILLER_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aReporter )
|
2019-07-08 19:44:40 +00:00
|
|
|
{
|
2021-06-16 15:11:17 +00:00
|
|
|
if( !getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty || m_fillInProgress )
|
2019-07-08 19:44:40 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-16 15:11:17 +00:00
|
|
|
m_fillInProgress = true;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
std::vector<ZONE*> toFill;
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2021-01-08 21:20:29 +00:00
|
|
|
for( ZONE* zone : board()->Zones() )
|
2019-07-08 19:44:40 +00:00
|
|
|
toFill.push_back(zone);
|
|
|
|
|
2021-08-14 20:05:21 +00:00
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
std::unique_ptr<WX_PROGRESS_REPORTER> reporter;
|
|
|
|
ZONE_FILLER filler( frame()->GetBoard(), &commit );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
|
|
|
if( aReporter )
|
2021-08-14 20:05:21 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
filler.SetProgressReporter( aReporter );
|
2021-08-14 20:05:21 +00:00
|
|
|
}
|
2020-09-14 17:54:14 +00:00
|
|
|
else
|
2021-08-14 20:05:21 +00:00
|
|
|
{
|
|
|
|
reporter = std::make_unique<WX_PROGRESS_REPORTER>( aCaller, _( "Checking Zones" ), 4 );
|
|
|
|
filler.SetProgressReporter( reporter.get() );
|
|
|
|
}
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
if( filler.Fill( toFill, true, aCaller ) )
|
2019-07-08 19:44:40 +00:00
|
|
|
{
|
2021-12-14 21:35:46 +00:00
|
|
|
board()->GetConnectivity()->Build( board() );
|
2022-02-04 13:44:08 +00:00
|
|
|
commit.Push( _( "Fill Zone(s)" ) );
|
2019-07-08 19:44:40 +00:00
|
|
|
getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty = false;
|
|
|
|
}
|
2020-08-12 16:39:57 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.Revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas()->Refresh();
|
2021-06-16 15:11:17 +00:00
|
|
|
m_fillInProgress = false;
|
2019-07-08 19:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-14 11:06:30 +00:00
|
|
|
void ZONE_FILLER_TOOL::singleShotRefocus( wxIdleEvent& )
|
|
|
|
{
|
|
|
|
canvas()->SetFocus();
|
|
|
|
canvas()->Unbind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-16 15:03:55 +00:00
|
|
|
void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aReporter )
|
2019-07-08 19:44:40 +00:00
|
|
|
{
|
2021-03-25 17:19:29 +00:00
|
|
|
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
|
2020-11-11 23:05:59 +00:00
|
|
|
std::vector<ZONE*> toFill;
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2021-06-16 15:11:17 +00:00
|
|
|
if( m_fillInProgress )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_fillInProgress = true;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : board()->Zones() )
|
2020-09-21 19:20:20 +00:00
|
|
|
toFill.push_back( zone );
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2021-03-25 17:19:29 +00:00
|
|
|
board()->IncrementTimeStamp(); // Clear caches
|
|
|
|
|
2021-08-14 20:05:21 +00:00
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
std::unique_ptr<WX_PROGRESS_REPORTER> reporter;
|
|
|
|
ZONE_FILLER filler( board(), &commit );
|
2020-09-14 17:54:14 +00:00
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
if( !board()->GetDesignSettings().m_DRCEngine->RulesValid() )
|
|
|
|
{
|
2021-03-25 17:19:29 +00:00
|
|
|
WX_INFOBAR* infobar = frame->GetInfoBar();
|
2022-02-14 17:19:28 +00:00
|
|
|
wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Show DRC rules" ),
|
2020-10-16 11:20:37 +00:00
|
|
|
wxEmptyString );
|
|
|
|
|
2021-03-25 17:19:29 +00:00
|
|
|
button->Bind( wxEVT_COMMAND_HYPERLINK,
|
|
|
|
std::function<void( wxHyperlinkEvent& aEvent )>(
|
2021-06-18 16:18:28 +00:00
|
|
|
[frame]( wxHyperlinkEvent& aEvent )
|
2021-03-25 17:19:29 +00:00
|
|
|
{
|
|
|
|
frame->ShowBoardSetupDialog( _( "Rules" ) );
|
|
|
|
} ) );
|
2020-10-16 11:20:37 +00:00
|
|
|
|
2020-10-16 16:07:59 +00:00
|
|
|
infobar->RemoveAllButtons();
|
|
|
|
infobar->AddButton( button );
|
|
|
|
|
2020-10-16 11:20:37 +00:00
|
|
|
infobar->ShowMessageFor( _( "Zone fills may be inaccurate. DRC rules contain errors." ),
|
|
|
|
10000, wxICON_WARNING );
|
|
|
|
}
|
|
|
|
|
2020-09-14 17:54:14 +00:00
|
|
|
if( aReporter )
|
2021-08-14 20:05:21 +00:00
|
|
|
{
|
2020-09-14 17:54:14 +00:00
|
|
|
filler.SetProgressReporter( aReporter );
|
2021-08-14 20:05:21 +00:00
|
|
|
}
|
2020-09-14 17:54:14 +00:00
|
|
|
else
|
2021-08-14 20:05:21 +00:00
|
|
|
{
|
2022-02-14 17:19:28 +00:00
|
|
|
reporter = std::make_unique<WX_PROGRESS_REPORTER>( aCaller, _( "Fill All Zones" ), 5 );
|
2021-08-14 20:05:21 +00:00
|
|
|
filler.SetProgressReporter( reporter.get() );
|
|
|
|
}
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2022-02-14 17:19:28 +00:00
|
|
|
if( filler.Fill( toFill ) )
|
2020-08-12 16:39:57 +00:00
|
|
|
{
|
2022-02-14 17:19:28 +00:00
|
|
|
reporter->AdvancePhase();
|
|
|
|
board()->GetConnectivity()->Build( board(), reporter.get() );
|
2019-07-08 19:44:40 +00:00
|
|
|
|
2022-02-14 17:19:28 +00:00
|
|
|
commit.Push( _( "Fill Zone(s)" ), true, true, false );
|
|
|
|
frame->m_ZoneFillsDirty = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.Revert();
|
2021-12-14 21:35:46 +00:00
|
|
|
}
|
2020-10-29 21:17:57 +00:00
|
|
|
|
2022-02-14 17:19:28 +00:00
|
|
|
if( filler.IsDebug() )
|
|
|
|
frame->UpdateUserInterface();
|
|
|
|
|
2019-07-08 19:44:40 +00:00
|
|
|
canvas()->Refresh();
|
2021-06-16 15:11:17 +00:00
|
|
|
m_fillInProgress = false;
|
2019-07-08 19:44:40 +00:00
|
|
|
|
|
|
|
// wxWidgets has keyboard focus issues after the progress reporter. Re-setting the focus
|
2019-07-14 11:06:30 +00:00
|
|
|
// here doesn't work, so we delay it to an idle event.
|
|
|
|
canvas()->Bind( wxEVT_IDLE, &ZONE_FILLER_TOOL::singleShotRefocus, this );
|
2019-07-08 19:44:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-16 15:11:17 +00:00
|
|
|
if( m_fillInProgress )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_fillInProgress = true;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
std::vector<ZONE*> toFill;
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
if( ZONE* passedZone = aEvent.Parameter<ZONE*>() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
toFill.push_back( passedZone );
|
2019-06-29 19:14:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
for( EDA_ITEM* item : selection() )
|
2019-06-29 19:14:43 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
if( ZONE* zone = dynamic_cast<ZONE*>( item ) )
|
2019-06-29 19:14:43 +00:00
|
|
|
toFill.push_back( zone );
|
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-14 20:05:21 +00:00
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
std::unique_ptr<WX_PROGRESS_REPORTER> reporter;
|
|
|
|
ZONE_FILLER filler( board(), &commit );
|
|
|
|
|
2022-02-14 17:19:28 +00:00
|
|
|
reporter = std::make_unique<WX_PROGRESS_REPORTER>( frame(), _( "Fill Zone" ), 5 );
|
2021-08-14 20:05:21 +00:00
|
|
|
filler.SetProgressReporter( reporter.get() );
|
2020-08-12 16:39:57 +00:00
|
|
|
|
|
|
|
if( filler.Fill( toFill ) )
|
2021-12-14 21:35:46 +00:00
|
|
|
{
|
2022-02-14 17:19:28 +00:00
|
|
|
reporter->AdvancePhase();
|
|
|
|
board()->GetConnectivity()->Build( board(), reporter.get() );
|
|
|
|
|
|
|
|
commit.Push( _( "Fill Zone(s)" ), true, true, false );
|
2021-12-14 21:35:46 +00:00
|
|
|
}
|
2020-08-12 16:39:57 +00:00
|
|
|
else
|
|
|
|
commit.Revert();
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2019-01-08 11:36:35 +00:00
|
|
|
canvas()->Refresh();
|
2021-06-16 15:11:17 +00:00
|
|
|
m_fillInProgress = false;
|
2017-11-23 16:20:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ZONE_FILLER_TOOL::ZoneFillAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-07-08 19:44:40 +00:00
|
|
|
FillAllZones( frame() );
|
2017-11-23 16:20:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ZONE_FILLER_TOOL::ZoneUnfill( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
2020-09-04 23:24:35 +00:00
|
|
|
for( EDA_ITEM* item : selection() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2021-03-08 12:57:33 +00:00
|
|
|
assert( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T );
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2017-11-23 16:20:27 +00:00
|
|
|
|
|
|
|
commit.Modify( zone );
|
|
|
|
|
2021-03-19 19:32:44 +00:00
|
|
|
zone->UnFill();
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _( "Unfill Zone" ) );
|
2019-01-08 11:36:35 +00:00
|
|
|
canvas()->Refresh();
|
2017-11-23 16:20:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ZONE_FILLER_TOOL::ZoneUnfillAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : board()->Zones() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
|
|
|
commit.Modify( zone );
|
|
|
|
|
2021-03-19 19:32:44 +00:00
|
|
|
zone->UnFill();
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
commit.Push( _( "Unfill All Zones" ) );
|
2019-01-08 11:36:35 +00:00
|
|
|
canvas()->Refresh();
|
2017-11-23 16:20:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_FILLER_TOOL::setTransitions()
|
|
|
|
{
|
|
|
|
// Zone actions
|
|
|
|
Go( &ZONE_FILLER_TOOL::ZoneFill, PCB_ACTIONS::zoneFill.MakeEvent() );
|
|
|
|
Go( &ZONE_FILLER_TOOL::ZoneFillAll, PCB_ACTIONS::zoneFillAll.MakeEvent() );
|
|
|
|
Go( &ZONE_FILLER_TOOL::ZoneUnfill, PCB_ACTIONS::zoneUnfill.MakeEvent() );
|
2018-10-01 07:00:59 +00:00
|
|
|
Go( &ZONE_FILLER_TOOL::ZoneUnfillAll, PCB_ACTIONS::zoneUnfillAll.MakeEvent() );
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|