Files
VirtualChemistry.Demo/Scenes/MainControlPanel.cs
2024-06-21 20:57:19 +08:00

81 lines
2.3 KiB
C#

using Godot;
using System.Linq;
using VirtualChemistry.Chemistry.Compounds.Implements;
using VirtualChemistry.Chemistry.Mixtures.Implements;
public partial class MainControlPanel : HBoxContainer
{
private HSlider EnvTemperature { get; set; }
private HSlider ContainerVolume { get; set; }
private HomogeneousMixture SelectedMixture { get; set; }
private Label Density { get; set; }
private Label Volume { get; set; }
private Label HeatConductivity { get; set; }
private Label Amount { get; set; }
private Label Temperature { get; set; }
private Tree Compounds { get; set; }
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
EnvTemperature = GetNode<HSlider>("V1/EnvTemperature");
ContainerVolume = GetNode<HSlider>("V1/ContainerVolume");
Density = GetNode<Label>("V2/HDensity/Density");
Volume = GetNode<Label>("V2/HVolume/Volume");
HeatConductivity = GetNode<Label>("V2/HHeatConductivity/HeatConductivity");
Amount = GetNode<Label>("V2/HAmount/Amount");
Temperature = GetNode<Label>("V2/HTemperature/Temperature");
Compounds = GetNode<Tree>("V3/Compounds");
GlobalScene.MainControlPanel = this;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void Update(HomogeneousMixture mixture)
{
SelectedMixture = mixture;
}
public void Update()
{
if (SelectedMixture == HomogeneousMixture.Null)
return;
Density.Text = $"{SelectedMixture.Density}";
Volume.Text = $"{SelectedMixture.Volume}";
HeatConductivity.Text = $"{SelectedMixture.HeatConductivity}";
Amount.Text = $"{SelectedMixture.Amount}";
Temperature.Text = $"{SelectedMixture.Temperature}";
}
private void BuildTree()
{
Compounds.Clear();
var groups = SelectedMixture.Compounds.GroupBy(x => x.Expression);
foreach (var group in groups)
{
TreeItem t = Compounds.CreateItem();
t.SetText(0, group.Key);
t.SetSelectable(0, false);
int i = 1;
foreach (Compound c in group)
{
TreeItem x = Compounds.CreateItem(t);
x.SetText(0, $"{i}th isomer");
x.SetMeta("isoExp", c.IsoRepresentation);
}
}
}
private void IsomerSelectedHandler()
{
GlobalScene.Demo.FullRepr.Text = Compounds
.GetSelected()
.GetMeta("isoExp")
.AsString();
}
}