diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 7e4121997d..13cce90257 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -675,6 +675,8 @@ void PCB_EDIT_FRAME::setupUIConditions() mgr->SetConditions( PCB_ACTIONS::zoneFill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) ); mgr->SetConditions( PCB_ACTIONS::zoneUnfill, ENABLE( SELECTION_CONDITIONS::MoreThan( 0 ) ) ); + mgr->SetConditions( PCB_ACTIONS::toggleLine45degMode, CHECK( cond.Line45degMode() ) ); + #define CURRENT_TOOL( action ) mgr->SetConditions( action, CHECK( cond.CurrentTool( action ) ) ) diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 5fe0c0391b..46f2ac9a1b 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -455,6 +455,10 @@ void PCB_EDIT_FRAME::ReCreateVToolbar() zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll ); m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawZone, std::move( zoneMenu ) ); + std::unique_ptr lineMenu = std::make_unique( false, selTool ); + lineMenu->Add( PCB_ACTIONS::toggleLine45degMode, ACTION_MENU::CHECK ); + m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawLine, std::move( lineMenu ) ); + m_drawToolBar->KiRealize(); } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 61c004eb04..630dcd123c 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1236,6 +1236,14 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) } +int DRAWING_TOOL::ToggleLine45degMode( const TOOL_EVENT& toolEvent ) +{ + m_frame->Settings().m_Use45DegreeGraphicSegments = !m_frame->Settings().m_Use45DegreeGraphicSegments; + + return 0; +} + + /** * Update an PCB_SHAPE from the current state of a TWO_POINT_GEOMETRY_MANAGER */ @@ -2430,4 +2438,5 @@ void DRAWING_TOOL::setTransitions() Go( &DRAWING_TOOL::PlaceText, PCB_ACTIONS::placeText.MakeEvent() ); Go( &DRAWING_TOOL::PlaceImportedGraphics, PCB_ACTIONS::placeImportedGraphics.MakeEvent() ); Go( &DRAWING_TOOL::SetAnchor, PCB_ACTIONS::setAnchor.MakeEvent() ); + Go( &DRAWING_TOOL::ToggleLine45degMode, PCB_ACTIONS::toggleLine45degMode.MakeEvent() ); } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 6b0daac4f5..099f13ceae 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -159,6 +159,11 @@ public: */ int SetAnchor( const TOOL_EVENT& aEvent ); + /** + * Toggle the 45 degree angle constraint for graphic lines. + */ + int ToggleLine45degMode( const TOOL_EVENT& aEvent ); + ///< Set up handlers for various events. void setTransitions() override; diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index 78cb0e5941..ab14e6e11b 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -24,6 +24,7 @@ */ #include "pcb_actions.h" +#include "tool/tool_event.h" #include #include #include @@ -211,6 +212,10 @@ TOOL_ACTION PCB_ACTIONS::closeOutline( "pcbnew.InteractiveDrawing.closeOutline", _( "Close Outline" ), _( "Close the in progress outline" ), checked_ok_xpm ); +TOOL_ACTION PCB_ACTIONS::toggleLine45degMode( "pcbnew.InteractiveDrawing.line45degMode", + AS_GLOBAL, 0, "", + _( "Limit Lines to 45 deg" ), _( "Limit graphic lines to H, V and 45 degrees" ), + nullptr, AF_NONE ); // DRC // diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 44d43a5804..282d58c0d0 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -165,6 +165,9 @@ public: static TOOL_ACTION deleteLastPoint; static TOOL_ACTION closeOutline; + /// Toggle 45 degree line drawing mode + static TOOL_ACTION toggleLine45degMode; + /// Increase width of currently drawn line static TOOL_ACTION incWidth; diff --git a/pcbnew/tools/pcb_editor_conditions.cpp b/pcbnew/tools/pcb_editor_conditions.cpp index 326d83cf15..8b56a302ef 100644 --- a/pcbnew/tools/pcb_editor_conditions.cpp +++ b/pcbnew/tools/pcb_editor_conditions.cpp @@ -23,6 +23,7 @@ */ +#include "pcbnew_settings.h" #include #include #include @@ -122,6 +123,16 @@ SELECTION_CONDITION PCB_EDITOR_CONDITIONS::ZoneDisplayMode( ZONE_DISPLAY_MODE aM } +SELECTION_CONDITION PCB_EDITOR_CONDITIONS::Line45degMode() +{ + PCB_BASE_FRAME* drwFrame = dynamic_cast( m_frame ); + + wxASSERT( drwFrame ); + + return std::bind( &PCB_EDITOR_CONDITIONS::line45degModeFunc, _1, drwFrame ); +} + + bool PCB_EDITOR_CONDITIONS::hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) { BOARD* board = aFrame->GetBoard(); @@ -171,3 +182,8 @@ bool PCB_EDITOR_CONDITIONS::zoneDisplayModeFunc( const SELECTION& aSelection, PC { return aFrame->GetDisplayOptions().m_ZoneDisplayMode == aMode; } + +bool PCB_EDITOR_CONDITIONS::line45degModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ) +{ + return aFrame->Settings().m_Use45DegreeGraphicSegments; +} diff --git a/pcbnew/tools/pcb_editor_conditions.h b/pcbnew/tools/pcb_editor_conditions.h index e347f830d1..c9804fd489 100644 --- a/pcbnew/tools/pcb_editor_conditions.h +++ b/pcbnew/tools/pcb_editor_conditions.h @@ -87,7 +87,7 @@ public: SELECTION_CONDITION ViaFillDisplay(); /** - * Create a functor that tests if the frame fills vias + * Create a functor that tests if the frame fills tracks * * @return Functor returning true if tracks are filled */ @@ -101,6 +101,13 @@ public: */ SELECTION_CONDITION ZoneDisplayMode( ZONE_DISPLAY_MODE aMode ); + /** + * Create a functor that tests whether only 45 degree graphic lines should be drawn + * + * @return Functor returning true if only 45 degree graphic lines should be drawn + */ + SELECTION_CONDITION Line45degMode(); + protected: ///< Helper function used by HasItems() static bool hasItemsFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); @@ -126,6 +133,9 @@ protected: ///< Helper function used by ZoneDisplayMode() static bool zoneDisplayModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame, ZONE_DISPLAY_MODE aMode ); + + ///< Helper function used by Line45degMode() + static bool line45degModeFunc( const SELECTION& aSelection, PCB_BASE_FRAME* aFrame ); }; #endif /* PCB_EDITOR_CONDITIONS_H_ */