UNPKG

@inweb/viewer-visualize

Version:

JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS

119 lines (111 loc) 5.91 kB
/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a // license agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// import { ICommandsRegistry, commandsRegistry } from "@inweb/viewer-core"; import { applyModelTransform } from "./ApplyModelTransform"; import { clearMarkup } from "./ClearMarkup"; import { clearSelected } from "./ClearSelected"; import { clearSlices } from "./ClearSlices"; import { createPreview } from "./CreatePreview"; import { explode, collect } from "./Explode"; import { getDefaultViewPositions } from "./GetDefaultViewPositions"; import { getModels } from "./GetModels"; import { getSelected } from "./GetSelected"; import { hideSelected } from "./HideSelected"; import { isolateSelected } from "./IsolateSelected"; import { regenerateAll } from "./RegenerateAll"; import { resetView } from "./ResetView"; import { selectModel } from "./SelectModel"; import { setActiveDragger } from "./SetActiveDragger"; import { setDefaultViewPosition } from "./SetDefaultViewPosition"; import { setMarkupColor } from "./SetMarkupColor"; import { setSelected } from "./SetSelected"; import { showAll } from "./ShowAll"; import { zoomToExtents } from "./ZoomToExtents"; import { zoomToObjects } from "./ZoomToObjects"; import { zoomToSelected } from "./ZoomToSelected"; import { autoTransformAllModelsToCentralPoint } from "./AutoTransformAllModelsToCentralPoint"; /** * Viewer commands registry. Use this registry to register custom commands. * * To implement custom command: * * 1. Define a command handler with a first `viewer` parameter. * 2. Register command handler in the commands registry by calling the {@link commands.registerCommand}. * * @example Implementing a custom command. * * ```javascript * import { commands, Viewer } from "@inweb/viewer-visualize"; * * function commandHandler(viewer: Viewer, name = "world"): void { * console.log(`Hello ${name}!!!`); * } * * commands.registerCommand("sayHello", commandHandler); * ``` * * @example Calling a custom command. * * ```javascript * viewer.executeCommand("sayHello", "user"); * ``` */ export const commands: ICommandsRegistry = commandsRegistry("visualizejs"); // build-in commands commands.registerCommand("applyModelTransform", applyModelTransform); commands.registerCommand("clearMarkup", clearMarkup); commands.registerCommand("clearSelected", clearSelected); commands.registerCommand("clearSlices", clearSlices); commands.registerCommand("createPreview", createPreview); commands.registerCommand("explode", explode); commands.registerCommand("collect", collect); commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions); commands.registerCommand("getModels", getModels); commands.registerCommand("getSelected", getSelected); commands.registerCommand("hideSelected", hideSelected); commands.registerCommand("isolateSelected", isolateSelected); commands.registerCommand("regenerateAll", regenerateAll); commands.registerCommand("resetView", resetView); commands.registerCommand("selectModel", selectModel); commands.registerCommand("setActiveDragger", setActiveDragger); commands.registerCommand("setDefaultViewPosition", setDefaultViewPosition); commands.registerCommand("setMarkupColor", setMarkupColor); commands.registerCommand("setSelected", setSelected); commands.registerCommand("showAll", showAll); commands.registerCommand("zoomToExtents", zoomToExtents); commands.registerCommand("zoomToObjects", zoomToObjects); commands.registerCommand("zoomToSelected", zoomToSelected); commands.registerCommand("autoTransformAllModelsToCentralPoint", autoTransformAllModelsToCentralPoint); commands.registerCommand("k3DViewTop", (viewer) => setDefaultViewPosition(viewer, "k3DViewTop")); commands.registerCommand("k3DViewBottom", (viewer) => setDefaultViewPosition(viewer, "k3DViewBottom")); commands.registerCommand("k3DViewLeft", (viewer) => setDefaultViewPosition(viewer, "k3DViewLeft")); commands.registerCommand("k3DViewRight", (viewer) => setDefaultViewPosition(viewer, "k3DViewRight")); commands.registerCommand("k3DViewFront", (viewer) => setDefaultViewPosition(viewer, "k3DViewFront")); commands.registerCommand("k3DViewBack", (viewer) => setDefaultViewPosition(viewer, "k3DViewBack")); commands.registerCommand("k3DViewSE", (viewer) => setDefaultViewPosition(viewer, "k3DViewSE")); commands.registerCommand("k3DViewSW", (viewer) => setDefaultViewPosition(viewer, "k3DViewSW")); commands.registerCommand("k3DViewNE", (viewer) => setDefaultViewPosition(viewer, "k3DViewNE")); commands.registerCommand("k3DViewNW", (viewer) => setDefaultViewPosition(viewer, "k3DViewNW")); commands.registerCommandAlias("clearMarkup", "clearOverlay"); commands.registerCommandAlias("clearSelected", "unselect"); commands.registerCommandAlias("zoomToExtents", "zoomExtents");