Table of Contents

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

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

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

ColorList

ContextMenu

Must be overridden, when Flags contains PropertyEntryType.ContextMenu. See ContextMenu

public override MenuWithHandler[] ContextMenu { get; }

Property Value

MenuWithHandler[]

Count

The number of layers in the list.

public int Count { get; }

Property Value

int

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

Layer

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

PropertyEntryType

IsSynchronized

Implements IsSynchronized. The list is not synchronized, the value is false.

public bool IsSynchronized { get; }

Property Value

bool

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

Index int

index from 0 to Count-1

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

IAttributeListContainer

SubItems

Must be overridden, when Flags contains PropertyEntryType.HasSubEntries. See SubItems

public override IPropertyEntry[] SubItems { get; }

Property Value

IPropertyEntry[]

SyncRoot

An object that can be used to lock the list for synchronized access (SyncRoot).

public object SyncRoot { get; }

Property Value

object

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

LayerToAdd Layer

the 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

array Array

the destination array, which must be large enough

index int

the index in array at 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

Name string

the 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

Name string

the 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

ly Layer

the 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

data IJsonWriteData

receives 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

info SerializationInfo

receives the data

context StreamingContext

the 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

LayerToRemove Layer

the 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

jsonSerialize JsonSerialize

the 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

data IJsonReadData

the 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

DidModifyDelegate

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

LayerList.LayerAddedDelegate

LayerRemovedEvent

Raised after a layer has been removed from the list by Remove(Layer).

public event LayerList.LayerRemovedDelegate LayerRemovedEvent

Event Type

LayerList.LayerRemovedDelegate