Simplify Move Exactly and Postion Relative dialogs.

Also removes g_UserUnit references.

Fixes: lp:1660154
* https://bugs.launchpad.net/kicad/+bug/1660154

(cherry picked from commit 1639636)
This commit is contained in:
Jeff Young 2018-06-12 08:36:35 +01:00
parent 5ce0f8ba54
commit 2ff414adb4
18 changed files with 1673 additions and 2781 deletions

View File

@ -237,6 +237,12 @@ bool UNIT_BINDER::IsIndeterminate() const
} }
void UNIT_BINDER::SetLabel( const wxString& aLabel )
{
m_label->SetLabel( aLabel );
}
void UNIT_BINDER::Enable( bool aEnable ) void UNIT_BINDER::Enable( bool aEnable )
{ {
m_label->Enable( aEnable ); m_label->Enable( aEnable );

View File

@ -97,6 +97,8 @@ public:
*/ */
virtual bool Validate( bool setFocusOnError = false ); virtual bool Validate( bool setFocusOnError = false );
void SetLabel( const wxString& aLabel );
/** /**
* Function Enable * Function Enable
* Enables/diasables the label, widget and units label. * Enables/diasables the label, widget and units label.

View File

@ -187,26 +187,29 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
if( itemsCount ) if( itemsCount )
{ {
MOVE_PARAMETERS params; wxPoint translation;
params.allowOverride = false; double rotation;
ROTATION_ANCHOR rotationAnchor = ROTATE_AROUND_SEL_CENTER;
DIALOG_MOVE_EXACT dialog( this, params ); DIALOG_MOVE_EXACT dialog( this, translation, rotation, rotationAnchor );
int ret = dialog.ShowModal(); if( dialog.ShowModal() == wxID_OK )
if( ret == wxID_OK )
{ {
SaveCopyInUndoList( currentModule, UR_CHANGED ); SaveCopyInUndoList( currentModule, UR_CHANGED );
wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre(); wxPoint blockCentre = GetScreen()->m_BlockLocate.Centre();
blockCentre += translation;
if( params.origin == RELATIVE_TO_CURRENT_POSITION ) switch( rotationAnchor )
{ {
blockCentre = wxPoint( 0, 0 ); case ROTATE_AROUND_SEL_CENTER:
MoveMarkedItemsExactly( currentModule, blockCentre, translation, rotation );
break;
case ROTATE_AROUND_USER_ORIGIN:
MoveMarkedItemsExactly( currentModule, GetScreen()->m_O_Curseur, translation, rotation );
break;
default:
wxFAIL_MSG( "Rotation choice shouldn't have been available in this context." );
} }
wxPoint finalMoveVector = params.translation - blockCentre;
MoveMarkedItemsExactly( currentModule, blockCentre, finalMoveVector, params.rotation );
} }
} }
break; break;

View File

@ -23,11 +23,6 @@
*/ */
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <base_units.h>
#include <macros.h>
#include <footprint_edit_frame.h>
#include <widgets/text_ctrl_eval.h>
#include "dialog_move_exact.h" #include "dialog_move_exact.h"
@ -35,110 +30,76 @@
DIALOG_MOVE_EXACT::MOVE_EXACT_OPTIONS DIALOG_MOVE_EXACT::m_options; 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, wxPoint& aTranslate,
double& aRotate, ROTATION_ANCHOR& aAnchor ) :
DIALOG_MOVE_EXACT_BASE( aParent ), DIALOG_MOVE_EXACT_BASE( aParent ),
m_parent( aParent ), m_translation( aTranslate ),
m_translation( aParams.translation ), m_rotation( aRotate ),
m_rotation( aParams.rotation ), m_rotationAnchor( aAnchor ),
m_origin( aParams.origin ), m_moveX( aParent, m_xLabel, m_xEntry, m_xUnit ),
m_anchor( aParams.anchor ), m_moveY( aParent, m_yLabel, m_yEntry, m_yUnit ),
m_allowOverride( aParams.allowOverride ), m_rotate( aParent, m_rotLabel, m_rotEntry, m_rotUnit )
m_editingFootprint( aParams.editingFootprint )
{ {
// set the unit labels
m_xUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
// tabbing goes through the entries in sequence // tabbing goes through the entries in sequence
m_yEntry->MoveAfterInTabOrder( m_xEntry ); m_yEntry->MoveAfterInTabOrder( m_xEntry );
m_rotEntry->MoveAfterInTabOrder( m_yEntry ); m_rotEntry->MoveAfterInTabOrder( m_yEntry );
updateDialogControls( m_options.polarCoords );
m_menuIDs.push_back( aAnchor );
m_menuIDs.push_back( ROTATE_AROUND_USER_ORIGIN );
if( aParent->IsType( FRAME_PCB ) )
m_menuIDs.push_back( ROTATE_AROUND_AUX_ORIGIN );
buildRotationAnchorMenu();
// and set up the entries according to the saved options // and set up the entries according to the saved options
m_polarCoords->SetValue( m_options.polarCoords ); m_polarCoords->SetValue( m_options.polarCoords );
m_xEntry->SetValue( wxString::FromDouble( m_options.entry1 ) ); m_moveX.SetValue( m_options.entry1 );
m_yEntry->SetValue( wxString::FromDouble( m_options.entry2 ) ); m_moveY.SetValue( m_options.entry2 );
m_rotEntry->SetValue( wxString::FromDouble( m_options.entryRotation ) );
m_originChooser->SetSelection( m_options.origin );
if( m_allowOverride ) m_rotate.SetUnits( DEGREES );
{ m_rotate.SetValue( m_options.entryRotation );
m_cbOverride->SetValue( m_options.overrideAnchor ); m_anchorOptions->SetSelection( std::min( m_options.entryAnchorSelection, m_menuIDs.size() ) );
m_anchorChoice->Enable( m_options.overrideAnchor );
// ME_ANCHOR_FROM_LIBRARY is not in the wxChoice options so show the first choice instead
if( m_options.anchor == ANCHOR_FROM_LIBRARY )
{
m_anchorChoice->SetSelection( ANCHOR_TOP_LEFT_PAD );
}
else
{
m_anchorChoice->SetSelection( m_options.anchor );
}
if( m_options.origin == RELATIVE_TO_CURRENT_POSITION )
{
// no footprint override necessary in this mode
m_cbOverride->Disable();
m_anchorChoice->Disable();
}
if( m_editingFootprint )
{
// there is no point in showing the center footprint option when editing footprints
m_anchorChoice->Delete( ANCHOR_CENTER_FOOTPRINT );
}
}
else
{
// hide the checkbox and choice control if overides are not allowed
bMainSizer->Hide( bAnchorSizer, true );
}
if( wxPoint( 0, 0 ) == aParent->GetScreen()->m_O_Curseur )
{
// disble the user origin option when the user oigin is not set
m_originChooser->Enable( RELATIVE_TO_USER_ORIGIN, false );
m_originChooser->SetItemToolTip( RELATIVE_TO_USER_ORIGIN,
wxString( "The user origin is currently not set\n"
"Set it by using the <space> hotkey" ) );
}
if( wxPoint( 0, 0 ) == aParent->GetGridOrigin() )
{
// disble the grid origin option when the user oigin is not set
m_originChooser->Enable( RELATIVE_TO_GRID_ORIGIN, false );
m_originChooser->SetItemToolTip( RELATIVE_TO_GRID_ORIGIN,
wxString( "The grid origin is currently not set\n"
"Set it by using the tool in the <place> menu" ) );
}
if( wxPoint( 0, 0 ) == aParent->GetAuxOrigin() )
{
// disble the grid origin option when the drill/place oigin is not set
m_originChooser->Enable( RELATIVE_TO_DRILL_PLACE_ORIGIN, false );
m_originChooser->SetItemToolTip( RELATIVE_TO_DRILL_PLACE_ORIGIN,
wxString( "The drill/place origin is currently not set\n"
"Set it by using the tool in the <place> menu" ) );
}
updateDlgTexts( m_polarCoords->IsChecked() );
m_stdButtonsOK->SetDefault(); m_stdButtonsOK->SetDefault();
GetSizer()->SetSizeHints( this ); FinishDialogSettings();
Layout();
} }
DIALOG_MOVE_EXACT::~DIALOG_MOVE_EXACT() void DIALOG_MOVE_EXACT::buildRotationAnchorMenu()
{ {
wxArrayString menuItems;
for( auto anchorID : m_menuIDs )
{
switch( anchorID )
{
case ROTATE_AROUND_ITEM_ANCHOR:
menuItems.push_back( _( "Rotate around item anchor" ) );
break;
case ROTATE_AROUND_SEL_CENTER:
menuItems.push_back( _( "Rotate around selection center" ) );
break;
case ROTATE_AROUND_USER_ORIGIN:
menuItems.push_back( _( "Rotate around user origin" ) );
break;
case ROTATE_AROUND_AUX_ORIGIN:
menuItems.push_back( _( "Rotate around drill/place origin" ) );
break;
}
}
m_anchorOptions->Set( menuItems );
} }
void DIALOG_MOVE_EXACT::ToPolarDeg( double x, double y, double& r, double& q ) void DIALOG_MOVE_EXACT::ToPolarDeg( double x, double y, double& r, double& q )
{ {
// convert to polar coordinates // convert to polar coordinates
r = hypot ( x, y ); r = hypot( x, y );
q = ( r != 0) ? RAD2DEG( atan2( y, x ) ) : 0; q = ( r != 0) ? RAD2DEG( atan2( y, x ) ) : 0;
} }
@ -148,8 +109,8 @@ bool DIALOG_MOVE_EXACT::GetTranslationInIU ( wxPoint& val, bool polar )
{ {
if( polar ) if( polar )
{ {
const int r = ValueFromTextCtrl( *m_xEntry ); const int r = m_moveX.GetValue();
const double q = DoubleValueFromString( DEGREES, m_yEntry->GetValue() ); const double q = m_moveY.GetValue();
val.x = r * cos( DEG2RAD( q / 10.0 ) ); val.x = r * cos( DEG2RAD( q / 10.0 ) );
val.y = r * sin( DEG2RAD( q / 10.0 ) ); val.y = r * sin( DEG2RAD( q / 10.0 ) );
@ -157,8 +118,8 @@ bool DIALOG_MOVE_EXACT::GetTranslationInIU ( wxPoint& val, bool polar )
else else
{ {
// direct read // direct read
val.x = ValueFromTextCtrl( *m_xEntry ); val.x = m_moveX.GetValue();
val.y = ValueFromTextCtrl( *m_yEntry ); val.y = m_moveY.GetValue();
} }
// no validation to do here, but in future, you could return false here // no validation to do here, but in future, you could return false here
@ -169,20 +130,22 @@ bool DIALOG_MOVE_EXACT::GetTranslationInIU ( wxPoint& val, bool polar )
void DIALOG_MOVE_EXACT::OnPolarChanged( wxCommandEvent& event ) void DIALOG_MOVE_EXACT::OnPolarChanged( wxCommandEvent& event )
{ {
bool newPolar = m_polarCoords->IsChecked(); bool newPolar = m_polarCoords->IsChecked();
updateDlgTexts( newPolar );
wxPoint val; wxPoint val;
// get the value as previously stored // get the value as previously stored
GetTranslationInIU( val, !newPolar ); GetTranslationInIU( val, !newPolar );
// now switch the controls to the new representations
updateDialogControls( newPolar );
if( newPolar ) if( newPolar )
{ {
// convert to polar coordinates // convert to polar coordinates
double r, q; double r, q;
ToPolarDeg( val.x, val.y, r, q ); ToPolarDeg( val.x, val.y, r, q );
PutValueInLocalUnits( *m_xEntry, KiROUND( r / 10.0) * 10 ); m_moveX.SetValue( KiROUND( r / 10.0) * 10 );
m_yEntry->SetValue( wxString::FromDouble( q ) ); m_moveY.SetValue( q * 10 );
} }
else else
{ {
@ -190,84 +153,49 @@ void DIALOG_MOVE_EXACT::OnPolarChanged( wxCommandEvent& event )
// note - round off the last decimal place (10nm) to prevent // note - round off the last decimal place (10nm) to prevent
// (some) rounding causing errors when round-tripping // (some) rounding causing errors when round-tripping
// you can never eliminate entirely, however // you can never eliminate entirely, however
PutValueInLocalUnits( *m_xEntry, KiROUND( val.x / 10.0 ) * 10 ); m_moveX.SetValue( KiROUND( val.x / 10.0 ) * 10 );
PutValueInLocalUnits( *m_yEntry, KiROUND( val.y / 10.0 ) * 10 ); m_moveY.SetValue( KiROUND( val.y / 10.0 ) * 10 );
} }
Layout();
} }
void DIALOG_MOVE_EXACT::OnOriginChanged( wxCommandEvent& event ) void DIALOG_MOVE_EXACT::updateDialogControls( bool aPolar )
{
if( m_originChooser->GetSelection() == RELATIVE_TO_CURRENT_POSITION )
{
//no need to override the achor in this mode since the reference in the current position
m_cbOverride->Disable();
m_anchorChoice->Disable();
}
else if( m_allowOverride )
{
m_cbOverride->Enable();
if( m_cbOverride->IsChecked() )
m_anchorChoice->Enable();
}
}
void DIALOG_MOVE_EXACT::OnOverrideChanged( wxCommandEvent& event )
{
if( m_cbOverride->IsChecked() )
{
m_anchorChoice->Enable();
}
else
{
m_anchorChoice->Disable();
}
}
void DIALOG_MOVE_EXACT::updateDlgTexts( bool aPolar )
{ {
if( aPolar ) if( aPolar )
{ {
m_xLabel->SetLabelText( _( "Distance:" ) ); // Polar radius m_moveX.SetLabel( _( "Distance:" ) ); // Polar radius
m_yLabel->SetLabelText( _( "Angle:" ) ); // Polar theta or angle m_moveY.SetLabel( _( "Angle:" ) ); // Polar theta or angle
m_moveY.SetUnits( DEGREES );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( DEGREES ) );
} }
else else
{ {
m_xLabel->SetLabelText( _( "Move vector X:" ) ); m_moveX.SetLabel( _( "Move X:" ) );
m_yLabel->SetLabelText( _( "Move vector Y:" ) ); m_moveY.SetLabel( _( "Move Y:" ) );
m_moveY.SetUnits( GetUserUnits() );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
} }
Layout();
} }
void DIALOG_MOVE_EXACT::OnClear( wxCommandEvent& event ) void DIALOG_MOVE_EXACT::OnClear( wxCommandEvent& event )
{ {
wxObject* obj = event.GetEventObject(); wxObject* obj = event.GetEventObject();
wxTextCtrl* entry = NULL;
if( obj == m_clearX ) if( obj == m_clearX )
{ {
entry = m_xEntry; m_moveX.SetValue( 0 );
} }
else if( obj == m_clearY ) else if( obj == m_clearY )
{ {
entry = m_yEntry; m_moveY.SetValue( 0 );
} }
else if( obj == m_clearRot ) else if( obj == m_clearRot )
{ {
entry = m_rotEntry; m_rotate.SetValue( 0 );
} }
if( entry )
entry->SetValue( "0" );
// Keep m_stdButtonsOK focused to allow enter key actiavte the OK button // Keep m_stdButtonsOK focused to allow enter key actiavte the OK button
m_stdButtonsOK->SetFocus(); m_stdButtonsOK->SetFocus();
} }
@ -275,59 +203,19 @@ void DIALOG_MOVE_EXACT::OnClear( wxCommandEvent& event )
bool DIALOG_MOVE_EXACT::TransferDataFromWindow() bool DIALOG_MOVE_EXACT::TransferDataFromWindow()
{ {
m_rotation = DoubleValueFromString( DEGREES, m_rotEntry->GetValue() );
m_origin = static_cast<MOVE_EXACT_ORIGIN>( m_originChooser->GetSelection() );
if( m_cbOverride->IsChecked() && m_allowOverride )
{
m_anchor = static_cast<MOVE_EXACT_ANCHOR>( m_anchorChoice->GetSelection() );
}
else
{
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( move_vector, m_polarCoords->IsChecked() ); bool ok = GetTranslationInIU( m_translation, m_polarCoords->IsChecked() );
m_rotation = m_rotate.GetValue();
switch( m_origin ) m_rotationAnchor = m_menuIDs[ m_anchorOptions->GetSelection() ];
{
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 )
{ {
// save the settings // save the settings
m_options.polarCoords = m_polarCoords->GetValue(); m_options.polarCoords = m_polarCoords->GetValue();
m_options.entry1 = DoubleValueFromString( UNSCALED_UNITS, m_xEntry->GetValue() ); m_options.entry1 = m_moveX.GetValue();
m_options.entry2 = DoubleValueFromString( UNSCALED_UNITS, m_yEntry->GetValue() ); m_options.entry2 = m_moveY.GetValue();
m_options.entryRotation = DoubleValueFromString( UNSCALED_UNITS, m_rotEntry->GetValue() ); m_options.entryRotation = m_rotate.GetValue();
m_options.origin = m_origin; m_options.entryAnchorSelection = (size_t) std::max( m_anchorOptions->GetSelection(), 0 );
m_options.anchor = static_cast<MOVE_EXACT_ANCHOR>( m_anchorChoice->GetSelection() );
m_options.overrideAnchor = m_cbOverride->IsChecked();
return true; return true;
} }

View File

@ -26,54 +26,38 @@
#define __DIALOG_MOVE_EXACT__ #define __DIALOG_MOVE_EXACT__
#include <vector> #include <vector>
// Include the wxFormBuider header base: #include <widgets/unit_binder.h>
#include <dialog_move_exact_base.h> #include <dialog_move_exact_base.h>
enum MOVE_EXACT_ORIGIN
enum ROTATION_ANCHOR
{ {
RELATIVE_TO_CURRENT_POSITION, ROTATE_AROUND_ITEM_ANCHOR,
RELATIVE_TO_USER_ORIGIN, ROTATE_AROUND_SEL_CENTER,
RELATIVE_TO_GRID_ORIGIN, ROTATE_AROUND_USER_ORIGIN,
RELATIVE_TO_DRILL_PLACE_ORIGIN, ROTATE_AROUND_AUX_ORIGIN
RELATIVE_TO_SHEET_ORIGIN
};
enum MOVE_EXACT_ANCHOR
{
ANCHOR_TOP_LEFT_PAD,
ANCHOR_CENTER_FOOTPRINT,
ANCHOR_FROM_LIBRARY
};
struct MOVE_PARAMETERS
{
wxPoint translation = wxPoint( 0,0 );
double rotation = 0;
MOVE_EXACT_ORIGIN origin = RELATIVE_TO_CURRENT_POSITION;
MOVE_EXACT_ANCHOR anchor = ANCHOR_FROM_LIBRARY;
bool allowOverride = true;
bool editingFootprint = false;
}; };
class DIALOG_MOVE_EXACT : public DIALOG_MOVE_EXACT_BASE class DIALOG_MOVE_EXACT : public DIALOG_MOVE_EXACT_BASE
{ {
private: private:
wxPoint& m_translation;
double& m_rotation;
ROTATION_ANCHOR& m_rotationAnchor;
PCB_BASE_FRAME* m_parent; UNIT_BINDER m_moveX;
wxPoint& m_translation; UNIT_BINDER m_moveY;
double& m_rotation; UNIT_BINDER m_rotate;
MOVE_EXACT_ORIGIN& m_origin;
MOVE_EXACT_ANCHOR& m_anchor; std::vector<ROTATION_ANCHOR> m_menuIDs;
bool& m_allowOverride;
bool& m_editingFootprint;
public: public:
// Constructor and destructor // Constructor and destructor
DIALOG_MOVE_EXACT(PCB_BASE_FRAME *aParent, MOVE_PARAMETERS &aParams ); DIALOG_MOVE_EXACT(PCB_BASE_FRAME *aParent, wxPoint& aTranslate,
~DIALOG_MOVE_EXACT(); double& aRotate, ROTATION_ANCHOR& aAnchor );
~DIALOG_MOVE_EXACT() { };
private: private:
@ -85,9 +69,6 @@ private:
void OnPolarChanged( wxCommandEvent& event ) override; void OnPolarChanged( wxCommandEvent& event ) override;
void OnClear( wxCommandEvent& event ) override; void OnClear( wxCommandEvent& event ) override;
void OnOriginChanged( wxCommandEvent& event ) override;
void OnOverrideChanged( wxCommandEvent& event ) override;
// Automatically called when clicking on the OK button // Automatically called when clicking on the OK button
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;
@ -107,30 +88,28 @@ private:
*/ */
bool GetTranslationInIU ( wxPoint& val, bool polar ); bool GetTranslationInIU ( wxPoint& val, bool polar );
// Update texts (comments) after changing the coordinates type (polar/cartesian) void buildRotationAnchorMenu();
void updateDlgTexts( bool aPolar );
// Update controls and their labels after changing the coordinates type (polar/cartesian)
void updateDialogControls( bool aPolar );
/** /**
* Persistent dialog options * Persistent dialog options
*/ */
struct MOVE_EXACT_OPTIONS struct MOVE_EXACT_OPTIONS
{ {
bool polarCoords; bool polarCoords;
double entry1; double entry1;
double entry2; double entry2;
double entryRotation; double entryRotation;
MOVE_EXACT_ORIGIN origin; size_t entryAnchorSelection;
MOVE_EXACT_ANCHOR anchor;
bool overrideAnchor;
MOVE_EXACT_OPTIONS(): MOVE_EXACT_OPTIONS():
polarCoords( false ), polarCoords( false ),
entry1( 0 ), entry1( 0 ),
entry2( 0 ), entry2( 0 ),
entryRotation( 0 ), entryRotation( 0 ),
origin( RELATIVE_TO_CURRENT_POSITION ), entryAnchorSelection( 0 )
anchor( ANCHOR_FROM_LIBRARY ),
overrideAnchor( false )
{ {
} }
}; };

View File

@ -1,12 +1,10 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Aug 4 2017) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#include "widgets/text_ctrl_eval.h"
#include "dialog_move_exact_base.h" #include "dialog_move_exact_base.h"
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -17,88 +15,74 @@ DIALOG_MOVE_EXACT_BASE::DIALOG_MOVE_EXACT_BASE( wxWindow* parent, wxWindowID id,
bMainSizer = new wxBoxSizer( wxVERTICAL ); bMainSizer = new wxBoxSizer( wxVERTICAL );
m_polarCoords = new wxCheckBox( this, wxID_ANY, _("Use polar coordinates"), wxDefaultPosition, wxDefaultSize, 0 );
bMainSizer->Add( m_polarCoords, 0, wxALL|wxEXPAND, 5 );
wxBoxSizer* bMiddleSizer;
bMiddleSizer = new wxBoxSizer( wxHORIZONTAL );
wxFlexGridSizer* fgInputSizer; wxFlexGridSizer* fgInputSizer;
fgInputSizer = new wxFlexGridSizer( 0, 4, 0, 0 ); fgInputSizer = new wxFlexGridSizer( 0, 4, 0, 5 );
fgInputSizer->AddGrowableCol( 1 ); fgInputSizer->AddGrowableCol( 1 );
fgInputSizer->SetFlexibleDirection( wxBOTH ); fgInputSizer->SetFlexibleDirection( wxBOTH );
fgInputSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); fgInputSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_xLabel = new wxStaticText( this, wxID_ANY, _("X:"), wxDefaultPosition, wxSize( -1,-1 ), 0 ); m_xLabel = new wxStaticText( this, wxID_ANY, _("Move X:"), wxDefaultPosition, wxSize( -1,-1 ), 0 );
m_xLabel->Wrap( -1 ); m_xLabel->Wrap( -1 );
fgInputSizer->Add( m_xLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); fgInputSizer->Add( m_xLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP, 5 );
m_xEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 ); m_xEntry = new wxTextCtrl( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgInputSizer->Add( m_xEntry, 0, wxALL|wxEXPAND, 5 ); fgInputSizer->Add( m_xEntry, 0, wxEXPAND|wxTOP, 5 );
m_xUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_xUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 );
m_xUnit->Wrap( -1 ); m_xUnit->Wrap( -1 );
fgInputSizer->Add( m_xUnit, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 ); fgInputSizer->Add( m_xUnit, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxTOP|wxRIGHT, 5 );
m_clearX = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_clearX = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgInputSizer->Add( m_clearX, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgInputSizer->Add( m_clearX, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 );
m_yLabel = new wxStaticText( this, wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_yLabel = new wxStaticText( this, wxID_ANY, _("Move Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_yLabel->Wrap( -1 ); m_yLabel->Wrap( -1 );
fgInputSizer->Add( m_yLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); fgInputSizer->Add( m_yLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5 );
m_yEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 ); m_yEntry = new wxTextCtrl( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgInputSizer->Add( m_yEntry, 0, wxALL|wxEXPAND, 5 ); fgInputSizer->Add( m_yEntry, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
m_yUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_yUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 );
m_yUnit->Wrap( -1 ); m_yUnit->Wrap( -1 );
fgInputSizer->Add( m_yUnit, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgInputSizer->Add( m_yUnit, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
m_clearY = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_clearY = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgInputSizer->Add( m_clearY, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgInputSizer->Add( m_clearY, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_rotLabel = new wxStaticText( this, wxID_ANY, _("Item rotation:"), wxDefaultPosition, wxDefaultSize, 0 ); m_rotLabel = new wxStaticText( this, wxID_ANY, _("Rotate:"), wxDefaultPosition, wxDefaultSize, 0 );
m_rotLabel->Wrap( -1 ); m_rotLabel->Wrap( -1 );
fgInputSizer->Add( m_rotLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); fgInputSizer->Add( m_rotLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5 );
m_rotEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 ); m_rotEntry = new wxTextCtrl( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgInputSizer->Add( m_rotEntry, 0, wxALL|wxEXPAND, 5 ); fgInputSizer->Add( m_rotEntry, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
m_rotUnit = new wxStaticText( this, wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 ); m_rotUnit = new wxStaticText( this, wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 );
m_rotUnit->Wrap( -1 ); m_rotUnit->Wrap( -1 );
fgInputSizer->Add( m_rotUnit, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgInputSizer->Add( m_rotUnit, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
m_clearRot = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_clearRot = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgInputSizer->Add( m_clearRot, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgInputSizer->Add( m_clearRot, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
bMiddleSizer->Add( fgInputSizer, 1, wxALL|wxBOTTOM|wxEXPAND|wxTOP, 5 ); fgInputSizer->Add( 0, 0, 1, wxEXPAND, 5 );
wxString m_originChooserChoices[] = { _("Current position"), _("User origin"), _("Grid origin"), _("Drill/Place origin"), _("Sheet origin") }; wxString m_anchorOptionsChoices[] = { _("Rotate around center of selection"), _("Rotate around User Origin"), _("Rotate around Drill/Place Origin") };
int m_originChooserNChoices = sizeof( m_originChooserChoices ) / sizeof( wxString ); int m_anchorOptionsNChoices = sizeof( m_anchorOptionsChoices ) / sizeof( wxString );
m_originChooser = new wxRadioBox( this, wxID_ANY, _("Move Relative To:"), wxDefaultPosition, wxDefaultSize, m_originChooserNChoices, m_originChooserChoices, 1, wxRA_SPECIFY_COLS ); m_anchorOptions = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_anchorOptionsNChoices, m_anchorOptionsChoices, 0 );
m_originChooser->SetSelection( 0 ); m_anchorOptions->SetSelection( 0 );
bMiddleSizer->Add( m_originChooser, 0, wxALL, 5 ); fgInputSizer->Add( m_anchorOptions, 0, wxEXPAND|wxBOTTOM, 5 );
bMainSizer->Add( bMiddleSizer, 1, wxEXPAND, 5 ); bMainSizer->Add( fgInputSizer, 0, wxEXPAND|wxALL, 10 );
bAnchorSizer = new wxBoxSizer( wxHORIZONTAL );
m_cbOverride = new wxCheckBox( this, wxID_ANY, _("Override default footprint anchor with:"), wxDefaultPosition, wxDefaultSize, 0 );
bAnchorSizer->Add( m_cbOverride, 1, wxALL, 5 );
wxString m_anchorChoiceChoices[] = { _("Top left pad"), _("Footprint center") };
int m_anchorChoiceNChoices = sizeof( m_anchorChoiceChoices ) / sizeof( wxString );
m_anchorChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_anchorChoiceNChoices, m_anchorChoiceChoices, 0 );
m_anchorChoice->SetSelection( 0 );
bAnchorSizer->Add( m_anchorChoice, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
bMainSizer->Add( bAnchorSizer, 0, wxEXPAND, 5 );
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bMainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); bMainSizer->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );
wxBoxSizer* bBottomSizer;
bBottomSizer = new wxBoxSizer( wxHORIZONTAL );
m_polarCoords = new wxCheckBox( this, wxID_ANY, _("Use polar coordinates"), wxDefaultPosition, wxDefaultSize, 0 );
bBottomSizer->Add( m_polarCoords, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 10 );
m_stdButtons = new wxStdDialogButtonSizer(); m_stdButtons = new wxStdDialogButtonSizer();
m_stdButtonsOK = new wxButton( this, wxID_OK ); m_stdButtonsOK = new wxButton( this, wxID_OK );
@ -107,35 +91,35 @@ DIALOG_MOVE_EXACT_BASE::DIALOG_MOVE_EXACT_BASE( wxWindow* parent, wxWindowID id,
m_stdButtons->AddButton( m_stdButtonsCancel ); m_stdButtons->AddButton( m_stdButtonsCancel );
m_stdButtons->Realize(); m_stdButtons->Realize();
bMainSizer->Add( m_stdButtons, 0, wxALL|wxEXPAND, 5 ); bBottomSizer->Add( m_stdButtons, 1, wxALL|wxEXPAND, 5 );
bMainSizer->Add( bBottomSizer, 0, wxEXPAND, 5 );
this->SetSizer( bMainSizer ); this->SetSizer( bMainSizer );
this->Layout(); this->Layout();
bMainSizer->Fit( this );
// Connect Events // Connect Events
m_polarCoords->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnPolarChanged ), NULL, this );
m_xEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_xEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearX->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearX->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_yEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_yEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearY->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearY->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_rotEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_rotEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearRot->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearRot->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_originChooser->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnOriginChanged ), NULL, this ); m_polarCoords->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnPolarChanged ), NULL, this );
m_cbOverride->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnOverrideChanged ), NULL, this );
} }
DIALOG_MOVE_EXACT_BASE::~DIALOG_MOVE_EXACT_BASE() DIALOG_MOVE_EXACT_BASE::~DIALOG_MOVE_EXACT_BASE()
{ {
// Disconnect Events // Disconnect Events
m_polarCoords->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnPolarChanged ), NULL, this );
m_xEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_xEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearX->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearX->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_yEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_yEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearY->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearY->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_rotEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this ); m_rotEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_MOVE_EXACT_BASE::OnTextFocusLost ), NULL, this );
m_clearRot->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this ); m_clearRot->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnClear ), NULL, this );
m_originChooser->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnOriginChanged ), NULL, this ); m_polarCoords->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnPolarChanged ), NULL, this );
m_cbOverride->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_MOVE_EXACT_BASE::OnOverrideChanged ), NULL, this );
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Aug 4 2017) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_MOVE_EXACT_BASE_H__ #ifndef __DIALOG_MOVE_EXACT_BASE_H__
@ -11,23 +11,19 @@
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
#include <wx/intl.h> #include <wx/intl.h>
class DIALOG_SHIM;
class TEXT_CTRL_EVAL;
#include "dialog_shim.h" #include "dialog_shim.h"
#include <wx/string.h> #include <wx/string.h>
#include <wx/checkbox.h> #include <wx/stattext.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <wx/font.h> #include <wx/font.h>
#include <wx/colour.h> #include <wx/colour.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/stattext.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/sizer.h>
#include <wx/radiobox.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/sizer.h>
#include <wx/statline.h> #include <wx/statline.h>
#include <wx/checkbox.h>
#include <wx/dialog.h> #include <wx/dialog.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -42,39 +38,34 @@ class DIALOG_MOVE_EXACT_BASE : public DIALOG_SHIM
protected: protected:
wxBoxSizer* bMainSizer; wxBoxSizer* bMainSizer;
wxCheckBox* m_polarCoords;
wxStaticText* m_xLabel; wxStaticText* m_xLabel;
TEXT_CTRL_EVAL* m_xEntry; wxTextCtrl* m_xEntry;
wxStaticText* m_xUnit; wxStaticText* m_xUnit;
wxButton* m_clearX; wxButton* m_clearX;
wxStaticText* m_yLabel; wxStaticText* m_yLabel;
TEXT_CTRL_EVAL* m_yEntry; wxTextCtrl* m_yEntry;
wxStaticText* m_yUnit; wxStaticText* m_yUnit;
wxButton* m_clearY; wxButton* m_clearY;
wxStaticText* m_rotLabel; wxStaticText* m_rotLabel;
TEXT_CTRL_EVAL* m_rotEntry; wxTextCtrl* m_rotEntry;
wxStaticText* m_rotUnit; wxStaticText* m_rotUnit;
wxButton* m_clearRot; wxButton* m_clearRot;
wxRadioBox* m_originChooser; wxChoice* m_anchorOptions;
wxBoxSizer* bAnchorSizer;
wxCheckBox* m_cbOverride;
wxChoice* m_anchorChoice;
wxStaticLine* m_staticline1; wxStaticLine* m_staticline1;
wxCheckBox* m_polarCoords;
wxStdDialogButtonSizer* m_stdButtons; wxStdDialogButtonSizer* m_stdButtons;
wxButton* m_stdButtonsOK; wxButton* m_stdButtonsOK;
wxButton* m_stdButtonsCancel; wxButton* m_stdButtonsCancel;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnPolarChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTextFocusLost( wxFocusEvent& event ) { event.Skip(); } virtual void OnTextFocusLost( wxFocusEvent& event ) { event.Skip(); }
virtual void OnClear( wxCommandEvent& event ) { event.Skip(); } virtual void OnClear( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOriginChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnPolarChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOverrideChanged( wxCommandEvent& event ) { event.Skip(); }
public: public:
DIALOG_MOVE_EXACT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Move Item"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 427,250 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_MOVE_EXACT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Move Item"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_MOVE_EXACT_BASE(); ~DIALOG_MOVE_EXACT_BASE();
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -22,54 +22,36 @@
*/ */
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <base_units.h> #include "tools/pcb_actions.h"
#include <macros.h>
#include <widgets/text_ctrl_eval.h>
#include <footprint_edit_frame.h>
#include "dialog_position_relative.h" #include "dialog_position_relative.h"
#include "tools/pcb_actions.h"
// initialise statics // initialise statics
DIALOG_POSITION_RELATIVE::POSITION_RELATIVE_OPTIONS DIALOG_POSITION_RELATIVE::m_options; DIALOG_POSITION_RELATIVE::POSITION_RELATIVE_OPTIONS DIALOG_POSITION_RELATIVE::m_options;
DIALOG_POSITION_RELATIVE::DIALOG_POSITION_RELATIVE( PCB_BASE_FRAME* aParent, TOOL_MANAGER* toolMgr, DIALOG_POSITION_RELATIVE::DIALOG_POSITION_RELATIVE( PCB_BASE_FRAME* aParent, TOOL_MANAGER* toolMgr,
wxPoint& translation, double& rotation, wxPoint& anchorPosition ) : wxPoint& translation, wxPoint& anchorPosition ) :
DIALOG_POSITION_RELATIVE_BASE( aParent ), DIALOG_POSITION_RELATIVE_BASE( aParent ),
m_toolMgr( toolMgr ), m_toolMgr( toolMgr ),
m_translation( translation ), m_translation( translation ),
m_rotation( rotation ), m_anchor_position( anchorPosition ),
m_anchor_position( anchorPosition ) m_xOffset( aParent, m_xLabel, m_xEntry, m_xUnit ),
m_yOffset( aParent, m_yLabel, m_yEntry, m_yUnit )
{ {
// set the unit labels
m_xUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
// tabbing goes through the entries in sequence // tabbing goes through the entries in sequence
m_yEntry->MoveAfterInTabOrder( m_xEntry ); m_yEntry->MoveAfterInTabOrder( m_xEntry );
m_rotEntry->MoveAfterInTabOrder( m_yEntry );
// and set up the entries according to the saved options // and set up the entries according to the saved options
m_polarCoords->SetValue( m_options.polarCoords ); m_polarCoords->SetValue( m_options.polarCoords );
m_xEntry->SetValue( wxString::FromDouble( m_options.entry1 ) ); updateDialogControls( m_polarCoords->IsChecked() );
m_yEntry->SetValue( wxString::FromDouble( m_options.entry2 ) );
m_rotEntry->SetValue( wxString::FromDouble( m_options.entryRotation ) );
updateDlgTexts( m_polarCoords->IsChecked() );
PutValueInLocalUnits( *m_anchor_x, m_anchor_position.x ); m_xOffset.SetValue( m_options.entry1 );
PutValueInLocalUnits( *m_anchor_y, m_anchor_position.y ); m_yOffset.SetValue( m_options.entry2 );
m_stdButtonsOK->SetDefault(); m_stdButtonsOK->SetDefault();
GetSizer()->SetSizeHints( this ); FinishDialogSettings();
Layout();
}
DIALOG_POSITION_RELATIVE::~DIALOG_POSITION_RELATIVE()
{
} }
@ -82,21 +64,21 @@ void DIALOG_POSITION_RELATIVE::ToPolarDeg( double x, double y, double& r, double
} }
bool DIALOG_POSITION_RELATIVE::GetTranslationInIU( wxPoint& val, bool polar ) bool DIALOG_POSITION_RELATIVE::GetTranslationInIU ( wxPoint& val, bool polar )
{ {
if( polar ) if( polar )
{ {
const int r = ValueFromTextCtrl( *m_xEntry ); const int r = m_xOffset.GetValue();
const double q = DoubleValueFromString( DEGREES, m_yEntry->GetValue() ); const double q = m_yOffset.GetValue();
val.x = r * cos( DEG2RAD( q / 10.0 ) ); val.x = r * cos( DEG2RAD( q / 10.0 ) );
val.y = r * sin( DEG2RAD( q / 10.0 ) ); val.y = r * sin( DEG2RAD( q / 10.0 ) );
} }
else else
{ {
// direct read // direct read
val.x = ValueFromTextCtrl( *m_xEntry ); val.x = m_xOffset.GetValue();
val.y = ValueFromTextCtrl( *m_yEntry ); val.y = m_yOffset.GetValue();
} }
// no validation to do here, but in future, you could return false here // no validation to do here, but in future, you could return false here
@ -107,21 +89,22 @@ bool DIALOG_POSITION_RELATIVE::GetTranslationInIU( wxPoint& val, bool polar )
void DIALOG_POSITION_RELATIVE::OnPolarChanged( wxCommandEvent& event ) void DIALOG_POSITION_RELATIVE::OnPolarChanged( wxCommandEvent& event )
{ {
bool newPolar = m_polarCoords->IsChecked(); bool newPolar = m_polarCoords->IsChecked();
updateDlgTexts( newPolar );
wxPoint val; wxPoint val;
// get the value as previously stored // get the value as previously stored
GetTranslationInIU( val, !newPolar ); GetTranslationInIU( val, !newPolar );
// now switch the controls to the new representations
updateDialogControls( newPolar );
if( newPolar ) if( newPolar )
{ {
// convert to polar coordinates // convert to polar coordinates
double r, q; double r, q;
ToPolarDeg( val.x, val.y, r, q ); ToPolarDeg( val.x, val.y, r, q );
PutValueInLocalUnits( *m_xEntry, KiROUND( r / 10.0 ) * 10 ); m_xOffset.SetValue( KiROUND( r / 10.0) * 10 );
m_yEntry->SetValue( wxString::FromDouble( q ) ); m_yOffset.SetValue( q * 10 );
} }
else else
{ {
@ -129,29 +112,26 @@ void DIALOG_POSITION_RELATIVE::OnPolarChanged( wxCommandEvent& event )
// note - round off the last decimal place (10nm) to prevent // note - round off the last decimal place (10nm) to prevent
// (some) rounding causing errors when round-tripping // (some) rounding causing errors when round-tripping
// you can never eliminate entirely, however // you can never eliminate entirely, however
PutValueInLocalUnits( *m_xEntry, KiROUND( val.x / 10.0 ) * 10 ); m_xOffset.SetValue( KiROUND( val.x / 10.0 ) * 10 );
PutValueInLocalUnits( *m_yEntry, KiROUND( val.y / 10.0 ) * 10 ); m_yOffset.SetValue( KiROUND( val.y / 10.0 ) * 10 );
} }
Layout();
} }
void DIALOG_POSITION_RELATIVE::updateDlgTexts( bool aPolar ) void DIALOG_POSITION_RELATIVE::updateDialogControls( bool aPolar )
{ {
if( aPolar ) if( aPolar )
{ {
m_xLabel->SetLabelText( _( "Distance from anchor:" ) ); // Polar radius m_xOffset.SetLabel( _( "Distance:" ) ); // Polar radius
m_yLabel->SetLabelText( _( "Angle:" ) ); // Polar theta or angle m_yOffset.SetLabel( _( "Angle:" ) ); // Polar theta or angle
m_yOffset.SetUnits( DEGREES );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( DEGREES ) );
} }
else else
{ {
m_xLabel->SetLabelText( _( "Position from anchor X:" ) ); m_xOffset.SetLabel( _( "Offset X:" ) );
m_yLabel->SetLabelText( _( "Position from anchor Y:" ) ); m_yOffset.SetLabel( _( "Offset Y:" ) );
m_yOffset.SetUnits( GetUserUnits() );
m_yUnit->SetLabelText( GetAbbreviatedUnitsLabel( g_UserUnit ) );
} }
} }
@ -159,23 +139,15 @@ void DIALOG_POSITION_RELATIVE::updateDlgTexts( bool aPolar )
void DIALOG_POSITION_RELATIVE::OnClear( wxCommandEvent& event ) void DIALOG_POSITION_RELATIVE::OnClear( wxCommandEvent& event )
{ {
wxObject* obj = event.GetEventObject(); wxObject* obj = event.GetEventObject();
wxTextCtrl* entry = NULL;
if( obj == m_clearX ) if( obj == m_clearX )
{ {
entry = m_xEntry; m_xOffset.SetValue( 0 );
} }
else if( obj == m_clearY ) else if( obj == m_clearY )
{ {
entry = m_yEntry; m_yOffset.SetValue( 0 );
} }
else if( obj == m_clearRot )
{
entry = m_rotEntry;
}
if( entry )
entry->SetValue( "0" );
} }
@ -186,22 +158,29 @@ void DIALOG_POSITION_RELATIVE::OnSelectItemClick( wxCommandEvent& event )
POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool<POSITION_RELATIVE_TOOL>(); POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool<POSITION_RELATIVE_TOOL>();
wxASSERT( posrelTool ); wxASSERT( posrelTool );
m_referenceInfo->SetLabel( _( "Reference item: <click item on canvas to select>" ) );
m_toolMgr->RunAction( PCB_ACTIONS::selectpositionRelativeItem, true ); m_toolMgr->RunAction( PCB_ACTIONS::selectpositionRelativeItem, true );
} }
void DIALOG_POSITION_RELATIVE::UpdateAnchor( const wxPoint& aPosition ) void DIALOG_POSITION_RELATIVE::UpdateAnchor( BOARD_ITEM* aItem )
{ {
m_anchor_position = aPosition; wxString reference = _( "<none selected>" );
PutValueInLocalUnits( *m_anchor_x, aPosition.x );
PutValueInLocalUnits( *m_anchor_y, aPosition.y ); if( aItem )
{
m_anchor_position = aItem->GetPosition();
reference = aItem->GetSelectMenuText( GetUserUnits() );
}
m_referenceInfo->SetLabel( _( "Reference item: " ) + reference );
Raise(); // required at least on OSX
} }
void DIALOG_POSITION_RELATIVE::OnOkClick( wxCommandEvent& event ) void DIALOG_POSITION_RELATIVE::OnOkClick( wxCommandEvent& event )
{ {
m_rotation = DoubleValueFromString( DEGREES, m_rotEntry->GetValue() );
// 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( m_translation, m_polarCoords->IsChecked() );
@ -209,13 +188,12 @@ void DIALOG_POSITION_RELATIVE::OnOkClick( wxCommandEvent& event )
{ {
// save the settings // save the settings
m_options.polarCoords = m_polarCoords->GetValue(); m_options.polarCoords = m_polarCoords->GetValue();
m_options.entry1 = DoubleValueFromString( UNSCALED_UNITS, m_xEntry->GetValue() ); m_options.entry1 = m_xOffset.GetValue();
m_options.entry2 = DoubleValueFromString( UNSCALED_UNITS, m_yEntry->GetValue() ); m_options.entry2 = m_yOffset.GetValue();
m_options.entryRotation = DoubleValueFromString( UNSCALED_UNITS, m_rotEntry->GetValue() );
POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool<POSITION_RELATIVE_TOOL>(); POSITION_RELATIVE_TOOL* posrelTool = m_toolMgr->GetTool<POSITION_RELATIVE_TOOL>();
wxASSERT( posrelTool ); wxASSERT( posrelTool );
posrelTool->RelativeItemSelectionMove( m_anchor_position, m_translation, m_rotation ); posrelTool->RelativeItemSelectionMove( m_anchor_position, m_translation, 0.0 );
event.Skip(); event.Skip();
} }

View File

@ -29,6 +29,7 @@
#include <dialogs/dialog_position_relative_base.h> #include <dialogs/dialog_position_relative_base.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <widgets/unit_binder.h>
#include "tools/position_relative_tool.h" #include "tools/position_relative_tool.h"
class DIALOG_POSITION_RELATIVE : public DIALOG_POSITION_RELATIVE_BASE class DIALOG_POSITION_RELATIVE : public DIALOG_POSITION_RELATIVE_BASE
@ -36,17 +37,19 @@ class DIALOG_POSITION_RELATIVE : public DIALOG_POSITION_RELATIVE_BASE
private: private:
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
wxPoint& m_translation; wxPoint& m_translation;
double& m_rotation; wxPoint& m_anchor_position;
wxPoint& m_anchor_position;
UNIT_BINDER m_xOffset;
UNIT_BINDER m_yOffset;
public: public:
// Constructor and destructor // Constructor and destructor
DIALOG_POSITION_RELATIVE( PCB_BASE_FRAME* aParent, TOOL_MANAGER* toolMgr, wxPoint& translation, DIALOG_POSITION_RELATIVE( PCB_BASE_FRAME* aParent, TOOL_MANAGER* toolMgr,
double& rotation, wxPoint& anchorposition ); wxPoint& translation, wxPoint& anchorposition );
~DIALOG_POSITION_RELATIVE(); ~DIALOG_POSITION_RELATIVE() { };
void UpdateAnchor( const wxPoint& aPosition ); void UpdateAnchor( BOARD_ITEM* aItem );
private: private:
@ -55,11 +58,11 @@ private:
*/ */
void OnTextFocusLost( wxFocusEvent& event ) override; void OnTextFocusLost( wxFocusEvent& event ) override;
void OnPolarChanged( wxCommandEvent& event ) override; void OnPolarChanged( wxCommandEvent& event ) override;
void OnClear( wxCommandEvent& event ) override; void OnClear( wxCommandEvent& event ) override;
void OnSelectItemClick( wxCommandEvent& event ) override; void OnSelectItemClick( wxCommandEvent& event ) override;
void OnOkClick( wxCommandEvent& event ) override; void OnOkClick( wxCommandEvent& event ) override;
/** /**
* Convert a given Cartesian point into a polar representation. * Convert a given Cartesian point into a polar representation.
@ -77,8 +80,8 @@ private:
*/ */
bool GetTranslationInIU( wxPoint& val, bool polar ); bool GetTranslationInIU( wxPoint& val, bool polar );
// Update texts (comments) after changing the coordinates type (polar/cartesian) // Update controls and their labels after changing the coordinates type (polar/cartesian)
void updateDlgTexts( bool aPolar ); void updateDialogControls( bool aPolar );
/** /**
* Persistent dialog options * Persistent dialog options
@ -88,13 +91,11 @@ private:
bool polarCoords; bool polarCoords;
double entry1; double entry1;
double entry2; double entry2;
double entryRotation;
POSITION_RELATIVE_OPTIONS() : POSITION_RELATIVE_OPTIONS() :
polarCoords( false ), polarCoords( false ),
entry1( 0 ), entry1( 0 ),
entry2( 0 ), entry2( 0 )
entryRotation( 0 )
{ {
} }
}; };

View File

@ -1,12 +1,10 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 2 2017) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#include "widgets/text_ctrl_eval.h"
#include "dialog_position_relative_base.h" #include "dialog_position_relative_base.h"
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -18,97 +16,82 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent,
wxBoxSizer* bMainSizer; wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxVERTICAL ); bMainSizer = new wxBoxSizer( wxVERTICAL );
m_staticTextHelp = new wxStaticText( this, wxID_ANY, _("The Anchor position is the origin of coordinates for the transform."), wxDefaultPosition, wxDefaultSize, 0 ); wxBoxSizer* bUpperSizer;
m_staticTextHelp->Wrap( -1 ); bUpperSizer = new wxBoxSizer( wxHORIZONTAL );
bMainSizer->Add( m_staticTextHelp, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
m_referenceInfo = new wxStaticText( this, wxID_ANY, _("Reference item: <none selected>"), wxDefaultPosition, wxDefaultSize, 0 );
m_referenceInfo->Wrap( -1 );
m_referenceInfo->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) );
m_referenceInfo->SetMinSize( wxSize( 340,-1 ) );
bUpperSizer->Add( m_referenceInfo, 0, wxALIGN_CENTER_HORIZONTAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
bUpperSizer->Add( 0, 0, 1, wxEXPAND, 5 );
m_select_anchor_button = new wxButton( this, wxID_ANY, _("Select"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_select_anchor_button->SetToolTip( _("Click and select a board item.\nThe anchor position will be the position of the selected item.") );
bUpperSizer->Add( m_select_anchor_button, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
bMainSizer->Add( bUpperSizer, 0, wxEXPAND|wxALL, 10 );
m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bMainSizer->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 ); bMainSizer->Add( m_staticline2, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );
m_polarCoords = new wxCheckBox( this, wxID_ANY, _("Use polar coordinates"), wxDefaultPosition, wxDefaultSize, 0 );
m_polarCoords->SetValue(true);
bMainSizer->Add( m_polarCoords, 0, wxALL|wxEXPAND, 5 );
wxFlexGridSizer* fgSizer2; wxFlexGridSizer* fgSizer2;
fgSizer2 = new wxFlexGridSizer( 0, 4, 0, 0 ); fgSizer2 = new wxFlexGridSizer( 0, 5, 5, 0 );
fgSizer2->AddGrowableCol( 1 ); fgSizer2->AddGrowableCol( 1 );
fgSizer2->SetFlexibleDirection( wxBOTH ); fgSizer2->SetFlexibleDirection( wxBOTH );
fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_xLabel = new wxStaticText( this, wxID_ANY, _("X:"), wxDefaultPosition, wxSize( -1,-1 ), 0 ); m_xLabel = new wxStaticText( this, wxID_ANY, _("Offset X:"), wxDefaultPosition, wxSize( -1,-1 ), 0 );
m_xLabel->Wrap( -1 ); m_xLabel->Wrap( -1 );
fgSizer2->Add( m_xLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); fgSizer2->Add( m_xLabel, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT, 5 );
m_xEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 ); m_xEntry = new wxTextCtrl( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_xEntry, 0, wxALL|wxEXPAND, 5 ); fgSizer2->Add( m_xEntry, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
m_xUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_xUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 );
m_xUnit->Wrap( -1 ); m_xUnit->Wrap( -1 );
fgSizer2->Add( m_xUnit, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxALL, 5 ); fgSizer2->Add( m_xUnit, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxTOP|wxRIGHT, 5 );
fgSizer2->Add( 0, 0, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
m_clearX = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_clearX = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgSizer2->Add( m_clearX, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgSizer2->Add( m_clearX, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxRIGHT|wxLEFT, 5 );
m_yLabel = new wxStaticText( this, wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_yLabel = new wxStaticText( this, wxID_ANY, _("Offset Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_yLabel->Wrap( -1 ); m_yLabel->Wrap( -1 );
fgSizer2->Add( m_yLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 ); fgSizer2->Add( m_yLabel, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 );
m_yEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 ); m_yEntry = new wxTextCtrl( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_yEntry, 0, wxALL|wxEXPAND, 5 ); fgSizer2->Add( m_yEntry, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_yUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_yUnit = new wxStaticText( this, wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 );
m_yUnit->Wrap( -1 ); m_yUnit->Wrap( -1 );
fgSizer2->Add( m_yUnit, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgSizer2->Add( m_yUnit, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 );
fgSizer2->Add( 0, 0, 1, wxEXPAND, 5 );
m_clearY = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT ); m_clearY = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgSizer2->Add( m_clearY, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); fgSizer2->Add( m_clearY, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_rotLabel = new wxStaticText( this, wxID_ANY, _("Item rotation:"), wxDefaultPosition, wxDefaultSize, 0 );
m_rotLabel->Wrap( -1 );
fgSizer2->Add( m_rotLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
m_rotEntry = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_rotEntry, 0, wxALL|wxEXPAND, 5 );
m_rotUnit = new wxStaticText( this, wxID_ANY, _("deg"), wxDefaultPosition, wxDefaultSize, 0 );
m_rotUnit->Wrap( -1 );
fgSizer2->Add( m_rotUnit, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_clearRot = new wxButton( this, wxID_ANY, _("Reset"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
fgSizer2->Add( m_clearRot, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_anchor_xLabel = new wxStaticText( this, wxID_ANY, _("Anchor position X:"), wxDefaultPosition, wxSize( -1,-1 ), 0 );
m_anchor_xLabel->Wrap( -1 );
m_anchor_xLabel->SetToolTip( _("The Anchor position is the origin of coordinates for the transform.") );
fgSizer2->Add( m_anchor_xLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
m_anchor_x = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_anchor_x, 0, wxALL, 5 );
m_anchor_yLabel = new wxStaticText( this, wxID_ANY, _("Y:"), wxDefaultPosition, wxSize( -1,-1 ), 0 );
m_anchor_yLabel->Wrap( -1 );
fgSizer2->Add( m_anchor_yLabel, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT|wxALL, 5 );
m_anchor_y = new TEXT_CTRL_EVAL( this, wxID_ANY, _("0"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_anchor_y, 0, wxALL, 5 );
bMainSizer->Add( fgSizer2, 1, wxEXPAND|wxTOP|wxBOTTOM, 5 ); bMainSizer->Add( fgSizer2, 1, wxEXPAND|wxALL, 10 );
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bMainSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 ); bMainSizer->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 10 );
wxBoxSizer* bSizerBottom; wxBoxSizer* bSizerBottom;
bSizerBottom = new wxBoxSizer( wxHORIZONTAL ); bSizerBottom = new wxBoxSizer( wxHORIZONTAL );
m_select_anchor_button = new wxButton( this, wxID_ANY, _("Select Anchor Position"), wxDefaultPosition, wxDefaultSize, 0 ); m_polarCoords = new wxCheckBox( this, wxID_ANY, _("Use polar coordinates"), wxDefaultPosition, wxDefaultSize, 0 );
m_select_anchor_button->SetToolTip( _("Click and select a board item.\nThe anchor position will be the position of the selected item.") ); m_polarCoords->SetValue(true);
bSizerBottom->Add( m_polarCoords, 0, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bSizerBottom->Add( m_select_anchor_button, 0, wxALL, 5 );
bSizerBottom->Add( 0, 0, 1, wxEXPAND, 5 );
m_stdButtons = new wxStdDialogButtonSizer(); m_stdButtons = new wxStdDialogButtonSizer();
m_stdButtonsOK = new wxButton( this, wxID_OK ); m_stdButtonsOK = new wxButton( this, wxID_OK );
@ -117,10 +100,10 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent,
m_stdButtons->AddButton( m_stdButtonsCancel ); m_stdButtons->AddButton( m_stdButtonsCancel );
m_stdButtons->Realize(); m_stdButtons->Realize();
bSizerBottom->Add( m_stdButtons, 0, wxALL|wxEXPAND, 5 ); bSizerBottom->Add( m_stdButtons, 1, wxALL|wxEXPAND, 5 );
bMainSizer->Add( bSizerBottom, 0, wxEXPAND, 5 ); bMainSizer->Add( bSizerBottom, 0, wxEXPAND|wxLEFT, 5 );
this->SetSizer( bMainSizer ); this->SetSizer( bMainSizer );
@ -129,14 +112,12 @@ DIALOG_POSITION_RELATIVE_BASE::DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent,
// Connect Events // Connect Events
this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) ); this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) );
m_polarCoords->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnPolarChanged ), NULL, this ); m_select_anchor_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this );
m_xEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_xEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this );
m_clearX->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); m_clearX->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_yEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_yEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this );
m_clearY->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); m_clearY->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_rotEntry->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_polarCoords->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnPolarChanged ), NULL, this );
m_clearRot->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_select_anchor_button->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this );
m_stdButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnOkClick ), NULL, this ); m_stdButtonsOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnOkClick ), NULL, this );
} }
@ -144,14 +125,12 @@ DIALOG_POSITION_RELATIVE_BASE::~DIALOG_POSITION_RELATIVE_BASE()
{ {
// Disconnect Events // Disconnect Events
this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) ); this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClose ) );
m_polarCoords->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnPolarChanged ), NULL, this ); m_select_anchor_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this );
m_xEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_xEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this );
m_clearX->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); m_clearX->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_yEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_yEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this );
m_clearY->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this ); m_clearY->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_rotEntry->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnTextFocusLost ), NULL, this ); m_polarCoords->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnPolarChanged ), NULL, this );
m_clearRot->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnClear ), NULL, this );
m_select_anchor_button->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnSelectItemClick ), NULL, this );
m_stdButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnOkClick ), NULL, this ); m_stdButtonsOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_POSITION_RELATIVE_BASE::OnOkClick ), NULL, this );
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jul 2 2017) // C++ code generated with wxFormBuilder (version Dec 30 2017)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef __DIALOG_POSITION_RELATIVE_BASE_H__ #ifndef __DIALOG_POSITION_RELATIVE_BASE_H__
@ -11,9 +11,6 @@
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
#include <wx/intl.h> #include <wx/intl.h>
class DIALOG_SHIM;
class TEXT_CTRL_EVAL;
#include "dialog_shim.h" #include "dialog_shim.h"
#include <wx/string.h> #include <wx/string.h>
#include <wx/stattext.h> #include <wx/stattext.h>
@ -21,11 +18,11 @@ class TEXT_CTRL_EVAL;
#include <wx/font.h> #include <wx/font.h>
#include <wx/colour.h> #include <wx/colour.h>
#include <wx/settings.h> #include <wx/settings.h>
#include <wx/statline.h>
#include <wx/checkbox.h>
#include <wx/textctrl.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/textctrl.h>
#include <wx/checkbox.h>
#include <wx/dialog.h> #include <wx/dialog.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -39,43 +36,35 @@ class DIALOG_POSITION_RELATIVE_BASE : public DIALOG_SHIM
private: private:
protected: protected:
wxStaticText* m_staticTextHelp; wxStaticText* m_referenceInfo;
wxButton* m_select_anchor_button;
wxStaticLine* m_staticline2; wxStaticLine* m_staticline2;
wxCheckBox* m_polarCoords;
wxStaticText* m_xLabel; wxStaticText* m_xLabel;
TEXT_CTRL_EVAL* m_xEntry; wxTextCtrl* m_xEntry;
wxStaticText* m_xUnit; wxStaticText* m_xUnit;
wxButton* m_clearX; wxButton* m_clearX;
wxStaticText* m_yLabel; wxStaticText* m_yLabel;
TEXT_CTRL_EVAL* m_yEntry; wxTextCtrl* m_yEntry;
wxStaticText* m_yUnit; wxStaticText* m_yUnit;
wxButton* m_clearY; wxButton* m_clearY;
wxStaticText* m_rotLabel;
TEXT_CTRL_EVAL* m_rotEntry;
wxStaticText* m_rotUnit;
wxButton* m_clearRot;
wxStaticText* m_anchor_xLabel;
TEXT_CTRL_EVAL* m_anchor_x;
wxStaticText* m_anchor_yLabel;
TEXT_CTRL_EVAL* m_anchor_y;
wxStaticLine* m_staticline1; wxStaticLine* m_staticline1;
wxButton* m_select_anchor_button; wxCheckBox* m_polarCoords;
wxStdDialogButtonSizer* m_stdButtons; wxStdDialogButtonSizer* m_stdButtons;
wxButton* m_stdButtonsOK; wxButton* m_stdButtonsOK;
wxButton* m_stdButtonsCancel; wxButton* m_stdButtonsCancel;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
virtual void OnPolarChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnSelectItemClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnTextFocusLost( wxFocusEvent& event ) { event.Skip(); } virtual void OnTextFocusLost( wxFocusEvent& event ) { event.Skip(); }
virtual void OnClear( wxCommandEvent& event ) { event.Skip(); } virtual void OnClear( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSelectItemClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnPolarChanged( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); }
public: public:
DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Position Relative"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_POSITION_RELATIVE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Position Relative To Reference Item"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_POSITION_RELATIVE_BASE(); ~DIALOG_POSITION_RELATIVE_BASE();
}; };

View File

@ -1598,9 +1598,11 @@ void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
void PCB_EDIT_FRAME::moveExact() void PCB_EDIT_FRAME::moveExact()
{ {
MOVE_PARAMETERS params; wxPoint translation;
double rotation;
ROTATION_ANCHOR rotationAnchor = ROTATE_AROUND_ITEM_ANCHOR;
DIALOG_MOVE_EXACT dialog( this, params ); DIALOG_MOVE_EXACT dialog( this, translation, rotation, rotationAnchor );
int ret = dialog.ShowModal(); int ret = dialog.ShowModal();
if( ret == wxID_OK ) if( ret == wxID_OK )
@ -1616,43 +1618,23 @@ void PCB_EDIT_FRAME::moveExact()
// Could be moved or rotated // Could be moved or rotated
SaveCopyInUndoList( itemToSave, UR_CHANGED ); SaveCopyInUndoList( itemToSave, UR_CHANGED );
// begin with the default anchor item->Move( translation );
wxPoint anchorPoint = item->GetPosition();
if( item->Type() == PCB_MODULE_T ) switch( rotationAnchor )
{ {
// cast to module to allow access to the pads case ROTATE_AROUND_ITEM_ANCHOR:
MODULE* mod = static_cast<MODULE*>( item ); item->Rotate( item->GetPosition(), rotation );
break;
switch( params.anchor ) case ROTATE_AROUND_USER_ORIGIN:
{ item->Rotate( GetScreen()->m_O_Curseur, rotation );
case ANCHOR_TOP_LEFT_PAD: break;
if( mod->GetTopLeftPad()->GetAttribute() == PAD_ATTRIB_SMD ) case ROTATE_AROUND_AUX_ORIGIN:
{ item->Rotate( GetAuxOrigin(), rotation );
anchorPoint = mod->GetTopLeftPad()->GetBoundingBox().GetPosition(); break;
} default:
else wxFAIL_MSG( "Rotation choice shouldn't have been available in this context." );
{
anchorPoint = mod->GetTopLeftPad()->GetPosition();
}
break;
case ANCHOR_CENTER_FOOTPRINT:
anchorPoint = mod->GetFootprintRect().GetCenter();
break;
case ANCHOR_FROM_LIBRARY:
; // nothing to do
}
} }
if( params.origin == RELATIVE_TO_CURRENT_POSITION )
{
anchorPoint = wxPoint( 0, 0 );
}
wxPoint finalMoveVector = params.translation - anchorPoint;
item->Move( finalMoveVector );
item->Rotate( item->GetPosition(), params.rotation );
m_canvas->Refresh(); m_canvas->Refresh();
} }
} }

View File

@ -845,11 +845,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
void FOOTPRINT_EDIT_FRAME::moveExact() void FOOTPRINT_EDIT_FRAME::moveExact()
{ {
MOVE_PARAMETERS params; wxPoint translation;
params.allowOverride = false; double rotation;
params.editingFootprint = true; ROTATION_ANCHOR rotationAnchor = ROTATE_AROUND_ITEM_ANCHOR;
DIALOG_MOVE_EXACT dialog( this, params ); DIALOG_MOVE_EXACT dialog( this, translation, rotation, rotationAnchor );
int ret = dialog.ShowModal(); int ret = dialog.ShowModal();
if( ret == wxID_OK ) if( ret == wxID_OK )
@ -858,17 +858,22 @@ void FOOTPRINT_EDIT_FRAME::moveExact()
BOARD_ITEM* item = GetScreen()->GetCurItem(); BOARD_ITEM* item = GetScreen()->GetCurItem();
wxPoint anchorPoint = item->GetPosition(); item->Move( translation );
if( params.origin == RELATIVE_TO_CURRENT_POSITION ) switch( rotationAnchor )
{ {
anchorPoint = wxPoint( 0, 0 ); case ROTATE_AROUND_ITEM_ANCHOR:
item->Rotate( item->GetPosition(), rotation );
break;
case ROTATE_AROUND_USER_ORIGIN:
item->Rotate( GetScreen()->m_O_Curseur, rotation );
break;
default:
wxFAIL_MSG( "Rotation choice shouldn't have been available in this context." );
} }
wxPoint finalMoveVector = params.translation - anchorPoint;
item->Move( finalMoveVector ); item->Rotate( item->GetPosition(), rotation );
item->Rotate( item->GetPosition(), params.rotation );
m_canvas->Refresh(); m_canvas->Refresh();
} }
@ -898,15 +903,25 @@ void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform )
case ID_MODEDIT_MODULE_MOVE_EXACT: case ID_MODEDIT_MODULE_MOVE_EXACT:
{ {
MOVE_PARAMETERS params; wxPoint translation;
double rotation;
ROTATION_ANCHOR rotationAnchor = ROTATE_AROUND_ITEM_ANCHOR;
DIALOG_MOVE_EXACT dialog( this, params ); DIALOG_MOVE_EXACT dialog( this, translation, rotation, rotationAnchor );
int ret = dialog.ShowModal();
if( ret == wxID_OK ) if( dialog.ShowModal() == wxID_OK )
{ {
MoveMarkedItemsExactly( module, wxPoint( 0, 0 ), switch( rotationAnchor )
params.translation, params.rotation, true ); {
case ROTATE_AROUND_ITEM_ANCHOR:
MoveMarkedItemsExactly( module, module->GetPosition() + translation, translation, rotation, true );
break;
case ROTATE_AROUND_USER_ORIGIN:
MoveMarkedItemsExactly( module, GetScreen()->m_O_Curseur, translation, rotation, true );
break;
default:
wxFAIL_MSG( "Rotation choice shouldn't have been available in this context." );
}
} }
break; break;

View File

@ -185,80 +185,6 @@ TOOL_ACTION PCB_ACTIONS::cutToClipboard( "pcbnew.InteractiveEdit.CutToClipboard"
_( "Cut" ), _( "Cut selected content to clipboard" ), _( "Cut" ), _( "Cut selected content to clipboard" ),
cut_xpm ); cut_xpm );
static wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS &params )
{
wxPoint anchorPoint;
if( params.origin == RELATIVE_TO_CURRENT_POSITION )
{
return wxPoint( 0, 0 );
}
// set default anchor
VECTOR2I rp = selection.GetCenter();
anchorPoint = wxPoint( rp.x, rp.y );
// If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override.
// Also run through this block if only one item is slected because it may be a module,
// in which case we want something different than the center of the selection
if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) )
{
BOARD_ITEM* topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftModule() );
// no module found if the GetTopLeftModule() returns null
if( topLeftItem != nullptr )
{
if( topLeftItem->Type() == PCB_MODULE_T )
{
// Cast to module to allow access to the pads
MODULE* mod = static_cast<MODULE*>( topLeftItem );
switch( params.anchor )
{
case ANCHOR_FROM_LIBRARY:
anchorPoint = mod->GetPosition();
break;
case ANCHOR_TOP_LEFT_PAD:
topLeftItem = mod->GetTopLeftPad();
break;
case ANCHOR_CENTER_FOOTPRINT:
anchorPoint = mod->GetFootprintRect().GetCenter();
break;
}
}
if( topLeftItem->Type() == PCB_PAD_T )
{
if( static_cast<D_PAD*>( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD )
{
// Use the top left corner of SMD pads as an anchor instead of the center
anchorPoint = topLeftItem->GetBoundingBox().GetPosition();
}
else
{
anchorPoint = topLeftItem->GetPosition();
}
}
}
else // no module found in the selection
{
// in a selection of non-modules
if( params.anchor == ANCHOR_TOP_LEFT_PAD )
{
// approach the top left pad override for non-modules by using the position of
// the topleft item as an anchor
topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
anchorPoint = topLeftItem->GetPosition();
}
}
}
return anchorPoint;
}
void filterItems( GENERAL_COLLECTOR& aCollector, bool sanitizePads, bool ensureEditable ) void filterItems( GENERAL_COLLECTOR& aCollector, bool sanitizePads, bool ensureEditable )
{ {
// Iterate from the back so we don't have to worry about removals. // Iterate from the back so we don't have to worry about removals.
@ -340,6 +266,7 @@ bool EDIT_TOOL::Init()
m_defaultSelectionFilter = SanitizePadsEnsureEditableFilter; m_defaultSelectionFilter = SanitizePadsEnsureEditableFilter;
// Allow pad editing in Footprint Editor
if( editFrame->IsType( FRAME_PCB_MODULE_EDITOR ) ) if( editFrame->IsType( FRAME_PCB_MODULE_EDITOR ) )
m_defaultSelectionFilter = EnsureEditableFilter; m_defaultSelectionFilter = EnsureEditableFilter;
@ -930,7 +857,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() ) if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() )
return 0; return 0;
// get a copy instead of reference (as we're going to clear the selectio before removing items) // get a copy instead of reference (as we're going to clear the selection before removing items)
auto selection = m_selectionTool->RequestSelection( m_defaultSelectionFilter ); auto selection = m_selectionTool->RequestSelection( m_defaultSelectionFilter );
if( m_selectionTool->CheckLock() == SELECTION_LOCKED ) if( m_selectionTool->CheckLock() == SELECTION_LOCKED )
@ -974,32 +901,46 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
return 0; return 0;
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
wxPoint translation;
double rotation;
ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
: ROTATE_AROUND_ITEM_ANCHOR;
MOVE_PARAMETERS params; DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor );
params.editingFootprint = m_editModules;
DIALOG_MOVE_EXACT dialog( editFrame, params );
int ret = dialog.ShowModal(); int ret = dialog.ShowModal();
if( ret == wxID_OK ) if( ret == wxID_OK )
{ {
VECTOR2I rp = selection.GetCenter(); VECTOR2I rp = selection.GetCenter();
wxPoint rotPoint( rp.x, rp.y ); wxPoint selCenter( rp.x, rp.y );
wxPoint anchorPoint = getAnchorPoint( selection, params );
wxPoint finalMoveVector = params.translation - anchorPoint;
// Make sure the rotation is from the right reference point // Make sure the rotation is from the right reference point
rotPoint += finalMoveVector; selCenter += translation;
for( auto item : selection ) for( auto selItem : selection )
{ {
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selItem );
if( !item->IsNew() ) if( !item->IsNew() )
m_commit->Modify( item ); m_commit->Modify( item );
static_cast<BOARD_ITEM*>( item )->Move( finalMoveVector ); item->Move( translation );
static_cast<BOARD_ITEM*>( item )->Rotate( rotPoint, params.rotation );
switch( rotationAnchor )
{
case ROTATE_AROUND_ITEM_ANCHOR:
item->Rotate( item->GetPosition(), rotation );
break;
case ROTATE_AROUND_SEL_CENTER:
item->Rotate( selCenter, rotation );
break;
case ROTATE_AROUND_USER_ORIGIN:
item->Rotate( editFrame->GetScreen()->m_O_Curseur, rotation );
break;
case ROTATE_AROUND_AUX_ORIGIN:
item->Rotate( editFrame->GetAuxOrigin(), rotation );
break;
}
if( !m_dragging ) if( !m_dragging )
getView()->Update( item ); getView()->Update( item );

View File

@ -53,10 +53,11 @@ TOOL_ACTION PCB_ACTIONS::selectpositionRelativeItem(
POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() : POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() :
PCB_TOOL( "pcbnew.PositionRelative" ), m_position_relative_dialog( NULL ), PCB_TOOL( "pcbnew.PositionRelative" ),
m_selectionTool( NULL ), m_anchor_item( NULL ) m_position_relative_dialog( NULL ),
m_selectionTool( NULL ),
m_anchor_item( NULL )
{ {
m_position_relative_rotation = 0.0;
} }
@ -93,18 +94,15 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
if( selection.Empty() ) if( selection.Empty() )
return 0; return 0;
m_position_relative_selection = selection; m_position_relative_selection = selection;
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
m_position_relative_rotation = 0;
if( !m_position_relative_dialog ) if( !m_position_relative_dialog )
m_position_relative_dialog = new DIALOG_POSITION_RELATIVE( editFrame, m_position_relative_dialog = new DIALOG_POSITION_RELATIVE( editFrame,
m_toolMgr, m_toolMgr,
m_position_relative_translation, m_position_relative_translation,
m_position_relative_rotation, m_anchor_position );
m_anchor_position );
m_position_relative_dialog->Show( true ); m_position_relative_dialog->Show( true );
@ -121,7 +119,7 @@ static bool selectPRitem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
const SELECTION& selection = selectionTool->RequestSelection( SanitizePadsFilter ); const SELECTION& selection = selectionTool->RequestSelection( EnsureEditableFilter );
if( selection.Empty() ) if( selection.Empty() )
return true; return true;
@ -179,7 +177,7 @@ void POSITION_RELATIVE_TOOL::UpdateAnchor( BOARD_ITEM* aItem )
m_anchor_item = aItem; m_anchor_item = aItem;
if( m_position_relative_dialog ) if( m_position_relative_dialog )
m_position_relative_dialog->UpdateAnchor( aItem->GetPosition() ); m_position_relative_dialog->UpdateAnchor( aItem );
} }

View File

@ -105,16 +105,13 @@ private:
///> Last anchor item selected by Position Relative To function. ///> Last anchor item selected by Position Relative To function.
BOARD_ITEM* m_anchor_item; BOARD_ITEM* m_anchor_item;
///> Translation for position relative function. ///> Translation for Position Relative To function.
wxPoint m_position_relative_translation; wxPoint m_position_relative_translation;
///> Anchor position for positive relative function. ///> Anchor position for Position Relative To function.
wxPoint m_anchor_position; wxPoint m_anchor_position;
///> Rotation for positive relative function. ///> Selection that will be moved by Position Relative To function.
double m_position_relative_rotation;
///> Selected that will be moved by Position relative function.
SELECTION m_position_relative_selection; SELECTION m_position_relative_selection;
}; };