Ejemplo n.º 1
0
        private void CuboidControl_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!FullSize || IsGridVisible)
            {
                return;
            }

            CuboidControl cc     = sender as CuboidControl;
            Canvas        canvas = cc.Parent as Canvas;

            if (!cc.Cuboid.IsOnTop)
            {
                return;
            }

            MainWindowViewModel vm = DataContext as MainWindowViewModel;

            if (cc.Cuboid.FromSelection)
            {
                switch (ViewDirection)
                {
                case ViewDirection.TopView:
                    cc.Cuboid.Z = CuboidsHelper.FindLastCoordinateForTopView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Y);
                    break;

                case ViewDirection.FrontView:
                    cc.Cuboid.Y = CuboidsHelper.FindLastCoordinateForFrontView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Z) - cc.Cuboid.Depth;
                    break;

                case ViewDirection.BackView:
                    cc.Cuboid.Y = CuboidsHelper.FindLastCoordinateForBackView(vm.Cuboids, cc.Cuboid.X, cc.Cuboid.Z);
                    break;

                case ViewDirection.LeftView:
                    cc.Cuboid.X = CuboidsHelper.FindLastCoordinateForLeftView(vm.Cuboids, cc.Cuboid.Y, cc.Cuboid.Z) - cc.Cuboid.Width;
                    break;

                case ViewDirection.RightView:
                    cc.Cuboid.X = CuboidsHelper.FindLastCoordinateForRightView(vm.Cuboids, cc.Cuboid.Y, cc.Cuboid.Z);
                    break;
                }

                Cuboid newCuboid = new Cuboid(cc.Cuboid);
                if (cc.Cuboid.IsDragged && CuboidsHelper.CheckIfCanBeAdded(vm.Cuboids, newCuboid))
                {
                    ObservableCollection <Cuboid> tmp = new ObservableCollection <Cuboid>(vm.Cuboids);
                    tmp.Add(newCuboid);
                    vm.Cuboids = new ObservableCollection <Cuboid>(tmp);
                    vm.Actions.Add(new List <ActionObject>()
                    {
                        new ActionObject(newCuboid, ActionType.Add)
                    });
                }
                cc.Cuboid.IsDragged = false;
            }
            else
            {
                if (ViewDirection == ViewDirection.TopView)
                {
                    cc.Cuboid.Z = CuboidsHelper.FindLastCoordinateForTopView(vm.Cuboids, cc.Cuboid);
                }
                if (CuboidsHelper.CheckIfCanBeAdded(vm.Cuboids, cc.Cuboid))
                {
                    Cuboid startCuboid = new Cuboid(cc.Cuboid);
                    startCuboid.X = startX;
                    startCuboid.Y = startY;
                    startCuboid.Z = startZ;
                    List <ActionObject> actions = new List <ActionObject>()
                    {
                        new ActionObject(startCuboid, ActionType.Remove),
                        new ActionObject(new Cuboid(cc.Cuboid), ActionType.Add)
                    };
                    vm.Actions.Add(actions);
                }
                else
                {
                    cc.Cuboid.X = startX;
                    cc.Cuboid.Y = startY;
                    cc.Cuboid.Z = startZ;
                }
            }

            CuboidsHelper.ResetIsOnTop(vm.Cuboids);
            CuboidsHelper.ResetZIndexes(canvas, ViewDirection);
            movingObject = null;
            Mouse.Capture(null);
        }
Ejemplo n.º 2
0
        private void Konstruktor_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!FullSize || !IsGridVisible)
            {
                return;
            }

            Canvas canvas           = sender as Canvas;
            int    largeFactor      = Settings.LargeFactor;
            double firstCoordinate  = e.GetPosition(canvas).X - canvas.Margin.Left;
            double secondCoordinate = e.GetPosition(canvas).Y - canvas.Margin.Top;

            firstCoordinate  = Math.Floor(firstCoordinate / largeFactor);
            secondCoordinate = Math.Floor(secondCoordinate / largeFactor);

            int max = Settings.MaxSize;
            MainWindowViewModel vm = DataContext as MainWindowViewModel;

            if (vm.SelectedCuboidId <= 0)
            {
                return;
            }

            // Add
            Cuboid selectedCuboid = vm.CuboidsSelection[vm.SelectedCuboidId - 1];
            int    x      = 0;
            int    y      = 0;
            int    z      = 0;
            int    width  = selectedCuboid.Width;
            int    depth  = selectedCuboid.Depth;
            int    height = selectedCuboid.Height;

            switch (ViewDirection)
            {
            case ViewDirection.TopView:
                x = (int)firstCoordinate;
                y = max - depth - (int)secondCoordinate;
                z = CuboidsHelper.FindLastCoordinateForTopView(Cuboids, x, y);
                break;

            case ViewDirection.FrontView:
                x = (int)firstCoordinate;
                z = max - height - (int)secondCoordinate;
                y = CuboidsHelper.FindLastCoordinateForFrontView(Cuboids, x, z) - depth;
                break;

            case ViewDirection.BackView:
                x = max - width - (int)firstCoordinate;
                z = max - height - (int)secondCoordinate;
                y = CuboidsHelper.FindLastCoordinateForBackView(Cuboids, x, z);
                break;

            case ViewDirection.LeftView:
                y = max - depth - (int)firstCoordinate;
                z = max - height - (int)secondCoordinate;
                x = CuboidsHelper.FindLastCoordinateForLeftView(Cuboids, y, z) - width;
                break;

            case ViewDirection.RightView:
                y = (int)firstCoordinate;
                z = max - height - (int)secondCoordinate;
                x = CuboidsHelper.FindLastCoordinateForRightView(Cuboids, y, z);
                break;
            }

            Cuboid newCuboid = new Cuboid(width, depth, height, x, y, z);

            if (CuboidsHelper.CheckIfCanBeAdded(Cuboids, newCuboid))
            {
                AddCuboid(newCuboid);
            }
        }