-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lumixcamera.cs
175 lines (148 loc) · 7.72 KB
/
Lumixcamera.cs
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using NINA.Core.Model;
using NINA.Core.Utility;
using NINA.Image.ImageData;
using NINA.Plugin;
using NINA.Plugin.Interfaces;
using NINA.Profile;
using NINA.Profile.Interfaces;
using NINA.WPF.Base.Interfaces.Mediator;
using NINA.WPF.Base.Interfaces.ViewModel;
using Roberthasson.NINA.Lumixcamera.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Settings = Roberthasson.NINA.Lumixcamera.Properties.Settings;
namespace Roberthasson.NINA.Lumixcamera {
/// <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 "Lumixcamera_Options" where Lumixcamera corresponds to the AssemblyTitle - In this template example it is found in the Options.xaml
/// </summary>
[Export(typeof(IPluginManifest))]
public class Lumixcamera : PluginBase, INotifyPropertyChanged {
private readonly IPluginOptionsAccessor pluginSettings;
private readonly IProfileService profileService;
private readonly IImageSaveMediator imageSaveMediator;
// Implementing a file pattern
private readonly ImagePattern exampleImagePattern = new ImagePattern("$$EXAMPLEPATTERN$$", "An example of an image pattern implementation", "LumixCamera");
[ImportingConstructor]
public Lumixcamera(IProfileService profileService, IOptionsVM options, IImageSaveMediator imageSaveMediator) {
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 into image saving for adding FITS keywords or image file patterns
this.imageSaveMediator = imageSaveMediator;
// Run these handlers when an image is being saved
this.imageSaveMediator.BeforeImageSaved += ImageSaveMediator_BeforeImageSaved;
this.imageSaveMediator.BeforeFinalizeImageSaved += ImageSaveMediator_BeforeFinalizeImageSaved;
// Register a new image file pattern for the Options > Imaging > File Patterns area
options.AddImagePattern(exampleImagePattern);
}
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;
imageSaveMediator.BeforeImageSaved -= ImageSaveMediator_BeforeImageSaved;
imageSaveMediator.BeforeFinalizeImageSaved -= ImageSaveMediator_BeforeFinalizeImageSaved;
return base.Teardown();
}
private void ProfileService_ProfileChanged(object sender, EventArgs e) {
// Raise the event that this profile specific value has been changed due to the profile switch
RaisePropertyChanged(nameof(ProfileSpecificNotificationMessage));
}
private Task ImageSaveMediator_BeforeImageSaved(object sender, BeforeImageSavedEventArgs e) {
// Insert the example FITS keyword of a specific data type into the image metadata object prior to the file being saved
// FITS keywords have a maximum of 8 characters. Comments are options. Comments that are too long will be truncated.
string exampleKeywordComment = "This is a {0} keyword";
// string
string exampleStringKeywordName = "STRKEYWD";
string exampleStringKeywordValue = "Example";
e.Image.MetaData.GenericHeaders.Add(new StringMetaDataHeader(exampleStringKeywordName, exampleStringKeywordValue, string.Format(exampleKeywordComment, "string")));
// integer
string exampleIntKeywordName = "INTKEYWD";
int exampleIntKeywordValue = 5;
e.Image.MetaData.GenericHeaders.Add(new IntMetaDataHeader(exampleIntKeywordName, exampleIntKeywordValue, string.Format(exampleKeywordComment, "integer")));
// double
string exampleDoubleKeywordName = "DBLKEYWD";
double exampleDoubleKeywordValue = 1.3d;
e.Image.MetaData.GenericHeaders.Add(new DoubleMetaDataHeader(exampleDoubleKeywordName, exampleDoubleKeywordValue, string.Format(exampleKeywordComment, "double")));
// Classes also exist for other data types:
// BoolMetaDataHeader()
// DateTimeMetaDataHeader()
return Task.CompletedTask;
}
private Task ImageSaveMediator_BeforeFinalizeImageSaved(object sender, BeforeFinalizeImageSavedEventArgs e) {
// Populate the example image pattern with data. This can provide data that may not be immediately available
e.AddImagePattern(new ImagePattern(exampleImagePattern.Key, exampleImagePattern.Description, exampleImagePattern.Category) {
Value = $"{DateTime.Now:yyyy-MM-ddTHH:mm:ss.ffffffK}"
});
return Task.CompletedTask;
}
public int SensorWidth {
get {
return Settings.Default.SensorWidth;
}
set {
Settings.Default.SensorWidth = value;
CoreUtil.SaveSettings(Settings.Default);
RaisePropertyChanged();
}
}
public int BitDepth {
get {
return Settings.Default.BitDepth;
}
set {
Settings.Default.BitDepth = value;
CoreUtil.SaveSettings(Settings.Default);
RaisePropertyChanged();
}
}
public int SensorHeight {
get {
return Settings.Default.SensorHeight;
}
set {
Settings.Default.SensorHeight = value;
CoreUtil.SaveSettings(Settings.Default);
RaisePropertyChanged();
}
}
public double PixelPitch {
get {
return Settings.Default.PixelPitch;
}
set {
Settings.Default.PixelPitch = 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 event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) {
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}