kicad/pcbnew/autorouter/routing_matrix.cpp

550 lines
15 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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
*
* Copyright (C) 1992-2012 KiCad Developers, see change_log.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
*/
/**
2012-09-12 17:28:55 +00:00
* @file routing_matrix.cpp
* @brief Functions to create autorouting maps
*/
#include <fctsys.h>
#include <common.h>
#include <pcbcommon.h>
#include <pcbnew.h>
#include <cell.h>
#include <autorout.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <class_edge_mod.h>
#include <class_pcb_text.h>
2007-08-21 14:34:54 +00:00
MATRIX_ROUTING_HEAD::MATRIX_ROUTING_HEAD()
{
m_BoardSide[0] = m_BoardSide[1] = NULL;
m_DistSide[0] = m_DistSide[1] = NULL;
m_DirSide[0] = m_DirSide[1] = NULL;
m_InitMatrixDone = false;
m_Nrows = m_Ncols = 0;
m_MemSize = 0;
m_RoutingLayersCount = 1;
}
MATRIX_ROUTING_HEAD::~MATRIX_ROUTING_HEAD()
{
}
bool MATRIX_ROUTING_HEAD::ComputeMatrixSize( BOARD* aPcb, bool aUseBoardEdgesOnly )
{
aPcb->ComputeBoundingBox( aUseBoardEdgesOnly );
2007-08-21 14:34:54 +00:00
++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
// The boundary box must have its start point on routing grid:
m_BrdBox = aPcb->GetBoundingBox();
m_BrdBox.SetX( m_BrdBox.GetX() - ( m_BrdBox.GetX() % m_GridRouting ) );
m_BrdBox.SetY( m_BrdBox.GetY() - ( m_BrdBox.GetY() % m_GridRouting ) );
++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
// The boundary box must have its end point on routing grid:
wxPoint end = m_BrdBox.GetEnd();
++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
end.x -= end.x % m_GridRouting;
end.x += m_GridRouting;
++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
end.y -= end.y % m_GridRouting;
end.y += m_GridRouting;
++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
m_BrdBox.SetEnd( end );
++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
aPcb->SetBoundingBox( m_BrdBox );
m_Nrows = m_BrdBox.GetHeight() / m_GridRouting;
m_Ncols = m_BrdBox.GetWidth() / m_GridRouting;
2011-03-09 14:30:39 +00:00
// gives a small margin
m_Ncols += 1;
m_Nrows += 1;
2007-08-21 14:34:54 +00:00
2011-03-09 14:30:39 +00:00
return true;
}
2007-08-21 14:34:54 +00:00
int MATRIX_ROUTING_HEAD::InitRoutingMatrix()
{
if( m_Nrows <= 0 || m_Ncols <= 0 )
2007-08-21 14:34:54 +00:00
return 0;
m_InitMatrixDone = true; // we have been called
// give a small margin for memory allocation:
int ii = (RoutingMatrix.m_Nrows + 1) * (RoutingMatrix.m_Ncols + 1);
int side = BOTTOM;
for( int jj = 0; jj < m_RoutingLayersCount; jj++ ) // m_RoutingLayersCount = 1 or 2
2007-08-21 14:34:54 +00:00
{
m_BoardSide[side] = NULL;
m_DistSide[side] = NULL;
m_DirSide[side] = NULL;
/* allocate matrix & initialize everything to empty */
m_BoardSide[side] = (MATRIX_CELL*) operator new( ii * sizeof(MATRIX_CELL) );
memset( m_BoardSide[side], 0, ii * sizeof(MATRIX_CELL) );
if( m_BoardSide[side] == NULL )
2007-08-21 14:34:54 +00:00
return -1;
// allocate Distances
m_DistSide[side] = (DIST_CELL*) operator new( ii * sizeof(DIST_CELL) );
memset( m_DistSide[side], 0, ii * sizeof(DIST_CELL) );
if( m_DistSide[side] == NULL )
2007-08-21 14:34:54 +00:00
return -1;
// allocate Dir (chars)
m_DirSide[side] = (char*) operator new( ii );
memset( m_DirSide[side], 0, ii );
if( m_DirSide[side] == NULL )
2007-08-21 14:34:54 +00:00
return -1;
side = TOP;
2007-08-21 14:34:54 +00:00
}
m_MemSize = m_RouteCount * ii * ( sizeof(MATRIX_CELL)
+ sizeof(DIST_CELL) + sizeof(char) );
2007-08-21 14:34:54 +00:00
return m_MemSize;
}
2007-08-21 14:34:54 +00:00
void MATRIX_ROUTING_HEAD::UnInitRoutingMatrix()
{
2007-08-21 14:34:54 +00:00
int ii;
m_InitMatrixDone = false;
2007-08-21 14:34:54 +00:00
for( ii = 0; ii < MAX_ROUTING_LAYERS_COUNT; ii++ )
2007-08-21 14:34:54 +00:00
{
// de-allocate Dir matrix
2007-08-21 14:34:54 +00:00
if( m_DirSide[ii] )
{
delete m_DirSide[ii];
m_DirSide[ii] = NULL;
2007-08-21 14:34:54 +00:00
}
// de-allocate Distances matrix
2007-08-21 14:34:54 +00:00
if( m_DistSide[ii] )
{
delete m_DistSide[ii];
m_DistSide[ii] = NULL;
2007-08-21 14:34:54 +00:00
}
// de-allocate cells matrix
2007-08-21 14:34:54 +00:00
if( m_BoardSide[ii] )
{
delete m_BoardSide[ii];
m_BoardSide[ii] = NULL;
2007-08-21 14:34:54 +00:00
}
}
m_Nrows = m_Ncols = 0;
}
/**
* Function PlaceCells
* Initialize the matrix routing by setting obstacles for each occupied cell
* a cell set to HOLE is an obstacle for tracks and vias
* a cell set to VIA_IMPOSSIBLE is an obstacle for vias only.
* a cell set to CELL_is_EDGE is a frontier.
* Tracks and vias having the same net code as net_code are skipped
* (htey do not are obstacles)
*
* For single-sided Routing 1:
* BOTTOM side is used, and Route_Layer_BOTTOM = Route_Layer_TOP
*
* If flag == FORCE_PADS: all pads will be put in matrix as obstacles.
2007-08-21 14:34:54 +00:00
*/
void PlaceCells( BOARD* aPcb, int net_code, int flag )
{
int ux0 = 0, uy0 = 0, ux1, uy1, dx, dy;
int marge, via_marge;
LAYER_MSK layerMask;
2007-08-21 14:34:54 +00:00
2009-09-10 15:22:26 +00:00
// use the default NETCLASS?
NETCLASS* nc = aPcb->m_NetClasses.GetDefault();
2009-09-10 15:22:26 +00:00
int trackWidth = nc->GetTrackWidth();
int clearance = nc->GetClearance();
int viaSize = nc->GetViaDiameter();
2009-09-10 15:22:26 +00:00
marge = clearance + (trackWidth / 2);
via_marge = clearance + (viaSize / 2);
2007-08-21 14:34:54 +00:00
// Place PADS on matrix routing:
for( unsigned i = 0; i < aPcb->GetPadCount(); ++i )
2007-08-21 14:34:54 +00:00
{
D_PAD* pad = aPcb->GetPad( i );
if( net_code != pad->GetNetCode() || (flag & FORCE_PADS) )
2007-08-21 14:34:54 +00:00
{
::PlacePad( pad, HOLE, marge, WRITE_CELL );
2007-08-21 14:34:54 +00:00
}
::PlacePad( pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
2007-08-21 14:34:54 +00:00
}
// Place outlines of modules on matrix routing, if they are on a copper layer
// or on the edge layer
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
2007-08-21 14:34:54 +00:00
{
for( BOARD_ITEM* item = module->GraphicalItems(); item; item = item->Next() )
2007-08-21 14:34:54 +00:00
{
switch( item->Type() )
2007-08-21 14:34:54 +00:00
{
case PCB_MODULE_EDGE_T:
{
EDGE_MODULE* edge = (EDGE_MODULE*) item;
EDGE_MODULE tmpEdge( *edge );
if( tmpEdge.GetLayer() == EDGE_N )
tmpEdge.SetLayer( UNDEFINED_LAYER );
TraceSegmentPcb( &tmpEdge, HOLE, marge, WRITE_CELL );
TraceSegmentPcb( &tmpEdge, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
}
break;
2007-08-21 14:34:54 +00:00
default:
break;
}
}
}
// Place board outlines and texts on copper layers:
for( BOARD_ITEM* item = aPcb->m_Drawings; item; item = item->Next() )
2007-08-21 14:34:54 +00:00
{
switch( item->Type() )
2007-08-21 14:34:54 +00:00
{
case PCB_LINE_T:
{
DRAWSEGMENT* DrawSegm;
int type_cell = HOLE;
DrawSegm = (DRAWSEGMENT*) item;
DRAWSEGMENT tmpSegm( DrawSegm );
if( DrawSegm->GetLayer() == EDGE_N )
2007-08-21 14:34:54 +00:00
{
tmpSegm.SetLayer( UNDEFINED_LAYER );
type_cell |= CELL_is_EDGE;
}
TraceSegmentPcb( &tmpSegm, type_cell, marge, WRITE_CELL );
}
break;
2007-08-21 14:34:54 +00:00
case PCB_TEXT_T:
2009-09-10 15:22:26 +00:00
{
TEXTE_PCB* PtText;
PtText = (TEXTE_PCB*) item;
if( PtText->GetText().Length() == 0 )
2007-08-21 14:34:54 +00:00
break;
2009-06-06 18:08:49 +00:00
EDA_RECT textbox = PtText->GetTextBox( -1 );
ux0 = textbox.GetX();
uy0 = textbox.GetY();
dx = textbox.GetWidth();
dy = textbox.GetHeight();
2007-08-21 14:34:54 +00:00
/* Put bounding box (rectangle) on matrix */
dx /= 2;
dy /= 2;
ux1 = ux0 + dx;
uy1 = uy0 + dy;
ux0 -= dx;
uy0 -= dy;
2007-08-21 14:34:54 +00:00
layerMask = GetLayerMask( PtText->GetLayer() );
2007-08-21 14:34:54 +00:00
TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge,
uy1 + marge, PtText->GetOrientation(),
layerMask, HOLE, WRITE_CELL );
TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge,
2007-08-21 14:34:54 +00:00
ux1 + via_marge, uy1 + via_marge,
PtText->GetOrientation(),
layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL );
2009-09-10 15:22:26 +00:00
}
break;
2007-08-21 14:34:54 +00:00
default:
break;
}
}
/* Put tracks and vias on matrix */
for( TRACK* track = aPcb->m_Track; track; track = track->Next() )
2007-08-21 14:34:54 +00:00
{
if( net_code == track->GetNetCode() )
2007-08-21 14:34:54 +00:00
continue;
TraceSegmentPcb( track, HOLE, marge, WRITE_CELL );
TraceSegmentPcb( track, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL );
2007-08-21 14:34:54 +00:00
}
}
2007-08-21 14:34:54 +00:00
int Build_Work( BOARD* Pcb )
{
++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
RATSNEST_ITEM* pt_rats;
D_PAD* pt_pad;
int r1, r2, c1, c2, current_net_code;
RATSNEST_ITEM* pt_ch;
int demi_pas = RoutingMatrix.m_GridRouting / 2;
++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
wxString msg;
2007-08-21 14:34:54 +00:00
InitWork(); /* clear work list */
int cellCount = 0;
2009-06-03 17:18:39 +00:00
for( unsigned ii = 0; ii < Pcb->GetRatsnestsCount(); ii++ )
2007-08-21 14:34:54 +00:00
{
pt_rats = &Pcb->m_FullRatsnest[ii];
/* We consider here only ratsnest that are active ( obviously not yet routed)
2009-11-15 14:12:53 +00:00
* and routables (that are not yet attempt to be routed and fail
*/
if( (pt_rats->m_Status & CH_ACTIF) == 0 )
2007-08-21 14:34:54 +00:00
continue;
if( pt_rats->m_Status & CH_UNROUTABLE )
2007-08-21 14:34:54 +00:00
continue;
if( (pt_rats->m_Status & CH_ROUTE_REQ) == 0 )
2007-08-21 14:34:54 +00:00
continue;
pt_pad = pt_rats->m_PadStart;
2007-08-21 14:34:54 +00:00
current_net_code = pt_pad->GetNetCode();
2007-08-21 14:34:54 +00:00
pt_ch = pt_rats;
r1 = ( pt_pad->GetPosition().y - RoutingMatrix.m_BrdBox.GetY() + demi_pas )
/ RoutingMatrix.m_GridRouting;
if( r1 < 0 || r1 >= RoutingMatrix.m_Nrows )
2007-08-21 14:34:54 +00:00
{
msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r1,
pt_pad->GetPosition().y, RoutingMatrix.m_BrdBox.GetY() );
2011-03-09 14:30:39 +00:00
wxMessageBox( msg );
2007-08-21 14:34:54 +00:00
return 0;
}
c1 = ( pt_pad->GetPosition().x - RoutingMatrix.m_BrdBox.GetX() + demi_pas ) / RoutingMatrix.m_GridRouting;
if( c1 < 0 || c1 >= RoutingMatrix.m_Ncols )
2007-08-21 14:34:54 +00:00
{
msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c1,
pt_pad->GetPosition().x, RoutingMatrix.m_BrdBox.GetX() );
2011-03-09 14:30:39 +00:00
wxMessageBox( msg );
2007-08-21 14:34:54 +00:00
return 0;
}
pt_pad = pt_rats->m_PadEnd;
2007-08-21 14:34:54 +00:00
r2 = ( pt_pad->GetPosition().y - RoutingMatrix.m_BrdBox.GetY()
+ demi_pas ) / RoutingMatrix.m_GridRouting;
if( r2 < 0 || r2 >= RoutingMatrix.m_Nrows )
2007-08-21 14:34:54 +00:00
{
msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r2,
pt_pad->GetPosition().y, RoutingMatrix.m_BrdBox.GetY() );
2011-03-09 14:30:39 +00:00
wxMessageBox( msg );
2007-08-21 14:34:54 +00:00
return 0;
}
c2 = ( pt_pad->GetPosition().x - RoutingMatrix.m_BrdBox.GetX() + demi_pas )
/ RoutingMatrix.m_GridRouting;
if( c2 < 0 || c2 >= RoutingMatrix.m_Ncols )
2007-08-21 14:34:54 +00:00
{
msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c2,
pt_pad->GetPosition().x, RoutingMatrix.m_BrdBox.GetX() );
2011-03-09 14:30:39 +00:00
wxMessageBox( msg );
2007-08-21 14:34:54 +00:00
return 0;
}
2009-06-03 17:18:39 +00:00
SetWork( r1, c1, current_net_code, r2, c2, pt_ch, 0 );
cellCount++;
2007-08-21 14:34:54 +00:00
}
SortWork();
return cellCount;
}
// Initialize m_opWriteCell member to make the aLogicOp
void MATRIX_ROUTING_HEAD::SetCellOperation( int aLogicOp )
{
switch( aLogicOp )
{
default:
case WRITE_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::SetCell;
break;
case WRITE_OR_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::OrCell;
break;
case WRITE_XOR_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::XorCell;
break;
case WRITE_AND_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::AndCell;
break;
case WRITE_ADD_CELL:
m_opWriteCell = &MATRIX_ROUTING_HEAD::AddCell;
break;
}
}
2011-03-09 14:30:39 +00:00
/* return the value stored in a cell
*/
MATRIX_CELL MATRIX_ROUTING_HEAD::GetCell( int aRow, int aCol, int aSide )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
return p[aRow * m_Ncols + aCol];
}
2011-03-09 14:30:39 +00:00
/* basic cell operation : WRITE operation
*/
void MATRIX_ROUTING_HEAD::SetCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * m_Ncols + aCol] = x;
}
2011-03-09 14:30:39 +00:00
/* basic cell operation : OR operation
*/
void MATRIX_ROUTING_HEAD::OrCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * m_Ncols + aCol] |= x;
}
2011-03-09 14:30:39 +00:00
/* basic cell operation : XOR operation
*/
void MATRIX_ROUTING_HEAD::XorCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * m_Ncols + aCol] ^= x;
}
2011-03-09 14:30:39 +00:00
/* basic cell operation : AND operation
*/
void MATRIX_ROUTING_HEAD::AndCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * m_Ncols + aCol] &= x;
}
2011-03-09 14:30:39 +00:00
/* basic cell operation : ADD operation
*/
void MATRIX_ROUTING_HEAD::AddCell( int aRow, int aCol, int aSide, MATRIX_CELL x )
{
2011-03-09 14:30:39 +00:00
MATRIX_CELL* p;
p = RoutingMatrix.m_BoardSide[aSide];
p[aRow * m_Ncols + aCol] += x;
}
/* fetch distance cell */
DIST_CELL MATRIX_ROUTING_HEAD::GetDist( int aRow, int aCol, int aSide ) /* fetch distance cell */
{
2011-03-09 14:30:39 +00:00
DIST_CELL* p;
p = RoutingMatrix.m_DistSide[aSide];
return p[aRow * m_Ncols + aCol];
}
/* store distance cell */
void MATRIX_ROUTING_HEAD::SetDist( int aRow, int aCol, int aSide, DIST_CELL x )
{
2011-03-09 14:30:39 +00:00
DIST_CELL* p;
p = RoutingMatrix.m_DistSide[aSide];
p[aRow * m_Ncols + aCol] = x;
}
/* fetch direction cell */
int MATRIX_ROUTING_HEAD::GetDir( int aRow, int aCol, int aSide )
{
2011-03-09 14:30:39 +00:00
DIR_CELL* p;
p = RoutingMatrix.m_DirSide[aSide];
return (int) (p[aRow * m_Ncols + aCol]);
}
/* store direction cell */
void MATRIX_ROUTING_HEAD::SetDir( int aRow, int aCol, int aSide, int x )
{
2011-03-09 14:30:39 +00:00
DIR_CELL* p;
p = RoutingMatrix.m_DirSide[aSide];
p[aRow * m_Ncols + aCol] = (char) x;
}