kicad/pcbnew/class_zone.cpp

898 lines
26 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 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"
2007-12-09 12:59:06 +00:00
2009-08-01 19:26:05 +00:00
#include "protos.h"
#include "class_board.h"
#include "class_zone.h"
#include "pcbnew.h"
#include "zones.h"
2009-08-01 19:26:05 +00:00
2007-12-09 12:59:06 +00:00
ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) :
BOARD_CONNECTED_ITEM( parent, PCB_ZONE_AREA_T )
2007-12-09 12:59:06 +00:00
{
SetNet( -1 ); // Net number for fast comparisons
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
2011-02-21 19:43:59 +00:00
smoothedPoly = NULL;
cornerSmoothingType = ZONE_SETTING::SMOOTHING_NONE;
cornerRadius = 0;
utility = 0; // flags used in polygon calculations
utility2 = 0; // flags used in polygon calculations
m_Poly = new CPolyLine(); // Outlines
g_Zone_Default_Setting.ExportSetting( *this );
2007-12-09 12:59:06 +00:00
}
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
}
bool ZONE_CONTAINER::UnFill()
{
bool change = ( m_FilledPolysList.size() > 0 ) || ( m_FillSegmList.size() > 0 );
m_FilledPolysList.clear();
m_FillSegmList.clear();
m_IsFilled = false;
return change;
}
2007-12-09 12:59:06 +00:00
const wxPoint ZONE_CONTAINER::GetPosition() const
{
return m_Poly? GetCornerPosition( 0 ) : wxPoint( 0, 0 );
}
void ZONE_CONTAINER::SetPosition( const wxPoint& aPos ) {}
void ZONE_CONTAINER::SetNet( int aNetCode )
{
BOARD_CONNECTED_ITEM::SetNet( aNetCode );
2007-12-09 12:59:06 +00:00
if( aNetCode < 0 )
return;
BOARD* board = GetBoard();
if( board )
{
NETINFO_ITEM* net = board->FindNet( aNetCode );
if( net )
m_Netname = net->GetNetname();
else
m_Netname.Empty();
}
else
{
m_Netname.Empty();
}
}
2007-12-09 12:59:06 +00:00
void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const wxPoint& offset )
{
if( DC == NULL )
return;
2008-03-04 04:22:27 +00:00
wxPoint seg_start, seg_end;
int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
BOARD* brd = GetBoard();
int 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 ) )
{
color &= ~MASKCOLOR;
color |= DARKDARKGRAY;
}
}
if( aDrawMode & GR_HIGHLIGHT )
{
if( aDrawMode & GR_AND )
color &= ~HIGHLIGHT_FLAG;
else
color |= HIGHLIGHT_FLAG;
}
if( color & HIGHLIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor;
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;
if( m_Poly->corner[ic].end_contour == false && 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->m_ClipBox, 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.x = m_Poly->m_HatchLines[ic].xi + offset.x;
seg_start.y = m_Poly->m_HatchLines[ic].yi + offset.y;
seg_end.x = m_Poly->m_HatchLines[ic].xf + offset.x;
seg_end.y = m_Poly->m_HatchLines[ic].yf + offset.y;
lines.push_back( seg_start );
lines.push_back( seg_end );
}
GRLineArray( &panel->m_ClipBox, DC, lines, 0, color );
}
void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
wxDC* DC, int aDrawMode, const wxPoint& offset )
{
static vector <char> CornersTypeBuffer;
static 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.size() == 0 ) // Nothing to draw
return;
BOARD* brd = GetBoard();
int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
int 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 ) )
{
color &= ~MASKCOLOR;
color |= DARKDARKGRAY;
}
}
if( aDrawMode & GR_HIGHLIGHT )
{
if( aDrawMode & GR_AND )
color &= ~HIGHLIGHT_FLAG;
else
color |= HIGHLIGHT_FLAG;
}
if( color & HIGHLIGHT_FLAG )
color = ColorRefs[color & MASKCOLOR].m_LightColor;
SetAlpha( &color, 150 );
CornersTypeBuffer.clear();
CornersBuffer.clear();
// Draw all filled areas
int imax = m_FilledPolysList.size() - 1;
for( int ic = 0; ic <= imax; ic++ )
{
CPolyPt* corner = &m_FilledPolysList[ic];
wxPoint coord( corner->x + offset.x, corner->y + offset.y );
CornersBuffer.push_back( coord );
CornersTypeBuffer.push_back( (char) corner->utility );
if( (corner->end_contour) || (ic == imax) ) // the last corner of a filled area is found: draw it
{
/* 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 by kbool to joint holes with external outline) are not drawn
*/
{
// 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;
if( CornersTypeBuffer[ie] == 0 ) // Draw only basic outlines, not extra segments
{
if( !DisplayOpt.DisplayPcbTrackFill || GetState( FORCE_SKETCH ) )
GRCSegm( &panel->m_ClipBox, DC,
x0, y0, x1, y1,
m_ZoneMinThickness, color );
else
GRFillCSegm( &panel->m_ClipBox, DC,
x0, y0, x1, y1,
m_ZoneMinThickness, color );
}
}
}
// Draw areas:
if( m_FillMode==0 && !outline_mode )
GRPoly( &panel->m_ClipBox, 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->m_ClipBox, DC, start.x, start.y, end.x, end.y,
m_ZoneMinThickness, color );
2009-08-06 18:30:46 +00:00
else
GRFillCSegm( &panel->m_ClipBox, DC, start.x, start.y, end.x, end.y,
m_ZoneMinThickness, color );
2009-08-06 18:30:46 +00:00
}
}
}
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 = MAX( ymax, corner.y );
xmax = MAX( xmax, corner.x );
ymin = MIN( ymin, corner.y );
xmin = 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, int draw_mode )
{
int 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;
int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer;
BOARD* brd = GetBoard();
int color = brd->GetLayerColor( m_Layer ) & MASKCOLOR;
if( DisplayOpt.ContrastModeDisplay )
{
if( !IsOnLayer( curr_layer ) )
{
color &= ~MASKCOLOR;
color |= DARKDARKGRAY;
}
}
// 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;
if( m_Poly->corner[ic].end_contour == false && ic < icmax )
{
2008-03-04 04:22:27 +00:00
is_close_segment = false;
xf = GetCornerPosition( ic + 1 ).x;
yf = GetCornerPosition( ic + 1 ).y;
if( (m_Poly->corner[ic + 1].end_contour) || (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 )
2008-03-04 04:22:27 +00:00
GRLine( &panel->m_ClipBox, DC, xi, yi, xf, yf, 0, WHITE );
else
GRLine( &panel->m_ClipBox, DC, xi, yi, xf, yf, 0, color );
}
2007-12-09 12:59:06 +00:00
}
bool ZONE_CONTAINER::HitTest( const wxPoint& refPos )
{
if( HitTestForCorner( refPos ) )
return true;
if( HitTestForEdge( refPos ) )
return true;
return false;
}
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos )
{
m_CornerSelection = -1; // Set to not found
// distance (in internal units) to detect a corner in a zone outline.
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// @todo use a scaling factor here of actual screen coordinates, so that
// when nanometers come, it still works.
#define CORNER_MIN_DIST 100
int min_dist = CORNER_MIN_DIST + 1;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
#if 0
// Dick: I don't see this as reasonable. The mouse distance from the zone is
// not a function of the grid, it is a fixed number of pixels, regardless of zoom.
if( GetBoard() && GetBoard()->m_PcbFrame )
{
// Use grid size because it is known
wxRealPoint grid = GetBoard()->m_PcbFrame->DrawPanel->GetGrid();
min_dist = wxRound( MIN( grid.x, grid.y ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
#endif
wxPoint delta;
unsigned lim = m_Poly->corner.size();
for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
{
delta.x = refPos.x - m_Poly->corner[item_pos].x;
delta.y = refPos.y - m_Poly->corner[item_pos].y;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// Calculate a distance:
int dist = MAX( abs( delta.x ), abs( delta.y ) );
if( dist < min_dist ) // this corner is a candidate:
{
m_CornerSelection = item_pos;
min_dist = dist;
}
}
return m_CornerSelection >= 0;
}
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
{
unsigned lim = m_Poly->corner.size();
m_CornerSelection = -1; // Set to not found
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
// @todo use a scaling factor here of actual screen coordinates, so that
// when nanometers come, it still works. This should be done in screen coordinates
// not internal units.
#define EDGE_MIN_DIST 200 // distance (in internal units) to detect a zone outline
int min_dist = EDGE_MIN_DIST+1;
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
#if 0
// Dick: I don't see this as reasonable. The mouse distance from the zone is
// not a function of the grid, it is a fixed number of pixels, regardless of zoom.
if( GetBoard() && GetBoard()->m_PcbFrame )
{
// Use grid size because it is known
wxRealPoint grid = GetBoard()->m_PcbFrame->DrawPanel->GetGrid();
min_dist = wxRound( MIN( grid.x, grid.y ) );
}
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
2011-12-05 06:15:33 +00:00
#endif
unsigned first_corner_pos = 0;
for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
{
unsigned end_segm = item_pos + 1;
/* the last corner of the current outline is tested
* the last segment of the current outline starts at current corner, and ends
* at the first corner of the outline
*/
if( m_Poly->corner[item_pos].end_contour || end_segm >= lim )
{
unsigned tmp = first_corner_pos;
first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline
end_segm = tmp; // end_segm is the beginning of the current outline
}
/* test the dist between segment and ref point */
int dist = (int) GetPointToLineSegmentDistance( refPos.x,
refPos.y,
m_Poly->corner[item_pos].x,
m_Poly->corner[item_pos].y,
m_Poly->corner[end_segm].x,
m_Poly->corner[end_segm].y );
if( dist < min_dist )
{
m_CornerSelection = item_pos;
min_dist = dist;
}
}
return m_CornerSelection >= 0;
}
bool ZONE_CONTAINER::HitTest( EDA_RECT& refArea )
2008-01-06 12:43:57 +00:00
{
bool is_out_of_box = false;
2008-01-06 12:43:57 +00:00
CRect rect = m_Poly->GetCornerBounds();
2008-01-06 12:43:57 +00:00
if( rect.left < refArea.GetX() )
is_out_of_box = true;
2008-01-06 12:43:57 +00:00
if( rect.top < refArea.GetY() )
is_out_of_box = true;
2008-01-06 12:43:57 +00:00
if( rect.right > refArea.GetRight() )
is_out_of_box = true;
2008-01-06 12:43:57 +00:00
if( rect.bottom > refArea.GetBottom() )
is_out_of_box = true;
return is_out_of_box ? false : true;
}
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 );
myClearance = max( hisClearance, myClearance );
}
return myClearance;
}
bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos )
{
unsigned indexstart = 0, indexend;
bool inside = false;
for( indexend = 0; indexend < m_FilledPolysList.size(); indexend++ )
{
if( m_FilledPolysList[indexend].end_contour ) // end of a filled sub-area found
{
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::DisplayInfo( EDA_DRAW_FRAME* frame )
{
wxString msg;
2008-03-04 04:22:27 +00:00
BOARD* board = (BOARD*) m_Parent;
wxASSERT( board );
frame->ClearMsgPanel();
msg = _( "Zone Outline" );
int ncont = m_Poly->GetContour( m_CornerSelection );
if( ncont )
msg << wxT( " " ) << _( "(Cutout)" );
frame->AppendMsgPanel( _( "Type" ), msg, DARKCYAN );
if( IsOnCopperLayer() )
{
if( GetNet() >= 0 )
{
NETINFO_ITEM* equipot = ( (PCB_BASE_FRAME*) frame )->GetBoard()->FindNet( GetNet() );
if( equipot )
msg = equipot->GetNetname();
else
msg = wxT( "<noname>" );
}
else // a netcode < 0 is an error
{
msg = wxT( " [" );
msg << m_Netname + wxT( "]" );
msg << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
}
frame->AppendMsgPanel( _( "NetName" ), msg, RED );
}
else
{
frame->AppendMsgPanel( _( "Non Copper Zone" ), wxEmptyString, RED );
}
/* Display net code : (useful in test or debug) */
msg.Printf( wxT( "%d" ), GetNet() );
frame->AppendMsgPanel( _( "NetCode" ), msg, RED );
2008-03-04 04:22:27 +00:00
msg = board->GetLayerName( m_Layer );
frame->AppendMsgPanel( _( "Layer" ), msg, BROWN );
msg.Printf( wxT( "%d" ), m_Poly->corner.size() );
frame->AppendMsgPanel( _( "Corners" ), msg, BLUE );
if( m_FillMode )
msg.Printf( _( "Segments" ), m_FillMode );
else
msg = _( "Polygons" );
frame->AppendMsgPanel( _( "Fill mode" ), msg, BROWN );
// Useful for statistics :
msg.Printf( wxT( "%d" ), m_Poly->m_HatchLines.size() );
frame->AppendMsgPanel( _( "Hatch lines" ), msg, BLUE );
if( m_FilledPolysList.size() )
{
msg.Printf( wxT( "%d" ), m_FilledPolysList.size() );
frame->AppendMsgPanel( _( "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->corner.size(); ii++ )
{
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
}
m_Poly->Hatch();
/* move filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
{
CPolyPt* corner = &m_FilledPolysList[ic];
corner->x += offset.x;
corner->y += 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:
if( m_Poly->corner[ii].end_contour || 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();
}
void ZONE_CONTAINER::Rotate( const wxPoint& centre, int angle )
2008-01-06 12:43:57 +00:00
{
2009-08-01 19:58:01 +00:00
wxPoint pos;
for( unsigned ii = 0; ii < m_Poly->corner.size(); ii++ )
{
pos.x = m_Poly->corner[ii].x;
pos.y = m_Poly->corner[ii].y;
RotatePoint( &pos, centre, angle );
m_Poly->corner[ii].x = pos.x;
m_Poly->corner[ii].y = pos.y;
}
m_Poly->Hatch();
2009-08-01 19:58:01 +00:00
/* rotate filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
{
CPolyPt* corner = &m_FilledPolysList[ic];
pos.x = corner->x;
pos.y = corner->y;
RotatePoint( &pos, centre, angle );
corner->x = pos.x;
corner->y = pos.y;
}
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( ChangeSideNumLayer( GetLayer() ) );
}
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 ii = 0; ii < m_Poly->corner.size(); ii++ )
{
m_Poly->corner[ii].y -= mirror_ref.y;
NEGATE( m_Poly->corner[ii].y );
m_Poly->corner[ii].y += mirror_ref.y;
}
m_Poly->Hatch();
2009-08-01 19:58:01 +00:00
/* mirror filled areas: */
for( unsigned ic = 0; ic < m_FilledPolysList.size(); ic++ )
{
CPolyPt* corner = &m_FilledPolysList[ic];
corner->y -= mirror_ref.y;
NEGATE( corner->y );
2009-08-01 19:58:01 +00:00
corner->y += mirror_ref.y;
}
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;
SetNet( src->GetNet() );
m_TimeStamp = 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_PadOption = src->m_PadOption;
m_ThermalReliefGap = src->m_ThermalReliefGap;
m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge;
m_Poly->m_HatchStyle = src->m_Poly->GetHatchStyle();
m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector <CSegment>
m_FilledPolysList.clear();
2009-08-06 18:30:46 +00:00
m_FilledPolysList = 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
2008-10-23 10:26:06 +00:00
bool ZONE_CONTAINER::SetNetNameFromNetCode( void )
{
NETINFO_ITEM* net;
if( m_Parent && ( net = ( (BOARD*) m_Parent )->FindNet( GetNet() ) ) )
2008-10-23 10:26:06 +00:00
{
m_Netname = net->GetNetname();
2008-10-23 10:26:06 +00:00
return true;
}
return false;
}
wxString ZONE_CONTAINER::GetSelectMenuText() const
{
wxString text;
NETINFO_ITEM* net;
BOARD* board = GetBoard();
text = _( "Zone Outline" );
int ncont = m_Poly->GetContour( m_CornerSelection );
if( ncont )
text << wxT( " " ) << _( "(Cutout)" );
text << wxT( " " );
text << wxString::Format( wxT( "(%8.8X)" ), m_TimeStamp );
if ( !IsOnCopperLayer() )
{
text << wxT( " [" ) << _( "Not on copper layer" ) << wxT( "]" );
}
else if( GetNet() >= 0 )
{
if( board )
{
net = board->FindNet( GetNet() );
if( net )
{
text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
}
}
else
{
text << _( "** NO BOARD DEFINED **" );
}
}
else // A netcode < 0 is an error flag (Netname not found or area not initialised)
{
text << wxT( " [" ) << m_Netname << wxT( "]" );
text << wxT( " <" ) << _( "Not Found" ) << wxT( ">" );
}
text << _( " on " ) << GetLayerName();
return text;
}