Commit 609abb2f authored by Wayne Stambaugh's avatar Wayne Stambaugh

Complete Eeschema unified move code.

* Schematic fields now use unified move code.
* Move the unified move code into file schedit.cpp
* Remove old schematic field move code.
parent 7bbe2f78
......@@ -461,73 +461,6 @@ 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
{
SCH_ITEM* oldItem = parent->GetUndoItem();
SCH_ITEM* currentItem;
// Items that are children of other objects are undone by swapping the contents
// of the parent items.
if( item->Type() == SCH_SHEET_PIN_T )
{
currentItem = (SCH_ITEM*) item->GetParent();
}
else
{
currentItem = item;
}
screen->SetCurItem( currentItem );
wxCHECK_RET( oldItem != NULL && currentItem->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
currentItem->SwapData( oldItem );
currentItem->ClearFlags();
}
aPanel->Refresh();
}
/* Routine to create new connection struct.
*/
SCH_JUNCTION* SCH_EDIT_FRAME::AddJunction( wxDC* aDC, const wxPoint& aPosition,
......@@ -552,37 +485,6 @@ 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() )
{
if( (aItem->Type() == SCH_SHEET_PIN_T) )
SetUndoItem( (SCH_ITEM*) aItem->GetParent() );
else
SetUndoItem( aItem );
}
aItem->SetFlags( IS_MOVED );
DrawPanel->CrossHairOff( aDC );
if( (aItem->Type() != SCH_SHEET_PIN_T) )
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;
......
......@@ -40,69 +40,6 @@
#include "sch_component.h"
/*
* Move standard text field. This routine is normally attached to the cursor.
*/
static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
{
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem();
if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) )
return;
if( aErase )
{
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
currentField->SetPosition( screen->GetCrossHairPosition() );
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_FIELD* currentField = (SCH_FIELD*) screen->GetCurItem();
if( currentField )
{
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
currentField->ClearFlags();
currentField->m_Pos = frame->m_OldPos;
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
}
screen->SetCurItem( NULL );
}
void SCH_EDIT_FRAME::MoveField( SCH_FIELD* aField, wxDC* aDC )
{
wxCHECK_RET( aField && (aField->Type() == SCH_FIELD_T) && !aField->GetText().IsEmpty(),
wxT( "Cannot move invalid component field." ) );
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
GetScreen()->SetCurItem( aField );
SetUndoItem( comp );
DrawPanel->CrossHairOff( aDC );
GetScreen()->SetCrossHairPosition( aField->GetPosition() );
DrawPanel->MoveCursorToCrossHair();
m_OldPos = aField->m_Pos;
DrawPanel->SetMouseCapture( moveField, abortMoveField );
aField->SetFlags( IS_MOVED );
DrawPanel->CrossHairOn( aDC );
}
void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC )
{
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
......
......@@ -493,8 +493,6 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
SCH_SCREEN* screen = GetScreen();
SCH_ITEM* item = screen->GetCurItem();
wxLogDebug( wxT( "Command member m_commandInt = %d." ), aEvent.GetInt() );
if( item == NULL )
{
// If we didn't get here by a hot key, then something has gone wrong.
......@@ -532,6 +530,7 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
case SCH_TEXT_T:
case SCH_COMPONENT_T:
case SCH_SHEET_PIN_T:
case SCH_FIELD_T:
MoveItem( item, &dc );
break;
......@@ -543,10 +542,6 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
StartMoveSheet( (SCH_SHEET*) item, &dc );
break;
case SCH_FIELD_T:
MoveField( (SCH_FIELD*) item, &dc );
break;
case SCH_MARKER_T:
default:
wxFAIL_MSG( wxString::Format( wxT( "Cannot move item type %s" ),
......@@ -721,3 +716,99 @@ bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
return false;
}
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
{
SCH_ITEM* oldItem = parent->GetUndoItem();
SCH_ITEM* currentItem;
// Items that are children of other objects are undone by swapping the contents
// of the parent items.
if( (item->Type() == SCH_SHEET_PIN_T) || (item->Type() == SCH_FIELD_T) )
{
currentItem = (SCH_ITEM*) item->GetParent();
}
else
{
currentItem = item;
}
wxCHECK_RET( oldItem != NULL && currentItem->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
currentItem->SwapData( oldItem );
item->ClearFlags();
}
aPanel->Refresh();
}
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() )
{
if( (aItem->Type() == SCH_SHEET_PIN_T) || (aItem->Type() == SCH_FIELD_T) )
SetUndoItem( (SCH_ITEM*) aItem->GetParent() );
else
SetUndoItem( aItem );
}
aItem->SetFlags( IS_MOVED );
DrawPanel->CrossHairOff( aDC );
if( aItem->Type() != SCH_SHEET_PIN_T )
GetScreen()->SetCrossHairPosition( aItem->GetPosition() );
DrawPanel->MoveCursorToCrossHair();
OnModify();
DrawPanel->SetMouseCapture( moveItem, abortMoveItem );
GetScreen()->SetCurItem( aItem );
moveItem( DrawPanel, aDC, wxDefaultPosition, true );
DrawPanel->CrossHairOn( aDC );
}
......@@ -836,7 +836,6 @@ private:
void ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC );
void SetInitCmp( SCH_COMPONENT* DrawComponent, wxDC* DC );
void MoveField( SCH_FIELD* aField, wxDC* aDC );
void EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC );
void RotateField( SCH_FIELD* aField, wxDC* aDC );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment