View primitives was fixed
This commit is contained in:
@@ -6,6 +6,7 @@ using StructureHelper.Infrastructure.UI.DataContexts;
|
||||
using StructureHelper.Infrastructure.UI.PrimitiveTemplates;
|
||||
using StructureHelper.MaterialCatalogWindow;
|
||||
using StructureHelper.Models.Materials;
|
||||
using StructureHelper.Models.Primitives.Factories;
|
||||
using StructureHelper.Services.Primitives;
|
||||
using StructureHelper.UnitSystem;
|
||||
using StructureHelper.Windows.CalculationWindows.CalculationPropertyWindow;
|
||||
@@ -20,7 +21,9 @@ using StructureHelperCommon.Infrastructures.Enums;
|
||||
using StructureHelperCommon.Infrastructures.Exceptions;
|
||||
using StructureHelperCommon.Infrastructures.Strings;
|
||||
using StructureHelperLogics.Models.Calculations.CalculationProperties;
|
||||
using StructureHelperLogics.Models.Primitives;
|
||||
using StructureHelperLogics.Models.Templates.RCs;
|
||||
using StructureHelperLogics.NdmCalculations.Primitives;
|
||||
using StructureHelperLogics.Services.NdmCalculations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -34,14 +37,14 @@ namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
const double ConstAxisLineThickness = 2d;
|
||||
|
||||
private List<IHeadMaterial> headMaterials;
|
||||
private readonly double scaleRate = 1.1;
|
||||
|
||||
private IPrimitiveRepository PrimitiveRepository { get; }
|
||||
public PrimitiveBase SelectedPrimitive { get; set; }
|
||||
|
||||
private readonly UnitSystemService unitSystemService;
|
||||
|
||||
private MainModel Model { get; }
|
||||
public ObservableCollection<PrimitiveBase> Primitives { get; set; }
|
||||
|
||||
@@ -75,7 +78,18 @@ namespace StructureHelper.Windows.MainWindow
|
||||
public double ScaleValue
|
||||
{
|
||||
get => scaleValue;
|
||||
set => OnPropertyChanged(value, ref scaleValue);
|
||||
set
|
||||
{
|
||||
OnPropertyChanged(value, ref scaleValue);
|
||||
axisLineThickness = ConstAxisLineThickness / scaleValue;
|
||||
OnPropertyChanged(nameof(AxisLineThickness));
|
||||
}
|
||||
}
|
||||
|
||||
public double AxisLineThickness
|
||||
{
|
||||
get =>axisLineThickness == 0d? ConstAxisLineThickness: axisLineThickness;
|
||||
set { axisLineThickness = value; }
|
||||
}
|
||||
|
||||
private double canvasWidth, canvasHeight, xX2, xY1, yX1, yY2;
|
||||
@@ -149,16 +163,14 @@ namespace StructureHelper.Windows.MainWindow
|
||||
public ICommand SetPopupCanBeClosedTrue { get; }
|
||||
public ICommand SetPopupCanBeClosedFalse { get; }
|
||||
|
||||
public string UnitsSystemName => unitSystemService.GetCurrentSystem().Name;
|
||||
|
||||
private double delta = 0.0005;
|
||||
private double axisLineThickness;
|
||||
|
||||
public MainViewModel(MainModel model, IPrimitiveRepository primitiveRepository, UnitSystemService unitSystemService)
|
||||
{
|
||||
PrimitiveRepository = primitiveRepository;
|
||||
Model = model;
|
||||
headMaterials = Model.HeadMaterialRepository.HeadMaterials;
|
||||
this.unitSystemService = unitSystemService;
|
||||
CanvasWidth = 1500;
|
||||
CanvasHeight = 1000;
|
||||
XX2 = CanvasWidth;
|
||||
@@ -169,25 +181,25 @@ namespace StructureHelper.Windows.MainWindow
|
||||
|
||||
LeftButtonUp = new RelayCommand(o =>
|
||||
{
|
||||
if (o is Rectangle rect) rect.BorderCaptured = false;
|
||||
if (o is RectangleViewPrimitive rect) rect.BorderCaptured = false;
|
||||
});
|
||||
LeftButtonDown = new RelayCommand(o =>
|
||||
{
|
||||
if (o is Rectangle rect) rect.BorderCaptured = true;
|
||||
if (o is RectangleViewPrimitive rect) rect.BorderCaptured = true;
|
||||
});
|
||||
PreviewMouseMove = new RelayCommand(o =>
|
||||
{
|
||||
if (o is Rectangle rect && rect.BorderCaptured && !rect.ElementLock)
|
||||
if (o is RectangleViewPrimitive rect && rect.BorderCaptured && !rect.ElementLock)
|
||||
{
|
||||
if (rect.PrimitiveWidth % 10d < delta || rect.PrimitiveWidth % 10d >= delta)
|
||||
rect.PrimitiveWidth = Math.Round(PanelX / 10d) * 10d - rect.X + 10d;
|
||||
rect.PrimitiveWidth = Math.Round(PanelX / 10d) * 10d - rect.PrimitiveLeft + 10d;
|
||||
else
|
||||
rect.PrimitiveWidth = PanelX - rect.X + 10d;
|
||||
rect.PrimitiveWidth = PanelX - rect.PrimitiveLeft + 10d;
|
||||
|
||||
if (rect.PrimitiveHeight % 10d < delta || rect.PrimitiveHeight % 10d >= delta)
|
||||
rect.PrimitiveHeight = Math.Round(PanelY / 10d) * 10d - rect.Y + 10d;
|
||||
rect.PrimitiveHeight = Math.Round(PanelY / 10d) * 10d - rect.PrimitiveTop + 10d;
|
||||
else
|
||||
rect.PrimitiveHeight = PanelY - rect.Y + 10d;
|
||||
rect.PrimitiveHeight = PanelY - rect.PrimitiveTop + 10d;
|
||||
}
|
||||
});
|
||||
ClearSelection = new RelayCommand(o =>
|
||||
@@ -211,10 +223,7 @@ namespace StructureHelper.Windows.MainWindow
|
||||
var materialCatalogView = new MaterialCatalogView(true, primitive);
|
||||
materialCatalogView.ShowDialog();
|
||||
});
|
||||
OpenUnitsSystemSettings = new RelayCommand(o =>
|
||||
{
|
||||
OnPropertyChanged(nameof(UnitsSystemName));
|
||||
});
|
||||
|
||||
SetColor = new RelayCommand(o =>
|
||||
{
|
||||
var primitive = o as PrimitiveBase;
|
||||
@@ -259,18 +268,33 @@ namespace StructureHelper.Windows.MainWindow
|
||||
AddPrimitive = new RelayCommand(o =>
|
||||
{
|
||||
if (!(o is PrimitiveType primitiveType)) return;
|
||||
PrimitiveBase primitive;
|
||||
PrimitiveBase viewPrimitive;
|
||||
INdmPrimitive ndmPrimitive;
|
||||
if (primitiveType == PrimitiveType.Rectangle)
|
||||
{
|
||||
primitive = new Rectangle(0.60, 0.40, 0, 0, this);
|
||||
var primitive = new RectanglePrimitive
|
||||
{
|
||||
Width = 0.4d,
|
||||
Height = 0.6d
|
||||
};
|
||||
ndmPrimitive = primitive;
|
||||
viewPrimitive = new RectangleViewPrimitive(primitive);
|
||||
|
||||
}
|
||||
else if (primitiveType == PrimitiveType.Point)
|
||||
{
|
||||
primitive = new Point(0.0005d, 0d, 0d, this);
|
||||
var primitive = new PointPrimitive
|
||||
{
|
||||
Area = 0.0005d
|
||||
};
|
||||
ndmPrimitive = primitive;
|
||||
viewPrimitive = new PointViewPrimitive(primitive);
|
||||
}
|
||||
|
||||
else { throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown + nameof(primitiveType)); }
|
||||
Primitives.Add(primitive);
|
||||
PrimitiveRepository.Add(primitive);
|
||||
viewPrimitive.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
|
||||
Primitives.Add(viewPrimitive);
|
||||
PrimitiveRepository.Add(viewPrimitive);
|
||||
});
|
||||
|
||||
DeletePrimitive = new RelayCommand(
|
||||
@@ -461,13 +485,6 @@ namespace StructureHelper.Windows.MainWindow
|
||||
wnd.ShowDialog();
|
||||
if (wnd.DialogResult == true)
|
||||
{
|
||||
var rect = template.Shape as StructureHelperCommon.Models.Shapes.RectangleShape;
|
||||
var width = rect.Width;
|
||||
var height = rect.Height;
|
||||
var area1 = Math.PI * template.BottomDiameter * template.BottomDiameter / 4d;
|
||||
var area2 = Math.PI * template.TopDiameter * template.TopDiameter / 4d;
|
||||
var gap = template.CoverGap;
|
||||
|
||||
IHeadMaterial concrete = new HeadMaterial() { Name = "Concrete" };
|
||||
concrete.HelperMaterial = Model.HeadMaterialRepository.LibMaterials.Where(x => (x.MaterialType == MaterialTypes.Concrete & x.Name.Contains("40"))).First();
|
||||
IHeadMaterial reinforcement = new HeadMaterial() { Name = "Reinforcement" };
|
||||
@@ -475,38 +492,14 @@ namespace StructureHelper.Windows.MainWindow
|
||||
headMaterials.Add(concrete);
|
||||
headMaterials.Add(reinforcement);
|
||||
OnPropertyChanged(nameof(headMaterials));
|
||||
|
||||
double[] xs = new double[] { -width / 2 + gap, width / 2 - gap };
|
||||
double[] ys = new double[] { -height / 2 + gap, height / 2 - gap };
|
||||
|
||||
yield return new Rectangle(width, height, 0, 0, this) { HeadMaterial = concrete, Name = "Concrete block" };
|
||||
yield return new Point(area1, xs[0], ys[0], this) { HeadMaterial = reinforcement, Name = "Left bottom point" };
|
||||
yield return new Point(area1, xs[1], ys[0], this) { HeadMaterial = reinforcement, Name = "Right bottom point" };
|
||||
yield return new Point(area2, xs[0], ys[1], this) { HeadMaterial = reinforcement, Name = "Left top point" };
|
||||
yield return new Point(area2, xs[1], ys[1], this) { HeadMaterial = reinforcement, Name = "Right top point" };
|
||||
|
||||
if (template.WidthCount > 2)
|
||||
var primitives = PrimitiveFactory.GetRectangleRCElement(template, concrete, reinforcement);
|
||||
foreach (var item in primitives)
|
||||
{
|
||||
int count = template.WidthCount - 1;
|
||||
double dist = (xs[1] - xs[0]) / count;
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
yield return new Point(area1, xs[0] + dist * i, ys[0], this) { HeadMaterial = reinforcement, Name = $"Bottom point {i}" };
|
||||
yield return new Point(area2, xs[0] + dist * i, ys[1], this) { HeadMaterial = reinforcement, Name = $"Top point {i}" };
|
||||
}
|
||||
}
|
||||
|
||||
if (template.HeightCount > 2)
|
||||
{
|
||||
int count = template.HeightCount - 1;
|
||||
double dist = (ys[1] - ys[0]) / count;
|
||||
for (int i = 1; i < count; i++)
|
||||
{
|
||||
yield return new Point(area1, xs[0], ys[0] + dist * i, this) { HeadMaterial = reinforcement, Name = $"Left point {i}" };
|
||||
yield return new Point(area1, xs[1], ys[0] + dist * i, this) { HeadMaterial = reinforcement, Name = $"Right point {i}" };
|
||||
}
|
||||
item.RegisterDeltas(CanvasWidth / 2, CanvasHeight / 2);
|
||||
}
|
||||
return primitives;
|
||||
}
|
||||
return new List<PrimitiveBase>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user