#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：TrayConfigure.py
@Description：
@Author：XSH
@Time：2025/11/11 17:16
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from AppInterfaces.ConfigureInterfaces import TrayConfigInterface
from AppCore.Levels import ObjectiveLevel
class TrayConfigure(TrayConfigInterface):
    Locker      : Qt.QMutex         = Qt.QMutex         ()
    IOLocker    : Qt.QReadWriteLock = Qt.QReadWriteLock ()


    def __init__(self, *args, **kwargs):
        super(TrayConfigure, self).__init__()
        self.initialization("TrayConfigure")


    def initValue(self):
        super(TrayConfigure, self).initValue()
        self.Information                      = '托盘参数'          #
        self.ID                               = 1               #
        self.Position_X                       = 147.8           #
        self.Position_Y                       = 16.0            #
        self.Position_Z                       = 10000000.0      #
        self.SlideSpacing                     = 5000            #
        self.SlideWidth                       = 23.0            #
        self.SlideHeight                      = 47.00           #
        self.Step_X                           = 1.0             #
        self.Step_Y                           = 1.0             #
        self.Step_X_20X                       = 0.7             #
        self.Step_Y_20X                       = 0.7             #
        self.Step_X_40X                       = 0.7             #
        self.Step_Y_40X                       = 0.7             #
        self.Step_X_100X                     = 0.7              #
        self.Step_Y_100X                     = 0.7              #


    def UpdateMaxLocation(self):
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        self.as_field(TrayConfigModel.first().to_field())

    
    def setPosition_xyz(self, x, y, z):
        if isinstance(x, (int, float)) and isinstance(y, (int, float)) and isinstance(z, (int, float)):
            from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
            Locker: Qt.QWriteLocker = Qt.QWriteLocker(self.IOLocker)
            self.Position_X = float(x)
            self.Position_Y = float(y)
            self.Position_Z = float(z)
            TrayConfigModel.setPosition_xyz(self.Position_X, self.Position_Y, self.Position_Z)

    
    def getPosition_xyz(self) -> (float, float, float):
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_X, self.Position_Y, self.Position_Z = TrayConfigModel.getPosition_xyz()
        return self.Position_X, self.Position_Y, self.Position_Z

    
    def getSlideSize(self) -> (float, float):
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideWidth, self.SlideHeight = TrayConfigModel.getSlideSize()
        return self.SlideWidth, self.SlideHeight


    def getStep(self, level: int) -> (float, float):
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        return TrayConfigModel.getStep(level)
    
    def getPosition_X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_X = TrayConfigModel.getPosition_X()
        return self.Position_X
    
    def getPosition_Y(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_Y = TrayConfigModel.getPosition_Y()
        return self.Position_Y
    
    def getPosition_Z(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_Z = TrayConfigModel.getPosition_Z()
        return self.Position_Z
    
    def getSlideSpacing(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideSpacing = TrayConfigModel.getSlideSpacing()
        return self.SlideSpacing
    
    def getSlideWidth(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)

        self.SlideWidth = TrayConfigModel.getSlideWidth()
        return self.SlideWidth
    
    def getSlideHeight(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideHeight = TrayConfigModel.getSlideHeight()
        return self.SlideHeight
    
    def getStep_X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X = TrayConfigModel.getStep_X()
        return self.Step_X
    
    def getStep_Y(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y = TrayConfigModel.getStep_Y()
        return self.Step_Y
    
    def getStep_X_20X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_20X = TrayConfigModel.getStep_X_20X()
        return self.Step_X_20X
    
    def getStep_Y_20X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_20X = TrayConfigModel.getStep_Y_20X()
        return self.Step_Y_20X
    
    def getStep_X_40X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_40X = TrayConfigModel.getStep_X_40X()
        return self.Step_X_40X
    
    def getStep_Y_40X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_40X = TrayConfigModel.getStep_Y_40X()
        return self.Step_Y_40X
    
    def getStep_X_100X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_100X = TrayConfigModel.getStep_X_100X()
        return self.Step_X_100X
    
    def getStep_Y_100X(self) -> float:
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_100X = TrayConfigModel.getStep_Y_100X()
        return self.Step_Y_100X

    
    def setPosition_X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_X = float(value)
        TrayConfigModel.setPosition_X(self.Position_X)


    
    def setPosition_Y(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_Y = float(value)
        TrayConfigModel.setPosition_Y(self.Position_Y)

    def setPosition_Z(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Position_Z = float(value)
        TrayConfigModel.setPosition_Z(self.Position_Z)

    def setSlideSpacing(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideSpacing = float(value)
        TrayConfigModel.setSlideSpacing(self.SlideSpacing)

    def setSlideWidth(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideWidth = float(value)
        TrayConfigModel.setSlideWidth(self.SlideWidth)

    def setSlideHeight(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.SlideHeight = float(value)
        TrayConfigModel.setSlideHeight(self.SlideHeight)

    def setStep_X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X = float(value)
        TrayConfigModel.setStep_X(self.Step_X)

    def setStep_Y(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y = float(value)
        TrayConfigModel.setStep_Y(self.Step_Y)

    def setStep_X_20X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_20X = float(value)
        TrayConfigModel.setStep_X_20X(self.Step_X_20X)

    def setStep_Y_20X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_20X = float(value)
        TrayConfigModel.setStep_Y_20X(self.Step_Y_20X)

    def setStep_X_40X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_40X = float(value)
        TrayConfigModel.setStep_X_40X(self.Step_X_40X)

    def setStep_Y_40X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_40X = float(value)
        TrayConfigModel.setStep_Y_40X(self.Step_Y_40X)

    def setStep_X_100X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_X_100X = float(value)
        TrayConfigModel.setStep_X_100X(self.Step_X_100X)

    def setStep_Y_100X(self, value: (int, float)):
        if not isinstance(value, (int, float)):
            return
        from AppCore.AppDBModels.ConfigModels.TrayConfigModel import TrayConfigModel
        Locker: Qt.QReadLocker = Qt.QReadLocker(self.IOLocker)
        self.Step_Y_100X = float(value)
        TrayConfigModel.setStep_Y_100X(self.Step_Y_100X)

