Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CircleArcTo.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
11 public class CircleArcTo : Point, ISegment
12 {
13 private LengthAttribute radius;
14 private BooleanAttribute clockwise;
15
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "CircleArcTo";
30
35 {
36 get => this.radius;
37 set => this.radius = value;
38 }
39
44 {
45 get => this.clockwise;
46 set => this.clockwise = value;
47 }
48
53 public override Task FromXml(XmlElement Input)
54 {
55 this.radius = new LengthAttribute(Input, "radius", this.Document);
56 this.clockwise = new BooleanAttribute(Input, "clockwise", this.Document);
57
58 return base.FromXml(Input);
59 }
60
65 public override void ExportAttributes(XmlWriter Output)
66 {
67 base.ExportAttributes(Output);
68
69 this.radius?.Export(Output);
70 this.clockwise?.Export(Output);
71 }
72
79 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
80 {
81 return new CircleArcTo(Document, Parent);
82 }
83
88 public override void CopyContents(ILayoutElement Destination)
89 {
90 base.CopyContents(Destination);
91
92 if (Destination is CircleArcTo Dest)
93 {
94 Dest.radius = this.radius?.CopyIfNotPreset(Destination.Document);
95 Dest.clockwise = this.clockwise?.CopyIfNotPreset(Destination.Document);
96 }
97 }
98
104 public override async Task DoMeasureDimensions(DrawingState State)
105 {
106 await base.DoMeasureDimensions(State);
107
108 EvaluationResult<Length> RadiusLength = await this.radius.TryEvaluate(State.Session);
109 if (RadiusLength.Ok)
110 State.CalcDrawingSize(RadiusLength.Result, ref this.r, true, (ILayoutElement)this);
111 else
112 this.defined = false;
113
114 EvaluationResult<bool> Clockwise = await this.clockwise.TryEvaluate(State.Session);
115 if (Clockwise.Ok)
116 this.clockDir = Clockwise.Result;
117 else
118 this.defined = false;
119 }
120
126 public virtual Task Measure(DrawingState State, PathState PathState)
127 {
128 if (this.defined)
130
131 return Task.CompletedTask;
132 }
133
137 protected float r;
138
142 protected bool clockDir;
143
150 public virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
151 {
152 if (this.defined)
153 {
155 Path.ArcTo(this.r, this.r, 0, SKPathArcSize.Small,
156 this.clockDir ? SKPathDirection.Clockwise : SKPathDirection.CounterClockwise,
157 this.xCoordinate, this.yCoordinate);
158 }
159
160 return Task.CompletedTask;
161 }
162
167 public override void ExportStateAttributes(XmlWriter Output)
168 {
169 base.ExportStateAttributes(Output);
170
171 this.radius?.ExportState(Output);
172 this.clockwise?.ExportState(Output);
173 }
174
175 // TODO: IDirectedElement
176 }
177}
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 circle arc to a point, relative to the origio of the current container
Definition: CircleArcTo.cs:12
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: CircleArcTo.cs:65
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: CircleArcTo.cs:79
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: CircleArcTo.cs:167
override string LocalName
Local name of type of element.
Definition: CircleArcTo.cs:29
virtual Task Measure(DrawingState State, PathState PathState)
Measures layout entities and defines unassigned properties.
Definition: CircleArcTo.cs:126
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: CircleArcTo.cs:88
CircleArcTo(Layout2DDocument Document, ILayoutElement Parent)
Draws a circle arc to a point, relative to the origio of the current container
Definition: CircleArcTo.cs:21
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: CircleArcTo.cs:104
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: CircleArcTo.cs:53
virtual Task Draw(DrawingState State, PathState PathState, SKPath Path)
Draws layout entities.
Definition: CircleArcTo.cs:150
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.