Commit 9861941d authored by stambaughw's avatar stambaughw
Browse files

Component library editor and viewer improvements and library draw object changes.

* Component library viewer restores state between uses.
* Fixed automatic zoom calculations in library viewer.
* Make library entry list dialog restore previous selection.
* Fix bounding box calculation for vertical field and text draw objects.
* Changed library draw object comparison to test for greater and less than.
* Initial preparation for merging separate library component draw item lists.
parent afb6898f
Loading
Loading
Loading
Loading
+49 −13
Original line number Original line Diff line number Diff line
@@ -20,8 +20,6 @@
#include "protos.h"
#include "protos.h"






LibDrawText::LibDrawText(LIB_COMPONENT * aParent) :
LibDrawText::LibDrawText(LIB_COMPONENT * aParent) :
    LIB_DRAW_ITEM( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE, aParent ),
    LIB_DRAW_ITEM( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE, aParent ),
    EDA_TextStruct()
    EDA_TextStruct()
@@ -193,14 +191,30 @@ LIB_DRAW_ITEM* LibDrawText::DoGenCopy()
}
}




bool LibDrawText::DoCompare( const LIB_DRAW_ITEM& other ) const
int LibDrawText::DoCompare( const LIB_DRAW_ITEM& other ) const
{
{
    wxASSERT( other.Type() == COMPONENT_GRAPHIC_TEXT_DRAW_TYPE );
    wxASSERT( other.Type() == COMPONENT_GRAPHIC_TEXT_DRAW_TYPE );


    const LibDrawText* tmp = ( LibDrawText* ) &other;
    const LibDrawText* tmp = ( LibDrawText* ) &other;


    return ( ( m_Pos == tmp->m_Pos ) && ( m_Size == tmp->m_Size )
    int result = m_Text.CmpNoCase( tmp->m_Text );
             && ( m_Text == tmp->m_Text ) );

    if( result != 0 )
        return result;

    if( m_Pos.x != tmp->m_Pos.x )
        return m_Pos.x - tmp->m_Pos.x;

    if( m_Pos.y != tmp->m_Pos.y )
        return m_Pos.y - tmp->m_Pos.y;

    if( m_Size.x != tmp->m_Size.x )
        return m_Size.x - tmp->m_Size.x;

    if( m_Size.y != tmp->m_Size.y )
        return m_Size.y - tmp->m_Size.y;

    return 0;
}
}




@@ -260,6 +274,7 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    wxPoint pos1, pos2;
    wxPoint pos1, pos2;


    int     color = ReturnLayerColor( LAYER_DEVICE );
    int     color = ReturnLayerColor( LAYER_DEVICE );

    if( aColor < 0 )       // Used normal color or selected color
    if( aColor < 0 )       // Used normal color or selected color
    {
    {
        if( ( m_Selected & IS_SELECTED ) )
        if( ( m_Selected & IS_SELECTED ) )
@@ -270,16 +285,18 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,


    pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
    pos1 = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;


    /* The text orientation may need to be flipped if the
     *  transformation matrix causes xy axes to be flipped. */
    int t1 = ( aTransformMatrix[0][0] != 0 ) ^ ( m_Orient != 0 );

    GRSetDrawMode( aDC, aDrawMode );
    GRSetDrawMode( aDC, aDrawMode );


    DrawGraphicText( aPanel, aDC, pos1, (EDA_Colors) color, m_Text,
    DrawGraphicText( aPanel, aDC, pos1, (EDA_Colors) color, m_Text,
                     t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT,
                     m_Orient, m_Size, m_HJustify, m_VJustify,
                     m_Size, m_HJustify, m_VJustify,
                     GetPenSize( ), m_Italic, m_Bold );
                     GetPenSize( ), m_Italic, m_Bold );

#if 0
    EDA_Rect bBox = GetBoundingBox();
    bBox.Inflate( 1, 1 );
    GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
}
}




@@ -294,3 +311,22 @@ void LibDrawText::DisplayInfo( WinEDA_DrawFrame* frame )


    frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
    frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
}
}


EDA_Rect LibDrawText::GetBoundingBox()
{
    EDA_Rect rect = GetTextBox();
    rect.m_Pos.y *= -1;
    rect.m_Pos.y -= rect.GetHeight();

    wxPoint orig = rect.GetOrigin();
    wxPoint end = rect.GetEnd();
    wxPoint center = rect.Centre();

    RotatePoint( &orig, center, m_Orient );
    RotatePoint( &end, center, m_Orient );
    rect.SetOrigin( orig );
    rect.SetEnd( end );

    return rect;
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -486,7 +486,7 @@ void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
    /* Enable this to draw the bounding box around the component to validate
    /* Enable this to draw the bounding box around the component to validate
     * the bounding box calculations. */
     * the bounding box calculations. */
#if 0
#if 0
    EDA_Rect bBox = LibEntry->GetBoundaryBox( Multi, convert );
    EDA_Rect bBox = GetBoundaryBox( multi, convert );
    GRRect( &panel->m_ClipBox, dc, bBox.GetOrigin().x, bBox.GetOrigin().y,
    GRRect( &panel->m_ClipBox, dc, bBox.GetOrigin().x, bBox.GetOrigin().y,
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
#endif
+57 −6
Original line number Original line Diff line number Diff line
@@ -8,6 +8,8 @@
#include "base_struct.h"
#include "base_struct.h"
#include "drawtxt.h"
#include "drawtxt.h"
#include "kicad_string.h"
#include "kicad_string.h"
#include "class_drawpanel.h"
#include "trigo.h"


#include "program.h"
#include "program.h"
#include "general.h"
#include "general.h"
@@ -309,9 +311,20 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    wxString* text = aData ? (wxString*)aData : &m_Text;
    wxString* text = aData ? (wxString*)aData : &m_Text;
    GRSetDrawMode( aDC, aDrawMode );
    GRSetDrawMode( aDC, aDrawMode );
    DrawGraphicText( aPanel, aDC, text_pos, (EDA_Colors) color, *text,
    DrawGraphicText( aPanel, aDC, text_pos, (EDA_Colors) color, *text,
                     m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
                     m_Orient, m_Size, m_HJustify, m_VJustify, linewidth,
                     m_Size, m_HJustify, m_VJustify, linewidth, m_Italic,
                     m_Italic, m_Bold );
                     m_Bold );

    /* Set to one (1) to draw bounding box around field text to validate
     * bounding box calculation. */
#if 0
    wxString tmp = m_Text;
    m_Text = *text;
    EDA_Rect bBox = GetBoundingBox();
    m_Text = tmp;
    bBox.Inflate( 1, 1 );
    GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
}
}




@@ -404,14 +417,33 @@ void LibDrawField::Copy( LibDrawField* Target ) const
}
}




bool LibDrawField::DoCompare( const LIB_DRAW_ITEM& other ) const
int LibDrawField::DoCompare( const LIB_DRAW_ITEM& other ) const
{
{
    wxASSERT( other.Type() == COMPONENT_FIELD_DRAW_TYPE );
    wxASSERT( other.Type() == COMPONENT_FIELD_DRAW_TYPE );


    const LibDrawField* tmp = ( LibDrawField* ) &other;
    const LibDrawField* tmp = ( LibDrawField* ) &other;


    return ( ( m_FieldId == tmp->m_FieldId ) && ( m_Text == tmp->m_Text )
    if( m_FieldId == tmp->m_FieldId )
             && ( m_Pos == tmp->m_Pos ) && ( m_Size == tmp->m_Size ) );
        return m_FieldId - tmp->m_FieldId;

    int result = m_Text.CmpNoCase( tmp->m_Text );

    if( result != 0 )
        return result;

    if( m_Pos.x != tmp->m_Pos.x )
        return m_Pos.x - tmp->m_Pos.x;

    if( m_Pos.y != tmp->m_Pos.y )
        return m_Pos.y - tmp->m_Pos.y;

    if( m_Size.x != tmp->m_Size.x )
        return m_Size.x - tmp->m_Size.x;

    if( m_Size.y != tmp->m_Size.y )
        return m_Size.y - tmp->m_Size.y;

    return 0;
}
}




@@ -476,6 +508,25 @@ wxString LibDrawField::GetFullText( int unit )
}
}




EDA_Rect LibDrawField::GetBoundingBox()
{
    EDA_Rect rect = GetTextBox();
    rect.m_Pos.y *= -1;
    rect.m_Pos.y -= rect.GetHeight();

    wxPoint orig = rect.GetOrigin();
    wxPoint end = rect.GetEnd();
    wxPoint center = rect.Centre();

    RotatePoint( &orig, center, m_Orient );
    RotatePoint( &end, center, m_Orient );
    rect.SetOrigin( orig );
    rect.SetEnd( end );

    return rect;
}


/**
/**
 * Function ReturnDefaultFieldName
 * Function ReturnDefaultFieldName
 * Return the default field name from its index (REFERENCE, VALUE ..)
 * Return the default field name from its index (REFERENCE, VALUE ..)
+2 −2
Original line number Original line Diff line number Diff line
@@ -79,7 +79,7 @@ public:
     *
     *
     * @return EDA_Rect - Bounding rectangle.
     * @return EDA_Rect - Bounding rectangle.
     */
     */
    virtual EDA_Rect GetBoundingBox() { return GetTextBox(); }
    virtual EDA_Rect GetBoundingBox();


    /**
    /**
     * Function HitTest
     * Function HitTest
@@ -132,7 +132,7 @@ public:


protected:
protected:
    virtual LIB_DRAW_ITEM* DoGenCopy();
    virtual LIB_DRAW_ITEM* DoGenCopy();
    virtual bool DoCompare( const LIB_DRAW_ITEM& other ) const;
    virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
    virtual void DoOffset( const wxPoint& offset );
    virtual void DoOffset( const wxPoint& offset );
    virtual bool DoTestInside( EDA_Rect& rect );
    virtual bool DoTestInside( EDA_Rect& rect );
    virtual void DoMove( const wxPoint& newPosition );
    virtual void DoMove( const wxPoint& newPosition );
+25 −2
Original line number Original line Diff line number Diff line
@@ -368,6 +368,15 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel,
                      Entry->m_DrawPinNum, Entry->m_DrawPinName,
                      Entry->m_DrawPinNum, Entry->m_DrawPinName,
                      aColor, aDrawMode );
                      aColor, aDrawMode );
    }
    }

    /* Set to one (1) to draw bounding box around pin to validate bounding
     * box calculation. */
#if 0
    EDA_Rect bBox = GetBoundingBox();
    bBox.Inflate( 5, 5 );
    GRRect( &aPanel->m_ClipBox, aDC, bBox.GetOrigin().x, bBox.GetOrigin().y,
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
}
}




@@ -1083,13 +1092,27 @@ LIB_DRAW_ITEM* LibDrawPin::DoGenCopy()
}
}




bool LibDrawPin::DoCompare( const LIB_DRAW_ITEM& other ) const
int LibDrawPin::DoCompare( const LIB_DRAW_ITEM& other ) const
{
{
    wxASSERT( other.Type() == COMPONENT_PIN_DRAW_TYPE );
    wxASSERT( other.Type() == COMPONENT_PIN_DRAW_TYPE );


    const LibDrawPin* tmp = ( LibDrawPin* ) &other;
    const LibDrawPin* tmp = ( LibDrawPin* ) &other;


    return ( m_Pos == tmp->m_Pos );
    if( m_PinNum != tmp->m_PinNum )
        return m_PinNum - tmp->m_PinNum;

    int result = m_PinName.CmpNoCase( tmp->m_PinName );

    if( result != 0 )
        return result;

    if( m_Pos.x != tmp->m_Pos.x )
        return m_Pos.x - tmp->m_Pos.x;

    if( m_Pos.y != tmp->m_Pos.y )
        return m_Pos.y - tmp->m_Pos.y;

    return 0;
}
}




Loading