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>
|
|
|
|
#include <class_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>
|
|
|
|
#include <widgets/progress_reporter.h>
|
2019-07-14 11:06:30 +00:00
|
|
|
#include <wx/event.h>
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include "pcb_actions.h"
|
|
|
|
#include "selection_tool.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() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.ZoneFiller" )
|
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
|
|
|
|
|
|
|
void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller )
|
|
|
|
{
|
|
|
|
if( !getEditFrame<PCB_EDIT_FRAME>()->m_ZoneFillsDirty )
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector<ZONE_CONTAINER*> toFill;
|
|
|
|
|
|
|
|
for( auto zone : board()->Zones() )
|
|
|
|
toFill.push_back(zone);
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
|
|
|
ZONE_FILLER filler( frame()->GetBoard(), &commit );
|
2019-07-14 11:06:30 +00:00
|
|
|
filler.InstallNewProgressReporter( aCaller, _( "Checking Zones" ), 4 );
|
2019-07-08 19:44:40 +00:00
|
|
|
|
|
|
|
if( filler.Fill( toFill, true ) )
|
|
|
|
{
|
2020-08-12 16:39:57 +00:00
|
|
|
commit.Push( _( "Fill Zone(s)" ), false );
|
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();
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-08 19:44:40 +00:00
|
|
|
void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller )
|
|
|
|
{
|
|
|
|
std::vector<ZONE_CONTAINER*> toFill;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
|
|
|
for( auto zone : board()->Zones() )
|
|
|
|
toFill.push_back(zone);
|
|
|
|
|
|
|
|
ZONE_FILLER filler( board(), &commit );
|
2019-07-14 11:06:30 +00:00
|
|
|
filler.InstallNewProgressReporter( aCaller, _( "Fill All Zones" ), 4 );
|
2019-07-08 19:44:40 +00:00
|
|
|
|
|
|
|
if( filler.Fill( toFill ) )
|
2020-08-12 16:39:57 +00:00
|
|
|
{
|
|
|
|
commit.Push( _( "Fill Zone(s)" ), false );
|
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();
|
|
|
|
}
|
2019-07-08 19:44:40 +00:00
|
|
|
|
|
|
|
canvas()->Refresh();
|
|
|
|
|
|
|
|
// 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 )
|
|
|
|
{
|
|
|
|
std::vector<ZONE_CONTAINER*> toFill;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
2019-06-29 19:14:43 +00:00
|
|
|
if( auto passedZone = aEvent.Parameter<ZONE_CONTAINER*>() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
2019-06-29 19:14:43 +00:00
|
|
|
if( passedZone->Type() == PCB_ZONE_AREA_T )
|
|
|
|
toFill.push_back( passedZone );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( auto item : selection() )
|
|
|
|
{
|
|
|
|
if( auto zone = dyn_cast<ZONE_CONTAINER*>( item ) )
|
|
|
|
toFill.push_back( zone );
|
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ZONE_FILLER filler( board(), &commit );
|
2019-07-14 11:06:30 +00:00
|
|
|
filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
|
2020-08-12 16:39:57 +00:00
|
|
|
|
|
|
|
if( filler.Fill( toFill ) )
|
|
|
|
commit.Push( _( "Fill Zone(s)" ), false );
|
|
|
|
else
|
|
|
|
commit.Revert();
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2019-01-08 11:36:35 +00:00
|
|
|
canvas()->Refresh();
|
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 );
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
for( auto item : selection() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
|
|
|
assert( item->Type() == PCB_ZONE_AREA_T );
|
|
|
|
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
|
|
|
|
|
|
|
commit.Modify( zone );
|
|
|
|
|
|
|
|
zone->SetIsFilled( false );
|
|
|
|
zone->ClearFilledPolysList();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
2017-11-30 16:22:45 +00:00
|
|
|
for ( auto zone : board()->Zones() )
|
2017-11-23 16:20:27 +00:00
|
|
|
{
|
|
|
|
commit.Modify( zone );
|
|
|
|
|
|
|
|
zone->SetIsFilled( false );
|
|
|
|
zone->ClearFilledPolysList();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|