From bc52f0a03b0cdea5b68eb851822bbe4dd8de5e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Mon, 20 May 2019 17:42:49 +0200 Subject: [PATCH] eemodern: clean printf debug gibberish, implement inline drag, move & cursor warp/reference point options --- eeschema/tools/ee_selection_tool.cpp | 10 +++++++ eeschema/tools/ee_selection_tool.h | 2 +- eeschema/tools/sch_move_tool.cpp | 39 +++++++++++++++++++++------- eeschema/tools/sch_move_tool.h | 2 ++ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index dddd092b82..b67e6e7f7f 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -380,12 +380,15 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) else if( evt->IsDrag( BUT_LEFT ) ) { bool empty = m_selection.Empty(); + + // selection is empty? try to start dragging the item under the point where drag started if( empty ) { m_selection = RequestSelection( movableItems ); empty = m_selection.Empty(); } + // selection STILL empty? attempt a rectangle multi-selection if( m_additive || m_subtractive || empty || m_frame->GetDragAlwaysSelects() ) { selectMultiple(); @@ -596,6 +599,13 @@ SELECTION& EE_SELECTION_TOOL::RequestSelection( const KICAD_T aFilterList[] ) clearSelection(); SelectPoint( cursorPos, aFilterList ); m_selection.SetIsHover( true ); + m_selection.ClearReferencePoint(); + } + + if( m_selection.Size() == 1 ) + { + VECTOR2I refP = ((SCH_ITEM*) m_selection.GetItem( 0 ))->GetPosition(); + m_selection.SetReferencePoint( refP ); } return m_selection; diff --git a/eeschema/tools/ee_selection_tool.h b/eeschema/tools/ee_selection_tool.h index e25020542e..44adb6ea85 100644 --- a/eeschema/tools/ee_selection_tool.h +++ b/eeschema/tools/ee_selection_tool.h @@ -237,7 +237,7 @@ private: ///> Sets up handlers for various events. void setTransitions() override; - + private: SCH_BASE_FRAME* m_frame; // Pointer to the parent frame SELECTION m_selection; // Current state of selection diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 863c0bcc7a..f13ce3de22 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -129,6 +129,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) VECTOR2I originalCursorPos = controls->GetCursorPosition(); bool moveMode; + m_anchorPoint.reset(); + // Be sure that there is at least one item that we can move. If there's no selection try // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection). SELECTION& selection = m_selectionTool->RequestSelection( movableItems ); @@ -178,6 +180,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) return 0; } + m_cursor = controls->GetCursorPosition(); + // Main loop: keep receiving events do { @@ -280,7 +284,17 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) if( selection.HasReferencePoint() ) { - VECTOR2I delta = m_cursor - selection.GetReferencePoint(); + m_anchorPoint = selection.GetReferencePoint(); + if( m_frame->GetMoveWarpsCursor() ) + { + getViewControls()->WarpCursor( *m_anchorPoint ); + m_cursor = *m_anchorPoint; + } + } + + if( m_anchorPoint ) + { + VECTOR2I delta = m_cursor - (*m_anchorPoint); // Drag items to the current cursor position for( EDA_ITEM* item : selection ) @@ -293,7 +307,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) updateView( item ); } - selection.SetReferencePoint( m_cursor ); + m_anchorPoint = m_cursor; } else if( selection.Size() == 1 ) { @@ -320,7 +334,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // m_cursor = controls->GetCursorPosition(); VECTOR2I delta( m_cursor - prevPos ); - selection.SetReferencePoint( m_cursor ); + m_anchorPoint = m_cursor; m_moveOffset += delta; prevPos = m_cursor; @@ -422,16 +436,23 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) m_moveInProgress = false; m_frame->SetNoToolSelected(); - - selection.ClearReferencePoint(); + m_anchorPoint.reset(); for( EDA_ITEM* item : selection ) item->ClearEditFlags(); if( restore_state ) { - m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); m_frame->RollbackSchematicFromUndo(); + + if( unselect ) + { + m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); + } + else + { + m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); + } } else { @@ -654,16 +675,14 @@ bool SCH_MOVE_TOOL::updateModificationPoint( SELECTION& aSelection ) // hierarchical sheets or components can have the anchor outside the view) if( item->IsMovableFromAnchorPoint() ) { - wxPoint pos = item->GetPosition(); - aSelection.SetReferencePoint( pos ); - + m_anchorPoint = item->GetPosition(); return true; } } // ...otherwise modify items with regard to the grid-snapped cursor position m_cursor = getViewControls()->GetCursorPosition( true ); - aSelection.SetReferencePoint( m_cursor ); + m_anchorPoint = m_cursor; return true; } diff --git a/eeschema/tools/sch_move_tool.h b/eeschema/tools/sch_move_tool.h index d9286f806b..679c84215e 100644 --- a/eeschema/tools/sch_move_tool.h +++ b/eeschema/tools/sch_move_tool.h @@ -80,6 +80,8 @@ private: ///> Last cursor position (needed for getModificationPoint() to avoid changes ///> of edit reference point). VECTOR2I m_cursor; + + boost::optional m_anchorPoint; }; #endif //KICAD_SCH_MOVE_TOOL_H