-
Notifications
You must be signed in to change notification settings - Fork 6
/
WaterfallManager.cs
149 lines (136 loc) · 6.71 KB
/
WaterfallManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DigiRite
{
/* Without this class, DigiRite has only a spectrum line display.
* This class, in its OnLoad() method, detects if WriteLog's waterfall component is installed.
* If its found, it substitutes that waterfall for the spectrum chart control.
*/
class WaterfallManager
{
public WriteLog.IWaterfallV3 iwaterfall { get; private set; } = null;
public WriteLog.IAnnotations annotations { get; private set; } = null;
public WriteLog.IPeakRx peak { get; private set; } = null;
public bool OnLoad(LogFile logfile, Control chartSpectrum, Label labelWaterfall, Control.ControlCollection collection, MainForm mainForm)
{
Control waterfall = null;
bool foundWriteLog = false;
// registry goop to look unconditionally in 32bit registry for WriteLog, whether we are x86 or x64
Microsoft.Win32.RegistryKey rk32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32);
{
if (null != rk32)
{
Microsoft.Win32.RegistryKey wlrk32 = rk32.OpenSubKey(@"Software\\W5XD\\WriteLog\\Install");
if (null != wlrk32)
{
object wlDir = wlrk32.GetValue("Directory");
/* SetCurrentDirectory
* Why?
* The WriteLog waterfall depends on the d3dcsx.dll (Microsoft's DirectX2D). That dll must be installed
* on a per-application basis. Win32's dll lookup for the case of loading for a .net assembly in the GAC
* needs to find d3dcxs. WL installs a copy, so we "cd" this exe there so it will be found.
*/
if (null != wlDir)
{
try
{
System.IO.Directory.SetCurrentDirectory(wlDir.ToString() +
#if BUILD_X86
"Programs"
#elif BUILD_X64
"DigiRite X64 Waterfall"
#endif
);
foundWriteLog = true;
}
catch (System.Exception) { } // ignore failure
}
wlrk32.Close();
}
rk32.Close();
}
}
if (!foundWriteLog)
{ // second chance look for waterfall install
Microsoft.Win32.RegistryKey rkMachineDefault = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Default);
if (null != rkMachineDefault)
{
Microsoft.Win32.RegistryKey wf = rkMachineDefault.OpenSubKey(@"Software\\DigiRite\\Waterfall");
if (null != wf)
{
object wfDir = wf.GetValue("Directory");
if (null != wfDir)
{
try {
System.IO.Directory.SetCurrentDirectory(wfDir.ToString() );
} catch (System.Exception) { } // ignore failure
}
wf.Close();
}
rkMachineDefault.Close();
}
}
try
{
// if WriteLog's DigiRiteWaterfall assembly loads, use it.
System.Reflection.Assembly waterfallAssembly = System.Reflection.Assembly.Load(
"WriteLogWaterfallDigiRite, Version=12.0.52.5, Culture=neutral, PublicKeyToken=e34bde9f0678e8b6");
System.Type t = waterfallAssembly.GetType("WriteLog.WaterfallFactory");
if (t == null)
throw new System.Exception("WaterfallFactory type not found");
wfFactory = (WriteLog.IWaterfallFactory)System.Activator.CreateInstance(t);
waterfall = (Control)wfFactory.GetWaterfall();
waterfallEditor = wfFactory.GetEditor() as Form;
iwaterfall = (WriteLog.IWaterfallV3)waterfall;
}
catch (System.Exception ex)
{ // if WriteLog is not installed, this is "normal successful completion"
logfile.SendToLog("Load waterfall exception " + ex.ToString()); // not normal
}
if (null != waterfall)
{ // waterfall loaded. it goes where chartSpectrum was.
((System.ComponentModel.ISupportInitialize)waterfall).BeginInit();
waterfall.Location = chartSpectrum.Location;
waterfall.Dock = chartSpectrum.Dock;
waterfall.Size = chartSpectrum.Size;
waterfall.TabIndex = chartSpectrum.TabIndex;
waterfall.Name = "waterfall";
waterfall.Font = labelWaterfall.Font; // labelWaterfall is placeholder for properties
waterfall.BackColor = labelWaterfall.BackColor;
waterfall.ForeColor = labelWaterfall.ForeColor;
waterfall.Visible = true;
iwaterfall.TxFreqHz = mainForm.TxFrequency;
iwaterfall.RxFreqHz = mainForm.RxFrequency;
iwaterfall.onTxFreqMove = new WriteLog.OnFreqMove((int hz) => { mainForm.TxFrequency = hz; });
iwaterfall.onRxFreqMove = new WriteLog.OnFreqMove((int hz) => { mainForm.RxFrequency = hz; });
((System.ComponentModel.ISupportInitialize)waterfall).EndInit();
collection.Remove(chartSpectrum);
collection.Add(waterfall);
collection.SetChildIndex(waterfall, 0);
peak = iwaterfall as WriteLog.IPeakRx;
annotations = iwaterfall as WriteLog.IAnnotations;
}
return iwaterfall != null;
}
public void StoreProperties()
{
if (null != wfFactory)
wfFactory.StoreProperties();
}
public void ShowOptionsDialog(System.Windows.Forms.Form par)
{
if (waterfallEditor != null)
{
if (waterfallEditor.WindowState == FormWindowState.Minimized)
waterfallEditor.WindowState = FormWindowState.Normal;
else if (!waterfallEditor.Visible)
waterfallEditor.Show(par);
}
}
private Form waterfallEditor;
private WriteLog.IWaterfallFactory wfFactory;
}
}