private static void ResolveMasters(DirectedGraphLayout layout_diagram, IVisio.Application app) { // for masters that are identified by their name and stencil, go find the actual master objects by // loading the specified stenciles var documents = app.Documents; var master_to_size = new Dictionary <IVisio.Master, VA.Drawing.Size>(); // Load and cache all the masters var loader = new MasterLoader(); foreach (var layout_shape in layout_diagram.Shapes) { loader.Add(layout_shape.MasterName, layout_shape.StencilName); } loader.Resolve(documents); // If no size was provided for the shape, then set the size based on the master var layoutshapes_without_size_info = layout_diagram.Shapes.Where(s => s.Size == null); foreach (var layoutshape in layoutshapes_without_size_info) { var master = loader.Get(layoutshape.MasterName, layoutshape.StencilName); var size = MsaglRenderer.TryGetValue(master_to_size, master.VisioMaster); if (!size.HasValue) { var master_bb = master.VisioMaster.GetBoundingBox(IVisio.VisBoundingBoxArgs.visBBoxUprightWH); size = master_bb.Size; master_to_size[master.VisioMaster] = size.Value; } layoutshape.Size = size.Value; } }
private void ResolveMasters(RenderContext context) { // Find all the shapes that use masters and for which // a Visio master object has not been identifies yet var shape_nodes = this._shapes .Where(shape => shape is Shape) .Cast <Shape>() .Where(shape => shape.Master.VisioMaster == null).ToList(); var loader = new MasterLoader(); foreach (var shape_node in shape_nodes) { loader.Add(shape_node.Master.MasterName, shape_node.Master.StencilName); } var application = context.VisioPage.Application; var docs = application.Documents; loader.Resolve(docs); foreach (var shape_node in shape_nodes) { var mref = loader.Get(shape_node.Master.MasterName, shape_node.Master.StencilName); shape_node.Master.VisioMaster = mref.VisioMaster; } // Ensure that all shapes to drop are assigned a visio master object foreach (var shape in this._shapes.Where(s => s is Shape).Cast <Shape>()) { if (shape.Master.VisioMaster == null) { throw new InternalAssertionException("Missing a master for a shape"); } } }