Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ImageInternal.cs
1using SkiaSharp;
2using System.Threading.Tasks;
3using System.Xml;
5using Waher.Script;
7
9{
13 public class ImageInternal : Image
14 {
15 private StringAttribute cid;
16
23 : base(Document, Parent)
24 {
25 }
26
30 public override string LocalName => "ImageInternal";
31
36 {
37 get => this.cid;
38 set => this.cid = value;
39 }
40
45 public override Task FromXml(XmlElement Input)
46 {
47 this.cid = new StringAttribute(Input, "cid", this.Document);
48
49 return base.FromXml(Input);
50 }
51
56 public override void ExportAttributes(XmlWriter Output)
57 {
58 base.ExportAttributes(Output);
59
60 this.cid?.Export(Output);
61 }
62
69 public override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
70 {
71 return new ImageInternal(Document, Parent);
72 }
73
78 public override void CopyContents(ILayoutElement Destination)
79 {
80 base.CopyContents(Destination);
81
82 if (Destination is ImageInternal Dest)
83 Dest.cid = this.cid?.CopyIfNotPreset(Destination.Document);
84 }
85
92 protected override async Task<SKImage> LoadImage(DrawingState State)
93 {
94 string ContentId = await this.cid.Evaluate(State.Session, string.Empty);
95 if (string.IsNullOrEmpty(ContentId))
96 return null;
97
98 if (this.Document.TryGetContent(ContentId, out object Content))
99 return Content as SKImage;
100
101 if (State.Session.TryGetVariable(ContentId, out Variable v))
102 {
103 object Obj = v.ValueObject;
104
105 if (Obj is SKImage Image)
106 return Image;
107
108 if (Obj is PixelInformation Pixels)
109 return Pixels.CreateBitmap();
110
111 if (Obj is Graph Graph)
112 {
113 Pixels = Graph.CreatePixels(State.Session);
114 return Pixels.CreateBitmap();
115 }
116 }
117
118 return await this.Document.RaiseGetInternalImage(ContentId);
119 }
120
125 public override void ExportStateAttributes(XmlWriter Output)
126 {
127 base.ExportStateAttributes(Output);
128
129 this.cid?.ExportState(Output);
130 }
131 }
132}
Contains a 2D layout document.
bool TryGetContent(string ContentId, out object Content)
Tries to get content from attached content.
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
StringAttribute 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:89
Abstract base class for images.
Definition: Image.cs:15
An image provided by the caller, identified by a content id.
override ILayoutElement Create(Layout2DDocument Document, ILayoutElement Parent)
Creates a new instance of the layout element.
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
ImageInternal(Layout2DDocument Document, ILayoutElement Parent)
An image provided by the caller, identified by a content id.
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
override async Task< SKImage > LoadImage(DrawingState State)
Loads the image defined by the element.
override string LocalName
Local name of type of element.
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Layout2DDocument Document
Layout document.
Base class for graphs.
Definition: Graph.cs:88
PixelInformation CreatePixels()
Creates a bitmap of the graph.
Definition: Graph.cs:379
Contains pixel information
abstract SKImage CreateBitmap()
Creates an SKImage image. It must be disposed by the caller.
Contains information about a variable.
Definition: Variable.cs:10
virtual bool TryGetVariable(string Name, out Variable Variable)
Tries to get a variable object, given its name.
Definition: Variables.cs:56
Base interface for all layout elements.
Layout2DDocument Document
Layout document.