Example #1
0
    public void Reset()
    {
        //1.check
        if (!CanExecuteReset())
        {
            Debug.Log("Can not execute reset" + "\n");
            return;
        }

        //2.handle gcode render
        GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean();
        GcodeRenderManager.GetInstance().Destroy();

        //3.remove all bean except initBean
        while (_undoStack.Count > 1)
        {
            _undoStack.Pop();
        }
        _redoStack.Clear();

        OperateBean initRenderBean = _undoStack.Peek();

        Debug.Log("Reset:" + "\n" + _curOperateBean + "-->" + "\n" + initRenderBean + "\n");

        operateRenderModel(initRenderBean);

        _curOperateBean = initRenderBean.DeepCopy();
    }
Example #2
0
    public void SetModelInitialLocalPosition()
    {
        Vector3 originDataSize = _model3d.GetOriginDataSize();
        //data <---> render : swap y <---> z
        float   y           = -(_deviceSize.y - originDataSize.z) / 2.0f;
        Vector3 newPosition = _model3d.GetRenderLocalPosition();

        newPosition.y = y / _deviceSize.y;
        newPosition.x = 0;
        newPosition.z = 0;
        _model3d.SetRenderLocalPosition(newPosition);

        _scaleRange = calculateScaleRange(_model3d.dataModel_origin, _deviceSize);

        //init _operateBean
        Vector2 move   = Vector2.zero;
        float   scale  = 1.0f;
        Vector3 rotate = Vector3.zero;
        Vector3 renderModel_LocalPosition = newPosition;
        Vector3 dataModel_Size            = _model3d.GetOriginDataSize();

        _curOperateBean = new OperateBean(move, scale, rotate, renderModel_LocalPosition, dataModel_Size);

        _undoStack.Clear();
        _redoStack.Clear();

        _undoStack.Push(_curOperateBean.DeepCopy());
    }
Example #3
0
    public void Redo()
    {
        //1.check
        if (!CanExecuteRedo())
        {
            Debug.Log("Can not execute redo" + "\n");
            return;
        }

        //handle gcode render
        GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean();
        GcodeRenderManager.GetInstance().Destroy();

        //_undoStack Pop and _redoStack push
        _undoStack.Push(_redoStack.Pop());

        OperateBean targetRenderBean = _undoStack.Peek();

        Debug.Log("redo:" + "\n" + _curOperateBean + "-->" + "\n" + targetRenderBean + "\n");

        operateRenderModel(targetRenderBean);

        _curOperateBean = targetRenderBean.DeepCopy();
    }
Example #4
0
    public void OnOperateEnd()
    {
        //1.check
        if (_model3d == null)
        {
            return;
        }

        OperateBean lastBean = _undoStack.Peek();

        if (lastBean.scale == _curOperateBean.scale &&
            lastBean.move == _curOperateBean.move &&
            lastBean.rotate == _curOperateBean.rotate)
        {
            Debug.Log("Model is not moved/scaled/rotated, return" + "\n");

            GcodeRenderManager.GetInstance().SetActive_gcodeRender(true);

            return;
        }

        UnityEngine.Debug.Log("************************ OnOperateEnd ***************************" + "\n");

        //2.release about gcode
        GcodeCreateManager.GetInstance().UnavailableCurGcodeCreateBean();
        GcodeRenderManager.GetInstance().Destroy();

        //3.operate
        bool moveChanged   = lastBean.move != _curOperateBean.move;
        bool scaleChanged  = lastBean.scale != _curOperateBean.scale;
        bool rotateChanged = lastBean.rotate != _curOperateBean.rotate;

        if (moveChanged)
        {
            Debug.Log("Model is moved" + "\n");
        }
        if (scaleChanged)
        {
            Debug.Log("Model is scaled" + "\n");
        }
        if (rotateChanged)
        {
            Debug.Log("Model is rotated" + "\n");
        }

        //case1: only move param changed
        if (moveChanged && !scaleChanged && !rotateChanged)
        {
            //No need to update dataModel, vertical value not changed
            //update dataModel may costs lot time
            Debug.Log("Model is only moved" + "\n");
        }
        else
        {
            //case2: scale/rotate changed
            Debug.Log("Model is scaled/rotated" + "\n");

            //UpdateCurDataModel
            //dataModel will change
            _model3d.UpdateCurDataModel(
                _curOperateBean.scale,
                _curOperateBean.move.x,
                _curOperateBean.move.y,
                _curOperateBean.rotate.x,
                _curOperateBean.rotate.y,
                _curOperateBean.rotate.z
                );

            //set render position
            float minZ_cur    = _model3d.dataModel_cur.GetMinZ();
            float minZ_origin = _model3d.dataModel_origin.GetMinZ();
            float disZ        = minZ_origin - minZ_cur;

            Vector3 newPosition = _model3d.renderedModel.shellCube.transform.localPosition;

            float y      = -(_deviceSize.y - _model3d.GetOriginDataSize().z) / 2.0f;
            float localY = y / _deviceSize.y;

            newPosition.y = localY + disZ / _deviceSize.y;
            _model3d.renderedModel.shellCube.transform.localPosition = newPosition;

            //record
            _curOperateBean.localPosition = newPosition;
            //after UpdateCurDataModel and operate render model,
            //the dataModel_cur.GetSize is actural renderModel size
            _curOperateBean.size = _model3d.dataModel_cur.GetSize();
        }

        //4.undo/redo
        _undoStack.Push(_curOperateBean.DeepCopy());
        _redoStack.Clear();

        UnityEngine.Debug.Log("***************************************************" + "\n");
    }