#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName   : CameraColorModel.py
@Account    : Administrator
@Time       : 2025/9/12 10:15
@Author     : xsh
@Description: 
"""
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 CameraColorModel(CoreModel):
    __tablename__ = 't_CameraColorModel'
    Information                         : Mapped[str   ] = mapped_column(Text      , default=''                , nullable=True , doc='说明信息　　', comment='说明信息　　')
    Level                               : Mapped[int   ] = mapped_column(primary_key=True                      , nullable=False, doc='物镜类型　　', comment='物镜类型　　')
    BalanceRatio0                       : Mapped[float ] = mapped_column(            default= 1.56494         , nullable=True , doc='颜色比例　　', comment='颜色比例　　')
    BalanceRatio1                       : Mapped[float ] = mapped_column(            default= 1.0             , nullable=True , doc='颜色比例　　', comment='颜色比例　　')
    BalanceRatio2                       : Mapped[float ] = mapped_column(            default= 2.20166         , nullable=True , doc='颜色比例　　', comment='颜色比例　　')
    ColorTransformationValue0           : Mapped[float ] = mapped_column(            default= 1.53125         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue1           : Mapped[float ] = mapped_column(            default= -0.3125         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue2           : Mapped[float ] = mapped_column(            default= -0.21875        , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue10          : Mapped[float ] = mapped_column(            default= -0.3125         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue11          : Mapped[float ] = mapped_column(            default= 1.84375         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue12          : Mapped[float ] = mapped_column(            default= -0.53125        , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue20          : Mapped[float ] = mapped_column(            default= -0.09375        , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue21          : Mapped[float ] = mapped_column(            default= -0.4375         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')
    ColorTransformationValue22          : Mapped[float ] = mapped_column(            default= 1.53125         , nullable=True , doc='颜色转换表　', comment='颜色转换表　')

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

    def initValue(self):
        super(CameraColorModel, self).initValue()
        self.Information                            = '未知物镜相机参数　　'
        self.Level                                  = ObjectiveLevel.ObjectiveNone #
        self.BalanceRatio0                          = 1.56494                      #
        self.BalanceRatio1                          = 1.0                          #
        self.BalanceRatio2                          = 2.20166                      #
        self.ColorTransformationValue0              = 1.53125                      #
        self.ColorTransformationValue1              = -0.3125                      #
        self.ColorTransformationValue2              = -0.21875                     #
        self.ColorTransformationValue10             = -0.3125                      #
        self.ColorTransformationValue11             = 1.84375                      #
        self.ColorTransformationValue12             = -0.53125                     #
        self.ColorTransformationValue20             = -0.09375                     #
        self.ColorTransformationValue21             = -0.4375                      #
        self.ColorTransformationValue22             = 1.53125                      #

    @classmethod
    def getConfig(cls, level: int):
        _level: int = level if level in ObjectiveLevel.all() else ObjectiveLevel.ObjectiveNone
        item : cls = cls.Primary(_level)
        if not item:
            item = cls.instance()
        return item


    @classmethod
    def initModels(cls) -> list:
        """托盘XY轴和相机XY的并系为  托盘X -> 相机Y 托盘Y -> 相机X"""
        items: list[cls] = [
            cls.instance(Level            = ObjectiveLevel.Objective1    , Information      = '１　　倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.Objective10   , Information      = '１０　倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.Objective40   , Information      = '４０　倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.Objective20   , Information      = '２０　倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.Objective63   , Information      = '６３　倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.Objective100  , Information      = '１００倍物镜相机参数'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
            cls.instance(Level            = ObjectiveLevel.ObjectiveNone , Information      = '未知物镜相机参数　　'    ,  BalanceRatio0                          = 1.56494  ,BalanceRatio1                          = 1.0      ,BalanceRatio2                          = 2.20166  ,ColorTransformationValue0              = 1.53125  ,ColorTransformationValue1              = -0.3125  ,ColorTransformationValue2              = -0.21875 ,ColorTransformationValue10             = -0.3125  ,ColorTransformationValue11             = 1.84375  ,ColorTransformationValue12             = -0.53125 ,ColorTransformationValue20             = -0.09375 ,ColorTransformationValue21             = -0.4375  ,ColorTransformationValue22             = 1.53125  ),
        ]
        return items





    __field__ = (
        'Information'                  ,
        'Level'                        ,
        'BalanceRatio0'                ,
        'BalanceRatio1'                ,
        'BalanceRatio2'                ,
        'ColorTransformationValue0'    ,
        'ColorTransformationValue1'    ,
        'ColorTransformationValue2'    ,
        'ColorTransformationValue10'   ,
        'ColorTransformationValue11'   ,
        'ColorTransformationValue12'   ,
        'ColorTransformationValue20'   ,
        'ColorTransformationValue21'   ,
        'ColorTransformationValue22'   ,
    )
    __types__ = (
        str   ,
        int   ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
        float ,
    )