Connect ruler tool with axes preferences

Adds "UpdatePreferences" action that is called when the preferences are
updated, allowing running tools to act on changes that may affect them

Fixes https://gitlab.com/kicad/code/kicad/issues/9737
This commit is contained in:
Seth Hillbrand 2021-11-23 12:51:37 -08:00
parent 65fc47cb8f
commit f97c7c78c8
7 changed files with 50 additions and 11 deletions

View File

@ -287,6 +287,10 @@ void EDA_DRAW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
viewControls->LoadSettings();
m_galDisplayOptions.ReadCommonConfig( *settings, this );
// Notify all tools the preferences have changed
if( m_toolManager )
m_toolManager->RunAction( ACTIONS::updatePreferences, true );
}

View File

@ -54,13 +54,21 @@ static int getShadowLayer( KIGFX::GAL* aGal )
static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
const VECTOR2D& aRulerVec, EDA_UNITS aUnits,
bool aDrawingDropShadows )
bool aDrawingDropShadows, bool aFlipX, bool aFlipY )
{
// draw the cursor labels
std::vector<wxString> cursorStrings;
cursorStrings.push_back( DimensionLabel( "x", aRulerVec.x, aUnits ) );
cursorStrings.push_back( DimensionLabel( "y", aRulerVec.y, aUnits ) );
VECTOR2D temp = aRulerVec;
if( aFlipX )
temp.x = -temp.x;
if( aFlipY )
temp.y = -temp.y;
cursorStrings.push_back( DimensionLabel( "x", temp.x, aUnits ) );
cursorStrings.push_back( DimensionLabel( "y", temp.y, aUnits ) );
cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aUnits ) );
@ -68,7 +76,7 @@ static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), degs,
EDA_UNITS::DEGREES ) );
auto temp = aRulerVec;
temp = aRulerVec;
DrawTextNextToCursor( aView, aCursor, -temp, cursorStrings, aDrawingDropShadows );
}
@ -258,10 +266,13 @@ void drawBacksideTicks( KIGFX::VIEW* aView, const VECTOR2D& aOrigin, const VECTO
}
RULER_ITEM::RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& aGeomMgr, EDA_UNITS userUnits )
RULER_ITEM::RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& aGeomMgr, EDA_UNITS userUnits,
bool aFlipX, bool aFlipY )
: EDA_ITEM( NOT_USED ), // Never added to anything - just a preview
m_geomMgr( aGeomMgr ),
m_userUnits( userUnits )
m_userUnits( userUnits ),
m_flipX( aFlipX ),
m_flipY( aFlipY )
{
}
@ -318,7 +329,7 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
VECTOR2D rulerVec( end - origin );
drawCursorStrings( aView, end, rulerVec, m_userUnits, drawingDropShadows );
drawCursorStrings( aView, end, rulerVec, m_userUnits, drawingDropShadows, m_flipX, m_flipY );
// basic tick size
const double minorTickLen = 5.0 / gal->GetWorldScale();

View File

@ -499,6 +499,9 @@ TOOL_ACTION ACTIONS::millimetersUnits( "common.Control.metricUnits",
TOOL_ACTION ACTIONS::updateUnits( "common.Control.updateUnits",
AS_GLOBAL );
TOOL_ACTION ACTIONS::updatePreferences( "common.Control.updatePreferences",
AS_GLOBAL );
TOOL_ACTION ACTIONS::toggleUnits( "common.Control.toggleUnits",
AS_GLOBAL,
MD_CTRL + 'U', LEGACY_HK_NAME( "Switch Units" ),
@ -653,7 +656,6 @@ TOOL_ACTION ACTIONS::reportBug( "common.SuiteControl.reportBug",
_( "Report a problem with KiCad" ),
BITMAPS::bug );
// System-wide selection Events
const TOOL_EVENT EVENTS::SelectedEvent( TC_MESSAGE, TA_ACTION, "common.Interactive.selected" );

View File

@ -205,7 +205,7 @@ int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
bool originSet = false;
TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
EDA_UNITS units = m_frame->GetUserUnits();
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units, false, false );
std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool );

View File

@ -41,7 +41,8 @@ class TWO_POINT_GEOMETRY_MANAGER;
class RULER_ITEM : public EDA_ITEM
{
public:
RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& m_geomMgr, EDA_UNITS userUnits );
RULER_ITEM( const TWO_POINT_GEOMETRY_MANAGER& m_geomMgr, EDA_UNITS userUnits, bool aFlipX,
bool aFlipY );
///< @copydoc EDA_ITEM::ViewBBox()
const BOX2I ViewBBox() const override;
@ -75,9 +76,17 @@ public:
*/
void SwitchUnits( EDA_UNITS aUnits ) { m_userUnits = aUnits; }
void UpdateDir( bool aFlipX, bool aFlipY )
{
m_flipX = aFlipX;
m_flipY = aFlipY;
}
private:
const TWO_POINT_GEOMETRY_MANAGER& m_geomMgr;
EDA_UNITS m_userUnits;
bool m_flipX;
bool m_flipY;
};
} // PREVIEW

View File

@ -167,6 +167,7 @@ public:
static TOOL_ACTION updateMenu;
static TOOL_ACTION activatePointEditor;
static TOOL_ACTION changeEditMethod;
static TOOL_ACTION updatePreferences;
// Suite
static TOOL_ACTION openPreferences;

View File

@ -207,7 +207,9 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
bool originSet = false;
EDA_UNITS units = frame()->GetUserUnits();
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units,
frame()->GetDisplayOptions().m_DisplayInvertXAxis,
frame()->GetDisplayOptions().m_DisplayInvertYAxis );
view.Add( &ruler );
view.SetVisible( &ruler, false );
@ -313,6 +315,16 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
view.Update( &ruler, KIGFX::GEOMETRY );
canvas()->Refresh();
}
evt->SetPassEvent();
}
else if( evt->IsAction( &ACTIONS::updatePreferences ) )
{
ruler.UpdateDir( frame()->GetDisplayOptions().m_DisplayInvertXAxis,
frame()->GetDisplayOptions().m_DisplayInvertYAxis );
view.Update( &ruler, KIGFX::GEOMETRY );
canvas()->Refresh();
evt->SetPassEvent();
}
else if( evt->IsClick( BUT_RIGHT ) )