From 5ea46e8b783becfde589d52e3a9bbab70ef55305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20W=C5=82ostowski?= Date: Mon, 20 May 2019 20:51:24 +0200 Subject: [PATCH] eemodern: initial attempt at inline drag/move actions --- .../dialogs/panel_eeschema_settings_base.fbp | 805 +++++++++++++++++- eeschema/eeschema_config.cpp | 12 + eeschema/sch_edit_frame.h | 16 + eeschema/tools/ee_actions.h | 1 + eeschema/tools/ee_selection_tool.cpp | 31 +- eeschema/tools/sch_edit_tool.cpp | 4 +- eeschema/tools/sch_move_tool.cpp | 58 +- 7 files changed, 909 insertions(+), 18 deletions(-) diff --git a/eeschema/dialogs/panel_eeschema_settings_base.fbp b/eeschema/dialogs/panel_eeschema_settings_base.fbp index 8f0b643627..1cd762d3fb 100644 --- a/eeschema/dialogs/panel_eeschema_settings_base.fbp +++ b/eeschema/dialogs/panel_eeschema_settings_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -49,6 +49,43 @@ wxTAB_TRAVERSAL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bPanelSizer @@ -138,6 +175,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -202,7 +269,37 @@ + + + + + + + + OnChooseUnits + + + + + + + + + + + + + + + + + + + + + + @@ -274,6 +371,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -338,6 +465,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -399,6 +560,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -460,6 +651,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -524,6 +745,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -585,6 +840,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -646,6 +931,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -710,6 +1025,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -771,6 +1120,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -832,6 +1211,36 @@ -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -894,6 +1303,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -979,6 +1421,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1043,6 +1516,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1059,6 +1563,7 @@ wxVERTICAL 1 none + 5 wxEXPAND|wxTOP|wxRIGHT|wxLEFT @@ -1121,6 +1626,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1185,6 +1721,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1249,6 +1816,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + wxID_ANY + Editing + + sbSizer11 + wxVERTICAL + 1 + none + + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Warp mouse to origin of moved object(s) + + 0 + + + 0 + + 1 + m_moveWarpsCursor + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxTOP|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Use cursor position as editing anchor + + 0 + + + 0 + + 1 + m_moveTakesCursorAsOrigin + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 60bb6344a7..e6c657b884 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -335,6 +335,10 @@ const wxChar RescueNeverShowEntry[] = wxT( "RescueNeverShow" ); const wxChar AutoplaceFieldsEntry[] = wxT( "AutoplaceFields" ); const wxChar AutoplaceJustifyEntry[] = wxT( "AutoplaceJustify" ); const wxChar AutoplaceAlignEntry[] = wxT( "AutoplaceAlign" ); +static const wxChar MoveWarpsCursorEntry[] = wxT( "MoveWarpsCursor" ); +static const wxChar MoveTakesCursorAsOriginEntry[] = wxT( "MoveTakesCursorAsOrigin" ); +static const wxChar DragActionIsMoveEntry[] = wxT( "DragActionIsMove" ); +static const wxChar DragAlwaysSelectsEntry[] = wxT( "DragAlwaysSelects" ); static const wxChar FootprintPreviewEntry[] = wxT( "FootprintPreview" ); static const wxChar DefaultBusWidthEntry[] = wxT( "DefaultBusWidth" ); static const wxChar DefaultDrawLineWidthEntry[] = wxT( "DefaultDrawLineWidth" ); @@ -413,6 +417,10 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) SetDefaultBusThickness( (int) aCfg->Read( DefaultBusWidthEntry, DEFAULTBUSTHICKNESS ) ); SetDefaultLineThickness( (int) aCfg->Read( DefaultDrawLineWidthEntry, DEFAULTDRAWLINETHICKNESS ) ); SCH_JUNCTION::SetSymbolSize( (int) aCfg->Read( DefaultJctSizeEntry, SCH_JUNCTION::GetSymbolSize() ) ); + aCfg->Read( MoveWarpsCursorEntry, &m_moveWarpsCursor, true ); + aCfg->Read( MoveTakesCursorAsOriginEntry, &m_moveTakesCursorAsOrigin, false ); + aCfg->Read( DragActionIsMoveEntry, &m_dragActionIsMove, true ); + aCfg->Read( DragAlwaysSelectsEntry, &m_dragAlwaysSelects, false ); aCfg->Read( ShowHiddenPinsEntry, &m_showAllPins, false ); aCfg->Read( HorzVertLinesOnlyEntry, &m_forceHVLines, true ); aCfg->Read( AutoplaceFieldsEntry, &m_autoplaceFields, true ); @@ -482,6 +490,10 @@ void SCH_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg ) wxConfigSaveSetups( aCfg, GetConfigurationSettings() ); + aCfg->Write( MoveWarpsCursorEntry, m_moveWarpsCursor ); + aCfg->Write( MoveTakesCursorAsOriginEntry, m_moveTakesCursorAsOrigin ); + aCfg->Write( DragActionIsMoveEntry, m_dragActionIsMove ); + aCfg->Write( DragAlwaysSelectsEntry, m_dragAlwaysSelects ); aCfg->Write( DefaultBusWidthEntry, (long) GetDefaultBusThickness() ); aCfg->Write( DefaultDrawLineWidthEntry, (long) GetDefaultLineThickness() ); aCfg->Write( DefaultJctSizeEntry, (long) SCH_JUNCTION::GetSymbolSize() ); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index f1324aba9e..44dd45c03f 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -136,6 +136,10 @@ private: bool m_autoplaceJustify; ///< allow autoplace to change justification bool m_autoplaceAlign; ///< align autoplaced fields to the grid bool m_footprintPreview; ///< whether to show footprint previews + bool m_moveTakesCursorAsOrigin; ///< eemodern: always take the cursor (instead of item origin) as move anchor + bool m_dragActionIsMove; ///< eemodern: if true, drag action defaults to move, otherwise it's drag + bool m_dragAlwaysSelects; ///< eemodern: if true, drag action only selects items (and never drags/moves) + bool m_moveWarpsCursor; ///< eemodern: if true, cursor is warped to move/drag origin /// An index to the last find item in the found items list #m_foundItems. int m_foundItemIndex; @@ -206,6 +210,18 @@ public: void OnCloseWindow( wxCloseEvent& Event ); + void SetMoveTakesCursorAsOrigin( bool aValue ) { m_moveTakesCursorAsOrigin = aValue; } + bool GetMoveTakesCursorAsOrigin() const { return m_moveTakesCursorAsOrigin; } + + void SetDragActionIsMove( bool aValue ) { m_dragActionIsMove = aValue; } + bool GetDragActionIsMove() const { return m_dragActionIsMove; } + + void SetDragAlwaysSelects( bool aValue ) { m_dragAlwaysSelects = aValue; } + bool GetDragAlwaysSelects() const { return m_dragAlwaysSelects; } + + void SetMoveWarpsCursor( bool aValue ) { m_moveWarpsCursor = aValue; } + bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; } + bool GetForceHVLines() const { return m_forceHVLines; } void SetForceHVLines( bool aForceHVdirection ) { m_forceHVLines = aForceHVdirection; } diff --git a/eeschema/tools/ee_actions.h b/eeschema/tools/ee_actions.h index 6592657cce..8ee03db6f7 100644 --- a/eeschema/tools/ee_actions.h +++ b/eeschema/tools/ee_actions.h @@ -113,6 +113,7 @@ public: static TOOL_ACTION finishDrawing; // Editing + static TOOL_ACTION moveActivate; static TOOL_ACTION move; static TOOL_ACTION drag; static TOOL_ACTION duplicate; diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 1dfb161df5..69233ac5fe 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -290,6 +290,26 @@ int EE_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent ) int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { + const KICAD_T movableItems[] = + { + SCH_MARKER_T, + SCH_JUNCTION_T, + SCH_NO_CONNECT_T, + SCH_BUS_BUS_ENTRY_T, + SCH_BUS_WIRE_ENTRY_T, + SCH_LINE_T, + SCH_BITMAP_T, + SCH_TEXT_T, + SCH_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_HIER_LABEL_T, + SCH_FIELD_T, + SCH_COMPONENT_T, + SCH_SHEET_PIN_T, + SCH_SHEET_T, + EOT + }; + // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { @@ -359,7 +379,14 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them else if( evt->IsDrag( BUT_LEFT ) ) { - if( m_additive || m_subtractive || m_selection.Empty() ) + bool stillEmpty = true; + if( m_selection.Empty() ) + { + m_selection = RequestSelection( movableItems ); + stillEmpty = m_selection.Empty(); + } + + if( m_additive || m_subtractive || stillEmpty ) { selectMultiple(); } @@ -369,7 +396,7 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) if( selectionContains( evt->Position() ) ) { // Yes -> run the move tool and wait till it finishes - m_toolMgr->InvokeTool( "eeschema.InteractiveEdit" ); + m_toolMgr->InvokeTool( "eeschema.InteractiveMove" ); } else { diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index b1e5d17344..c6217e02c1 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -547,7 +547,7 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) } else if( selection.GetSize() > 1 ) { - rotPoint = m_frame->GetNearestGridPosition( (wxPoint)selection.GetCenter() ); + rotPoint = (wxPoint)selection.GetReferencePoint(); for( unsigned ii = 0; ii < selection.GetSize(); ii++ ) { @@ -732,7 +732,7 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) } else if( selection.GetSize() > 1 ) { - mirrorPoint = m_frame->GetNearestGridPosition( (wxPoint)selection.GetCenter() ); + mirrorPoint = (wxPoint)selection.GetReferencePoint(); for( unsigned ii = 0; ii < selection.GetSize(); ii++ ) { diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index e8cd9e0578..20e4764041 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -46,6 +46,10 @@ TOOL_ACTION EE_ACTIONS::drag( "eeschema.InteractiveEdit.drag", AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DRAG ), _( "Drag" ), _( "Drags the selected item(s)" ), move_xpm, AF_ACTIVATE ); +TOOL_ACTION EE_ACTIONS::moveActivate( "eeschema.InteractiveMove", + AS_GLOBAL, 0, + _( "Move Activate" ), "", move_xpm, AF_ACTIVATE ); + // For adding to or removing from selections #define QUIET_MODE true @@ -90,6 +94,26 @@ bool SCH_MOVE_TOOL::Init() } +void SCH_MOVE_TOOL::Reset( RESET_REASON aReason ) +{ + if( aReason == MODEL_RELOAD ) + { + m_moveInProgress = false; + m_moveOffset = { 0, 0 }; + + // Init variables used by every drawing tool + m_controls = getViewControls(); + m_frame = getEditFrame(); + } +} + +/* TODO - Tom/Jeff + - add preferences option "Move origin: always cursor / item origin" + - add preferences option "Default drag action: drag items / move" + - add preferences option "Drag always selects" + */ + + int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { const KICAD_T movableItems[] = @@ -125,10 +149,16 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) if( selection.Empty() ) return 0; - if( aEvent.IsAction( &EE_ACTIONS::move ) ) + if( aEvent.IsAction( &EE_ACTIONS::move ) || aEvent.IsAction( &EE_ACTIONS::moveActivate ) ) + { m_frame->SetToolID( ID_SCH_MOVE, wxCURSOR_DEFAULT, _( "Move Items" ) ); + moveMode = true; + } else + { m_frame->SetToolID( ID_SCH_DRAG, wxCURSOR_DEFAULT, _( "Drag Items" ) ); + moveMode = false; + } Activate(); controls->ShowCursor( true ); @@ -143,14 +173,14 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { if( !selection.Front()->IsNew() ) { - // User must have switched from move to drag or vice-versa. Reset the selected - // items so we can start again with the current m_isDragOperation and m_moveOffset. - m_frame->RollbackSchematicFromUndo(); + // User must have switched from move to drag or vice-versa. Reset the moved items + // so we can start again with the current m_isDragOperation and m_moveOffset. + m_frame->RollbackSchematicFromUndo(); m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE ); - m_moveInProgress = false; - // And give it a kick so it doesn't have to wait for the first mouse movement to - // refresh. - m_toolMgr->RunAction( EE_ACTIONS::refreshPreview ); + m_moveInProgress = false; + // And give it a kick so it doesn't have to wait for the first mouse movement to + // refresh. + m_toolMgr->RunAction( EE_ACTIONS::refreshPreview ); } return 0; } @@ -160,7 +190,8 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { controls->SetSnapping( !evt->Modifier( MD_ALT ) ); - if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag ) + if( evt->IsAction( &EE_ACTIONS::moveActivate ) + || evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &EE_ACTIONS::refreshPreview ) ) { @@ -181,7 +212,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Add connections to the selection for a drag. // - if( m_frame->GetToolId() == ID_SCH_DRAG ) + if( !moveMode ) { for( EDA_ITEM* item : selection ) { @@ -200,7 +231,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Mark the edges of the block with dangling flags for a move. // - if( m_frame->GetToolId() == ID_SCH_MOVE ) + if( moveMode ) { std::vector internalPoints; @@ -247,7 +278,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) // Apply any initial offset in case we're coming from a previous command. // if( !item->GetParent() || !item->GetParent()->IsSelected() ) - moveItem( item, m_moveOffset, m_frame->GetToolId() == ID_SCH_DRAG ); + moveItem( item, m_moveOffset, !moveMode ); } // Set up the starting position and move/drag offset @@ -265,7 +296,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) if( item->GetParent() && item->GetParent()->IsSelected() ) continue; - moveItem( item, delta, m_frame->GetToolId() == ID_SCH_DRAG ); + moveItem( item, delta, !moveMode ); updateView( item ); } @@ -439,6 +470,7 @@ void SCH_MOVE_TOOL::getConnectedDragItems( SCH_ITEM* aOriginalItem, wxPoint aPoi switch( test->Type() ) { + default: case SCH_LINE_T: { // Select the connected end of wires/bus connections.