/// <summary> /// Displaye <see cref="DiagramItem"/> objects according to given diagram definition /// </summary> /// <param name="diagramDefinition">Definition of diagram with items to display</param> /// <param name="context">Context available for diagram definition</param> private void displayItems(DiagramDefinition diagramDefinition, DiagramContext context) { foreach (var definition in context.RootItemDefinitions) { var item = new DiagramItem(definition, context); InitializeItemDrawing(item); } if (!diagramDefinition.ShowJoinLines) { return; } //show join lines foreach (var joinDefinition in diagramDefinition.JoinDefinitions) { foreach (var from in Engine.DefiningItems(joinDefinition.From)) { foreach (var to in Engine.DefiningItems(joinDefinition.To)) { var join = _diagramFactory.CreateJoin(joinDefinition, context); Engine.AddJoin(join, from, to); } } } }
/// <summary> /// Display diagram specified by given definition /// </summary> /// <param name="diagramDefinition">Diagram definition to be displayed</param> /// <returns>Context of displayed diagram</returns> public DiagramContext Display(DiagramDefinition diagramDefinition) { _currentDiagram = diagramDefinition; Engine.Clear(); if (diagramDefinition == null) { return(null); } var context = new DiagramContext(this, diagramDefinition); displayItems(diagramDefinition, context); var menu = createContextMenu(diagramDefinition, context); //context menu handling Engine.Output.ContextMenu = menu; if (_lastContextMenuHandler != null) { Engine.Output.ContextMenuOpening -= _lastContextMenuHandler; } _lastContextMenuHandler = (s, e) => menu_ContextMenuOpening(menu, context); Engine.Output.ContextMenuOpening += _lastContextMenuHandler; Engine.Output.SetContext(context); Engine.Display(); return(context); }
/// <summary> /// Create context menu according to edits and commands in given definition /// </summary> /// <param name="diagramDefinition">Definitin of diagram</param> /// <param name="context">Context available for diagram definition</param> /// <returns>Created context menu</returns> private ContextMenu createContextMenu(DiagramDefinition diagramDefinition, DiagramContext context) { var menu = new ContextMenu(); //add edit entries foreach (var edit in diagramDefinition.Edits) { if (!edit.IsActive(diagramDefinition.InitialView)) { continue; } var item = createEditItem(edit, context); menu.Items.Add(item); } foreach (var menuProvider in diagramDefinition.MenuProviders) { var item = new MenuItem(); item.Header = menuProvider.Key; item.Tag = menuProvider.Value; menu.Items.Add(item); } //add command entries foreach (var command in diagramDefinition.Commands) { var item = new MenuItem(); item.Header = command.Name; item.Click += (e, s) => command.Command(); menu.Items.Add(item); } return(menu); }
/// <summary> /// Initializes a new instance of the <see cref="DiagramContext"/> class. /// </summary> /// <param name="provider">The drawings provider.</param> /// <param name="diagram">The diagram definition.</param> internal DiagramContext(DrawingProvider provider, DiagramDefinition diagram) { Provider = provider; Diagram = diagram; }