Export to CSV was added

This commit is contained in:
Evgeny Redikultsev
2022-12-22 21:08:28 +05:00
parent b3952767c8
commit 913d31e04f
16 changed files with 190 additions and 18 deletions

View File

@@ -15,8 +15,8 @@
<Button Content=">>" Command="{Binding AddSelected}"/>
<Button Content="&lt;&lt;" Command="{Binding RemoveSelected}"/>
</StackPanel>
<ListBox Grid.Column="2" ItemsSource="{Binding TargetItems}" SelectedItem="{Binding SelectedTargetItem}" ItemTemplate="{StaticResource ResourceKey=SimpleItemTemplate}"/>
<ListBox Grid.Column="2" ItemsSource="{Binding TargetItems}"
SelectedItem="{Binding SelectedTargetItem}" ItemTemplate="{StaticResource ResourceKey=SimpleItemTemplate}"/>
</Grid>
</DataTemplate>
</ResourceDictionary>

Binary file not shown.

View File

@@ -16,5 +16,7 @@ namespace StructureHelperCommon.Infrastructures.Strings
public static string LimitStatesIsNotValid => "#0005: Type of limite state is not valid";
public static string LoadTermIsNotValid => "#0006: Load term is not valid";
public static string IncorrectValue => "#0007: value is not valid";
public static string FileCantBeDeleted => "#0008: File can't be deleted";
public static string FileCantBeSaved => "#0009: File can't be saved";
}
}

View File

@@ -27,5 +27,21 @@ namespace StructureHelperCommon.Models.Forces
DesignForces.Add(new DesignForceTuple(LimitStates.SLS, CalcTerms.ShortTerm));
DesignForces.Add(new DesignForceTuple(LimitStates.SLS, CalcTerms.LongTerm));
}
public object Clone()
{
var newItem = new ForceCombinationList();
newItem.Name = Name + " copy";
newItem.SetInGravityCenter = SetInGravityCenter;
newItem.ForcePoint.X = ForcePoint.X;
newItem.ForcePoint.Y = ForcePoint.Y;
newItem.DesignForces.Clear();
foreach (var item in DesignForces)
{
var newForce = item.Clone() as IDesignForceTuple;
newItem.DesignForces.Add(newForce);
}
return newItem;
}
}
}

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Forces
{
public interface IForceCombinationList
public interface IForceCombinationList : ICloneable
{
string Name { get; set; }
bool SetInGravityCenter { get; set; }

View File

@@ -132,6 +132,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
public object Clone()
{
IForceCalculator calculator = new ForceCalculator();
calculator.Name = Name + " copy";
calculator.LimitStatesList.Clear();
calculator.LimitStatesList.AddRange(LimitStatesList);
calculator.CalcTermsList.Clear();

View File

@@ -7,7 +7,7 @@ using System.Collections.Generic;
namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
{
public interface IForceCalculator : INdmCalculator, IHasPrimitives, IHasForceCombinations, ICloneable
public interface IForceCalculator : INdmCalculator, IHasPrimitives, IHasForceCombinations
{
List<CalcTerms> CalcTermsList { get; }
double IterationAccuracy { get; set; }

View File

@@ -0,0 +1,75 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperLogics.NdmCalculations.Analyses
{
public class ExportToCSVLogic : IExportResultLogic
{
string filename;
public void Export(INdmResult ndmResult)
{
string separator = ";";
StringBuilder output = new StringBuilder();
if (ndmResult is ForcesResults)
{
var forceResults = ndmResult as ForcesResults;
string[] headings =
{
"Limit State",
"Calc duration",
"Mx",
"My",
"Nz",
"kx",
"ky",
"epsz"
};
output.AppendLine(string.Join(separator, headings));
foreach (var item in forceResults.ForcesResultList)
{
if (item.IsValid == true)
{
var tuple = item.DesignForceTuple.ForceTuple;
var strainMatrix = item.LoaderResults.StrainMatrix;
string[] newLine =
{
item.DesignForceTuple.LimitState.ToString(),
item.DesignForceTuple.CalcTerm.ToString(),
tuple.Mx.ToString(),
tuple.My.ToString(),
tuple.Nz.ToString(),
strainMatrix.Kx.ToString(),
strainMatrix.Ky.ToString(),
strainMatrix.EpsZ.ToString()
};
output.AppendLine(string.Join(separator, newLine));
}
}
try
{
File.AppendAllText(filename, output.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Data could not be written to the CSV file.");
return;
}
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown +": "+ nameof(ndmResult));
}
public ExportToCSVLogic(string filename)
{
this.filename = filename;
}
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace StructureHelperLogics.NdmCalculations.Analyses
{
internal interface IExportResultLogic
public interface IExportResultLogic
{
void Export(INdmResult ndmResult);
}

View File

@@ -9,7 +9,7 @@ using TaskManager;
namespace StructureHelperLogics.NdmCalculations.Analyses
{
public interface INdmCalculator
public interface INdmCalculator : ICloneable
{
string Name { get; set; }
/// <summary>

View File

@@ -55,17 +55,14 @@
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding AllowedPrimitives}"
SelectedItem="{Binding SelectedAllowedPrimitive}"
ItemTemplate="{StaticResource ColoredItemTemplate}">
</ListBox>
ItemTemplate="{StaticResource ColoredItemTemplate}"/>
<StackPanel Grid.Column="1">
<Button Content="Add all" Command="{Binding AddAllPrimitivesCommand}"/>
<Button Content="Clear all" Command="{Binding ClearAllPrimitivesCommand}"/>
<Button Content=">>" Command="{Binding AddSelectedPrimitiveCommand}"/>
<Button Content="&lt;&lt;" Command="{Binding RemoveSelectedPrimitiveCommand}"/>
</StackPanel>
<ListBox Grid.Column="2" ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}" ItemTemplate="{StaticResource ColoredItemTemplate}">
</ListBox>
<ListBox Grid.Column="2" ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}" ItemTemplate="{StaticResource ColoredItemTemplate}"/>
</Grid>
</TabItem>
<TabItem Header="Iterations">

View File

@@ -7,11 +7,11 @@
xmlns:vm="clr-namespace:StructureHelper.Windows.ViewModels.Calculations.Calculators"
d:DataContext="{d:DesignInstance vm:ForcesResultsViewModel}"
mc:Ignorable="d"
Title="ForceResultsView" Height="350" Width="650" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen">
Title="Calculation Results" Height="350" Width="850" MinHeight="300" MinWidth="400" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="90"/>
</Grid.ColumnDefinitions>
<DataGrid x:Name="ResultGrid" IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding ForcesResults.ForcesResultList}" SelectedItem="{Binding SelectedResult}" >
<DataGrid.RowStyle>

View File

@@ -72,6 +72,7 @@
<ListBox.ContextMenu>
<ContextMenu>
<Button Content="Edit" Command="{Binding Edit}"/>
<Button Content="Copy" Command="{Binding Copy}"/>
<Button Content="Delete" Command="{Binding Delete}"/>
</ContextMenu>
</ListBox.ContextMenu>
@@ -122,6 +123,7 @@
<ContextMenu>
<Button Content="Run" Command="{Binding Run}"/>
<Button Content="Edit" Command="{Binding Edit}"/>
<Button Content="Copy" Command="{Binding Copy}"/>
<Button Content="Delete" Command="{Binding Delete}"/>
</ContextMenu>
</ListBox.ContextMenu>

View File

@@ -7,12 +7,16 @@ using StructureHelper.Services.Reports;
using StructureHelper.Services.Reports.CalculationReports;
using StructureHelper.Services.ResultViewers;
using StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalculatorViews;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperLogics.NdmCalculations.Analyses;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmCalculations;
using StructureHelperLogics.Services.NdmPrimitives;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -59,12 +63,48 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
return exportToCSVCommand ??
(exportToCSVCommand = new RelayCommand(o =>
{
ExportToCSV();
}
));
}
}
private void ExportToCSV()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "csv |*.csv";
saveFileDialog.Title = "Save an Image File";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var filename = saveFileDialog.FileName;
// If the file name is not an empty string open it for saving.
if (filename != "")
{
if (File.Exists(filename))
{
try
{
File.Delete(filename);
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.FileCantBeDeleted + ex + filename);
}
}
try
{
var logic = new ExportToCSVLogic(saveFileDialog.FileName);
logic.Export(forcesResults);
}
catch (Exception ex)
{
throw new StructureHelperException(ErrorStrings.FileCantBeSaved + ex + filename);
}
}
}
}
public RelayCommand InterpolateCommand
{
get
@@ -91,7 +131,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
{
var vm = new ForcesResultsViewModel(calculator);
var wnd = new ForceResultsView(vm);
wnd.Show();
wnd.ShowDialog();
}
}

View File

@@ -50,8 +50,12 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
(
editCalculatorCommand = new RelayCommand(o =>
{
var tmpSelected = SelectedItem;
EditCalculator();
Items.Clear();
AddItems(repository.CalculatorsList);
OnPropertyChanged(nameof(Items));
SelectedItem = tmpSelected;
}, o => SelectedItem != null));
}
}
@@ -68,6 +72,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}
private RelayCommand deleteCalculatorCommand;
private RelayCommand runCommand;
private RelayCommand copyCalculatorCommand;
public RelayCommand Delete
{
get
@@ -100,13 +106,27 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
var calculator = SelectedItem as IForceCalculator;
var vm = new ForcesResultsViewModel(calculator);
var wnd = new ForceResultsView(vm);
wnd.Show();
wnd.ShowDialog();
}
}, o => SelectedItem != null));
}
}
public RelayCommand Copy => throw new NotImplementedException();
public RelayCommand Copy
{
get
{
return copyCalculatorCommand ??
(
copyCalculatorCommand = new RelayCommand(o =>
{
var item = SelectedItem.Clone() as INdmCalculator;
repository.CalculatorsList.Add(item);
Items.Add(item);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void DeleteCalculator()
{

View File

@@ -3,6 +3,7 @@ using StructureHelper.Windows.Forces;
using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Analyses;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -65,6 +66,8 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}
}
private RelayCommand editForceCombinationCommand;
private RelayCommand copyCommand;
public RelayCommand Edit
{
get
@@ -74,12 +77,28 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
editForceCombinationCommand = new RelayCommand(o =>
{
EditForceCombination();
Items.Clear();
AddItems(repository.ForceCombinationLists);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
public RelayCommand Copy => throw new NotImplementedException();
public RelayCommand Copy
{
get
{
return copyCommand ??
(
copyCommand = new RelayCommand(o =>
{
var item = SelectedItem.Clone() as IForceCombinationList;
repository.ForceCombinationLists.Add(item);
Items.Add(item);
OnPropertyChanged(nameof(Items));
}, o => SelectedItem != null));
}
}
private void EditForceCombination()
{