Commit ae84ca2f authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

PCBNew locate pad code refactoring and other minor fixes.

* Refactor pad locate code into the appropriate object.
* Dead code removal.
* Lots of coding style policy fixes.
parent 3d7c91af
Loading
Loading
Loading
Loading
+143 −129
Original line number Diff line number Diff line
/***********************************************************/
/*                      wxPcbStruct.h:                     */
/*      Classes used in pcbnew, cvpcb and gerbview         */
/***********************************************************/
/**
 * @file wxBasePcbStruct.h
 * @brief Classes used in pcbnew, cvpcb and gerbview.
 */

#ifndef  WX_BASE_PCB_FRAME_H
#define  WX_BASE_PCB_FRAME_H
@@ -98,16 +98,12 @@ public:

    // General
    virtual void OnCloseWindow( wxCloseEvent& Event ) = 0;

    virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) { }
    virtual void ReCreateHToolbar() = 0;
    virtual void ReCreateVToolbar() = 0;
    virtual void    OnLeftClick( wxDC*          DC,
                                 const wxPoint& MousePos ) = 0;
    virtual void    OnLeftDClick( wxDC*          DC,
                                  const wxPoint& MousePos ) = 0;
    virtual bool    OnRightClick( const wxPoint& MousePos,
                                  wxMenu*        PopMenu )  = 0;
    virtual void OnLeftClick( wxDC* DC, const wxPoint& MousePos ) = 0;
    virtual void OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) = 0;
    virtual bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )  = 0;
    virtual void ReCreateMenuBar();
    virtual void SetToolID( int aId, int aCursor, const wxString& aToolMsg );
    virtual void UpdateStatusBar();
@@ -161,11 +157,10 @@ public:
     * of "selecting" an item more formal, and to indivisibly tie the operation
     * of selecting an item to displaying it using BOARD_ITEM::Display_Infos().
     * @param aItem The BOARD_ITEM to make the selected item or NULL if none.
     * @param aDisplayInfo = true to display item info, false if not (default =
     *true)
     * @param aDisplayInfo = true to display item info, false if not (default = true)
     */
    void                     SetCurItem( BOARD_ITEM* aItem,
                                         bool        aDisplayInfo = true );
    void SetCurItem( BOARD_ITEM* aItem, bool aDisplayInfo = true );

    BOARD_ITEM* GetCurItem();

    /**
@@ -256,8 +251,7 @@ public:
    void RotateTextModule( TEXTE_MODULE* Text, wxDC* DC );
    void DeleteTextModule( TEXTE_MODULE* Text );
    void PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC );
    void          StartMoveTexteModule( TEXTE_MODULE* Text,
                                        wxDC*         DC );
    void StartMoveTexteModule( TEXTE_MODULE* Text, wxDC* DC );
    TEXTE_MODULE* CreateTextModule( MODULE* Module, wxDC* DC );

    /**
@@ -279,8 +273,7 @@ public:
    void ResetModuleTextSizes( int aType, wxDC* aDC );

    void InstallPadOptionsFrame( D_PAD*         pad );
    void          InstallTextModOptionsFrame( TEXTE_MODULE* TextMod,
                                              wxDC*         DC );
    void InstallTextModOptionsFrame( TEXTE_MODULE* TextMod, wxDC* DC );

    void AddPad( MODULE* Module, bool draw );

@@ -299,9 +292,7 @@ public:
    void PlacePad( D_PAD* Pad, wxDC* DC );
    void Export_Pad_Settings( D_PAD* aPad );
    void Import_Pad_Settings( D_PAD* aPad, bool aDraw );
    void          Global_Import_Pad_Settings( D_PAD* aPad,
                                              bool   aDraw );

    void Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw );

    // loading footprints

@@ -333,8 +324,7 @@ public:
     *                    having one (or more) of these keywords in their
     *                    keyword list ( aKeyWord = wxEmptyString if not used )
     *
     *  @return wxEmptyString if abort or fails, or the selected module name if
     *          Ok
     *  @return wxEmptyString if abort or fails, or the selected module name if Ok
     */
    wxString Select_1_Module_From_List( EDA_DRAW_FRAME* aWindow,
                                        const wxString& aLibraryFullFilename,
@@ -385,13 +375,41 @@ public:
    void DrawGeneralRatsnest( wxDC* aDC, int aNetcode = 0 );

    void trace_ratsnest_pad( wxDC* DC );
    void     build_ratsnest_pad( BOARD_ITEM*    ref,
                                 const wxPoint& refpos,
                                 bool           init );
    void build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, bool init );

    void Tst_Ratsnest( wxDC* DC, int ref_netcode );
    void     test_connexions( wxDC* DC );
    void     test_1_net_connexion( wxDC* DC, int net_code );

    /**
     * Function TestConnections
     * tests the connections relative to all nets.
     * <p>
     * This function update the status of the ratsnest ( flag CH_ACTIF = 0 if a connection
     * is found, = 1 else) track segments are assumed to be sorted by net codes.
     * This is the case because when a new track is added, it is inserted in the linked list
     * according to its net code. and when nets are changed (when a new netlist is read)
     * tracks are sorted before using this function.
     * </p>
     * @param aDC = current Device Context
     */
    void TestConnections( wxDC* aDC );

    /**
     * Function TestNetConnection
     * tests the connections relative to \a aNetCode.  Track segments are assumed to be
     * sorted by net codes.
     * @param aDC Cyrrent Device Context
     * @param aNetCode The net code to test
     */
    void TestNetConnection( wxDC* aDC, int aNetCode );

    /**
     * Function RecalculateAllTracksNetcode
     * search connections between tracks and pads and propagate pad net codes to the track
     * segments.
     * <p>
     * This is a 2 pass computation.  First we search a connection between a track segment
     * and a pad.  If the connection is found, the segment netcode is set to the pad netcode.
     */
    void RecalculateAllTracksNetcode();

    /* Plotting functions:
@@ -415,6 +433,7 @@ public:
    void Plot_Layer( PLOTTER*    plotter,
                     int         Layer,
                     GRTraceMode trace_mode );

    /**
     * Function Plot_Standard_Layer
     * plot copper or technical layers.
@@ -432,9 +451,7 @@ public:
                              bool aPlotVia, GRTraceMode aPlotMode,
                              bool aSkipNPTH_Pads = false );

    void     Plot_Serigraphie( PLOTTER*    plotter,
                               int         masque_layer,
                               GRTraceMode trace_mode );
    void Plot_Serigraphie( PLOTTER* plotter, int masque_layer, GRTraceMode trace_mode );

    /**
     * Function PlotDrillMark
@@ -447,9 +464,7 @@ public:
     * @param aSmallDrillShape = true to plot a small drill shape, false to
     *                           plot the actual drill shape
     */
    void     PlotDrillMark( PLOTTER*    aPlotter,
                            GRTraceMode aTraceMode,
                            bool        aSmallDrillShape );
    void PlotDrillMark( PLOTTER* aPlotter, GRTraceMode aTraceMode, bool aSmallDrillShape );

    /* Functions relative to Undo/redo commands:
     */
@@ -484,8 +499,7 @@ public:
    // layerhandling:
    // (See pcbnew/sel_layer.cpp for description of why null_layer parameter
    // is provided)
    int          SelectLayer( int default_layer, int min_layer, int max_layer,
                              bool null_layer = false );
    int SelectLayer( int default_layer, int min_layer, int max_layer, bool null_layer = false );
    void SelectLayerPair();
    virtual void SwitchLayer( wxDC* DC, int layer );

+182 −158
Original line number Diff line number Diff line
/***********************************************************/
/*                      wxPcbStruct.h                      */
/***********************************************************/
/**
 * @file wxPcbStruct.h
 */

#ifndef  WXPCB_STRUCT_H
#define  WXPCB_STRUCT_H
@@ -194,8 +194,7 @@ public:
     * @param aPrintMirrorMode = true to plot mirrored
     * @param aData = a pointer on an auxiliary data (NULL if not used)
     */
    virtual void PrintPage( wxDC* aDC,
                            int aPrintMaskLayer, bool aPrintMirrorMode,
    virtual void PrintPage( wxDC* aDC, int aPrintMaskLayer, bool aPrintMirrorMode,
                            void * aData = NULL );

    void GetKicadAbout( wxCommandEvent& event );
@@ -372,6 +371,7 @@ public:
     * <p>
     * Reloads the 3D view if required and calls the base PCB_BASE_FRAME::OnModify function
     * to update auxiliary information.
     * </p>
     */
    virtual void OnModify();

@@ -475,7 +475,7 @@ public:
     * Put data pointed by List in the previous state, i.e. the state memorized by List
     * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo
     * @param aRedoCommand = a bool: true for redo, false for undo
     * @param aRebuildRatsnet = a bool: true to rebuild ratsnet (normal use), false
     * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false
     * to just retrieve last state (used in abort commands that do not need to
     * rebuild ratsnest)
     */
@@ -780,8 +780,7 @@ public:
     * @param aUndoPickList = the undo list used to save  OldModule. If null,
     *                        OldModule is deleted
     */
    void       Exchange_Module( MODULE*            aOldModule,
                                MODULE*            aNewModule,
    void Exchange_Module( MODULE* aOldModule, MODULE* aNewModule,
                          PICKED_ITEMS_LIST* aUndoPickList );

    // loading modules: see PCB_BASE_FRAME
@@ -797,7 +796,6 @@ public:
     */
    void OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem );


    // Highlight functions:
    int Select_High_Light( wxDC* DC );
    void High_Light( wxDC* DC );
@@ -910,12 +908,39 @@ public:
    void Attribut_Segment( TRACK* track, wxDC* DC, bool Flag_On );
    void Attribut_Track( TRACK* track, wxDC* DC, bool Flag_On );
    void Attribut_net( wxDC* DC, int net_code, bool Flag_On );
    void   Start_MoveOneNodeOrSegment( TRACK* track, wxDC* DC, int command );

    /**
     * Function StartMoveOneNodeOrSegment
     * initializes the parameters to move one  via or/and a terminal point of a track segment
     * The terminal point of other connected segments (if any) are moved too.
     */
    void StartMoveOneNodeOrSegment( TRACK* aTrack, wxDC* aDC, int aCommand );

    bool PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC );

    /**
     * @todo This function is broken, because it merge segments having different
     *       widths or without any connectivity test.
     * 2 collinear segments can be merged only if no other segment or via is
     * connected to the common point and if they have the same width. See
     * cleanup.cpp for merge functions and consider MarkTrace() to locate segments
     * that can be merged
     */
    bool MergeCollinearTracks( TRACK* track, wxDC* DC, int end );

    void Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC );
    void SwitchLayer( wxDC* DC, int layer );
    bool   Add_45_degrees_Segment( wxDC* DC );

    /**
     * Function Add45DegreeSegment
     * adds a track segment between 2 tracks segments if these 2 segments
     * make a 90 deg angle, in order to have 45 deg track segments
     * Its only works on horizontal or vertical segments.
     *
     * @param aDC The wxDC device context to draw on.
     * @return A bool value true if ok or false if not.
     */
    bool Add45DegreeSegment( wxDC* aDC );

    /**
     * Function EraseRedundantTrack
@@ -965,7 +990,6 @@ public:
     */
    void Delete_OldZone_Fill( SEGZONE* aZone, long aTimestamp = 0 );


    /**
     * Function Delete_LastCreatedCorner
     * Used only while creating a new zone outline
@@ -1107,7 +1131,6 @@ public:
    DIMENSION* Begin_Dimension( DIMENSION* Dimension, wxDC* DC );
    void Delete_Dimension( DIMENSION* Dimension, wxDC* DC );


    // netlist  handling:
    void InstallNetlistFrame( wxDC* DC );

@@ -1227,6 +1250,7 @@ public:
     * application name appended with no file.  Otherwise, the title is set to the full path
     * and file name and read only is appended to the title if the user does not have write
     * access to the file.
     * </p>
     */
    void UpdateTitle();

+152 −10
Original line number Diff line number Diff line
@@ -6,9 +6,8 @@
#include "common.h"

#include "pcbnew.h"
#include "class_board_design_settings.h"
#include "colors_selection.h"

#include "class_board.h"

/* This is an odd place for this, but cvpcb won't link if it is
 *  in class_board_item.cpp like I first tried it.
@@ -32,10 +31,8 @@ BOARD::BOARD( EDA_ITEM* parent, PCB_BASE_FRAME* frame ) :
    m_NbNoconnect = 0;                      // Number of unconnected nets.

    m_CurrentZoneContour = NULL;            // This ZONE_CONTAINER handle the
                                            // zone contour currently in
                                            // progress
    m_NetInfo = new NETINFO_LIST( this );   // handle nets info list (name,
                                            // design constraints ..
                                            // zone contour currently in progress
    m_NetInfo = new NETINFO_LIST( this );   // handle nets info list (name, design constraints ..
    m_NetInfo->BuildListOfNets();           // prepare pads and nets lists containers.

    for( int layer = 0; layer < NB_COPPER_LAYERS; ++layer )
@@ -45,11 +42,9 @@ BOARD::BOARD( EDA_ITEM* parent, PCB_BASE_FRAME* frame ) :
    }

    // Initial parameters for the default NETCLASS come from the global
    // preferences
    // within g_DesignSettings via the NETCLASS() constructor.
    // preferences within g_DesignSettings via the NETCLASS() constructor.
    // Should user eventually load a board from a disk file, then these
    // defaults
    // will get overwritten during load.
    // defaults will get overwritten during load.
    m_NetClasses.GetDefault()->SetDescription( _( "This is the default net class." ) );
    m_ViaSizeSelector    = 0;
    m_TrackWidthSelector = 0;
@@ -1340,8 +1335,10 @@ bool BOARD::Save( FILE* aFile ) const
    fprintf( aFile, "$TRACK\n" );

    for( item = m_Track; item; item = item->Next() )
    {
        if( !item->Save( aFile ) )
            goto out;
    }

    fprintf( aFile, "$EndTRACK\n" );

@@ -1349,8 +1346,10 @@ bool BOARD::Save( FILE* aFile ) const
    fprintf( aFile, "$ZONE\n" );

    for( item = m_Zone; item; item = item->Next() )
    {
        if( !item->Save( aFile ) )
            goto out;
    }

    fprintf( aFile, "$EndZONE\n" );

@@ -1492,6 +1491,149 @@ TRACK* BOARD::GetViaByPosition( const wxPoint& aPosition, int aLayerMask )
}


D_PAD* BOARD::GetPad( const wxPoint& aPosition, int aLayerMask )
{
    D_PAD* pad = NULL;

    for( MODULE* module = m_Modules;  module && ( pad == NULL );  module = module->Next() )
    {
        if( aLayerMask )
            pad = module->GetPad( aPosition, aLayerMask );
        else
            pad = module->GetPad( aPosition, ALL_LAYERS );
    }

    return pad;
}


D_PAD* BOARD::GetPad( TRACK* aTrace, int aEndPoint )
{
    D_PAD*  pad = NULL;
    wxPoint aPosition;

    int     aLayerMask = g_TabOneLayerMask[aTrace->GetLayer()];

    if( aEndPoint == START )
    {
        aPosition = aTrace->m_Start;
    }
    else
    {
        aPosition = aTrace->m_End;
    }

    for( MODULE* module = m_Modules;  module;  module = module->Next() )
    {
        pad = module->GetPad( aPosition, aLayerMask );

        if( pad != NULL )
            break;
    }

    return pad;
}


D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, int aLayerMask )
{
    for( unsigned i=0; i<GetPadsCount();  ++i )
    {
        D_PAD* pad = m_NetInfo->GetPad(i);

        if( pad->m_Pos != aPosition )
            continue;

        /* Pad found, it must be on the correct layer */
        if( pad->m_layerMask & aLayerMask )
            return pad;
    }

    return NULL;
}


D_PAD* BOARD::GetPad( LISTE_PAD* aPad, const wxPoint& aPosition, int aLayerMask )
{
    D_PAD*     pad;
    int        ii;

    int        nb_pad  = GetPadsCount();
    LISTE_PAD* ptr_pad = aPad;
    LISTE_PAD* lim = aPad + nb_pad - 1;

    ptr_pad = aPad;

    while( nb_pad )
    {
        pad      = *ptr_pad;
        ii       = nb_pad;
        nb_pad >>= 1;

        if( (ii & 1) && ( ii > 1 ) )
            nb_pad++;

        if( pad->m_Pos.x < aPosition.x ) /* Must search after this item */
        {
            ptr_pad += nb_pad;

            if( ptr_pad > lim )
                ptr_pad = lim;

            continue;
        }

        if( pad->m_Pos.x > aPosition.x ) /* Must search before this item */
        {
            ptr_pad -= nb_pad;

            if( ptr_pad < aPad )
                ptr_pad = aPad;

            continue;
        }

        /* A suitable block is found (X coordinate matches the px reference: but we
         * must matches the Y coordinate */
        if( pad->m_Pos.x == aPosition.x )
        {
            /* Search the beginning of the block */
            while( ptr_pad >= aPad )
            {
                pad = *ptr_pad;

                if( pad->m_Pos.x == aPosition.x )
                    ptr_pad--;
                else
                    break;
            }

            ptr_pad++;  /* ptr_pad = first pad which have pad->m_Pos.x = px */

            for( ; ; ptr_pad++ )
            {
                if( ptr_pad > lim )
                    return NULL; /* outside suitable block */

                pad = *ptr_pad;

                if( pad->m_Pos.x != aPosition.x )
                    return NULL; /* outside suitable block */

                if( pad->m_Pos.y != aPosition.y )
                    continue;

                /* A Pad if found here: but it must mach the layer */
                if( pad->m_layerMask & aLayerMask )  // Matches layer => a connected pad is found!
                    return pad;
            }
        }
    }

    return NULL;
}


#if defined(DEBUG)

void BOARD::Show( int nestLevel, std::ostream& os )
+50 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@

#include "dlist.h"
#include "class_netinfo.h"
#include "class_pad.h"
#include "class_colors_design_settings.h"
#include "class_board_design_settings.h"

@@ -1091,6 +1092,55 @@ public:
     * @return TRACK* A point a to the SEGVIA object if found, else NULL.
     */
    TRACK* GetViaByPosition( const wxPoint& aPosition, int aLayerMask = -1 );

    /**
     * Function GetPad
     * finds a pad \a aPosition on \a aLayer.
     *
     * @param aPosition A wxPoint object containing the position to hit test.
     * @param aLayerMask A layer or layers to mask the hit test.
     * @return A pointer to a D_PAD object if found or NULL if not found.
     */
    D_PAD* GetPad( const wxPoint& aPosition, int aLayerMask = ALL_LAYERS );

    /**
     * Function GetPad
     * finds a pad connected to \a aEndPoint of \a aTrace.
     *
     * @param aTrace A pointer to a TRACK object to hit test against.
     * @param aEndPoint The end point of \a aTrace the hit test against.
     * @return A pointer to a D_PAD object if found or NULL if not found.
     */
    D_PAD* GetPad( TRACK* aTrace, int aEndPoint );

    /**
     * Function GetPadFast
     * return pad found at \a aPosition on \a aLayer uning the fast search method.
     * <p>
     * The fast search method only works if the pad list has already been built.
     * </p>
     * @param aPosition A wxPoint object containing the position to hit test.
     * @param aLayer A layer or layers to mask the hit test.
     * @return A pointer to a D_PAD object if found or NULL if not found.
     */
    D_PAD* GetPadFast( const wxPoint& aPosition, int aLayer );

    /**
     * Function GetPad
     * locates the pad connected at \a aPosition on \a aLayer starting at list postion
     * \a aPad
     * <p>
     * This function uses a fast search in this sorted pad list and it is faster than
     * GetPadFast().  This list is a sorted pad list must be built before calling this
     * function.
     * </p>
     * @note The normal pad list #m_Pads is sorted by increasing netcodes.
     * @param aPad A D_PAD object pointer the first pad in the list to begin searching.
     * @param aPosition A wxPoint object containing the position to test.
     * @param aLayerMast A layer or layers to mask the hit test.
     * @return A D_PAD object pointer to the connected pad.
     */
    D_PAD* GetPad( LISTE_PAD* aPad, const wxPoint& aPosition, int aLayerMask );
};

#endif      // #ifndef CLASS_BOARD_H
+16 −0
Original line number Diff line number Diff line
@@ -819,6 +819,22 @@ D_PAD* MODULE::FindPadByName( const wxString& aPadName ) const
}


D_PAD* MODULE::GetPad( const wxPoint& aPosition, int aLayerMask )
{
    for( D_PAD* pad = m_Pads;   pad;   pad = pad->Next() )
    {
        /* ... and on the correct layer. */
        if( ( pad->m_layerMask & aLayerMask ) == 0 )
            continue;

        if( pad->HitTest( aPosition ) )
            return pad;
    }

    return NULL;
}


// see class_module.h
SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData,
                             const KICAD_T scanTypes[] )
Loading