2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-07-01 13:16:51 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2019-03-06 15:34:21 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-17 20:01:27 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_zone.cpp
|
|
|
|
* @brief Implementation of class to handle copper zones.
|
|
|
|
*/
|
2007-12-09 12:59:06 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <pcb_screen.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <macros.h>
|
2018-01-29 15:39:40 +00:00
|
|
|
#include <pcb_base_frame.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2007-12-09 12:59:06 +00:00
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
#include <convert_to_biu.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_zone.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <zones.h>
|
2012-07-30 07:40:25 +00:00
|
|
|
#include <math_for_graphics.h>
|
2012-07-31 17:51:58 +00:00
|
|
|
#include <polygon_test_point_inside.h>
|
2009-08-01 19:26:05 +00:00
|
|
|
|
2007-12-09 12:59:06 +00:00
|
|
|
|
2012-02-06 05:44:19 +00:00
|
|
|
ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
|
|
|
|
BOARD_CONNECTED_ITEM( aBoard, PCB_ZONE_AREA_T )
|
2007-12-09 12:59:06 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
m_CornerSelection = nullptr; // no corner is selected
|
2011-01-20 18:40:33 +00:00
|
|
|
m_IsFilled = false; // fill status : true when the zone is filled
|
2017-12-04 18:06:47 +00:00
|
|
|
m_FillMode = ZFM_POLYGONS;
|
2018-03-19 09:02:05 +00:00
|
|
|
m_hatchStyle = DIAGONAL_EDGE;
|
|
|
|
m_hatchPitch = GetDefaultHatchPitch();
|
|
|
|
m_hv45 = false;
|
2018-02-18 09:09:13 +00:00
|
|
|
m_HatchFillTypeThickness = 0;
|
|
|
|
m_HatchFillTypeGap = 0;
|
|
|
|
m_HatchFillTypeOrientation = 0.0;
|
|
|
|
m_HatchFillTypeSmoothingLevel = 0; // Grid pattern smoothing type. 0 = no smoothing
|
|
|
|
m_HatchFillTypeSmoothingValue = 0.1; // Grid pattern chamfer value relative to the gap value
|
|
|
|
// used only if m_HatchFillTypeSmoothingLevel > 0
|
2012-01-29 19:29:19 +00:00
|
|
|
m_priority = 0;
|
2012-07-13 18:55:29 +00:00
|
|
|
m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
|
2012-07-14 16:27:25 +00:00
|
|
|
SetIsKeepout( false );
|
|
|
|
SetDoNotAllowCopperPour( false ); // has meaning only if m_isKeepout == true
|
|
|
|
SetDoNotAllowVias( true ); // has meaning only if m_isKeepout == true
|
|
|
|
SetDoNotAllowTracks( true ); // has meaning only if m_isKeepout == true
|
2012-07-13 18:55:29 +00:00
|
|
|
m_cornerRadius = 0;
|
2013-03-26 09:58:40 +00:00
|
|
|
SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
|
2017-03-07 12:06:00 +00:00
|
|
|
m_Poly = new SHAPE_POLY_SET(); // Outlines
|
2012-02-06 05:44:19 +00:00
|
|
|
aBoard->GetZoneSettings().ExportSetting( *this );
|
2019-03-14 13:35:55 +00:00
|
|
|
|
|
|
|
m_needRefill = false; // True only after some edition.
|
2007-12-09 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) :
|
|
|
|
BOARD_CONNECTED_ITEM( aZone )
|
|
|
|
{
|
|
|
|
// Should the copy be on the same net?
|
2014-02-25 10:40:34 +00:00
|
|
|
SetNetCode( aZone.GetNetCode() );
|
2017-03-07 12:06:00 +00:00
|
|
|
m_Poly = new SHAPE_POLY_SET( *aZone.m_Poly );
|
2012-01-14 19:50:32 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// For corner moving, corner index to drag, or nullptr if no selection
|
|
|
|
m_CornerSelection = nullptr;
|
2012-05-29 18:10:56 +00:00
|
|
|
m_IsFilled = aZone.m_IsFilled;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
|
|
|
|
m_ZoneMinThickness = aZone.m_ZoneMinThickness;
|
|
|
|
m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
|
2018-03-20 22:44:04 +00:00
|
|
|
m_hv45 = aZone.m_hv45;
|
2012-01-29 19:29:19 +00:00
|
|
|
m_priority = aZone.m_priority;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount;
|
2012-02-24 23:23:46 +00:00
|
|
|
m_PadConnection = aZone.m_PadConnection;
|
2012-01-14 19:50:32 +00:00
|
|
|
m_ThermalReliefGap = aZone.m_ThermalReliefGap;
|
|
|
|
m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge;
|
2013-05-14 18:47:01 +00:00
|
|
|
m_FilledPolysList.Append( aZone.m_FilledPolysList );
|
|
|
|
m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
|
2012-05-29 18:10:56 +00:00
|
|
|
|
2012-07-13 18:55:29 +00:00
|
|
|
m_isKeepout = aZone.m_isKeepout;
|
2012-07-14 16:27:25 +00:00
|
|
|
m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
|
2012-07-13 18:55:29 +00:00
|
|
|
m_doNotAllowVias = aZone.m_doNotAllowVias;
|
|
|
|
m_doNotAllowTracks = aZone.m_doNotAllowTracks;
|
|
|
|
|
|
|
|
m_cornerSmoothingType = aZone.m_cornerSmoothingType;
|
|
|
|
m_cornerRadius = aZone.m_cornerRadius;
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
m_hatchStyle = aZone.m_hatchStyle;
|
|
|
|
m_hatchPitch = aZone.m_hatchPitch;
|
|
|
|
m_HatchLines = aZone.m_HatchLines;
|
|
|
|
|
2017-09-29 16:49:09 +00:00
|
|
|
SetLayerSet( aZone.GetLayerSet() );
|
2013-03-26 09:58:40 +00:00
|
|
|
SetLocalFlags( aZone.GetLocalFlags() );
|
2019-03-14 13:35:55 +00:00
|
|
|
|
|
|
|
SetNeedRefill( aZone.NeedRefill() );
|
2012-01-14 19:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
ZONE_CONTAINER& ZONE_CONTAINER::operator=( const ZONE_CONTAINER& aOther )
|
|
|
|
{
|
|
|
|
BOARD_CONNECTED_ITEM::operator=( aOther );
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Replace the outlines for aOther outlines.
|
|
|
|
delete m_Poly;
|
|
|
|
m_Poly = new SHAPE_POLY_SET( *aOther.m_Poly );
|
|
|
|
|
|
|
|
m_CornerSelection = nullptr; // for corner moving, corner index to (null if no selection)
|
2016-05-31 08:27:52 +00:00
|
|
|
m_ZoneClearance = aOther.m_ZoneClearance; // clearance value
|
|
|
|
m_ZoneMinThickness = aOther.m_ZoneMinThickness;
|
|
|
|
m_FillMode = aOther.m_FillMode; // filling mode (segments/polygons)
|
|
|
|
m_ArcToSegmentsCount = aOther.m_ArcToSegmentsCount;
|
|
|
|
m_PadConnection = aOther.m_PadConnection;
|
|
|
|
m_ThermalReliefGap = aOther.m_ThermalReliefGap;
|
|
|
|
m_ThermalReliefCopperBridge = aOther.m_ThermalReliefCopperBridge;
|
2017-03-07 12:06:00 +00:00
|
|
|
SetHatchStyle( aOther.GetHatchStyle() );
|
|
|
|
SetHatchPitch( aOther.GetHatchPitch() );
|
|
|
|
m_HatchLines = aOther.m_HatchLines; // copy vector <SEG>
|
2016-05-31 08:27:52 +00:00
|
|
|
m_FilledPolysList.RemoveAllContours();
|
|
|
|
m_FilledPolysList.Append( aOther.m_FilledPolysList );
|
|
|
|
m_FillSegmList.clear();
|
|
|
|
m_FillSegmList = aOther.m_FillSegmList;
|
|
|
|
|
2017-09-29 16:49:09 +00:00
|
|
|
SetLayerSet( aOther.GetLayerSet() );
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-04 12:27:16 +00:00
|
|
|
ZONE_CONTAINER::~ZONE_CONTAINER()
|
2007-12-09 12:59:06 +00:00
|
|
|
{
|
2008-01-31 20:53:44 +00:00
|
|
|
delete m_Poly;
|
2017-03-07 12:06:00 +00:00
|
|
|
delete m_CornerSelection;
|
2007-12-09 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2012-03-17 14:39:27 +00:00
|
|
|
EDA_ITEM* ZONE_CONTAINER::Clone() const
|
2012-01-14 19:50:32 +00:00
|
|
|
{
|
|
|
|
return new ZONE_CONTAINER( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-16 16:04:49 +00:00
|
|
|
bool ZONE_CONTAINER::UnFill()
|
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
bool change = ( !m_FilledPolysList.IsEmpty() ) ||
|
2013-05-09 19:08:12 +00:00
|
|
|
( m_FillSegmList.size() > 0 );
|
2011-07-16 16:04:49 +00:00
|
|
|
|
2013-05-14 18:47:01 +00:00
|
|
|
m_FilledPolysList.RemoveAllContours();
|
2011-07-16 16:04:49 +00:00
|
|
|
m_FillSegmList.clear();
|
|
|
|
m_IsFilled = false;
|
|
|
|
|
|
|
|
return change;
|
|
|
|
}
|
2007-12-09 12:59:06 +00:00
|
|
|
|
2011-10-17 20:01:27 +00:00
|
|
|
|
2017-12-18 17:24:25 +00:00
|
|
|
const wxPoint ZONE_CONTAINER::GetPosition() const
|
2008-10-29 15:26:53 +00:00
|
|
|
{
|
2017-12-18 17:24:25 +00:00
|
|
|
return (wxPoint) GetCornerPosition( 0 );
|
2011-11-29 17:25:30 +00:00
|
|
|
}
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2011-11-24 17:32:51 +00:00
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
PCB_LAYER_ID ZONE_CONTAINER::GetLayer() const
|
|
|
|
{
|
|
|
|
return BOARD_ITEM::GetLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ZONE_CONTAINER::IsOnCopperLayer() const
|
|
|
|
{
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
return ( m_layerSet & LSET::AllCuMask() ).count() > 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return IsCopperLayer( GetLayer() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ZONE_CONTAINER::CommonLayerExists( const LSET aLayerSet ) const
|
|
|
|
{
|
|
|
|
LSET common = GetLayerSet() & aLayerSet;
|
|
|
|
|
|
|
|
return common.count() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::SetLayer( PCB_LAYER_ID aLayer )
|
|
|
|
{
|
|
|
|
SetLayerSet( LSET( aLayer ) );
|
|
|
|
|
|
|
|
m_Layer = aLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::SetLayerSet( LSET aLayerSet )
|
|
|
|
{
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
// Keepouts can only exist on copper layers
|
|
|
|
aLayerSet &= LSET::AllCuMask();
|
|
|
|
}
|
|
|
|
|
2017-09-29 16:49:09 +00:00
|
|
|
if( aLayerSet.count() == 0 )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-14 13:35:55 +00:00
|
|
|
if( m_layerSet != aLayerSet )
|
|
|
|
SetNeedRefill( true );
|
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
m_layerSet = aLayerSet;
|
|
|
|
|
|
|
|
// Set the single layer to the first selected layer
|
|
|
|
m_Layer = aLayerSet.Seq()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LSET ZONE_CONTAINER::GetLayerSet() const
|
|
|
|
{
|
|
|
|
// TODO - Enable multi-layer zones for all zone types
|
|
|
|
// not just keepout zones
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
return m_layerSet;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return LSET( m_Layer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const
|
|
|
|
{
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
LSEQ layers = m_layerSet.Seq();
|
|
|
|
|
|
|
|
for( unsigned int idx = 0; idx < layers.size(); idx++ )
|
|
|
|
{
|
|
|
|
aLayers[idx] = layers[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
aCount = layers.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aLayers[0] = m_Layer;
|
|
|
|
aCount = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ZONE_CONTAINER::IsOnLayer( PCB_LAYER_ID aLayer ) const
|
|
|
|
{
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
return m_layerSet.test( aLayer );
|
|
|
|
}
|
|
|
|
|
|
|
|
return BOARD_ITEM::IsOnLayer( aLayer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 14:50:12 +00:00
|
|
|
void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
|
|
|
|
const wxPoint& offset )
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2014-06-29 13:05:51 +00:00
|
|
|
if( !DC )
|
2008-01-31 20:53:44 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
wxPoint seg_start, seg_end;
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
|
2014-06-29 13:05:51 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
|
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
PCB_LAYER_ID draw_layer = UNDEFINED_LAYER;
|
|
|
|
|
|
|
|
LSET layers = GetLayerSet() & brd->GetVisibleLayers();
|
|
|
|
|
|
|
|
// If there are no visible layers and the zone is not highlighted, return
|
|
|
|
if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keepout zones can exist on multiple layers
|
|
|
|
* Thus, determining which color to use to render them is a bit tricky.
|
|
|
|
* In descending order of priority:
|
|
|
|
*
|
|
|
|
* 1. If in GR_HIGHLIGHT mode:
|
|
|
|
* a. If zone is on selected layer, use layer color!
|
|
|
|
* b. Else, use grey
|
|
|
|
* 1. Not in GR_HIGHLIGHT mode
|
|
|
|
* a. If zone is on selected layer, use layer color
|
|
|
|
* b. Else, use color of top-most (visible) layer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
// At least one layer must be provided!
|
|
|
|
assert( GetLayerSet().count() > 0 );
|
|
|
|
|
|
|
|
// Not on any visible layer?
|
|
|
|
if( layers.count() == 0 && !( aDrawMode & GR_HIGHLIGHT ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is keepout zone present on the selected layer?
|
|
|
|
if( layers.test( curr_layer ) )
|
|
|
|
{
|
|
|
|
draw_layer = curr_layer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Select the first (top) visible layer
|
|
|
|
if( layers.count() > 0 )
|
|
|
|
{
|
|
|
|
draw_layer = layers.Seq()[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
draw_layer = GetLayerSet().Seq()[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/* Non-keepout zones are easier to deal with
|
|
|
|
*/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_layer = GetLayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( draw_layer != UNDEFINED_LAYER );
|
|
|
|
|
|
|
|
auto color = frame->Settings().Colors().GetLayerColor( draw_layer );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
GRSetDrawMode( DC, aDrawMode );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts->m_ContrastModeDisplay )
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( curr_layer ) )
|
2017-10-30 17:21:07 +00:00
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2017-10-30 17:21:07 +00:00
|
|
|
}
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
|
2017-10-30 17:21:07 +00:00
|
|
|
{
|
2017-02-20 16:57:41 +00:00
|
|
|
color.SetToLegacyHighlightColor();
|
2017-10-30 17:21:07 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
color.a = 0.588;
|
2008-12-03 10:32:53 +00:00
|
|
|
|
2007-12-29 19:15:58 +00:00
|
|
|
// draw the lines
|
2010-10-13 19:50:23 +00:00
|
|
|
std::vector<wxPoint> lines;
|
2011-01-20 18:40:33 +00:00
|
|
|
lines.reserve( (GetNumCorners() * 2) + 2 );
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Iterate through the segments of the outline
|
|
|
|
for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Create the segment
|
|
|
|
SEG segment = *iterator;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
lines.push_back( static_cast<wxPoint>( segment.A ) + offset );
|
|
|
|
lines.push_back( static_cast<wxPoint>( segment.B ) + offset );
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
|
2008-01-31 20:53:44 +00:00
|
|
|
|
|
|
|
// draw hatches
|
2010-10-13 19:50:23 +00:00
|
|
|
lines.clear();
|
2017-03-07 12:06:00 +00:00
|
|
|
lines.reserve( (m_HatchLines.size() * 2) + 2 );
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( unsigned ic = 0; ic < m_HatchLines.size(); ic++ )
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
seg_start = static_cast<wxPoint>( m_HatchLines[ic].A ) + offset;
|
|
|
|
seg_end = static_cast<wxPoint>( m_HatchLines[ic].B ) + offset;
|
2010-10-13 19:50:23 +00:00
|
|
|
lines.push_back( seg_start );
|
|
|
|
lines.push_back( seg_end );
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
2010-12-14 15:56:30 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
|
2012-09-01 13:38:27 +00:00
|
|
|
wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2017-10-30 17:21:07 +00:00
|
|
|
|
2012-08-03 15:43:15 +00:00
|
|
|
static std::vector <wxPoint> CornersBuffer;
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
|
2009-01-05 05:21:35 +00:00
|
|
|
|
2008-12-12 21:30:07 +00:00
|
|
|
// outline_mode is false to show filled polys,
|
|
|
|
// and true to show polygons outlines only (test and debug purposes)
|
2015-01-10 10:27:49 +00:00
|
|
|
bool outline_mode = displ_opts->m_DisplayZonesMode == 2 ? true : false;
|
2008-09-26 19:51:36 +00:00
|
|
|
|
|
|
|
if( DC == NULL )
|
|
|
|
return;
|
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts->m_DisplayZonesMode == 1 ) // Do not show filled areas
|
2008-09-26 19:51:36 +00:00
|
|
|
return;
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( m_FilledPolysList.IsEmpty() ) // Nothing to draw
|
2008-09-26 19:51:36 +00:00
|
|
|
return;
|
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
BOARD* brd = GetBoard();
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
|
2017-08-04 12:43:02 +00:00
|
|
|
|
|
|
|
auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
|
2008-09-26 19:51:36 +00:00
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
if( brd->IsLayerVisible( GetLayer() ) == false && !( aDrawMode & GR_HIGHLIGHT ) )
|
2008-09-26 19:51:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, aDrawMode );
|
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts->m_ContrastModeDisplay )
|
2008-09-26 19:51:36 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( curr_layer ) )
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2008-09-26 19:51:36 +00:00
|
|
|
}
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
if( ( aDrawMode & GR_HIGHLIGHT ) && !( aDrawMode & GR_AND ) )
|
|
|
|
color.SetToLegacyHighlightColor();
|
2008-09-26 19:51:36 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
color.a = 0.588;
|
2008-09-26 19:51:36 +00:00
|
|
|
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for ( int ic = 0; ic < m_FilledPolysList.OutlineCount(); ic++ )
|
2015-07-14 20:23:13 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const SHAPE_LINE_CHAIN& path = m_FilledPolysList.COutline( ic );
|
|
|
|
|
|
|
|
CornersBuffer.clear();
|
|
|
|
|
|
|
|
wxPoint p0;
|
2015-07-14 11:36:24 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int j = 0; j < path.PointCount(); j++ )
|
2015-07-14 11:36:24 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
const VECTOR2I& corner = path.CPoint( j );
|
2015-07-14 20:23:13 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
wxPoint coord( corner.x + offset.x, corner.y + offset.y );
|
|
|
|
|
|
|
|
if( j == 0 )
|
|
|
|
p0 = coord;
|
2015-07-14 11:36:24 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
CornersBuffer.push_back( coord );
|
2015-07-14 20:23:13 +00:00
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
|
|
|
|
CornersBuffer.push_back( p0 );
|
|
|
|
|
|
|
|
// Draw outlines:
|
|
|
|
if( ( m_ZoneMinThickness > 1 ) || outline_mode )
|
|
|
|
{
|
|
|
|
int ilim = CornersBuffer.size() - 1;
|
|
|
|
|
2019-03-06 15:34:21 +00:00
|
|
|
int line_thickness = m_ZoneMinThickness;
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
|
|
|
|
{
|
|
|
|
// Draw only basic outlines, not extra segments.
|
|
|
|
if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
|
|
|
|
GRCSegm( panel->GetClipBox(), DC,
|
2019-03-06 15:34:21 +00:00
|
|
|
CornersBuffer[is], CornersBuffer[ie], line_thickness, color );
|
2015-07-27 19:45:57 +00:00
|
|
|
else
|
2019-03-06 15:34:21 +00:00
|
|
|
GRFilledSegment( panel->GetClipBox(), DC,
|
|
|
|
CornersBuffer[is], CornersBuffer[ie], line_thickness, color );
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw areas:
|
2018-02-18 09:09:13 +00:00
|
|
|
if( m_FillMode != ZFM_SEGMENTS && !outline_mode )
|
2015-07-27 19:45:57 +00:00
|
|
|
GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
|
|
|
|
true, 0, color, color );
|
2008-09-26 19:51:36 +00:00
|
|
|
}
|
2009-08-06 18:30:46 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
if( m_FillMode == ZFM_SEGMENTS && !outline_mode ) // filled with segments
|
2009-08-06 18:30:46 +00:00
|
|
|
{
|
|
|
|
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
|
|
|
{
|
2017-12-04 18:06:47 +00:00
|
|
|
wxPoint start = (wxPoint) ( m_FillSegmList[ic].A + VECTOR2I(offset) );
|
|
|
|
wxPoint end = (wxPoint) ( m_FillSegmList[ic].B + VECTOR2I(offset) );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( !displ_opts->m_DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
|
2011-12-29 20:11:42 +00:00
|
|
|
GRCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
|
2010-12-10 19:47:44 +00:00
|
|
|
m_ZoneMinThickness, color );
|
2009-08-06 18:30:46 +00:00
|
|
|
else
|
2011-12-29 20:11:42 +00:00
|
|
|
GRFillCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
|
2010-12-10 19:47:44 +00:00
|
|
|
m_ZoneMinThickness, color );
|
2009-08-06 18:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-26 19:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
const EDA_RECT ZONE_CONTAINER::GetBoundingBox() const
|
2008-05-02 05:16:35 +00:00
|
|
|
{
|
2008-09-26 19:51:36 +00:00
|
|
|
const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
|
2008-05-02 05:16:35 +00:00
|
|
|
|
2008-09-26 19:51:36 +00:00
|
|
|
int ymax = -PRELOAD;
|
|
|
|
int ymin = PRELOAD;
|
|
|
|
int xmin = PRELOAD;
|
|
|
|
int xmax = -PRELOAD;
|
2008-05-02 05:16:35 +00:00
|
|
|
|
2008-09-26 19:51:36 +00:00
|
|
|
int count = GetNumCorners();
|
2008-05-02 05:16:35 +00:00
|
|
|
|
2011-01-20 18:40:33 +00:00
|
|
|
for( int i = 0; i<count; ++i )
|
2008-05-02 05:16:35 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
wxPoint corner = static_cast<wxPoint>( GetCornerPosition( i ) );
|
2008-05-02 05:16:35 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
ymax = std::max( ymax, corner.y );
|
|
|
|
xmax = std::max( xmax, corner.x );
|
|
|
|
ymin = std::min( ymin, corner.y );
|
|
|
|
xmin = std::min( xmin, corner.x );
|
2008-05-02 05:16:35 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
|
2008-05-02 05:16:35 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-01 13:38:27 +00:00
|
|
|
void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC,
|
|
|
|
GR_DRAWMODE draw_mode )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2012-09-01 13:38:27 +00:00
|
|
|
GR_DRAWMODE current_gr_mode = draw_mode;
|
2008-09-26 19:51:36 +00:00
|
|
|
bool is_close_segment = false;
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2014-06-29 13:05:51 +00:00
|
|
|
if( !DC )
|
2008-01-31 20:53:44 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-13 03:19:33 +00:00
|
|
|
PCB_LAYER_ID curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
|
2017-08-04 12:43:02 +00:00
|
|
|
|
|
|
|
auto frame = static_cast<PCB_BASE_FRAME*> ( panel->GetParent() );
|
2017-10-30 17:21:07 +00:00
|
|
|
auto color = frame->Settings().Colors().GetLayerColor( GetLayer() );
|
2017-08-04 12:43:02 +00:00
|
|
|
|
2017-10-30 17:21:07 +00:00
|
|
|
auto displ_opts = (PCB_DISPLAY_OPTIONS*)( panel->GetDisplayOptions() );
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
if( displ_opts->m_ContrastModeDisplay )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
|
|
|
if( !IsOnLayer( curr_layer ) )
|
2017-02-20 16:57:41 +00:00
|
|
|
color = COLOR4D( DARKDARKGRAY );
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Object to iterate through the corners of the outlines
|
|
|
|
SHAPE_POLY_SET::ITERATOR iterator = m_Poly->Iterate();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Segment start and end
|
|
|
|
VECTOR2I seg_start, seg_end;
|
|
|
|
|
|
|
|
// Remember the first point of this contour
|
|
|
|
VECTOR2I contour_first_point = *iterator;
|
|
|
|
|
|
|
|
// Iterate through all the corners of the outlines and build the segments to draw
|
|
|
|
while( iterator )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Get the first point of the current segment
|
|
|
|
seg_start = *iterator;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Get the last point of the current segment, handling the case where the end of the
|
|
|
|
// contour is reached, when the last point of the segment is the first point of the
|
|
|
|
// contour
|
|
|
|
if( !iterator.IsEndContour() )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Set GR mode to default
|
|
|
|
current_gr_mode = draw_mode;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_POLY_SET::ITERATOR iterator_copy = iterator;
|
|
|
|
iterator_copy++;
|
|
|
|
if( iterator_copy.IsEndContour() )
|
2008-03-04 04:22:27 +00:00
|
|
|
current_gr_mode = GR_XOR;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
|
|
|
is_close_segment = false;
|
|
|
|
|
|
|
|
iterator++;
|
|
|
|
seg_end = *iterator;
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
2017-03-07 12:06:00 +00:00
|
|
|
else
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2008-03-04 04:22:27 +00:00
|
|
|
is_close_segment = true;
|
2008-10-19 18:18:45 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
seg_end = contour_first_point;
|
|
|
|
|
|
|
|
// Reassign first point of the contour to the next contour start
|
|
|
|
iterator++;
|
|
|
|
|
|
|
|
if( iterator )
|
|
|
|
contour_first_point = *iterator;
|
|
|
|
|
|
|
|
// Set GR mode to XOR
|
|
|
|
current_gr_mode = GR_XOR;
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-03-04 04:22:27 +00:00
|
|
|
GRSetDrawMode( DC, current_gr_mode );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-09-26 19:51:36 +00:00
|
|
|
if( is_close_segment )
|
2017-03-07 12:06:00 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
|
|
|
|
WHITE );
|
2008-03-04 04:22:27 +00:00
|
|
|
else
|
2017-03-07 12:06:00 +00:00
|
|
|
GRLine( panel->GetClipBox(), DC, seg_start.x, seg_start.y, seg_end.x, seg_end.y, 0,
|
|
|
|
color );
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
2007-12-09 12:59:06 +00:00
|
|
|
}
|
|
|
|
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2012-03-08 20:44:03 +00:00
|
|
|
int ZONE_CONTAINER::GetThermalReliefGap( D_PAD* aPad ) const
|
|
|
|
{
|
|
|
|
if( aPad == NULL || aPad->GetThermalGap() == 0 )
|
|
|
|
return m_ThermalReliefGap;
|
|
|
|
else
|
|
|
|
return aPad->GetThermalGap();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ZONE_CONTAINER::GetThermalReliefCopperBridge( D_PAD* aPad ) const
|
|
|
|
{
|
|
|
|
if( aPad == NULL || aPad->GetThermalWidth() == 0 )
|
|
|
|
return m_ThermalReliefCopperBridge;
|
|
|
|
else
|
|
|
|
return aPad->GetThermalWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-15 12:49:11 +00:00
|
|
|
void ZONE_CONTAINER::SetCornerRadius( unsigned int aRadius )
|
|
|
|
{
|
2019-03-14 13:35:55 +00:00
|
|
|
if( m_cornerRadius != aRadius )
|
|
|
|
SetNeedRefill( true );
|
|
|
|
|
2015-05-15 12:49:11 +00:00
|
|
|
m_cornerRadius = aRadius;
|
2017-11-02 20:41:29 +00:00
|
|
|
}
|
2015-05-15 12:49:11 +00:00
|
|
|
|
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) const
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2018-11-17 00:34:12 +00:00
|
|
|
// Normally accuracy is zoom-relative, but for the generic HitTest we just use
|
|
|
|
// a fixed (small) value.
|
|
|
|
int accuracy = Millimeter2iu( 0.05 );
|
|
|
|
|
|
|
|
return HitTestForCorner( aPosition, accuracy * 2 ) || HitTestForEdge( aPosition, accuracy );
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2018-11-17 00:34:12 +00:00
|
|
|
void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition, int aAccuracy )
|
2014-05-04 17:08:36 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_POLY_SET::VERTEX_INDEX corner;
|
2014-05-04 17:08:36 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// If there is some corner to be selected, assign it to m_CornerSelection
|
2018-11-17 00:34:12 +00:00
|
|
|
if( HitTestForCorner( aPosition, aAccuracy * 2, corner )
|
|
|
|
|| HitTestForEdge( aPosition, aAccuracy, corner ) )
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
|
|
|
if( m_CornerSelection == nullptr )
|
|
|
|
m_CornerSelection = new SHAPE_POLY_SET::VERTEX_INDEX;
|
2014-05-04 17:08:36 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
*m_CornerSelection = corner;
|
|
|
|
}
|
|
|
|
}
|
2014-05-04 17:08:36 +00:00
|
|
|
|
2018-11-17 00:34:12 +00:00
|
|
|
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy,
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2018-11-17 00:34:12 +00:00
|
|
|
return m_Poly->CollideVertex( VECTOR2I( refPos ), aCornerHit, aAccuracy );
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2018-11-17 00:34:12 +00:00
|
|
|
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos, int aAccuracy ) const
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET::VERTEX_INDEX dummy;
|
2018-11-17 00:34:12 +00:00
|
|
|
return HitTestForCorner( refPos, aAccuracy, dummy );
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-17 00:34:12 +00:00
|
|
|
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy,
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_POLY_SET::VERTEX_INDEX& aCornerHit ) const
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
2018-11-17 00:34:12 +00:00
|
|
|
return m_Poly->CollideEdge( VECTOR2I( refPos ), aCornerHit, aAccuracy );
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-17 00:34:12 +00:00
|
|
|
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos, int aAccuracy ) const
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET::VERTEX_INDEX dummy;
|
2018-11-17 00:34:12 +00:00
|
|
|
return HitTestForEdge( refPos, aAccuracy, dummy );
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2017-05-01 12:10:24 +00:00
|
|
|
// Calculate bounding box for zone
|
|
|
|
EDA_RECT bbox = GetBoundingBox();
|
2014-11-08 12:25:29 +00:00
|
|
|
bbox.Normalize();
|
2013-09-21 18:09:41 +00:00
|
|
|
|
2017-05-01 12:10:24 +00:00
|
|
|
EDA_RECT arect = aRect;
|
|
|
|
arect.Normalize();
|
|
|
|
arect.Inflate( aAccuracy );
|
|
|
|
|
2013-09-21 18:09:41 +00:00
|
|
|
if( aContained )
|
2017-05-01 12:10:24 +00:00
|
|
|
{
|
|
|
|
return arect.Contains( bbox );
|
|
|
|
}
|
2017-03-07 12:06:00 +00:00
|
|
|
else // Test for intersection between aBox and the polygon
|
2013-09-21 18:09:41 +00:00
|
|
|
// For a polygon, using its bounding box has no sense here
|
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
// Fast test: if aBox is outside the polygon bounding box,
|
2013-09-21 18:09:41 +00:00
|
|
|
// rectangles cannot intersect
|
2017-05-01 12:10:24 +00:00
|
|
|
if( !arect.Intersects( bbox ) )
|
2013-09-21 18:09:41 +00:00
|
|
|
return false;
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// aBox is inside the polygon bounding box,
|
2013-09-21 18:09:41 +00:00
|
|
|
// and can intersect the polygon: use a fine test.
|
2017-03-07 12:06:00 +00:00
|
|
|
// aBox intersects the polygon if at least one aBox corner
|
2013-09-21 18:09:41 +00:00
|
|
|
// is inside the polygon
|
2017-05-02 07:14:07 +00:00
|
|
|
|
|
|
|
/*
|
2017-05-01 12:10:24 +00:00
|
|
|
wxPoint origin = arect.GetOrigin();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-05-01 12:10:24 +00:00
|
|
|
int w = arect.GetWidth();
|
|
|
|
int h = arect.GetHeight();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2017-05-02 07:14:07 +00:00
|
|
|
|
2017-05-01 12:10:24 +00:00
|
|
|
if ( HitTestInsideZone( origin ) ||
|
|
|
|
HitTestInsideZone( origin + wxPoint( w, 0 ) ) ||
|
|
|
|
HitTestInsideZone( origin + wxPoint( w, h ) ) ||
|
|
|
|
HitTestInsideZone( origin + wxPoint( 0, h ) ) )
|
|
|
|
{
|
2013-09-21 18:09:41 +00:00
|
|
|
return true;
|
2017-05-01 12:10:24 +00:00
|
|
|
}
|
2017-05-02 07:14:07 +00:00
|
|
|
*/
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// No corner inside aBox, but outlines can intersect aBox
|
|
|
|
// if one of outline corners is inside aBox
|
|
|
|
int count = m_Poly->TotalVertices();
|
2013-09-21 18:09:41 +00:00
|
|
|
for( int ii =0; ii < count; ii++ )
|
|
|
|
{
|
2017-05-01 12:10:24 +00:00
|
|
|
auto vertex = m_Poly->Vertex( ii );
|
|
|
|
auto vertexNext = m_Poly->Vertex( ( ii + 1 ) % count );
|
|
|
|
|
|
|
|
// Test if the point is within the rect
|
|
|
|
if( arect.Contains( ( wxPoint ) vertex ) )
|
|
|
|
{
|
2013-09-21 18:09:41 +00:00
|
|
|
return true;
|
2017-05-01 12:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test if this edge intersects the rect
|
|
|
|
if( arect.Intersects( ( wxPoint ) vertex, ( wxPoint ) vertexNext ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-21 18:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2011-08-09 03:41:20 +00:00
|
|
|
int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
|
|
|
|
{
|
|
|
|
int myClearance = m_ZoneClearance;
|
|
|
|
|
2017-08-26 06:55:32 +00:00
|
|
|
#if 1 // Maybe the netclass clearance should not come into play for a zone?
|
2011-08-09 14:13:01 +00:00
|
|
|
// At least the policy decision can be controlled by the zone
|
|
|
|
// itself, i.e. here. On reasons of insufficient documentation,
|
|
|
|
// the user will be less bewildered if we simply respect the
|
|
|
|
// "zone clearance" setting in the zone properties dialog. (At least
|
|
|
|
// until there is a UI boolean for this.)
|
2011-08-09 03:41:20 +00:00
|
|
|
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR myClass = GetNetClass();
|
2011-08-09 14:13:01 +00:00
|
|
|
|
|
|
|
if( myClass )
|
|
|
|
myClearance = std::max( myClearance, myClass->GetClearance() );
|
2011-08-09 03:41:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if( aItem )
|
|
|
|
{
|
|
|
|
int hisClearance = aItem->GetClearance( NULL );
|
2012-08-03 15:43:15 +00:00
|
|
|
myClearance = std::max( hisClearance, myClearance );
|
2011-08-09 03:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return myClearance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-15 14:31:16 +00:00
|
|
|
bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
|
2008-11-27 10:12:46 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
return m_FilledPolysList.Contains( VECTOR2I( aRefPos.x, aRefPos.y ) );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
void ZONE_CONTAINER::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
|
2007-12-29 19:15:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2008-01-31 20:53:44 +00:00
|
|
|
|
|
|
|
msg = _( "Zone Outline" );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
// Display Cutout instead of Outline for holes inside a zone
|
|
|
|
// i.e. when num contour !=0
|
2017-03-07 12:06:00 +00:00
|
|
|
// Check whether the selected corner is in a hole; i.e., in any contour but the first one.
|
|
|
|
if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
|
2008-01-31 20:53:44 +00:00
|
|
|
msg << wxT( " " ) << _( "(Cutout)" );
|
2008-01-05 13:37:51 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
msg.Empty();
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( GetDoNotAllowVias() )
|
2014-11-15 19:06:05 +00:00
|
|
|
AccumulateDescription( msg, _( "No via" ) );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( GetDoNotAllowTracks() )
|
2013-04-07 11:55:18 +00:00
|
|
|
AccumulateDescription( msg, _("No track") );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( GetDoNotAllowCopperPour() )
|
2013-04-07 11:55:18 +00:00
|
|
|
AccumulateDescription( msg, _("No copper pour") );
|
2012-11-23 09:10:37 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
|
2012-11-23 09:10:37 +00:00
|
|
|
}
|
|
|
|
else if( IsOnCopperLayer() )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( GetNetCode() >= 0 )
|
2008-09-26 19:51:36 +00:00
|
|
|
{
|
2015-01-22 12:06:34 +00:00
|
|
|
NETINFO_ITEM* net = GetNet();
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2015-01-22 12:06:34 +00:00
|
|
|
if( net )
|
|
|
|
msg = net->GetNetname();
|
|
|
|
else // Should not occur
|
|
|
|
msg = _( "<unknown>" );
|
2008-09-26 19:51:36 +00:00
|
|
|
}
|
2015-01-22 12:06:34 +00:00
|
|
|
else // a netcode < 0 is an error
|
|
|
|
msg = wxT( "<error>" );
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
|
|
|
|
|
2012-01-29 19:29:19 +00:00
|
|
|
// Display net code : (useful in test or debug)
|
2014-02-25 10:40:34 +00:00
|
|
|
msg.Printf( wxT( "%d" ), GetNetCode() );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
|
2012-01-29 19:29:19 +00:00
|
|
|
|
|
|
|
// Display priority level
|
|
|
|
msg.Printf( wxT( "%d" ), GetPriority() );
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
|
2008-09-26 19:51:36 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2013-01-12 17:32:24 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2013-04-07 11:55:18 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BROWN ) );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
msg.Printf( wxT( "%d" ), (int) m_Poly->TotalVertices() );
|
2018-02-18 09:09:13 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Vertices" ), msg, BLUE ) );
|
2007-12-29 19:15:58 +00:00
|
|
|
|
2018-02-18 09:09:13 +00:00
|
|
|
switch( m_FillMode )
|
|
|
|
{
|
|
|
|
case ZFM_POLYGONS:
|
|
|
|
msg = _( "Polygons" ); break;
|
|
|
|
case ZFM_HATCH_PATTERN:
|
|
|
|
msg = _( "Hatch Fill" ); break;
|
|
|
|
case ZFM_SEGMENTS: // Deprecated: found in old boards
|
|
|
|
msg = _( "Segments" ); break;
|
|
|
|
default:
|
|
|
|
msg = _( "Unknown" ); break;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Fill Mode" ), msg, BROWN ) );
|
2008-10-07 09:32:56 +00:00
|
|
|
|
2008-10-08 12:36:27 +00:00
|
|
|
// Useful for statistics :
|
2017-03-07 12:06:00 +00:00
|
|
|
msg.Printf( wxT( "%d" ), (int) m_HatchLines.size() );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Hatch Lines" ), msg, BLUE ) );
|
2008-10-08 12:36:27 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
if( !m_FilledPolysList.IsEmpty() )
|
2008-10-08 12:36:27 +00:00
|
|
|
{
|
2015-11-04 08:48:34 +00:00
|
|
|
msg.Printf( wxT( "%d" ), m_FilledPolysList.TotalVertices() );
|
2014-11-15 19:06:05 +00:00
|
|
|
aList.push_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg, BLUE ) );
|
2008-10-08 12:36:27 +00:00
|
|
|
}
|
2007-12-29 19:15:58 +00:00
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
|
|
|
|
|
2008-02-01 21:30:45 +00:00
|
|
|
/* Geometric transforms: */
|
2008-01-31 20:53:44 +00:00
|
|
|
|
|
|
|
void ZONE_CONTAINER::Move( const wxPoint& offset )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2008-12-03 10:32:53 +00:00
|
|
|
/* move outlines */
|
2017-03-07 12:06:00 +00:00
|
|
|
m_Poly->Move( VECTOR2I( offset ) );
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
Hatch();
|
2008-12-03 10:32:53 +00:00
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
m_FilledPolysList.Move( VECTOR2I( offset.x, offset.y ) );
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2009-08-06 18:30:46 +00:00
|
|
|
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
|
|
|
{
|
2017-12-04 18:06:47 +00:00
|
|
|
m_FillSegmList[ic].A += VECTOR2I(offset);
|
|
|
|
m_FillSegmList[ic].B += VECTOR2I(offset);
|
2009-08-06 18:30:46 +00:00
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 19:51:36 +00:00
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
void ZONE_CONTAINER::MoveEdge( const wxPoint& offset, int aEdge )
|
2008-02-01 21:30:45 +00:00
|
|
|
{
|
2017-04-16 16:32:47 +00:00
|
|
|
int next_corner;
|
2008-02-01 21:30:45 +00:00
|
|
|
|
2017-04-16 16:32:47 +00:00
|
|
|
if( m_Poly->GetNeighbourIndexes( aEdge, nullptr, &next_corner ) )
|
|
|
|
{
|
|
|
|
m_Poly->Vertex( aEdge ) += VECTOR2I( offset );
|
|
|
|
m_Poly->Vertex( next_corner ) += VECTOR2I( offset );
|
|
|
|
Hatch();
|
2019-03-14 13:35:55 +00:00
|
|
|
|
|
|
|
SetNeedRefill( true );
|
2017-04-16 16:32:47 +00:00
|
|
|
}
|
2008-02-01 21:30:45 +00:00
|
|
|
}
|
|
|
|
|
2008-01-31 20:53:44 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2009-08-01 19:58:01 +00:00
|
|
|
wxPoint pos;
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
pos = static_cast<wxPoint>( *iterator );
|
2008-01-31 20:53:44 +00:00
|
|
|
RotatePoint( &pos, centre, angle );
|
2017-03-07 12:06:00 +00:00
|
|
|
iterator->x = pos.x;
|
|
|
|
iterator->y = pos.y;
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
Hatch();
|
2009-08-01 19:58:01 +00:00
|
|
|
|
|
|
|
/* rotate filled areas: */
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
|
2015-07-27 19:45:57 +00:00
|
|
|
RotatePoint( &ic->x, &ic->y, centre.x, centre.y, angle );
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2009-08-06 18:30:46 +00:00
|
|
|
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
|
|
|
{
|
2018-06-22 23:35:07 +00:00
|
|
|
wxPoint a( m_FillSegmList[ic].A );
|
2017-12-04 18:06:47 +00:00
|
|
|
RotatePoint( &a, centre, angle );
|
|
|
|
m_FillSegmList[ic].A = a;
|
2018-06-22 23:35:07 +00:00
|
|
|
wxPoint b( m_FillSegmList[ic].B );
|
2017-12-04 18:06:47 +00:00
|
|
|
RotatePoint( &b, centre, angle );
|
|
|
|
m_FillSegmList[ic].B = a;
|
2009-08-06 18:30:46 +00:00
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 18:40:33 +00:00
|
|
|
|
|
|
|
void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
Mirror( aCentre );
|
2015-12-27 15:51:13 +00:00
|
|
|
int copperLayerCount = GetBoard()->GetCopperLayerCount();
|
2017-10-30 17:21:07 +00:00
|
|
|
|
|
|
|
if( GetIsKeepout() )
|
|
|
|
{
|
|
|
|
SetLayerSet( FlipLayerMask( GetLayerSet(), copperLayerCount ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
|
|
|
|
}
|
2009-08-01 19:26:05 +00:00
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2008-01-31 20:53:44 +00:00
|
|
|
void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
|
2008-01-31 20:53:44 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
int py = mirror_ref.y - iterator->y;
|
|
|
|
iterator->y = py + mirror_ref.y;
|
2008-01-31 20:53:44 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
Hatch();
|
2009-08-01 19:58:01 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto ic = m_FilledPolysList.Iterate(); ic; ++ic )
|
2009-08-01 19:58:01 +00:00
|
|
|
{
|
2015-07-27 19:45:57 +00:00
|
|
|
int py = mirror_ref.y - ic->y;
|
|
|
|
ic->y = py + mirror_ref.y;
|
2009-08-01 19:58:01 +00:00
|
|
|
}
|
2011-01-20 18:40:33 +00:00
|
|
|
|
2009-08-06 18:30:46 +00:00
|
|
|
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
|
|
|
|
{
|
2017-12-04 18:06:47 +00:00
|
|
|
MIRROR( m_FillSegmList[ic].A.y, mirror_ref.y );
|
2018-06-22 23:35:07 +00:00
|
|
|
MIRROR( m_FillSegmList[ic].B.y, mirror_ref.y );
|
2009-08-06 18:30:46 +00:00
|
|
|
}
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-24 23:23:46 +00:00
|
|
|
ZoneConnection ZONE_CONTAINER::GetPadConnection( D_PAD* aPad ) const
|
|
|
|
{
|
2015-08-18 14:19:17 +00:00
|
|
|
if( aPad == NULL || aPad->GetZoneConnection() == PAD_ZONE_CONN_INHERITED )
|
2012-02-24 23:23:46 +00:00
|
|
|
return m_PadConnection;
|
|
|
|
else
|
|
|
|
return aPad->GetZoneConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
|
|
|
|
{
|
|
|
|
if( aPolygon.empty() )
|
|
|
|
return;
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_LINE_CHAIN outline;
|
|
|
|
|
|
|
|
// Create an outline and populate it with the points of aPolygon
|
2012-06-09 17:00:13 +00:00
|
|
|
for( unsigned i = 0; i < aPolygon.size(); i++ )
|
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
outline.Append( VECTOR2I( aPolygon[i] ) );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
outline.SetClosed( true );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Add the outline as a new polygon in the polygon set
|
2017-04-07 06:02:26 +00:00
|
|
|
if( m_Poly->OutlineCount() == 0 )
|
|
|
|
m_Poly->AddOutline( outline );
|
|
|
|
else
|
|
|
|
m_Poly->AddHole( outline );
|
2019-03-14 13:35:55 +00:00
|
|
|
|
|
|
|
SetNeedRefill( true );
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-04-07 06:02:26 +00:00
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
bool ZONE_CONTAINER::AppendCorner( wxPoint aPosition, int aHoleIdx, bool aAllowDuplication )
|
|
|
|
{
|
|
|
|
// Ensure the main outline exists:
|
|
|
|
if( m_Poly->OutlineCount() == 0 )
|
|
|
|
m_Poly->NewOutline();
|
|
|
|
|
|
|
|
// If aHoleIdx >= 0, the corner musty be added to the hole, index aHoleIdx.
|
|
|
|
// (remember: the index of the first hole is 0)
|
|
|
|
// Return error if if does dot exist.
|
|
|
|
if( aHoleIdx >= m_Poly->HoleCount( 0 ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_Poly->Append( aPosition.x, aPosition.y, -1, aHoleIdx, aAllowDuplication );
|
|
|
|
|
2019-03-14 13:35:55 +00:00
|
|
|
SetNeedRefill( true );
|
|
|
|
|
2017-06-19 11:29:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
wxString ZONE_CONTAINER::GetSelectMenuText( EDA_UNITS_T aUnits ) const
|
2011-07-14 15:42:44 +00:00
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
// Check whether the selected contour is a hole (contour index > 0)
|
|
|
|
if( m_CornerSelection != nullptr && m_CornerSelection->m_contour > 0 )
|
2018-01-31 09:08:57 +00:00
|
|
|
text << wxT( " " ) << _( "(Cutout)" );
|
2011-07-14 15:42:44 +00:00
|
|
|
|
2013-02-07 17:56:41 +00:00
|
|
|
if( GetIsKeepout() )
|
|
|
|
text << wxT( " " ) << _( "(Keepout)" );
|
2018-01-31 09:08:57 +00:00
|
|
|
else
|
|
|
|
text << GetNetnameMsg();
|
2011-07-14 15:42:44 +00:00
|
|
|
|
2018-04-10 10:52:12 +00:00
|
|
|
return wxString::Format( _( "Zone Outline %s on %s" ), text, GetLayerName() );
|
2015-12-27 15:51:13 +00:00
|
|
|
}
|
2017-02-20 12:20:39 +00:00
|
|
|
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
int ZONE_CONTAINER::GetHatchPitch() const
|
|
|
|
{
|
|
|
|
return m_hatchPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::SetHatch( int aHatchStyle, int aHatchPitch, bool aRebuildHatch )
|
|
|
|
{
|
|
|
|
SetHatchPitch( aHatchPitch );
|
|
|
|
m_hatchStyle = (ZONE_CONTAINER::HATCH_STYLE) aHatchStyle;
|
|
|
|
|
|
|
|
if( aRebuildHatch )
|
|
|
|
Hatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::SetHatchPitch( int aPitch )
|
|
|
|
{
|
|
|
|
m_hatchPitch = aPitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ZONE_CONTAINER::UnHatch()
|
|
|
|
{
|
|
|
|
m_HatchLines.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Creates hatch lines inside the outline of the complex polygon
|
|
|
|
// sort function used in ::Hatch to sort points by descending wxPoint.x values
|
|
|
|
bool sortEndsByDescendingX( const VECTOR2I& ref, const VECTOR2I& tst )
|
|
|
|
{
|
|
|
|
return tst.x < ref.x;
|
|
|
|
}
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
void ZONE_CONTAINER::Hatch()
|
|
|
|
{
|
|
|
|
UnHatch();
|
|
|
|
|
|
|
|
if( m_hatchStyle == NO_HATCH || m_hatchPitch == 0 || m_Poly->IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// define range for hatch lines
|
|
|
|
int min_x = m_Poly->Vertex( 0 ).x;
|
|
|
|
int max_x = m_Poly->Vertex( 0 ).x;
|
|
|
|
int min_y = m_Poly->Vertex( 0 ).y;
|
|
|
|
int max_y = m_Poly->Vertex( 0 ).y;
|
|
|
|
|
|
|
|
for( auto iterator = m_Poly->IterateWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
if( iterator->x < min_x )
|
|
|
|
min_x = iterator->x;
|
|
|
|
|
|
|
|
if( iterator->x > max_x )
|
|
|
|
max_x = iterator->x;
|
|
|
|
|
|
|
|
if( iterator->y < min_y )
|
|
|
|
min_y = iterator->y;
|
|
|
|
|
|
|
|
if( iterator->y > max_y )
|
|
|
|
max_y = iterator->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate spacing between 2 hatch lines
|
|
|
|
int spacing;
|
|
|
|
|
|
|
|
if( m_hatchStyle == DIAGONAL_EDGE )
|
|
|
|
spacing = m_hatchPitch;
|
|
|
|
else
|
|
|
|
spacing = m_hatchPitch * 2;
|
|
|
|
|
|
|
|
// set the "length" of hatch lines (the length on horizontal axis)
|
|
|
|
int hatch_line_len = m_hatchPitch;
|
|
|
|
|
|
|
|
// To have a better look, give a slope depending on the layer
|
|
|
|
LAYER_NUM layer = GetLayer();
|
|
|
|
int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
|
|
|
|
double slope = 0.707106 * slope_flag; // 45 degrees slope
|
|
|
|
int max_a, min_a;
|
|
|
|
|
|
|
|
if( slope_flag == 1 )
|
|
|
|
{
|
|
|
|
max_a = KiROUND( max_y - slope * min_x );
|
|
|
|
min_a = KiROUND( min_y - slope * max_x );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
max_a = KiROUND( max_y - slope * max_x );
|
|
|
|
min_a = KiROUND( min_y - slope * min_x );
|
|
|
|
}
|
|
|
|
|
|
|
|
min_a = (min_a / spacing) * spacing;
|
|
|
|
|
|
|
|
// calculate an offset depending on layer number,
|
|
|
|
// for a better look of hatches on a multilayer board
|
|
|
|
int offset = (layer * 7) / 8;
|
|
|
|
min_a += offset;
|
|
|
|
|
|
|
|
// loop through hatch lines
|
|
|
|
#define MAXPTS 200 // Usually we store only few values per one hatch line
|
|
|
|
// depending on the complexity of the zone outline
|
|
|
|
|
|
|
|
static std::vector<VECTOR2I> pointbuffer;
|
|
|
|
pointbuffer.clear();
|
|
|
|
pointbuffer.reserve( MAXPTS + 2 );
|
|
|
|
|
|
|
|
for( int a = min_a; a < max_a; a += spacing )
|
|
|
|
{
|
|
|
|
// get intersection points for this hatch line
|
|
|
|
|
|
|
|
// Note: because we should have an even number of intersections with the
|
|
|
|
// current hatch line and the zone outline (a closed polygon,
|
|
|
|
// or a set of closed polygons), if an odd count is found
|
|
|
|
// we skip this line (should not occur)
|
|
|
|
pointbuffer.clear();
|
|
|
|
|
|
|
|
// Iterate through all vertices
|
|
|
|
for( auto iterator = m_Poly->IterateSegmentsWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
double x, y, x2, y2;
|
|
|
|
int ok;
|
|
|
|
|
|
|
|
SEG segment = *iterator;
|
|
|
|
|
|
|
|
ok = FindLineSegmentIntersection( a, slope,
|
|
|
|
segment.A.x, segment.A.y,
|
|
|
|
segment.B.x, segment.B.y,
|
|
|
|
&x, &y, &x2, &y2 );
|
|
|
|
|
|
|
|
if( ok )
|
|
|
|
{
|
|
|
|
VECTOR2I point( KiROUND( x ), KiROUND( y ) );
|
|
|
|
pointbuffer.push_back( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ok == 2 )
|
|
|
|
{
|
|
|
|
VECTOR2I point( KiROUND( x2 ), KiROUND( y2 ) );
|
|
|
|
pointbuffer.push_back( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pointbuffer.size() >= MAXPTS ) // overflow
|
|
|
|
{
|
|
|
|
wxASSERT( 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we have found an even intersection points count
|
|
|
|
// because intersections are the ends of segments
|
|
|
|
// inside the polygon(s) and a segment has 2 ends.
|
|
|
|
// if not, this is a strange case (a bug ?) so skip this hatch
|
|
|
|
if( pointbuffer.size() % 2 != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// sort points in order of descending x (if more than 2) to
|
|
|
|
// ensure the starting point and the ending point of the same segment
|
|
|
|
// are stored one just after the other.
|
|
|
|
if( pointbuffer.size() > 2 )
|
|
|
|
sort( pointbuffer.begin(), pointbuffer.end(), sortEndsByDescendingX );
|
|
|
|
|
|
|
|
// creates lines or short segments inside the complex polygon
|
|
|
|
for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
|
|
|
|
{
|
|
|
|
int dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
|
|
|
|
|
|
|
|
// Push only one line for diagonal hatch,
|
|
|
|
// or for small lines < twice the line length
|
|
|
|
// else push 2 small lines
|
2017-11-20 15:47:11 +00:00
|
|
|
if( m_hatchStyle == DIAGONAL_FULL || std::abs( dx ) < 2 * hatch_line_len )
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
|
|
|
m_HatchLines.push_back( SEG( pointbuffer[ip], pointbuffer[ip + 1] ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
|
|
|
|
slope = dy / dx;
|
|
|
|
|
|
|
|
if( dx > 0 )
|
|
|
|
dx = hatch_line_len;
|
|
|
|
else
|
|
|
|
dx = -hatch_line_len;
|
|
|
|
|
|
|
|
int x1 = KiROUND( pointbuffer[ip].x + dx );
|
|
|
|
int x2 = KiROUND( pointbuffer[ip + 1].x - dx );
|
|
|
|
int y1 = KiROUND( pointbuffer[ip].y + dx * slope );
|
|
|
|
int y2 = KiROUND( pointbuffer[ip + 1].y - dx * slope );
|
|
|
|
|
|
|
|
m_HatchLines.push_back(SEG(pointbuffer[ip].x, pointbuffer[ip].y, x1, y1));
|
|
|
|
|
|
|
|
m_HatchLines.push_back( SEG( pointbuffer[ip+1].x, pointbuffer[ip+1].y, x2, y2 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-01 13:16:51 +00:00
|
|
|
int ZONE_CONTAINER::GetDefaultHatchPitch()
|
|
|
|
{
|
|
|
|
return Mils2iu( 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-20 12:20:39 +00:00
|
|
|
BITMAP_DEF ZONE_CONTAINER::GetMenuImage() const
|
|
|
|
{
|
|
|
|
return add_zone_xpm;
|
|
|
|
}
|
2017-10-31 13:59:03 +00:00
|
|
|
|
2018-06-22 23:35:07 +00:00
|
|
|
|
2017-10-31 13:59:03 +00:00
|
|
|
void ZONE_CONTAINER::SwapData( BOARD_ITEM* aImage )
|
|
|
|
{
|
|
|
|
assert( aImage->Type() == PCB_ZONE_AREA_T );
|
|
|
|
|
|
|
|
std::swap( *((ZONE_CONTAINER*) this), *((ZONE_CONTAINER*) aImage) );
|
|
|
|
}
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2018-06-22 23:35:07 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
void ZONE_CONTAINER::CacheTriangulation()
|
|
|
|
{
|
|
|
|
m_FilledPolysList.CacheTriangulation();
|
|
|
|
}
|
2017-12-04 18:06:47 +00:00
|
|
|
|
2018-06-22 23:35:07 +00:00
|
|
|
|
2017-12-04 18:06:47 +00:00
|
|
|
bool ZONE_CONTAINER::BuildSmoothedPoly( SHAPE_POLY_SET& aSmoothedPoly ) const
|
|
|
|
{
|
|
|
|
if( GetNumCorners() <= 2 ) // malformed zone. polygon calculations do not like it ...
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Make a smoothed polygon out of the user-drawn polygon if required
|
|
|
|
switch( m_cornerSmoothingType )
|
|
|
|
{
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_CHAMFER:
|
|
|
|
aSmoothedPoly = m_Poly->Chamfer( m_cornerRadius );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZONE_SETTINGS::SMOOTHING_FILLET:
|
2018-03-22 18:02:45 +00:00
|
|
|
// Note: we're now using m_ArcToSegmentsCount only as a hint to determine accuracy
|
|
|
|
// vs. speed.
|
|
|
|
if( m_ArcToSegmentsCount > SEGMENT_COUNT_CROSSOVER )
|
|
|
|
aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_HIGH_DEF );
|
|
|
|
else
|
|
|
|
aSmoothedPoly = m_Poly->Fillet( m_cornerRadius, ARC_LOW_DEF );
|
2017-12-04 18:06:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Acute angles between adjacent edges can create issues in calculations,
|
|
|
|
// in inflate/deflate outlines transforms, especially when the angle is very small.
|
|
|
|
// We can avoid issues by creating a very small chamfer which remove acute angles,
|
|
|
|
// or left it without chamfer and use only CPOLYGONS_LIST::InflateOutline to create
|
|
|
|
// clearance areas
|
|
|
|
aSmoothedPoly = m_Poly->Chamfer( Millimeter2iu( 0.0 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
2017-12-13 23:33:20 +00:00
|
|
|
|
|
|
|
/* Function TransformOutlinesShapeWithClearanceToPolygon
|
|
|
|
* Convert the zone filled areas polygons to polygons
|
|
|
|
* inflated (optional) by max( aClearanceValue, the zone clearance)
|
|
|
|
* and copy them in aCornerBuffer
|
|
|
|
* param aClearanceValue = the clearance around polygons
|
|
|
|
* param aAddClearance = true to add a clearance area to the polygon
|
|
|
|
* false to create the outline polygon.
|
|
|
|
*/
|
|
|
|
void ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(
|
|
|
|
SHAPE_POLY_SET& aCornerBuffer, int aMinClearanceValue, bool aUseNetClearance ) const
|
|
|
|
{
|
|
|
|
// Creates the zone outline polygon (with holes if any)
|
|
|
|
SHAPE_POLY_SET polybuffer;
|
|
|
|
BuildSmoothedPoly( polybuffer );
|
|
|
|
|
|
|
|
// add clearance to outline
|
|
|
|
int clearance = aMinClearanceValue;
|
|
|
|
|
|
|
|
if( aUseNetClearance && IsOnCopperLayer() )
|
|
|
|
{
|
|
|
|
clearance = GetClearance();
|
|
|
|
if( aMinClearanceValue > clearance )
|
|
|
|
clearance = aMinClearanceValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the polygon with clearance
|
|
|
|
// holes are linked to the main outline, so only one polygon is created.
|
|
|
|
if( clearance )
|
2019-01-04 01:34:59 +00:00
|
|
|
polybuffer.Inflate( clearance, ARC_APPROX_SEGMENTS_COUNT_HIGH_DEF );
|
2017-12-13 23:33:20 +00:00
|
|
|
|
|
|
|
polybuffer.Fracture( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
aCornerBuffer.Append( polybuffer );
|
|
|
|
}
|