Ejemplo n.º 1
0
 protected virtual void OnNGraphChanged(TItem item, GraphEventType graphEventType)
 {
     if (_nGraphChanged != null)
     {
         _nGraphChanged(this, new GraphChangedEventArgs <TItem, TEdge>(this, GraphCursor.Create(this, item), graphEventType));
     }
 }
Ejemplo n.º 2
0
        public static void Delete <TItem, TEdge> (this IGraphScene <TItem, TEdge> scene, TItem item, ICollection <TItem> done)
            where TEdge : TItem, IEdge <TItem>
        {
            if (done == null)
            {
                done = new Set <TItem> ();
            }

            Action <TItem> requestDelete = cand => scene.RequestDelete(cand, done);

            if (!done.Contains(item))
            {
                foreach (var edge in scene.Graph.PostorderTwig(item))
                {
                    requestDelete(edge);
                }

                var dependencies = Registry.Pooled <GraphDepencencies <TItem, TEdge> > ();
                dependencies.VisitItems(
                    GraphCursor.Create(scene.Graph, item),
                    requestDelete,
                    GraphEventType.Remove);

                scene.RequestDelete(item, null);
                done.Add(item);
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable <TItem> DependsOn <TItem, TEdge> (this IGraph <TItem, TEdge> graph, TItem source, GraphEventType eventType) where TEdge : IEdge <TItem>
        {
            var dep = graph as IGraphDependencies <TItem, TEdge>;

            if (dep != null)
            {
                return(dep.DependsOn(GraphCursor.Create(graph, source), eventType));
            }
            return(new TItem[0]);
        }
Ejemplo n.º 4
0
 public override bool Remove(IThing item)
 {
     SchemaFacade.Dependencies.VisitItems(
         GraphCursor.Create(this, item),
         d => {
         RemoveThingToDisplay(d);
         this.OnGraphChange(d, GraphEventType.Remove);
         Source.Remove(d);
     },
         GraphEventType.Remove);
     RemoveThingToDisplay(item);
     return(Source.Remove(item));
 }
        protected virtual void BackGraphChange(object sender, GraphChangeArgs <TSourceItem, TSourceEdge> args)
        {
            var graph     = args.Graph;
            var backItem  = args.Item;
            var eventType = args.EventType;

            if (backItem == null)
            {
                return;
            }

            var change = Tuple.Create(graph, backItem, eventType);

            if (graphChanging.Contains(change))
            {
                return;
            }

            try {
                graphChanging.Add(change);

                var displays           = new HashSet <IGraphSceneDisplay <TSinkItem, TSinkEdge> > ();
                var removeDependencies = false;

                var senderAsSink = (sender as IGraph <TSinkItem, TSinkEdge>).RootSink();

                var scenes = ScenesOfBackGraph(graph)
                             // leave alone the sender:
                             .Where(s => s.Graph.RootSink() != senderAsSink)
                             .ToArray();

                Action <TSourceItem> visit = sourceItem => {
                    foreach (var scene in scenes)
                    {
                        var graphPair = scene.Graph.Source <TSinkItem, TSinkEdge, TSourceItem, TSourceEdge> ();

                        var sinkItem = default(TSinkItem);

                        if (eventType == GraphEventType.Add)
                        {
                            sinkItem = graphPair.Get(sourceItem);
                            if (sinkItem is TSinkEdge)
                            {
                                SceneEdgeAdd(scene, (TSinkEdge)sinkItem);
                                displays.Add(DisplayOf(scene));
                            }
                            continue;
                        }

                        if (graphPair.Count == 0 || !graphPair.Source2Sink.TryGetValue(sourceItem, out sinkItem))
                        {
                            continue;
                        }

                        var visible = scene.Contains(sinkItem);

                        if (eventType == GraphEventType.Remove)
                        {
                            if (removeDependencies)
                            {
                                if (visible &&
                                    !scene.Requests
                                    .OfType <DeleteCommand <TSinkItem, TSinkEdge> > ()
                                    .Any(r => sinkItem.Equals(r.Subject)))
                                {
                                    scene.RequestDelete(sinkItem, null);
                                }

                                if (visible)
                                {
                                    displays.Add(DisplayOf(scene));
                                }
                            }
                            else
                            {
                                if (visible)
                                {
                                    if (scene.Focused != null && scene.Focused.Equals(sinkItem))
                                    {
                                        scene.Focused = default(TSinkItem);
                                    }
                                    scene.Selected.Remove(sinkItem);

                                    scene.Requests.Add(new RemoveBoundsCommand <TSinkItem, TSinkEdge> (sinkItem, scene));
                                    scene.Graph.Twig(sinkItem).ForEach(e =>
                                                                       scene.Requests.Add(new RemoveBoundsCommand <TSinkItem, TSinkEdge> (e, scene)));
                                    displays.Add(DisplayOf(scene));
                                }
                            }
                        }

                        if (eventType == GraphEventType.Update)
                        {
                            if (backItem is TSourceEdge && sinkItem is TSinkEdge)
                            {
                                SceneEdgeChanged(graph, (TSourceEdge)backItem, scene, (TSinkEdge)sinkItem);
                                if (visible)
                                {
                                    displays.Add(DisplayOf(scene));
                                }
                            }
                            else
                            {
                                graphPair.UpdateSink(sinkItem);
                                if (visible)
                                {
                                    scene.Requests.Add(new LayoutCommand <TSinkItem> (sinkItem, LayoutActionType.Justify));
                                    displays.Add(DisplayOf(scene));
                                }
                            }
                        }
                    }
                };

                if (eventType == GraphEventType.Remove)
                {
                    try {
                        var dependencies = Registry.Pooled <GraphDepencencies <TSourceItem, TSourceEdge> > ();
                        removeDependencies = true;
                        dependencies.VisitItems(GraphCursor.Create(graph, backItem), visit, eventType);
                    } catch (Exception ex) {
                        Trace.TraceError(ex.Message);
                    } finally {
                        removeDependencies = false;
                    }
                }

                visit(backItem);

                displays.Where(display => display != null)
                .ForEach(display => {
                    display.Perform();
                    Xwt.Application.MainLoop.QueueExitAction(() => display.QueueDraw());
                });

                Action <TSourceItem> visitAfter = sourceItem => {
                    foreach (var scene in scenes)
                    {
                        var graphPair = scene.Graph.Source <TSinkItem, TSinkEdge, TSourceItem, TSourceEdge> ();

                        var sinkItem = default(TSinkItem);
                        if (graphPair.Count == 0 || !graphPair.Source2Sink.TryGetValue(sourceItem, out sinkItem))
                        {
                            continue;
                        }

                        var visible = scene.Contains(sinkItem);
                        if (eventType == GraphEventType.Remove)
                        {
                            SceneItemRemoveAfterDisplayUpdate(scene, sinkItem);
                        }
                    }
                };

                visitAfter(backItem);

                Xwt.Application.MainLoop.DispatchPendingEvents();
            } catch (Exception ex) {
                Trace.TraceError(ex.Message);
            } finally {
                graphChanging.Remove(change);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// gets a complete list of things
        /// as: link.leaf, link.marker, link.root
        /// if graph is SchemaGraph:
        /// thing.description, thing.pathtodescrition
        /// </summary>
        /// <param name="source"></param>
        /// <param name="graph"></param>
        /// <returns></returns>
        public static IEnumerable <IThing> CompletedThings(this IEnumerable <IThing> things, IGraph <IThing, ILink> graph)
        {
            if (things == null)
            {
                yield break;
            }

            var sourceGraph = graph.Unwrap();

            var             stack    = new Queue <IThing> ();
            var             done     = new Set <IThing> ();
            Action <IThing> addThing = null;
            Action <ILink>  addLink  = (link) => {
                if (!done.Contains(link))
                {
                    var walk = sourceGraph.Walk();
                    if (!done.Contains(link.Marker))
                    {
                        foreach (var thing in walk.Walk(link.Marker, 0))
                        {
                            addThing(thing.Node);
                        }
                    }
                    addThing(link.Root);
                    addThing(link.Leaf);

                    stack.Enqueue(link);
                    done.Add(link);
                }
            };

            addThing = (thing) => {
                if (!done.Contains(thing))
                {
                    if (thing is ILink)
                    {
                        foreach (var vein in graph.Vein((ILink)thing))
                        {
                            addLink(vein);
                        }
                    }
                    else
                    {
                        stack.Enqueue(thing);
                        done.Add(thing);
                    }
                }
            };

            foreach (var thing in things)
            {
                addThing(thing);

                var schemaGraph = graph as SchemaThingGraph;
                if (schemaGraph != null)
                {
                    addThing(schemaGraph.ThingToDisplay(thing));
                    foreach (var link in schemaGraph.ThingToDisplayPath(thing))
                    {
                        addThing(link);
                    }
                }

                Registry.Pooled <GraphDepencencies <IThing, ILink> > ().VisitItems(
                    GraphCursor.Create(graph, thing), d => addThing(d), GraphEventType.Add);
            }

            foreach (var item in stack)
            {
                yield return(item);
            }
        }
Ejemplo n.º 7
0
 public override void SetContent(IGraph <IVisual, IVisualEdge> graph, IVisual visual)
 {
     DigidocVidget.SetDocument(GraphCursor.Create(graph, visual));
 }