示例#1
0
        public IVisio.Shape RenderPie(IVisio.Page page)
        {
            if (this.Angle == 0.0)
            {
                var p1 = this.GetPointAtRadius(this.Center, this.Radius, this.SectorStartAngle);
                return(page.DrawLine(this.Center, p1));
            }
            else if (this.Angle >= 2 * System.Math.PI)
            {
                var A     = this.Center.Add(-this.Radius, -this.Radius);
                var B     = this.Center.Add(this.Radius, this.Radius);
                var rect  = new Drawing.Rectangle(A, B);
                var shape = page.DrawOval(rect);
                return(shape);
            }
            else
            {
                int degree;
                var pie_bez = this.GetShapeBezierForPie(out degree);

                // Render the bezier
                var doubles_array = Drawing.Point.ToDoubles(pie_bez).ToArray();
                var pie_slice     = page.DrawBezier(doubles_array, (short)degree, 0);
                return(pie_slice);
            }
        }
示例#2
0
        public IVisio.Shape RenderDoughnut(IVisio.Page page)
        {
            double total_angle = this.Angle;

            if (total_angle == 0.0)
            {
                var p1    = this.GetPointAtRadius(this.Center, this.SectorStartAngle, this.InnerRadius);
                var p2    = this.GetPointAtRadius(this.Center, this.SectorStartAngle, this.Radius);
                var shape = page.DrawLine(p1, p2);
                return(shape);
            }
            else if (total_angle >= System.Math.PI)
            {
                var outer_radius_point = new Drawing.Point(this.Radius, this.Radius);
                var C          = this.Center - outer_radius_point;
                var D          = this.Center + outer_radius_point;
                var outer_rect = new Drawing.Rectangle(C, D);

                var inner_radius_point = new Drawing.Point(this.InnerRadius, this.InnerRadius);
                var A          = this.Center - inner_radius_point - C;
                var B          = this.Center + inner_radius_point - C;
                var inner_rect = new Drawing.Rectangle(A, B);

                var shape = page.DrawOval(outer_rect);
                shape.DrawOval(inner_rect.Left, inner_rect.Bottom, inner_rect.Right, inner_rect.Top);

                return(shape);
            }
            else
            {
                int degree;
                var thickarc = this.GetShapeBezierForDoughnut(out degree);

                // Render the bezier
                var doubles_array = Drawing.Point.ToDoubles(thickarc).ToArray();
                var pie_slice     = page.DrawBezier(doubles_array, (short)degree, 0);
                return(pie_slice);
            }
        }
示例#3
0
        public static void AutomateVisio()
        {
            Visio.Application oVisio     = null;
            Visio.Documents   oDocs      = null;
            Visio.Document    oDoc       = null;
            Visio.Pages       oPages     = null;
            Visio.Page        oPage      = null;
            Visio.Shape       oRectShape = null;
            Visio.Shape       oOvalShape = null;

            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                oVisio         = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                oDocs = oVisio.Documents;
                oDoc  = oDocs.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");

                oPages     = oDoc.Pages;
                oPage      = oPages[1];
                oRectShape = oPage.DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oOvalShape = oPage.DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample1.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution1.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
            finally
            {
                // Clean up the unmanaged Visio COM resources by explicitly
                // calling Marshal.FinalReleaseComObject on all accessor objects.
                // See http://support.microsoft.com/kb/317109.

                if (oOvalShape != null)
                {
                    Marshal.FinalReleaseComObject(oOvalShape);
                    oOvalShape = null;
                }
                if (oRectShape != null)
                {
                    Marshal.FinalReleaseComObject(oRectShape);
                    oRectShape = null;
                }
                if (oPage != null)
                {
                    Marshal.FinalReleaseComObject(oPage);
                    oPage = null;
                }
                if (oPages != null)
                {
                    Marshal.FinalReleaseComObject(oPages);
                    oPages = null;
                }
                if (oDoc != null)
                {
                    Marshal.FinalReleaseComObject(oDoc);
                    oDoc = null;
                }
                if (oDocs != null)
                {
                    Marshal.FinalReleaseComObject(oDocs);
                    oDocs = null;
                }
                if (oVisio != null)
                {
                    Marshal.FinalReleaseComObject(oVisio);
                    oVisio = null;
                }
            }
        }