Position Relative Move tool fixes

- corrected copyright headers
- code formatting
- made dialog pointer private, added UpdateAnchor() and modified click
handler routine accordingly
- renamed .fbp file to match other dialogs pattern
This commit is contained in:
Maciej Suminski 2017-06-12 16:21:06 +02:00
parent aeb23188f1
commit fc58bd3848
5 changed files with 37 additions and 35 deletions

View File

@ -1,8 +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) 2014 John Beard, john.j.beard@gmail.com * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2014 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
@ -187,7 +186,7 @@ void DIALOG_POSITION_RELATIVE::OnSelectItemClick( wxCommandEvent& event )
} }
void DIALOG_POSITION_RELATIVE::UpdateAchor( BOARD_ITEM* aBoardItem ) void DIALOG_POSITION_RELATIVE::UpdateAnchor( BOARD_ITEM* aBoardItem )
{ {
m_anchor_position = aBoardItem->GetPosition(); m_anchor_position = aBoardItem->GetPosition();

View File

@ -1,8 +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) 2014 John Beard, john.j.beard@gmail.com * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2014 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
@ -47,7 +46,7 @@ public:
double& rotation, wxPoint& anchorposition ); double& rotation, wxPoint& anchorposition );
~DIALOG_POSITION_RELATIVE(); ~DIALOG_POSITION_RELATIVE();
void UpdateAchor( BOARD_ITEM* aBoardItem ); void UpdateAnchor( BOARD_ITEM* aBoardItem );
private: private:

View File

@ -1,9 +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) 2013-2015 CERN * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* 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
@ -90,8 +88,10 @@ TOOL_ACTION PCB_ACTIONS::selectpositionRelativeItem(
"", "",
nullptr ); nullptr );
POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() : POSITION_RELATIVE_TOOL::POSITION_RELATIVE_TOOL() :
PCB_TOOL( "pcbnew.PositionRelative" ), m_selectionTool( NULL ) PCB_TOOL( "pcbnew.PositionRelative" ), m_position_relative_dialog( NULL ),
m_selectionTool( NULL ), m_anchor_item( NULL )
{ {
} }
@ -115,7 +115,6 @@ bool POSITION_RELATIVE_TOOL::Init()
return false; return false;
} }
return true; return true;
} }
@ -136,7 +135,6 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
m_position_relative_rotation = 0; 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,
@ -150,15 +148,12 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent )
} }
static bool selectPRitem( TOOL_MANAGER* aToolMgr, static bool selectPRitem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
BOARD_ITEM* m_anchor_item,
const VECTOR2D& aPosition )
{ {
SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>(); SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
POSITION_RELATIVE_TOOL* positionRelativeTool = aToolMgr->GetTool<POSITION_RELATIVE_TOOL>(); POSITION_RELATIVE_TOOL* positionRelativeTool = aToolMgr->GetTool<POSITION_RELATIVE_TOOL>();
wxCHECK( selectionTool, false );
assert( selectionTool ); wxCHECK( positionRelativeTool, false );
assert( positionRelativeTool );
aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true ); aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
@ -169,18 +164,12 @@ static bool selectPRitem( TOOL_MANAGER* aToolMgr,
if( selection.Empty() ) if( selection.Empty() )
return true; return true;
m_anchor_item = static_cast<BOARD_ITEM*>( selection.Front() ); positionRelativeTool->UpdateAnchor( static_cast<BOARD_ITEM*>( selection.Front() ) );
positionRelativeTool->m_position_relative_dialog->UpdateAchor( m_anchor_item );
return true; return true;
} }
BOARD_ITEM* POSITION_RELATIVE_TOOL::GetAnchorItem()
{
return m_anchor_item;
}
int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint anchorPosition, int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint anchorPosition,
wxPoint relativePosition, wxPoint relativePosition,
double rotation ) double rotation )
@ -215,7 +204,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent
assert( picker ); assert( picker );
picker->SetSnapping( false ); picker->SetSnapping( false );
picker->SetClickHandler( std::bind( selectPRitem, m_toolMgr, m_anchor_item, _1 ) ); picker->SetClickHandler( std::bind( selectPRitem, m_toolMgr, _1 ) );
picker->Activate(); picker->Activate();
Wait(); Wait();
@ -223,6 +212,15 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent
} }
void POSITION_RELATIVE_TOOL::UpdateAnchor( BOARD_ITEM* aItem )
{
m_anchor_item = aItem;
if( m_position_relative_dialog )
m_position_relative_dialog->UpdateAnchor( aItem );
}
void POSITION_RELATIVE_TOOL::SetTransitions() void POSITION_RELATIVE_TOOL::SetTransitions()
{ {
Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() ); Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() );

View File

@ -1,9 +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) 2013-2015 CERN * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* 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
@ -49,12 +47,11 @@ class POSITION_RELATIVE_TOOL : public PCB_TOOL
public: public:
POSITION_RELATIVE_TOOL(); POSITION_RELATIVE_TOOL();
void Reset( RESET_REASON aReason ); void Reset( RESET_REASON aReason ) override;
/// @copydoc POSITION_RELATIVE_TOOL::Init() /// @copydoc POSITION_RELATIVE_TOOL::Init()
bool Init() override; bool Init() override;
/** /**
* Function PositionRelative() * Function PositionRelative()
* *
@ -82,18 +79,27 @@ public:
* *
* Gets the last selected anchor item. * Gets the last selected anchor item.
*/ */
BOARD_ITEM* GetAnchorItem(); BOARD_ITEM* GetAnchorItem()
{
return m_anchor_item;
}
/**
* Function UpdateAnchor()
*
* Selects the item to be used as the reference for relative move operation.
*/
void UpdateAnchor( BOARD_ITEM* aItem );
///> Sets up handlers for various events. ///> Sets up handlers for various events.
void SetTransitions() override; void SetTransitions() override;
private:
DIALOG_POSITION_RELATIVE* m_position_relative_dialog; DIALOG_POSITION_RELATIVE* m_position_relative_dialog;
private:
///> Selection tool used for obtaining selected items ///> Selection tool used for obtaining selected items
SELECTION_TOOL* m_selectionTool; SELECTION_TOOL* m_selectionTool;
std::unique_ptr<BOARD_COMMIT> m_commit; std::unique_ptr<BOARD_COMMIT> m_commit;
///> Last anchor item selected by Position Relative To function. ///> Last anchor item selected by Position Relative To function.