2012-06-08 09:56:42 +00:00
|
|
|
/**
|
|
|
|
* @file autoplac.cpp
|
2013-11-25 11:29:16 +00:00
|
|
|
* @brief Functions to automatically place Footprints on a board.
|
2012-06-08 09:56:42 +00:00
|
|
|
*/
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* 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.
|
2011-11-10 15:55:05 +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
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbcommon.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
#include <autorout.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <cell.h>
|
|
|
|
#include <colors_selection.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
|
|
|
#include <class_drawsegment.h>
|
2012-06-05 19:07:33 +00:00
|
|
|
#include <convert_to_biu.h>
|
2013-11-24 17:48:14 +00:00
|
|
|
#include <base_units.h>
|
|
|
|
#include <protos.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
#define GAIN 16
|
|
|
|
#define KEEP_OUT_MARGIN 500
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
/* Penalty (cost) for CntRot90 and CntRot180:
|
|
|
|
* CntRot90 and CntRot180 are from 0 (rotation allowed) to 10 (rotation not allowed)
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
2012-06-10 16:21:18 +00:00
|
|
|
static const double OrientPenality[11] =
|
2009-11-12 15:43:38 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
2.0, // CntRot = 0 rotation prohibited
|
|
|
|
1.9, // CntRot = 1
|
|
|
|
1.8, // CntRot = 2
|
|
|
|
1.7, // CntRot = 3
|
|
|
|
1.6, // CntRot = 4
|
|
|
|
1.5, // CntRot = 5
|
|
|
|
1.4, // CntRot = 5
|
|
|
|
1.3, // CntRot = 7
|
|
|
|
1.2, // CntRot = 8
|
|
|
|
1.1, // CntRot = 9
|
|
|
|
1.0 // CntRot = 10 rotation authorized, no penalty
|
2007-08-10 19:14:51 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Cell states.
|
2013-11-24 17:48:14 +00:00
|
|
|
#define OUT_OF_BOARD -2
|
|
|
|
#define OCCUPED_By_MODULE -1
|
2013-11-25 11:29:16 +00:00
|
|
|
#define FREE_CELL 0
|
++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
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
static wxPoint CurrPosition; // Current position of the current module placement
|
2012-06-10 16:21:18 +00:00
|
|
|
double MinCout;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
/* generates the Routing matrix, used to fing the best placement
|
|
|
|
* of a footprint.
|
|
|
|
* Allocate a "bitmap" which is an image of the real board
|
|
|
|
* the bitmap handles:
|
|
|
|
* - The free areas
|
|
|
|
* - penalties (cell not occupied, but near occupied areas)
|
|
|
|
* - cells occupied by footprints, board cutout ...
|
|
|
|
*/
|
|
|
|
int genPlacementRoutingMatrix( BOARD* aBrd, EDA_MSG_PANEL* messagePanel );
|
|
|
|
|
|
|
|
/* searches for the optimal position of aModule.
|
|
|
|
* return 1 if placement impossible or 0 if OK.
|
|
|
|
*/
|
|
|
|
static int getOptimalModulePlacement( PCB_EDIT_FRAME* aFrame,
|
|
|
|
MODULE* aModule, wxDC* aDC );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function compute_Ratsnest_PlaceModule
|
|
|
|
* displays the module's ratsnest during displacement, and assess the "cost"
|
|
|
|
* of the position.
|
|
|
|
*
|
|
|
|
* The cost is the longest ratsnest distance with penalty for connections
|
|
|
|
* approaching 45 degrees.
|
|
|
|
*/
|
|
|
|
static double compute_Ratsnest_PlaceModule( BOARD* aBrd );
|
|
|
|
|
|
|
|
/* Place a footprint on the Routing matrix.
|
|
|
|
*/
|
|
|
|
void genModuleOnRoutingMatrix( MODULE* Module );
|
2013-11-25 11:29:16 +00:00
|
|
|
/*
|
|
|
|
* Displays the Placement/Routing matrix on the screen
|
|
|
|
*/
|
|
|
|
static void drawPlacementRoutingMatrix( BOARD* aBrd, wxDC* DC );
|
2013-11-24 17:48:14 +00:00
|
|
|
|
|
|
|
static int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
static void CreateKeepOutRectangle( int ux0, int uy0, int ux1, int uy1,
|
|
|
|
int marge, int aKeepOut, int aLayerMask );
|
|
|
|
|
|
|
|
static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC );
|
|
|
|
static int propagate();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
MODULE* currModule = NULL;
|
|
|
|
wxPoint PosOK;
|
|
|
|
wxPoint memopos;
|
|
|
|
int error;
|
|
|
|
LAYER_NUM lay_tmp_TOP, lay_tmp_BOTTOM;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-12-13 20:42:42 +00:00
|
|
|
// Undo: init list
|
2013-11-24 17:48:14 +00:00
|
|
|
PICKED_ITEMS_LIST newList;
|
|
|
|
|
2011-12-13 20:42:42 +00:00
|
|
|
newList.m_Status = UR_CHANGED;
|
2013-11-24 17:48:14 +00:00
|
|
|
ITEM_PICKER picker( NULL, UR_CHANGED );
|
2011-12-13 20:42:42 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
switch( place_mode )
|
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
case PLACE_1_MODULE:
|
|
|
|
currModule = Module;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( currModule == NULL )
|
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
currModule->SetIsPlaced( false );
|
|
|
|
currModule->SetNeedsPlaced( false );
|
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
case PLACE_OUT_OF_BOARD:
|
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
case PLACE_ALL:
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( !IsOK( this, _( "Footprints NOT LOCKED will be moved" ) ) )
|
|
|
|
return;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLACE_INCREMENTAL:
|
|
|
|
|
|
|
|
if( !IsOK( this, _( "Footprints NOT PLACED will be moved" ) ) )
|
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memopos = CurrPosition;
|
2013-11-24 17:48:14 +00:00
|
|
|
lay_tmp_BOTTOM = g_Route_Layer_BOTTOM;
|
|
|
|
lay_tmp_TOP = g_Route_Layer_TOP;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
RoutingMatrix.m_GridRouting = (int) GetScreen()->GetGridSize().x;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
// Ensure Board.m_GridRouting has a reasonable value:
|
2013-11-25 11:29:16 +00:00
|
|
|
if( RoutingMatrix.m_GridRouting < Millimeter2iu( 0.25 ) )
|
|
|
|
RoutingMatrix.m_GridRouting = Millimeter2iu( 0.25 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Compute module parameters used in auto place
|
2013-11-24 17:48:14 +00:00
|
|
|
if( genPlacementRoutingMatrix( GetBoard(), m_messagePanel ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
int moduleCount = 0;
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
switch( place_mode )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_1_MODULE:
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( currModule == Module )
|
2011-12-13 20:42:42 +00:00
|
|
|
{
|
|
|
|
// Module will be placed, add to undo.
|
2012-06-08 09:56:42 +00:00
|
|
|
picker.SetItem( currModule );
|
2011-12-13 20:42:42 +00:00
|
|
|
newList.PushItem( picker );
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( true );
|
2011-12-13 20:42:42 +00:00
|
|
|
}
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_OUT_OF_BOARD:
|
2012-06-08 09:56:42 +00:00
|
|
|
Module->SetIsPlaced( false );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( Module->IsLocked() )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !RoutingMatrix.m_BrdBox.Contains( Module->GetPosition() ) )
|
2011-12-13 20:42:42 +00:00
|
|
|
{
|
|
|
|
// Module will be placed, add to undo.
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( Module );
|
2011-12-13 20:42:42 +00:00
|
|
|
newList.PushItem( picker );
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( true );
|
2011-12-13 20:42:42 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_ALL:
|
2012-06-08 09:56:42 +00:00
|
|
|
Module->SetIsPlaced( false );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( Module->IsLocked() )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-13 20:42:42 +00:00
|
|
|
// Module will be placed, add to undo.
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( Module );
|
2011-12-13 20:42:42 +00:00
|
|
|
newList.PushItem( picker );
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( true );
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_INCREMENTAL:
|
2013-11-24 17:48:14 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( Module->IsLocked() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-06-08 09:56:42 +00:00
|
|
|
Module->SetIsPlaced( false );
|
2011-09-20 13:57:40 +00:00
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !Module->NeedsPlaced() )
|
2011-12-13 20:42:42 +00:00
|
|
|
{
|
|
|
|
// Module will be placed, add to undo.
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetItem( Module );
|
2011-12-13 20:42:42 +00:00
|
|
|
newList.PushItem( picker );
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( true );
|
2011-12-13 20:42:42 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( Module->NeedsPlaced() ) // Erase from screen
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-06-08 09:56:42 +00:00
|
|
|
moduleCount++;
|
2011-12-22 13:28:11 +00:00
|
|
|
Module->Draw( m_canvas, DC, GR_XOR );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
genModuleOnRoutingMatrix( Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
// Undo command: prepare list
|
2011-12-13 20:42:42 +00:00
|
|
|
if( newList.GetCount() )
|
|
|
|
SaveCopyInUndoList( newList, UR_CHANGED );
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int cnt = 0;
|
|
|
|
wxString msg;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
while( ( Module = PickModule( this, DC ) ) != NULL )
|
|
|
|
{
|
2012-06-08 09:56:42 +00:00
|
|
|
// Display some info about activity, module placement can take a while:
|
2013-11-24 17:48:14 +00:00
|
|
|
msg.Printf( _( "Place module %d of %d" ), cnt, moduleCount );
|
2012-06-08 09:56:42 +00:00
|
|
|
SetStatusText( msg );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
double initialOrient = Module->GetOrientation();
|
2013-08-03 05:15:23 +00:00
|
|
|
// Display fill area of interest, barriers, penalties.
|
2013-11-25 11:29:16 +00:00
|
|
|
drawPlacementRoutingMatrix( GetBoard(), DC );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
error = getOptimalModulePlacement( this, Module, DC );
|
2013-11-25 11:29:16 +00:00
|
|
|
double bestScore = MinCout;
|
|
|
|
double bestRotation = 0.0;
|
|
|
|
int rotAllowed;
|
2013-11-24 17:48:14 +00:00
|
|
|
PosOK = CurrPosition;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
// Try orientations 90, 180, 270 degrees from initial orientation
|
|
|
|
rotAllowed = Module->GetPlacementCost180();
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( rotAllowed != 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, 1800.0, true );
|
2013-11-24 17:48:14 +00:00
|
|
|
error = getOptimalModulePlacement( this, Module, DC );
|
2013-11-25 11:29:16 +00:00
|
|
|
MinCout *= OrientPenality[rotAllowed];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( bestScore > MinCout ) // This orientation is better.
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
PosOK = CurrPosition;
|
2013-11-25 11:29:16 +00:00
|
|
|
bestScore = MinCout;
|
|
|
|
bestRotation = 1800.0;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, initialOrient, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Determine if the best orientation of a module is 90.
|
2013-11-25 11:29:16 +00:00
|
|
|
rotAllowed = Module->GetPlacementCost90();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( rotAllowed != 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, 900.0, true );
|
2013-11-24 17:48:14 +00:00
|
|
|
error = getOptimalModulePlacement( this, Module, DC );
|
2013-11-25 11:29:16 +00:00
|
|
|
MinCout *= OrientPenality[rotAllowed];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( bestScore > MinCout ) // This orientation is better.
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
PosOK = CurrPosition;
|
2013-11-25 11:29:16 +00:00
|
|
|
bestScore = MinCout;
|
|
|
|
bestRotation = 900.0;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, initialOrient, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
// Determine if the best orientation of a module is -90.
|
|
|
|
if( rotAllowed != 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, 2700.0, true );
|
2013-11-24 17:48:14 +00:00
|
|
|
error = getOptimalModulePlacement( this, Module, DC );
|
2013-11-25 11:29:16 +00:00
|
|
|
MinCout *= OrientPenality[rotAllowed];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( bestScore > MinCout ) // This orientation is better.
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
PosOK = CurrPosition;
|
2013-11-25 11:29:16 +00:00
|
|
|
bestScore = MinCout;
|
|
|
|
bestRotation = 2700.0;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-25 11:29:16 +00:00
|
|
|
Rotate_Module( DC, Module, initialOrient, false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
end_of_tst:
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
break;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Place module.
|
|
|
|
CurrPosition = GetCrossHairPosition();
|
|
|
|
SetCrossHairPosition( PosOK );
|
2013-11-25 11:29:16 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( Module, DC );
|
2013-11-25 11:29:16 +00:00
|
|
|
|
|
|
|
bestRotation += initialOrient;
|
|
|
|
|
|
|
|
if( bestRotation != Module->GetOrientation() )
|
|
|
|
Rotate_Module( DC, Module, bestRotation, false );
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( CurrPosition );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
Module->CalculateBoundingBox();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
genModuleOnRoutingMatrix( Module );
|
2012-06-08 09:56:42 +00:00
|
|
|
Module->SetIsPlaced( true );
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetNeedsPlaced( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition = memopos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
RoutingMatrix.UnInitRoutingMatrix();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
g_Route_Layer_TOP = lay_tmp_TOP;
|
|
|
|
g_Route_Layer_BOTTOM = lay_tmp_BOTTOM;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
Module->CalculateBoundingBox();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2009-06-11 14:26:17 +00:00
|
|
|
Compile_Ratsnest( DC, true );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->ReDraw( DC, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
void drawPlacementRoutingMatrix( BOARD* aBrd, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int ii, jj;
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T color;
|
2013-11-24 17:48:14 +00:00
|
|
|
int ox, oy;
|
2011-03-09 14:30:39 +00:00
|
|
|
MATRIX_CELL top_state, bottom_state;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
for( ii = 0; ii < RoutingMatrix.m_Nrows; ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-06-08 09:56:42 +00:00
|
|
|
oy = RoutingMatrix.m_BrdBox.GetY() + ( ii * RoutingMatrix.m_GridRouting );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
for( jj = 0; jj < RoutingMatrix.m_Ncols; jj++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
ox = RoutingMatrix.m_BrdBox.GetX() + (jj * RoutingMatrix.m_GridRouting);
|
|
|
|
color = BLACK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
top_state = RoutingMatrix.GetCell( ii, jj, TOP );
|
|
|
|
bottom_state = RoutingMatrix.GetCell( ii, jj, BOTTOM );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( top_state & CELL_is_ZONE )
|
2007-08-10 19:14:51 +00:00
|
|
|
color = BLUE;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// obstacles
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( top_state & CELL_is_EDGE ) || ( bottom_state & CELL_is_EDGE ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
color = WHITE;
|
2009-11-12 15:43:38 +00:00
|
|
|
else if( top_state & ( HOLE | CELL_is_MODULE ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
color = LIGHTRED;
|
|
|
|
else if( bottom_state & (HOLE | CELL_is_MODULE) )
|
|
|
|
color = LIGHTGREEN;
|
2013-11-24 17:48:14 +00:00
|
|
|
else // Display the filling and keep out regions.
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
if( RoutingMatrix.GetDist( ii, jj, TOP )
|
|
|
|
|| RoutingMatrix.GetDist( ii, jj, BOTTOM ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
color = DARKGRAY;
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
GRPutPixel( NULL, DC, ox, oy, color );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int genPlacementRoutingMatrix( BOARD* aBrd, EDA_MSG_PANEL* messagePanel )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
wxString msg;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
RoutingMatrix.UnInitRoutingMatrix();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
EDA_RECT bbox = aBrd->ComputeBoundingBox( true );
|
++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
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( bbox.GetWidth() == 0 || bbox.GetHeight() == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
DisplayError( NULL, _( "No PCB edge found, unknown board size!" ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
RoutingMatrix.ComputeMatrixSize( aBrd, true );
|
2012-06-10 16:21:18 +00:00
|
|
|
int nbCells = RoutingMatrix.m_Ncols * RoutingMatrix.m_Nrows;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
messagePanel->EraseMsgBox();
|
2012-06-10 16:21:18 +00:00
|
|
|
msg.Printf( wxT( "%d" ), RoutingMatrix.m_Ncols );
|
2013-11-24 17:48:14 +00:00
|
|
|
messagePanel->SetMessage( 1, _( "Cols" ), msg, GREEN );
|
2012-06-10 16:21:18 +00:00
|
|
|
msg.Printf( wxT( "%d" ), RoutingMatrix.m_Nrows );
|
2013-11-24 17:48:14 +00:00
|
|
|
messagePanel->SetMessage( 7, _( "Lines" ), msg, GREEN );
|
2012-06-10 16:21:18 +00:00
|
|
|
msg.Printf( wxT( "%d" ), nbCells );
|
2013-11-24 17:48:14 +00:00
|
|
|
messagePanel->SetMessage( 14, _( "Cells." ), msg, YELLOW );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Choose the number of board sides.
|
2012-06-26 17:57:37 +00:00
|
|
|
RoutingMatrix.m_RoutingLayersCount = 2;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
RoutingMatrix.InitRoutingMatrix();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Display memory usage.
|
2012-06-05 19:07:33 +00:00
|
|
|
msg.Printf( wxT( "%d" ), RoutingMatrix.m_MemSize / 1024 );
|
2013-11-24 17:48:14 +00:00
|
|
|
messagePanel->SetMessage( 24, wxT( "Mem(Kb)" ), msg, CYAN );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
g_Route_Layer_BOTTOM = LAYER_N_FRONT;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-26 17:57:37 +00:00
|
|
|
if( RoutingMatrix.m_RoutingLayersCount > 1 )
|
2013-03-27 18:32:12 +00:00
|
|
|
g_Route_Layer_BOTTOM = LAYER_N_BACK;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
g_Route_Layer_TOP = LAYER_N_FRONT;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Place the edge layer segments
|
2007-08-10 19:14:51 +00:00
|
|
|
TRACK TmpSegm( NULL );
|
|
|
|
|
2013-03-31 13:27:46 +00:00
|
|
|
TmpSegm.SetLayer( UNDEFINED_LAYER );
|
2007-10-13 06:18:44 +00:00
|
|
|
TmpSegm.SetNet( -1 );
|
2013-01-13 00:04:00 +00:00
|
|
|
TmpSegm.SetWidth( RoutingMatrix.m_GridRouting / 2 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
EDA_ITEM* PtStruct = aBrd->m_Drawings;
|
2012-06-08 09:56:42 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
DRAWSEGMENT* DrawSegm;
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( PtStruct->Type() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_LINE_T:
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawSegm = (DRAWSEGMENT*) PtStruct;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( DrawSegm->GetLayer() != EDGE_N )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
TmpSegm.SetStart( DrawSegm->GetStart() );
|
2013-11-24 17:48:14 +00:00
|
|
|
TmpSegm.SetEnd( DrawSegm->GetEnd() );
|
2011-12-14 04:29:25 +00:00
|
|
|
TmpSegm.SetShape( DrawSegm->GetShape() );
|
|
|
|
TmpSegm.m_Param = DrawSegm->GetAngle();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-17 16:06:12 +00:00
|
|
|
TraceSegmentPcb( &TmpSegm, HOLE | CELL_is_EDGE,
|
2012-06-05 19:07:33 +00:00
|
|
|
RoutingMatrix.m_GridRouting, WRITE_CELL );
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_TEXT_T:
|
2007-08-10 19:14:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// Mark cells of the routing matrix to CELL_is_ZONE
|
|
|
|
// (i.e. availlable cell to place a module )
|
|
|
|
// Init a starting point of attachment to the area.
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.OrCell( RoutingMatrix.m_Nrows / 2, RoutingMatrix.m_Ncols / 2,
|
|
|
|
BOTTOM, CELL_is_ZONE );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// find and mark all other availlable cells:
|
|
|
|
for( int ii = 1; ii != 0; )
|
2011-12-12 14:02:37 +00:00
|
|
|
ii = propagate();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// Initialize top layer. to the same value as the bottom layer
|
2012-06-05 19:07:33 +00:00
|
|
|
if( RoutingMatrix.m_BoardSide[TOP] )
|
|
|
|
memcpy( RoutingMatrix.m_BoardSide[TOP], RoutingMatrix.m_BoardSide[BOTTOM],
|
2012-06-10 16:21:18 +00:00
|
|
|
nbCells * sizeof(MATRIX_CELL) );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
/* Place module on Routing matrix.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2013-11-24 17:48:14 +00:00
|
|
|
void genModuleOnRoutingMatrix( MODULE* Module )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int ox, oy, fx, fy;
|
|
|
|
int layerMask;
|
|
|
|
D_PAD* Pad;
|
|
|
|
|
|
|
|
EDA_RECT fpBBox = Module->GetBoundingBox();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
fpBBox.Inflate( RoutingMatrix.m_GridRouting / 2 );
|
|
|
|
ox = fpBBox.GetX();
|
|
|
|
fx = fpBBox.GetRight();
|
|
|
|
oy = fpBBox.GetY();
|
|
|
|
fy = fpBBox.GetBottom();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( ox < RoutingMatrix.m_BrdBox.GetX() )
|
|
|
|
ox = RoutingMatrix.m_BrdBox.GetX();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( ox > RoutingMatrix.m_BrdBox.GetRight() )
|
|
|
|
ox = RoutingMatrix.m_BrdBox.GetRight();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( fx < RoutingMatrix.m_BrdBox.GetX() )
|
|
|
|
fx = RoutingMatrix.m_BrdBox.GetX();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( fx > RoutingMatrix.m_BrdBox.GetRight() )
|
|
|
|
fx = RoutingMatrix.m_BrdBox.GetRight();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( oy < RoutingMatrix.m_BrdBox.GetY() )
|
|
|
|
oy = RoutingMatrix.m_BrdBox.GetY();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( oy > RoutingMatrix.m_BrdBox.GetBottom() )
|
|
|
|
oy = RoutingMatrix.m_BrdBox.GetBottom();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( fy < RoutingMatrix.m_BrdBox.GetY() )
|
|
|
|
fy = RoutingMatrix.m_BrdBox.GetY();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( fy > RoutingMatrix.m_BrdBox.GetBottom() )
|
|
|
|
fy = RoutingMatrix.m_BrdBox.GetBottom();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
layerMask = 0;
|
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_FRONT )
|
2011-09-07 19:41:04 +00:00
|
|
|
layerMask = LAYER_FRONT;
|
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_BACK )
|
2011-09-07 19:41:04 +00:00
|
|
|
layerMask = LAYER_BACK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-17 16:06:12 +00:00
|
|
|
TraceFilledRectangle( ox, oy, fx, fy, layerMask,
|
2007-08-10 19:14:51 +00:00
|
|
|
CELL_is_MODULE, WRITE_OR_CELL );
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Trace pads + clearance areas.
|
2013-03-18 19:36:07 +00:00
|
|
|
for( Pad = Module->Pads(); Pad != NULL; Pad = Pad->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int margin = (RoutingMatrix.m_GridRouting / 2) + Pad->GetClearance();
|
|
|
|
::PlacePad( Pad, CELL_is_MODULE, margin, WRITE_OR_CELL );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Trace clearance.
|
2013-11-24 17:48:14 +00:00
|
|
|
int margin = ( RoutingMatrix.m_GridRouting * Module->GetPadCount() ) / GAIN;
|
|
|
|
CreateKeepOutRectangle( ox, oy, fx, fy, margin, KEEP_OUT_MARGIN, layerMask );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
// A minor helper function to draw a bounding box:
|
|
|
|
inline void draw_FootprintRect(EDA_RECT * aClipBox, wxDC* aDC, EDA_RECT& fpBBox, EDA_COLOR_T aColor)
|
|
|
|
{
|
|
|
|
#ifndef USE_WX_OVERLAY
|
|
|
|
GRRect( aClipBox, aDC, fpBBox, 0, aColor );
|
|
|
|
#endif
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int getOptimalModulePlacement( PCB_EDIT_FRAME* aFrame, MODULE* aModule, wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int error = 1;
|
|
|
|
wxPoint LastPosOK;
|
2013-11-24 17:48:14 +00:00
|
|
|
double min_cost, curr_cost, Score;
|
2007-08-10 19:14:51 +00:00
|
|
|
bool TstOtherSide;
|
2012-06-08 09:56:42 +00:00
|
|
|
bool showRats = g_Show_Module_Ratsnest;
|
2013-11-24 17:48:14 +00:00
|
|
|
BOARD* brd = aFrame->GetBoard();
|
2012-06-08 09:56:42 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
aModule->CalculateBoundingBox();
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
g_Show_Module_Ratsnest = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
brd->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
|
|
|
aFrame->SetMsgPanel( aModule );
|
|
|
|
|
|
|
|
LastPosOK = RoutingMatrix.m_BrdBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
wxPoint mod_pos = aModule->GetPosition();
|
|
|
|
EDA_RECT fpBBox = aModule->GetFootprintRect();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Move fpBBox to have the footprint position at (0,0)
|
|
|
|
fpBBox.Move( -mod_pos );
|
|
|
|
wxPoint fpBBoxOrg = fpBBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Calculate the limit of the footprint position, relative
|
|
|
|
// to the routing matrix area
|
|
|
|
wxPoint xylimit = RoutingMatrix.m_BrdBox.GetEnd() - fpBBox.GetEnd();
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
wxPoint initialPos = RoutingMatrix.m_BrdBox.GetOrigin() - fpBBoxOrg;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Stay on grid.
|
|
|
|
initialPos.x -= initialPos.x % RoutingMatrix.m_GridRouting;
|
|
|
|
initialPos.y -= initialPos.y % RoutingMatrix.m_GridRouting;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
CurrPosition = initialPos;
|
|
|
|
|
|
|
|
// Undraw the current footprint
|
|
|
|
g_Offset_Module = wxPoint( 0, 0 );
|
|
|
|
DrawModuleOutlines( aFrame->GetCanvas(), aDC, aModule );
|
|
|
|
|
|
|
|
g_Offset_Module = mod_pos - CurrPosition;
|
|
|
|
|
|
|
|
/* Examine pads, and set TstOtherSide to true if a footprint
|
|
|
|
* has at least 1 pad through.
|
2009-11-12 15:43:38 +00:00
|
|
|
*/
|
2011-03-09 20:09:11 +00:00
|
|
|
TstOtherSide = false;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-26 17:57:37 +00:00
|
|
|
if( RoutingMatrix.m_RoutingLayersCount > 1 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
D_PAD* Pad;
|
|
|
|
int otherLayerMask = LAYER_BACK;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
if( aModule->GetLayer() == LAYER_N_BACK )
|
2011-09-07 19:41:04 +00:00
|
|
|
otherLayerMask = LAYER_FRONT;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
for( Pad = aModule->Pads(); Pad != NULL; Pad = Pad->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
if( ( Pad->GetLayerMask() & otherLayerMask ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-03-09 20:09:11 +00:00
|
|
|
TstOtherSide = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// Draw the initial bounding box position
|
2013-11-25 11:29:16 +00:00
|
|
|
EDA_COLOR_T color = BROWN;
|
2013-11-24 17:48:14 +00:00
|
|
|
fpBBox.SetOrigin( fpBBoxOrg + CurrPosition );
|
2013-11-25 11:29:16 +00:00
|
|
|
draw_FootprintRect(aFrame->GetCanvas()->GetClipBox(), aDC, fpBBox, color);
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
min_cost = -1.0;
|
|
|
|
aFrame->SetStatusText( wxT( "Score ??, pos ??" ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
for( ; CurrPosition.x < xylimit.x; CurrPosition.x += RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
wxYield();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( aFrame->GetCanvas()->GetAbortRequest() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
if( IsOK( aFrame, _( "OK to abort?" ) ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return ESC;
|
|
|
|
else
|
2013-11-24 17:48:14 +00:00
|
|
|
aFrame->GetCanvas()->SetAbortRequest( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
CurrPosition.y = initialPos.y;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
for( ; CurrPosition.y < xylimit.y; CurrPosition.y += RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-08-03 05:15:23 +00:00
|
|
|
// Erase traces.
|
2013-11-25 11:29:16 +00:00
|
|
|
draw_FootprintRect( aFrame->GetCanvas()->GetClipBox(), aDC, fpBBox, color );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
fpBBox.SetOrigin( fpBBoxOrg + CurrPosition );
|
|
|
|
g_Offset_Module = mod_pos - CurrPosition;
|
|
|
|
int keepOutCost = TstModuleOnBoard( brd, aModule, TstOtherSide );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
// Draw at new place
|
|
|
|
color = keepOutCost >= 0 ? BROWN : RED;
|
|
|
|
draw_FootprintRect( aFrame->GetCanvas()->GetClipBox(), aDC, fpBBox, color );
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( keepOutCost >= 0 ) // i.e. if the module can be put here
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
error = 0;
|
2013-11-24 17:48:14 +00:00
|
|
|
aFrame->build_ratsnest_module( aModule );
|
|
|
|
curr_cost = compute_Ratsnest_PlaceModule( brd );
|
|
|
|
Score = curr_cost + keepOutCost;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( (min_cost >= Score ) || (min_cost < 0 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
LastPosOK = CurrPosition;
|
|
|
|
min_cost = Score;
|
2007-08-10 19:14:51 +00:00
|
|
|
wxString msg;
|
2013-11-24 17:48:14 +00:00
|
|
|
msg.Printf( wxT( "Score %g, pos %s, %s" ),
|
|
|
|
min_cost,
|
2013-11-25 06:10:24 +00:00
|
|
|
GetChars( ::CoordinateToString( LastPosOK.x ) ),
|
|
|
|
GetChars( ::CoordinateToString( LastPosOK.y ) ) );
|
2013-11-24 17:48:14 +00:00
|
|
|
aFrame->SetStatusText( msg );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
// erasing the last traces
|
|
|
|
GRRect( aFrame->GetCanvas()->GetClipBox(), aDC, fpBBox, 0, BROWN );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
g_Show_Module_Ratsnest = showRats;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Regeneration of the modified variable.
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition = LastPosOK;
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
brd->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
MinCout = min_cost;
|
2007-08-10 19:14:51 +00:00
|
|
|
return error;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Test if the rectangular area (ux, ux .. y0, y1):
|
|
|
|
* - is a free zone (except OCCUPED_By_MODULE returns)
|
|
|
|
* - is on the working surface of the board (otherwise returns OUT_OF_BOARD)
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2013-11-25 11:29:16 +00:00
|
|
|
* Returns OUT_OF_BOARD, or OCCUPED_By_MODULE or FREE_CELL if OK
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2013-11-24 17:48:14 +00:00
|
|
|
int TstRectangle( BOARD* Pcb, const EDA_RECT& aRect, int side )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
EDA_RECT rect = aRect;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
rect.Inflate( RoutingMatrix.m_GridRouting / 2 );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
wxPoint start = rect.GetOrigin();
|
|
|
|
wxPoint end = rect.GetEnd();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
start -= RoutingMatrix.m_BrdBox.GetOrigin();
|
|
|
|
end -= RoutingMatrix.m_BrdBox.GetOrigin();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int row_min = start.y / RoutingMatrix.m_GridRouting;
|
|
|
|
int row_max = end.y / RoutingMatrix.m_GridRouting;
|
|
|
|
int col_min = start.x / RoutingMatrix.m_GridRouting;
|
|
|
|
int col_max = end.x / RoutingMatrix.m_GridRouting;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( start.y > row_min * RoutingMatrix.m_GridRouting )
|
|
|
|
row_min++;
|
|
|
|
|
|
|
|
if( start.x > col_min * RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( row_max >= ( RoutingMatrix.m_Nrows - 1 ) )
|
|
|
|
row_max = RoutingMatrix.m_Nrows - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( col_max >= ( RoutingMatrix.m_Ncols - 1 ) )
|
|
|
|
col_max = RoutingMatrix.m_Ncols - 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
for( int row = row_min; row <= row_max; row++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
for( int col = col_min; col <= col_max; col++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
unsigned int data = RoutingMatrix.GetCell( row, col, side );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( data & CELL_is_ZONE ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return OUT_OF_BOARD;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( (data & CELL_is_MODULE) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return OCCUPED_By_MODULE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
return FREE_CELL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Calculates and returns the clearance area of the rectangular surface
|
2013-11-24 17:48:14 +00:00
|
|
|
* aRect):
|
2009-11-12 15:43:38 +00:00
|
|
|
* (Sum of cells in terms of distance)
|
|
|
|
*/
|
2013-11-24 17:48:14 +00:00
|
|
|
unsigned int CalculateKeepOutArea( const EDA_RECT& aRect, int side )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
wxPoint start = aRect.GetOrigin();
|
|
|
|
wxPoint end = aRect.GetEnd();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
start -= RoutingMatrix.m_BrdBox.GetOrigin();
|
|
|
|
end -= RoutingMatrix.m_BrdBox.GetOrigin();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int row_min = start.y / RoutingMatrix.m_GridRouting;
|
|
|
|
int row_max = end.y / RoutingMatrix.m_GridRouting;
|
|
|
|
int col_min = start.x / RoutingMatrix.m_GridRouting;
|
|
|
|
int col_max = end.x / RoutingMatrix.m_GridRouting;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( start.y > row_min * RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_min++;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( start.x > col_min * RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( row_max >= ( RoutingMatrix.m_Nrows - 1 ) )
|
|
|
|
row_max = RoutingMatrix.m_Nrows - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( col_max >= ( RoutingMatrix.m_Ncols - 1 ) )
|
|
|
|
col_max = RoutingMatrix.m_Ncols - 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
unsigned int keepOutCost = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
for( int row = row_min; row <= row_max; row++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
for( int col = col_min; col <= col_max; col++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
// RoutingMatrix.GetDist returns the "cost" of the cell
|
|
|
|
// at position (row, col)
|
|
|
|
// in autoplace this is the cost of the cell, if it is
|
|
|
|
// inside aRect
|
|
|
|
keepOutCost += RoutingMatrix.GetDist( row, col, side );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
return keepOutCost;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Test if the module can be placed on the board.
|
|
|
|
* Returns the value TstRectangle().
|
2013-11-24 17:48:14 +00:00
|
|
|
* Module is known by its bounding box
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2013-11-24 17:48:14 +00:00
|
|
|
int TstModuleOnBoard( BOARD* Pcb, MODULE* aModule, bool TstOtherSide )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int side = TOP;
|
|
|
|
int otherside = BOTTOM;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( aModule->GetLayer() == LAYER_N_BACK )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
side = BOTTOM; otherside = TOP;
|
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
EDA_RECT fpBBox = aModule->GetFootprintRect();
|
|
|
|
fpBBox.Move( -g_Offset_Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int diag = TstRectangle( Pcb, fpBBox, side );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( diag != FREE_CELL )
|
2013-11-24 17:48:14 +00:00
|
|
|
return diag;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( TstOtherSide )
|
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
diag = TstRectangle( Pcb, fpBBox, otherside );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-25 11:29:16 +00:00
|
|
|
if( diag != FREE_CELL )
|
2013-11-24 17:48:14 +00:00
|
|
|
return diag;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
int marge = ( RoutingMatrix.m_GridRouting * aModule->GetPadCount() ) / GAIN;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
fpBBox.Inflate( marge );
|
|
|
|
return CalculateKeepOutArea( fpBBox, side );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
double compute_Ratsnest_PlaceModule( BOARD* aBrd )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
double curr_cost;
|
2012-06-08 09:56:42 +00:00
|
|
|
wxPoint start; // start point of a ratsnest
|
|
|
|
wxPoint end; // end point of a ratsnest
|
2013-11-24 17:48:14 +00:00
|
|
|
int dx, dy;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( ( aBrd->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return -1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
curr_cost = 0;
|
2010-01-29 20:36:12 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
for( unsigned ii = 0; ii < aBrd->m_LocalRatsnest.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
RATSNEST_ITEM* pt_local_rats_nest = &aBrd->m_LocalRatsnest[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( ( pt_local_rats_nest->m_Status & LOCAL_RATSNEST_ITEM ) )
|
2013-11-24 17:48:14 +00:00
|
|
|
continue; // Skip ratsnest between 2 pads of the current module
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// Skip modules not inside the board area
|
2013-11-24 17:48:14 +00:00
|
|
|
MODULE* module = pt_local_rats_nest->m_PadEnd->GetParent();
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
if( !RoutingMatrix.m_BrdBox.Contains( module->GetPosition() ) )
|
|
|
|
continue;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
start = pt_local_rats_nest->m_PadStart->GetPosition() - g_Offset_Module;
|
|
|
|
end = pt_local_rats_nest->m_PadEnd->GetPosition();
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Cost of the ratsnest.
|
2013-11-24 17:48:14 +00:00
|
|
|
dx = end.x - start.x;
|
|
|
|
dy = end.y - start.y;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
dx = abs( dx );
|
|
|
|
dy = abs( dy );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
// ttry to have always dx >= dy to calculate the cost of the rastsnet
|
|
|
|
if( dx < dy )
|
|
|
|
EXCHG( dx, dy );
|
|
|
|
|
|
|
|
// Cost of the connection = lenght + penalty due to the slope
|
|
|
|
// dx is the biggest lenght relative to the X or Y axis
|
|
|
|
// the penalty is max for 45 degrees ratsnests,
|
|
|
|
// and 0 for horizontal or vertical ratsnests.
|
|
|
|
// For Horizontal and Vertical ratsnests, dy = 0;
|
2013-11-24 17:48:14 +00:00
|
|
|
double conn_cost = hypot( dx, dy * 2.0 );
|
|
|
|
curr_cost += conn_cost; // Total cost = sum of costs of each connection
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
return curr_cost;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function CreateKeepOutRectangle
|
2012-06-08 09:56:42 +00:00
|
|
|
* builds the cost map:
|
|
|
|
* Cells ( in Dist map ) inside the rect x0,y0 a x1,y1 are
|
2011-09-20 13:57:40 +00:00
|
|
|
* incremented by value aKeepOut
|
2009-11-15 14:12:53 +00:00
|
|
|
* Cell outside this rectangle, but inside the rectangle
|
2012-06-08 09:56:42 +00:00
|
|
|
* x0,y0 -marge to x1,y1 + marge are incremented by a decreasing value
|
2013-11-24 17:48:14 +00:00
|
|
|
* (aKeepOut ... 0). The decreasing value depends on the distance to the first rectangle
|
|
|
|
* Therefore the cost is high in rect x0,y0 to x1,y1, and decrease outside this rectangle
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2012-06-08 09:56:42 +00:00
|
|
|
void CreateKeepOutRectangle( int ux0, int uy0, int ux1, int uy1,
|
|
|
|
int marge, int aKeepOut, int aLayerMask )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int row, col;
|
|
|
|
int row_min, row_max, col_min, col_max, pmarge;
|
|
|
|
int trace = 0;
|
|
|
|
DIST_CELL data, LocalKeepOut;
|
|
|
|
int lgain, cgain;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
if( aLayerMask & GetLayerMask( g_Route_Layer_BOTTOM ) )
|
2013-11-24 17:48:14 +00:00
|
|
|
trace = 1; // Trace on bottom layer.
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-03-27 18:32:12 +00:00
|
|
|
if( ( aLayerMask & GetLayerMask( g_Route_Layer_TOP ) ) && RoutingMatrix.m_RoutingLayersCount )
|
2013-11-24 17:48:14 +00:00
|
|
|
trace |= 2; // Trace on top layer.
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( trace == 0 )
|
|
|
|
return;
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
ux0 -= RoutingMatrix.m_BrdBox.GetX();
|
|
|
|
uy0 -= RoutingMatrix.m_BrdBox.GetY();
|
|
|
|
ux1 -= RoutingMatrix.m_BrdBox.GetX();
|
|
|
|
uy1 -= RoutingMatrix.m_BrdBox.GetY();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
ux0 -= marge; ux1 += marge;
|
|
|
|
uy0 -= marge; uy1 += marge;
|
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
pmarge = marge / RoutingMatrix.m_GridRouting;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
|
|
|
if( pmarge < 1 )
|
2007-08-10 19:14:51 +00:00
|
|
|
pmarge = 1;
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Calculate the coordinate limits of the rectangle.
|
2012-06-05 19:07:33 +00:00
|
|
|
row_max = uy1 / RoutingMatrix.m_GridRouting;
|
|
|
|
col_max = ux1 / RoutingMatrix.m_GridRouting;
|
|
|
|
row_min = uy0 / RoutingMatrix.m_GridRouting;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
if( uy0 > row_min * RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_min++;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
col_min = ux0 / RoutingMatrix.m_GridRouting;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-05 19:07:33 +00:00
|
|
|
if( ux0 > col_min * RoutingMatrix.m_GridRouting )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( row_max >= (RoutingMatrix.m_Nrows - 1) )
|
|
|
|
row_max = RoutingMatrix.m_Nrows - 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
if( col_max >= (RoutingMatrix.m_Ncols - 1) )
|
|
|
|
col_max = RoutingMatrix.m_Ncols - 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
lgain = 256;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( row < pmarge )
|
2009-11-12 15:43:38 +00:00
|
|
|
lgain = ( 256 * row ) / pmarge;
|
2007-08-10 19:14:51 +00:00
|
|
|
else if( row > row_max - pmarge )
|
2009-11-12 15:43:38 +00:00
|
|
|
lgain = ( 256 * ( row_max - row ) ) / pmarge;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
// RoutingMatrix Dist map containt the "cost" of the cell
|
|
|
|
// at position (row, col)
|
|
|
|
// in autoplace this is the cost of the cell, when
|
|
|
|
// a footprint overlaps it, near a "master" footprint
|
|
|
|
// this cost is hight near the "master" footprint
|
|
|
|
// and decrease with the distance
|
2007-08-10 19:14:51 +00:00
|
|
|
cgain = 256;
|
2011-09-20 13:57:40 +00:00
|
|
|
LocalKeepOut = aKeepOut;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( col < pmarge )
|
2009-11-12 15:43:38 +00:00
|
|
|
cgain = ( 256 * col ) / pmarge;
|
2007-08-10 19:14:51 +00:00
|
|
|
else if( col > col_max - pmarge )
|
2009-11-12 15:43:38 +00:00
|
|
|
cgain = ( 256 * ( col_max - col ) ) / pmarge;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
cgain = ( cgain * lgain ) / 256;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( cgain != 256 )
|
2011-09-16 14:13:02 +00:00
|
|
|
LocalKeepOut = ( LocalKeepOut * cgain ) / 256;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( trace & 1 )
|
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
data = RoutingMatrix.GetDist( row, col, BOTTOM ) + LocalKeepOut;
|
|
|
|
RoutingMatrix.SetDist( row, col, BOTTOM, data );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( trace & 2 )
|
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
data = RoutingMatrix.GetDist( row, col, TOP );
|
|
|
|
data = std::max( data, LocalKeepOut );
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.SetDist( row, col, TOP, data );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Sort routines
|
2010-11-26 17:47:35 +00:00
|
|
|
static bool Tri_PlaceModules( MODULE* ref, MODULE* compare )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
double ff1, ff2;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
ff1 = ref->GetArea() * ref->GetPadCount();
|
|
|
|
ff2 = compare->GetArea() * compare->GetPadCount();
|
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
return ff2 < ff1;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-11-27 13:20:42 +00:00
|
|
|
static bool sortFootprintsByRatsnestSize( MODULE* ref, MODULE* compare )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
double ff1, ff2;
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
ff1 = ref->GetArea() * ref->GetFlag();
|
|
|
|
ff2 = compare->GetArea() * compare->GetFlag();
|
2010-11-26 17:47:35 +00:00
|
|
|
return ff2 < ff1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
/**
|
|
|
|
* Function PickModule
|
|
|
|
* find the "best" module place
|
|
|
|
* The criteria are:
|
2011-09-16 14:13:02 +00:00
|
|
|
* - Maximum ratsnest with modules already placed
|
2009-11-12 15:43:38 +00:00
|
|
|
* - Max size, and number of pads max
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
MODULE* Module;
|
2010-11-26 17:47:35 +00:00
|
|
|
std::vector <MODULE*> moduleList;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
// Build sorted footprints list (sort by decreasing size )
|
|
|
|
Module = pcbframe->GetBoard()->m_Modules;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
Module->CalculateBoundingBox();
|
2013-11-24 17:48:14 +00:00
|
|
|
moduleList.push_back( Module );
|
2010-11-26 17:47:35 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
sort( moduleList.begin(), moduleList.end(), Tri_PlaceModules );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
for( unsigned ii = 0; ii < moduleList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
Module = moduleList[ii];
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->SetFlag( 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !Module->NeedsPlaced() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2013-01-12 17:32:24 +00:00
|
|
|
pcbframe->SetMsgPanel( Module );
|
2010-12-29 17:47:32 +00:00
|
|
|
pcbframe->build_ratsnest_module( Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Calculate external ratsnest.
|
2011-09-07 19:41:04 +00:00
|
|
|
for( unsigned ii = 0; ii < pcbframe->GetBoard()->m_LocalRatsnest.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( pcbframe->GetBoard()->m_LocalRatsnest[ii].m_Status &
|
|
|
|
LOCAL_RATSNEST_ITEM ) == 0 )
|
2013-03-13 18:53:58 +00:00
|
|
|
Module->IncrementFlag();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-11-27 13:20:42 +00:00
|
|
|
sort( moduleList.begin(), moduleList.end(), sortFootprintsByRatsnestSize );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
// Search for "best" module.
|
2013-11-24 17:48:14 +00:00
|
|
|
MODULE* bestModule = NULL;
|
|
|
|
MODULE* altModule = NULL;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
for( unsigned ii = 0; ii < moduleList.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
Module = moduleList[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( !Module->NeedsPlaced() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
altModule = Module;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( Module->GetFlag() == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
bestModule = Module;
|
|
|
|
break;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
if( bestModule )
|
|
|
|
return bestModule;
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
2010-11-26 17:47:35 +00:00
|
|
|
return altModule;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-08 09:56:42 +00:00
|
|
|
/**
|
|
|
|
* Function propagate
|
|
|
|
* Used only in autoplace calculations
|
|
|
|
* Uses the routing matrix to fill the cells within the zone
|
|
|
|
* Search and mark cells within the zone, and agree with DRC options.
|
|
|
|
* Requirements:
|
|
|
|
* Start from an initial point, to fill zone
|
|
|
|
* The zone must have no "copper island"
|
|
|
|
* Algorithm:
|
|
|
|
* If the current cell has a neighbor flagged as "cell in the zone", it
|
|
|
|
* become a cell in the zone
|
|
|
|
* The first point in the zone is the starting point
|
|
|
|
* 4 searches within the matrix are made:
|
|
|
|
* 1 - Left to right and top to bottom
|
|
|
|
* 2 - Right to left and top to bottom
|
|
|
|
* 3 - bottom to top and Right to left
|
|
|
|
* 4 - bottom to top and Left to right
|
|
|
|
* Given the current cell, for each search, we consider the 2 neighbor cells
|
|
|
|
* the previous cell on the same line and the previous cell on the same column.
|
|
|
|
*
|
|
|
|
* This function can request some iterations
|
|
|
|
* Iterations are made until no cell is added to the zone.
|
2012-09-22 11:19:37 +00:00
|
|
|
* @return added cells count (i.e. which the attribute CELL_is_ZONE is set)
|
2012-06-08 09:56:42 +00:00
|
|
|
*/
|
|
|
|
int propagate()
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2013-11-24 17:48:14 +00:00
|
|
|
int row, col;
|
|
|
|
long current_cell, old_cell_H;
|
|
|
|
std::vector<long> pt_cell_V;
|
|
|
|
int nbpoints = 0;
|
2010-11-26 17:47:35 +00:00
|
|
|
|
|
|
|
#define NO_CELL_ZONE (HOLE | CELL_is_EDGE | CELL_is_ZONE)
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
pt_cell_V.reserve( std::max( RoutingMatrix.m_Nrows, RoutingMatrix.m_Ncols ) );
|
2011-11-10 15:55:05 +00:00
|
|
|
fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
// Search from left to right and top to bottom.
|
2012-06-10 16:21:18 +00:00
|
|
|
for( row = 0; row < RoutingMatrix.m_Nrows; row++ )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( col = 0; col < RoutingMatrix.m_Ncols; col++ )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
current_cell = RoutingMatrix.GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( current_cell == 0 ) // a free cell is found
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[col] & CELL_is_ZONE) )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
2010-11-26 17:47:35 +00:00
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
pt_cell_V[col] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
// Search from right to left and top to bottom/
|
|
|
|
fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( row = 0; row < RoutingMatrix.m_Nrows; row++ )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
2011-11-10 15:55:05 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( col = RoutingMatrix.m_Ncols - 1; col >= 0; col-- )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
current_cell = RoutingMatrix.GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( current_cell == 0 ) // a free cell is found
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[col] & CELL_is_ZONE) )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
2010-11-26 17:47:35 +00:00
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
pt_cell_V[col] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
// Search from bottom to top and right to left.
|
|
|
|
fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( col = RoutingMatrix.m_Ncols - 1; col >= 0; col-- )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( row = RoutingMatrix.m_Nrows - 1; row >= 0; row-- )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
current_cell = RoutingMatrix.GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( current_cell == 0 ) // a free cell is found
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[row] & CELL_is_ZONE) )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
2010-11-26 17:47:35 +00:00
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
pt_cell_V[row] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
// Search from bottom to top and left to right.
|
|
|
|
fill( pt_cell_V.begin(), pt_cell_V.end(), 0 );
|
2011-04-12 14:19:59 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( col = 0; col < RoutingMatrix.m_Ncols; col++ )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-06-10 16:21:18 +00:00
|
|
|
for( row = RoutingMatrix.m_Nrows - 1; row >= 0; row-- )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
current_cell = RoutingMatrix.GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2013-11-24 17:48:14 +00:00
|
|
|
if( current_cell == 0 ) // a free cell is found
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[row] & CELL_is_ZONE) )
|
2010-11-26 17:47:35 +00:00
|
|
|
{
|
2012-06-10 16:21:18 +00:00
|
|
|
RoutingMatrix.OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
2010-11-26 17:47:35 +00:00
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
pt_cell_V[row] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nbpoints;
|
|
|
|
}
|