# Copyright (c) 2026 JSOL CORPORATION
#
# 本スクリプトはMITライセンスのもとで公開しています。
# ライセンス全文は以下を参照してください。
# https://www.jmag-international.com/jp/scriptlibrary/jmag_script_library_mit/

app = designer.GetApplication()


def getThermalModelRegionCheckItems(dimension):
    """モデルの次元に応じて確認対象の熱モデル領域を取得する。"""
    checkItems = [
        (u"stator_gap", u"ギャップ（ステータ側）"),
        (u"rotor_gap", u"ギャップ（ロータ側）"),
        (u"stator_outer", u"ステータ外周"),
        (u"rotor_inner", u"ロータ内周"),
    ]

    if dimension == 2:
        checkItems.extend([
            (u"stator_core", u"ステータコア"),
            (u"rotor_core", u"ロータコア"),
            (u"coil", u"コイル（1スロット）"),
        ])
    elif dimension == 3:
        checkItems.extend([
            (u"stator_core", u"ステータコア（前面）"),
            (u"rotor_core", u"ロータコア（前面）"),
            (u"coil", u"コイル（前面）（1スロット）"),
            (u"rear_stator_core", u"ステータコア（後面）"),
            (u"rear_rotor_core", u"ロータコア（後面）"),
            (u"rear_coil", u"コイル（後面）（1スロット）"),
        ])

    return checkItems


def checkUnassignedThermalModelRegions(thermalModelRegion, checkItems):
    """熱モデル領域の未設定項目を確認して表示する。"""
    warningExists = False
    for key, label in checkItems:
        if thermalModelRegion.HasWarning(key):
            print(u"{0} は未設定です".format(label))
            warningExists = True

    if not warningExists:
        print(u"熱モデル領域はすべて設定されています")


def main():
    """現在のスタディの熱モデル領域について未設定項目を確認する。"""
    model = app.GetCurrentModel()
    study = app.GetCurrentStudy()
    thermalModelRegion = study.GetThermalModelRegion()

    if not thermalModelRegion.IsValid():
        return

    checkItems = getThermalModelRegionCheckItems(model.GetDimension())
    checkUnassignedThermalModelRegions(thermalModelRegion, checkItems)


main()
