I am currently trying to build a Qt driver for plplot, plotting in a QWidget (via a QPixmap), and among other things, I would like it to be able to plreplot() when the widget is resized, so that everything doesn't look stretched then.
What I basically do is the usual stream copy/replot thing:
PLINT old_stream, new_stream;
plsqtdev(this); // sets the Qt device for plotting, works like plsmem for the mem driver, calls plP_setphy to set the actual plot size
plcpstrm(old_stream, 0); // Copy the old buffer to the new one
plsstrm(old_stream); // Close the old stream
The first resize goes OK. As a concrete example, I originally plotted something at coordinate 39 (out of 500), and after resize from 500 to 1123, it is set to 87. The problem is with the following resizes. After resize from 1123 to 338, the new coordinate is not 87*338/1123 but 39*338/1123(=11), as 39 is the buffered coordinate. But my device size has changed!
*To make it simple, the coordinates seem to be buffered, but not the size of the device they are relative to. The sized used is the size of the device the stream is copied from, even if this stream itself was copied from another device, with another size.*
Do you know a way to cope with this without having to hack through the plplot engine itself?
I don't think that the mem driver can do that. For the wxWidgets driver I have to explicitely tell the driver via a special function that the plotwindows was resized and that the scale parameter need to be changed. I don't think that the mem driver has that capabilty. I think you need to open a new stream and recall all plplot functions yourself - which sounds more cumbersome that it is, since you must have a special interface to your widget anyway for your program, I think. I do this for a special wxWidgets 2d plot canvas where I hide the PLplot interface behind my own "more nicer" interface.
Have a quick look at the code mem.c, there is no scale parameter. Since during a replot only the buffered plot line commands are repeated with the same coordinates I think there will be no changes. It wouldn't be too hard to change the mem.c driver though, but in the moment my time is a little bit limited.
Thanks for this very quick answer.
I currently do not pay attention to the mem driver. I can use it, but I am trying to see if a native Qt driver couldn't be better as someone (you, maybe?) suggested in another thread. Anyway, the issue is the same with the mem driver, if we activate buffering (which is not done by default).
Even though I may choose the "recall all plplot functions myself" option, I would have liked to find an elegant solution to this issue :) I may have missed something, as there are soooo many parameters to a stream...
I just recall my issue more clearly, because I am not sure it was that clear in my first post.
- Stream1, of size1, has a buffer of commands buffer1, with coordinates relative to size1
I copy it to stream2:
- Stream2, of size2, has buffer1, and calc_dimap (plcore.c) gives a conversion factor from size1 to size2
I copy it to stream3:
- Stream3, of size3, has buffer1, and calc_dimap gives a conversion factor from size2 to size3 <- here lies the error, as buffer1 is relative to Stream1, the conversion factor should be from size1 to size3.