Example #1
0
        public override void ToolSelected(bool preventHistory)
        {
            _form.Show(Editor.Instance);
            Editor.Instance.Focus();

            // Init the points and copy caches
            _copies = new Dictionary <Solid, Solid>();
            Points  = new List <VMPoint>();

            SelectionChanged();

            _snapPointOffset = null;
            _movingPoint     = null;
            MoveSelection    = null;

            if (_currentTool != null)
            {
                _currentTool.ToolSelected(preventHistory);
            }

            Mediator.Subscribe(EditorMediator.SelectionChanged, this);
            Mediator.Subscribe(HotkeysMediator.VMStandardMode, this);
            Mediator.Subscribe(HotkeysMediator.VMScalingMode, this);
            Mediator.Subscribe(HotkeysMediator.VMFaceEditMode, this);
        }
Example #2
0
        public override void MouseUp(ViewportBase viewport, ViewportEvent e)
        {
            base.MouseUp(viewport, e);

            if (_currentTool == null)
            {
                return;
            }
            _currentTool.MouseUp(viewport, e);

            if (!(viewport is Viewport2D))
            {
                return;
            }
            if (_currentTool.NoSelection())
            {
                return;
            }

            if (!e.Handled)
            {
                if (MoveSelection != null && !KeyboardState.Ctrl)
                {
                    // If we were clicking on a point, and the mouse hasn't moved yet,
                    // and ctrl is not down, deselect the other points.
                    Points.ForEach(x => x.IsSelected        = false);
                    MoveSelection.ForEach(x => x.IsSelected = true);
                    VertexSelectionChanged();

                    _currentTool.MouseClick(viewport, e);
                }
                else
                {
                    _currentTool.DragEnd();
                }
            }

            RefreshMidpoints();
            _snapPointOffset = null;
            _movingPoint     = null;
            MoveSelection    = null;
        }
Example #3
0
        public override void ToolDeselected(bool preventHistory)
        {
            Mediator.UnsubscribeAll(this);

            if (_currentTool != null)
            {
                _currentTool.ToolDeselected(preventHistory);
            }

            // Commit the changes
            Commit(_copies.Values.ToList());

            _copies          = null;
            Points           = null;
            _snapPointOffset = null;
            _movingPoint     = null;
            MoveSelection    = null;

            _form.Hide();
        }
Example #4
0
        public override void MouseDown(ViewportBase vp, ViewportEvent e)
        {
            _clickSelectionDone = false;
            if (_currentTool != null)
            {
                // If the current tool handles the event, we're done
                _currentTool.MouseDown(vp, e);
                if (e.Handled)
                {
                    return;
                }
            }
            if (!(vp is Viewport2D))
            {
                MouseDown((Viewport3D)vp, e);
                return;
            }

            if (_currentTool == null)
            {
                return;
            }

            if (_currentTool.NoSelection())
            {
                return;
            }

            var viewport = (Viewport2D)vp;

            // Otherwise we try a selection
            // Find the clicked vertices
            var vtxs = _currentTool.GetVerticesAtPoint(e.X, viewport.Height - e.Y, viewport);

            if (!vtxs.Any())
            {
                // Nothing clicked
                if (!KeyboardState.Ctrl)
                {
                    // Deselect all the points if not ctrl-ing
                    Points.ForEach(x => x.IsSelected = false);
                }

                // Try to select in 2D

                // Create a box to represent the click, with a tolerance level
                var unused    = viewport.GetUnusedCoordinate(new Coordinate(100000, 100000, 100000));
                var tolerance = 4 / viewport.Zoom; // Selection tolerance of four pixels
                var used      = viewport.Expand(new Coordinate(tolerance, tolerance, 0));
                var add       = used + unused;
                var click     = viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y));
                var box       = new Box(click - add, click + add);

                var centerHandles = Select.DrawCenterHandles;
                var centerOnly    = Select.ClickSelectByCenterHandlesOnly;
                // Get the first element that intersects with the box
                var solid = Document.Map.WorldSpawn.GetAllNodesIntersecting2DLineTest(box, centerHandles, centerOnly).OfType <Solid>().FirstOrDefault();

                if (solid != null)
                {
                    // select solid
                    var select   = new[] { solid };
                    var deselect = !KeyboardState.Ctrl ? Document.Selection.GetSelectedObjects() : new MapObject[0];
                    Document.PerformAction("Select VM solid", new ChangeSelection(select, deselect));

                    // Don't do other click operations
                    return;
                }

                base.MouseDown(vp, e);
                return;
            }

            var vtx = vtxs.First();

            // When clicking, only select vertices in a single solid
            vtxs = vtxs.Where(x => x.Solid == vtx.Solid).ToList();

            // If any vertices are selected, don't change the selection yet
            if (!vtxs.Any(x => x.IsSelected))
            {
                _clickSelectionDone = true;
                DoSelection(vtxs, viewport);
            }

            // Only move selected vertices
            vtxs = vtxs.Where(x => x.IsSelected).ToList();
            if (!vtxs.Any())
            {
                return;
            }

            // Use the fist vertex as the control point
            _currentTool.DragStart(vtxs);
            MoveSelection    = vtxs;
            _snapPointOffset = SnapIfNeeded(viewport.Expand(viewport.ScreenToWorld(e.X, viewport.Height - e.Y))) - viewport.ZeroUnusedCoordinate(vtx.Coordinate);
            _movingPoint     = vtx;
        }
Example #5
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VMPoint obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }