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,
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,
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;
GRLastMoveToY = y2;
......@@ -658,114 +650,63 @@ void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
GRSetColorPen( DC, Color, aPenSize );
GRSetBrush( DC, Color, false );
radius = (width + 1) >> 1;
dx = x2 - x1;
dy = y2 - y1;
if( dx == 0 ) /* segment vertical */
{
dwx = radius;
if( dy >= 0 )
dwx = -dwx;
sx1 = x1 - dwx;
sy1 = y1;
ex1 = x2 - dwx;
ey1 = y2;
DC->DrawLine( sx1, sy1, ex1, ey1 );
sx2 = x1 + dwx;
sy2 = y1;
ex2 = x2 + dwx;
ey2 = y2;
DC->DrawLine( sx2, sy2, ex2, ey2 );
}
else if( dy == 0 ) /* segment horizontal */
{
dwy = radius;
if( dx < 0 )
dwy = -dwy;
sx1 = x1;
sy1 = y1 - dwy;
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 );
}
int radius = (width + 1) >> 1;
int dx = x2 - x1;
int dy = y2 - y1;
double angle = -ArcTangente( dy, dx );
wxPoint start;
wxPoint end;
wxPoint org( x1, y1);
int len = (int) hypot( dx, dy );
// We know if the DC is mirrored, to draw arcs
int slx = DC->DeviceToLogicalX( 1 ) - DC->DeviceToLogicalX( 0 );
int sly = DC->DeviceToLogicalY( 1 ) - DC->DeviceToLogicalY( 0 );
bool mirrored = (slx > 0 && sly < 0) || (slx < 0 && sly > 0);
// first edge
start.x = 0;
start.y = radius;
end.x = len;
end.y = radius;
RotatePoint( &start, angle);
RotatePoint( &end, angle);
start += org;
end += org;
DC->DrawLine( start, end );
// first rounded end
end.x = 0;
end.y = -radius;
RotatePoint( &end, angle);
end += org;
if( !mirrored )
DC->DrawArc( end, start, org );
else
{
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;
DC->DrawArc( start, end, org );
ex1 = x2 - dwx2;
ey1 = y2 - dwy2;
DC->DrawLine( sx1, sy1, ex1, ey1 );
// second edge
start.x = len;
start.y = -radius;
RotatePoint( &start, angle);
start += org;
sx2 = x1 + dwx2;
sy2 = y1 + dwy2;
DC->DrawLine( start, end );
ex2 = x2 + dwx2;
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 )
{
DC->DrawArc( sx2, sy2, sx1, sy1, x1, y1 );
DC->DrawArc( ex1, ey1, ex2, ey2, x2, y2 );
}
if( !mirrored )
DC->DrawArc( end.x, end.y, start.x, start.y, x2, y2 );
else
{
DC->DrawArc( sx1, sy1, sx2, sy2, x1, y1 );
DC->DrawArc( ex2, ey2, ex1, ey1, x2, y2 );
}
DC->DrawArc( start.x, start.y, end.x, end.y, x2, y2 );
}
......
......@@ -200,8 +200,16 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
StAngle = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle;
if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle );
if( !panel->GetPrintMirrored() )
{
if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle );
}
else // Mirrored mode: arc orientation is reversed
{
if( StAngle < EndAngle )
EXCHG( StAngle, EndAngle );
}
if( typeaff == LINE )
{
......
......@@ -282,7 +282,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
if( printMirror )
{
// 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;
......@@ -301,21 +301,29 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
screen->m_IsPrinting = true;
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 )
{
// To plot mirror, we reverse the y axis, and modify the plot y origin
dc->SetAxisOrientation( true, true );
// To plot mirror, we reverse the x axis, and modify the plot x origin
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
* (this is the upper left corner) but the Y axis is reversed, therefore the plotting area
* is the y coordinate values from - PlotAreaSize.y to 0 */
int y_dc_offset = PlotAreaSizeInPixels.y;
y_dc_offset = KiROUND( y_dc_offset * userscale );
dc->SetDeviceOrigin( 0, y_dc_offset );
* (this is the upper left corner) but the X axis is reversed, therefore the plotting area
* is the x coordinate values from - PlotAreaSize.x to 0 */
int x_dc_offset = PlotAreaSizeInPixels.x;
x_dc_offset = KiROUND( x_dc_offset * userscale );
dc->SetDeviceOrigin( x_dc_offset, 0 );
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->GetClipBox()->GetSize() ) );
......@@ -359,13 +367,9 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
printMirror, &m_PrintParams );
GRForceBlackPen( false );
}
if( m_PrintParams.m_Print_Black_and_White )
else
GRForceBlackPen( true );
if( m_PrintParams.PrintBorderAndTitleBlock() )
m_Parent->DrawWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize,
IU_PER_MILS, titleblockFilename );
#if defined (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