Profile Picture

Zoom to selection (NNodeList)

Posted By michal bandrowski 15 Years Ago
Author
Message
michal bandrowski
Posted 15 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 10, Visits: 1
Thank You.

Ivo Milanov
Posted 15 Years Ago
View Quick Profile
Forum Member

Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)Forum Member (35 reputation)

Group: Forum Members
Last Active: 2 Months Ago
Posts: 35, Visits: 15

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



michal bandrowski
questionmark Posted 15 Years Ago
View Quick Profile
Junior Member

Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)Junior Member (10 reputation)

Group: Forum Members
Last Active: 15 Years Ago
Posts: 10, Visits: 1
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



Similar Topics


Reading This Topic