Commit 29a1bdb3 authored by jean-pierre charras's avatar jean-pierre charras

Fix issues in print mirror. (include some changes coming from Cirilo Berdarno's patch)

gr_basic.cpp: rewrite the function which draws the outlines of a thick segment.
parent f214a576
...@@ -623,18 +623,10 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector<wxPoint>& aLines, ...@@ -623,18 +623,10 @@ void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC, std::vector<wxPoint>& aLines,
aClipBox->Inflate(-aWidth/2); aClipBox->Inflate(-aWidth/2);
} }
// Draw the outline of a thick segment wih rounded ends
void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int width, int aPenSize, EDA_COLOR_T Color ) int width, int aPenSize, EDA_COLOR_T Color )
{ {
long radius;
int dwx, dwy;
long dx, dy, dwx2, dwy2;
long sx1, sy1, ex1, ey1;
long sx2, sy2, ex2, ey2;
bool swap_ends = false;
GRLastMoveToX = x2; GRLastMoveToX = x2;
GRLastMoveToY = y2; GRLastMoveToY = y2;
...@@ -658,114 +650,63 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -658,114 +650,63 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
GRSetColorPen( DC, Color, aPenSize ); GRSetColorPen( DC, Color, aPenSize );
GRSetBrush( DC, Color, false ); GRSetBrush( DC, Color, false );
radius = (width + 1) >> 1; int radius = (width + 1) >> 1;
int dx = x2 - x1;
dx = x2 - x1; int dy = y2 - y1;
dy = y2 - y1; double angle = -ArcTangente( dy, dx );
wxPoint start;
if( dx == 0 ) /* segment vertical */ wxPoint end;
{ wxPoint org( x1, y1);
dwx = radius; int len = (int) hypot( dx, dy );
if( dy >= 0 )
dwx = -dwx; // We know if the DC is mirrored, to draw arcs
int slx = DC->DeviceToLogicalX( 1 ) - DC->DeviceToLogicalX( 0 );
sx1 = x1 - dwx; int sly = DC->DeviceToLogicalY( 1 ) - DC->DeviceToLogicalY( 0 );
sy1 = y1; bool mirrored = (slx > 0 && sly < 0) || (slx < 0 && sly > 0);
ex1 = x2 - dwx; // first edge
ey1 = y2; start.x = 0;
start.y = radius;
DC->DrawLine( sx1, sy1, ex1, ey1 ); end.x = len;
end.y = radius;
sx2 = x1 + dwx; RotatePoint( &start, angle);
sy2 = y1; RotatePoint( &end, angle);
ex2 = x2 + dwx; start += org;
ey2 = y2; end += org;
DC->DrawLine( sx2, sy2, ex2, ey2 ); DC->DrawLine( start, end );
}
else if( dy == 0 ) /* segment horizontal */ // first rounded end
{ end.x = 0;
dwy = radius; end.y = -radius;
if( dx < 0 ) RotatePoint( &end, angle);
dwy = -dwy; end += org;
sx1 = x1; if( !mirrored )
sy1 = y1 - dwy; DC->DrawArc( end, start, org );
ex1 = x2;
ey1 = y2 - dwy;
DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1;
sy2 = y1 + dwy;
ex2 = x2;
ey2 = y2 + dwy;
DC->DrawLine( sx2, sy2, ex2, ey2 );
}
else else
{ DC->DrawArc( start, end, org );
if( std::abs( dx ) == std::abs( dy ) ) // segment 45 degrees
{
dwx = dwy = ( (width * 5) + 4 ) / 7; // = width / 2 * 0.707
if( dy < 0 )
{
if( dx <= 0 )
{
dwx = -dwx; swap_ends = true;
}
}
else // dy >= 0
{
if( dx > 0 )
{
dwy = -dwy; swap_ends = true;
}
else
swap_ends = true;
}
}
else
{
double delta_angle = ArcTangente( dy, dx );
dwx = 0;
dwy = width;
RotatePoint( &dwx, &dwy, -delta_angle );
}
dwx2 = dwx >> 1;
dwy2 = dwy >> 1;
sx1 = x1 - dwx2;
sy1 = y1 - dwy2;
ex1 = x2 - dwx2;
ey1 = y2 - dwy2;
DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1 + dwx2; // second edge
sy2 = y1 + dwy2; start.x = len;
start.y = -radius;
RotatePoint( &start, angle);
start += org;
ex2 = x2 + dwx2; DC->DrawLine( start, end );
ey2 = y2 + dwy2;
DC->DrawLine( sx2, sy2, ex2, ey2 ); // second rounded end
} end.x = len;
end.y = radius;
RotatePoint( &end, angle);
end += org;
if( swap_ends ) if( !mirrored )
{ DC->DrawArc( end.x, end.y, start.x, start.y, x2, y2 );
DC->DrawArc( sx2, sy2, sx1, sy1, x1, y1 );
DC->DrawArc( ex1, ey1, ex2, ey2, x2, y2 );
}
else else
{ DC->DrawArc( start.x, start.y, end.x, end.y, x2, y2 );
DC->DrawArc( sx1, sy1, sx2, sy2, x1, y1 );
DC->DrawArc( ex2, ey2, ex1, ey1, x2, y2 );
}
} }
......
...@@ -200,8 +200,16 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, ...@@ -200,8 +200,16 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
StAngle = ArcTangente( dy - uy0, dx - ux0 ); StAngle = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle; EndAngle = StAngle + m_Angle;
if( !panel->GetPrintMirrored() )
{
if( StAngle > EndAngle ) if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle ); EXCHG( StAngle, EndAngle );
}
else // Mirrored mode: arc orientation is reversed
{
if( StAngle < EndAngle )
EXCHG( StAngle, EndAngle );
}
if( typeaff == LINE ) if( typeaff == LINE )
{ {
......
...@@ -282,7 +282,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -282,7 +282,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
if( printMirror ) if( printMirror )
{ {
// Calculate the mirrored center of the board. // Calculate the mirrored center of the board.
center.y = m_Parent->GetPageSizeIU().y - boardBoundingBox.Centre().y; center.x = m_Parent->GetPageSizeIU().x - boardBoundingBox.Centre().x;
} }
offset += center; offset += center;
...@@ -301,21 +301,29 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -301,21 +301,29 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
screen->m_IsPrinting = true; screen->m_IsPrinting = true;
EDA_COLOR_T bg_color = g_DrawBgColor; EDA_COLOR_T bg_color = g_DrawBgColor;
// Print frame reference, if reqquested, before
if( m_PrintParams.m_Print_Black_and_White )
GRForceBlackPen( true );
if( m_PrintParams.PrintBorderAndTitleBlock() )
m_Parent->DrawWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, titleblockFilename );
if( printMirror ) if( printMirror )
{ {
// To plot mirror, we reverse the y axis, and modify the plot y origin // To plot mirror, we reverse the x axis, and modify the plot x origin
dc->SetAxisOrientation( true, true ); dc->SetAxisOrientation( false, false);
/* Plot offset y is moved by the y plot area size in order to have /* Plot offset x is moved by the x plot area size in order to have
* the old draw area in the new draw area, because the draw origin has not moved * the old draw area in the new draw area, because the draw origin has not moved
* (this is the upper left corner) but the Y axis is reversed, therefore the plotting area * (this is the upper left corner) but the X axis is reversed, therefore the plotting area
* is the y coordinate values from - PlotAreaSize.y to 0 */ * is the x coordinate values from - PlotAreaSize.x to 0 */
int y_dc_offset = PlotAreaSizeInPixels.y; int x_dc_offset = PlotAreaSizeInPixels.x;
y_dc_offset = KiROUND( y_dc_offset * userscale ); x_dc_offset = KiROUND( x_dc_offset * userscale );
dc->SetDeviceOrigin( 0, y_dc_offset ); dc->SetDeviceOrigin( x_dc_offset, 0 );
wxLogTrace( tracePrinting, wxT( "Device origin: x=%d, y=%d" ), wxLogTrace( tracePrinting, wxT( "Device origin: x=%d, y=%d" ),
0, y_dc_offset ); x_dc_offset, 0 );
panel->SetClipBox( EDA_RECT( wxPoint( -MAX_VALUE/2, -MAX_VALUE/2 ), panel->SetClipBox( EDA_RECT( wxPoint( -MAX_VALUE/2, -MAX_VALUE/2 ),
panel->GetClipBox()->GetSize() ) ); panel->GetClipBox()->GetSize() ) );
...@@ -359,13 +367,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage() ...@@ -359,13 +367,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
printMirror, &m_PrintParams ); printMirror, &m_PrintParams );
GRForceBlackPen( false ); GRForceBlackPen( false );
} }
else
if( m_PrintParams.m_Print_Black_and_White )
GRForceBlackPen( true ); GRForceBlackPen( true );
if( m_PrintParams.PrintBorderAndTitleBlock() )
m_Parent->DrawWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, titleblockFilename );
#if defined (GERBVIEW) #if defined (GERBVIEW)
// In B&W mode, do not force black pen for Gerbview // In B&W mode, do not force black pen for Gerbview
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment