protected SceneInfo SaveToThing(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout, IThing thing, string name) { var result = default(SceneInfo); if (thing is IStreamThing || thing == null) { var content = new Content <Stream> ( new MemoryStream(), CompressionType.bZip2, ContentTypes.LimadaSheet); var serializer = new SheetSerializer(); serializer.Save(content.Data, scene.Graph, layout); content.Data.Position = 0; content.Description = name; thing = new VisualThingsContentViz().AssignContent(scene.Graph, thing, content); result = SheetStore.RegisterSceneInfo(thing.Id, name); result.State.Hollow = false; result.State.Clean = true; result.State.CopyTo(scene.State); } else { throw new ArgumentException("thing must be a StreamThing"); } return(result); }
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); } }
public void LoadSearch(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout, object name) { var graph = scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink>(); if (graph == null) { throw new ArgumentException("Search works only on ThingGraphs"); } scene.CleanScene(); var visuals = scene.Graph.ThingGraph() .Search(name, false) .Select(t => graph.Get(t)); new GraphSceneFacade <IVisual, IVisualEdge>(() => scene, layout) .Add(visuals, false, false); var aligner = new Aligner <IVisual, IVisualEdge>(scene, layout); aligner.FullLayout(null, new Point(layout.Border.Width, layout.Border.Height), layout.Options(), new VisualComparer()); aligner.Commit(); scene.ClearSpatialIndex(); }
public static void ChangeShape(IGraphScene <IVisual, IVisualEdge> scene, IVisual visual, IShape newShape) { if (visual == null || (visual is IVisualEdge)) { return; } if (newShape != null) { newShape = (IShape)newShape.Clone(); newShape.Location = visual.Shape.Location; newShape.DataSize = visual.Shape.DataSize; var changeShape = new ActionCommand <IVisual, IShape> ( visual, newShape, delegate(IVisual target, IShape shape) { target.Shape = shape; }); scene.Requests.Add(changeShape); if (visual.Shape is VectorShape || newShape is VectorShape) { scene.Requests.Add(new LayoutCommand <IVisual> (visual, LayoutActionType.Justify)); } foreach (var edge in scene.Twig(visual)) { scene.Requests.Add(new LayoutCommand <IVisual> (edge, LayoutActionType.Justify)); } } }
public static void Select(IGraphScene <TItem, TEdge> scene, IEnumerable <TItem> selection, ModifierKeys modifiers) { bool isLinkKey = modifiers.HasFlag(ModifierKeys.Shift); var oldSelected = new Set <TItem>(); foreach (var item in scene.Selected.Elements) { oldSelected.Add(item); } if ((modifiers & ModifierKeys.Control) != ModifierKeys.Control) { scene.Selected.Clear(); } foreach (var item in selection) { bool isLink = item is TEdge; bool add = (isLinkKey && isLink) || (!isLinkKey && !isLink); if (add) { scene.Selected.Add(item); if (!oldSelected.Contains(item)) { scene.Requests.Add(new Command <TItem>(item)); } oldSelected.Remove(item); } } foreach (var item in oldSelected) { scene.Requests.Add(new Command <TItem>(item)); } }
/// <summary> /// removes items after display perform is done /// </summary> /// <param name="sinkScene"></param> /// <param name="sinkItem"></param> protected virtual void SceneItemRemoveAfterDisplayUpdate(IGraphScene <TSinkItem, TSinkEdge> sinkScene, TSinkItem sinkItem) { var graphs = new Stack <IGraph <TSinkItem, TSinkEdge> > (); graphs.Push(sinkScene.Graph); while (graphs.Count > 0) { var graph = graphs.Pop(); var sinkGraph = graph as ISinkGraph <TSinkItem, TSinkEdge>; if (graph.Contains(sinkItem)) { if (sinkGraph != null) { sinkGraph.RemoveSinkItem(sinkItem); } else { graph.Remove(sinkItem); } } var graphPair = graph as IGraphPair <TSinkItem, TSinkItem, TSinkEdge, TSinkEdge>; if (graphPair != null) { graphs.Push(graphPair.Source); } } }
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); } }
public static void LinkItem(IGraphScene <IVisual, IVisualEdge> scene, IVisual item, Point pt, int hitSize, bool itemIsRoot) { if (item == null) { return; } var target = scene.Hovered; if (target == null && scene.Focused != null && scene.Focused.Shape.IsHit(pt, hitSize)) { target = scene.Focused; } if (item != target) { if (itemIsRoot) { CreateEdge(scene, item, target); } else { CreateEdge(scene, target, item); } } }
/// <summary> /// if item is not an edge or done == null, a <see cref="DeleteCommand{TItem, TEdge}"/> is added/> /// if item is an edge, a <see cref="DeleteEdgeCommand{TItem, TEdge}"/> is added /// this does NOT delete the edge /// </summary> /// <typeparam name="TItem"></typeparam> /// <typeparam name="TEdge"></typeparam> /// <param name="scene"></param> /// <param name="item"></param> /// <param name="done"></param> public static void RequestDelete <TItem, TEdge> (this IGraphScene <TItem, TEdge> scene, TItem item, ICollection <TItem> done) where TEdge : TItem, IEdge <TItem> { if (done == null || !done.Contains(item)) { // prove if already in Requests? but RemoveBoundsCommand is a DeleteCommand too! //if (scene.Requests.OfType<DeleteCommand<TItem, TEdge>> ().Any (c => c.Subject.Equals (item))) // return; ICommand <TItem> command = null; if (item is TEdge && done != null) { command = new DeleteEdgeCommand <TItem, TEdge> (item, scene); } else { command = new DeleteCommand <TItem, TEdge> (item, scene); } scene.Requests.Add(command); if (done != null) { done.Add(item); } } ; }
public static void CheckLayout <TItem, TEdge> (this IGraphScene <TItem, TEdge> scene, IGraphSceneLayout <TItem, TEdge> layout) where TEdge : TItem, IEdge <TItem> { if (scene != layout.Data) { throw new ArgumentException($"{nameof (layout)}.Data differs from {nameof (scene)}: {scene.GetHashCode ():X8} != {layout.Data.Graph.GetHashCode ():X8}"); } }
public virtual void SceneFocusChangedCallback(IGraphScene <TItem, TEdge> scene, TItem item) { if (SceneFocusChanged != null) { focusChangedEventArgs = new GraphSceneEventArgs <TItem, TEdge>(scene, item); } }
/// <summary> /// enumerates all things of scene's selected elements /// if a Digidoc is the only selected, then the Pages of the Digidoc are enumerated /// </summary> /// <param name="scene"></param> /// <returns></returns> public IEnumerable <IThing> SelectedThings(IGraphScene <IVisual, IVisualEdge> scene) { var visuals = scene.Selected.Elements; if (visuals.Count() == 0) { visuals = scene.Graph.Where(v => !(v is IVisualEdge)); } if (visuals.Count() == 0) { return(null); } IEnumerable <IThing> things = null; if (visuals.Count() == 1) { var thing = scene.Graph.ThingOf(visuals.First()); var digidoc = new DigidocSchema(scene.Graph.ThingGraph(), thing); if (digidoc.HasPages()) { things = digidoc.OrderedPages(); } } if (things == null) { things = visuals .OrderBy(v => v.Location, new PointComparer { Delta = 20 }) .Select(v => scene.Graph.ThingOf(v)); } return(things); }
public ImageExporter(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout) : base() { this.Data = scene; this.Layout = layout; Compose(); }
public static IVisual VisualOfContent(this IGraphScene <IVisual, IVisualEdge> scene, Content <Stream> content) { if (scene == null || scene.Graph == null || content == null) { return(null); } return(VisualContentViz.VisualOfContent(scene.Graph, content)); }
/// <summary> /// gives back the conntent of the scene's focused /// </summary> /// <param name="scene"></param> /// <returns></returns> public static Content <Stream> ContentOfFocused(this IGraphScene <IVisual, IVisualEdge> scene) { if (scene == null) { return(null); } return(scene.ContentOfVisual(scene.Focused)); }
public void PopulateScene(IGraphScene <IVisual, IVisualEdge> scene) { if (ThingGraph != null) { this.Graph = new VisualThingGraph(new VisualGraph(), this.ThingGraph); scene.Graph = this.Graph; } }
public static IGraphSceneLayout <TItem, TEdge> CloneLayout <TItem, TEdge> (this IGraphScene <TItem, TEdge> scene, IGraphSceneLayout <TItem, TEdge> layout) where TEdge : TItem, IEdge <TItem> { IGraphSceneLayout <TItem, TEdge> result = null; Func <IGraphScene <TItem, TEdge> > handler = () => scene; result = Activator.CreateInstance(layout.GetType(), new object [] { handler, layout.StyleSheet }) as IGraphSceneLayout <TItem, TEdge>; return(result); }
public override void BeforeDataChange(IGraphScene <TItem, TEdge> old) { base.BeforeDataChange(old); if (old != null) { old.FocusChanged -= SceneFocusChangedCallback; } }
protected void ReportElems(IGraphScene <IVisual, IVisualEdge> scene, IEnumerable <IVisual> elms, ILocator <IVisual> locator, AlignerOptions options) { elms .OrderBy(e => locator.GetLocation(e), new PointComparer { Delta = options.Distance.Width, Order = options.PointOrder }) .ForEach(e => ReportDetail("\t{3}{0}\t{1}\t{2}", e.Data, locator.GetLocation(e), locator.GetSize(e), scene.Focused == e ? "*" : "")); }
public virtual void Clear() { this._scene = null; this._view = null; this._graph = null; this._subGraph = null; CreatedItems.Clear(); }
/// <summary> /// true if scene.Graph is backed by a ThingGraph /// </summary> /// <param name="scene"></param> /// <returns></returns> public static bool HasThingGraph(this IGraphScene <IVisual, IVisualEdge> scene) { if (scene == null) { return(false); } return(scene.Graph.Source <IVisual, IVisualEdge, IThing, ILink> () != null); }
public void GraphChanged( object sender, GraphChangeArgs <IVisual, IVisualEdge> args, IVisual sinkItem, IGraphScene <IVisual, IVisualEdge> sinkScene, IGraphSceneDisplay <IVisual, IVisualEdge> sinkDisplay) { // everything is done in MeshBackHandler return; }
Stream SaveSheet(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout) { var sheet = new SheetSerializer(); var s = new MemoryStream(); sheet.Save(s, scene.Graph, scene.CloneLayout(layout)); s.Position = 0; return(s); }
protected virtual void SceneEdgeAdd(IGraphScene <TSinkItem, TSinkEdge> sinkScene, TSinkEdge sinkEdge) { if (sinkScene.Contains(sinkEdge.Root) && (sinkScene.Contains(sinkEdge.Leaf))) { sinkScene.Graph.Add(sinkEdge); sinkScene.Requests.Add(new LayoutCommand <TSinkItem> (sinkEdge, LayoutActionType.Invoke)); sinkScene.Requests.Add(new LayoutCommand <TSinkItem> (sinkEdge, LayoutActionType.Justify)); } }
public static Content <Stream> ContentOfVisual(this IGraphScene <IVisual, IVisualEdge> scene, IVisual visual) { if (scene == null || scene.Graph == null || visual == null) { return(null); } return(VisualContentViz.ContentOf(scene.Graph, visual)); }
public void RemoveScene(IGraphScene <TItem, TEdge> scene) { if (scene != null) { var graph = scene.Graph; graph.GraphChange -= this.VisualGraphChange; graph.ChangeData -= this.VisualGraphChangeData; Scenes.Remove(scene); // UnregisterBackGraph (graph); } }
public static void AddVisual(this IGraphScene <IVisual, IVisualEdge> scene, IVisual visual, IGraphSceneLayout <IVisual, IVisualEdge> layout) { if (scene.Focused != null) { PlaceVisual(scene, scene.Focused, visual, layout); } else { AddItem(scene, visual, layout, scene.NoHit); } }
protected IGraphScene <IVisual, IVisualEdge> SceneWithTestData(int exampleNr, int count = 1) { IGraphScene <IVisual, IVisualEdge> scene = null; var examples = new SceneExamples(); var testData = examples.Examples [exampleNr]; testData.Data.Count = count; scene = examples.GetScene(testData.Data); return(scene); }
public PrintDocument CreatePrintDocument(IGraphScene <IVisual, IVisualEdge> scene, IGraphSceneLayout <IVisual, IVisualEdge> layout) { this.painter = new ImageExporter(scene, layout); painter.Viewport.ClipOrigin = scene.Shape.Location; var doc = new PrintDocument(); doc.PrintPage += new PrintPageEventHandler(doc_PrintPage); return(doc); }
public virtual void Arrange(IGraphScene <IVisual, IVisualEdge> scene) { var location = startAt; var level2Width = Nodes[2].Size.Width + distance.Width + Nodes[3].Size.Width; var ident = startAt.X; Nodes[1].Location = new Point( ident + (level2Width - Nodes[1].Size.Width) / 2, startAt.Y); var level2Y = Nodes[1].Location.Y + Nodes[1].Size.Height + distance.Height; Nodes[2].Location = new Point( ident, level2Y); Nodes[3].Location = new Point( ident + level2Width - Nodes[3].Size.Width, level2Y); Nodes[4].Location = new Point( ident + (level2Width - Nodes[4].Size.Width) / 2, level2Y + Nodes[3].Size.Height + distance.Height); ident = ident + level2Width + distance.Width; level2Width = Nodes[6].Size.Width + distance.Width + Nodes[7].Size.Width; Nodes[5].Location = new Point( ident + (level2Width - Nodes[5].Size.Width) / 2, Nodes[1].Location.Y); level2Y = Nodes[5].Location.Y + Nodes[5].Size.Height + distance.Height; Nodes[6].Location = new Point( ident, level2Y); Nodes[7].Location = new Point( ident + level2Width - Nodes[7].Size.Width, level2Y); Nodes[8].Location = new Point( ident + (level2Width - Nodes[8].Size.Width) / 2, level2Y + Nodes[7].Size.Height + distance.Height); var vector = new Vector(); vector.Start = Nodes[1].Shape[Anchor.RightMiddle]; vector.End = Nodes[6].Shape[Anchor.LeftMiddle]; ((VectorShape)Line1.Shape).Data = vector; }