On 1/18/10 11:11 PM, Jack Dodds wrote:
> I am having trouble implementing the previewing and printing of PLplot
> output in a wxWidgets application. The PLplot code works reliably when
> drawing on a wxPLplotwindow, but works only on random pages when drawing on
> a wxPLplotstream that is created for print or print preview purposes. When
> it does not work, it produces nothing on the output device.
Uh, I never tested printing with the wxWidgets driver, although it
> Eclipse CDT 3.4.2
> MinGW 3.15
> wxWidgets 2.8.9
> PLplot 5.8.0-RC1
> Windows XP SP3.
This version of Plplot is rather old. I think I completely restructured
most of the code and fixed numerous bugs, so you might try to use the
latest PLplot version. I didn't change much at the interface
(wxPLplotwindows, etc.) so it might just work, using PLplot 5.9.5
without changing much code on your side (if at all).
> The intended plot is a 2-D graph of a spectrum. The PLplot calls are in a
> class SpectrumPlot which knows nothing about wxWidgets.
> SpectrumPlot::Draw() takes a plstream as an argument and draws the graph on
> It works reliably when drawing on the wxPLplotstream obtained from a
> Printing is implemented with the provided wxPrinter and wxPrintPreview
> classes. These both use a class SpectraPrintout derived from the provided
> class wxPrintout in which GetPageInfo(), HasPage(), and OnPrintPage() are
> SpectraPrintout::OnPrintPage() creates a wxPLplotstream, passing to it the
> wxDC device context from the argument list of OnPrintPage(). Then it calls
> For debug purposes, after drawing the graph, OnPrintPage() calls
> wxDC::DrawCircle() to draw two circles over top of the graph. That is, the
> circles are drawn by directly accessing the wxWidgets methods, without using
> the PLplotstream.
> This sometimes works and sometimes does not, both in output to the printer,
> and in print preview. When it does work, the graph is either previewed or
> printed as it should be, and the wxDC::DrawCircle() circles appear on top of
> the graph (as expected, since they are drawn last). When it does not work,
> only the circles appear. The graph does not appear.
> When printing several pages in one printing operation, the code works on
> some pages and not on others. When previewing, some pages display
> correctly, others do not. Multiple attempts to preview the same page yield
> success and failure apparently at random.
> The wxDC::DrawCircle() circles are always displayed. However, when the
> graph is displayed correctly, the circles are black filled. When the graph
> is not displayed, the circles are white filled. This is likely because the
> graph drawing code changes the palette.
Sure, I set wxBrush and wxPen according to the PLplot commands.
Also, calling wxDC::MinX(),
> wxDC::MinY(), wxDC::MaxX(), wxDC::MaxY() gives zeros when the graph is not
> displayed correctly, but displays reasonable values when the graph is
> displayed correctly. This suggests that the underlying wxDC methods are not
> being called at all in the cases where the graph is not displayed correctly,
> so that the palette is not changed and the plot extent is not updated.
I'm quite sure, that the constructor of wxPLplotstream was quite buggy.
I did a lot of changes there, since I always forgot some case. It worked
on Windows, then not on Linux. I fixed it there, then I had problems
with freetype code and so on. This may be the problem, since you're
using an old PLplot version.
> It appears that some object is either not being properly initialized, or is
> being overwritten, at random. Perhaps an object created on the stack or the
> heap is being destroyed before it should be, causing some internal error to
> be set in PLplot. Since wxWidgets always draws the circles correctly, it
> appears that the problem exists in my code or the PLplot code, not
This I'm sure.
> I would appreciate advice on how to narrow down the problem.
If you want to stay with PLplot 5.8.0 I'm afraid you must debug it
yourself. I've Windows only running in Virtualbox and compiling
something in there is a PITA and getting the old code to run...
Anyway, I'll help you as much as possible. If you look at the wxWidgets
driver code, there are actually only some functions which do the actuall
void plD_line_wxwidgets( PLStream *pls, short x1a, short y1a, short x2a,
short y2a )
void plD_polyline_wxwidgets( PLStream *pls, short *xa, short *ya, PLINT
and some others (fill_polygon; eop, bop, state do some "organizational"
work). It would be good to add a printf line right at the start of
line_wxwidgets and polyline_wxwidgets and print out x1a, y1a, .... or
the first points of the polyline. That way you can make sure, that these
functions are actually called. Mind though, that if you run your app the
printf output will be sent to ... somewhere. That's a known
"problem/feature" for Windows apps, so it might be best, to open a file
and fprintf the stuff to this file.
I actually expect, that these functions are not called, so do the same
for the plD_init_wxwidgets (if we actually ever get there).
Sure, you can do the same with a decent debugger (set a breakpoint at
these functions), without printfing around, but I don't know how good
Eclipse is nowadays.
Using PLplot 5.9.5 you could try to add the print feature to the
wxPLplotDemo application in examples/C++ and see if you can reproduce
the problem. This would it also make it easy for me for further
debugging. Actually it is a good idea, to add such functionality to
wxPLplotDemo anyways, but I doubt that I'll find time anytime soon to do
So try the stuff I suggested above and if you've new information let me
know, so that I can give further advice.
> Jack Dodds
> Geo Equipment Manufacturing Ltd.
> Geotech Ltd.
> 245 Industrial Parkway North
> Aurora, Ontario, Canada
> L4G 4C4
> Phone: 905-841-5004
> Fax: 905-841-0611
> Email: jack@...
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> Plplot-general mailing list
Dr. Werner Smekal
Institut fuer Angewandte Physik
Technische Universitaet Wien
Wiedner Hauptstr 8-10
phone: +43-(0)1-58801-13463 (office)