Appy units updating more consistently to editing assistants.

Fixes https://gitlab.com/kicad/code/kicad/issues/6283
This commit is contained in:
Jeff Young 2020-11-04 14:08:06 +00:00
parent f6c17001e4
commit 8c782506b9
5 changed files with 41 additions and 27 deletions

View File

@ -246,7 +246,6 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
break;
}
}
else if( evt->IsActivate() )
{
if( originSet )
@ -263,7 +262,6 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
break;
}
}
// click or drag starts
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
{
@ -275,7 +273,6 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
originSet = true;
}
// second click or mouse up after drag ends
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
{
@ -284,7 +281,6 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
controls.SetAutoPan( false );
controls.CaptureCursor( false );
}
// move or drag when origin set updates rules
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
{
@ -294,9 +290,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
view.SetVisible( &ruler, true );
view.Update( &ruler, KIGFX::GEOMETRY );
}
else if( evt->IsAction( &ACTIONS::toggleUnits )
|| evt->IsAction( &ACTIONS::updateUnits ) )
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
if( m_frame->GetUserUnits() != units )
{
@ -304,15 +298,16 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
ruler.SwitchUnits( units );
view.Update( &ruler, KIGFX::GEOMETRY );
}
evt->SetPassEvent();
}
else if( evt->IsClick( BUT_RIGHT ) )
{
m_menu.ShowContextMenu( m_frame->GetCurrentSelection() );
}
else
{
evt->SetPassEvent();
}
}
view.SetVisible( &ruler, false );

View File

@ -65,6 +65,8 @@ namespace PREVIEW
return "ARC_ASSISTANT";
}
void SetUnits( EDA_UNITS aUnits ) { m_units = aUnits; }
private:
const ARC_GEOM_MANAGER& m_constructMan;
EDA_UNITS m_units;

View File

@ -82,6 +82,8 @@ public:
return "TWO_POINT_ASSISTANT";
}
void SetUnits( EDA_UNITS aUnits ) { m_units = aUnits; }
private:
const TWO_POINT_GEOMETRY_MANAGER& m_constructMan;
EDA_UNITS m_units;

View File

@ -1168,7 +1168,8 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( m_frame->IsGridVisible() );
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() );
VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(),
LSET::AllLayersMask() );
m_controls->ForceCursorPosition( true, cursorPos );
if( evt->IsClick( BUT_LEFT ) )
@ -1208,10 +1209,10 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
/**
* Update an PCB_SHAPE from the current state of an Two POINT Geometry Manager
* Update an PCB_SHAPE from the current state of a TWO_POINT_GEOMETRY_MANAGER
*/
static void updateSegmentFromConstructionMgr(
const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER& aMgr, PCB_SHAPE* aGraphic )
static void updateSegmentFromGeometryMgr( const KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER& aMgr,
PCB_SHAPE* aGraphic )
{
auto vec = aMgr.GetOrigin();
@ -1238,8 +1239,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, PCB_SHAPE*
// drawing assistant overlay
// TODO: workaround because PCB_SHAPE_TYPE_T is not visible from commons.
KIGFX::PREVIEW::GEOM_SHAPE geomShape( static_cast<KIGFX::PREVIEW::GEOM_SHAPE>( aShape ) );
KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst(
twoPointManager, m_frame->GetUserUnits(), geomShape );
KIGFX::PREVIEW::TWO_POINT_ASSISTANT twoPointAsst( twoPointManager, m_frame->GetUserUnits(),
geomShape );
// Add a VIEW_GROUP that serves as a preview for the new item
PCBNEW_SELECTION preview;
@ -1383,7 +1384,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, PCB_SHAPE*
m_controls->SetAutoPan( true );
m_controls->CaptureCursor( true );
updateSegmentFromConstructionMgr( twoPointManager, graphic );
updateSegmentFromGeometryMgr( twoPointManager, graphic );
started = true;
}
@ -1440,7 +1441,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, PCB_SHAPE*
twoPointManager.SetAngleSnap( false );
}
updateSegmentFromConstructionMgr( twoPointManager, graphic );
updateSegmentFromGeometryMgr( twoPointManager, graphic );
m_view->Update( &preview );
m_view->Update( &twoPointAsst );
}
@ -1463,6 +1464,12 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, PCB_SHAPE*
isLocalOriginSet = true;
evt->SetPassEvent();
}
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
twoPointAsst.SetUnits( frame()->GetUserUnits() );
m_view->Update( &twoPointAsst );
evt->SetPassEvent();
}
else
{
evt->SetPassEvent();
@ -1666,6 +1673,12 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool
{
arcManager.ToggleClockwise();
}
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
arcAsst.SetUnits( frame()->GetUserUnits() );
m_view->Update( &arcAsst );
evt->SetPassEvent();
}
else
{
evt->SetPassEvent();
@ -1889,7 +1902,6 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_controls->SetAutoPan( false );
m_controls->CaptureCursor( false );
}
// adding a corner
else if( polyGeomMgr.AddPoint( cursorPos ) )
{
@ -1943,6 +1955,14 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
frame()->SetMsgPanel( zoneTool.GetZone() );
}
}
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
// If we ever have an assistant here that reports dimensions, we'll want to
// update its units here....
// zoneAsst.SetUnits( frame()->GetUserUnits() );
// m_view->Update( &zoneAsst );
evt->SetPassEvent();
}
else
{
evt->SetPassEvent();

View File

@ -256,7 +256,6 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
break;
}
}
else if( evt->IsActivate() )
{
if( originSet )
@ -273,7 +272,6 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
break;
}
}
// click or drag starts
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
{
@ -285,7 +283,6 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
originSet = true;
}
// second click or mouse up after drag ends
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
{
@ -294,7 +291,6 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
controls.SetAutoPan( false );
controls.CaptureCursor( false );
}
// move or drag when origin set updates rules
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
{
@ -304,9 +300,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
view.SetVisible( &ruler, true );
view.Update( &ruler, KIGFX::GEOMETRY );
}
else if( evt->IsAction( &ACTIONS::toggleUnits )
|| evt->IsAction( &ACTIONS::updateUnits ) )
else if( evt->IsAction( &ACTIONS::updateUnits ) )
{
if( frame()->GetUserUnits() != units )
{
@ -315,15 +309,16 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
view.Update( &ruler, KIGFX::GEOMETRY );
canvas()->Refresh();
}
evt->SetPassEvent();
}
else if( evt->IsClick( BUT_RIGHT ) )
{
m_menu.ShowContextMenu();
}
else
{
evt->SetPassEvent();
}
}
view.SetVisible( &ruler, false );