Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Circle.cs
1using System.Threading.Tasks;
2using System.Xml;
3using SkiaSharp;
5
7{
11 public class Circle : FigurePoint
12 {
13 private LengthAttribute radius;
14 private float r;
15
21 public Circle(Layout2DDocument Document, ILayoutElement Parent)
22 : base(Document, Parent)
23 {
24 }
25
29 public override string LocalName => "Circle";
30
35 {
36 get => this.radius;
37 set => this.radius = value;
38 }
39
44 public override Task FromXml(XmlElement Input)
45 {
46 this.radius = new LengthAttribute(Input, "radius", this.Document);
47 return base.FromXml(Input);
48 }
49
54 public override void ExportAttributes(XmlWriter Output)
55 {
56 base.ExportAttributes(Output);
57
58 this.radius?.Export(Output);
59 }
60
67 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
68 {
69 return new Circle(Document, Parent);
70 }
71
76 public override void CopyContents(ILayoutElement Destination)
77 {
78 base.CopyContents(Destination);
79
80 if (Destination is Circle Dest)
81 Dest.radius = this.radius?.CopyIfNotPreset(Destination.Document);
82 }
83
89 public override async Task DoMeasureDimensions(DrawingState State)
90 {
91 await base.DoMeasureDimensions(State);
92
93 EvaluationResult<Length> RadiusLength = await this.radius.TryEvaluate(State.Session);
94 if (RadiusLength.Ok)
95 {
96 State.CalcDrawingSize(RadiusLength.Result, ref this.r, true, (ILayoutElement)this);
97 this.Width = this.ExplicitWidth = this.Height = this.ExplicitHeight = 2 * this.r;
98 }
99 else
100 this.defined = false;
101
102 if (this.defined)
103 {
104 this.IncludePoint(this.xCoordinate - this.r, this.yCoordinate);
105 this.IncludePoint(this.xCoordinate + this.r, this.yCoordinate);
106 this.IncludePoint(this.xCoordinate, this.yCoordinate - this.r);
107 this.IncludePoint(this.xCoordinate, this.yCoordinate + this.r);
108 }
109 }
110
115 public override async Task Draw(DrawingState State)
116 {
117 if (this.defined)
118 {
119 SKPaint Fill = await this.TryGetFill(State);
120 if (!(Fill is null))
121 State.Canvas.DrawCircle(this.xCoordinate, this.yCoordinate, this.r, Fill);
122
123 SKPaint Pen = await this.TryGetPen(State);
124 if (!(Pen is null))
125 State.Canvas.DrawCircle(this.xCoordinate, this.yCoordinate, this.r, Pen);
126 }
127
128 await base.Draw(State);
129 }
130
135 public override void ExportStateAttributes(XmlWriter Output)
136 {
137 base.ExportStateAttributes(Output);
138
139 this.radius?.ExportState(Output);
140 }
141 }
142}
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
LengthAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
SKCanvas Canvas
Current drawing canvas.
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.
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: Circle.cs:54
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: Circle.cs:135
Circle(Layout2DDocument Document, ILayoutElement Parent)
A circle
Definition: Circle.cs:21
LengthAttribute RadiusAttribute
Radius
Definition: Circle.cs:35
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: Circle.cs:44
override async Task Draw(DrawingState State)
Draws layout entities.
Definition: Circle.cs:115
override string LocalName
Local name of type of element.
Definition: Circle.cs:29
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
Definition: Circle.cs:67
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: Circle.cs:76
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: Circle.cs:89
async Task< SKPaint > TryGetPen(DrawingState State)
Tries to get the pen associated with the element, if one is defined.
Definition: Figure.cs:111
async Task< SKPaint > TryGetFill(DrawingState State)
Tries to get the filling of the figure, if one is defined.
Definition: Figure.cs:130
Abstract base class for figures based on a point.
Definition: FigurePoint.cs:11
void IncludePoint(float X, float Y, float RX, float RY, float Angle)
Includes a point in the area measurement.
Layout2DDocument Document
Layout document.
bool defined
If element is well-defined.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.