Esempio n. 1
0
        public List <int> AddHyperlink(Models.TargetShapes targets, HyperlinkCells hlink)
        {
            if (hlink == null)
            {
                throw new System.ArgumentNullException(nameof(hlink));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            var hyperlink_indices = new List <int>();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddHyperlink)))
            {
                foreach (var shape in targets.Shapes)
                {
                    int hi = HyperlinkHelper.Add(shape, hlink);
                    hyperlink_indices.Add(hi);
                }
            }

            return(hyperlink_indices);
        }
Esempio n. 2
0
        public IDictionary <IVisio.Shape, CustomPropertyDictionary> GetCustomProperties(Models.TargetShapes targets)
        {
            var cmdtarget = this._client.GetCommandTargetPage();

            var dicof_shape_to_cpdic = new Dictionary <IVisio.Shape, CustomPropertyDictionary>();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(dicof_shape_to_cpdic);
            }

            var listof_cpdic = CustomPropertyHelper.GetCellsAsDictionary(cmdtarget.ActivePage, targets.Shapes, CellValueType.Formula);


            for (int i = 0; i < targets.Shapes.Count; i++)
            {
                var shape = targets.Shapes[i];
                var cpdic = listof_cpdic[i];
                dicof_shape_to_cpdic[shape] = cpdic;
            }

            return(dicof_shape_to_cpdic);
        }
Esempio n. 3
0
        public void SetShapeName(Models.TargetShapes targets, IList <string> names)
        {
            if (names == null || names.Count < 1)
            {
                // do nothing
                return;
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetShapeName)))
            {
                int numnames = names.Count;

                int up_to = System.Math.Min(numnames, targets.Shapes.Count);

                for (int i = 0; i < up_to; i++)
                {
                    var new_name = names[i];

                    if (new_name != null)
                    {
                        var shape = targets.Shapes[i];
                        shape.Name = new_name;
                    }
                }
            }
        }
Esempio n. 4
0
        public void SetShapeText(Models.TargetShapes targets, IList <string> texts)
        {
            if (texts == null || texts.Count < 1)
            {
                return;
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetShapeText)))
            {
                // Apply text to each shape
                // if there are fewer texts than shapes then
                // start reusing the texts from the beginning

                int count = 0;
                foreach (var shape in targets.Shapes)
                {
                    string text = texts[count % texts.Count];
                    if (text != null)
                    {
                        shape.Text = text;
                    }
                    count++;
                }
            }
        }
Esempio n. 5
0
        public void DeleteCustomPropertyWithName(Models.TargetShapes targets, string name)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException(nameof(name));
            }

            if (name.Length < 1)
            {
                throw new System.ArgumentException("name cannot be empty", nameof(name));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DeleteCustomPropertyWithName)))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Delete(shape, name);
                }
            }
        }
Esempio n. 6
0
        public List <int> AddControlToShapes(Models.TargetShapes targets, ControlCells ctrl)
        {
            if (ctrl == null)
            {
                throw new System.ArgumentNullException(nameof(ctrl));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            var control_indices = new List <int>();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddControlToShapes)))
            {
                foreach (var shape in targets.Shapes)
                {
                    int ci = ControlHelper.Add(shape, ctrl);
                    control_indices.Add(ci);
                }
            }

            return(control_indices);
        }
        public Dictionary <IVisio.Shape, VA.Shapes.UserDefinedCellDictionary> GetUserDefinedCells(Models.TargetShapes targets, VASS.CellValueType cvt)
        {
            var cmdtarget = this._client.GetCommandTargetPage();
            var dicof_shape_to_udcelldic = new Dictionary <IVisio.Shape, VA.Shapes.UserDefinedCellDictionary>();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(dicof_shape_to_udcelldic);
            }

            var page             = cmdtarget.ActivePage;
            var shapeidpairs     = VisioAutomation.ShapeIDPairs.FromShapes(targets.Shapes);
            var listof_udcelldic = VA.Shapes.UserDefinedCellHelper.GetCellsAsDictionary((IVisio.Page)page, shapeidpairs, cvt);

            for (int i = 0; i < targets.Shapes.Count; i++)
            {
                var shape = targets.Shapes[i];
                var props = listof_udcelldic[i];
                dicof_shape_to_udcelldic[shape] = props;
            }

            return(dicof_shape_to_udcelldic);
        }
Esempio n. 8
0
        public Dictionary <int, LockCells> GetLockCells(Models.TargetShapes targets, VASS.CellValueType cvt)
        {
            var cmdtarget = this._client.GetCommandTargetPage();

            targets = targets.ResolveShapes(this._client);
            if (targets.Shapes.Count < 1)
            {
                return(new Dictionary <int, LockCells>());
            }

            var dic = new Dictionary <int, LockCells>();

            var page            = cmdtarget.ActivePage;
            var target_shapeids = targets.Shapes.Select(s => (int)s.ID16).ToList();

            var cells = VisioAutomation.Shapes.LockCells.GetCells(page, target_shapeids, cvt);

            for (int i = 0; i < target_shapeids.Count; i++)
            {
                var shapeid   = target_shapeids[i];
                var cur_cells = cells[i];
                dic[shapeid] = cur_cells;
            }

            return(dic);
        }
Esempio n. 9
0
        public List <string> GetShapeText(Models.TargetShapes targets)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <string>(0));
            }

            var texts = targets.Shapes.Select(s => s.Text).ToList();

            return(texts);
        }
        public void DistributeSelectionOnAxis(Models.TargetShapes targets, Models.Axis axis, double spacing)
        {
            var cmdtarget = this._client.GetCommandTargetPage();

            var page = cmdtarget.ActivePage;

            targets = targets.ResolveShapes(this._client);
            var targetids = targets.ToShapeIDs();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DistributeSelectionOnAxis)))
            {
                VisioScripting.Helpers.ArrangeHelper.DistributeWithSpacing(page, targetids, axis, spacing);
            }
        }
Esempio n. 11
0
        public List <bool> ContainCustomPropertyWithName(Models.TargetShapes targets, string name)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException(nameof(name));
            }

            targets = targets.ResolveShapes(this._client);

            var results = new List <bool>(targets.Shapes.Count);
            var values  = targets.Shapes.Select(shape => CustomPropertyHelper.Contains(shape, name));

            results.AddRange(values);

            return(results);
        }
        public void SetUserDefinedCell(Models.TargetShapes targets, Models.UserDefinedCell userdefinedcell)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetUserDefinedCell)))
            {
                foreach (var shape in targets.Shapes)
                {
                    VA.Shapes.UserDefinedCellHelper.Set(shape, userdefinedcell.Name, userdefinedcell.Cells);
                }
            }
        }
Esempio n. 13
0
        public List <VisioAutomation.Text.TextFormat> GetShapeTextFormat(Models.TargetShapes targets)
        {
            var cmdtarget = this._client.GetCommandTargetDocument();

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <VisioAutomation.Text.TextFormat>(0));
            }

            var pairs       = targets.ToShapeIdPairs();
            var application = cmdtarget.Application;
            var formats     = VisioAutomation.Text.TextFormat.GetFormat(application.ActivePage, pairs, CellValueType.Formula);

            return(formats);
        }
Esempio n. 14
0
        public Dictionary <IVisio.Shape, IList <ControlCells> > GetControls(Models.TargetShapes targets, CellValueType cvt)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new Dictionary <IVisio.Shape, IList <ControlCells> >(0));
            }

            var dic = new Dictionary <IVisio.Shape, IList <ControlCells> >(targets.Shapes.Count);

            foreach (var shape in targets.Shapes)
            {
                var controls = ControlCells.GetCells(shape, cvt);
                dic[shape] = controls;
            }
            return(dic);
        }
        public List <bool> ContainsUserDefinedCellsWithName(Models.TargetShapes targets, string name)
        {
            if (name == null)
            {
                throw new System.ArgumentNullException(nameof(name));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <bool>());
            }

            var all_shapes = this._client.Selection.GetShapesInSelection();
            var results    = all_shapes.Select(s => VA.Shapes.UserDefinedCellHelper.Contains(s, name)).ToList();

            return(results);
        }
        public IDictionary <IVisio.Shape, IList <ConnectionPointCells> > GetConnectionPoints(Models.TargetShapes targets)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new Dictionary <IVisio.Shape, IList <ConnectionPointCells> >());
            }

            var dic = new Dictionary <IVisio.Shape, IList <ConnectionPointCells> >();

            foreach (var shape in targets.Shapes)
            {
                var cp = VisioAutomation.Shapes.ConnectionPointCells.GetCells(shape, CellValueType.Formula);
                dic[shape] = cp;
            }

            return(dic);
        }
Esempio n. 17
0
        public void DeleteControlWithIndex(Models.TargetShapes targets, int index)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            // restrict the operation to those shapes that actually have enough
            // controls to qualify for deleting
            var qualified_shapes = targets.Shapes.Where(shape => ControlHelper.GetCount(shape) > index);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(DeleteControlWithIndex)))
            {
                foreach (var shape in qualified_shapes)
                {
                    ControlHelper.Delete(shape, index);
                }
            }
        }
Esempio n. 18
0
        internal void __SetCells(Models.TargetShapes targets, VASS.CellGroups.CellGroup cells, IVisio.Page page)
        {
            targets = targets.ResolveShapes(this._client);
            var shapeids = targets.ToShapeIDs();
            var writer   = new VASS.Writers.SidSrcWriter();

            foreach (var shapeid in shapeids.ShapeIDs)
            {
                if (cells is VASS.CellGroups.CellGroup)
                {
                    var cells_mr = (VASS.CellGroups.CellGroup)cells;
                    writer.SetValues((short)shapeid, cells_mr, 0);
                }
                else
                {
                    var cells_sr = (VASS.CellGroups.CellGroup)cells;
                    writer.SetValues((short)shapeid, cells_sr);
                }
            }

            writer.CommitFormulas(page);
        }
Esempio n. 19
0
        public void SetCustomProperty(Models.TargetShapes targets, string name, CustomPropertyCells customprop)
        {
            if (customprop == null)
            {
                throw new System.ArgumentNullException(nameof(customprop));
            }

            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return;
            }

            customprop.EncodeValues();

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetCustomProperty)))
            {
                foreach (var shape in targets.Shapes)
                {
                    CustomPropertyHelper.Set(shape, name, customprop);
                }
            }
        }
        public List <int> AddConnectionPoint(
            Models.TargetShapes targets,
            string fx,
            string fy,
            Models.ConnectionPointType type)
        {
            targets = targets.ResolveShapes(this._client);

            if (targets.Shapes.Count < 1)
            {
                return(new List <int>(0));
            }

            int dirx = 0;
            int diry = 0;

            var indices = new List <int>(targets.Shapes.Count);

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(AddConnectionPoint)))
            {
                var cp = new ConnectionPointCells();
                cp.X    = fx;
                cp.Y    = fy;
                cp.DirX = dirx;
                cp.DirY = diry;
                cp.Type = (int)type;

                foreach (var shape in targets.Shapes)
                {
                    int index = ConnectionPointHelper.Add(shape, cp);
                    indices.Add(index);
                }
            }

            return(indices);
        }
Esempio n. 21
0
        public void SetLockCells(Models.TargetShapes targets, LockCells lockcells)
        {
            var cmdtarget = this._client.GetCommandTargetPage();

            targets = targets.ResolveShapes(this._client);
            if (targets.Shapes.Count < 1)
            {
                return;
            }

            var page            = cmdtarget.ActivePage;
            var target_shapeids = targets.ToShapeIDs();
            var writer          = new VASS.Writers.SidSrcWriter();

            foreach (int shapeid in target_shapeids.ShapeIDs)
            {
                writer.SetValues((short)shapeid, lockcells);
            }

            using (var undoscope = this._client.Undo.NewUndoScope(nameof(SetLockCells)))
            {
                writer.CommitFormulas(page);
            }
        }