示例#1
0
        public static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IEnumerable <Geometry.Point> points)
        {
            if (masters == null)
            {
                throw new System.ArgumentNullException(nameof(masters));
            }

            if (masters.Count < 1)
            {
                return(new short[0]);
            }

            if (points == null)
            {
                throw new System.ArgumentNullException(nameof(points));
            }

            // NOTE: DropMany will fail if you pass in zero items to drop
            var masters_obj_array = masters.Cast <object>().ToArray();
            var xy_array          = Geometry.Point.ToDoubles(points).ToArray();

            System.Array outids_sa;

            page.DropManyU(masters_obj_array, xy_array, out outids_sa);

            short[] outids = (short[])outids_sa;
            return(outids);
        }
        private static short[] DropManyU(
            IVisio.Page page,
            IList <IVisio.Master> masters,
            IList <VisioAutomation.Geometry.Rectangle> rects)
        {
            var points   = rects.Select(r => r.Center).ToList();
            var shapeids = page.DropManyU(masters, points);

            // Dropping takes care of the PinX and PinY
            // Now set the Width's and Heights
            var writer = new SidSrcWriter();

            for (int i = 0; i < rects.Count; i++)
            {
                writer.SetValue(shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormWidth, rects[i].Width);
                writer.SetValue(shapeids[i], VisioAutomation.ShapeSheet.SrcConstants.XFormHeight, rects[i].Height);
            }

            writer.CommitFormulas(page);

            return(shapeids);
        }
示例#3
0
        public static short[] DropManyAutoConnectors(
            IVisio.Page page,
            ICollection <Geometry.Point> points)
        {
            if (points == null)
            {
                throw new System.ArgumentNullException(nameof(points));
            }

            // NOTE: DropMany will fail if you pass in zero items to drop

            var app               = page.Application;
            var thing             = app.ConnectorToolDataObject;
            int num_points        = points.Count;
            var masters_obj_array = Enumerable.Repeat(thing, num_points).ToArray();
            var xy_array          = Geometry.Point.ToDoubles(points).ToArray();

            System.Array outids_sa;

            page.DropManyU(masters_obj_array, xy_array, out outids_sa);

            short[] outids = (short[])outids_sa;
            return(outids);
        }
        public static IList <IVisio.Shape> ConnectShapes(IVisio.Page page, IList <IVisio.Shape> fromshapes, IList <IVisio.Shape> toshapes, IVisio.Master connector_master, bool force_manual)
        {
            if (connector_master == null && force_manual)
            {
                throw new System.ArgumentNullException("if the connector object is null then force manual must be false");
            }
            // no_connector + force_manual -> INVALID
            // no_connector + not_force_manual -> AutoConect
            // yes_connector + force_manual -> Manual Connection
            // object false  + not_force_manual-> Autoconnect

            if (fromshapes == null)
            {
                throw new System.ArgumentNullException(nameof(fromshapes));
            }

            if (toshapes == null)
            {
                throw new System.ArgumentNullException(nameof(toshapes));
            }

            if (fromshapes.Count != toshapes.Count)
            {
                throw new System.ArgumentException("must have same number of from and to shapes");
            }

            if (fromshapes.Count == 0)
            {
                return(new List <IVisio.Shape>(0));
            }

            int num_connectors = fromshapes.Count;
            var connectors     = new List <IVisio.Shape>(num_connectors);

            var points = Enumerable.Range(0, num_connectors).Select(i => new Drawing.Point(i * 2.0, -2)).ToList();
            IList <IVisio.Shape> con_shapes = null;

            if (connector_master != null)
            {
                var     masters      = Enumerable.Repeat(connector_master, num_connectors).ToList();
                short[] con_shapeids = page.DropManyU(masters, points);
                con_shapes = page.Shapes.GetShapesFromIDs(con_shapeids);
            }
            else
            {
                short[] con_shapeids = Pages.PageHelper.DropManyAutoConnectors(page, points);
                con_shapes = page.Shapes.GetShapesFromIDs(con_shapeids);
            }

            for (int i = 0; i < num_connectors; i++)
            {
                var from_shape = fromshapes[i];
                var to_shape   = toshapes[i];
                var connector  = con_shapes[i];

                // Connect from Shape 1 to Shape2
                ConnectorHelper.ConnectShapes(from_shape, to_shape, connector, true);

                connectors.Add(connector);
            }

            return(connectors);
        }