kicad/pcbnew/class_zone.cpp

898 lines
27 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
*/
/**
* @file class_zone.cpp
* @brief Implementation of class to handle copper zones.
*/
2007-12-09 12:59:06 +00:00
#include <fctsys.h>
#include <wxstruct.h>
#include <trigo.h>
#include <class_pcb_screen.h>
#include <class_drawpanel.h>
#include <kicad_string.h>
#include <pcbcommon.h>
#include <colors_selection.h>
#include <richio.h>
#include <macros.h>
#include <wxBasePcbFrame.h>
#include <msgpanel.h>
2007-12-09 12:59:06 +00:00
#include <class_board.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <zones.h>
#include <math_for_graphics.h>
#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
{
m_CornerSelection = -1;
m_IsFilled = false; // fill status : true when the zone is filled
m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments
2012-01-29 19:29:19 +00:00
m_priority = 0;
m_smoothedPoly = NULL;
m_cornerSmoothingType = ZONE_SETTINGS::SMOOTHING_NONE;
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
m_cornerRadius = 0;
SetLocalFlags( 0 ); // flags tempoarry used in zone calculations
m_Poly = new CPolyLine(); // Outlines
2012-02-06 05:44:19 +00:00
aBoard->GetZoneSettings().ExportSetting( *this );
2007-12-09 12:59:06 +00:00
}
ZONE_CONTAINER::ZONE_CONTAINER( const ZONE_CONTAINER& aZone ) :
BOARD_CONNECTED_ITEM( aZone )
{
// Should the copy be on the same net?
SetNetCode( aZone.GetNetCode() );
m_Poly = new CPolyLine( *aZone.m_Poly );
// For corner moving, corner index to drag, or -1 if no selection
m_CornerSelection = -1;
m_IsFilled = aZone.m_IsFilled;
m_ZoneClearance = aZone.m_ZoneClearance; // clearance value
m_ZoneMinThickness = aZone.m_ZoneMinThickness;
m_FillMode = aZone.m_FillMode; // Filling mode (segments/polygons)
2012-01-29 19:29:19 +00:00
m_priority = aZone.m_priority;
m_ArcToSegmentsCount = aZone.m_ArcToSegmentsCount;
m_PadConnection = aZone.m_PadConnection;
m_ThermalReliefGap = aZone.m_ThermalReliefGap;
m_ThermalReliefCopperBridge = aZone.m_ThermalReliefCopperBridge;
m_FilledPolysList.Append( aZone.m_FilledPolysList );
m_FillSegmList = aZone.m_FillSegmList; // vector <> copy
m_isKeepout = aZone.m_isKeepout;
m_doNotAllowCopperPour = aZone.m_doNotAllowCopperPour;
m_doNotAllowVias = aZone.m_doNotAllowVias;
m_doNotAllowTracks = aZone.m_doNotAllowTracks;
m_cornerSmoothingType = aZone.m_cornerSmoothingType;
m_cornerRadius = aZone.m_cornerRadius;
SetLocalFlags( aZone.GetLocalFlags() );
}
ZONE_CONTAINER::~ZONE_CONTAINER()
2007-12-09 12:59:06 +00:00
{
delete m_Poly;
m_Poly = NULL;
2007-12-09 12:59:06 +00:00
}
EDA_ITEM* ZONE_CONTAINER::Clone() const
{
return new ZONE_CONTAINER( *this );
}
bool ZONE_CONTAINER::UnFill()
{
bool change = ( m_FilledPolysList.GetCornersCount() > 0 ) ||
( m_FillSegmList.size() > 0 );
m_FilledPolysList.RemoveAllContours();
m_FillSegmList.clear();
m_IsFilled = false;
return change;
}
2007-12-09 12:59:06 +00:00
2012-02-20 04:33:54 +00:00
const wxPoint& ZONE_CONTAINER::GetPosition() const
{
2012-02-20 04:33:54 +00:00
static const wxPoint dummy;
2012-02-20 04:33:54 +00:00
return m_Poly ? GetCornerPosition( 0 ) : dummy;
}
void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE aDrawMode,
const wxPoint& offset )
{
if( DC == NULL )
return;
2008-03-04 04:22:27 +00:00
wxPoint seg_start, seg_end;
LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
BOARD* brd = GetBoard();
EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG )
return;
GRSetDrawMode( DC, aDrawMode );
if( DisplayOpt.ContrastModeDisplay )
{
if( !IsOnLayer( curr_layer ) )
ColorTurnToDarkDarkGray( &color );
}
if( aDrawMode & GR_HIGHLIGHT )
ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) );
ColorApplyHighlightFlag( &color );
SetAlpha( &color, 150 );
// draw the lines
int i_start_contour = 0;
std::vector<wxPoint> lines;
lines.reserve( (GetNumCorners() * 2) + 2 );
for( int ic = 0; ic < GetNumCorners(); ic++ )
{
seg_start = GetCornerPosition( ic ) + offset;
2013-05-08 18:20:58 +00:00
if( !m_Poly->m_CornersList.IsEndContour( ic ) && ic < GetNumCorners() - 1 )
{
seg_end = GetCornerPosition( ic + 1 ) + offset;
}
else
{
seg_end = GetCornerPosition( i_start_contour ) + offset;
i_start_contour = ic + 1;
}
lines.push_back( seg_start );
lines.push_back( seg_end );
}
GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
// draw hatches
lines.clear();
lines.reserve( (m_Poly->m_HatchLines.size() * 2) + 2 );
for( unsigned ic = 0; ic < m_Poly->m_HatchLines.size(); ic++ )
{
seg_start = m_Poly->m_HatchLines[ic].m_Start + offset;
seg_end = m_Poly->m_HatchLines[ic].m_End + offset;
lines.push_back( seg_start );
lines.push_back( seg_end );
}
GRLineArray( panel->GetClipBox(), DC, lines, 0, color );
}
void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
wxDC* DC, GR_DRAWMODE aDrawMode, const wxPoint& offset )
{
2012-08-03 15:43:15 +00:00
static std::vector <char> CornersTypeBuffer;
static std::vector <wxPoint> CornersBuffer;
// outline_mode is false to show filled polys,
// and true to show polygons outlines only (test and debug purposes)
bool outline_mode = DisplayOpt.DisplayZonesMode == 2 ? true : false;
if( DC == NULL )
return;
if( DisplayOpt.DisplayZonesMode == 1 ) // Do not show filled areas
return;
if( m_FilledPolysList.GetCornersCount() == 0 ) // Nothing to draw
return;
BOARD* brd = GetBoard();
LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG )
return;
GRSetDrawMode( DC, aDrawMode );
if( DisplayOpt.ContrastModeDisplay )
{
if( !IsOnLayer( curr_layer ) )
ColorTurnToDarkDarkGray( &color );
}
if( aDrawMode & GR_HIGHLIGHT )
ColorChangeHighlightFlag( &color, !(aDrawMode & GR_AND) );
ColorApplyHighlightFlag( &color );
SetAlpha( &color, 150 );
CornersTypeBuffer.clear();
CornersBuffer.clear();
// Draw all filled areas
int imax = m_FilledPolysList.GetCornersCount() - 1;
for( int ic = 0; ic <= imax; ic++ )
{
2013-05-08 18:20:58 +00:00
const CPolyPt& corner = m_FilledPolysList.GetCorner( ic );
wxPoint coord( corner.x + offset.x, corner.y + offset.y );
CornersBuffer.push_back( coord );
2013-05-08 18:20:58 +00:00
CornersTypeBuffer.push_back( (char) corner.m_utility );
// the last corner of a filled area is found: draw it
2013-05-08 18:20:58 +00:00
if( (corner.end_contour) || (ic == imax) )
{
/* Draw the current filled area: draw segments outline first
* Curiously, draw segments outline first and after draw filled polygons
* with outlines thickness = 0 is a faster than
* just draw filled polygons but with outlines thickness = m_ZoneMinThickness
* So DO NOT use draw filled polygons with outlines having a thickness > 0
* Note: Extra segments ( added to joint holes with external outline) flagged by
* m_utility != 0 are not drawn
* Note not all polygon libraries provide a flag for these extra-segments, therefore
* the m_utility member can be always 0
*/
{
// Draw outlines:
if( (m_ZoneMinThickness > 1) || outline_mode )
{
int ilim = CornersBuffer.size() - 1;
for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ )
{
int x0 = CornersBuffer[is].x;
int y0 = CornersBuffer[is].y;
int x1 = CornersBuffer[ie].x;
int y1 = CornersBuffer[ie].y;
// Draw only basic outlines, not extra segments.
if( CornersTypeBuffer[ie] == 0 )
{
if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
GRCSegm( panel->GetClipBox(), DC,
x0, y0, x1, y1,
m_ZoneMinThickness, color );
else
GRFillCSegm( panel->GetClipBox(), DC,
x0, y0, x1, y1,
m_ZoneMinThickness, color );
}
}
}
// Draw areas:
if( m_FillMode==0 && !outline_mode )
GRPoly( panel->GetClipBox(), DC, CornersBuffer.size(), &CornersBuffer[0],
true, 0, color, color );
}
CornersTypeBuffer.clear();
CornersBuffer.clear();
}
}
2009-08-06 18:30:46 +00:00
if( m_FillMode == 1 && !outline_mode ) // filled with segments
{
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
{
wxPoint start = m_FillSegmList[ic].m_Start + offset;
wxPoint end = m_FillSegmList[ic].m_End + offset;
2009-08-06 18:30:46 +00:00
if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
GRCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
m_ZoneMinThickness, color );
2009-08-06 18:30:46 +00:00
else
GRFillCSegm( panel->GetClipBox(), DC, start.x, start.y, end.x, end.y,
m_ZoneMinThickness, color );
2009-08-06 18:30:46 +00:00
}
}
}
const EDA_RECT ZONE_CONTAINER::GetBoundingBox() const
{
const int PRELOAD = 0x7FFFFFFF; // Biggest integer (32 bits)
int ymax = -PRELOAD;
int ymin = PRELOAD;
int xmin = PRELOAD;
int xmax = -PRELOAD;
int count = GetNumCorners();
for( int i = 0; i<count; ++i )
{
wxPoint corner = GetCornerPosition( i );
ymax = std::max( ymax, corner.y );
xmax = std::max( xmax, corner.x );
ymin = std::min( ymin, corner.y );
xmin = std::min( xmin, corner.x );
}
EDA_RECT ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
return ret;
}
void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC,
GR_DRAWMODE draw_mode )
{
GR_DRAWMODE current_gr_mode = draw_mode;
bool is_close_segment = false;
2008-03-04 04:22:27 +00:00
wxPoint seg_start, seg_end;
if( DC == NULL )
return;
LAYER_NUM curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
BOARD* brd = GetBoard();
EDA_COLOR_T color = brd->GetLayerColor( m_Layer );
if( DisplayOpt.ContrastModeDisplay )
{
if( !IsOnLayer( curr_layer ) )
ColorTurnToDarkDarkGray( &color );
}
// draw the lines
wxPoint start_contour_pos = GetCornerPosition( 0 );
2008-10-19 18:18:45 +00:00
int icmax = GetNumCorners() - 1;
for( int ic = 0; ic <= icmax; ic++ )
{
int xi = GetCornerPosition( ic ).x;
int yi = GetCornerPosition( ic ).y;
int xf, yf;
2013-05-08 18:20:58 +00:00
if( !m_Poly->m_CornersList.IsEndContour( ic ) && ic < icmax )
{
2008-03-04 04:22:27 +00:00
is_close_segment = false;
xf = GetCornerPosition( ic + 1 ).x;
yf = GetCornerPosition( ic + 1 ).y;
2013-05-08 18:20:58 +00:00
if( m_Poly->m_CornersList.IsEndContour( ic + 1 ) || (ic == icmax - 1) )
2008-03-04 04:22:27 +00:00
current_gr_mode = GR_XOR;
else
current_gr_mode = draw_mode;
}
else // Draw the line from last corner to the first corner of the current contour
{
2008-03-04 04:22:27 +00:00
is_close_segment = true;
current_gr_mode = GR_XOR;
xf = start_contour_pos.x;
yf = start_contour_pos.y;
2008-10-19 18:18:45 +00:00
// Prepare the next contour for drawing, if exists
2008-10-19 18:18:45 +00:00
if( ic < icmax )
start_contour_pos = GetCornerPosition( ic + 1 );
}
2008-03-04 04:22:27 +00:00
GRSetDrawMode( DC, current_gr_mode );
if( is_close_segment )
GRLine( panel->GetClipBox(), DC, xi, yi, xf, yf, 0, WHITE );
2008-03-04 04:22:27 +00:00
else
GRLine( panel->GetClipBox(), DC, xi, yi, xf, yf, 0, color );
}
2007-12-09 12:59:06 +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();
}
bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition )
{
if( HitTestForCorner( aPosition ) )
return true;
if( HitTestForEdge( aPosition ) )
return true;
return false;
}
// Zones outlines have no thickness, so it Hit Test functions
// we must have a default distance between the test point
// and a corner or a zone edge:
#define MAX_DIST_IN_MM 0.25
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
{
int distmax = Millimeter2iu( MAX_DIST_IN_MM );
m_CornerSelection = m_Poly->HitTestForCorner( refPos, distmax );
return m_CornerSelection >= 0;
}
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
{
int distmax = Millimeter2iu( MAX_DIST_IN_MM );
m_CornerSelection = m_Poly->HitTestForEdge( refPos, distmax );
return m_CornerSelection >= 0;
}
bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
2008-01-06 12:43:57 +00:00
{
EDA_RECT arect = aRect;
arect.Inflate( aAccuracy );
CRect rect = m_Poly->GetBoundingBox();
EDA_RECT bbox;
bbox.SetOrigin( rect.left, rect.bottom );
bbox.SetEnd( rect.right, rect.top );
if( aContained )
return arect.Contains( bbox );
else // Test for intersection between aRect and the polygon
// For a polygon, using its bounding box has no sense here
{
// Fast test: if aRect is outside the polygon bounding box,
// rectangles cannot intersect
if( ! bbox.Intersects( arect ) )
return false;
// aRect is inside the polygon bounding box,
// and can intersect the polygon: use a fine test.
// aRect intersects the polygon if at least one aRect corner
// is inside the polygon
wxPoint corner = arect.GetOrigin();
if( HitTestInsideZone( corner ) )
return true;
corner.x = arect.GetEnd().x;
2008-01-06 12:43:57 +00:00
if( HitTestInsideZone( corner ) )
return true;
2008-01-06 12:43:57 +00:00
corner = arect.GetEnd();
if( HitTestInsideZone( corner ) )
return true;
corner.x = arect.GetOrigin().x;
if( HitTestInsideZone( corner ) )
return true;
2008-01-06 12:43:57 +00:00
// No corner inside arect, but outlines can intersect arect
// if one of outline corners is inside arect
int count = m_Poly->GetCornersCount();
for( int ii =0; ii < count; ii++ )
{
if( arect.Contains( m_Poly->GetPos( ii ) ) )
return true;
}
return false;
}
2008-01-06 12:43:57 +00:00
}
int ZONE_CONTAINER::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
{
int myClearance = m_ZoneClearance;
2011-08-09 14:13:01 +00:00
#if 0 // Maybe the netclass clearance should not come into play for a zone?
// 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 14:13:01 +00:00
NETCLASS* myClass = GetNetClass();
if( myClass )
myClearance = std::max( myClearance, myClass->GetClearance() );
#endif
if( aItem )
{
int hisClearance = aItem->GetClearance( NULL );
2012-08-03 15:43:15 +00:00
myClearance = std::max( hisClearance, myClearance );
}
return myClearance;
}
bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos ) const
{
unsigned indexstart = 0, indexend;
bool inside = false;
for( indexend = 0; indexend < m_FilledPolysList.GetCornersCount(); indexend++ )
{
2013-05-08 18:20:58 +00:00
if( m_FilledPolysList.IsEndContour( indexend ) ) // end of a filled sub-area found
{
2013-05-08 18:20:58 +00:00
if( TestPointInsidePolygon( m_FilledPolysList, indexstart, indexend,
aRefPos.x, aRefPos.y ) )
{
inside = true;
break;
}
// Prepare test of next area which starts after the current index end (if exists)
indexstart = indexend + 1;
}
}
return inside;
}
void ZONE_CONTAINER::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
{
wxString msg;
msg = _( "Zone Outline" );
// Display Cutout instead of Outline for holes inside a zone
// i.e. when num contour !=0
int ncont = m_Poly->GetContour( m_CornerSelection );
if( ncont )
msg << wxT( " " ) << _( "(Cutout)" );
aList.push_back( MSG_PANEL_ITEM( _( "Type" ), msg, DARKCYAN ) );
if( GetIsKeepout() )
{
msg.Empty();
if( GetDoNotAllowVias() )
AccumulateDescription( msg, _("No via") );
if( GetDoNotAllowTracks() )
AccumulateDescription( msg, _("No track") );
if( GetDoNotAllowCopperPour() )
AccumulateDescription( msg, _("No copper pour") );
aList.push_back( MSG_PANEL_ITEM( _( "Keepout" ), msg, RED ) );
}
else if( IsOnCopperLayer() )
{
if( GetNetCode() >= 0 )
{
NETINFO_ITEM* equipot = GetNet();
if( equipot )
msg = equipot->GetNetname();
else
msg = wxT( "<noname>" );
}
else // a netcode < 0 is an error
{
msg = wxT( " [" );
msg << GetNetname() + wxT( "]" );
msg << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
}
aList.push_back( MSG_PANEL_ITEM( _( "NetName" ), msg, RED ) );
2012-01-29 19:29:19 +00:00
#if 1
// Display net code : (useful in test or debug)
msg.Printf( wxT( "%d" ), GetNetCode() );
aList.push_back( MSG_PANEL_ITEM( _( "NetCode" ), msg, RED ) );
2012-01-29 19:29:19 +00:00
#endif
// Display priority level
msg.Printf( wxT( "%d" ), GetPriority() );
aList.push_back( MSG_PANEL_ITEM( _( "Priority" ), msg, BLUE ) );
}
else
{
aList.push_back( MSG_PANEL_ITEM( _( "Non Copper Zone" ), wxEmptyString, RED ) );
}
aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), BROWN ) );
msg.Printf( wxT( "%d" ), (int) m_Poly->m_CornersList.GetCornersCount() );
aList.push_back( MSG_PANEL_ITEM( _( "Corners" ), msg, BLUE ) );
if( m_FillMode )
msg = _( "Segments" );
else
msg = _( "Polygons" );
aList.push_back( MSG_PANEL_ITEM( _( "Fill mode" ), msg, BROWN ) );
// Useful for statistics :
msg.Printf( wxT( "%d" ), (int) m_Poly->m_HatchLines.size() );
aList.push_back( MSG_PANEL_ITEM( _( "Hatch lines" ), msg, BLUE ) );
if( m_FilledPolysList.GetCornersCount() )
{
msg.Printf( wxT( "%d" ), (int) m_FilledPolysList.GetCornersCount() );
aList.push_back( MSG_PANEL_ITEM( _( "Corners in DrawList" ), msg, BLUE ) );
}
}
2008-01-06 12:43:57 +00:00
/* Geometric transforms: */
void ZONE_CONTAINER::Move( const wxPoint& offset )
2008-01-06 12:43:57 +00:00
{
/* move outlines */
for( unsigned ii = 0; ii < m_Poly->m_CornersList.GetCornersCount(); ii++ )
{
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
}
m_Poly->Hatch();
/* move filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
{
2013-05-08 18:20:58 +00:00
m_FilledPolysList.SetX( ic, m_FilledPolysList.GetX( ic ) + offset.x );
m_FilledPolysList.SetY( ic, m_FilledPolysList.GetY( ic ) + offset.y );
}
2009-08-06 18:30:46 +00:00
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
{
m_FillSegmList[ic].m_Start += offset;
m_FillSegmList[ic].m_End += offset;
2009-08-06 18:30:46 +00:00
}
2008-01-06 12:43:57 +00:00
}
void ZONE_CONTAINER::MoveEdge( const wxPoint& offset )
{
2008-03-04 04:22:27 +00:00
int ii = m_CornerSelection;
2008-03-04 04:22:27 +00:00
// Move the start point of the selected edge:
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
2008-03-04 04:22:27 +00:00
// Move the end point of the selected edge:
2013-05-08 18:20:58 +00:00
if( m_Poly->m_CornersList.IsEndContour( ii ) || ii == GetNumCorners() - 1 )
2008-03-04 04:22:27 +00:00
{
int icont = m_Poly->GetContour( ii );
ii = m_Poly->GetContourStart( icont );
}
else
{
2008-03-04 04:22:27 +00:00
ii++;
}
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
m_Poly->Hatch();
}
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;
for( unsigned ic = 0; ic < m_Poly->m_CornersList.GetCornersCount(); ic++ )
{
2013-05-08 18:20:58 +00:00
pos = m_Poly->m_CornersList.GetPos( ic );
RotatePoint( &pos, centre, angle );
2013-05-08 18:20:58 +00:00
m_Poly->SetX( ic, pos.x );
m_Poly->SetY( ic, pos.y );
}
m_Poly->Hatch();
2009-08-01 19:58:01 +00:00
/* rotate filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
2009-08-01 19:58:01 +00:00
{
2013-05-08 18:20:58 +00:00
pos = m_FilledPolysList.GetPos( ic );
2009-08-01 19:58:01 +00:00
RotatePoint( &pos, centre, angle );
2013-05-08 18:20:58 +00:00
m_FilledPolysList.SetX( ic, pos.x );
m_FilledPolysList.SetY( ic, pos.y );
2009-08-01 19:58:01 +00:00
}
2009-08-06 18:30:46 +00:00
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
{
RotatePoint( &m_FillSegmList[ic].m_Start, centre, angle );
RotatePoint( &m_FillSegmList[ic].m_End, centre, angle );
}
2008-01-06 12:43:57 +00:00
}
void ZONE_CONTAINER::Flip( const wxPoint& aCentre )
2009-08-01 19:26:05 +00:00
{
Mirror( aCentre );
SetLayer( FlipLayer( GetLayer() ) );
2009-08-01 19:26:05 +00:00
}
2008-01-06 12:43:57 +00:00
void ZONE_CONTAINER::Mirror( const wxPoint& mirror_ref )
2008-01-06 12:43:57 +00:00
{
for( unsigned ic = 0; ic < m_Poly->m_CornersList.GetCornersCount(); ic++ )
{
2013-05-08 18:20:58 +00:00
int py = m_Poly->m_CornersList.GetY( ic ) - mirror_ref.y;
NEGATE( py );
m_Poly->m_CornersList.SetY( ic, py + mirror_ref.y );
}
m_Poly->Hatch();
2009-08-01 19:58:01 +00:00
/* mirror filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.GetCornersCount(); ic++ )
2009-08-01 19:58:01 +00:00
{
2013-05-08 18:20:58 +00:00
int py = m_FilledPolysList.GetY( ic ) - mirror_ref.y;
NEGATE( py );
m_FilledPolysList.SetY( ic, py + mirror_ref.y );
2009-08-01 19:58:01 +00:00
}
2009-08-06 18:30:46 +00:00
for( unsigned ic = 0; ic < m_FillSegmList.size(); ic++ )
{
m_FillSegmList[ic].m_Start.y -= mirror_ref.y;
NEGATE( m_FillSegmList[ic].m_Start.y );
2009-08-06 18:30:46 +00:00
m_FillSegmList[ic].m_Start.y += mirror_ref.y;
m_FillSegmList[ic].m_End.y -= mirror_ref.y;
NEGATE( m_FillSegmList[ic].m_End.y );
2009-08-06 18:30:46 +00:00
m_FillSegmList[ic].m_End.y += mirror_ref.y;
}
2008-01-06 12:43:57 +00:00
}
void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src )
2008-01-06 12:43:57 +00:00
{
m_Parent = src->m_Parent;
m_Layer = src->m_Layer;
SetNetCode( src->GetNetCode() );
2011-12-12 08:37:05 +00:00
SetTimeStamp( src->m_TimeStamp );
m_Poly->RemoveAllContours();
m_Poly->Copy( src->m_Poly ); // copy outlines
m_CornerSelection = -1; // For corner moving, corner index to drag, or -1 if no selection
m_ZoneClearance = src->m_ZoneClearance; // clearance value
m_ZoneMinThickness = src->m_ZoneMinThickness;
m_FillMode = src->m_FillMode; // Filling mode (segments/polygons)
m_ArcToSegmentsCount = src->m_ArcToSegmentsCount;
m_PadConnection = src->m_PadConnection;
m_ThermalReliefGap = src->m_ThermalReliefGap;
m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge;
m_Poly->SetHatchStyle( src->m_Poly->GetHatchStyle() );
m_Poly->SetHatchPitch( src->m_Poly->GetHatchPitch() );
m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector <CSegment>
m_FilledPolysList.RemoveAllContours();
m_FilledPolysList.Append( src->m_FilledPolysList );
m_FillSegmList.clear();
2009-08-06 18:30:46 +00:00
m_FillSegmList = src->m_FillSegmList;
2008-01-06 12:43:57 +00:00
}
2008-10-23 10:26:06 +00:00
ZoneConnection ZONE_CONTAINER::GetPadConnection( D_PAD* aPad ) const
{
if( aPad == NULL || aPad->GetZoneConnection() == UNDEFINED_CONNECTION )
return m_PadConnection;
else
return aPad->GetZoneConnection();
}
void ZONE_CONTAINER::AddPolygon( std::vector< wxPoint >& aPolygon )
{
if( aPolygon.empty() )
return;
for( unsigned i = 0; i < aPolygon.size(); i++ )
{
if( i == 0 )
m_Poly->Start( GetLayer(), aPolygon[i].x, aPolygon[i].y, GetHatchStyle() );
else
AppendCorner( aPolygon[i] );
}
m_Poly->CloseLastContour();
}
wxString ZONE_CONTAINER::GetSelectMenuText() const
{
wxString text;
NETINFO_ITEM* net;
BOARD* board = GetBoard();
int ncont = m_Poly->GetContour( m_CornerSelection );
if( ncont )
text << wxT( " " ) << _( "(Cutout)" );
if( GetIsKeepout() )
text << wxT( " " ) << _( "(Keepout)" );
text << wxString::Format( wxT( " (%08lX)" ), m_TimeStamp );
// Display net name for copper zones
if( !GetIsKeepout() )
{
if( GetNetCode() >= 0 )
{
if( board )
{
net = GetNet();
if( net )
{
text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
}
}
else
{
text << _( "** NO BOARD DEFINED **" );
}
}
else
{ // A netcode < 0 is an error:
// Netname not found or area not initialised
text << wxT( " [" ) << GetNetname() << wxT( "]" );
text << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
}
}
wxString msg;
msg.Printf( _( "Zone Outline %s on %s" ), GetChars( text ),
GetChars( GetLayerName() ) );
return msg;
}