KApplication
kds-plugin-document / Exports / KApplication
Interface: KApplication
KApplication 是使用酷大师前端 Plugin API 的起点。
从这里我们可以获取很多其他有用的 API 接口。例如:
- 代表当前打开的酷大师方案的 KDesign 接口,从这里我们可以调用酷大师的各种建模命令,如拉伸、扫掠、布尔等,对方案数据进行修改;
- 代表酷大师视图窗口的 KView 接口,从这里我们可以获取酷大师的画布和相机对象,并在画布中绘制各种临时图形元素;
- 代表酷大师选择集的 KSelection 接口,从这里我们可以获取酷大师画布中的各种被选择的对象,如造型面、造型边、参考线、成组等 ... ...
KApplication 还可以激活一个插件自定义工具对象 (KTool),它可以响应各种鼠标、键盘事件,实现和酷大师内置建模工具类似的交互效果; KApplication 还可以注册、注销酷大师应用的事件观察者,供插件响应酷大师发出的各种事件
请阅读下面的方法注释,以获取更详细的信息
The KApplication interface serves as the "entry point" for most other APIs. From here we can get the active design, which represents the user's design data; we can get the active view, which represents the application's graphics view. We can also activate a custom tool, which is the tool that plugin provides to interact with the design data... please check the comments below for more information.
Table of contents
Methods
- activateCustomTool
- addObserver
- deactivateCustomTool
- getActiveDesign
- getActiveView
- getApplicationUI
- getClientStorage
- getPickHelper
- getPluginModelLibraryHelper
- getPluginUI
- getPluginViewById
- getSelection
- getTestHelper
- getToast
- getToolHelper
- registerMessageHandler
- removeObserver
- setTimeout
- unRegisterMessageHandler
Methods
activateCustomTool
▸ activateCustomTool(tool
, clearSelection?
): boolean
激活插件自定义工具。插件自定义工具能响应各种鼠标、键盘事件,从而实现和酷大师内置建模工具类似的交互效果
Activate the custom tool.
Parameters
Name | Type | Description |
---|---|---|
tool | KTool | The custom tool. |
clearSelection? | boolean | If the clearSelection flag is set to true, when the tool is activated, the selection will be cleared. The default value is false. |
Returns
boolean
Return true if successful, otherwise return false.
Defined in
api.d.ts:386
addObserver
▸ addObserver(observer
): boolean
添加酷大师应用观察者。目前观察者主要用于响应插件关闭的消息,这样插件本身可以完成一些业务逻辑,比如保存插件本身的业务数据
The method is used to add an plugin observer to the application object.
Parameters
Name | Type | Description |
---|---|---|
observer | KApplicationObserver | The observer to add. |
Returns
boolean
Return true if successful, else return false.
Defined in
api.d.ts:419
deactivateCustomTool
▸ deactivateCustomTool(tool
, clearSelection?
): boolean
反激活插件自定义工具
Daactivate the custom tool.
Parameters
Name | Type | Description |
---|---|---|
tool | KTool | The custom tool. |
clearSelection? | boolean | If the clearSelection flag is set to true, when the tool is deactivated, the selection will be cleared. The default value is false. |
Returns
boolean
Return true if successful, otherwise return false.
Defined in
api.d.ts:397
getActiveDesign
▸ getActiveDesign(): KDesign
获取当前打开的酷大师方案。从 KDesign 接口我们可以调用酷大师各种建模命令,如拉伸、扫掠、布尔等,对方案数据进行修改
Get the active design.
Returns
The active design.
Defined in
api.d.ts:321
getActiveView
▸ getActiveView(): KView
获取酷大师视图窗口。从 KView 接口我们可以获取酷大师的画布和相机对象,并在画布中绘制各种临时图形元素
Get the active view.
Returns
The active view.
Defined in
api.d.ts:330
getApplicationUI
▸ getApplicationUI(): KApplicationUI
获取酷大师应用的 UI 面板,即顶部工具栏、左侧栏、右侧属性面板等组成的酷大师 UI 面板
Get the KApplicationUI object for operating the application UI.
Returns
The KApplicationUI object for operating the application UI.
Defined in
api.d.ts:348
getClientStorage
▸ getClientStorage(): KClientStorage
获取客户端临时存储对象。通过该对象,插件可在客户端进行临时数据存取
Get the KClientStorage object for allowing you to store data on the user's local machine.
Returns
The KClientStorage object.
Defined in
api.d.ts:357
getPickHelper
▸ getPickHelper(): KPickHelper
获取选择帮助器,此接口提供了按屏幕 2d 点选,按屏幕 2d 矩形框选等进行选择的方法
Get the KPickHelper object for allowing you to pick entities.
Returns
The KPickHelper object.
Defined in
api.d.ts:375
getPluginModelLibraryHelper
▸ getPluginModelLibraryHelper(): KPluginModelLibraryHelper
获取插件模型库帮助器,包含模型公库和私库
Get the KPluginModelLibraryHelper object.
Returns
The KPluginModelLibraryHelper object.
Defined in
api.d.ts:456
getPluginUI
▸ getPluginUI(): KPluginUI
获取插件 UI 面板。插件如果提供了 UI html,就是在这个 UI 面板里打开的。我们可以调整此 UI 面板的大小,发送和响应插件自定义消息
Get the KPluginUI object for operating the plugin UIs.
Returns
The KPluginUI object for operating the plugin UIs.
Defined in
api.d.ts:339
getPluginViewById
▸ getPluginViewById(id
): KPluginView
根据viewId获取PluginView,可以从沙盒代码向iframe view发送自定义消息
Get the KPluginView object.
Parameters
Name | Type |
---|---|
id | string |
Returns
The KPluginView object.
Defined in
api.d.ts:447
getSelection
▸ getSelection(): KSelection
获取酷大师选择集。用户在视图窗口中用鼠标选中的造型面、造型边、参考线、成组等,都可以从此选择集中得到
Get the selection operation handle.
Returns
The selection operation handle.
Defined in
api.d.ts:313
getTestHelper
▸ getTestHelper(): KTestHelper
Deprecated
获取酷大师测试帮助器。目前此接口仅用于酷大师 UI 自动化测试,不建议插件开发者使用
Get the utility helper that is only used for testing.
Returns
The KTestHelper object
Defined in
api.d.ts:438
getToast
▸ getToast(): KToast
获取酷大师信息提示接口
Get the toast operation handle.
Returns
The toast operation handle.
Defined in
api.d.ts:304
getToolHelper
▸ getToolHelper(): KToolHelper
获取自定义工具 KTool 的帮助接口,此接口提供了一组帮助自定义工具实现更复杂交互效果的方法,例如激活选择功能,激活框选功能,设置选择过滤器等
Get the utility helper for plugin tools.
Returns
The KToolHelper object.
Defined in
api.d.ts:366
registerMessageHandler
▸ registerMessageHandler(callback
): string
将沙盒代码中的自定义消息处理函数注册到酷大师
Register the custom message handler in the sandbox code to KooMaster.
Parameters
Name | Type |
---|---|
callback | (data : any , origin : string ) => void |
Returns
string
the unique handleId.
Defined in
api.d.ts:465
removeObserver
▸ removeObserver(observer
): boolean
移除酷大师应用观察者
The method is used to remove the plugin observer from the application object.
Parameters
Name | Type | Description |
---|---|---|
observer | KApplicationObserver | The observer to remove. |
Returns
boolean
Return true if successful, else return false.
Defined in
api.d.ts:429
setTimeout
▸ setTimeout(callback
, time
, ...args
): void
@deprecated:延时若干毫秒后执行一个函数 (本方法将被移除。建议直接使用 JS 内置的 setTimeout 方法)
The method is used to call a function after the specified number of milliseconds.
Parameters
Name | Type | Description |
---|---|---|
callback | (...args : any []) => void | The called function. |
time | number | The specified number of milliseconds. |
...args | any [] | The parameters passed to the callback function |
Returns
void
Defined in
api.d.ts:409
unRegisterMessageHandler
▸ unRegisterMessageHandler(handerId
): boolean
从沙盒代码中解绑自定义消息处理函数
Unregister the custom message handler.
Parameters
Name | Type |
---|---|
handerId | string |
Returns
boolean
true if message handler has registered and has been removed, or false if the message handler hasn't registered.
Defined in
api.d.ts:474