vtkviewer-vue 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +753 -0
- package/README.md +1760 -0
- package/lib/types/components/PluginToolbar.vue.d.ts +7 -0
- package/lib/types/components/ToolbarExtension.vue.d.ts +9 -0
- package/lib/types/components/ToolbarInfoPanel.vue.d.ts +10 -0
- package/lib/types/components/VtkViewer.vue.d.ts +32 -0
- package/lib/types/components/index.d.ts +4 -0
- package/lib/types/composables/index.d.ts +7 -0
- package/lib/types/composables/useFormatLoader.d.ts +33 -0
- package/lib/types/composables/useResponsiveLayout.d.ts +46 -0
- package/lib/types/composables/useUIPlugins.d.ts +57 -0
- package/lib/types/composables/useViewer.d.ts +47 -0
- package/lib/types/configs/index.d.ts +76 -0
- package/lib/types/core/CommandRegistrar.d.ts +12 -0
- package/lib/types/core/CommandRegistry.d.ts +34 -0
- package/lib/types/core/ConfigAccessor.d.ts +33 -0
- package/lib/types/core/DisposalRegistry.d.ts +32 -0
- package/lib/types/core/EventBus.d.ts +79 -0
- package/lib/types/core/FormatDetector.d.ts +59 -0
- package/lib/types/core/I18nManager.d.ts +135 -0
- package/lib/types/core/InteractionSubContext.d.ts +73 -0
- package/lib/types/core/RenderSubContext.d.ts +74 -0
- package/lib/types/core/ResetManager.d.ts +122 -0
- package/lib/types/core/ResetRegistry.d.ts +170 -0
- package/lib/types/core/SceneSubContext.d.ts +25 -0
- package/lib/types/core/StateManager.d.ts +104 -0
- package/lib/types/core/ThemeContext.d.ts +37 -0
- package/lib/types/core/ToolbarExtensionRegistry.d.ts +105 -0
- package/lib/types/core/ToolbarInfoRegistry.d.ts +77 -0
- package/lib/types/core/UISubContext.d.ts +32 -0
- package/lib/types/core/ViewerContext.d.ts +101 -0
- package/lib/types/core/ViewerContextBuilder.d.ts +57 -0
- package/lib/types/core/createViewerContext.d.ts +26 -0
- package/lib/types/core/index.d.ts +23 -0
- package/lib/types/icons/index.d.ts +47 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/plugins/PluginBase.d.ts +131 -0
- package/lib/types/plugins/PluginRegistry.d.ts +67 -0
- package/lib/types/plugins/defaults.d.ts +3 -0
- package/lib/types/plugins/format/DrcPlugin.d.ts +30 -0
- package/lib/types/plugins/format/GlbPlugin.d.ts +23 -0
- package/lib/types/plugins/format/ObjPlugin.d.ts +23 -0
- package/lib/types/plugins/format/PdbPlugin.d.ts +33 -0
- package/lib/types/plugins/format/PlyPlugin.d.ts +24 -0
- package/lib/types/plugins/format/StlPlugin.d.ts +25 -0
- package/lib/types/plugins/format/VtiPlugin.d.ts +60 -0
- package/lib/types/plugins/format/VtpPlugin.d.ts +24 -0
- package/lib/types/plugins/format/VtuPlugin.d.ts +25 -0
- package/lib/types/plugins/format/ZipPlugin.d.ts +38 -0
- package/lib/types/plugins/format/index.d.ts +13 -0
- package/lib/types/plugins/index.d.ts +13 -0
- package/lib/types/plugins/injectionKeys.d.ts +22 -0
- package/lib/types/plugins/pluginUtils.d.ts +61 -0
- package/lib/types/plugins/service/DragDropPlugin.d.ts +94 -0
- package/lib/types/plugins/service/KeyBindingPlugin.d.ts +83 -0
- package/lib/types/plugins/service/MemoryPressurePlugin.d.ts +68 -0
- package/lib/types/plugins/service/index.d.ts +6 -0
- package/lib/types/plugins/toolbar/animation/AnimationPlugin.d.ts +34 -0
- package/lib/types/plugins/toolbar/animation/index.d.ts +1 -0
- package/lib/types/plugins/toolbar/index.d.ts +9 -0
- package/lib/types/plugins/toolbar/interaction/CenterModelPlugin.d.ts +21 -0
- package/lib/types/plugins/toolbar/interaction/FullscreenPlugin.d.ts +27 -0
- package/lib/types/plugins/toolbar/interaction/PanPlugin.d.ts +24 -0
- package/lib/types/plugins/toolbar/interaction/ResetAllPlugin.d.ts +25 -0
- package/lib/types/plugins/toolbar/interaction/RotatePlugin.d.ts +24 -0
- package/lib/types/plugins/toolbar/interaction/ViewSelectPlugin.d.ts +26 -0
- package/lib/types/plugins/toolbar/interaction/ZoomPlugin.d.ts +24 -0
- package/lib/types/plugins/toolbar/interaction/index.d.ts +7 -0
- package/lib/types/plugins/toolbar/model/ClippingPlugin.d.ts +87 -0
- package/lib/types/plugins/toolbar/model/ColorByPlugin.d.ts +113 -0
- package/lib/types/plugins/toolbar/model/LoadModelPlugin.d.ts +93 -0
- package/lib/types/plugins/toolbar/model/RenderPrecisionPlugin.d.ts +68 -0
- package/lib/types/plugins/toolbar/model/RenderStylePlugin.d.ts +88 -0
- package/lib/types/plugins/toolbar/model/UnloadModelPlugin.d.ts +25 -0
- package/lib/types/plugins/toolbar/model/index.d.ts +6 -0
- package/lib/types/plugins/toolbar/scene/AxesPlugin.d.ts +96 -0
- package/lib/types/plugins/toolbar/scene/BackgroundColorPlugin.d.ts +25 -0
- package/lib/types/plugins/toolbar/scene/LanguageSwitchPlugin.d.ts +45 -0
- package/lib/types/plugins/toolbar/scene/LightIntensityPlugin.d.ts +42 -0
- package/lib/types/plugins/toolbar/scene/RenderGridPlugin.d.ts +98 -0
- package/lib/types/plugins/toolbar/scene/ThemeSwitchPlugin.d.ts +49 -0
- package/lib/types/plugins/toolbar/scene/index.d.ts +6 -0
- package/lib/types/plugins/toolbar/tools/BookmarkPlugin.d.ts +70 -0
- package/lib/types/plugins/toolbar/tools/MeasurementPlugin.d.ts +112 -0
- package/lib/types/plugins/toolbar/tools/PerformancePlugin.d.ts +55 -0
- package/lib/types/plugins/toolbar/tools/ScreenshotPlugin.d.ts +58 -0
- package/lib/types/plugins/toolbar/tools/index.d.ts +4 -0
- package/lib/types/plugins/toolbar/utils.d.ts +67 -0
- package/lib/types/plugins/types/index.d.ts +250 -0
- package/lib/types/plugins/ui/ErrorPlugin.d.ts +30 -0
- package/lib/types/plugins/ui/FilenameInfoPlugin.d.ts +40 -0
- package/lib/types/plugins/ui/LoadingPlugin.d.ts +28 -0
- package/lib/types/plugins/ui/SceneTreePlugin.d.ts +60 -0
- package/lib/types/plugins/ui/WebGLContextLostPlugin.d.ts +33 -0
- package/lib/types/plugins/ui/index.d.ts +8 -0
- package/lib/types/polyfills.d.ts +1 -0
- package/lib/types/types/index.d.ts +187 -0
- package/lib/types/types/vtk-modules.d.ts +80 -0
- package/lib/types/utils/asyncUtils.d.ts +8 -0
- package/lib/types/utils/colorByUtils.d.ts +55 -0
- package/lib/types/utils/debugLog.d.ts +13 -0
- package/lib/types/utils/errorHandler.d.ts +28 -0
- package/lib/types/utils/index.d.ts +10 -0
- package/lib/types/utils/sceneUtils.d.ts +11 -0
- package/lib/types/utils/themeManager.d.ts +78 -0
- package/lib/types/utils/volumeUtils.d.ts +14 -0
- package/lib/types/utils/vtkHelpers.d.ts +46 -0
- package/lib/types/utils/vtuLoader.d.ts +26 -0
- package/lib/types/utils/zipReader.d.ts +71 -0
- package/lib/vtkviewer.css +2 -0
- package/lib/vtkviewer.js +54714 -0
- package/lib/vtkviewer.umd.cjs +4560 -0
- package/package.json +89 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* i18n 翻译函数签名。
|
|
4
|
+
* 与 vue-i18n / i18next / react-intl 的 t() 签名兼容。
|
|
5
|
+
*
|
|
6
|
+
* @param key 翻译 key
|
|
7
|
+
* @returns 翻译后的字符串;未找到对应 key 时返回 key 自身
|
|
8
|
+
*/
|
|
9
|
+
export type I18nTranslateFunction = (key: string) => string;
|
|
10
|
+
/** 语言选项(对应 UI 下拉菜单中的语言条目) */
|
|
11
|
+
export interface LanguageOption {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class I18nManager {
|
|
16
|
+
/** 当前语言(单一数据源) */
|
|
17
|
+
readonly currentLocale: Ref<string>;
|
|
18
|
+
/**
|
|
19
|
+
* 翻译状态变更版号。
|
|
20
|
+
* _externalT / _packs 不是响应式的,通过此 ref 让 computed 感知它们的变化。
|
|
21
|
+
* 每次 setExternalTranslator() 或 registerLocale() 时递增。
|
|
22
|
+
*/
|
|
23
|
+
private _stateVersion;
|
|
24
|
+
/** 外部注入的翻译函数(null = 无外部注入,走内置包) */
|
|
25
|
+
private _externalT;
|
|
26
|
+
/** 语言包注册表(locale → { key → value }) */
|
|
27
|
+
private _packs;
|
|
28
|
+
/**
|
|
29
|
+
* 默认语言标识。
|
|
30
|
+
* 由 VtkViewer 根据 props.locale 设置;未传 props.locale 时为 'zh'。
|
|
31
|
+
* 用于 reset 操作恢复初始语言。
|
|
32
|
+
*/
|
|
33
|
+
private _defaultLocale;
|
|
34
|
+
/** UI 语言选项列表(下拉菜单可用语言) */
|
|
35
|
+
private _languageOptions;
|
|
36
|
+
/** locale 变更回调列表 */
|
|
37
|
+
private _localeCallbacks;
|
|
38
|
+
/** 是否已销毁 */
|
|
39
|
+
private _disposed;
|
|
40
|
+
constructor();
|
|
41
|
+
/**
|
|
42
|
+
* 设置/清除外部翻译函数。
|
|
43
|
+
*
|
|
44
|
+
* - 传入函数:后续 translate() 优先调用此函数
|
|
45
|
+
* - 传入 null:清除外部函数,完全回退内置包
|
|
46
|
+
*
|
|
47
|
+
* 外部函数的约定:
|
|
48
|
+
* - 找到翻译 → 返回翻译后的字符串
|
|
49
|
+
* - 未找到 → 返回 key 自身(不要返回 '' 或 undefined)
|
|
50
|
+
*/
|
|
51
|
+
setExternalTranslator(fn: I18nTranslateFunction | null): void;
|
|
52
|
+
/**
|
|
53
|
+
* 命令式翻译快照。
|
|
54
|
+
*
|
|
55
|
+
* 每次调用返回当前 locale 下的翻译结果。
|
|
56
|
+
* 适用场景:非 Vue 上下文(工具函数、throw Error、console、DOM 操作)。
|
|
57
|
+
*
|
|
58
|
+
* @param key 翻译 key
|
|
59
|
+
* @returns 翻译后的字符串
|
|
60
|
+
*/
|
|
61
|
+
translate(key: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* 响应式翻译 computed。
|
|
64
|
+
*
|
|
65
|
+
* 返回 ComputedRef,在 Vue 的 computed/render 函数中使用时
|
|
66
|
+
* 自动追踪 currentLocale 变化,locale 切换后自动重求值。
|
|
67
|
+
*
|
|
68
|
+
* 适用场景:Vue render 函数、computed 属性、模板绑定。
|
|
69
|
+
*
|
|
70
|
+
* @param key 翻译 key
|
|
71
|
+
* @returns ComputedRef<string>
|
|
72
|
+
*/
|
|
73
|
+
t(key: string): ComputedRef<string>;
|
|
74
|
+
/**
|
|
75
|
+
* 切换语言,触发所有响应式依赖更新。
|
|
76
|
+
* 同时同步通知 onLocaleChanged 注册的回调。
|
|
77
|
+
*/
|
|
78
|
+
setLocale(locale: string): void;
|
|
79
|
+
/**
|
|
80
|
+
* 设置默认语言(由 VtkViewer 根据 props.locale 调用)。
|
|
81
|
+
* 只记录默认值,不切换当前语言。
|
|
82
|
+
*/
|
|
83
|
+
setDefaultLocale(locale: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* 重置到默认语言。
|
|
86
|
+
* 由 LanguageSwitchPlugin 响应 ResetManager 或类似重置操作时调用。
|
|
87
|
+
*/
|
|
88
|
+
resetLocale(): void;
|
|
89
|
+
/** 注册/覆盖语言包 */
|
|
90
|
+
registerLocale(locale: string, pack: Record<string, string>): void;
|
|
91
|
+
/** 获取已注册的语言包 locale 列表 */
|
|
92
|
+
getAvailableLocales(): string[];
|
|
93
|
+
/**
|
|
94
|
+
* 设置 UI 语言选项列表(下拉菜单中显示的语言条目)。
|
|
95
|
+
* 传入空数组或不传则重置为内置默认 zh/en。
|
|
96
|
+
*/
|
|
97
|
+
setLanguageOptions(opts?: LanguageOption[]): void;
|
|
98
|
+
/** 获取 UI 语言选项列表 */
|
|
99
|
+
getLanguageOptions(): LanguageOption[];
|
|
100
|
+
/**
|
|
101
|
+
* 注册 locale 变更回调。
|
|
102
|
+
* 与 EventBus 不同,此回调不经过事件总线,
|
|
103
|
+
* 直接在 currentLocale ref 变化时同步触发。
|
|
104
|
+
*
|
|
105
|
+
* @returns 取消注册函数
|
|
106
|
+
*/
|
|
107
|
+
onLocaleChanged(callback: (locale: string) => void): () => void;
|
|
108
|
+
/** 销毁实例,释放回调引用(测试/多实例场景) */
|
|
109
|
+
dispose(): void;
|
|
110
|
+
/**
|
|
111
|
+
* 翻译查找核心逻辑。
|
|
112
|
+
*
|
|
113
|
+
* 优先级链:
|
|
114
|
+
* 1. 外部注入的 t(key) — 不返回 key 自身 → 使用
|
|
115
|
+
* 2. currentLocale 内置包 — key 存在 → 使用
|
|
116
|
+
* 3. 默认 locale (zh) 内置包 — key 存在 → 使用
|
|
117
|
+
* 4. key 自身 — fallback → 返回 key
|
|
118
|
+
*/
|
|
119
|
+
private _lookup;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 获取全局 I18nManager 单例。
|
|
123
|
+
*
|
|
124
|
+
* 默认场景(单一查看器实例)直接使用此函数。
|
|
125
|
+
* 多实例场景可通过 new I18nManager() 创建独立实例。
|
|
126
|
+
*/
|
|
127
|
+
export declare function getI18nManager(): I18nManager;
|
|
128
|
+
/**
|
|
129
|
+
* 便捷:全局单例的直接引用。
|
|
130
|
+
*
|
|
131
|
+
* 模块加载时即创建,可在任何 .ts 文件中直接 import 使用:
|
|
132
|
+
* import { i18n } from '../core/I18nManager'
|
|
133
|
+
* const text = i18n.translate('vtkviewer.plugin.rotate.name')
|
|
134
|
+
*/
|
|
135
|
+
export declare const i18n: I18nManager;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 交互子上下文
|
|
3
|
+
* 管理用户交互工具(旋转、缩放、平移等)
|
|
4
|
+
*/
|
|
5
|
+
/** 交互配置 */
|
|
6
|
+
export interface InteractionConfig {
|
|
7
|
+
rotate?: boolean;
|
|
8
|
+
zoom?: boolean;
|
|
9
|
+
pan?: boolean;
|
|
10
|
+
keyboardControl?: boolean;
|
|
11
|
+
gesture?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** 操纵器类型 */
|
|
14
|
+
export type ManipulatorType = 'rotate' | 'zoom' | 'pan' | 'gesture' | 'keyboard';
|
|
15
|
+
/** 操纵器配置 */
|
|
16
|
+
export interface ManipulatorConfig {
|
|
17
|
+
/** 鼠标按钮(0=左键, 1=中键, 2=右键, -1=滚轮) */
|
|
18
|
+
button?: number;
|
|
19
|
+
/** 是否启用拖拽 */
|
|
20
|
+
dragEnabled?: boolean;
|
|
21
|
+
/** 是否启用滚动 */
|
|
22
|
+
scrollEnabled?: boolean;
|
|
23
|
+
/** 键盘按键列表 */
|
|
24
|
+
keys?: string[];
|
|
25
|
+
/** 手势类型 */
|
|
26
|
+
gestureType?: 'pinch' | 'rotate' | 'pan';
|
|
27
|
+
/** 自定义配置 */
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 交互子上下文接口
|
|
32
|
+
* 提供交互工具的开关、状态查询和高级配置能力
|
|
33
|
+
*/
|
|
34
|
+
export interface InteractionSubContext {
|
|
35
|
+
/** 初始化 VTK.js 交互管线(在渲染窗口可用后调用) */
|
|
36
|
+
init(): void;
|
|
37
|
+
/** 获取所有工具的启用状态 */
|
|
38
|
+
getEnabledTools(): {
|
|
39
|
+
rotate: boolean;
|
|
40
|
+
zoom: boolean;
|
|
41
|
+
pan: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** 查询指定工具是否启用 */
|
|
44
|
+
isEnabled(tool: string): boolean;
|
|
45
|
+
/** 切换工具启用状态 */
|
|
46
|
+
toggleTool(tool: string): void;
|
|
47
|
+
/** 设置工具启用状态 */
|
|
48
|
+
setToolEnabled(tool: string, enabled: boolean): void;
|
|
49
|
+
/** 批量更新交互配置 */
|
|
50
|
+
updateInteraction(config: InteractionConfig): void;
|
|
51
|
+
/** 键盘控制是否启用 */
|
|
52
|
+
isKeyboardControlEnabled(): boolean;
|
|
53
|
+
/** 切换键盘控制 */
|
|
54
|
+
toggleKeyboardControl(): void;
|
|
55
|
+
/** 手势是否启用 */
|
|
56
|
+
isGestureEnabled(): boolean;
|
|
57
|
+
/** 是否为触屏设备 */
|
|
58
|
+
isTouchDevice(): boolean;
|
|
59
|
+
/** 获取指定类型的操纵器实例 */
|
|
60
|
+
getManipulator(type: ManipulatorType): any | null;
|
|
61
|
+
/** 配置指定类型的操纵器参数 */
|
|
62
|
+
configureManipulator(type: ManipulatorType, config: ManipulatorConfig): void;
|
|
63
|
+
/** 重置操纵器到默认配置 */
|
|
64
|
+
resetManipulator(type: ManipulatorType): void;
|
|
65
|
+
/** 重置所有操纵器到默认配置 */
|
|
66
|
+
resetAllManipulators(): void;
|
|
67
|
+
/** 获取当前交互配置快照 */
|
|
68
|
+
getInteractionSnapshot(): InteractionConfig & {
|
|
69
|
+
manipulators: Record<ManipulatorType, ManipulatorConfig>;
|
|
70
|
+
};
|
|
71
|
+
/** 释放所有 VTK.js 交互资源 */
|
|
72
|
+
dispose(): void;
|
|
73
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { vtkRenderWindow } from '@kitware/vtk.js/Rendering/Core/RenderWindow';
|
|
2
|
+
import { vtkRenderer } from '@kitware/vtk.js/Rendering/Core/Renderer';
|
|
3
|
+
import { vtkCamera } from '@kitware/vtk.js/Rendering/Core/Camera';
|
|
4
|
+
/** 相机预设 */
|
|
5
|
+
export type CameraPreset = 'front' | 'back' | 'left' | 'right' | 'top' | 'bottom' | 'iso';
|
|
6
|
+
/** 相机状态(含投影模式、视场角、平行缩放) */
|
|
7
|
+
export interface CameraState {
|
|
8
|
+
position: [number, number, number];
|
|
9
|
+
focalPoint: [number, number, number];
|
|
10
|
+
viewUp: [number, number, number];
|
|
11
|
+
/** 是否为平行投影(正交投影) */
|
|
12
|
+
parallelProjection?: boolean;
|
|
13
|
+
/** 平行投影缩放比例 */
|
|
14
|
+
parallelScale?: number;
|
|
15
|
+
/** 透视投影视场角(度) */
|
|
16
|
+
viewAngle?: number;
|
|
17
|
+
}
|
|
18
|
+
/** 截图选项 */
|
|
19
|
+
export interface ScreenshotOptions {
|
|
20
|
+
/** 截图格式 */
|
|
21
|
+
format?: 'png' | 'jpeg' | 'webp';
|
|
22
|
+
/** 图片质量 (0-1) */
|
|
23
|
+
quality?: number;
|
|
24
|
+
/** 自定义宽度(像素),优先级高于 multiplier */
|
|
25
|
+
width?: number;
|
|
26
|
+
/** 自定义高度(像素),优先级高于 multiplier */
|
|
27
|
+
height?: number;
|
|
28
|
+
/** 倍率(1x/2x/4x),基于当前视口尺寸计算 */
|
|
29
|
+
multiplier?: 1 | 2 | 4;
|
|
30
|
+
/** 是否透明背景 */
|
|
31
|
+
transparentBackground?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 渲染子上下文接口
|
|
35
|
+
* 提供 VTK.js 渲染管线的访问能力
|
|
36
|
+
*/
|
|
37
|
+
export interface RenderSubContext {
|
|
38
|
+
/** 获取渲染窗口 */
|
|
39
|
+
getRenderWindow(): vtkRenderWindow | null;
|
|
40
|
+
/** 获取渲染器 */
|
|
41
|
+
getRenderer(): vtkRenderer | null;
|
|
42
|
+
/** 获取相机 */
|
|
43
|
+
getCamera(): vtkCamera | null;
|
|
44
|
+
/** 获取交互器(来自 GenericRenderWindow,用于 OrientationMarkerWidget 等需要交互器的组件) */
|
|
45
|
+
getInteractor(): any | null;
|
|
46
|
+
/** 获取容器元素 */
|
|
47
|
+
getContainer(): HTMLElement | null;
|
|
48
|
+
/** 渲染器是否就绪 */
|
|
49
|
+
isReady(): boolean;
|
|
50
|
+
/** WebGL上下文是否丢失 */
|
|
51
|
+
isContextLost(): boolean;
|
|
52
|
+
/** 触发渲染 */
|
|
53
|
+
render(): void;
|
|
54
|
+
/** 重置相机(仅适配场景范围,不改变视角方向) */
|
|
55
|
+
resetCamera(): void;
|
|
56
|
+
/** 重置到默认视图(重置相机位置+视角+裁剪范围,用于加载新模型或重置所有) */
|
|
57
|
+
resetToDefaultView(): void;
|
|
58
|
+
/** 保存当前相机状态作为初始状态(模型加载后调用) */
|
|
59
|
+
saveInitialCameraState(): void;
|
|
60
|
+
/** 清除保存的初始相机状态(场景清除时调用) */
|
|
61
|
+
clearInitialCameraState(): void;
|
|
62
|
+
/** 设置相机预设视角 */
|
|
63
|
+
setCameraView(preset: CameraPreset): void;
|
|
64
|
+
/** 保存相机状态 */
|
|
65
|
+
saveCameraState(): CameraState;
|
|
66
|
+
/** 恢复相机状态 */
|
|
67
|
+
restoreCameraState(state: CameraState): void;
|
|
68
|
+
/** 将渲染管线附加到DOM容器(创建Canvas并初始化WebGL) */
|
|
69
|
+
attachToContainer(container: HTMLElement): void;
|
|
70
|
+
/** 通知 VTK.js 容器尺寸已变化,触发 Canvas 重新测量并渲染 */
|
|
71
|
+
resize(): void;
|
|
72
|
+
/** 释放所有VTK.js资源(销毁渲染窗口、渲染器等) */
|
|
73
|
+
dispose(): void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { EventBus } from './EventBus';
|
|
2
|
+
import { ResetScope, ResetRegistry } from './ResetRegistry';
|
|
3
|
+
/** 重置级别 */
|
|
4
|
+
export declare enum ResetLevel {
|
|
5
|
+
/** 软重置:仅重置插件内部状态,保留配置 */
|
|
6
|
+
SOFT = "soft",
|
|
7
|
+
/** 硬重置:重置所有状态,恢复默认配置 */
|
|
8
|
+
HARD = "hard",
|
|
9
|
+
/** 完全重置:重置状态并重新初始化 */
|
|
10
|
+
FULL = "full"
|
|
11
|
+
}
|
|
12
|
+
/** 重置上下文 */
|
|
13
|
+
export interface ResetContext {
|
|
14
|
+
/** 重置级别 */
|
|
15
|
+
level: ResetLevel;
|
|
16
|
+
/** 触发重置的来源 */
|
|
17
|
+
source: string;
|
|
18
|
+
/** 重置时间戳 */
|
|
19
|
+
timestamp: number;
|
|
20
|
+
/** 额外参数 */
|
|
21
|
+
params?: Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
/** 重置结果 */
|
|
24
|
+
export interface ResetResult {
|
|
25
|
+
/** 插件 ID */
|
|
26
|
+
pluginId: string;
|
|
27
|
+
/** 是否成功 */
|
|
28
|
+
success: boolean;
|
|
29
|
+
/** 耗时(毫秒) */
|
|
30
|
+
duration: number;
|
|
31
|
+
/** 错误信息 */
|
|
32
|
+
error?: Error;
|
|
33
|
+
}
|
|
34
|
+
/** 重置报告 */
|
|
35
|
+
export interface ResetReport {
|
|
36
|
+
/** 总插件数 */
|
|
37
|
+
total: number;
|
|
38
|
+
/** 成功数 */
|
|
39
|
+
succeeded: number;
|
|
40
|
+
/** 失败数 */
|
|
41
|
+
failed: number;
|
|
42
|
+
/** 跳过数(未实现重置) */
|
|
43
|
+
skipped: number;
|
|
44
|
+
/** 总耗时(毫秒) */
|
|
45
|
+
totalDuration: number;
|
|
46
|
+
/** 各插件结果 */
|
|
47
|
+
results: ResetResult[];
|
|
48
|
+
}
|
|
49
|
+
/** 重置管理器配置 */
|
|
50
|
+
export interface ResetManagerConfig {
|
|
51
|
+
/** 单个插件重置超时时间(毫秒) */
|
|
52
|
+
pluginTimeout: number;
|
|
53
|
+
/** 是否在单个插件失败时继续执行 */
|
|
54
|
+
continueOnError: boolean;
|
|
55
|
+
/** 是否记录详细日志 */
|
|
56
|
+
verbose: boolean;
|
|
57
|
+
/** 重置前延迟(毫秒),用于防抖 */
|
|
58
|
+
debounceMs: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 重置管理器
|
|
62
|
+
* 对外提供统一的重置 API,内部完全委托 ResetRegistry
|
|
63
|
+
*/
|
|
64
|
+
export declare class ResetManager {
|
|
65
|
+
private config;
|
|
66
|
+
private eventBus;
|
|
67
|
+
private resetRegistry;
|
|
68
|
+
private debounceTimer;
|
|
69
|
+
constructor(eventBus: EventBus, resetRegistry: ResetRegistry, config?: Partial<ResetManagerConfig>);
|
|
70
|
+
/**
|
|
71
|
+
* 执行全局重置
|
|
72
|
+
* 只执行 scope 包含 GLOBAL 的动作,INDEPENDENT 动作不受影响
|
|
73
|
+
*/
|
|
74
|
+
resetAll(level?: ResetLevel, source?: string, params?: Record<string, any>): Promise<ResetReport>;
|
|
75
|
+
/**
|
|
76
|
+
* 精准触发指定插件的指定重置动作
|
|
77
|
+
* 与全局 resetAll 完全解耦
|
|
78
|
+
*
|
|
79
|
+
* @param pluginId 目标插件 ID
|
|
80
|
+
* @param actionName 动作名称(省略则使用默认动作)
|
|
81
|
+
* @param level 重置级别
|
|
82
|
+
* @param source 触发来源
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* // 清除测量数据(不触发全局重置)
|
|
86
|
+
* resetManager.invoke('measurement', 'clear')
|
|
87
|
+
*
|
|
88
|
+
* // 使用插件默认动作
|
|
89
|
+
* resetManager.invoke('cuttingPlane')
|
|
90
|
+
*/
|
|
91
|
+
invoke(pluginId: string, actionName?: string, level?: ResetLevel, source?: string): Promise<ResetResult>;
|
|
92
|
+
/**
|
|
93
|
+
* 按作用域批量触发重置
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // 清理所有"非全局"的插件状态(如切换模型时)
|
|
97
|
+
* resetManager.invokeByScope(ResetScope.INDEPENDENT)
|
|
98
|
+
*/
|
|
99
|
+
invokeByScope(scope: ResetScope, level?: ResetLevel, source?: string): Promise<ResetResult[]>;
|
|
100
|
+
/**
|
|
101
|
+
* 获取指定插件的所有可用重置动作
|
|
102
|
+
* 用于 UI 展示"可重置"菜单
|
|
103
|
+
*/
|
|
104
|
+
getAvailableActions(pluginId: string): Array<{
|
|
105
|
+
name: string;
|
|
106
|
+
description?: string;
|
|
107
|
+
scope: ResetScope;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* 获取所有已注册重置动作的插件列表
|
|
111
|
+
*/
|
|
112
|
+
getResettablePluginIds(): string[];
|
|
113
|
+
/**
|
|
114
|
+
* 执行重置(带防抖)
|
|
115
|
+
*/
|
|
116
|
+
private debounceReset;
|
|
117
|
+
/**
|
|
118
|
+
* 执行实际重置逻辑
|
|
119
|
+
* 通过 ResetRegistry 执行所有全局作用域动作
|
|
120
|
+
*/
|
|
121
|
+
private executeReset;
|
|
122
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { PluginRegistry, IViewerPlugin } from '../plugins';
|
|
2
|
+
import { EventBus } from './EventBus';
|
|
3
|
+
import { ResetLevel, ResetContext, ResetResult } from './ResetManager';
|
|
4
|
+
/**
|
|
5
|
+
* 重置作用域
|
|
6
|
+
* 决定一个重置动作在哪些场景下被触发
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ResetScope {
|
|
9
|
+
/**
|
|
10
|
+
* 全局作用域:参与 resetAll 流程
|
|
11
|
+
* 典型场景:相机重置、工具状态恢复默认
|
|
12
|
+
*/
|
|
13
|
+
GLOBAL = "global",
|
|
14
|
+
/**
|
|
15
|
+
* 独立作用域:不参与 resetAll,只能被显式调用
|
|
16
|
+
* 典型场景:清除测量数据、重置动画状态、重置特定 UI 面板
|
|
17
|
+
*/
|
|
18
|
+
INDEPENDENT = "independent",
|
|
19
|
+
/**
|
|
20
|
+
* 条件作用域:仅在条件满足时参与 resetAll
|
|
21
|
+
* 典型场景:仅当模型已加载时才重置切割平面、仅当标注存在时才清除标注
|
|
22
|
+
*/
|
|
23
|
+
CONDITIONAL = "conditional"
|
|
24
|
+
}
|
|
25
|
+
/** 重置动作守卫条件 */
|
|
26
|
+
export interface ResetGuard {
|
|
27
|
+
/**
|
|
28
|
+
* 条件判断函数
|
|
29
|
+
* 返回 true 表示允许执行重置,false 表示跳过
|
|
30
|
+
*/
|
|
31
|
+
predicate: () => boolean;
|
|
32
|
+
/** 条件不满足时的跳过原因(用于日志) */
|
|
33
|
+
skipReason?: string;
|
|
34
|
+
}
|
|
35
|
+
/** 重置链配置 */
|
|
36
|
+
export interface ResetChain {
|
|
37
|
+
/**
|
|
38
|
+
* 当前动作完成后触发的目标动作列表
|
|
39
|
+
* 格式: 'pluginId:actionName' 或 'pluginId'(触发该插件的 default action)
|
|
40
|
+
*/
|
|
41
|
+
triggers: string[];
|
|
42
|
+
/** 是否仅在当前动作成功时才触发链 */
|
|
43
|
+
onlyOnSuccess?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 单个重置动作定义
|
|
47
|
+
* 插件通过 registerResetActions() 注册一个或多个动作
|
|
48
|
+
*/
|
|
49
|
+
export interface ResetAction {
|
|
50
|
+
/** 动作名称(同一插件内唯一) */
|
|
51
|
+
name: string;
|
|
52
|
+
/** 重置作用域 */
|
|
53
|
+
scope: ResetScope;
|
|
54
|
+
/**
|
|
55
|
+
* 执行函数
|
|
56
|
+
* @param context 重置上下文
|
|
57
|
+
*/
|
|
58
|
+
execute: (context: ResetContext) => void | Promise<void>;
|
|
59
|
+
/** 是否为该插件的默认重置动作(未指定 actionName 时调用) */
|
|
60
|
+
isDefault?: boolean;
|
|
61
|
+
/** 作用域为 CONDITIONAL 时的守卫条件 */
|
|
62
|
+
guard?: ResetGuard;
|
|
63
|
+
/** 重置链:完成后触发的后续动作 */
|
|
64
|
+
chain?: ResetChain;
|
|
65
|
+
/** 优先级(数值小的先执行,默认 200) */
|
|
66
|
+
priority?: number;
|
|
67
|
+
/** 人类可读描述(用于日志和调试) */
|
|
68
|
+
description?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 增强的可重置插件接口
|
|
72
|
+
* 替代原 IResettable,支持多动作注册
|
|
73
|
+
*/
|
|
74
|
+
export interface IResettableActions {
|
|
75
|
+
/**
|
|
76
|
+
* 注册该插件的所有重置动作
|
|
77
|
+
* 返回动作数组,由 ResetRegistry 统一索引
|
|
78
|
+
*/
|
|
79
|
+
registerResetActions(): ResetAction[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 类型守卫:检查插件是否实现了 IResettableActions
|
|
83
|
+
*/
|
|
84
|
+
export declare function hasResetActions(plugin: IViewerPlugin): plugin is IViewerPlugin & IResettableActions;
|
|
85
|
+
/** 注册到 ResetRegistry 的动作条目 */
|
|
86
|
+
interface ResetActionEntry {
|
|
87
|
+
/** 所属插件 ID */
|
|
88
|
+
pluginId: string;
|
|
89
|
+
/** 动作定义 */
|
|
90
|
+
action: ResetAction;
|
|
91
|
+
/** 全局唯一键: 'pluginId:actionName' */
|
|
92
|
+
key: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 重置注册表
|
|
96
|
+
* 负责收集、索引、查询所有插件的重置动作
|
|
97
|
+
*
|
|
98
|
+
* 生命周期:
|
|
99
|
+
* 1. 插件初始化时调用 collectActions() 收集所有动作
|
|
100
|
+
* 2. ResetManager 通过此表按需查找和执行动作
|
|
101
|
+
* 3. 插件卸载时自动移除其动作
|
|
102
|
+
*/
|
|
103
|
+
export declare class ResetRegistry {
|
|
104
|
+
private actions;
|
|
105
|
+
private pluginActions;
|
|
106
|
+
private eventBus;
|
|
107
|
+
private pluginRegistry;
|
|
108
|
+
private collected;
|
|
109
|
+
constructor(eventBus: EventBus, pluginRegistry: PluginRegistry);
|
|
110
|
+
/**
|
|
111
|
+
* 从所有已初始化插件中收集重置动作
|
|
112
|
+
* 应在所有插件 initAll() 完成后调用
|
|
113
|
+
*/
|
|
114
|
+
collectActions(): void;
|
|
115
|
+
/**
|
|
116
|
+
* 注册单个插件的重置动作
|
|
117
|
+
*/
|
|
118
|
+
private registerPluginActions;
|
|
119
|
+
/**
|
|
120
|
+
* 获取指定插件的所有重置动作
|
|
121
|
+
*/
|
|
122
|
+
getActions(pluginId: string): ResetAction[];
|
|
123
|
+
/**
|
|
124
|
+
* 获取指定插件的默认重置动作
|
|
125
|
+
*/
|
|
126
|
+
getDefaultAction(pluginId: string): ResetAction | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* 通过 'pluginId:actionName' 键获取动作
|
|
129
|
+
*/
|
|
130
|
+
getActionByKey(key: string): ResetActionEntry | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* 获取所有属于指定作用域的动作
|
|
133
|
+
*/
|
|
134
|
+
getActionsByScope(scope: ResetScope): ResetActionEntry[];
|
|
135
|
+
/**
|
|
136
|
+
* 获取所有参与全局重置的动作
|
|
137
|
+
* 即 scope === GLOBAL,或 scope === CONDITIONAL 且守卫条件满足
|
|
138
|
+
*/
|
|
139
|
+
getGlobalResetActions(): ResetActionEntry[];
|
|
140
|
+
/**
|
|
141
|
+
* 检查插件是否有注册的重置动作
|
|
142
|
+
*/
|
|
143
|
+
hasActions(pluginId: string): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* 获取所有已注册的插件 ID
|
|
146
|
+
*/
|
|
147
|
+
getRegisteredPluginIds(): string[];
|
|
148
|
+
/**
|
|
149
|
+
* 执行指定插件的指定动作
|
|
150
|
+
* @param pluginId 插件 ID
|
|
151
|
+
* @param actionName 动作名称(省略则使用默认动作)
|
|
152
|
+
* @param level 重置级别
|
|
153
|
+
* @param source 触发来源
|
|
154
|
+
*/
|
|
155
|
+
invoke(pluginId: string, actionName?: string, level?: ResetLevel, source?: string): Promise<ResetResult>;
|
|
156
|
+
/**
|
|
157
|
+
* 批量执行指定作用域的所有动作
|
|
158
|
+
*/
|
|
159
|
+
invokeByScope(scope: ResetScope, level?: ResetLevel, source?: string): Promise<ResetResult[]>;
|
|
160
|
+
/**
|
|
161
|
+
* 执行单个重置动作(含条件守卫、链式触发)
|
|
162
|
+
*/
|
|
163
|
+
private executeAction;
|
|
164
|
+
/**
|
|
165
|
+
* 执行重置链
|
|
166
|
+
* @param triggers 目标列表,格式 'pluginId:actionName' 或 'pluginId'
|
|
167
|
+
*/
|
|
168
|
+
private executeChain;
|
|
169
|
+
}
|
|
170
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { vtkActor } from '@kitware/vtk.js/Rendering/Core/Actor';
|
|
3
|
+
import { vtkVolume } from '@kitware/vtk.js/Rendering/Core/Volume';
|
|
4
|
+
/**
|
|
5
|
+
* 场景子上下文接口
|
|
6
|
+
* 提供场景对象的增删查能力
|
|
7
|
+
*/
|
|
8
|
+
export interface SceneSubContext {
|
|
9
|
+
/** 获取所有 Actor */
|
|
10
|
+
getActors(): vtkActor[];
|
|
11
|
+
/** 获取所有 Volume */
|
|
12
|
+
getVolumes(): vtkVolume[];
|
|
13
|
+
/** 是否处于体渲染模式 */
|
|
14
|
+
isVolumeRendering(): boolean;
|
|
15
|
+
/** 场景中是否有模型(Actor 或 Volume) */
|
|
16
|
+
hasModels(): boolean;
|
|
17
|
+
/** 响应式模型数量(Vue 可追踪) */
|
|
18
|
+
readonly modelCount: Ref<number>;
|
|
19
|
+
/** 添加 Actor 到场景 */
|
|
20
|
+
addActor(actor: vtkActor): void;
|
|
21
|
+
/** 添加 Volume 到场景 */
|
|
22
|
+
addVolume(volume: vtkVolume): void;
|
|
23
|
+
/** 清空场景 */
|
|
24
|
+
clearScene(): void;
|
|
25
|
+
}
|