public IVisio.Page CreatePage(FormPage formpage)
        {
            this.FormPage = formpage;

            this.page = this.VisioPages.Add();
            this.page.Name = formpage.Name;

            // Update the Page Cells
            var pagesheet = this.page.PageSheet;
            var pageupdate = new ShapeSheet.Update();

            var pagecells = new Pages.PageCells();
            pagecells.PageWidth = formpage.Size.Width;
            pagecells.PageHeight = formpage.Size.Height;
            pagecells.PageLeftMargin = formpage.Margin.Left;
            pagecells.PageRightMargin = formpage.Margin.Right;
            pagecells.PageTopMargin = formpage.Margin.Top;
            pagecells.PageBottomMargin = formpage.Margin.Bottom;
            pageupdate.SetFormulas(pagecells);
            pageupdate.Execute(pagesheet);


            this.Reset();
            return this.page;
        }
Exemplo n.º 2
0
 public PageComparer(Visio.Application app, Visio.Page page1, Visio.Page page2, Visio.Page resultPage)
 {
     _page1 = page1;
     _page2 = page2;
     _resultPage = resultPage;
     _app = app;
 }
Exemplo n.º 3
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }


            // First handle any page properties
            if (this.Name!=null)
            {
                page.NameU = this.Name;
            }

            this.VisioPage = page;

            var page_sheet = page.PageSheet;

            var app = page.Application;


            using (var perfscope = new Application.PerfScope(app, this.PerfSettings))
            {
                if (this.Size.HasValue)
                {
                    this.PageCells.PageHeight = this.Size.Value.Height;
                    this.PageCells.PageWidth = this.Size.Value.Width;
                }

                var update = new ShapeSheet.Update();
                update.SetFormulas((short)page_sheet.ID, this.PageCells);
                update.Execute(page);
                
                // Then render the shapes
                this.Shapes.Render(page);

                // Perform any additional layout
                if (this.Layout != null)
                {
                    this.Layout.Apply(page);
                }

                // Optionally, perform page resizing to fit contents
                if (this.ResizeToFit)
                {
                    if (this.ResizeToFitMargin.HasValue)
                    {
                        page.ResizeToFitContents(this.ResizeToFitMargin.Value);
                    }
                    else
                    {
                        page.ResizeToFitContents();
                    }
                }
            }

        }
        public SurfaceTarget(IVisio.Master master)
        {
            if (master== null)
            {
                throw new System.ArgumentNullException(nameof(master));
            }

            this.Page = null;
            this.Master = master;
            this.Shape = null;
        }
        public SurfaceTarget(IVisio.Shape shape)
        {
            if (shape== null)
            {
                throw new System.ArgumentNullException(nameof(shape));
            }

            this.Page = null;
            this.Master = null;
            this.Shape = shape;
        }
Exemplo n.º 6
0
        public IVisio.Page Render(IVisio.Document doc)
        {
            if (doc== null)
            {
                throw new System.ArgumentNullException(nameof(doc));
            }

            var pages = doc.Pages;
            var page = pages.Add();
            this.VisioPage = page;

            this.Render(page);
            
            return page;
        }
Exemplo n.º 7
0
        public static bool GetIntCellVal(Visio.Page visPage, string strCellName, out int iValue)
        {
            Visio.Shape visShapePage;
            Visio.Cell  visCell;
            iValue = -1;

            try
            {
                visShapePage = visPage.PageSheet;
                visCell      = visShapePage.get_CellsU(strCellName);
                return(GetIntCellVal(visCell, (int)Visio.VisUnitCodes.visNumber, out iValue));
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        public static bool GetDoubleCellVal(Visio.Page visPage, string strCellName, int visUnits, out double dblValue)
        {
            Visio.Shape visShapePage;
            Visio.Cell  visCell;
            dblValue = -1.0;

            try
            {
                visShapePage = visPage.PageSheet;
                visCell      = visShapePage.get_CellsU(strCellName);
                return(GetDoubleCellVal(visCell, visUnits, out dblValue));
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 9
0
        internal IVisio.Page Draw(FormRenderingContext context)
        {
            var r = new InteractiveRenderer(context.Document);

            this.VisioPage = r.CreatePage(this);
            context.Page   = this.VisioPage;

            var titleblock = new TextBlock(new Geometry.Size(7.5, 0.5), this.Title);

            int fontid = context.GetFontID(this.DefaultFont);

            titleblock.TextBlockCells.VerticalAlign         = 0;
            titleblock.ParagraphFormatCells.HorizontalAlign = 0;
            titleblock.FormatCells.LineWeight    = 0;
            titleblock.FormatCells.LinePattern   = 0;
            titleblock.CharacterFormatCells.Font = fontid;
            titleblock.CharacterFormatCells.Size = get_pt_string(this.TitleTextSize);



            // Draw the shapes
            var titleshape = r.AddShape(titleblock);

            r.Linefeed();

            double body_height = r.GetDistanceToBottomMargin();
            var    bodyblock   = new TextBlock(new Geometry.Size(7.5, body_height), this.Body);

            bodyblock.ParagraphFormatCells.HorizontalAlign = 0;
            bodyblock.ParagraphFormatCells.SpacingAfter    = get_pt_string(this.BodyParaSpacingAfter);
            bodyblock.CharacterFormatCells.Font            = fontid;
            bodyblock.CharacterFormatCells.Size            = get_pt_string(this.BodyTextSize);
            bodyblock.FormatCells.LineWeight       = 0;
            bodyblock.FormatCells.LinePattern      = 0;
            bodyblock.TextBlockCells.VerticalAlign = 0;
            bodyblock.FormatCells.LineWeight       = 0;
            bodyblock.FormatCells.LinePattern      = 0;

            var bodyshape = r.AddShape(bodyblock);

            r.Linefeed();

            r.Finish();
            return(this.VisioPage);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a new page in a Visio file showing all the direct entity relationships participated in
        /// by the passed-in array of entities.
        /// </summary>
        /// <param name="entities">Core entities for the diagram</param>
        /// <param name="worker">The worker.</param>
        /// <param name="e">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param>
        private void BuildDiagram(List <string> entities, BackgroundWorker worker, DoWorkEventArgs e)
        {
            // Get the default page of our new document
            VisioApi.Page page = _document.Pages[1];
            page.Name = "MSCRMToolKit generated diagram";
            int cptEntititesTreated = 0;

            // Get the metadata for each passed-in entity, draw it, and draw its relationships.
            foreach (string entityName in entities)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
                cptEntititesTreated++;
                worker.ReportProgress(cptEntititesTreated);
                EntityMetadata entity = GetEntityMetadata(entityName);

                // Create a Visio rectangle shape.
                VisioApi.Shape rect;

                try
                {
                    // There is no "Get Try", so we have to rely on an exception to tell us it does not exists
                    // We have to skip some entities because they may have already been added by relationships of another entity
                    rect = page.Shapes.get_ItemU(entity.LogicalName);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    rect = DrawEntityRectangle(page, entity);
                }

                // Draw all relationships TO this entity.
                DrawRelationships(entity, rect, entity.ManyToManyRelationships, false, worker, e);
                DrawRelationships(entity, rect, entity.ManyToOneRelationships, false, worker, e);

                // Draw all relationshipos FROM this entity
                DrawRelationships(entity, rect, entity.OneToManyRelationships, true, worker, e);
            }

            // Arrange the shapes to fit the page.
            page.Layout();
            page.ResizeToFitContents();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a new page in a Visio file showing all the direct entity relationships participated in
        /// by the passed-in array of entities.
        /// </summary>
        /// <param name="entities">Core entities for the diagram</param>
        /// <param name="pageTitle">Page title</param>
        private void BuildDiagram(string[] entities, string pageTitle)
        {
            // Get the default page of our new document
            VisioApi.Page page = _document.Pages[1];
            page.Name = pageTitle;
            int i = 1;

            // Get the metadata for each passed-in entity, draw it, and draw its relationships.
            foreach (string entityName in entities)
            {
                Console.Write("Processing entity {1}/{2} {3}: {0}", entityName, i, entities.Length, DateTime.Now.ToLongTimeString());

                EntityMetadata entity = GetEntityMetadata(entityName);

                // Create a Visio rectangle shape.
                VisioApi.Shape rect;

                try
                {
                    // There is no "Get Try", so we have to rely on an exception to tell us it does not exists
                    // We have to skip some entities because they may have already been added by relationships of another entity
                    rect = page.Shapes.get_ItemU(entity.LogicalName);
                }
                catch (System.Runtime.InteropServices.COMException)
                {
                    rect = DrawEntityRectangle(page, entity.LogicalName, null == entity.DisplayName.UserLocalizedLabel ? "" : entity.DisplayName.UserLocalizedLabel.Label, entity.OwnershipType.Value);
                    Console.Write('.');                     // Show progress
                }

                // Draw all relationships TO this entity.
                DrawRelationships(entity, rect, entity.ManyToManyRelationships, false);
                Console.Write('.');                 // Show progress
                DrawRelationships(entity, rect, entity.ManyToOneRelationships, false);

                // Draw all relationshipos FROM this entity
                DrawRelationships(entity, rect, entity.OneToManyRelationships, true);
                Console.WriteLine('.');                 // Show progress

                i++;
            }

            // Arrange the shapes to fit the page.
            page.Layout();
            page.ResizeToFitContents();
        }
Exemplo n.º 12
0
        public static List <CustomPropertyDictionary> Get(IVisio.Page page, IList <IVisio.Shape> shapes)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (shapes == null)
            {
                throw new ArgumentNullException(nameof(shapes));
            }

            var shapeids              = shapes.Select(s => s.ID).ToList();
            var customprops_dic       = new List <CustomPropertyDictionary>(shapeids.Count);
            var customprops_per_shape = CustomPropertyCells.GetCells(page, shapeids);

            if (customprops_per_shape.Count != shapeids.Count)
            {
                throw new InternalAssertionException();
            }

            for (int shape_index = 0; shape_index < shapeids.Count; shape_index++)
            {
                var shape = shapes[shape_index];
                var customprops_for_shape = customprops_per_shape[shape_index];
                var prop_names            = CustomPropertyHelper.GetNames(shape);

                if (customprops_for_shape.Count != prop_names.Count)
                {
                    throw new InternalAssertionException();
                }

                var dic = new CustomPropertyDictionary(prop_names.Count);

                for (int prop_index = 0; prop_index < prop_names.Count(); prop_index++)
                {
                    string prop_name = prop_names[prop_index];
                    dic[prop_name] = customprops_for_shape[prop_index];
                }

                customprops_dic.Add(dic);
            }

            return(customprops_dic);
        }
Exemplo n.º 13
0
        public static IList <Dictionary <string, CustomPropertyCells> > Get(IVisio.Page page, IList <IVisio.Shape> shapes)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            if (shapes == null)
            {
                throw new ArgumentNullException("shapes");
            }

            var shapeids              = shapes.Select(s => s.ID).ToList();
            var customprops_dic       = new List <Dictionary <string, CustomPropertyCells> >(shapeids.Count);
            var customprops_per_shape = CustomPropertyCells.GetCells(page, shapeids);

            if (customprops_per_shape.Count != shapeids.Count)
            {
                throw new VA.AutomationException("1");
            }

            for (int shape_index = 0; shape_index < shapeids.Count; shape_index++)
            {
                var shape = shapes[shape_index];
                var customprops_for_shape = customprops_per_shape[shape_index];
                var prop_names            = GetNames(shape);

                if (customprops_for_shape.Count != prop_names.Count)
                {
                    throw new VA.AutomationException("2");
                }

                var dic = new Dictionary <string, CustomPropertyCells>(prop_names.Count);

                for (int prop_index = 0; prop_index < prop_names.Count(); prop_index++)
                {
                    string prop_name = prop_names[prop_index];
                    dic[prop_name] = customprops_for_shape[prop_index];
                }

                customprops_dic.Add(dic);
            }

            return(customprops_dic);
        }
Exemplo n.º 14
0
        public void Generate(CfgSystem system)
        {
            Visio.Application visio = new Visio.Application();
            Visio.Document    doc   = visio.Documents.Add("");
            Visio.Page        page  = doc.Pages[1];
            page.Name = "Architecture";

            // Open with flags Visio.VisOpenSaveArgs.visOpenRO | Visio.VisOpenSaveArgs.visOpenDocked.
            Visio.Document stencil      = visio.Documents.OpenEx(Settings.StencilName, 0x2 | 0x4);
            Visio.Master   serverMaster = stencil.Masters["Server"];

            double paperHeight = doc.get_PaperHeight(Visio.VisUnitCodes.visInches);
            double paperWidth  = doc.get_PaperWidth(Visio.VisUnitCodes.visInches);

            int    numColumns       = 2;
            int    numRows          = (system.Hosts.Count + (numColumns - 1)) / numColumns;
            double verticalGap      = paperHeight / numRows;
            double horizontalGap    = paperWidth / numColumns;
            double verticalMargin   = verticalGap / 2;
            double horizontalMargin = horizontalGap / 2;

            double verticalPosition   = verticalMargin;
            double horizontalPosition = horizontalMargin;
            int    verticalIndex      = 1;
            int    horizontalIndex    = 1;

            foreach (CfgHost host in system.Hosts)
            {
                Visio.Shape shape = page.Drop(serverMaster, horizontalPosition, verticalPosition);
                modifyShapeText(shape, host);

                if (verticalIndex == numRows)
                {
                    verticalIndex       = 1;
                    verticalPosition    = verticalMargin;
                    horizontalIndex    += 1;
                    horizontalPosition += horizontalGap;
                }
                else
                {
                    verticalIndex    += 1;
                    verticalPosition += verticalGap;
                }
            }
        }
Exemplo n.º 15
0
        public static void DistributeWithSpacing(IVisio.Page page, IList <int> shapeids, Drawing.Axis axis, double spacing)
        {
            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(spacing));
            }

            if (shapeids.Count < 2)
            {
                return;
            }

            // Calculate the new Xfrms
            var sortpos = axis == Drawing.Axis.XAxis
                ? RelativePosition.PinX
                : RelativePosition.PinY;

            var delta = axis == Drawing.Axis.XAxis
                ? new Drawing.Size(spacing, 0)
                : new Drawing.Size(0, spacing);


            var sorted_shape_ids = ArrangeHelper.SortShapesByPosition(page, shapeids, sortpos);
            var input_xfrms      = Shapes.XFormCells.GetCells(page, sorted_shape_ids);
            var output_xfrms     = new List <Shapes.XFormCells>(input_xfrms.Count);
            var bb      = ArrangeHelper.GetBoundingBox(input_xfrms);
            var cur_pos = new Drawing.Point(bb.Left, bb.Bottom);

            foreach (var input_xfrm in input_xfrms)
            {
                var new_pinpos = axis == Drawing.Axis.XAxis
                    ? new Drawing.Point(cur_pos.X + input_xfrm.LocPinX.Result, input_xfrm.PinY.Result)
                    : new Drawing.Point(input_xfrm.PinX.Result, cur_pos.Y + input_xfrm.LocPinY.Result);

                var output_xfrm = new Shapes.XFormCells();
                output_xfrm.PinX = new_pinpos.X;
                output_xfrm.PinY = new_pinpos.Y;
                output_xfrms.Add(output_xfrm);

                cur_pos = cur_pos.Add(input_xfrm.Width.Result, input_xfrm.Height.Result).Add(delta);
            }

            // Apply the changes
            ArrangeHelper.update_xfrms(page, sorted_shape_ids, output_xfrms);
        }
Exemplo n.º 16
0
        internal static void GetSourceFileInfo(Visio.Application app, string doc, string page, string shape, string shapeu, string[] v)
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           MethodBase.GetCurrentMethod().Name));

            Visio.Page  activePage  = app.ActivePage;
            Visio.Shape activeShape = app.ActivePage.Shapes[shape];

            try
            {
                FileInfoShape fileInfoShape = new FileInfoShape(activeShape);

                VisioHelper.DisplayInWatchWindow(string.Format("{0}",
                                                               fileInfoShape.ToString()));

                VisioHelper.DisplayInWatchWindow(string.Format("{0}",
                                                               fileInfoShape.DisplayInfo()));

                string fileNameAndPath = fileInfoShape.SourceFileFileName;

                var sourceCode = "";

                using (var sr = new StreamReader(fileNameAndPath))
                {
                    sourceCode = sr.ReadToEnd();
                }

                List <String> methodNames = VNC.CodeAnalysis.Helpers.VB.GetMethodNames(sourceCode);

                // OK.  Now we have a list of Method Names.  Let's add shapes for each of them.

                Visio.Master methodMaster = app.Documents[@"API.vssx"].Masters[@"Roslyn SuperFile"];

                foreach (string methodName in methodNames)
                {
                    Visio.Shape newMethod = activePage.Drop(methodMaster, 5.0, 5.0);
                    newMethod.CellsU["Prop.MethodName"].FormulaU = methodName.WrapInDblQuotes();
                }
            }
            catch (Exception ex)
            {
                VisioHelper.DisplayInWatchWindow(string.Format("{0}",
                                                               ex.ToString()));
            }
        }
Exemplo n.º 17
0
        public static void Render(IVisio.Page page, DirectedGraphLayout directedGraphLayout, MsaglLayoutOptions options)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var renderer = new MsaglRenderer();

            renderer.LayoutOptions = options;
            renderer.Render(directedGraphLayout, page);
            page.ResizeToFitContents(renderer.LayoutOptions.ResizeBorderWidth);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Converts the selected Flow Diagram to an Architecture Chart.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void convertToArchChartBtn_Click(object sender, RibbonControlEventArgs e)
        {
            // The user needs to select one or more Transform Center node of a Transform
            // Center Diagram to start the conversion.
            Visio.Selection selection = app.ActiveWindow.Selection;

            if (selection.Count == 0)
            {
                MessageBox.Show("Select a Data Flow Diagram to Convert.");
            }
            else
            {
                // Outputs the resulting Chart on the Architecture Chart Page.
                Visio.Page outputPage = Utilities.getDrawingPage(app, CaseTypes.ARCHITECTURE_PAGE);
                FlowSystem flowEditor = new FlowSystem();
                flowEditor.convertToArchitectureChart(selection, outputPage);
            }
        }
Exemplo n.º 19
0
        public static VisioAutomation.Drawing.Size GetPageSize(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var query      = new ShapeSheetQuery();
            var col_height = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageHeight, "PageHeight");
            var col_width  = query.AddCell(VisioAutomation.ShapeSheet.SrcConstants.PageWidth, "PageWidth");

            var    results = query.GetResults <double>(page.PageSheet);
            double height  = results.Cells[col_height];
            double width   = results.Cells[col_width];
            var    s       = new VisioAutomation.Drawing.Size(width, height);

            return(s);
        }
Exemplo n.º 20
0
        public static VA.Geometry.Size GetPageSize(IVisio.Page page)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException(nameof(page));
            }

            var query      = new CellQuery();
            var col_height = query.Columns.Add(VA.ShapeSheet.SrcConstants.PageHeight, nameof(VA.ShapeSheet.SrcConstants.PageHeight));
            var col_width  = query.Columns.Add(VA.ShapeSheet.SrcConstants.PageWidth, nameof(VA.ShapeSheet.SrcConstants.PageHeight));

            var    results = query.GetResults <double>(page.PageSheet);
            double height  = results.Cells[col_height];
            double width   = results.Cells[col_width];
            var    s       = new VA.Geometry.Size(width, height);

            return(s);
        }
Exemplo n.º 21
0
        public static void SnapCorner(IVisio.Page page, IList <int> shapeids, VA.Drawing.Size snapsize, VA.Arrange.SnapCornerPosition corner)
        {
            // First caculate the new transforms
            var snap_grid    = new VA.Drawing.SnappingGrid(snapsize);
            var input_xfrms  = ArrangeHelper.GetXForm(page, shapeids);
            var output_xfrms = new List <VA.Shapes.XFormCells>(input_xfrms.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var old_lower_left = ArrangeHelper.GetRectangle(input_xfrm).LowerLeft;
                var new_lower_left = snap_grid.Snap(old_lower_left);
                var output_xfrm    = _SnapCorner(corner, new_lower_left, input_xfrm);
                output_xfrms.Add(output_xfrm);
            }

            // Now apply them
            update_xfrms(page, shapeids, output_xfrms);
        }
Exemplo n.º 22
0
        private List <ShapeInfo> getAllConnectors(VisioDrawing v)
        {
            List <ShapeInfo> list = new List <ShapeInfo>();
            AxDrawingControl dc   = v.visioControl;

            Visio.Page currentPage = dc.Window.Application.ActivePage;
            foreach (Visio.Shape shp in currentPage.Shapes)
            {
                if (shp.NameU.Contains("Connector"))
                {
                    ShapeInfo si = new ShapeInfo();
                    si.NameU = shp.NameU;
                    si.Text  = shp.Text;
                    list.Add(si);
                }
            }
            return(list);
        }
Exemplo n.º 23
0
        public static List <CustomPropertyDictionary> GetCells(IVisio.Page page, IList <IVisio.Shape> shapes, CellValueType type)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            if (shapes == null)
            {
                throw new ArgumentNullException(nameof(shapes));
            }

            var shapeids = shapes.Select(s => s.ID).ToList();
            var customprops_per_shape = CustomPropertyCells.GetCells(page, shapeids, type);
            var customprops_dic       = create_dic(shapes, shapeids, customprops_per_shape);

            return(customprops_dic);
        }
Exemplo n.º 24
0
        protected static IList <T> _GetCells <T, RT>(
            IVisio.Page page, IList <int> shapeids,
            Query.CellQuery query,
            RowToObject <T, RT> row_to_object)
        {
            CellGroup.check_query(query);

            var surface         = new ShapeSheetSurface(page);
            var data_for_shapes = query.GetCellData <RT>(surface, shapeids);
            var list            = new List <T>(shapeids.Count);

            foreach (var data_for_shape in data_for_shapes)
            {
                var cells = row_to_object(data_for_shape.Cells);
                list.Add(cells);
            }
            return(list);
        }
Exemplo n.º 25
0
        private void stateDiagramToTable_Click(object sender, RibbonControlEventArgs e)
        {
            // The user needs to select one or more State Transiton Diagram Node
            // to start the conversion.
            Visio.Selection selection = app.ActiveWindow.Selection;

            if (selection.Count == 0)
            {
                MessageBox.Show("Select a State Transition Diagram to Convert.");
            }
            else
            {
                // Outputs the resulting State transition table to the State Transition Page
                Visio.Page outputPage = Utilities.getDrawingPage(app, CaseTypes.STATE_TABLE_PAGE);
                FlowSystem flowEditor = new FlowSystem();
                flowEditor.stateDiagramToTable(selection, outputPage);
            }
        }
Exemplo n.º 26
0
        public void Render(IVisio.Page page)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            var nodes_to_draw = this.Nodes.Where(n => n.Draw).ToList();

            var page_node = new Dom.Page();

            var shape_nodes = new List <Dom.Shape>(nodes_to_draw.Count);

            foreach (var node in nodes_to_draw)
            {
                var shape_node = page_node.Shapes.Drop(node.Master, node.Rectangle.Center);

                if (node.Cells != null)
                {
                    shape_node.Cells = node.Cells.ShallowCopy();
                }

                shape_node.Cells.XFormWidth  = node.Rectangle.Width;
                shape_node.Cells.XFormHeight = node.Rectangle.Height;

                if (!string.IsNullOrEmpty(node.Text))
                {
                    shape_node.Text = new VisioAutomation.Models.Text.Element(node.Text);
                }

                shape_nodes.Add(shape_node);
            }

            page_node.Shapes.Render(page);

            for (int i = 0; i < nodes_to_draw.Count; i++)
            {
                var node       = nodes_to_draw[i];
                var shape_node = shape_nodes[i];

                node.Shape   = shape_node.VisioShape;
                node.ShapeID = shape_node.VisioShapeID;
            }
        }
Exemplo n.º 27
0
        public void addSequanceDiagram(ref Word.Document doc)
        {
            try
            {
                Visio.Document sequenceVisio;
                string         sequenceDiagramPath = Directory.GetCurrentDirectory() + "\\Templates\\" + Constants.ServiceFlow + "\\ServiceSequanceDiagram.vsdx";
                sequenceVisio = visioApp.Documents.Open(sequenceDiagramPath);
                Visio.Page sequencePage = sequenceVisio.Pages[1];
                foreach (Visio.Shape shp in sequencePage.Shapes)
                {
                    if (shp.Name != "Watermark Title" && shp.Text != "")
                    {
                        shp.Text = shp.Text.Replace("ServiceCanonicalName", Constants.ServiceCanonicalName);
                        shp.Text = shp.Text.Replace("Subject", Constants.Subject);
                        shp.Text = shp.Text.Replace("Backend", Constants.BackendName);
                    }
                }

                Visio.Selection sequenceDiagram = sequencePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll);

                sequenceDiagram.Copy();
                //rollback
                foreach (Visio.Shape shp in sequencePage.Shapes)
                {
                    if (shp.Name != "Watermark Title" && shp.Text != "")
                    {
                        shp.Text = shp.Text.Replace(Constants.ServiceCanonicalName, "ServiceCanonicalName");
                        shp.Text = shp.Text.Replace(Constants.Subject, "Subject");
                        shp.Text = shp.Text.Replace(Constants.BackendName, "Backend");
                    }
                }
                sequenceVisio.Saved = true;


                Word.Bookmark sequenceDiagBM  = doc.Bookmarks["SequenceDiagram"];
                Word.Range    sequenceDiagRng = sequenceDiagBM.Range;
                sequenceDiagRng.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting);
                Console.WriteLine("Sequance Diagram Added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 28
0
        public static void DistributeWithSpacing(IVisio.Page page, TargetShapeIDs target, Axis axis, double spacing)
        {
            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(spacing));
            }

            if (target.ShapeIDs.Count < 2)
            {
                return;
            }

            // Calculate the new Xfrms
            var sortpos = axis == Axis.XAxis
                ? ShapeRelativePosition.PinX
                : ShapeRelativePosition.PinY;

            var delta = axis == Axis.XAxis
                ? new Drawing.Size(spacing, 0)
                : new Drawing.Size(0, spacing);


            var input_xfrms = ShapeXFormData.Get(page, target);
            var bb          = ShapeXFormData.GetBoundingBox(input_xfrms);
            var cur_pos     = new Drawing.Point(bb.Left, bb.Bottom);

            var newpositions = new List <VisioAutomation.Drawing.Point>(target.ShapeIDs.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var new_pinpos = axis == Axis.XAxis
                    ? new Drawing.Point(cur_pos.X + input_xfrm.LocPinX, input_xfrm.PinY)
                    : new Drawing.Point(input_xfrm.PinX, cur_pos.Y + input_xfrm.LocPinY);

                newpositions.Add(new_pinpos);
                cur_pos = cur_pos.Add(input_xfrm.Width, input_xfrm.Height).Add(delta);
            }

            // Apply the changes
            var sorted_shape_ids = ArrangeHelper.SortShapesByPosition(page, target, sortpos);

            ModifyPinPositions(page, sorted_shape_ids, newpositions);
        }
Exemplo n.º 29
0
        public void Apply(IVisio.Page page)
        {
            var pagecells = new PageLayoutFormulas();

            this.SetPageCells(pagecells);

            var writer = new FormulaWriterSRC();

            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.AvenueSizeX, pagecells.AvenueSizeX);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.AvenueSizeY, pagecells.AvenueSizeY);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.LineRouteExt, pagecells.LineRouteExt);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.RouteStyle, pagecells.RouteStyle);
            writer.SetFormula(VisioAutomation.ShapeSheet.SRCConstants.PlaceStyle, pagecells.PlaceStyle);

            var pagesheet = page.PageSheet;

            writer.Commit(pagesheet);
            page.Layout();
        }
Exemplo n.º 30
0
        public static Shape PlaceGenericElement(Page page,
                                                Master elementStencil,
                                                GenericElement element,
                                                int row, int column, double space,
                                                Dictionary <int, String> columnMap,
                                                bool showNotes)
        {
            Shape elementShape = page.Drop(elementStencil, 0.0, 0.0);

            DecorateShape(element, columnMap, showNotes, elementShape);

            double elementWidth  = elementShape.CellsU["Width"].ResultIU;
            double elementHeight = elementShape.CellsU["Height"].ResultIU;

            elementShape.Cells["PinX"].ResultIU = CalculateX(column, elementWidth, space);
            elementShape.Cells["PinY"].ResultIU = CalculateY(row, elementHeight, space);

            return(elementShape);
        }
Exemplo n.º 31
0
        public static short[] DropManyU(this IVisio.Page page, IList <IVisio.Master> masters, IEnumerable <VA.Drawing.Point> points, IList <string> names)
        {
            var surface = new VA.Drawing.DrawingSurface(page);

            short[] shapeids = surface.DropManyU(masters, points);

            if (names != null)
            {
                var page_shapes = page.Shapes;
                //ShapeIDs should come back in the same order... if Names for the masters are passed in, assign the Name. Makes it easier to find later
                for (int i = 0; i < shapeids.Length; i++)
                {
                    var shapeid   = shapeids[i];
                    var cur_shape = page_shapes[shapeid];
                    cur_shape.Name = names[i];
                }
            }
            return(shapeids);
        }
Exemplo n.º 32
0
        public static void FitShapeToText(IVisio.Page page, IEnumerable <IVisio.Shape> shapes)
        {
            if (page == null)
            {
                throw new System.ArgumentNullException("page");
            }

            if (shapes == null)
            {
                throw new System.ArgumentNullException("shapes");
            }

            var shapeids = shapes.Select(s => s.ID).ToList();

            // Calculate the new sizes for each shape
            var new_sizes = new List <VA.Drawing.Size>(shapeids.Count);

            foreach (var shape in shapes)
            {
                var text_bounding_box = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightText).Size;
                var wh_bounding_box   = shape.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH).Size;

                double max_w    = System.Math.Max(text_bounding_box.Width, wh_bounding_box.Width);
                double max_h    = System.Math.Max(text_bounding_box.Height, wh_bounding_box.Height);
                var    max_size = new VA.Drawing.Size(max_w, max_h);
                new_sizes.Add(max_size);
            }

            var src_width  = VA.ShapeSheet.SRCConstants.Width;
            var src_height = VA.ShapeSheet.SRCConstants.Height;

            var update = new VA.ShapeSheet.Update();

            for (int i = 0; i < new_sizes.Count; i++)
            {
                var shapeid  = shapeids[i];
                var new_size = new_sizes[i];
                update.SetFormula((short)shapeid, src_width, new_size.Width);
                update.SetFormula((short)shapeid, src_height, new_size.Height);
            }

            update.Execute(page);
        }
Exemplo n.º 33
0
        private static void ClearPage(Visio.Page page)
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodBase.GetCurrentMethod().Name));

            try
            {
                for (int i = page.Shapes.Count - 1; i >= 0; i--)
                {
                    page.Shapes[i].Delete();
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, Common.LOG_CATEGORY);
            }

            System.Diagnostics.Debug.WriteLine(string.Format("Shapes on Page: {0}", page.Shapes.Count));
        }
Exemplo n.º 34
0
        private static void AddTOCLinkToPage(Visio.Page page)
        {
            VisioHelper.DisplayInWatchWindow(string.Format("{0}()",
                                                           System.Reflection.MethodBase.GetCurrentMethod().Name));

            if (page.Background != 0)
            {
                // Skip background pages
                return;
            }

            int undoScope = Globals.ThisAddIn.Application.BeginUndoScope("AddTOCLinkToPage");

            // Clear out any existing link.

            foreach (Visio.Shape shape in page.Shapes)
            {
                if (shape.Text == "Table of Contents" || shape.Name == "TOCLink")
                {
                    shape.Delete();
                }
            }

            Visio.Shape tocShape = page.DrawRectangle(
                cTOC_Page_Initial_xLoc, cTOC_PageLink_Initial_yLoc,
                cTOC_Page_Initial_xLoc + cTOC_PageLink_Width, cTOC_PageLink_Initial_yLoc + cTOC_PageLink_Height);

            tocShape.Name = "TOCLink";

            tocShape.Text             = "Table of Contents";
            tocShape.TextStyle        = "Normal";
            tocShape.LineStyle        = "Text Only";
            tocShape.FillStyle        = "Text Only";
            tocShape.Characters.Begin = 0;
            tocShape.Characters.End   = 0;
            tocShape.Characters.set_CharProps((short)Visio.VisCellIndices.visCharacterSize, 6);

            Visio.Hyperlink hlink = tocShape.Hyperlinks.Add();
            // hlink.Name = "do we need a name?";
            hlink.SubAddress = "Table of Contents";

            Globals.ThisAddIn.Application.EndUndoScope(undoScope, true);
        }
Exemplo n.º 35
0
        public static void SnapCorner(IVisio.Page page, Models.TargetShapeIDs target, VisioAutomation.Geometry.Size snapsize, Models.SnapCornerPosition corner)
        {
            // First caculate the new transforms
            var snap_grid    = new Models.SnappingGrid(snapsize);
            var input_xfrms  = VisioScripting.Models.ShapeXFormData.Get(page, target);
            var output_xfrms = new List <VisioAutomation.Geometry.Point>(input_xfrms.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var old_rect         = input_xfrm.GetRectangle();
                var old_lower_left   = old_rect.LowerLeft;
                var new_lower_left   = snap_grid.Snap(old_lower_left);
                var new_pin_position = ArrangeHelper._get_pin_position_for_corner(input_xfrm, new_lower_left, corner);
                var output_xfrm      = new VisioAutomation.Geometry.Point(new_pin_position.X, new_pin_position.Y);
                output_xfrms.Add(output_xfrm);
            }

            _modify_pin_positions(page, target.ShapeIDs, output_xfrms);
        }
Exemplo n.º 36
0
        internal static void _distribute_with_spacing(IVisio.Page page, IList <int> shapeids, Models.Axis axis, double spacing)
        {
            if (spacing < 0.0)
            {
                throw new System.ArgumentOutOfRangeException(nameof(spacing));
            }

            if (shapeids.Count < 2)
            {
                return;
            }

            // Calculate the new Xfrms
            var sortpos = axis == VisioScripting.Models.Axis.XAxis
                ? VisioScripting.Models.ShapeRelativePosition.PinX
                : VisioScripting.Models.ShapeRelativePosition.PinY;

            var delta = axis == VisioScripting.Models.Axis.XAxis
                ? new VisioAutomation.Geometry.Size(spacing, 0)
                : new VisioAutomation.Geometry.Size(0, spacing);


            var input_xfrms = VisioScripting.Models.ShapeXFormData._get_xfrms(page, shapeids);
            var bb          = VisioScripting.Models.ShapeXFormData.GetBoundingBox(input_xfrms);
            var cur_pos     = new VisioAutomation.Geometry.Point(bb.Left, bb.Bottom);

            var newpositions = new List <VisioAutomation.Geometry.Point>(shapeids.Count);

            foreach (var input_xfrm in input_xfrms)
            {
                var new_pinpos = axis == VisioScripting.Models.Axis.XAxis
                    ? new VisioAutomation.Geometry.Point(cur_pos.X + input_xfrm.XFormLocPinX, input_xfrm.XFormPinY)
                    : new VisioAutomation.Geometry.Point(input_xfrm.XFormPinX, cur_pos.Y + input_xfrm.XFormLocPinY);

                newpositions.Add(new_pinpos);
                cur_pos = cur_pos.Add(input_xfrm.XFormWidth, input_xfrm.XFormHeight).Add(delta);
            }

            // Apply the changes
            var sorted_shapeids = ArrangeHelper._sort_shapes_by_position(page, shapeids, sortpos);

            _modify_pin_positions(page, sorted_shapeids, newpositions);
        }
        internal IVisio.Page Draw(FormRenderingContext ctx)
        {
            var r = new InteractiveRenderer(ctx.Document);
            var page_cells = new Pages.PageCells();
            this.VisioPage = r.CreatePage(this);
            ctx.Page = this.VisioPage;

            var titleblock = new TextBlock(new Drawing.Size(7.5, 0.5), this.Title);

            int _fontid = ctx.GetFontID(this.DefaultFont);
            titleblock.TextBlockCells.VerticalAlign = 0;
            titleblock.ParagraphCells.HorizontalAlign = 0;
            titleblock.FormatCells.LineWeight = 0;
            titleblock.FormatCells.LinePattern = 0;
            titleblock.CharacterCells.Font = _fontid;
            titleblock.CharacterCells.Size = get_pt_string(this.TitleTextSize);



            // Draw the shapes
            var titleshape = r.AddShape(titleblock);
            r.Linefeed();

            double body_height = r.GetDistanceToBottomMargin();
            var bodyblock = new TextBlock(new Drawing.Size(7.5, body_height), this.Body);
            bodyblock.ParagraphCells.HorizontalAlign = 0;
            bodyblock.ParagraphCells.SpacingAfter = get_pt_string(this.BodyParaSpacingAfter);
            bodyblock.CharacterCells.Font = _fontid;
            bodyblock.CharacterCells.Size = get_pt_string(this.BodyTextSize);
            bodyblock.FormatCells.LineWeight = 0;
            bodyblock.FormatCells.LinePattern = 0;
            bodyblock.TextBlockCells.VerticalAlign = 0;
            bodyblock.FormatCells.LineWeight = 0;
            bodyblock.FormatCells.LinePattern = 0;

            var bodyshape = r.AddShape(bodyblock);
            r.Linefeed();

            r.Finish();
            return this.VisioPage;
        }
 public RenderContext(IVisio.Page visio_page)
 {
     this.id_to_shape = new Dictionary<short, IVisio.Shape>();
     this.VisioPage = visio_page;
     this.pageshapes = visio_page.Shapes;
 }
 public ShapeSheetUpdate(VA.Scripting.Client ss,IVisio.Page page)
 {
     this.Client = ss;
     this.TargetPage = page;
     this.update = new VA.ShapeSheet.Update();
 }
Exemplo n.º 40
0
        /// <summary>
        /// Initializes a new insance of the StringControl class.
        /// </summary>
        /// <param name="definition">Definition of the property.</param>
        /// <param name="mode">The current design mode.</param>
        public ItemListControl(XmlElement definition, string mode,Page _page)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
            page = _page;
            //opr = _opr;
            _mode = mode;
            _definition = definition;
            #region Use Standard Sizes

            labelControl.Top = Property.LabelTop;
            labelControl.Left = Property.LabelLeft;
            labelControl.Width = Property.LabelWidth;
            valueControl.Top = Property.ValueTop;
            valueControl.Left = Property.ValueLeft;

            //valueControl.Width = Property.ValueWidth;
            this.Height = valueControl.Height + Property.PropertyMarginBottom;
            this.Height = valueControl.Height + Property.PropertyMarginBottom;

            #endregion

            // Initialize control
            Initialize(definition);

            XmlAttribute itemAttribute = definition.Attributes["itemType"];
            if (itemAttribute != null)
            {
                ItemType = itemAttribute.Value;
            }
            itemAttribute = definition.Attributes["itemName"];
            if (itemAttribute != null)
            {
                ItemName = itemAttribute.Value;
            }
            itemAttribute = definition.Attributes["complexLabel"];
            if (itemAttribute != null)
            {
                ComplexLabel = itemAttribute.Value;
            }
            itemAttribute = definition.Attributes["complexPattern"];
            if (itemAttribute != null)
            {
                ComplexPattern = itemAttribute.Value;
            }
            itemAttribute = definition.Attributes["processType"];
            if (itemAttribute != null)
            {
                processShape = bool.Parse(itemAttribute.Value);
            }

            itemAttribute = definition.Attributes["childPattern"];
            if (itemAttribute != null)
            {
                childPattern = itemAttribute.Value;
            }

            labelControl.Text = this.Label;
            valueControl.Text = "";

            /*
             * Height / number of rows.
             */
            labelControl.Height = valueControl.Height;

            /*
             * Check required
             */
            if (IsRequired(definition, mode) == true)
            {
                req = new RequiredFieldValidator();
                req.ControlToValidate = this.valueControl;
                req.ControlToValidate.Validating += new CancelEventHandler(ControlToValidate_Validating);
                req.ErrorMessage = "Required.";
                req.IconPadding = 2;
            }
        }
 public ShapeSheetUpdate(Client client, IVisio.Page page)
 {
     this.Client = client;
     this.TargetPage = page;
     this.update = new ShapeSheet.Update();
 }