コード例 #1
0
        public void AddText()
        {
            var shapes = GetCurrentlySelectedShapes();

            if (shapes.Count <= 0)
            {
                Error(TextCollection.DrawingsLabSelectAtLeastOneShape);
                return;
            }

            var text = DrawingsLabDialogs.ShowInsertTextDialog();

            if (text == null)
            {
                return;
            }

            Globals.ThisAddIn.Application.StartNewUndoEntry();
            foreach (var shape in shapes)
            {
                try
                {
                    Graphics.SetText(shape, text);
                }
                catch (ArgumentException)
                {
                    Debug.WriteLine("Unable to write text to " + shape.Name);
                }
            }
        }
コード例 #2
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;
                    }
                }
            }
        }