Add import of polygon from dxf
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StructureHelper.Services.Exports
|
|
||||||
{
|
|
||||||
internal class ExportToFileInputData : IExportToFileInputData
|
|
||||||
{
|
|
||||||
public string FileName { get; set; } = "New file";
|
|
||||||
public string Filter { get; set; }
|
|
||||||
public string Title { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,38 +2,33 @@
|
|||||||
using StructureHelper.Windows.ViewModels.Errors;
|
using StructureHelper.Windows.ViewModels.Errors;
|
||||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
using StructureHelperCommon.Services.Exports;
|
using StructureHelperCommon.Services.Exports;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace StructureHelper.Services.Exports
|
namespace StructureHelper.Services.Exports
|
||||||
{
|
{
|
||||||
internal class ExportToFileService : IExportService
|
public class ExportToFileService : IExportLogic
|
||||||
{
|
{
|
||||||
IExportToFileInputData inputData;
|
private IFileIOnputData inputData;
|
||||||
IExportResultLogic logic;
|
private IExportToFileLogic exportLogic;
|
||||||
|
|
||||||
public ExportToFileService(IExportToFileInputData inputData, IExportResultLogic logic)
|
public ExportToFileService(IFileIOnputData inputData, IExportToFileLogic exportLogic)
|
||||||
{
|
{
|
||||||
this.inputData = inputData;
|
this.inputData = inputData;
|
||||||
this.logic = logic;
|
this.exportLogic = exportLogic;
|
||||||
}
|
}
|
||||||
public void Export()
|
public void Export()
|
||||||
{
|
{
|
||||||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
SaveFileDialog dialog = new()
|
||||||
saveFileDialog.Filter = inputData.Filter;
|
|
||||||
saveFileDialog.Title = inputData.Title;
|
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
{
|
||||||
var filename = saveFileDialog.FileName;
|
Filter = inputData.Filter,
|
||||||
// If the file name is not an empty string open it for saving.
|
Title = inputData.Title
|
||||||
|
};
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
var filename = dialog.FileName;
|
||||||
if (filename != "")
|
if (filename != "")
|
||||||
{
|
{
|
||||||
SaveFile(filename);
|
SaveFile(filename);
|
||||||
@@ -79,8 +74,8 @@ namespace StructureHelper.Services.Exports
|
|||||||
}
|
}
|
||||||
private void ExportFile(string fileName)
|
private void ExportFile(string fileName)
|
||||||
{
|
{
|
||||||
logic.FileName = fileName;
|
exportLogic.FileName = fileName;
|
||||||
logic.Export();
|
exportLogic.Export();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
OpenFile(fileName);
|
OpenFile(fileName);
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StructureHelper.Services.Exports
|
|
||||||
{
|
|
||||||
internal interface IExportService
|
|
||||||
{
|
|
||||||
void Export();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StructureHelper.Services.Exports
|
|
||||||
{
|
|
||||||
internal interface IExportToFileInputData
|
|
||||||
{
|
|
||||||
string FileName { get; set; }
|
|
||||||
string Filter { get; set; }
|
|
||||||
string Title { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
77
StructureHelper/Services/Exports/ImportFromFileService.cs
Normal file
77
StructureHelper/Services/Exports/ImportFromFileService.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using StructureHelper.Windows.Errors;
|
||||||
|
using StructureHelper.Windows.ViewModels.Errors;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace StructureHelper.Services.Exports
|
||||||
|
{
|
||||||
|
internal class ImportFromFileService : IImportFromFileLogic
|
||||||
|
{
|
||||||
|
private IFileIOnputData inputData;
|
||||||
|
private IImportFromFileLogic importLogic;
|
||||||
|
|
||||||
|
public string FileName {get; set; }
|
||||||
|
public ImportFromFileService(IFileIOnputData inputData, IImportFromFileLogic importLogic)
|
||||||
|
{
|
||||||
|
this.inputData = inputData;
|
||||||
|
this.importLogic = importLogic;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Import()
|
||||||
|
{
|
||||||
|
OpenFileDialog dialog = new OpenFileDialog()
|
||||||
|
{
|
||||||
|
Filter = inputData.Filter,
|
||||||
|
Title = inputData.Title
|
||||||
|
};
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
var filename = dialog.FileName;
|
||||||
|
if (filename != "")
|
||||||
|
{
|
||||||
|
OpenFile(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenFile(string filename)
|
||||||
|
{
|
||||||
|
CheckIfFileExist(filename);
|
||||||
|
ImportFromFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ImportFromFile(string filename)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
importLogic.FileName = filename;
|
||||||
|
importLogic.Import();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var vm = new ErrorProcessor()
|
||||||
|
{
|
||||||
|
ShortText = ErrorStrings.FileCantBeOpened + ": " + filename,
|
||||||
|
DetailText = $"File: {filename} can be opened \n {ex}"
|
||||||
|
};
|
||||||
|
new ErrorMessage(vm).ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CheckIfFileExist(string filename)
|
||||||
|
{
|
||||||
|
if (!File.Exists(filename))
|
||||||
|
{
|
||||||
|
var vm = new ErrorProcessor()
|
||||||
|
{
|
||||||
|
ShortText = ErrorStrings.FileDoesNotExsist + ": " + filename,
|
||||||
|
DetailText = $"File {filename} does not exist"
|
||||||
|
};
|
||||||
|
new ErrorMessage(vm).ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using StructureHelper.Infrastructure;
|
using StructureHelper.Infrastructure;
|
||||||
using StructureHelper.Services.Exports;
|
using StructureHelper.Services.Exports;
|
||||||
using StructureHelper.Windows.CalculationWindows.CalculatorsViews;
|
using StructureHelper.Windows.CalculationWindows.CalculatorsViews;
|
||||||
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperLogics.Models.BeamShears;
|
using StructureHelperLogics.Models.BeamShears;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -48,13 +50,8 @@ namespace StructureHelper.Windows.BeamShears
|
|||||||
private void ExportToExcel(object obj)
|
private void ExportToExcel(object obj)
|
||||||
{
|
{
|
||||||
if (SelectedResult is null) { return; }
|
if (SelectedResult is null) { return; }
|
||||||
var inputData = new ExportToFileInputData
|
|
||||||
{
|
|
||||||
Filter = "csv |*.csv",
|
|
||||||
Title = "Save in *.csv File"
|
|
||||||
};
|
|
||||||
var logic = new ExportActionResultToCSVLogic(SelectedResult);
|
var logic = new ExportActionResultToCSVLogic(SelectedResult);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(FileInputDataFactory.GetFileIOInputData(FileInputDataType.Csv), logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using StructureHelper.Infrastructure;
|
using StructureHelper.Infrastructure;
|
||||||
using StructureHelper.Services.Exports;
|
using StructureHelper.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
using StructureHelperLogics.NdmCalculations.Cracking;
|
using StructureHelperLogics.NdmCalculations.Cracking;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -53,11 +54,7 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews
|
|||||||
public ICommand ExportToCSVCommand => exportToCSVCommand ??= new RelayCommand(o => { ExportToCSV(); });
|
public ICommand ExportToCSVCommand => exportToCSVCommand ??= new RelayCommand(o => { ExportToCSV(); });
|
||||||
private void ExportToCSV()
|
private void ExportToCSV()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
var inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Csv);
|
||||||
{
|
|
||||||
Filter = "csv |*.csv",
|
|
||||||
Title = "Save in *.csv File"
|
|
||||||
};
|
|
||||||
var logic = new ExportCrackResultToCSVLogic(resultModel);
|
var logic = new ExportCrackResultToCSVLogic(resultModel);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ using StructureHelperCommon.Infrastructures.Interfaces;
|
|||||||
using StructureHelperCommon.Infrastructures.Settings;
|
using StructureHelperCommon.Infrastructures.Settings;
|
||||||
using StructureHelperCommon.Models.Forces;
|
using StructureHelperCommon.Models.Forces;
|
||||||
using StructureHelperCommon.Models.Shapes;
|
using StructureHelperCommon.Models.Shapes;
|
||||||
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperCommon.Services.Forces;
|
using StructureHelperCommon.Services.Forces;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||||
@@ -134,13 +136,8 @@ namespace StructureHelper.Windows.CalculationWindows.CalculatorsViews.ForceCalcu
|
|||||||
public ICommand ExportToCSVCommand => exportToCSVCommand ??= new RelayCommand(o => { ExportToCSV();});
|
public ICommand ExportToCSVCommand => exportToCSVCommand ??= new RelayCommand(o => { ExportToCSV();});
|
||||||
private void ExportToCSV()
|
private void ExportToCSV()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
|
||||||
{
|
|
||||||
Filter = "csv |*.csv",
|
|
||||||
Title = "Save in *.csv File"
|
|
||||||
};
|
|
||||||
var logic = new ExportForcesResultToCSVLogic(resultModel);
|
var logic = new ExportForcesResultToCSVLogic(resultModel);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(FileInputDataFactory.GetFileIOInputData(FileInputDataType.Csv), logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
}
|
}
|
||||||
public ICommand ShowGraphsCommand
|
public ICommand ShowGraphsCommand
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
using StructureHelper.Services.Exports;
|
using StructureHelper.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace StructureHelper.Windows.Graphs
|
namespace StructureHelper.Windows.Graphs
|
||||||
{
|
{
|
||||||
@@ -15,11 +11,7 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
{
|
{
|
||||||
public void SaveImageToFile(FrameworkElement element, double scaleFactor = 1)
|
public void SaveImageToFile(FrameworkElement element, double scaleFactor = 1)
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
var inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Png);
|
||||||
{
|
|
||||||
Filter = "png |*.png",
|
|
||||||
Title = "Save in *.png File"
|
|
||||||
};
|
|
||||||
var logic = new ExportFrameWorkElementLogic(element, scaleFactor);
|
var logic = new ExportFrameWorkElementLogic(element, scaleFactor);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using StructureHelper.Infrastructure;
|
|||||||
using StructureHelper.Services.Exports;
|
using StructureHelper.Services.Exports;
|
||||||
using StructureHelper.Windows.ViewModels;
|
using StructureHelper.Windows.ViewModels;
|
||||||
using StructureHelperCommon.Models.Parameters;
|
using StructureHelperCommon.Models.Parameters;
|
||||||
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses;
|
using StructureHelperLogics.NdmCalculations.Analyses;
|
||||||
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
|
||||||
using System;
|
using System;
|
||||||
@@ -87,11 +89,7 @@ namespace StructureHelper.Windows.Graphs
|
|||||||
|
|
||||||
private void ExportSeries()
|
private void ExportSeries()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
var inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Csv);
|
||||||
{
|
|
||||||
Filter = "csv |*.csv",
|
|
||||||
Title = "Save in *.csv File"
|
|
||||||
};
|
|
||||||
var logic = new ExportChartToCSVLogic(Series);
|
var logic = new ExportChartToCSVLogic(Series);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
|
|||||||
@@ -142,8 +142,8 @@
|
|||||||
CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False">
|
CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False">
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<DataGridTextColumn Width="5" Foreground="DarkGray"/>
|
<DataGridTextColumn Width="5" Foreground="DarkGray"/>
|
||||||
<DataGridTextColumn Width="100" Header="X" Binding="{Binding Point.X}" CanUserSort="False"/>
|
<DataGridTextColumn Width="100" Header="X" Binding="{Binding Point.X, Converter={StaticResource LengthConverter}}" CanUserSort="False"/>
|
||||||
<DataGridTextColumn Width="100" Header="Y" Binding="{Binding Point.Y}" CanUserSort="False"/>
|
<DataGridTextColumn Width="100" Header="Y" Binding="{Binding Point.Y, Converter={StaticResource LengthConverter}}" CanUserSort="False"/>
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -9,10 +9,13 @@ using StructureHelper.Windows.BeamShears;
|
|||||||
using StructureHelper.Windows.Shapes.Logics;
|
using StructureHelper.Windows.Shapes.Logics;
|
||||||
using StructureHelper.Windows.UserControls.WorkPlanes;
|
using StructureHelper.Windows.UserControls.WorkPlanes;
|
||||||
using StructureHelper.Windows.ViewModels;
|
using StructureHelper.Windows.ViewModels;
|
||||||
|
using StructureHelper.Windows.ViewModels.Errors;
|
||||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
using StructureHelperCommon.Infrastructures.Interfaces;
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
using StructureHelperCommon.Models.Shapes;
|
using StructureHelperCommon.Models.Shapes;
|
||||||
|
using StructureHelperCommon.Models.Shapes.Logics;
|
||||||
using StructureHelperCommon.Services.Exports;
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
using StructureHelperLogics.Models.BeamShears;
|
using StructureHelperLogics.Models.BeamShears;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -67,25 +70,35 @@ namespace StructureHelper.Windows.Shapes
|
|||||||
|
|
||||||
private void ImportFromDxf(object commandParameter)
|
private void ImportFromDxf(object commandParameter)
|
||||||
{
|
{
|
||||||
// your DXF file name
|
SafetyProcessor.RunSafeProcess(GetPolyline2D, "Error of obtaining of dxf polyline");
|
||||||
string file = "sample.dxf";
|
SafetyProcessor.RunSafeProcess(UpdatePolygon, "Error of updating of polygon");
|
||||||
// this check is optional but recommended before loading a DXF file
|
}
|
||||||
DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file);
|
|
||||||
// netDxf is only compatible with AutoCad2000 and higher DXF versions
|
private void UpdatePolygon()
|
||||||
if (dxfVersion < DxfVersion.AutoCad2000) return;
|
{
|
||||||
// load file
|
var convertLogic = new Polyline2DToLinePoligonConvertLogic();
|
||||||
DxfDocument loaded = DxfDocument.Load(file);
|
LinePolygonShape newPolygonShape = convertLogic.Convert(polyline);
|
||||||
|
newPolygonShape.IsClosed = true;
|
||||||
|
var updateLogic = new LinePolygonShapeUpdateStrategy();
|
||||||
|
updateLogic.Update(polygonShape, newPolygonShape);
|
||||||
|
ReloadVertices();
|
||||||
|
Redraw(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GetPolyline2D()
|
||||||
|
{
|
||||||
|
FileIOInputData inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Dxf);
|
||||||
|
var logic = new SinglePolyline2DImportFromDxfLogic();
|
||||||
|
var importService = new ImportFromFileService(inputData, logic);
|
||||||
|
importService.Import();
|
||||||
|
polyline = logic.Polyline2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand ExportToDxfCommand => exportToDxfCommand ??= new RelayCommand(ExportToDxf);
|
public ICommand ExportToDxfCommand => exportToDxfCommand ??= new RelayCommand(ExportToDxf);
|
||||||
|
|
||||||
private void ExportToDxf(object commandParameter)
|
private void ExportToDxf(object commandParameter)
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
FileIOInputData inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Dxf);
|
||||||
{
|
|
||||||
Filter = "dxf |*.dxf",
|
|
||||||
Title = "Save in *.dxf File"
|
|
||||||
};
|
|
||||||
var logic = new ShapesExportToDxfLogic(polygonShape, LayerNames.StructiralPrimitives);
|
var logic = new ShapesExportToDxfLogic(polygonShape, LayerNames.StructiralPrimitives);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
@@ -191,6 +204,7 @@ namespace StructureHelper.Windows.Shapes
|
|||||||
private RelayCommand deleteVertexCommand;
|
private RelayCommand deleteVertexCommand;
|
||||||
private RelayCommand flipVerticalCommand;
|
private RelayCommand flipVerticalCommand;
|
||||||
private RelayCommand flipHorizontalCommand;
|
private RelayCommand flipHorizontalCommand;
|
||||||
|
private static Polyline2D polyline;
|
||||||
|
|
||||||
public ICommand DeleteVertexCommand => deleteVertexCommand ??= new RelayCommand(DeleteVertex,
|
public ICommand DeleteVertexCommand => deleteVertexCommand ??= new RelayCommand(DeleteVertex,
|
||||||
o => SelectedVertex is not null && Vertices.Count >= minVertexCount);
|
o => SelectedVertex is not null && Vertices.Count >= minVertexCount);
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using StructureHelperCommon.Services.Exports;
|
||||||
|
using StructureHelperCommon.Services.Exports.Factories;
|
||||||
|
|
||||||
namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCalculatorVMs
|
namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCalculatorVMs
|
||||||
{
|
{
|
||||||
@@ -32,11 +34,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators.GeometryCa
|
|||||||
}
|
}
|
||||||
private void ExportToCSV()
|
private void ExportToCSV()
|
||||||
{
|
{
|
||||||
var inputData = new ExportToFileInputData
|
var inputData = FileInputDataFactory.GetFileIOInputData(FileInputDataType.Csv);
|
||||||
{
|
|
||||||
Filter = "csv |*.csv",
|
|
||||||
Title = "Save in csv File"
|
|
||||||
};
|
|
||||||
var logic = new ExportGeometryResultToCSVLogic(result);
|
var logic = new ExportGeometryResultToCSVLogic(result);
|
||||||
var exportService = new ExportToFileService(inputData, logic);
|
var exportService = new ExportToFileService(inputData, logic);
|
||||||
exportService.Export();
|
exportService.Export();
|
||||||
|
|||||||
@@ -29,5 +29,7 @@
|
|||||||
public static string CalculationError => "#0019: Error of calculation";
|
public static string CalculationError => "#0019: Error of calculation";
|
||||||
public static string SourceObject => "#0020: Source object";
|
public static string SourceObject => "#0020: Source object";
|
||||||
public static string TargetObject => "#0021: Target object";
|
public static string TargetObject => "#0021: Target object";
|
||||||
|
public static string FileDoesNotExsist => "#0022: File does not exist";
|
||||||
|
public static string FileCantBeOpened => "#0023: File can not be opened";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,18 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Implements logic for convert from one object to another one
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Type of target object</typeparam>
|
||||||
|
/// <typeparam name="V">Type of source object</typeparam>
|
||||||
public interface IObjectConvertStrategy<T, V>
|
public interface IObjectConvertStrategy<T, V>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts sourve object to another one
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">Source object</param>
|
||||||
|
/// <returns>Target object</returns>
|
||||||
T Convert(V source);
|
T Convert(V source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Models.Shapes
|
||||||
|
{
|
||||||
|
public enum ArcFlatteningMode
|
||||||
|
{
|
||||||
|
ByAngleStep,
|
||||||
|
BySegmentCount,
|
||||||
|
ByMaxSegmentLength,
|
||||||
|
Combined
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ArcFlatteningOption : IArcFlatteningOption
|
||||||
|
{
|
||||||
|
public ArcFlatteningMode Mode { get; set; } = ArcFlatteningMode.Combined;
|
||||||
|
public double AngleStepRadians { get; set; } = Math.PI / 8; // 22.5°
|
||||||
|
public int SegmentCount { get; set; } = 2;
|
||||||
|
public double MaxSegmentLength { get; set; } = 0.05; // (m)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace StructureHelperCommon.Models.Shapes
|
||||||
|
{
|
||||||
|
public interface IArcFlatteningOption
|
||||||
|
{
|
||||||
|
double AngleStepRadians { get; set; }
|
||||||
|
double MaxSegmentLength { get; set; }
|
||||||
|
ArcFlatteningMode Mode { get; set; }
|
||||||
|
int SegmentCount { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using netDxf.Entities;
|
||||||
|
using StructureHelperCommon.Infrastructures.Interfaces;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Models.Shapes
|
||||||
|
{
|
||||||
|
public class Polyline2DToLinePoligonConvertLogic : IObjectConvertStrategy<LinePolygonShape, Polyline2D>
|
||||||
|
{
|
||||||
|
private const double metresToMillimeters = 1000.0;
|
||||||
|
private IArcFlatteningOption options = new ArcFlatteningOption();
|
||||||
|
|
||||||
|
public LinePolygonShape Convert(Polyline2D source)
|
||||||
|
{
|
||||||
|
var polygon = new LinePolygonShape(Guid.NewGuid());
|
||||||
|
|
||||||
|
for (int i = 0; i < source.Vertexes.Count; i++)
|
||||||
|
{
|
||||||
|
var v1 = source.Vertexes[i];
|
||||||
|
var v2 = source.Vertexes[(i + 1) % source.Vertexes.Count];
|
||||||
|
|
||||||
|
polygon.AddVertex(new Vertex(v1.Position.X / metresToMillimeters, v1.Position.Y / metresToMillimeters));
|
||||||
|
|
||||||
|
double bulge = v1.Bulge;
|
||||||
|
if (Math.Abs(bulge) < 1e-9)
|
||||||
|
continue;
|
||||||
|
ProcessBulge(polygon, v1, v2, bulge);
|
||||||
|
}
|
||||||
|
|
||||||
|
polygon.IsClosed = source.IsClosed;
|
||||||
|
return polygon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProcessBulge(LinePolygonShape polygon, Polyline2DVertex v1, Polyline2DVertex v2, double bulge)
|
||||||
|
{
|
||||||
|
var p1 = v1.Position;
|
||||||
|
var p2 = v2.Position;
|
||||||
|
|
||||||
|
double chord = Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2));
|
||||||
|
double theta = 4 * Math.Atan(Math.Abs(bulge));
|
||||||
|
double radius = chord / (2 * Math.Sin(theta / 2));
|
||||||
|
|
||||||
|
double dir = bulge > 0 ? 1 : -1;
|
||||||
|
|
||||||
|
// Compute arc center
|
||||||
|
double mx = (p1.X + p2.X) / 2;
|
||||||
|
double my = (p1.Y + p2.Y) / 2;
|
||||||
|
double nx = -(p2.Y - p1.Y) / chord;
|
||||||
|
double ny = (p2.X - p1.X) / chord;
|
||||||
|
double d = radius * Math.Cos(theta / 2);
|
||||||
|
double cx = mx + dir * nx * d;
|
||||||
|
double cy = my + dir * ny * d;
|
||||||
|
|
||||||
|
double a1 = Math.Atan2(p1.Y - cy, p1.X - cx);
|
||||||
|
double a2 = Math.Atan2(p2.Y - cy, p2.X - cx);
|
||||||
|
|
||||||
|
double totalAngle = a2 - a1;
|
||||||
|
if (dir > 0 && totalAngle < 0) totalAngle += 2 * Math.PI;
|
||||||
|
if (dir < 0 && totalAngle > 0) totalAngle -= 2 * Math.PI;
|
||||||
|
|
||||||
|
double stepAngle = GetEffectiveStepAngle(radius, Math.Abs(totalAngle), options);
|
||||||
|
int segments = Math.Max(2, (int)Math.Ceiling(Math.Abs(totalAngle) / stepAngle));
|
||||||
|
|
||||||
|
for (int j = 1; j < segments; j++)
|
||||||
|
{
|
||||||
|
double a = a1 + totalAngle * j / segments;
|
||||||
|
double x = cx + radius * Math.Cos(a);
|
||||||
|
double y = cy + radius * Math.Sin(a);
|
||||||
|
polygon.AddVertex(new Vertex(x / metresToMillimeters, y / metresToMillimeters));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double GetEffectiveStepAngle(double radius, double arcAngle, IArcFlatteningOption options)
|
||||||
|
{
|
||||||
|
// compute angle from each criterion
|
||||||
|
double byAngle = options.AngleStepRadians;
|
||||||
|
double byCount = arcAngle / options.SegmentCount;
|
||||||
|
double byLength = 2 * Math.Asin(options.MaxSegmentLength / (2 * radius));
|
||||||
|
|
||||||
|
return options.Mode switch
|
||||||
|
{
|
||||||
|
ArcFlatteningMode.ByAngleStep => byAngle,
|
||||||
|
ArcFlatteningMode.BySegmentCount => byCount,
|
||||||
|
ArcFlatteningMode.ByMaxSegmentLength => byLength,
|
||||||
|
ArcFlatteningMode.Combined => Math.Min(byAngle, Math.Min(byCount, byLength)),
|
||||||
|
_ => byAngle
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports.Factories
|
||||||
|
{
|
||||||
|
public enum FileInputDataType
|
||||||
|
{
|
||||||
|
Csv,
|
||||||
|
Png,
|
||||||
|
Dxf
|
||||||
|
}
|
||||||
|
public static class FileInputDataFactory
|
||||||
|
{
|
||||||
|
public static FileIOInputData GetFileIOInputData(FileInputDataType dataType)
|
||||||
|
{
|
||||||
|
if (dataType == FileInputDataType.Csv)
|
||||||
|
{
|
||||||
|
return new FileIOInputData
|
||||||
|
{
|
||||||
|
Filter = "csv |*.csv",
|
||||||
|
Title = "Save in csv File"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (dataType == FileInputDataType.Png)
|
||||||
|
{
|
||||||
|
return new FileIOInputData
|
||||||
|
{
|
||||||
|
Filter = "png |*.png",
|
||||||
|
Title = "Save in *.png File"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (dataType == FileInputDataType.Dxf)
|
||||||
|
{
|
||||||
|
return new FileIOInputData
|
||||||
|
{
|
||||||
|
Filter = "dxf |*.dxf",
|
||||||
|
Title = "Save in *.dxf File"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(dataType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public class FileIOInputData : IFileIOnputData
|
||||||
|
{
|
||||||
|
public string FileName { get; set; } = "New file";
|
||||||
|
public string Filter { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
54
StructureHelperCommon/Services/Exports/GetDxfLayerLogic.cs
Normal file
54
StructureHelperCommon/Services/Exports/GetDxfLayerLogic.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using netDxf;
|
||||||
|
using netDxf.Tables;
|
||||||
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public class GetDxfLayerLogic : IGetDxfLayerLogic
|
||||||
|
{
|
||||||
|
private const string PrimitivesLayer = "STR-PRM";
|
||||||
|
private const string OpeningsLayer = "STR-OPN";
|
||||||
|
private const string RebarLayer = "STR-REB";
|
||||||
|
private const string LayerNameIsUnKnown = ": Layer name is unknown";
|
||||||
|
public Layer GetOrCreateLayer(DxfDocument dxf, LayerNames layerName)
|
||||||
|
{
|
||||||
|
string newLayerName = GetLayerName(layerName);
|
||||||
|
Layer newLayer = dxf.Layers.Contains(newLayerName)
|
||||||
|
? dxf.Layers[newLayerName]
|
||||||
|
: new Layer(newLayerName)
|
||||||
|
{
|
||||||
|
Color = GetLayerColor(layerName)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!dxf.Layers.Contains(newLayerName))
|
||||||
|
dxf.Layers.Add(newLayer);
|
||||||
|
return newLayer;
|
||||||
|
}
|
||||||
|
public string GetLayerName(LayerNames layerName)
|
||||||
|
{
|
||||||
|
if (layerName == LayerNames.StructiralPrimitives) { return PrimitivesLayer; }
|
||||||
|
else if (layerName == LayerNames.StructuralOpenings) { return OpeningsLayer; }
|
||||||
|
else if (layerName == LayerNames.StructuralRebars) { return RebarLayer; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AciColor GetLayerColor(LayerNames layerName)
|
||||||
|
{
|
||||||
|
if (layerName == LayerNames.StructiralPrimitives) { return AciColor.Blue; }
|
||||||
|
else if (layerName == LayerNames.StructuralOpenings) { return AciColor.DarkGray; }
|
||||||
|
else if (layerName == LayerNames.StructuralRebars) { return AciColor.Magenta; }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
StructureHelperCommon/Services/Exports/IExportLogic.cs
Normal file
7
StructureHelperCommon/Services/Exports/IExportLogic.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public interface IExportLogic
|
||||||
|
{
|
||||||
|
void Export();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace StructureHelperCommon.Services.Exports
|
namespace StructureHelperCommon.Services.Exports
|
||||||
{
|
{
|
||||||
public interface IExportResultLogic
|
public interface IExportToFileLogic : IExportLogic
|
||||||
{
|
{
|
||||||
string FileName { get; set; }
|
string FileName { get; set; }
|
||||||
void Export();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public interface IFileIOnputData
|
||||||
|
{
|
||||||
|
string FileName { get; set; }
|
||||||
|
string Filter { get; set; }
|
||||||
|
string Title { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
12
StructureHelperCommon/Services/Exports/IGetDxfLayerLogic.cs
Normal file
12
StructureHelperCommon/Services/Exports/IGetDxfLayerLogic.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using netDxf;
|
||||||
|
using netDxf.Tables;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public interface IGetDxfLayerLogic
|
||||||
|
{
|
||||||
|
AciColor GetLayerColor(LayerNames layerName);
|
||||||
|
string GetLayerName(LayerNames layerName);
|
||||||
|
Layer GetOrCreateLayer(DxfDocument dxf, LayerNames layerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public interface IImportFromFileLogic : IImportLogic
|
||||||
|
{
|
||||||
|
string FileName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
13
StructureHelperCommon/Services/Exports/IImportLogic.cs
Normal file
13
StructureHelperCommon/Services/Exports/IImportLogic.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public interface IImportLogic
|
||||||
|
{
|
||||||
|
void Import();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using netDxf;
|
||||||
|
using netDxf.Entities;
|
||||||
|
using netDxf.Header;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public class ShapesAllImportFromDxfLogic : IImportFromFileLogic
|
||||||
|
{
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public List<EntityObject> Entities { get; set; } = [];
|
||||||
|
public void Import()
|
||||||
|
{
|
||||||
|
// this check is optional but recommended before loading a DXF file
|
||||||
|
DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(FileName);
|
||||||
|
// netDxf is only compatible with AutoCad2000 and higher DXF versions
|
||||||
|
if (dxfVersion < DxfVersion.AutoCad2000) return;
|
||||||
|
// load file
|
||||||
|
DxfDocument dxf = DxfDocument.Load(FileName);
|
||||||
|
Entities.Clear();
|
||||||
|
if (dxf != null)
|
||||||
|
{
|
||||||
|
Entities.AddRange(dxf.Entities.All);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,11 +3,7 @@ using netDxf.Entities;
|
|||||||
using netDxf.Tables;
|
using netDxf.Tables;
|
||||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||||
using StructureHelperCommon.Models.Shapes;
|
using StructureHelperCommon.Models.Shapes;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace StructureHelperCommon.Services.Exports
|
namespace StructureHelperCommon.Services.Exports
|
||||||
{
|
{
|
||||||
@@ -17,14 +13,12 @@ namespace StructureHelperCommon.Services.Exports
|
|||||||
StructuralOpenings,
|
StructuralOpenings,
|
||||||
StructuralRebars
|
StructuralRebars
|
||||||
}
|
}
|
||||||
public class ShapesExportToDxfLogic : IExportResultLogic
|
public class ShapesExportToDxfLogic : IExportToFileLogic
|
||||||
{
|
{
|
||||||
private const string PrimitivesLayer = "STR-PRM";
|
|
||||||
private const string OpeningsLayer = "STR-OPN";
|
|
||||||
private const string RebarLayer = "STR-REB";
|
|
||||||
private const string LayerNameIsUnKnown = ": Layer name is unknown";
|
|
||||||
private const string ShapeTypeIsUnknown = ": Shape is unknown";
|
private const string ShapeTypeIsUnknown = ": Shape is unknown";
|
||||||
|
private const double metresToMillimeters = 1000.0;
|
||||||
private readonly List<(IShape shape, LayerNames layerName)> shapes = [];
|
private readonly List<(IShape shape, LayerNames layerName)> shapes = [];
|
||||||
|
private IGetDxfLayerLogic layerLogic = new GetDxfLayerLogic();
|
||||||
|
|
||||||
public ShapesExportToDxfLogic(List<(IShape shape, LayerNames layerName)> shapes)
|
public ShapesExportToDxfLogic(List<(IShape shape, LayerNames layerName)> shapes)
|
||||||
{
|
{
|
||||||
@@ -45,19 +39,12 @@ namespace StructureHelperCommon.Services.Exports
|
|||||||
{
|
{
|
||||||
ProcessShape(dxf, shape);
|
ProcessShape(dxf, shape);
|
||||||
}
|
}
|
||||||
Layer primitiveLayer = new Layer(PrimitivesLayer)
|
|
||||||
{
|
|
||||||
Color = AciColor.Blue
|
|
||||||
};
|
|
||||||
dxf.Layers.Add(primitiveLayer);
|
|
||||||
|
|
||||||
// save to file
|
|
||||||
dxf.Save(FileName);
|
dxf.Save(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessShape(DxfDocument dxf, (IShape shape, LayerNames layerName) shape)
|
private void ProcessShape(DxfDocument dxf, (IShape shape, LayerNames layerName) shape)
|
||||||
{
|
{
|
||||||
Layer layer = GetOrCreateLayer(dxf, shape.layerName);
|
Layer layer = layerLogic.GetOrCreateLayer(dxf, shape.layerName);
|
||||||
ProcessShape(dxf, shape.shape, layer);
|
ProcessShape(dxf, shape.shape, layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +65,7 @@ namespace StructureHelperCommon.Services.Exports
|
|||||||
List<Polyline2DVertex> polylineVertices = [];
|
List<Polyline2DVertex> polylineVertices = [];
|
||||||
foreach (var item in linePolygon.Vertices)
|
foreach (var item in linePolygon.Vertices)
|
||||||
{
|
{
|
||||||
Polyline2DVertex vertex = new Polyline2DVertex(item.Point.X, item.Point.Y);
|
Polyline2DVertex vertex = new Polyline2DVertex(item.Point.X * metresToMillimeters, item.Point.Y * metresToMillimeters);
|
||||||
polylineVertices.Add(vertex);
|
polylineVertices.Add(vertex);
|
||||||
}
|
}
|
||||||
Polyline2D polyline2D = new Polyline2D(polylineVertices)
|
Polyline2D polyline2D = new Polyline2D(polylineVertices)
|
||||||
@@ -88,42 +75,5 @@ namespace StructureHelperCommon.Services.Exports
|
|||||||
};
|
};
|
||||||
dxf.Entities.Add(polyline2D);
|
dxf.Entities.Add(polyline2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Layer GetOrCreateLayer(DxfDocument dxf, LayerNames layerName)
|
|
||||||
{
|
|
||||||
string newLayerName = GetLayerName(layerName);
|
|
||||||
Layer newLayer = dxf.Layers.Contains("newLayerName")
|
|
||||||
? dxf.Layers["newLayerName"]
|
|
||||||
: new Layer("newLayerName")
|
|
||||||
{
|
|
||||||
Color = GetLayerColor(layerName)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!dxf.Layers.Contains(newLayerName))
|
|
||||||
dxf.Layers.Add(newLayer);
|
|
||||||
return newLayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetLayerName(LayerNames layerName)
|
|
||||||
{
|
|
||||||
if (layerName == LayerNames.StructiralPrimitives) { return PrimitivesLayer; }
|
|
||||||
else if (layerName == LayerNames.StructuralOpenings) { return OpeningsLayer; }
|
|
||||||
else if (layerName == LayerNames.StructuralRebars) { return RebarLayer; }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AciColor GetLayerColor(LayerNames layerName)
|
|
||||||
{
|
|
||||||
if (layerName == LayerNames.StructiralPrimitives) { return AciColor.Blue; }
|
|
||||||
else if (layerName == LayerNames.StructuralOpenings) { return AciColor.DarkGray; }
|
|
||||||
else if (layerName == LayerNames.StructuralRebars) { return AciColor.Magenta; }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknownObj(layerName) + LayerNameIsUnKnown);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using netDxf.Entities;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace StructureHelperCommon.Services.Exports
|
||||||
|
{
|
||||||
|
public class SinglePolyline2DImportFromDxfLogic : IImportFromFileLogic
|
||||||
|
{
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public Polyline2D Polyline2D { get; private set; }
|
||||||
|
public void Import()
|
||||||
|
{
|
||||||
|
var importLogic = new ShapesAllImportFromDxfLogic() { FileName = FileName};
|
||||||
|
importLogic.Import();
|
||||||
|
var entities = importLogic.Entities;
|
||||||
|
Polyline2D = entities.Single(x => x is Polyline2D) as Polyline2D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ using System.Windows.Media.Imaging;
|
|||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
{
|
{
|
||||||
public class ExportFrameWorkElementLogic : IExportResultLogic
|
public class ExportFrameWorkElementLogic : IExportToFileLogic
|
||||||
{
|
{
|
||||||
private FrameworkElement element;
|
private FrameworkElement element;
|
||||||
private double scaleFactor;
|
private double scaleFactor;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
{
|
{
|
||||||
public class ExportGeometryResultToCSVLogic : IExportResultLogic
|
public class ExportGeometryResultToCSVLogic : IExportToFileLogic
|
||||||
{
|
{
|
||||||
const string separator = ";";
|
const string separator = ";";
|
||||||
StringBuilder output;
|
StringBuilder output;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Windows.Media.Imaging;
|
|||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
{
|
{
|
||||||
public class ExportResultToBitmapLogic : IExportResultLogic
|
public class ExportResultToBitmapLogic : IExportToFileLogic
|
||||||
{
|
{
|
||||||
private BitmapImage bitmapImage;
|
private BitmapImage bitmapImage;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace StructureHelperLogics.NdmCalculations.Analyses
|
namespace StructureHelperLogics.NdmCalculations.Analyses
|
||||||
{
|
{
|
||||||
public abstract class ExportToCSVLogicBase : IExportResultLogic
|
public abstract class ExportToCSVLogicBase : IExportToFileLogic
|
||||||
{
|
{
|
||||||
public string separator => ";";
|
public string separator => ";";
|
||||||
public StringBuilder output { get; } = new();
|
public StringBuilder output { get; } = new();
|
||||||
|
|||||||
Reference in New Issue
Block a user