Add copy to clipboard command for material

This commit is contained in:
Evgeny Redikultsev
2024-12-21 22:26:29 +05:00
parent a7dd63ccd4
commit fb017af47d
17 changed files with 451 additions and 186 deletions

View File

@@ -3,38 +3,19 @@ using System.Text;
namespace StructureHelperLogics.NdmCalculations.Analyses
{
public class ExportForceResultToCSVLogic : IExportResultLogic
public class ExportForcesResultToCSVLogic : ExportToCSVLogicBase
{
const string separator = ";";
StringBuilder output;
IForcesResults results;
public string FileName { get; set; }
public void Export()
public ExportForcesResultToCSVLogic(IForcesResults results)
{
ExportHeadings();
ExportBoby();
try
{
File.AppendAllText(FileName, output.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Data could not be written to the CSV file.");
return;
}
this.results = results;
}
public ExportForceResultToCSVLogic(IForcesResults forcesResults)
{
this.results = forcesResults;
output = new StringBuilder();
}
private void ExportHeadings()
public override void ExportHeadings()
{
string[] headings =
{
{
"Limit State",
"Calc duration",
"Mx",
@@ -46,7 +27,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
};
output.AppendLine(string.Join(separator, headings));
}
private void ExportBoby()
public override void ExportBoby()
{
foreach (var item in results.ForcesResultList)
{

View File

@@ -27,12 +27,23 @@ namespace StructureHelperLogics.NdmCalculations.Analyses
private static void EncodeVisual(FrameworkElement visual, string fileName, BitmapEncoder encoder)
{
var bitmap = new RenderTargetBitmap((int)visual.ActualWidth, (int)visual.ActualHeight, 96, 96, PixelFormats.Pbgra32);
// Measure and arrange the element to ensure it's fully rendered
visual.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
Rect previousBounds = VisualTreeHelper.GetDescendantBounds(visual);
visual.Arrange(new Rect(0, 0, visual.ActualWidth, visual.ActualHeight));
var bitmap = new RenderTargetBitmap(
(int)visual.ActualWidth,
(int)visual.ActualHeight,
96,
96,
PixelFormats.Pbgra32);
bitmap.Render(visual);
var frame = BitmapFrame.Create(bitmap);
encoder.Frames.Add(frame);
using (var stream = File.Create(fileName)) encoder.Save(stream);
visual.Arrange(previousBounds);
}
}
}

View File

@@ -0,0 +1,29 @@
using System.Text;
namespace StructureHelperLogics.NdmCalculations.Analyses
{
public abstract class ExportToCSVLogicBase : IExportResultLogic
{
public string separator => ";";
public StringBuilder output { get; } = new();
public string FileName { get; set; }
public void Export()
{
ExportHeadings();
ExportBoby();
try
{
File.AppendAllText(FileName, output.ToString());
}
catch (Exception ex)
{
Console.WriteLine("Data could not be written to the CSV file.");
return;
}
}
public abstract void ExportBoby();
public abstract void ExportHeadings();
}
}