Added reviewing of results in graphic mode
This commit is contained in:
@@ -7,6 +7,9 @@ using System.Windows.Media;
|
||||
|
||||
namespace FieldVisualizer.Entities.ColorMaps.Factories
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory for creating of different color maps
|
||||
/// </summary>
|
||||
public static class ColorMapFactory
|
||||
{
|
||||
public static IColorMap GetColorMap(ColorMapsTypes mapsTypes)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
public class CirclePrimitive : ICirclePrimitive
|
||||
{
|
||||
public double Diameter { get; set; }
|
||||
public double Value { get; set; }
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public double Area => Math.PI * Math.Pow(Diameter, 2) / 4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FieldVisualizer.Entities.Values.Primitives
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent circle primitive
|
||||
/// </summary>
|
||||
public interface ICirclePrimitive : IValuePrimitive
|
||||
{
|
||||
double Diameter { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,6 @@ namespace FieldVisualizer.Entities.Values.Primitives
|
||||
double Value { get; }
|
||||
double CenterX { get; }
|
||||
double CenterY { get; }
|
||||
double Area { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,6 @@ namespace FieldVisualizer.Entities.Values.Primitives
|
||||
public double Value { get; set; }
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public double Area => Height * Width;
|
||||
}
|
||||
}
|
||||
|
||||
27
FieldVisualizer/InfraStructures/Comands/RelayCommand.cs
Normal file
27
FieldVisualizer/InfraStructures/Comands/RelayCommand.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FieldVisualizer.Infrastructure.Commands
|
||||
{
|
||||
public class RelayCommand : ICommand
|
||||
{
|
||||
private Action<object> execute;
|
||||
private Func<object, bool> canExecute;
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add => CommandManager.RequerySuggested += value;
|
||||
remove => CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
|
||||
public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)
|
||||
{
|
||||
this.execute = execute;
|
||||
this.canExecute = canExecute;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter) => canExecute == null || canExecute(parameter);
|
||||
|
||||
public void Execute(object parameter) => execute(parameter);
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@ namespace FieldVisualizer.InfraStructures.Strings
|
||||
public static class ErrorStrings
|
||||
{
|
||||
public static string ColorMapTypeIsUnknown => "#0001: ColorMap type is unknown";
|
||||
public static string PrimitiveTypeIsUnknown => "#0002: Type of primitive is unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ namespace FieldVisualizer.Services.ColorServices
|
||||
const byte Alpha = 0xff;
|
||||
public static Color GetColorByValue(IValueRange range, IColorMap map, double val)
|
||||
{
|
||||
double minVal = range.BottomValue;
|
||||
double maxVal = range.TopValue;
|
||||
double minVal = range.BottomValue - 1e-15d*(Math.Abs(range.BottomValue));
|
||||
double maxVal = range.TopValue + 1e-15d * (Math.Abs(range.TopValue));
|
||||
if (range.TopValue == minVal || map.Colors.Count == 0) { return map.Colors[0]; }
|
||||
if (val > maxVal || val < minVal) { return Colors.Gray; }
|
||||
if (val == minVal) { return map.Colors[0]; }
|
||||
if (val == maxVal) { return map.Colors[map.Colors.Count - 1]; }
|
||||
|
||||
double valPerc = (val - minVal) / (maxVal - minVal);// value%
|
||||
double colorPerc = 1d / (map.Colors.Count - 1); // % of each block of color. the last is the "100% Color"
|
||||
//if (valPerc == 1d)
|
||||
//{ return map.Colors[map.Colors.Count - 1]; }
|
||||
double colorPerc = 1d / (map.Colors.Count - 1d); // % of each block of color. the last is the "100% Color"
|
||||
double blockOfColor = valPerc / colorPerc;// the integer part repersents how many block to skip
|
||||
int blockIdx = (int)Math.Truncate(blockOfColor);// Idx of
|
||||
double valPercResidual = valPerc - (blockIdx * colorPerc);//remove the part represented of block
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.InfraStructures.Exceptions;
|
||||
using FieldVisualizer.InfraStructures.Strings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,7 +13,7 @@ namespace FieldVisualizer.Services.PrimitiveServices
|
||||
{
|
||||
public static class PrimitiveOperations
|
||||
{
|
||||
public static IValueRange GetValuRange(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
public static IValueRange GetValueRange(IEnumerable<IValuePrimitive> valuePrimitives)
|
||||
{
|
||||
double minVal =0d, maxVal = 0d;
|
||||
foreach (var primitive in valuePrimitives)
|
||||
@@ -57,6 +59,13 @@ namespace FieldVisualizer.Services.PrimitiveServices
|
||||
coords.Add(rectanglePrimitive.CenterX + rectanglePrimitive.Width / 2);
|
||||
coords.Add(rectanglePrimitive.CenterX - rectanglePrimitive.Width / 2);
|
||||
}
|
||||
else if (primitive is ICirclePrimitive)
|
||||
{
|
||||
ICirclePrimitive circlePrimitive = primitive as ICirclePrimitive;
|
||||
coords.Add(circlePrimitive.CenterX + circlePrimitive.Diameter / 2);
|
||||
coords.Add(circlePrimitive.CenterX - circlePrimitive.Diameter / 2);
|
||||
}
|
||||
else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown);}
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
@@ -72,6 +81,13 @@ namespace FieldVisualizer.Services.PrimitiveServices
|
||||
coords.Add(rectanglePrimitive.CenterY + rectanglePrimitive.Height / 2);
|
||||
coords.Add(rectanglePrimitive.CenterY - rectanglePrimitive.Height / 2);
|
||||
}
|
||||
else if (primitive is ICirclePrimitive)
|
||||
{
|
||||
ICirclePrimitive circlePrimitive = primitive as ICirclePrimitive;
|
||||
coords.Add(circlePrimitive.CenterY + circlePrimitive.Diameter / 2);
|
||||
coords.Add(circlePrimitive.CenterY - circlePrimitive.Diameter / 2);
|
||||
}
|
||||
else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown); }
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ namespace FieldVisualizer.Services.ValueRanges
|
||||
else
|
||||
{
|
||||
double dVal = (valueRange.TopValue - valueRange.BottomValue) / divisionNumber;
|
||||
double currentBottom = valueRange.BottomValue;
|
||||
double startBottom = valueRange.BottomValue;
|
||||
for (int i = 0; i < divisionNumber; i++ )
|
||||
{
|
||||
currentBottom = i * dVal;
|
||||
|
||||
double currentBottom = startBottom + i * dVal;
|
||||
var newRange = new ValueRange() { BottomValue = currentBottom, TopValue = currentBottom + dVal };
|
||||
valueRanges.Add(newRange);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button x:Name="RebuildButton" Content="Rebuild" Click="RebuildButton_Click"/>
|
||||
<Button x:Name="ZoomInButton" Content="ZoomIn" Click="ZoomInButton_Click"/>
|
||||
<Button x:Name="ZoomOutButton" Content="ZoomOut" Click="ZoomOutButton_Click"/>
|
||||
<Button x:Name="ChangeColorMapButton" Content="ColorMap" Click="ChangeColorMapButton_Click"/>
|
||||
<Button x:Name="RebuildButton" Content="Rebuild" Command="{Binding RebuildCommand}"/>
|
||||
<Button x:Name="ZoomInButton" Content="ZoomIn" Command="{Binding ZoomInCommand}"/>
|
||||
<Button x:Name="ZoomOutButton" Content="ZoomOut" Command="{Binding ZoomOutCommand}"/>
|
||||
<Button x:Name="ChangeColorMapButton" Content="ColorMap" Command="{Binding ChangeColorMapCommand}"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer Name="WorkPlaneViewer" Grid.Row="1" HorizontalScrollBarVisibility="Visible">
|
||||
<ScrollViewer.Background>
|
||||
|
||||
@@ -2,25 +2,20 @@
|
||||
using FieldVisualizer.Entities.ColorMaps.Factories;
|
||||
using FieldVisualizer.Entities.Values;
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
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.Diagnostics;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace FieldVisualizer.Windows.UserControls
|
||||
@@ -30,7 +25,12 @@ namespace FieldVisualizer.Windows.UserControls
|
||||
/// </summary>
|
||||
public partial class FieldViewer : UserControl
|
||||
{
|
||||
public IPrimitiveSet _PrimitiveSet { get; set; }
|
||||
public ICommand RebuildCommand { get; }
|
||||
public ICommand ZoomInCommand { get; }
|
||||
public ICommand ZoomOutCommand { get; }
|
||||
public ICommand ChangeColorMapCommand { get; }
|
||||
|
||||
public IPrimitiveSet PrimitiveSet { get; set; }
|
||||
private double dX, dY;
|
||||
private ColorMapsTypes _ColorMapType;
|
||||
private IColorMap _ColorMap;
|
||||
@@ -43,34 +43,38 @@ namespace FieldVisualizer.Windows.UserControls
|
||||
{
|
||||
InitializeComponent();
|
||||
_ColorMapType = ColorMapsTypes.FullSpectrum;
|
||||
DataContext = this;
|
||||
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());
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
_ValueRange = PrimitiveOperations.GetValuRange(_PrimitiveSet.ValuePrimitives);
|
||||
if (PrimitiveValidation() == false) { return; }
|
||||
_ValueRange = PrimitiveOperations.GetValueRange(PrimitiveSet.ValuePrimitives);
|
||||
_ValueRanges = ValueRangeOperations.DivideValueRange(_ValueRange, RangeNumber);
|
||||
_ColorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
||||
_ValueColorRanges = ColorOperations.GetValueColorRanges(_ValueRange, _ValueRanges, _ColorMap);
|
||||
if ((_PrimitiveSet is null) == false)
|
||||
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];
|
||||
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)
|
||||
foreach (var primitive in PrimitiveSet.ValuePrimitives)
|
||||
{
|
||||
if (primitive is IRectanglePrimitive)
|
||||
{
|
||||
@@ -78,58 +82,77 @@ namespace FieldVisualizer.Windows.UserControls
|
||||
Rectangle rectangle = ProcessRectanglePrimitive(rectanglePrimitive);
|
||||
WorkPlaneCanvas.Children.Add(rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WorkPlaneBox_MouseWheel(object sender, MouseWheelEventArgs e)
|
||||
else if (primitive is ICirclePrimitive)
|
||||
{
|
||||
WorkPlaneBox.Height *= WorkPlaneBox.ActualHeight * 0.5;
|
||||
WorkPlaneBox.Width *= WorkPlaneBox.ActualWidth * 0.5;
|
||||
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();
|
||||
rectangle.Height = rectanglePrimitive.Height;
|
||||
rectangle.Width = rectanglePrimitive.Width;
|
||||
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, rectanglePrimitive.Value);
|
||||
brush.Color = ColorOperations.GetColorByValue(_ValueRange, _ColorMap, valuePrimitive.Value);
|
||||
foreach (var valueRange in _ValueColorRanges)
|
||||
{
|
||||
if (rectanglePrimitive.Value >= valueRange.BottomValue & rectanglePrimitive.Value <= valueRange.TopValue & (! valueRange.IsActive))
|
||||
if (valuePrimitive.Value >= valueRange.BottomValue & valuePrimitive.Value <= valueRange.TopValue & (!valueRange.IsActive))
|
||||
{
|
||||
brush.Color = Colors.Gray;
|
||||
}
|
||||
}
|
||||
rectangle.ToolTip = rectanglePrimitive.Value;
|
||||
rectangle.Fill = brush;
|
||||
Canvas.SetLeft(rectangle, rectanglePrimitive.CenterX - dX);
|
||||
Canvas.SetTop(rectangle, rectanglePrimitive.CenterY - dY);
|
||||
return rectangle;
|
||||
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 RebuildButton_Click(object sender, RoutedEventArgs e)
|
||||
private void Zoom(double coefficient)
|
||||
{
|
||||
ProcessPrimitives();
|
||||
WorkPlaneBox.Width *= coefficient;
|
||||
WorkPlaneBox.Height *= coefficient;
|
||||
}
|
||||
|
||||
private void ZoomInButton_Click(object sender, RoutedEventArgs e)
|
||||
private void ChangeColorMap()
|
||||
{
|
||||
WorkPlaneBox.Width *= 1.2;
|
||||
WorkPlaneBox.Height *= 1.2;
|
||||
//Iterate all available color maps one by one
|
||||
try
|
||||
{
|
||||
_ColorMapType++;
|
||||
IColorMap colorMap = ColorMapFactory.GetColorMap(_ColorMapType);
|
||||
}
|
||||
|
||||
private void ChangeColorMapButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_ColorMapType < ColorMapsTypes.BlueToWhite) { _ColorMapType++;}
|
||||
else { _ColorMapType = 0;}
|
||||
catch (Exception ex) { _ColorMapType = 0; }
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void ZoomOutButton_Click(object sender, RoutedEventArgs e)
|
||||
private bool PrimitiveValidation()
|
||||
{
|
||||
WorkPlaneBox.Width *= 0.8;
|
||||
WorkPlaneBox.Height *= 0.8;
|
||||
if (PrimitiveSet == null || PrimitiveSet.ValuePrimitives.Count() == 0) { return false; }
|
||||
else return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid x:Name="grid">
|
||||
<StackPanel>
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF868686"></TextBlock>
|
||||
<ListBox Name="LegendBox" ItemsSource="{Binding}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
@@ -32,6 +33,7 @@
|
||||
</LinearGradientBrush>
|
||||
</Rectangle.Fill>
|
||||
</Rectangle>
|
||||
<TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="#FF868686" Text="{Binding AverageValue}"/>
|
||||
<Rectangle Grid.Column="3" Margin="0,2,0,2" ToolTip="{Binding Path=TopValue}">
|
||||
<Rectangle.Fill>
|
||||
<SolidColorBrush Color="{Binding Path=TopColor}"/>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using FieldVisualizer.Windows.UserControls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -21,20 +22,27 @@ namespace FieldVisualizer.Windows
|
||||
/// </summary>
|
||||
public partial class WndFieldViewer : Window
|
||||
{
|
||||
public ObservableCollection<IPrimitiveSet> PrimitiveSets { get; private set; }
|
||||
public WndFieldViewer(IEnumerable<IPrimitiveSet> primitiveSets)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = primitiveSets;
|
||||
PrimitiveSets = new ObservableCollection<IPrimitiveSet>();
|
||||
foreach (var primitiveSet in primitiveSets)
|
||||
{
|
||||
FieldViewerControl._PrimitiveSet = primitiveSet;
|
||||
PrimitiveSets.Add(primitiveSet);
|
||||
}
|
||||
this.DataContext = PrimitiveSets;
|
||||
|
||||
}
|
||||
|
||||
private void SetsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
ListBox lb = sender as ListBox;
|
||||
if (lb.SelectedItem != null)
|
||||
{
|
||||
FieldViewerControl.PrimitiveSet = lb.SelectedItem as IPrimitiveSet;
|
||||
FieldViewerControl.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,18 +26,33 @@ namespace FiledVisualzerDemo
|
||||
int jmax = 100;
|
||||
PrimitiveSet primitiveSet = new PrimitiveSet();
|
||||
primitiveSets.Add(primitiveSet);
|
||||
primitiveSets.Add(primitiveSet);
|
||||
List<IValuePrimitive> primitives = new List<IValuePrimitive>();
|
||||
primitiveSet.ValuePrimitives = primitives;
|
||||
IValuePrimitive primitive;
|
||||
for (int i = 0; i < imax; i++)
|
||||
{
|
||||
for (int j = 0; j < jmax; j++)
|
||||
{
|
||||
IValuePrimitive primitive = new RectanglePrimitive() { Height = 10, Width = 20, CenterX = - 20 * i, CenterY = - 10 * j, Value = i + j };
|
||||
primitive = new RectanglePrimitive() { Height = 10, Width = 20, CenterX = 20 * i, CenterY = 10 * j, Value = -(i + j) };
|
||||
primitives.Add(primitive);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
primitive = new CirclePrimitive() { Diameter = 150, CenterX = -200 * i, CenterY = -100 * j, Value = i * 100 + j * 200 };
|
||||
primitives.Add(primitive);
|
||||
}
|
||||
}
|
||||
primitiveSet = new PrimitiveSet();
|
||||
primitives = new List<IValuePrimitive>();
|
||||
primitive = new RectanglePrimitive() { Height = 100, Width = 200, CenterX = 0, CenterY = 0, Value = 100 };
|
||||
primitives.Add(primitive);
|
||||
primitive = new CirclePrimitive() { Diameter = 50, CenterX = 0, CenterY = 0, Value = -100 };
|
||||
primitives.Add(primitive);
|
||||
primitiveSet.ValuePrimitives = primitives;
|
||||
primitiveSets.Add(primitiveSet);
|
||||
FieldViewerOperation.ShowViewer(primitiveSets);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace StructureHelper.Infrastructure.UI.DataContexts
|
||||
ICenter center = new Center { X = centerX, Y = centerY };
|
||||
IShape shape = new StructureHelperCommon.Models.Shapes.Rectangle { Height = height, Width = width, Angle = 0 };
|
||||
IPrimitiveMaterial primitiveMaterial = new PrimitiveMaterial { MaterialType = GetMaterialTypes(), ClassName = materialName, Strength = Material.DesignCompressiveStrength };
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 1, NdmMinDivision = 20 };
|
||||
INdmPrimitive ndmPrimitive = new NdmPrimitive { Center = center, Shape = shape, PrimitiveMaterial = primitiveMaterial, NdmMaxSize = 0.01, NdmMinDivision = 20 };
|
||||
return ndmPrimitive;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
16
Services/ResultViewers/IResultFunc.cs
Normal file
16
Services/ResultViewers/IResultFunc.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Services.ResultViewers
|
||||
{
|
||||
public interface IResultFunc
|
||||
{
|
||||
string Name { get; }
|
||||
Func<IStrainMatrix, INdm, double> ResultFunction { get; }
|
||||
}
|
||||
}
|
||||
16
Services/ResultViewers/ResultFunc.cs
Normal file
16
Services/ResultViewers/ResultFunc.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Services.ResultViewers
|
||||
{
|
||||
public class ResultFunc : IResultFunc
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Func<IStrainMatrix, INdm, double> ResultFunction { get; set; }
|
||||
}
|
||||
}
|
||||
23
Services/ResultViewers/ResultFuncFactory.cs
Normal file
23
Services/ResultViewers/ResultFuncFactory.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using LoaderCalculator.Logics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Services.ResultViewers
|
||||
{
|
||||
public static class ResultFuncFactory
|
||||
{
|
||||
public static IEnumerable<IResultFunc> GetResultFuncs()
|
||||
{
|
||||
List<IResultFunc> resultFuncs = new List<IResultFunc>();
|
||||
IStressLogic stressLogic = new StressLogic();
|
||||
resultFuncs.Add(new ResultFunc() { Name = "Total Strain", ResultFunction = stressLogic.GetTotalStrain });
|
||||
resultFuncs.Add(new ResultFunc() { Name = "Elastic Srtain", ResultFunction = stressLogic.GetElasticStrain });
|
||||
resultFuncs.Add(new ResultFunc() { Name = "Plastic Strain", ResultFunction = stressLogic.GetPlasticStrain });
|
||||
resultFuncs.Add(new ResultFunc() { Name = "Stress", ResultFunction = stressLogic.GetStress });
|
||||
return resultFuncs;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Services/ResultViewers/ShowIsoFieldResult.cs
Normal file
46
Services/ResultViewers/ShowIsoFieldResult.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using FieldVisualizer.Entities.Values.Primitives;
|
||||
using FieldVisualizer.WindowsOperation;
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using LoaderCalculator.Logics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelper.Services.ResultViewers
|
||||
{
|
||||
public static class ShowIsoFieldResult
|
||||
{
|
||||
public static void ShowResult(IStrainMatrix strainMatrix, IEnumerable<INdm> ndms, IEnumerable<IResultFunc> resultFuncs)
|
||||
{
|
||||
List<IPrimitiveSet> primitiveSets = new List<IPrimitiveSet>();
|
||||
foreach (var valDelegate in resultFuncs)
|
||||
{
|
||||
PrimitiveSet primitiveSet = new PrimitiveSet() { Name = valDelegate.Name };
|
||||
List<IValuePrimitive> primitives = new List<IValuePrimitive>();
|
||||
foreach (INdm ndm in ndms)
|
||||
{
|
||||
double val = valDelegate.ResultFunction.Invoke(strainMatrix, ndm);
|
||||
IValuePrimitive valuePrimitive;
|
||||
if (ndm is IRectangleNdm)
|
||||
{
|
||||
var shapeNdm = ndm as IRectangleNdm;
|
||||
valuePrimitive = new RectanglePrimitive() { CenterX = ndm.CenterX, CenterY = ndm.CenterY, Height = shapeNdm.Height, Width = shapeNdm.Width, Value = val };
|
||||
}
|
||||
else
|
||||
{
|
||||
valuePrimitive = new CirclePrimitive() { CenterX = ndm.CenterX, CenterY = ndm.CenterY, Diameter = Math.Sqrt(ndm.Area / Math.PI) * 2, Value = val };
|
||||
}
|
||||
primitives.Add(valuePrimitive);
|
||||
}
|
||||
primitiveSet.ValuePrimitives = primitives;
|
||||
primitiveSets.Add(primitiveSet);
|
||||
}
|
||||
|
||||
FieldViewerOperation.ShowViewer(primitiveSets);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,10 @@
|
||||
<DependentUpon>PrimitivePopup.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Services\PrimitiveService.cs" />
|
||||
<Compile Include="Services\ResultViewers\IResultFunc.cs" />
|
||||
<Compile Include="Services\ResultViewers\ResultFunc.cs" />
|
||||
<Compile Include="Services\ResultViewers\ResultFuncFactory.cs" />
|
||||
<Compile Include="Services\ResultViewers\ShowIsoFieldResult.cs" />
|
||||
<Compile Include="UnitSystem\UnitSystemService.cs" />
|
||||
<Compile Include="UnitSystem\Enums\SystemTypes.cs" />
|
||||
<Compile Include="UnitSystem\Systems\SystemSi.cs" />
|
||||
@@ -193,6 +197,10 @@
|
||||
<Folder Include="Logics\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="FieldVisualizer\FieldVisualizer.csproj">
|
||||
<Project>{87064B50-3B7C-4A91-AF4A-941C6F95D997}</Project>
|
||||
<Name>FieldVisualizer</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="StructureHelperCommon\StructureHelperCommon.csproj">
|
||||
<Project>{5dfec3fd-9677-47bb-9e88-eb71828b5913}</Project>
|
||||
<Name>StructureHelperCommon</Name>
|
||||
|
||||
@@ -20,15 +20,18 @@ namespace StructureHelperTests.FieldsVisualizerTests.ColorOperationTests
|
||||
valueRange = new ValueRange() { BottomValue = 0, TopValue = 100 };
|
||||
}
|
||||
|
||||
[TestCase(-10, 255, 128, 128, 128)] //Gray as less than minimum
|
||||
[TestCase(0, 255, 255, 128, 128)]
|
||||
[TestCase(50, 255, 255, 255, 0)]
|
||||
[TestCase(100, 255, 0, 0, 255)]//Blue
|
||||
[TestCase(110, 255,128, 128, 128)] //Gray as greater than maximum
|
||||
public void Run_ShouldPass(double val, int expectedA, int expectedR, int expectedG, int expectedB)
|
||||
[TestCase(0, 100, -10, 255, 128, 128, 128)] //Gray as less than minimum
|
||||
[TestCase(0, 100, 0, 255, 255, 128, 128)]
|
||||
[TestCase(0, 100, 50, 255, 255, 255, 0)]
|
||||
[TestCase(0, 100, 100, 255, 0, 0, 255)]//Blue
|
||||
[TestCase(0, 100, 110, 255,128, 128, 128)] //Gray as greater than maximum
|
||||
[TestCase(-100, 100, 110, 255, 128, 128, 128)] //Gray as greater than maximum
|
||||
[TestCase(-100, 100, 100, 255, 0, 0, 255)]//Blue
|
||||
[TestCase(100, 100, -100, 255, 255, 128, 128)]
|
||||
public void Run_ShouldPass(double bottomVal, double topVal, double val, int expectedA, int expectedR, int expectedG, int expectedB)
|
||||
{
|
||||
//Arrange
|
||||
|
||||
valueRange = new ValueRange() { BottomValue = bottomVal, TopValue = topVal };
|
||||
//Act
|
||||
var result = ColorOperations.GetColorByValue(valueRange, FullSpectrum, val);
|
||||
var actualA = result.A;
|
||||
|
||||
@@ -94,6 +94,9 @@
|
||||
<Name>StructureHelperLogics</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="FieldsVisualizerTests\WindowTests\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator;
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using LoaderCalculator.Data.ResultData;
|
||||
using LoaderCalculator.Data.SourceData;
|
||||
using StructureHelper.Services;
|
||||
using StructureHelper.UnitSystem;
|
||||
using StructureHelper.UnitSystem.Systems;
|
||||
using StructureHelperLogics.Infrastructures.CommonEnums;
|
||||
using StructureHelperLogics.NdmCalculations.Triangulations;
|
||||
using StructureHelperLogics.Services;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
@@ -26,5 +36,39 @@ namespace StructureHelper.Windows.MainWindow
|
||||
.Select(x => x.GetNdmPrimitive(unitSystem))
|
||||
.Concat(primitiveRepository.GetPoints().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray(), mx, my, nz);
|
||||
}
|
||||
|
||||
public IEnumerable<INdm> GetNdms()
|
||||
{
|
||||
var unitSystem = unitSystemService.GetCurrentSystem();
|
||||
var ndmPrimitives = primitiveRepository.GetRectangles()
|
||||
.Select(x => x.GetNdmPrimitive(unitSystem))
|
||||
.Concat(primitiveRepository.GetPoints().Select(x => x.GetNdmPrimitive(unitSystem))).ToArray();
|
||||
|
||||
//Настройки триангуляции, пока опции могут быть только такие
|
||||
ITriangulationOptions options = new TriangulationOptions { LimiteState = LimitStates.Collapse, CalcTerm = CalcTerms.ShortTerm };
|
||||
|
||||
//Формируем коллекцию элементарных участков для расчета в библитеке (т.е. выполняем триангуляцию)
|
||||
List<INdm> ndmCollection = new List<INdm>();
|
||||
ndmCollection.AddRange(Triangulation.GetNdms(ndmPrimitives, options));
|
||||
|
||||
return ndmCollection;
|
||||
}
|
||||
|
||||
public ILoaderResults CalculateResult(IEnumerable<INdm> ndmCollection, IForceMatrix forceMatrix)
|
||||
{
|
||||
var loaderData = new LoaderOptions
|
||||
{
|
||||
Preconditions = new Preconditions
|
||||
{
|
||||
ConditionRate = 0.01,
|
||||
MaxIterationCount = 100,
|
||||
StartForceMatrix = forceMatrix
|
||||
},
|
||||
NdmCollection = ndmCollection
|
||||
};
|
||||
var calculator = new Calculator();
|
||||
calculator.Run(loaderData, new CancellationToken());
|
||||
return calculator.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ using StructureHelper.Services;
|
||||
using StructureHelper.Windows.ColorPickerWindow;
|
||||
using StructureHelper.UnitSystem;
|
||||
using StructureHelper.Models.Materials;
|
||||
using LoaderCalculator.Data.Matrix;
|
||||
using LoaderCalculator.Data.Ndms;
|
||||
using StructureHelper.Services.ResultViewers;
|
||||
|
||||
namespace StructureHelper.Windows.MainWindow
|
||||
{
|
||||
@@ -232,12 +235,13 @@ namespace StructureHelper.Windows.MainWindow
|
||||
|
||||
Calculate = new RelayCommand(o =>
|
||||
{
|
||||
var matrix = model.Calculate(10e3, 0d, 0d);
|
||||
MessageBox.Show(
|
||||
$"{nameof(matrix.EpsZ)} = {matrix.EpsZ};\n" +
|
||||
$"{nameof(matrix.Kx)} = {matrix.Kx};\n" +
|
||||
$"{nameof(matrix.Ky)} = {matrix.Ky}",
|
||||
"StructureHelper");
|
||||
//var matrix = model.Calculate(10e3, 0d, 0d);
|
||||
//MessageBox.Show(
|
||||
// $"{nameof(matrix.EpsZ)} = {matrix.EpsZ};\n" +
|
||||
// $"{nameof(matrix.Kx)} = {matrix.Kx};\n" +
|
||||
// $"{nameof(matrix.Ky)} = {matrix.Ky}",
|
||||
// "StructureHelper");
|
||||
CalculateResult();
|
||||
});
|
||||
|
||||
SetPopupCanBeClosedTrue = new RelayCommand(o =>
|
||||
@@ -253,6 +257,14 @@ namespace StructureHelper.Windows.MainWindow
|
||||
});
|
||||
}
|
||||
|
||||
private void CalculateResult()
|
||||
{
|
||||
IForceMatrix forceMatrix = new ForceMatrix() { Mx = 10e3, My = 10e3, Nz = 0 };
|
||||
IEnumerable<INdm> ndms = Model.GetNdms();
|
||||
var loaderResult = Model.CalculateResult(ndms, forceMatrix);
|
||||
ShowIsoFieldResult.ShowResult(loaderResult.StrainMatrix, ndms, ResultFuncFactory.GetResultFuncs());
|
||||
}
|
||||
|
||||
private IEnumerable<PrimitiveBase> GetTestCasePrimitives()
|
||||
{
|
||||
var width = 400;
|
||||
|
||||
Reference in New Issue
Block a user