
"""
Contains GUI forms for the slice filter.

"""
from __future__ import absolute_import
from __future__ import unicode_literals
from PySide2 import QtCore, QtWidgets


from . import base
from ...rendering import slicePlane
from ...filtering.filters import sliceFilter


################################################################################

class SliceSettingsDialog(base.GenericSettingsDialog):
    """
    Slice filter settings form.
    
    """
    def __init__(self, mainWindow, title, parent=None):
        super(SliceSettingsDialog, self).__init__(title, parent, "Slice")
        
        # slice plane
        self.slicePlane = slicePlane.SlicePlane(self.pipelinePage)
        
        # settings
        self._settings = sliceFilter.SliceFilterSettings()
        
        # defaults
        lattice = self.pipelinePage.inputState
        self._settings.updateSetting("x0", lattice.cellDims[0] / 2.0)
        self._settings.updateSetting("y0", lattice.cellDims[1] / 2.0)
        self._settings.updateSetting("z0", lattice.cellDims[2] / 2.0)
        self.showSlicePlaneChecked = False
        
        # show slice plane
        self.showSlicePlaneCheck = QtWidgets.QCheckBox()
        self.showSlicePlaneCheck.stateChanged.connect(self.showPlaneChanged)
        self.showSlicePlaneCheck.setToolTip("Show the slice plane as a visual aid")
        self.contentLayout.addRow("Show slice plane", self.showSlicePlaneCheck)
        
        self.addHorizontalDivider()
        
        # plane centre
        x0SpinBox = QtWidgets.QDoubleSpinBox()
        x0SpinBox.setSingleStep(1)
        x0SpinBox.setMinimum(-1000)
        x0SpinBox.setMaximum(1000)
        x0SpinBox.setValue(self._settings.getSetting("x0"))
        x0SpinBox.setToolTip("Plane centre x value")
        x0SpinBox.valueChanged.connect(self.x0Changed)
        
        y0SpinBox = QtWidgets.QDoubleSpinBox()
        y0SpinBox.setSingleStep(1)
        y0SpinBox.setMinimum(-1000)
        y0SpinBox.setMaximum(1000)
        y0SpinBox.setValue(self._settings.getSetting("y0"))
        y0SpinBox.setToolTip("Plane centre y value")
        y0SpinBox.valueChanged.connect(self.y0Changed)
        
        z0SpinBox = QtWidgets.QDoubleSpinBox()
        z0SpinBox.setSingleStep(1)
        z0SpinBox.setMinimum(-1000)
        z0SpinBox.setMaximum(1000)
        z0SpinBox.setValue(self._settings.getSetting("z0"))
        z0SpinBox.setToolTip("Plane centre z value")
        z0SpinBox.valueChanged.connect(self.z0Changed)
        
        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(x0SpinBox)
        hbox.addWidget(QtWidgets.QLabel(","))
        hbox.addWidget(y0SpinBox)
        hbox.addWidget(QtWidgets.QLabel(","))
        hbox.addWidget(z0SpinBox)
        self.contentLayout.addRow("Place centre", hbox)
        
        # plane normal 
        xnSpinBox = QtWidgets.QDoubleSpinBox()
        xnSpinBox.setSingleStep(0.1)
        xnSpinBox.setMinimum(-1000)
        xnSpinBox.setMaximum(1000)
        xnSpinBox.setValue(self._settings.getSetting("xn"))
        xnSpinBox.setToolTip("Plane normal x value")