int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); if( !hoverSelection() || m_selectionTool->CheckLock() == SELECTION_LOCKED ) return 0; wxPoint rotatePoint = getModificationPoint( selection ); for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i ); m_commit->Modify( item ); item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); } if( !m_dragging ) m_commit->Push( _( "Rotate" ) ); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); // TODO selectionModified m_toolMgr->RunAction( COMMON_ACTIONS::editModifiedSelection, true ); return 0; }
int TOOL_EVT_UTILS::GetEventRotationAngle( const PCB_BASE_EDIT_FRAME& aFrame, const TOOL_EVENT& aEvt ) { wxASSERT_MSG( IsRotateToolEvt( aEvt ), "Expected rotation event" ); const int rotAngle = aFrame.GetRotationAngle(); const int angleMultiplier = aEvt.Parameter<intptr_t>(); return rotAngle * angleMultiplier; }
int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); // Shall the selection be cleared at the end? bool unselect = selection.Empty(); if( !makeSelection( selection ) || m_selectionTool->CheckLock() ) { setTransitions(); return 0; } wxPoint rotatePoint = getModificationPoint( selection ); if( !m_dragging ) // If it is being dragged, then it is already saved with UR_CHANGED flag { editFrame->OnModify(); editFrame->SaveCopyInUndoList( selection.items, UR_ROTATED, rotatePoint ); } for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i ); item->Rotate( rotatePoint, editFrame->GetRotationAngle() ); if( !m_dragging ) item->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); } updateRatsnest( m_dragging ); // Update dragging offset (distance between cursor and the first dragged item) m_offset = static_cast<BOARD_ITEM*>( selection.items.GetPickedItem( 0 ) )->GetPosition() - rotatePoint; if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else getModel<BOARD>()->GetRatsnest()->Recalculate(); if( unselect ) m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true ); setTransitions(); return 0; }