Commit dfa7e1d6 authored by charras's avatar charras
Browse files

Code cleaning and enhancements about EDA_TextStruct

parent 86a40a93
Loading
Loading
Loading
Loading
+130 −51
Original line number Original line Diff line number Diff line
@@ -185,23 +185,114 @@ EDA_TextStruct::~EDA_TextStruct()
}
}




/********************************/
/**
int EDA_TextStruct::Len_Size()
 * Function LenSize
/********************************/
 * @return the text lenght in internal units

 * @param aLine : the line of text to consider.
// Return the text lenght in internal units
 * For single line text, this parameter is always m_Text
 */
int EDA_TextStruct::LenSize( const wxString& aLine )
{
{
    int nbchar = m_Text.Len();
    int nbchar = aLine.Len();
    int len;


    if( nbchar == 0 )
    int len = ( ( (10 * m_Size.x ) / 9 ) + m_Width ) * nbchar;
        return 0;


    len = ( ( (10 * m_Size.x ) / 9 ) + m_Width ) * nbchar;
    return len;
    return len;
}
}




/** Function GetTextBox
 * useful in multiline texts to calculate the full text or a line area (for zones filling, locate functions....)
 * @return the rect containing the line of text (i.e. the position and the size of one line)
 * this rectangle is calculated for 0 orient text. if orient is not 0 the rect must be rotated to match the physical area
 * @param aLine : the line of text to consider.
 * for single line text, aLine is unused
 * If aLine == -1, the full area (considering all lines) is returned
 */
EDA_Rect EDA_TextStruct::GetTextBox( int aLine )
{
    EDA_Rect       rect;
    wxPoint        pos;
    wxArrayString* list = NULL;

    wxString*      text = &m_Text;

    if( m_MultilineAllowed )
    {
        list = wxStringSplit( m_Text, '\n' );
        if( aLine >= 0 && (aLine < (int)list->GetCount()) )
            text = &list->Item( aLine );
        else
            text = &list->Item( 0 );
    }


    // calculate the H and V size
    int    dx = LenSize( *text );
    int    dy = m_Size.y + m_Width;
    int extra_dy = (m_Size.y * 3)/10;      // extra dy value for letters like j and y

    /* Creates bounding box (rectangle) for an horizontal text */
    wxSize textsize = wxSize( dx, dy );
    rect.SetOrigin( m_Pos );

    // for multiline texts ans aLine < 0, merge all rectangles
    if( m_MultilineAllowed && aLine < 0 )
    {
        dy = GetInterline();
        for( unsigned ii = 1; ii < list->GetCount(); ii++ )
        {
            text = &list->Item( ii );
            dx   = LenSize( *text );
            textsize.x  = MAX( textsize.x, dx );
            textsize.y += dy;
        }
    }
    delete list;

    textsize.y += extra_dy;
    rect.SetSize( textsize );

    /* Now, calculate the rect origin, according to text justification
     * At this point the area origin is the text origin.
     * This is true only for left and top text justified.
     * and must be recalculated for others justifications
     * also, note the V justification is relative to the first line
     */
    switch( m_HJustify )
    {
    case GR_TEXT_HJUSTIFY_LEFT:
        break;

    case GR_TEXT_HJUSTIFY_CENTER:
        rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
        break;

    case GR_TEXT_HJUSTIFY_RIGHT:
        rect.SetX( rect.GetX() - rect.GetWidth() );
        break;
    }

    dy = m_Size.y + m_Width;
    switch( m_VJustify )
    {
    case GR_TEXT_VJUSTIFY_TOP:
        break;

    case GR_TEXT_VJUSTIFY_CENTER:
        rect.SetY( rect.GetY() - (dy / 2) );
        break;

    case GR_TEXT_VJUSTIFY_BOTTOM:
        rect.SetY( rect.GetY() + (dy / 2) );
        break;
    }

    rect.Normalize();       // Make h and v sizes always >= 0
    return rect;
}


/*************************************************/
/*************************************************/
bool EDA_TextStruct::HitTest( const wxPoint& posref )
bool EDA_TextStruct::HitTest( const wxPoint& posref )
/*************************************************/
/*************************************************/
@@ -212,21 +303,13 @@ bool EDA_TextStruct::HitTest( const wxPoint& posref )
 *      false else.
 *      false else.
 */
 */
{
{
    int     dx, dy;
    EDA_Rect rect = GetTextBox( -1 );   // Get the full text area.
    wxPoint location;

    dx = (int) ( ( Pitch() * GetLength() ) / 2 );
    dy = m_Size.y / 2;


    /* Is the ref point inside the text area ?  */
    /* Is the ref point inside the text area ?  */
    location = posref - m_Pos;
    wxPoint location = posref;

    RotatePoint( &location, m_Pos, -m_Orient );
    RotatePoint( &location, -m_Orient );


    if( ( abs( location.x ) <= abs( dx ) ) && ( abs( location.y ) <= abs( dy ) ) )
    return rect.Inside ( location);
        return true;

    return false;
}
}




@@ -279,18 +362,15 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
 */
 */


{
{

    if( m_MultilineAllowed )
    if( m_MultilineAllowed )
    {
    {
        wxPoint        pos  = m_Pos;
        wxPoint        pos  = m_Pos;
        wxArrayString* list = wxStringSplit( m_Text, '\n' );
        wxArrayString* list = wxStringSplit( m_Text, '\n' );
        wxPoint        offset;
        wxPoint        offset;


        offset.y = (int) (m_Size.y * 1.5 );
        offset.y = GetInterline();


        RotatePoint( &offset, m_Orient );
        RotatePoint( &offset, m_Orient );
        if( m_Mirror )
            offset.x = -offset.x;
        for( unsigned i = 0; i<list->Count(); i++ )
        for( unsigned i = 0; i<list->Count(); i++ )
        {
        {
            wxString txt = list->Item( i );
            wxString txt = list->Item( i );
@@ -308,7 +388,6 @@ void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,


        delete (list);
        delete (list);
    }
    }

    else
    else
        DrawOneLineOfText( aPanel,
        DrawOneLineOfText( aPanel,
                           aDC,
                           aDC,
+2 −2
Original line number Original line Diff line number Diff line
@@ -709,9 +709,9 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center )
        DrawText = (SCH_TEXT*) DrawStruct;
        DrawText = (SCH_TEXT*) DrawStruct;
        px = DrawText->m_Pos;
        px = DrawText->m_Pos;
        if( DrawText->m_Orient == 0 )       /* horizontal text */
        if( DrawText->m_Orient == 0 )       /* horizontal text */
            dx = DrawText->Len_Size() / 2;
            dx = DrawText->LenSize(DrawText->m_Text) / 2;
        else if( DrawText->m_Orient == 2 )  /* invert horizontal text*/
        else if( DrawText->m_Orient == 2 )  /* invert horizontal text*/
            dx = -DrawText->Len_Size() / 2;
            dx = -DrawText->LenSize(DrawText->m_Text) / 2;
        else
        else
            dx = 0;
            dx = 0;
        px.x += dx;
        px.x += dx;
+24 −3
Original line number Original line Diff line number Diff line
@@ -567,10 +567,31 @@ public:
    bool    HitTest( EDA_Rect& refArea );
    bool    HitTest( EDA_Rect& refArea );


    /**
    /**
     * Function Len_Size
     * Function LenSize
     * Return the text lenght in internal units
     * @return the text lenght in internal units
     * @param aLine : the line of text to consider.
     * For single line text, this parameter is always m_Text
     */
     */
    int     Len_Size();
    int     LenSize(const wxString & aLine);

    /** Function GetTextBox
     * useful in multiline texts to calculate the full text or a line area (for zones filling, locate functions....)
     * @return the rect containing the line of text (i.e. the position and the size of one line)
     * this rectangle is calculated for 0 orient text. if orient is not 0 the rect must be rotated to match the physical area
     * @param aLine : the line of text to consider.
     * for single line text, aLine is unused
     * If aLine == -1, the full area (considering all lines) is returned
     */
    EDA_Rect GetTextBox( int aLine = -1);
    
    /** Function GetInterline
     * return the distance between 2 text lines
     * has meaning only for multiline texts
     */
    int GetInterline()
    {
        return (( m_Size.y * 13 ) / 10) + m_Width;
    }
};
};


#endif /* BASE_STRUCT_H */
#endif /* BASE_STRUCT_H */
+19 −28
Original line number Original line Diff line number Diff line
@@ -277,8 +277,6 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
            break;
            break;


        case TYPE_TEXTE:
        case TYPE_TEXTE:
            if( ( (TEXTE_PCB*) item )->GetLength() == 0 )
                break;
            AddTextBoxWithClearancePolygon( booleng, (TEXTE_PCB*) item, m_ZoneClearance );
            AddTextBoxWithClearancePolygon( booleng, (TEXTE_PCB*) item, m_ZoneClearance );
            have_poly_to_substract = true;
            have_poly_to_substract = true;
            break;
            break;
@@ -1234,36 +1232,29 @@ void AddRingPolygon( Bool_Engine* aBooleng, wxPoint aCentre,
void    AddTextBoxWithClearancePolygon( Bool_Engine* aBooleng,
void    AddTextBoxWithClearancePolygon( Bool_Engine* aBooleng,
                                        TEXTE_PCB* aText, int aClearanceValue )
                                        TEXTE_PCB* aText, int aClearanceValue )
{
{
    int corners[8];     // Buffer of coordinates
    if ( aText->GetLength() == 0 )
    int ii;
        return;


    int dx = aText->Pitch() * aText->GetLength();
    wxPoint corners[4];     // Buffer of polygon corners
    int dy = aText->m_Size.y + aText->m_Width;


    EDA_Rect rect = aText->GetTextBox( -1 );
    /* Creates bounding box (rectangle) for an horizontal text */
    rect.Inflate( aClearanceValue, aClearanceValue );
    dx /= 2; dy /= 2;    /* dx et dy = demi dimensionx X et Y */
    corners[0] = rect.GetOrigin();
    dx += aClearanceValue;
    corners[1].y = corners[0].y;
    dy += aClearanceValue;
    corners[1].x = rect.GetRight();
    corners[0] = aText->m_Pos.x - dx;
    corners[2].x = corners[1].x;
    corners[1] = aText->m_Pos.y - dy;
    corners[2].y = rect.GetBottom();
    corners[2] = aText->m_Pos.x + dx;
    corners[3].y = corners[2].y;
    corners[3] = aText->m_Pos.y - dy;
    corners[3].x = corners[0].x;
    corners[4] = aText->m_Pos.x + dx;

    corners[5] = aText->m_Pos.y + dy;
    corners[6] = aText->m_Pos.x - dx;
    corners[7] = aText->m_Pos.y + dy;

    // Rotate rectangle
    RotatePoint( &corners[0], &corners[1], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
    RotatePoint( &corners[2], &corners[3], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
    RotatePoint( &corners[4], &corners[5], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
    RotatePoint( &corners[6], &corners[7], aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
 
 
    if( aBooleng->StartPolygonAdd( GROUP_B ) )
    if( aBooleng->StartPolygonAdd( GROUP_B ) )
    {
    {
        for( ii = 0; ii < 8; ii += 2 )
        for( int ii = 0; ii < 4; ii ++ )
        {
        {
            aBooleng->AddPoint( corners[ii], corners[ii + 1] );
            // Rotate polygon
            RotatePoint( &corners[ii].x, &corners[ii].y, aText->m_Pos.x, aText->m_Pos.y, aText->m_Orient );
            aBooleng->AddPoint( corners[ii].x, corners[ii].y );
        }
        }


        aBooleng->EndPolygonAdd();
        aBooleng->EndPolygonAdd();