Ejemplo n.º 1
0
        private void AddAdjacentPoint(Face face, VMPoint point)
        {
            var solid = face.Parent;
            var s     = point.MidpointStart.Coordinate;
            var e     = point.MidpointEnd.Coordinate;

            foreach (var f in solid.Faces.Where(x => x != face))
            {
                foreach (var edge in f.GetEdges())
                {
                    if (edge.Start == s && edge.End == e)
                    {
                        var idx = f.Vertices.FindIndex(x => x.Location == e);
                        f.Vertices.Insert(idx, new Vertex(point.Coordinate, f));
                        return;
                    }
                    if (edge.Start == e && edge.End == s)
                    {
                        var idx = f.Vertices.FindIndex(x => x.Location == s);
                        f.Vertices.Insert(idx, new Vertex(point.Coordinate, f));
                        return;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public ScaleTool(VMTool mainTool)
     : base(mainTool)
 {
     var sc = new ScaleControl();
     Control = sc;
     sc.ValueChanged += ValueChanged;
     sc.ValueReset += ValueReset;
     sc.ResetOrigin += ResetOrigin;
     _origin = new VMPoint {Coordinate = Coordinate.Zero, Vertices = new List<Vertex>()};
 }
Ejemplo n.º 3
0
        public ScaleTool(VMTool mainTool) : base(mainTool)
        {
            var sc = new ScaleControl();

            Control          = sc;
            sc.ValueChanged += ValueChanged;
            sc.ValueReset   += ValueReset;
            sc.ResetOrigin  += ResetOrigin;
            _origin          = new VMPoint {
                Coordinate = Coordinate.Zero, Vertices = new List <Vertex>()
            };
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public override void ToolSelected(bool preventHistory)
        {
            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);
        }
Ejemplo n.º 7
0
 public bool IsMidPointFor(VMPoint start, VMPoint end)
 {
     return(IsMidPoint &&
            ((start == MidpointStart && end == MidpointEnd) ||
             (end == MidpointStart && start == MidpointEnd)));
 }
Ejemplo n.º 8
0
        private void AddAdjacentPoint(Face face, VMPoint point)
        {
            var solid = face.Parent;
            var s = point.MidpointStart.Coordinate;
            var e = point.MidpointEnd.Coordinate;

            foreach (var f in solid.Faces.Where(x => x != face))
            {
                foreach (var edge in f.GetEdges())
                {
                    if (edge.Start == s && edge.End == e)
                    {
                        var idx = f.Vertices.FindIndex(x => x.Location == e);
                        f.Vertices.Insert(idx, new Vertex(point.Coordinate, f));
                        return;
                    }
                    if (edge.Start == e && edge.End == s)
                    {
                        var idx = f.Vertices.FindIndex(x => x.Location == s);
                        f.Vertices.Insert(idx, new Vertex(point.Coordinate, f));
                        return;
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public bool IsMidPointFor(VMPoint start, VMPoint end)
 {
     return IsMidPoint
            && ((start == MidpointStart && end == MidpointEnd)
                || (end == MidpointStart && start == MidpointEnd));
 }
Ejemplo n.º 10
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;
        }