Fix EESchema undo and abort move regressions.

* Component moves can now be undone do to incorrect virtual method declaration
  in schematic component object.
* Undoing a field move now redraws the undone field properly.
* Fix bug when after aborting a field move kept displaying context menu
  field items.
* Removed unused current field member variable and access methods from the
  schematic edit frame object.
* Update component move code to comply with coding policy.
This commit is contained in:
Wayne Stambaugh 2011-04-08 13:41:52 -04:00
parent 1016448c02
commit 053498d1a4
7 changed files with 101 additions and 124 deletions

View File

@ -1,5 +1,5 @@
/********************************/ /********************************/
/* Scehematic component edition */ /* Schematic component edition */
/********************************/ /********************************/
#include "fctsys.h" #include "fctsys.h"
@ -22,16 +22,15 @@
static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
{ {
wxPoint pos; wxPoint pos;
int fieldNdx;
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent(); SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
SCH_FIELD* currentField = frame->GetCurrentField(); SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem();
if( currentField == NULL ) if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) )
return; return;
SCH_COMPONENT* component = (SCH_COMPONENT*) currentField->GetParent(); SCH_COMPONENT* component = (SCH_COMPONENT*) currentField->GetParent();
fieldNdx = currentField->m_FieldId;
currentField->m_AddExtraText = frame->m_Multiflag; currentField->m_AddExtraText = frame->m_Multiflag;
@ -46,7 +45,7 @@ static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositi
// But here we want the relative position of the moved field // But here we want the relative position of the moved field
// and we know the actual position. // and we know the actual position.
// So we are using the inverse rotation/mirror transform. // So we are using the inverse rotation/mirror transform.
wxPoint pt( aPanel->GetScreen()->GetCrossHairPosition() - pos ); wxPoint pt( screen->GetCrossHairPosition() - pos );
TRANSFORM itrsfm = component->GetTransform().InverseTransform(); TRANSFORM itrsfm = component->GetTransform().InverseTransform();
currentField->m_Pos = pos + itrsfm.TransformCoordinate( pt ); currentField->m_Pos = pos + itrsfm.TransformCoordinate( pt );
@ -58,18 +57,19 @@ static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositi
static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC ) static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{ {
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent(); SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
SCH_FIELD* currentField = frame->GetCurrentField(); SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_FIELD* currentField = (SCH_FIELD*) screen->GetCurItem();
if( currentField ) if( currentField )
{ {
currentField->m_AddExtraText = frame->m_Multiflag; currentField->m_AddExtraText = frame->m_Multiflag;
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
currentField->ClearFlags( 0 ); currentField->ClearFlags();
currentField->m_Pos = frame->m_OldPos; currentField->m_Pos = frame->m_OldPos;
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
} }
frame->SetCurrentField( NULL ); screen->SetCurItem( NULL );
} }
@ -82,7 +82,7 @@ void SCH_EDIT_FRAME::MoveField( SCH_FIELD* aField, wxDC* aDC )
wxPoint pos, newpos; wxPoint pos, newpos;
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent(); SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
SetCurrentField( aField ); GetScreen()->SetCurItem( aField );
SetUndoItem( comp ); SetUndoItem( comp );
pos = comp->m_Pos; pos = comp->m_Pos;

View File

@ -24,12 +24,47 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, /**
bool aErase ); * Move a component.
static void ExitPlaceCmp( EDA_DRAW_PANEL* Panel, wxDC* DC ); */
static void moveComponent( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_COMPONENT* component = (SCH_COMPONENT*) screen->GetCurItem();
static TRANSFORM OldTransform; if( aErase )
static wxPoint OldPos; {
component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
}
component->Move( screen->GetCrossHairPosition() - component->m_Pos );
component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
}
/*
* Abort a place component command in progress.
*/
static void abortMoveComponent( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_COMPONENT* component = (SCH_COMPONENT*) screen->GetCurItem();
if( component->IsNew() )
{
SAFE_DELETE( component );
}
else
{
component->SwapData( (SCH_COMPONENT*) frame->GetUndoItem() );
component->ClearFlags();
}
aPanel->Refresh( true );
screen->SetCurItem( NULL );
}
wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
@ -75,11 +110,11 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
SCH_COMPONENT* Component = NULL; SCH_COMPONENT* Component = NULL;
CMP_LIBRARY* Library = NULL; CMP_LIBRARY* Library = NULL;
wxString Name, keys, msg; wxString Name, keys, msg;
bool AllowWildSeach = TRUE; bool AllowWildSeach = true;
static wxString lastCommponentName; static wxString lastCommponentName;
m_itemToRepeat = NULL; m_itemToRepeat = NULL;
DrawPanel->m_IgnoreMouseEvents = TRUE; DrawPanel->m_IgnoreMouseEvents = true;
if( !libname.IsEmpty() ) if( !libname.IsEmpty() )
{ {
@ -105,7 +140,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
if ( dlg.ShowModal() == wxID_CANCEL ) if ( dlg.ShowModal() == wxID_CANCEL )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
@ -123,7 +158,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
if( Name.IsEmpty() ) if( Name.IsEmpty() )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
@ -134,35 +169,35 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
if( Name.GetChar( 0 ) == '=' ) if( Name.GetChar( 0 ) == '=' )
{ {
AllowWildSeach = FALSE; AllowWildSeach = false;
keys = Name.AfterFirst( '=' ); keys = Name.AfterFirst( '=' );
Name = DataBaseGetName( this, keys, Name ); Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() ) if( Name.IsEmpty() )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
} }
else if( Name == wxT( "*" ) ) else if( Name == wxT( "*" ) )
{ {
AllowWildSeach = FALSE; AllowWildSeach = false;
if( GetNameOfPartToLoad( this, Library, Name ) == 0 ) if( GetNameOfPartToLoad( this, Library, Name ) == 0 )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
} }
else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) ) else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )
{ {
AllowWildSeach = FALSE; AllowWildSeach = false;
Name = DataBaseGetName( this, keys, Name ); Name = DataBaseGetName( this, keys, Name );
if( Name.IsEmpty() ) if( Name.IsEmpty() )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
@ -172,7 +207,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */ if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */
{ {
AllowWildSeach = FALSE; AllowWildSeach = false;
wxString wildname = wxChar( '*' ) + Name + wxChar( '*' ); wxString wildname = wxChar( '*' ) + Name + wxChar( '*' );
Name = wildname; Name = wildname;
Name = DataBaseGetName( this, keys, Name ); Name = DataBaseGetName( this, keys, Name );
@ -182,13 +217,13 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
if( Entry == NULL ) if( Entry == NULL )
{ {
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
return NULL; return NULL;
} }
} }
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
if( Entry == NULL ) if( Entry == NULL )
@ -200,7 +235,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
lastCommponentName = Name; lastCommponentName = Name;
AddHistoryComponentName( HistoryList, Name ); AddHistoryComponentName( HistoryList, Name );
DrawPanel->SetMouseCapture( ShowWhileMoving, ExitPlaceCmp ); DrawPanel->SetMouseCapture( moveComponent, abortMoveComponent );
Component = new SCH_COMPONENT( *Entry, GetSheet(), unit, convert, Component = new SCH_COMPONENT( *Entry, GetSheet(), unit, convert,
GetScreen()->GetCrossHairPosition(), true ); GetScreen()->GetCrossHairPosition(), true );
@ -218,27 +253,6 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
} }
/**
* Move a component.
*/
static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
{
wxPoint move_vector;
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_COMPONENT* Component = (SCH_COMPONENT*) screen->GetCurItem();
if( aErase )
{
Component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
}
move_vector = screen->GetCrossHairPosition() - Component->m_Pos;
Component->Move( move_vector );
Component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
}
/* /*
* Routine to rotate and mirror a component. * Routine to rotate and mirror a component.
* *
@ -309,33 +323,6 @@ void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )
} }
/*
* Abort a place component command in progress.
*/
static void ExitPlaceCmp( EDA_DRAW_PANEL* Panel, wxDC* DC )
{
SCH_SCREEN* screen = (SCH_SCREEN*) Panel->GetScreen();
SCH_COMPONENT* Component = (SCH_COMPONENT*) screen->GetCurItem();
if( Component->m_Flags & IS_NEW )
{
Component->m_Flags = 0;
SAFE_DELETE( Component );
}
else if( Component )
{
wxPoint move_vector = OldPos - Component->m_Pos;
Component->Move( move_vector );
Component->SetTransform( OldTransform );
Component->m_Flags = 0;
}
Panel->Refresh( true );
screen->SetCurItem( NULL );
}
/* /*
* Handle select part in multi-part component. * Handle select part in multi-part component.
*/ */
@ -446,25 +433,20 @@ void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC )
} }
void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC ) void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* aComponent, wxDC* aDC )
{ {
if( Component == NULL ) wxCHECK_RET( (aComponent != NULL) && (aComponent->Type() == SCH_COMPONENT_T),
return; wxT( "Cannot move invalid component. Bad Programmer!" ) );
if( Component->Type() != SCH_COMPONENT_T ) if( aComponent->GetFlags() == 0 )
return; SetUndoItem( aComponent );
if( Component->m_Flags == 0 ) DrawPanel->CrossHairOff( aDC );
SetUndoItem( Component ); GetScreen()->SetCrossHairPosition( aComponent->m_Pos );
DrawPanel->CrossHairOff( DC );
GetScreen()->SetCrossHairPosition( Component->m_Pos );
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
DrawPanel->SetMouseCapture( ShowWhileMoving, ExitPlaceCmp ); DrawPanel->SetMouseCapture( moveComponent, abortMoveComponent );
GetScreen()->SetCurItem( Component ); GetScreen()->SetCurItem( aComponent );
OldPos = Component->m_Pos;
OldTransform = Component->GetTransform();
#if 1 #if 1
@ -473,21 +455,21 @@ void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC )
// RefreshDrawingRect(), then by drawing the first time in xor mode so that // RefreshDrawingRect(), then by drawing the first time in xor mode so that
// subsequent xor drawing modes will fully erase this first copy. // subsequent xor drawing modes will fully erase this first copy.
Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only aComponent->SetFlags( IS_MOVED ); // omit redrawing the component, erase only
DrawPanel->RefreshDrawingRect( Component->GetBoundingBox() ); DrawPanel->RefreshDrawingRect( aComponent->GetBoundingBox() );
Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); aComponent->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
#else #else
Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); aComponent->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
Component->m_Flags |= IS_MOVED; aComponent->SetFlags( IS_MOVED );
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, FALSE ); moveComponent( DrawPanel, aDC, false );
#endif #endif
DrawPanel->m_AutoPAN_Request = TRUE; DrawPanel->m_AutoPAN_Request = true;
DrawPanel->CrossHairOn( DC ); DrawPanel->CrossHairOn( aDC );
} }

View File

@ -554,24 +554,29 @@ LIB_PIN* SCH_COMPONENT::GetPin( const wxString& number )
} }
void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem ) void SCH_COMPONENT::SwapData( SCH_ITEM* aItem )
{ {
EXCHG( m_ChipName, copyitem->m_ChipName ); wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_COMPONENT_T),
EXCHG( m_Pos, copyitem->m_Pos ); wxT( "Cannot swap data with invalid component." ) );
EXCHG( m_unit, copyitem->m_unit );
EXCHG( m_convert, copyitem->m_convert ); SCH_COMPONENT* component = (SCH_COMPONENT*) aItem;
EXCHG( m_ChipName, component->m_ChipName );
EXCHG( m_Pos, component->m_Pos );
EXCHG( m_unit, component->m_unit );
EXCHG( m_convert, component->m_convert );
TRANSFORM tmp = m_transform; TRANSFORM tmp = m_transform;
m_transform = copyitem->m_transform; m_transform = component->m_transform;
copyitem->m_transform = tmp; component->m_transform = tmp;
m_Fields.swap( copyitem->m_Fields ); // std::vector's swap() m_Fields.swap( component->m_Fields ); // std::vector's swap()
// Reparent items after copying data // Reparent items after copying data
// (after swap(), m_Parent member does not point to the right parent): // (after swap(), m_Parent member does not point to the right parent):
for( int ii = 0; ii < copyitem->GetFieldCount(); ++ii ) for( int ii = 0; ii < component->GetFieldCount(); ++ii )
{ {
copyitem->GetField( ii )->SetParent( copyitem ); component->GetField( ii )->SetParent( component );
} }
for( int ii = 0; ii < GetFieldCount(); ++ii ) for( int ii = 0; ii < GetFieldCount(); ++ii )
@ -579,7 +584,7 @@ void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem )
GetField( ii )->SetParent( this ); GetField( ii )->SetParent( this );
} }
EXCHG( m_PathsAndReferences, copyitem->m_PathsAndReferences ); EXCHG( m_PathsAndReferences, component->m_PathsAndReferences );
} }

View File

@ -254,7 +254,7 @@ public:
int Color, int Color,
bool DrawPinText ); bool DrawPinText );
void SwapData( SCH_COMPONENT* copyitem ); virtual void SwapData( SCH_ITEM* aItem );
void Place( SCH_EDIT_FRAME* frame, wxDC* DC ); void Place( SCH_EDIT_FRAME* frame, wxDC* DC );

View File

@ -391,7 +391,6 @@ void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
ClearFlags(); ClearFlags();
frame->GetScreen()->SetCurItem( NULL ); frame->GetScreen()->SetCurItem( NULL );
frame->OnModify(); frame->OnModify();
frame->SetCurrentField( NULL );
} }

View File

@ -160,7 +160,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
m_Draw_Axis = FALSE; // TRUE to show axis m_Draw_Axis = FALSE; // TRUE to show axis
m_Draw_Sheet_Ref = TRUE; // TRUE to show sheet references m_Draw_Sheet_Ref = TRUE; // TRUE to show sheet references
m_CurrentSheet = new SCH_SHEET_PATH(); m_CurrentSheet = new SCH_SHEET_PATH();
m_CurrentField = NULL;
m_Multiflag = 0; m_Multiflag = 0;
m_TextFieldSize = DEFAULT_SIZE_TEXT; m_TextFieldSize = DEFAULT_SIZE_TEXT;
m_LibeditFrame = NULL; // Component editor frame. m_LibeditFrame = NULL; // Component editor frame.
@ -368,6 +367,7 @@ void SCH_EDIT_FRAME::SaveUndoItemInUndoList( SCH_ITEM* aItem )
aItem->SwapData( m_undoItem ); aItem->SwapData( m_undoItem );
SaveCopyInUndoList( aItem, UR_CHANGED ); SaveCopyInUndoList( aItem, UR_CHANGED );
aItem->SwapData( m_undoItem ); aItem->SwapData( m_undoItem );
m_undoItem = NULL;
} }

View File

@ -75,7 +75,6 @@ protected:
private: private:
wxString m_DefaultSchematicFileName; wxString m_DefaultSchematicFileName;
SCH_FIELD* m_CurrentField;
int m_TextFieldSize; int m_TextFieldSize;
PARAM_CFG_ARRAY m_projectFileParams; PARAM_CFG_ARRAY m_projectFileParams;
PARAM_CFG_ARRAY m_configSettings; PARAM_CFG_ARRAY m_configSettings;
@ -183,14 +182,6 @@ public:
void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, void OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
EDA_ITEM* aItem = NULL ); EDA_ITEM* aItem = NULL );
SCH_FIELD* GetCurrentField() { return m_CurrentField; }
void SetCurrentField( SCH_FIELD* aCurrentField )
{
m_CurrentField = aCurrentField;
}
/** /**
* Function OnModify * Function OnModify
* Must be called after a schematic change * Must be called after a schematic change