#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ChamberConfigModel.py
@Description：
@Author：XSH
@Time：2025/11/17 19:09
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from datetime import datetime, date
import copy
from AppCore.AppDBModels.CoreModel import (CoreModel, DBManager, dbController)
from sqlalchemy.orm import declarative_base, mapper, sessionmaker, Session
from sqlalchemy.orm import (declarative_base, Mapped, mapped_column, relationship, mapper, sessionmaker)
from sqlalchemy import Table, Engine, create_engine, Column, ForeignKey, and_, or_, insert, delete, update, select, func, ColumnElement,distinct
from sqlalchemy.types import (Text, VARCHAR, REAL, Float, Integer, String, SmallInteger, DateTime, Date, ARRAY,Boolean, JSON)
from sqlalchemy.orm.decl_api import DeclarativeBase, MetaData
from AppUtils.utils import *
from AppCore.Levels import *


class ChamberConfigModel(CoreModel):
    __tablename__ = 't_ChamberConfigModel'
    ID                              : Mapped[int    ] = mapped_column(primary_key=True                                  , nullable=False, doc='数据序号　　　　', comment='数据序号　　　　')
    AxisZHoverPosition              : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    AxisZDragPosition               : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    AxisZTraySpacing                : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    AxisHScanCodePosition           : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    AxisHScanCodeSpacing            : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    PickTrayXPosition               : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    PickTrayYPosition               : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    CheckChamberXPosition           : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    CheckChamberYPosition           : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    CheckChamberZPosition           : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    ScanningSlideXPosition          : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    ScanningSlideYPosition          : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')
    ScanningSlideXSpacing           : Mapped[float  ] = mapped_column(default=0.0                                       , nullable=True , doc='定焦距离　　　　', comment='定焦距离　　　　')


    def __init__(self, **args):
        super(ChamberConfigModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    def initValue(self):
        super(ChamberConfigModel, self).initValue()
        self.ID                              = 1            #
        self.AxisZHoverPosition              = 0.0          #
        self.AxisZDragPosition               = 0.0          #
        self.AxisZTraySpacing                = 0.0          #
        self.AxisHScanCodePosition           = 0.0          #
        self.AxisHScanCodeSpacing            = 0.0          #
        self.PickTrayXPosition               = 0.0          #
        self.PickTrayYPosition               = 0.0          #
        self.CheckChamberXPosition           = 0.0          #
        self.CheckChamberYPosition           = 0.0          #
        self.CheckChamberZPosition           = 0.0          #
        self.ScanningSlideXPosition          = 0.0          #
        self.ScanningSlideYPosition          = 0.0          #
        self.ScanningSlideXSpacing           = 0.0          #



    @classmethod
    def initModels(cls) -> list:
        return [
            cls.instance(ID                              = 1   ,AxisZHoverPosition              = 0.0 ,AxisZDragPosition               = 0.0 ,AxisZTraySpacing                = 0.0 ,AxisHScanCodePosition           = 0.0 ,AxisHScanCodeSpacing            = 0.0 ,PickTrayXPosition               = 0.0 ,PickTrayYPosition               = 0.0 ,CheckChamberXPosition           = 0.0 ,CheckChamberYPosition           = 0.0 ,CheckChamberZPosition           = 0.0 ,ScanningSlideXPosition          = 0.0 ,ScanningSlideYPosition          = 0.0 ,ScanningSlideXSpacing           = 0.0 )
        ]
    @classmethod
    def getObjectiveConfig(cls) -> 'ChamberConfigModel':
        item: cls = cls.first()
        return item

    @classmethod
    def getConfig(cls) -> 'ChamberConfigModel':
        return cls.first()

    @classmethod
    def getPickPosition_xyz(cls) -> (float, float, float):
        item: cls = cls.first()
        return item.GetPickTrayXPosition, item.GetPickTrayYPosition, item.GetCheckChamberZPosition

    @classmethod
    def getCheckPosition_xyz(cls) -> (float, float, float):
        item: cls = cls.first()
        return item.GetCheckChamberXPosition, item.GetCheckChamberYPosition, item.GetCheckChamberZPosition
    @classmethod
    def setPickPosition_xyz(cls, x: (int, float), y: (int, float), z: (int, float)):
        if isinstance(x, (int, float)) and isinstance(y, (int, float)) and isinstance(z, (int, float)):
            cls.changed({
                cls.CheckChamberXPosition : float(x),
                cls.CheckChamberYPosition : float(y),
                cls.CheckChamberZPosition : float(z),
            })


    @classmethod
    def getScanPosition_xy(cls) -> (float, float):
        item: cls = cls.first()
        return item.GetScanningSlideXPosition, item.GetScanningSlideYPosition

    @classmethod
    def setScanPosition_xyz(cls, x: (int, float), y: (int, float)):
        if isinstance(x, (int, float)) and isinstance(y, (int, float)):
            cls.changed({
                cls.ScanningSlideXPosition : float(x),
                cls.ScanningSlideYPosition : float(y),
            })

    @classmethod
    def getAxisZHoverPosition              (cls) -> float:
        item: cls = cls.first()
        return item.GetAxisZHoverPosition              #

    @classmethod
    def getAxisZDragPosition               (cls) -> float:
        item: cls = cls.first()
        return item.GetAxisZDragPosition               #

    @classmethod
    def getAxisZTraySpacing                (cls) -> float:
        item: cls = cls.first()
        return item.GetAxisZTraySpacing                #

    @classmethod
    def getAxisHScanCodePosition           (cls) -> float:
        item: cls = cls.first()
        return item.GetAxisHScanCodePosition           #

    @classmethod
    def getAxisHScanCodeSpacing            (cls) -> float:
        item: cls = cls.first()
        return item.GetAxisHScanCodeSpacing            #

    @classmethod
    def getPickTrayXPosition               (cls) -> float:
        item: cls = cls.first()
        return item.GetPickTrayXPosition               #

    @classmethod
    def getPickTrayYPosition               (cls) -> float:
        item: cls = cls.first()
        return item.GetPickTrayYPosition               #

    @classmethod
    def getCheckChamberXPosition           (cls) -> float:
        item: cls = cls.first()
        return item.GetCheckChamberXPosition           #

    @classmethod
    def getCheckChamberYPosition           (cls) -> float:
        item: cls = cls.first()
        return item.GetCheckChamberYPosition           #

    @classmethod
    def getCheckChamberZPosition           (cls) -> float:
        item: cls = cls.first()
        return item.GetCheckChamberZPosition           #

    @classmethod
    def getScanningSlideXPosition          (cls) -> float:
        item: cls = cls.first()
        return item.GetScanningSlideXPosition          #

    @classmethod
    def getScanningSlideYPosition          (cls) -> float:
        item: cls = cls.first()
        return item.GetScanningSlideYPosition          #

    @classmethod
    def getScanningSlideXSpacing           (cls) -> float:
        item: cls = cls.first()
        return item.GetScanningSlideXSpacing           #

    @classmethod
    def setAxisZHoverPosition              (cls, value: (int, float)):
        if isinstance(value, (int, float)):
                cls.changed({cls.AxisZHoverPosition              : float(value)})
    @classmethod
    def setAxisZDragPosition               (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.AxisZDragPosition               : float(value)})
    @classmethod
    def setAxisZTraySpacing                (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.AxisZTraySpacing                : float(value)})
    @classmethod
    def setAxisHScanCodePosition           (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.AxisHScanCodePosition           : float(value)})
    @classmethod
    def setAxisHScanCodeSpacing            (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.AxisHScanCodeSpacing            : float(value)})
    @classmethod
    def setPickTrayXPosition               (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.PickTrayXPosition               : float(value)})
    @classmethod
    def setPickTrayYPosition               (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.PickTrayYPosition               : float(value)})
    @classmethod
    def setCheckChamberXPosition           (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.CheckChamberXPosition           : float(value)})
    @classmethod
    def setCheckChamberYPosition           (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.CheckChamberYPosition           : float(value)})
    @classmethod
    def setCheckChamberZPosition           (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.CheckChamberZPosition           : float(value)})
    @classmethod
    def setScanningSlideXPosition          (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.ScanningSlideXPosition          : float(value)})
    @classmethod
    def setScanningSlideYPosition          (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.ScanningSlideYPosition          : float(value)})
    @classmethod
    def setScanningSlideXSpacing           (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.ScanningSlideXSpacing           : float(value)})


    def SetAxisZHoverPosition              (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.AxisZHoverPosition               = float(value)

    def SetAxisZDragPosition               (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.AxisZDragPosition                = float(value)

    def SetAxisZTraySpacing                (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.AxisZTraySpacing                 = float(value)

    def SetAxisHScanCodePosition           (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.AxisHScanCodePosition            = float(value)

    def SetAxisHScanCodeSpacing            (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.AxisHScanCodeSpacing             = float(value)

    def SetPickTrayXPosition               (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.PickTrayXPosition                = float(value)

    def SetPickTrayYPosition               (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.PickTrayYPosition                = float(value)

    def SetCheckChamberXPosition           (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.CheckChamberXPosition            = float(value)

    def SetCheckChamberYPosition           (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.CheckChamberYPosition            = float(value)

    def SetCheckChamberZPosition           (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.CheckChamberZPosition            = float(value)

    def SetScanningSlideXPosition          (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.ScanningSlideXPosition           = float(value)

    def SetScanningSlideYPosition          (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.ScanningSlideYPosition           = float(value)

    def SetScanningSlideXSpacing           (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.ScanningSlideXSpacing            = float(value)

    @property
    def GetAxisZHoverPosition              (self) -> float:
        return None if not self.hasAxisZHoverPosition              else self.AxisZHoverPosition

    @property
    def GetAxisZDragPosition               (self) -> float:
        return None if not self.hasAxisZDragPosition               else self.AxisZDragPosition

    @property
    def GetAxisZTraySpacing                (self) -> float:
        return None if not self.hasAxisZTraySpacing                else self.AxisZTraySpacing

    @property
    def GetAxisHScanCodePosition           (self) -> float:
        return None if not self.hasAxisHScanCodePosition           else self.AxisHScanCodePosition

    @property
    def GetAxisHScanCodeSpacing            (self) -> float:
        return None if not self.hasAxisHScanCodeSpacing            else self.AxisHScanCodeSpacing

    @property
    def GetPickTrayXPosition               (self) -> float:
        return None if not self.hasPickTrayXPosition               else self.PickTrayXPosition

    @property
    def GetPickTrayYPosition               (self) -> float:
        return None if not self.hasPickTrayYPosition               else self.PickTrayYPosition

    @property
    def GetCheckChamberXPosition           (self) -> float:
        return None if not self.hasCheckChamberXPosition           else self.CheckChamberXPosition

    @property
    def GetCheckChamberYPosition           (self) -> float:
        return None if not self.hasCheckChamberYPosition           else self.CheckChamberYPosition

    @property
    def GetCheckChamberZPosition           (self) -> float:
        return None if not self.hasCheckChamberZPosition           else self.CheckChamberZPosition

    @property
    def GetScanningSlideXPosition          (self) -> float:
        return None if not self.hasScanningSlideXPosition          else self.ScanningSlideXPosition

    @property
    def GetScanningSlideYPosition          (self) -> float:
        return None if not self.hasScanningSlideYPosition          else self.ScanningSlideYPosition

    @property
    def GetScanningSlideXSpacing           (self) -> float:
        return None if not self.hasScanningSlideXSpacing           else self.ScanningSlideXSpacing

    @property
    def hasAxisZHoverPosition              (self) -> bool:
        return hasattr(self, 'AxisZHoverPosition'     ) and isinstance(self.AxisZHoverPosition              , (int, float))

    @property
    def hasAxisZDragPosition               (self) -> bool:
        return hasattr(self, 'AxisZDragPosition'      ) and isinstance(self.AxisZDragPosition               , (int, float))

    @property
    def hasAxisZTraySpacing                (self) -> bool:
        return hasattr(self, 'AxisZTraySpacing'       ) and isinstance(self.AxisZTraySpacing                , (int, float))

    @property
    def hasAxisHScanCodePosition           (self) -> bool:
        return hasattr(self, 'AxisHScanCodePosition'  ) and isinstance(self.AxisHScanCodePosition           , (int, float))

    @property
    def hasAxisHScanCodeSpacing            (self) -> bool:
        return hasattr(self, 'AxisHScanCodeSpacing'   ) and isinstance(self.AxisHScanCodeSpacing            , (int, float))

    @property
    def hasPickTrayXPosition               (self) -> bool:
        return hasattr(self, 'PickTrayXPosition'      ) and isinstance(self.PickTrayXPosition               , (int, float))

    @property
    def hasPickTrayYPosition               (self) -> bool:
        return hasattr(self, 'PickTrayYPosition'      ) and isinstance(self.PickTrayYPosition               , (int, float))

    @property
    def hasCheckChamberXPosition           (self) -> bool:
        return hasattr(self, 'CheckChamberXPosition'  ) and isinstance(self.CheckChamberXPosition           , (int, float))

    @property
    def hasCheckChamberYPosition           (self) -> bool:
        return hasattr(self, 'CheckChamberYPosition'  ) and isinstance(self.CheckChamberYPosition           , (int, float))

    @property
    def hasCheckChamberZPosition           (self) -> bool:
        return hasattr(self, 'CheckChamberZPosition'  ) and isinstance(self.CheckChamberZPosition           , (int, float))

    @property
    def hasScanningSlideXPosition          (self) -> bool:
        return hasattr(self, 'ScanningSlideXPosition' ) and isinstance(self.ScanningSlideXPosition          , (int, float))

    @property
    def hasScanningSlideYPosition          (self) -> bool:
        return hasattr(self, 'ScanningSlideYPosition' ) and isinstance(self.ScanningSlideYPosition          , (int, float))

    @property
    def hasScanningSlideXSpacing           (self) -> bool:
        return hasattr(self, 'ScanningSlideXSpacing'  ) and isinstance(self.ScanningSlideXSpacing           , (int, float))










