/// <summary>
 /// Adds the node to the graph.
 /// </summary>
 /// <param name='node'>
 /// The node to add.
 /// </param>/
 public void AddNode(UTNode node)
 {
     if (nodes == null) {
         nodes = new List<UTNode>();
     }
     nodes.Add(node);
 }
Ejemplo n.º 2
0
    private int ProcessForEachNode(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        var entry = node.Data;
        UTAutomationPlanEntry subTree = null;

        if (entry is UTAutomationPlanForEachEntry)
        {
            subTree = ((UTAutomationPlanForEachEntry)entry).startOfSubtree;
        }
        if (entry is UTAutomationPlanForEachFileEntry)
        {
            subTree = ((UTAutomationPlanForEachFileEntry)entry).startOfSubtree;
        }
        if (entry is UTMyForEachForBuildEntry)
        {
            subTree = ((UTMyForEachForBuildEntry)entry).startOfSubtree;
        }
        if (subTree != null)
        {
            var subTreeNode = graph.GetNodeFor(subTree);
            EnsureEmptyColumn(currentColumn + 1);
            currentRow = ProcessNode(subTreeNode, currentRow, currentColumn + 1);
        }

        var nextEntry = entry.NextEntry;

        if (nextEntry != null)
        {
            return(ProcessNode(graph.GetNodeFor(nextEntry), currentRow + 1, currentColumn));
        }
        return(currentRow);
    }
Ejemplo n.º 3
0
    private int ProcessDecisionNode(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        var entry      = node.Data;
        var leftEntry  = ((UTAutomationPlanDecisionEntry)entry).entryIfTrue;
        var rightEntry = ((UTAutomationPlanDecisionEntry)entry).entryIfFalse;

        var deepestRow = currentRow;

        if (rightEntry != null)
        {
            var subTreeNode = graph.GetNodeFor(rightEntry);
            EnsureEmptyColumn(currentColumn + 1);
            deepestRow = ProcessNode(subTreeNode, currentRow + 1, currentColumn + 1);
        }

        if (leftEntry != null)
        {
            var subTreeNode = graph.GetNodeFor(leftEntry);
            EnsureEmptyColumn(currentColumn);
            deepestRow = Math.Max(deepestRow, ProcessNode(subTreeNode, currentRow + 1, currentColumn));
        }
        return(deepestRow);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Adds an arbitrary entry at the given position.
    /// </summary>
    /// <returns>
    /// The entry that was added.
    /// </returns>
    /// <param name='position'>
    /// Position at which the entry should be added.
    /// </param>
    /// <typeparam name='T'>
    /// The type of the entry to be added.
    /// </typeparam>
    public T AddEntry <T> (Vector2 position) where T : UTAutomationPlanEntry
    {
        CUUndoUtility.RegisterUndo(new UObject[] { data, graphData }, "Add Node");
        var entry = UTils.AddAssetOfType <T> (PlanPath, true);

        entry.automationPlanEntryId = Guid.NewGuid().ToString();
        if (data.firstEntry == null)
        {
            data.firstEntry = entry;
        }

        UTNode node = new UTNode();

        node.Data   = entry;
        node.Bounds = new Rect(position.x, position.y, 200, 200);
        graphData.AddNode(node);

        // add offset for next node
        position.x += 50;
        position.y += 50;
        EditorUtility.SetDirty(entry);
        EditorUtility.SetDirty(graphData);
        SelectNode(node, SelectionMode.Replace);
        return(entry);
    }
 private static void AddToNodeList(List<List<UTNode>> nodeList, int index, UTNode node)
 {
     while (nodeList.Count <= index) {
         nodeList.Add (new List<UTNode>());
     }
     List<UTNode> nodes = nodeList[index];
     nodes.Add (node);
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Gets the node referenced from a certain node by a connector representing a certain property.
    /// </summary>
    /// <returns>
    /// The referenced node or null if no node is referenced.
    /// </returns>
    /// <param name='source'>
    /// The source node.
    /// </param>
    /// <param name='sourceProperty'>
    /// The property of the automation plan entry represented by the node that holds the reference to another node/entry.
    /// </param>
    public UTNode GetReferencedNode(UTNode source, string sourceProperty)
    {
        var reference = graphData.GetReference(source.Data, sourceProperty);

        if (reference != null)
        {
            return(graphData.GetNodeFor(reference.Target));
        }
        return(null);
    }
Ejemplo n.º 7
0
    private static void AddToNodeList(List <List <UTNode> > nodeList, int index, UTNode node)
    {
        while (nodeList.Count <= index)
        {
            nodeList.Add(new List <UTNode>());
        }
        List <UTNode> nodes = nodeList[index];

        nodes.Add(node);
    }
    // Layout-Rules:
    // Comments stay where they are
    // unconnected nodes stay where they are
    // Decision nodes are centered above their following nodes.
    // For-Each/For-Each-File: Subplan is put right
    // all other nodes are layouted top down.
    public void Relayout(UTGraph graph, UTNode startingNode)
    {
        if ( startingNode == null) {
            return;
        }

        this.graph = graph;
        columns.Clear();
        rows.Clear();
        visitedNodes.Clear();
        ProcessNode(startingNode, 0, 0);
        DoLayout();
    }
Ejemplo n.º 9
0
    // Layout-Rules:
    // Comments stay where they are
    // unconnected nodes stay where they are
    // Decision nodes are centered above their following nodes.
    // For-Each/For-Each-File: Subplan is put right
    // all other nodes are layouted top down.

    public void Relayout(UTGraph graph, UTNode startingNode)
    {
        if (startingNode == null)
        {
            return;
        }

        this.graph = graph;
        columns.Clear();
        rows.Clear();
        visitedNodes.Clear();
        ProcessNode(startingNode, 0, 0);
        DoLayout();
    }
Ejemplo n.º 10
0
    private int ProcessSimpleEntry(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        UTAutomationPlanEntry entry = node.Data;
        var nextEntry = entry.NextEntry;

        if (nextEntry != null)
        {
            return(ProcessNode(graph.GetNodeFor(nextEntry), currentRow + 1, currentColumn));
        }
        return(currentRow);
    }
Ejemplo n.º 11
0
	/// <summary>
	/// Deletes a node from the graph. Also deletes all references pointing from and to that node.
	/// </summary>
	/// <param name='node'>
	/// The node to delete.
	/// </param>
	public void DeleteNode(UTNode node) {
		if (nodes == null || !nodes.Contains(node)) {
			throw new ArgumentException("Trying to delete non-existing node.");
		}
		var sourceRefs = GetSourceReferences(node.Data);
		var targetRefs  = GetTargetReferences(node.Data);
		
		foreach(var reference in sourceRefs) {
			DeleteReference(reference);
		}
		foreach(var reference in targetRefs) {
			DeleteReference(reference);
		}
		
		nodes.Remove(node);
	}
Ejemplo n.º 12
0
    public void SelectNodeInInspector(UTNode node)
    {
        var actionEntry = node.Data as UTAutomationPlanSingleActionEntry;

        if (actionEntry != null)
        {
            Selection.activeObject = actionEntry.action;
            return;
        }

        var planEntry = node.Data as UTAutomationPlanPlanEntry;

        if (planEntry != null)
        {
            Selection.activeObject = planEntry.plan;
        }
    }
Ejemplo n.º 13
0
    /// <summary>
    /// Selects a single node
    /// </summary>
    /// <param name='node'>
    /// Node to select.
    /// </param>
    /// <param name='mode'>
    /// The selection node.
    /// </param>
    public void SelectNode(UTNode node, SelectionMode mode)
    {
        switch (mode)
        {
        case SelectionMode.Replace:
            selectedNodes.Clear();
            selectedNodes.Add(node);
            SelectNodeInInspector(node);
            break;

        case SelectionMode.Add:
            selectedNodes.Add(node);
            break;

        case SelectionMode.Subtract:
            selectedNodes.Remove(node);
            break;
        }
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Loads a plan into this model.
    /// </summary>
    /// <param name='plan'>
    /// The plan to load.
    /// </param>
    public void LoadPlan(UTAutomationPlan plan)
    {
        if (plan != null)
        {
            data = plan;
            string path = PlanPath;
            graphData = null;
            selectedNodes.Clear();

            // objects with hide fagl are not returned by LoadAssetAtPath
            UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(path);
            foreach (UnityEngine.Object asset in assets)
            {
                if (asset is UTGraph)
                {
                    graphData = (UTGraph)asset;
                    break;
                }
            }
            if (graphData == null)
            {
                graphData      = UTils.AddAssetOfType <UTGraph> (path, true);
                graphData.name = "Graph";
                EditorUtility.SetDirty(graphData);
            }
            if (plan.firstEntry != null)
            {
                SelectNode(graphData.GetNodeFor(plan.firstEntry), SelectionMode.Add);
            }
        }
        else
        {
            data      = null;
            graphData = null;
            selectedNodes.Clear();
            highlightedNode = null;
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Adds a connection between a node's connector and another node.
    /// </summary>
    /// <param name='sourceConnector'>
    /// Source connector.
    /// </param>
    /// <param name='targetNode'>
    /// Target node.
    /// </param>
    public void AddConnection(UTNode.Connector sourceConnector, UTNode targetNode)
    {
        var sourceEntry = sourceConnector.owner.Data;
        var property    = sourceConnector.property;
        var targetEntry = targetNode.Data;
        var sourceNode  = sourceConnector.owner;

        CUUndoUtility.RegisterUndo(new UObject[] { sourceEntry, graphData }, "Add connector");
        var reference = graphData.GetReference(sourceEntry, property);

        if (reference == null)
        {
            reference                = new UTReference();
            reference.Source         = sourceEntry;
            reference.SourceProperty = property;
            graphData.AddReference(reference);
        }
        reference.Target = targetEntry;
        SetProperty(sourceEntry, property, targetEntry);
        sourceNode.Recalc();
        EditorUtility.SetDirty(sourceEntry);
        EditorUtility.SetDirty(graphData);
    }
Ejemplo n.º 16
0
    private int ProcessNode(UTNode node, int currentRow, int currentColumn)
    {
        if (visitedNodes.Contains(node))
        {
            return(currentRow);
        }
        visitedNodes.Add(node);
        var entry = node.Data;

        if (entry is UTAutomationPlanForEachEntry || entry is UTAutomationPlanForEachFileEntry || entry is UTMyForEachForBuildEntry)
        {
            return(ProcessForEachNode(node, currentRow, currentColumn));
        }
        else
        if (entry is UTAutomationPlanDecisionEntry)
        {
            return(ProcessDecisionNode(node, currentRow, currentColumn));
        }
        else
        {
            return(ProcessSimpleEntry(node, currentRow, currentColumn));
        }
    }
Ejemplo n.º 17
0
 private void AddToRow(UTNode node, int row)
 {
     AddToNodeList(rows, row, node);
 }
Ejemplo n.º 18
0
 private void AddToColumn(UTNode node, int column)
 {
     AddToNodeList(columns, column, node);
 }
    private int ProcessSimpleEntry(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        UTAutomationPlanEntry entry = node.Data;
        var nextEntry = entry.NextEntry;
        if ( nextEntry != null) {
            return ProcessNode(graph.GetNodeFor(nextEntry), currentRow+1, currentColumn);
        }
        return currentRow;
    }
    private int ProcessNode(UTNode node, int currentRow, int currentColumn)
    {
        if (visitedNodes.Contains(node)) {
            return currentRow;
        }
        visitedNodes.Add(node);
        var entry = node.Data;

        if ( entry is UTAutomationPlanForEachEntry || entry is UTAutomationPlanForEachFileEntry) {
            return ProcessForEachNode(node, currentRow, currentColumn);
        }
        else
        if ( entry is UTAutomationPlanDecisionEntry ) {
            return ProcessDecisionNode(node, currentRow, currentColumn);
        }
        else {
            return ProcessSimpleEntry(node, currentRow, currentColumn);
        }
    }
    private int ProcessForEachNode(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        var entry = node.Data;
        UTAutomationPlanEntry subTree = null;
        if (entry is UTAutomationPlanForEachEntry) {
            subTree = ((UTAutomationPlanForEachEntry)entry).startOfSubtree;
        }
        if (entry is UTAutomationPlanForEachFileEntry) {
            subTree = ((UTAutomationPlanForEachFileEntry)entry).startOfSubtree;
        }
        if (subTree != null) {
            var subTreeNode = graph.GetNodeFor(subTree);
            EnsureEmptyColumn(currentColumn+1);
            currentRow = ProcessNode(subTreeNode, currentRow, currentColumn+1);
        }

        var nextEntry = entry.NextEntry;
        if ( nextEntry != null) {
            return ProcessNode(graph.GetNodeFor(nextEntry), currentRow+1, currentColumn);
        }
        return currentRow;
    }
Ejemplo n.º 22
0
	/// <summary>
	/// Adds the node to the graph.
	/// </summary>
	/// <param name='node'>
	/// The node to add.
	/// </param>/
	public void AddNode(UTNode node) {
		if (nodes == null) {
			nodes = new List<UTNode>();
		}
		nodes.Add(node);
	}
 public NodeEventData(Event evt, UTNodeEditorModel model, UTNode.Connector connector)
 {
     this.evt = evt;
     this.model = model;
     this.connector = connector;
 }
    private static void DrawNode(UTNodeEditorModel editorModel, UTNode node, NodeDrawingPhase phase)
    {
        if (phase == NodeDrawingPhase.DrawNodes) {
            var style = UTEditorResources.GraphNodeStyle;
            if (node.Data is UTAutomationPlanNoteEntry) {
                style = UTEditorResources.GraphCommentStyle;
                if (editorModel.SelectedNodes.Contains (node)) {
                    style = UTEditorResources.GraphCommentSelectedStyle;
                }
            } else {
                if (editorModel.SelectedNodes.Contains (node)) {
                    style = UTEditorResources.GraphNodeSelectedStyle;
                }
                if (node == editorModel.HighlightedNode) {
                    style = UTEditorResources.GraphNodeHighlightStyle;
                }
            }

            GUI.Box (node.Bounds, "", style);
            if (editorModel.IsFirstNode (node)) {
                GUI.DrawTexture (node.IndicatorBounds, UTEditorResources.FirstNodeTexture);
            }
            if (node.Data is UTAutomationPlanPlanEntry) {
                GUI.DrawTexture( node.SecondaryIndicatorBounds, UTEditorResources.ExecutePlanTexture);
            }
        }

        foreach (var connector in node.Connectors) {
            if (phase == NodeDrawingPhase.DrawNodes) {
                GUI.Label (connector.labelPosition, connector.label, connector.labelStyle);
                GUI.Box (connector.connectorPosition, "",
                    connector.isConnected ? UTEditorResources.GraphNodeConnectorStyle :
                    UTEditorResources.GraphNodeConnectorStyleEmpty);
            }
            if (phase == NodeDrawingPhase.DrawLines) {
                var targetNode = editorModel.GetReferencedNode (node, connector.property);
                if (targetNode != null) {
                    UTLineUtils.DrawLine (connector.connectorPosition.center, targetNode.Bounds.center);
                }
            }
        }

        if (phase == NodeDrawingPhase.DrawNodes) {
            GUI.Label (node.Bounds, node.Label, UTEditorResources.GraphNodeHeaderStyle);
            if (!string.IsNullOrEmpty(node.Text)) {
                GUI.Label(node.TextBounds, node.Text, UTEditorResources.GraphNodeTextStyle);
            }
        }
    }
Ejemplo n.º 25
0
 /// <summary>
 /// Determines whether the given node is the first node in the automation plan..
 /// </summary>
 /// <param name='node'>
 /// The node to check.
 /// </param>
 public bool IsFirstNode(UTNode node)
 {
     return(data.firstEntry == node.Data);
 }
Ejemplo n.º 26
0
    /// <summary>
    /// Deletes a node from the graph. Also deletes all references pointing from and to that node.
    /// </summary>
    /// <param name='node'>
    /// The node to delete.
    /// </param>
    public void DeleteNode(UTNode node)
    {
        if (nodes == null || !nodes.Contains(node)) {
            throw new ArgumentException("Trying to delete non-existing node.");
        }
        var sourceRefs = GetSourceReferences(node.Data);
        var targetRefs  = GetTargetReferences(node.Data);

        foreach(var reference in sourceRefs) {
            DeleteReference(reference);
        }
        foreach(var reference in targetRefs) {
            DeleteReference(reference);
        }

        nodes.Remove(node);
    }
 private void AddToColumn(UTNode node, int column)
 {
     AddToNodeList(columns, column, node);
 }
 private void AddToRow(UTNode node, int row)
 {
     AddToNodeList(rows, row, node);
 }
Ejemplo n.º 29
0
    private static void DrawNode(UTNodeEditorModel editorModel, UTNode node, NodeDrawingPhase phase)
    {
        if (phase == NodeDrawingPhase.DrawNodes)
        {
            var style = UTEditorResources.GraphNodeStyle;
            if (node.Data is UTAutomationPlanNoteEntry)
            {
                style = UTEditorResources.GraphCommentStyle;
                if (editorModel.SelectedNodes.Contains(node))
                {
                    style = UTEditorResources.GraphCommentSelectedStyle;
                }
            }
            else
            {
                if (editorModel.SelectedNodes.Contains(node))
                {
                    style = UTEditorResources.GraphNodeSelectedStyle;
                }
                if (node == editorModel.HighlightedNode)
                {
                    style = UTEditorResources.GraphNodeHighlightStyle;
                }
            }

            GUI.Box(node.Bounds, "", style);
            if (editorModel.IsFirstNode(node))
            {
                GUI.DrawTexture(node.IndicatorBounds, UTEditorResources.FirstNodeTexture);
            }
            if (node.Data is UTAutomationPlanPlanEntry)
            {
                GUI.DrawTexture(node.SecondaryIndicatorBounds, UTEditorResources.ExecutePlanTexture);
            }
        }

        foreach (var connector in node.Connectors)
        {
            if (phase == NodeDrawingPhase.DrawNodes)
            {
                GUI.Label(connector.labelPosition, connector.label, connector.labelStyle);
                GUI.Box(connector.connectorPosition, "",
                        connector.isConnected ? UTEditorResources.GraphNodeConnectorStyle :
                        UTEditorResources.GraphNodeConnectorStyleEmpty);
            }
            if (phase == NodeDrawingPhase.DrawLines)
            {
                var targetNode = editorModel.GetReferencedNode(node, connector.property);
                if (targetNode != null)
                {
                    UTLineUtils.DrawLine(connector.connectorPosition.center, targetNode.Bounds.center);
                }
            }
        }


        if (phase == NodeDrawingPhase.DrawNodes)
        {
            GUI.Label(node.Bounds, node.Label, UTEditorResources.GraphNodeHeaderStyle);
            if (!string.IsNullOrEmpty(node.Text))
            {
                GUI.Label(node.TextBounds, node.Text, UTEditorResources.GraphNodeTextStyle);
            }
        }
    }
Ejemplo n.º 30
0
 /// <summary>
 /// Sets the first node  (entry) of the automation plan.
 /// </summary>
 /// <param name='node'>
 /// Node which should be the first node.
 /// </param>
 public void SetFirstNode(UTNode node)
 {
     data.firstEntry = node.Data;
     node.Recalc();
     EditorUtility.SetDirty(data);
 }
    private int ProcessDecisionNode(UTNode node, int currentRow, int currentColumn)
    {
        AddToColumn(node, currentColumn);
        AddToRow(node, currentRow);

        var entry = node.Data;
        var leftEntry = ((UTAutomationPlanDecisionEntry)entry).entryIfTrue;
        var rightEntry = ((UTAutomationPlanDecisionEntry)entry).entryIfFalse;

        var deepestRow = currentRow;

        if (rightEntry != null) {
            var subTreeNode = graph.GetNodeFor(rightEntry);
            EnsureEmptyColumn(currentColumn+1);
            deepestRow = ProcessNode(subTreeNode, currentRow+1, currentColumn+1);
        }

        if ( leftEntry != null) {
            var subTreeNode = graph.GetNodeFor(leftEntry);
            EnsureEmptyColumn(currentColumn);
            deepestRow = Math.Max(deepestRow, ProcessNode(subTreeNode, currentRow+1, currentColumn));
        }
        return deepestRow;
    }