2007-08-20 01:20:48 +00:00
|
|
|
/****************************************************************/
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Routines for automatic displacement and rotation of modules. */
|
2007-08-20 01:20:48 +00:00
|
|
|
/****************************************************************/
|
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"
|
|
|
|
#include "kicad_string.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"
|
|
|
|
#include "cell.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "pcbnew_id.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
2009-12-20 19:48:58 +00:00
|
|
|
#include "kicad_device_context.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
typedef enum {
|
2007-08-20 01:20:48 +00:00
|
|
|
FIXE_MODULE,
|
|
|
|
FREE_MODULE,
|
|
|
|
FIXE_ALL_MODULES,
|
|
|
|
FREE_ALL_MODULES
|
|
|
|
} SelectFixeFct;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static int tri_modules( MODULE** pt_ref, MODULE** pt_compare );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
wxString ModulesMaskSelection = wxT( "*" );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-23 15:28:45 +00:00
|
|
|
/* Called on events (popup menus) relative to automove and autoplace footprints
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
void WinEDA_PcbFrame::AutoPlace( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int id = event.GetId();
|
|
|
|
bool on_state;
|
|
|
|
|
|
|
|
if( m_HToolBar == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-08-12 05:57:14 +00:00
|
|
|
INSTALL_DC( dc, DrawPanel );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-23 15:28:45 +00:00
|
|
|
switch( id )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-08-17 10:41:44 +00:00
|
|
|
case ID_TOOLBARH_PCB_MODE_MODULE:
|
|
|
|
on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_MODULE );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( on_state )
|
|
|
|
{
|
2010-08-17 10:41:44 +00:00
|
|
|
m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_TRACKS, FALSE );
|
|
|
|
m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_MODULE;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m_HTOOL_current_state = 0;
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-08-17 10:41:44 +00:00
|
|
|
case ID_TOOLBARH_PCB_MODE_TRACKS:
|
|
|
|
on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_TRACKS );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( on_state )
|
|
|
|
{
|
2010-08-17 10:41:44 +00:00
|
|
|
m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_MODULE, FALSE );
|
|
|
|
m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_TRACKS;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m_HTOOL_current_state = 0;
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_SELECT_LAYERS:
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_FIXE_MODULE:
|
2008-04-17 16:25:29 +00:00
|
|
|
FixeModule( (MODULE*) GetScreen()->GetCurItem(), TRUE );
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_FREE_MODULE:
|
2008-04-17 16:25:29 +00:00
|
|
|
FixeModule( (MODULE*) GetScreen()->GetCurItem(), FALSE );
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_FREE_ALL_MODULES:
|
|
|
|
FixeModule( NULL, FALSE );
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_FIXE_ALL_MODULES:
|
|
|
|
FixeModule( NULL, TRUE );
|
2010-08-12 05:57:14 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case ID_POPUP_CANCEL_CURRENT_COMMAND:
|
|
|
|
if( DrawPanel->ManageCurseur
|
|
|
|
&& DrawPanel->ForceCloseManageCurseur )
|
|
|
|
{
|
|
|
|
DrawPanel->ForceCloseManageCurseur( DrawPanel, &dc );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
2010-08-12 05:57:14 +00:00
|
|
|
default: // Abort a current command (if any)
|
|
|
|
DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Erase ratsnest if needed */
|
|
|
|
if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) )
|
|
|
|
DrawGeneralRatsnest( &dc );
|
|
|
|
GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST;
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
case ID_POPUP_PCB_AUTOPLACE_CURRENT_MODULE:
|
2008-04-17 16:25:29 +00:00
|
|
|
AutoPlaceModule( (MODULE*) GetScreen()->GetCurItem(),
|
2007-08-20 01:20:48 +00:00
|
|
|
PLACE_1_MODULE, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_ALL_MODULES:
|
|
|
|
AutoPlaceModule( NULL, PLACE_ALL, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_NEW_MODULES:
|
|
|
|
AutoPlaceModule( NULL, PLACE_OUT_OF_BOARD, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOPLACE_NEXT_MODULE:
|
|
|
|
AutoPlaceModule( NULL, PLACE_INCREMENTAL, &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOMOVE_ALL_MODULES:
|
2009-10-23 15:28:45 +00:00
|
|
|
AutoMoveModulesOnPcb( FALSE );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOMOVE_NEW_MODULES:
|
2009-10-23 15:28:45 +00:00
|
|
|
AutoMoveModulesOnPcb( TRUE );
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_REORIENT_ALL_MODULES:
|
2009-11-12 15:43:38 +00:00
|
|
|
OnOrientFootprints();
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_ALL_MODULES:
|
|
|
|
Autoroute( &dc, ROUTE_ALL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_MODULE:
|
|
|
|
Autoroute( &dc, ROUTE_MODULE );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_PAD:
|
|
|
|
Autoroute( &dc, ROUTE_PAD );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_NET:
|
|
|
|
Autoroute( &dc, ROUTE_NET );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_PCB_AUTOROUTE_RESET_UNROUTED:
|
|
|
|
Reset_Noroutable( &dc );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( this, wxT( "AutoPlace command error" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST;
|
2009-06-11 14:26:17 +00:00
|
|
|
Compile_Ratsnest( &dc, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-08-11 18:17:12 +00:00
|
|
|
/* Function to move components in a rectangular area format 4 / 3,
|
|
|
|
* starting from the mouse cursor
|
|
|
|
* The components with the FIXED status set are not moved
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
void WinEDA_PcbFrame::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE** pt_Dmod, ** BaseListeModules;
|
|
|
|
MODULE* Module;
|
|
|
|
wxPoint start, current;
|
|
|
|
int Ymax_size, Xsize_allowed;
|
2009-11-12 15:43:38 +00:00
|
|
|
int pas_grille = (int) GetScreen()->GetGridSize().x;
|
2007-08-20 01:20:48 +00:00
|
|
|
bool EdgeExists;
|
|
|
|
float surface;
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
DisplayError( this, _( "No modules found!" ) );
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Confirmation */
|
2009-11-12 15:43:38 +00:00
|
|
|
if( !IsOK( this, _( "Move modules?" ) ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
EdgeExists = SetBoardBoundaryBoxFromEdgesOnly();
|
|
|
|
|
|
|
|
if( PlaceModulesHorsPcb && !EdgeExists )
|
|
|
|
{
|
|
|
|
DisplayError( this,
|
2010-06-19 10:58:50 +00:00
|
|
|
_( "Could not automatically place modules. No board outlines detected." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = GetBoard()->m_Modules;
|
2009-11-12 15:43:38 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
Module->Set_Rectangle_Encadrement();
|
|
|
|
Module->SetRectangleExinscrit();
|
|
|
|
}
|
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
BaseListeModules = GenListeModules( GetBoard(), NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* If allocation of modules not PCBs, the cursor is placed below
|
|
|
|
* PCB, to avoid placing components in PCB area.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
|
|
|
if( PlaceModulesHorsPcb && EdgeExists )
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( GetScreen()->m_Curseur.y <
|
|
|
|
(GetBoard()->m_BoundaryBox.GetBottom() + 2000) )
|
|
|
|
GetScreen()->m_Curseur.y = GetBoard()->m_BoundaryBox.GetBottom() +
|
|
|
|
2000;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* calculating the area occupied by the circuits */
|
2007-08-20 01:20:48 +00:00
|
|
|
surface = 0.0;
|
|
|
|
for( pt_Dmod = BaseListeModules; *pt_Dmod != NULL; pt_Dmod++ )
|
|
|
|
{
|
|
|
|
Module = *pt_Dmod;
|
|
|
|
if( PlaceModulesHorsPcb && EdgeExists )
|
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_BoundaryBox.Inside( Module->m_Pos ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
surface += Module->m_Surface;
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
Xsize_allowed = (int) ( sqrt( surface ) * 4.0 / 3.0 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
start = current = GetScreen()->m_Curseur;
|
2007-08-20 01:20:48 +00:00
|
|
|
Ymax_size = 0;
|
|
|
|
|
|
|
|
for( pt_Dmod = BaseListeModules; *pt_Dmod != NULL; pt_Dmod++ )
|
|
|
|
{
|
|
|
|
Module = *pt_Dmod;
|
2007-09-09 02:27:03 +00:00
|
|
|
if( Module->IsLocked() )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( PlaceModulesHorsPcb && EdgeExists )
|
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_BoundaryBox.Inside( Module->m_Pos ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( current.x > (Xsize_allowed + start.x) )
|
|
|
|
{
|
|
|
|
current.x = start.x;
|
|
|
|
current.y += Ymax_size + pas_grille;
|
|
|
|
Ymax_size = 0;
|
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur.x =
|
2007-08-20 01:20:48 +00:00
|
|
|
current.x + Module->m_Pos.x - Module->m_RealBoundaryBox.GetX();
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur.y =
|
2007-08-20 01:20:48 +00:00
|
|
|
current.y + Module->m_Pos.y - Module->m_RealBoundaryBox.GetY();
|
|
|
|
Ymax_size = MAX( Ymax_size, Module->m_RealBoundaryBox.GetHeight() );
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
PutOnGrid( &GetScreen()->m_Curseur );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-23 15:28:45 +00:00
|
|
|
Place_Module( Module, NULL, true );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
current.x += Module->m_RealBoundaryBox.GetWidth() + pas_grille;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyFree( BaseListeModules );
|
2009-10-23 15:28:45 +00:00
|
|
|
DrawPanel->Refresh();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Update (TRUE or FALSE) FIXED attribute on the module Module
|
|
|
|
* or all the modules if Module == NULL
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
void WinEDA_PcbFrame::FixeModule( MODULE* Module, bool Fixe )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( Module )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2007-09-09 02:27:03 +00:00
|
|
|
Module->SetLocked( Fixe );
|
2008-04-01 05:21:50 +00:00
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
Module->DisplayInfo( this );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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-20 01:20:48 +00:00
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
if( WildCompareString( ModulesMaskSelection,
|
|
|
|
Module->m_Reference->m_Text ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2007-09-09 02:27:03 +00:00
|
|
|
Module->SetLocked( Fixe );
|
2010-02-19 13:23:58 +00:00
|
|
|
OnModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Create memory allocation by the ordered list of structures D_MODULES
|
|
|
|
* Describing the module to move
|
|
|
|
* The end of the list is indicated by NULL
|
|
|
|
* Also returns the number of modules per NbModules *
|
|
|
|
* Deallocates memory after use
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
MODULE** GenListeModules( BOARD* Pcb, int* NbModules )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* Module;
|
|
|
|
MODULE** ListeMod, ** PtList;
|
|
|
|
int NbMod;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Reserve memory for descriptions of modules that are to be moved. */
|
2007-08-20 01:20:48 +00:00
|
|
|
Module = Pcb->m_Modules;
|
|
|
|
NbMod = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
NbMod++;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
ListeMod = (MODULE**) MyZMalloc( (NbMod + 1) * sizeof(MODULE*) );
|
2007-08-20 01:20:48 +00:00
|
|
|
if( ListeMod == NULL )
|
|
|
|
{
|
|
|
|
if( NbModules != NULL )
|
|
|
|
*NbModules = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PtList = ListeMod;
|
|
|
|
Module = Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
*PtList = Module; PtList++;
|
|
|
|
Module->SetRectangleExinscrit();
|
|
|
|
}
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Sort by surface area module largest to smallest */
|
2007-08-20 01:20:48 +00:00
|
|
|
qsort( ListeMod, NbMod, sizeof(MODULE * *),
|
2009-11-12 15:43:38 +00:00
|
|
|
( int ( * )( const void*, const void* ) )tri_modules );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( NbModules != NULL )
|
|
|
|
*NbModules = NbMod;
|
|
|
|
return ListeMod;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static int tri_modules( MODULE** pt_ref, MODULE** pt_compare )
|
|
|
|
{
|
|
|
|
float ff;
|
|
|
|
|
|
|
|
ff = (*pt_ref)->m_Surface - (*pt_compare)->m_Surface;
|
|
|
|
if( ff < 0 )
|
|
|
|
return 1;
|
|
|
|
if( ff > 0 )
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|