-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeamEnumerator.cs
87 lines (75 loc) · 3.34 KB
/
BeamEnumerator.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
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
using System.Drawing;
using BeamEnumerator;
// TODO: Uncomment the following line if the script requires write access.
[assembly: ESAPIScript(IsWriteable = true)]
namespace VMS.TPS
{
public class Script
{
const string SCRIPT_NAME = "BeamEnumerator";
public Script()
{
}
[MethodImpl(MethodImplOptions.NoInlining)]
public void Execute(ScriptContext context , System.Windows.Window window/*, ScriptEnvironment environment*/)
{
if (context.ExternalPlanSetup == null)
{
MessageBox.Show("Please load a treatment plan");
return;
}
var ui = new UserControl1(context);
// decide on DRR parameters depending on plan name
Regex mammaMatch = new Regex("MA"); // potential plan ID for breast plans
Regex thoraxMatch = new Regex("TH"); // potential plan ID for thorax plans
if (mammaMatch.IsMatch(context.PlanSetup.Id.ToUpper())) // breast plan uses mamma DRR setting
{
//drrSelection = "Mamma DRR";
ui.MammaButton.IsChecked = true;
ui.drrParam.SetLayerParameters(0, 1.0, -450.0, 150.0, -1000.0, 1000.0);
}
else if (thoraxMatch.IsMatch(context.PlanSetup.Id.ToUpper())) // thorax plan uses thorax
{
//drrSelection = "Thorax DRR";
ui.ThoraxButton.IsChecked = true;
ui.drrParam.SetLayerParameters(0, 1.0, -500.0, 1000.0, -020.0, -100.0);
ui.drrParam.SetLayerParameters(1, 2.0, -300.0, 800.0, -200.0, 50.0);
}
else // all other plans use the default bone DRR setting
{
//drrSelection = "Knochen DRR";
ui.KnochenButton.IsChecked = true;
ui.drrParam.SetLayerParameters(0, 2.0, -16.0, 126.0, 20.0, 60.0);
ui.drrParam.SetLayerParameters(1, 10.0, 100.0, 1000.0);
}
// try to guess initial BeamIdx from reference point
string refPtId = context.ExternalPlanSetup.ReferencePoints.OrderBy(x => x.Id).FirstOrDefault().Id;
int index = Char.ToUpper(refPtId[1]) - 64; // converts character to number (A=1, B=2 etc.)
if (Char.IsDigit(refPtId[0]) && Char.IsLetter(refPtId[1]))
{
ui.BeamIdx = refPtId[0] + index.ToString() + ui.BeamIdx.Remove(0, 2); //index could be more than one character!
}
else if (Char.IsDigit(refPtId[0]))
{
ui.BeamIdx = refPtId[0] + ui.BeamIdx.Remove(0, 1);
}
// Modifications start from here
context.Patient.BeginModifications();
window.Content = ui;
window.SizeToContent = SizeToContent.WidthAndHeight;
window.Title = "BeamEnumerator";
//window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
}
}
}