void InitGraph() { graph = GraphBuilder <T, P> .Build(seedEntities, graphBackend.GetRelations, builderRNG, Settings.Instance.maxGraphNodes); if (graph == null) { return; } // delay the view construction, so this.drawRect can be set before that runs. Exec(() => view = new IMView <T, P>(graph, this)); // run layout, unless the user wants to use caches and a cache could be loaded bool runLayout = Settings.Instance.cacheLayouts ? !GraphPosSerialization.LoadGraphLayout(graph, seedEntities, graphBackend.GetDecoratedType()) : true; if (runLayout) { layoutRunning = true; // make the view focus on the initial graph unfolding adjustTransformMode = AdjustTransformMode.Instant; Exec(DoAutoLayout); } }
void IWorkspace.ExpandEntity(object entityObj) { var entity = entityObj as T; if (entity == null) { Log.Error("Can't expand entity: it is not of type " + typeof(T)); return; } if (graph == null) { return; } if (!graph.ContainsVertex(entity)) { Log.Error("Can't expand entity that is not in the graph: " + entity); return; } GraphBuilder <T, P> .Expand(graph, entity, graphBackend.GetRelations, builderRNG, graph.VertexCount + Settings.Instance.maxGraphNodes); adjustTransformMode = AdjustTransformMode.Not; // don't mess with the user's transform settings Exec(DoAutoLayout); }
public void OnToolbarGUI() { EditorGUI.BeginChangeCheck(); if (graph != null && GUILayout.Button("Relayout", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { Exec(() => api.Relayout()); } // let user pick a layout type (iff tree layout is an option) if (graph != null && graph.IsTree()) { layoutType = (LayoutType)GUIUtil.EnumToolbar("", layoutType, (t) => layoutButtonContent[(LayoutType)t], EditorStyles.miniButton); if (EditorGUI.EndChangeCheck()) { GUIUtil.SetPrefsInt(GetPrefsKeyLayout(), (int)layoutType); adjustTransformMode = AdjustTransformMode.Smooth; Exec(DoAutoLayout); } } #if DEBUG if (GUILayout.Button("DumpTopo", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { TopologySerializer <T, P> .DumpTopology(graph); } #endif // draw view controls if (view != null) { GUILayout.FlexibleSpace(); view.OnToolbarGUI(); } }
void IWorkspace.AddTargets(object[] targetsToAdd, Vector2 pos) { if (targetsToAdd == null) { Log.Error("Targets are null"); return; } if (targetsToAdd.Any(obj => !expectedTargetType.IsAssignableFrom(obj.GetType()))) { Log.Error("Not all targets are of type " + expectedTargetType); return; } if (graph == null) { return; } var addedTargetSeeds = targetsToAdd.SelectMany(graphBackend.Init); var newSeeds = addedTargetSeeds.Except(seedEntities).ToHashSet(); // find the ones that are actually new seedEntities.UnionWith(newSeeds); // when no position is given, use screen center if (pos == Vector2.zero) { pos = (view == null) ? Vector2.zero : view.GetGraphPosition(drawRect.center); } else // transform pos to graph space { pos = (view == null) ? Vector2.zero : view.GetGraphPosition(pos); } GraphBuilder <T, P> .Append(graph, newSeeds, pos, graphBackend.GetRelations, builderRNG, graph.VertexCount + Settings.Instance.maxGraphNodes); adjustTransformMode = AdjustTransformMode.Not; // don't mess with the user's transform settings Exec(DoAutoLayout); }
public void Relayout() { adjustTransformMode = AdjustTransformMode.Smooth; Exec(DoAutoLayout); }