diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 3a58214467..985df05f5b 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -25,16 +25,11 @@ #include "drawing_tool.h" #include "pcb_actions.h" - #include -#include -#include -#include #include #include #include #include -#include #include #include #include @@ -42,11 +37,8 @@ #include #include #include -#include "grid_helper.h" -#include "point_editor.h" #include #include -#include // for KiROUND #include #include @@ -58,6 +50,8 @@ #include #include #include +#include +#include #include using SCOPED_DRAW_MODE = SCOPED_SET_RESET; @@ -639,7 +633,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - PCB_LAYER_ID layer = getDrawingLayer(); + PCB_LAYER_ID layer = m_frame->GetActiveLayer(); if( layer == Edge_Cuts ) // dimensions are not allowed on EdgeCuts layer = Dwgs_User; @@ -966,8 +960,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN POINT_EDITOR* pointEditor = m_toolMgr->GetTool(); DRAWSEGMENT*& graphic = *aGraphic; - m_lineWidth = getSegmentWidth( getDrawingLayer() ); - m_frame->SetActiveLayer( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); // Add a VIEW_GROUP that serves as a preview for the new item PCBNEW_SELECTION preview; @@ -996,7 +989,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); - cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), getDrawingLayer() ); + cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ); m_controls->ForceCursorPosition( true, cursorPos ); // 45 degree angle constraint enabled with an option and toggled with Ctrl @@ -1072,8 +1065,8 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN } else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) { - m_lineWidth = getSegmentWidth( getDrawingLayer() ); - graphic->SetLayer( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); + graphic->SetLayer( m_frame->GetActiveLayer() ); graphic->SetWidth( m_lineWidth ); m_view->Update( &preview ); frame()->SetMsgPanel( graphic ); @@ -1094,14 +1087,14 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN aStartingPoint = NULLOPT; } - m_lineWidth = getSegmentWidth( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); // Init the new item attributes graphic->SetShape( (STROKE_T) aShape ); graphic->SetWidth( m_lineWidth ); graphic->SetStart( (wxPoint) cursorPos ); graphic->SetEnd( (wxPoint) cursorPos ); - graphic->SetLayer( getDrawingLayer() ); + graphic->SetLayer( m_frame->GetActiveLayer() ); grid.SetSkipPoint( cursorPos ); if( !isLocalOriginSet ) @@ -1224,7 +1217,7 @@ static void updateArcFromConstructionMgr( const KIGFX::PREVIEW::ARC_GEOM_MANAGER bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bool aImmediateMode ) { DRAWSEGMENT*& graphic = *aGraphic; - m_lineWidth = getSegmentWidth( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); // Arc geometric construction manager KIGFX::PREVIEW::ARC_GEOM_MANAGER arcManager; @@ -1253,7 +1246,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo // Main loop: keep receiving events while( TOOL_EVENT* evt = Wait() ) { - PCB_LAYER_ID layer = getDrawingLayer(); + PCB_LAYER_ID layer = m_frame->GetActiveLayer(); graphic->SetLayer( layer ); m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); @@ -1311,7 +1304,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); - m_lineWidth = getSegmentWidth( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); // Init the new item attributes // (non-geometric, those are handled by the manager) @@ -1338,8 +1331,8 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo } else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) { - m_lineWidth = getSegmentWidth( getDrawingLayer() ); - graphic->SetLayer( getDrawingLayer() ); + m_lineWidth = getSegmentWidth( m_frame->GetActiveLayer() ); + graphic->SetLayer( m_frame->GetActiveLayer() ); graphic->SetWidth( m_lineWidth ); m_view->Update( &preview ); frame()->SetMsgPanel( graphic ); @@ -1462,9 +1455,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) params.m_mode = zoneMode; params.m_sourceZone = sourceZone; - if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON ) - params.m_layer = getDrawingLayer(); - else if( zoneMode == ZONE_MODE::SIMILAR ) + if( zoneMode == ZONE_MODE::SIMILAR ) params.m_layer = sourceZone->GetLayer(); else params.m_layer = m_frame->GetActiveLayer(); @@ -1550,9 +1541,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) } else if( evt->IsAction( &PCB_ACTIONS::layerChanged ) ) { - if( zoneMode == ZONE_MODE::GRAPHIC_POLYGON ) - params.m_layer = getDrawingLayer(); - else if( zoneMode == ZONE_MODE::ADD || zoneMode == ZONE_MODE::CUTOUT ) + if( zoneMode != ZONE_MODE::SIMILAR ) params.m_layer = frame()->GetActiveLayer(); } else if( evt->IsClick( BUT_RIGHT ) ) @@ -1954,27 +1943,6 @@ int DRAWING_TOOL::getSegmentWidth( PCB_LAYER_ID aLayer ) const } -PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer() const -{ - PCB_LAYER_ID layer = m_frame->GetActiveLayer(); - - if( ( GetDrawingMode() == MODE::DIMENSION || GetDrawingMode() == MODE::GRAPHIC_POLYGON ) - && IsCopperLayer( layer ) ) - { - if( layer == F_Cu ) - layer = F_SilkS; - else if( layer == B_Cu ) - layer = B_SilkS; - else - layer = Dwgs_User; - - m_frame->SetActiveLayer( layer ); - } - - return layer; -} - - const unsigned int DRAWING_TOOL::WIDTH_STEP = Millimeter2iu( 0.1 ); diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 082608b109..7726fe4f09 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -224,8 +224,6 @@ private: ///> Returns the appropriate width for a segment depending on the settings. int getSegmentWidth( PCB_LAYER_ID aLayer ) const; - PCB_LAYER_ID getDrawingLayer() const; - KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_controls; BOARD* m_board; diff --git a/pcbnew/tools/zone_create_helper.cpp b/pcbnew/tools/zone_create_helper.cpp index 24492f3c00..f9a5123e47 100644 --- a/pcbnew/tools/zone_create_helper.cpp +++ b/pcbnew/tools/zone_create_helper.cpp @@ -213,12 +213,12 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) graphicPolygonsLayers.reset( Edge_Cuts ).reset( F_CrtYd ).reset( B_CrtYd ); - if( graphicPolygonsLayers.Contains( m_tool.getDrawingLayer() ) ) + if( graphicPolygonsLayers.Contains( m_params.m_layer ) ) { auto poly = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent ) : new DRAWSEGMENT(); poly->SetShape ( S_POLYGON ); - poly->SetLayer( m_tool.getDrawingLayer() ); + poly->SetLayer( m_params.m_layer ); poly->SetPolyShape ( *aZone->Outline() ); bCommit.Add( poly ); m_tool.GetManager()->RunAction( PCB_ACTIONS::selectItem, true, poly ); @@ -232,7 +232,7 @@ void ZONE_CREATE_HELPER::commitZone( std::unique_ptr aZone ) auto new_seg = m_tool.m_editModules ? new EDGE_MODULE( (MODULE *) parent ) : new DRAWSEGMENT(); new_seg->SetShape( S_SEGMENT ); - new_seg->SetLayer( m_tool.getDrawingLayer() ); + new_seg->SetLayer( m_params.m_layer ); new_seg->SetStart( wxPoint( seg.Get().A.x, seg.Get().A.y ) ); new_seg->SetEnd( wxPoint( seg.Get().B.x, seg.Get().B.y ) ); bCommit.Add( new_seg );