Fix 2 minor issues in SVG plots: sometimes a color was not good. Rectangles with 0 vertiacl or horizontal size are not plot.

Minor code cleaning.
Also fix a minor coverity warning about a not initialized member.
This commit is contained in:
jean-pierre charras 2015-07-13 20:36:06 +02:00
parent 6289f5bcf4
commit c8f8256329
4 changed files with 89 additions and 121 deletions

View File

@ -6,8 +6,8 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -190,6 +190,9 @@ void SVG_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
void SVG_PLOTTER::SetColor( EDA_COLOR_T color )
{
PSLIKE_PLOTTER::SetColor( color );
if( m_graphics_changed )
setSVGPlotStyle();
}
@ -307,19 +310,30 @@ void SVG_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, int w
DPOINT end_dev = userToDeviceCoordinates( rect.GetEnd() );
DSIZE size_dev = end_dev - org_dev;
// Ensure size of rect in device coordinates is > 0
// Inkscape has problems with negative values for width and/or height
// I don't know if this is a SVG issue or a Inkscape issue, but
// Inkscape has problems with negative or null values for width and/or height, so avoid them
DBOX rect_dev( org_dev, size_dev);
rect_dev.Normalize();
setFillMode( fill );
SetCurrentLineWidth( width );
fprintf( outputFile,
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n",
rect_dev.GetPosition().x, rect_dev.GetPosition().y,
rect_dev.GetSize().x, rect_dev.GetSize().y,
0.0 // radius of rounded corners
);
// Rectangles having a 0 size value for height or width are just not drawn on Inscape,
// so use a line when happens.
if( rect_dev.GetSize().x == 0.0 || rect_dev.GetSize().y == 0.0 ) // Draw a line
fprintf( outputFile,
"<line x1=\"%g\" y1=\"%g\" x2=\"%g\" y2=\"%g\" />\n",
rect_dev.GetPosition().x, rect_dev.GetPosition().y,
rect_dev.GetEnd().x, rect_dev.GetEnd().y
);
else
fprintf( outputFile,
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n",
rect_dev.GetPosition().x, rect_dev.GetPosition().y,
rect_dev.GetSize().x, rect_dev.GetSize().y,
0.0 // radius of rounded corners
);
}

View File

@ -631,7 +631,6 @@ void PLOTTER::Text( const wxPoint& aPos,
SetCurrentLineWidth( textPensize );
if( aColor >= 0 )
SetColor( aColor );
@ -662,10 +661,7 @@ void PLOTTER::Text( const wxPoint& aPos,
DrawGraphicText( NULL, NULL, positions[ii], aColor, txt,
aOrient, aSize,
aH_justify, aV_justify,
textPensize, aItalic,
aBold,
NULL,
this );
textPensize, aItalic, aBold, NULL, this );
}
delete multilineText;
@ -675,10 +671,7 @@ void PLOTTER::Text( const wxPoint& aPos,
DrawGraphicText( NULL, NULL, aPos, aColor, aText,
aOrient, aSize,
aH_justify, aV_justify,
textPensize, aItalic,
aBold,
NULL,
this );
textPensize, aItalic, aBold, NULL, this );
}
if( aWidth != textPensize )

View File

@ -979,37 +979,19 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1, y1 + clock_size );
GRLineTo( clipbox,
aDC,
x1 + MapX1 * clock_size * 2,
y1,
width,
color );
GRLineTo( clipbox,
aDC,
x1,
y1 - clock_size,
width,
color );
GRLineTo( clipbox, aDC, x1 + MapX1 * clock_size * 2, y1,
width, color );
GRLineTo( clipbox, aDC, x1, y1 - clock_size, width, color );
}
else /* MapX1 = 0 */
{
GRMoveTo( x1 + clock_size, y1 );
GRLineTo( clipbox,
aDC,
x1,
y1 + MapY1 * clock_size * 2,
width,
color );
GRLineTo( clipbox,
aDC,
x1 - clock_size,
y1,
width,
color );
GRLineTo( clipbox, aDC, x1, y1 + MapY1 * clock_size * 2,
width, color );
GRLineTo( clipbox, aDC, x1 - clock_size, y1,
width, color );
}
GRMoveTo( MapX1 * clock_size * 2 + x1,
MapY1 * clock_size * 2 + y1 );
GRMoveTo( MapX1 * clock_size * 2 + x1, MapY1 * clock_size * 2 + y1 );
GRLineTo( clipbox, aDC, posX, posY, width, color );
}
else
@ -1024,34 +1006,18 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1, y1 + clock_size );
GRLineTo( clipbox,
aDC,
x1 - MapX1 * clock_size * 2,
y1,
width,
color );
GRLineTo( clipbox,
aDC,
x1,
y1 - clock_size,
width,
color );
GRLineTo( clipbox, aDC, x1 - MapX1 * clock_size * 2, y1,
width, color );
GRLineTo( clipbox, aDC, x1, y1 - clock_size,
width, color );
}
else /* MapX1 = 0 */
{
GRMoveTo( x1 + clock_size, y1 );
GRLineTo( clipbox,
aDC,
x1,
y1 - MapY1 * clock_size * 2,
width,
color );
GRLineTo( clipbox,
aDC,
x1 - clock_size,
y1,
width,
color );
GRLineTo( clipbox, aDC, x1, y1 - MapY1 * clock_size * 2,
width, color );
GRLineTo( clipbox, aDC, x1 - clock_size, y1,
width, color );
}
}
@ -1061,12 +1027,9 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
GRMoveTo( x1 + MapX1 * symbol_size * 2, y1 );
GRLineTo( clipbox,
aDC,
x1 + MapX1 * symbol_size * 2,
y1 - symbol_size * 2,
width,
color );
GRLineTo( clipbox, aDC,
x1 + MapX1 * symbol_size * 2, y1 - symbol_size * 2,
width, color );
GRLineTo( clipbox, aDC, x1, y1, width, color );
}
else /* MapX1 = 0 */
@ -1095,12 +1058,8 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
else /* MapX1 = 0 */
{
GRMoveTo( x1 - symbol_size * 2, y1 );
GRLineTo( clipbox,
aDC,
x1,
y1 + MapY1 * symbol_size * 2,
width,
color );
GRLineTo( clipbox, aDC, x1, y1 + MapY1 * symbol_size * 2,
width, color );
}
}
else if( m_shape & NONLOGIC ) /* NonLogic pin symbol */
@ -1108,20 +1067,16 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
const int symbol_size = ExternalPinDecoSize( *this );
GRMoveTo( x1 - (MapX1 + MapY1) * symbol_size,
y1 - (MapY1 - MapX1) * symbol_size );
GRLineTo( clipbox,
aDC,
GRLineTo( clipbox, aDC,
x1 + (MapX1 + MapY1) * symbol_size,
y1 + (MapY1 - MapX1) * symbol_size,
width,
color );
width, color );
GRMoveTo( x1 - (MapX1 - MapY1) * symbol_size,
y1 - (MapY1 + MapX1) * symbol_size );
GRLineTo( clipbox,
aDC,
GRLineTo( clipbox, aDC,
x1 + (MapX1 - MapY1) * symbol_size,
y1 + (MapY1 + MapX1) * symbol_size,
width,
color );
width, color );
}
// Draw the pin end target (active end of the pin)
@ -1158,9 +1113,11 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
EDA_COLOR_T Color,
GR_DRAWMODE DrawMode )
{
int x, y, x1, y1;
if( !DrawPinName && !DrawPinNum )
return;
int x, y;
wxString StringPinNum;
EDA_COLOR_T NameColor, NumColor;
wxSize PinNameSize( m_nameTextSize, m_nameTextSize );
wxSize PinNumSize( m_numTextSize, m_numTextSize );
@ -1178,16 +1135,16 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( (Color < 0) && IsSelected() )
Color = GetItemSelectedColor();
NameColor = (EDA_COLOR_T) ( Color == UNSPECIFIED_COLOR ?
GetLayerColor( LAYER_PINNAM ) : Color );
NumColor = (EDA_COLOR_T) ( Color == UNSPECIFIED_COLOR ?
GetLayerColor( LAYER_PINNUM ) : Color );
EDA_COLOR_T NameColor = Color == UNSPECIFIED_COLOR ?
GetLayerColor( LAYER_PINNAM ) : Color;
EDA_COLOR_T NumColor = Color == UNSPECIFIED_COLOR ?
GetLayerColor( LAYER_PINNUM ) : Color;
/* Create the pin num string */
PinStringNum( StringPinNum );
x1 = pin_pos.x;
y1 = pin_pos.y;
int x1 = pin_pos.x;
int y1 = pin_pos.y;
switch( orient )
{
@ -1211,7 +1168,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
if( m_name.IsEmpty() )
DrawPinName = false;
if( TextInside ) /* Draw the text inside, but the pin numbers outside. */
if( TextInside ) // Draw the text inside, but the pin numbers outside.
{
if( (orient == PIN_LEFT) || (orient == PIN_RIGHT) )
{
@ -1363,6 +1320,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
EDA_COLOR_T color = GetLayerColor( LAYER_PIN );
aPlotter->SetColor( color );
aPlotter->SetCurrentLineWidth( GetPenSize() );
MapX1 = MapY1 = 0;
x1 = aPosition.x; y1 = aPosition.y;
@ -1449,6 +1407,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
if( m_shape & LOWLEVEL_IN ) /* IEEE symbol "Active Low Input" */
{
const int symbol_size = ExternalPinDecoSize( *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1 + MapX1 * symbol_size * 2, y1 ) );
@ -1460,7 +1419,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
{
aPlotter->MoveTo( wxPoint( x1, y1 + MapY1 * symbol_size * 2 ) );
aPlotter->LineTo( wxPoint( x1 - symbol_size * 2,
y1 + MapY1 * symbol_size * 2 ) );
y1 + MapY1 * symbol_size * 2 ) );
aPlotter->FinishTo( wxPoint( x1, y1 ) );
}
}
@ -1469,6 +1428,7 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
if( m_shape & LOWLEVEL_OUT ) /* IEEE symbol "Active Low Output" */
{
const int symbol_size = ExternalPinDecoSize( *this );
if( MapY1 == 0 ) /* MapX1 = +- 1 */
{
aPlotter->MoveTo( wxPoint( x1, y1 - symbol_size * 2 ) );
@ -1504,28 +1464,33 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
}
void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
wxPoint& pin_pos,
int orient,
int TextInside,
bool DrawPinNum,
bool DrawPinName,
int aWidth )
void LIB_PIN::PlotPinTexts( PLOTTER* plotter, wxPoint& pin_pos, int orient,
int TextInside, bool DrawPinNum,
bool DrawPinName, int aWidth )
{
int x, y, x1, y1;
wxString StringPinNum;
EDA_COLOR_T NameColor, NumColor;
wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
/* Get the num and name colors */
NameColor = GetLayerColor( LAYER_PINNAM );
NumColor = GetLayerColor( LAYER_PINNUM );
if( m_name.IsEmpty() || m_name == wxT( "~" ) )
DrawPinName = false;
/* Create the pin num string */
wxString StringPinNum;
PinStringNum( StringPinNum );
x1 = pin_pos.x;
y1 = pin_pos.y;
if( StringPinNum.IsEmpty() )
DrawPinNum = false;
if( !DrawPinNum && !DrawPinName )
return;
int x, y;
wxSize PinNameSize = wxSize( m_nameTextSize, m_nameTextSize );
wxSize PinNumSize = wxSize( m_numTextSize, m_numTextSize );
/* Get the num and name colors */
EDA_COLOR_T NameColor = GetLayerColor( LAYER_PINNAM );
EDA_COLOR_T NumColor = GetLayerColor( LAYER_PINNUM );
int x1 = pin_pos.x;
int y1 = pin_pos.y;
switch( orient )
{
@ -1546,9 +1511,6 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
break;
}
if( m_name.IsEmpty() )
DrawPinName = false;
/* Draw the text inside, but the pin numbers outside. */
if( TextInside )
{
@ -1940,7 +1902,6 @@ void LIB_PIN::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
wxPoint pos = aTransform.TransformCoordinate( m_position ) + offset;
plotter->SetCurrentLineWidth( GetPenSize() );
PlotSymbol( plotter, pos, orient );
PlotPinTexts( plotter, pos, orient, GetParent()->GetPinNameOffset(),
GetParent()->ShowPinNumbers(), GetParent()->ShowPinNames(),

View File

@ -49,7 +49,7 @@ public:
VIEW_CONTROLS( VIEW* aView ) : m_view( aView ),
m_forceCursorPosition( false ), m_cursorCaptured( false ), m_snappingEnabled( false ),
m_grabMouse( false ), m_autoPanEnabled( false ), m_autoPanMargin( 0.1 ),
m_autoPanSpeed( 0.15 )
m_autoPanSpeed( 0.15 ), m_enableZoomNoCenter( false )
{
}