From 609abb2f0c1ec54a43f2a1bcdb64faaecae3109d Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 22 Oct 2011 08:31:44 -0400 Subject: [PATCH] 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. --- eeschema/bus-wire-junction.cpp | 98 --------------------- eeschema/edit_component_in_schematic.cpp | 63 -------------- eeschema/schedit.cpp | 103 +++++++++++++++++++++-- include/wxEeschemaStruct.h | 1 - 4 files changed, 97 insertions(+), 168 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 58eca8bafb..5515917bbe 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -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; diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp index bb4a560af0..e84c8f836a 100644 --- a/eeschema/edit_component_in_schematic.cpp +++ b/eeschema/edit_component_in_schematic.cpp @@ -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, diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 70ae3a5a7c..1f99a00725 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -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 ); +} diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 96a7082c07..4a322faadd 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -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 );