Table of Contents

Class LinePattern

Namespace
CADability.Attribute
Assembly
CADability.dll

A named attribute which defines a dash pattern for the display of curves: an array of alternating stroke and gap lengths (Pattern) and a LinePattern.Scaling which says whether these lengths are pixels, world units or layout units (mm on paper). An empty pattern means a solid line. Line patterns are kept in the LinePatternList of the project, are referenced by objects implementing ILinePattern and can be edited in the property grid.

public class LinePattern : PropertyEntryImpl, IPropertyEntry, IShowProperty, INamedAttribute, ISerializable, ICommandHandler, IJsonSerialize
Inheritance
LinePattern
Implements
Inherited Members

Constructors

LinePattern()

Creates an empty and unnamed LinePattern

public LinePattern()

LinePattern(SerializationInfo, StreamingContext)

Constructor required by deserialization

protected LinePattern(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

LinePattern(string, params double[])

Creates a line pattern with the given name and stroke/gap lengths, with Layout scaling. The array is taken over as it is; it should have an even number of elements (see Pattern), an empty array gives a solid line. The object does not belong to a list yet, see Add(LinePattern).

public LinePattern(string name, params double[] pattern)

Parameters

name string

the name, unique within the LinePatternList it is added to

pattern double[]

alternating stroke and gap lengths, e.g. 2.0, 2.0 for a dashed line

Properties

ContextMenu

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

public override MenuWithHandler[] ContextMenu { get; }

Property Value

MenuWithHandler[]

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

LabelText

An explicit label text. When set (not null) it is shown instead of the text from the StringTable; use it for entries whose label is not a fixed resource string, e.g. the name of an item. Call Refresh() after changing it while the entry is displayed.

public override string LabelText { get; set; }

Property Value

string

Name

The name of the line pattern, unique within its LinePatternList and shown in the control center. Setting a name that is already used by another entry of the list throws a NameAlreadyExistsException; otherwise the change is forwarded to the owner of the list (the project), which records it for undo.

public string Name { get; set; }

Property Value

string

Parent

The LinePatternList this line pattern belongs to, or null (Parent). It is set by the list when the line pattern is added or removed; the line pattern forwards its changes to it. Hides Parent, the parent of the entry in the control center.

public IAttributeList Parent { get; set; }

Property Value

IAttributeList

Pattern

The dash pattern as an array of alternating stroke and gap lengths in the units given by Scale: element 0 is the length of the first stroke, element 1 the length of the following gap, and so on; the pattern repeats along the curve. An empty array means a solid line. The getter returns the internal array, which must not be modified; the setter stores a copy (null is treated as empty), throws an ArgumentException for an odd number of elements, and forwards the change to the owner of the list (undoable).

public double[] Pattern { get; set; }

Property Value

double[]

PatternCount

The number of stroke/gap pairs in Pattern; 0 for a solid line.

public int PatternCount { get; }

Property Value

int

Scale

Gets or sets the LinePattern.Scaling of this LinePattern.

public LinePattern.Scaling Scale { get; set; }

Property Value

LinePattern.Scaling

Solid

True when the pattern is empty, i.e. the line is drawn continuously. Setting the property, whatever the value, removes the pattern and makes the line solid (undoable).

public bool Solid { get; set; }

Property Value

bool

SubItems

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

public override IPropertyEntry[] SubItems { get; }

Property Value

IPropertyEntry[]

Methods

Added(IPropertyPage)

Implementation of Added(IPropertyPage): memorizes the page in propertyPage and reports Added. Override it to subscribe to events while the entry is displayed, and call the base implementation.

public override void Added(IPropertyPage pp)

Parameters

pp IPropertyPage

the property page the entry was added to

Clone()

Returns a clone of this LinePattern

public LinePattern Clone()

Returns

LinePattern

EditTextChanged(string)

May be overridden when Flags contains PropertyEntryType.ValueEditable. See EditTextChanged(string),

public override bool EditTextChanged(string newValue)

Parameters

newValue string

Returns

bool

EndEdit(bool, bool, string)

Must be overridden when Flags contains PropertyEntryType.ValueEditable. See EndEdit(bool, bool, string)

public override void EndEdit(bool aborted, bool modified, string newValue)

Parameters

aborted bool
modified bool
newValue string

GetGap(int)

Returns the length of the gap of the pair at the given index, i.e. the gap that follows the stroke of that pair.

public double GetGap(int index)

Parameters

index int

index of the pair, 0 to PatternCount-1

Returns

double

the gap length in the units of Scale

GetObjectData(IJsonWriteData)

Writes the name, pattern and scaling of this line pattern 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

GetStroke(int)

Returns the length of the stroke of the pair at the given index.

public double GetStroke(int index)

Parameters

index int

index of the pair, 0 to PatternCount-1

Returns

double

the stroke length in the units of Scale

Read(string, SerializationInfo, StreamingContext)

Reads the LinePattern stored under the given name from the legacy binary serialization data (ISerializable). For use in the deserialization constructors of objects that have a line pattern; missing or incompatible entries yield null instead of an exception, so that older files can be read.

public static LinePattern Read(string name, SerializationInfo info, StreamingContext context)

Parameters

name string

the name the LinePattern was stored under

info SerializationInfo

the serialization data

context StreamingContext

the source of the serialization

Returns

LinePattern

the LinePattern, or null when there is no entry with that name or it is not a LinePattern

Removed(IPropertyPage)

Implementation of Removed(IPropertyPage): closes the undo context of the project (an edit may have been interrupted by removing the entry), reports Removed and forgets the page. Override it to unsubscribe from events, and call the base implementation.

public override void Removed(IPropertyPage pp)

Parameters

pp IPropertyPage

the property page the entry was removed from

SetObjectData(IJsonReadData)

Restores this line pattern from the JSON data written by GetObjectData(IJsonWriteData) (IJsonSerialize).

public void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

the data to read from

SetPattern(int, double, double)

Sets the stroke and gap lengths of the pair at the given index. The change is forwarded to the owner of the list (undoable).

public void SetPattern(int index, double stroke, double gap)

Parameters

index int

index of the pair, 0 to PatternCount-1

stroke double

the length of the stroke in the units of Scale

gap double

the length of the gap that follows the stroke

Exceptions

IndexOutOfRangeException

when the index is out of range