/// <summary>
        /// Runs the layout and disposes the module afterwards.
        /// </summary>
        /// <remarks>
        /// This method will be called in a separate thread. If the layout has been called successfully
        /// the method <see cref="LayoutDone"/> will be called afterwards to apply the layout.
        /// If the layout has been canceled or an error has happened during layout the <see cref="Done"/>
        /// will be raised with an instance of <see cref="LayoutEventArgs"/>.
        /// </remarks>
        /// <param name="moduleContext">The module context for this operation.</param>
        /// <param name="graph">The graph to apply the layout to.</param>
        /// <param name="compoundEdit">The undo edit which wraps the layout. It has been created in <see cref="StartWithIGraph"/>
        /// and will be closed after a successful layout or canceled otherwise.</param>
        private async Task RunModuleAsync(ILookup moduleContext, IGraph graph, ICompoundEdit compoundEdit)
        {
            GraphControl view = moduleContext.Lookup <GraphControl>();

            try {
                await RunModule();

                Dispose();
                if (view.Dispatcher.CheckAccess())
                {
                    await LayoutDone(graph, moduleContext, compoundEdit);
                }
                else
                {
                    Invoke(view.Dispatcher, new Action(async() => await LayoutDone(graph, moduleContext, compoundEdit)));
                }
            } catch (ThreadAbortException tae) {
                compoundEdit.Cancel();
                if (view.Dispatcher.CheckAccess())
                {
                    OnDone(new LayoutEventArgs(tae));
                }
                else
                {
                    await view.Dispatcher.BeginInvoke(new Action(() => OnDone(new LayoutEventArgs(tae))));
                }
            } catch (AlgorithmAbortedException aae) {
                // layout was canceled. do nothing then.
                compoundEdit.Cancel();
                if (view.Dispatcher.CheckAccess())
                {
                    OnDone(new LayoutEventArgs(aae));
                }
                else
                {
                    Invoke(view.Dispatcher, new Action(() => OnDone(new LayoutEventArgs(aae))));
                }
            } catch (Exception ex) {
                compoundEdit.Cancel();
                if (view.Dispatcher.CheckAccess())
                {
                    OnDone(new LayoutEventArgs(ex));
                }
                else
                {
                    Invoke(view.Dispatcher, new Action(() => OnDone(new LayoutEventArgs(ex))));
                }
            } finally {
                FreeReentrant();
                TableLayoutConfigurator.CleanUp(graph);
            }
        }
        /// <summary>
        /// Runs the layout and disposes the module afterwards.
        /// </summary>
        /// <remarks>
        /// This method will be called in a separate thread. If the layout has been called successfully
        /// the method <see cref="LayoutDone"/> will be called afterwards to apply the layout.
        /// If the layout has been canceled or an error has happened during layout the <see cref="Done"/>
        /// will be raised with an instance of <see cref="LayoutEventArgs"/>.
        /// </remarks>
        /// <param name="moduleContext">The module context for this operation.</param>
        /// <param name="graph">The graph to apply the layout to.</param>
        /// <param name="compoundEdit">The undo edit which wraps the layout. It has been created in <see cref="StartWithIGraph"/>
        /// and will be closed after a successful layout or canceled otherwise.</param>
        private async Task RunModuleAsync(ILookup moduleContext, IGraph graph, ICompoundEdit compoundEdit)
        {
            GraphControl view = moduleContext.Lookup <GraphControl>();

            try {
                await RunModule();

                Dispose();
                if (!view.InvokeRequired)
                {
                    await LayoutDone(graph, moduleContext, compoundEdit);
                }
                else
                {
                    view.Invoke(new LayoutDoneHandler(LayoutDone), graph, moduleContext, compoundEdit);
                }
            } catch (ThreadAbortException tae) {
                compoundEdit.Cancel();
                if (!view.InvokeRequired)
                {
                    OnDone(new LayoutEventArgs(tae));
                }
                else
                {
                    view.BeginInvoke(new EventHandler(OnDone), view, new LayoutEventArgs(tae));
                }
            } catch (AlgorithmAbortedException aae) {
                // layout was canceled. do nothing then.
                compoundEdit.Cancel();
                if (!view.InvokeRequired)
                {
                    OnDone(new LayoutEventArgs(aae));
                }
                else
                {
                    view.Invoke(new EventHandler(OnDone), view, new LayoutEventArgs(aae));
                }
            } catch (Exception ex) {
                compoundEdit.Cancel();
                if (!view.InvokeRequired)
                {
                    OnDone(new LayoutEventArgs(ex));
                }
                else
                {
                    view.Invoke(new EventHandler(OnDone), view, new LayoutEventArgs(ex));
                }
            } finally {
                FreeReentrant();
                TableLayoutConfigurator.CleanUp(graph);
            }
        }
 /// <summary>
 /// Called after the a layout run finished.
 /// </summary>
 private void OnExecutorFinished()
 {
     if (canceled)
     {
         layoutEdit.Cancel();
     }
     else if (stopped)
     {
         layoutEdit.Commit();
     }
 }
 public virtual void CancelReshape(IInputModeContext context, RectD originalBounds)
 {
     rectangle.Reshape(originalBounds);
     foreach (var pair in reshapeHandlers)
     {
         pair.Value.CancelReshape(context, originalNodeLayouts[pair.Key]);
     }
     foreach (var pair in this.orthogonalEdgeDragHandlers)
     {
         pair.Value.CancelDrag();
     }
     compoundEdit.Cancel();
     Clear(context);
 }
        /// <summary>
        /// Called after the a layout run finished.
        /// </summary>
        private void OnExecutorFinished()
        {
            if (canceled)
            {
                layoutEdit.Cancel();
            }
            else if (stopped)
            {
                // finish undo/redo
                // save the layout of the rectangular area before and after the gesture
                var newRect = clearRect.ToRectD();
                var oldRect = oldClearRect;
                graphControl.Graph.AddUndoUnit("Rectangle changed", "Rectangle changed",
                                               () => clearRect.Reshape(oldRect),
                                               () => clearRect.Reshape(newRect));

                // add all changes of the complete gesture as one undo/redo unit
                layoutEdit.Commit();
            }
        }
Exemple #6
0
        /// <summary>
        /// Cancels the drag and cleans up.
        /// </summary>
        public void CancelDrag(IInputModeContext context, PointD originalLocation)
        {
            SetAngle(context, initialAngle);

            var portContext = new DelegatingContext(context);

            foreach (var portHandle in portHandles)
            {
                portHandle.CancelDrag(portContext, originalLocation);
            }
            portHandles.Clear();
            if (reshapeHandler != null)
            {
                reshapeHandler.CancelReshape(context, node.Layout.ToRectD());
            }
            if (compoundEdit != null)
            {
                compoundEdit.Cancel();
            }
            nodeAngles = null;
            ClearSameAngleHighlights(context);
        }