Partially fix work with user color

This commit is contained in:
Evgeny Redikultsev
2022-09-13 22:23:27 +05:00
parent 7a4fd63fc2
commit 6c6327c554
4 changed files with 65 additions and 9 deletions

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FieldVisualizer.ViewModels.FieldViewerViewModels
{
public class FieldViewerViewModel : ViewModelBase
{
}
}

View File

@@ -0,0 +1,24 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace FieldVisualizer.ViewModels
{
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged<T>(T value, T prop, [CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanged<T>(T value, ref T prop, [CallerMemberName] string propertyName = null)
{
prop = value;
OnPropertyChanged(propertyName);
}
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

View File

@@ -36,10 +36,11 @@
</ScrollViewer> </ScrollViewer>
</Grid> </Grid>
<StackPanel Grid.Column="2"> <StackPanel Grid.Column="2">
<CheckBox x:Name="cbMinValueEnabled" Margin="3" Content="Minimum Value"/> <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=UserValueRange.BottomValue}"/>
<CheckBox x:Name="cbMaxValueEnabled" Margin="3" Content="Maximum Value"/> <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=UserValueRange.TopValue}"/>
<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>
</Grid> </Grid>

View File

@@ -29,9 +29,12 @@ namespace FieldVisualizer.Windows.UserControls
public ICommand ZoomInCommand { get; } public ICommand ZoomInCommand { get; }
public ICommand ZoomOutCommand { get; } public ICommand ZoomOutCommand { get; }
public ICommand ChangeColorMapCommand { get; } public ICommand ChangeColorMapCommand { get; }
public ICommand SetUserColorsCommand { get; }
public IPrimitiveSet PrimitiveSet { get; set; } public IPrimitiveSet PrimitiveSet { get; set; }
public IValueRange UserValueRange { get; set; } public IValueRange UserValueRange { get; set; }
public bool SetMinValue { get; set; }
public bool SetMaxValue { get; set; }
private double dX, dY; private double dX, dY;
private ColorMapsTypes _ColorMapType; private ColorMapsTypes _ColorMapType;
@@ -50,9 +53,12 @@ namespace FieldVisualizer.Windows.UserControls
ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation()); ZoomInCommand = new RelayCommand(o => Zoom(1.2), o => PrimitiveValidation());
ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation()); ZoomOutCommand = new RelayCommand(o => Zoom(0.8), o => PrimitiveValidation());
ChangeColorMapCommand = new RelayCommand(o => ChangeColorMap(), o => PrimitiveValidation()); ChangeColorMapCommand = new RelayCommand(o => ChangeColorMap(), o => PrimitiveValidation());
SetUserColorsCommand = new RelayCommand(o => ColorRefresh(), o => (SetMinValue || SetMaxValue));
UserValueRange = new ValueRange() { BottomValue = 0, TopValue = 0 }; UserValueRange = new ValueRange() { BottomValue = 0, TopValue = 0 };
SetMinValue = false;
SetMaxValue = false;
} }
public void Refresh() public void ColorRefresh()
{ {
if (PrimitiveValidation() == false) { return; } if (PrimitiveValidation() == false) { return; }
_ColorMap = ColorMapFactory.GetColorMap(_ColorMapType); _ColorMap = ColorMapFactory.GetColorMap(_ColorMapType);
@@ -66,7 +72,6 @@ namespace FieldVisualizer.Windows.UserControls
} }
private void ProcessPrimitives() private void ProcessPrimitives()
{ {
WorkPlaneCanvas.Children.Clear(); WorkPlaneCanvas.Children.Clear();
double sizeX = PrimitiveOperations.GetSizeX(PrimitiveSet.ValuePrimitives); double sizeX = PrimitiveOperations.GetSizeX(PrimitiveSet.ValuePrimitives);
double sizeY = PrimitiveOperations.GetSizeY(PrimitiveSet.ValuePrimitives); double sizeY = PrimitiveOperations.GetSizeY(PrimitiveSet.ValuePrimitives);
@@ -90,7 +95,7 @@ namespace FieldVisualizer.Windows.UserControls
Ellipse ellipse = ProcessCirclePrimitive(circlePrimitive); Ellipse ellipse = ProcessCirclePrimitive(circlePrimitive);
WorkPlaneCanvas.Children.Add(ellipse); WorkPlaneCanvas.Children.Add(ellipse);
} }
else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown);} else { throw new FieldVisulizerException(ErrorStrings.PrimitiveTypeIsUnknown); }
} }
} }
private Rectangle ProcessRectanglePrimitive(IRectanglePrimitive rectanglePrimitive) private Rectangle ProcessRectanglePrimitive(IRectanglePrimitive rectanglePrimitive)
@@ -133,7 +138,7 @@ namespace FieldVisualizer.Windows.UserControls
shape.Tag = valuePrimitive; shape.Tag = valuePrimitive;
shape.Fill = brush; shape.Fill = brush;
Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX); Canvas.SetLeft(shape, valuePrimitive.CenterX - addX - dX);
Canvas.SetTop(shape, - valuePrimitive.CenterY - addY - dY); Canvas.SetTop(shape, -valuePrimitive.CenterY - addY - dY);
} }
private void Zoom(double coefficient) private void Zoom(double coefficient)
{ {
@@ -149,7 +154,7 @@ namespace FieldVisualizer.Windows.UserControls
IColorMap colorMap = ColorMapFactory.GetColorMap(_ColorMapType); IColorMap colorMap = ColorMapFactory.GetColorMap(_ColorMapType);
} }
catch (Exception ex) { _ColorMapType = 0; } catch (Exception ex) { _ColorMapType = 0; }
Refresh(); ColorRefresh();
} }
private bool PrimitiveValidation() private bool PrimitiveValidation()
{ {
@@ -159,10 +164,24 @@ namespace FieldVisualizer.Windows.UserControls
private void SetColor() private void SetColor()
{ {
valueRange = PrimitiveOperations.GetValueRange(PrimitiveSet.ValuePrimitives); valueRange = PrimitiveOperations.GetValueRange(PrimitiveSet.ValuePrimitives);
if (cbMinValueEnabled.IsChecked == true) { valueRange.BottomValue = UserValueRange.BottomValue; } else { UserValueRange.BottomValue = valueRange.BottomValue; } //if bottom value is greater than top value
if (cbMaxValueEnabled.IsChecked == true) { valueRange.TopValue = UserValueRange.TopValue; } else { UserValueRange.TopValue = valueRange.TopValue; } 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); _ValueRanges = ValueRangeOperations.DivideValueRange(valueRange, RangeNumber);
_ValueColorRanges = ColorOperations.GetValueColorRanges(valueRange, _ValueRanges, _ColorMap); _ValueColorRanges = ColorOperations.GetValueColorRanges(valueRange, _ValueRanges, _ColorMap);
} }
public void Refresh()
{
SetMinValue = false;
SetMaxValue = false;
ColorRefresh();
}
} }
} }