Refactor GAL dialog prompt for new zone settings
Break a chunk of the new zone tool out into a separate function to keep the code clear. When zone cutouts and similar zone tools are added, they'll get the settings from existing zones. This commit now used std::unique_ptr for the temporary zone item, which simplifies handling of the ownership of that item.
This commit is contained in:
parent
1f9c483535
commit
d37586aeaf
|
@ -1143,9 +1143,52 @@ bool DRAWING_TOOL::drawArc( DRAWSEGMENT*& aGraphic )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::unique_ptr<ZONE_CONTAINER> DRAWING_TOOL::createNewZone(
|
||||||
|
bool aKeepout )
|
||||||
|
{
|
||||||
|
const auto& board = *getModel<BOARD>();
|
||||||
|
|
||||||
|
// Get the current default settings for zones
|
||||||
|
ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings();
|
||||||
|
zoneInfo.m_CurrentZone_Layer = m_frame->GetScreen()->m_Active_Layer;
|
||||||
|
zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode();
|
||||||
|
zoneInfo.SetIsKeepout( aKeepout );
|
||||||
|
|
||||||
|
m_controls->SetAutoPan( true );
|
||||||
|
m_controls->CaptureCursor( true );
|
||||||
|
|
||||||
|
// Show options dialog
|
||||||
|
ZONE_EDIT_T dialogResult;
|
||||||
|
|
||||||
|
if( aKeepout )
|
||||||
|
dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneInfo );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) )
|
||||||
|
dialogResult = InvokeCopperZonesEditor( m_frame, &zoneInfo );
|
||||||
|
else
|
||||||
|
dialogResult = InvokeNonCopperZonesEditor( m_frame, NULL, &zoneInfo );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( dialogResult == ZONE_ABORT )
|
||||||
|
{
|
||||||
|
m_controls->SetAutoPan( false );
|
||||||
|
m_controls->CaptureCursor( false );
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto newZone = std::make_unique<ZONE_CONTAINER>( m_board );
|
||||||
|
|
||||||
|
// Apply the selected settings
|
||||||
|
zoneInfo.ExportSetting( *newZone );
|
||||||
|
|
||||||
|
return newZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int DRAWING_TOOL::drawZone( bool aKeepout )
|
int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
{
|
{
|
||||||
ZONE_CONTAINER* zone = NULL;
|
std::unique_ptr<ZONE_CONTAINER> zone;
|
||||||
DRAWSEGMENT line45;
|
DRAWSEGMENT line45;
|
||||||
DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line
|
DRAWSEGMENT* helperLine = NULL; // we will need more than one helper line
|
||||||
BOARD_COMMIT commit( m_frame );
|
BOARD_COMMIT commit( m_frame );
|
||||||
|
@ -1192,8 +1235,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
{
|
{
|
||||||
if( numPoints > 0 ) // cancel the current zone
|
if( numPoints > 0 ) // cancel the current zone
|
||||||
{
|
{
|
||||||
delete zone;
|
zone = nullptr;
|
||||||
zone = NULL;
|
|
||||||
m_controls->SetAutoPan( false );
|
m_controls->SetAutoPan( false );
|
||||||
m_controls->CaptureCursor( false );
|
m_controls->CaptureCursor( false );
|
||||||
|
|
||||||
|
@ -1235,18 +1277,15 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
zone->Outline()->RemoveNullSegments();
|
zone->Outline()->RemoveNullSegments();
|
||||||
|
|
||||||
if( !aKeepout )
|
if( !aKeepout )
|
||||||
static_cast<PCB_EDIT_FRAME*>( m_frame )->Fill_Zone( zone );
|
static_cast<PCB_EDIT_FRAME*>( m_frame )->Fill_Zone( zone.get() );
|
||||||
|
|
||||||
commit.Add( zone );
|
commit.Add( zone.release() );
|
||||||
commit.Push( _( "Draw a zone" ) );
|
commit.Push( _( "Draw a zone" ) );
|
||||||
|
}
|
||||||
|
|
||||||
zone = NULL;
|
// if kept, this was released. if still not null,
|
||||||
}
|
// this zone is now unwanted and can be removed
|
||||||
else
|
zone = nullptr;
|
||||||
{
|
|
||||||
delete zone;
|
|
||||||
zone = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
numPoints = 0;
|
numPoints = 0;
|
||||||
m_controls->SetAutoPan( false );
|
m_controls->SetAutoPan( false );
|
||||||
|
@ -1265,44 +1304,17 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
{
|
{
|
||||||
if( numPoints == 0 ) // it's the first click
|
if( numPoints == 0 ) // it's the first click
|
||||||
{
|
{
|
||||||
const auto& board = *getModel<BOARD>();
|
zone = createNewZone( aKeepout );
|
||||||
|
|
||||||
// Get the current default settings for zones
|
if( !zone )
|
||||||
ZONE_SETTINGS zoneInfo = m_frame->GetZoneSettings();
|
|
||||||
zoneInfo.m_CurrentZone_Layer = m_frame->GetScreen()->m_Active_Layer;
|
|
||||||
zoneInfo.m_NetcodeSelection = board.GetHighLightNetCode();
|
|
||||||
zoneInfo.SetIsKeepout( aKeepout );
|
|
||||||
|
|
||||||
m_controls->SetAutoPan( true );
|
|
||||||
m_controls->CaptureCursor( true );
|
|
||||||
|
|
||||||
// Show options dialog
|
|
||||||
ZONE_EDIT_T dialogResult;
|
|
||||||
|
|
||||||
if( aKeepout )
|
|
||||||
dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneInfo );
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if( IsCopperLayer( zoneInfo.m_CurrentZone_Layer ) )
|
|
||||||
dialogResult = InvokeCopperZonesEditor( m_frame, &zoneInfo );
|
|
||||||
else
|
|
||||||
dialogResult = InvokeNonCopperZonesEditor( m_frame, NULL, &zoneInfo );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( dialogResult == ZONE_ABORT )
|
|
||||||
{
|
|
||||||
m_controls->SetAutoPan( false );
|
|
||||||
m_controls->CaptureCursor( false );
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the selected settings
|
m_frame->GetGalCanvas()->SetTopLayer( zone->GetLayer() );
|
||||||
zone = new ZONE_CONTAINER( m_board );
|
|
||||||
zoneInfo.ExportSetting( *zone );
|
|
||||||
m_frame->GetGalCanvas()->SetTopLayer( zoneInfo.m_CurrentZone_Layer );
|
|
||||||
|
|
||||||
// Add the first point
|
// Add the first point
|
||||||
zone->Outline()->Start( zoneInfo.m_CurrentZone_Layer,
|
zone->Outline()->Start( zone->GetLayer(),
|
||||||
cursorPos.x, cursorPos.y,
|
cursorPos.x, cursorPos.y,
|
||||||
zone->GetHatchStyle() );
|
zone->GetHatchStyle() );
|
||||||
origin = cursorPos;
|
origin = cursorPos;
|
||||||
|
@ -1311,7 +1323,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
|
||||||
helperLine = new DRAWSEGMENT;
|
helperLine = new DRAWSEGMENT;
|
||||||
helperLine->SetShape( S_SEGMENT );
|
helperLine->SetShape( S_SEGMENT );
|
||||||
helperLine->SetWidth( 1 );
|
helperLine->SetWidth( 1 );
|
||||||
helperLine->SetLayer( zoneInfo.m_CurrentZone_Layer );
|
helperLine->SetLayer( zone->GetLayer() );
|
||||||
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
helperLine->SetStart( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
helperLine->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) );
|
||||||
line45 = *helperLine;
|
line45 = *helperLine;
|
||||||
|
|
|
@ -184,6 +184,17 @@ private:
|
||||||
///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
|
///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
|
||||||
int drawZone( bool aKeepout );
|
int drawZone( bool aKeepout );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function createNewZone()
|
||||||
|
*
|
||||||
|
* Prompt the user for new zone settings, and create a new zone with
|
||||||
|
* those settings
|
||||||
|
*
|
||||||
|
* @param aKeepout should the zone be a keepout
|
||||||
|
* @return the new zone, can be null if the user aborted
|
||||||
|
*/
|
||||||
|
std::unique_ptr<ZONE_CONTAINER> createNewZone( bool aKeepout );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function make45DegLine()
|
* Function make45DegLine()
|
||||||
* Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin stays the same,
|
* Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin stays the same,
|
||||||
|
|
Loading…
Reference in New Issue