import type { LiteralUnion } from 'type-fest'; import type { ExpressionSource } from '@cloudpss/expression'; import type { ArgumentMap, ConditionExpression } from '@cloudpss/expression/definitions'; import type { PinLikeParameter } from './parameter.js'; const _PinDataType = Object.freeze(['real', 'integer', 'logical', 'text'] as const); /** 引脚数据类型 */ export const PinDataType: readonly PinDataType[] = _PinDataType; /** 引脚数据类型 */ export type PinDataType = LiteralUnion<'' | (typeof _PinDataType)[number], string>; const _PinConnectionType = Object.freeze([ // EMTP 'electrical', 'input', 'output', // IES 'electricalAc', 'electricalDc', 'water', 'hotWater', 'coldWater', 'ice', 'hydrogen', 'nitrogen', 'ammonia', ] as const); /** 连接类型*/ export const PinConnectionType: readonly PinConnectionType[] = _PinConnectionType; /** 连接类型 */ export type PinConnectionType = LiteralUnion<'' | (typeof _PinConnectionType)[number], string>; /** 模型引脚定义 */ export interface PinDefinition { /** 实现阶段用于索引的键值,在整个模型中不能重复 */ key: string; /** 引脚名称 */ name: string; /** 引脚详细描述(MD) */ description: string; /** 引脚生效的条件表达式 */ condition?: ConditionExpression; /** 数据维数(目前最多两维) */ dim?: Array>; /** 是否有图形上的实际引脚与之对应 */ visible: boolean; /** 数据类型 */ data: PinDataType; /** 连接类型 */ connection: PinConnectionType; } /** 测试引脚定义 */ export function isPinDefinition(value: unknown): value is PinDefinition { if (typeof value != 'object' || value == null) return false; const v = value as PinDefinition; return ( typeof v.key === 'string' && typeof v.name === 'string' && typeof v.description == 'string' && typeof v.visible == 'boolean' ); } /** 转换为相应的参数定义 */ export function toPinLikeParameter(pin: PinDefinition): PinLikeParameter { return { ...pin, type: 'pinLike', value: '', }; } /** 未求值的引脚表 */ export type PinMap = ArgumentMap>;