问题

/**
 * Created by dx-hyc on 2017/4/5.
 * 移动
 */

var dxsModuleFreeDesign_move = function (opt) {
    // 继承类属性
    dxsModuleFun.call(this, opt);

    // 增加本类属性
    this.D3Event.mousemove = true;
    this.D3Event.mousedown = true;
    this.D3Event.mouseup = true;

    this.isMoved = false;
    this.checkMove = false;
};

dxsModuleFreeDesign_move.prototype = Object.create(dxsModuleFun.prototype);

dxsModuleFreeDesign_move.prototype.constructor = dxsModuleFreeDesign_move;

Object.assign(dxsModuleFreeDesign_move.prototype, {

    init: function (opt) {
        // 注册 子模块
        this.me.name = 'move';
        this._init(opt);

        // 自定义初始化
    },

    on: function (opt) {
        this._on(opt);
        // 自定义启动
    },

    off: function (opt) {
        this._off(opt);
        // 自定义关闭
    },

    onMouseMove: function (event) {
        event.preventDefault();
        var scope = this;
        if (this.checkMove && this.module.mouseDownPos.distanceToSquared(this.module.mouse) > 36)
            this.module.isMoved = true;

        if (this.module.moveFlag && this.module.isMoved) {
            this.isMoved = true;
            this.module.moveDelta.subVectors(Studio.builder.vertexOnDraftPlane, this.module.downPos);
            this.module.moveWithRestrain(this.module.moveTarget, this.module.moveDelta);
            this.module.moveTarget.owner.board && this.module.moveTarget.owner.board.updateMesh();
            //qml,显示距离
            // var wallEditLength0 = $("#wallEditLength1");
            // var wallEditLength1 = $("#wallEditLength2");
            // wallEditLength0.show();
            // wallEditLength1.show();
            //moveTarget为线段时
            if (!this.module.moveTarget.isDXSLine) {

                var lines = Studio.builder.currentDraft.linesWithPoint(this.module.moveTarget);
                //多个线条情况
                var wallEditLengths=$(".meiling_input");//获取输入框,第一个为画墙时的输入框,从1开始
                // for(var i = 1; i < wallEditLengths.length&&i<=lines.length; i++){
                //     $(wallEditLengths[i]).show();
                // }
                for (var i = 0; i < lines.length; i++) {
                    var p0, length0, linePos0 = new THREE.Vector3(),targetPoint = new THREE.Vector3(),
                        middlePos0 = new THREE.Vector3(), offset = 12;
                    p0 = lines[i].p0.point.clone();
                    if (DXSUtils.pointEqual(p0, this.module.moveTarget.point)) {
                        p0 = lines[i].p1.point.clone();
                    }
                    length0 = this.module.moveTarget.point.clone().sub(p0.clone()).length();
                    $(wallEditLengths[i+1]).val(Math.floor(length0 * 1000));
                    DXSUtils.worldToScreenPos(Studio.view.current.camera, Studio.moduleFreeDesign.domRect, p0.clone(), linePos0);
                    DXSUtils.worldToScreenPos(Studio.view.current.camera, Studio.moduleFreeDesign.domRect, this.module.moveTarget.point, targetPoint);
                    middlePos0.copy(targetPoint).add(linePos0).multiplyScalar(0.5);
                    if (DXSUtils.floatEqual(targetPoint.x, linePos0.x)) {
                        middlePos0.x += offset;
                    } else {
                        // 根据斜率设置输入框位置
                        k = ( targetPoint.clone().y - linePos0.y ) / ( targetPoint.clone().x - linePos0.x );
                        if (k < -1)
                            middlePos0.x += offset;
                        else if (k < 0)
                            middlePos0.y += offset;
                        else if (k < 1)
                            middlePos0.y -= offset + $(wallEditLengths[i+1]).outerHeight();
                        else {
                            middlePos0.x += offset;
                            middlePos0.y -= $(wallEditLengths[i+1]).outerHeight();
                        }
                    }
                    $(wallEditLengths[i+1]).offset({top: middlePos0.y, left: middlePos0.x});
                    //设置输入框中的值
                    $(wallEditLengths[i+1]).focus();
                    // console.log("移动后的line值:");
                    // console.log(lines[0].p0,lines[0].p1);
                    // console.log(lines[1].p0,lines[1].p1);
                    if (!$(wallEditLengths[i+1]).data('show')) {
                        $(wallEditLengths[i+1]).data('show', true);
                        $(wallEditLengths[i+1]).show();
                        $(wallEditLengths[i+1]).unbind();
                        (function(arg,lp0,lp1){
                            $(wallEditLengths[arg+1]).keydown(function (event) {
                                if (event.keyCode == 13) {
                                    var sign = false;
                                    if (/[a-zA-Z]/.test($(wallEditLengths[arg+1]).val())) {
                                        layer.msg('不能输入字母!');
                                    } else {
                                        // console.log("修改前的line:");
                                        // console.log(lins[0].p0,lins[0].p1);
                                        // console.log(lins[1].p0,lins[1].p1);
                                        var lins = Studio.builder.currentDraft.linesWithPoint(scope.module.moveTarget);
                                        if(Studio.utils.pointEqual(lins[0].p0.point,lp0))
                                        if (!DXSUtils.pointEqual(lins[arg].p1.point.clone(), scope.module.moveTarget.point.clone())) {
                                            sign = true;
                                            // var t = lines[arg].p1.point.clone();
                                            // lines[arg].p1.point = lines[arg].p0.point.clone();
                                            // lines[arg].p0.point = t.clone();
                                        }
                                        var p0;
                                        if(sign){
                                            p0 = lins[arg].p1.point.clone();
                                        }else{
                                            p0 = lins[arg].p0.point.clone();
                                        }

                                        var direction = scope.module.moveTarget.point.clone().sub(p0.clone()).normalize();
                                        var endPoint = direction.multiplyScalar($(wallEditLengths[arg+1]).val() / 1000).add(p0.clone());
                                        if(sign){
                                            lins[arg].p0.point = endPoint;
                                        }else{
                                            lins[arg].p1.point = endPoint;
                                        }
                                        // console.log("修改后的值:");
                                        // console.log(lins[0].p0,lins[0].p1);
                                        // console.log(lins[1].p0,lins[1].p1);
                                        // if (sign) {
                                        //     var t = lines[arg].p1.point.clone();
                                        //     lines[arg].p1.point = lines[arg].p0.point.clone();
                                        //     lines[arg].p0.point = t.clone();
                                        // }
                                        if (Studio.builder.currentDraft.board)
                                            Studio.builder.currentDraft.board.updateMesh();
                                    }
                                }
                            });
                        })(i,lines[i].p0.point.clone(),lines[i].p1.point.clone());
                    }

                }
            }


        }
    },

    onMouseDown: function (event) {
        event.preventDefault();

        this.checkMove = true;
        this.module.mouseDownPos.copy(this.module.mouse);
        this.module.downPos.copy(Studio.builder.vertexOnDraftPlane);

        if (event.button != 0) return;
        if (!Studio.builder.currentDraft) return;
        if (!Studio.builder.hovered) return;
        if (Studio.builder.hovered.owner != Studio.builder.currentDraft) return;
        if (!(Studio.builder.hovered.isDXSPoint || Studio.builder.hovered.isDXSLine)) return;

        this.module.moveTarget = Studio.builder.hovered;
        this.module.moveFlag = true;
        this.module.beginMoveWithRestrain(this.module.moveTarget);
    },

    onMouseUp: function (event) {
        event.preventDefault();
        this.checkMove = false;
        this.module.isMoved = false;

        if (this.module.moveFlag) {
            this.module.moveFlag = false;
            if (this.isMoved) {
                this.isMoved = false;
                if (this.module.moveTarget.isDXSPoint)
                    Studio.builder.execute(new DXSCommandMovePoint(this.module.moveTarget));
                else {
                    Studio.builder.execute(new DXSCommandMoveLine(this.module.moveTarget));
                }
            }
        }
    }
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值