From 7d4cb91f390541c46bc6d99b9236fd4c1295fac8 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Fri, 25 Feb 2022 16:27:55 +0000 Subject: [PATCH] Schematic: disallow center rotation, allow both endpoint rotations Center rotation will often misalign lines to the grid, which is bad until fix off grid items on the schematic. We can rotate a connection end into a new connection or to become collinear with an existing line, so we need to check for this at the end of rotation. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/10565 --- eeschema/sch_line.cpp | 6 ++++-- eeschema/tools/ee_selection_tool.cpp | 4 ---- eeschema/tools/sch_edit_tool.cpp | 29 +++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index 64c77f4f4e..5f027967c6 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -447,10 +447,12 @@ void SCH_LINE::MirrorHorizontally( int aCenter ) void SCH_LINE::Rotate( const wxPoint& aCenter ) { + // When we allow off grid items, the + // else if should become a plain if to allow + // rotation around the center of the line if( m_flags & STARTPOINT ) RotatePoint( &m_start, aCenter, 900 ); - - if( m_flags & ENDPOINT ) + else if( m_flags & ENDPOINT ) RotatePoint( &m_end, aCenter, 900 ); } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 6eedc8e2a8..eacae9e085 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -853,10 +853,6 @@ void EE_SELECTION_TOOL::narrowSelection( EE_COLLECTOR& collector, const VECTOR2I else line->SetFlags( STARTPOINT | ENDPOINT ); } - else if( collector[i]->Type() == SCH_LINE_T ) - { - static_cast( collector[i] )->SetFlags( STARTPOINT | ENDPOINT ); - } } // Apply some ugly heuristics to avoid disambiguation menus whenever possible diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index e7664708a0..134c439d84 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -445,7 +445,6 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) int principalItemCount = 0; // User-selected items (as opposed to connected wires) wxPoint rotPoint; bool moving = false; - bool connections = false; for( unsigned ii = 0; ii < selection.GetSize(); ii++ ) { @@ -511,6 +510,28 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) } case SCH_LINE_T: + { + SCH_LINE* line = static_cast( head ); + + // Equal checks for both and neither. We need this because on undo + // the item will have both flags cleared, but will be selected, so it is possible + // for the user to get a selected line with neither endpoint selected. We + // set flags to make sure Rotate() works when we call it. + if( line->HasFlag( STARTPOINT ) == line->HasFlag( ENDPOINT ) ) + { + line->SetFlags( STARTPOINT | ENDPOINT ); + // When we allow off grid items, the rotPoint should be set to the midpoint + // of the line to allow rotation around the center, and the next if + // should become an else-if + } + + if( line->HasFlag( STARTPOINT ) ) + rotPoint = line->GetEndPoint(); + else if( line->HasFlag( ENDPOINT ) ) + rotPoint = line->GetStartPoint(); + } + + KI_FALLTHROUGH; case SCH_BUS_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T: for( int i = 0; clockwise ? i < 3 : i < 1; ++i ) @@ -557,7 +578,6 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) break; } - connections = head->IsConnectable(); m_frame->UpdateItem( head, false, true ); } else @@ -636,7 +656,6 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) } } - connections |= item->IsConnectable(); m_frame->UpdateItem( item, false, true ); updateItem( item, true ); } @@ -652,8 +671,8 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) if( selection.IsHover() ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - if( connections ) - m_frame->TestDanglingEnds(); + m_frame->RecalculateConnections( LOCAL_CLEANUP ); + m_frame->TestDanglingEnds(); m_frame->OnModify(); }