コード例 #1
0
        private void Gizmo_TransformationChanged(object sender, TransformationEvent transformationEvent)
        {
            switch (transformationEvent)
            {
            case TransformationEvent.TranslationStarted:
                TranslateAction translation = new TranslateAction(_vm.SelectedEntities, _vm);
                translation.TransformStartPoint         = _vm.SelectionLocation;
                GlobalManagement.Instance.CurrentAction = translation;
                break;

            case TransformationEvent.TranslationEnded:
                GlobalManagement.Instance.UndoStack.Push(GlobalManagement.Instance.CurrentAction);
                GlobalManagement.Instance.CurrentAction = null;
                break;

            case TransformationEvent.RotationStarted:
                RotateAction rotation = new RotateAction(_vm.SelectedEntities, _vm);
                mouseHandlingMode      = MouseHandlingMode.RotateObject;
                rotation.StartRotation = _vm.GizmoOrientation;
                rotation.PivotPoint    = _vm.SelectionLocation;
                GlobalManagement.Instance.CurrentAction = rotation;
                break;

            case TransformationEvent.RotationEnded:
                mouseHandlingMode = MouseHandlingMode.None;
                GlobalManagement.Instance.UndoStack.Push(GlobalManagement.Instance.CurrentAction);
                GlobalManagement.Instance.CurrentAction = null;
                break;
            }
        }
コード例 #2
0
 public void Reset()
 {
     Action = new TranslateAction();
     Action.Transform = this.transform;
 }
コード例 #3
0
        private void Instance_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if ((e.PropertyName == "GizmoDragX" && _vm.GizmoDragX) ||
                (e.PropertyName == "GizmoDragY" && _vm.GizmoDragY))
            {
                mouseHandlingMode = MouseHandlingMode.DragObject;
            }

            if (e.PropertyName == "IsCreatingRectangularBuilding" && GlobalManagement.Instance.IsCreatingRectangularBuilding)
            {
                mouseHandlingMode = MouseHandlingMode.CreateRectangle;
            }

            if (e.PropertyName == "IsCreatingPolygonalBuilding" && GlobalManagement.Instance.IsCreatingPolygonalBuilding)
            {
                mouseHandlingMode = MouseHandlingMode.CreatePolygon;
            }

            if (e.PropertyName == "IsCreatingTextMarker" && _vm.IsCreatingTextMarker)
            {
                mouseHandlingMode        = MouseHandlingMode.CreateTextMarker;
                zoomAndPanControl.Cursor = Cursors.Pen;
            }

            if (e.PropertyName == nameof(_vm.IsCreatingWallAttachement) && _vm.IsCreatingWallAttachement)
            {
                mouseHandlingMode = MouseHandlingMode.CreateWallAttachable;
            }

            if (e.PropertyName == nameof(_vm.IsCreatingWall) && _vm.IsCreatingWall)
            {
                mouseHandlingMode = MouseHandlingMode.CreateWall;
            }

            if (e.PropertyName == "SelectionLocation" && mouseHandlingMode != MouseHandlingMode.DragObject)
            {
                Point canvasPoint = FromZoomControlToCanvasCoordinates(_vm.SelectionLocation.MeterToPx());
                _vm.GizmoX = Utils.PxToMeter(canvasPoint.X - Gizmo.Width / 2);
                _vm.GizmoY = Utils.PxToMeter(canvasPoint.Y - Gizmo.Height / 2);
            }

            // update selected entities postion
            if ((e.PropertyName == "GizmoX" || e.PropertyName == "GizmoY") && mouseHandlingMode == MouseHandlingMode.DragObject)
            {
                if (GlobalManagement.Instance.CurrentAction != null && GlobalManagement.Instance.CurrentAction is TranslateAction)
                {
                    TranslateAction translation = (TranslateAction)GlobalManagement.Instance.CurrentAction;
                    Point           pxPoint     = FromCanvasToZoomControlCoordinates(new Point(Utils.MeterToPx(_vm.GizmoX) + Gizmo.Width / 2,
                                                                                               Utils.MeterToPx(_vm.GizmoY) + Gizmo.Height / 2));
                    translation.TransformEndPoint = pxPoint.PxToMeter();
                    translation.Do();
                }
                else
                {
                    mouseHandlingMode = MouseHandlingMode.None;
                }
            }

            // update selected entities rotation
            if (e.PropertyName == "GizmoOrientation" && mouseHandlingMode == MouseHandlingMode.RotateObject)
            {
                RotateAction rotation = (RotateAction)GlobalManagement.Instance.CurrentAction;
                rotation.EndRotation = _vm.GizmoOrientation;
                rotation.Do();
            }

            if (e.PropertyName == nameof(_vm.LastSelected) && !_vm.SelectedEntities.Contains(_vm.CurrentlyManipulatedObject) && !(_vm.LastSelected is VisualCornerManipulator))
            {
                // remove corner manipulators on changing selection
                var items = _vm.MapEntities.Where(item => item is VisualCornerManipulator).ToList();
                for (int i = 0; i < items.Count; i++)
                {
                    _vm.MapEntities.Remove(items[i]);
                }
                if (_vm is DataModel)
                {
                    ((DataModel)_vm).CurrentCorners = null;
                }
            }

            #region terrain
            if (e.PropertyName == "CurrentMap" || e.PropertyName == "MapWidth" || e.PropertyName == "MapHeight")
            {
                ExpandContent();
            }

            if (e.PropertyName == "ContentScale" && _vm is DataModel)
            {
                foreach (VisualCornerManipulator manipulator in _vm.MapEntities.Where(item => item is VisualCornerManipulator))
                {
                    manipulator.Width  = Constants.ManipulatorDiameter / _vm.ContentScale;
                    manipulator.Height = Constants.ManipulatorDiameter / _vm.ContentScale;
                }
            }

            if (e.PropertyName == "TerrainBrushSize" || e.PropertyName == "ContentScale")
            {
                TerrainMap.DefaultDrawingAttributes.Width  = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize);
                TerrainMap.DefaultDrawingAttributes.Height = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize);

                TerrainEllipse.Width    = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize) * _vm.ContentScale;
                TerrainEllipse.Height   = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize) * _vm.ContentScale;
                TerrainEllipse.Margin   = new Thickness(-TerrainEllipse.Width / 2, -TerrainEllipse.Height / 2, 0, 0);
                TerrainRectangle.Width  = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize) * _vm.ContentScale;
                TerrainRectangle.Height = Utils.MeterToPx(GlobalManagement.Instance.TerrainBrushSize) * _vm.ContentScale;
                TerrainRectangle.Margin = new Thickness(-TerrainRectangle.Width / 2, -TerrainRectangle.Height / 2, 0, 0);
            }
            else if (e.PropertyName == "TerrainBrush")
            {
                switch (GlobalManagement.Instance.TerrainBrush)
                {
                case TerrainBrush.Circle:
                    TerrainMap.DefaultDrawingAttributes.StylusTip = System.Windows.Ink.StylusTip.Ellipse;
                    break;

                case TerrainBrush.Rectangle:
                    TerrainMap.DefaultDrawingAttributes.StylusTip = System.Windows.Ink.StylusTip.Rectangle;
                    break;
                }
            }
            else if (e.PropertyName == "Terrain")
            {
                switch (GlobalManagement.Instance.Terrain)
                {
                case FloorMaterial.Asphalt:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.LightGray;
                    break;

                case FloorMaterial.Grass:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.OliveDrab;
                    break;

                case FloorMaterial.Stone:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.Gray;
                    break;

                case FloorMaterial.Water:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.CornflowerBlue;
                    break;

                case FloorMaterial.Wood:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.DarkGoldenrod;
                    break;

                case FloorMaterial.Sand:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.PaleGoldenrod;
                    break;

                default:
                    TerrainMap.DefaultDrawingAttributes.Color = Colors.White;
                    break;
                }
            }
            #endregion
        }