diff --git a/pcbnew/dialogs/dialog_position_relative.cpp b/pcbnew/dialogs/dialog_position_relative.cpp index 91f6adc88b..edd7691b85 100644 --- a/pcbnew/dialogs/dialog_position_relative.cpp +++ b/pcbnew/dialogs/dialog_position_relative.cpp @@ -1,8 +1,7 @@ /* * 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) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * 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(); diff --git a/pcbnew/dialogs/dialog_position_relative.h b/pcbnew/dialogs/dialog_position_relative.h index 07a854518f..2adaf0c0c6 100644 --- a/pcbnew/dialogs/dialog_position_relative.h +++ b/pcbnew/dialogs/dialog_position_relative.h @@ -1,8 +1,7 @@ /* * 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) 1992-2014 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -47,7 +46,7 @@ public: double& rotation, wxPoint& anchorposition ); ~DIALOG_POSITION_RELATIVE(); - void UpdateAchor( BOARD_ITEM* aBoardItem ); + void UpdateAnchor( BOARD_ITEM* aBoardItem ); private: diff --git a/pcbnew/dialogs/dialog_position_relative.fbp b/pcbnew/dialogs/dialog_position_relative_base.fbp similarity index 100% rename from pcbnew/dialogs/dialog_position_relative.fbp rename to pcbnew/dialogs/dialog_position_relative_base.fbp diff --git a/pcbnew/tools/position_relative_tool.cpp b/pcbnew/tools/position_relative_tool.cpp index bbe66d8ba6..fce8de099c 100644 --- a/pcbnew/tools/position_relative_tool.cpp +++ b/pcbnew/tools/position_relative_tool.cpp @@ -1,9 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013-2015 CERN - * @author Maciej Suminski - * @author Tomasz Wlostowski + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -90,8 +88,10 @@ TOOL_ACTION PCB_ACTIONS::selectpositionRelativeItem( "", nullptr ); + 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 true; } @@ -136,7 +135,6 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) PCB_BASE_FRAME* editFrame = getEditFrame(); m_position_relative_rotation = 0; - if( !m_position_relative_dialog ) m_position_relative_dialog = new DIALOG_POSITION_RELATIVE( editFrame, m_toolMgr, @@ -150,15 +148,12 @@ int POSITION_RELATIVE_TOOL::PositionRelative( const TOOL_EVENT& aEvent ) } -static bool selectPRitem( TOOL_MANAGER* aToolMgr, - BOARD_ITEM* m_anchor_item, - const VECTOR2D& aPosition ) +static bool selectPRitem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) { SELECTION_TOOL* selectionTool = aToolMgr->GetTool(); POSITION_RELATIVE_TOOL* positionRelativeTool = aToolMgr->GetTool(); - - assert( selectionTool ); - assert( positionRelativeTool ); + wxCHECK( selectionTool, false ); + wxCHECK( positionRelativeTool, false ); aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true ); @@ -169,18 +164,12 @@ static bool selectPRitem( TOOL_MANAGER* aToolMgr, if( selection.Empty() ) return true; - m_anchor_item = static_cast( selection.Front() ); - positionRelativeTool->m_position_relative_dialog->UpdateAchor( m_anchor_item ); + positionRelativeTool->UpdateAnchor( static_cast( selection.Front() ) ); + return true; } -BOARD_ITEM* POSITION_RELATIVE_TOOL::GetAnchorItem() -{ - return m_anchor_item; -} - - int POSITION_RELATIVE_TOOL::RelativeItemSelectionMove( wxPoint anchorPosition, wxPoint relativePosition, double rotation ) @@ -215,7 +204,7 @@ int POSITION_RELATIVE_TOOL::SelectPositionRelativeItem( const TOOL_EVENT& aEvent assert( picker ); picker->SetSnapping( false ); - picker->SetClickHandler( std::bind( selectPRitem, m_toolMgr, m_anchor_item, _1 ) ); + picker->SetClickHandler( std::bind( selectPRitem, m_toolMgr, _1 ) ); picker->Activate(); 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() { Go( &POSITION_RELATIVE_TOOL::PositionRelative, PCB_ACTIONS::positionRelative.MakeEvent() ); diff --git a/pcbnew/tools/position_relative_tool.h b/pcbnew/tools/position_relative_tool.h index 9e9c696e93..f7f48b2263 100644 --- a/pcbnew/tools/position_relative_tool.h +++ b/pcbnew/tools/position_relative_tool.h @@ -1,9 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013-2015 CERN - * @author Maciej Suminski - * @author Tomasz Wlostowski + * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -49,12 +47,11 @@ class POSITION_RELATIVE_TOOL : public PCB_TOOL public: POSITION_RELATIVE_TOOL(); - void Reset( RESET_REASON aReason ); + void Reset( RESET_REASON aReason ) override; /// @copydoc POSITION_RELATIVE_TOOL::Init() bool Init() override; - /** * Function PositionRelative() * @@ -82,18 +79,27 @@ public: * * 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. void SetTransitions() override; +private: DIALOG_POSITION_RELATIVE* m_position_relative_dialog; -private: ///> Selection tool used for obtaining selected items SELECTION_TOOL* m_selectionTool; - std::unique_ptr m_commit; ///> Last anchor item selected by Position Relative To function.