Class Layer
- Namespace
- Northwoods.Go
- Assembly
- Northwoods.GoDiagram.WinForms.dll
Layers are how named collections of Parts are drawn in front or behind other collections of Parts in a Diagram.
public class Layer
- Inheritance
-
Layer
- Inherited Members
Remarks
Layers can only contain Parts, such as Nodes and Links. They cannot hold GraphObjects directly.
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.
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. A Part cannot be in more than one Layer at a time.
Each Diagram starts off with the following list of Layers:
- "Grid"
- "ViewportBackground"
- "Background"
- "" (the default layer)
- "Foreground"
- "ViewportForeground"
- "Adornment"
- "Tool"
Layers are drawn and presented in order. Parts are normally put in the default layer.
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.
The "Grid", "Adornment", "Tool", and both "Viewport..." layers are considered IsTemporary. Changes to objects in temporary layers are not recorded by the UndoManager. Parts in temporary layers are not selected. Objects in temporary layers do not receive click events unless you set their IsActionable to true.
Use FindLayer(string) to get the Layer with a particular name. 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. 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.
public Layer()
Properties
AllowCopy
Gets or sets whether the user may copy objects in this layer.
public bool AllowCopy { get; set; }
Property Value
Remarks
The initial value is true.
AllowDelete
Gets or sets whether the user may delete objects in this layer.
public bool AllowDelete { get; set; }
Property Value
Remarks
The initial value is true.
AllowGroup
Gets or sets whether the user may group parts together in this layer.
public bool AllowGroup { get; set; }
Property Value
Remarks
The initial value is true.
AllowLink
Gets or sets whether the user may draw new links in this layer.
public bool AllowLink { get; set; }
Property Value
Remarks
The initial value is true.
AllowMove
Gets or sets whether the user may move objects in this layer.
public bool AllowMove { get; set; }
Property Value
Remarks
The initial value is true.
AllowRelink
Gets or sets whether the user may reconnect existing links in this layer.
public bool AllowRelink { get; set; }
Property Value
Remarks
The initial value is true.
AllowReshape
Gets or sets whether the user may reshape parts in this layer.
public bool AllowReshape { get; set; }
Property Value
Remarks
The initial value is true.
AllowResize
Gets or sets whether the user may resize parts in this layer.
public bool AllowResize { get; set; }
Property Value
Remarks
The initial value is true.
AllowRotate
Gets or sets whether the user may rotate parts in this layer.
public bool AllowRotate { get; set; }
Property Value
Remarks
The initial value is true.
AllowSelect
Gets or sets whether the user may select objects in this layer.
public bool AllowSelect { get; set; }
Property Value
Remarks
The initial value is true.
AllowTextEdit
Gets or sets whether the user may do in-place text editing in this layer.
public bool AllowTextEdit { get; set; }
Property Value
Remarks
The initial value is true.
AllowUngroup
Gets or sets whether the user may ungroup existing groups in this layer.
public bool AllowUngroup { get; set; }
Property Value
Remarks
The initial value is true.
Diagram
This read-only property returns the Diagram that is using this Layer.
public Diagram Diagram { get; }
Property Value
IsInDocumentBounds
Gets or sets whether or not a layer is included in the DocumentBounds computation.
public bool IsInDocumentBounds { get; set; }
Property Value
Remarks
Default value is true.
IsTemporary
Gets or sets whether the objects in this layer are considered temporary.
public bool IsTemporary { get; set; }
Property Value
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.
IsViewportAligned
Gets or sets whether this layer enforces its Parts to remain in viewport coordinates.
public bool IsViewportAligned { get; set; }
Property Value
Remarks
Diagrams have two default layers with this set to true
: "ViewportBackground" and "ViewportForeground".
These layers also have IsInDocumentBounds set to false and IsTemporary set to true.
If you set this property on a layer, you may wish to set those properties also.
Parts in viewport coordinate layers will get their positions and scales set automatically, to remain invariantly placed and sized in the viewport.
Instead of position, Parts are placed by setting their Alignment and AlignmentFocus values in the same way they are used in a Spot Panel. However, the Alignment spot, if it is Default as it is by default, will be treated as BottomRight rather than Center as a "Spot" Panel does. The AlignmentFocus spot, if it is Default as it is by default, will be treated as the same Spot as the Alignment without any offset. This is convenient for aligning Parts along the sides of the viewport. If you wish to arrange a Part to be near the side of the viewport at a certain distance, specify that in the Alignment Spot. For example, the following code places the red circle near the bottom right corner, but inset by 10 units from both the right and the bottom sides.
myDiagram.Add(
new Part {
LayerName = "ViewportBackground",
Alignment = new Spot(1, 1, -10, -10)
}
.Add(
new Shape("Circle") { Fill = "red", Width = 20, Height = 20 }
);
For example usage, see Legends and Titles.
Parts in viewport coordinate layers may have unexpected interactions if they are connected to Parts in non-viewport coordinate layers. Setting this value to true automatically sets IsInDocumentBounds to false.
Name
Gets or sets the name for this layer.
public string Name { get; set; }
Property Value
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.
public double Opacity { get; set; }
Property Value
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.
public IReadOnlyCollection<Part> Parts { get; }
Property Value
Remarks
Pickable
Gets or sets whether methods such as FindElementAt(Point, Func<GraphObject, GraphObject>, Predicate<GraphObject>) find any of the objects in this layer.
public bool Pickable { get; set; }
Property Value
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.
public bool Visible { get; set; }
Property Value
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.
public GraphObject FindElementAt(Point p, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null)
Parameters
p
Pointnavig
Func<GraphObject, GraphObject>pred
Predicate<GraphObject>
Returns
FindElementAt<T>(Point, Func<GraphObject, T>, Predicate<T>)
Find the front-most GraphObject in this layer at the given point in document coordinates.
public T FindElementAt<T>(Point p, Func<GraphObject, T> navig = null, Predicate<T> pred = null) where T : GraphObject
Parameters
p
PointA Point in document coordinates.
navig
Func<GraphObject, T>A function taking a GraphObject and returning a GraphObject, defaulting to the identity.
pred
Predicate<T>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
- T
The first GraphObject in the Z-order, or else null.
Type Parameters
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.
public ICollection<GraphObject> FindElementsAt(Point p, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null, ICollection<GraphObject> coll = null)
Parameters
p
Pointnavig
Func<GraphObject, GraphObject>pred
Predicate<GraphObject>coll
ICollection<GraphObject>
Returns
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.
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
p
PointA Point in document coordinates.
navig
Func<GraphObject, T>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.
pred
Predicate<T>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.
coll
SAn optional collection to add the results to.
Returns
- 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
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.
public ICollection<GraphObject> FindElementsIn(Rect r, Func<GraphObject, GraphObject> navig = null, Predicate<GraphObject> pred = null, bool partialInclusion = false, ICollection<GraphObject> coll = null)
Parameters
r
Rectnavig
Func<GraphObject, GraphObject>pred
Predicate<GraphObject>partialInclusion
boolcoll
ICollection<GraphObject>
Returns
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.
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
r
RectA Rect in document coordinates.
navig
Func<GraphObject, T>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.
pred
Predicate<T>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.
partialInclusion
boolWhether 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.
coll
SAn optional collection to add the results to.
Returns
- 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
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.
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
p
Pointdist
doublenavig
Func<GraphObject, GraphObject>pred
Predicate<GraphObject>partialInclusion
boolcoll
ICollection<GraphObject>
Returns
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.
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
p
PointA Point in document coordinates.
dist
doubleThe distance from the point.
navig
Func<GraphObject, T>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.
pred
Predicate<T>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.
partialInclusion
boolWhether 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.
coll
SAn optional collection to add the results to.
Returns
- 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
T
S