Пример #1
0
        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.Geometry.Size>();

            // Load and cache all the masters
            var master_cache = new MasterCache();

            foreach (var layout_shape in layout_diagram.Shapes)
            {
                master_cache.Add(layout_shape.MasterName, layout_shape.StencilName);
            }
            master_cache.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 = master_cache.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;
            }
        }
Пример #2
0
        private void _resolve_masters(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.OfType <Shape>()
                              .Where(shape => shape.Master.VisioMaster == null).ToList();

            var master_cache = new MasterCache();

            foreach (var shape_node in shape_nodes)
            {
                master_cache.Add(shape_node.Master.MasterName, shape_node.Master.StencilName);
            }

            var application = context.VisioPage.Application;
            var docs        = application.Documents;

            master_cache.Resolve(docs);

            foreach (var shape_node in shape_nodes)
            {
                var mref = master_cache.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.OfType <Shape>())
            {
                if (shape.Master.VisioMaster == null)
                {
                    throw new InternalAssertionException("Missing a master for a shape");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Gets the cache associated with a type derived from the abstract class Model.
        /// If the cache hasn't been accessed yet, this creates one for the type.
        /// </summary>
        public static ModelCache Get(Type type)
        {
            if (MasterCache == null)
            {
                MasterCache = new Dictionary <Type, ModelCache>();
            }

            if (!MasterCache.ContainsKey(type))
            {
                MasterCache.Add(type, new ModelCache(type));
            }

            return(MasterCache[type]);
        }