[Drawkit] Grid span issues (was Re: Beta 4 Finally up!)
Graham Cox
graham.cox at bigpond.com
Tue Jul 22 18:20:12 PDT 2008
Hi Brad,
Yes, that does seem a bit wonky now you highlight it. I'll be honest -
I've started to lose track a little bit of exactly what my intentions
were there. I was trying to accommodate your wish that span could be
something other than 1; seems I goofed.
So, let me just go back over the basic concepts so I can get it clear
in my mind, and we'll see what needs to be fixed.
1. "Span" is *defined* as the distance in Quartz points for 1 of
whatever units you want to use. This number and the units themselves
are stored by the DKDrawing object. The grid is then meant to use this
basic value as a starting point for setting up and drawing the grid.
The reason that the grid no longer stores span is because the drawing
is already doing that and I don't want data duplication - the grid
should be obtaining this value from the drawing as needed. The reason
the drawing has this information is because it still allows "real
world" measurements even if you have no grid layer - the grid is
intended just to visualise the co-ordinates (and secondarily to
provide snapping assistance).
2. When rendering the grid, you may want to use a multiple other than
1. So if your span was 32 points representing 1km, but you wanted to
draw 2km squares, you'd use a span multiplier of 2. It should also be
possible to have non-integer multipliers.
I think you're right - the multiplier should be stored separately by
the grid. It would be unknown to the drawing object, but taken into
account when the grid is set up. Getting rid of the method -
setSpanDistance:divisions:majors: and putting everything into the
other method would help I think, because it then makes it clear that
there is just one place to set this.
So in your case you'd want to set "microns" as the unit, define the
distance for 1 µm, then have a multiplier of 1000. That would be a lot
simpler than trying to fiddle all the factors yourself. Is that the
way you'd like to see it?
cheers, Graham
On 23 Jul 2008, at 6:51 am, Brad Larson wrote:
> Thanks a lot for this, there look to be a large number of
> improvements under the hood.
>
> However, I'm having some problems with the new way that DKGridLayer
> handles units and spans. Right now, it equates a single realspace
> unit to the width of a span. In Beta 3, the two values were
> independent. This causes a problem in our case, where we have small
> units (microns), but only want to have spans every 100 or 1000
> microns. Under Beta 4, the drawing grid for our program is solid
> black. In Beta 3, DKGridLayer would set and read back the
> m_spanDistance instance variable, but now only the DKDrawing's
> unitToPointsConversionFactor is used.
>
> In fact, in DKGridLayer's
> setDistanceForUnitSpan:drawingUnits:span:divisions:majors:rulerSteps
> : the conversion factor is first set by
>
> [[self drawing] setDrawingUnits:units
> unitToPointsConversionFactor:conversionFactor];
>
> then the following is called to set up the spans:
>
> [self setSpanDistance:conversionFactor * span divisions:divs
> majors:majors];
>
> but in setSpanDistance:divisions:majors: the
> unitToPointsConverstionFactor is overwritten by
>
> [[self drawing] setDrawingUnits:[[self drawing] drawingUnits]
> unitToPointsConversionFactor:unitDistance];
>
> where unitDistance was conversionFactor * span from the previous
> call. It seems to me that this should instead be setting an
> instance variable for the span distance, as was done before. It's a
> little odd to have the unitToPointsConversionFactor set to two
> different values in a row.
>
> Am I reading this correctly or is there a way to set a span with a
> length other than one unit that I'm missing?
More information about the Drawkit
mailing list