Commit 6a4e8aa9 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Eeschema schematic item move code unification.

* Add get and set position methods to all schematic items.
* Encapsulate schematic item position members.
* Add swap data method to schematic items that lacked one.
* Remove global swap data function used by undo and redo functions.
* Unify as many schematic move methods as possible.
* Remove unnecessary place schematic item methods.
* All schematic items are now moved in the same event handler.
* Fixed bug in hierarchical sheet get menu item string method.
* Make no connect and junction items movable, fixes lp:804048
parent 341e3a50
Loading
Loading
Loading
Loading
+32 −9
Original line number Diff line number Diff line
/************************/
/*	sch_item_struct.cpp */
/************************/
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2006 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 Kicad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file sch_item_struct.cpp
 */

#include "fctsys.h"
#include "common.h"
@@ -52,12 +77,6 @@ SCH_ITEM::~SCH_ITEM()
}


/**
 * place the struct in m_drawList.
 * if it is a new item, it it also put in undo list
 * for an "old" item, saving it in undo list must be done before editing,
 * and not here!
 */
void SCH_ITEM::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC )
{
    SCH_SCREEN* screen = aFrame->GetScreen();
@@ -70,6 +89,10 @@ void SCH_ITEM::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC )
        aFrame->SetRepeatItem( this );
        aFrame->SaveCopyInUndoList( this, UR_NEW );
    }
    else
    {
        aFrame->SaveUndoItemInUndoList( this );
    }

    m_Flags = 0;
    screen->SetModify();
+28 −2
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file backanno.cpp
 * @brief Functions for backannotating footprint information.
@@ -64,11 +89,12 @@ bool SCH_EDIT_FRAME::ProcessStuffFile( FILE* aFile, bool aSetFieldAttributeToVis
                     * it is probably not yet initialized
                     */
                    if( fpfield->m_Text.IsEmpty()
                        && ( fpfield->m_Pos == component->m_Pos ) )
                      && ( fpfield->GetPosition() == component->GetPosition() ) )
                    {
                        fpfield->m_Orient = component->GetField( VALUE )->m_Orient;
                        fpfield->m_Pos    = component->GetField( VALUE )->m_Pos;
                        fpfield->SetPosition( component->GetField( VALUE )->GetPosition() );
                        fpfield->m_Size   = component->GetField( VALUE )->m_Size;

                        if( fpfield->m_Orient == 0 )
                            fpfield->m_Pos.y += 100;
                        else
+104 −3
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file bus-wire-junction.cpp
 * @brief Code for editing buses, wires, and junctions.
@@ -436,6 +461,60 @@ void SCH_EDIT_FRAME::DeleteCurrentSegment( wxDC* DC )
}


static void moveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
{
    SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
    SCH_ITEM* item = screen->GetCurItem();

    wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );

    // Erase the current item at its current position.
    if( aErase )
        item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );

    item->SetPosition( screen->GetCrossHairPosition() );

    // Draw the item item at it's new position.
    item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}


static void abortMoveItem( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{
    SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
    SCH_ITEM* item = screen->GetCurItem();
    SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) aPanel->GetParent();

    parent->SetRepeatItem( NULL );
    screen->SetCurItem( NULL );

    if( item == NULL )  /* no current item */
        return;

    if( item->IsNew() )
    {
        delete item;
        item = NULL;
    }
    else    // Move command on an existing text item, restore the values of the original.
    {
        SCH_ITEM* olditem = parent->GetUndoItem();
        screen->SetCurItem( item );

        wxCHECK_RET( olditem != NULL && item->Type() == olditem->Type(),
                     wxT( "Cannot restore undefined or bad last schematic item." ) );

        // Never delete existing item, because it can be referenced by an undo/redo command
        // Just restore its data

        item->SwapData( olditem );
        item->ClearFlags();
    }

    aPanel->Refresh();
}


/* Routine to create new connection struct.
 */
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
@@ -460,6 +539,29 @@ SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
}


void SCH_EDIT_FRAME::MoveItem( SCH_ITEM* aItem, wxDC* aDC )
{
    wxCHECK_RET( aItem != NULL, wxT( "Cannot move invalid schematic item" ) );

    m_itemToRepeat = NULL;

    if( !aItem->IsNew() )
        SetUndoItem( aItem );

    aItem->SetFlags( IS_MOVED );

    DrawPanel->CrossHairOff( aDC );
    GetScreen()->SetCrossHairPosition( aItem->GetPosition() );
    DrawPanel->MoveCursorToCrossHair();

    OnModify();
    DrawPanel->SetMouseCapture( moveItem, abortMoveItem );
    GetScreen()->SetCurItem( aItem );
    moveItem( DrawPanel, aDC, wxDefaultPosition, true );
    DrawPanel->CrossHairOn( aDC );
}


SCH_NO_CONNECT* SCH_EDIT_FRAME::AddNoConnect( wxDC* aDC, const wxPoint& aPosition )
{
    SCH_NO_CONNECT* NewNoConnect;
@@ -517,12 +619,12 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
    if( m_itemToRepeat->Type() == SCH_COMPONENT_T ) // If repeat component then put in move mode
    {
        wxPoint pos = GetScreen()->GetCrossHairPosition() -
            ( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos;
                      ( (SCH_COMPONENT*) m_itemToRepeat )->GetPosition();
        m_itemToRepeat->SetFlags( IS_NEW );
        ( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp();
        m_itemToRepeat->Move( pos );
        m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
        StartMovePart( (SCH_COMPONENT*) m_itemToRepeat, DC );
        MoveItem( m_itemToRepeat, DC );
        return;
    }

@@ -541,4 +643,3 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
        m_itemToRepeat->ClearFlags();
    }
}
+26 −73
Original line number Diff line number Diff line
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

/**
 * @file busentry.cpp
 * @brief Code to handle manipulation of bus entry objects.
@@ -16,55 +41,6 @@


static int     s_LastShape = '\\';
static wxPoint ItemInitialPosition;


static void ExitBusEntry( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
    /* Exit bus entry mode. */
    SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) Panel->GetScreen()->GetCurItem();

    if( BusEntry )
    {
        BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );

        if( BusEntry->IsNew() )
        {
            delete BusEntry;
            Panel->GetScreen()->SetCurItem( NULL );
        }
        else
        {
            BusEntry->m_Pos = ItemInitialPosition;
            BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
            BusEntry->m_Flags = 0;
        }
    }

    SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent();

    parent->SetRepeatItem( NULL );
}


static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
                             bool aErase )
{
    // Draws the bus entry while moving the cursor
    BASE_SCREEN*   screen   = aPanel->GetScreen();
    SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) screen->GetCurItem();

    if( BusEntry == NULL )
        return;

    /* Erase the last segment position. */
    if( aErase )
        BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );

    /* Redraw at the new position. */
    BusEntry->m_Pos = screen->GetCrossHairPosition();
    BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}


SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type )
@@ -79,30 +55,6 @@ SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type )
}


void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
{
    if( BusEntry == NULL )
        return;

    if( !BusEntry->IsNew() )    // not already in edit, save shape
        SetUndoItem( BusEntry );

    BusEntry->SetFlags( IS_MOVED );

    ItemInitialPosition = BusEntry->m_Pos;

    DrawPanel->CrossHairOff( DC );
    GetScreen()->SetCrossHairPosition( BusEntry->m_Pos );
    DrawPanel->MoveCursorToCrossHair();

    GetScreen()->SetCurItem( BusEntry );
    DrawPanel->m_mouseCaptureCallback = ShowWhileMoving;
    DrawPanel->m_endMouseCaptureCallback = ExitBusEntry;

    DrawPanel->CrossHairOn( DC );
}


/* set the shape of BusEntry (shape = / or \ )
 */
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape )
@@ -147,5 +99,6 @@ int SCH_EDIT_FRAME::GetBusEntryShape( SCH_BUS_ENTRY* BusEntry )

    if( BusEntry->m_Size.y < 0 )
        entry_shape = '/';

    return entry_shape;
}
+1 −1
Original line number Diff line number Diff line
@@ -669,7 +669,7 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_COMPONENT* aLibComp
    m_IsNew     = false;
    m_Flag      = 0;
    m_TimeStamp = aComponent->m_TimeStamp;
    m_CmpPos    = aComponent->m_Pos;
    m_CmpPos    = aComponent->GetPosition();
    m_SheetNum  = 0;

    if( aComponent->GetRef( &aSheetPath ).IsEmpty() )
Loading