Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EllipseArcTo.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
11 public class EllipseArcTo : Point, ISegment
12 {
13 private LengthAttribute radiusX;
14 private LengthAttribute radiusY;
15 private BooleanAttribute clockwise;
16
23 : base(Document, Parent)
24 {
25 }
26
30 public override string LocalName => "EllipseArcTo";
31
36 {
37 get => this.radiusX;
38 set => this.radiusX = value;
39 }
40
45 {
46 get => this.radiusY;
47 set => this.radiusY = value;
48 }
49
54 {
55 get => this.clockwise;
56 set => this.clockwise = value;
57 }
58
63 public override Task FromXml(XmlElement Input)
64 {
65 this.radiusX = new LengthAttribute(Input, "radiusX", this.Document);
66 this.radiusY = new LengthAttribute(Input, "radiusY", this.Document);
67 this.clockwise = new BooleanAttribute(Input, "clockwise", this.Document);
68
69 return base.FromXml(Input);
70 }
71
76 public override void ExportAttributes(XmlWriter Output)
77 {
78 base.ExportAttributes(Output);
79
80 this.radiusX?.Export(Output);
81 this.radiusY?.Export(Output);
82 this.clockwise?.Export(Output);
83 }
84
91 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
92 {
93 return new EllipseArcTo(Document, Parent);
94 }
95
100 public override void CopyContents(ILayoutElement Destination)
101 {
102 base.CopyContents(Destination);
103
104 if (Destination is EllipseArcTo Dest)
105 {
106 Dest.radiusX = this.radiusX?.CopyIfNotPreset(Destination.Document);
107 Dest.radiusY = this.radiusY?.CopyIfNotPreset(Destination.Document);
108 Dest.clockwise = this.clockwise?.CopyIfNotPreset(Destination.Document);
109 }
110 }
111
117 public override async Task DoMeasureDimensions(DrawingState State)
118 {
119 await base.DoMeasureDimensions(State);
120
121 EvaluationResult<Length> RadiusLength = await this.radiusX.TryEvaluate(State.Session);
122 if (RadiusLength.Ok)
123 State.CalcDrawingSize(RadiusLength.Result, ref this.rX, true, this);
124 else
125 this.defined = false;
126
127 RadiusLength = await this.radiusY.TryEvaluate(State.Session);
128 if (RadiusLength.Ok)
129 State.CalcDrawingSize(RadiusLength.Result, ref this.rY, false, this);
130 else
131 this.defined = false;
132
133 EvaluationResult<bool> Clockwise = await this.clockwise.TryEvaluate(State.Session);
134 if (Clockwise.Ok)
135 this.clockDir = Clockwise.Result;
136 else
137 this.defined = false;
138 }
139
145 public virtual Task Measure(DrawingState State, PathState PathState)
146 {
147 if (this.defined)
149
150 return Task.CompletedTask;
151 }
152
156 protected float rX;
157
161 protected float rY;
162
166 protected bool clockDir;
167
174 public virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
175 {
176 if (this.defined)
177 {
179 Path.ArcTo(this.rX, this.rY, 0, SKPathArcSize.Small,
180 this.clockDir ? SKPathDirection.Clockwise : SKPathDirection.CounterClockwise,
181 this.xCoordinate, this.yCoordinate);
182 }
183
184 return Task.CompletedTask;
185 }
186
191 public override void ExportStateAttributes(XmlWriter Output)
192 {
193 base.ExportStateAttributes(Output);
194
195 this.radiusX?.ExportState(Output);
196 this.radiusY?.ExportState(Output);
197 this.clockwise?.ExportState(Output);
198 }
199
200 // TODO: IDirectedElement
201 }
202}
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
Definition: Attribute.cs:187
void ExportState(XmlWriter Output)
Exports the state of the attribute.
Definition: Attribute.cs:199
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Definition: Attribute.cs:256
BooleanAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
LengthAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
Variables Session
Current session.
Definition: DrawingState.cs:91
void CalcDrawingSize(Length L, ref float Size, bool Horizontal, ILayoutElement Element)
Converts a defined length to drawing size.
Draws a ellipse arc to a point, relative to the origio of the current container
Definition: EllipseArcTo.cs:12
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: EllipseArcTo.cs:91
EllipseArcTo(Layout2DDocument Document, ILayoutElement Parent)
Draws a ellipse arc to a point, relative to the origio of the current container
Definition: EllipseArcTo.cs:22
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: EllipseArcTo.cs:76
virtual Task Measure(DrawingState State, PathState PathState)
Measures layout entities and defines unassigned properties.
virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
Draws layout entities.
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: EllipseArcTo.cs:63
override string LocalName
Local name of type of element.
Definition: EllipseArcTo.cs:30
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
void Set(float X, float Y)
Sets a new coordinate
Definition: PathState.cs:161
Layout2DDocument Document
Layout document.
bool defined
If element is well-defined.
Abstract base class for layout elements with one point.
Definition: Point.cs:11
float yCoordinate
Measured Y-coordinate
Definition: Point.cs:122
float xCoordinate
Measured X-coordinate
Definition: Point.cs:117
Base interface for all layout elements.
Layout2DDocument Document
Layout document.