Exemple #1
0
        public void MultiCloneExtendTool()
        {
            var shapes = GetCurrentlySelectedShapes();

            if (shapes.Count == 0 || shapes.Count % 2 != 0)
            {
                Error(TextCollection.DrawingsLabSelectTwoSetsOfShapes);
                return;
            }

            int clones = DrawingsLabDialogs.ShowMultiCloneNumericDialog();

            if (clones <= 0)
            {
                return;
            }

            Globals.ThisAddIn.Application.StartNewUndoEntry();
            int midpoint = shapes.Count / 2;

            for (int i = 0; i < shapes.Count / 2; ++i)
            {
                // Do the cloning for every pair of shapes (i, midpoint+i)
                var firstShape  = shapes[i];
                var secondShape = shapes[midpoint + i];

                var newlyAddedShapes = new List <Shape>();
                for (int j = 0; j < clones; ++j)
                {
                    var newShape = firstShape.Duplicate()[1];
                    int index    = j + 1;

                    newShape.Left     = secondShape.Left + (secondShape.Left - firstShape.Left) * index;
                    newShape.Top      = secondShape.Top + (secondShape.Top - firstShape.Top) * index;
                    newShape.Rotation = secondShape.Rotation + (secondShape.Rotation - firstShape.Rotation) * index;
                    newlyAddedShapes.Add(newShape);
                }

                // Set Z-Orders of newly created shapes.
                if (secondShape.ZOrderPosition < firstShape.ZOrderPosition)
                {
                    // first shape in front of last shape. Order the in-between shapes accordingly.
                    Shape prevShape = secondShape;
                    foreach (var shape in newlyAddedShapes)
                    {
                        Graphics.MoveZUntilBehind(shape, prevShape);
                        prevShape = shape;
                    }
                }
            }
        }
Exemple #2
0
        private static void SynchroniseZOrders(SortedDictionary <int, Shape> shapeOriginalZOrders)
        {
            Shape lastShape = null;

            foreach (var entry in shapeOriginalZOrders.Reverse())
            {
                var shape = entry.Value;
                if (lastShape != null)
                {
                    Graphics.MoveZUntilBehind(shape, lastShape);
                }
                lastShape = shape;
            }
        }
Exemple #3
0
        public void SendBehindShape()
        {
            var shapes = GetCurrentlySelectedShapes();

            if (shapes.Count < 2)
            {
                Error(TextCollection.DrawingsLabSelectAtLeastTwoShapes);
                return;
            }

            Globals.ThisAddIn.Application.StartNewUndoEntry();
            var shapeToMoveBehind = shapes.Last();

            shapes.RemoveAt(shapes.Count - 1);

            Graphics.SortByZOrder(shapes);
            shapes.Reverse();
            foreach (var shape in shapes)
            {
                Graphics.MoveZUntilBehind(shape, shapeToMoveBehind);
            }
        }
Exemple #4
0
        public void MultiCloneGridTool()
        {
            var shapes = GetCurrentlySelectedShapes();

            if (shapes.Count != 2)
            {
                Error(TextCollection.DrawingsLabSelectExactlyTwoShapes);
                return;
            }

            var sourceShape = shapes[0];
            var targetShape = shapes[1];

            var dialog = new MultiCloneGridDialog(sourceShape.Left, sourceShape.Top, targetShape.Left, targetShape.Top);

            if (dialog.ShowDialog() != true)
            {
                return;
            }
            if (dialog.DialogResult != true)
            {
                return;
            }

            Globals.ThisAddIn.Application.StartNewUndoEntry();
            // Clone shapes in a grid.
            var newlyAddedShapes = new List <Shape>();

            var dx         = targetShape.Left - sourceShape.Left;
            var dy         = targetShape.Top - sourceShape.Top;
            int skipIndexX = 1;
            int skipIndexY = 1;

            if (!dialog.IsExtend)
            {
                // Is between.
                dx         = dx / (dialog.XCopies - 1);
                dy         = dy / (dialog.YCopies - 1);
                skipIndexX = dialog.XCopies - 1;
                skipIndexY = dialog.YCopies - 1;
            }

            for (int y = 0; y < dialog.YCopies; ++y)
            {
                for (int x = 0; x < dialog.XCopies; ++x)
                {
                    if (x == 0 && y == 0)
                    {
                        continue;
                    }
                    if (x == skipIndexX && y == skipIndexY)
                    {
                        continue;
                    }

                    var newShape = sourceShape.Duplicate()[1];
                    newShape.Left = sourceShape.Left + dx * x;
                    newShape.Top  = sourceShape.Top + dy * y;
                    newlyAddedShapes.Add(newShape);
                }
            }

            // Set Z-Orders of newly created shapes.
            if (dialog.IsExtend)
            {
                // Multiclone Extend
                if (sourceShape.ZOrderPosition < targetShape.ZOrderPosition)
                {
                    if (newlyAddedShapes.Count >= dialog.YCopies)
                    {
                        for (int i = 0; i < dialog.YCopies; ++i)
                        {
                            Graphics.MoveZToJustBehind(newlyAddedShapes[i], targetShape);
                        }
                    }
                }
                else
                {
                    // first shape in front of last shape. Order the in-between shapes accordingly.
                    Shape prevShape = targetShape;
                    foreach (var shape in newlyAddedShapes)
                    {
                        Graphics.MoveZUntilBehind(shape, prevShape);
                        prevShape = shape;
                    }

                    if (newlyAddedShapes.Count >= dialog.YCopies)
                    {
                        for (int i = 0; i < dialog.YCopies; ++i)
                        {
                            Graphics.MoveZToJustInFront(newlyAddedShapes[i], targetShape);
                        }
                    }
                }
            }
            else
            {
                // Multiclone Between
                if (sourceShape.ZOrderPosition < targetShape.ZOrderPosition)
                {
                    // last shape in front of first shape. Order the in-between shapes accordingly.
                    foreach (var shape in newlyAddedShapes)
                    {
                        Graphics.MoveZUntilBehind(shape, targetShape);
                    }
                }
                else
                {
                    // first shape in front of last shape. Order the in-between shapes accordingly.
                    newlyAddedShapes.Reverse();
                    foreach (var shape in newlyAddedShapes)
                    {
                        Graphics.MoveZUntilBehind(shape, sourceShape);
                    }
                }
            }
        }