Commit 2fb2ab0d authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Refactor PCBNew selection clarification menu text code.

* Move menu text code from base board item object to the appropriate
  object.
* Add helper to get board layer to base board item object.
parent 9a51dc75
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -151,17 +151,6 @@ public:
    }


    /**
     * Function MenuText
     * returns the text to use in any menu type UI control which must uniquely
     * identify this item.
     * @param aPcb The PCB in which this item resides, needed for Net lookup.
     * @return wxString
     * @todo: maybe: make this virtual and split into each derived class
     */
    wxString        MenuText( const BOARD* aPcb ) const;


    /**
     * Function MenuIcon
     * @return const char** - The XPM to use in any UI control which can help
@@ -224,8 +213,17 @@ public:
     * returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
     */
    virtual BOARD* GetBoard() const;

    /**
     * Function GetLayerName
     * returns the name of the PCB layer on which the item resides.
     *
     * @return wxString containing the layer name associated with this item.
     */
    wxString GetLayerName() const;
};


class NETCLASS;

/**
+16 −205
Original line number Diff line number Diff line
@@ -14,9 +14,7 @@
#include "bitmaps.h"


/********************************************************/
wxString BOARD_ITEM::ShowShape( Track_Shapes aShape )
/********************************************************/
{
    switch( aShape )
    {
@@ -31,213 +29,11 @@ wxString BOARD_ITEM::ShowShape( Track_Shapes aShape )
}


/**
 * return a specific comment for "this". Used in pop up menus
 * @param aPcb = the parent board
 */
wxString BOARD_ITEM::MenuText( const BOARD* aPcb ) const
{
    wxString            text;
    wxString            msg;
    wxString            temp;
    NETINFO_ITEM* net;
    const BOARD_ITEM*   item = this;
    D_PAD *             pad;

    switch( item->Type() )
    {
    case TYPE_MODULE:
        text << _( "Footprint" ) << wxT( " " ) << ( (MODULE*) item )->GetReference();
        text << wxT( " (" ) << aPcb->GetLayerName( item->m_Layer ).Trim() << wxT( ")" );
        break;

    case TYPE_PAD:
        pad = (D_PAD *) this;
        text << _( "Pad" ) << wxT( " \"" ) << pad->ReturnStringPadName() << wxT( "\" (" );

        if ( (pad->m_Masque_Layer & ALL_CU_LAYERS) == ALL_CU_LAYERS )
            text << _("all copper layers");
        else if( (pad->m_Masque_Layer & LAYER_BACK) == LAYER_BACK )
            text << aPcb->GetLayerName( LAYER_N_BACK ).Trim();
        else if( (pad->m_Masque_Layer & LAYER_FRONT) == LAYER_FRONT )
            text << aPcb->GetLayerName( LAYER_N_FRONT );
        else
            text << _("???");

        text << _( ") of " ) << ( (MODULE*) GetParent() )->GetReference();
        break;

    case TYPE_DRAWSEGMENT:
        text << _( "Pcb Graphic" ) << wxT(": ")
            << ShowShape( (Track_Shapes) ((DRAWSEGMENT*)item)->m_Shape )
            << wxChar(' ') << _("Length:") << valeur_param( (int) ((DRAWSEGMENT*)item)->GetLength(), temp )
            << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim();
        break;

    case TYPE_TEXTE:
        text << _( "Pcb Text" ) << wxT( " " );
        if( ( (TEXTE_PCB*) item )->m_Text.Len() < 12 )
            text << ( (TEXTE_PCB*) item )->m_Text;
        else
            text += ( (TEXTE_PCB*) item )->m_Text.Left( 10 ) + wxT( ".." );
        text << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim();
        break;

    case TYPE_TEXTE_MODULE:
        switch( ( (TEXTE_MODULE*) item )->m_Type )
        {
        case TEXT_is_REFERENCE:
            text << _( "Reference" ) << wxT( " " ) << ( (TEXTE_MODULE*) item )->m_Text;
            break;

        case TEXT_is_VALUE:
            text << _( "Value" ) << wxT( " " ) << ( (TEXTE_MODULE*) item )->m_Text << _( " of " )
                 << ( (MODULE*) GetParent() )->GetReference();
            break;

        default:    // wrap this one in quotes:
            text << _( "Text" ) << wxT( " \"" ) << ( (TEXTE_MODULE*) item )->m_Text <<
            wxT( "\"" ) << _( " of " )
                 << ( (MODULE*) GetParent() )->GetReference();
            break;
        }
        break;

    case TYPE_EDGE_MODULE:
        text << _( "Graphic" ) << wxT( " " );
        text << ShowShape( (Track_Shapes) ( (EDGE_MODULE*) item )->m_Shape );
        text << wxT( " (" ) << aPcb->GetLayerName( ((EDGE_MODULE*) item )->m_Layer ).Trim() << wxT( ")" );
        text << _( " of " )
             << ( (MODULE*) GetParent() )->GetReference();
        break;

    case TYPE_TRACK:
        // deleting tracks requires all the information we can get to
        // disambiguate all the choices under the cursor!
        text << _( "Track" ) << wxT( " " ) << ((TRACK*)item)->ShowWidth();
        net = aPcb->FindNet( ((TRACK*)item)->GetNet() );
        if( net )
        {
            text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
        }
        text << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim()
             << wxT("  ") << _("Net:") << ((TRACK*)item)->GetNet()
             << wxT("  ") << _("Length:") << valeur_param( (int) ((TRACK*)item)->GetLength(), temp );
        break;

    case TYPE_ZONE_CONTAINER:
        text = _( "Zone Outline" );
        {
            ZONE_CONTAINER* area = (ZONE_CONTAINER*) this;
            int ncont = area->m_Poly->GetContour(area->m_CornerSelection);
            if( ncont )
                text << wxT(" ") << _("(Cutout)");
        }
        text << wxT( " " );
        {
            wxString TimeStampText;
            TimeStampText.Printf( wxT( "(%8.8X)" ), item->m_TimeStamp );
            text << TimeStampText;
        }
        if ( !((ZONE_CONTAINER*) item)->IsOnCopperLayer() )
        {
            text << wxT( " [" ) << _("Not on copper layer") << wxT( "]" );
        }
        else if( ((ZONE_CONTAINER*) item)->GetNet() >= 0 )
        {
            net = aPcb->FindNet( ( (ZONE_CONTAINER*) item )->GetNet() );
            if( net )
            {
                text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
            }
        }
        else    // A netcode < 0 is an error flag (Netname not found or area not initialised)
        {
            text << wxT( " [" ) << ( (ZONE_CONTAINER*) item )->m_Netname << wxT( "]" );
            text << wxT(" <") << _("Not Found") << wxT(">");
        }
        text << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim();
        break;

    case TYPE_ZONE:
        text = _( "Zone" );
        text << wxT( " " );
        {
            wxString TimeStampText;
            TimeStampText.Printf( wxT( "(%8.8X)" ), item->m_TimeStamp );
            text << TimeStampText;
        }
        net = aPcb->FindNet( ( (SEGZONE*) item )->GetNet() );
        if( net )
        {
            text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
        }
        text << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim();
        break;

    case TYPE_VIA:
        {
            SEGVIA* via = (SEGVIA*) item;
            text << _( "Via" ) << wxT( " " ) << via->ShowWidth();

            int shape = via->Shape();
            if( shape == VIA_BLIND_BURIED )
                text << wxT(" ") << _( "Blind/Buried" );
            else if( shape == VIA_MICROVIA )
                text << wxT(" ") << _("Micro Via");
            // else say nothing about normal (through) vias

            net = aPcb->FindNet( via->GetNet() );
            if( net )
            {
                text << wxT( " [" ) << net->GetNetname() << wxT( "]" );
            }
            text << wxChar(' ') << _("Net:") << via->GetNet();

            if( shape != VIA_THROUGH )
            {
                // say which layers, only two for now
                int topLayer;
                int botLayer;
                via->ReturnLayerPair( &topLayer, &botLayer );
                text << _( " on " ) << aPcb->GetLayerName( topLayer).Trim() << wxT(" <-> ")
                    << aPcb->GetLayerName( botLayer ).Trim();
            }
        }
        break;

    case TYPE_MARKER_PCB:
        text << _( "Marker" ) << wxT( " @(" ) << ((MARKER_PCB*)item)->GetPos().x
             << wxT(",") << ((MARKER_PCB*)item)->GetPos().y << wxT(")");
        break;

    case TYPE_DIMENSION:
        text << _( "Dimension" ) << wxT( " \"" ) << ( (DIMENSION*) item )->GetText() << wxT( "\"" );
        break;

    case TYPE_MIRE:
        valeur_param( ((MIREPCB*)item)->m_Size, msg );
        text << _( "Target" ) << _( " on " ) << aPcb->GetLayerName( item->GetLayer() ).Trim()
            << wxT( " " ) << _( "size" ) << wxT( " " ) << msg
            ;
        break;

    default:
        text << item->GetClass() << wxT( " Unexpected item type: BUG!!" );
        break;
    }

    return text;
}


/*****************************************/
const char** BOARD_ITEM::MenuIcon() const
/*****************************************/

/** return a specific icon pointer (an xpm icon)  for "this". Used in pop up menus
 * @return an icon pointer (can be NULL)
 */
const char** BOARD_ITEM::MenuIcon() const
{
    const char**            xpm;
    const BOARD_ITEM* item = this;
@@ -301,6 +97,7 @@ const char** BOARD_ITEM::MenuIcon() const
    return (const char**) xpm;
}


void BOARD_ITEM::UnLink()
{
    DLIST<BOARD_ITEM>* list = (DLIST<BOARD_ITEM>*) GetList();
@@ -323,3 +120,17 @@ BOARD* BOARD_ITEM::GetBoard() const
    return NULL;
}


wxString BOARD_ITEM::GetLayerName() const
{
    wxString layerName;
    BOARD* board = GetBoard();

    if( board != NULL )
        return board->GetLayerName( m_Layer ).Trim();

    wxFAIL_MSG( wxT( "No board found for board item type " ) + GetClass() );
    layerName = _( "** undefined layer **" );

    return layerName;
}
+12 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ void DIMENSION::SetText( const wxString& NewText )

/* Return the dimension text
*/
wxString DIMENSION::GetText( void )
wxString DIMENSION::GetText( void ) const
{
    return m_Text->m_Text;
}
@@ -430,7 +430,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
    /* Init layer : */
    m_Text->SetLayer( GetLayer() );

    /* calculate the size of the cdimension
    /* calculate the size of the dimension
     * (text + line above the text) */
    ii = m_Text->m_Size.y +
         m_Text->m_Thickness + (m_Width * 3);
@@ -777,3 +777,13 @@ EDA_RECT DIMENSION::GetBoundingBox() const

    return bBox;
}


wxString DIMENSION::GetSelectMenuText() const
{
    wxString text;

    text << _( "Dimension" ) << wxT( " \"" ) << GetText() << wxT( "\"" );

    return text;
}
+3 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ public:
    bool Save( FILE* aFile ) const;

    void    SetText( const wxString& NewText );
    wxString GetText( void );
    wxString GetText( void ) const;

    void    Copy( DIMENSION* source );

@@ -134,6 +134,8 @@ public:
    }

    EDA_RECT GetBoundingBox() const;

    virtual wxString GetSelectMenuText() const;
};

#endif  // #define DIMENSION_H
+13 −0
Original line number Diff line number Diff line
@@ -495,6 +495,19 @@ bool DRAWSEGMENT::HitTest( EDA_RECT& refArea )
}


wxString DRAWSEGMENT::GetSelectMenuText() const
{
    wxString text;
    wxString temp;

    text << _( "Pcb Graphic" ) << wxT(": ") << ShowShape( (Track_Shapes)m_Shape )
         << wxChar(' ') << _("Length:") << valeur_param( GetLength(), temp )
         << _( " on " ) << GetLayerName();

    return text;
}


#if defined(DEBUG)
/**
 * Function Show
Loading