2007-08-04 01:12:30 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* Routines generales de gestion des commandes usuelles */
|
|
|
|
/********************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-09-19 15:29:50 +00:00
|
|
|
/* controle.cpp */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
2007-09-25 08:23:53 +00:00
|
|
|
#include "protos.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "id.h"
|
2007-08-24 03:40:04 +00:00
|
|
|
#include "collectors.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
#include "bitmaps.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-06 16:16:48 +00:00
|
|
|
/*************************************************************************************/
|
|
|
|
static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aCollector )
|
|
|
|
/*************************************************************************************/
|
2007-09-14 16:15:27 +00:00
|
|
|
/**
|
|
|
|
* Function AllAreModulesAndReturnSmallestIfSo
|
|
|
|
* tests that all items in the collection are MODULEs and if so, returns the
|
|
|
|
* smallest MODULE.
|
|
|
|
* @return BOARD_ITEM* - The smallest or NULL.
|
2007-09-25 08:23:53 +00:00
|
|
|
*/
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
|
|
|
int count = aCollector->GetCount();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
for( int i = 0; i<count; ++i )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( (*aCollector)[i]->Type() != TYPE_MODULE )
|
2007-09-14 16:15:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
// all are modules, now find smallest MODULE
|
|
|
|
|
|
|
|
int minDim = 0x7FFFFFFF;
|
|
|
|
int minNdx = 0;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
for( int i = 0; i<count; ++i )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
|
|
|
MODULE* module = (MODULE*) (*aCollector)[i];
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
int lx = module->m_BoundaryBox.GetWidth();
|
|
|
|
int ly = module->m_BoundaryBox.GetHeight();
|
|
|
|
|
|
|
|
int lmin = MIN( lx, ly );
|
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
if( lmin <= minDim )
|
|
|
|
{
|
|
|
|
minDim = lmin;
|
|
|
|
minNdx = i;
|
|
|
|
}
|
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-14 16:15:27 +00:00
|
|
|
return (*aCollector)[minNdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
|
|
|
|
/****************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
BOARD_ITEM* item;
|
|
|
|
|
|
|
|
GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();
|
2007-08-24 03:40:04 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
// Assign to scanList the proper item types desired based on tool type
|
|
|
|
// or hotkey that is in play.
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-10-07 18:24:15 +00:00
|
|
|
const KICAD_T* scanList = NULL;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
if( aHotKeyCode )
|
|
|
|
{
|
2007-09-26 20:10:12 +00:00
|
|
|
// @todo: add switch here and add calls to PcbGeneralLocateAndDisplay( int aHotKeyCode )
|
|
|
|
// when searching is needed from a hotkey handler
|
2007-09-25 15:10:01 +00:00
|
|
|
}
|
|
|
|
else if( m_ID_current_state == 0 )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
switch( m_HTOOL_current_state )
|
|
|
|
{
|
|
|
|
case ID_TOOLBARH_PCB_AUTOPLACE:
|
|
|
|
scanList = GENERAL_COLLECTOR::ModuleItems;
|
|
|
|
break;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
default:
|
2008-12-12 21:30:07 +00:00
|
|
|
scanList = DisplayOpt.DisplayZonesMode == 0 ?
|
2007-10-01 15:37:42 +00:00
|
|
|
GENERAL_COLLECTOR::AllBoardItems :
|
|
|
|
GENERAL_COLLECTOR::AllButZones;
|
2007-09-12 02:14:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch( m_ID_current_state )
|
|
|
|
{
|
|
|
|
case ID_PCB_SHOW_1_RATSNEST_BUTT:
|
|
|
|
scanList = GENERAL_COLLECTOR::PadsOrModules;
|
2007-09-25 08:23:53 +00:00
|
|
|
break;
|
2007-09-12 02:14:07 +00:00
|
|
|
|
|
|
|
case ID_TRACK_BUTT:
|
|
|
|
scanList = GENERAL_COLLECTOR::Tracks;
|
2007-09-25 08:23:53 +00:00
|
|
|
break;
|
2007-09-12 02:14:07 +00:00
|
|
|
|
|
|
|
case ID_COMPONENT_BUTT:
|
|
|
|
scanList = GENERAL_COLLECTOR::ModuleItems;
|
|
|
|
break;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
default:
|
2008-12-12 21:30:07 +00:00
|
|
|
scanList = DisplayOpt.DisplayZonesMode == 0 ?
|
2007-10-01 15:37:42 +00:00
|
|
|
GENERAL_COLLECTOR::AllBoardItems :
|
|
|
|
GENERAL_COLLECTOR::AllButZones;
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
m_Collector->Collect( m_Pcb, scanList, GetScreen()->RefPos( true ), guide );
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2007-10-01 15:37:42 +00:00
|
|
|
#if 0
|
2007-09-25 15:10:01 +00:00
|
|
|
// debugging: print out the collected items, showing their priority order too.
|
2007-10-01 15:37:42 +00:00
|
|
|
for( int i = 0; i<m_Collector->GetCount(); ++i )
|
2007-09-25 15:10:01 +00:00
|
|
|
(*m_Collector)[i]->Show( 0, std::cout );
|
2007-10-01 15:37:42 +00:00
|
|
|
#endif
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
/* Remove redundancies: most of time, zones are found twice,
|
|
|
|
* because zones are filled twice ( once by by horizontal and once by vertical segments )
|
|
|
|
*/
|
|
|
|
unsigned long timestampzone = 0;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
for( int ii = 0; ii < m_Collector->GetCount(); ii++ )
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[ii];
|
2008-12-04 04:28:11 +00:00
|
|
|
if( item->Type() != TYPE_ZONE )
|
2007-09-25 08:23:53 +00:00
|
|
|
continue;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
/* Found a TYPE ZONE */
|
|
|
|
if( item->m_TimeStamp == timestampzone ) // Remove it, redundant, zone already found
|
|
|
|
{
|
|
|
|
m_Collector->Remove( ii );
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
timestampzone = item->m_TimeStamp;
|
|
|
|
}
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
if( m_Collector->GetCount() <= 1 )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[0];
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2007-09-21 13:23:51 +00:00
|
|
|
// If the count is 2, and first item is a pad or moduletext, and the 2nd item is its parent module:
|
2007-09-25 08:23:53 +00:00
|
|
|
else if( m_Collector->GetCount() == 2
|
2008-12-04 04:28:11 +00:00
|
|
|
&& ( (*m_Collector)[0]->Type() == TYPE_PAD || (*m_Collector)[0]->Type() ==
|
|
|
|
TYPE_TEXTE_MODULE )
|
|
|
|
&& (*m_Collector)[1]->Type() == TYPE_MODULE && (*m_Collector)[0]->GetParent()==
|
2007-10-01 15:37:42 +00:00
|
|
|
(*m_Collector)[1] )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
|
|
|
item = (*m_Collector)[0];
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2007-09-14 16:15:27 +00:00
|
|
|
// if all are modules, find the smallest one amoung the primary choices
|
2007-09-25 08:23:53 +00:00
|
|
|
else if( ( item = AllAreModulesAndReturnSmallestIfSo( m_Collector ) ) != NULL )
|
2007-09-14 16:15:27 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
SetCurItem( item );
|
2007-09-14 16:15:27 +00:00
|
|
|
}
|
2007-09-26 20:10:12 +00:00
|
|
|
else // we can't figure out which item user wants, do popup menu so user can choose
|
2007-08-24 03:40:04 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
wxMenu itemMenu;
|
|
|
|
|
2007-10-10 04:45:26 +00:00
|
|
|
/* Give a title to the selection menu. This is also a cancel menu item */
|
|
|
|
wxMenuItem * item_title = new wxMenuItem(&itemMenu, -1, _( "Selection Clarification" ) );
|
2007-10-07 18:24:15 +00:00
|
|
|
#ifdef __WINDOWS__
|
2007-10-10 04:45:26 +00:00
|
|
|
wxFont bold_font(*wxNORMAL_FONT);
|
|
|
|
bold_font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
bold_font.SetStyle( wxFONTSTYLE_ITALIC);
|
|
|
|
item_title->SetFont(bold_font);
|
2007-10-07 18:24:15 +00:00
|
|
|
#endif
|
2007-10-10 04:45:26 +00:00
|
|
|
itemMenu.Append(item_title);
|
|
|
|
itemMenu.AppendSeparator();
|
2007-09-12 02:14:07 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
int limit = MIN( MAX_ITEMS_IN_PICKER, m_Collector->GetCount() );
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
for( int i = 0; i<limit; ++i )
|
2007-09-12 02:14:07 +00:00
|
|
|
{
|
2007-09-25 08:23:53 +00:00
|
|
|
wxString text;
|
|
|
|
const char** xpm;
|
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
item = (*m_Collector)[i];
|
|
|
|
|
2007-09-15 04:25:54 +00:00
|
|
|
text = item->MenuText( m_Pcb );
|
2007-09-12 02:14:07 +00:00
|
|
|
xpm = item->MenuIcon();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
|
|
|
ADD_MENUITEM( &itemMenu, ID_POPUP_PCB_ITEM_SELECTION_START + i, text, xpm );
|
2007-09-12 02:14:07 +00:00
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
/* @todo: rather than assignment to TRUE, these should be increment and decrement operators throughout _everywhere_.
|
2007-10-01 15:37:42 +00:00
|
|
|
* That way we can handle nesting.
|
|
|
|
* But I tried that and found there cases where the assignment to TRUE (converted to a m_IgnoreMouseEvents++ )
|
|
|
|
* was not balanced with the -- (now m_IgnoreMouseEvents=FALSE), so I had to revert.
|
|
|
|
* Somebody should track down these and make them balanced.
|
|
|
|
* DrawPanel->m_IgnoreMouseEvents = TRUE;
|
|
|
|
*/
|
2007-09-12 02:14:07 +00:00
|
|
|
|
|
|
|
// this menu's handler is void WinEDA_BasePcbFrame::ProcessItemSelection()
|
|
|
|
// and it calls SetCurItem() which in turn calls Display_Infos() on the item.
|
2007-10-10 04:45:26 +00:00
|
|
|
DrawPanel->m_AbortRequest = true; // changed in false if an item
|
|
|
|
PopupMenu( &itemMenu ); // m_AbortRequest = false if an item is selected
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-26 20:10:12 +00:00
|
|
|
// DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
// The function ProcessItemSelection() has set the current item, return it.
|
|
|
|
item = GetCurItem();
|
2007-08-24 03:40:04 +00:00
|
|
|
}
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-08-24 03:40:04 +00:00
|
|
|
return item;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-29 20:35:11 +00:00
|
|
|
/**
|
|
|
|
* Function Join
|
2008-03-04 19:17:19 +00:00
|
|
|
* finds the point where line segment (b1,b0) intersects with segment (a1,a0).
|
|
|
|
* If that point would be outside of (a0,a1), the respective endpoint is used.
|
2008-02-26 21:12:08 +00:00
|
|
|
* Join returns the point in "res" and "true" if a suitable point was found,
|
2008-03-04 19:17:19 +00:00
|
|
|
* "false" if both lines are parallel or if the length of either segment is zero.
|
2008-02-26 21:12:08 +00:00
|
|
|
*/
|
2008-02-29 20:35:11 +00:00
|
|
|
static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-02-29 20:35:11 +00:00
|
|
|
/* References:
|
|
|
|
http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
|
|
|
|
http://www.gekkou.co.uk/blogs/monologues/2007/12/13/1197586800000.html
|
|
|
|
*/
|
|
|
|
|
2008-02-29 23:01:30 +00:00
|
|
|
double denom;
|
2008-02-26 21:12:08 +00:00
|
|
|
double t;
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
// if either segment is zero length
|
|
|
|
if( a1.x==a0.x && a1.y==a0.y )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( b1.x==b0.x && b1.y==b0.y )
|
|
|
|
return false;
|
|
|
|
|
2008-02-26 21:12:08 +00:00
|
|
|
a1 -= a0;
|
|
|
|
b1 -= b0;
|
2008-03-04 19:17:19 +00:00
|
|
|
|
2008-02-26 21:12:08 +00:00
|
|
|
b0 -= a0;
|
|
|
|
|
2008-02-29 23:01:30 +00:00
|
|
|
denom = (double) b1.y * a1.x - (double) b1.x * a1.y;
|
2008-02-29 20:35:11 +00:00
|
|
|
if( !denom )
|
|
|
|
{
|
|
|
|
return false; // parallel
|
|
|
|
}
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-02-29 23:01:30 +00:00
|
|
|
t = ((double) b1.y * b0.x - (double) b1.x * b0.y ) / denom;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
|
|
|
t = min( max( t, 0.0 ), 1.0 );
|
|
|
|
|
2008-02-29 20:35:11 +00:00
|
|
|
res->x = (int) round( a0.x + t * a1.x );
|
|
|
|
res->y = (int) round( a0.y + t * a1.y );
|
2008-02-26 21:12:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Project" finds the projection of a grid point on a track. This is the point
|
|
|
|
* from where we want to draw new orthogonal tracks when starting on a track.
|
|
|
|
*/
|
2008-02-29 20:35:11 +00:00
|
|
|
bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
|
|
|
if( track->m_Start == track->m_End )
|
|
|
|
return false;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
wxPoint vec = track->m_End - track->m_Start;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
double t = double( on_grid.x - track->m_Start.x ) * vec.x +
|
2008-02-29 23:01:30 +00:00
|
|
|
double( on_grid.y - track->m_Start.y ) * vec.y;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-02-29 23:01:30 +00:00
|
|
|
t /= (double) vec.x * vec.x + (double) vec.y * vec.y;
|
2008-02-26 21:12:08 +00:00
|
|
|
t = min( max( t, 0.0 ), 1.0 );
|
|
|
|
|
2008-02-29 23:01:30 +00:00
|
|
|
res->x = (int) round( track->m_Start.x + t * vec.x );
|
|
|
|
res->y = (int) round( track->m_Start.y + t * vec.y );
|
2008-02-26 21:12:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-29 20:35:11 +00:00
|
|
|
/**
|
|
|
|
* Function Magnetize
|
|
|
|
* tests to see if there are any magnetic items within near reach of the given
|
|
|
|
* "curpos". If yes, then curpos is adjusted appropriately according to that
|
|
|
|
* near magnetic item and true is returned.
|
|
|
|
* @param curpos The initial position, and what to adjust if a change is needed.
|
2008-03-04 19:17:19 +00:00
|
|
|
* @return bool - true if the position was adjusted magnetically, else false.
|
2008-02-29 20:35:11 +00:00
|
|
|
*/
|
2008-02-26 21:12:08 +00:00
|
|
|
static bool Magnetize( BOARD* m_Pcb, WinEDA_PcbFrame* frame,
|
2008-02-29 20:35:11 +00:00
|
|
|
int aCurrentTool, wxSize grid, wxPoint on_grid, wxPoint* curpos )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-02-29 20:35:11 +00:00
|
|
|
bool doCheckNet = g_MagneticPadOption != capture_always && Drc_On;
|
2008-03-04 19:17:19 +00:00
|
|
|
bool doTrack = false;
|
|
|
|
bool doPad = false;
|
|
|
|
bool amMovingVia = false;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
TRACK* currTrack = g_CurrentTrackSegment;
|
|
|
|
BOARD_ITEM* currItem = frame->GetCurItem();
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
// D( printf( "currTrack=%p currItem=%p currTrack->Type()=%d currItem->Type()=%d\n", currTrack, currItem, currTrack ? currTrack->Type() : 0, currItem ? currItem->Type() : 0 ); )
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( !currTrack && currItem && currItem->Type()==TYPE_VIA && currItem->m_Flags )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
// moving a VIA
|
|
|
|
currTrack = (TRACK*) currItem;
|
|
|
|
amMovingVia = true;
|
2008-02-29 20:35:11 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
return false; // comment this return out and play with it.
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
2008-03-04 19:17:19 +00:00
|
|
|
else if( currItem != currTrack )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
currTrack = NULL;
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( g_MagneticPadOption == capture_always )
|
|
|
|
doPad = true;
|
|
|
|
|
|
|
|
if( g_MagneticTrackOption == capture_always )
|
|
|
|
doTrack = true;
|
|
|
|
|
|
|
|
if( aCurrentTool == ID_TRACK_BUTT || amMovingVia )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
int q = capture_cursor_in_track_tool;
|
|
|
|
|
|
|
|
if( g_MagneticPadOption == q )
|
|
|
|
doPad = true;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( g_MagneticTrackOption == q )
|
|
|
|
doTrack = true;
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-05 22:40:07 +00:00
|
|
|
// D(printf("doPad=%d doTrack=%d aCurrentTool=%d amMovingVia=%d\n", doPad, doTrack, aCurrentTool, amMovingVia );)
|
2008-03-04 19:17:19 +00:00
|
|
|
|
|
|
|
// The search precedence order is pads, then tracks/vias
|
|
|
|
|
|
|
|
if( doPad )
|
2008-02-29 20:35:11 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
D_PAD* pad = Locate_Any_Pad( m_Pcb, CURSEUR_OFF_GRILLE, TRUE );
|
|
|
|
if( pad )
|
|
|
|
{
|
|
|
|
if( doCheckNet && currTrack && currTrack->GetNet() != pad->GetNet() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*curpos = pad->m_Pos;
|
|
|
|
return true;
|
|
|
|
}
|
2008-02-29 20:35:11 +00:00
|
|
|
}
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
// after pads, only track & via tests remain, skip them if not desired
|
|
|
|
if( doTrack )
|
2008-02-26 21:12:08 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
int layer = ( (PCB_SCREEN*) ActiveScreen )->m_Active_Layer;
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
for( TRACK* via = m_Pcb->m_Track;
|
|
|
|
via && (via = Locate_Via_Area( via, *curpos, layer )) != NULL;
|
|
|
|
via = via->Next() )
|
|
|
|
{
|
|
|
|
if( via != currTrack ) // a via cannot influence itself
|
|
|
|
{
|
2008-03-04 21:10:18 +00:00
|
|
|
if( !doCheckNet || !currTrack || currTrack->GetNet() == via->GetNet() )
|
|
|
|
{
|
|
|
|
*curpos = via->m_Start;
|
2008-03-10 13:33:12 +00:00
|
|
|
// D(printf("via hit\n");)
|
2008-03-04 21:10:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-03-04 19:17:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
//D( printf( "skipping self\n" ); )
|
2008-03-04 19:17:19 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( !currTrack )
|
|
|
|
{
|
|
|
|
int layer_mask = g_TabOneLayerMask[layer];
|
2008-02-29 20:35:11 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
TRACK* track = Locate_Pistes( m_Pcb->m_Track, layer_mask, CURSEUR_OFF_GRILLE );
|
2008-12-04 04:28:11 +00:00
|
|
|
if( !track || track->Type() != TYPE_TRACK )
|
|
|
|
{
|
|
|
|
// D(printf("!currTrack and track=%p not found, layer_mask=0x%X\n", track, layer_mask );)
|
2008-03-04 19:17:19 +00:00
|
|
|
return false;
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
2008-02-29 20:35:11 +00:00
|
|
|
|
2008-03-10 13:33:12 +00:00
|
|
|
// D( printf( "Project\n" ); )
|
2008-03-04 19:17:19 +00:00
|
|
|
return Project( curpos, on_grid, track );
|
|
|
|
}
|
2008-02-29 20:35:11 +00:00
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
/*
|
|
|
|
* In two segment mode, ignore the final segment if it's inside a grid
|
|
|
|
* square.
|
|
|
|
*/
|
|
|
|
if( !amMovingVia && currTrack && g_TwoSegmentTrackBuild && currTrack->Back()
|
|
|
|
&& currTrack->m_Start.x - grid.x < currTrack->m_End.x
|
|
|
|
&& currTrack->m_Start.x + grid.x > currTrack->m_End.x
|
|
|
|
&& currTrack->m_Start.y - grid.y < currTrack->m_End.y
|
|
|
|
&& currTrack->m_Start.y + grid.y > currTrack->m_End.y )
|
2008-02-29 20:35:11 +00:00
|
|
|
{
|
2008-03-04 19:17:19 +00:00
|
|
|
currTrack = currTrack->Back();
|
2008-02-29 20:35:11 +00:00
|
|
|
}
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
|
|
|
|
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
|
2008-02-29 20:35:11 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track->Type() != TYPE_TRACK )
|
2008-03-04 19:17:19 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( doCheckNet && currTrack && currTrack->GetNet() != track->GetNet() )
|
|
|
|
continue;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( g_DesignSettings.m_LayerColor[track->GetLayer()] & ITEM_NOT_SHOW )
|
2008-03-04 19:17:19 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// omit the layer check if moving a via
|
|
|
|
if( !amMovingVia && !track->IsOnLayer( layer ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !track->HitTest( *curpos ) )
|
|
|
|
continue;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
D(printf( "have track prospect\n");)
|
|
|
|
|
2008-03-04 19:17:19 +00:00
|
|
|
if( Join( curpos, track->m_Start, track->m_End, currTrack->m_Start, currTrack->m_End ) )
|
|
|
|
{
|
2008-03-10 13:33:12 +00:00
|
|
|
// D(printf( "join currTrack->Type()=%d\n", currTrack->Type() );)
|
2008-03-04 19:17:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aCurrentTool == ID_TRACK_BUTT || amMovingVia )
|
|
|
|
{
|
|
|
|
// At this point we have a drawing mouse on a track, we are drawing
|
|
|
|
// a new track and that new track is parallel to the track the
|
|
|
|
// mouse is on. Find the nearest end point of the track under mouse
|
|
|
|
// to the mouse and return that.
|
|
|
|
double distStart = hypot( double( curpos->x - track->m_Start.x ),
|
|
|
|
double( curpos->y - track->m_Start.y ));
|
|
|
|
|
|
|
|
double distEnd = hypot( double( curpos->x - track->m_End.x ),
|
|
|
|
double( curpos->y - track->m_End.y ));
|
|
|
|
|
|
|
|
// if track not via, or if its a via dragging but not with its adjacent track
|
2008-12-04 04:28:11 +00:00
|
|
|
if( currTrack->Type() != TYPE_VIA
|
|
|
|
|| ( currTrack->m_Start != track->m_Start && currTrack->m_Start != track->m_End ))
|
2008-03-04 19:17:19 +00:00
|
|
|
{
|
|
|
|
if( distStart <= currTrack->m_Width/2 )
|
|
|
|
{
|
2008-03-10 13:33:12 +00:00
|
|
|
// D(printf("nearest end is start\n");)
|
2008-03-04 19:17:19 +00:00
|
|
|
*curpos = track->m_Start;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( distEnd <= currTrack->m_Width/2 )
|
|
|
|
{
|
2008-03-10 13:33:12 +00:00
|
|
|
// D(printf("nearest end is end\n");)
|
2008-03-04 19:17:19 +00:00
|
|
|
*curpos = track->m_End;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @todo otherwise confine curpos such that it stays centered
|
|
|
|
// within "track"
|
|
|
|
}
|
|
|
|
}
|
2008-02-29 20:35:11 +00:00
|
|
|
}
|
2008-02-26 21:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************************/
|
2007-08-04 01:12:30 +00:00
|
|
|
void WinEDA_BasePcbFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
|
2007-05-06 16:03:28 +00:00
|
|
|
/*****************************************************************/
|
|
|
|
{
|
2007-08-04 01:12:30 +00:00
|
|
|
wxSize delta;
|
|
|
|
int zoom = GetScreen()->GetZoom();
|
|
|
|
wxPoint curpos, oldpos;
|
|
|
|
int hotkey = 0;
|
|
|
|
|
|
|
|
ActiveScreen = GetScreen();
|
|
|
|
|
|
|
|
// Save the board after the time out :
|
|
|
|
int CurrentTime = time( NULL );
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
if( !GetScreen()->IsModify() || GetScreen()->IsSave() )
|
2007-09-25 08:23:53 +00:00
|
|
|
{
|
2007-08-04 04:40:07 +00:00
|
|
|
/* If no change, reset the time out */
|
2007-08-04 01:12:30 +00:00
|
|
|
g_SaveTime = CurrentTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (CurrentTime - g_SaveTime) > g_TimeOut )
|
|
|
|
{
|
|
|
|
wxString tmpFileName = GetScreen()->m_FileName;
|
|
|
|
wxString filename = g_SaveFileName + PcbExtBuffer;
|
|
|
|
bool flgmodify = GetScreen()->IsModify();
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
( (WinEDA_PcbFrame*) this )->SavePcbFile( filename );
|
2007-08-04 04:40:07 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
if( flgmodify ) // Set the flags m_Modify cleared by SavePcbFile()
|
|
|
|
{
|
|
|
|
GetScreen()->SetModify();
|
|
|
|
GetScreen()->SetSave(); // Set the flags m_FlagSave cleared by SetModify()
|
|
|
|
}
|
|
|
|
GetScreen()->m_FileName = tmpFileName;
|
|
|
|
SetTitle( GetScreen()->m_FileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos = DrawPanel->CursorRealPosition( Mouse );
|
2007-12-05 17:56:57 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
oldpos = GetScreen()->m_Curseur;
|
|
|
|
|
|
|
|
delta.x = (int) round( (double) GetScreen()->GetGrid().x / zoom );
|
|
|
|
delta.y = (int) round( (double) GetScreen()->GetGrid().y / zoom );
|
2008-02-26 21:12:08 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
if( delta.x <= 0 )
|
|
|
|
delta.x = 1;
|
2008-04-29 03:18:02 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
if( delta.y <= 0 )
|
|
|
|
delta.y = 1;
|
|
|
|
|
|
|
|
switch( g_KeyPressed )
|
|
|
|
{
|
|
|
|
case EDA_PANNING_UP_KEY:
|
|
|
|
OnZoom( ID_ZOOM_PANNING_UP );
|
2008-04-17 16:25:29 +00:00
|
|
|
curpos = GetScreen()->m_Curseur;
|
2007-08-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDA_PANNING_DOWN_KEY:
|
|
|
|
OnZoom( ID_ZOOM_PANNING_DOWN );
|
2008-04-17 16:25:29 +00:00
|
|
|
curpos = GetScreen()->m_Curseur;
|
2007-08-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDA_PANNING_LEFT_KEY:
|
|
|
|
OnZoom( ID_ZOOM_PANNING_LEFT );
|
2008-04-17 16:25:29 +00:00
|
|
|
curpos = GetScreen()->m_Curseur;
|
2007-08-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDA_PANNING_RIGHT_KEY:
|
|
|
|
OnZoom( ID_ZOOM_PANNING_RIGHT );
|
2008-04-17 16:25:29 +00:00
|
|
|
curpos = GetScreen()->m_Curseur;
|
2007-08-04 01:12:30 +00:00
|
|
|
break;
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
case EDA_ZOOM_IN_FROM_MOUSE:
|
2008-02-17 21:19:13 +00:00
|
|
|
OnZoom( ID_ZOOM_IN_KEY );
|
2007-08-04 01:12:30 +00:00
|
|
|
oldpos = curpos = GetScreen()->m_Curseur;
|
|
|
|
break;
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
case EDA_ZOOM_OUT_FROM_MOUSE:
|
2008-02-17 21:19:13 +00:00
|
|
|
OnZoom( ID_ZOOM_OUT_KEY );
|
2007-08-04 01:12:30 +00:00
|
|
|
oldpos = curpos = GetScreen()->m_Curseur;
|
|
|
|
break;
|
|
|
|
|
2007-09-25 08:23:53 +00:00
|
|
|
case EDA_ZOOM_CENTER_FROM_MOUSE:
|
2007-08-04 01:12:30 +00:00
|
|
|
OnZoom( ID_ZOOM_CENTER_KEY );
|
|
|
|
oldpos = curpos = GetScreen()->m_Curseur;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_NUMPAD8: /* Deplacement curseur vers le haut */
|
|
|
|
case WXK_UP:
|
|
|
|
Mouse.y -= delta.y;
|
|
|
|
DrawPanel->MouseTo( Mouse );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_NUMPAD2: /* Deplacement curseur vers le bas */
|
|
|
|
case WXK_DOWN:
|
|
|
|
Mouse.y += delta.y;
|
|
|
|
DrawPanel->MouseTo( Mouse );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_NUMPAD4: /* Deplacement curseur vers la gauche */
|
|
|
|
case WXK_LEFT:
|
|
|
|
Mouse.x -= delta.x;
|
|
|
|
DrawPanel->MouseTo( Mouse );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_NUMPAD6: /* Deplacement curseur vers la droite */
|
|
|
|
case WXK_RIGHT:
|
|
|
|
Mouse.x += delta.x;
|
|
|
|
DrawPanel->MouseTo( Mouse );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
hotkey = g_KeyPressed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put cursor in new position, according to the zoom keys (if any) */
|
|
|
|
GetScreen()->m_Curseur = curpos;
|
|
|
|
|
|
|
|
/* Put cursor on grid or a pad centre if requested
|
2007-08-04 04:40:07 +00:00
|
|
|
* But if the tool DELETE is active the cursor is left off grid
|
|
|
|
* this is better to reach items to delete off grid
|
2007-08-04 01:12:30 +00:00
|
|
|
*/
|
|
|
|
bool keep_on_grid = TRUE;
|
|
|
|
if( m_ID_current_state == ID_PCB_DELETE_ITEM_BUTT )
|
|
|
|
keep_on_grid = FALSE;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
/* Cursor is left off grid if no block in progress and no moving object */
|
|
|
|
if( GetScreen()->BlockLocate.m_State != STATE_NO_BLOCK )
|
|
|
|
keep_on_grid = TRUE;
|
2007-09-25 08:23:53 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
EDA_BaseStruct* DrawStruct = GetScreen()->GetCurItem();
|
2007-08-04 01:12:30 +00:00
|
|
|
if( DrawStruct && DrawStruct->m_Flags )
|
|
|
|
keep_on_grid = TRUE;
|
|
|
|
|
2008-02-27 15:26:16 +00:00
|
|
|
if( keep_on_grid )
|
|
|
|
{
|
|
|
|
wxPoint on_grid = curpos;
|
2007-08-04 01:12:30 +00:00
|
|
|
|
2008-02-27 15:26:16 +00:00
|
|
|
PutOnGrid( &on_grid );
|
|
|
|
if( Magnetize(m_Pcb, (WinEDA_PcbFrame *) this, m_ID_current_state,
|
2008-02-29 20:35:11 +00:00
|
|
|
GetScreen()->GetGrid(), on_grid, &curpos) )
|
|
|
|
{
|
2008-02-27 15:26:16 +00:00
|
|
|
GetScreen()->m_Curseur = curpos;
|
2008-02-29 20:35:11 +00:00
|
|
|
}
|
2008-02-27 15:26:16 +00:00
|
|
|
else
|
|
|
|
{
|
2008-02-29 20:35:11 +00:00
|
|
|
// If there's no intrusion and DRC is active, we pass the cursor
|
|
|
|
// "as is", and let ShowNewTrackWhenMovingCursor figure out what to do.
|
2008-02-27 15:26:16 +00:00
|
|
|
if( !Drc_On || !g_CurrentTrackSegment
|
|
|
|
|| g_CurrentTrackSegment != this->GetCurItem()
|
2008-02-29 20:35:11 +00:00
|
|
|
|| !LocateIntrusion( m_Pcb->m_Track, g_CurrentTrackSegment->GetNet(),
|
2008-02-27 15:26:16 +00:00
|
|
|
g_CurrentTrackSegment->m_Width ) )
|
2008-02-29 20:35:11 +00:00
|
|
|
{
|
2008-02-27 15:26:16 +00:00
|
|
|
GetScreen()->m_Curseur = on_grid;
|
2008-02-29 20:35:11 +00:00
|
|
|
}
|
2008-02-27 15:26:16 +00:00
|
|
|
}
|
2007-08-04 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( oldpos != GetScreen()->m_Curseur )
|
|
|
|
{
|
|
|
|
curpos = GetScreen()->m_Curseur;
|
|
|
|
GetScreen()->m_Curseur = oldpos;
|
|
|
|
DrawPanel->CursorOff( DC );
|
|
|
|
|
|
|
|
GetScreen()->m_Curseur = curpos;
|
|
|
|
DrawPanel->CursorOn( DC );
|
|
|
|
|
|
|
|
if( DrawPanel->ManageCurseur )
|
|
|
|
{
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-20 10:55:09 +00:00
|
|
|
if( hotkey )
|
|
|
|
{
|
|
|
|
OnHotKey( DC, hotkey, NULL );
|
|
|
|
}
|
|
|
|
|
2007-08-04 01:12:30 +00:00
|
|
|
if( GetScreen()->IsRefreshReq() )
|
|
|
|
{
|
|
|
|
RedrawActiveWindow( DC, TRUE );
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:14:25 +00:00
|
|
|
SetToolbars();
|
2008-04-29 13:35:26 +00:00
|
|
|
|
2007-10-16 19:05:33 +00:00
|
|
|
Affiche_Status_Box(); /* Display new cursor coordinates */
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|