Edition of primitives is changed

This commit is contained in:
Evgeny Redikultsev
2022-10-30 18:58:51 +05:00
parent 87a42efc24
commit e1af4d5e07
48 changed files with 1198 additions and 146 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Infrastructure.Exceptions
{
internal class StructureHelperException : Exception
{
public StructureHelperException(string errorString) : base(errorString)
{
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Infrastructure.Strings
{
internal static class ErrorStrings
{
public static string ObjectTypeIsUnknown => "#0001: Object type is unknown";
public static string MaterialTypeIsUnknown => "#0002: Material type is unknown";
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Area : UnitBase
{
public override string unitName { get => "Area"; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= UnitConstatnts.LengthConstant * UnitConstatnts.LengthConstant;
return val;
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null)
{
var strVal = value as string;
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= (UnitConstatnts.LengthConstant * UnitConstatnts.LengthConstant);
return val;
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Length : UnitBase
{
public override string unitName { get => "Length"; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null) { val = (double)value; }
else { throw new Exception($"{unitName} value is null"); }
val *= UnitConstatnts.LengthConstant;
return val;
}
public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
double val;
if (value != null)
{
var strVal = value as string;
double.TryParse(strVal, out val);
}
else { throw new Exception($"{unitName} value is null"); }
val /= UnitConstatnts.LengthConstant;
return val;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal abstract class UnitBase : IValueConverter
{
public abstract string unitName { get;}
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
public abstract object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture);
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal static class UnitConstatnts
{
public static double LengthConstant = 1000d;
}
}

View File

@@ -10,10 +10,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
{
public class Point : PrimitiveBase
{
public Point(double d, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Point, x, y, ownerVm)
public double Area { get; set; }
public Point(double area, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Point, x, y, ownerVm)
{
PrimitiveWidth = d;
PrimitiveHeight = d;
Name = "New point";
Area = area;
PreviewMouseMove = new RelayCommand(o =>
{
if (!(o is Point point)) return;
@@ -32,17 +33,17 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
point.ShowedY = -(ownerVm.PanelY - pointDelta - OwnerVm.XY1);
}
});
ShowedX = x;
ShowedY = y;
CenterX = x;
CenterY = y;
}
public double Diameter { get => Math.Sqrt(Area / Math.PI) * 2; }
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
{
var diam = unitSystem.ConvertLength(PrimitiveWidth);
double area = diam * diam * Math.PI / 4;
string materialName = MaterialName;
ICenter center = new Center { X = unitSystem.ConvertLength(ShowedX), Y = unitSystem.ConvertLength(ShowedY) };
IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = area };
ICenter center = new Center { X = CenterX, Y = CenterY };
IShape shape = new StructureHelperCommon.Models.Shapes.Point { Area = this.Area };
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial };
return ndmPrimitive;

View File

@@ -3,6 +3,9 @@ using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Infrastructure.Exceptions;
using StructureHelper.Infrastructure.Strings;
using StructureHelper.Infrastructure.UI.Converters.Units;
using StructureHelper.Models.Materials;
using StructureHelper.UnitSystem.Systems;
using StructureHelper.Windows.MainWindow;
@@ -16,9 +19,14 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
#region Поля
private readonly PrimitiveType type;
private string name;
private double centerX, centerY;
private int minElementDivision;
private double maxElementSize;
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
private Brush brush;
private MaterialDefinitionBase material;
private double prestrain_kx, prestrain_ky, prestrain_epsz;
private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight, showedX, showedY;
protected double delta = 0.5;
private int showedZIndex = 1, zIndex;
@@ -39,6 +47,61 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
}
}
public string Name
{
get => name;
set
{
OnPropertyChanged(value, ref name);
}
}
public double CenterX
{
get => centerX;
set
{
if (this is Rectangle)
{
ShowedX = value - primitiveWidth / 2d;
}
else if (this is Point)
{
Point point = this as Point;
ShowedX = value - point.Diameter / 2;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
OnPropertyChanged(value, ref centerX);
}
}
public double CenterY
{
get => centerY;
set
{
if (this is Rectangle)
{
ShowedY = value - primitiveHeight / 2d;
}
else if (this is Point)
{
Point point = this as Point;
ShowedY = value - point.Diameter / 2;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
OnPropertyChanged(value, ref centerY);
}
}
public int MinElementDivision
{
get => minElementDivision;
set { OnPropertyChanged(value, ref minElementDivision); }
}
public double MaxElementSize
{
get => maxElementSize;
set { OnPropertyChanged(value, ref maxElementSize); }
}
public bool Captured
{
set => OnPropertyChanged(value, ref captured);
@@ -203,10 +266,11 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
PrimitiveDoubleClick = new RelayCommand(o =>
{
PopupCanBeClosed = false;
Captured = false;
ParamsPanelVisibilty = true;
ParameterCaptured = true;
//PopupCanBeClosed = false;
//Captured = false;
//ParamsPanelVisibilty = true;
//ParameterCaptured = true;
});
OwnerVm = ownerVM;
}
@@ -215,13 +279,29 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
private void UpdateCoordinatesX(double showedX)
{
if (Type == PrimitiveType.Rectangle) X = showedX + OwnerVm.YX1;
if (Type == PrimitiveType.Point) X = showedX + OwnerVm.YX1 - PrimitiveWidth / 2;
if (this is Rectangle)
{
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
}
else if (this is Point)
{
Point point = this as Point;
X = showedX + OwnerVm.YX1 / UnitConstatnts.LengthConstant;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
}
private void UpdateCoordinatesY(double showedY)
{
if (Type == PrimitiveType.Rectangle) Y = -showedY + OwnerVm.XY1 - PrimitiveHeight;
if (Type == PrimitiveType.Point) Y = -showedY + OwnerVm.XY1 - PrimitiveWidth / 2;
if (this is Rectangle)
{
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - PrimitiveHeight;
}
else if (this is Point)
{
Point point = this as Point;
Y = -showedY + OwnerVm.XY1 / UnitConstatnts.LengthConstant - point.Diameter;
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown); }
}
public abstract INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem);
@@ -230,7 +310,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
MaterialTypes materialTypes;
if (Material is ConcreteDefinition) { materialTypes = MaterialTypes.Concrete; }
else if (Material is RebarDefinition) { materialTypes = MaterialTypes.Reinforcement; }
else { throw new Exception("MaterialType is unknown"); }
else { throw new StructureHelperException(ErrorStrings.MaterialTypeIsUnknown); }
return materialTypes;
}
}

View File

@@ -13,6 +13,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
public Rectangle(double primitiveWidth, double primitiveHeight, double x, double y, MainViewModel ownerVm) : base(PrimitiveType.Rectangle, x, y, ownerVm)
{
Type = PrimitiveType.Rectangle;
Name = "New rectangle";
PrimitiveWidth = primitiveWidth;
PrimitiveHeight = primitiveHeight;
PreviewMouseMove = new RelayCommand(o =>
@@ -34,22 +35,23 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
rect.ShowedY = -(OwnerVm.PanelY - deltaY - OwnerVm.XY1 + rect.PrimitiveHeight);
}
});
ShowedX = x;
ShowedY = y;
CenterX = x;
CenterY = y;
MinElementDivision = 10;
MaxElementSize = Math.Min(Math.Min(PrimitiveWidth, PrimitiveHeight) / MinElementDivision, 0.01);
}
public override INdmPrimitive GetNdmPrimitive(IUnitSystem unitSystem)
{
var width = unitSystem.ConvertLength(PrimitiveWidth);
var height = unitSystem.ConvertLength(PrimitiveHeight);
double centerX = unitSystem.ConvertLength(ShowedX) + width / 2;
double centerY = unitSystem.ConvertLength(ShowedY) + height / 2;
var width = PrimitiveWidth;
var height = PrimitiveHeight;
double centerX = CenterX;
double centerY = CenterY;
string materialName = MaterialName;
ICenter center = new Center { X = centerX, Y = centerY };
IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 };
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 0.01, NdmMinDivision = 20 };
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = MaxElementSize, NdmMinDivision = MinElementDivision };
return ndmPrimitive;
}
}

View File

@@ -12,7 +12,7 @@
<StackPanel>
<Ellipse Style="{StaticResource EllipseStyle}" d:DataContext="{d:DesignInstance dataContexts:Point}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">
<!--<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseUp">
@@ -20,10 +20,10 @@
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
</i:EventTrigger>-->
<!--<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
</mouseEventTriggers:DoubleClickEventTrigger>
</mouseEventTriggers:DoubleClickEventTrigger>-->
</i:Interaction.Triggers>
</Ellipse>
<userControls:PrimitivePopup Type="Rectangle" IsOpen="{Binding ParamsPanelVisibilty}" d:DataContext="{d:DesignInstance dataContexts:PrimitiveBase}"/>

View File

@@ -15,7 +15,7 @@
<Grid>
<Rectangle Style="{StaticResource RectangleStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">
<!--<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveLeftButtonDown}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseUp">
@@ -23,13 +23,13 @@
</i:EventTrigger>
<i:EventTrigger EventName="PreviewMouseMove">
<i:InvokeCommandAction Command="{Binding PreviewMouseMove}" CommandParameter="{Binding}"/>
</i:EventTrigger>
<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
</i:EventTrigger>-->
<!--<mouseEventTriggers:DoubleClickEventTrigger EventName="MouseDown">
<i:InvokeCommandAction Command="{Binding PrimitiveDoubleClick}" CommandParameter="{Binding}"/>
</mouseEventTriggers:DoubleClickEventTrigger>
</mouseEventTriggers:DoubleClickEventTrigger>-->
</i:Interaction.Triggers>
</Rectangle>
<Rectangle Cursor="SizeNWSE" Width="20" Height="20" Fill="{Binding Brush}" VerticalAlignment="Bottom" HorizontalAlignment="Right">
<Rectangle Cursor="SizeNWSE" Fill="{Binding Brush}" VerticalAlignment="Bottom" HorizontalAlignment="Right">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseDown">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.LeftButtonDown}" CommandParameter="{Binding}"/>

View File

@@ -5,12 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dataContexts="clr-namespace:StructureHelper.Infrastructure.UI.DataContexts"
xmlns:converters ="clr-namespace:StructureHelper.Infrastructure.UI.Converters.Units"
mc:Ignorable="d" >
<converters:Length x:Key="LengthConverter"/>
<converters:Area x:Key="AreaConverter"/>
<Style TargetType="Shape" x:Key="ShapeStyle">
<Setter Property="Fill" Value="{Binding Brush, Mode=TwoWay}"/>
<Setter Property="Opacity" Value="{Binding Opacity, Mode=TwoWay}"/>
<Setter Property="ToolTip">
<!--<Setter Property="ToolTip">
<Setter.Value>
<ToolTip Background="White" BorderBrush="Black" BorderThickness="1">
<Grid>
@@ -38,18 +42,18 @@
</Grid>
</ToolTip>
</Setter.Value>
</Setter>
</Setter>-->
</Style>
<Style x:Key="EllipseStyle" TargetType="Ellipse" BasedOn="{StaticResource ShapeStyle}">
<Style.Setters>
<Setter Property="Width" Value="{Binding PrimitiveWidth}"/>
<Setter Property="Height" Value="{Binding PrimitiveWidth}"/>
<Setter Property="Width" Value="{Binding Diameter, Converter={StaticResource LengthConverter}}"/>
<Setter Property="Height" Value="{Binding Diameter, Converter={StaticResource LengthConverter}}"/>
</Style.Setters>
</Style>
<Style x:Key="RectangleStyle" TargetType="Rectangle" BasedOn="{StaticResource ShapeStyle}">
<Setter Property="Width" Value="{Binding PrimitiveWidth}"/>
<Setter Property="Height" Value="{Binding PrimitiveHeight}"/>
<Setter Property="Width" Value="{Binding PrimitiveWidth, Converter={StaticResource LengthConverter}}"/>
<Setter Property="Height" Value="{Binding PrimitiveHeight, Converter={StaticResource LengthConverter}}"/>
</Style>
</ResourceDictionary>