Esempio n. 1
0
	///////////////////////
	// CLASS FUNCTIONS
	///////////////////////
	
	public void PreProcess() {
		
		// Generate samples
		graph = new FlowNode[vertices.Length];
		for( int i = 0; i < graph.Length; i++ ){
			graph[i] = new FlowNode();
			graph[i].water = 0.0f;
			graph[i].worldposition = target.TransformPoint( vertices[i] );
			graph[i].additionalheight = Mathf.Max( 0.0f, 0.0f - graph[i].worldposition.y );
		}
		
		// Add vertex links to graph nodes
		for( int i = 0; i < triangles.Length; i+=3 ){
			int t0= triangles[i];
			int t1= triangles[i+1];
			int t2= triangles[i+2];
			
			graph[t0].vertexlinks_list.Add(t1);
			graph[t0].vertexlinks_list.Add(t2);
			
			graph[t1].vertexlinks_list.Add(t0);
			graph[t1].vertexlinks_list.Add(t2);
			
			graph[t2].vertexlinks_list.Add(t0);
			graph[t2].vertexlinks_list.Add(t1);
			
			graph[t0].linkedTriangles++;
			graph[t1].linkedTriangles++;
			graph[t2].linkedTriangles++;
		}
		
		// Remove doubles in nodes
		for( int i = 0; i < vertices.Length; i++ ){
			ArrayList links = new ArrayList();
			ArrayList nodelinks = graph[i].vertexlinks_list;
			for( int j = 0; j < nodelinks.Count; j++ ) {
				if (!HasLink(links, (int)nodelinks[j])) links.Add(nodelinks[j]);
			}
			
			// Transfer node links from list to array
			graph[i].vertexlinks = new int[links.Count];
			for( int j = 0; j < graph[i].vertexlinks.Length; j++ ) {
				graph[i].vertexlinks[j] = (int)links[j];
			}
			
			// Clear node list
			graph[i].vertexlinks_list.Clear();
		}
		
		// Find edges
		for( int i = 0; i < graph.Length; i++ ) {
			if( graph[i].vertexlinks.Length > graph[i].linkedTriangles ) graph[i].isEdge = true;
		}
	}
Esempio n. 2
0
	public FlowNode Clone(){
		FlowNode clone = new FlowNode();
		clone.vertexlinks = this.vertexlinks;
		clone.water = this.water;
		clone.flowdirection = this.flowdirection;
		clone.worldposition = this.worldposition;
		clone.additionalheight = this.additionalheight;
		clone.isEdge = this.isEdge;
		clone.vertexlinks_list = this.vertexlinks_list;
		clone.linkedTriangles = this.linkedTriangles;
		
		return clone;
	}
Esempio n. 3
0
        public void ProcessEvent(FlowNode.EFlowEvent _event, UInt16 id)
        {
            Logging./*CryConsole.*/LogAlways("Process Event; Mono style.");

            switch (_event)
            {
                case EFlowEvent.Activate:
                    {/*
                        if (IsPortActive(nodeInfo, (int)EInputPorts.EIP_Start))
                        {
                            ActivateOutput(nodeInfo, (int)EOutputPorts.EOP_Started);
                        }*/
                    }
                    break;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Sets the source flow node of this sequence flow.
 /// </summary>
 /// <param name="source">  the source of this sequence flow </param>
 /// <returns> the builder object </returns>
 public virtual B from(FlowNode source)
 {
     element.Source = source;
     source.Outgoing.Add(element);
     return(myself);
 }
 protected override ISet <VariableAlias> Transfer(FlowNode node, ISet <VariableAlias> data)
 {
     return(_TransferRegular(node, data, false));
 }
        public static List <VariableInfo> DrawVariables(Rect position, IEnumerable <VariableInfo> variables, Dictionary <string, VariableInfo> ovrrideInputs, List <VariableInfo> inputs)
        {
            if (inputs != null)
            {
                for (int i = 0; i < inputs.Count; i++)
                {
                    var input    = inputs[i];
                    var variable = variables.Where(o => o.Name == input.Name).FirstOrDefault();
                    if (variable == null || variable.Type != input.Type)
                    {
                        inputs.RemoveAt(i);
                        i--;
                        GUI.changed = true;
                    }
                }
            }

            Rect rowRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

            GUIStyle labelStyle = new GUIStyle("label");
            //    labelStyle.fontStyle = FontStyle.Bold;

            int inputCount = variables.Where(o => o.IsIn).Count();
            // if (inputCount > 0)
            {
                rowRect.x     = position.x;
                rowRect.width = position.width;
                rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Input"), labelStyle);
                GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Input"), labelStyle);
                rowRect.y += rowRect.height;
                using (new GUIDepthScope())
                {
                    variables.Where(o => o.IsIn).OrderBy(o => o.Name).Where((variable, index) =>
                    {
                        VariableInfo inVar = null;

                        if (inputs != null)
                        {
                            inVar = inputs.Where(o => o.Name == variable.Name).FirstOrDefault();
                        }

                        if (inVar != null && inVar.Type != variable.Type)
                        {
                            inputs.Remove(inVar);
                            inVar       = null;
                            GUI.changed = true;
                        }


                        rowRect.x     = position.x;
                        rowRect.width = position.width;
                        rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                        if (inVar == null)
                        {
                            GUI.color = Color.gray;
                        }
                        else
                        {
                            GUI.color = Color.white;
                        }
                        GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name));

                        GUI.color = Color.white;

                        var tmpRect = GUIExtensions.Width(ref rowRect, rowRect.width - variableCheckWidth);
                        if (inVar != null)
                        {
                            object newValue2;

                            newValue2 = SerializableValuePropertyDrawer.ValueField(tmpRect, inVar.DefaultValue, inVar.Type);
                            if (!object.Equals(newValue2, inVar.DefaultValue))
                            {
                                inVar.DefaultValue = newValue2;
                                GUI.changed        = true;
                            }
                        }
                        else
                        {
                            GUI.enabled = false;

                            object value = variable.DefaultValue;
                            if (ovrrideInputs.ContainsKey(variable.Name))
                            {
                                value = ovrrideInputs[variable.Name].DefaultValue;
                            }
                            SerializableValuePropertyDrawer.ValueField(tmpRect, value, variable.Type);
                            GUI.enabled = true;
                        }


                        rowRect.xMin += 5f;

                        if (EditorGUI.Toggle(rowRect, inVar != null))
                        {
                            if (inVar == null)
                            {
                                inVar = new VariableInfo(variable.Name, variable.Type, variable.DefaultValue);
                                if (inputs == null)
                                {
                                    inputs = new List <VariableInfo>();
                                }
                                inputs.Add(inVar);
                                GUI.changed = true;
                            }
                        }
                        else
                        {
                            if (inVar != null)
                            {
                                inputs.Remove(inVar);
                                GUI.changed = true;
                            }
                        }

                        rowRect.y = rowRect.yMax;
                        return(false);
                    }).Count();
                }
            }

            int outputCount = variables.Where(o => o.IsOut).Count();

            //     if (outputCount > 0)
            {
                rowRect.x     = position.x;
                rowRect.width = position.width;
                rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;
                //rowRect = EditorGUI.PrefixLabel(rowRect, new GUIContent("Output"), labelStyle);

                GUI.Label(GUIExtensions.Width(ref rowRect, EditorGUIUtility.labelWidth), new GUIContent("Output"), labelStyle);
                rowRect.y += rowRect.height;

                using (new GUIDepthScope())
                {
                    variables.Where(o => o.IsOut).OrderBy(o => o.Name).Where((variable, index) =>
                    {
                        rowRect.x     = position.x;
                        rowRect.width = position.width;
                        rowRect.xMin += GUI.depth * GUIDepthScope.Pixels;

                        GUI.Label(GUIExtensions.Width(ref rowRect, variableLabelWidth), new GUIContent(variable.Name));
                        GUI.Label(rowRect, new GUIContent(FlowNode.GetDisplayValueTypeName(variable.Type), variable.Type.FullName));
                        rowRect.y += rowRect.height;
                        return(false);
                    }).Count();
                }
            }
            return(inputs);
        }
 virtual protected void OnRegisterExtraPorts(FlowNode node)
 {
 }
Esempio n. 8
0
 public void Set(FlowNode next)
 {
     nodes.Add(next);
     first = next;
     second = null;
 }
        // The logic is similar to UpdateCloneReferences.
        // the difference is in this function, we need to set reference by Property.
        void UpdateCloneReferenceByModelItem(FlowNode currentFlowElement,
                                             Dictionary <FlowNode, ModelItem> modelItems, Dictionary <FlowNode, FlowNode> clonedFlowElements)
        {
            if (typeof(FlowStep).IsAssignableFrom(currentFlowElement.GetType()))
            {
                FlowStep  currentFlowStep = (FlowStep)currentFlowElement;
                FlowStep  clonedFlowStep  = (FlowStep)clonedFlowElements[currentFlowElement];
                ModelItem modelItem       = modelItems[clonedFlowStep];
                FlowNode  nextFlowElement = currentFlowStep.Next;
                if (nextFlowElement != null && clonedFlowElements.ContainsKey(nextFlowElement))
                {
                    modelItem.Properties["Next"].SetValue(clonedFlowElements[nextFlowElement]);
                }
                else
                {
                    modelItem.Properties["Next"].SetValue(null);
                }
            }
            else if (typeof(FlowDecision).IsAssignableFrom(currentFlowElement.GetType()))
            {
                if (!modelItems.ContainsKey(currentFlowElement))
                {
                    Fx.Assert("Should not happen.");
                }
                FlowDecision currentFlowDecision = (FlowDecision)currentFlowElement;
                FlowDecision clonedFlowDecision  = (FlowDecision)clonedFlowElements[currentFlowElement];
                Fx.Assert(currentFlowDecision == clonedFlowDecision, "should not happen");
                ModelItem modelItem = modelItems[currentFlowElement];
                Fx.Assert(modelItem != null, "should not happen");
                FlowNode trueElement  = currentFlowDecision.True;
                FlowNode falseElement = currentFlowDecision.False;

                if (trueElement != null && clonedFlowElements.ContainsKey(trueElement))
                {
                    modelItem.Properties["True"].SetValue(clonedFlowElements[trueElement]);
                }
                else
                {
                    modelItem.Properties["True"].SetValue(null);
                }

                if (falseElement != null && clonedFlowElements.ContainsKey(falseElement))
                {
                    modelItem.Properties["False"].SetValue(clonedFlowElements[falseElement]);
                }
                else
                {
                    modelItem.Properties["False"].SetValue(null);
                }
            }
            else if (GenericFlowSwitchHelper.IsGenericFlowSwitch(currentFlowElement.GetType()))
            {
                GenericFlowSwitchHelper.ReferenceCopy(currentFlowElement.GetType().GetGenericArguments()[0],
                                                      currentFlowElement,
                                                      modelItems,
                                                      clonedFlowElements);
            }
            else
            {
                Debug.Fail("Unknown FlowNode");
            }
        }
Esempio n. 10
0
 public void OnFlowNodeSignal(FlowNode node, PropertyInfo signal)
 {
     _nodesToRun.Add(new KeyValuePair <FlowNode, PropertyInfo>(node, signal));
 }
Esempio n. 11
0
    public override Null Visit(WhileStmt node)
    {
        // Create an flow node for the back edge
        FlowNode end = next.Get();
        FlowNode loop = new FlowNode();

        // Calculate flow for the body block
        next.Set(loop);
        node.block.Accept(this);
        FlowNode body = next.Get();

        // Calculate flow for the test expression
        next.Set(body, end);
        node.test.Accept(this);

        // Link the back edge to before the test expression
        loop.next.Add(next.Get());

        return null;
    }
Esempio n. 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="activityBehavior"></param>
        /// <param name="flowNode"></param>
        protected internal virtual void ExecuteActivityBehavior(IActivityBehavior activityBehavior, FlowNode flowNode)
        {
            log.LogDebug($"Executing activityBehavior {activityBehavior.GetType()} on activity '{flowNode.Id}' with execution {execution.Id}");

            ProcessEngineConfigurationImpl processEngineConfiguration = Context.ProcessEngineConfiguration;

            if (processEngineConfiguration != null && processEngineConfiguration.EventDispatcher.Enabled)
            {
                processEngineConfiguration.EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateActivityEvent(ActivitiEventType.ACTIVITY_STARTED, flowNode.Id, flowNode.Name, execution.Id, execution.ProcessInstanceId, execution.ProcessDefinitionId, flowNode));
            }

            try
            {
                activityBehavior.Execute(execution);
            }
            catch (Exception e)
            {
                throw new Exception($"{e.Message}", e);
            }
        }
 public abstract void RegisterPorts(FlowNode node, ReflectedFieldNodeWrapper.AccessMode accessMode);
Esempio n. 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="flowNode"></param>
        protected internal virtual void ExecuteAsynchronous(FlowNode flowNode)
        {
            IJobEntity job = commandContext.JobManager.CreateAsyncJob(execution, flowNode.Exclusive);

            commandContext.JobManager.ScheduleAsyncJob(job);
        }
 /// <summary>
 /// Creates an expression equality which makes use of flow information and aliases.
 /// </summary>
 /// <param name="aNode">The control flow graph node where the first expression is located.</param>
 /// <param name="bNode">The control flow graph node where the second expression is located.</param>
 /// <param name="aliases">The aliases collected within the control flow graph.</param>
 public ExpressionEquality(FlowNode aNode, FlowNode bNode, AliasAnalysis aliases)
 {
     _aNode   = aNode;
     _bNode   = bNode;
     _aliases = aliases;
 }
Esempio n. 16
0
        void NodeProcessEvent(FlowNode.EFlowEvent flowEvent, UInt16 nodeId)
        {
            Trace.TraceInformation("Process event on node of type {0}", nodeId);

            object[] args = new object[2];
            args[0] = flowEvent;
            args[1] = nodeId;

            InvokeNodeFunc(nodeId, "ProcessEvent", args);
        }
Esempio n. 17
0
 /// <summary>
 /// Gets the alias information of a variable at the exit of the given node.
 /// </summary>
 /// <param name="variableName">The name of the variable to get the alias information of.</param>
 /// <param name="node">The node where to get the alias information of.</param>
 /// <returns>The alias information.</returns>
 public IEnumerable <VariableAlias> GetAliasesOfVariableAfter(string variableName, FlowNode node)
 {
     return(_GetAliases(Exit[node], variableName));
 }
Esempio n. 18
0
 public void OnFlowNodeSignal(FlowNode node, PropertyInfo signal)
 {
     _addIn.OnFlowNodeSignal(node, signal);
 }
Esempio n. 19
0
 public Result(FlowNode node, Knowledge knowledge)
 {
     this.node = node;
     this.knowledge = knowledge;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="flowNode"></param>
        protected internal virtual void LeaveFlowNode(FlowNode flowNode)
        {
            log.LogDebug($"Leaving flow node {flowNode.GetType()} with id '{flowNode.Id}' by following it's {flowNode.OutgoingFlows.Count} outgoing sequenceflow");

            // Get default sequence flow (if set)
            string defaultSequenceFlowId = null;

            if (flowNode is Activity)
            {
                defaultSequenceFlowId = ((Activity)flowNode).DefaultFlow;
            }
            else if (flowNode is Gateway)
            {
                defaultSequenceFlowId = ((Gateway)flowNode).DefaultFlow;
            }

            // Determine which sequence flows can be used for leaving
            IList <SequenceFlow> outgoingSequenceFlows = new List <SequenceFlow>();

            foreach (SequenceFlow sequenceFlow in flowNode.OutgoingFlows)
            {
                string skipExpressionString = sequenceFlow.SkipExpression;
                if (!SkipExpressionUtil.IsSkipExpressionEnabled(execution, skipExpressionString))
                {
                    if (!evaluateConditions || (evaluateConditions && ConditionUtil.HasTrueCondition(sequenceFlow, execution) && (defaultSequenceFlowId is null || !defaultSequenceFlowId.Equals(sequenceFlow.Id))))
                    {
                        outgoingSequenceFlows.Add(sequenceFlow);
                    }
                }
                else if (flowNode.OutgoingFlows.Count == 1 || SkipExpressionUtil.ShouldSkipFlowElement(commandContext, execution, skipExpressionString))
                {
                    // The 'skip' for a sequence flow means that we skip the condition, not the sequence flow.
                    outgoingSequenceFlows.Add(sequenceFlow);
                }
            }

            // Check if there is a default sequence flow
            if (outgoingSequenceFlows.Count == 0 && evaluateConditions)
            { // The elements that set this to false also have no support for default sequence flow
                if (!(defaultSequenceFlowId is null))
                {
                    foreach (SequenceFlow sequenceFlow in flowNode.OutgoingFlows)
                    {
                        if (defaultSequenceFlowId.Equals(sequenceFlow.Id))
                        {
                            outgoingSequenceFlows.Add(sequenceFlow);
                            break;
                        }
                    }
                }
            }

            // No outgoing found. Ending the execution
            if (outgoingSequenceFlows.Count == 0)
            {
                if (flowNode.OutgoingFlows == null || flowNode.OutgoingFlows.Count == 0)
                {
                    log.LogDebug($"No outgoing sequence flow found for flow node '{flowNode.Id}'.");
                    Context.Agenda.PlanEndExecutionOperation(execution);
                }
                else
                {
                    throw new ActivitiException("No outgoing sequence flow of element '" + flowNode.Id + "' could be selected for continuing the process");
                }
            }
            else
            {
                // Leave, and reuse the incoming sequence flow, make executions for all the others (if applicable)

                IExecutionEntityManager  executionEntityManager = commandContext.ExecutionEntityManager;
                IList <IExecutionEntity> outgoingExecutions     = new List <IExecutionEntity>(flowNode.OutgoingFlows.Count);

                SequenceFlow sequenceFlow = outgoingSequenceFlows[0];

                // Reuse existing one
                execution.CurrentFlowElement = sequenceFlow;
                execution.IsActive           = true;
                outgoingExecutions.Add(execution);

                // Executions for all the other one
                if (outgoingSequenceFlows.Count > 1)
                {
                    for (int i = 1; i < outgoingSequenceFlows.Count; i++)
                    {
                        IExecutionEntity parent = !(execution.ParentId is null) ? execution.Parent : execution;
                        IExecutionEntity outgoingExecutionEntity = commandContext.ExecutionEntityManager.CreateChildExecution(parent);

                        SequenceFlow outgoingSequenceFlow = outgoingSequenceFlows[i];
                        outgoingExecutionEntity.CurrentFlowElement = outgoingSequenceFlow;

                        executionEntityManager.Insert(outgoingExecutionEntity);
                        outgoingExecutions.Add(outgoingExecutionEntity);
                    }
                }

                // Leave (only done when all executions have been made, since some queries depend on this)
                foreach (IExecutionEntity outgoingExecution in outgoingExecutions)
                {
                    Context.Agenda.PlanContinueProcessOperation(outgoingExecution);
                }
            }
        }
Esempio n. 21
0
 public void Clear()
 {
     first = second = null;
 }
Esempio n. 22
0
 /// <summary>
 /// Creates a new available expression with the given binary expression.
 /// </summary>
 /// <param name="expression">The binary expression represented by this instance.</param>
 public AvailableExpression(FlowNode node, BinaryExpression expression) : this(node, (Expression)expression)
 {
 }
Esempio n. 23
0
 public AssignNode(Symbol symbol, IsNull isNull, FlowNode next)
     : base(next)
 {
     this.symbol = symbol;
     this.isNull = isNull;
 }
Esempio n. 24
0
 /// <summary>
 /// Creates a new available expression with the given invocation expression.
 /// </summary>
 /// <param name="expression">The invocation expression represented by this instance.</param>
 public AvailableExpression(FlowNode node, InvocationExpression expression) : this(node, (Expression)expression)
 {
 }
Esempio n. 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="flowNode"></param>
 /// <returns></returns>
 protected internal virtual bool IsExtraScopeNeeded(FlowNode flowNode)
 {
     return(flowNode.SubProcess is object);
 }
Esempio n. 26
0
        public Node Create(Program parentProgram)
        {
            FlowNode node = (Activator.CreateInstance(FlowNodeType) as FlowNode).SetSource(Identifier, 0).SetPosition(new VectorPosition(0, 0)).SetProgram(parentProgram) as FlowNode;

            return(node);
        }
        ///-------------------------------------------------------------------------

        abstract protected void OnRegisterPorts(FlowNode node);
 sealed protected override void OnRegisterDerivedPorts(FlowNode node)
 {
     node.AddFlowInput("In", (f) => { Begin(Invoke(), f); });
 }
Esempio n. 29
0
        // TODO: Consider splitting into multiple methods to increase readability
        public GeneratedGraphs Translate()
        {
            this.builder      = new FlowGraphBuilder(this.flowGraphId);
            this.ingoingEdges = this.ComputeIngoingEdges(this.BuildGraph);

            this.expressionTranslator    = new ExpressionTranslator(this);
            this.buildToFlowVariablesMap = new OrdinalOverlay <BuildVariableId, BuildVariable, FlowVariable>();
            this.buildToFlowNodesMap     = new OrdinalOverlay <BuildNodeId, BuildNode, FlowNodeMappedInfo>();
            var nodeQueue    = new Queue <BuildNode>();
            var edgeQueue    = new Queue <EdgeInfo>();
            var visitedNodes = new OrdinalOverlay <BuildNodeId, BuildNode, bool>();

            var buildParameters = this.BuildGraph.Variables
                                  .Where(v => v.Origin == VariableOrigin.Parameter || v.Origin == VariableOrigin.This);
            var flowParameters = new List <FlowVariable>();

            foreach (var parameter in buildParameters)
            {
                flowParameters.Add(this.TranslateVariable(parameter));
            }

            var flowEnterNode = this.builder.AddEnterNode(flowParameters);

            this.buildToFlowNodesMap[this.BuildGraph.EnterNode] = flowEnterNode;
            visitedNodes[this.BuildGraph.EnterNode]             = true;

            Contract.Assert(this.BuildGraph.EnterNode.OutgoingEdges.Count == 1);
            var firstNonEnterNode = this.BuildGraph.EnterNode.OutgoingEdges.Single().To;

            nodeQueue.Enqueue(firstNonEnterNode);
            visitedNodes[firstNonEnterNode] = true;

            while (nodeQueue.Count > 0)
            {
                var buildNode = nodeQueue.Dequeue();
                Contract.Assert(visitedNodes[buildNode]);
                Contract.Assert(this.buildToFlowNodesMap[buildNode].FlowNode == null);

                BuildNode firstBuildNode, lastBuildNode;

                var flowNode = this.TryTranslateBorderNode(buildNode);
                if (flowNode != null)
                {
                    firstBuildNode = buildNode;
                    lastBuildNode  = buildNode;

                    this.buildToFlowNodesMap[buildNode] = flowNode;
                }
                else
                {
                    this.ProcessInnerNodesSequence(buildNode, out firstBuildNode, out lastBuildNode, out var operations);
                    flowNode = this.builder.AddInnerNode(operations, lastBuildNode.Flags);      // TODO: Handle flag merging when there are flag types that need it
                    this.MapAssignmentsToFlowNode(firstBuildNode, lastBuildNode, flowNode);
                }

                // TODO: Try to get rid of the empty nodes (empty blocks etc.)
                Contract.Assert(flowNode != null);

                foreach (var edge in lastBuildNode.OutgoingEdges)
                {
                    if (!visitedNodes[edge.To])
                    {
                        nodeQueue.Enqueue(edge.To);
                        visitedNodes[edge.To] = true;
                    }
                }

                foreach (var edgeInfo in this.ingoingEdges[firstBuildNode])
                {
                    var flowFromNode = this.buildToFlowNodesMap[edgeInfo.From].FlowNode;
                    if (flowFromNode == null)
                    {
                        edgeQueue.Enqueue(edgeInfo);
                    }
                    else
                    {
                        this.TranslateEdge(edgeInfo.Edge, edgeInfo.From, flowFromNode, flowNode);
                    }
                }
            }

            while (edgeQueue.Count > 0)
            {
                var      edgeInfo = edgeQueue.Dequeue();
                FlowNode flowFrom = this.buildToFlowNodesMap[edgeInfo.From];
                FlowNode flowTo   = this.buildToFlowNodesMap[edgeInfo.Edge.To];

                Contract.Assert(flowFrom != null);
                Contract.Assert(flowTo != null);
                this.TranslateEdge(edgeInfo.Edge, edgeInfo.From, flowFrom, flowTo);
            }

            this.FlowGraph = this.builder.FreezeAndReleaseGraph();

            this.FinishDisplayGraph();

            return(new GeneratedGraphs(this.FlowGraph, this.DisplayGraph));
        }
Esempio n. 30
0
 public void Initialize(FlowNode node)
 {
     this.m_FlowNode = node;
 }
Esempio n. 31
0
 /// <summary>
 /// Sets the target flow node of this sequence flow.
 /// </summary>
 /// <param name="target">  the target of this sequence flow </param>
 /// <returns> the builder object </returns>
 public virtual B to(FlowNode target)
 {
     element.Target = target;
     target.Incoming.Add(element);
     return(myself);
 }
Esempio n. 32
0
 /// <summary>
 /// 创建人工节点
 /// </summary>
 /// <param name="setting"></param>
 /// <param name="displayName"></param>
 /// <param name="actioner"></param>
 /// <param name="humanResultTo"></param>
 /// <param name="nexts"></param>
 /// <returns></returns>
 public static FlowStep CreateHuman(ActivitySetting setting
     , string displayName
     , Expression<Func<ActivityContext, string[]>> actioner
     , Variable<string> humanResultTo
     , IDictionary<string, FlowNode> nexts
     , FlowNode defaultFlowNode)
 {
     return null;
     //return CreateHuman(setting
     //    , displayName
     //    , new Taobao.Activities.Expressions.LambdaValue<string[]>(actioner)
     //    , humanResultTo
     //    , nexts
     //    , defaultFlowNode);
 }
Esempio n. 33
0
 /// <summary>
 /// Gets the alias information of a variable at the entry of the given node.
 /// </summary>
 /// <param name="variableName">The name of the variable to get the alias information of.</param>
 /// <param name="node">The node where to get the alias information of.</param>
 /// <returns>The alias information.</returns>
 public IEnumerable <VariableAlias> GetAliasesOfVariableBefore(string variableName, FlowNode node)
 {
     return(_GetAliases(Entry[node], variableName));
 }
Esempio n. 34
0
        /// <summary>
        /// 创建人工节点
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="displayName"></param>
        /// <param name="actioner"></param>
        /// <param name="humanResultTo"></param>
        /// <param name="nexts"></param>
        /// <param name="defaultFlowNode"></param>
        /// <returns></returns>
        public static FlowStep CreateHuman(ActivitySetting setting
            , string displayName
            , IActionersHelper actioner//Activity<string[]> actioner
            , Variable<string> humanResultTo
            , IDictionary<string, FlowNode> nexts
            , FlowNode defaultFlowNode)
        {
            var human = CreateHuman(setting, displayName, actioner, humanResultTo);
            var step = new FlowStep();
            step.Action = human;

            if (nexts == null && defaultFlowNode == null) return step;

            //设置finish cases
            //HACK:在进入switch之前就已经计算出任务结果
            var flowSwitch = new FlowSwitch<string>(o => humanResultTo.Get(o));
            if (defaultFlowNode != null)
                flowSwitch.Default = defaultFlowNode;
            if (nexts != null)
                nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value));
            step.Next = flowSwitch;
            return step;
        }
Esempio n. 35
0
    private void Visit(FlowNode node, Knowledge knowledge)
    {
        // Memoize the results so we don't do more work than necessary. This is
        // also required to handle loops without hanging.
        Result result = new Result(node, knowledge);
        if (results.Contains(result)) {
            return;
        }
        results.Add(result);

        // Add to the knowledge flowing through this path, but stop if flow stops
        knowledge = knowledge.Clone();
        if (!node.Update(knowledge)) {
            return;
        }

        // Merge that knowledge into the total knowledge for this node
        if (node.knowledge != null) {
            node.knowledge.UnionWith(knowledge);
        } else {
            node.knowledge = knowledge.Clone();
        }

        // Propagate flow to next links
        foreach (FlowNode next in node.next) {
            Visit(next, knowledge);
        }
    }
Esempio n. 36
0
 /// <summary>
 /// 创建并行节点
 /// </summary>
 /// <param name="setting"></param>
 /// <param name="displayName"></param>
 /// <param name="completionScript"></param>
 /// <param name="next"></param>
 /// <param name="branchs"></param>
 /// <returns></returns>
 public static FlowStep CreateParallel(ActivitySetting setting
     , string displayName
     , string completionScript
     , FlowNode next
     , params Custom[] branchs)
 {
     return new FlowStep() { Action = CreateCustomParallel(setting, displayName, completionScript, branchs), Next = next };
 }
Esempio n. 37
0
 public AliasNode(Symbol leftSymbol, Symbol rightSymbol, FlowNode next)
     : base(next)
 {
     this.leftSymbol = leftSymbol;
     this.rightSymbol = rightSymbol;
 }
Esempio n. 38
0
        /// <summary>
        /// 创建SubProcess子流程节点
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="displayName"></param>
        /// <param name="serverScript">节点执行内容脚本</param>
        /// <param name="finishRule">节点完成规则</param>
        /// <param name="serverScriptResultTo">执行内容的结果输出到指定变量</param>
        /// <param name="serverResultTo">节点执行结果输出到变量</param>
        /// <param name="nexts"></param>
        /// <param name="defaultFlowNode"></param>
        /// <returns></returns>
        public static FlowStep CreateSubProcess(ActivitySetting setting
            , string displayName
            , IDictionary<string, string> finishRule
            , Variable<string> resultTo
            , IDictionary<string, FlowNode> nexts
            , FlowNode defaultFlowNode)
        {
            var server = CreateSubProcess(setting, displayName, finishRule, resultTo);
            var step = new FlowStep();
            step.Action = server;

            if (nexts == null && defaultFlowNode == null) return step;

            //设置finish cases
            var flowSwitch = new FlowSwitch<string>(o => resultTo.Get(o));
            if (defaultFlowNode != null)
                flowSwitch.Default = defaultFlowNode;
            if (nexts != null)
                nexts.ToList().ForEach(o => flowSwitch.Cases.Add(o.Key, o.Value));
            step.Next = flowSwitch;
            return step;
        }
Esempio n. 39
0
 public override Null Visit(FuncDef node)
 {
     // Make a new end node to start off the flow
     FlowNode root = new FlowNode();
     nodeMap.Add(node, root);
     next.Set(root);
     node.block.Accept(this);
     for (int i = node.argDefs.Count - 1; i >= 0; i--) {
         node.argDefs[i].Accept(this);
     }
     roots.Add(next.Get());
     return null;
 }
 private bool _IsExpectedTransfer(FlowNode node, string sourceMethod, string targetMethod, bool transferTo, bool transferBack)
 {
     return(node is FlowTransfer transfer &&
            transfer.TransfersTo == transferTo && transfer.TransfersBack == transferBack &&
            transfer.SourceMethod.Equals(sourceMethod) && transfer.TargetMethod.Equals(targetMethod));
 }
Esempio n. 41
0
 public FlowNode Get()
 {
     // Merge multiple next flow nodes to make sure there is only one next flow node
     if (second != null) {
         first = new FlowNode(first, second);
         second = null;
         nodes.Add(first);
     }
     return first;
 }
 private bool _IsExpectedBoundary(FlowNode node, string methodName, FlowKind kind)
 {
     return(node is FlowBoundary boundary &&
            boundary.MethodName.Equals(methodName) && boundary.Kind == kind);
 }
Esempio n. 43
0
 public void Set(FlowNode trueNode, FlowNode falseNode)
 {
     nodes.Add(trueNode);
     nodes.Add(falseNode);
     first = trueNode;
     second = falseNode;
 }
                private static bool BFS(Dictionary<uint, Dictionary<uint, FlowEdge>> neighbours, uint source, uint sink, out FlowNode path)
                {
                    path = null;
                    Queue<FlowNode> open = new Queue<FlowNode>();
                    open.Enqueue(new FlowNode(source, null, int.MaxValue));

                    HashSet<uint> done = new HashSet<uint>();
                    done.Add(source);

                    FlowNode node;
                    while (open.Count > 0)
                    {
                        node = open.Dequeue();
                        foreach (uint i in neighbours[node.Node].Keys)
                        {
                            if (done.Contains(i) || neighbours[node.Node][i].Residual == 0)
                                continue;
                            if (i == sink)
                            {
                                path = new FlowNode(i, node, Math.Min(neighbours[node.Node][i].Residual, node.Capacity));
                                return true;
                            }
                            open.Enqueue(new FlowNode(i, node, Math.Min(neighbours[node.Node][i].Residual, node.Capacity)));
                            done.Add(i);
                        }
                    }

                    return false;
                }
Esempio n. 45
0
 public BlockerNode(FlowNode next)
     : base(next)
 {
 }
Esempio n. 46
0
	public void FlowUpdate (){

		FlowNode[] buffer = new FlowNode[graph.Length];
		
		
		for( int i = 0; i < graph.Length; i++ ) {
			buffer[i] = ((FlowNode)graph[i]).Clone();
		}
		
		int k= 0;
		while( k < graphnodespercycle ){
			k++;
			graph_cycle++;
			if( graph_cycle == graph.Length ) graph_cycle = 0;
			
			int i=0;
				i = graph_cycle;
			
			FlowNode node= graph[i] as FlowNode;
			float node_h = node.worldposition.y + node.additionalheight + node.water;
			
			ArrayList nlink_flow_node = new ArrayList();
			ArrayList nlink_flow_water= new ArrayList();
			float total_waterflow= 0.0f;
			float fluid_flow_magnitude= 0.0f;
			
			// run loops if this node contains water
			if( node.water > 0.0f ) {
				// Get nodes that water flows to plus height differences
				for( int j = 0; j < node.vertexlinks.Length; j++ ) {
					
					FlowNode n = buffer[node.vertexlinks[j]] as FlowNode;
					
					float node_link_h = n.worldposition.y + n.additionalheight + n.water;
					if( node_h > node_link_h ) {
						float node_diff = node_h - node_link_h;
						
						nlink_flow_node.Add(n);
						nlink_flow_water.Add(node_diff);
						
						total_waterflow += node_diff;
						
						node_diff = Mathf.Min(node_diff, node.water);
						if( node_diff > fluid_flow_magnitude ) fluid_flow_magnitude = node_diff;
					}
				}
				
				// Subtract water from center node
				buffer[i].water -= fluid_flow_magnitude * fluidViscosity;
				
				// Flow off edge
				if( node.isEdge && node.water > 0 ) buffer[i].water = 0;
				
				// Calculate water distribution between node links
				if( total_waterflow > 0.0f ){
					for( int j = 0; j < nlink_flow_node.Count; j++ ) {
						FlowNode n = nlink_flow_node[j] as FlowNode;
						float nw = (float)nlink_flow_water[j];
						n.water += (nw / total_waterflow) * fluid_flow_magnitude * fluidViscosity;
					}
				}
			}
		}
		
		for (int i = 0; i < graph.Length; i++) {
			FlowNode node = (FlowNode)buffer[i];
			
			Vector3 flowdirection = Vector3.zero;
			
			for (int j = 0; j < node.vertexlinks.Length; j++) {
				FlowNode linkedNode = (FlowNode)buffer[node.vertexlinks[j]];
				
				float heightDifference = ((node.water + node.additionalheight + node.worldposition.y) - (linkedNode.water + linkedNode.additionalheight + linkedNode.worldposition.y));
				
				if (heightDifference > 0) {
					flowdirection += Vector3.Normalize(new Vector3(linkedNode.worldposition.x - node.worldposition.x, 0, linkedNode.worldposition.z - node.worldposition.z)) * heightDifference;
				}
			}
			
			node.flowdirection = flowdirection;
		}
		
		graph = buffer;
	}
Esempio n. 47
0
        private IFlowSwitchLink DeleteLinkImpl(Connector link, bool isMoveOrAutoSplit         = false,
                                               HashSet <ModelItem> referenceUpdatedModelItems = null)
        {
            IFlowSwitchLink caseKey       = null;
            ModelItem       linkModelItem = FlowchartDesigner.GetLinkModelItem(link);

            if (referenceUpdatedModelItems != null &&
                referenceUpdatedModelItems.Contains(linkModelItem))
            {
                return(caseKey);
            }
            ConnectionPoint srcConnectionPoint  = FreeFormPanel.GetSourceConnectionPoint(link);
            ConnectionPoint destConnectionPoint = FreeFormPanel.GetDestinationConnectionPoint(link);

            if (typeof(FlowStep).IsAssignableFrom(linkModelItem.ItemType))
            {
                linkModelItem.Properties["Next"].SetValue(null);
            }
            else if (typeof(FlowDecision).IsAssignableFrom(linkModelItem.ItemType))
            {
                //Determine if it is True or False branch.
                if (srcConnectionPoint.Equals(FlowchartDesigner.GetTrueConnectionPoint(srcConnectionPoint.ParentDesigner)))
                {
                    //True branch
                    linkModelItem.Properties["True"].SetValue(null);
                }
                else
                {
                    linkModelItem.Properties["False"].SetValue(null);
                }
            }
            else if (typeof(IFlowSwitchLink).IsAssignableFrom(linkModelItem.ItemType))
            {
                IFlowSwitchLink flowSwitchLink = (IFlowSwitchLink)linkModelItem.GetCurrentValue();
                caseKey = flowSwitchLink;
                //Transitioning from the fakeModelItem world to the real ModelItem world.
                FlowNode  fs = flowSwitchLink.ParentFlowSwitch;
                ModelItem realFlowSwitchMI = (this.ModelItem as IModelTreeItem).ModelTreeManager.WrapAsModelItem(fs);
                if (referenceUpdatedModelItems != null &&
                    referenceUpdatedModelItems.Contains(realFlowSwitchMI))
                {
                    return(caseKey);
                }

                if (flowSwitchLink.IsDefaultCase)
                {
                    realFlowSwitchMI.Properties["Default"].SetValue(null);

                    if (!isMoveOrAutoSplit)
                    {
                        realFlowSwitchMI.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue);
                    }
                }
                else
                {
                    GenericFlowSwitchHelper.RemoveCase(realFlowSwitchMI.Properties["Cases"], flowSwitchLink.CaseObject);
                }
            }
            else // StartNode
            {
                this.ModelItem.Properties["StartNode"].SetValue(null);
            }

            this.StoreConnectorViewState(linkModelItem, null, srcConnectionPoint, true);
            return(caseKey);
        }
Esempio n. 48
0
        sealed protected override void OnRegisterPorts(FlowNode node)
        {
            var o = node.AddFlowOutput(" ");

            node.AddFlowInput(" ", (Flow f) => { Invoke(); o.Call(f); });
        }
 public FlowNode(uint node, FlowNode parent, uint capacity)
 {
     this.Node = node;
     this.Parent = parent;
     this.Capacity = capacity;
 }
Esempio n. 50
0
 public abstract void RegisterPorts(FlowNode node);
Esempio n. 51
0
 //since we want to check the condition per frame, this is implementing this way instead of a parameter
 protected override void OnRegisterExtraPorts(FlowNode node)
 {
     condition = node.AddValueInput <bool>("Condition");
 }
Esempio n. 52
0
        //public virtual void Push(ItemDefinition value)
        //{
        //    if (value == null)
        //        throw new ArgumentNullException(nameof(value));

        //    this.itemDefinitions.Add(value.Id, value);
        //    this.elements.Add(value.Id, value);

        //    Queue<Action<object>> queue = null;
        //    if(this.requestQueues.TryGetValue(value.Id, out queue))
        //    {
        //        while(queue.Count > 0)
        //        {
        //            var action = queue.Dequeue();
        //            action(value);
        //        }

        //        this.requestQueues.Remove(value.Id);
        //    }
        //}

        //public virtual void Push(Message value)
        //{
        //    if (value == null)
        //        throw new ArgumentNullException(nameof(value));

        //    this.messages.Add(value.Id, value);
        //    this.elements.Add(value.Id, value);

        //    Queue<Action<object>> queue = null;
        //    if (this.requestQueues.TryGetValue(value.Id, out queue))
        //    {
        //        while (queue.Count > 0)
        //        {
        //            var action = queue.Dequeue();
        //            action(value);
        //        }

        //        this.requestQueues.Remove(value.Id);
        //    }
        //}
        public virtual void AddFlowNode(FlowNode flowNode)
        {
            this.flowNodes.Add(flowNode);
        }