Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eianlei committed May 25, 2021
1 parent 9307a3b commit 8b719a3
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 21 deletions.
25 changes: 13 additions & 12 deletions FillCalcWin/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*"></RowDefinition>
<RowDefinition Height="3*"></RowDefinition>
<RowDefinition Height="0*"></RowDefinition>
<RowDefinition Height="2.5*"></RowDefinition>
<RowDefinition Height="2.5*"></RowDefinition>
<RowDefinition Height="1*"></RowDefinition>
<RowDefinition Height="4*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Header="Current tank mix" Grid.Column="0" Grid.Row="0" Background="LavenderBlush" Opacity="0.9">
Expand Down Expand Up @@ -209,25 +209,26 @@
<ComboBoxItem IsSelected="True">Ideal Gas Law</ComboBoxItem>
<ComboBoxItem>Van Der Waals law</ComboBoxItem>
</ComboBox>-->
<TabControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
<TabControl Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"
SelectedIndex="{Binding Path=selected_tab}"
ToolTip="select your blending method to get instructions">
<TabItem Header="Air top">
<TextBlock x:Name="txt_air">Nothing yet</TextBlock>
ToolTip="select your blending method to get instructions" SelectionChanged="FillTypeChange">
<TabItem Header="Air top" Background="Azure">
<TextBlock x:Name="txt_air" Background="Azure">Plain air fill or topping with air</TextBlock>
</TabItem>
<TabItem Header="Nitrox CFM top">
<TextBlock x:Name="txt_nitrox">Nothing yet</TextBlock>
<TextBlock x:Name="txt_nitrox">Continous Flow Mix (CFM) with Nitrox, max 36% Oxygen</TextBlock>
</TabItem>
<TabItem Header="Trimix CFM top">
<TextBlock x:Name="txt_tmx">Nothing yet</TextBlock>
<TextBlock x:Name="txt_tmx">Continous Flow Mix (CFM) with Trimix</TextBlock>
</TabItem>
<TabItem Header="Partial Pressure">
<TextBlock x:Name="txt_pp">Nothing yet</TextBlock>
<TabItem Header="Partial Pressure" Background="Orange">
<TextBlock x:Name="txt_pp" Background="Orange">Partial Pressure filling, start with Helium, then Oxygen, top with air</TextBlock>
</TabItem>
<TabItem Header="He + Nitrox CFM">
<TextBlock x:Name="txt_henx">Nothing yet</TextBlock>
<TextBlock x:Name="txt_henx">Add Helium by decanting, then top with Nitrox CFM</TextBlock>
</TabItem>
</TabControl>
<TextBlock Grid.Row="3" Grid.ColumnSpan="2" x:Name="txt_result" Background="White">Results appear here</TextBlock>
</Grid>
</Grid>

Expand Down
56 changes: 50 additions & 6 deletions FillCalcWin/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Reflection;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Media;

//[assembly: AssemblyVersion("1.1.0.0")]

Expand All @@ -37,7 +38,7 @@ public partial class MainWindow : RibbonWindow
o2_price = 4.14,
he_price = 25.00,
compressor_price = 5.00,
selected_tab = (int) TmxCalcClass.FILLTYPE.pp
selected_tab = (int)TmxCalcClass.FILLTYPE.pp
};
public Window1 HelpWindow;

Expand All @@ -55,6 +56,7 @@ public MainWindow()
gas.txt_pp = this.txt_pp;
gas.txt_henx = this.txt_henx;
gas.txt_cost = this.txt_cost;
gas.txt_result = this.txt_result;
// do the first calculation with default values
gas.CalculateGas();

Expand Down Expand Up @@ -138,7 +140,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
private int _stop_o2;
private int _stop_he;
private int _selected_tab;
private TextBlock _txt_air, _txt_nitrox, _txt_tmx, _txt_pp, _txt_henx;
private TextBlock _txt_air, _txt_nitrox, _txt_tmx, _txt_pp, _txt_henx, _txt_result;
public TextBlock txt_cost;
private int _tank_liters;
double _o2_price;
Expand All @@ -153,6 +155,7 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
public TextBlock txt_tmx { get { return _txt_tmx; } set { _txt_tmx = value; } }
public TextBlock txt_pp { get { return _txt_pp; } set { _txt_pp = value; } }
public TextBlock txt_henx { get { return _txt_henx; } set { _txt_henx = value; } }
public TextBlock txt_result { get { return _txt_result; } set { _txt_result = value; } }

public bool VdW
{
Expand Down Expand Up @@ -305,7 +308,7 @@ public int stop_he
public void CalculateGas()
{
TmxCalcClass.TmxResult result;
VanDerWaals.VdW_Result vdw_result = new VanDerWaals.VdW_Result {status_code = 66, status_txt = "dazed and confused"};
VanDerWaals.VdW_Result vdw_result = new VanDerWaals.VdW_Result { status_code = 66, status_txt = "dazed and confused" };

if (_txt_air != null)
{
Expand All @@ -318,10 +321,19 @@ public void CalculateGas()
filltype = TmxCalcClass.filltypes[selected_tab];
result = TmxCalcClass.TmxCalc(filltype, start_bar, start_o2, start_he,
stop_bar, stop_o2, stop_he);
if (_vdw == true) {
if (_vdw == true & selected_tab == (int)TmxCalcClass.FILLTYPE.pp)
{
vdw_result = VanDerWaals.vdw_calc(start_bar, stop_bar, start_o2, start_he, stop_o2, stop_he, tank_liters, 20.0);
_txt_result.Text = vdw_result.status_txt;
}
switch (selected_tab)
else
_txt_result.Text = result.status_txt;
if (result.status_code != 0)
_txt_result.Background = Brushes.LightPink;
else
_txt_result.Background = Brushes.White;

/* switch (selected_tab)
{
case (int)TmxCalcClass.FILLTYPE.air:
_txt_air.Text = result.status_txt;
Expand Down Expand Up @@ -349,7 +361,8 @@ public void CalculateGas()
selected_tab = (int)TmxCalcClass.FILLTYPE.air;
_txt_henx.Text = "Internal error at CalculateGas()";
break;
}
} */

var result_c = TmxCalcClass.Tmx_cost_calc(tank_liters, stop_bar, result.add_o2, result.add_he,
o2_price, he_price, compressor_price);
txt_cost.Text = result_c.status_txt;
Expand Down Expand Up @@ -449,6 +462,37 @@ private void rBugs(object sender, RoutedEventArgs e)
// Launch browser to github issues...
System.Diagnostics.Process.Start("https://github.com/eianlei/FillCalcWin/issues");
}

private void FillTypeChange(object sender, SelectionChangedEventArgs e)
{
switch (gas.selected_tab)
{
case (int)TmxCalcClass.FILLTYPE.air:
gas.stop_he = 0;
gas.stop_o2 = 21;
iud_stop_he.Visibility = Visibility.Hidden;
break;
case (int)TmxCalcClass.FILLTYPE.nx:
iud_stop_he.Visibility = Visibility.Hidden;
break;
case (int)TmxCalcClass.FILLTYPE.tmx:
if (gas.stop_he==0) gas.stop_he = 35;
iud_stop_he.Visibility = Visibility.Visible;
break;
case (int)TmxCalcClass.FILLTYPE.pp:
if (gas.stop_he == 0) gas.stop_he = 35;
iud_stop_he.Visibility = Visibility.Visible;
break;
case (int)TmxCalcClass.FILLTYPE.cfm:
if (gas.stop_he == 0) gas.stop_he = 35;
iud_stop_he.Visibility = Visibility.Visible;
break;
default:
gas.selected_tab = (int)TmxCalcClass.FILLTYPE.air;
gas.txt_result.Text = "Internal error at FillTypeChange()";
break;
}
}
}
}

43 changes: 40 additions & 3 deletions FillCalcWin/vdw_calc_python2csharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static double vdw_solve_mols(
// instead use algorithms at RootFinding.cs moduel, reused from
// https://www.codeproject.com/Articles/79541/Three-Methods-for-Root-finding-in-C
VdW_eqation vdw_eq = new VdW_eqation(p: pressure, n: seed_n, V: volume, T: temp_K, a: mix_a, b: mix_b);
//TODO: add try cath exception here
double solved_n = RootFinding.Bisect(vdw_eq.solve_mols, seed_n * 0.6, seed_n *1.5, 0.001, 0.1);


Expand Down Expand Up @@ -241,6 +242,7 @@ public static VdW_Result vdw_calc(

// how many mols of gas we want to have, in total and of each kind
double vdw_want_mols_all = vdw_solve_mols(want_bar, volume, want_o2_f, want_he_f, want_n2_f, end_temp_c);
//TODO: error checking to be nicer
if (vdw_want_mols_all > 0)
{
vdw_want_mols_o2 = vdw_want_mols_all * want_o2_f;
Expand All @@ -267,7 +269,14 @@ public static VdW_Result vdw_calc(

// then solve for pressure of this new mix
var mix_helium_bars = vdw_solve_pressure(mix_he_mols_all, volume, mix_he_o2_f, mix_he_he_f, mix_he_n2_f, start_temp_c);
//TODO: more error checking needed here
var vdw_fill_he_bars = mix_helium_bars - start_bar;
if (vdw_fill_he_bars < 0)
{
vdw_result.status_txt = "ERROR 12: negative Helium fill";
vdw_result.status_code = 12;
return vdw_result;
}

// air is topped last, but we need to calculate how much we need it, so we can calculate for oxygen
var air_o2_mols_o2 = vdw_fill_mols_n2 * (0.21 / 0.79);
Expand All @@ -279,7 +288,14 @@ public static VdW_Result vdw_calc(

// then solve for pressure of this new mix
var mix_oxygen_bars = vdw_solve_pressure(mix_o2_mols_all, volume, mix_o2_o2_f, mix_o2_he_f, mix_o2_n2_f, start_temp_c);
//TODO: error checking needed here
var vdw_fill_o2_bars = mix_oxygen_bars - mix_helium_bars;
if (vdw_fill_o2_bars < 0)
{
vdw_result.status_txt = "ERROR 13: negative Oxygen fill";
vdw_result.status_code = 13;
return vdw_result;
}

// finally air
var vdw_fill_air_bars = want_bar - mix_oxygen_bars;
Expand All @@ -288,10 +304,31 @@ public static VdW_Result vdw_calc(
vdw_result.fill_air_bars = vdw_fill_air_bars;

// build the string for return
string start_mix = $"Starting from {start_bar} bar with mix {start_o2:F0}/{start_he:F0} (O2/He).";
string start_mix;
if (start_bar >0 )
start_mix = $"Starting from {start_bar} bar with mix {start_o2:F0}/{start_he:F0} (O2/He).";
else
start_mix = "Starting from EMPTY TANK ";
string result_mix = $"Resulting mix will be {want_o2:F0}/{want_he:F0} (O2/He).";
string he_fill = $"From {start_bar:F1} bars add {vdw_fill_he_bars:F1} bar Helium,";
string o2_fill = $"From {mix_helium_bars:F1} bars add {vdw_fill_o2_bars:F1} bar Oxygen,";
string he_fill;
if (vdw_fill_he_bars > 0)
{
he_fill = $"From {start_bar:F1} bars add {vdw_fill_he_bars:F1} bar Helium,";
}
else
{
he_fill = "* no Helium added";
}
string o2_fill;
if (vdw_fill_o2_bars > 0)
{
o2_fill = $"From {mix_helium_bars:F1} bars add {vdw_fill_o2_bars:F1} bar Oxygen,";
}
else
{
o2_fill = "* no Oxygen added";
}

string result =
$"{start_mix}\n" +
$"Van der Waals blend:\n" +
Expand Down

0 comments on commit 8b719a3

Please sign in to comment.