Repository navigation
Expand file tree
/
Copy pathAddToAlignmentModel.cs
More file actions
146 lines (133 loc) · 6.22 KB
/
Copy pathAddToAlignmentModel.cs
File metadata and controls
146 lines (133 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using NINA.Core.Utility;
using NINA.Plugin;
using NINA.Plugin.Interfaces;
using NINA.Profile;
using NINA.Profile.Interfaces;
using NINA.WPF.Base.Interfaces.ViewModel;
using System;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Settings = ADPUK.NINA.AddToAlignmentModel.Properties.Settings;
namespace ADPUK.NINA.AddToAlignmentModel {
/// <summary>
/// This class exports the IPluginManifest interface and will be used for the general plugin information and options
/// The base class "PluginBase" will populate all the necessary Manifest Meta Data out of the AssemblyInfo attributes. Please fill these accoringly
///
/// An instance of this class will be created and set as datacontext on the plugin options tab in N.I.N.A. to be able to configure global plugin settings
/// The user interface for the settings will be defined by a DataTemplate with the key having the naming convention "AddToAlignmentModel_Options" where AddToAlignmentModel corresponds to the AssemblyTitle - In this template example it is found in the Options.xaml
/// </summary>
[Export(typeof(IPluginManifest))]
public class AddToAlignmentModel : PluginBase, INotifyPropertyChanged {
private readonly PluginOptionsAccessor pluginSettings;
private readonly IProfileService profileService;
[ImportingConstructor]
public AddToAlignmentModel(IProfileService profileService, IOptionsVM options) {
if (Settings.Default.UpdateSettings) {
Settings.Default.Upgrade();
Settings.Default.UpdateSettings = false;
CoreUtil.SaveSettings(Settings.Default);
}
// This helper class can be used to store plugin settings that are dependent on the current profile
this.pluginSettings = new PluginOptionsAccessor(profileService, Guid.Parse(this.Identifier));
this.profileService = profileService;
// React on a changed profile
profileService.ProfileChanged += ProfileService_ProfileChanged;
// Hook in to telescope
}
public override Task Teardown() {
// Make sure to unregister an event when the object is no longer in use. Otherwise garbage collection will be prevented.
profileService.ProfileChanged -= ProfileService_ProfileChanged;
return base.Teardown();
}
private void ProfileService_ProfileChanged(object sender, EventArgs e) {
// Rase the event that this profile specific value has been changed due to the profile switch
RaisePropertyChanged(nameof(ProfileSpecificNotificationMessage));
}
public string DefaultNotificationMessage {
get {
return Settings.Default.DefaultNotificationMessage;
}
set {
Settings.Default.DefaultNotificationMessage = value;
CoreUtil.SaveSettings(Settings.Default);
RaisePropertyChanged();
}
}
public string ProfileSpecificNotificationMessage {
get {
return pluginSettings.GetValueString(nameof(ProfileSpecificNotificationMessage), string.Empty);
}
set {
pluginSettings.SetValueString(nameof(ProfileSpecificNotificationMessage), value);
RaisePropertyChanged();
}
}
public int NumberOfAzimuthPoints {
get { return pluginSettings.GetValueInt32(nameof(NumberOfAzimuthPoints), 4); }
set {
pluginSettings.SetValueInt32(nameof(NumberOfAzimuthPoints), value);
RaisePropertyChanged("total_Steps");
RaisePropertyChanged();
}
}
public int NumberOfAltitudePoints {
get { return pluginSettings.GetValueInt32(nameof(NumberOfAltitudePoints), 2); }
set {
pluginSettings.SetValueInt32(nameof(NumberOfAltitudePoints), value);
RaisePropertyChanged("total_Steps");
RaisePropertyChanged();
}
}
public double MaxElevation {
get { return pluginSettings.GetValueDouble(nameof(MaxElevation), 80.0); }
set {
if (value > 85.0) value = 85.0;
pluginSettings.SetValueDouble(nameof(MaxElevation), value);
RaisePropertyChanged("total_Steps");
RaisePropertyChanged();
}
}
public double MinElevation {
get { return pluginSettings.GetValueDouble(nameof(MinElevation), 35.0); }
set {
if (value < 0.0) value = 0.0;
pluginSettings.SetValueDouble(nameof(MinElevation), value);
RaisePropertyChanged("total_Steps");
RaisePropertyChanged();
}
}
public int SolveAttempts {
get { return pluginSettings.GetValueInt32(nameof(SolveAttempts), 1); }
set {
pluginSettings.SetValueInt32(nameof(SolveAttempts), value);
RaisePropertyChanged();
}
}
public double MinElevationAboveHorizon {
get {
var mh = pluginSettings.GetValueDouble(nameof(MinElevationAboveHorizon), 0.0);
if (mh == 0.0) return 0.0;
return mh;
}
set {
if (value < 0.0) value = 0.0;
if (value >= MaxElevation) value = MaxElevation;
pluginSettings.SetValueDouble(nameof(MinElevationAboveHorizon), value);
RaisePropertyChanged();
}
}
public bool EnableEquatorialMounts {
get { return pluginSettings.GetValueBoolean(nameof(EnableEquatorialMounts), false); }
set {
pluginSettings.SetValueBoolean(nameof(EnableEquatorialMounts), value);
RaisePropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}