Skip to content

Commit b894ed6

Browse files
committed
Night Mode and Updated Events
1 parent 93d9481 commit b894ed6

11 files changed

+276
-144
lines changed

AttitudeIndicator/AttitudeIndicator.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Compile Include="UDPSettingsControl.xaml.cs">
7979
<DependentUpon>UDPSettingsControl.xaml</DependentUpon>
8080
</Compile>
81+
<Compile Include="ValueConverter.cs" />
8182
<Compile Include="ViewModels\ApplicationViewModel.cs" />
8283
<Compile Include="ViewModels\BaseViewModel.cs" />
8384
<Compile Include="ViewModels\RelayCommand.cs" />

AttitudeIndicator/GimbalVisual3D.cs

+28-29
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public GimbalVisual3D()
2222
{
2323
var group = new Model3DGroup();
2424
group.Children.Add(PsiRing.Model);
25-
//BetaRing.Model.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90));
2625
group.Children.Add(ThetaRing.Model);
2726
group.Children.Add(PhiRing.Model);
2827
this.Visual3DModel = group;
28+
OrientationChanged();
2929
}
3030

3131

@@ -42,6 +42,11 @@ public double Diameter
4242
set { SetValue(DiameterProperty, value); }
4343
}
4444

45+
/// <summary>
46+
/// If the size of the Gimbal is changed, the rings must be resized as well
47+
/// </summary>
48+
/// <param name="d"></param>
49+
/// <param name="e"></param>
4550
private static void DiameterChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
4651
{
4752
var gimb = d as GimbalVisual3D;
@@ -52,63 +57,57 @@ private static void DiameterChanged(DependencyObject d, DependencyPropertyChange
5257
gimb.ThetaRing.RingDiameter = dia * 0.9;
5358
gimb.PhiRing.RingDiameter = dia * 0.8;
5459
}
60+
5561

56-
57-
58-
59-
//private Transform3DGroup PhiRingTransform => { var ret = new Transform3DGroup(); return ret; }
60-
61-
62-
63-
62+
/// <summary>
63+
/// Transform individual rings accordingly
64+
/// </summary>
6465
private void OrientationChanged()
6566
{
6667

67-
var rotation = TransformationHelper.GetEulerangle(Orientation);
68+
var rotation = TransformationHelper.QuaternionToEuler(Orientation);
6869

6970

7071
rotation *= 180 / Math.PI; // RAD to Degree converstion
7172

72-
73-
74-
73+
var q = new Quaternion(new Vector3D(0, 0, -1), rotation.Z);
7574
var tgPsiRing = new Transform3DGroup();
76-
tgPsiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), rotation.X)));
77-
75+
tgPsiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(q.Axis, q.Angle)));
7876
this.PsiRing.Model.Transform = tgPsiRing;
77+
78+
79+
7980

8081
var tgthetaRing = new Transform3DGroup();
82+
q *= new Quaternion(new Vector3D(0, -1, 0), rotation.Y);
8183
tgthetaRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 90)));
82-
tgthetaRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), rotation.X)));
83-
tgthetaRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), rotation.Y)));
84+
tgthetaRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(q.Axis, q.Angle)));
85+
8486

8587
this.ThetaRing.Model.Transform = tgthetaRing;
86-
88+
q *= new Quaternion(new Vector3D(1, 0, 0), rotation.X);
8789
var tgPhiRing = new Transform3DGroup();
8890
tgPhiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));
89-
tgPhiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), rotation.X)));
90-
tgPhiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), rotation.Y)));
91-
tgPhiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), rotation.Z)));
92-
91+
tgPhiRing.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(q.Axis, q.Angle)));
9392
this.PhiRing.Model.Transform = tgPhiRing;
9493

9594
}
9695

9796

9897
public static readonly DependencyProperty OrientationProperty =
99-
DependencyProperty.Register(nameof(Orientation), typeof(Matrix3D), typeof(GimbalVisual3D),
100-
new UIPropertyMetadata(new Matrix3D(), (s, d) => (s as GimbalVisual3D).OrientationChanged()));
98+
DependencyProperty.Register(nameof(Orientation), typeof(Quaternion), typeof(GimbalVisual3D),
99+
new UIPropertyMetadata(new Quaternion(), (s, d) => (s as GimbalVisual3D).OrientationChanged()));
101100

102101

103-
public Matrix3D Orientation
102+
/// <summary>
103+
/// Property for the current flight orientation
104+
/// </summary>
105+
public Quaternion Orientation
104106
{
105-
get => (Matrix3D)GetValue(OrientationProperty);
107+
get => (Quaternion)GetValue(OrientationProperty);
106108
set { SetValue(OrientationProperty, value); }
107109
}
108110

109-
110-
111-
112111

113112

114113
#endregion

AttitudeIndicator/MainWindow.xaml

+29-11
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
mc:Ignorable="d"
99
xmlns:fa="http://schemas.fontawesome.io/icons/"
1010
Title="Attitude Indicator - MecatronicsLab 2019 - TU Graz" Height="550" Width="800" MinHeight="300" MinWidth="500">
11-
<Grid>
11+
<Window.Resources>
12+
<local:BooleanToVisibilityConverter x:Key="BoolToVisibility" />
13+
</Window.Resources>
14+
<Grid>
1215
<Grid.ColumnDefinitions>
1316
<ColumnDefinition Width="*"/>
1417
<ColumnDefinition Width="200"/>
1518
</Grid.ColumnDefinitions>
1619

17-
<h:HelixViewport3D Grid.ColumnSpan="2" ModelUpDirection="0 0 1" ViewCubeHorizontalPosition="Left" >
20+
<h:HelixViewport3D Grid.ColumnSpan="2" ModelUpDirection="0 0 1" ViewCubeHorizontalPosition="Left" ViewCubeVerticalPosition="Top" Background="{DynamicResource ThemeBackGround}">
1821
<h:HelixViewport3D.DefaultCamera>
1922
<PerspectiveCamera Position="-14,10,10" LookDirection="14,-10,-10" UpDirection="0,0,1" />
2023
</h:HelixViewport3D.DefaultCamera>
@@ -66,7 +69,7 @@
6669

6770

6871

69-
<local:GimbalVisual3D Diameter="4" Visibility="Visible" Orientation="{Binding AirPlaneMatrixTransform}" />
72+
<local:GimbalVisual3D Diameter="4" Orientation="{Binding Rotation}" Visibility="{Binding ElementName=GimbalVisibilityButton, Path=IsChecked, Converter={StaticResource BoolToVisibility}}"/>
7073

7174

7275
<h:GridLinesVisual3D Width="10" Length="10" MinorDistance="1" MajorDistance="1" Thickness="0.01"/>
@@ -81,14 +84,29 @@
8184

8285

8386
<!-- MENU Bar on the right screen side-->
84-
<StackPanel Grid.Column="1" >
85-
86-
<TextBlock Margin="0 10 0 0" FontSize="14" >Euler Angles</TextBlock>
87-
<local:EulerAnglesDisplay/>
88-
<TextBlock Margin="0 10 0 0" FontSize="14" >Unit Quaternion</TextBlock>
89-
<local:QuaternionDisplay DataContext="{Binding Rotation}"/>
87+
<StackPanel Grid.Column="1">
88+
<DockPanel LastChildFill="False">
89+
<ToggleButton x:Name="GimbalVisibilityButton" DockPanel.Dock="Right" Margin="2">
90+
<ToggleButton.ToolTip>
91+
<TextBlock>Show Gimbal Rings</TextBlock>
92+
</ToggleButton.ToolTip>
93+
<fa:ImageAwesome Icon="Compass" Height="20"/>
94+
</ToggleButton>
95+
<ToggleButton x:Name="DarkModeButton" DockPanel.Dock="Right" Margin="2" Click="DarkModeButton_Click">
96+
<ToggleButton.ToolTip>
97+
<TextBlock>NightMode</TextBlock>
98+
</ToggleButton.ToolTip>
99+
<fa:ImageAwesome Icon="MoonOutline" Height="20"/>
100+
</ToggleButton>
101+
</DockPanel>
102+
103+
104+
<TextBlock Margin="0 10 0 0" FontSize="14" Foreground="{DynamicResource ThemeForeground}">Euler Angles</TextBlock>
105+
<local:EulerAnglesDisplay Foreground="{DynamicResource ThemeForeground}"/>
106+
<TextBlock Margin="0 10 0 0" FontSize="14" Foreground="{DynamicResource ThemeForeground}">Unit Quaternion</TextBlock>
107+
<local:QuaternionDisplay DataContext="{Binding Rotation}" Foreground="{DynamicResource ThemeForeground}"/>
90108
<!--Expander for the data link controls-->
91-
<Expander Header="Data Link">
109+
<Expander Header="Data Link" Foreground="{DynamicResource ThemeForeground}">
92110
<StackPanel>
93111
<Border Style="{StaticResource LightBorder}" Margin="5">
94112
<StackPanel>
@@ -106,7 +124,7 @@
106124
</Expander>
107125

108126
<!--Expander for the manual Controls By sliders-->
109-
<Expander Header="ManualInput">
127+
<Expander Header="Manual Input" Foreground="{DynamicResource ThemeForeground}">
110128
<Border Style="{StaticResource LightBorder}">
111129
<StackPanel>
112130
<Slider Name = "slider"

AttitudeIndicator/MainWindow.xaml.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.ComponentModel;
1717
using HelixToolkit.Wpf;
1818
using AttitudeIndicator.ViewModels;
19+
using System.Windows.Controls.Primitives;
1920

2021
namespace AttitudeIndicator
2122
{
@@ -29,14 +30,27 @@ public MainWindow()
2930
InitializeComponent();
3031
// Do Init here // Just because I m lazy
3132
DataContext = new ApplicationViewModel();
32-
3333

3434

35+
3536
}
3637

37-
38+
private void DarkModeButton_Click(object sender, RoutedEventArgs e)
39+
{
40+
var toggle = sender as ToggleButton;
3841

42+
if(toggle.IsChecked == true)
43+
{
44+
this.Resources["ThemeBackGround"] = new SolidColorBrush(Colors.Black);
45+
this.Resources["ThemeForeground"] = new SolidColorBrush(Colors.White);
46+
}
47+
else
48+
{
49+
this.Resources["ThemeBackGround"] = new SolidColorBrush(Colors.White);
50+
this.Resources["ThemeForeground"] = new SolidColorBrush(Colors.Black);
51+
}
3952

4053

54+
}
4155
}
4256
}

AttitudeIndicator/Styles.xaml

+15-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:local="clr-namespace:AttitudeIndicator">
44

5-
5+
6+
7+
<Color x:Key="WindowColor">#FFE8EDF9</Color>
8+
<Color x:Key="ContentAreaColorLight">#FFC5CBF9</Color>
9+
<Color x:Key="ContentAreaColorDark">#FF7381F9</Color>
610

11+
<SolidColorBrush x:Key="ThemeForeground" Color="Black"/>
12+
<SolidColorBrush x:Key="ThemeBackGround" Color="White"/>
13+
14+
715
<Style TargetType="{x:Type Button}" x:Key="Hoverless">
816
<Setter Property="Background" Value="Transparent" />
917
<Setter Property="BorderThickness" Value="0" />
@@ -150,6 +158,7 @@
150158
<Setter Property="Template">
151159
<Setter.Value>
152160
<ControlTemplate TargetType="ToggleButton">
161+
153162
<ControlTemplate.Triggers>
154163
<Trigger Property="ToggleButton.IsChecked" Value="True">
155164
<Setter Property="Background">
@@ -158,14 +167,17 @@
158167
</Setter.Value>
159168
</Setter>
160169
</Trigger>
161-
162170
</ControlTemplate.Triggers>
171+
163172
<Border x:Name="OuterBorder"
164173
Background="{TemplateBinding Background}"
165174
BorderBrush="{TemplateBinding BorderBrush}"
166-
BorderThickness="{TemplateBinding BorderThickness}">
175+
BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4">
167176

168177
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" x:Name="InnerBoarder" BorderBrush="LightGray" BorderThickness="1" CornerRadius="4">
178+
179+
180+
169181
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
170182
</Border>
171183

0 commit comments

Comments
 (0)