View model for iso viewer was added
This commit is contained in:
@@ -1,12 +1,371 @@
|
|||||||
using System;
|
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||||
|
using FieldVisualizer.Entities.ColorMaps;
|
||||||
|
using FieldVisualizer.Entities.Values.Primitives;
|
||||||
|
using FieldVisualizer.Entities.Values;
|
||||||
|
using FieldVisualizer.Infrastructure.Commands;
|
||||||
|
using FieldVisualizer.InfraStructures.Enums;
|
||||||
|
using FieldVisualizer.InfraStructures.Exceptions;
|
||||||
|
using FieldVisualizer.InfraStructures.Strings;
|
||||||
|
using FieldVisualizer.Services.ColorServices;
|
||||||
|
using FieldVisualizer.Services.PrimitiveServices;
|
||||||
|
using FieldVisualizer.Services.ValueRanges;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using FieldVisualizer.Windows.UserControls;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace FieldVisualizer.ViewModels.FieldViewerViewModels
|
namespace FieldVisualizer.ViewModels.FieldViewerViewModels
|
||||||
{
|
{
|
||||||
public class FieldViewerViewModel : ViewModelBase
|
public class FieldViewerViewModel : ViewModelBase, IDataErrorInfo
|
||||||
{
|
{
|
||||||
|
public ICommand RebuildCommand { get; }
|
||||||
|
public ICommand ZoomInCommand { get; }
|
||||||
|
public ICommand ZoomOutCommand { get; }
|
||||||
|
public ICommand ChangeColorMapCommand { get; }
|
||||||
|
public ICommand SetUserColorsCommand { get; }
|
||||||
|
|
||||||
|
public IPrimitiveSet PrimitiveSet
|
||||||
|
{ get
|
||||||
|
{
|
||||||
|
return primitiveSet;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
primitiveSet = value;
|
||||||
|
OnPropertyChanged(nameof(PrimitiveSet));
|
||||||
|
SumTotal = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Sum(x => x.Value);
|
||||||
|
OnPropertyChanged(nameof(SumTotal));
|
||||||
|
SumNeg = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value < 0).Sum(x => x.Value);
|
||||||
|
OnPropertyChanged(nameof(SumNeg));
|
||||||
|
SumPos = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.Value > 0).Sum(x => x.Value);
|
||||||
|
OnPropertyChanged(nameof(SumPos));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IValueRange UserValueRange { get; set; }
|
||||||
|
public bool SetMinValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return setMinValue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
setMinValue = value;
|
||||||
|
OnPropertyChanged(nameof(SetMinValue));
|
||||||
|
//OnPropertyChanged(nameof(UserMinValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool SetMaxValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return setMaxValue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
setMaxValue = value;
|
||||||
|
OnPropertyChanged(nameof(SetMaxValue));
|
||||||
|
//OnPropertyChanged(nameof(UserMaxValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public double UserMinValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return UserValueRange.BottomValue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
UserValueRange.BottomValue = value;
|
||||||
|
OnPropertyChanged(nameof(UserMinValue));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public double UserMaxValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return UserValueRange.TopValue;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
double tmpVal = UserValueRange.TopValue;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UserValueRange.TopValue = value;
|
||||||
|
OnPropertyChanged(nameof(UserMaxValue));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
UserValueRange.TopValue = tmpVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double SumTotal { get; private set;}
|
||||||
|
public double SumNeg { get; private set; }
|
||||||
|
public double SumPos { get; private set; }
|
||||||
|
|
||||||
|
public Viewbox WorkPlaneBox { get; set; }
|
||||||
|
public VerticalLegend Legend { get; set; }
|
||||||
|
public Canvas WorkPlaneCanvas { get; set; }
|
||||||
|
|
||||||
|
public double ScrolWidth { get; set; }
|
||||||
|
public double ScrolHeight { get; set; }
|
||||||
|
|
||||||
|
public string Error { get; }
|
||||||
|
public string this[string columnName]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
string error = String.Empty;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IPrimitiveSet primitiveSet;
|
||||||
|
private double dX, dY;
|
||||||
|
private ColorMapsTypes _ColorMapType;
|
||||||
|
private IColorMap _ColorMap;
|
||||||
|
private IValueRange valueRange;
|
||||||
|
private IEnumerable<IValueRange> _ValueRanges;
|
||||||
|
private IEnumerable<IValueColorRange> _ValueColorRanges;
|
||||||
|
private bool setMinValue;
|
||||||
|
private bool setMaxValue;
|
||||||
|
const int RangeNumber = 16;
|
||||||
|
|
||||||
|
public FieldViewerViewModel()
|
||||||
|
{
|
||||||
|
_ColorMapType = ColorMapsTypes.FullSpectrum;
|
||||||
|
RebuildCommand = new RelayCommand(o => ProcessPrimitives(), o => PrimitiveValidation());
|
||||||
|
ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation());
|
||||||
|
ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation());
|
||||||
|
ChangeColorMapCommand = new RelayCommand(o => ChangeColorMap(), o => PrimitiveValidation());
|
||||||
|
SetUserColorsCommand = new RelayCommand(o => ColorRefresh(), o => (SetMinValue || SetMaxValue));
|
||||||
|
UserValueRange = new ValueRange() { BottomValue = 0, TopValue = 0 };
|
||||||
|
SetMinValue = false;
|
||||||
|
SetMaxValue = false;
|
||||||
|
}
|
||||||
|
public void ColorRefresh()
|
||||||
|
{
|
||||||
|
if (PrimitiveValidation() == false) { return; }
|
||||||
|
_ColorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
||||||
|
SetColor();
|
||||||
|
if ((PrimitiveSet is null) == false)
|
||||||
|
{
|
||||||
|
ProcessPrimitives();
|
||||||
|
Legend.ValueColorRanges = _ValueColorRanges;
|
||||||
|
Legend.Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void ProcessPrimitives()
|
||||||
|
{
|
||||||
|
WorkPlaneCanvas.Children.Clear();
|
||||||
|
double sizeX = PrimitiveOperations.GetSizeX(PrimitiveSet.ValuePrimitives);
|
||||||
|
double sizeY = PrimitiveOperations.GetSizeY(PrimitiveSet.ValuePrimitives);
|
||||||
|
dX = PrimitiveOperations.GetMinMaxX(PrimitiveSet.ValuePrimitives)[0];
|
||||||
|
dY = PrimitiveOperations.GetMinMaxY(PrimitiveSet.ValuePrimitives)[0];
|
||||||
|
WorkPlaneCanvas.Width = Math.Abs(sizeX);
|
||||||
|
WorkPlaneCanvas.Height = Math.Abs(sizeY);
|
||||||
|
WorkPlaneBox.Width = ScrolWidth - 50;
|
||||||
|
WorkPlaneBox.Height = ScrolHeight - 50;
|
||||||
|
foreach (var primitive in PrimitiveSet.ValuePrimitives)
|
||||||
|
{
|
||||||
|
if (primitive is IRectanglePrimitive)
|
||||||
|
{
|
||||||
|
IRectanglePrimitive rectanglePrimitive = primitive as IRectanglePrimitive;
|
||||||
|
Rectangle rectangle = ProcessRectanglePrimitive(rectanglePrimitive);
|
||||||
|
WorkPlaneCanvas.Children.Add(rectangle);
|
||||||
|
}
|
||||||
|
else if (primitive is ICirclePrimitive)
|
||||||
|
{
|
||||||
|
ICirclePrimitive circlePrimitive = primitive as ICirclePrimitive;
|
||||||
|
Ellipse ellipse = ProcessCirclePrimitive(circlePrimitive);
|
||||||
|
WorkPlaneCanvas.Children.Add(ellipse);
|
||||||
|
}
|
||||||
|
else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Rectangle ProcessRectanglePrimitive(IRectanglePrimitive rectanglePrimitive)
|
||||||
|
{
|
||||||
|
Rectangle rectangle = new Rectangle
|
||||||
|
{
|
||||||
|
Height = rectanglePrimitive.Height,
|
||||||
|
Width = rectanglePrimitive.Width
|
||||||
|
};
|
||||||
|
double addX = rectanglePrimitive.Width / 2;
|
||||||
|
double addY = rectanglePrimitive.Height / 2;
|
||||||
|
ProcessShape(rectangle, rectanglePrimitive, addX, addY);
|
||||||
|
return rectangle;
|
||||||
|
}
|
||||||
|
private Ellipse ProcessCirclePrimitive(ICirclePrimitive circlePrimitive)
|
||||||
|
{
|
||||||
|
Ellipse ellipse = new Ellipse
|
||||||
|
{
|
||||||
|
Height = circlePrimitive.Diameter,
|
||||||
|
Width = circlePrimitive.Diameter
|
||||||
|
};
|
||||||
|
double addX = circlePrimitive.Diameter / 2;
|
||||||
|
double addY = circlePrimitive.Diameter / 2;
|
||||||
|
|
||||||
|
ProcessShape(ellipse, circlePrimitive, addX, addY);
|
||||||
|
return ellipse;
|
||||||
|
}
|
||||||
|
private void ProcessShape(Shape shape, IValuePrimitive valuePrimitive, double addX, double addY)
|
||||||
|
{
|
||||||
|
SolidColorBrush brush = new SolidColorBrush();
|
||||||
|
brush.Color = ColorOperations.GetColorByValue(valueRange, _ColorMap, valuePrimitive.Value);
|
||||||
|
foreach (var valueRange in _ValueColorRanges)
|
||||||
|
{
|
||||||
|
if (valuePrimitive.Value >= valueRange.BottomValue & valuePrimitive.Value <= valueRange.TopValue & (!valueRange.IsActive))
|
||||||
|
{
|
||||||
|
brush.Color = Colors.Gray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shape.ToolTip = valuePrimitive.Value;
|
||||||
|
shape.Tag = valuePrimitive;
|
||||||
|
shape.Fill = brush;
|
||||||
|
Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX);
|
||||||
|
Canvas.SetTop(shape, -valuePrimitive.CenterY - addY - dY);
|
||||||
|
}
|
||||||
|
private void Zoom(double coefficient)
|
||||||
|
{
|
||||||
|
WorkPlaneBox.Width *= coefficient;
|
||||||
|
WorkPlaneBox.Height *= coefficient;
|
||||||
|
}
|
||||||
|
private void ChangeColorMap()
|
||||||
|
{
|
||||||
|
//Iterate all available color maps one by one
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ColorMapType++;
|
||||||
|
IColorMap colorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
||||||
|
}
|
||||||
|
catch (Exception ex) { _ColorMapType = 0; }
|
||||||
|
ColorRefresh();
|
||||||
|
}
|
||||||
|
private bool PrimitiveValidation()
|
||||||
|
{
|
||||||
|
if (PrimitiveSet == null || PrimitiveSet.ValuePrimitives.Count() == 0) { return false; }
|
||||||
|
else return true;
|
||||||
|
}
|
||||||
|
private void SetColor()
|
||||||
|
{
|
||||||
|
valueRange = PrimitiveOperations.GetValueRange(PrimitiveSet.ValuePrimitives);
|
||||||
|
//if bottom value is greater than top value
|
||||||
|
if (SetMinValue
|
||||||
|
& SetMaxValue
|
||||||
|
& (UserValueRange.BottomValue > UserValueRange.TopValue))
|
||||||
|
{
|
||||||
|
UserValueRange.TopValue = UserValueRange.BottomValue;
|
||||||
|
}
|
||||||
|
if (SetMinValue) { valueRange.BottomValue = UserValueRange.BottomValue; } else { UserValueRange.BottomValue = valueRange.BottomValue; }
|
||||||
|
if (SetMaxValue) { valueRange.TopValue = UserValueRange.TopValue; } else { UserValueRange.TopValue = valueRange.TopValue; }
|
||||||
|
_ValueRanges = ValueRangeOperations.DivideValueRange(valueRange, RangeNumber);
|
||||||
|
_ValueColorRanges = ColorOperations.GetValueColorRanges(valueRange, _ValueRanges, _ColorMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Refresh()
|
||||||
|
{
|
||||||
|
SetMinValue = false;
|
||||||
|
SetMaxValue = false;
|
||||||
|
ColorRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private double crossLineX;
|
||||||
|
private double crossLineY;
|
||||||
|
|
||||||
|
public double CrossLineX { get => crossLineX; set => SetProperty(ref crossLineX, value); }
|
||||||
|
public double CrossLineY { get => crossLineY; set => SetProperty(ref crossLineY, value); }
|
||||||
|
|
||||||
|
private ICommand setCrossLineCommand;
|
||||||
|
|
||||||
|
public ICommand SetCrossLineCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (setCrossLineCommand == null)
|
||||||
|
{
|
||||||
|
setCrossLineCommand = new RelayCommand(SetCrossLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
return setCrossLineCommand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetCrossLine(object commandParameter)
|
||||||
|
{
|
||||||
|
AddCrossLine();
|
||||||
|
AddSummaryInfoCrossLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddCrossLine()
|
||||||
|
{
|
||||||
|
double width = WorkPlaneCanvas.ActualWidth;
|
||||||
|
double heigth = WorkPlaneCanvas.ActualHeight;
|
||||||
|
Line line = new Line();
|
||||||
|
if (crossLineX == 0d)
|
||||||
|
{
|
||||||
|
line.X1 = - width / 2d - dX;
|
||||||
|
line.Y1 = - crossLineY - dY;
|
||||||
|
line.X2 = width / 2d - dX;
|
||||||
|
line.Y2 = - crossLineY - dY;
|
||||||
|
}
|
||||||
|
else if (crossLineY == 0d)
|
||||||
|
{
|
||||||
|
line.X1 = crossLineX - dX;
|
||||||
|
line.Y1 = heigth / 2 - dY;
|
||||||
|
line.X2 = crossLineX - dX;
|
||||||
|
line.Y2 = -heigth / 2 - dY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
line.X1 = - width / 2d - dX;
|
||||||
|
line.Y1 = -(crossLineY / crossLineX * width / 2 + crossLineY) - dY;
|
||||||
|
line.X2 = width / 2d - dX;
|
||||||
|
line.Y2 = -(-crossLineY / crossLineX * width / 2 + crossLineY) - dY ;
|
||||||
|
}
|
||||||
|
SolidColorBrush brush = new SolidColorBrush();
|
||||||
|
brush.Color = Colors.Red;
|
||||||
|
line.Fill = brush;
|
||||||
|
line.Stroke = brush;
|
||||||
|
line.StrokeThickness = (width + heigth) / 100;
|
||||||
|
WorkPlaneCanvas.Children.Add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double sumAboveLine;
|
||||||
|
private double sumUnderLine;
|
||||||
|
|
||||||
|
public double SumAboveLine { get => sumAboveLine; set => SetProperty(ref sumAboveLine, value); }
|
||||||
|
public double SumUnderLine { get => sumUnderLine; set => SetProperty(ref sumUnderLine, value); }
|
||||||
|
|
||||||
|
private double GetPointOfCrossLine(double x)
|
||||||
|
{
|
||||||
|
double y;
|
||||||
|
if (crossLineX == 0d)
|
||||||
|
{
|
||||||
|
y = crossLineY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
y = -crossLineY / crossLineX - crossLineY;
|
||||||
|
}
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddSummaryInfoCrossLine()
|
||||||
|
{
|
||||||
|
SumAboveLine = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x=>x.CenterY >= GetPointOfCrossLine(x.CenterX)).Sum(x => x.Value);
|
||||||
|
SumUnderLine = primitiveSet is null ? 0 : primitiveSet.ValuePrimitives.Where(x => x.CenterY <= GetPointOfCrossLine(x.CenterX)).Sum(x => x.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,17 @@ namespace FieldVisualizer.ViewModels
|
|||||||
|
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||||
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
|
||||||
|
protected bool SetProperty<T>(ref T field, T newValue, [CallerMemberName] string propertyName = null)
|
||||||
|
{
|
||||||
|
if (!Equals(field, newValue))
|
||||||
|
{
|
||||||
|
field = newValue;
|
||||||
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="clr-namespace:FieldVisualizer.Windows.UserControls"
|
xmlns:local="clr-namespace:FieldVisualizer.Windows.UserControls"
|
||||||
|
xmlns:vm="clr-namespace:FieldVisualizer.ViewModels.FieldViewerViewModels"
|
||||||
|
d:DataContext="{d:DesignInstance vm:FieldViewerViewModel}"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450" d:DesignWidth="800">
|
d:DesignHeight="450" d:DesignWidth="800">
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
<Button x:Name="ZoomOutButton" Content="ZoomOut" Command="{Binding ZoomOutCommand}"/>
|
<Button x:Name="ZoomOutButton" Content="ZoomOut" Command="{Binding ZoomOutCommand}"/>
|
||||||
<Button x:Name="ChangeColorMapButton" Content="ColorMap" Command="{Binding ChangeColorMapCommand}"/>
|
<Button x:Name="ChangeColorMapButton" Content="ColorMap" Command="{Binding ChangeColorMapCommand}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ScrollViewer Name="WorkPlaneViewer" Grid.Row="1" HorizontalScrollBarVisibility="Visible">
|
<ScrollViewer Name="WorkPlaneViewer" Grid.Row="1" HorizontalScrollBarVisibility="Visible" SizeChanged="WorkPlaneViewer_SizeChanged">
|
||||||
<ScrollViewer.Background>
|
<ScrollViewer.Background>
|
||||||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
|
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
|
||||||
<GradientStop Color="Black"/>
|
<GradientStop Color="Black"/>
|
||||||
@@ -31,17 +33,60 @@
|
|||||||
</LinearGradientBrush>
|
</LinearGradientBrush>
|
||||||
</ScrollViewer.Background>
|
</ScrollViewer.Background>
|
||||||
<Viewbox Name="WorkPlaneBox" Margin="10">
|
<Viewbox Name="WorkPlaneBox" Margin="10">
|
||||||
<Canvas Name="WorkPlaneCanvas"/>
|
<Canvas Name="WorkPlaneCanvas">
|
||||||
|
</Canvas>
|
||||||
</Viewbox>
|
</Viewbox>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
<StackPanel Grid.Column="2">
|
<ScrollViewer Grid.Column="2">
|
||||||
|
<StackPanel>
|
||||||
|
<Expander Header="Color legend" IsExpanded="True">
|
||||||
|
<StackPanel>
|
||||||
<CheckBox x:Name="cbMinValueEnabled" Margin="3" Content="Minimum Value" IsChecked="{Binding Path=SetMinValue}"/>
|
<CheckBox x:Name="cbMinValueEnabled" Margin="3" Content="Minimum Value" IsChecked="{Binding Path=SetMinValue}"/>
|
||||||
<TextBox x:Name="tbMinValue" Margin="20,3,3,3" IsEnabled="{Binding IsChecked, ElementName=cbMinValueEnabled}" Text="{Binding Path=UserValueRange.BottomValue}"/>
|
<TextBox x:Name="tbMinValue" Margin="20,3,3,3" IsEnabled="{Binding IsChecked, ElementName=cbMinValueEnabled}" Text="{Binding Path=UserMinValue, ValidatesOnDataErrors=True}"/>
|
||||||
<CheckBox x:Name="cbMaxValueEnabled" Margin="3" Content="Maximum Value" IsChecked="{Binding Path=SetMaxValue}"/>
|
<CheckBox x:Name="cbMaxValueEnabled" Margin="3" Content="Maximum Value" IsChecked="{Binding Path=SetMaxValue}"/>
|
||||||
<TextBox x:Name="tbMaxValue" Margin="20,3,3,3" IsEnabled="{Binding IsChecked, ElementName=cbMaxValueEnabled}" Text="{Binding Path=UserValueRange.TopValue}"/>
|
<TextBox x:Name="tbMaxValue" Margin="20,3,3,3" IsEnabled="{Binding IsChecked, ElementName=cbMaxValueEnabled}" Text="{Binding Path=UserMaxValue, ValidatesOnDataErrors=True}"/>
|
||||||
<Button Margin="3" Content="Set custom colors" Command="{Binding SetUserColorsCommand}"/>
|
<Button Margin="3" Content="Set custom colors" Command="{Binding SetUserColorsCommand}"/>
|
||||||
<local:VerticalLegend x:Name="LegendViewer" Margin="3" Grid.Column="2"/>
|
<local:VerticalLegend x:Name="LegendViewer" Margin="3" Grid.Column="2"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
</Expander>
|
||||||
|
<Expander Header="Summary information" IsExpanded="False">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="Total sum: "/>
|
||||||
|
<TextBlock Text="{Binding SumTotal}"/>
|
||||||
|
<TextBlock Text="Sum negative: "/>
|
||||||
|
<TextBlock Text="{Binding SumNeg}"/>
|
||||||
|
<TextBlock Text="Sum positive: "/>
|
||||||
|
<TextBlock Text="{Binding SumPos}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Expander>
|
||||||
|
<Expander Header="Summary section" IsExpanded="False">
|
||||||
|
<StackPanel>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
<RowDefinition Height="25"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="120"/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Text="X-distance"/>
|
||||||
|
<TextBox Grid.Column="1" Text="{Binding CrossLineX, ValidatesOnDataErrors=True}"/>
|
||||||
|
<TextBlock Grid.Row="1" Text="Y-distance"/>
|
||||||
|
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding CrossLineY, ValidatesOnDataErrors=True}"/>
|
||||||
|
</Grid>
|
||||||
|
<Button Content="Set section line" Command="{Binding SetCrossLineCommand}"/>
|
||||||
|
<TextBlock Text="Sum above line: "/>
|
||||||
|
<TextBlock Text="{Binding SumAboveLine}"/>
|
||||||
|
<TextBlock Text="Sum under line: "/>
|
||||||
|
<TextBlock Text="{Binding SumUnderLine}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Expander>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
</ScrollViewer>
|
||||||
|
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using FieldVisualizer.InfraStructures.Strings;
|
|||||||
using FieldVisualizer.Services.ColorServices;
|
using FieldVisualizer.Services.ColorServices;
|
||||||
using FieldVisualizer.Services.PrimitiveServices;
|
using FieldVisualizer.Services.PrimitiveServices;
|
||||||
using FieldVisualizer.Services.ValueRanges;
|
using FieldVisualizer.Services.ValueRanges;
|
||||||
|
using FieldVisualizer.ViewModels.FieldViewerViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -25,163 +26,42 @@ namespace FieldVisualizer.Windows.UserControls
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FieldViewer : UserControl
|
public partial class FieldViewer : UserControl
|
||||||
{
|
{
|
||||||
public ICommand RebuildCommand { get; }
|
private FieldViewerViewModel viewModel;
|
||||||
public ICommand ZoomInCommand { get; }
|
|
||||||
public ICommand ZoomOutCommand { get; }
|
|
||||||
public ICommand ChangeColorMapCommand { get; }
|
|
||||||
public ICommand SetUserColorsCommand { get; }
|
|
||||||
|
|
||||||
public IPrimitiveSet PrimitiveSet { get; set; }
|
|
||||||
public IValueRange UserValueRange { get; set; }
|
|
||||||
public bool SetMinValue { get; set; }
|
|
||||||
public bool SetMaxValue { get; set; }
|
|
||||||
|
|
||||||
private double dX, dY;
|
|
||||||
private ColorMapsTypes _ColorMapType;
|
|
||||||
private IColorMap _ColorMap;
|
|
||||||
private IValueRange valueRange;
|
|
||||||
private IEnumerable<IValueRange> _ValueRanges;
|
|
||||||
private IEnumerable<IValueColorRange> _ValueColorRanges;
|
|
||||||
const int RangeNumber = 16;
|
|
||||||
|
|
||||||
public FieldViewer()
|
public FieldViewer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_ColorMapType = ColorMapsTypes.FullSpectrum;
|
viewModel = new FieldViewerViewModel();
|
||||||
DataContext = this;
|
this.DataContext = viewModel;
|
||||||
RebuildCommand = new RelayCommand(o => ProcessPrimitives(), o => PrimitiveValidation());
|
PrimitiveSet = viewModel.PrimitiveSet;
|
||||||
ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation());
|
viewModel.WorkPlaneBox = WorkPlaneBox;
|
||||||
ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation());
|
viewModel.WorkPlaneCanvas = WorkPlaneCanvas;
|
||||||
ChangeColorMapCommand = new RelayCommand(o => ChangeColorMap(), o => PrimitiveValidation());
|
viewModel.Legend = LegendViewer;
|
||||||
SetUserColorsCommand = new RelayCommand(o => ColorRefresh(), o => (SetMinValue || SetMaxValue));
|
|
||||||
UserValueRange = new ValueRange() { BottomValue = 0, TopValue = 0 };
|
|
||||||
SetMinValue = false;
|
|
||||||
SetMaxValue = false;
|
|
||||||
}
|
|
||||||
public void ColorRefresh()
|
|
||||||
{
|
|
||||||
if (PrimitiveValidation() == false) { return; }
|
|
||||||
_ColorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
|
||||||
SetColor();
|
|
||||||
if ((PrimitiveSet is null) == false)
|
|
||||||
{
|
|
||||||
ProcessPrimitives();
|
|
||||||
LegendViewer.ValueColorRanges = _ValueColorRanges;
|
|
||||||
LegendViewer.Refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ProcessPrimitives()
|
|
||||||
{
|
|
||||||
WorkPlaneCanvas.Children.Clear();
|
|
||||||
double sizeX = PrimitiveOperations.GetSizeX(PrimitiveSet.ValuePrimitives);
|
|
||||||
double sizeY = PrimitiveOperations.GetSizeY(PrimitiveSet.ValuePrimitives);
|
|
||||||
dX = PrimitiveOperations.GetMinMaxX(PrimitiveSet.ValuePrimitives)[0];
|
|
||||||
dY = PrimitiveOperations.GetMinMaxY(PrimitiveSet.ValuePrimitives)[0];
|
|
||||||
WorkPlaneCanvas.Width = Math.Abs(sizeX);
|
|
||||||
WorkPlaneCanvas.Height = Math.Abs(sizeY);
|
|
||||||
WorkPlaneBox.Width = WorkPlaneViewer.ActualWidth - 50;
|
|
||||||
WorkPlaneBox.Height = WorkPlaneViewer.ActualHeight - 50;
|
|
||||||
foreach (var primitive in PrimitiveSet.ValuePrimitives)
|
|
||||||
{
|
|
||||||
if (primitive is IRectanglePrimitive)
|
|
||||||
{
|
|
||||||
IRectanglePrimitive rectanglePrimitive = primitive as IRectanglePrimitive;
|
|
||||||
Rectangle rectangle = ProcessRectanglePrimitive(rectanglePrimitive);
|
|
||||||
WorkPlaneCanvas.Children.Add(rectangle);
|
|
||||||
}
|
|
||||||
else if (primitive is ICirclePrimitive)
|
|
||||||
{
|
|
||||||
ICirclePrimitive circlePrimitive = primitive as ICirclePrimitive;
|
|
||||||
Ellipse ellipse = ProcessCirclePrimitive(circlePrimitive);
|
|
||||||
WorkPlaneCanvas.Children.Add(ellipse);
|
|
||||||
}
|
|
||||||
else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private Rectangle ProcessRectanglePrimitive(IRectanglePrimitive rectanglePrimitive)
|
|
||||||
{
|
|
||||||
Rectangle rectangle = new Rectangle
|
|
||||||
{
|
|
||||||
Height = rectanglePrimitive.Height,
|
|
||||||
Width = rectanglePrimitive.Width
|
|
||||||
};
|
|
||||||
double addX = rectanglePrimitive.Width / 2;
|
|
||||||
double addY = rectanglePrimitive.Height / 2;
|
|
||||||
ProcessShape(rectangle, rectanglePrimitive, addX, addY);
|
|
||||||
return rectangle;
|
|
||||||
}
|
|
||||||
private Ellipse ProcessCirclePrimitive(ICirclePrimitive circlePrimitive)
|
|
||||||
{
|
|
||||||
Ellipse ellipse = new Ellipse
|
|
||||||
{
|
|
||||||
Height = circlePrimitive.Diameter,
|
|
||||||
Width = circlePrimitive.Diameter
|
|
||||||
};
|
|
||||||
double addX = circlePrimitive.Diameter / 2;
|
|
||||||
double addY = circlePrimitive.Diameter / 2;
|
|
||||||
|
|
||||||
ProcessShape(ellipse, circlePrimitive, addX, addY);
|
|
||||||
return ellipse;
|
|
||||||
}
|
|
||||||
private void ProcessShape(Shape shape, IValuePrimitive valuePrimitive, double addX, double addY)
|
|
||||||
{
|
|
||||||
SolidColorBrush brush = new SolidColorBrush();
|
|
||||||
brush.Color = ColorOperations.GetColorByValue(valueRange, _ColorMap, valuePrimitive.Value);
|
|
||||||
foreach (var valueRange in _ValueColorRanges)
|
|
||||||
{
|
|
||||||
if (valuePrimitive.Value >= valueRange.BottomValue & valuePrimitive.Value <= valueRange.TopValue & (!valueRange.IsActive))
|
|
||||||
{
|
|
||||||
brush.Color = Colors.Gray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
shape.ToolTip = valuePrimitive.Value;
|
|
||||||
shape.Tag = valuePrimitive;
|
|
||||||
shape.Fill = brush;
|
|
||||||
Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX);
|
|
||||||
Canvas.SetTop(shape, -valuePrimitive.CenterY - addY - dY);
|
|
||||||
}
|
|
||||||
private void Zoom(double coefficient)
|
|
||||||
{
|
|
||||||
WorkPlaneBox.Width *= coefficient;
|
|
||||||
WorkPlaneBox.Height *= coefficient;
|
|
||||||
}
|
|
||||||
private void ChangeColorMap()
|
|
||||||
{
|
|
||||||
//Iterate all available color maps one by one
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_ColorMapType++;
|
|
||||||
IColorMap colorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
|
||||||
}
|
|
||||||
catch (Exception ex) { _ColorMapType = 0; }
|
|
||||||
ColorRefresh();
|
|
||||||
}
|
|
||||||
private bool PrimitiveValidation()
|
|
||||||
{
|
|
||||||
if (PrimitiveSet == null || PrimitiveSet.ValuePrimitives.Count() == 0) { return false; }
|
|
||||||
else return true;
|
|
||||||
}
|
|
||||||
private void SetColor()
|
|
||||||
{
|
|
||||||
valueRange = PrimitiveOperations.GetValueRange(PrimitiveSet.ValuePrimitives);
|
|
||||||
//if bottom value is greater than top value
|
|
||||||
if (SetMinValue
|
|
||||||
& SetMaxValue
|
|
||||||
& (UserValueRange.BottomValue > UserValueRange.TopValue))
|
|
||||||
{
|
|
||||||
UserValueRange.TopValue = UserValueRange.BottomValue;
|
|
||||||
}
|
|
||||||
if (SetMinValue) { valueRange.BottomValue = UserValueRange.BottomValue; } else { UserValueRange.BottomValue = valueRange.BottomValue; }
|
|
||||||
if (SetMaxValue) { valueRange.TopValue = UserValueRange.TopValue; } else { UserValueRange.TopValue = valueRange.TopValue; }
|
|
||||||
_ValueRanges = ValueRangeOperations.DivideValueRange(valueRange, RangeNumber);
|
|
||||||
_ValueColorRanges = ColorOperations.GetValueColorRanges(valueRange, _ValueRanges, _ColorMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Refresh()
|
//public FieldViewer(FieldViewerViewModel vm)
|
||||||
|
//{
|
||||||
|
// InitializeComponent();
|
||||||
|
// viewModel = vm;
|
||||||
|
// this.DataContext = viewModel;
|
||||||
|
// PrimitiveSet = viewModel.PrimitiveSet;
|
||||||
|
// viewModel.WorkPlaneBox = WorkPlaneBox;
|
||||||
|
// viewModel.WorkPlaneCanvas = WorkPlaneCanvas;
|
||||||
|
// viewModel.Legend = LegendViewer;
|
||||||
|
//}
|
||||||
|
|
||||||
|
public IPrimitiveSet PrimitiveSet { get => viewModel.PrimitiveSet; set { viewModel.PrimitiveSet = value; } }
|
||||||
|
|
||||||
|
internal void Refresh()
|
||||||
{
|
{
|
||||||
SetMinValue = false;
|
viewModel.Refresh();
|
||||||
SetMaxValue = false;
|
}
|
||||||
ColorRefresh();
|
|
||||||
|
private void WorkPlaneViewer_SizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
|
{
|
||||||
|
ScrollViewer viewer = (ScrollViewer)sender;
|
||||||
|
viewModel.ScrolWidth = viewer.ActualWidth;
|
||||||
|
viewModel.ScrolHeight = viewer.ActualHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -14,9 +14,13 @@ namespace StructureHelper.Services.ResultViewers
|
|||||||
List<IResultFunc> resultFuncs = new List<IResultFunc>();
|
List<IResultFunc> resultFuncs = new List<IResultFunc>();
|
||||||
IStressLogic stressLogic = new StressLogic();
|
IStressLogic stressLogic = new StressLogic();
|
||||||
resultFuncs.Add(new ResultFunc() { Name = "Total Strain", ResultFunction = stressLogic.GetTotalStrain });
|
resultFuncs.Add(new ResultFunc() { Name = "Total Strain", ResultFunction = stressLogic.GetTotalStrain });
|
||||||
|
resultFuncs.Add(new ResultFunc() { Name = "Total Strain with prestrain", ResultFunction = stressLogic.GetTotalStrainWithPresrain });
|
||||||
resultFuncs.Add(new ResultFunc() { Name = "Elastic Strain", ResultFunction = stressLogic.GetElasticStrain });
|
resultFuncs.Add(new ResultFunc() { Name = "Elastic Strain", ResultFunction = stressLogic.GetElasticStrain });
|
||||||
resultFuncs.Add(new ResultFunc() { Name = "Plastic Strain", ResultFunction = stressLogic.GetPlasticStrain });
|
resultFuncs.Add(new ResultFunc() { Name = "Plastic Strain", ResultFunction = stressLogic.GetPlasticStrain });
|
||||||
resultFuncs.Add(new ResultFunc() { Name = "Stress", ResultFunction = stressLogic.GetStress });
|
resultFuncs.Add(new ResultFunc() { Name = "Stress", ResultFunction = stressLogic.GetStress });
|
||||||
|
resultFuncs.Add(new ResultFunc() { Name = "Force", ResultFunction = stressLogic.GetForce });
|
||||||
|
resultFuncs.Add(new ResultFunc() { Name = "Moment X", ResultFunction = stressLogic.GetMomentX });
|
||||||
|
resultFuncs.Add(new ResultFunc() { Name = "Moment Y", ResultFunction = stressLogic.GetMomentY });
|
||||||
return resultFuncs;
|
return resultFuncs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user