Commit 172bbc8f authored by jean-pierre charras's avatar jean-pierre charras

Eeschema: fix Bug #1180902 (Libedit creates empty svg images)

parent 0f885e7f
......@@ -383,18 +383,56 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
{
wxASSERT( aPlotter != NULL );
aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
bool fill = aPlotter->GetColorMode();
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
// Lib Fields not are plotted here, because this plot function
// is used to plot schematic items, which have they own fields
if( item.Type() == LIB_FIELD_T )
continue;
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
continue;
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
continue;
aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
item.Plot( aPlotter, aOffset, fill, aTransform );
}
}
void LIB_COMPONENT::PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
const wxPoint& aOffset, const TRANSFORM& aTransform )
{
wxASSERT( aPlotter != NULL );
aPlotter->SetColor( GetLayerColor( LAYER_FIELDS ) );
bool fill = aPlotter->GetColorMode();
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
if( item.Type() != LIB_FIELD_T )
continue;
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
continue;
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
continue;
// The reference is a special case: we shoud change the basic text
// to add '?' and the part id
LIB_FIELD& field = (LIB_FIELD&) item;
wxString tmp = field.GetText();
if( field.GetId() == REFERENCE )
{
wxString text = field.GetFullText( aUnit );
field.SetText( text );
}
item.Plot( aPlotter, aOffset, fill, aTransform );
field.SetText( tmp );
}
}
......
......@@ -404,7 +404,9 @@ public:
bool aOnlySelected = false );
/**
* Plot component to plotter.
* Plot lib component to plotter.
* Lib Fields not are plotted here, because this plot function
* is used to plot schematic items, which have they own fields
*
* @param aPlotter - Plotter object to plot to.
* @param aUnit - Component part to plot.
......@@ -415,6 +417,19 @@ public:
void Plot( PLOTTER* aPlotter, int aUnit, int aConvert, const wxPoint& aOffset,
const TRANSFORM& aTransform );
/**
* Plot Lib Fields only of the component to plotter.
* is used to plot the full lib component, outside the schematic
*
* @param aPlotter - Plotter object to plot to.
* @param aUnit - Component part to plot.
* @param aConvert - Component alternate body style to plot.
* @param aOffset - Distance to shift the plot coordinates.
* @param aTransform - Component plot transform matrix.
*/
void PlotLibFields( PLOTTER* aPlotter, int aUnit, int aConvert,
const wxPoint& aOffset, const TRANSFORM& aTransform );
/**
* Add a new draw \a aItem to the draw object list.
*
......
......@@ -473,9 +473,33 @@ void LIB_FIELD::Rotate( const wxPoint& center, bool aRotateCCW )
}
void LIB_FIELD::Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
void LIB_FIELD::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
const TRANSFORM& aTransform )
{
if( IsVoid() )
return;
/* Calculate the text orientation, according to the component
* orientation/mirror */
int orient = m_Orient;
if( aTransform.y1 ) // Rotate component 90 deg.
{
if( orient == TEXT_ORIENT_HORIZ )
orient = TEXT_ORIENT_VERT;
else
orient = TEXT_ORIENT_HORIZ;
}
EDA_RECT BoundaryBox = GetBoundingBox();
EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER;
EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER;
wxPoint textpos = aTransform.TransformCoordinate( BoundaryBox.Centre() )
+ aOffset;
aPlotter->Text( textpos, GetDefaultColor(), m_Text, orient, m_Size,
hjustify, vjustify,
GetPenSize(), m_Italic, m_Bold );
}
......
......@@ -41,6 +41,8 @@
#include <class_library.h>
#include <dialogs/dialog_plot_schematic.h>
#include <boost/foreach.hpp>
void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event )
{
......@@ -103,7 +105,7 @@ void LIB_EDIT_FRAME::OnPlotCurrentComponent( wxCommandEvent& event )
pageTemp.SetHeightMils( int( componentSize.y * 1.2 ) );
GetScreen()->SetPageSettings( pageTemp );
SVG_Print_Component( FullFileName );
SVG_PlotComponent( FullFileName );
GetScreen()->SetPageSettings( pageSave );
}
break;
......@@ -136,12 +138,49 @@ void LIB_EDIT_FRAME::CreatePNGorJPEGFile( const wxString& aFileName, bool aFmt_j
}
void LIB_EDIT_FRAME::SVG_Print_Component( const wxString& FullFileName )
void LIB_EDIT_FRAME::SVG_PlotComponent( const wxString& aFullFileName )
{
bool plotBW = false;
bool plotFrameRef = false;
DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( this, FullFileName, GetScreen(),
plotBW, plotFrameRef );
const bool plotBW = false;
const PAGE_INFO& pageInfo = GetScreen()->GetPageSettings();
SVG_PLOTTER* plotter = new SVG_PLOTTER();
plotter->SetPageSettings( pageInfo );
plotter->SetDefaultLineWidth( GetDefaultLineThickness() );
plotter->SetColorMode( plotBW );
wxPoint plot_offset;
const double scale = 1.0;
plotter->SetViewport( plot_offset, IU_PER_DECIMILS, scale, false );
// Init :
plotter->SetCreator( wxT( "Eeschema-SVG" ) );
if( ! plotter->OpenFile( aFullFileName ) )
{
delete plotter;
return;
}
LOCALE_IO toggle;
plotter->StartPlot();
if( m_component )
{
TRANSFORM temp; // Uses default transform
wxPoint plotPos;
plotPos.x = pageInfo.GetWidthIU() /2;
plotPos.y = pageInfo.GetHeightIU()/2;
m_component->Plot( plotter, GetUnit(), GetConvert(), plotPos, temp );
// Plot lib fields, not plotted by m_component->Plot():
m_component->PlotLibFields( plotter, GetUnit(), GetConvert(),
plotPos, temp );
}
plotter->EndPlot();
delete plotter;
}
void LIB_EDIT_FRAME::PrintPage( wxDC* aDC, LAYER_MSK aPrintMask, bool aPrintMirrorMode, void* aData)
......
......@@ -641,11 +641,11 @@ public:
bool aPrintMirrorMode, void* aData = NULL );
/**
* Function SVG_Print_Component
* Function SVG_PlotComponent
* Creates the SVG print file for the current edited component.
* @param aFullFileName = the full filename of the file
* @param aFullFileName = the full filename
*/
void SVG_Print_Component( const wxString& aFullFileName );
void SVG_PlotComponent( const wxString& aFullFileName );
DECLARE_EVENT_TABLE()
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 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
......@@ -549,9 +551,10 @@ bool SCH_SCREEN::Save( FILE* aFile ) const
return true;
}
// note: SCH_SCREEN::Draw is useful only for schematic.
// library editor and library viewer do not use a draw list, and therefore
// SCH_SCREEN::Draw draws nothing
/* note: SCH_SCREEN::Draw is useful only for schematic.
* library editor and library viewer do not use a draw list, and therefore
* SCH_SCREEN::Draw draws nothing
*/
void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
{
for( SCH_ITEM* item = m_drawList.begin(); item != NULL; item = item->Next() )
......@@ -568,6 +571,10 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode
}
/* note: SCH_SCREEN::Plot is useful only for schematic.
* library editor and library viewer do not use a draw list, and therefore
* SCH_SCREEN::Plot plots nothing
*/
void SCH_SCREEN::Plot( PLOTTER* aPlotter )
{
for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
......
......@@ -184,6 +184,9 @@ public:
/**
* Function Draw
* draws all the items in the screen to \a aCanvas.
* note: this function is useful only for schematic.
* library editor and library viewer do not use a draw list, and therefore
* draws nothing
* @param aCanvas The canvas item to draw on.
* @param aDC The device context to draw on.
* @param aDrawMode The drawing mode.
......@@ -195,6 +198,9 @@ public:
/**
* Function Plot
* plots all the schematic objects to \a aPlotter.
* note: this function is useful only for schematic.
* library editor and library viewer do not use a draw list, and therefore
* plots nothing
*
* @param aPlotter The plotter object to plot to.
*/
......
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