diff --git a/include/preview_items/two_point_geom_manager.h b/include/preview_items/two_point_geom_manager.h index a7302830d7..12b152d462 100644 --- a/include/preview_items/two_point_geom_manager.h +++ b/include/preview_items/two_point_geom_manager.h @@ -46,7 +46,6 @@ public: { m_origin = aOrigin; m_originSet = true; - setGeometryChanged(); } VECTOR2I GetOrigin() const @@ -63,8 +62,6 @@ public: m_end = GetVectorSnapped45( aEnd - m_origin ) + m_origin; else m_end = aEnd; - - setGeometryChanged(); } VECTOR2I GetEnd() const @@ -96,41 +93,19 @@ public: void Reset() { m_originSet = false; - setGeometryChanged(); } - /** - * @return true if the geometry has changed, eg such that a client should redraw. - */ - bool HasGeometryChanged() const + bool IsEmpty() const { - return m_changed; - } - - /** - * Clear the geometry changed flag, call after the client code has updated everything as - * needed. - */ - void ClearGeometryChanged() - { - m_changed = false; - } - -protected: - ///< Mark the geometry as changed for clients to notice - void setGeometryChanged() - { - m_changed = true; + return !m_originSet || m_origin == m_end; } private: - VECTOR2I m_origin, m_end; - bool m_angleSnap = false; - - ///< Has the geometry changed such that a client should redraw? - bool m_changed = false; - bool m_originSet = false; + VECTOR2I m_origin; + VECTOR2I m_end; + bool m_angleSnap = false; + bool m_originSet = false; }; } // PREVIEW diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index b10f2182a2..5fa47b54f5 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1985,29 +1985,23 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic, { PCB_SHAPE* snapItem = dynamic_cast( grid.GetSnapped() ); - if( shape == SHAPE_T::SEGMENT && ( twoPointMgr.GetOrigin() == twoPointMgr.GetEnd() - || evt->IsDblClick( BUT_LEFT ) - || snapItem ) ) + if( shape == SHAPE_T::SEGMENT && snapItem && graphic->GetLength() > 0 ) { - // User has clicked twice in the same spot - // or clicked on the end of an existing segment (closing a path) + // User has clicked on the end of an existing segment, closing a path BOARD_COMMIT commit( m_frame ); - // If the user clicks on an existing snap point from a drawsegment - // we finish the segment as they are likely closing a path - if( snapItem && graphic->GetLength() > 0.0 ) - { - commit.Add( graphic ); - commit.Push( _( "Draw Line" ) ); - m_toolMgr->RunAction( PCB_ACTIONS::selectItem, graphic ); - } - else - { - delete graphic; - } + commit.Add( graphic ); + commit.Push( _( "Draw Line" ) ); + m_toolMgr->RunAction( PCB_ACTIONS::selectItem, graphic ); graphic = nullptr; } + else if( twoPointMgr.IsEmpty() || evt->IsDblClick( BUT_LEFT ) ) + { + // User has clicked twice in the same spot, meaning we're finished + delete graphic; + graphic = nullptr; + } preview.Clear(); twoPointMgr.Reset();