Copy To window was added

This commit is contained in:
Evgeny Redikultsev
2024-02-02 12:48:39 +05:00
parent 783d5e0591
commit b1fc0c763f
16 changed files with 166 additions and 35 deletions

View File

@@ -22,8 +22,8 @@ namespace StructureHelper
builder.RegisterType<PrimitiveRepository>().As<IPrimitiveRepository>().SingleInstance(); builder.RegisterType<PrimitiveRepository>().As<IPrimitiveRepository>().SingleInstance();
builder.RegisterType<UnitSystemService>().AsSelf().SingleInstance(); builder.RegisterType<UnitSystemService>().AsSelf().SingleInstance();
builder.RegisterType<CalculationService>().AsSelf().SingleInstance(); builder.RegisterType<CalculationService>().AsSelf().SingleInstance();
builder.RegisterType<MainModel>().AsSelf().SingleInstance(); builder.RegisterType<CrossSectionModel>().AsSelf().SingleInstance();
builder.RegisterType<MainViewModel>().AsSelf().SingleInstance(); builder.RegisterType<CrossSectionViewModel>().AsSelf().SingleInstance();
builder.RegisterType<MainView>().AsSelf(); builder.RegisterType<MainView>().AsSelf();

View File

@@ -242,7 +242,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
DeltaY = dy; DeltaY = dy;
} }
public MainViewModel OwnerVM { get; private set; } public CrossSectionViewModel OwnerVM { get; private set; }
public double DeltaX { get; private set; } public double DeltaX { get; private set; }
public double DeltaY { get; private set; } public double DeltaY { get; private set; }

View File

@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<History>True|2023-02-25T08:37:39.2738786Z;False|2023-02-25T13:37:24.0284261+05:00;True|2023-02-25T13:34:01.6858860+05:00;True|2023-02-25T13:31:18.8295711+05:00;False|2023-02-25T13:25:21.5807199+05:00;False|2023-02-25T13:24:41.7164398+05:00;</History> <History>True|2024-02-02T07:22:50.1454015Z;True|2023-02-25T13:37:39.2738786+05:00;False|2023-02-25T13:37:24.0284261+05:00;True|2023-02-25T13:34:01.6858860+05:00;True|2023-02-25T13:31:18.8295711+05:00;False|2023-02-25T13:25:21.5807199+05:00;False|2023-02-25T13:24:41.7164398+05:00;</History>
<LastFailureDetails /> <LastFailureDetails />
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@@ -24,7 +24,7 @@ using System.Threading;
namespace StructureHelper.Windows.MainWindow namespace StructureHelper.Windows.MainWindow
{ {
public class MainModel public class CrossSectionModel
{ {
public ICrossSection Section { get; private set; } public ICrossSection Section { get; private set; }
private IPrimitiveRepository primitiveRepository; private IPrimitiveRepository primitiveRepository;
@@ -37,7 +37,7 @@ namespace StructureHelper.Windows.MainWindow
public ICalculationProperty CalculationProperty { get; private set; } public ICalculationProperty CalculationProperty { get; private set; }
public MainModel(IPrimitiveRepository primitiveRepository, CalculationService calculationService, UnitSystemService unitSystemService) public CrossSectionModel(IPrimitiveRepository primitiveRepository, CalculationService calculationService, UnitSystemService unitSystemService)
{ {
this.primitiveRepository = primitiveRepository; this.primitiveRepository = primitiveRepository;
this.calculationService = calculationService; this.calculationService = calculationService;

View File

@@ -25,7 +25,7 @@ using System.Windows.Input;
namespace StructureHelper.Windows.MainWindow namespace StructureHelper.Windows.MainWindow
{ {
public class MainViewModel : ViewModelBase public class CrossSectionViewModel : ViewModelBase
{ {
ICrossSection section; ICrossSection section;
ICrossSectionRepository repository => section.SectionRepository; ICrossSectionRepository repository => section.SectionRepository;
@@ -44,7 +44,7 @@ namespace StructureHelper.Windows.MainWindow
public PrimitiveViewModelLogic PrimitiveLogic => primitiveLogic; public PrimitiveViewModelLogic PrimitiveLogic => primitiveLogic;
public HelpLogic HelpLogic => new HelpLogic(); public HelpLogic HelpLogic => new HelpLogic();
private MainModel Model { get; } private CrossSectionModel Model { get; }
private double panelX, panelY, scrollPanelX, scrollPanelY; private double panelX, panelY, scrollPanelX, scrollPanelY;
@@ -220,7 +220,7 @@ namespace StructureHelper.Windows.MainWindow
private RelayCommand selectPrimitive; private RelayCommand selectPrimitive;
private MaterialsViewModel materialsLogic; private MaterialsViewModel materialsLogic;
public MainViewModel(MainModel model) public CrossSectionViewModel(CrossSectionModel model)
{ {
visualProperty = new CrossSectionViewVisualProperty(); visualProperty = new CrossSectionViewVisualProperty();
Model = model; Model = model;

View File

@@ -54,6 +54,11 @@
<Image Width="16" Height="16" Source="/Windows/MainWindow/Copy.png" /> <Image Width="16" Height="16" Source="/Windows/MainWindow/Copy.png" />
</MenuItem.Icon> </MenuItem.Icon>
</MenuItem> </MenuItem>
<MenuItem Header="Copy To" Command="{Binding CopyTo}">
<MenuItem.Icon>
<Image Width="16" Height="16" Source="/Windows/MainWindow/Copy.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Command="{Binding Delete}"> <MenuItem Header="Delete" Command="{Binding Delete}">
<MenuItem.Icon> <MenuItem.Icon>
<Image Width="16" Height="16" Source="/Windows/MainWindow/Delete.png" /> <Image Width="16" Height="16" Source="/Windows/MainWindow/Delete.png" />

View File

@@ -8,10 +8,10 @@ namespace StructureHelper.Windows.MainWindow
{ {
public partial class MainView : Window public partial class MainView : Window
{ {
private MainViewModel viewModel; private CrossSectionViewModel viewModel;
public IPrimitiveRepository PrimitiveRepository { get; } public IPrimitiveRepository PrimitiveRepository { get; }
public MainView(IPrimitiveRepository primitiveRepository, MainViewModel viewModel) public MainView(IPrimitiveRepository primitiveRepository, CrossSectionViewModel viewModel)
{ {
PrimitiveRepository = primitiveRepository; PrimitiveRepository = primitiveRepository;
this.viewModel = viewModel; this.viewModel = viewModel;

View File

@@ -6,7 +6,7 @@
xmlns:local="clr-namespace:StructureHelper.Windows.Services" xmlns:local="clr-namespace:StructureHelper.Windows.Services"
d:DataContext ="{d:DesignInstance local:CopyByParameterViewModel}" d:DataContext ="{d:DesignInstance local:CopyByParameterViewModel}"
mc:Ignorable="d" mc:Ignorable="d"
Title="Copy To" Height="260" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterOwner"> Title="Copy To" Height="300" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Window.Resources> <Window.Resources>
<Style TargetType="TextBox"> <Style TargetType="TextBox">
<Setter Property="Margin" Value="2"/> <Setter Property="Margin" Value="2"/>
@@ -35,11 +35,11 @@
<TextBlock Grid.Row="1" Text="Delta Y"/> <TextBlock Grid.Row="1" Text="Delta Y"/>
<TextBlock Grid.Row="2" Text="Angle"/> <TextBlock Grid.Row="2" Text="Angle"/>
<TextBlock Grid.Row="3" Text="Distance"/> <TextBlock Grid.Row="3" Text="Distance"/>
<TextBox Grid.Column="1" Text=""/> <TextBox Grid.Column="1" Text="{Binding DeltaX, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
<TextBox Grid.Column="1" Grid.Row="1" Text=""/> <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding DeltaY, Converter={StaticResource LengthConverter}, ValidatesOnDataErrors=True}"/>
<TextBox Grid.Column="1" Grid.Row="2" Text="" IsEnabled="False"/> <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Angle}" IsEnabled="False"/>
<TextBox Grid.Column="1" Grid.Row="3" Text="" IsEnabled="False"/> <TextBox Grid.Column="1" Grid.Row="3" Text="{Binding Distance, Converter={StaticResource LengthConverter}}" IsEnabled="False"/>
<CheckBox Grid.Row="4" Content="Relative coordinates"/> <CheckBox Grid.Row="4" Content="Relative coordinates" Visibility="Hidden"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
<GroupBox Header="Copy count"> <GroupBox Header="Copy count">
@@ -52,7 +52,7 @@
<RowDefinition Height="27"/> <RowDefinition Height="27"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox Grid.Column="1" Text=""/> <TextBox Grid.Column="1" Text="{Binding CopyCount, ValidatesOnDataErrors=True}"/>
</Grid> </Grid>
</GroupBox> </GroupBox>

View File

@@ -19,9 +19,13 @@ namespace StructureHelper.Windows.Services
/// </summary> /// </summary>
public partial class CopyByParameterView : Window public partial class CopyByParameterView : Window
{ {
public CopyByParameterView() private CopyByParameterViewModel viewModel;
public CopyByParameterView(CopyByParameterViewModel viewModel)
{ {
InitializeComponent(); InitializeComponent();
this.viewModel = viewModel;
DataContext = this.viewModel;
this.viewModel.ParentWindow = this;
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using StructureHelper.Windows.ViewModels; using StructureHelper.Windows.ViewModels;
using StructureHelperCommon.Models.Shapes;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -7,7 +8,85 @@ using System.Threading.Tasks;
namespace StructureHelper.Windows.Services namespace StructureHelper.Windows.Services
{ {
internal class CopyByParameterViewModel : OkCancelViewModelBase public class CopyByParameterViewModel : OkCancelViewModelBase
{ {
private double deltaX;
private double deltaY;
private int copyCount;
public double DeltaX
{
get => deltaX; set
{
deltaX = value;
RefreshAngle();
OnPropertyChanged(nameof(deltaX));
}
}
public double DeltaY
{
get => deltaY; set
{
deltaY = value;
RefreshAngle();
OnPropertyChanged(nameof(deltaY));
}
}
public double Angle { get; set; }
public double Distance { get; set; }
public int CopyCount
{
get => copyCount; set
{
int newValue;
try
{
newValue = value;
copyCount = newValue;
OnPropertyChanged(nameof(CopyCount));
}
catch (Exception)
{
}
}
}
private IPoint2D originalCenter;
public CopyByParameterViewModel(IPoint2D originalCenter)
{
deltaX = 0.2d;
deltaY = 0d;
copyCount = 1;
this.originalCenter = originalCenter;
RefreshAngle();
}
public List<IPoint2D> GetNewItemCenters()
{
var result = new List<IPoint2D>();
for (int i = 1; i <= CopyCount; i++)
{
var newPoint = new Point2D()
{
X = originalCenter.X + deltaX * i,
Y = originalCenter.Y + deltaY * i,
};
result.Add(newPoint);
}
return result;
}
private void RefreshAngle()
{
Angle = Math.Atan2(deltaX, deltaY) * 180d / Math.PI - 90d;
Angle = Math.Round(Angle, 1);
Distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
Distance = Math.Round(Distance, 3);
OnPropertyChanged(nameof(Angle));
OnPropertyChanged(nameof(Distance));
}
} }
} }

View File

@@ -19,6 +19,8 @@ using System.Windows.Documents;
using StructureHelper.Windows.PrimitiveProperiesWindow; using StructureHelper.Windows.PrimitiveProperiesWindow;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System.Windows.Input; using System.Windows.Input;
using StructureHelper.Windows.Services;
using StructureHelperCommon.Models.Shapes;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{ {
@@ -32,6 +34,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
private ICommand copyCommand; private ICommand copyCommand;
private ICommand setToFront; private ICommand setToFront;
private ICommand setToBack; private ICommand setToBack;
private ICommand copyToCommand;
public double CanvasWidth { get; set; } public double CanvasWidth { get; set; }
public double CanvasHeight { get; set; } public double CanvasHeight { get; set; }
@@ -186,15 +189,42 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
return copyCommand ?? return copyCommand ??
( (
copyCommand = new RelayCommand( copyCommand = new RelayCommand(
o => CopySelectedItem(), o => CopySelectedItem(SelectedItem.GetNdmPrimitive()),
o => SelectedItem != null o => SelectedItem != null
)); ));
} }
} }
private void CopySelectedItem() public ICommand CopyTo
{
get
{
return copyToCommand ??
(
copyToCommand = new RelayCommand(
o => CopyToSelectedItem(SelectedItem.GetNdmPrimitive()),
o => SelectedItem != null
));
}
}
private void CopyToSelectedItem(INdmPrimitive ndmPrimitive)
{
var copyByParameterVM = new CopyByParameterViewModel(ndmPrimitive.Center);
var wnd = new CopyByParameterView(copyByParameterVM);
wnd.ShowDialog();
if (wnd.DialogResult != true) { return;}
var points = copyByParameterVM.GetNewItemCenters();
foreach (var item in points)
{
var newPrimitive = CopySelectedItem(ndmPrimitive);
newPrimitive.CenterX = item.X;
newPrimitive.CenterY = item.Y;
}
}
private PrimitiveBase CopySelectedItem(INdmPrimitive oldPrimitive)
{ {
var oldPrimitive = SelectedItem.GetNdmPrimitive();
var newPrimitive = oldPrimitive.Clone() as INdmPrimitive; var newPrimitive = oldPrimitive.Clone() as INdmPrimitive;
newPrimitive.Name += " copy"; newPrimitive.Name += " copy";
repository.Primitives.Add(newPrimitive); repository.Primitives.Add(newPrimitive);
@@ -218,6 +248,7 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
Items.Add(primitiveBase); Items.Add(primitiveBase);
OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(Items));
OnPropertyChanged(nameof(PrimitivesCount)); OnPropertyChanged(nameof(PrimitivesCount));
return primitiveBase;
} }
public int PrimitivesCount => repository.Primitives.Count(); public int PrimitivesCount => repository.Primitives.Count();

View File

@@ -66,7 +66,9 @@ namespace StructureHelperCommon.Models
{ {
var table = new TableLogEntry(6); var table = new TableLogEntry(6);
table.Priority = Priority; table.Priority = Priority;
table.Table.AddRow(GetForceTupleHeaderRow(new ForceTuple())); //type of force tuple for creating a header is taken by first member
var firstMember = forceTuples.First();
table.Table.AddRow(GetForceTupleHeaderRow(firstMember));
foreach (var forceTuple in forceTuples) foreach (var forceTuple in forceTuples)
{ {
table.Table.AddRow(GetForceTupleRow(forceTuple)); table.Table.AddRow(GetForceTupleRow(forceTuple));

View File

@@ -33,7 +33,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
var checkResult = CheckInputData(); var checkResult = CheckInputData();
if (checkResult != "") if (checkResult != "")
{ {
Result = new ForcesResults() { IsValid = false, Description = checkResult }; Result = new ForcesResults()
{
IsValid = false,
Description = checkResult
};
return; return;
} }
else else

View File

@@ -59,7 +59,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
MaxIterationCount = accuracy.MaxIterationCount, MaxIterationCount = accuracy.MaxIterationCount,
StartForceMatrix = new ForceMatrix { Mx = mx, My = my, Nz = nz } StartForceMatrix = new ForceMatrix { Mx = mx, My = my, Nz = nz }
}, },
ActionToOutputResults = ShowResultToConsole, ActionToOutputResults = ShowResultToTrace,
NdmCollection = ndmCollection NdmCollection = ndmCollection
}; };
var calculator = new Calculator(); var calculator = new Calculator();
@@ -70,7 +70,7 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
if (calcResult.AccuracyRate <= accuracy.IterationAccuracy) if (calcResult.AccuracyRate <= accuracy.IterationAccuracy)
{ {
TraceLogger?.AddMessage($"Analisis is done succsesfully"); TraceLogger?.AddMessage($"Analisis is done succsesfully");
TraceLogger?.AddMessage($"Current accuracy {calcResult.AccuracyRate}, {calcResult.IterationCounter} iteration has done", TraceLogStatuses.Debug); TraceLogger?.AddMessage($"Current accuracy {calcResult.AccuracyRate} has acheived in {calcResult.IterationCounter} iteration", TraceLogStatuses.Debug);
return new ForcesTupleResult() return new ForcesTupleResult()
{ {
IsValid = true, IsValid = true,
@@ -82,7 +82,12 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
{ {
TraceLogger?.AddMessage($"Required accuracy rate has not achived", TraceLogStatuses.Error); TraceLogger?.AddMessage($"Required accuracy rate has not achived", TraceLogStatuses.Error);
TraceLogger?.AddMessage($"Current accuracy {calcResult.AccuracyRate}, {calcResult.IterationCounter} iteration has done", TraceLogStatuses.Warning); TraceLogger?.AddMessage($"Current accuracy {calcResult.AccuracyRate}, {calcResult.IterationCounter} iteration has done", TraceLogStatuses.Warning);
return new ForcesTupleResult() { IsValid = false, Description = "Required accuracy rate has not achived", LoaderResults = calcResult }; return new ForcesTupleResult()
{
IsValid = false,
Description = "Required accuracy rate has not achived",
LoaderResults = calcResult
};
} }
} }
@@ -116,5 +121,11 @@ namespace StructureHelperLogics.NdmCalculations.Analyses.ByForces
var strain = result.StrainMatrix; var strain = result.StrainMatrix;
//MessageBox.Show($" Текущие результаты в {result.IterationCounter} итерации:"); //MessageBox.Show($" Текущие результаты в {result.IterationCounter} итерации:");
} }
private void ShowResultToTrace(ILoaderResults result)
{
var strain = result.StrainMatrix;
TraceLogger?.AddMessage($"Iteration {result.IterationCounter}, current accuracy rate {result.AccuracyRate}", TraceLogStatuses.Debug,100);
}
} }
} }

View File

@@ -117,9 +117,9 @@ namespace StructureHelperLogics.NdmCalculations.Cracking
var crackedStrainTuple = GetStrainTuple(EndTuple); var crackedStrainTuple = GetStrainTuple(EndTuple);
TraceLogger?.AddMessage($"Strains in cracked section from actual (end) force"); TraceLogger?.AddMessage($"Strains in cracked section from actual (end) force");
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(crackedStrainTuple)); TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(crackedStrainTuple));
TraceLogger?.AddMessage($"Average curvatures of cracked part of element"); TraceLogger?.AddMessage($"Average strains of cracked part of element");
TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(reducedStrainTuple)); TraceLogger?.AddEntry(new TraceTablesFactory().GetByForceTuple(reducedStrainTuple));
TraceLogger?.AddMessage($"Calculating factors of reducing of stifness"); TraceLogger?.AddMessage($"Factors of reducing of stiffness");
result.FactorOfCrackAppearance = factorOfCrackAppearance; result.FactorOfCrackAppearance = factorOfCrackAppearance;
result.IsValid = true; result.IsValid = true;
result.IsSectionCracked = true; result.IsSectionCracked = true;

View File

@@ -5,11 +5,6 @@ using StructureHelperCommon.Models;
using StructureHelperCommon.Models.Calculators; using StructureHelperCommon.Models.Calculators;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.NdmCalculations.Analyses.ByForces; using StructureHelperLogics.NdmCalculations.Analyses.ByForces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperLogics.NdmCalculations.Cracking namespace StructureHelperLogics.NdmCalculations.Cracking
{ {