Nevron Forum

Zoom to selection (NNodeList)

https://www.nevron.com/Forum/Topic2457.aspx

By michal bandrowski - Thursday, July 2, 2009

Hi,

I have node list (NNodeList) with shapes and I do call view.Selection.RegionSelect(nodeList), but it only selects them - what I'd like to see is to zoom view to region, specyfied with all shapes in node list.
If there is no such method, I'll consider of using view.Zoom(float, point) - so here is my another question - how can I translate region size to zoom level, so then region will take whole view ?

Thanks in advance,
Michal
By Ivo Milanov - Monday, July 6, 2009

Hi Michal,

The behavior that you want to achieve is very similar to the Fit view layout of the drawing view. The only difference being that you are fitting the view to some nodes bounds. The following code will achieve this behavior in all possible cases of measurement units and drawing scales.


// get the bounds of the selected objects

NRectangleF bounds = NFunctions.ComputeNodesBounds(view.Selection.Nodes, null);

 

// get the scaling of scene units to world (painting units)

// for documents without a drawing scale these are equal to 1

float sceneToWorldScaleX = document.SceneScaleToWorldX;

float sceneToWorldScaleY = document.SceneScaleToWorldY;

 

// compute the page scale

// for documents measured in pixels this is equal to 1

float pageScale = view.MeasurementUnitConverter.ConvertX(document.WorldMeasurementUnit, NGraphicsUnit.Pixel, 1);

 

// determine the zoom

NSizeF windowSize = view.WindowSize;

float zoom = Math.Min(windowSize.Width / (bounds.Width * pageScale * sceneToWorldScaleX),

windowSize.Height / (bounds.Height * pageScale * sceneToWorldScaleY));

 

// zoom to nodes bounds center

view.Zoom(zoom, bounds.Center);

Hope this helps - questions or comments - please feel free...

Best regards,
Ivo Milanov

By michal bandrowski - Thursday, July 9, 2009

Thank You.