diff --git a/common/preview_items/polygon_geom_manager.cpp b/common/preview_items/polygon_geom_manager.cpp index af54ba08d2..86c64d3324 100644 --- a/common/preview_items/polygon_geom_manager.cpp +++ b/common/preview_items/polygon_geom_manager.cpp @@ -23,7 +23,7 @@ #include -#include +#include POLYGON_GEOM_MANAGER::POLYGON_GEOM_MANAGER( CLIENT& aClient ): @@ -144,24 +144,16 @@ void POLYGON_GEOM_MANAGER::updateLeaderPoints( const VECTOR2I& aEndPoint, LEADER { wxCHECK( m_lockedPoints.PointCount() > 0, /*void*/ ); const VECTOR2I& lastPt = m_lockedPoints.CLastPoint(); + auto newEnd = VECTOR2I( lastPt ); if( m_leaderMode == LEADER_MODE::DEG45 || aModifier == LEADER_MODE::DEG45 ) { + const VECTOR2I lineVector( aEndPoint - lastPt ); // get a restricted 45/H/V line from the last fixed point to the cursor - DIRECTION_45 direction( lastPt - aEndPoint ); - m_leaderPts = direction.BuildInitialTrace( lastPt, aEndPoint ); - - // Can also add chain back to start, but this rearely produces - // usable result - //SHAPE_LINE_CHAIN newChain; - //DIRECTION_45 directionToStart( aEndPoint - m_lockedPoints.front() ); - //newChain.Append( directionToStart.BuildInitialTrace( aEndPoint, m_lockedPoints.front() ) ); - } - else - { - // direct segment - m_leaderPts = SHAPE_LINE_CHAIN( lastPt, aEndPoint ); + newEnd += GetVectorSnapped45( lineVector ); } + // direct segment + m_leaderPts = SHAPE_LINE_CHAIN( lastPt, newEnd ); m_client.OnGeometryChange( *this ); } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index bc75b704fb..00b7841c39 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include #include #include @@ -933,8 +932,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, { // Only two shapes are currently supported assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); - - DRAWSEGMENT line45; GRID_HELPER grid( m_frame ); m_lineWidth = getSegmentWidth( getDrawingLayer() ); @@ -966,9 +963,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, m_controls->ForceCursorPosition( true, cursorPos ); aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); - if( aShape == S_SEGMENT ) - line45 = *aGraphic; // used only for direction 45 mode with lines - preview.Add( aGraphic ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( true ); @@ -997,12 +991,15 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, if( direction45 ) { - preview.Add( &line45 ); - make45DegLine( aGraphic, &line45, cursorPos ); + const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) ); + + // get a restricted 45/H/V line from the last fixed point to the cursor + auto newEnd = GetVectorSnapped45( lineVector ); + aGraphic->SetEnd( aGraphic->GetStart() + wxPoint( newEnd.x, newEnd.y ) ); + m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) ); } else { - preview.Remove( &line45 ); aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); } @@ -1048,9 +1045,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, if( !IsOCurseurSet ) m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y ); - if( aShape == S_SEGMENT ) - line45 = *aGraphic; // used only for direction 45 mode with lines - preview.Add( aGraphic ); frame()->SetMsgPanel( aGraphic ); m_controls->SetAutoPan( true ); @@ -1071,26 +1065,9 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, { BOARD_COMMIT commit( m_frame ); - // a clear sign that the current drawing is finished - // Now we have to add the helper line as well, unless it is zero-length - if( direction45 && line45.GetStart() != aGraphic->GetStart() ) - { - DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( mod ) : new DRAWSEGMENT; - - // Copy coordinates, layer, etc. - *l = line45; - - // If snapping, add both paths - if( snapItem && l->GetLength() > 0.0 ) - commit.Add( l->Clone() ); - - l->SetEnd( aGraphic->GetStart() ); - commit.Add( l ); - } - // If the user clicks on an existing snap point from a drawsegment // we finish the segment as they are likely closing a path - else if( snapItem && aGraphic->GetLength() > 0.0 ) + if( snapItem && aGraphic->GetLength() > 0.0 ) { DRAWSEGMENT* l = m_editModules ? new EDGE_MODULE( mod ) : new DRAWSEGMENT; @@ -1113,7 +1090,14 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, { // 45 degree lines if( direction45 && aShape == S_SEGMENT ) - make45DegLine( aGraphic, &line45, cursorPos ); + { + const VECTOR2I lineVector( cursorPos - VECTOR2I( aGraphic->GetStart() ) ); + + // get a restricted 45/H/V line from the last fixed point to the cursor + auto newEnd = GetVectorSnapped45( lineVector ); + aGraphic->SetEnd( aGraphic->GetStart() + wxPoint( newEnd.x, newEnd.y ) ); + m_controls->ForceCursorPosition( true, VECTOR2I( aGraphic->GetEnd() ) ); + } else aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); @@ -1128,7 +1112,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, { m_lineWidth += WIDTH_STEP; aGraphic->SetWidth( m_lineWidth ); - line45.SetWidth( m_lineWidth ); m_view->Update( &preview ); frame()->SetMsgPanel( aGraphic ); } @@ -1136,7 +1119,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, { m_lineWidth -= WIDTH_STEP; aGraphic->SetWidth( m_lineWidth ); - line45.SetWidth( m_lineWidth ); m_view->Update( &preview ); frame()->SetMsgPanel( aGraphic ); } @@ -1503,28 +1485,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout, ZONE_MODE aMode ) } -void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper, - VECTOR2I& aPos ) const -{ - VECTOR2I origin( aSegment->GetStart() ); - DIRECTION_45 direction( origin - aPos ); - SHAPE_LINE_CHAIN newChain = direction.BuildInitialTrace( origin, aPos ); - - if( newChain.PointCount() > 2 ) - { - aSegment->SetEnd( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) ); - aHelper->SetStart( wxPoint( newChain.Point( -2 ).x, newChain.Point( -2 ).y ) ); - aHelper->SetEnd( wxPoint( newChain.Point( -1 ).x, newChain.Point( -1 ).y ) ); - } - else - { - aSegment->SetEnd( wxPoint( aPos.x, aPos.y ) ); - aHelper->SetStart( wxPoint( aPos.x, aPos.y ) ); - aHelper->SetEnd( wxPoint( aPos.x, aPos.y ) ); - } -} - - int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) { struct VIA_PLACER : public INTERACTIVE_PLACER_BASE diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 872ea04ea0..a016916727 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -245,16 +245,6 @@ private: */ void runPolygonEventLoop( POLYGON_GEOM_MANAGER& aPolyGeomMgr ); - /** - * Function make45DegLine() - * Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin stays the same, - * the end of the aSegment is modified according to the current cursor position. - * @param aSegment is the segment that is currently drawn. - * @param aHelper is a helper line that shows the next possible segment. - * @param aPos is the position of the cursor for this event - */ - void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper, VECTOR2I& aPos ) const; - /** * Function constrainDimension() * Forces the dimension lime to be drawn on multiple of 45 degrees