/// <summary> /// Default command handler. /// </summary> /// <param name="graphToolState">The state.</param> /// <param name="command">The command.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, ItemizeNodeCommand command) { bool undoPushed = false; using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { var graphModel = graphToolState.GraphViewState.GraphModel; foreach (var model in command.Models.Where(m => m is IVariableNodeModel || m is IConstantNodeModel)) { var edges = graphModel.GetEdgesConnections(model.OutputPort).ToList(); for (var i = 1; i < edges.Count; i++) { if (!undoPushed) { undoPushed = true; graphToolState.PushUndo(command); } var newModel = (ISingleOutputPortNodeModel)graphModel.DuplicateNode(model, i * 50 * Vector2.up); graphUpdater.MarkNew(newModel); var edge = edges[i]; var newEdge = graphModel.CreateEdge(edge.ToPort, newModel.OutputPort); var deletedModels = graphModel.DeleteEdge(edge); graphUpdater.MarkNew(newEdge); graphUpdater.MarkDeleted(deletedModels); } } } }
public void ClearSelectionWorks() { var node1 = new NodeModel(); var node2 = new NodeModel(); var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); using (var selectionUpdater = state.SelectionState.UpdateScope) { selectionUpdater.ClearSelection(state.WindowState.GraphModel); selectionUpdater.SelectElements(new[] { node1, node2 }, true); } Assert.IsTrue(state.SelectionState.IsSelected(node1)); Assert.IsTrue(state.SelectionState.IsSelected(node2)); using (var selectionUpdater = state.SelectionState.UpdateScope) { selectionUpdater.ClearSelection(state.WindowState.GraphModel); } Assert.IsFalse(state.SelectionState.IsSelected(node1)); Assert.IsFalse(state.SelectionState.IsSelected(node2)); }
public TracingTimeline(GraphView graphView, GraphToolState windowGraphToolState) { m_GraphView = graphView; m_WindowGraphToolState = windowGraphToolState; m_TimeArea = new TimeArea(); m_Overlay = new AnimEditorOverlay() { PlayHeadColor = new Color(0.2117647F, 0.6039216F, 0.8F) }; m_State = new TimelineState(m_TimeArea); m_Overlay.state = m_State; var debugger = ((Stencil)m_WindowGraphToolState?.WindowState.GraphModel?.Stencil)?.Debugger; IGraphTrace trace = debugger?.GetGraphTrace(m_WindowGraphToolState?.WindowState.GraphModel, m_WindowGraphToolState.TracingControlState.CurrentTracingTarget); if (trace?.AllFrames != null && trace.AllFrames.Count > 0) { int firstFrame = trace.AllFrames[0].Frame; int lastFrame = trace.AllFrames[trace.AllFrames.Count - 1].Frame; m_TimeArea.SetShownRange( firstFrame - k_MinTimeVisibleOnTheRight, lastFrame + k_MinTimeVisibleOnTheRight); } }
public static void DefaultCommandHandler(GraphToolState graphToolState, CommandThatRebuildsAll command) { using (var updater = graphToolState.GraphViewState.UpdateScope) { updater.ForceCompleteUpdate(); } }
public static void DefaultCommandHandler(GraphToolState graphToolState, CommandThatMarksNew command) { using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { var placematModel = graphToolState.GraphViewState.GraphModel.CreatePlacemat(Rect.zero); graphUpdater.MarkNew(placematModel); } }
public void Setup() { var prefs = Preferences.CreatePreferences(nameof(SearcherSizeTests)); m_State = new GraphToolState(new Hash128(), prefs); m_State.ResetSearcherSizes(); m_State.SetInitialSearcherSize(null, k_DefaultSize, k_DefaultRatio); m_State.SetInitialSearcherSize(SearcherService.Usage.k_CreateNode, k_CreateNodeDefaultSize, k_CreateNodeDefaultRatio); }
public static void DefaultCommandHandler(GraphToolState graphToolState, CommandThatMarksChanged command) { using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { var placemat = graphToolState.GraphViewState.GraphModel.PlacematModels.FirstOrDefault(); Debug.Assert(placemat != null); graphUpdater.MarkChanged(placemat); } }
public static void DefaultHandler(GraphToolState state, SetTemperatureCommand command) { state.PushUndo(command); using (var graphUpdater = state.GraphViewState.UpdateScope) { foreach (var nodeModel in command.Models) { nodeModel.Temperature = command.Value; graphUpdater.MarkChanged(nodeModel); } } }
public static void DefaultHandler(GraphToolState state, RemovePortCommand command) { state.PushUndo(command); using (var graphUpdater = state.GraphViewState.UpdateScope) { foreach (var nodeModel in command.Models) { nodeModel.RemoveIngredientPort(); graphUpdater.MarkChanged(nodeModel); } } }
public void EmptyChangeSetsDoNotDirtyAsset() { var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); var initialDirtyCount = EditorUtility.GetDirtyCount(m_Asset1 as Object); using (var graphUpdater = state.GraphViewState.UpdateScope) { graphUpdater.MarkNew(Enumerable.Empty <IGraphElementModel>()); graphUpdater.MarkChanged(Enumerable.Empty <IGraphElementModel>()); graphUpdater.MarkDeleted(Enumerable.Empty <IGraphElementModel>()); } Assert.AreEqual(initialDirtyCount, EditorUtility.GetDirtyCount(m_Asset1 as Object)); }
public void AllStateComponentsReturnsAllStateComponents() { var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); var sc = new HashSet <IStateComponent>(state.AllStateComponents); var foundComponents = new HashSet <IStateComponent>(); foreach (var fieldInfo in typeof(GraphToolState) .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(fi => typeof(IStateComponent).IsAssignableFrom(fi.FieldType)) ) { foundComponents.Add(fieldInfo.GetValue(state) as IStateComponent); Assert.IsTrue(sc.Contains(fieldInfo.GetValue(state) as IStateComponent), fieldInfo.Name + " is not included in AllStateComponents"); } Assert.AreEqual(sc, foundComponents); }
public static void DefaultHandler(GraphToolState state, AddPortCommand command) { if (!command.Models.Any() || command.m_PortDirection == PortDirection.None) { return; } state.PushUndo(command); using (var updater = state.GraphViewState.UpdateScope) { foreach (var nodeModel in command.Models) { nodeModel.AddPort(command.m_PortOrientation, command.m_PortDirection); } updater.MarkChanged(command.Models); } }
/// <summary> /// Default command handler. /// </summary> /// <param name="graphToolState">The state.</param> /// <param name="command">The command.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, LockConstantNodeCommand command) { if (!command.Models.Any()) { return; } graphToolState.PushUndo(command); using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { foreach (var constantNodeModel in command.Models) { constantNodeModel.IsLocked = command.Value; } graphUpdater.MarkChanged(command.Models); } }
void ClearHighlights(GraphToolState state) { var currentGraphModel = state?.WindowState.GraphModel; currentGraphModel?.DeleteBadgesOfType <DebuggingErrorBadgeModel>(); currentGraphModel?.DeleteBadgesOfType <DebuggingValueBadgeModel>(); foreach (Node x in m_GraphView.Nodes.ToList()) { x.RemoveFromClassList(k_TraceHighlight); x.RemoveFromClassList(k_TraceSecondaryHighlight); x.RemoveFromClassList(k_ExceptionHighlight); x.Query <DebuggingPort>().ForEach(p => { p.ExecutionPortActive = false; }); } }
public static void DefaultCommandHandler(GraphToolState graphToolState, SetNumberOfInputPortCommand command) { if (!command.Models.Any()) { return; } graphToolState.PushUndo(command); using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { foreach (var nodeModel in command.Models) { nodeModel.InputPortCount = command.Value; nodeModel.DefineNode(); } graphUpdater.MarkChanged(command.Models); } }
public void SelectionStateIsTiedToAssetAndView() { var node = new NodeModel(); var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); state.LoadGraphAsset(m_Asset1, null); Assert.IsNotNull(state.SelectionState); using (var selectionUpdater = state.SelectionState.UpdateScope) { selectionUpdater.SelectElements(new[] { node }, true); } Assert.IsTrue(state.SelectionState.IsSelected(node)); // Load another asset in the same view: node is not selected anymore. var state2 = new GraphToolState(viewGuid1, null); state2.LoadGraphAsset(m_Asset2, null); var selectionState2 = state2.SelectionState; Assert.IsNotNull(selectionState2); Assert.IsFalse(selectionState2.IsSelected(node)); // Load the same asset in the another view: node is not selected anymore. var viewGuid2 = SerializableGUID.Generate(); state2 = new GraphToolState(viewGuid2, null); state2.LoadGraphAsset(m_Asset1, null); selectionState2 = state2.SelectionState; Assert.IsNotNull(selectionState2); Assert.IsFalse(selectionState2.IsSelected(node)); // Reload the same asset in the original view: node is still selected. state2 = new GraphToolState(viewGuid1, null); state2.LoadGraphAsset(m_Asset1, null); selectionState2 = state2.SelectionState; Assert.IsNotNull(selectionState2); Assert.IsTrue(selectionState2.IsSelected(node)); }
/// <summary> /// Default command handler. /// </summary> /// <param name="graphToolState">The state.</param> /// <param name="command">The command.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, ChangeVariableDeclarationCommand command) { if (!command.Models.Any()) { return; } graphToolState.PushUndo(command); using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) { foreach (var model in command.Models) { model.DeclarationModel = command.Variable; var references = graphToolState.GraphViewState.GraphModel.FindReferencesInGraph <IVariableNodeModel>(command.Variable); graphUpdater.MarkChanged(references); } graphUpdater.MarkChanged(command.Models); } }
public void MarkChangedHasNoEffectIfModelIsNew() { var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); var dummyModel = new TestNodeModel(); using (var graphUpdater = state.GraphViewState.UpdateScope) { graphUpdater.MarkNew(dummyModel); } var changes = state.GraphViewState.GetAggregatedChangeset(0); Assert.IsTrue(changes.NewModels.Contains(dummyModel)); using (var graphUpdater = state.GraphViewState.UpdateScope) { graphUpdater.MarkChanged(dummyModel); } changes = state.GraphViewState.GetAggregatedChangeset(0); Assert.IsFalse(changes.ChangedModels.Contains(dummyModel)); }
internal void MapDebuggingData(GraphToolState state) { bool needUpdate = false; if (m_Stopwatch == null) { m_Stopwatch = Stopwatch.StartNew(); } else if (EditorApplication.isPaused || m_Stopwatch.ElapsedMilliseconds > k_UpdateIntervalMs) { needUpdate = true; m_Stopwatch.Restart(); } var currentGraphModel = state?.GraphViewState.GraphModel; var debugger = ((Stencil)currentGraphModel?.Stencil)?.Debugger; if (state == null || debugger == null) { return; } if (needUpdate && debugger.GetTracingSteps(currentGraphModel, state.TracingControlState.CurrentTracingFrame, state.TracingControlState.CurrentTracingTarget, out var stepList)) { using (var updater = state.TracingDataState.UpdateScope) { updater.MaxTracingStep = stepList?.Count ?? 0; updater.DebuggingData = stepList; } // PF FIXME HighlightTrace should be an observer on tracing states. ClearHighlights(state); HighlightTrace(state.TracingControlState.CurrentTracingStep, state.TracingDataState.DebuggingData); } }
public void MarkDeletedRemovesModelFromTheChangedList() { var viewGuid1 = SerializableGUID.Generate(); var state = new GraphToolState(viewGuid1, null); var dummyModel = new TestNodeModel(); using (var graphUpdater = state.GraphViewState.UpdateScope) { graphUpdater.MarkChanged(dummyModel); } var changes = state.GraphViewState.GetAggregatedChangeset(0); Assert.IsTrue(changes.ChangedModels.Contains(dummyModel)); using (var graphUpdater = state.GraphViewState.UpdateScope) { graphUpdater.MarkDeleted(dummyModel); } changes = state.GraphViewState.GetAggregatedChangeset(0); Assert.IsFalse(changes.ChangedModels.Contains(dummyModel)); Assert.IsTrue(changes.DeletedModels.Contains(dummyModel)); }
/// <summary> /// Default command handler. /// </summary> /// <param name="graphToolState">The state to modify.</param> /// <param name="command">The command to apply to the state.</param> public static void DefaultCommandHandler(GraphToolState graphToolState, ConvertConstantNodesAndVariableNodesCommand command) { if ((command.ConstantNodeModels?.Count ?? 0) == 0 && (command.VariableNodeModels?.Count ?? 0) == 0) { return; } graphToolState.PushUndo(command); using (var graphUpdater = graphToolState.GraphViewState.UpdateScope) using (var selectionUpdater = graphToolState.SelectionState.UpdateScope) { var graphModel = graphToolState.GraphViewState.GraphModel; foreach (var constantModel in command.ConstantNodeModels ?? Enumerable.Empty <IConstantNodeModel>()) { var declarationModel = graphModel.CreateGraphVariableDeclaration( constantModel.Type.GenerateTypeHandle(), constantModel.Type.FriendlyName().CodifyStringInternal(), ModifierFlags.None, true, constantModel.Value.CloneConstant()); graphUpdater.MarkNew(declarationModel); var variableModel = graphModel.CreateVariableNode(declarationModel, constantModel.Position); if (variableModel != null) { graphUpdater.MarkNew(variableModel); selectionUpdater.SelectElement(variableModel, true); variableModel.State = constantModel.State; if (constantModel.HasUserColor) { variableModel.Color = constantModel.Color; } foreach (var edge in graphModel.GetEdgesConnections(constantModel.OutputPort).ToList()) { var newEdge = graphModel.CreateEdge(edge.ToPort, variableModel.OutputPort); var deletedModels = graphModel.DeleteEdge(edge); graphUpdater.MarkNew(newEdge); graphUpdater.MarkDeleted(deletedModels); selectionUpdater.SelectElements(deletedModels, false); } } var deletedElements = graphModel.DeleteNode(constantModel, deleteConnections: false); graphUpdater.MarkDeleted(deletedElements); selectionUpdater.SelectElements(deletedElements, false); } foreach (var variableModel in command.VariableNodeModels ?? Enumerable.Empty <IVariableNodeModel>()) { if (graphModel.Stencil.GetConstantNodeValueType(variableModel.GetDataType()) == null) { continue; } var constantModel = graphModel.CreateConstantNode(variableModel.GetDataType(), variableModel.Title, variableModel.Position); constantModel.ObjectValue = variableModel.VariableDeclarationModel?.InitializationModel?.ObjectValue; constantModel.State = variableModel.State; if (variableModel.HasUserColor) { constantModel.Color = variableModel.Color; } graphUpdater.MarkNew(constantModel); selectionUpdater.SelectElement(constantModel, true); var edgeModels = graphModel.GetEdgesConnections(variableModel.OutputPort).ToList(); foreach (var edge in edgeModels) { var newEdge = graphModel.CreateEdge(edge.ToPort, constantModel.OutputPort); var deletedModels = graphModel.DeleteEdge(edge); graphUpdater.MarkNew(newEdge); graphUpdater.MarkDeleted(deletedModels); selectionUpdater.SelectElements(deletedModels, false); } var deletedElements = graphModel.DeleteNode(variableModel, deleteConnections: false); graphUpdater.MarkDeleted(deletedElements); selectionUpdater.SelectElements(deletedElements, false); } } }
public static void DefaultCommandHandler(GraphToolState graphToolState, CommandThatDoesNothing command) { }