import { __awaiter, __extends, __generator } from "tslib";
import { Cartesian3, } from '@taotieh/cesium_extend';
import ClipWithPlane from './ClipWithPlane';
var State;
(function (State) {
    State[State["READY"] = 0] = "READY";
    State[State["POINT_ORIGIN_SELECTED"] = 1] = "POINT_ORIGIN_SELECTED";
    State[State["POINT_ORIGIN_CHANGED"] = 2] = "POINT_ORIGIN_CHANGED";
    State[State["DONE"] = 3] = "DONE";
})(State || (State = {}));
/** **************************************************************
 *  使用强制绑定为水平方向的面刨切, 重写部分函数, 实现选重原点之后只生水平面
 *****************************************************************/
var ClipWithHorizon = /** @class */ (function (_super) {
    __extends(ClipWithHorizon, _super);
    function ClipWithHorizon(viewer, instance) {
        var _this = 
        /** **********************************************************
         *  父类构造需要指定原点和法线, 这里的值无意义. 等待后续鼠标动作赋值
         *************************************************************/
        _super.call(this, viewer, instance, Cartesian3.ZERO.clone(), Cartesian3.UNIT_Y.clone()) || this;
        _this._toReset();
        return _this;
    }
    ClipWithHorizon.prototype._toSelectOrigin = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a, origin, normal, cPo;
            var _this = this;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = this, origin = _a._origin, normal = _a._normal;
                        return [4 /*yield*/, this._selectPoint(origin)];
                    case 1:
                        _b.sent();
                        cPo = this._instance.getInstancePointerControl();
                        cPo.once('rightClick', function () { return _this.stop(); });
                        this._state = State.POINT_ORIGIN_SELECTED;
                        return [4 /*yield*/, this._createCuttingPlaneWithOrigin(Cartesian3.negate(Cartesian3.UNIT_Z, normal), origin)];
                    case 2:
                        _b.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    ClipWithHorizon.prototype._toReset = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this._state = State.READY;
                        return [4 /*yield*/, _super.prototype._toReset.call(this)];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    ClipWithHorizon.prototype.start = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                _super.prototype.start.call(this);
                this._toReset();
                this.next();
                return [2 /*return*/];
            });
        });
    };
    ClipWithHorizon.prototype.next = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (this._state) {
                    case State.READY:
                        this._toSelectOrigin();
                        break;
                    default:
                        this._toReset();
                }
                return [2 /*return*/];
            });
        });
    };
    ClipWithHorizon.prototype.stop = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this._toReset()];
                    case 1:
                        _a.sent();
                        _super.prototype.stop.call(this);
                        return [2 /*return*/];
                }
            });
        });
    };
    return ClipWithHorizon;
}(ClipWithPlane));
export default ClipWithHorizon;
