Commit 7e1745da authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

EESchema block object select improvements and other minor fixes.

* Move schematic select block from global variable to SCH_EDIT_FRAME.
* Remove redundant schematic drawing code for eeredraw.cpp.
* Move block select code into SCH_SCREEN object.
* Simpilify block item select code.
* Fix bug in SCH_LINE selection state test.
* Add test to schematic objects for connectability.
* Make copy block items function a private method in SCH_EDIT_FRAME.
parent 1e2e1442
Loading
Loading
Loading
Loading
+49 −356
Original line number Original line Diff line number Diff line
@@ -8,7 +8,6 @@
#include "common.h"
#include "common.h"
#include "class_drawpanel.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "confirm.h"
#include "block_commande.h"
#include "wxEeschemaStruct.h"
#include "wxEeschemaStruct.h"
#include "class_sch_screen.h"
#include "class_sch_screen.h"


@@ -38,13 +37,7 @@ void DuplicateItemsInList( SCH_SCREEN* screen,
                                  PICKED_ITEMS_LIST& aItemsList,
                                  PICKED_ITEMS_LIST& aItemsList,
                                  const wxPoint      aMoveVector );
                                  const wxPoint      aMoveVector );


static void     CollectStructsToDrag( SCH_SCREEN* screen );
static void     AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition );
static LIB_PIN* GetNextPinPosition( SCH_COMPONENT* aComponent,
                                    wxPoint&       aPosition,
                                    LIB_PIN*       aPin );
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void     SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList );




/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
@@ -92,7 +85,7 @@ void SCH_EDIT_FRAME::InitBlockPasteInfos()
{
{
    BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
    BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;


    block->m_ItemsSelection.CopyList( g_BlockSaveDataList.m_ItemsSelection );
    block->m_ItemsSelection.CopyList( m_blockItems.m_ItemsSelection );
    DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
    DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
}
}


@@ -217,13 +210,16 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
    {
    {
        BlockState   state   = block->m_State;
        BlockState   state   = block->m_State;
        CmdBlockType command = block->m_Command;
        CmdBlockType command = block->m_Command;

        if( DrawPanel->ForceCloseManageCurseur )
        if( DrawPanel->ForceCloseManageCurseur )
            DrawPanel->ForceCloseManageCurseur( DrawPanel, DC );
            DrawPanel->ForceCloseManageCurseur( DrawPanel, DC );

        block->m_State   = state;
        block->m_State   = state;
        block->m_Command = command;
        block->m_Command = command;
        DrawPanel->ManageCurseur = DrawAndSizingBlockOutlines;
        DrawPanel->ManageCurseur = DrawAndSizingBlockOutlines;
        DrawPanel->ForceCloseManageCurseur = AbortBlockCurrentCommand;
        DrawPanel->ForceCloseManageCurseur = AbortBlockCurrentCommand;
        GetScreen()->m_Curseur = block->GetEnd();
        GetScreen()->m_Curseur = block->GetEnd();

        if( block->m_Command != BLOCK_ABORT )
        if( block->m_Command != BLOCK_ABORT )
            DrawPanel->MouseToCursorSchema();
            DrawPanel->MouseToCursorSchema();
    }
    }
@@ -250,7 +246,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
            if( block->GetCount() )
            if( block->GetCount() )
            {
            {
                nextcmd = true;
                nextcmd = true;
                CollectStructsToDrag( GetScreen() );
                GetScreen()->SelectBlockItems();
                DrawPanel->ManageCurseur( DrawPanel, DC, false );
                DrawPanel->ManageCurseur( DrawPanel, DC, false );
                DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
                DrawPanel->ManageCurseur = DrawMovingBlockOutlines;
                DrawPanel->ManageCurseur( DrawPanel, DC, false );
                DrawPanel->ManageCurseur( DrawPanel, DC, false );
@@ -267,11 +263,13 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
        case BLOCK_DELETE: /* Delete */
        case BLOCK_DELETE: /* Delete */
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
            DrawAndSizingBlockOutlines( DrawPanel, DC, false );
            DrawAndSizingBlockOutlines( DrawPanel, DC, false );

            if( block->GetCount() )
            if( block->GetCount() )
            {
            {
                DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
                DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
                OnModify();
                OnModify();
            }
            }

            block->ClearItemsList();
            block->ClearItemsList();
            TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
            TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
            DrawPanel->Refresh();
            DrawPanel->Refresh();
@@ -280,12 +278,14 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
        case BLOCK_SAVE:  /* Save */
        case BLOCK_SAVE:  /* Save */
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
            DrawAndSizingBlockOutlines( DrawPanel, DC, false );
            DrawAndSizingBlockOutlines( DrawPanel, DC, false );

            if( block->GetCount() )
            if( block->GetCount() )
            {
            {
                wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
                wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
                SaveStructListForPaste( block->m_ItemsSelection );
                copyBlockItems( block->m_ItemsSelection );
                MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector );
                MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector );
             }
             }

            block->ClearItemsList();
            block->ClearItemsList();
            break;
            break;


@@ -336,7 +336,7 @@ bool SCH_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
 *      and if the current command is block move.
 *      and if the current command is block move.
 * Execute a command other than block move from the current block move selected items list.
 * Execute a command other than block move from the current block move selected items list.
 * Due to (minor) problems in undo/redo or/and display block,
 * Due to (minor) problems in undo/redo or/and display block,
 * a mirror/rotate command is immediatly executed and multible block commands
 * a mirror/rotate command is immediately executed and multiple block commands
 * are not allowed (multiple commands are tricky to undo/redo in one time)
 * are not allowed (multiple commands are tricky to undo/redo in one time)
 */
 */
void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
@@ -350,6 +350,7 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
    // can convert only a block move command to an other command
    // can convert only a block move command to an other command
    if( block->m_Command != BLOCK_MOVE )
    if( block->m_Command != BLOCK_MOVE )
        return;
        return;

    // Useless if the new command is block move because we are already in block move.
    // Useless if the new command is block move because we are already in block move.
    if( Command == BLOCK_MOVE )
    if( Command == BLOCK_MOVE )
        return;
        return;
@@ -367,18 +368,22 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
    case BLOCK_DRAG:     /* move to Drag */
    case BLOCK_DRAG:     /* move to Drag */
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );

        // Clear list of items to move, and rebuild it with items to drag:
        // Clear list of items to move, and rebuild it with items to drag:
        block->ClearItemsList();
        block->ClearItemsList();


        BreakSegmentOnJunction( GetScreen() );
        BreakSegmentOnJunction( GetScreen() );


        PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
        PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );

        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
            blockCmdFinished = false;
            blockCmdFinished = false;
            CollectStructsToDrag( GetScreen() );
            GetScreen()->SelectBlockItems();

            if( DrawPanel->ManageCurseur )
            if( DrawPanel->ManageCurseur )
                DrawPanel->ManageCurseur( DrawPanel, DC, false );
                DrawPanel->ManageCurseur( DrawPanel, DC, false );

            block->m_State = STATE_BLOCK_MOVE;
            block->m_State = STATE_BLOCK_MOVE;
        }
        }
        break;
        break;
@@ -386,11 +391,13 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
    case BLOCK_DELETE:     /* move to Delete */
    case BLOCK_DELETE:     /* move to Delete */
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );

        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
            DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
            DeleteItemsInList( DrawPanel, block->m_ItemsSelection );
            OnModify();
            OnModify();
        }
        }

        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        DrawPanel->Refresh();
        DrawPanel->Refresh();
        break;
        break;
@@ -398,11 +405,12 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
    case BLOCK_SAVE:     /* Save list in paste buffer*/
    case BLOCK_SAVE:     /* Save list in paste buffer*/
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );

        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
            wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
            wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
            SaveStructListForPaste( block->m_ItemsSelection );
            copyBlockItems( block->m_ItemsSelection );
            MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector );
            MoveItemsInList( m_blockItems.m_ItemsSelection, move_vector );
        }
        }
        break;
        break;


@@ -418,7 +426,6 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
//            blockCmdFinished = true;
            /* Compute the rotation center and put it on grid */
            /* Compute the rotation center and put it on grid */
            wxPoint rotationPoint = block->Centre();
            wxPoint rotationPoint = block->Centre();
            PutOnGrid( &rotationPoint );
            PutOnGrid( &rotationPoint );
@@ -426,26 +433,23 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
            RotateListOfItems( block->m_ItemsSelection, rotationPoint );
            RotateListOfItems( block->m_ItemsSelection, rotationPoint );
            OnModify();
            OnModify();
        }
        }

        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        DrawPanel->Refresh();
        DrawPanel->Refresh();
//        block->m_State   = STATE_BLOCK_MOVE;
//        block->m_Command = BLOCK_MOVE; //allows multiple rotate
        break;
        break;


    case BLOCK_MIRROR_X:
    case BLOCK_MIRROR_X:
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );

        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
//            blockCmdFinished = true;
            /* Compute the mirror center and put it on grid */
            /* Compute the mirror center and put it on grid */
            wxPoint mirrorPoint = block->Centre();
            wxPoint mirrorPoint = block->Centre();
            PutOnGrid( &mirrorPoint );
            PutOnGrid( &mirrorPoint );
            SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_X, mirrorPoint );
            SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_X, mirrorPoint );
            Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint );
            Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint );
            OnModify();
            OnModify();
//            block->m_State   = STATE_BLOCK_MOVE;
//            block->m_Command = BLOCK_MOVE; //allows multiple mirrors
        }
        }
        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        DrawPanel->Refresh();
        DrawPanel->Refresh();
@@ -454,17 +458,15 @@ void SCH_EDIT_FRAME::HandleBlockEndByPopUp( int Command, wxDC* DC )
    case BLOCK_MIRROR_Y:
    case BLOCK_MIRROR_Y:
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, false );
            DrawPanel->ManageCurseur( DrawPanel, DC, false );

        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
//            blockCmdFinished = true;
            /* Compute the mirror center and put it on grid */
            /* Compute the mirror center and put it on grid */
            wxPoint mirrorPoint = block->Centre();
            wxPoint mirrorPoint = block->Centre();
            PutOnGrid( &mirrorPoint );
            PutOnGrid( &mirrorPoint );
            SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_Y, mirrorPoint );
            SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_Y, mirrorPoint );
            MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
            MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
            OnModify();
            OnModify();
//            block->m_State   = STATE_BLOCK_MOVE;
//            block->m_Command = BLOCK_MOVE; //allows multiple mirrors
        }
        }


        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
        TestDanglingEnds( GetScreen()->GetDrawItems(), DC );
@@ -506,7 +508,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool era
        for( unsigned ii = 0; ii < block->GetCount(); ii++ )
        for( unsigned ii = 0; ii < block->GetCount(); ii++ )
        {
        {
            schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
            schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
            DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector );
            schitem->Draw( panel, DC, block->m_MoveVector, g_XorMode, g_GhostColor );
        }
        }
    }
    }


@@ -518,27 +520,23 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool era
    for( unsigned ii = 0; ii < block->GetCount(); ii++ )
    for( unsigned ii = 0; ii < block->GetCount(); ii++ )
    {
    {
        schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
        schitem = (SCH_ITEM*) block->m_ItemsSelection.GetPickedItem( ii );
        DrawStructsInGhost( panel, DC, schitem, block->m_MoveVector );
        schitem->Draw( panel, DC, block->m_MoveVector, g_XorMode, g_GhostColor );
    }
    }
}
}




/* Routine to Save an object from global drawing object list.
void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList )
 *  This routine is the same as delete but:
 *  - the original list is NOT removed.
 *  - List is saved in g_BlockSaveDataList
 */
void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
{
{
    g_BlockSaveDataList.ClearListAndDeleteItems();   // delete previous saved list, if exists
    m_blockItems.ClearListAndDeleteItems();   // delete previous saved list, if exists


    /* save the new list: */
    /* save the new list: */
    ITEM_PICKER item;
    ITEM_PICKER item;


    // In list the wrapper is owner of the shematic item, we can use the UR_DELETED
    // In list the wrapper is owner of the schematic item, we can use the UR_DELETED
    // status for the picker because pickers with this status are owner of the picked item
    // status for the picker because pickers with this status are owner of the picked item
    // (or TODO ?: create a new status like UR_DUPLICATE)
    // (or TODO ?: create a new status like UR_DUPLICATE)
    item.m_UndoRedoStatus = UR_DELETED;
    item.m_UndoRedoStatus = UR_DELETED;

    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
    {
    {
        // Clear m_Flag member of selected items:
        // Clear m_Flag member of selected items:
@@ -547,20 +545,20 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
        SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
        SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
        DrawStructCopy->SetParent( NULL );
        DrawStructCopy->SetParent( NULL );
        item.m_PickedItem = DrawStructCopy;
        item.m_PickedItem = DrawStructCopy;
        g_BlockSaveDataList.PushItem( item );
        m_blockItems.PushItem( item );
    }
    }
}
}




/*****************************************************************************
/*****************************************************************************
* Routine to paste a structure from the g_BlockSaveDataList stack.
* Routine to paste a structure from the m_blockItems stack.
*   This routine is the same as undelete but original list is NOT removed.
*   This routine is the same as undelete but original list is NOT removed.
*****************************************************************************/
*****************************************************************************/
void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
{
{
    SCH_ITEM* Struct;
    SCH_ITEM* Struct;


    if( g_BlockSaveDataList.GetCount() == 0 )
    if( m_blockItems.GetCount() == 0 )
    {
    {
        DisplayError( this, wxT( "No struct to paste" ) );
        DisplayError( this, wxT( "No struct to paste" ) );
        return;
        return;
@@ -570,10 +568,10 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )


    // Creates data, and push it as new data in undo item list buffer
    // Creates data, and push it as new data in undo item list buffer
    ITEM_PICKER       picker( NULL, UR_NEW );
    ITEM_PICKER       picker( NULL, UR_NEW );
    for( unsigned ii = 0; ii < g_BlockSaveDataList.GetCount(); ii++ )

    for( unsigned ii = 0; ii < m_blockItems.GetCount(); ii++ )
    {
    {
        Struct = DuplicateStruct(
        Struct = DuplicateStruct( (SCH_ITEM*) m_blockItems.m_ItemsSelection.GetPickedItem( ii ) );
            (SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetPickedItem( ii ) );
        picker.m_PickedItem = Struct;
        picker.m_PickedItem = Struct;
        picklist.PushItem( picker );
        picklist.PushItem( picker );


@@ -584,7 +582,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
            ( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL );
            ( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL );
        }
        }
        SetaParent( Struct, GetScreen() );
        SetaParent( Struct, GetScreen() );
        RedrawOneStruct( DrawPanel, DC, Struct, GR_DEFAULT_DRAWMODE );
        Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        Struct->SetNext( GetScreen()->GetDrawItems() );
        Struct->SetNext( GetScreen()->GetDrawItems() );
        GetScreen()->SetDrawItems( Struct );
        GetScreen()->SetDrawItems( Struct );
    }
    }
@@ -600,308 +598,3 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )


    return;
    return;
}
}


/* Set in  m_BlockLocate.m_ItemsSelection items members .m_Flags to SELECTED
 * Creates the list of items found when a drag block is initiated.
 * items are those selected in window block an some items outside this area but
 * connected to a selected item (connected wires to a component or an entry )
 */
static void CollectStructsToDrag( SCH_SCREEN* screen )
{
    SCH_ITEM*          Struct;
    SCH_LINE*          SegmStruct;

    PICKED_ITEMS_LIST* pickedlist = &screen->m_BlockLocate.m_ItemsSelection;

    if( pickedlist->GetCount() == 0 )
        return;

    screen->ClearDrawingState();

    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
        Struct->m_Flags = SELECTED;
    }

    if( screen->m_BlockLocate.m_Command != BLOCK_DRAG )
        return;


    /* Remove the displacement of segment and undo the selection. */
    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
        if( Struct->Type() == SCH_LINE_T )
        {
            SegmStruct = (SCH_LINE*) Struct;
            if( !screen->m_BlockLocate.Contains( SegmStruct->m_Start ) )
                SegmStruct->m_Flags |= STARTPOINT;

            if( !screen->m_BlockLocate.Contains( SegmStruct->m_End ) )
                SegmStruct->m_Flags |= ENDPOINT;

            // Save m_Flags for Undo/redo drag operations:
            pickedlist->SetPickerFlags( SegmStruct->m_Flags, ii );
        }
    }

    /* Search for other items to drag. They are end wires connected to selected
     * items
     */
    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
        if( ( Struct->Type() == SCH_LABEL_T )
           || ( Struct->Type() == SCH_GLOBAL_LABEL_T )
           || ( Struct->Type() == SCH_HIERARCHICAL_LABEL_T ) )
        {
            #undef STRUCT
            #define STRUCT ( (SCH_TEXT*) Struct )
            if( !screen->m_BlockLocate.Contains( STRUCT->m_Pos ) )
            {
                AddPickedItem( screen, STRUCT->m_Pos );
            }
        }

        if( Struct->Type() == SCH_COMPONENT_T )
        {
            // Add all pins of the selected component to list
            wxPoint  pos;
            LIB_PIN* pin = GetNextPinPosition( (SCH_COMPONENT*) Struct, pos, NULL );
            while( pin )
            {
                if( !screen->m_BlockLocate.Contains( pos ) )
                {
                    // This pin is outside area,
                    // but because it is a pin of a selected component
                    // we must also select connected items to this pin
                    // and mainly wires
                    AddPickedItem( screen, pos );
                }

                pin = GetNextPinPosition( (SCH_COMPONENT*) Struct, pos, pin );
            }
        }

        if( Struct->Type() == SCH_SHEET_T )
        {
            SCH_SHEET* sheet = (SCH_SHEET*) Struct;

            // Add all pins sheets of a selected hierarchical sheet to the list
            BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() )
            {
                AddPickedItem( screen, label.m_Pos );
            }
        }

        if( Struct->Type() == SCH_BUS_ENTRY_T )
        {
            SCH_BUS_ENTRY* item = (SCH_BUS_ENTRY*) Struct;
            AddPickedItem( screen, item->m_Pos );
            AddPickedItem( screen, item->m_End() );
        }
    }
}


/** AddPickedItem
 * add to the picked list in screen->m_BlockLocate items found at location
 * position
 * @param screen = the screen to consider
 * @param position = the wxPoint where items must be located to be select
 */
static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
{
    SCH_ITEM* Struct;

    /* Review the list of already selected elements. */
    PICKED_ITEMS_LIST* pickedlist = &screen->m_BlockLocate.m_ItemsSelection;

    for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
    {
        Struct = (SCH_ITEM*) pickedlist->GetPickedItem( ii );

        switch( Struct->Type() )
        {
        case SCH_LINE_T:
                #undef STRUCT
                #define STRUCT ( (SCH_LINE*) Struct )
            if( STRUCT->m_Start == position )
                STRUCT->m_Flags &= ~STARTPOINT;

            if( STRUCT->m_End == position )
                STRUCT->m_Flags &= ~ENDPOINT;

            // Save m_Flags for Undo/redo drag operations:
            pickedlist->SetPickerFlags( STRUCT->m_Flags, ii );
            break;

        default:
            break;
        }
    }

    /* Review the list of elements not selected. */

    ITEM_PICKER picker;
    Struct = (SCH_ITEM*) screen->GetDrawItems();

    while( Struct )
    {
        picker.m_PickedItem     = Struct;
        picker.m_PickedItemType = Struct->Type();
        switch( Struct->Type() )
        {
        case TYPE_NOT_INIT:
            break;

        case SCH_POLYLINE_T:
            if( Struct->m_Flags & SELECTED )
                break;
            break;

        case SCH_JUNCTION_T:
                #undef STRUCT
                #define STRUCT ( (SCH_JUNCTION*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;
            if( STRUCT->m_Pos != position )
                break;
            pickedlist->PushItem( picker );
            break;

        case SCH_LINE_T:
                #undef STRUCT
                #define STRUCT ( (SCH_LINE*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;
            if( STRUCT->m_Start == position )
            {
                Struct->m_Flags  = SELECTED | ENDPOINT | STARTPOINT;
                Struct->m_Flags &= ~STARTPOINT;
                // Save m_Flags for Undo/redo drag operations:
                picker.m_PickerFlags = Struct->m_Flags;
                pickedlist->PushItem( picker );
            }
            else if( STRUCT->m_End == position )
            {
                Struct->m_Flags  = SELECTED | ENDPOINT | STARTPOINT;
                Struct->m_Flags &= ~ENDPOINT;
                // Save m_Flags for Undo/redo drag operations:
                picker.m_PickerFlags = Struct->m_Flags;
                pickedlist->PushItem( picker );
            }
            break;

        case SCH_BUS_ENTRY_T:
            break;

        case SCH_TEXT_T:
            break;

        case SCH_LABEL_T:
                #undef STRUCT
                #define STRUCT ( (SCH_LABEL*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;  /* Already in list */
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            pickedlist->PushItem( picker );
            break;

        case SCH_HIERARCHICAL_LABEL_T:
        case SCH_GLOBAL_LABEL_T:
                #undef STRUCT
                #define STRUCT ( (SCH_LABEL*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;  /* Already in list */
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            pickedlist->PushItem( picker );
            break;

        case SCH_COMPONENT_T:
        case SCH_SHEET_T:
        case SCH_SHEET_LABEL_T:
            break;

        case SCH_MARKER_T:
                #undef STRUCT
                #define STRUCT ( (SCH_MARKER*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;  /* Already in list */
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            pickedlist->PushItem( picker );
            break;

        case SCH_NO_CONNECT_T:
                #undef STRUCT
                #define STRUCT ( (SCH_NO_CONNECT*) Struct )
            if( Struct->m_Flags & SELECTED )
                break;  /* Already in list */
            if( STRUCT->m_Pos != position )
                break;
            Struct->m_Flags |= SELECTED;
            pickedlist->PushItem( picker );
            break;

        default:
            break;
        }
        Struct = Struct->Next();
    }
}


/**
 * Function GetNextPinPosition()
 * calculate position of the "next" pin of the aDrawLibItem component
 * @param aComponent = component to test.
 * @param aPosition = the actual next pin position in schematic, according to the component
 * orientation and position
 * @param aPin = search for the next pin after aPin. aPin = NULL to find the first pin in list
 * @return a pointer to the next pin found or NULL
 */
static LIB_PIN* GetNextPinPosition( SCH_COMPONENT* aComponent,
                                    wxPoint&       aPosition,
                                    LIB_PIN*       aPin )
{
    static LIB_COMPONENT* Entry;

    if( aPin == NULL )
    {
        Entry = CMP_LIBRARY::FindLibraryComponent( aComponent->GetLibName() );

        if( Entry == NULL )
            return NULL;
    }

    aPin = Entry->GetNextPin( aPin );

    int multi       = aComponent->GetUnit();
    int convert     = aComponent->GetConvert();
    for( ; aPin != NULL; aPin = Entry->GetNextPin( aPin ) )
    {
        wxASSERT( aPin->Type() == LIB_PIN_T );

        /* Skip items not used for this part */
        if( multi && aPin->GetUnit() && ( aPin->GetUnit() != multi ) )
            continue;

        if( convert && aPin->GetConvert() && ( aPin->GetConvert() != convert ) )
            continue;

        /* Calculate the pin position (according to the component orientation)
         */
        aPosition = aComponent->GetPinPhysicalPosition( aPin );
        return aPin;
    }

    return NULL;
}
+3 −153

File changed.

Preview size limit exceeded, changes collapsed.

+0 −4
Original line number Original line Diff line number Diff line
@@ -37,10 +37,6 @@ SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item
                                 * before it is modified (used for undo
                                 * before it is modified (used for undo
                                 * managing to restore old values ) */
                                 * managing to restore old values ) */


/* Block operation (copy, paste) */
BLOCK_SELECTOR           g_BlockSaveDataList;   // List of items to paste
                                                // (Created by Block Save)

bool                     g_HVLines = true;      // Bool: force H or V
bool                     g_HVLines = true;      // Bool: force H or V
                                                // directions (Wires, Bus ..)
                                                // directions (Wires, Bus ..)


+0 −4
Original line number Original line Diff line number Diff line
@@ -142,10 +142,6 @@ extern SCH_ITEM* g_ItemToUndoCopy; /* copy of last modified schematic item
                                         * before it is modified (used for undo
                                         * before it is modified (used for undo
                                         * managing to restore old values ) */
                                         * managing to restore old values ) */


/* Block operation (copy, paste) */
extern BLOCK_SELECTOR g_BlockSaveDataList; /* List of items to paste (Created
                                            * by Block Save) */

// Management options.
// Management options.
extern bool      g_HVLines;
extern bool      g_HVLines;


+11 −13
Original line number Original line Diff line number Diff line
@@ -212,8 +212,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
    // Set the component value that can differ from component name in lib, for aliases
    // Set the component value that can differ from component name in lib, for aliases
    Component->GetField( VALUE )->m_Text = Name;
    Component->GetField( VALUE )->m_Text = Name;
    Component->DisplayInfo( this );
    Component->DisplayInfo( this );

    Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    DrawStructsInGhost( DrawPanel, DC, Component, wxPoint( 0, 0 ) );


    return Component;
    return Component;
}
}
@@ -232,13 +231,12 @@ static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )


    if( erase )
    if( erase )
    {
    {
        DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) );
        Component->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    }
    }


    move_vector = screen->m_Curseur - Component->m_Pos;
    move_vector = screen->m_Curseur - Component->m_Pos;
    Component->Move( move_vector );
    Component->Move( move_vector );

    Component->Draw( panel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    DrawStructsInGhost( panel, DC, Component, wxPoint(0,0) );
}
}




@@ -258,7 +256,7 @@ void SCH_EDIT_FRAME::CmpRotationMiroir( SCH_COMPONENT* DrawComponent, wxDC* DC,
        DrawPanel->CursorOff( DC );
        DrawPanel->CursorOff( DC );


        if( DrawComponent->m_Flags )
        if( DrawComponent->m_Flags )
            DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
        else
        else
        {
        {
            DrawPanel->PostDirtyRect( DrawComponent->GetBoundingBox() );
            DrawPanel->PostDirtyRect( DrawComponent->GetBoundingBox() );
@@ -271,7 +269,7 @@ void SCH_EDIT_FRAME::CmpRotationMiroir( SCH_COMPONENT* DrawComponent, wxDC* DC,
    if( DC )
    if( DC )
    {
    {
        if( DrawComponent->m_Flags )
        if( DrawComponent->m_Flags )
            DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
        else
        else
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        DrawPanel->CursorOn( DC );
        DrawPanel->CursorOn( DC );
@@ -342,7 +340,7 @@ void SCH_EDIT_FRAME::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC*
        unit = m_UnitCount;
        unit = m_UnitCount;


    if( DrawComponent->m_Flags )
    if( DrawComponent->m_Flags )
        DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
    else
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );


@@ -352,7 +350,7 @@ void SCH_EDIT_FRAME::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC*


    /* Redraw the component in the new position. */
    /* Redraw the component in the new position. */
    if( DrawComponent->m_Flags )
    if( DrawComponent->m_Flags )
        DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
    else
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );


@@ -380,7 +378,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC )
    }
    }


    if( DrawComponent->m_Flags )
    if( DrawComponent->m_Flags )
        DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
    else
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );


@@ -397,7 +395,7 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC )


    /* Redraw the component in the new position. */
    /* Redraw the component in the new position. */
    if( DrawComponent->m_Flags & IS_MOVED )
    if( DrawComponent->m_Flags & IS_MOVED )
        DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
    else
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );


@@ -444,11 +442,11 @@ void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC )
    Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only
    Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only
    DrawPanel->PostDirtyRect( Component->GetBoundingBox() );
    DrawPanel->PostDirtyRect( Component->GetBoundingBox() );


    DrawStructsInGhost( DrawPanel, DC, Component, wxPoint(0,0) );
    Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );


#else
#else


    RedrawOneStruct( DrawPanel, DC, Component, g_XorMode );
    Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );


    Component->m_Flags |= IS_MOVED;
    Component->m_Flags |= IS_MOVED;


Loading