Commit 1c4d925d authored by Wayne Stambaugh's avatar Wayne Stambaugh

PCBNew locate footprint code refactoring and other minor fixes.

* Refactor locate footprint function into the board object.
* Remove locate.cpp as it is no longer needed.
* Actually remove track.cpp from repo that I missed on the last commit.
* Increase the size of the layer pair tool bar bitmap so that it looks
  better with the new larger tool bar images.
* Fixes to prevent common headers from complaining when not included
  in the correct order in source files.
parent ab76e809
......@@ -4,6 +4,10 @@
#include "hotkeys_basic.h"
#include <wx/bmpcbox.h>
class EDA_TOOLBAR;
/* class to display a layer list.
*
*/
......
......@@ -8,6 +8,9 @@
#define _DIALOG_HELPERS_H_
#include "common.h" // EDA_UNITS_T
/**
* class EDA_LIST_DIALOG
*
......
......@@ -137,7 +137,6 @@ set(PCBNEW_SRCS
layer_widget.cpp
librairi.cpp
loadcmp.cpp
locate.cpp
magnetic_tracks_functions.cpp
menubar_modedit.cpp
menubar_pcbframe.cpp
......
......@@ -2017,6 +2017,84 @@ TRACK* BOARD::MarkTrace( TRACK* aTrace,
}
MODULE* BOARD::GetFootprint( const wxPoint& aPosition, int aActiveLayer,
bool aVisibleOnly, bool aIgnoreLocked )
{
MODULE* pt_module;
MODULE* module = NULL;
MODULE* Altmodule = NULL;
int min_dim = 0x7FFFFFFF;
int alt_min_dim = 0x7FFFFFFF;
int layer;
for( pt_module = m_Modules; pt_module; pt_module = (MODULE*) pt_module->Next() )
{
// is the ref point within the module's bounds?
if( !pt_module->HitTest( aPosition ) )
continue;
// if caller wants to ignore locked modules, and this one is locked, skip it.
if( aIgnoreLocked && pt_module->IsLocked() )
continue;
/* Calculate priority: the priority is given to the layer of the
* module and the copper layer if the module layer is indelible,
* adhesive copper, a layer if cmp module layer is indelible,
* adhesive component.
*/
layer = pt_module->GetLayer();
if( layer==ADHESIVE_N_BACK || layer==SILKSCREEN_N_BACK )
layer = LAYER_N_BACK;
else if( layer==ADHESIVE_N_FRONT || layer==SILKSCREEN_N_FRONT )
layer = LAYER_N_FRONT;
/* Test of minimum size to choosing the best candidate. */
EDA_RECT bb = pt_module->GetFootPrintRect();
int offx = bb.GetX() + bb.GetWidth() / 2;
int offy = bb.GetY() + bb.GetHeight() / 2;
//off x & offy point to the middle of the box.
int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy );
//int dist = MIN(lx, ly); // to pick the smallest module (kinda
// screwy with same-sized modules -- this is bad!)
if( aActiveLayer == layer )
{
if( dist <= min_dim )
{
/* better footprint shown on the active layer */
module = pt_module;
min_dim = dist;
}
}
else if( aVisibleOnly && IsModuleLayerVisible( layer ) )
{
if( dist <= alt_min_dim )
{
/* better footprint shown on other layers */
Altmodule = pt_module;
alt_min_dim = dist;
}
}
}
if( module )
{
return module;
}
if( Altmodule )
{
return Altmodule;
}
return NULL;
}
#if defined(DEBUG)
void BOARD::Show( int nestLevel, std::ostream& os )
......
......@@ -1196,6 +1196,23 @@ public:
*/
TRACK* MarkTrace( TRACK* aTrace, int* aCount, int* aTraceLength,
int* aDieLength, bool aReorder );
/**
* Function GetFootprint
* get a footprint by its bounding rectangle at \a aPosition on \a aLayer.
* <p>
* If more than one footprint is at \a aPosition, then the closest footprint on the
* active layer is returned. The distance is calculated via manhattan distance from
* the center of the bounding rectangle to \a aPosition.
*
* @param aPosition Flag bits, tuning the search, see pcbnew.h
* @param aActiveLayer Layer to test.
* @param aVisibleOnly Search only the visible layers if true.
* @param aIgnoreLocked Ignore locked modules when true.
* @return MODULE* The best module or NULL if none.
*/
MODULE* GetFootprint( const wxPoint& aPosition, int aActiveLayer,
bool aVisibleOnly, bool aIgnoreLocked = false );
};
#endif // #ifndef CLASS_BOARD_H
......@@ -599,7 +599,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit
if( !itemCurrentlyEdited )
{
pos = screen->RefPos( true );
module = Locate_Prefered_Module( GetBoard(), pos, screen->m_Active_Layer, true );
module = GetBoard()->GetFootprint( pos, screen->m_Active_Layer, true );
}
else if( GetCurItem()->Type() == TYPE_MODULE )
{
......@@ -689,7 +689,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC )
if( ItemFree )
{
wxPoint pos = GetScreen()->RefPos( false );
MODULE* module = Locate_Prefered_Module( GetBoard(), pos, ALL_LAYERS, false );
MODULE* module = GetBoard()->GetFootprint( pos, ALL_LAYERS, false );
if( module == NULL )
return false;
......
/*******************/
/* Locate element. */
/*******************/
#include "fctsys.h"
#include "common.h"
#include "pcbnew.h"
#include "class_board_design_settings.h"
#include "protos.h"
/**
* Function Locate_Prefered_Module
* locates a footprint by its bounding rectangle. If several footprints
* are possible, then the priority is: the closest on the active layer, then
* closest.
* The current mouse or cursor coordinates are grabbed from the active window
* to perform hit-testing.
* distance is calculated via manhattan distance from the center of the
* bounding rectangle to the cursor position.
*
* @param aPcb The BOARD to search within.
* @param aPosition Flag bits, tuning the search, see pcbnew.h
* @param aActiveLayer Layer to test.
* @param aVisibleOnly Search only the visible layers if true.
* @param aIgnoreLocked Ignore locked modules when true.
* @return MODULE* The best module or NULL if none.
*/
MODULE* Locate_Prefered_Module( BOARD* aPcb, const wxPoint& aPosition, int aActiveLayer,
bool aVisibleOnly, bool aIgnoreLocked )
{
MODULE* pt_module;
MODULE* module = NULL;
MODULE* Altmodule = NULL;
int min_dim = 0x7FFFFFFF;
int alt_min_dim = 0x7FFFFFFF;
int layer;
pt_module = aPcb->m_Modules;
for( ; pt_module; pt_module = (MODULE*) pt_module->Next() )
{
// is the ref point within the module's bounds?
if( !pt_module->HitTest( aPosition ) )
continue;
// if caller wants to ignore locked modules, and this one is locked, skip it.
if( aIgnoreLocked && pt_module->IsLocked() )
continue;
/* Calculate priority: the priority is given to the layer of the
* module and the copper layer if the module layer is indelible,
* adhesive copper, a layer if cmp module layer is indelible,
* adhesive component.
*/
layer = pt_module->GetLayer();
if( layer==ADHESIVE_N_BACK || layer==SILKSCREEN_N_BACK )
layer = LAYER_N_BACK;
else if( layer==ADHESIVE_N_FRONT || layer==SILKSCREEN_N_FRONT )
layer = LAYER_N_FRONT;
/* Test of minimum size to choosing the best candidate. */
EDA_RECT bb = pt_module->GetFootPrintRect();
int offx = bb.GetX() + bb.GetWidth() / 2;
int offy = bb.GetY() + bb.GetHeight() / 2;
//off x & offy point to the middle of the box.
int dist = abs( aPosition.x - offx ) + abs( aPosition.y - offy );
//int dist = MIN(lx, ly); // to pick the smallest module (kinda
// screwy with same-sized modules -- this is bad!)
if( aActiveLayer == layer )
{
if( dist <= min_dim )
{
/* better footprint shown on the active layer */
module = pt_module;
min_dim = dist;
}
}
else if( aVisibleOnly && aPcb->IsModuleLayerVisible( layer ) )
{
if( dist <= alt_min_dim )
{
/* better footprint shown on other layers */
Altmodule = pt_module;
alt_min_dim = dist;
}
}
}
if( module )
{
return module;
}
if( Altmodule )
{
return Altmodule;
}
return NULL;
}
......@@ -61,15 +61,6 @@ void DrawTraces( EDA_DRAW_PANEL* panel,
int nbsegment,
int mode_color );
/****************/
/* LOCATE.CPP : */
/****************/
/* Locate a footprint by its bounding rectangle. */
MODULE* Locate_Prefered_Module( BOARD* aPcb, const wxPoint& aPosition, int aActiveLayer,
bool aVisibleOnly, bool aIgnoreLocked = false );
/*************/
/* MODULES.C */
/*************/
......
/***************************************/
/* tool_pcb.cpp: PCB editor tool bars */
/***************************************/
/**
* @file tool_pcb.cpp
* @brief PCB editor tool bars
*/
#include "fctsys.h"
#include "wx/wupdlock.h"
#include "help_common_strings.h"
#include "dialog_helpers.h"
#include "class_layer_box_selector.h"
#include "colors_selection.h"
#include "pcbnew.h"
#include "wxPcbStruct.h"
#include "class_board_design_settings.h"
#include "colors_selection.h"
#include "dialog_helpers.h"
#include "pcbnew_id.h"
#include "hotkeys.h"
#include "wx/wupdlock.h"
#ifdef __UNIX__
#define LISTBOX_WIDTH 150
......@@ -18,42 +24,40 @@
#define LISTBOX_WIDTH 130
#endif
#include "wx/ownerdrw.h"
#include "wx/menuitem.h"
#include "hotkeys.h"
#include "help_common_strings.h"
#include "class_layer_box_selector.h"
#define SEL_LAYER_HELP _( \
"Show active layer selections\nand select layer pair for route and place via" )
/* Data to build the layer pair indicator button */
static wxBitmap* LayerPairBitmap = NULL;
static const char s_BitmapLayerIcon[16][16] = {
static const char s_BitmapLayerIcon[24][24] = {
// 0 = draw pixel with active layer color
// 1 = draw pixel with top layer color (top/bottom layer used in
// autoroute and place via)
// 1 = draw pixel with top layer color (top/bottom layer used inautoroute and place via)
// 2 = draw pixel with bottom layer color
// 3 = draw pixel with via color
{ 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 1, 1, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 3, 3, 0, 1, 1, 3, 3, 0, 0, 0, 0 },
{ 2, 2, 2, 2, 3, 3, 0, 1, 1, 1, 1, 3, 3, 2, 2, 2 },
{ 2, 2, 2, 2, 3, 3, 1, 1, 1, 0, 0, 3, 3, 2, 2, 2 },
{ 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2 },
{ 0, 0, 0, 0, 0, 3, 3, 1, 1, 0, 3, 3, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 3, 3, 3, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0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, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
......@@ -111,7 +115,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
/* Create the bitmap too and its Memory DC, if not already made */
if( LayerPairBitmap == NULL )
{
LayerPairBitmap = new wxBitmap( 16, 16 );
LayerPairBitmap = new wxBitmap( 24, 24 );
}
/* Draw the icon, with colors according to the active layer and layer
......@@ -119,42 +123,36 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
*/
wxMemoryDC iconDC;
iconDC.SelectObject( *LayerPairBitmap );
int buttcolor = -1;
wxPen pen;
int buttonColor = -1;
for( ii = 0; ii < 16; ii++ )
for( ii = 0; ii < 24; ii++ )
{
for( jj = 0; jj < 16; jj++ )
for( jj = 0; jj < 24; jj++ )
{
if( s_BitmapLayerIcon[ii][jj] != buttcolor )
if( s_BitmapLayerIcon[ii][jj] != buttonColor )
{
buttcolor = s_BitmapLayerIcon[ii][jj];
int color;
switch( buttcolor )
switch( s_BitmapLayerIcon[ii][jj] )
{
default:
case 0:
color = active_layer_color;
pen.SetColour( MakeColour( active_layer_color ) );
break;
case 1:
color = Route_Layer_TOP_color;
pen.SetColour( MakeColour( Route_Layer_TOP_color) );
break;
case 2:
color = Route_Layer_BOTTOM_color;
pen.SetColour( MakeColour( Route_Layer_BOTTOM_color ) );
break;
case 3:
color = via_color;
pen.SetColour( MakeColour( via_color ) );
break;
}
color &= MASKCOLOR;
pen.SetColour( ColorRefs[color].m_Red,
ColorRefs[color].m_Green,
ColorRefs[color].m_Blue );
buttonColor = s_BitmapLayerIcon[ii][jj];
iconDC.SetPen( pen );
}
......@@ -444,8 +442,7 @@ void PCB_EDIT_FRAME::ReCreateVToolbar()
}
/* Create the auxiliary vertical right toolbar, showing tools for
* microwave applications
/* Create the auxiliary vertical right toolbar, showing tools for microwave applications
*/
void PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar()
{
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment