Class Layer

GoDiagram®
v10.0.11
by Northwoods Software®

Layers are how named collections of Parts are drawn in front or behind other collections of Parts in a Diagram.

Inheritance
Layer
Namespace: Northwoods.Go
Assembly: Northwoods.GoDiagram.Avalonia.dll
Syntax
public class Layer
Remarks

Layers can only contain Parts, such as Nodes and Links. They cannot hold GraphObjects directly.

You put a Part into a Layer by assigning LayerName with the name of the Layer. You can use data binding to initialize and remember a Part's layer's name. You can change a Part's layer by modifying its LayerName, which changes its Layer.

Each Diagram starts off with the following list of Layers: "Grid", "Background", "" (the default layer), "Foreground", "Adornment", "Tool". Parts are normally put in the default layer. The "Grid", "Adornment", and "Tool" layers are considered IsTemporary. Changes to objects in temporary layers are not recorded by the UndoManager. Parts in temporary layers are not selected and are not considered to be part of the document. Objects in temporary layers do not receive click events unless you set their IsActionable to true. The "Grid" layer is the furthest back; it also contains "temporary" parts that cannot be selected. Furthermore the "Grid" layer has Pickable set to false so that mouse or touch events and calls to the "Find..." methods do not even consider any parts in that layer.

Layers have many properties that control what actions users are permitted to perform involving the parts in the layer. These properties are very much like the similarly named properties on Diagram.

Z-ordering

Layers are drawn and presented in order. You can add your own layers by calling AddLayerBefore(Layer, Layer) or AddLayerAfter(Layer, Layer) to insert a new layer at a particular place in the z-order, or to re-order existing layers. Use FindLayer(string) to get the Layer with a particular name. Parts can be individually z-ordered within a layer by setting ZOrder.

Constructors

Layer()

This constructs an empty Layer; you should set the Name before adding the Layer to a Diagram.

Declaration
public Layer()

Properties

AllowCopy

Gets or sets whether the user may copy objects in this layer.

Declaration
public bool AllowCopy { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowDelete

Gets or sets whether the user may delete objects in this layer.

Declaration
public bool AllowDelete { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowGroup

Gets or sets whether the user may group parts together in this layer.

Declaration
public bool AllowGroup { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

Gets or sets whether the user may draw new links in this layer.

Declaration
public bool AllowLink { get; set; }
Property Value
Type Description
bool

The initial value is true.

AllowMove

Gets or sets whether the user may move objects in this layer.

Declaration
public bool AllowMove { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

Gets or sets whether the user may reconnect existing links in this layer.

Declaration
public bool AllowRelink { get; set; }
Property Value
Type Description
bool

The initial value is true.

AllowReshape

Gets or sets whether the user may reshape parts in this layer.

Declaration
public bool AllowReshape { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowResize

Gets or sets whether the user may resize parts in this layer.

Declaration
public bool AllowResize { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowRotate

Gets or sets whether the user may rotate parts in this layer.

Declaration
public bool AllowRotate { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowSelect

Gets or sets whether the user may select objects in this layer.

Declaration
public bool AllowSelect { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowTextEdit

Gets or sets whether the user may do in-place text editing in this layer.

Declaration
public bool AllowTextEdit { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

AllowUngroup

Gets or sets whether the user may ungroup existing groups in this layer.

Declaration
public bool AllowUngroup { get; set; }
Property Value
Type Description
bool
Remarks

The initial value is true.

Diagram

This read-only property returns the Diagram that is using this Layer.

Declaration
public Diagram Diagram { get; }
Property Value
Type Description
Diagram

IsInDocumentBounds

Gets or sets whether or not a layer is included in the DocumentBounds computation.

Declaration
public bool IsInDocumentBounds { get; set; }
Property Value
Type Description
bool
Remarks

Default value is true.

IsTemporary

Gets or sets whether the objects in this layer are considered temporary.

Declaration
public bool IsTemporary { get; set; }
Property Value
Type Description
bool
Remarks

Parts in temporary layers are not selectable, and changes to Parts in temporary layers are not recorded in the UndoManager. Objects in temporary layers do not receive click events unless you set their IsActionable to true.

Temporary layers are excluded from bounds calculations, with the exception of the "Tool" layer, so that temporary objects created while dragging are included in the bounds.

Default value is false.

Name

Gets or sets the name for this layer.

Declaration
public string Name { get; set; }
Property Value
Type Description
string
Remarks

The initial value is an empty string, which is also the name of the default layer. The name should be unique among the diagram's Layers.

Opacity

Gets or sets the opacity for all parts in this layer.

Declaration
public double Opacity { get; set; }
Property Value
Type Description
double
Remarks

The value must be between 0.0 (fully transparent) and 1.0 (no additional transparency). This value is multiplicative with any existing transparency, for instance from a Brush or image transparency. The default value is 1.

This property, unlike Visible, does not change whether any objects are found by the "Find..." methods.

See Also

Parts

This read-only property returns a read-only collection for this Layer's Parts.

Declaration
public IReadOnlyCollection<Part> Parts { get; }
Property Value
Type Description
IReadOnlyCollection<Part>
Remarks

The Parts can be Nodes, Links, Groups, Adornments, or simple Parts.

Pickable

Gets or sets whether methods such as FindElementAt(Point, Func<GraphObject, GraphObject>, Predicate<GraphObject>) find any of the objects in this layer.

Declaration
public bool Pickable { get; set; }
Property Value
Type Description
bool
Remarks

The default value is true. When this property is false, all of the "Find..." methods will fail to find parts that are in this layer.

Note that setting pickable to false does not prevent users from selecting nodes. It does prevent them from selecting nodes by clicking on them, but does not prevent selection through other mechanisms such as the DragSelectingTool or SelectAll() or calls to Select(Part).

You can control whether individual GraphObjects are "hittable" by setting Pickable.

See Also

Visible

Gets or sets whether the user may view any of the objects in this layer.

Declaration
public bool Visible { get; set; }
Property Value
Type Description
bool
Remarks

The default value is true -- all visible Parts are drawn. When this property is false, all of the "Find..." methods will fail to find parts that are in this layer.

See Also

Methods

FindElementAt(Point, Func<GraphObject, GraphObject>, Predicate<GraphObject>)

A convenience function for FindElementAt<T>(Point, Func<GraphObject, T>, Predicate<T>), returning a GraphObject rather than a specified type.

Declaration
public GraphObject FindElementAt(Point p, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null)
Parameters
Type Name Description
Point p
Func<GraphObject, GraphObject> navig
Predicate<GraphObject> pred
Returns
Type Description
GraphObject

FindElementAt<T>(Point, Func<GraphObject, T>, Predicate<T>)

Find the front-most GraphObject in this layer at the given point in document coordinates.

Declaration
public T FindElementAt<T>(Point p, Func<GraphObject, T> navig = null, Predicate<T> pred = null) where T : GraphObject
Parameters
Type Name Description
Point p

A Point in document coordinates.

Func<GraphObject, T> navig

A function taking a GraphObject and returning a GraphObject, defaulting to the identity.

Predicate<T> pred

A function taking the GraphObject returned by navig and returning true if that element should be returned, defaulting to a predicate that always returns true.

Returns
Type Description
T

The first GraphObject in the Z-order, or else null.

Type Parameters
Name Description
T
Remarks

If Visible is false, this method will not find any elements in this layer. However, Opacity does not affect this method.

FindElementsAt(Point, Func<GraphObject, GraphObject>, Predicate<GraphObject>, ICollection<GraphObject>)

A convenience function for FindElementsAt<T, S>(Point, Func<GraphObject, T>, Predicate<T>, S), returning a collection of GraphObjects rather than a collection of the specified type.

Declaration
public ICollection<GraphObject> FindElementsAt(Point p, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null, ICollection<GraphObject> coll = null)
Parameters
Type Name Description
Point p
Func<GraphObject, GraphObject> navig
Predicate<GraphObject> pred
ICollection<GraphObject> coll
Returns
Type Description
ICollection<GraphObject>

FindElementsAt<T, S>(Point, Func<GraphObject, T>, Predicate<T>, S)

Return a collection of the GraphObjects of this layer at the given point in document coordinates.

Declaration
public S FindElementsAt<T, S>(Point p, Func<GraphObject, T> navig = null, Predicate<T> pred = null, S coll = null) where T : GraphObject where S : class, ICollection<T>
Parameters
Type Name Description
Point p

A Point in document coordinates.

Func<GraphObject, T> navig

A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

Predicate<T> pred

A function taking the GraphObject returned by navig and returning true if that element should be returned, defaulting to a predicate that always returns true.

S coll

An optional collection to add the results to.

Returns
Type Description
S

a collection of GraphObjects that will contain all GraphObjects located at Point p, or else an empty collection. If a collection was passed in, it is returned.

Type Parameters
Name Description
T
S
Remarks

If Visible is false, this method will not find any elements in this layer. However, Opacity does not affect this method.

FindElementsIn(Rect, Func<GraphObject, GraphObject>, Predicate<GraphObject>, bool, ICollection<GraphObject>)

A convenience function for FindElementsIn<T, S>(Rect, Func<GraphObject, T>, Predicate<T>, bool, S), returning a collection of GraphObjects rather than a collection of the specified type.

Declaration
public ICollection<GraphObject> FindElementsIn(Rect r, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null, bool partialInclusion = false, ICollection<GraphObject> coll = null)
Parameters
Type Name Description
Rect r
Func<GraphObject, GraphObject> navig
Predicate<GraphObject> pred
bool partialInclusion
ICollection<GraphObject> coll
Returns
Type Description
ICollection<GraphObject>

FindElementsIn<T, S>(Rect, Func<GraphObject, T>, Predicate<T>, bool, S)

Returns a collection of all GraphObjects that are inside or that intersect a given Rect in document coordinates.

Declaration
public S FindElementsIn<T, S>(Rect r, Func<GraphObject, T> navig = null, Predicate<T> pred = null, bool partialInclusion = false, S coll = null) where T : GraphObject where S : class, ICollection<T>
Parameters
Type Name Description
Rect r

A Rect in document coordinates.

Func<GraphObject, T> navig

A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

Predicate<T> pred

A function taking the GraphObject returned by navig and returning true if that element should be returned, defaulting to a predicate that always returns true.

bool partialInclusion

Whether an element can match if it merely intersects the rectangular area (true) or if it must be entirely inside the rectangular area (false). The default value is false.

S coll

An optional collection to add the results to.

Returns
Type Description
S

a collection of GraphObjects that will contain all GraphObjects located in or near Rect r, or else an empty collection. If a collection was passed in, it is returned.

Type Parameters
Name Description
T
S
Remarks

If Visible is false, this method will not find any elements in this layer. However, Opacity does not affect this method.

FindElementsNear(Point, double, Func<GraphObject, GraphObject>, Predicate<GraphObject>, bool, ICollection<GraphObject>)

A convenience function for FindElementsNear<T, S>(Point, double, Func<GraphObject, T>, Predicate<T>, bool, S), returning a collection of GraphObjects rather than a collection of the specified type.

Declaration
public ICollection<GraphObject> FindElementsNear(Point p, double dist, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null, bool partialInclusion = true, ICollection<GraphObject> coll = null)
Parameters
Type Name Description
Point p
double dist
Func<GraphObject, GraphObject> navig
Predicate<GraphObject> pred
bool partialInclusion
ICollection<GraphObject> coll
Returns
Type Description
ICollection<GraphObject>

FindElementsNear<T, S>(Point, double, Func<GraphObject, T>, Predicate<T>, bool, S)

Returns a collection of all GraphObjects that are within a certain distance of a given point in document coordinates.

Declaration
public S FindElementsNear<T, S>(Point p, double dist, Func<GraphObject, T> navig = null, Predicate<T> pred = null, bool partialInclusion = true, S coll = null) where T : GraphObject where S : class, ICollection<T>
Parameters
Type Name Description
Point p

A Point in document coordinates.

double dist

The distance from the point.

Func<GraphObject, T> navig

A function taking a GraphObject and returning a GraphObject, defaulting to the identity. If this function returns null, the given GraphObject will not be included in the results.

Predicate<T> pred

A function taking the GraphObject returned by navig and returning true if that element should be returned, defaulting to a predicate that always returns true.

bool partialInclusion

Whether an element can match if it merely intersects the circular area (true) or if it must be entirely inside the circular area (false). The default value is true.

S coll

An optional collection to add the results to.

Returns
Type Description
S

a collection of GraphObjects that will contain all GraphObjects located at Point p, or else an empty collection. If a collection was passed in, it is returned.

Type Parameters
Name Description
T
S
Remarks

If Visible is false, this method will not find any elements in this layer. However, Opacity does not affect this method.