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

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
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@
#include "hotkeys_basic.h"
#include <wx/bmpcbox.h>


class EDA_TOOLBAR;


/* class to display a layer list.
 *
 */
+3 −0
Original line number Diff line number Diff line
@@ -8,6 +8,9 @@
#define  _DIALOG_HELPERS_H_


#include "common.h"             // EDA_UNITS_T


/**
 * class EDA_LIST_DIALOG
 *
+0 −1
Original line number Diff line number Diff line
@@ -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
+78 −0
Original line number Diff line number Diff line
@@ -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 )
+17 −0
Original line number Diff line number Diff line
@@ -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
Loading