private void DispatchDiagramChangeEvent(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent diagramNodeAddedEvent:
                AddNode(diagramNodeAddedEvent.DiagramNode);
                break;

            case DiagramNodeRemovedEvent diagramNodeRemovedEvent:
                RemoveNode(diagramNodeRemovedEvent.DiagramNode);
                break;

            case DiagramConnectorAddedEvent diagramConnectorAddedEvent:
                AddConnector(diagramConnectorAddedEvent.DiagramConnector);
                break;

            case DiagramConnectorRemovedEvent diagramConnectorRemovedEvent:
                RemoveConnector(diagramConnectorRemovedEvent.DiagramConnector);
                break;

            case DiagramClearedEvent _:
                ClearViewport();
                break;
            }
        }
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     if (diagramEvent is DiagramNodeAddedEvent diagramNodeAddedEvent)
     {
         RemoveModelNode(diagramNodeAddedEvent.NewNode.Id);
     }
 }
        private void OnDiagramChanged(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent diagramNodeAddedEvent:
                _incrementalLayoutEngine.EnqueueDiagramAction(new AddDiagramNodeAction(diagramNodeAddedEvent.NewNode));
                break;

            case DiagramConnectorAddedEvent diagramConnectorAddedEvent:
                _incrementalLayoutEngine.EnqueueDiagramAction(new AddDiagramConnectorAction(diagramConnectorAddedEvent.NewConnector));
                break;

            case DiagramNodeSizeChangedEvent diagramNodeSizeChangedEvent:
                var diagramNode = diagramNodeSizeChangedEvent.NewNode;
                _incrementalLayoutEngine.EnqueueDiagramAction(new ResizeDiagramNodeAction(diagramNode, diagramNode.Size));
                break;

            case DiagramNodeRemovedEvent diagramNodeRemovedEvent:
                _incrementalLayoutEngine.EnqueueDiagramAction(new RemoveDiagramNodeAction(diagramNodeRemovedEvent.OldNode));
                break;

            case DiagramConnectorRemovedEvent diagramConnectorRemovedEvent:
                _incrementalLayoutEngine.EnqueueDiagramAction(new RemoveDiagramConnectorAction(diagramConnectorRemovedEvent.OldConnector));
                break;

            case DiagramClearedEvent _:
                _incrementalLayoutEngine.EnqueueDiagramAction(new ClearDiagramAction());
                break;
            }
        }
Example #4
0
        private void OnDiagramChanged(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent diagramNodeAddedEvent:
                var addedDiagramNode     = diagramNodeAddedEvent.DiagramNode;
                var addDiagramNodeAction = new AddDiagramNodeAction(addedDiagramNode);

                if (addedDiagramNode is IContainerDiagramNode containerDiagramNode)
                {
                    var incrementalLayoutEngine = CreateLayoutEngine(DiagramService);
                    _layoutEnginesPerNodes.Add(containerDiagramNode.Id, incrementalLayoutEngine);
                }

                var layoutEngineForAddedDiagramNode = GetLayoutEngine(addedDiagramNode);
                layoutEngineForAddedDiagramNode.EnqueueDiagramAction(addDiagramNodeAction);
                _modelNodeToContainingLayoutEngine.Add(addedDiagramNode.Id, layoutEngineForAddedDiagramNode);
                break;

            case DiagramConnectorAddedEvent diagramConnectorAddedEvent:
                var addedDiagramConnector     = diagramConnectorAddedEvent.DiagramConnector;
                var addDiagramConnectorAction = new AddDiagramConnectorAction(addedDiagramConnector);

                var layoutEngineForAddedDiagramConnector = GetLayoutEngine(addedDiagramConnector);
                if (layoutEngineForAddedDiagramConnector != null)
                {
                    layoutEngineForAddedDiagramConnector.EnqueueDiagramAction(addDiagramConnectorAction);
                    _modelRelationshipToContainingLayoutEngine.Add(addedDiagramConnector.Id, layoutEngineForAddedDiagramConnector);
                }
                break;

            case DiagramNodeSizeChangedEvent diagramNodeSizeChangedEvent:
                var resizedDiagramNode      = diagramNodeSizeChangedEvent.DiagramNode;
                var resizeDiagramNodeAction = new ResizeDiagramNodeAction(resizedDiagramNode, resizedDiagramNode.Size);
                _modelNodeToContainingLayoutEngine[resizedDiagramNode.Id].EnqueueDiagramAction(resizeDiagramNodeAction);
                break;

            case DiagramNodeRemovedEvent diagramNodeRemovedEvent:
                var removedDiagramNode      = diagramNodeRemovedEvent.DiagramNode;
                var removeDiagramNodeAction = new RemoveDiagramNodeAction(removedDiagramNode);
                _modelNodeToContainingLayoutEngine[removedDiagramNode.Id].EnqueueDiagramAction(removeDiagramNodeAction);
                break;

            case DiagramConnectorRemovedEvent diagramConnectorRemovedEvent:
                var removedDiagramConnector      = diagramConnectorRemovedEvent.DiagramConnector;
                var removeDiagramConnectorAction = new RemoveDiagramConnectorAction(removedDiagramConnector);
                _modelRelationshipToContainingLayoutEngine[removedDiagramConnector.Id].EnqueueDiagramAction(removeDiagramConnectorAction);
                break;

            case DiagramClearedEvent _:
                foreach (var incrementalLayoutEngine in _layoutEnginesPerNodes.Values)
                {
                    incrementalLayoutEngine.Dispose();
                }

                _layoutEnginesPerNodes.Clear();
                _rootLayoutEngine.EnqueueDiagramAction(new ClearDiagramAction());
                break;
            }
        }
Example #5
0
        private void DispatchDiagramChangeEvent(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent nodeAddedEvent:
                AddNode(nodeAddedEvent.NewNode, nodeAddedEvent.NewNode.ParentNodeId.ToNullable());
                break;

            case DiagramNodeRemovedEvent nodeRemovedEvent:
                RemoveNode(nodeRemovedEvent.OldNode);
                break;

            case DiagramConnectorAddedEvent connectorAddedEvent:
                AddConnector(connectorAddedEvent.NewConnector);
                break;

            case DiagramConnectorRemovedEvent connectorRemovedEvent:
                RemoveConnector(connectorRemovedEvent.OldConnector);
                break;

            case DiagramClearedEvent _:
                ClearViewport();
                break;
            }
        }
Example #6
0
        private void OnDiagramChanged(DiagramEventBase diagramEvent)
        {
            var model   = ModelService.Model;
            var diagram = diagramEvent.NewDiagram;

            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent diagramNodeAddedEvent:
                var modelNode = diagramNodeAddedEvent.NewNode.ModelNode;
                ShowModelRelationshipsIfBothEndsAreVisible(modelNode, model, diagram);
                break;

            case DiagramNodeRemovedEvent _:
                // TODO: optimize: should check only surrounding nodes of the deleted one (not all in diagram)
                foreach (var diagramNode in diagram.Nodes)
                {
                    ShowModelRelationshipsIfBothEndsAreVisible(diagramNode.ModelNode, model, diagram);
                }
                break;

            case DiagramConnectorAddedEvent _:
                HideRedundantConnectors(diagram);
                break;

                // DiagramConnectorRemovedEvent is not handled
                // because that would put back removed connectors immediately
                // (because nodes are removed after connectors)
            }
        }
Example #7
0
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     if (diagramEvent is DiagramConnectorRouteChangedEvent diagramConnectorRouteChangedEvent &&
         DiagramConnectorIdEqualityComparer.Instance.Equals(diagramConnectorRouteChangedEvent.NewConnector, DiagramConnector))
     {
         DiagramShape = diagramConnectorRouteChangedEvent.NewConnector;
         RoutePoints  = diagramConnectorRouteChangedEvent.NewConnector.Route.ToWpf();
     }
 }
 private void DispatchDiagramEvent(DiagramEventBase diagramEvent)
 {
     switch (diagramEvent)
     {
     case DiagramNodeRectChangedEvent diagramNodeRectChangedEvent:
         FollowDiagramNode(diagramNodeRectChangedEvent.NewNode);
         break;
     }
 }
Example #9
0
 protected virtual void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     if (diagramEvent is DiagramNodeChangedEventBase diagramNodeChangedEvent &&
         DiagramNodeIdEqualityComparer.Instance.Equals(diagramNodeChangedEvent.DiagramNode, DiagramNode))
     {
         DiagramShape = diagramNodeChangedEvent.DiagramNode;
         PopulateFromDiagramNode(diagramNodeChangedEvent.DiagramNode);
     }
 }
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     switch (diagramEvent)
     {
     case DiagramNodeAddedEvent diagramNodeAddedEvent:
         RoslynModelService.ExtendModelWithRelatedNodes(diagramNodeAddedEvent.DiagramNode.ModelNode, recursive: false);
         break;
     }
 }
Example #11
0
 private void OnDiagramChangedAsync(DiagramEventBase diagramEvent)
 {
     switch (diagramEvent)
     {
     case DiagramNodeAddedEvent diagramNodeAddedEvent:
         // It's a fire-and-forget async call, no need to await.
         var task = RoslynModelService.ExtendModelWithRelatedNodesAsync(diagramNodeAddedEvent.DiagramNode.ModelNode, recursive: false);
         break;
     }
 }
Example #12
0
        private void OnDiagramChanged(DiagramEventBase diagramEvent)
        {
            lock (_diagramEventQueue)
            {
                Debug.WriteLine($"Event arrived: {diagramEvent}");
                _diagramEventQueue.Enqueue(diagramEvent);
            }

            _diagramEventArrivedEvent.Set();
        }
Example #13
0
        private void OnDiagramChanged(DiagramEventBase diagramEvent)
        {
            _lastDiagram = diagramEvent.NewDiagram;

            if (diagramEvent is DiagramClearedEvent)
            {
                HideAllWidgets();
            }

            UpdateDiagramContentRect(diagramEvent.NewDiagram);
        }
Example #14
0
        private async Task OnDiagramChangedAsync(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeAddedEvent diagramNodeAddedEvent:
                // It's a fire-and-forget async call, no need to await.
                // ReSharper disable once UnusedVariable
                await RoslynModelService.ExtendModelWithRelatedNodesAsync(diagramNodeAddedEvent.DiagramNode.ModelNode, recursive : false);

                break;
            }
        }
        private void OnDiagramChanged([NotNull] DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
                case DiagramNodeRectChangedEvent _:
                case DiagramConnectorRouteChangedEvent _:
                    return;
            }

            var diagram = diagramEvent.NewDiagram;
            var diagramLayoutInfo = _layoutAlgorithm.Calculate(diagram);
            DiagramService.ApplyLayout(diagramLayoutInfo);
        }
Example #16
0
        private void DispatchDiagramEvent(DiagramEventBase diagramEvent)
        {
            switch (diagramEvent)
            {
            case DiagramNodeSizeChangedEvent diagramNodeSizeChangedEvent:
                FollowDiagramNode(diagramNodeSizeChangedEvent.DiagramNode);
                break;

            case DiagramNodePositionChangedEvent diagramNodePositionChangedEvent:
                FollowDiagramNode(diagramNodePositionChangedEvent.DiagramNode);
                break;
            }
        }
Example #17
0
        private DiagramEventBase GetLastEventFromQueue()
        {
            DiagramEventBase lastEvent = null;

            lock (_diagramEventQueue)
            {
                while (_diagramEventQueue.Any())
                {
                    lastEvent = _diagramEventQueue.Dequeue();
                }
            }

            return(lastEvent);
        }
Example #18
0
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     _hostUiServices.Run(async() => await OnDiagramChangedAsync(diagramEvent));
 }
Example #19
0
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     _lastDiagram = diagramEvent.NewDiagram;
     UpdateEnabledState();
 }
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     _diagramContentRect = diagramEvent.NewDiagram.Rect.ToWpf();
 }
Example #21
0
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     EnsureUiThread(() => DispatchDiagramEvent(diagramEvent));
 }
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     _lastDiagram = diagramEvent.NewDiagram;
     UpdateVisibility();
 }
Example #23
0
 private void OnDiagramChanged(DiagramEventBase diagramEvent)
 {
     // All diagram-induced view model manipulation must occur on the UI thread to avoid certain race conditions.
     // (E.g. avoid the case when creating a connector view model precedes the creation of its source and target node view models.)
     EnsureUiThread(() => DispatchDiagramChangeEvent(diagramEvent));
 }