Primitive View Logic for Main View modael was added

This commit is contained in:
Evgeny Redikultsev
2023-01-04 18:43:11 +05:00
parent 913d31e04f
commit 2d7c8648ab
24 changed files with 557 additions and 341 deletions

View File

@@ -27,11 +27,9 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
private IPrimitiveRepository primitiveRepository; private IPrimitiveRepository primitiveRepository;
private INdmPrimitive primitive; private INdmPrimitive primitive;
private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured; private bool captured, parameterCaptured, elementLock, paramsPanelVisibilty, popupCanBeClosed = true, borderCaptured;
private bool setMaterialColor; private double showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight;
private Color color;
private double opacity = 1, showedOpacity = 0, x, y, xY1, yX1, primitiveWidth, primitiveHeight;
protected double delta = 0.5; protected double delta = 0.5;
private int showedZIndex = 1, zIndex; private int showedZIndex = 1;
#endregion #endregion
@@ -109,21 +107,23 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
public bool SetMaterialColor public bool SetMaterialColor
{ {
get => setMaterialColor; get => primitive.VisualProperty.SetMaterialColor;
set set
{ {
OnPropertyChanged(value, ref setMaterialColor); primitive.VisualProperty.SetMaterialColor = value;
OnPropertyChanged(nameof(Color)); OnPropertyChanged(nameof(Color));
} }
} }
public Color Color public Color Color
{ {
get => ((setMaterialColor == true) & (primitive.HeadMaterial !=null))? primitive.HeadMaterial.Color : color; get => ((primitive.VisualProperty.SetMaterialColor == true)
& (primitive.HeadMaterial !=null))? primitive.HeadMaterial.Color : primitive.VisualProperty.Color;
set set
{ {
SetMaterialColor = false; SetMaterialColor = false;
OnPropertyChanged(value, ref color); primitive.VisualProperty.Color = value;
OnPropertyChanged(nameof(Color));
} }
} }
@@ -142,11 +142,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
get => elementLock; get => elementLock;
set => OnPropertyChanged(value, ref elementLock); set => OnPropertyChanged(value, ref elementLock);
} }
public Brush Brush
{
get => new SolidColorBrush(Color);
set { }
}
public bool ParamsPanelVisibilty public bool ParamsPanelVisibilty
{ {
@@ -168,10 +163,25 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
OnPropertyChanged(value, ref showedOpacity); OnPropertyChanged(value, ref showedOpacity);
} }
} }
public bool IsVisible
{
get => primitive.VisualProperty.IsVisible;
set
{
primitive.VisualProperty.IsVisible = value;
OnPropertyChanged(nameof(IsVisible));
}
}
public double Opacity public double Opacity
{ {
get => opacity; get => primitive.VisualProperty.Opacity;
set => OnPropertyChanged(value, ref opacity); set
{
primitive.VisualProperty.Opacity = value;
OnPropertyChanged(nameof(Opacity));
}
} }
public int ShowedZIndex public int ShowedZIndex
{ {
@@ -185,8 +195,12 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
} }
public int ZIndex public int ZIndex
{ {
get => zIndex; get => primitive.VisualProperty.ZIndex;
set => OnPropertyChanged(value, ref zIndex); set
{
primitive.VisualProperty.ZIndex = value;
OnPropertyChanged(nameof(ZIndex));
}
} }
public double Xy1 public double Xy1
@@ -218,8 +232,6 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
public PrimitiveBase(INdmPrimitive primitive) public PrimitiveBase(INdmPrimitive primitive)
{ {
color = ColorProcessor.GetRandomColor();
SetMaterialColor = true;
this.primitive = primitive; this.primitive = primitive;
} }

View File

@@ -8,7 +8,7 @@
<ColumnDefinition Width="60"/> <ColumnDefinition Width="60"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding SourceItems}" SelectedItem="{Binding SelectedSourceItem}" ItemTemplate="{StaticResource ResourceKey=SimpleItemTemplate}"/> <ListBox ItemsSource="{Binding SourceItems}" SelectedItem="{Binding SelectedSourceItem}" ItemTemplate="{Binding ItemDataDemplate}"/>
<StackPanel Grid.Column="1"> <StackPanel Grid.Column="1">
<Button Content="Add all" Command="{Binding AddAll}"/> <Button Content="Add all" Command="{Binding AddAll}"/>
<Button Content="Clear all" Command="{Binding ClearAll}"/> <Button Content="Clear all" Command="{Binding ClearAll}"/>
@@ -16,7 +16,7 @@
<Button Content="&lt;&lt;" Command="{Binding RemoveSelected}"/> <Button Content="&lt;&lt;" Command="{Binding RemoveSelected}"/>
</StackPanel> </StackPanel>
<ListBox Grid.Column="2" ItemsSource="{Binding TargetItems}" <ListBox Grid.Column="2" ItemsSource="{Binding TargetItems}"
SelectedItem="{Binding SelectedTargetItem}" ItemTemplate="{StaticResource ResourceKey=SimpleItemTemplate}"/> SelectedItem="{Binding SelectedTargetItem}" ItemTemplate="{Binding ItemDataDemplate}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -19,7 +19,7 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style TargetType="Shape" x:Key="ShapeStyle"> <Style TargetType="{x:Type Shape}" x:Key="ShapeStyle">
<Setter Property="Fill"> <Setter Property="Fill">
<Setter.Value> <Setter.Value>
<SolidColorBrush Color="{Binding Color}"/> <SolidColorBrush Color="{Binding Color}"/>
@@ -33,6 +33,9 @@
<Setter Property="Stroke" Value="Red"/> <Setter Property="Stroke" Value="Red"/>
<Setter Property="StrokeThickness" Value="0.002"/> <Setter Property="StrokeThickness" Value="0.002"/>
</Trigger> </Trigger>
<!--<Trigger Property="IsVisible" Value="False">
<Setter Property="Visibility" Value="Hidden"/>
</Trigger>-->
</Style.Triggers> </Style.Triggers>
</Style> </Style>

View File

@@ -238,6 +238,8 @@
<Compile Include="Windows\ViewModels\Calculations\CalculationProperies\CalculationPropertyViewModel.cs" /> <Compile Include="Windows\ViewModels\Calculations\CalculationProperies\CalculationPropertyViewModel.cs" />
<Compile Include="Windows\ViewModels\Calculations\CalculationResult\CalculationResultViewModel.cs" /> <Compile Include="Windows\ViewModels\Calculations\CalculationResult\CalculationResultViewModel.cs" />
<Compile Include="Windows\ViewModels\Calculations\Calculators\ForcesResultsViewModel.cs" /> <Compile Include="Windows\ViewModels\Calculations\Calculators\ForcesResultsViewModel.cs" />
<Compile Include="Windows\ViewModels\NdmCrossSections\IPrimitiveViewModelLogic.cs" />
<Compile Include="Windows\ViewModels\NdmCrossSections\PrimitiveViewModelLogic.cs" />
<Compile Include="Windows\ViewModels\SourceToTargetViewModel.cs" /> <Compile Include="Windows\ViewModels\SourceToTargetViewModel.cs" />
<Compile Include="Windows\ViewModels\Calculations\Calculators\ForceCalculatorViewModel.cs" /> <Compile Include="Windows\ViewModels\Calculations\Calculators\ForceCalculatorViewModel.cs" />
<Compile Include="Windows\ViewModels\Calculations\Calculators\ICombinationSourceToTargetViewModel.cs" /> <Compile Include="Windows\ViewModels\Calculations\Calculators\ICombinationSourceToTargetViewModel.cs" />

View File

@@ -18,5 +18,6 @@ namespace StructureHelperCommon.Infrastructures.Strings
public static string IncorrectValue => "#0007: value 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 FileCantBeDeleted => "#0008: File can't be deleted";
public static string FileCantBeSaved => "#0009: File can't be saved"; public static string FileCantBeSaved => "#0009: File can't be saved";
public static string VisualPropertyIsNotRight => "#0010: VisualPropertyIsNotRight";
} }
} }

View File

@@ -19,6 +19,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives
double PrestrainKx { get; set; } double PrestrainKx { get; set; }
double PrestrainKy { get; set; } double PrestrainKy { get; set; }
double PrestrainEpsZ { get; set; } double PrestrainEpsZ { get; set; }
IVisualProperty VisualProperty {get; }
IEnumerable<INdm> GetNdms(IMaterial material); IEnumerable<INdm> GetNdms(IMaterial material);
} }

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperLogics.NdmCalculations.Primitives
{
public interface IVisualProperty
{
bool IsVisible { get; set; }
Color Color { get; set; }
bool SetMaterialColor { get; set; }
int ZIndex { get; set; }
double Opacity { get; set; }
}
}

View File

@@ -31,6 +31,7 @@ namespace StructureHelperLogics.NdmCalculations.Primitives
public IPoint2D EndPoint { get; set; } public IPoint2D EndPoint { get; set; }
public double Thickness { get; set; } public double Thickness { get; set; }
public IVisualProperty VisualProperty => throw new NotImplementedException();
public LinePrimitive() public LinePrimitive()
{ {

View File

@@ -26,17 +26,16 @@ namespace StructureHelperLogics.Models.Primitives
public double PrestrainEpsZ { get; set; } public double PrestrainEpsZ { get; set; }
public double Area { get; set; } public double Area { get; set; }
public IVisualProperty VisualProperty { get; }
public PointPrimitive() public PointPrimitive()
{ {
Name = "New Point"; Name = "New Point";
Area = 0.0005d; Area = 0.0005d;
VisualProperty = new VisualProperty();
} }
public PointPrimitive(IHeadMaterial material) public PointPrimitive(IHeadMaterial material) : this() { HeadMaterial = material; }
{
HeadMaterial = material;
}
public IEnumerable<INdm> GetNdms(IMaterial material) public IEnumerable<INdm> GetNdms(IMaterial material)
{ {

View File

@@ -31,11 +31,14 @@ namespace StructureHelperLogics.NdmCalculations.Primitives
public double Height { get; set; } public double Height { get; set; }
public double Angle { get; set; } public double Angle { get; set; }
public IVisualProperty VisualProperty { get; }
public RectanglePrimitive() public RectanglePrimitive()
{ {
Name = "New Rectangle"; Name = "New Rectangle";
NdmMaxSize = 0.01d; NdmMaxSize = 0.01d;
NdmMinDivision = 10; NdmMinDivision = 10;
VisualProperty = new VisualProperty();
} }
public RectanglePrimitive(IHeadMaterial material) : this() { HeadMaterial = material; } public RectanglePrimitive(IHeadMaterial material) : this() { HeadMaterial = material; }

View File

@@ -0,0 +1,42 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Services.ColorServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace StructureHelperLogics.NdmCalculations.Primitives
{
public class VisualProperty : IVisualProperty
{
public bool IsVisible { get; set; }
public Color Color { get; set; }
public bool SetMaterialColor { get; set; }
public int ZIndex { get; set; }
private double opacity;
public double Opacity
{
get { return opacity; }
set
{
if (value < 0d || value > 1d) { throw new StructureHelperException(ErrorStrings.VisualPropertyIsNotRight + nameof(Opacity) + value); }
opacity = value;
}
}
public VisualProperty()
{
IsVisible = true;
Color = ColorProcessor.GetRandomColor();
SetMaterialColor = true;
ZIndex = 0;
Opacity = 1;
}
}
}

View File

@@ -15,10 +15,22 @@ namespace StructureHelperLogics.Services.NdmPrimitives
{ {
public static class NdmPrimitivesService public static class NdmPrimitivesService
{ {
public static void CopyVisualProperty(IVisualProperty source, IVisualProperty target)
{
target.IsVisible = source.IsVisible;
target.Color = source.Color;
target.SetMaterialColor = source.SetMaterialColor;
target.Opacity = source.Opacity;
target.ZIndex = source.ZIndex;
}
public static void CopyNdmProperties (INdmPrimitive source, INdmPrimitive target) public static void CopyNdmProperties (INdmPrimitive source, INdmPrimitive target)
{ {
target.Name = source.Name + " - copy" ; target.Name = source.Name + " copy" ;
target.HeadMaterial = source.HeadMaterial; if (source.HeadMaterial != null) target.HeadMaterial = source.HeadMaterial;
CopyVisualProperty(source.VisualProperty, target.VisualProperty);
target.CenterX = source.CenterX;
target.CenterY = source.CenterY;
target.PrestrainKx = source.PrestrainKx; target.PrestrainKx = source.PrestrainKx;
target.PrestrainKy = source.PrestrainKy; target.PrestrainKy = source.PrestrainKy;
target.PrestrainEpsZ = source.PrestrainEpsZ; target.PrestrainEpsZ = source.PrestrainEpsZ;

View File

@@ -47,23 +47,7 @@
<ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding CombinationViewModel}"/> <ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding CombinationViewModel}"/>
</TabItem> </TabItem>
<TabItem Header="Primitives"> <TabItem Header="Primitives">
<Grid> <ContentControl ContentTemplate="{StaticResource SourceToTarget}" Content="{Binding PrimitivesViewModel}"/>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="60"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ListBox ItemsSource="{Binding AllowedPrimitives}"
SelectedItem="{Binding SelectedAllowedPrimitive}"
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}"/>
</Grid>
</TabItem> </TabItem>
<TabItem Header="Iterations"> <TabItem Header="Iterations">
<Grid> <Grid>

View File

@@ -21,6 +21,7 @@
<DataTemplate DataType="{x:Type dataContexts:PointViewPrimitive}"> <DataTemplate DataType="{x:Type dataContexts:PointViewPrimitive}">
<dataTemplates:EllipseTemplate/> <dataTemplates:EllipseTemplate/>
</DataTemplate> </DataTemplate>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</Window.Resources> </Window.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@@ -94,20 +95,23 @@
<ListBox ItemsSource="{Binding HeadMaterials}" ItemTemplate="{StaticResource ColoredItemTemplate}"> <ListBox ItemsSource="{Binding HeadMaterials}" ItemTemplate="{StaticResource ColoredItemTemplate}">
</ListBox> </ListBox>
</Expander> </Expander>
<Expander Header="Geometry" MinWidth="20" > <Expander Header="Geometry" MinWidth="20" DataContext="{Binding PrimitiveLogic}">
<Expander.ContextMenu> <Expander.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem Header="Add"> <MenuItem Header="Add">
<Button Content="Add Rectangle" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/> <Button Content="Add Rectangle" Command="{Binding Add}" CommandParameter="{x:Static enums:PrimitiveType.Rectangle}"/>
<Button Content="Add Point" Command="{Binding AddPrimitive}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/> <Button Content="Add Point" Command="{Binding Add}" CommandParameter="{x:Static enums:PrimitiveType.Point}"/>
</MenuItem> </MenuItem>
</ContextMenu> </ContextMenu>
</Expander.ContextMenu> </Expander.ContextMenu>
<ListBox ItemsSource="{Binding Primitives}" SelectedItem="{Binding SelectedPrimitive}" ItemTemplate="{StaticResource ColoredItemTemplate}"> <ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" ItemTemplate="{StaticResource ColoredItemTemplate}">
<ListBox.ContextMenu> <ListBox.ContextMenu>
<ContextMenu> <ContextMenu>
<Button Content="Edit" Command="{Binding EditPrimitive}"/> <Button Content="Edit" Command="{Binding Edit}"/>
<Button Content="Delete" Command="{Binding DeletePrimitive}"/> <Button Content="Copy" Command="{Binding Copy}"/>
<Button Content="Delete" Command="{Binding Delete}"/>
<Button Content="To Foreground" Command="{Binding SetToFront}"/>
<Button Content="To Background" Command="{Binding SetToBack}"/>
</ContextMenu> </ContextMenu>
</ListBox.ContextMenu> </ListBox.ContextMenu>
</ListBox> </ListBox>
@@ -170,22 +174,10 @@
<Rectangle StrokeThickness="{Binding GridLineThickness}" Height="0.050" Width="0.050" Stroke="Darkgray"/> <Rectangle StrokeThickness="{Binding GridLineThickness}" Height="0.050" Width="0.050" Stroke="Darkgray"/>
</VisualBrush.Visual> </VisualBrush.Visual>
</VisualBrush> </VisualBrush>
<!--<DrawingBrush Viewport="0,0,0.05,0.05" ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing>
<GeometryDrawing Brush="Black">
<GeometryDrawing.Geometry>
<GeometryGroup FillRule="EvenOdd">
<RectangleGeometry Rect="0,0,0.050,0.050"/>
<RectangleGeometry Rect="0,0,0.0499,0.0499"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>-->
</Canvas.Background> </Canvas.Background>
<Line X1="0" X2="{Binding XX2}" Y1="{Binding XY1}" Y2="{Binding XY1}" Stroke="Red" StrokeThickness="{Binding AxisLineThickness}"/> <Line X1="0" X2="{Binding XX2}" Y1="{Binding XY1}" Y2="{Binding XY1}" Stroke="Red" StrokeThickness="{Binding AxisLineThickness}"/>
<Line X1="{Binding YX1}" X2="{Binding YX1}" Y1="0" Y2="{Binding YY2}" Stroke="ForestGreen" StrokeThickness="{Binding AxisLineThickness}"/> <Line X1="{Binding YX1}" X2="{Binding YX1}" Y1="0" Y2="{Binding YY2}" Stroke="ForestGreen" StrokeThickness="{Binding AxisLineThickness}"/>
<ItemsControl ItemsSource="{Binding Primitives}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> <ItemsControl ItemsSource="{Binding PrimitiveLogic.Items}" d:DataContext="{d:DesignInstance vm:MainViewModel}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<Canvas/> <Canvas/>
@@ -196,6 +188,7 @@
<Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/> <Setter Property="Canvas.ZIndex" Value="{Binding ZIndex}"/>
<Setter Property="Canvas.Left" Value="{Binding PrimitiveLeft}"/> <Setter Property="Canvas.Left" Value="{Binding PrimitiveLeft}"/>
<Setter Property="Canvas.Top" Value="{Binding PrimitiveTop}"/> <Setter Property="Canvas.Top" Value="{Binding PrimitiveTop}"/>
<Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Style> </Style>
</ItemsControl.ItemContainerStyle> </ItemsControl.ItemContainerStyle>
</ItemsControl> </ItemsControl>
@@ -213,7 +206,7 @@
<StatusBarItem> <StatusBarItem>
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock Text="Number of primitives: "/> <TextBlock Text="Number of primitives: "/>
<TextBlock Text="{Binding PrimitivesCount}"/> <TextBlock Text="{Binding PrimitiveLogic.PrimitivesCount}"/>
</StackPanel> </StackPanel>
</StatusBarItem> </StatusBarItem>
</StatusBar> </StatusBar>

View File

@@ -1,31 +1,23 @@
using LoaderCalculator.Data.Ndms; using LoaderCalculator.Data.Ndms;
using LoaderCalculator.Logics.Geometry; using LoaderCalculator.Logics.Geometry;
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Enums;
using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.MaterialCatalogWindow; using StructureHelper.MaterialCatalogWindow;
using StructureHelper.Models.Materials; using StructureHelper.Models.Materials;
using StructureHelper.Models.Primitives.Factories;
using StructureHelper.Windows.CalculationWindows.CalculationPropertyWindow; using StructureHelper.Windows.CalculationWindows.CalculationPropertyWindow;
using StructureHelper.Windows.CalculationWindows.CalculationResultWindow; using StructureHelper.Windows.CalculationWindows.CalculationResultWindow;
using StructureHelper.Windows.ColorPickerWindow; using StructureHelper.Windows.ColorPickerWindow;
using StructureHelper.Windows.MainWindow.Materials; using StructureHelper.Windows.MainWindow.Materials;
using StructureHelper.Windows.PrimitiveProperiesWindow;
using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam; using StructureHelper.Windows.PrimitiveTemplates.RCs.RectangleBeam;
using StructureHelper.Windows.ViewModels.Calculations.CalculationProperies; using StructureHelper.Windows.ViewModels.Calculations.CalculationProperies;
using StructureHelper.Windows.ViewModels.Calculations.CalculationResult; using StructureHelper.Windows.ViewModels.Calculations.CalculationResult;
using StructureHelper.Windows.ViewModels.NdmCrossSections; using StructureHelper.Windows.ViewModels.NdmCrossSections;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Settings;
using StructureHelperCommon.Infrastructures.Strings; using StructureHelperCommon.Infrastructures.Strings;
using StructureHelperCommon.Models.Forces; using StructureHelperCommon.Models.Forces;
using StructureHelperLogics.Models.Calculations.CalculationProperties; using StructureHelperLogics.Models.Calculations.CalculationProperties;
using StructureHelperLogics.Models.CrossSections; using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.Models.Materials;
using StructureHelperLogics.Models.Primitives;
using StructureHelperLogics.Models.Templates.CrossSections.RCs; using StructureHelperLogics.Models.Templates.CrossSections.RCs;
using StructureHelperLogics.Models.Templates.RCs; using StructureHelperLogics.Models.Templates.RCs;
using StructureHelperLogics.NdmCalculations.Primitives;
using StructureHelperLogics.Services.NdmCalculations; using StructureHelperLogics.Services.NdmCalculations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@@ -54,9 +46,9 @@ namespace StructureHelper.Windows.MainWindow
private readonly ICalculatorsViewModelLogic calculatorsLogic; private readonly ICalculatorsViewModelLogic calculatorsLogic;
public ICalculatorsViewModelLogic CalculatorsLogic { get => calculatorsLogic;} public ICalculatorsViewModelLogic CalculatorsLogic { get => calculatorsLogic;}
public IForceCombinationViewModelLogic CombinationsLogic { get => combinationsLogic; } public IForceCombinationViewModelLogic CombinationsLogic { get => combinationsLogic; }
public IPrimitiveViewModelLogic PrimitiveLogic => primitiveLogic;
private MainModel Model { get; } private MainModel Model { get; }
public ObservableCollection<PrimitiveBase> Primitives { get; private set; }
private double panelX, panelY, scrollPanelX, scrollPanelY; private double panelX, panelY, scrollPanelX, scrollPanelY;
private CalculationProperty calculationProperty; private CalculationProperty calculationProperty;
@@ -82,8 +74,6 @@ namespace StructureHelper.Windows.MainWindow
set => OnPropertyChanged(value, ref scrollPanelY); set => OnPropertyChanged(value, ref scrollPanelY);
} }
public int PrimitivesCount => Primitives.Count;
private double scaleValue; private double scaleValue;
public double ScaleValue public double ScaleValue
@@ -155,13 +145,10 @@ namespace StructureHelper.Windows.MainWindow
get => yY2; get => yY2;
set => OnPropertyChanged(value, ref yY2); set => OnPropertyChanged(value, ref yY2);
} }
public ICommand AddPrimitive { get; }
public ICommand Calculate { get; } public ICommand Calculate { get; }
public ICommand DeletePrimitive { get; }
public ICommand EditCalculationPropertyCommand { get; } public ICommand EditCalculationPropertyCommand { get; }
public ICommand EditHeadMaterialsCommand { get; } public ICommand EditHeadMaterialsCommand { get; }
public ICommand EditPrimitive { get; }
public ICommand AddBeamCase { get; } public ICommand AddBeamCase { get; }
public ICommand AddColumnCase { get; } public ICommand AddColumnCase { get; }
public ICommand AddSlabCase { get; } public ICommand AddSlabCase { get; }
@@ -185,6 +172,7 @@ namespace StructureHelper.Windows.MainWindow
private double axisLineThickness; private double axisLineThickness;
private double gridLineThickness; private double gridLineThickness;
private IForceCombinationViewModelLogic combinationsLogic; private IForceCombinationViewModelLogic combinationsLogic;
private IPrimitiveViewModelLogic primitiveLogic;
public MainViewModel(MainModel model) public MainViewModel(MainModel model)
{ {
@@ -194,6 +182,7 @@ namespace StructureHelper.Windows.MainWindow
calculatorsLogic = new CalculatorsViewModelLogic(repository); calculatorsLogic = new CalculatorsViewModelLogic(repository);
CanvasWidth = 2d * scale; CanvasWidth = 2d * scale;
CanvasHeight = 1.5d * scale; CanvasHeight = 1.5d * scale;
primitiveLogic = new PrimitiveViewModelLogic(repository) { CanvasWidth = CanvasWidth, CanvasHeight = CanvasHeight };
XX2 = CanvasWidth; XX2 = CanvasWidth;
XY1 = CanvasHeight / 2d; XY1 = CanvasHeight / 2d;
YX1 = CanvasWidth / 2d; YX1 = CanvasWidth / 2d;
@@ -226,15 +215,6 @@ namespace StructureHelper.Windows.MainWindow
rect.PrimitiveHeight = PanelY - rect.PrimitiveTop + 10d; rect.PrimitiveHeight = PanelY - rect.PrimitiveTop + 10d;
} }
}); });
ClearSelection = new RelayCommand(o =>
{
var primitive = Primitives?.FirstOrDefault(x => x.ParamsPanelVisibilty);
if (primitive != null && primitive.PopupCanBeClosed)
{
primitive.ParamsPanelVisibilty = false;
primitive.ParameterCaptured = false;
}
});
EditHeadMaterialsCommand = new RelayCommand(o => EditHeadMaterials()); EditHeadMaterialsCommand = new RelayCommand(o => EditHeadMaterials());
OpenMaterialCatalog = new RelayCommand(o => OpenMaterialCatalog = new RelayCommand(o =>
{ {
@@ -254,24 +234,6 @@ namespace StructureHelper.Windows.MainWindow
var colorPickerView = new ColorPickerView(primitive); var colorPickerView = new ColorPickerView(primitive);
colorPickerView.ShowDialog(); colorPickerView.ShowDialog();
}); });
SetInFrontOfAll = new RelayCommand(o =>
{
if (!(o is PrimitiveBase primitive)) return;
foreach (var primitiveDefinition in Primitives)
if (primitiveDefinition.ShowedZIndex > primitive.ShowedZIndex && primitiveDefinition != primitive)
primitiveDefinition.ShowedZIndex--;
primitive.ShowedZIndex = PrimitivesCount;
OnPropertyChanged(nameof(primitive.ShowedZIndex));
});
SetInBackOfAll = new RelayCommand(o =>
{
if (!(o is PrimitiveBase primitive)) return;
foreach (var primitiveDefinition in Primitives)
if (primitiveDefinition != primitive && primitiveDefinition.ShowedZIndex < primitive.ShowedZIndex)
primitiveDefinition.ShowedZIndex++;
primitive.ShowedZIndex = 1;
OnPropertyChanged(nameof(primitive.ShowedZIndex));
});
ScaleCanvasDown = new RelayCommand(o => ScaleCanvasDown = new RelayCommand(o =>
{ {
@@ -287,83 +249,20 @@ namespace StructureHelper.Windows.MainWindow
ScaleValue /= scaleRate; ScaleValue /= scaleRate;
}); });
Primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(repository.Primitives);
AddPrimitive = new RelayCommand(o =>
{
if (!(o is PrimitiveType primitiveType)) return;
PrimitiveBase viewPrimitive;
INdmPrimitive ndmPrimitive;
if (primitiveType == PrimitiveType.Rectangle)
{
var primitive = new RectanglePrimitive
{
Width = 0.4d,
Height = 0.6d
};
ndmPrimitive = primitive;
viewPrimitive = new RectangleViewPrimitive(primitive);
}
else if (primitiveType == PrimitiveType.Point)
{
var primitive = new PointPrimitive
{
Area = 0.0005d
};
ndmPrimitive = primitive;
viewPrimitive = new PointViewPrimitive(primitive);
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); }
viewPrimitive.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
repository.Primitives.Add(ndmPrimitive);
Primitives.Add(viewPrimitive);
OnPropertyChanged(nameof(Primitives));
OnPropertyChanged(nameof(PrimitivesCount));
});
DeletePrimitive = new RelayCommand(
o=>DeleteSelectedPrimitive(),
o => SelectedPrimitive != null
);
EditPrimitive = new RelayCommand(
o => EditSelectedPrimitive(),
o => SelectedPrimitive != null
);
AddBeamCase = new RelayCommand(o => AddBeamCase = new RelayCommand(o =>
{ {
foreach (var primitive in GetBeamCasePrimitives()) PrimitiveLogic.AddItems(GetBeamCasePrimitives());
{ //OnPropertyChanged(nameof(PrimitivesCount));
Primitives.Add(primitive);
var ndmPrimitive = primitive.GetNdmPrimitive();
repository.Primitives.Add(ndmPrimitive);
}
OnPropertyChanged(nameof(PrimitivesCount));
}); });
AddColumnCase = new RelayCommand(o => AddColumnCase = new RelayCommand(o =>
{ {
foreach (var primitive in GetColumnCasePrimitives()) PrimitiveLogic.AddItems(GetColumnCasePrimitives());
{
Primitives.Add(primitive);
var ndmPrimitive = primitive.GetNdmPrimitive();
repository.Primitives.Add(ndmPrimitive);
}
OnPropertyChanged(nameof(PrimitivesCount));
}); });
AddSlabCase = new RelayCommand(o => AddSlabCase = new RelayCommand(o =>
{ {
foreach (var primitive in GetSlabCasePrimitives()) PrimitiveLogic.AddItems(GetSlabCasePrimitives());
{
Primitives.Add(primitive);
var ndmPrimitive = primitive.GetNdmPrimitive();
repository.Primitives.Add(ndmPrimitive);
}
OnPropertyChanged(nameof(PrimitivesCount));
}); });
Calculate = new RelayCommand(o => Calculate = new RelayCommand(o =>
@@ -406,39 +305,12 @@ namespace StructureHelper.Windows.MainWindow
var wnd = new HeadMaterialsView(repository); var wnd = new HeadMaterialsView(repository);
wnd.ShowDialog(); wnd.ShowDialog();
OnPropertyChanged(nameof(HeadMaterials)); OnPropertyChanged(nameof(HeadMaterials));
foreach (var primitive in Primitives) foreach (var primitive in primitiveLogic.Items)
{ {
primitive.RefreshColor(); primitive.RefreshColor();
} }
} }
private void DeleteSelectedPrimitive()
{
if (! (SelectedPrimitive is null))
{
var dialogResult = MessageBox.Show("Delete primitive?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
var ndmPrimitive = SelectedPrimitive.GetNdmPrimitive();
repository.Primitives.Remove(ndmPrimitive);
Primitives.Remove(SelectedPrimitive);
}
}
else { MessageBox.Show("Selection is changed", "Please, select primitive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); }
OnPropertyChanged(nameof(PrimitivesCount));
}
private void EditSelectedPrimitive()
{
if (!(SelectedPrimitive is null))
{
var wnd = new PrimitiveProperties(SelectedPrimitive, repository);
wnd.ShowDialog();
OnPropertyChanged(nameof(HeadMaterials));
}
else { MessageBox.Show("Selection is changed", "Please, select primitive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); }
}
private void CalculateResult() private void CalculateResult()
{ {
bool check = CheckAnalisysOptions(); bool check = CheckAnalisysOptions();
@@ -460,16 +332,14 @@ namespace StructureHelper.Windows.MainWindow
MessageBox.Show($"{ErrorStrings.UnknownError}: {ex}", "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show($"{ErrorStrings.UnknownError}: {ex}", "Check data for analisys", MessageBoxButtons.OK, MessageBoxIcon.Warning);
} }
} }
private bool CheckAnalisysOptions() private bool CheckAnalisysOptions()
{ {
if (CheckMaterials() == false) { return false; } if (CheckMaterials() == false) { return false; }
return true; return true;
} }
private bool CheckMaterials() private bool CheckMaterials()
{ {
foreach (var item in Primitives) foreach (var item in primitiveLogic.Items)
{ {
if (item.HeadMaterial == null) if (item.HeadMaterial == null)
{ {
@@ -479,32 +349,27 @@ namespace StructureHelper.Windows.MainWindow
} }
return true; return true;
} }
private IEnumerable<PrimitiveBase> GetBeamCasePrimitives() private IEnumerable<PrimitiveBase> GetBeamCasePrimitives()
{ {
var template = new RectangleBeamTemplate(); var template = new RectangleBeamTemplate();
return GetCasePrimitives(template); return GetCasePrimitives(template);
} }
private IEnumerable<PrimitiveBase> GetColumnCasePrimitives() private IEnumerable<PrimitiveBase> GetColumnCasePrimitives()
{ {
var template = new RectangleBeamTemplate(0.5d, 0.5d) { CoverGap = 0.05, WidthCount = 3, HeightCount = 3, TopDiameter = 0.025d, BottomDiameter = 0.025d }; var template = new RectangleBeamTemplate(0.5d, 0.5d) { CoverGap = 0.05, WidthCount = 3, HeightCount = 3, TopDiameter = 0.025d, BottomDiameter = 0.025d };
return GetCasePrimitives(template); return GetCasePrimitives(template);
} }
private IEnumerable<PrimitiveBase> GetSlabCasePrimitives() private IEnumerable<PrimitiveBase> GetSlabCasePrimitives()
{ {
var template = new RectangleBeamTemplate(1d, 0.2d) { CoverGap = 0.04, WidthCount = 5, HeightCount = 2, TopDiameter = 0.012d, BottomDiameter = 0.012d }; var template = new RectangleBeamTemplate(1d, 0.2d) { CoverGap = 0.04, WidthCount = 5, HeightCount = 2, TopDiameter = 0.012d, BottomDiameter = 0.012d };
return GetCasePrimitives(template); return GetCasePrimitives(template);
} }
private void EditCalculationProperty() private void EditCalculationProperty()
{ {
CalculationPropertyViewModel viewModel = new CalculationPropertyViewModel(calculationProperty); CalculationPropertyViewModel viewModel = new CalculationPropertyViewModel(calculationProperty);
var view = new CalculationPropertyView(viewModel); var view = new CalculationPropertyView(viewModel);
view.ShowDialog(); view.ShowDialog();
} }
private IEnumerable<PrimitiveBase> GetCasePrimitives(RectangleBeamTemplate template) private IEnumerable<PrimitiveBase> GetCasePrimitives(RectangleBeamTemplate template)
{ {
var wnd = new RectangleBeamView(template); var wnd = new RectangleBeamView(template);
@@ -520,13 +385,12 @@ namespace StructureHelper.Windows.MainWindow
OnPropertyChanged(nameof(HeadMaterials)); OnPropertyChanged(nameof(HeadMaterials));
CombinationsLogic.AddItems(newRepository.ForceCombinationLists); CombinationsLogic.AddItems(newRepository.ForceCombinationLists);
CalculatorsLogic.AddItems(newRepository.CalculatorsList); CalculatorsLogic.AddItems(newRepository.CalculatorsList);
//OnPropertyChanged(nameof(CombinationsLogic.Items));
//OnPropertyChanged(nameof(CalculatorsLogic.Items));
var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives); var primitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(newRepository.Primitives);
foreach (var item in primitives) foreach (var item in primitives)
{ {
item.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2); item.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
} }
PrimitiveLogic.Refresh();
return primitives; return primitives;
} }
return new List<PrimitiveBase>(); return new List<PrimitiveBase>();

View File

@@ -1,4 +1,4 @@
<Window x:Class="StructureHelper.Windows.PrimitiveProperiesWindow.PrimitiveProperties" <Window x:Class="StructureHelper.Windows.PrimitiveProperiesWindow.PrimitivePropertiesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@@ -9,6 +9,7 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="PrimitiveProperties" Height="450" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"> Title="PrimitiveProperties" Height="450" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Window.Resources> <Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<DataTemplate x:Key="RectangleProperties"> <DataTemplate x:Key="RectangleProperties">
<Expander Header="Rectangle" IsExpanded="True"> <Expander Header="Rectangle" IsExpanded="True">
<Grid> <Grid>
@@ -61,6 +62,8 @@
</Expander> </Expander>
</DataTemplate> </DataTemplate>
</Window.Resources> </Window.Resources>
<TabControl>
<TabItem Header="Main">
<ScrollViewer> <ScrollViewer>
<StackPanel x:Name="StpProperties"> <StackPanel x:Name="StpProperties">
<Expander Header="Common properties" IsExpanded="True"> <Expander Header="Common properties" IsExpanded="True">
@@ -70,8 +73,6 @@
<RowDefinition Height="22"/> <RowDefinition Height="22"/>
<RowDefinition Height="22"/> <RowDefinition Height="22"/>
<RowDefinition Height="22"/> <RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100"/>
@@ -81,11 +82,9 @@
<TextBlock Grid.Row="1" Text="Name of material"/> <TextBlock Grid.Row="1" Text="Name of material"/>
<TextBlock Grid.Row="2" Text="Center X"/> <TextBlock Grid.Row="2" Text="Center X"/>
<TextBlock Grid.Row="3" Text="Center Y"/> <TextBlock Grid.Row="3" Text="Center Y"/>
<TextBlock Grid.Row="4" Text="Material color"/>
<TextBlock Grid.Row="5" Text="Z-index (integer)"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Name}"/> <TextBox Grid.Row="0" Grid.Column="1" Margin="1" Text="{Binding Name}"/>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left"> <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Left">
<ComboBox Width="120" ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding PrimitiveMaterial}"> <ComboBox Width="100" ItemsSource="{Binding HeadMaterials}" SelectedItem="{Binding PrimitiveMaterial}">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
@@ -108,16 +107,6 @@
</StackPanel> </StackPanel>
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}, ValidatesOnExceptions=True}"/> <TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding CenterX, Converter={StaticResource LengthConverter}, ValidatesOnExceptions=True}"/>
<TextBox Grid.Row="3" Grid.Column="1" Margin="1" Text="{Binding CenterY, Converter={StaticResource LengthConverter}, ValidatesOnExceptions=True}"/> <TextBox Grid.Row="3" Grid.Column="1" Margin="1" Text="{Binding CenterY, Converter={StaticResource LengthConverter}, ValidatesOnExceptions=True}"/>
<TextBox Grid.Row="5" Grid.Column="1" Margin="1" Text="{Binding ZIndex}"/>
<StackPanel Grid.Row="4" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<CheckBox IsChecked="{Binding SetMaterialColor}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,20,0"/>
<Rectangle Width="50" Margin="5,0,10,0">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color}"/>
</Rectangle.Fill>
</Rectangle>
<Button Width="50" Content="..." Command="{Binding EditColorCommand}"/>
</StackPanel>
</Grid> </Grid>
</Expander> </Expander>
<Expander Header="Prestrain" IsExpanded="False"> <Expander Header="Prestrain" IsExpanded="False">
@@ -141,4 +130,47 @@
</Expander> </Expander>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>
</TabItem>
<TabItem Header="Visual">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
<RowDefinition Height="30"/>
<RowDefinition Height="22"/>
<RowDefinition Height="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Text="Visible"/>
<TextBlock Grid.Row="1" Text="Material color"/>
<TextBlock Grid.Row="2" Text="Z-index (integer)"/>
<TextBlock Grid.Row="3" Text="Opacity"/>
<CheckBox Grid.Column="1" IsChecked="{Binding IsVisible}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<CheckBox IsChecked="{Binding SetMaterialColor}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,20,0"/>
<Rectangle Width="50" Margin="5,0,10,0">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding Color}"/>
</Rectangle.Fill>
</Rectangle>
<Button Width="50" Content="..." Command="{Binding EditColorCommand}"/>
</StackPanel>
<TextBox Grid.Row="2" Grid.Column="1" Margin="1" Text="{Binding ZIndex}"/>
<Grid Grid.Row="3" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding Opacity, Converter={StaticResource PlainDouble}, ValidatesOnExceptions=True}" Margin="5"/>
<Slider Grid.Column="1" Value="{Binding Opacity}" Maximum="100" TickPlacement="BottomRight" TickFrequency="10" IsSnapToTickEnabled="True" Margin="2"/>
</Grid>
</Grid>
</TabItem>
</TabControl>
</Window> </Window>

View File

@@ -25,11 +25,11 @@ namespace StructureHelper.Windows.PrimitiveProperiesWindow
/// <summary> /// <summary>
/// Логика взаимодействия для PrimitiveProperties.xaml /// Логика взаимодействия для PrimitiveProperties.xaml
/// </summary> /// </summary>
public partial class PrimitiveProperties : Window public partial class PrimitivePropertiesView : Window
{ {
PrimitiveBase primitive; PrimitiveBase primitive;
private PrimitivePropertiesViewModel viewModel; private PrimitivePropertiesViewModel viewModel;
public PrimitiveProperties(PrimitiveBase primitive, IHasHeadMaterials headMaterials) public PrimitivePropertiesView(PrimitiveBase primitive, IHasHeadMaterials headMaterials)
{ {
this.primitive = primitive; this.primitive = primitive;
viewModel = new PrimitivePropertiesViewModel(this.primitive, headMaterials); viewModel = new PrimitivePropertiesViewModel(this.primitive, headMaterials);

View File

@@ -1,5 +1,6 @@
using StructureHelper.Infrastructure; using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts; using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelper.Services.Primitives;
using StructureHelperCommon.Infrastructures.Enums; using StructureHelperCommon.Infrastructures.Enums;
using StructureHelperCommon.Infrastructures.Exceptions; using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperCommon.Infrastructures.Strings; using StructureHelperCommon.Infrastructures.Strings;
@@ -13,6 +14,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@@ -48,7 +50,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
public bool LongTerm { get; set; } public bool LongTerm { get; set; }
public ISourceToTargetViewModel<IForceCombinationList> CombinationViewModel { get; } public ISourceToTargetViewModel<IForceCombinationList> CombinationViewModel { get; }
//public ISourceToTargetViewModel<PrimitiveBase> PrimitivesViewModel { get; } public ISourceToTargetViewModel<PrimitiveBase> PrimitivesViewModel { get; }
public PrimitiveBase SelectedAllowedPrimitive { get; set; } public PrimitiveBase SelectedAllowedPrimitive { get; set; }
public PrimitiveBase SelectedPrimitive { get; set; } public PrimitiveBase SelectedPrimitive { get; set; }
@@ -60,7 +62,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
var sourceItems = forcesCalculator.Primitives; var sourceItems = forcesCalculator.Primitives;
var rejectedItems = allowedPrimitives.Where(x => sourceItems.Contains(x)); var rejectedItems = allowedPrimitives.Where(x => sourceItems.Contains(x));
var filteredItems = allowedPrimitives.Except(rejectedItems); var filteredItems = allowedPrimitives.Except(rejectedItems);
return ConvertNdmPrimitivesToPrimitiveBase(filteredItems); return PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(filteredItems);
} }
} }
public ObservableCollection<PrimitiveBase> Primitives public ObservableCollection<PrimitiveBase> Primitives
@@ -68,7 +70,7 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
get get
{ {
var sourceItems = forcesCalculator.Primitives; var sourceItems = forcesCalculator.Primitives;
return ConvertNdmPrimitivesToPrimitiveBase(sourceItems); return PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(sourceItems);
} }
} }
@@ -149,37 +151,19 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
CombinationViewModel = new SourceToTargetViewModel<IForceCombinationList>(); CombinationViewModel = new SourceToTargetViewModel<IForceCombinationList>();
CombinationViewModel.SetTargetItems(forcesCalculator.ForceCombinationLists); CombinationViewModel.SetTargetItems(forcesCalculator.ForceCombinationLists);
CombinationViewModel.SetSourceItems(allowedForceCombinations); CombinationViewModel.SetSourceItems(allowedForceCombinations);
CombinationViewModel.ItemDataDemplate = Application.Current.Resources["SimpleItemTemplate"] as DataTemplate;
//PrimitivesViewModel = new SourceToTargetViewModel<PrimitiveBase>(); PrimitivesViewModel = new SourceToTargetViewModel<PrimitiveBase>();
//var targetItems = forcesCalculator.NdmPrimitives; var targetItems = forcesCalculator.Primitives;
//var viewPrimitives = ConvertNdmPrimitivesToPrimitiveBase(targetItems); var sourceViewPrimitives = PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(allowedPrimitives);
//PrimitivesViewModel.SetTargetItems(viewPrimitives); var viewPrimitives = sourceViewPrimitives.Where(x => targetItems.Contains(x.GetNdmPrimitive()));
//var sourceViewPrimitives = ConvertNdmPrimitivesToPrimitiveBase(allowedPrimitives) ; PrimitivesViewModel.SetTargetItems(viewPrimitives);
//PrimitivesViewModel.SetSourceItems(sourceViewPrimitives); PrimitivesViewModel.SetSourceItems(sourceViewPrimitives);
PrimitivesViewModel.ItemDataDemplate = Application.Current.Resources["ColoredItemTemplate"] as DataTemplate;
InputRefresh(); InputRefresh();
} }
private ObservableCollection<PrimitiveBase> ConvertNdmPrimitivesToPrimitiveBase(IEnumerable<INdmPrimitive> primitives)
{
ObservableCollection<PrimitiveBase> viewItems = new ObservableCollection<PrimitiveBase>();
foreach (var item in primitives)
{
if (item is IPointPrimitive)
{
var point = item as IPointPrimitive;
viewItems.Add(new PointViewPrimitive(point));
}
else if (item is IRectanglePrimitive)
{
var rect = item as IRectanglePrimitive;
viewItems.Add(new RectangleViewPrimitive(rect));
}
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown);
}
return viewItems;
}
public void InputRefresh() public void InputRefresh()
{ {
ULS = forcesCalculator.LimitStatesList.Contains(LimitStates.ULS); ULS = forcesCalculator.LimitStatesList.Contains(LimitStates.ULS);
@@ -196,11 +180,11 @@ namespace StructureHelper.Windows.ViewModels.Calculations.Calculators
{ {
forcesCalculator.ForceCombinationLists.Add(item); forcesCalculator.ForceCombinationLists.Add(item);
} }
//forcesCalculator.NdmPrimitives.Clear(); forcesCalculator.Primitives.Clear();
//foreach (var item in PrimitivesViewModel.GetTargetItems()) foreach (var item in PrimitivesViewModel.GetTargetItems())
//{ {
// forcesCalculator.NdmPrimitives.Add(item.GetNdmPrimitive()); forcesCalculator.Primitives.Add(item.GetNdmPrimitive());
//} }
forcesCalculator.LimitStatesList.Clear(); forcesCalculator.LimitStatesList.Clear();
if (ULS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.ULS); } if (ULS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.ULS); }
if (SLS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.SLS); } if (SLS == true) { forcesCalculator.LimitStatesList.Add(LimitStates.SLS); }

View File

@@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
namespace StructureHelper.Windows.ViewModels namespace StructureHelper.Windows.ViewModels
{ {
@@ -14,6 +15,7 @@ namespace StructureHelper.Windows.ViewModels
TItem SelectedTargetItem { get; set; } TItem SelectedTargetItem { get; set; }
ObservableCollection<TItem> SourceItems { get; } ObservableCollection<TItem> SourceItems { get; }
ObservableCollection<TItem> TargetItems { get; } ObservableCollection<TItem> TargetItems { get; }
DataTemplate ItemDataDemplate { get; set; }
RelayCommand AddAll { get; } RelayCommand AddAll { get; }
RelayCommand ClearAll { get; } RelayCommand ClearAll { get; }
RelayCommand AddSelected { get; } RelayCommand AddSelected { get; }

View File

@@ -21,14 +21,14 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
public INdmCalculator SelectedItem { get; set; } public INdmCalculator SelectedItem { get; set; }
public ObservableCollection<INdmCalculator> Items { get; private set; } public ObservableCollection<INdmCalculator> Items { get; private set; }
private RelayCommand addCalculatorCommand; private RelayCommand addCommand;
public RelayCommand Add public RelayCommand Add
{ {
get get
{ {
return addCalculatorCommand ?? return addCommand ??
( (
addCalculatorCommand = new RelayCommand(o => addCommand = new RelayCommand(o =>
{ {
AddCalculator(); AddCalculator();
OnPropertyChanged(nameof(Items)); OnPropertyChanged(nameof(Items));
@@ -41,14 +41,14 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
Items.Add(item); Items.Add(item);
repository.CalculatorsList.Add(item); repository.CalculatorsList.Add(item);
} }
private RelayCommand editCalculatorCommand; private RelayCommand editCommand;
public RelayCommand Edit public RelayCommand Edit
{ {
get get
{ {
return editCalculatorCommand ?? return editCommand ??
( (
editCalculatorCommand = new RelayCommand(o => editCommand = new RelayCommand(o =>
{ {
var tmpSelected = SelectedItem; var tmpSelected = SelectedItem;
EditCalculator(); EditCalculator();
@@ -70,23 +70,22 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
wnd.ShowDialog(); wnd.ShowDialog();
} }
} }
private RelayCommand deleteCalculatorCommand; private RelayCommand deleteCommand;
private RelayCommand runCommand; private RelayCommand runCommand;
private RelayCommand copyCalculatorCommand; private RelayCommand copyCommand;
public RelayCommand Delete public RelayCommand Delete
{ {
get get
{ {
return deleteCalculatorCommand ?? return deleteCommand ??
( (
deleteCalculatorCommand = new RelayCommand(o => deleteCommand = new RelayCommand(o =>
{ {
DeleteCalculator(); DeleteCalculator();
}, o => SelectedItem != null)); }, o => SelectedItem != null));
} }
} }
public RelayCommand Run public RelayCommand Run
{ {
get get
@@ -111,14 +110,13 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}, o => SelectedItem != null)); }, o => SelectedItem != null));
} }
} }
public RelayCommand Copy public RelayCommand Copy
{ {
get get
{ {
return copyCalculatorCommand ?? return copyCommand ??
( (
copyCalculatorCommand = new RelayCommand(o => copyCommand = new RelayCommand(o =>
{ {
var item = SelectedItem.Clone() as INdmCalculator; var item = SelectedItem.Clone() as INdmCalculator;
repository.CalculatorsList.Add(item); repository.CalculatorsList.Add(item);
@@ -127,7 +125,6 @@ namespace StructureHelper.Windows.ViewModels.NdmCrossSections
}, o => SelectedItem != null)); }, o => SelectedItem != null));
} }
} }
private void DeleteCalculator() private void DeleteCalculator()
{ {
var dialogResult = MessageBox.Show("Delete calculator?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); var dialogResult = MessageBox.Show("Delete calculator?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

View File

@@ -0,0 +1,13 @@
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.UI.DataContexts;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public interface IPrimitiveViewModelLogic : ICRUDViewModel<PrimitiveBase>
{
RelayCommand SetToFront { get; }
RelayCommand SetToBack { get; }
int PrimitivesCount { get; }
void Refresh();
}
}

View File

@@ -0,0 +1,227 @@
using FieldVisualizer.ViewModels;
using StructureHelper.Infrastructure.UI.DataContexts;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Primitives;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StructureHelper.Services.Primitives;
using StructureHelper.Infrastructure;
using StructureHelper.Infrastructure.Enums;
using StructureHelperCommon.Infrastructures.Exceptions;
using StructureHelperLogics.Models.Primitives;
using StructureHelperCommon.Infrastructures.Strings;
using ViewModelBase = StructureHelper.Infrastructure.ViewModelBase;
using System.Windows.Forms;
using System.Windows.Documents;
using StructureHelper.Windows.PrimitiveProperiesWindow;
namespace StructureHelper.Windows.ViewModels.NdmCrossSections
{
public class PrimitiveViewModelLogic : ViewModelBase, IPrimitiveViewModelLogic
{
private readonly ICrossSectionRepository repository;
private RelayCommand addCommand;
private RelayCommand deleteCommand;
private RelayCommand editCommand;
private RelayCommand copyCommand;
private RelayCommand setToFront;
private RelayCommand setToBack;
public double CanvasWidth { get; set; }
public double CanvasHeight { get; set; }
public PrimitiveBase SelectedItem { get; set; }
public ObservableCollection<PrimitiveBase> Items { get; private set; }
public RelayCommand Add
{
get
{
return addCommand ??
(
addCommand = new RelayCommand(o =>
{
if (!(o is PrimitiveType primitiveType)) return;
AddPrimitive(primitiveType);
}
));
}
}
private void AddPrimitive(PrimitiveType primitiveType)
{
PrimitiveBase viewPrimitive;
INdmPrimitive ndmPrimitive;
if (primitiveType == PrimitiveType.Rectangle)
{
var primitive = new RectanglePrimitive
{
Width = 0.4d,
Height = 0.6d
};
ndmPrimitive = primitive;
viewPrimitive = new RectangleViewPrimitive(primitive);
}
else if (primitiveType == PrimitiveType.Point)
{
var primitive = new PointPrimitive
{
Area = 0.0005d
};
ndmPrimitive = primitive;
viewPrimitive = new PointViewPrimitive(primitive);
}
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); }
viewPrimitive.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
repository.Primitives.Add(ndmPrimitive);
Items.Add(viewPrimitive);
OnPropertyChanged(nameof(Items));
OnPropertyChanged(nameof(PrimitivesCount));
}
public RelayCommand Delete
{
get
{
return deleteCommand ??
(
deleteCommand = new RelayCommand(o=>
DeleteSelectedPrimitive(),
o => SelectedItem != null
));
}
}
private void DeleteSelectedPrimitive()
{
var dialogResult = MessageBox.Show("Delete primitive?", "Please, confirm deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
var ndmPrimitive = SelectedItem.GetNdmPrimitive();
repository.Primitives.Remove(ndmPrimitive);
Items.Remove(SelectedItem);
}
OnPropertyChanged(nameof(Items));
OnPropertyChanged(nameof(PrimitivesCount));
}
public RelayCommand Edit
{
get
{
return editCommand ??
(
editCommand = new RelayCommand(
o => EditSelectedItem(),
o => SelectedItem != null
));
}
}
private void EditSelectedItem()
{
var wnd = new PrimitivePropertiesView(SelectedItem, repository);
wnd.ShowDialog();
}
public RelayCommand Copy
{
get
{
return copyCommand ??
(
copyCommand = new RelayCommand(
o => CopySelectedItem(),
o => SelectedItem != null
));
}
}
private void CopySelectedItem()
{
var oldPrimitive = SelectedItem.GetNdmPrimitive();
var newPrimitive = oldPrimitive.Clone() as INdmPrimitive;
repository.Primitives.Add(newPrimitive);
PrimitiveBase primitiveBase;
if (newPrimitive is IRectanglePrimitive) { primitiveBase = new RectangleViewPrimitive(newPrimitive as IRectanglePrimitive); }
else if (newPrimitive is IPointPrimitive) { primitiveBase = new PointViewPrimitive(newPrimitive as IPointPrimitive); }
else throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown);
primitiveBase.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
Items.Add(primitiveBase);
OnPropertyChanged(nameof(Items));
OnPropertyChanged(nameof(PrimitivesCount));
}
public int PrimitivesCount => repository.Primitives.Count();
public RelayCommand SetToFront
{
get
{
return setToFront ??
(setToFront = new RelayCommand(o=>
{
int maxZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Max();
SelectedItem.ZIndex = maxZIndex + 1;
},o => CheckMaxIndex()
));
}
}
private bool CheckMaxIndex()
{
if (SelectedItem is null) return false;
int maxZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Max();
if (SelectedItem.ZIndex <= maxZIndex) return true;
else return false;
}
private bool CheckMinIndex()
{
if (SelectedItem is null) return false;
int minZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Min();
if (SelectedItem.ZIndex >= minZIndex) return true;
else return false;
}
public RelayCommand SetToBack
{
get
{
return setToBack ??
(setToBack = new RelayCommand(o =>
{
int minZIndex = Items.Select(x => x.GetNdmPrimitive().VisualProperty.ZIndex).Min();
SelectedItem.ZIndex = minZIndex - 1;
}, o => CheckMinIndex()
));
}
}
public void AddItems(IEnumerable<PrimitiveBase> items)
{
foreach (var item in items)
{
Items.Add(item);
}
}
public void Refresh()
{
OnPropertyChanged(nameof(PrimitivesCount));
}
public PrimitiveViewModelLogic(ICrossSectionRepository repository)
{
this.repository = repository;
Items = new ObservableCollection<PrimitiveBase>();
AddItems(PrimitiveOperations.ConvertNdmPrimitivesToPrimitiveBase(this.repository.Primitives));
}
}
}

View File

@@ -206,6 +206,28 @@ namespace StructureHelper.Windows.ViewModels.PrimitiveProperties
} }
} }
public bool IsVisible
{
get => primitive.IsVisible;
set
{
primitive.IsVisible = value;
OnPropertyChanged(nameof(IsVisible));
}
}
public double Opacity
{
get => primitive.Opacity * 100d;
set
{
if (value < 0d ) { value = 0d; }
if (value > 100d) { value = 100d; }
primitive.Opacity = value / 100d;
OnPropertyChanged(nameof(Opacity));
}
}
public string this[string columnName] public string this[string columnName]
{ {
get get

View File

@@ -7,6 +7,7 @@ using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
namespace StructureHelper.Windows.ViewModels namespace StructureHelper.Windows.ViewModels
{ {
@@ -23,6 +24,7 @@ namespace StructureHelper.Windows.ViewModels
public TItem SelectedTargetItem { get; set; } public TItem SelectedTargetItem { get; set; }
public ObservableCollection<TItem> SourceItems { get; } public ObservableCollection<TItem> SourceItems { get; }
public ObservableCollection<TItem> TargetItems { get; } public ObservableCollection<TItem> TargetItems { get; }
public DataTemplate ItemDataDemplate { get; set; }
public RelayCommand AddAll public RelayCommand AddAll
{ {
get get
@@ -82,6 +84,8 @@ namespace StructureHelper.Windows.ViewModels
} }
} }
public SourceToTargetViewModel() public SourceToTargetViewModel()
{ {
SourceItems = new ObservableCollection<TItem>(); SourceItems = new ObservableCollection<TItem>();