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:
parent
cb75b72978
commit
bf832dd941
|
@ -200,35 +200,12 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
|
|||
SaveCopyInUndoList( currentModule, UR_CHANGED );
|
||||
wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre();
|
||||
|
||||
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 blockCentre to zero
|
||||
origin = 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 );
|
||||
}
|
||||
|
|
|
@ -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_BASE( aParent ),
|
||||
m_parent( aParent ),
|
||||
m_translation( aParams.translation ),
|
||||
m_rotation( aParams.rotation ),
|
||||
m_origin( aParams.origin ),
|
||||
|
@ -283,8 +284,36 @@ void DIALOG_MOVE_EXACT::OnOkClick( wxCommandEvent& event )
|
|||
m_anchor = ANCHOR_FROM_LIBRARY;
|
||||
}
|
||||
|
||||
wxPoint move_vector, origin;
|
||||
// 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 )
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ class DIALOG_MOVE_EXACT : public DIALOG_MOVE_EXACT_BASE
|
|||
{
|
||||
private:
|
||||
|
||||
PCB_BASE_FRAME* m_parent;
|
||||
wxPoint& m_translation;
|
||||
double& m_rotation;
|
||||
MOVE_EXACT_ORIGIN& m_origin;
|
||||
|
|
|
@ -1581,35 +1581,12 @@ void PCB_EDIT_FRAME::moveExact()
|
|||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
break;
|
||||
}
|
||||
|
||||
wxPoint finalMoveVector = params.translation + origin - anchorPoint;
|
||||
wxPoint finalMoveVector = params.translation - anchorPoint;
|
||||
|
||||
item->Move( finalMoveVector );
|
||||
item->Rotate( item->GetPosition(), params.rotation );
|
||||
|
|
|
@ -852,35 +852,13 @@ void FOOTPRINT_EDIT_FRAME::moveExact()
|
|||
BOARD_ITEM* item = GetScreen()->GetCurItem();
|
||||
|
||||
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 );
|
||||
break;
|
||||
}
|
||||
|
||||
wxPoint finalMoveVector = params.translation + origin - anchorPoint;
|
||||
wxPoint finalMoveVector = params.translation - anchorPoint;
|
||||
|
||||
item->Move( finalMoveVector );
|
||||
item->Rotate( item->GetPosition(), params.rotation );
|
||||
|
|
|
@ -788,35 +788,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
|
|||
}
|
||||
}
|
||||
|
||||
wxPoint origin;
|
||||
|
||||
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;
|
||||
wxPoint finalMoveVector = params.translation - anchorPoint;
|
||||
|
||||
// Make sure the rotation is from the right reference point
|
||||
rotPoint += finalMoveVector;
|
||||
|
|
Loading…
Reference in New Issue