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
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
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
namestringthe name, unique within the LinePatternList it is added to
patterndouble[]alternating stroke and gap lengths, e.g.
2.0, 2.0for a dashed line
Properties
ContextMenu
Must be overridden, when Flags contains PropertyEntryType.ContextMenu. See ContextMenu
public override MenuWithHandler[] ContextMenu { get; }
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
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
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
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
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
Scale
Gets or sets the LinePattern.Scaling of this LinePattern.
public LinePattern.Scaling Scale { get; set; }
Property Value
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
SubItems
Must be overridden, when Flags contains PropertyEntryType.HasSubEntries. See SubItems
public override IPropertyEntry[] SubItems { get; }
Property Value
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
ppIPropertyPagethe property page the entry was added to
Clone()
Returns a clone of this LinePattern
public LinePattern Clone()
Returns
EditTextChanged(string)
May be overridden when Flags contains PropertyEntryType.ValueEditable. See EditTextChanged(string),
public override bool EditTextChanged(string newValue)
Parameters
newValuestring
Returns
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
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
indexintindex of the pair, 0 to PatternCount-1
Returns
GetObjectData(IJsonWriteData)
Writes the name, pattern and scaling of this line pattern 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
GetStroke(int)
Returns the length of the stroke of the pair at the given index.
public double GetStroke(int index)
Parameters
indexintindex of the pair, 0 to PatternCount-1
Returns
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
namestringthe name the LinePattern was stored under
infoSerializationInfothe serialization data
contextStreamingContextthe 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
ppIPropertyPagethe 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
dataIJsonReadDatathe 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
indexintindex of the pair, 0 to PatternCount-1
strokedoublethe length of the stroke in the units of Scale
gapdoublethe length of the gap that follows the stroke
Exceptions
- IndexOutOfRangeException
when the index is out of range