Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
seto77 committed Jul 16, 2021
1 parent 523bfe8 commit c940ed3
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 435 deletions.
38 changes: 22 additions & 16 deletions Crystallography.Controls/CrystalDatabase/CrystalDatabaseControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Drawing;
using MessagePack;
using MessagePack.Resolvers;
using System.Threading.Tasks;

#endregion

Expand Down Expand Up @@ -95,22 +96,6 @@ private void ReadDatabaseWorker_DoWork(object sender, DoWorkEventArgs e)
try
{
sw.Restart();
//if (filename.ToLower().EndsWith("cdb2"))
//{
// var progressStep = 500;
// using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
// var formatter = new BinaryFormatter();
// var total = (int)formatter.Deserialize(fs);
// for (int i = 0; i < total; i++)
// {
// var c = (Crystal2)formatter.Deserialize(fs);
// dataTable.Add(c);

// if (i > progressStep * 2 && i % progressStep == 0)
// report(i, total, sw.ElapsedMilliseconds, "Loading database...");
// }
//}
//else
if (filename.ToLower().EndsWith("cdb3"))
{
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
Expand Down Expand Up @@ -416,6 +401,27 @@ private void bindingSource_CurrentChanged(object sender, EventArgs e)
{
CrystalChanged?.Invoke(sender, e);
}

public void RecalculateDensityAndFormula()
{
var sw = new Stopwatch();
sw.Restart();
for(int i= 0; i<dataSet.DataTableCrystalDatabase.Count; i++)
{
var c = dataSet.DataTableCrystalDatabase.Get(i).ToCrystal();
//c.GetFormulaAndDensity();
dataSet.DataTableCrystalDatabase.Rows[i]["Formula"] = c.ChemicalFormulaSum;
dataSet.DataTableCrystalDatabase.Rows[i]["Density"] = c.Density;

if (i % 200 == 0)
{
(double progress, string message)= report(i, dataSet.DataTableCrystalDatabase.Count, sw.ElapsedMilliseconds, "Now recalculating Density and Formula. ");

ProgressChanged?.Invoke(this, progress, message);
Application.DoEvents();
}
}
}
#endregion

}
Expand Down
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>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<AssemblyVersion>2021.7.16.0306</AssemblyVersion>
<FileVersion>2021.7.16.0306</FileVersion>
<AssemblyVersion>2021.7.16.0500</AssemblyVersion>
<FileVersion>2021.7.16.0500</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
11 changes: 8 additions & 3 deletions Crystallography.Controls/DataSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,6 @@ public void Add(int h, int k, int l, int mult, double d, double twoTheta, Comple

partial class DataTableCrystalDatabaseDataTable
{

readonly ReaderWriterLockSlim rwlock = new();

static readonly MessagePackSerializerOptions msgOptions = StandardResolverAllowPrivate.Options.WithCompression(MessagePackCompression.Lz4BlockArray);
static byte[] serialize<T>(T c) => MessagePackSerializer.Serialize(c, msgOptions);
static T deserialize<T>(object obj) => MessagePackSerializer.Deserialize<T>((byte[])obj, msgOptions);
Expand All @@ -221,6 +218,14 @@ partial class DataTableCrystalDatabaseDataTable
/// <returns></returns>
public Crystal2 Get(object o) => o is DataRowView drv && drv.Row is DataTableCrystalDatabaseRow r ? deserialize<Crystal2>(r[SerializedCrystal2Column]) : null;


/// <summary>
/// 引数はbindingSourceMain.Currentオブジェクト.
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public Crystal2 Get(int i) =>deserialize<Crystal2>(Rows[i][0]);

public void Add(Crystal2 crystal) => Add(CreateRow(crystal));
public void Add(DataTableCrystalDatabaseRow row) => Rows.Add(row);

Expand Down
33 changes: 12 additions & 21 deletions Crystallography.Controls/Wave/WaveLengthControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c940ed3

Please sign in to comment.