From dc0cf3b802a0ef1995711b6d7fdd4f54f187b3b5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 10 Apr 2021 10:31:42 +0100 Subject: [PATCH] Clean up a confusing API. AllowDRCViolations is kept in any mode as a *setting*, but only controls router behaviour when the mode is mark obstacles. Fixes https://gitlab.com/kicad/code/kicad/issues/7795 --- pcbnew/dialogs/dialog_pns_settings.cpp | 8 ++++---- pcbnew/router/pns_component_dragger.cpp | 3 ++- pcbnew/router/pns_diff_pair_placer.cpp | 5 ++--- pcbnew/router/pns_dragger.cpp | 4 ++-- pcbnew/router/pns_line_placer.cpp | 4 ++-- pcbnew/router/pns_router.cpp | 2 +- pcbnew/router/pns_routing_settings.cpp | 4 ++-- pcbnew/router/pns_routing_settings.h | 18 +++++++++--------- pcbnew/tools/drawing_tool.cpp | 5 ++--- 9 files changed, 26 insertions(+), 27 deletions(-) diff --git a/pcbnew/dialogs/dialog_pns_settings.cpp b/pcbnew/dialogs/dialog_pns_settings.cpp index fd2e1337eb..83bd6fa26a 100644 --- a/pcbnew/dialogs/dialog_pns_settings.cpp +++ b/pcbnew/dialogs/dialog_pns_settings.cpp @@ -44,7 +44,7 @@ DIALOG_PNS_SETTINGS::DIALOG_PNS_SETTINGS( wxWindow* aParent, PNS::ROUTING_SETTIN m_smartPads->SetValue( m_settings.SmartPads() ); m_effort->SetValue( m_settings.OptimizerEffort() ); m_smoothDragged->SetValue( m_settings.SmoothDraggedSegments() ); - m_violateDrc->SetValue( m_settings.CanViolateDRC() ); + m_violateDrc->SetValue( m_settings.GetAllowDRCViolationsSetting() ); m_freeAngleMode->SetValue( m_settings.GetFreeAngleMode() ); m_dragToolMode->SetSelection ( m_settings.InlineDragEnabled() ? 1 : 0 ); m_optimizeDraggedTrack->SetValue( m_settings.GetOptimizeDraggedTrack() ); @@ -83,7 +83,7 @@ void DIALOG_PNS_SETTINGS::OnOkClick( wxCommandEvent& aEvent ) if( m_mode->GetSelection() == PNS::RM_MarkObstacles ) { - m_settings.SetCanViolateDRC( m_violateDrc->GetValue() ); + m_settings.SetAllowDRCViolations( m_violateDrc->GetValue() ); m_settings.SetFreeAngleMode( m_freeAngleMode->GetValue() ); } @@ -98,7 +98,7 @@ void DIALOG_PNS_SETTINGS::onModeChange( wxCommandEvent& aEvent ) m_freeAngleMode->SetValue( m_settings.GetFreeAngleMode() ); m_freeAngleMode->Enable(); - m_violateDrc->SetValue( m_settings.CanViolateDRC() ); + m_violateDrc->SetValue( m_settings.GetAllowDRCViolationsSetting() ); m_violateDrc->Enable(); } else @@ -110,7 +110,7 @@ void DIALOG_PNS_SETTINGS::onModeChange( wxCommandEvent& aEvent ) m_freeAngleMode->Enable( false ); if( m_violateDrc->IsEnabled() ) - m_settings.SetCanViolateDRC( m_violateDrc->GetValue() ); + m_settings.SetAllowDRCViolations( m_violateDrc->GetValue() ); m_violateDrc->SetValue( false ); m_violateDrc->Enable( false ); diff --git a/pcbnew/router/pns_component_dragger.cpp b/pcbnew/router/pns_component_dragger.cpp index 311bc3f007..5fcbba63ec 100644 --- a/pcbnew/router/pns_component_dragger.cpp +++ b/pcbnew/router/pns_component_dragger.cpp @@ -163,7 +163,8 @@ bool COMPONENT_DRAGGER::FixRoute() if( node ) { bool ok; - if( Settings().CanViolateDRC() ) + + if( Settings().AllowDRCViolations() ) ok = true; else ok = !node->CheckColliding( m_draggedItems ); diff --git a/pcbnew/router/pns_diff_pair_placer.cpp b/pcbnew/router/pns_diff_pair_placer.cpp index 25ff16f17b..6a541c6908 100644 --- a/pcbnew/router/pns_diff_pair_placer.cpp +++ b/pcbnew/router/pns_diff_pair_placer.cpp @@ -713,11 +713,10 @@ void DIFF_PAIR_PLACER::UpdateSizes( const SIZES_SETTINGS& aSizes ) bool DIFF_PAIR_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish ) { - if( !m_fitOk && !Settings().CanViolateDRC() ) + if( !m_fitOk && !Settings().AllowDRCViolations() ) return false; - if( m_currentTrace.CP().SegmentCount() < 1 || - m_currentTrace.CN().SegmentCount() < 1 ) + if( m_currentTrace.CP().SegmentCount() < 1 || m_currentTrace.CN().SegmentCount() < 1 ) return false; if( m_currentTrace.CP().SegmentCount() > 1 ) diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 3c744e7ae8..5e5844ab81 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -256,7 +256,7 @@ bool DRAGGER::dragMarkObstacles( const VECTOR2I& aP ) } } - if( Settings().CanViolateDRC() ) + if( Settings().AllowDRCViolations() ) m_dragStatus = true; else m_dragStatus = !m_world->CheckColliding( m_draggedItems ); @@ -619,7 +619,7 @@ bool DRAGGER::FixRoute() return false; } - if( !m_dragStatus && !Settings().CanViolateDRC() ) + if( !m_dragStatus && !Settings().AllowDRCViolations() ) return false; Router()->CommitRouting( node ); diff --git a/pcbnew/router/pns_line_placer.cpp b/pcbnew/router/pns_line_placer.cpp index c856d07c71..5390e8cabd 100644 --- a/pcbnew/router/pns_line_placer.cpp +++ b/pcbnew/router/pns_line_placer.cpp @@ -520,7 +520,7 @@ bool LINE_PLACER::rhMarkObstacles( const VECTOR2I& aP, LINE& aNewHead ) m_head.SetBlockingObstacle( nullptr ); // If we are enforcing DRC violations, push back to the hull - if( !Settings().CanViolateDRC() ) + if( !Settings().AllowDRCViolations() ) { NODE::OPT_OBSTACLE obs = m_currentNode->NearestObstacle( &m_head ); @@ -1048,7 +1048,7 @@ bool LINE_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinis } // Collisions still prevent fixing unless "Allow DRC violations" is checked - if( !Settings().CanViolateDRC() && m_world->CheckColliding( &pl ) ) + if( !Settings().AllowDRCViolations() && m_world->CheckColliding( &pl ) ) return false; } diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index d8c9221bcf..4c9494a315 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -182,7 +182,7 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM bool ROUTER::isStartingPointRoutable( const VECTOR2I& aWhere, ITEM* aStartItem, int aLayer ) { - if( Settings().CanViolateDRC() && Settings().Mode() == RM_MarkObstacles ) + if( Settings().AllowDRCViolations() ) return true; if( m_mode == PNS_MODE_ROUTE_DIFF_PAIR ) diff --git a/pcbnew/router/pns_routing_settings.cpp b/pcbnew/router/pns_routing_settings.cpp index 45b973a8f3..9324624d64 100644 --- a/pcbnew/router/pns_routing_settings.cpp +++ b/pcbnew/router/pns_routing_settings.cpp @@ -45,7 +45,7 @@ ROUTING_SETTINGS::ROUTING_SETTINGS( JSON_SETTINGS* aParent, const std::string& a m_walkaroundIterationLimit = 40; m_jumpOverObstacles = false; m_smoothDraggedSegments = true; - m_canViolateDRC = false; + m_allowDRCViolations = false; m_freeAngleMode = false; m_inlineDragEnabled = false; m_snapToTracks = false; @@ -85,7 +85,7 @@ ROUTING_SETTINGS::ROUTING_SETTINGS( JSON_SETTINGS* aParent, const std::string& a m_params.emplace_back( new PARAM( "smooth_dragged_segments", &m_smoothDraggedSegments, true ) ); - m_params.emplace_back( new PARAM( "can_violate_drc", &m_canViolateDRC, false ) ); + m_params.emplace_back( new PARAM( "can_violate_drc", &m_allowDRCViolations, false ) ); m_params.emplace_back( new PARAM( "free_angle_mode", &m_freeAngleMode, false ) ); m_params.emplace_back( new PARAM( "inline_drag", &m_inlineDragEnabled, false ) ); m_params.emplace_back( new PARAM( "snap_to_tracks", &m_snapToTracks, false ) ); diff --git a/pcbnew/router/pns_routing_settings.h b/pcbnew/router/pns_routing_settings.h index dfcbeee766..0bf62dd240 100644 --- a/pcbnew/router/pns_routing_settings.h +++ b/pcbnew/router/pns_routing_settings.h @@ -119,17 +119,17 @@ public: ///< Return true if jumping over unmovable obstacles is on. bool JumpOverObstacles() const { return m_jumpOverObstacles; } - - ///< Enable/disable jumping over unmovable obstacles. - void SetJumpOverObstacles( bool aJumpOverObstacles ) - { - m_jumpOverObstacles = aJumpOverObstacles; - } + void SetJumpOverObstacles( bool aJump ) { m_jumpOverObstacles = aJump; } void SetStartDiagonal( bool aStartDiagonal ) { m_startDiagonal = aStartDiagonal; } - bool CanViolateDRC() const { return m_canViolateDRC; } - void SetCanViolateDRC( bool aViolate ) { m_canViolateDRC = aViolate; } + bool AllowDRCViolations() const + { + return m_routingMode == PNS_MODE::RM_MarkObstacles && m_allowDRCViolations; + } + + bool GetAllowDRCViolationsSetting() const { return m_allowDRCViolations; } + void SetAllowDRCViolations( bool aViolate ) { m_allowDRCViolations = aViolate; } bool GetFreeAngleMode() const { return m_freeAngleMode; } @@ -173,7 +173,7 @@ private: bool m_followMouse; bool m_jumpOverObstacles; bool m_smoothDraggedSegments; - bool m_canViolateDRC; + bool m_allowDRCViolations; bool m_freeAngleMode; bool m_inlineDragEnabled; bool m_snapToTracks; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 3d63f71633..b446281d4f 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -2218,10 +2218,9 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) m_worstClearance( 0 ), m_flaggedDRC( false ) { - ROUTER_TOOL* router = m_frame->GetToolManager()->GetTool(); - PNS::ROUTING_SETTINGS& cfg = router->Router()->Settings(); + ROUTER_TOOL* router = m_frame->GetToolManager()->GetTool(); - m_allowDRCViolations = cfg.Mode() == PNS::RM_MarkObstacles && cfg.CanViolateDRC(); + m_allowDRCViolations = router->Router()->Settings().AllowDRCViolations(); try {