Class LayerList
- Namespace
- CADability.Attribute
- Assembly
- CADability.dll
A list of Layers, always sorted alphabetically by name. The names must be unique: adding or renaming a layer so that a name would occur twice throws a NameAlreadyExistsException. The list is owned by a project or by the global settings, keeps a current layer and is displayed in the property page with its layers as sub entries.
public class LayerList : PropertyEntryImpl, IPropertyEntry, IShowProperty, INotifyModification, ISerializable, ICollection, IEnumerable, IAttributeList, ICommandHandler, IDeserializationCallback, IJsonSerialize, IJsonSerializeDone
- Inheritance
-
LayerList
- Implements
- Inherited Members
Constructors
LayerList()
Creates an empty layer list without a current layer. A new Project gets a clone of the global layer list, so this constructor is rarely needed; GetDefault() creates a list with the default layers.
public LayerList()
LayerList(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected LayerList(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Properties
ColorList
The ColorList of the owner of this list (the project or the global settings), or null when the list has no owner.
public ColorList ColorList { get; }
Property Value
ContextMenu
Must be overridden, when Flags contains PropertyEntryType.ContextMenu. See ContextMenu
public override MenuWithHandler[] ContextMenu { get; }
Property Value
Count
The number of layers in the list.
public int Count { get; }
Property Value
Current
The current layer: the layer that newly constructed objects get (see SetDefaults(IGeoObject)), shown in bold in the control center. When no current layer has been set, the first layer of the list is used. Only a layer that belongs to this list can be made current; a layer that is not in the list is ignored.
public Layer Current { get; set; }
Property Value
Flags
Implementation of Flags: the derived class states what the entry is and what the user can do with it. The flags must match the overridden members, e.g. HasSubEntries requires SubItems, ValueEditable requires Value and EndEdit(bool, bool, string), DropDown requires GetDropDownList() and ListBoxSelected(int).
public override PropertyEntryType Flags { get; }
Property Value
IsSynchronized
Implements IsSynchronized. The list is not synchronized, the value is false.
public bool IsSynchronized { get; }
Property Value
this[int]
Returns the layer at the given position in the alphabetical order of the names, or null when the index is out of range.
public Layer this[int Index] { get; }
Parameters
Property Value
- Layer
the layer, or null
Owner
The Project or Settings that holds this list. It is set by the owner when the list is added to it; the list asks it before removing a layer (see Remove(Layer)) and forwards changes of its layers to it.
public IAttributeListContainer Owner { get; set; }
Property Value
SubItems
Must be overridden, when Flags contains PropertyEntryType.HasSubEntries. See SubItems
public override IPropertyEntry[] SubItems { get; }
Property Value
SyncRoot
An object that can be used to lock the list for synchronized access (SyncRoot).
public object SyncRoot { get; }
Property Value
Methods
Add(Layer)
Adds a new layer to the list. The first layer added becomes the current layer. A NameAlreadyExistsException is thrown if there is already a layer with the same name.
public void Add(Layer LayerToAdd)
Parameters
LayerToAddLayerthe layer to add
CopyTo(Array, int)
Copies the layers, in alphabetical order of their names, to the given array (CopyTo(Array, int)).
public void CopyTo(Array array, int index)
Parameters
arrayArraythe destination array, which must be large enough
indexintthe index in
arrayat which copying begins
CreateOrFind(string)
Returns the layer with the given name, creating and adding it to the list when there is none yet. This is the
usual way to get a layer for an object: project.LayerList.CreateOrFind("3D").
public Layer CreateOrFind(string Name)
Parameters
Namestringthe name of the layer
Returns
- Layer
the existing or newly created layer
Find(string)
Returns the layer with the given name, or null if there is no such layer in the list.
public Layer Find(string Name)
Parameters
Namestringthe name of the layer
Returns
- Layer
the layer, or null
FindIndex(Layer)
Returns the position of the given layer object in the alphabetical order of the list, as used by the indexer.
public int FindIndex(Layer ly)
Parameters
lyLayerthe layer to look for (compared by reference)
Returns
- int
the index, or -1 when the layer is not in this list
GetDefault()
Creates a layer list with the layer names taken from the string resource "LayerList.Default". Used when no global layer list is available.
public static LayerList GetDefault()
Returns
- LayerList
the default layer list
GetEnumerator()
Enumerates the layers in alphabetical order of their names, so foreach (Layer l in layerList) can be used.
public IEnumerator GetEnumerator()
Returns
- IEnumerator
an enumerator over the Layer objects
GetObjectData(IJsonWriteData)
Writes the layers and the current layer for the JSON serialization (IJsonSerialize).
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatareceives the data
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
Remove(Layer)
Removes a layer from the list. Nothing happens if the layer is not in the list or if the owner of the list (project or settings) refuses the removal, e.g. because the layer is still in use.
public void Remove(Layer LayerToRemove)
Parameters
LayerToRemoveLayerthe layer to remove
SerializationDone(JsonSerialize)
Callback of the JSON serialization (IJsonSerializeDone): after all objects have been read, the layers have their names and the sorted list is built.
public void SerializationDone(JsonSerialize jsonSerialize)
Parameters
jsonSerializeJsonSerializethe serializer
SetObjectData(IJsonReadData)
Restores the layers and the current layer from the JSON data written by GetObjectData(IJsonWriteData) (IJsonSerialize). The layers may still be empty here, so the list, which is sorted by their names, is built in SerializationDone(JsonSerialize).
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDatathe data to read from
ToArray()
Returns all layers of the list as an array, sorted alphabetically by name.
public Layer[] ToArray()
Returns
- Layer[]
a new array with the layers; empty when the list is empty
Events
DidModifyEvent
Raised when a layer is added, removed or renamed (INotifyModification). Changes of the other properties of a layer are forwarded to the Owner instead.
public event DidModifyDelegate DidModifyEvent
Event Type
LayerAddedEvent
Raised after a layer has been added to the list by Add(Layer) (this includes CreateOrFind(string) and the commands of the context menu). Views use it to update their lists of visible layers (CheckedLayerList).
public event LayerList.LayerAddedDelegate LayerAddedEvent
Event Type
LayerRemovedEvent
Raised after a layer has been removed from the list by Remove(Layer).
public event LayerList.LayerRemovedDelegate LayerRemovedEvent