# Path: pytripgui/tree_vc/tree_items.py
# class PatientItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self.data = PatientModel()
# 
#     def __repr__(self):
#         if self.data.name:
#             return "Patient: " + self.data.name
#         return "No named patient"
# 
# Path: pytripgui/tree_vc/tree_items.py
# class PlanItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self._data = Plan()
#         self.field_counter = 1
# 
#     def __repr__(self):
#         if self.data.basename:
#             return "Plan: " + self.data.basename
#         return "No named plan"
# 
#     def add_child(self, child):
#         super().add_child(child)
# 
#         if isinstance(child, FieldItem):
#             child.data.number = self.field_counter
#             self.field_counter = self.field_counter + 1
# 
#     @property
#     def data(self):
#         self._data.fields = [child.data for child in self.children]
#         for field in self._data.fields:
#             field.kernel = self._data.default_kernel
#         return self._data
# 
#     @data.setter
#     def data(self, data):
#         self._data = data
# 
# Path: pytripgui/tree_vc/tree_items.py
# class FieldItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self.data = FieldModel()
# 
#     def __repr__(self):
#         return "Field: " + str(self.data.number)
# 
# Path: pytripgui/tree_vc/tree_items.py
# class SimulationResultItem(TreeItem):
#     def __repr__(self):
#         if self.data:
#             return self.data.__str__()
#         return "Empty simulation"
# 
# Path: pytripgui/plan_executor/simulation_results.py
# class SimulationResults:
#     def __init__(self, patient, plan, name):
#         self.patient = patient
#         self.plan = plan
#         self.name = name
#         self.volume_histograms = {}
# 
#         self._compute_target_dvh()
#         self._compute_target_lvh()
# 
#     def get_doses(self):
#         return self.plan.dosecubes
# 
#     def get_dose(self, dose_type):
#         if dose_type not in DosCube.allowed_suffix:
#             raise ValueError("Wrong dose type")
# 
#         for dose in self.plan.dosecubes:
#             if dose.basename.endswith("." + dose_type):
#                 return dose
#         return None
# 
#     def get_lets(self):
#         return self.plan.letcubes
# 
#     def import_dos(self, dos_path):
#         logger.debug("Open DosCube {:s}".format(dos_path))
#         dos = DosCube()
#         dos.read(dos_path)
#         self.plan.dosecubes.append(dos)
# 
#     def import_let(self, let_path):
#         logger.debug("Open LETCube {:s}".format(let_path))
#         let = LETCube()
#         let.read(let_path)
#         self.plan.letcubes.append(let)
# 
#     def get_let(self, let_type):
#         if let_type not in LETCube.allowed_suffix:
#             raise ValueError("Wrong LET type")
# 
#         for let in self.plan.letcubes:
#             if let.basename.endswith("." + let_type):
#                 return let
#         return None
# 
#     def _compute_target_dvh(self):
#         for dose in self.plan.dosecubes:
#             dose_type = dose.basename.split(".")[-1]
#             target_name = self.plan.voi_target.name
#             dvh = {target_name: volhist.VolHist(dose, self.patient.vdx.get_voi_by_name(target_name))}
#             self.volume_histograms["DVH " + dose_type] = dvh
# 
#     def _compute_target_lvh(self):
#         for let in self.plan.letcubes:
#             let_type = let.basename.split(".")[-1]
#             target_name = self.plan.voi_target.name
#             lvh = {target_name: volhist.VolHist(let, self.patient.vdx.get_voi_by_name(target_name))}
#             self.volume_histograms["LVH " + let_type] = lvh
# 
#     def __str__(self):
#         return "Sim: " + self.name


import logging
from events import Events
from PyQt5.QtCore import Qt, QPoint, QModelIndex
from PyQt5.QtWidgets import QTreeView, QMenu
from pytripgui.tree_vc.tree_items import PatientItem
from pytripgui.tree_vc.tree_items import PlanItem
from pytripgui.tree_vc.tree_items import FieldItem
from pytripgui.tree_vc.tree_items import SimulationResultItem
from pytripgui.plan_executor.simulation_results import SimulationResults




logger = logging.getLogger(__name__)


class TreeView(QTreeView):
    def __init__(self, parent=None):
        super().__init__(parent)


# Path: pytripgui/tree_vc/tree_items.py
# class PatientItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self.data = PatientModel()
# 
#     def __repr__(self):
#         if self.data.name:
#             return "Patient: " + self.data.name
#         return "No named patient"
# 
# Path: pytripgui/tree_vc/tree_items.py
# class PlanItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self._data = Plan()
#         self.field_counter = 1
# 
#     def __repr__(self):
#         if self.data.basename:
#             return "Plan: " + self.data.basename
#         return "No named plan"
# 
#     def add_child(self, child):
#         super().add_child(child)
# 
#         if isinstance(child, FieldItem):
#             child.data.number = self.field_counter
#             self.field_counter = self.field_counter + 1
# 
#     @property
#     def data(self):
#         self._data.fields = [child.data for child in self.children]
#         for field in self._data.fields:
#             field.kernel = self._data.default_kernel
#         return self._data
# 
#     @data.setter
#     def data(self, data):
#         self._data = data
# 
# Path: pytripgui/tree_vc/tree_items.py
# class FieldItem(TreeItem):
#     def __init__(self):
#         super().__init__()
# 
#         self.data = FieldModel()
# 
#     def __repr__(self):
#         return "Field: " + str(self.data.number)
# 
# Path: pytripgui/tree_vc/tree_items.py
# class SimulationResultItem(TreeItem):
#     def __repr__(self):
#         if self.data:
#             return self.data.__str__()
#         return "Empty simulation"
# 
# Path: pytripgui/plan_executor/simulation_results.py
# class SimulationResults:
#     def __init__(self, patient, plan, name):
#         self.patient = patient
#         self.plan = plan
#         self.name = name
#         self.volume_histograms = {}
# 
#         self._compute_target_dvh()
#         self._compute_target_lvh()
# 
#     def get_doses(self):
#         return self.plan.dosecubes
# 
#     def get_dose(self, dose_type):
#         if dose_type not in DosCube.allowed_suffix:
#             raise ValueError("Wrong dose type")
# 
#         for dose in self.plan.dosecubes:
#             if dose.basename.endswith("." + dose_type):
#                 return dose
#         return None
# 
#     def get_lets(self):
#         return self.plan.letcubes
# 
#     def import_dos(self, dos_path):
#         logger.debug("Open DosCube {:s}".format(dos_path))
#         dos = DosCube()
#         dos.read(dos_path)
#         self.plan.dosecubes.append(dos)
# 
#     def import_let(self, let_path):
#         logger.debug("Open LETCube {:s}".format(let_path))
#         let = LETCube()
#         let.read(let_path)
#         self.plan.letcubes.append(let)
# 
#     def get_let(self, let_type):
#         if let_type not in LETCube.allowed_suffix:
#             raise ValueError("Wrong LET type")
# 
#         for let in self.plan.letcubes:
#             if let.basename.endswith("." + let_type):
#                 return let
#         return None
# 
#     def _compute_target_dvh(self):
#         for dose in self.plan.dosecubes:
#             dose_type = dose.basename.split(".")[-1]
#             target_name = self.plan.voi_target.name
#             dvh = {target_name: volhist.VolHist(dose, self.patient.vdx.get_voi_by_name(target_name))}
#             self.volume_histograms["DVH " + dose_type] = dvh
# 
#     def _compute_target_lvh(self):
#         for let in self.plan.letcubes:
#             let_type = let.basename.split(".")[-1]
#             target_name = self.plan.voi_target.name
#             lvh = {target_name: volhist.VolHist(let, self.patient.vdx.get_voi_by_name(target_name))}
#             self.volume_histograms["LVH " + let_type] = lvh
# 
#     def __str__(self):
#         return "Sim: " + self.name


# Path: pytripgui/tree_vc/tree_view.py
import logging
from events import Events
from PyQt5.QtCore import Qt, QPoint, QModelIndex
from PyQt5.QtWidgets import QTreeView, QMenu
from pytripgui.tree_vc.tree_items import PatientItem
from pytripgui.tree_vc.tree_items import PlanItem
from pytripgui.tree_vc.tree_items import FieldItem
from pytripgui.tree_vc.tree_items import SimulationResultItem
from pytripgui.plan_executor.simulation_results import SimulationResults





logger = logging.getLogger(__name__)


class TreeView(QTreeView):
    def __init__(self, parent=None):
        super().__init__(parent)


        self.selected_item = None