Smarten up double-click handing in PCBNew drawing tool.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15700
This commit is contained in:
Jeff Young 2023-09-24 18:49:22 +01:00
parent c2c71facb1
commit aef0f44b8e
2 changed files with 17 additions and 48 deletions

View File

@ -46,7 +46,6 @@ public:
{ {
m_origin = aOrigin; m_origin = aOrigin;
m_originSet = true; m_originSet = true;
setGeometryChanged();
} }
VECTOR2I GetOrigin() const VECTOR2I GetOrigin() const
@ -63,8 +62,6 @@ public:
m_end = GetVectorSnapped45( aEnd - m_origin ) + m_origin; m_end = GetVectorSnapped45( aEnd - m_origin ) + m_origin;
else else
m_end = aEnd; m_end = aEnd;
setGeometryChanged();
} }
VECTOR2I GetEnd() const VECTOR2I GetEnd() const
@ -96,41 +93,19 @@ public:
void Reset() void Reset()
{ {
m_originSet = false; m_originSet = false;
setGeometryChanged();
} }
/** bool IsEmpty() const
* @return true if the geometry has changed, eg such that a client should redraw.
*/
bool HasGeometryChanged() const
{ {
return m_changed; return !m_originSet || m_origin == m_end;
}
/**
* 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;
} }
private: private:
VECTOR2I m_origin, m_end; VECTOR2I m_origin;
bool m_angleSnap = false; VECTOR2I m_end;
bool m_angleSnap = false;
///< Has the geometry changed such that a client should redraw? bool m_originSet = false;
bool m_changed = false;
bool m_originSet = false;
}; };
} // PREVIEW } // PREVIEW

View File

@ -1985,29 +1985,23 @@ bool DRAWING_TOOL::drawShape( const TOOL_EVENT& aTool, PCB_SHAPE** aGraphic,
{ {
PCB_SHAPE* snapItem = dynamic_cast<PCB_SHAPE*>( grid.GetSnapped() ); PCB_SHAPE* snapItem = dynamic_cast<PCB_SHAPE*>( grid.GetSnapped() );
if( shape == SHAPE_T::SEGMENT && ( twoPointMgr.GetOrigin() == twoPointMgr.GetEnd() if( shape == SHAPE_T::SEGMENT && snapItem && graphic->GetLength() > 0 )
|| evt->IsDblClick( BUT_LEFT )
|| snapItem ) )
{ {
// User has clicked twice in the same spot // User has clicked on the end of an existing segment, closing a path
// or clicked on the end of an existing segment (closing a path)
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
// If the user clicks on an existing snap point from a drawsegment commit.Add( graphic );
// we finish the segment as they are likely closing a path commit.Push( _( "Draw Line" ) );
if( snapItem && graphic->GetLength() > 0.0 ) m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, graphic );
{
commit.Add( graphic );
commit.Push( _( "Draw Line" ) );
m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, graphic );
}
else
{
delete graphic;
}
graphic = nullptr; 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(); preview.Clear();
twoPointMgr.Reset(); twoPointMgr.Reset();