"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TryPanTransformUCImp = exports.TryPanTransformUC = void 0;
exports.makeTryPanTransformUC = makeTryPanTransformUC;
const core_1 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const PanTransformUC_1 = require("./PanTransformUC");
class TryPanTransformUC extends core_1.AppObjectUC {
}
exports.TryPanTransformUC = TryPanTransformUC;
TryPanTransformUC.type = "TryPanTransformUC";
function makeTryPanTransformUC(appObject) {
    return new TryPanTransformUCImp(appObject);
}
class TryPanTransformUCImp extends TryPanTransformUC {
    get pixelToRay() {
        return this.getCachedSingleton(Babylon_1.PixelToSceneRayUC.type)
            ?.pixelToSceneRay;
    }
    get rayPickUC() {
        return this.getCachedSingleton(Babylon_1.SceneRayPickUC.type);
    }
    constructor(appObject) {
        super(appObject, TryPanTransformUC.type);
        this.allow = () => {
            return true;
        };
        this.tryWithPixel = (pixel) => {
            if (!this.pixelToRay) {
                return false;
            }
            const ray = this.pixelToRay(pixel);
            return this.tryWithRay(ray);
        };
        this.moveWithPixel = (pixel) => {
            if (!this.pixelToRay) {
                return;
            }
            const ray = this.pixelToRay(pixel);
            return this.moveWithRay(ray);
        };
        this.tryWithRay = (pickRay) => {
            this.panUC = undefined;
            if (!this.allow())
                return false;
            const scenePick = this.rayPickUC?.sceneRayPick(pickRay);
            if (!scenePick || !scenePick.worldPickPoint)
                return false;
            const appObjectID = scenePick.appObjectID;
            if (!appObjectID)
                return false;
            this.panUC = PanTransformUC_1.PanTransformUC.get(appObjectID, this.appObjects);
            if (this.panUC === undefined) {
                return false;
            }
            this.panUC.initializeRay(pickRay);
            return true;
        };
        this.moveWithRay = (pickRay) => {
            if (!this.panUC)
                return;
            this.panUC.updateRay(pickRay);
        };
        this.stop = () => {
            if (!this.panUC)
                return;
            this.panUC.finish();
            this.panUC = undefined;
        };
        this.cancel = () => {
            if (!this.panUC)
                return;
            this.panUC.cancelPan();
            this.panUC = undefined;
        };
    }
}
exports.TryPanTransformUCImp = TryPanTransformUCImp;
//# sourceMappingURL=TryPanTransformUC.js.map