UNPKG

@itwin/core-markup

Version:
86 lines 3.98 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module MarkupTools */ import { BeButton, CoordinateLockOverrides, EventHandled, IModelApp, PrimitiveTool } from "@itwin/core-frontend"; import { MarkupApp } from "./Markup"; /** Base class for all tools that operate on Markup elements. * @public */ export class MarkupTool extends PrimitiveTool { markup; static toolKey = "MarkupTools:tools.Markup."; requireWriteableTarget() { return false; } isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp === IModelApp.toolAdmin.markupView); } async onInstall() { if (undefined === MarkupApp.markup) return false; this.markup = MarkupApp.markup; return super.onInstall(); } async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); } async onUnsuspend() { this.showPrompt(); } async onRestartTool() { return this.exitTool(); } showPrompt() { } setupAndPromptForNextAction() { IModelApp.toolAdmin.toolState.coordLockOvr = CoordinateLockOverrides.All; // Don't adjust point to ACS or grid... this.showPrompt(); } outputMarkupPrompt(msg) { IModelApp.notifications.outputPromptByKey(MarkupTool.toolKey + msg); } async onTouchMoveStart(ev, startEv) { if (startEv.isSingleTouch) await IModelApp.toolAdmin.convertTouchMoveStartToButtonDownAndMotion(startEv, ev); return EventHandled.Yes; // View tools are not allowed during redlining; use touch events to create markup and don't pass event to IdleTool... } async onTouchMove(ev) { return IModelApp.toolAdmin.convertTouchMoveToMotion(ev); } async onTouchComplete(ev) { return IModelApp.toolAdmin.convertTouchEndToButtonUp(ev); } async onTouchCancel(ev) { return IModelApp.toolAdmin.convertTouchEndToButtonUp(ev, BeButton.Reset); } async undoPreviousStep() { if (await this.onUndoPreviousStep()) // first see if this tool has an "oops" operation. return true; // yes, we're done this.markup.undo.doUndo(); // otherwise undo the last change by previous tools return true; } async redoPreviousStep() { if (await this.onRedoPreviousStep()) return true; this.markup.undo.doRedo(); return true; } /** Find the topmost MarkupElement at the specified point in the markup view. * @param pt the point in view coordinates * @returns The topmost element, or undefined if no elements under pt. */ pickElement(pt) { const markup = this.markup; const rect = markup.markupDiv.getBoundingClientRect(); const node = document.elementFromPoint(pt.x + rect.left, pt.y + rect.top); if (!node || !node.instance) return undefined; const el = node.instance; return el.getChildOrGroupOf(markup.svgMarkup); } setCurrentStyle(element, canBeFilled) { element.css(MarkupApp.props.active.element); if (!canBeFilled) element.css({ fill: "none" }); } setCurrentTextStyle(element) { element.css(MarkupApp.props.active.text); } /** @internal */ createBoxedText(g, text) { const boxedText = g.group().addClass(MarkupApp.boxedTextClass); const outline = text.getOutline(3); this.setCurrentStyle(outline, true); outline.css({ "stroke-width": 1 }); outline.addTo(boxedText); text.addTo(boxedText); // make sure the text is on top return boxedText; } } //# sourceMappingURL=MarkupTool.js.map