pcbnew - refactor move exactly tool (1/2)

This patch does the following:
* move the determination of the origin coordinates to the dialog (reduces code duplication)
This commit is contained in:
Robbert Lagerweij 2017-06-22 21:25:40 +02:00 committed by Maciej Suminski
parent cb75b72978
commit bf832dd941
6 changed files with 38 additions and 104 deletions

View File

@ -200,35 +200,12 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
SaveCopyInUndoList( currentModule, UR_CHANGED ); SaveCopyInUndoList( currentModule, UR_CHANGED );
wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre(); wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre();
wxPoint origin; if( params.origin == RELATIVE_TO_CURRENT_POSITION )
switch( params.origin )
{ {
case RELATIVE_TO_USER_ORIGIN:
origin = GetScreen()->m_O_Curseur;
break;
case RELATIVE_TO_GRID_ORIGIN:
origin = GetGridOrigin();
break;
case RELATIVE_TO_DRILL_PLACE_ORIGIN:
origin = GetAuxOrigin();
break;
case RELATIVE_TO_SHEET_ORIGIN:
origin = wxPoint( 0, 0 );
break;
case RELATIVE_TO_CURRENT_POSITION:
// relative movement means that only the translation values should be used:
// -> set origin and blockCentre to zero
origin = wxPoint( 0, 0 );
blockCentre = wxPoint( 0, 0 ); blockCentre = wxPoint( 0, 0 );
break;
} }
wxPoint finalMoveVector = params.translation + origin - blockCentre; wxPoint finalMoveVector = params.translation - blockCentre;
MoveMarkedItemsExactly( currentModule, blockCentre, finalMoveVector, params.rotation ); MoveMarkedItemsExactly( currentModule, blockCentre, finalMoveVector, params.rotation );
} }

View File

@ -37,6 +37,7 @@ DIALOG_MOVE_EXACT::MOVE_EXACT_OPTIONS DIALOG_MOVE_EXACT::m_options;
DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(PCB_BASE_FRAME *aParent, MOVE_PARAMETERS &aParams ) : DIALOG_MOVE_EXACT::DIALOG_MOVE_EXACT(PCB_BASE_FRAME *aParent, MOVE_PARAMETERS &aParams ) :
DIALOG_MOVE_EXACT_BASE( aParent ), DIALOG_MOVE_EXACT_BASE( aParent ),
m_parent( aParent ),
m_translation( aParams.translation ), m_translation( aParams.translation ),
m_rotation( aParams.rotation ), m_rotation( aParams.rotation ),
m_origin( aParams.origin ), m_origin( aParams.origin ),
@ -283,8 +284,36 @@ void DIALOG_MOVE_EXACT::OnOkClick( wxCommandEvent& event )
m_anchor = ANCHOR_FROM_LIBRARY; m_anchor = ANCHOR_FROM_LIBRARY;
} }
wxPoint move_vector, origin;
// for the output, we only deliver a Cartesian vector // for the output, we only deliver a Cartesian vector
bool ok = GetTranslationInIU( m_translation, m_polarCoords->IsChecked() ); bool ok = GetTranslationInIU( move_vector, m_polarCoords->IsChecked() );
switch( m_origin )
{
case RELATIVE_TO_USER_ORIGIN:
origin = m_parent->GetScreen()->m_O_Curseur;
break;
case RELATIVE_TO_GRID_ORIGIN:
origin = m_parent->GetGridOrigin();
break;
case RELATIVE_TO_DRILL_PLACE_ORIGIN:
origin = m_parent->GetAuxOrigin();
break;
case RELATIVE_TO_SHEET_ORIGIN:
origin = wxPoint( 0, 0 );
break;
case RELATIVE_TO_CURRENT_POSITION:
// relative movement means that only the translation values should be used:
// -> set origin and anchor to zero
origin = wxPoint( 0, 0 );
break;
}
m_translation = move_vector + origin;
if( ok ) if( ok )
{ {

View File

@ -63,6 +63,7 @@ class DIALOG_MOVE_EXACT : public DIALOG_MOVE_EXACT_BASE
{ {
private: private:
PCB_BASE_FRAME* m_parent;
wxPoint& m_translation; wxPoint& m_translation;
double& m_rotation; double& m_rotation;
MOVE_EXACT_ORIGIN& m_origin; MOVE_EXACT_ORIGIN& m_origin;

View File

@ -1581,35 +1581,12 @@ void PCB_EDIT_FRAME::moveExact()
} }
} }
wxPoint origin; if( params.origin == RELATIVE_TO_CURRENT_POSITION )
switch( params.origin )
{ {
case RELATIVE_TO_USER_ORIGIN:
origin = GetScreen()->m_O_Curseur;
break;
case RELATIVE_TO_GRID_ORIGIN:
origin = GetGridOrigin();
break;
case RELATIVE_TO_DRILL_PLACE_ORIGIN:
origin = GetAuxOrigin();
break;
case RELATIVE_TO_SHEET_ORIGIN:
origin = wxPoint( 0, 0 );
break;
case RELATIVE_TO_CURRENT_POSITION:
// relative movement means that only the translation values should be used:
// -> set origin and anchor to zero
origin = wxPoint( 0, 0 );
anchorPoint = wxPoint( 0, 0 ); anchorPoint = wxPoint( 0, 0 );
break;
} }
wxPoint finalMoveVector = params.translation + origin - anchorPoint; wxPoint finalMoveVector = params.translation - anchorPoint;
item->Move( finalMoveVector ); item->Move( finalMoveVector );
item->Rotate( item->GetPosition(), params.rotation ); item->Rotate( item->GetPosition(), params.rotation );

View File

@ -852,35 +852,13 @@ void FOOTPRINT_EDIT_FRAME::moveExact()
BOARD_ITEM* item = GetScreen()->GetCurItem(); BOARD_ITEM* item = GetScreen()->GetCurItem();
wxPoint anchorPoint = item->GetPosition(); wxPoint anchorPoint = item->GetPosition();
wxPoint origin;
switch( params.origin ) if( params.origin == RELATIVE_TO_CURRENT_POSITION )
{ {
case RELATIVE_TO_USER_ORIGIN:
origin = GetScreen()->m_O_Curseur;
break;
case RELATIVE_TO_GRID_ORIGIN:
origin = GetGridOrigin();
break;
case RELATIVE_TO_DRILL_PLACE_ORIGIN:
origin = GetAuxOrigin();
break;
case RELATIVE_TO_SHEET_ORIGIN:
origin = wxPoint( 0, 0 );
break;
case RELATIVE_TO_CURRENT_POSITION:
// relative movement means that only the translation values should be used:
// -> set origin and anchor to zero
origin = wxPoint( 0, 0 );
anchorPoint = wxPoint( 0, 0 ); anchorPoint = wxPoint( 0, 0 );
break;
} }
wxPoint finalMoveVector = params.translation + origin - anchorPoint; wxPoint finalMoveVector = params.translation - anchorPoint;
item->Move( finalMoveVector ); item->Move( finalMoveVector );
item->Rotate( item->GetPosition(), params.rotation ); item->Rotate( item->GetPosition(), params.rotation );

View File

@ -788,35 +788,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
} }
} }
wxPoint origin; wxPoint finalMoveVector = params.translation - anchorPoint;
switch( params.origin )
{
case RELATIVE_TO_USER_ORIGIN:
origin = editFrame->GetScreen()->m_O_Curseur;
break;
case RELATIVE_TO_GRID_ORIGIN:
origin = editFrame->GetGridOrigin();
break;
case RELATIVE_TO_DRILL_PLACE_ORIGIN:
origin = editFrame->GetAuxOrigin();
break;
case RELATIVE_TO_SHEET_ORIGIN:
origin = wxPoint( 0, 0 );
break;
case RELATIVE_TO_CURRENT_POSITION:
// relative movement means that only the translation values should be used:
// -> set origin and anchor to zero
origin = wxPoint( 0, 0 );
anchorPoint = wxPoint( 0, 0 );
break;
}
wxPoint finalMoveVector = params.translation + origin - anchorPoint;
// Make sure the rotation is from the right reference point // Make sure the rotation is from the right reference point
rotPoint += finalMoveVector; rotPoint += finalMoveVector;