48 lines
3.6 KiB
Python
48 lines
3.6 KiB
Python
|
|
"""Generate scanner palette metadata from the integrated backend route registry."""
|
||
|
|
import json
|
||
|
|
from pathlib import Path
|
||
|
|
from generate_scanner_routes import operations, ROOT
|
||
|
|
|
||
|
|
templates={
|
||
|
|
'CONNECT':{'deviceType':3}, 'CREATE_PROJECT':{'mode':'trak'},
|
||
|
|
'DISCONNECT':{'confirm':False,'discardProject':False,'expectedProjectId':None,'expectedSessionId':None},
|
||
|
|
'RECONNECT':{'confirm':False,'discardProject':False,'expectedProjectId':None,'expectedSessionId':None,'deviceType':3},
|
||
|
|
'PARAMETERS':{'pointDistance':0.2,'brightness':8}, 'MESH':{},
|
||
|
|
'EXPORT':{'formats':['STL']}, 'SNAPSHOT':{'maxPoints':100000,'include':['points','markers','meshes']},
|
||
|
|
'ALIGN':{'action':'enter'}, 'EDIT':{'projectUuid':'','markerIds':[],'confirm':False},
|
||
|
|
'CLIP_PLANE':{'center':[0,0,0],'normal':[0,0,1],'deleteBelowPoints':False,'deleteBelowMarkers':False,'confirm':False},
|
||
|
|
'CALIBRATION_MODE':{'mode':0},'CALIBRATION_TRAK':{'trakType':1,'confirm':False},
|
||
|
|
'CALIBRATION_APPLY_LAST':{'mode':0,'confirm':False},
|
||
|
|
'CALIBRATION_FREE':{'enabled':True,'confirm':False},'CALIBRATION_ADVANCED':{'enabled':True,'confirm':False},
|
||
|
|
}
|
||
|
|
labels={'deviceType':'设备类型','mode':'工程或标定模式','name':'工程或导出名称','formats':'导出格式',
|
||
|
|
'confirm':'已核对本次操作的目标和影响','discardProject':'舍弃尚未导出的内存工程',
|
||
|
|
'expectedProjectId':'已核对的工程目录编号','expectedSessionId':'已核对的设备会话编号',
|
||
|
|
'enabled':'启用','trakType':'跟踪仪标定类型'}
|
||
|
|
|
||
|
|
def main():
|
||
|
|
records=[]
|
||
|
|
for name,method,path,title,action in operations():
|
||
|
|
default=templates.get(name,{})
|
||
|
|
if name in ('CALIBRATION_START','CALIBRATION_SYSTEM','CALIBRATION_CAPTURE','CALIBRATION_COMPUTE'):default={'confirm':False}
|
||
|
|
fields=[]
|
||
|
|
if name not in ('PARAMETERS','MESH','SNAPSHOT','ALIGN','EDIT','CLIP_PLANE'):
|
||
|
|
for key in dict.fromkeys(list(default)+(['name'] if name in ('CREATE_PROJECT','EXPORT') else [])):
|
||
|
|
value=default.get(key)
|
||
|
|
kind='boolean' if isinstance(value,bool) else 'number' if isinstance(value,int) else 'array' if isinstance(value,list) else 'text'
|
||
|
|
options=None
|
||
|
|
if key=='deviceType': options=[{'value':3,'label':'单套 Trak Nova / Trak'},{'value':4,'label':'多套设备'}]
|
||
|
|
if key=='mode': options=[{'value':v,'label':str(v)} for v in (['trak','laser'] if name=='CREATE_PROJECT' else [0,1,2,3])]
|
||
|
|
if key=='trakType': options=[{'value':v,'label':label} for v,label in enumerate(['快速','标准','精细','UE Nova蓝光'])]
|
||
|
|
fields.append(dict(key=key,label=labels.get(key,key),type=kind,options=options,optional=key=='name',nullable=key.startswith('expected')))
|
||
|
|
records.append(dict(key=name,method=method,path='/metadata' if path=='/' else path.removeprefix('/api/v1'),
|
||
|
|
title=title,action=action,defaultBody=default,fields=fields,
|
||
|
|
advanced=name in ('PARAMETERS','MESH','SNAPSHOT','ALIGN','EDIT','CLIP_PLANE')))
|
||
|
|
target=ROOT/'am-web/src/cmvr/common/utils/scannerOperations.mjs'
|
||
|
|
target.write_text('// Generated from ScannerOperation.java by scripts/generate_scanner_frontend.py.\n'
|
||
|
|
+'export const SCANNER_OPERATIONS = '+json.dumps(records,ensure_ascii=False,indent=2)+'\n'
|
||
|
|
+'export const getScannerOperation = (action) => SCANNER_OPERATIONS.find((item) => item.action === action)\n',encoding='utf-8')
|
||
|
|
print(f'Generated frontend API and component metadata for {len(records)} supplier routes')
|
||
|
|
|
||
|
|
if __name__=='__main__':main()
|