Nevron .NET Vision Documentation
Layouts - Getting Started

Since all types of layouts derive from base NLayout class, this class defines a common and easy way to apply a layout to a certain set of objects. This is performed by its Layout method.

As input this method takes only two arguments - a list of objects, which must be arranged and a layout context instance. The following example demonstrates how to apply a layout to the drawing document active layer children:

C#
Copy Code
// create a layout (for example a symmetrical layout)
NLayout layout = new NSymmetricalLayout();

// synchronize the resolution and measurement units
layout.Resolution = document.Resolution;
layout.MeasurementUnit = document.MeasurementUnit;

// get the shapes to layout
NNodeList shapes = document.ActiveLayer.Children(NFilters.Shape2D);

// layout the shapes
layout.Layout(shapes, new NDrawingLayoutContext(document));
Visual Basic
Copy Code
' create a layout (for example a symmetrical layout)
Dim layout As NLayout = New NSymmetricalLayout()

' synchronize the resolution and measurement units
layout.Resolution = document.Resolution
layout.MeasurementUnit = document.MeasurementUnit

' get the shapes to layout
Dim shapes As NNodeList = document.ActiveLayer.Children(NFilters.Shape2D)

' layout the shapes
layout.Layout(shapes, New NDrawingLayoutContext(document))
Layout Context

The purpose of the layout context is to abstract the particular type of layout from the actual type of objects it works with as well as to help the layout build a body representation for each of the arranged objects.

This is achieved with the help of three adapters:

  1. Graph adapter - abstracts the layout from the actual way in which the arranged objects form a graph structure.
  2. Body adapter - abstracts the layout from the actual geometry and coordinate system of the objects, which it layouts. It is also used to provide supplemental data for each object (see below).
  3. Body container adapter - abstracts the layout from the container in which the layout takes place.

Given these three adapters layouts basically perform the following steps:

  1. Build a graph representation of the arranged objects
  2. Create a body representations of the arranged objects 
  3. Arrange the body representations
  4. Apply the body representations to the arranged objects

In Nevron Diagram you can use the following adapters:

  1. NShapeGraphAdapter - adapts shape connections to graph relations.
  2. NShapeBodyAdapter - adapts shape geometry, position and properties to the layout specific bodies.
  3. NDrawingBodyContrainerAdapter - adapts the drawing document as a body container.

If you want to use the default adapters create an instance of the NDrawingLayoutContext class. You can also specify the shapes to be layouted using the proper NDrawingLayoutContext constructor.

Supplemental Data

Certain layouts support per object specified data. For example the dock layout supports per vertex specified dock area, while the spring layout supports per edge specified spring length and spring stiffness.

The supplemental data in general is retrieved with the help of the body adapter and is property based. The documentation for each particular type of layout specifies what supplemental data it supports.

In Nevron Diagram the supplemental layout data for each shape is grouped in an instance of the NLayoutData class accessible from the LayoutData property of the shape.

Performance Considerations

When dealing with very large graphs (i.e. graphs with hundreds or thousands of vertices and edges) the layouting process may need more time to complete. If you want to speed it up you can disable some of the steps that the layout performs (see the topics for individual layouts for more information). You can also set the MultiThreaded property to true, because some of the layouts (such as the Orthogonal Graph Layout) can take advantage of multicore CPUs.

Measurements and Measurement Units

All layout measurements (metrics) are specified in the layout current measurement unit. The layout also expects that all object provided metrics are in its current measurement unit.

The default layout measurement unit is pixel, so if the arranged objects are also defined in pixels no conversion is need. If this is not the case however you must synchronize the layout measurement unit with the unit of the arranged objects (as shown in the code example above).

 

 


©2017. Nevron Software LLC.

Send Feedback