Commit 7c7d675c authored by stambaughw's avatar stambaughw
Browse files

Component library object improvements.

* Library component objects can now draw themselves without external drawing code.
* Fix all the library drawing and field objects to support component drawing code.
* Provide proper file dialog wild card for symbol libraries and us wxFileDialog.
* Update component library editing code to reflect component drawing changes.
parent d4a5e5ac
Loading
Loading
Loading
Loading
+93 −118
Original line number Original line Diff line number Diff line
/****************************************************/
/****************************************************/
/*	block_libedt.cpp       							*/
/*  block_libedit.cpp                                */
/* Gestion des Operations sur Blocks et Effacements */
/* Gestion des Operations sur Blocks et Effacements */
/****************************************************/
/****************************************************/


@@ -15,24 +15,21 @@
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"


/* Variables Locales */


/* Fonctions exportees */
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,

                                     bool erase );
/* Fonctions Locales */
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static int  MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
static int  MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
                             EDA_Rect&               Rect );
                             EDA_Rect&               Rect );


static void ClearMarkItems( EDA_LibComponentStruct* LibComponent );
static void ClearMarkItems( EDA_LibComponentStruct* LibComponent );
static void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset );
static void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset );
static void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset );
static void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset );
static void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset );
static void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry,
                               wxPoint offset );
static void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry );
static void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry );


/*********************************************************/

void ClearMarkItems( EDA_LibComponentStruct* LibComponent )
void ClearMarkItems( EDA_LibComponentStruct* LibComponent )
/*********************************************************/
{
{
    LibEDA_BaseStruct* item;
    LibEDA_BaseStruct* item;


@@ -45,27 +42,27 @@ void ClearMarkItems( EDA_LibComponentStruct* LibComponent )
}
}




/***************************************************************/
/*
int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
 * Mark items inside rect.
                     EDA_Rect&               Rect )
/***************************************************************/

/* Mark items inside rect.
 * Items are inside rect when an end point is inside rect
 * Items are inside rect when an end point is inside rect
 *
 *
 * Rules for convert drawings and other parts ( for multi part per package):
 * Rules for convert drawings and other parts ( for multi part per package):
 *  - Commons are always marked
 *  - Commons are always marked
 *  - Specific graphic shapes must agree with the current displayed part and convert
 *  - Specific graphic shapes must agree with the current displayed part and
 *    convert
 *  - Because most of pins are specific to current part and current convert:
 *  - Because most of pins are specific to current part and current convert:
 *     - if g_EditPinByPinIsOn == TRUE, or flag .m_UnitSelectionLocked == TRUE,
 *     - if g_EditPinByPinIsOn == TRUE, or flag .m_UnitSelectionLocked == TRUE,
 *       only the pins specific to current part and current convert are marked
 *       only the pins specific to current part and current convert are marked
 *     - all specific to current convert pins are marked;
 *     - all specific to current convert pins are marked;
 */
 */
int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
                     EDA_Rect&               Rect )
{
{
    LibEDA_BaseStruct* item;
    LibEDA_BaseStruct* item;
    int                ItemsCount = 0;
    int                ItemsCount = 0;
    wxPoint            pos;
    wxPoint            pos;
    bool ItemIsInOtherPart, ItemIsInOtherConvert;
    bool               ItemIsInOtherPart;
    bool               ItemIsInOtherConvert;


    if( LibComponent == NULL )
    if( LibComponent == NULL )
        return 0;
        return 0;
@@ -188,7 +185,7 @@ int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
        case COMPONENT_FIELD_DRAW_TYPE:
        case COMPONENT_FIELD_DRAW_TYPE:
            break;
            break;


        default:
        defualt:
            break;
            break;
        }
        }
    }
    }
@@ -197,13 +194,11 @@ int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
}
}




/*************************************************************************/
/*
int WinEDA_LibeditFrame::ReturnBlockCommand( int key )
 * Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
/*************************************************************************/

/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
 *  the key (ALT, SHIFT ALT ..)
 *  the key (ALT, SHIFT ALT ..)
 */
 */
int WinEDA_LibeditFrame::ReturnBlockCommand( int key )
{
{
    int cmd;
    int cmd;


@@ -243,17 +238,17 @@ int WinEDA_LibeditFrame::ReturnBlockCommand( int key )
}
}




/****************************************************/
/*
int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
 * Command BLOCK END (end of block sizing)
/****************************************************/

/* Command BLOCK END (end of block sizing)
 *  return :
 *  return :
 *  0 if command finished (zoom, delete ...)
 *  0 if command finished (zoom, delete ...)
 *  1 if HandleBlockPlace must follow (items found, and a block place command must follow)
 *  1 if HandleBlockPlace must follow (items found, and a block place
 * command must follow)
 */
 */
int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
{
{
    int ItemsCount = 0, MustDoPlace = 0;
    int ItemsCount = 0;
    int MustDoPlace = 0;


    if( GetScreen()->m_BlockLocate.GetCount() )
    if( GetScreen()->m_BlockLocate.GetCount() )
    {
    {
@@ -278,7 +273,8 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
    case BLOCK_DRAG:        /* Drag */
    case BLOCK_DRAG:        /* Drag */
    case BLOCK_MOVE:        /* Move */
    case BLOCK_MOVE:        /* Move */
    case BLOCK_COPY:        /* Copy */
    case BLOCK_COPY:        /* Copy */
        ItemsCount = MarkItemsInBloc( CurrentLibEntry, GetScreen()->m_BlockLocate );
        ItemsCount = MarkItemsInBloc( CurrentLibEntry,
                                      GetScreen()->m_BlockLocate );
        if( ItemsCount )
        if( ItemsCount )
        {
        {
            MustDoPlace = 1;
            MustDoPlace = 1;
@@ -300,7 +296,8 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
        break;
        break;


    case BLOCK_DELETE:     /* Delete */
    case BLOCK_DELETE:     /* Delete */
        ItemsCount = MarkItemsInBloc( CurrentLibEntry, GetScreen()->m_BlockLocate );
        ItemsCount = MarkItemsInBloc( CurrentLibEntry,
                                      GetScreen()->m_BlockLocate );
        if( ItemsCount )
        if( ItemsCount )
            SaveCopyInUndoList( CurrentLibEntry );
            SaveCopyInUndoList( CurrentLibEntry );
        DeleteMarkedItems( CurrentLibEntry );
        DeleteMarkedItems( CurrentLibEntry );
@@ -315,10 +312,12 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )




    case BLOCK_MIRROR_Y:
    case BLOCK_MIRROR_Y:
        ItemsCount = MarkItemsInBloc( CurrentLibEntry, GetScreen()->m_BlockLocate );
        ItemsCount = MarkItemsInBloc( CurrentLibEntry,
                                      GetScreen()->m_BlockLocate );
        if( ItemsCount )
        if( ItemsCount )
            SaveCopyInUndoList( CurrentLibEntry );
            SaveCopyInUndoList( CurrentLibEntry );
        MirrorMarkedItems( CurrentLibEntry, GetScreen()->m_BlockLocate.Centre() );
        MirrorMarkedItems( CurrentLibEntry,
                           GetScreen()->m_BlockLocate.Centre() );
        break;
        break;


    case BLOCK_ZOOM:     /* Window Zoom */
    case BLOCK_ZOOM:     /* Window Zoom */
@@ -344,7 +343,8 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
        DrawPanel->ManageCurseur = NULL;
        DrawPanel->ManageCurseur = NULL;
        DrawPanel->ForceCloseManageCurseur = NULL;
        DrawPanel->ForceCloseManageCurseur = NULL;
        GetScreen()->SetCurItem( NULL );
        GetScreen()->SetCurItem( NULL );
        SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
        SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor,
                   wxEmptyString );
        DrawPanel->Refresh( TRUE );
        DrawPanel->Refresh( TRUE );
    }
    }


@@ -353,15 +353,13 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC )
}
}




/******************************************************/
/*
void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )
 * Routine to handle the BLOCK PLACE commande
/******************************************************/

/* Routine to handle the BLOCK PLACE commande
 *  Last routine for block operation for:
 *  Last routine for block operation for:
 *  - block move & drag
 *  - block move & drag
 *  - block copie & paste
 *  - block copie & paste
 */
 */
void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )
{
{
    bool err = FALSE;
    bool err = FALSE;


@@ -384,14 +382,16 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )
    case BLOCK_PRESELECT_MOVE:      /* Move with preselection list*/
    case BLOCK_PRESELECT_MOVE:      /* Move with preselection list*/
        GetScreen()->m_BlockLocate.ClearItemsList();
        GetScreen()->m_BlockLocate.ClearItemsList();
        SaveCopyInUndoList( CurrentLibEntry );
        SaveCopyInUndoList( CurrentLibEntry );
        MoveMarkedItems( CurrentLibEntry, GetScreen()->m_BlockLocate.m_MoveVector );
        MoveMarkedItems( CurrentLibEntry,
                         GetScreen()->m_BlockLocate.m_MoveVector );
        DrawPanel->Refresh( TRUE );
        DrawPanel->Refresh( TRUE );
        break;
        break;


    case BLOCK_COPY:     /* Copy */
    case BLOCK_COPY:     /* Copy */
        GetScreen()->m_BlockLocate.ClearItemsList();
        GetScreen()->m_BlockLocate.ClearItemsList();
        SaveCopyInUndoList( CurrentLibEntry );
        SaveCopyInUndoList( CurrentLibEntry );
        CopyMarkedItems( CurrentLibEntry, GetScreen()->m_BlockLocate.m_MoveVector );
        CopyMarkedItems( CurrentLibEntry,
                         GetScreen()->m_BlockLocate.m_MoveVector );
        break;
        break;


    case BLOCK_PASTE:     /* Paste (recopie du dernier bloc sauve */
    case BLOCK_PASTE:     /* Paste (recopie du dernier bloc sauve */
@@ -400,7 +400,8 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )


    case BLOCK_MIRROR_Y:      /* Invert by popup menu, from block move */
    case BLOCK_MIRROR_Y:      /* Invert by popup menu, from block move */
        SaveCopyInUndoList( CurrentLibEntry );
        SaveCopyInUndoList( CurrentLibEntry );
        MirrorMarkedItems( CurrentLibEntry, GetScreen()->m_BlockLocate.Centre() );
        MirrorMarkedItems( CurrentLibEntry,
                           GetScreen()->m_BlockLocate.Centre() );
        break;
        break;


    case BLOCK_ZOOM:        // Handled by HandleBlockEnd
    case BLOCK_ZOOM:        // Handled by HandleBlockEnd
@@ -414,7 +415,6 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )


    GetScreen()->SetModify();
    GetScreen()->SetModify();



    DrawPanel->ManageCurseur             = NULL;
    DrawPanel->ManageCurseur             = NULL;
    DrawPanel->ForceCloseManageCurseur   = NULL;
    DrawPanel->ForceCloseManageCurseur   = NULL;
    GetScreen()->m_BlockLocate.m_Flags   = 0;
    GetScreen()->m_BlockLocate.m_Flags   = 0;
@@ -423,22 +423,20 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC )
    GetScreen()->SetCurItem( NULL );
    GetScreen()->SetCurItem( NULL );
    DrawPanel->Refresh( TRUE );
    DrawPanel->Refresh( TRUE );


    SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
    SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor,
               wxEmptyString );
}
}




/************************************************************************/
/*
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
 * Retrace le contour du block de recherche de structures
                                     bool erase )
/************************************************************************/

/* Retrace le contour du block de recherche de structures
 *  L'ensemble du block suit le curseur
 *  L'ensemble du block suit le curseur
 */
 */
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
                                     bool erase )
{
{
    BLOCK_SELECTOR* PtBlock;
    BLOCK_SELECTOR* PtBlock;
    BASE_SCREEN* screen = panel->GetScreen();
    BASE_SCREEN* screen = panel->GetScreen();
    LibEDA_BaseStruct* item;
    wxPoint move_offset;
    wxPoint move_offset;


    PtBlock = &screen->m_BlockLocate;
    PtBlock = &screen->m_BlockLocate;
@@ -446,60 +444,42 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
    /* Effacement ancien cadre */
    /* Effacement ancien cadre */
    if( erase )
    if( erase )
    {
    {
        PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color );
        PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode,
                       PtBlock->m_Color );


        if( CurrentLibEntry )
        if( CurrentLibEntry )
        {
        {
            item = CurrentLibEntry->m_Drawings;
            CurrentLibEntry->Draw( panel, DC, PtBlock->m_MoveVector,
            for( ; item != NULL; item = item->Next() )
                                   CurrentUnit, CurrentConvert, g_XorMode,
            {
                                   -1, DefaultTransformMatrix, true, false,
                if( item->m_Selected == 0 )
                                   true );
                    continue;
                /* Do not draw items for other units */
                if( CurrentUnit && item->m_Unit && (item->m_Unit != CurrentUnit) )
                    continue;
                if( CurrentConvert && item->m_Convert && (item->m_Convert != CurrentConvert) )
                    continue;
                DrawLibraryDrawStruct( panel, DC, CurrentLibEntry,
                                       PtBlock->m_MoveVector, item, g_XorMode );
            }
        }
        }
    }
    }


    /* Redessin nouvel affichage */
    /* Redessin nouvel affichage */
    PtBlock->m_MoveVector.x = screen->m_Curseur.x - PtBlock->m_BlockLastCursorPosition.x;
    PtBlock->m_MoveVector.x =
    PtBlock->m_MoveVector.y = screen->m_Curseur.y - PtBlock->m_BlockLastCursorPosition.y;
        screen->m_Curseur.x - PtBlock->m_BlockLastCursorPosition.x;
    PtBlock->m_MoveVector.y =
        screen->m_Curseur.y - PtBlock->m_BlockLastCursorPosition.y;


    GRSetDrawMode( DC, g_XorMode );
    GRSetDrawMode( DC, g_XorMode );
    PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode, PtBlock->m_Color );
    PtBlock->Draw( panel, DC, PtBlock->m_MoveVector, g_XorMode,

                   PtBlock->m_Color );


    if( CurrentLibEntry )
    if( CurrentLibEntry )
    {
    {
        item = CurrentLibEntry->m_Drawings;
        CurrentLibEntry->Draw( panel, DC, PtBlock->m_MoveVector,
        for( ; item != NULL; item = item->Next() )
                               CurrentUnit, CurrentConvert, g_XorMode,
        {
                               -1, DefaultTransformMatrix, true, false,
            if( item->m_Selected == 0 )
                               true );
                continue;
            /* Do not draw items for other units */
            if( CurrentUnit && item->m_Unit && (item->m_Unit != CurrentUnit) )
                continue;
            if( CurrentConvert && item->m_Convert && (item->m_Convert != CurrentConvert) )
                continue;
            DrawLibraryDrawStruct( panel, DC, CurrentLibEntry,
                                   PtBlock->m_MoveVector,
                                   item, g_XorMode );
        }
    }
    }
}
}




/****************************************************************************/
/*
void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
 * Copy marked items, at new position = old position + offset
/****************************************************************************/

/* Copy marked items, at new position = old position + offset
 */
 */
void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
{
{
    LibEDA_BaseStruct* item;
    LibEDA_BaseStruct* item;


@@ -522,12 +502,10 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
}
}




/****************************************************************************/
/*
void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
 * Move marked items, at new position = old position + offset
/****************************************************************************/

/* Move marked items, at new position = old position + offset
 */
 */
void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
{
{
    LibEDA_BaseStruct* item;
    LibEDA_BaseStruct* item;


@@ -580,7 +558,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
            break;
            break;


        default:
        default:
            ;
            break;
        }
        }


        item->m_Flags = item->m_Selected = 0;
        item->m_Flags = item->m_Selected = 0;
@@ -588,12 +566,10 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
}
}




/******************************************************/
/*
void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry )
 * Delete marked items
/******************************************************/

/* Delete marked items
 */
 */
void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry )
{
{
    LibEDA_BaseStruct* item, * next_item;
    LibEDA_BaseStruct* item, * next_item;


@@ -606,17 +582,15 @@ void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry )
        next_item = item->Next();
        next_item = item->Next();
        if( item->m_Selected == 0 )
        if( item->m_Selected == 0 )
            continue;
            continue;
        DeleteOneLibraryDrawStruct( NULL, NULL, LibEntry, item, 0 );
        LibEntry->RemoveDrawItem( item );
    }
    }
}
}




/****************************************************************************/
/*
void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
 * Mirror marked items, refer to a Vertical axis at position offset
/****************************************************************************/

/* Mirror marked items, refer to a Vertical axis at position offset
 */
 */
void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
{
{
#define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
#define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
    LibEDA_BaseStruct* item;
    LibEDA_BaseStruct* item;
@@ -658,7 +632,8 @@ void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
            SETMIRROR( ( (LibDrawArc*) item )->m_Pos.x );
            SETMIRROR( ( (LibDrawArc*) item )->m_Pos.x );
            SETMIRROR( ( (LibDrawArc*) item )->m_ArcStart.x );
            SETMIRROR( ( (LibDrawArc*) item )->m_ArcStart.x );
            SETMIRROR( ( (LibDrawArc*) item )->m_ArcEnd.x );
            SETMIRROR( ( (LibDrawArc*) item )->m_ArcEnd.x );
            EXCHG( ( (LibDrawArc*) item )->m_ArcStart, ( (LibDrawArc*) item )->m_ArcEnd );
            EXCHG( ( (LibDrawArc*) item )->m_ArcStart,
                   ( (LibDrawArc*) item )->m_ArcEnd );
            break;
            break;
        }
        }


@@ -689,7 +664,7 @@ void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
            break;
            break;


        default:
        default:
            ;
            break;
        }
        }


        item->m_Flags = item->m_Selected = 0;
        item->m_Flags = item->m_Selected = 0;
+8 −3
Original line number Original line Diff line number Diff line
@@ -42,7 +42,8 @@ bool LibDrawText::Save( FILE* ExportFile ) const
    fprintf( ExportFile, "T %d %d %d %d %d %d %d %s ", m_Orient,
    fprintf( ExportFile, "T %d %d %d %d %d %d %d %s ", m_Orient,
            m_Pos.x, m_Pos.y, m_Size.x, m_Attributs, m_Unit, m_Convert,
            m_Pos.x, m_Pos.y, m_Size.x, m_Attributs, m_Unit, m_Convert,
            CONV_TO_UTF8( text ) );
            CONV_TO_UTF8( text ) );
    fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal", (m_Bold>0) ? 1 : 0 );
    fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal",
             ( m_Bold>0 ) ? 1 : 0 );


    char hjustify = 'C';
    char hjustify = 'C';
    if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
    if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
@@ -76,7 +77,8 @@ bool LibDrawText::Load( char* line, wxString& errorMsg )


    cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s %s %d %c %c",
    cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s %s %d %c %c",
                  &m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
                  &m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
                  &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify, &vjustify );
                  &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
                  &vjustify );


    if( cnt < 8 )
    if( cnt < 8 )
    {
    {
@@ -149,7 +151,8 @@ bool LibDrawText::HitTest( const wxPoint& refPos )
 * @param aThreshold = unused here (TextHitTest calculates its threshold )
 * @param aThreshold = unused here (TextHitTest calculates its threshold )
 * @param aTransMat = the transform matrix
 * @param aTransMat = the transform matrix
 */
 */
bool LibDrawText::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] )
bool LibDrawText::HitTest( wxPoint aPosRef, int aThreshold,
                           const int aTransMat[2][2] )
{
{
    wxPoint physicalpos = TransformCoordinate( aTransMat, m_Pos );
    wxPoint physicalpos = TransformCoordinate( aTransMat, m_Pos );
    wxPoint tmp = m_Pos;
    wxPoint tmp = m_Pos;
@@ -229,6 +232,8 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
     *  transformation matrix causes xy axes to be flipped. */
     *  transformation matrix causes xy axes to be flipped. */
    int t1 = ( aTransformMatrix[0][0] != 0 ) ^ ( m_Orient != 0 );
    int t1 = ( aTransformMatrix[0][0] != 0 ) ^ ( m_Orient != 0 );


    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,
                     t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT,
                     m_Size, m_HJustify, m_VJustify,
                     m_Size, m_HJustify, m_VJustify,
+132 −3
Original line number Original line Diff line number Diff line
@@ -6,15 +6,14 @@
#include "common.h"
#include "common.h"
#include "kicad_string.h"
#include "kicad_string.h"
#include "confirm.h"
#include "confirm.h"
#include "class_drawpanel.h"
#include "gr_basic.h"


#include "program.h"
#include "program.h"
#include "libcmp.h"
#include "libcmp.h"
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"


#include <wx/tokenzr.h>
#include <wx/txtstrm.h>



int SortItemsFct(const void* ref, const void* item)
int SortItemsFct(const void* ref, const void* item)
{
{
@@ -260,6 +259,136 @@ EDA_LibComponentStruct::~EDA_LibComponentStruct()
}
}




void EDA_LibComponentStruct::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
                                   const wxPoint& offset, int multi,
                                   int convert, int drawMode, int color,
                                   const int transformMatrix[2][2],
                                   bool showPinText, bool drawFields,
                                   bool onlySelected )
{
    wxString           fieldText;
    LibDrawField*      Field;
    LibEDA_BaseStruct* drawItem;
    BASE_SCREEN*       screen = panel->GetScreen();

    GRSetDrawMode( dc, drawMode );

    for( drawItem = m_Drawings; drawItem != NULL; drawItem = drawItem->Next() )
    {
        if( onlySelected && drawItem->m_Selected == 0 )
            continue;

        // Do not draw an item while moving (the cursor handler does that)
        if( drawItem->m_Flags & IS_MOVED )
            continue;

        /* Do not draw items not attached to the current part */
        if( multi && drawItem->m_Unit && ( drawItem->m_Unit != multi ) )
            continue;

        if( convert && drawItem->m_Convert && ( drawItem->m_Convert != convert ) )
            continue;


        if( drawItem->Type() == COMPONENT_PIN_DRAW_TYPE )
        {
            drawItem->Draw( panel, dc, offset, color, drawMode, &showPinText,
                            transformMatrix );
        }
        else
        {
            bool force_nofill =
                ( screen->m_IsPrinting
                  && drawItem->m_Fill == FILLED_WITH_BG_BODYCOLOR
                  && GetGRForceBlackPenState() );

            drawItem->Draw( panel, dc, offset, color, drawMode,
                            (void*) force_nofill, transformMatrix );
        }
    }

    if( drawFields )
    {
        /* The reference designator field is a special case for naming
         * convention.
         *
         * FIXME: This should be handled by the LibDrawField class.
         */
        if( m_UnitCount > 1 )
        {
#if defined(KICAD_GOST)
            fieldText.Printf( wxT( "%s?.%c" ), (const wxChar*) m_Prefix.m_Text,
                              multi + '1' - 1 );
#else
            fieldText.Printf( wxT( "%s?%c" ), (const wxChar*) m_Prefix.m_Text,
                              multi + 'A' - 1 );
#endif
        }
        else
        {
            fieldText = m_Prefix.m_Text + wxT( "?" );
        }

        m_Prefix.Draw( panel, dc, offset, color, drawMode, &fieldText,
                       transformMatrix );
        m_Name.Draw( panel, dc, offset, color, drawMode, NULL, transformMatrix );

        for( Field = m_Fields; Field != NULL; Field = Field->Next() )
        {
            Field->Draw( panel, dc, offset, color, drawMode, NULL,
                         transformMatrix );
        }
    }

    int len = panel->GetScreen()->Unscale( 3 );
    GRLine( &panel->m_ClipBox, dc, offset.x, offset.y - len, offset.x,
            offset.y + len, 0, color );
    GRLine( &panel->m_ClipBox, dc, offset.x - len, offset.y, offset.x + len,
            offset.y, 0, color );

    /* Enable this to draw the bounding box around the component to validate
     * the bounding box calculations. */
#if 0
    EDA_Rect bBox = LibEntry->GetBoundaryBox( Multi, convert );
    GRRect( &panel->m_ClipBox, dc, bBox.GetOrigin().x, bBox.GetOrigin().y,
            bBox.GetEnd().x, bBox.GetEnd().y, 0, LIGHTMAGENTA );
#endif
}


void EDA_LibComponentStruct::RemoveDrawItem( LibEDA_BaseStruct* item,
                                             WinEDA_DrawPanel* panel,
                                             wxDC* dc )
{
    wxASSERT( item != NULL );

    LibEDA_BaseStruct* prevItem = m_Drawings;

    if( dc != NULL )
        item->Draw( panel, dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
                        DefaultTransformMatrix );

    if( m_Drawings == item )
    {
        m_Drawings = item->Next();
        SAFE_DELETE( item );
        return;
    }

    while( prevItem )
    {
        if( prevItem->Next() == item )
        {
            prevItem->SetNext( item->Next() );
            SAFE_DELETE( item );
            break;
        }

        prevItem = prevItem->Next();
    }
}


/**
/**
 * Function Save
 * Function Save
 * writes the data structures for this object out to a FILE in "*.brd" format.
 * writes the data structures for this object out to a FILE in "*.brd" format.
+34 −0
Original line number Original line Diff line number Diff line
@@ -165,6 +165,40 @@ public:
     * @param aFields - a std::vector <LibDrawField> to import.
     * @param aFields - a std::vector <LibDrawField> to import.
     */
     */
    void SetFields( const std::vector <LibDrawField> aFields );
    void SetFields( const std::vector <LibDrawField> aFields );

    /**
     * Draw component.
     *
     * @param panel - Window to draw on.
     * @param dc - Device context to draw on.
     * @param offset - Position to component.
     * @param multi - Component unit if multiple parts per component.
     * @param convert - Component conversion (DeMorgan) if available.
     * @param drawMode - Device context drawing mode, see wxDC.
     * @param color - Color to draw component.
     * @param transformMatrix - Cooridinate adjustment settings.
     * @param showPinText - Show pin text if true.
     * @param drawFields - Draw field text if true otherwise just draw
     *                     body items.
     * @param onlySelected - Draws only the body items that are selected.
     *                       Used for block move redraws.
     */
    void Draw( WinEDA_DrawPanel* panel, wxDC* dc, const wxPoint& offset,
               int multi, int convert, int drawMode, int color = -1,
               const int transformMatrix[2][2] = DefaultTransformMatrix,
               bool showPinText = true, bool drawFields = true,
               bool onlySelected = false );

    /**
     * Remove draw item from list.
     *
     * @param item - Draw item to remove from list.
     * @param panel - Panel to remove part from.
     * @param dc - Device context to remove part from.
     */
    void RemoveDrawItem( LibEDA_BaseStruct* item,
                         WinEDA_DrawPanel* panel = NULL,
                         wxDC* dc = NULL );
};
};




+18 −14
Original line number Original line Diff line number Diff line
@@ -236,8 +236,7 @@ parameter <%c> is not valid" ),
 */
 */
int LibDrawField::GetPenSize()
int LibDrawField::GetPenSize()
{
{
    int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
    return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
    return pensize;
}
}




@@ -250,19 +249,23 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
                         void* aData, const int aTransformMatrix[2][2] )
                         void* aData, const int aTransformMatrix[2][2] )
{
{
    wxPoint  text_pos;
    wxPoint  text_pos;

    int      color;
    int     color     = aColor;
    int      linewidth = GetPenSize();
    int      linewidth = GetPenSize();
    linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );


    linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );


    if( aColor < 0 )               // Used normal color or selected color
    if( ( m_Attributs & TEXT_NO_VISIBLE ) && ( aColor < 0 ) )
    {
        color = g_InvisibleItemColor;
    }
    else if( ( m_Selected & IS_SELECTED ) && ( aColor < 0 ) )
    {
    {
        if( (m_Selected & IS_SELECTED) )
        color = g_ItemSelectetColor;
        color = g_ItemSelectetColor;
    }
    }
    else
    else
    {
        color = aColor;
        color = aColor;
    }


    if( color < 0 )
    if( color < 0 )
    {
    {
@@ -281,13 +284,14 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
            break;
            break;
        }
        }
    }
    }
    text_pos = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;


    text_pos = TransformCoordinate( aTransformMatrix, m_Pos ) + aOffset;
    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->GetData(),
    DrawGraphicText( aPanel, aDC, text_pos, (EDA_Colors) color, *text,
                     m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
                     m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
                     m_Size, m_HJustify, m_VJustify, linewidth, m_Italic, m_Bold );
                     m_Size, m_HJustify, m_VJustify, linewidth, m_Italic,
                     m_Bold );
}
}




Loading