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. * 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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * 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 ) void SVG_PLOTTER::SetColor( EDA_COLOR_T color )
{ {
PSLIKE_PLOTTER::SetColor( 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() ); DPOINT end_dev = userToDeviceCoordinates( rect.GetEnd() );
DSIZE size_dev = end_dev - org_dev; DSIZE size_dev = end_dev - org_dev;
// Ensure size of rect in device coordinates is > 0 // 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); DBOX rect_dev( org_dev, size_dev);
rect_dev.Normalize(); rect_dev.Normalize();
setFillMode( fill ); setFillMode( fill );
SetCurrentLineWidth( width ); SetCurrentLineWidth( width );
fprintf( outputFile, // Rectangles having a 0 size value for height or width are just not drawn on Inscape,
"<rect x=\"%g\" y=\"%g\" width=\"%g\" height=\"%g\" rx=\"%g\" />\n", // so use a line when happens.
rect_dev.GetPosition().x, rect_dev.GetPosition().y, if( rect_dev.GetSize().x == 0.0 || rect_dev.GetSize().y == 0.0 ) // Draw a line
rect_dev.GetSize().x, rect_dev.GetSize().y, fprintf( outputFile,
0.0 // radius of rounded corners "<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 ); SetCurrentLineWidth( textPensize );
if( aColor >= 0 ) if( aColor >= 0 )
SetColor( aColor ); SetColor( aColor );
@ -662,10 +661,7 @@ void PLOTTER::Text( const wxPoint& aPos,
DrawGraphicText( NULL, NULL, positions[ii], aColor, txt, DrawGraphicText( NULL, NULL, positions[ii], aColor, txt,
aOrient, aSize, aOrient, aSize,
aH_justify, aV_justify, aH_justify, aV_justify,
textPensize, aItalic, textPensize, aItalic, aBold, NULL, this );
aBold,
NULL,
this );
} }
delete multilineText; delete multilineText;
@ -675,10 +671,7 @@ void PLOTTER::Text( const wxPoint& aPos,
DrawGraphicText( NULL, NULL, aPos, aColor, aText, DrawGraphicText( NULL, NULL, aPos, aColor, aText,
aOrient, aSize, aOrient, aSize,
aH_justify, aV_justify, aH_justify, aV_justify,
textPensize, aItalic, textPensize, aItalic, aBold, NULL, this );
aBold,
NULL,
this );
} }
if( aWidth != textPensize ) if( aWidth != textPensize )

View File

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

View File

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