Пример #1
0
        public void ExportPages(string dir, GraphCursor <IVisual, IVisualEdge> source)
        {
            var graph         = source.Graph;
            var digidocVisual = source.Cursor;
            var man           = new StreamContentIoManager();

            if (HasPages(graph, digidocVisual))
            {
                int i = 0;
                var s = source.Cursor.Data == null ? CommonSchema.NullString : source.Cursor.Data.ToString();

                foreach (var pageContent in PageStreams(graph, digidocVisual))
                {
                    var info     = man.GetContentInfo(pageContent);
                    var ext      = info != null ? "." + info.Extension : "";
                    var pageName = i.ToString().PadLeft(5, '0');
                    if (pageContent.Description != null)
                    {
                        pageName = pageContent.Description.ToString().PadLeft(5, '0');
                    }

                    var name = dir + Path.DirectorySeparatorChar + s + " " + pageName + ext;

                    man.WriteSink(pageContent, new Uri(name));
                    pageContent.Data.Dispose();
                    pageContent.Data = null;
                }
            }
        }
Пример #2
0
        public void ReadThingGraphCursor(IGraphScene <IVisual, IVisualEdge> scene)
        {
            try {
                DefaultDialogValues(OpenFileDialog, ThingGraphCursorIoManager.ReadFilter);
                if (scene != null && scene.HasThingGraph())
                {
                    if (FileDialogShow(OpenFileDialog, true) == DialogResult.Ok)
                    {
                        var graphCursor = new GraphCursor <IThing, ILink>(scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink>().Source);
                        var uri         = IoUtils.UriFromFileName(OpenFileDialog.FileName);
                        ThingGraphCursorIoManager.ConfigureSinkIo = s => ConfigureSink(s);

                        graphCursor = ThingGraphCursorIoManager.ReadSink(uri, graphCursor);
                        if (graphCursor != null)
                        {
                            Registry.Create <ISceneViz <IVisual, IThing, IVisualEdge, ILink> > ()
                            .SetDescription(scene, graphCursor.Cursor, OpenFileDialog.FileName);
                        }
                        OpenFileDialog.ResetFileName();
                    }
                }
            } catch (Exception ex) {
                Registry.Pooled <IExceptionHandler>().Catch(ex, MessageType.OK);
            }
        }
Пример #3
0
 protected virtual void OnNGraphChanged(TItem item, GraphEventType graphEventType)
 {
     if (_nGraphChanged != null)
     {
         _nGraphChanged(this, new GraphChangedEventArgs <TItem, TEdge>(this, GraphCursor.Create(this, item), graphEventType));
     }
 }
Пример #4
0
 protected virtual void OnItemPropertyChanged(GraphCursor <TItem, TEdge> subject)
 {
     if (_itemPropertyChanged != null)
     {
         _itemPropertyChanged(this, new ItemPropertyChangedEventArgs <TItem, TEdge>());
     }
 }
Пример #5
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);
            }
        }
Пример #6
0
        public static IEnumerable <IThing> DependsOn(GraphCursor <IThing, ILink> source, GraphEventType eventType)
        {
            var graph = source.Graph.Unwrap();

            return(graph.Edges(source.Cursor)
                   .Where(l => l != null && l.Marker != null && Deps.Contains(l.Marker.Id))
                   .Select(l => l.Leaf)
                   .ToArray());
        }
Пример #7
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]);
        }
Пример #8
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));
 }
Пример #9
0
        public virtual IEnumerable <IThing> DependsOn(GraphCursor <IThing, ILink> source, GraphEventType eventType)
        {
            if (HasPages(source))
            {
                var doc   = source.Cursor;
                var graph = source.Graph.Unwrap();

                foreach (var link in PageLinks(graph as IThingGraph, doc).ToArray())
                {
                    var page       = link.Leaf;
                    var singleEdge = graph.HasSingleEdge(page);
                    yield return(link);

                    if (singleEdge || eventType != GraphEventType.Remove)
                    {
                        yield return(page);
                    }
                }
            }
        }
Пример #10
0
        public virtual void SetDocument(GraphCursor <IVisual, IVisualEdge> source)
        {
            var pagesDisplay = this.PagesDisplay;

            // bring the docpages into view:
            var docManager = new DigidocViz();
            var pageScene  = new Scene();

            pagesDisplay.Data = pageScene;

            var doc = source.Graph.ThingOf(source.Cursor);
            IGraph <IVisual, IVisualEdge> targetGraph = null;

            targetGraph = Mesh.CreateSinkGraph(source.Graph);

            pageScene.Graph = targetGraph;

            Mesh.AddScene(pageScene);

            var targetDocument = targetGraph.VisualOf(doc);

            this.DocumentVisual = targetDocument;

            // get the pages and add them to scene:
            var pages = docManager.Pages(targetGraph, targetDocument).OrderBy(e => e, new VisualComparer()).ToList();

            pages.ForEach(page => pagesDisplay.Data.Add(page));

            var distance = pagesDisplay.Layout.Distance;

            pagesDisplay.Layout.Border = this.Border;

            var aligner = new Aligner <IVisual, IVisualEdge> (pagesDisplay.Data, pagesDisplay.Layout);
            var dd      = this.Border.Height;
            var options = new AlignerOptions {
                Distance        = new Size(dd, dd),
                AlignX          = Alignment.End,
                AlignY          = Alignment.Start,
                Dimension       = Dimension.X,
                PointOrderDelta = 1
            };

            aligner.OneColumn(pages, (Point)this.Border, options);
            aligner.Locator.Commit(aligner.GraphScene.Requests);

            new State {
                Hollow = true
            }.CopyTo(pagesDisplay.State);
            pagesDisplay.Text = source.Cursor.Data == null ? CommonSchema.NullString : source.Cursor.Data.ToString();
            pagesDisplay.Viewport.Reset();
            pagesDisplay.BackendRenderer.Render();

            // show first page:
            var firstPage = pages.FirstOrDefault();

            if (firstPage != null)
            {
                pageScene.Focused = firstPage;
                pagesDisplay.OnSceneFocusChanged();
            }
            pagesDisplay.Perform();

            var pageCache  = new Set <IVisual> (pages);
            var moveResize = pagesDisplay.ActionDispatcher.GetAction <GraphItemMoveResizeAction <IVisual, IVisualEdge> > ();

            moveResize.FocusFilter = e => pageCache.Contains(e) ? null : e;
        }
Пример #11
0
 public bool HasPages(GraphCursor <IVisual, IVisualEdge> source)
 {
     return(HasPages(source.Graph, source.Cursor));
 }
Пример #12
0
 public IEnumerable <IVisual> Pages(GraphCursor <IVisual, IVisualEdge> source)
 {
     return(Pages(source.Graph, source.Cursor));
 }
Пример #13
0
 public GraphChangedEventArgs(object source, GraphCursor <TItem, TEdge> subject, Graphs.GraphEventType graphEventType)
 {
     this.Source         = Source;
     this.Subject        = subject;
     this.GraphEventType = graphEventType;
 }
        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);
            }
        }
Пример #15
0
 public bool HasPages(GraphCursor <IThing, ILink> cursor)
 {
     return(HasPages(cursor.Graph, cursor.Cursor));
 }
Пример #16
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);
            }
        }
Пример #17
0
 public override void SetContent(IGraph <IVisual, IVisualEdge> graph, IVisual visual)
 {
     DigidocVidget.SetDocument(GraphCursor.Create(graph, visual));
 }