Use custom hidden ObjectManipulator to move entities

Requires Eyeshot >= 9.0.394.

This sample uses a hidden custom ObjectManipulator to move the entities.

After the entities are selected, clicking on the viewport starts the dragging of the selected entities on view.

When the viewport is clicked again the translation is applied to the entities.

    class MyOM : ObjectManipulator
    {
        public MyOM(ObjectManipulator another) : base(another.Size, another.Visible, another.ShowOriginalWhileEditing, another.Translate, another.TranslateX,
        another.TranslateY, another.TranslateZ, another.RotateX, another.RotateY, another.RotateZ, another.RotationStep, another.TranslationStep)
        {

        }

        private bool first = true;

        public void EnableDragging(bool enable, Viewport viewport, MouseEventArgs e)
        {
            if (enable)
            {
                PickedEntity = 0;
                Enable(new Identity(), true);
            }
            else
                PickedEntity = -1;

            OnMouseDown(e, viewport);

            first = true;
        }

        protected override bool OnMouseUp(System.Windows.Forms.MouseEventArgs e, Viewport viewport)
        {
            var res = base.OnMouseUp(e, viewport);

            Dragging = true;

            return res;
        }

        protected override bool OnDrag(ref Point lastPoint, Point curPoint, Viewport viewport, BlockReference selectedBlockRef)
        {
            if (first)
                lastPoint = curPoint;

            first = false;
            return base.OnDrag(ref lastPoint, curPoint, viewport, selectedBlockRef);

        }

        public override void Draw(RenderParams data)
        {
            //base.Draw(data);
        }
    }

    public Form1()
    {

        InitializeComponent();
        ...
        viewportLayout1.Click += VpOnClick;
    }

    private bool b = false;

    private void VpOnClick(object sender, EventArgs eventArgs)
    {
        if (viewportLayout1.ActionMode != actionType.None)
            return;

        if (b)
            viewportLayout1.ObjectManipulator.Apply();
        else
        {
            ((MyOM)viewportLayout1.ObjectManipulator).EnableDragging(true, viewportLayout1.Viewports[0], (MouseEventArgs)eventArgs);
        }

        b = !b;
    }

    protected override void OnLoad(EventArgs e)
    {
        viewportLayout1.Entities.Add(Mesh.CreateSphere(10, 10, 10));

        viewportLayout1.ObjectManipulator = new MyOM(vp.ObjectManipulator);
        viewportLayout1.CompileUserInterfaceElements();

        viewportLayout1.Entities[0].Selected = true;
    }
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

1 comment

Please sign in to leave a comment.