public MasterRef(string mastername, string stencilname) { if (mastername == null) { throw new ArgumentNullException(nameof(mastername)); } if (MasterRef.EndwithVSSorVSSX(mastername)) { throw new AutomationException("Master name ends with .VSS or .VSSX"); } if (this.StencilName != null) { if (!MasterRef.EndwithVSSorVSSX(stencilname)) { throw new AutomationException("Stencil name does not end with .VSS"); } } else { // Stencil names are allowed to be null. In this case // it means look for the stencil in the active document } this.VisioMaster = null; this.MasterName = mastername; this.StencilName = stencilname; }
public void NewDocument() { var docs = this.Application.Documents; this.doc = docs.Add(""); this.stencil = docs.OpenStencil("basic_u.vss"); var masters = stencil.Masters; this._masterRectangle = masters["Rectangle"]; }
public SurfaceTarget(IVisio.Shape shape) { if (shape== null) { throw new System.ArgumentNullException(nameof(shape)); } this.Page = null; this.Master = null; this.Shape = shape; }
public MasterRef(IVisio.Master master) { if (master == null) { throw new ArgumentNullException(nameof(master)); } this.VisioMaster = master; this.MasterName = null; this.StencilName = null; }
public SurfaceTarget(IVisio.Master master) { if (master== null) { throw new System.ArgumentNullException(nameof(master)); } this.Page = null; this.Master = master; this.Shape = null; }
public static async void QueryWorkItems(Visio.Application app, string doc, string page, string shape, string shapeu, string[] array) { Int64 startTicks = Log.APPLICATION("Enter", Common.LOG_CATEGORY); if (!VerifyRequiredStencils(app)) { MessageBox.Show($"Cannot locate or open required Stencils, aborting. Review Log for details"); return; } Visio.Page activePage = app.ActivePage; Visio.Shape activeShape = app.ActivePage.Shapes[shape]; WorkItemShapeInfo shapeInfo = new WorkItemShapeInfo(activeShape); // TODO(crhodes) // Logic here to decide what query to perform. // For now we support // TeamProject // TeamProject + WorkItemType // WorkItemType // ID IList <WorkItem> result = null; if (!string.IsNullOrEmpty(shapeInfo.TeamProject)) { result = await GetInfoByTeamProject(shapeInfo); } else if (!string.IsNullOrEmpty(shapeInfo.ID)) { result = await GetInfoById(shapeInfo); } if (result is null) { return; } if (result.Count > 0) { Point initialPosition = GetPosition(activeShape); Point insertionPoint = initialPosition; string stencilName = "Azure DevOps.vssx"; Visio.Document linkStencil; Visio.Master linkMaster = null; string targetShapeName = activeShape.CellsU["Prop.WIShapeName"].ResultStrU[VisUnitCodes.visUnitsString]; var version = WorkItemShapeInfo.WorkItemShapeVersion.V2; try { linkStencil = app.Documents[stencilName]; try { linkMaster = linkStencil.Masters[targetShapeName]; } catch (Exception ex) { VisioHelper.DisplayInWatchWindow(string.Format(" Cannot find Master named:>{0}<", targetShapeName)); } } catch (Exception ex) { VisioHelper.DisplayInWatchWindow(string.Format(" Cannot find open Stencil named:>{0}<", stencilName)); } // TODO(crhodes) // Figure out how to get size of shape from master. // HACK(crhodes) // .25 is for Link counts double height = version == WorkItemShapeInfo.WorkItemShapeVersion.V1 ? 0.375 : 0.475; WorkItemOffsets workItemOffsets = new WorkItemOffsets(initialPosition, height: height, padX: 0.25, padY: 0.05); foreach (var linkedWorkItem in result) { //// NOTE(crhodes) //// This includes the current shape. Do not add it. //// May always be first one. Maybe loop counter //if (linkedWorkItem.Id == id) //{ // continue; //} VisioHelper.DisplayInWatchWindow($"{linkedWorkItem.Id} {linkedWorkItem.Fields["System.Title"]}"); insertionPoint = AZDOPageLayout.CalculateInsertionPointQueriedWorkItems(initialPosition, linkedWorkItem, shapeInfo, workItemOffsets); AddNewWorkItemShapeToPage(activePage, linkMaster, linkedWorkItem, insertionPoint, shapeInfo, version); } } Log.APPLICATION("Exit", Common.LOG_CATEGORY, startTicks); }
public static List <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.ArgumentException("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]; ConnectorHelper.ConnectShapes(from_shape, to_shape, connector, true); connectors.Add(connector); } return(connectors); }
public static List <IVisio.Shape> ConnectShapes(IVisio.Page page, IList <IVisio.Shape> fromshapes, IList <IVisio.Shape> toshapes, IVisio.Master connector_master) { return(ConnectorHelper.ConnectShapes(page, fromshapes, toshapes, connector_master, true)); }
public DrawingSurface(IVisio.Master master) { this.Target = new SurfaceTarget(master); }
public MasterRef(string mastername, string stencilname) { this.MasterName = mastername; this.StencilName = stencilname; this.VisioMaster = null; }
public static Geometry.Rectangle GetBoundingBox(this IVisio.Master master, IVisio.VisBoundingBoxArgs args) { var surface = new VisioAutomation.SurfaceTarget(master); return(surface.GetBoundingBox(args)); }
/// <summary> /// Given a color map (Name:color), this function plots the information as /// as a key on the page. /// </summary> /// <param name="colorMap">Colro information to display.</param> /// <param name="contentDocument">Document to display the info.</param> private static void DisplayNamespaceKey( Dictionary <string, string> colorMap, Visio.Document contentDocument) { const double KeyPitchX = 2.0; const double KeyX = 1.75; const double KeyPitchY = 1.0; const double KeyY = 0.75; const double KeyInitialX = 1.5; Visio.Document stencilDocument = contentDocument.Application.Documents.OpenEx( "Basic_U.vss", (short)Visio.VisOpenSaveArgs.visOpenDocked); Visio.Master shape = stencilDocument.Masters["Rectangle"]; Visio.Page targetPage = contentDocument.Pages[1]; int i = 0; double dropX = KeyInitialX; double dropY = 1.0; // group all of the items in the key Program.selectionTree = contentDocument.DocumentSheet.Application.ActiveWindow.Selection; Program.selectionTree.DeselectAll(); foreach (string colorName in colorMap.Keys) { Visio.Shape boxShape = targetPage.Drop(shape, dropX, dropY); Program.selectionTree.Select(boxShape, (short)Visio.VisSelectArgs.visSelect); // set the templateShape height, width, text, and color boxShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormIn, (short)Visio.VisCellIndices.visXFormHeight).ResultIU = KeyY; boxShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormIn, (short)Visio.VisCellIndices.visXFormWidth).ResultIU = KeyX; boxShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowFill, (short)Visio.VisCellIndices.visFillForegnd).FormulaU = colorMap[colorName]; string[] namespaceTokens = colorName.Split(new char[] { '.' }); string shortNamespace = namespaceTokens[namespaceTokens.Length - 1]; boxShape.Text = string.Format("{0}\n({1})", shortNamespace, colorName); i++; dropX += KeyPitchX; // bit of a kluge, but it works. if (i % 4 == 0) { dropX = KeyInitialX; dropY += KeyPitchY; } } Program.selectionTree.Group(); Program.selectionTree.DeselectAll(); }
/// <summary> /// This function uses the node information to place a copy of the templateShape /// on the targetPage, in the right color, at the specified location. /// The new shape is linked to the parent. The Children of the node are then /// (recursively) placed on the page, linked to this new node. /// </summary> /// <param name="colorMap">Namespace color map to used for rendering.</param> /// <param name="targetPage">Visio page to place the objects.</param> /// <param name="node">Node object to place.</param> /// <param name="templateShape">Which shape to use to display.</param> /// <param name="parentShape">Parent visio node to attach child to.</param> /// <param name="baseLocationX">XLocation to start displaying subtree.</param> /// <param name="baseLocationY">YLocation to start displaying subtree.</param> /// <returns>Returns the next available Y coordinate to display an object.</returns> private static double PlaceOneShape( Dictionary <string, string> colorMap, Visio.Page targetPage, TypeTreeNode node, Visio.Master templateShape, Visio.Shape parentShape, double baseLocationX, double baseLocationY) { double movingYBase = baseLocationY; Visio.Shape newlyPlacedShape = targetPage.Drop(templateShape, baseLocationX, baseLocationY); // add the new object to the selection group for later "group" operation Program.selectionTree.Select(newlyPlacedShape, (short)Visio.VisSelectArgs.visSelect); if (parentShape != null) { Visio.Document stencilDocument = targetPage.Application.Documents.OpenEx( "Blocks.vss", (short)Visio.VisOpenSaveArgs.visOpenDocked); Visio.Master connectorMaster = stencilDocument.Masters["Dynamic connector"]; Visio.Shape connectorShape = targetPage.Drop(connectorMaster, 1.0, 1.0); Program.selectionTree.Select(connectorShape, (short)Visio.VisSelectArgs.visSelect); ConnectShapes(parentShape, newlyPlacedShape, connectorShape); } // set the templateShape height, width, text, and color newlyPlacedShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormIn, (short)Visio.VisCellIndices.visXFormHeight).ResultIU = Program.BoxY; newlyPlacedShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormIn, (short)Visio.VisCellIndices.visXFormWidth).ResultIU = Program.BoxX; string shortNamespace = String.Empty; if (!String.IsNullOrEmpty(node.RawType.Namespace)) { string[] namespaceTokens = node.RawType.Namespace.Split(new char[] { '.' }); shortNamespace = namespaceTokens[namespaceTokens.Length - 1]; } newlyPlacedShape.Text = string.Format("{0} ({1})", node.Name, shortNamespace); // if there is an entry in the color map, use it. if (!String.IsNullOrEmpty(node.RawType.Namespace) && colorMap.ContainsKey(node.RawType.Namespace)) { newlyPlacedShape.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowFill, (short)Visio.VisCellIndices.visFillForegnd).FormulaU = colorMap[node.RawType.Namespace]; } movingYBase += Program.BoxPitchY; foreach (TypeTreeNode t in node.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name)) { movingYBase = PlaceOneShape( colorMap, targetPage, t, templateShape, newlyPlacedShape, baseLocationX + Program.BoxPitchX, // x adds Depth movingYBase); } return(movingYBase); }
public void AddShapes() { Visio.Application visio = this.Application; Visio.Documents documents = this.Application.Documents; Visio.Page page = visio.ActivePage; Visio.Document document = visio.ActiveDocument; if (document == null) { document = visio.Documents.Add(""); } if (page == null) { page = document.Pages.Add(); } List <Service> services = null; try { ServicesApi api = new ServicesApi(); services = api.getServices(true, ""); } catch (ApiException e) { System.Windows.Forms.MessageBox.Show("Error calling the LeanIX API: " + e.Message); return; } catch (System.Net.WebException) { System.Windows.Forms.MessageBox.Show("Please check your internet connection"); return; } if (services == null || services.Count == 0) { System.Windows.Forms.MessageBox.Show("No data received from API"); return; } Dictionary <String, Visio.Shape> placedShapes = new Dictionary <String, Visio.Shape>(); //add shapes foreach (Service s in services) { if (s.serviceHasInterfaces == null || s.serviceHasInterfaces.Count == 0) { continue; } Visio.Document stencil = documents.OpenEx("Basic Shapes.vss", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked); Visio.Master visioRectMaster = stencil.Masters.get_ItemU(@"Rounded Rectangle"); Visio.Shape visioRectShape = page.Drop(visioRectMaster, 0, 0); visioRectShape.Text = s.name; placedShapes.Add(s.ID, visioRectShape); } //connect shapes foreach (Service s in services) { foreach (ServiceHasInterface si in s.serviceHasInterfaces) { Visio.Shape sourceShape = placedShapes[s.ID]; Visio.Shape targetShape = placedShapes[si.serviceRefID]; if (targetShape != null) { sourceShape.AutoConnect(targetShape, Visio.VisAutoConnectDir.visAutoConnectDirLeft); } } } //set the layout and resize the page page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOPlaceStyle).ResultIU = 6; page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLORouteStyle).ResultIU = 1; page.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOSplit).ResultIU = 1; page.Layout(); page.ResizeToFitContents(); }
public void Commit(IVisio.Master shape) { var surface = new VisioAutomation.ShapeSheet.ShapeSheetSurface(shape); this._commit_to_surface(surface); }
public List <IVisio.Shape> ConnectShapes(VisioScripting.TargetPage target_page, IList <IVisio.Shape> fromshapes, IList <IVisio.Shape> toshapes, IVisio.Master master) { target_page = target_page.ResolveToPage(this._client); using (var undoscope = this._client.Undo.NewUndoScope(nameof(ConnectShapes))) { if (master == null) { var connectors = ConnectorHelper.ConnectShapes(target_page.Page, fromshapes, toshapes, null, false); return(connectors); } else { var connectors = ConnectorHelper.ConnectShapes(target_page.Page, fromshapes, toshapes, master); return(connectors); } } }
public List <IVisio.Shape> ConnectShapes(IList <IVisio.Shape> fromshapes, IList <IVisio.Shape> toshapes, IVisio.Master master) { var cmdtarget = this._client.GetCommandTargetPage(); using (var undoscope = this._client.Undo.NewUndoScope(nameof(ConnectShapes))) { if (master == null) { var connectors = ConnectorHelper.ConnectShapes(cmdtarget.ActivePage, fromshapes, toshapes, null, false); return(connectors); } else { var connectors = ConnectorHelper.ConnectShapes(cmdtarget.ActivePage, fromshapes, toshapes, master); return(connectors); } } }
public Shape(IVisio.Master master, VA.Drawing.Point pos) { this.Master = new VA.DOM.MasterRef(master); this.DropPosition = pos; }
public Shape(IVisio.Master master, VA.Drawing.Rectangle rect) { this.Master = new VA.DOM.MasterRef(master); this.DropPosition = rect.Center; this.DropSize = rect.Size; }
public ShapeSheetSurface(IVisio.Master master) { this.Target = new SurfaceTarget(master); }
/// <summary> /// This is the root of the recursive descent to display the tree on the Visio doc. /// The function uses PlaceOneShape() to start the recursive display. /// </summary> /// <param name="colorMap">Color map to use to render.</param> /// <param name="root">Root node to render.</param> private static void BuildAndDisplayWithVisio( Dictionary <string, string> colorMap, TypeTreeNode root) { Visio.Application app = null; Visio.Document contentDocument = null; try { app = new Visio.Application(); app.Settings.EnableAutoConnect = false; ////app.Window.WindowState = (int)Visio.VisWindowStates.visWSRestored; app.Window.WindowState = (int)Visio.VisWindowStates.visWSMinimized; contentDocument = app.Documents.AddEx( string.Empty, Visio.VisMeasurementSystem.visMSUS, (int)Visio.VisOpenSaveArgs.visAddDocked, (int)0); contentDocument.PaperSize = Visio.VisPaperSizes.visPaperSizeE; contentDocument.PrintLandscape = true; /* * Visio.Document stencilDocument = contentDocument.Application.Documents.OpenEx( * "Basic_U.vss", * (short)Visio.VisOpenSaveArgs.visOpenDocked); * Visio.Master shape = stencilDocument.Masters["Rectangle"]; */ Visio.Master shape = contentDocument.Application.Documents.OpenEx( "Basic_U.vss", (short)Visio.VisOpenSaveArgs.visOpenDocked).Masters["Rectangle"]; Visio.Page targetPage = contentDocument.Pages[1]; targetPage.Name = "MFx Class Hirearchy"; BuildHeadersAndFooters(colorMap, contentDocument); /* * Program.selectionTree = app.ActiveWindow.Selection; * Program.selectionTree.DeselectAll(); */ double movingYBase = 4.0; foreach (TypeTreeNode t in root.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name)) { movingYBase = PlaceOneShape( colorMap, targetPage, t, shape, null, 2.0, movingYBase); } // now turn the selection into a group, and run the layout code // to make the tree look "right" ////Program.selectionTree.Group(); // resize, set the placement, and connector routing styles Visio.Cell layoutCell; layoutCell = targetPage.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOResizePage); layoutCell.FormulaU = "FALSE"; // don't add more pages to contain the tree, let the user edit layoutCell = targetPage.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLOPlaceStyle); layoutCell.set_Result( Visio.VisUnitCodes.visPageUnits, (double)Visio.VisCellVals.visPLOPlaceCompactDownRight); layoutCell = targetPage.PageSheet.get_CellsSRC( (short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowPageLayout, (short)Visio.VisCellIndices.visPLORouteStyle); layoutCell.set_Result( Visio.VisUnitCodes.visPageUnits, (double)Visio.VisCellVals.visLORouteOrgChartNS); targetPage.Layout(); ////Program.selectionTree.Layout(); Program.selectionTree.Group(); Console.WriteLine("Print and save Visio doc if you want, then enter to quit (Visio will close)."); Console.ReadLine(); } finally { if (contentDocument != null) { contentDocument.Saved = true; // not really, but we can lie so the close/quit works. contentDocument.Close(); } if (app != null) { app.Quit(); } } }
public Shape(IVisio.Master master, double x, double y) : this(master, new VA.Drawing.Point(x, y)) { }
public void OpenForEdit(IVisio.Master master) { var mdraw_window = master.OpenDrawWindow(); mdraw_window.Activate(); }
public Shape(IVisio.Master master, VA.Drawing.Point pos, string name) { this.Master = new MasterRef(master); this.DropPosition = pos; this.VisioShape.NameU = name; }