Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
seto committed Dec 2, 2024
1 parent b08c31c commit f37e984
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 148 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# WFO1000: プロパティ コンテンツのコード シリアル化構成がありません
dotnet_diagnostic.WFO1000.severity = silent
4 changes: 2 additions & 2 deletions Crystallography.Controls/Crystallography.Controls.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<OutputType>Library</OutputType>
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyVersion>2024.11.25.0729</AssemblyVersion>
<FileVersion>2024.11.25.0729</FileVersion>
<AssemblyVersion>2024.12.2.0541</AssemblyVersion>
<FileVersion>2024.12.2.0541</FileVersion>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<ApplicationUseCompatibleTextRendering>true</ApplicationUseCompatibleTextRendering>
<ApplicationVisualStyles>true</ApplicationVisualStyles>
Expand Down
20 changes: 10 additions & 10 deletions Crystallography/Crystal/ConvertCrystalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,16 @@ private static (Crystal2, string) CellParamForAmc(string str)
for (int i = 0; i < 6; i++) if (s[i].EndsWith(',')) s[i] = s[i].TrimEnd(','); //最後に','が入っているときは削除


if (Miscellaneous.IsDecimalPointComma)
for (int i = 0; i < 6; i++) s[i] = s[i].Replace('.', ',');
else
for (int i = 0; i < 6; i++) s[i] = s[i].Replace(',', '.');
A = Convert.ToDouble(s[0]);
B = Convert.ToDouble(s[1]);
C = Convert.ToDouble(s[2]);
Alpha = Convert.ToDouble(s[3]);
Beta = Convert.ToDouble(s[4]);
Gamma = Convert.ToDouble(s[5]);
//if (Miscellaneous.IsDecimalPointComma)
// for (int i = 0; i < 6; i++) s[i] = s[i].Replace('.', ',');
//else
// for (int i = 0; i < 6; i++) s[i] = s[i].Replace(',', '.');
A = s[0].ToDouble();
B = s[1].ToDouble();
C = s[2].ToDouble();
Alpha = s[3].ToDouble();
Beta = s[4].ToDouble();
Gamma = s[5].ToDouble();
}
catch { return (null, null); }
string SgName = s[6];
Expand Down
4 changes: 2 additions & 2 deletions Crystallography/Crystallography.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<OutputType>Library</OutputType>
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyVersion>2024.11.25.0729</AssemblyVersion>
<FileVersion>2024.11.25.0729</FileVersion>
<AssemblyVersion>2024.12.2.0541</AssemblyVersion>
<FileVersion>2024.12.2.0541</FileVersion>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
Expand Down
21 changes: 19 additions & 2 deletions Crystallography/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ public static (int H, int K, int L) Cross(ref this (int H, int K, int L) x, (int
#region Stringの拡張
public static class StringEx
{
public static System.Globalization.CultureInfo InvCul = System.Globalization.CultureInfo.InvariantCulture;

/// <summary>
/// 拡張メソッド. 指定したseparatorで文字を区切り、文字の配列を返す.
/// </summary>
Expand Down Expand Up @@ -297,7 +299,21 @@ public static string[] Split(this string s, bool removeEmptyEntries = true)
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static double ToDouble(this string s) => !s.Contains('/') ? Convert.ToDouble(s) : s.Split("/", true)[0].ToDouble() / s.Split("/", true)[1].ToDouble();
public static double ToDouble(this string s)
{

if(s.Contains('/'))
{
var index = s.LastIndexOf('/');
return s[0..index].ToDouble() / s[(index+1)..].ToDouble();
}
else
{
s = s.Replace(',', '.');
return Convert.ToDouble(s,InvCul);
}
//return !s.Contains('/') ? Convert.ToDouble(s) : s.Split("/", true)[0].ToDouble() / s.Split("/", true)[1].ToDouble();
}

/// <summary>
/// 拡張メソッド. ConvertToInt32を拡張メソッドとして呼び出す. 変換できない場合は例外発生
Expand Down Expand Up @@ -334,10 +350,11 @@ public static class DoubleEx
public static double Min(this double[][] d) => d.Min(e => e.Min());
public static double Max(this double[][][] d) => d.Max(e => e.Max());
public static double Min(this double[][][] d) => d.Min(e => e.Min());

}
#endregion



#region Graphicsクラス
/// <summary>
/// Graphics クラスの描画関数にdoubleを受けられるにようにした拡張メソッド
Expand Down
1 change: 1 addition & 0 deletions Crystallography/Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static bool IsDecimalPointComma
/// <returns></returns>
public static bool isFileExistsAndLocked(string path)
{

if (File.Exists(path))
{
FileStream stream = null;
Expand Down
46 changes: 27 additions & 19 deletions Crystallography/PdiFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ public static DiffractionProfile2[] ReadPdi2File(string fileName, int version =
if (strList[0].Contains("Wave Length", StringComparison.Ordinal))
{
if (strList[0].Contains("(nm)", StringComparison.Ordinal))
diffProf.SrcProperty.WaveLength = Convert.ToDouble((strList[0].Split(':', true))[1]);
//diffProf.SrcProperty.WaveLength = Convert.ToDouble((strList[0].Split(':', true))[1]);
diffProf.SrcProperty.WaveLength = (strList[0].Split(':', true))[1].ToDouble();
else if (strList[0].Contains("(0.1nm)", StringComparison.Ordinal))
diffProf.SrcProperty.WaveLength = Convert.ToDouble((strList[0].Split(':', true))[1]) / 10.0;
//diffProf.SrcProperty.WaveLength = Convert.ToDouble((strList[0].Split(':', true))[1]) / 10.0;
diffProf.SrcProperty.WaveLength = (strList[0].Split(':', true))[1].ToDouble() / 10.0;
}

if ((strList[4].Split(':', true))[1] == "Angle")
Expand All @@ -160,7 +162,8 @@ public static DiffractionProfile2[] ReadPdi2File(string fileName, int version =
for (int i = 5; i < strList.Count; i++)
{
string[] str = strList[i].Split(',', true);
diffProf.SourceProfile.Pt.Add(new PointD(Convert.ToDouble(str[0]), Convert.ToDouble(str[1])));
//diffProf.SourceProfile.Pt.Add(new PointD(Convert.ToDouble(str[0]), Convert.ToDouble(str[1])));
diffProf.SourceProfile.Pt.Add(new PointD(str[0].ToDouble(), str[1].ToDouble()));
}
diffProf.Name = fileName.Remove(0, fileName.LastIndexOf('\\') + 1);
return new DiffractionProfile2[] { diffProf };
Expand All @@ -179,7 +182,7 @@ public static DiffractionProfile2[] ReadRasFile(string fileName)
strArray.Add(tempstr);
reader.Close();
if (strArray.Count <= 3)
return Array.Empty<DiffractionProfile2>();
return [];

var dp = new List<DiffractionProfile2>();

Expand All @@ -194,8 +197,10 @@ public static DiffractionProfile2[] ReadRasFile(string fileName)
if (strArray[i] != "*RAS_INT_END")
{
string[] tempStr = strArray[i].Split(new[] { ' ' });
double x = Convert.ToDouble(tempStr[0]);
double y = Convert.ToDouble(tempStr[1]);
//double x = Convert.ToDouble(tempStr[0]);
//double y = Convert.ToDouble(tempStr[1]);
double x = tempStr[0].ToDouble();
double y = tempStr[1].ToDouble();
dp[^1].SourceProfile.Pt.Add(new PointD(x, y));
}
else
Expand All @@ -208,8 +213,8 @@ public static DiffractionProfile2[] ReadRasFile(string fileName)
dp[i].Name = $"{Path.GetFileName(fileName)}{(dp.Count > 1 ? $" -{i}" : "")}";

if (dp.Count > 0)
return dp.ToArray();
else return Array.Empty<DiffractionProfile2>();
return [.. dp];
else return [];
}

/// <summary>
Expand All @@ -235,11 +240,11 @@ public static DiffractionProfile2[] ReadCSVFile(string fileName)

try
{
var title = strArray[0].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var axis = strArray[1].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var value = strArray[2].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var title = strArray[0].Split([','], StringSplitOptions.RemoveEmptyEntries);
var axis = strArray[1].Split([','], StringSplitOptions.RemoveEmptyEntries);
var value = strArray[2].Split([','], StringSplitOptions.RemoveEmptyEntries);
if (title.Length * 2 != axis.Length || axis.Length != value.Length)
return Array.Empty<DiffractionProfile2>();
return [];

var dp = new DiffractionProfile2[title.Length];
for (int i = 0; i < dp.Length; i++)
Expand All @@ -252,8 +257,10 @@ public static DiffractionProfile2[] ReadCSVFile(string fileName)
value = strArray[i].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < value.Length / 2; j++)
{
double x = Convert.ToDouble(value[j * 2]);
double y = Convert.ToDouble(value[j * 2 + 1]);
//double x = Convert.ToDouble(value[j * 2]);
//double y = Convert.ToDouble(value[j * 2 + 1]);
var x = value[j * 2].ToDouble();
var y = value[j * 2 + 1].ToDouble();
dp[j].SourceProfile.Pt.Add(new PointD(x, y));
}
}
Expand Down Expand Up @@ -295,19 +302,20 @@ public static DiffractionProfile2 ConvertUnknownFileToProfileData(string fileNam
var stringList = new List<string[]>();
//まず指定されたセパレータで全てを区切る
for (int i = 0; i < strArray.Count; i++)
stringList.Add(strArray[i].Split(new char[] { separater }, StringSplitOptions.RemoveEmptyEntries));
stringList.Add(strArray[i].Split([separater], StringSplitOptions.RemoveEmptyEntries));
//その全てを数値に変換する
var doubleList = new List<double[]>();
for (int i = 0; i < stringList.Count; i++)
{
var doubleTemp = new List<double>();
for (int j = 0; j < stringList[i].Length; j++)
{
var str = Miscellaneous.IsDecimalPointComma ? stringList[i][j].Replace('.', ',') : stringList[i][j].Replace(',', '.');
if (double.TryParse(str, out double result))
doubleTemp.Add(result);
//var str = Miscellaneous.IsDecimalPointComma ? stringList[i][j].Replace('.', ',') : stringList[i][j].Replace(',', '.');
//if (double.TryParse(str, out double result))
// doubleTemp.Add(result);
doubleTemp.Add(stringList[i][j].ToDouble());
}
doubleList.Add(doubleTemp.ToArray());
doubleList.Add([.. doubleTemp]);
}
int count = 1;
int beforeLength = 0;
Expand Down
5 changes: 5 additions & 0 deletions PDIndexer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Crystallography.Controls",
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "PDindexerSetup", "PDindexerSetup\PDindexerSetup.vdproj", "{80EF52B7-7757-4980-A47A-0772A37AB289}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{965242BA-7668-45BD-AB8B-C1F8CD894B2D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
13 changes: 5 additions & 8 deletions PDIndexer/DataConverter/EDXControl.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PDIndexer
{
public partial class EDXControl : UserControl
{

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public double[] EGC
{
get => new[] { numericBoxEGC0.Value, numericBoxEGC1.Value, numericBoxEGC2.Value };
Expand All @@ -27,10 +21,13 @@ public double[] EGC
}
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool Valid { get => checkBox1.Checked; set => checkBox1.Checked = value; }

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string DetectorName { get => checkBox1.Text; set => checkBox1.Text = value; }

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool CheckBoxVisible { get => checkBox1.Visible; set => checkBox1.Visible = value; }

public EDXControl()
Expand Down
72 changes: 36 additions & 36 deletions PDIndexer/FormFitting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void ButtonSaveTableAsCSV_Click(object sender, EventArgs e)
{
var dlg = new SaveFileDialog { Filter = "*.csv|*.csv" };
if (dlg.ShowDialog() == DialogResult.OK)
using (StreamWriter sw = new StreamWriter(dlg.FileName, false))
using (StreamWriter sw = new(dlg.FileName, false))
sw.Write(text.Replace("\t", ","));
}
}
Expand All @@ -181,41 +181,39 @@ private void FormFitting_DragDrop(object sender, DragEventArgs e)
string[] fileName = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (fileName.Length == 1 && fileName[0].ToLower().EndsWith("csv"))
{
using (var sr = new StreamReader(fileName[0]))
using var sr = new StreamReader(fileName[0]);
if (sr.ReadLine().StartsWith("Checked,hkl"))
{
if (sr.ReadLine().StartsWith("Checked,hkl"))
int n = 0;
while (sr.Peek() > -1)
{
int n = 0;
while (sr.Peek() > -1)
var line = sr.ReadLine().Split(new[] { ',' }, StringSplitOptions.None);
if (line.Length > 2 && n < dataSet.DataTablePeakFitting.Rows.Count)
{
var line = sr.ReadLine().Split(new[] { ',' }, StringSplitOptions.None);
if (line.Length > 2 && n < dataSet.DataTablePeakFitting.Rows.Count)
var dr = dataSet.DataTablePeakFitting.Rows[n] as DataSet.DataTablePeakFittingRow;
dr.Check = line[0] == "True";
dr.Function = line[3];
dr.X = Convert.ToDouble(line[4]);
dr.XErr = Convert.ToDouble(line[5]);
dr.FWHM = Convert.ToDouble(line[6]);
dr.Intensity = Convert.ToDouble(line[7]);
dr.R = Convert.ToDouble(line[8]);
if (n < TargetCrystal.Plane.Count)
{
var dr = dataSet.DataTablePeakFitting.Rows[n] as DataSet.DataTablePeakFittingRow;
dr.Check = line[0] == "True";
dr.Function = line[3];
dr.X = Convert.ToDouble(line[4]);
dr.XErr = Convert.ToDouble(line[5]);
dr.FWHM = Convert.ToDouble(line[6]);
dr.Intensity = Convert.ToDouble(line[7]);
dr.R = Convert.ToDouble(line[8]);
if (n < TargetCrystal.Plane.Count)
TargetCrystal.Plane[n].IsFittingChecked = line[0] == "True";
TargetCrystal.Plane[n].peakFunction.Option = line[3] switch
{
TargetCrystal.Plane[n].IsFittingChecked = line[0] == "True";
TargetCrystal.Plane[n].peakFunction.Option = line[3] switch
{
"Simple" => PeakFunctionForm.Simple,
"Sym PV" => PeakFunctionForm.PseudoVoigt,
"Sym Pea" => PeakFunctionForm.Peason,
"Spl PV" => PeakFunctionForm.SplitPseudoVoigt,
"Spl Pea" => PeakFunctionForm.SplitPseudoVoigt,
_ => PeakFunctionForm.PseudoVoigt
};

}
"Simple" => PeakFunctionForm.Simple,
"Sym PV" => PeakFunctionForm.PseudoVoigt,
"Sym Pea" => PeakFunctionForm.Peason,
"Spl PV" => PeakFunctionForm.SplitPseudoVoigt,
"Spl Pea" => PeakFunctionForm.SplitPseudoVoigt,
_ => PeakFunctionForm.PseudoVoigt
};

}
n++;
}
n++;
}
}
}
Expand Down Expand Up @@ -253,12 +251,14 @@ public void Fitting()
p.XObs = 0;
p.observedIntensity = 0;
p.DecompositionGroup = -1;
p.peakFunction = new PeakFunction();
p.peakFunction.X = p.XCalc;
p.peakFunction.range = p.SerchRange * SerchRangeFactor; ;
p.peakFunction.Hk = p.FWHM * SerchRangeFactor;
p.peakFunction.Option = p.SerchOption;
p.peakFunction.Color = Color.FromArgb(c.Argb);
p.peakFunction = new PeakFunction
{
X = p.XCalc,
range = p.SerchRange * SerchRangeFactor,
Hk = p.FWHM * SerchRangeFactor,
Option = p.SerchOption,
Color = Color.FromArgb(c.Argb)
};

if (p.SerchOption == PeakFunctionForm.Simple) //Simpleもーどのときはここで処理
{
Expand Down Expand Up @@ -804,7 +804,7 @@ public void FittingDiffraction()
case "triclinic":
#region triclinic

var constants = CrystalGeometry.GetErrorTriclinic(p.ToArray());
var constants = CrystalGeometry.GetErrorTriclinic([.. p]);
if (constants.Length != 0)
{
a = constants[0];
Expand Down
Loading

0 comments on commit f37e984

Please sign in to comment.