PDA

View Full Version : Constant Grid



myzinsky
4th September 2012, 09:26
Hi,

I have a timing diagram like this:

8180

I want a constant grid, for example every 10 ns because this represents e.g. a clock.

Compare: http://www.texample.net/media/tikz/examples/PNG/timing-diagram.png

Any ideas?

Uwe
4th September 2012, 11:32
QwtPlotGrid draws major or minor grid lines depending on the ticks it gets from the corresponding scales. So you have the option to modify the scale f.e by setting a step size to 10 - or by modifying the max major, max minor attributes. When you don't need zooming/panning you can even assign the ticks manually ( using QwtPlot::setAxisScaleDiv() ).

The other option is to have the grid lines independent from the scales. For this you can overload QwtPlotGrid::updateScaleDiv(). Simply replace the ticks in the incoming scaleDiv object by something aligned to 10 and keep its boundaries.

HTH,
Uwe

myzinsky
5th September 2012, 09:52
I Set the stepsize to 10...

But, whe I zoom everything changed again :(

Uwe
5th September 2012, 11:16
But, whe I zoom everything changed again :(
Setting a fixed step size doesn't make too much sense when zooming ( consider a step size of 10 for a range of 5-6 ).

But as I wrote before - simply decouple the grid from the ticks of the scales by overloading QwtPlotGrid::updateScaleDiv().


class YourGrid: public QwtPlotGrid
{
public:
...
virtual void updateScaleDiv( const QwtScaleDiv& xScaleDiv, const QwtScaleDiv& yScaleDiv )
{
QwtScaleDiv scaleDiv;
scaleDiv.setInterval( xScaleDiv.interval() );

double min = xScaleDiv.interval().lowerBound();
double max = xScaleDiv.interval.upperBound();
if ( min > max )
qSwap( min, max );

const int stepSize = 10.0;

min = static_cast<int>( min / stepSize ) * stepSize;

QList<double > ticks;
for ( double tick = min; tick <= max; tick += stepSize )
ticks += tick;

scaleDiv.setTicks( QwtScaleDiv::MajorTick, ticks );

QwtPlotGrid::updateScaleDiv( scaleDiv, yScaleDiv );
}

Uwe

myzinsky
5th September 2012, 11:48
It works fine!

But I had to change this:



double min = xScaleDiv.interval().minValue();
double max = xScaleDiv.interval().maxValue();


Tank You Uwe!
Regards