2009-11-12 15:43:38 +00:00
|
|
|
/*******************************************/
|
|
|
|
/* Routines to automatically place MODULES */
|
|
|
|
/*******************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "autorout.h"
|
2008-10-20 05:59:58 +00:00
|
|
|
#include "zones.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "cell.h"
|
2009-10-28 11:48:47 +00:00
|
|
|
#include "class_board_design_settings.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
#define GAIN 16
|
2007-06-05 12:10:51 +00:00
|
|
|
#define PENALITE 500
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Penalty for guidance given by CntRot90 and CntRot180:
|
|
|
|
* graduated from 0 (rotation allowed) to 10 (rotation count null)
|
|
|
|
* the count is increased.
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
static const float OrientPenality[11] =
|
|
|
|
{
|
|
|
|
2.0f, /* CntRot = 0 rotation prohibited */
|
|
|
|
1.9f, /* CntRot = 1 */
|
|
|
|
1.8f, /* CntRot = 2 */
|
|
|
|
1.7f, /* CntRot = 3 */
|
|
|
|
1.6f, /* CntRot = 4 */
|
|
|
|
1.5f, /* CntRot = 5 */
|
|
|
|
1.4f, /* CntRot = 5 */
|
|
|
|
1.3f, /* CntRot = 7 */
|
|
|
|
1.2f, /* CntRot = 8 */
|
|
|
|
1.1f, /* CntRot = 9 */
|
|
|
|
1.0f /* CntRot = 10 rotation authorized, no penalty */
|
2007-08-10 19:14:51 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Cell states. */
|
2007-08-10 19:14:51 +00:00
|
|
|
#define OUT_OF_BOARD -2
|
2007-06-05 12:10:51 +00:00
|
|
|
#define OCCUPED_By_MODULE -1
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
static wxPoint CurrPosition; // Current position of the current module
|
|
|
|
// placement
|
2007-08-10 19:14:51 +00:00
|
|
|
static bool AutoPlaceShowAll = TRUE;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
float MinCout;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
static int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
static void TracePenaliteRectangle( BOARD* Pcb,
|
|
|
|
int ux0,
|
|
|
|
int uy0,
|
|
|
|
int ux1,
|
|
|
|
int uy1,
|
|
|
|
int marge,
|
|
|
|
int Penalite,
|
|
|
|
int masque_layer );
|
|
|
|
static MODULE* PickModule( WinEDA_PcbFrame* pcbframe, wxDC* DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Routine to automatically place components in the contour of the PCB
|
|
|
|
* The components with the FIXED status are not moved. If the menu is
|
|
|
|
* calling the placement of 1 module, it will be replaced.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
void WinEDA_PcbFrame::AutoPlaceModule( MODULE* Module,
|
|
|
|
int place_mode,
|
|
|
|
wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int ii, activ;
|
|
|
|
MODULE* ThisModule = NULL;
|
|
|
|
wxPoint PosOK;
|
|
|
|
wxPoint memopos;
|
|
|
|
int error;
|
2009-11-12 15:43:38 +00:00
|
|
|
int NbModules = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
int NbTotalModules = 0;
|
|
|
|
float Pas;
|
|
|
|
int lay_tmp_TOP, lay_tmp_BOTTOM, OldPasRoute;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
DrawPanel->m_AbortRequest = FALSE;
|
|
|
|
DrawPanel->m_AbortEnable = TRUE;
|
|
|
|
|
|
|
|
switch( place_mode )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_1_MODULE:
|
2007-08-10 19:14:51 +00:00
|
|
|
ThisModule = Module;
|
|
|
|
if( ThisModule == NULL )
|
|
|
|
return;
|
|
|
|
ThisModule->m_ModuleStatus &= ~(MODULE_is_PLACED | MODULE_to_PLACE);
|
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_OUT_OF_BOARD:
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_ALL:
|
2007-08-10 19:14:51 +00:00
|
|
|
if( !IsOK( this, _( "Footprints NOT LOCKED will be moved" ) ) )
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_INCREMENTAL:
|
2007-08-10 19:14:51 +00:00
|
|
|
if( !IsOK( this, _( "Footprints NOT PLACED will be moved" ) ) )
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memopos = CurrPosition;
|
|
|
|
lay_tmp_BOTTOM = Route_Layer_BOTTOM;
|
|
|
|
lay_tmp_TOP = Route_Layer_TOP;
|
|
|
|
OldPasRoute = g_GridRoutingSize;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
g_GridRoutingSize = (int) GetScreen()->GetGridSize().x;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
// Ensure g_GridRoutingSize has a reasonnable value:
|
|
|
|
if( g_GridRoutingSize < 10 )
|
2009-11-12 15:43:38 +00:00
|
|
|
g_GridRoutingSize = 10; // Min value = 1/1000 inch
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
/* Compute module parmeters used in auto place */
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2010-11-26 17:47:35 +00:00
|
|
|
NbTotalModules = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
Module->Set_Rectangle_Encadrement();
|
|
|
|
Module->SetRectangleExinscrit();
|
2010-11-26 17:47:35 +00:00
|
|
|
NbTotalModules ++;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( GenPlaceBoard() == 0 )
|
|
|
|
return;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
Module->m_ModuleStatus &= ~MODULE_to_PLACE;
|
|
|
|
|
|
|
|
switch( place_mode )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_1_MODULE:
|
2007-08-10 19:14:51 +00:00
|
|
|
if( ThisModule == Module )
|
|
|
|
Module->m_ModuleStatus |= MODULE_to_PLACE;
|
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_OUT_OF_BOARD:
|
2007-08-10 19:14:51 +00:00
|
|
|
Module->m_ModuleStatus &= ~MODULE_is_PLACED;
|
|
|
|
if( Module->m_ModuleStatus & MODULE_is_LOCKED )
|
|
|
|
break;
|
2009-01-05 05:21:35 +00:00
|
|
|
if( !GetBoard()->m_BoundaryBox.Inside( Module->m_Pos ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
Module->m_ModuleStatus |= MODULE_to_PLACE;
|
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_ALL:
|
2007-08-10 19:14:51 +00:00
|
|
|
Module->m_ModuleStatus &= ~MODULE_is_PLACED;
|
|
|
|
if( Module->m_ModuleStatus & MODULE_is_LOCKED )
|
|
|
|
break;
|
|
|
|
Module->m_ModuleStatus |= MODULE_to_PLACE;
|
|
|
|
break;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
case PLACE_INCREMENTAL:
|
2007-08-10 19:14:51 +00:00
|
|
|
if( Module->m_ModuleStatus & MODULE_is_LOCKED )
|
|
|
|
{
|
|
|
|
Module->m_ModuleStatus &= ~MODULE_is_PLACED; break;
|
|
|
|
}
|
|
|
|
if( !(Module->m_ModuleStatus & MODULE_is_PLACED) )
|
|
|
|
Module->m_ModuleStatus |= MODULE_to_PLACE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( Module->m_ModuleStatus & MODULE_to_PLACE ) // Erase from screen
|
|
|
|
{
|
|
|
|
NbModules++;
|
2008-04-01 05:21:50 +00:00
|
|
|
Module->Draw( DrawPanel, DC, GR_XOR );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GenModuleOnBoard( Module );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
activ = 0;
|
|
|
|
Pas = 100.0;
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( NbModules )
|
|
|
|
Pas = 100.0 / (float) NbModules;
|
|
|
|
while( ( Module = PickModule( this, DC ) ) != NULL )
|
|
|
|
{
|
|
|
|
float BestScore;
|
|
|
|
DisplayActivity( (int) (activ * Pas), wxEmptyString ); activ++;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Display fill area of interest, barriers, penalties. */
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawInfoPlace( DC );
|
|
|
|
|
|
|
|
error = RecherchePlacementModule( Module, DC );
|
|
|
|
BestScore = MinCout;
|
2009-11-12 15:43:38 +00:00
|
|
|
PosOK = CurrPosition;
|
2007-08-10 19:14:51 +00:00
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Determine if the best orientation of a module is 180. */
|
2007-08-10 19:14:51 +00:00
|
|
|
ii = Module->m_CntRot180 & 0x0F;
|
2009-11-12 15:43:38 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
int Angle_Rot_Module = 1800;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
Module->SetRectangleExinscrit();
|
|
|
|
error = RecherchePlacementModule( Module, DC );
|
|
|
|
MinCout *= OrientPenality[ii];
|
2009-11-12 15:43:38 +00:00
|
|
|
if( BestScore > MinCout ) /* This orientation is best. */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
PosOK = CurrPosition;
|
|
|
|
BestScore = MinCout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Angle_Rot_Module = -1800;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
}
|
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Determine if the best orientation of a module is 90. */
|
2007-08-10 19:14:51 +00:00
|
|
|
ii = Module->m_CntRot90 & 0x0F;
|
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
int Angle_Rot_Module = 900;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
error = RecherchePlacementModule( Module, DC );
|
|
|
|
MinCout *= OrientPenality[ii];
|
2009-11-12 15:43:38 +00:00
|
|
|
if( BestScore > MinCout ) /* This orientation is best. */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
PosOK = CurrPosition;
|
|
|
|
BestScore = MinCout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Angle_Rot_Module = -900;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
}
|
|
|
|
if( error == ESC )
|
|
|
|
goto end_of_tst;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Determine if the best orientation of a module is 270. */
|
2007-08-10 19:14:51 +00:00
|
|
|
ii = (Module->m_CntRot90 >> 4 ) & 0x0F;
|
|
|
|
if( ii != 0 )
|
|
|
|
{
|
|
|
|
int Angle_Rot_Module = 2700;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
error = RecherchePlacementModule( Module, DC );
|
|
|
|
MinCout *= OrientPenality[ii];
|
2009-11-12 15:43:38 +00:00
|
|
|
if( BestScore > MinCout ) /* This orientation is best. */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
PosOK = CurrPosition;
|
|
|
|
BestScore = MinCout;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Angle_Rot_Module = -2700;
|
|
|
|
Rotate_Module( DC, Module, Angle_Rot_Module, FALSE );
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Place module. */
|
2008-04-17 16:25:29 +00:00
|
|
|
CurrPosition = GetScreen()->m_Curseur;
|
|
|
|
GetScreen()->m_Curseur = PosOK;
|
2007-08-10 19:14:51 +00:00
|
|
|
Place_Module( Module, DC );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur = CurrPosition;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
Module->Set_Rectangle_Encadrement();
|
|
|
|
Module->SetRectangleExinscrit();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
GenModuleOnBoard( Module );
|
|
|
|
Module->m_ModuleStatus |= MODULE_is_PLACED;
|
|
|
|
Module->m_ModuleStatus &= ~MODULE_to_PLACE;
|
|
|
|
}
|
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
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
Board.UnInitBoard();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
Route_Layer_TOP = lay_tmp_TOP;
|
|
|
|
Route_Layer_BOTTOM = lay_tmp_BOTTOM;
|
|
|
|
g_GridRoutingSize = OldPasRoute;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
Module->Set_Rectangle_Encadrement();
|
|
|
|
}
|
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 );
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawPanel->ReDraw( DC, TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawPanel->m_AbortEnable = FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
void WinEDA_PcbFrame::DrawInfoPlace( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
int color, ii, jj;
|
|
|
|
int ox, oy;
|
2009-06-01 18:28:34 +00:00
|
|
|
BoardCell top_state, bottom_state;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, GR_COPY );
|
|
|
|
for( ii = 0; ii < Nrows; ii++ )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
oy = GetBoard()->m_BoundaryBox.m_Pos.y + ( ii * g_GridRoutingSize );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
for( jj = 0; jj < Ncols; jj++ )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
ox = GetBoard()->m_BoundaryBox.m_Pos.x +
|
|
|
|
(jj * g_GridRoutingSize);
|
2007-08-10 19:14:51 +00:00
|
|
|
color = BLACK;
|
|
|
|
|
|
|
|
top_state = GetCell( ii, jj, TOP );
|
|
|
|
bottom_state = GetCell( ii, jj, BOTTOM );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( top_state & CELL_is_ZONE )
|
2007-08-10 19:14:51 +00:00
|
|
|
color = BLUE;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
else /* Display the filling and keep out regions. */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
if( GetDist( ii, jj, TOP ) || GetDist( ii, jj, BOTTOM ) )
|
|
|
|
color = DARKGRAY;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRPutPixel( &DrawPanel->m_ClipBox, DC, ox, oy, color );
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Generate board (component side copper + rating):
|
|
|
|
* Allocate the memory needed to represent in "bitmap" on the grid
|
|
|
|
* Current:
|
|
|
|
* - The size of clearance area of component (the board)
|
|
|
|
* - The bitmap PENALTIES
|
|
|
|
* And initialize the cells of the board has
|
|
|
|
* - Hole in the cells occupied by a segment EDGE
|
|
|
|
* - CELL_is_ZONE for cell internal contour EDGE (if closed)
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* Placement surface (board) gives the cells internal to the contour
|
|
|
|
* PCB, and among the latter the free cells and cells already occupied
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* The bitmap PENALTIES give cells occupied by the modules,
|
|
|
|
* Plus a surface penalty related to the number of pads of the module
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* Bitmap of the penalty is set to 0
|
|
|
|
* Occupation cell is a 0 leaves
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
int WinEDA_PcbFrame::GenPlaceBoard()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int jj, ii;
|
|
|
|
int NbCells;
|
|
|
|
EDA_BaseStruct* PtStruct;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
Board.UnInitBoard();
|
|
|
|
|
|
|
|
if( !SetBoardBoundaryBoxFromEdgesOnly() )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
DisplayError( this, _( "No PCB edge found, unknown board size!" ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The boundary box must have its start point on placing grid: */
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x -= GetBoard()->m_BoundaryBox.m_Pos.x %
|
|
|
|
g_GridRoutingSize;
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.y -= GetBoard()->m_BoundaryBox.m_Pos.y %
|
|
|
|
g_GridRoutingSize;
|
2007-08-10 19:14:51 +00:00
|
|
|
/* The boundary box must have its end point on placing grid: */
|
2009-01-05 05:21:35 +00:00
|
|
|
wxPoint end = GetBoard()->m_BoundaryBox.GetEnd();
|
2007-08-10 19:14:51 +00:00
|
|
|
end.x -= end.x % g_GridRoutingSize; end.x += g_GridRoutingSize;
|
|
|
|
end.y -= end.y % g_GridRoutingSize; end.y += g_GridRoutingSize;
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_BoundaryBox.SetEnd( end );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Nrows = GetBoard()->m_BoundaryBox.GetHeight() / g_GridRoutingSize;
|
|
|
|
Ncols = GetBoard()->m_BoundaryBox.GetWidth() / g_GridRoutingSize;
|
2007-08-10 19:14:51 +00:00
|
|
|
/* get a small margin for memory allocation: */
|
|
|
|
Ncols += 2; Nrows += 2;
|
|
|
|
NbCells = Ncols * Nrows;
|
|
|
|
|
|
|
|
MsgPanel->EraseMsgBox();
|
|
|
|
msg.Printf( wxT( "%d" ), Ncols );
|
|
|
|
Affiche_1_Parametre( this, 1, _( "Cols" ), msg, GREEN );
|
|
|
|
msg.Printf( wxT( "%d" ), Nrows );
|
|
|
|
Affiche_1_Parametre( this, 7, _( "Lines" ), msg, GREEN );
|
|
|
|
msg.Printf( wxT( "%d" ), NbCells );
|
|
|
|
Affiche_1_Parametre( this, 14, _( "Cells." ), msg, YELLOW );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Choose the number of board sides. */
|
2007-08-10 19:14:51 +00:00
|
|
|
Nb_Sides = TWO_SIDES;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
Affiche_1_Parametre( this, 22, wxT( "S" ),
|
|
|
|
( Nb_Sides == TWO_SIDES ) ? wxT( "2" ) : wxT( "1" ),
|
|
|
|
WHITE );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
Board.InitBoard();
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Display memory usage. */
|
2007-08-10 19:14:51 +00:00
|
|
|
msg.Printf( wxT( "%d" ), Board.m_MemSize / 1024 );
|
2009-11-12 15:43:38 +00:00
|
|
|
Affiche_1_Parametre( this, 24, wxT( "Mem(Kb)" ), msg, CYAN );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-12-07 03:46:13 +00:00
|
|
|
Route_Layer_BOTTOM = LAYER_N_FRONT;
|
2007-08-10 19:14:51 +00:00
|
|
|
if( Nb_Sides == TWO_SIDES )
|
2009-12-07 03:46:13 +00:00
|
|
|
Route_Layer_BOTTOM = LAYER_N_BACK;
|
|
|
|
Route_Layer_TOP = LAYER_N_FRONT;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
/* Place the edge layer segments */
|
2009-01-05 05:21:35 +00:00
|
|
|
PtStruct = GetBoard()->m_Drawings;
|
2007-08-10 19:14:51 +00:00
|
|
|
TRACK TmpSegm( NULL );
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
TmpSegm.SetLayer( -1 );
|
2007-10-13 06:18:44 +00:00
|
|
|
TmpSegm.SetNet( -1 );
|
2009-11-12 15:43:38 +00:00
|
|
|
TmpSegm.m_Width = g_GridRoutingSize / 2;
|
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
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_DRAWSEGMENT:
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawSegm = (DRAWSEGMENT*) PtStruct;
|
2007-08-23 04:28:46 +00:00
|
|
|
if( DrawSegm->GetLayer() != EDGE_N )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
TmpSegm.m_Start = DrawSegm->m_Start;
|
|
|
|
TmpSegm.m_End = DrawSegm->m_End;
|
|
|
|
TmpSegm.m_Shape = DrawSegm->m_Shape;
|
|
|
|
TmpSegm.m_Param = DrawSegm->m_Angle;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
TraceSegmentPcb( GetBoard(), &TmpSegm, HOLE | CELL_is_EDGE,
|
|
|
|
g_GridRoutingSize, WRITE_CELL );
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
case TYPE_TEXTE:
|
2007-08-10 19:14:51 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Init the point of attachment to the area. */
|
2007-08-10 19:14:51 +00:00
|
|
|
OrCell( Nrows / 2, Ncols / 2, BOTTOM, CELL_is_ZONE );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Fill bottom layer zones. */
|
|
|
|
ii = 1;
|
|
|
|
jj = 1;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
while( ii )
|
|
|
|
{
|
|
|
|
msg.Printf( wxT( "%d" ), jj++ );
|
|
|
|
Affiche_1_Parametre( this, 50, _( "Loop" ), msg, CYAN );
|
|
|
|
ii = Propagation( this );
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Initialize top layer. */
|
2007-08-10 19:14:51 +00:00
|
|
|
if( Board.m_BoardSide[TOP] )
|
2009-11-12 15:43:38 +00:00
|
|
|
memcpy( Board.m_BoardSide[TOP], Board.m_BoardSide[BOTTOM],
|
|
|
|
NbCells * sizeof(BoardCell) );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Place module on board.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
void WinEDA_PcbFrame::GenModuleOnBoard( MODULE* Module )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int ox, oy, fx, fy, Penalite;
|
|
|
|
int marge = g_GridRoutingSize / 2;
|
|
|
|
int masque_layer;
|
|
|
|
D_PAD* Pad;
|
|
|
|
|
|
|
|
ox = Module->m_RealBoundaryBox.m_Pos.x - marge;
|
|
|
|
fx = Module->m_RealBoundaryBox.GetRight() + marge;
|
|
|
|
oy = Module->m_RealBoundaryBox.m_Pos.y - marge;
|
|
|
|
fy = Module->m_RealBoundaryBox.GetBottom() + marge;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( ox < GetBoard()->m_BoundaryBox.m_Pos.x )
|
|
|
|
ox = GetBoard()->m_BoundaryBox.m_Pos.x;
|
|
|
|
if( ox > GetBoard()->m_BoundaryBox.GetRight() )
|
|
|
|
ox = GetBoard()->m_BoundaryBox.GetRight();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( fx < GetBoard()->m_BoundaryBox.m_Pos.x )
|
|
|
|
fx = GetBoard()->m_BoundaryBox.m_Pos.x;
|
|
|
|
if( fx > GetBoard()->m_BoundaryBox.GetRight() )
|
|
|
|
fx = GetBoard()->m_BoundaryBox.GetRight();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( oy < GetBoard()->m_BoundaryBox.m_Pos.y )
|
|
|
|
oy = GetBoard()->m_BoundaryBox.m_Pos.y;
|
|
|
|
if( oy > GetBoard()->m_BoundaryBox.GetBottom() )
|
|
|
|
oy = GetBoard()->m_BoundaryBox.GetBottom();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( fy < GetBoard()->m_BoundaryBox.m_Pos.y )
|
|
|
|
fy = GetBoard()->m_BoundaryBox.m_Pos.y;
|
|
|
|
if( fy > GetBoard()->m_BoundaryBox.GetBottom() )
|
|
|
|
fy = GetBoard()->m_BoundaryBox.GetBottom();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
masque_layer = 0;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_FRONT )
|
2009-12-21 13:05:11 +00:00
|
|
|
masque_layer = LAYER_FRONT;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_BACK )
|
2009-12-21 13:05:11 +00:00
|
|
|
masque_layer = LAYER_BACK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
TraceFilledRectangle( GetBoard(), ox, oy, fx, fy, masque_layer,
|
2007-08-10 19:14:51 +00:00
|
|
|
CELL_is_MODULE, WRITE_OR_CELL );
|
|
|
|
|
2009-09-10 15:22:26 +00:00
|
|
|
int trackWidth = GetBoard()->m_NetClasses.GetDefault()->GetTrackWidth();
|
|
|
|
int clearance = GetBoard()->m_NetClasses.GetDefault()->GetClearance();
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Trace pads and surface safely. */
|
2009-09-10 15:22:26 +00:00
|
|
|
marge = trackWidth + clearance;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
Place_1_Pad_Board( GetBoard(), Pad, CELL_is_MODULE, marge,
|
|
|
|
WRITE_OR_CELL );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Trace clearance. */
|
2007-08-10 19:14:51 +00:00
|
|
|
marge = (g_GridRoutingSize * Module->m_PadNum ) / GAIN;
|
|
|
|
Penalite = PENALITE;
|
2009-01-05 05:21:35 +00:00
|
|
|
TracePenaliteRectangle( GetBoard(), ox, oy, fx, fy, marge, Penalite,
|
2007-08-10 19:14:51 +00:00
|
|
|
masque_layer );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2009-11-12 15:43:38 +00:00
|
|
|
* Search for the optimal position of the module.
|
|
|
|
* Entree:
|
|
|
|
* Module tip MODULE struct module's place.
|
|
|
|
* Returns:
|
|
|
|
* 1 if placement impossible, 0 if OK
|
|
|
|
* = MinCout and external variable = cost of best placement
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
int WinEDA_PcbFrame::RecherchePlacementModule( MODULE* Module, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int cx, cy;
|
2009-11-12 15:43:38 +00:00
|
|
|
int ox, oy, fx, fy; /* occupying part of the module focuses on the
|
|
|
|
* cursor */
|
2007-08-10 19:14:51 +00:00
|
|
|
int error = 1;
|
|
|
|
int DisplayChevelu = 0;
|
|
|
|
wxPoint LastPosOK;
|
|
|
|
float mincout, cout, Score;
|
|
|
|
int Penalite;
|
|
|
|
bool TstOtherSide;
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
Module->DisplayInfo( this );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
LastPosOK.x = GetBoard()->m_BoundaryBox.m_Pos.x;
|
|
|
|
LastPosOK.y = GetBoard()->m_BoundaryBox.m_Pos.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
cx = Module->m_Pos.x; cy = Module->m_Pos.y;
|
|
|
|
ox = Module->m_RealBoundaryBox.m_Pos.x - cx;
|
|
|
|
fx = Module->m_RealBoundaryBox.m_Size.x + ox;
|
|
|
|
oy = Module->m_RealBoundaryBox.m_Pos.y - cy;
|
|
|
|
fy = Module->m_RealBoundaryBox.m_Size.y + oy;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
CurrPosition.x = GetBoard()->m_BoundaryBox.m_Pos.x - ox;
|
|
|
|
CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy;
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Module placement on grid. */
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition.x -= CurrPosition.x % g_GridRoutingSize;
|
|
|
|
CurrPosition.y -= CurrPosition.y % g_GridRoutingSize;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
g_Offset_Module.x = cx - CurrPosition.x;
|
|
|
|
g_Offset_Module.y = cy - CurrPosition.y;
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Test pads, a printed circuit with components of the 2 dimensions
|
|
|
|
* can become a component on opposite side if there is at least 1 patch
|
|
|
|
* appearing on the other side.
|
|
|
|
*/
|
2007-08-10 19:14:51 +00:00
|
|
|
TstOtherSide = FALSE;
|
|
|
|
if( Nb_Sides == TWO_SIDES )
|
|
|
|
{
|
|
|
|
D_PAD* Pad; int masque_otherlayer;
|
2009-12-21 13:05:11 +00:00
|
|
|
masque_otherlayer = LAYER_BACK;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_BACK )
|
2009-12-21 13:05:11 +00:00
|
|
|
masque_otherlayer = LAYER_FRONT;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( Pad->m_Masque_Layer & masque_otherlayer ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
TstOtherSide = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module );
|
|
|
|
|
|
|
|
mincout = -1.0;
|
|
|
|
Affiche_Message( wxT( "Score ??, pos ??" ) );
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
for( ; CurrPosition.x < GetBoard()->m_BoundaryBox.GetRight() - fx;
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition.x += g_GridRoutingSize )
|
|
|
|
{
|
|
|
|
wxYield();
|
|
|
|
if( DrawPanel->m_AbortRequest )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( IsOK( this, _( "Ok to abort?" ) ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return ESC;
|
|
|
|
else
|
|
|
|
DrawPanel->m_AbortRequest = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx = Module->m_Pos.x; cy = Module->m_Pos.y;
|
|
|
|
Module->m_RealBoundaryBox.m_Pos.x = ox + CurrPosition.x;
|
|
|
|
Module->m_RealBoundaryBox.m_Pos.y = oy + CurrPosition.y;
|
|
|
|
|
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module );
|
|
|
|
|
|
|
|
g_Offset_Module.x = cx - CurrPosition.x;
|
2009-01-05 05:21:35 +00:00
|
|
|
CurrPosition.y = GetBoard()->m_BoundaryBox.m_Pos.y - oy;
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Placement on grid. */
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition.y -= CurrPosition.y % g_GridRoutingSize;
|
|
|
|
|
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module );
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
for( ; CurrPosition.y < GetBoard()->m_BoundaryBox.GetBottom() - fy;
|
2007-08-10 19:14:51 +00:00
|
|
|
CurrPosition.y += g_GridRoutingSize )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Erase traces. */
|
2007-08-10 19:14:51 +00:00
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module );
|
|
|
|
if( DisplayChevelu )
|
|
|
|
Compute_Ratsnest_PlaceModule( DC );
|
|
|
|
DisplayChevelu = 0;
|
|
|
|
Module->m_RealBoundaryBox.m_Pos.x = ox + CurrPosition.x;
|
|
|
|
Module->m_RealBoundaryBox.m_Pos.y = oy + CurrPosition.y;
|
|
|
|
|
|
|
|
g_Offset_Module.y = cy - CurrPosition.y;
|
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module );
|
2009-01-05 05:21:35 +00:00
|
|
|
Penalite = TstModuleOnBoard( GetBoard(), Module, TstOtherSide );
|
2009-11-12 15:43:38 +00:00
|
|
|
if( Penalite >= 0 ) /* c a d if the module can be placed. */
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
error = 0;
|
|
|
|
build_ratsnest_module( DC, Module );
|
|
|
|
cout = Compute_Ratsnest_PlaceModule( DC );
|
|
|
|
DisplayChevelu = 1;
|
|
|
|
Score = cout + (float) Penalite;
|
|
|
|
|
|
|
|
if( (mincout >= Score ) || (mincout < 0 ) )
|
|
|
|
{
|
|
|
|
LastPosOK = CurrPosition;
|
|
|
|
mincout = Score;
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "Score %d, pos %3.4f, %3.4f" ),
|
|
|
|
(int) mincout,
|
2009-11-12 15:43:38 +00:00
|
|
|
(float) LastPosOK.x / 10000,
|
|
|
|
(float) LastPosOK.y / 10000 );
|
2007-08-10 19:14:51 +00:00
|
|
|
Affiche_Message( msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( DisplayChevelu )
|
|
|
|
Compute_Ratsnest_PlaceModule( DC );
|
|
|
|
DisplayChevelu = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
DrawModuleOutlines( DrawPanel, DC, Module ); /* erasing the last traces */
|
2007-08-10 19:14:51 +00:00
|
|
|
if( DisplayChevelu )
|
|
|
|
Compute_Ratsnest_PlaceModule( DC );
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Regeneration of the modified variable. */
|
2007-08-10 19:14:51 +00:00
|
|
|
Module->m_RealBoundaryBox.m_Pos.x = ox + cx;
|
|
|
|
Module->m_RealBoundaryBox.m_Pos.y = oy + cy;
|
|
|
|
CurrPosition = LastPosOK;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~( RATSNEST_ITEM_LOCAL_OK | LISTE_PAD_OK );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
MinCout = mincout;
|
|
|
|
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
|
|
|
*
|
2009-11-12 15:43:38 +00:00
|
|
|
* Returns 0 if OK
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
int TstRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int row, col;
|
|
|
|
int row_min, row_max, col_min, col_max;
|
|
|
|
unsigned int data;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 -= Pcb->m_BoundaryBox.m_Pos.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
row_max = uy1 / g_GridRoutingSize;
|
|
|
|
col_max = ux1 / g_GridRoutingSize;
|
2009-11-12 15:43:38 +00:00
|
|
|
row_min = uy0 / g_GridRoutingSize;
|
|
|
|
if( uy0 > row_min * g_GridRoutingSize )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_min++;
|
2009-11-12 15:43:38 +00:00
|
|
|
col_min = ux0 / g_GridRoutingSize;
|
|
|
|
if( ux0 > col_min * g_GridRoutingSize )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
if( row_max >= ( Nrows - 1 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_max = Nrows - 1;
|
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
if( col_max >= ( Ncols - 1 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
data = GetCell( row, col, side );
|
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;
|
2009-11-12 15:43:38 +00:00
|
|
|
if( data & CELL_is_MODULE )
|
2007-08-10 19:14:51 +00:00
|
|
|
return OCCUPED_By_MODULE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
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
|
|
|
|
* (ux, ux .. y0, y1):
|
|
|
|
* (Sum of cells in terms of distance)
|
|
|
|
*/
|
2007-08-10 19:14:51 +00:00
|
|
|
unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0,
|
|
|
|
int ux1, int uy1, int side )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int row, col;
|
|
|
|
int row_min, row_max, col_min, col_max;
|
|
|
|
unsigned int Penalite;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 -= Pcb->m_BoundaryBox.m_Pos.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
row_max = uy1 / g_GridRoutingSize;
|
|
|
|
col_max = ux1 / g_GridRoutingSize;
|
2009-11-12 15:43:38 +00:00
|
|
|
row_min = uy0 / g_GridRoutingSize;
|
|
|
|
if( uy0 > row_min * g_GridRoutingSize )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_min++;
|
2009-11-12 15:43:38 +00:00
|
|
|
col_min = ux0 / g_GridRoutingSize;
|
|
|
|
if( ux0 > col_min * g_GridRoutingSize )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
if( row_max >= ( Nrows - 1 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
row_max = Nrows - 1;
|
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
if( col_max >= ( Ncols - 1 ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
Penalite = 0;
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
for( col = col_min; col <= col_max; col++ )
|
|
|
|
{
|
|
|
|
Penalite += (int) GetDist( row, col, side );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Penalite;
|
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().
|
|
|
|
* Module is known by its rectangle
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int ox, oy, fx, fy;
|
|
|
|
int error, Penalite, marge, side, otherside;
|
|
|
|
|
|
|
|
side = TOP; otherside = BOTTOM;
|
2009-12-07 03:46:13 +00:00
|
|
|
if( Module->GetLayer() == LAYER_N_BACK )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
|
|
|
side = BOTTOM; otherside = TOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
ox = Module->m_RealBoundaryBox.m_Pos.x;
|
|
|
|
fx = Module->m_RealBoundaryBox.GetRight();
|
|
|
|
oy = Module->m_RealBoundaryBox.m_Pos.y;
|
|
|
|
fy = Module->m_RealBoundaryBox.GetBottom();
|
|
|
|
|
|
|
|
error = TstRectangle( Pcb, ox, oy, fx, fy, side );
|
|
|
|
if( error < 0 )
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if( TstOtherSide )
|
|
|
|
{
|
|
|
|
error = TstRectangle( Pcb, ox, oy, fx, fy, otherside );
|
|
|
|
if( error < 0 )
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
marge = ( g_GridRoutingSize * Module->m_PadNum ) / GAIN;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
Penalite = CalculePenaliteRectangle( Pcb, ox - marge, oy - marge,
|
|
|
|
fx + marge, fy + marge, side );
|
|
|
|
return Penalite;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/*
|
|
|
|
* Display the module's ratsnet during displacement, and
|
|
|
|
* assess the "cost" of the position.
|
|
|
|
* The cost is the longest ratsnest distance with penalty for connections
|
|
|
|
* approaching 45 degrees.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
float WinEDA_PcbFrame::Compute_Ratsnest_PlaceModule( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
double cout, icout;
|
|
|
|
int ox, oy;
|
|
|
|
int fx, fy;
|
|
|
|
int dx, dy;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( GetBoard()->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
return -1;
|
2007-12-01 03:42:52 +00:00
|
|
|
cout = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-01-29 20:36:12 +00:00
|
|
|
int color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
|
|
|
|
|
|
|
|
if( AutoPlaceShowAll )
|
|
|
|
GRSetDrawMode( DC, GR_XOR );
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < GetBoard()->m_LocalRatsnest.size(); ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
RATSNEST_ITEM* pt_local_chevelu = &GetBoard()->m_LocalRatsnest[ii];
|
2009-11-12 15:43:38 +00:00
|
|
|
if( !( pt_local_chevelu->m_Status & LOCAL_RATSNEST_ITEM ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
ox = pt_local_chevelu->m_PadStart->GetPosition().x -
|
|
|
|
g_Offset_Module.x;
|
|
|
|
oy = pt_local_chevelu->m_PadStart->GetPosition().y -
|
|
|
|
g_Offset_Module.y;
|
2009-05-24 18:28:36 +00:00
|
|
|
fx = pt_local_chevelu->m_PadEnd->GetPosition().x;
|
|
|
|
fy = pt_local_chevelu->m_PadEnd->GetPosition().y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( AutoPlaceShowAll )
|
|
|
|
{
|
|
|
|
GRLine( &DrawPanel->m_ClipBox, DC, ox, oy, fx, fy,
|
2010-01-29 20:36:12 +00:00
|
|
|
0, color );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Cost of the ratsnest. */
|
2008-04-01 05:21:50 +00:00
|
|
|
dx = fx - ox;
|
2007-12-01 03:42:52 +00:00
|
|
|
dy = fy - oy;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
|
|
|
dx = abs( dx );
|
2007-12-01 03:42:52 +00:00
|
|
|
dy = abs( dy );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( dx < dy )
|
2009-11-12 15:43:38 +00:00
|
|
|
EXCHG( dx, dy ); /* dx >= dy */
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Cost of the longest connection. */
|
2007-08-10 19:14:51 +00:00
|
|
|
icout = (float) dx * dx;
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Cost of inclination. */
|
2007-08-10 19:14:51 +00:00
|
|
|
icout += 3 * (float) dy * dy;
|
|
|
|
icout = sqrt( icout );
|
2009-11-12 15:43:38 +00:00
|
|
|
cout += icout; /* Total cost = sum of costs of each connection. */
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
return (float) cout;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/***********************************/
|
|
|
|
/* Draw keep out area of a module. */
|
|
|
|
/***********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-15 14:12:53 +00:00
|
|
|
/* Buid the cost map.
|
|
|
|
* Cells ( in Dist mao ) inside the rect x0,y0 a x1,y1 are
|
|
|
|
* incremented by value Penalite
|
|
|
|
* Cell outside this rectangle, but inside the rectangle
|
|
|
|
* x0,y0 -marge to x1,y1 + marge sont incrementede by a decreasing value
|
|
|
|
* (Penalite ... 0). The decreasing value de pends on the distance to the first rectangle
|
|
|
|
* Therefore the cost is hight in rect x0,y0 a x1,y1, and decrease outside this rectangle
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
static void TracePenaliteRectangle( BOARD* Pcb,
|
|
|
|
int ux0,
|
|
|
|
int uy0,
|
|
|
|
int ux1,
|
|
|
|
int uy1,
|
|
|
|
int marge,
|
|
|
|
int Penalite,
|
|
|
|
int masque_layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
int row, col;
|
|
|
|
int row_min, row_max, col_min, col_max, pmarge;
|
|
|
|
int trace = 0;
|
|
|
|
DistCell data, LocalPenalite;
|
|
|
|
int lgain, cgain;
|
|
|
|
|
|
|
|
if( masque_layer & g_TabOneLayerMask[Route_Layer_BOTTOM] )
|
2009-11-12 15:43:38 +00:00
|
|
|
trace = 1; /* Trace on bottom layer. */
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( ( masque_layer & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides )
|
|
|
|
trace |= 2; /* Trace on top layer. */
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
if( trace == 0 )
|
|
|
|
return;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
ux0 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy0 -= Pcb->m_BoundaryBox.m_Pos.y;
|
|
|
|
ux1 -= Pcb->m_BoundaryBox.m_Pos.x;
|
|
|
|
uy1 -= Pcb->m_BoundaryBox.m_Pos.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
|
|
|
ux0 -= marge; ux1 += marge;
|
|
|
|
uy0 -= marge; uy1 += marge;
|
|
|
|
|
|
|
|
pmarge = marge / g_GridRoutingSize; if( pmarge < 1 )
|
|
|
|
pmarge = 1;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Calculate the coordinate limits of the rectangle. */
|
2007-08-10 19:14:51 +00:00
|
|
|
row_max = uy1 / g_GridRoutingSize;
|
|
|
|
col_max = ux1 / g_GridRoutingSize;
|
|
|
|
row_min = uy0 / g_GridRoutingSize; if( uy0 > row_min * g_GridRoutingSize )
|
|
|
|
row_min++;
|
|
|
|
col_min = ux0 / g_GridRoutingSize; if( ux0 > col_min * g_GridRoutingSize )
|
|
|
|
col_min++;
|
|
|
|
|
|
|
|
if( row_min < 0 )
|
|
|
|
row_min = 0;
|
|
|
|
if( row_max >= (Nrows - 1) )
|
|
|
|
row_max = Nrows - 1;
|
|
|
|
if( col_min < 0 )
|
|
|
|
col_min = 0;
|
|
|
|
if( col_max >= (Ncols - 1) )
|
|
|
|
col_max = Ncols - 1;
|
|
|
|
|
|
|
|
for( row = row_min; row <= row_max; row++ )
|
|
|
|
{
|
|
|
|
lgain = 256;
|
|
|
|
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++ )
|
|
|
|
{
|
|
|
|
cgain = 256;
|
|
|
|
LocalPenalite = Penalite;
|
|
|
|
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;
|
2007-08-10 19:14:51 +00:00
|
|
|
if( cgain != 256 )
|
2009-11-12 15:43:38 +00:00
|
|
|
LocalPenalite = ( LocalPenalite * cgain ) / 256;
|
2007-08-10 19:14:51 +00:00
|
|
|
if( trace & 1 )
|
|
|
|
{
|
|
|
|
data = GetDist( row, col, BOTTOM ) + LocalPenalite;
|
|
|
|
SetDist( row, col, BOTTOM, data );
|
|
|
|
}
|
|
|
|
if( trace & 2 )
|
|
|
|
{
|
|
|
|
data = GetDist( row, col, TOP );
|
2007-08-23 04:28:46 +00:00
|
|
|
data = MAX( data, LocalPenalite );
|
2007-08-10 19:14:51 +00:00
|
|
|
SetDist( row, col, TOP, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
/* Sort routines */
|
|
|
|
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
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
ff1 = ref->m_Surface * ref->m_PadNum;
|
|
|
|
ff2 = compare->m_Surface * compare->m_PadNum;
|
|
|
|
return ff2 < ff1;
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
static bool Tri_RatsModules( MODULE* ref, MODULE* compare )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
double ff1, ff2;
|
|
|
|
|
|
|
|
ff1 = ref->m_Surface * ref->flag;
|
|
|
|
ff2 = compare->m_Surface * compare->flag;
|
|
|
|
return ff2 < ff1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Find the "best" module place
|
|
|
|
* The criteria of choice are:
|
|
|
|
* - Maximum ratsnet with modules already placed
|
|
|
|
* - Max size, and number of pads max
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
static MODULE* PickModule( WinEDA_PcbFrame* pcbframe, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-11-26 17:47:35 +00:00
|
|
|
MODULE* Module;
|
|
|
|
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;
|
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
|
|
|
{
|
|
|
|
Module->Set_Rectangle_Encadrement();
|
|
|
|
Module->SetRectangleExinscrit();
|
|
|
|
moduleList.push_back(Module);
|
|
|
|
}
|
|
|
|
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];
|
|
|
|
Module->flag = 0;
|
|
|
|
if( !( Module->m_ModuleStatus & MODULE_to_PLACE ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2009-05-24 18:28:36 +00:00
|
|
|
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
|
2010-11-26 17:47:35 +00:00
|
|
|
Module->DisplayInfo( pcbframe );
|
|
|
|
pcbframe->build_ratsnest_module( DC, Module );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Calculate external ratsnet. */
|
|
|
|
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 )
|
2010-11-26 17:47:35 +00:00
|
|
|
Module->flag++;
|
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
|
|
|
|
2010-11-26 17:47:35 +00:00
|
|
|
sort( moduleList.begin(), moduleList.end(), Tri_RatsModules );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Search for "best" module. */
|
2010-11-26 17:47:35 +00:00
|
|
|
MODULE* bestModule = NULL;
|
|
|
|
MODULE* altModule = NULL;
|
|
|
|
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];
|
|
|
|
if( !( Module->m_ModuleStatus & MODULE_to_PLACE ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2010-11-26 17:47:35 +00:00
|
|
|
altModule = Module;
|
|
|
|
if( Module->flag == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/*
|
|
|
|
* Determine the rectangle of the pcb, according to the contours
|
|
|
|
* layer (EDGE) only
|
|
|
|
* Output:
|
|
|
|
* GetBoard()->m_BoundaryBox updated
|
|
|
|
* Returns FALSE if no contour
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
bool WinEDA_PcbFrame::SetBoardBoundaryBoxFromEdgesOnly()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
int rayon, cx, cy, d;
|
|
|
|
int xmax, ymax;
|
|
|
|
BOARD_ITEM* PtStruct;
|
|
|
|
DRAWSEGMENT* ptr;
|
|
|
|
bool succes = FALSE;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard() == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x = GetBoard()->m_BoundaryBox.m_Pos.y =
|
|
|
|
0x7FFFFFFFl;
|
2007-08-10 19:14:51 +00:00
|
|
|
xmax = ymax = -0x7FFFFFFFl;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
PtStruct = GetBoard()->m_Drawings;
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; PtStruct != NULL; PtStruct = PtStruct->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct->Type() != TYPE_DRAWSEGMENT )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
succes = TRUE;
|
|
|
|
ptr = (DRAWSEGMENT*) PtStruct;
|
|
|
|
d = (ptr->m_Width / 2) + 1;
|
|
|
|
if( ptr->m_Shape == S_CIRCLE )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
cx = ptr->m_Start.x; cy = ptr->m_Start.y;
|
|
|
|
rayon =
|
|
|
|
(int) hypot( (double) ( ptr->m_End.x - cx ),
|
|
|
|
(double) ( ptr->m_End.y - cy ) );
|
2007-08-10 19:14:51 +00:00
|
|
|
rayon += d;
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x = MIN(
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x, cx - rayon );
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.y = MIN(
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.y, cy - rayon );
|
2007-08-23 04:28:46 +00:00
|
|
|
xmax = MAX( xmax, cx + rayon );
|
|
|
|
ymax = MAX( ymax, cy + rayon );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
cx = MIN( ptr->m_Start.x, ptr->m_End.x );
|
|
|
|
cy = MIN( ptr->m_Start.y, ptr->m_End.y );
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x = MIN(
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.x, cx - d );
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.y = MIN(
|
|
|
|
GetBoard()->m_BoundaryBox.m_Pos.y, cy - d );
|
2007-08-23 04:28:46 +00:00
|
|
|
cx = MAX( ptr->m_Start.x, ptr->m_End.x );
|
|
|
|
cy = MAX( ptr->m_Start.y, ptr->m_End.y );
|
|
|
|
xmax = MAX( xmax, cx + d );
|
|
|
|
ymax = MAX( ymax, cy + d );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
GetBoard()->m_BoundaryBox.SetWidth(
|
|
|
|
xmax - GetBoard()->m_BoundaryBox.m_Pos.x );
|
|
|
|
GetBoard()->m_BoundaryBox.SetHeight(
|
|
|
|
ymax - GetBoard()->m_BoundaryBox.m_Pos.y );
|
2007-08-10 19:14:51 +00:00
|
|
|
return succes;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2010-11-26 17:47:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
/********************************************/
|
|
|
|
int Propagation( WinEDA_PcbFrame* frame )
|
|
|
|
/********************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Propagation
|
|
|
|
* Used now 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 neightbour 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 neightbour cells
|
|
|
|
* the previous cell on the same line and the previous cell on the same column.
|
|
|
|
*
|
|
|
|
* This funtion can request some iterations
|
|
|
|
* Iterations are made until no cell is added to the zone.
|
|
|
|
* @return: added cells count (i.e. which the attribute CELL_is_ZONE is set)
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int row, col, nn;
|
|
|
|
long current_cell, old_cell_H;
|
|
|
|
int long* pt_cell_V;
|
|
|
|
int nbpoints = 0;
|
|
|
|
|
|
|
|
#define NO_CELL_ZONE (HOLE | CELL_is_EDGE | CELL_is_ZONE)
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 57, wxT( "Detect" ), msg, CYAN );
|
|
|
|
Affiche_1_Parametre( frame, -1, wxEmptyString, wxT( "1" ), CYAN );
|
|
|
|
|
|
|
|
// Alloc memory to handle 1 line or 1 colunmn on the routing matrix
|
|
|
|
nn = MAX( Nrows, Ncols ) * sizeof(*pt_cell_V);
|
|
|
|
pt_cell_V = (long*) MyMalloc( nn );
|
|
|
|
|
|
|
|
/* search 1 : from left to right and top to bottom */
|
|
|
|
memset( pt_cell_V, 0, nn );
|
|
|
|
for( row = 0; row < Nrows; row++ )
|
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
|
|
|
for( col = 0; col < Ncols; col++ )
|
|
|
|
{
|
|
|
|
current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
|
|
|
if( current_cell == 0 ) /* a free cell is found */
|
|
|
|
{
|
|
|
|
if( (old_cell_H & CELL_is_ZONE)
|
|
|
|
|| (pt_cell_V[col] & CELL_is_ZONE) )
|
|
|
|
{
|
|
|
|
OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pt_cell_V[col] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search 2 : from right to left and top to bottom */
|
|
|
|
Affiche_1_Parametre( frame, -1, wxEmptyString, wxT( "2" ), CYAN );
|
|
|
|
memset( pt_cell_V, 0, nn );
|
|
|
|
for( row = 0; row < Nrows; row++ )
|
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
|
|
|
for( col = Ncols - 1; col >= 0; col-- )
|
|
|
|
{
|
|
|
|
current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
|
|
|
if( current_cell == 0 ) /* a free cell is found */
|
|
|
|
{
|
|
|
|
if( (old_cell_H & CELL_is_ZONE)
|
|
|
|
|| (pt_cell_V[col] & CELL_is_ZONE) )
|
|
|
|
{
|
|
|
|
OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pt_cell_V[col] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search 3 : from bottom to top and right to left balayage */
|
|
|
|
Affiche_1_Parametre( frame, -1, wxEmptyString, wxT( "3" ), CYAN );
|
|
|
|
memset( pt_cell_V, 0, nn );
|
|
|
|
for( col = Ncols - 1; col >= 0; col-- )
|
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
|
|
|
for( row = Nrows - 1; row >= 0; row-- )
|
|
|
|
{
|
|
|
|
current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
|
|
|
if( current_cell == 0 ) /* a free cell is found */
|
|
|
|
{
|
|
|
|
if( (old_cell_H & CELL_is_ZONE)
|
|
|
|
|| (pt_cell_V[row] & CELL_is_ZONE) )
|
|
|
|
{
|
|
|
|
OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pt_cell_V[row] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search 4 : from bottom to top and left to right */
|
|
|
|
Affiche_1_Parametre( frame, -1, wxEmptyString, wxT( "4" ), CYAN );
|
|
|
|
memset( pt_cell_V, 0, nn );
|
|
|
|
for( col = 0; col < Ncols; col++ )
|
|
|
|
{
|
|
|
|
old_cell_H = 0;
|
|
|
|
for( row = Nrows - 1; row >= 0; row-- )
|
|
|
|
{
|
|
|
|
current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE;
|
|
|
|
if( current_cell == 0 ) /* a free cell is found */
|
|
|
|
{
|
|
|
|
if( (old_cell_H & CELL_is_ZONE)
|
|
|
|
|| (pt_cell_V[row] & CELL_is_ZONE) )
|
|
|
|
{
|
|
|
|
OrCell( row, col, BOTTOM, CELL_is_ZONE );
|
|
|
|
current_cell = CELL_is_ZONE;
|
|
|
|
nbpoints++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pt_cell_V[row] = old_cell_H = current_cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFree( pt_cell_V );
|
|
|
|
|
|
|
|
return nbpoints;
|
|
|
|
}
|
|
|
|
|