|
| 1 | +import re |
| 2 | +import customtkinter as ctk |
| 3 | + |
| 4 | +import numpy as np |
| 5 | + |
| 6 | +from ..functions import dp, pdd |
| 7 | +from ..resources.language import Text |
| 8 | +from .profile import ProfileHandler |
| 9 | +from .tgs_graph import TGS_Plot |
| 10 | +from .paramframe import Parameters |
| 11 | +from .scrollframe import ScrollFrame |
| 12 | + |
| 13 | +class RayStationData: |
| 14 | + def __init__(self, list, index): |
| 15 | + |
| 16 | + self.axis = np.array(list[0]) |
| 17 | + self.dose = np.array(list[1]) |
| 18 | + self.direction = list[4] |
| 19 | + self.normpoint = max(self.dose) |
| 20 | + |
| 21 | + self.std_dev = np.array([0.0 for i in range(len(self.dose))]) |
| 22 | + |
| 23 | + self.filepath = list[2] |
| 24 | + |
| 25 | + if "/" in self.filepath: |
| 26 | + self.filename = self.filepath.split("/")[-1][:-4] + f" - Scan {index}" |
| 27 | + else: |
| 28 | + self.filename = self.filepath.split("\\")[-1][:-4] + f" - Scan {index}" |
| 29 | + |
| 30 | + self.unit = list[3] |
| 31 | + |
| 32 | + |
| 33 | + def params(self): |
| 34 | + if self.direction == "Z": |
| 35 | + return pdd.calculate_parameters( |
| 36 | + np.array(self.axis), |
| 37 | + self.dose / max(self.dose), |
| 38 | + [], |
| 39 | + ) |
| 40 | + else: |
| 41 | + params = dp.calculate_parameters( |
| 42 | + self.axis, self.dose / max(self.dose) |
| 43 | + ) |
| 44 | + self.cax = params[1] |
| 45 | + return params |
| 46 | + |
| 47 | + |
| 48 | +class RayStationMultiImporter(ScrollFrame): |
| 49 | + def __init__(self, filepath, parent, plotlist, options): |
| 50 | + super().__init__(parent=parent) |
| 51 | + self.parent = parent |
| 52 | + self.text = Text() |
| 53 | + self.lang = ProfileHandler().get_attribute("language") |
| 54 | + self.plotlist = plotlist |
| 55 | + self.path = filepath |
| 56 | + self.options = options |
| 57 | + self.root = self.options.parent.master.master.parent |
| 58 | + self.pack_propagate(False) |
| 59 | + self.grid_propagate(False) |
| 60 | + self.canvas.pack_propagate(False) |
| 61 | + |
| 62 | + with open(filepath, "r") as file: |
| 63 | + lines = file.readlines() |
| 64 | + unit = "Gy" |
| 65 | + self.alldata = [] |
| 66 | + direction = "" |
| 67 | + field_size="" |
| 68 | + ssd="" |
| 69 | + for index, line in enumerate(lines): |
| 70 | + |
| 71 | + if "SSD" in line: |
| 72 | + ssd = line.split(":;")[-1].strip() |
| 73 | + |
| 74 | + elif "Fieldsize" in line: |
| 75 | + _, x1,y1,x2,y2 = line.split(";") |
| 76 | + x = abs(float(x1)) + abs(float(x2)) |
| 77 | + y = abs(float(y1)) + abs(float(y2)) |
| 78 | + field_size = f"{x}x{y} mm" |
| 79 | + |
| 80 | + elif "CurveType" in line: |
| 81 | + direction = line.split(":;")[-1].strip() |
| 82 | + direcs = {"Inline":"X", "Crossline":"Y", "Depth":"Z", "Diagonal":"XY"} |
| 83 | + direction = direcs[direction] |
| 84 | + |
| 85 | + if "StartPoint" in line: |
| 86 | + xdata, ydata = [], [] |
| 87 | + i = 1 |
| 88 | + while "End" not in lines[index + i]: |
| 89 | + xdata += [float(lines[index + i].split(";")[0])] |
| 90 | + ydata += [float(lines[index + i].split(";")[1])] |
| 91 | + i += 1 |
| 92 | + self.alldata += [ |
| 93 | + [np.array(xdata), np.array(ydata), filepath, unit, direction, ssd, field_size] |
| 94 | + ] |
| 95 | + direction = "" |
| 96 | + ssd = "" |
| 97 | + field_size = "" |
| 98 | + |
| 99 | + self.plots = [] |
| 100 | + theme = ProfileHandler().get_attribute("color_scheme") |
| 101 | + colors2 = {"light": "#E5E5E5", "dark":"#212121"} |
| 102 | + colors3 = {"light": "#DBDBDB", "dark":"#2B2B2B"} |
| 103 | + self.configure(fg_color=colors2[theme]) |
| 104 | + self.canvas.configure(bg=colors3[theme], highlightbackground=colors3[theme]) |
| 105 | + self.scrollbar.configure(fg_color=colors3[theme]) |
| 106 | + self.options.dataframe2.grid_remove() |
| 107 | + self.options.dataframe1.grid_remove() |
| 108 | + self.grid(row=0, rowspan=2, column=0, sticky="nsew") |
| 109 | + self.label = ctk.CTkLabel(self.viewPort, text=Text().select[self.lang], font=("Bahnschrift", 14, "bold")) |
| 110 | + self.label.pack(anchor="n", pady=5) |
| 111 | + self.variables = [ctk.BooleanVar() for i in range(len(self.alldata))] |
| 112 | + [var.set(False) for var in self.variables] |
| 113 | + self.buttons = [ |
| 114 | + ctk.CTkCheckBox( |
| 115 | + self.viewPort, |
| 116 | + variable=self.variables[i], |
| 117 | + text=f"Scan {i+1}: {self.alldata[i][6]} {self.alldata[i][5]}mm {self.alldata[i][4]}", |
| 118 | + ) |
| 119 | + for i in range(len(self.alldata)) |
| 120 | + ] |
| 121 | + [button.pack(anchor="w") for button in self.buttons] |
| 122 | + self.submitbutton = ctk.CTkButton( |
| 123 | + self.viewPort, |
| 124 | + text=Text().submit[ProfileHandler().get_attribute("language")], |
| 125 | + command=self.submit, |
| 126 | + ) |
| 127 | + self.submitbutton.pack(anchor="s", pady=5) |
| 128 | + self.parent.master.master.parent.bind("<Return>", self.submit) |
| 129 | + |
| 130 | + def submit(self, event=None): |
| 131 | + |
| 132 | + self.plots = [] |
| 133 | + |
| 134 | + |
| 135 | + for index, dataset in enumerate(self.alldata): |
| 136 | + if self.variables[index].get() != True: |
| 137 | + continue |
| 138 | + else: |
| 139 | + self.plotlist += [TGS_Plot(self.options, RayStationData(dataset, index + 1))] |
| 140 | + self.options.parameters.append(Parameters(self.options.paramslist.viewPort, self.plotlist[-1], self.lang)) |
| 141 | + self.options.parameters[-1].grid(row=len(self.options.parameters)-1, sticky="ew", padx=5, pady=5) |
| 142 | + self.options.plotbuttons.append(ctk.CTkRadioButton(self.options.graphlist.viewPort, text=self.plotlist[-1].label, variable=self.options.current_plot, text_color = self.plotlist[-1].linecolor, value=self.plotlist[-1].label, command=self.options.change_current_plot, font=("Bahnschrift", 14, "bold"))) |
| 143 | + self.options.plotbuttons[-1].grid(sticky="w", padx=5, pady=5) |
| 144 | + if len(self.options.parent.plots) == 1: |
| 145 | + self.options.enable_all_buttons() |
| 146 | + try: |
| 147 | + self.options.current_plot.set(self.plotlist[-1].label) |
| 148 | + self.options.filenames.append(self.path) |
| 149 | + self.options.parent.saved = False |
| 150 | + self.options.update_plotlist() |
| 151 | + self.options.parent.update() |
| 152 | + except IndexError: |
| 153 | + pass |
| 154 | + |
| 155 | + self.canvas.unbind_all("<MouseWheel>") |
| 156 | + self.destroy() |
| 157 | + self.options.dataframe1.grid(row=1, column=0, sticky="nsew", padx=5, pady=5) |
| 158 | + self.options.dataframe2.grid(row=0, column=0, sticky="nsew", padx=5, pady=5) |
0 commit comments