Ejemplo n.º 1
0
        public static OperatorPart FindOpPartWithFunctorTypeInSubTree <T>(OperatorPart opPart, int maxDepth) where T : class
        {
            if (opPart == null || maxDepth < 0)
            {
                return(null);
            }

            var castedOpPart = opPart.Func as T;

            if (castedOpPart != null)
            {
                return(opPart);
            }

            foreach (var input in opPart.Connections)
            {
                var foundElement = FindOpPartWithFunctorTypeInSubTree <T>(input, maxDepth - 1);
                if (foundElement != null)
                {
                    return(foundElement);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
 public void AlreadyVisited(OperatorPart opPart)
 {
     if (opPart.Func != null)
     {
         UpdateStackTop(opPart.Func.Changed);
     }
 }
Ejemplo n.º 3
0
        public void InsertConnectionAt(OperatorPart inputToConnect, int index)
        {
            if ((_connections.Count > 0) && !IsMultiInput)
            {
                throw new Exception("multiple connections not allowed");
            }

            if ((index < 0) || (index > _connections.Count))
            {
                throw new Exception("index out of range");
            }

            _connections.Insert(index, inputToConnect);

            if (IsDefaultFuncSet)
            {
                ReplaceDefaultWithValueFunc();
            }

            inputToConnect.ChangedEvent     += ChangedHandler;
            inputToConnect.TypeChangedEvent += TypeChangedHandler;

            if ((_type == FunctionType.Generic) && (inputToConnect.Type != FunctionType.Generic))
            {
                EmitTypeChangedEvent(Type);
            }

            _function.Changed = true;
            ChangedEvent(this, new ChangedEventArgs(_changedTime, ChangedState.Subtree));
            ManipulatedEvent(this, EventArgs.Empty);
        }
Ejemplo n.º 4
0
 protected static void EvalMultiInput(OperatorPart multiInput, OperatorPartContext context)
 {
     foreach (var input in multiInput.Connections)
     {
         input.Eval(context);
     }
 }
Ejemplo n.º 5
0
        public static OperatorPart FindLowestUnconnectedOpPart(OperatorPart opPart, int maxDepth)
        {
            if (opPart == null)
            {
                return(null);
            }
            if (maxDepth < 0)
            {
                return(null);
            }

            if (opPart.Connections.Count == 0)
            {
                return(opPart);
            }

            foreach (var input in opPart.Connections)
            {
                OperatorPart foundElement = FindLowestUnconnectedOpPart(input, maxDepth - 1);
                if (foundElement != null)
                {
                    return(foundElement);
                }
            }
            return(null);
        }
Ejemplo n.º 6
0
 public void PreEvaluate(OperatorPart opPart)
 {
     if (_opPartThatWouldBuildACycle.Contains(opPart))
     {
         HasCycle = true;
     }
 }
Ejemplo n.º 7
0
        public void EmitChangedEventForOutput(int outputId)
        {
            OperatorPart output = (from o in Parent.Outputs
                                   where o.Func.EvaluationIndex == outputId
                                   select o).Single();

            output.Func.Changed = true;
            output.EmitChangedEvent();
        }
Ejemplo n.º 8
0
 internal Connection(Guid id, Operator sourceOp, OperatorPart sourceOpPart, Operator targetOp, OperatorPart targetOpPart, int connectionIdx)
 {
     ID           = id;
     SourceOp     = sourceOp;
     SourceOpPart = sourceOpPart;
     TargetOp     = targetOp;
     TargetOpPart = targetOpPart;
     Index        = connectionIdx;
 }
Ejemplo n.º 9
0
            public void PreEvaluate(OperatorPart opPart)
            {
                T func = opPart.Func as T;

                if (func != null)
                {
                    CollectedOpPartFunctions.Add(func);
                }
            }
Ejemplo n.º 10
0
        public static void CollectAllMetaOperators(this OperatorPart operatorPart, HashSet <MetaOperator> collectedMetaOperators)
        {
            var collectedOperators = new HashSet <Operator>();

            CollectAllOperators(operatorPart, collectedOperators);
            foreach (var op in collectedOperators)
            {
                collectedMetaOperators.Add(op.Definition);
            }
        }
Ejemplo n.º 11
0
            public void PreEvaluate(OperatorPart opPart)
            {
                var metaOperator = opPart.Parent.Definition;

                if (!CollectedOperators.Contains(metaOperator))
                {
                    // new op, add
                    CollectedOperators.Add(metaOperator);
                }
            }
Ejemplo n.º 12
0
        public void WriteInput(OperatorPart opPart)
        {
            Writer.WriteStartObject();

            Writer.WriteValue("Name", opPart.Name);
            Writer.WriteValue("ID", opPart.ID);
            Writer.WriteValue("Type", opPart.Type);
            Writer.WriteValue("Value", ValueUtilities.GetValueForTypeFromContext(opPart.Type, opPart.Eval(new OperatorPartContext())));

            Writer.WriteEndObject();
        }
Ejemplo n.º 13
0
        internal void InsertInput(int index, OperatorPart input)
        {
            if ((index < 0) || (index > Inputs.Count))
            {
                throw new IndexOutOfRangeException();
            }

            Inputs.Insert(index, input);
            input.Parent = this;

            EventExt.Raise(InputAddedEvent, this, new OperatorPartChangedEventArgs(input));
        }
Ejemplo n.º 14
0
        public static OperatorPart GetRegardingAnimationOpPart(OperatorPart input)
        {
            var animationOpPart = FindOpPartWithFunctorTypeInSubTree <ICurve>(input, 3);
            var timeAccOpPart   = FindOpPartWithFunctorTypeInSubTree <OperatorPartTraits.ITimeAccessor>(animationOpPart, 3);

            if (animationOpPart != null && timeAccOpPart != null)
            {
                return(animationOpPart);
            }

            return(null);
        }
Ejemplo n.º 15
0
        public void ReadAndSetInputValues(OperatorPart opPart, JToken jsonOpPart)
        {
            opPart.Name = jsonOpPart["Name"].Value <string>();
            if (opPart.ID != Guid.Parse(jsonOpPart["ID"].Value <string>()))
            {
                throw new System.Exception("Wrong op part id in file");
            }

            string type  = jsonOpPart["Type"].Value <string>();
            string value = jsonOpPart["Value"].Value <string>();

            opPart.Func = Utilities.CreateValueFunction(ValueUtilities.CreateValue(type, value));
        }
Ejemplo n.º 16
0
        internal void InsertOutput(int index, OperatorPart output)
        {
            if ((index < 0) || (index > Outputs.Count))
            {
                throw new IndexOutOfRangeException();
            }

            Outputs.Insert(index, output);
            output.Parent = this;
            UpdateOutputIndices();

            EventExt.Raise(OutputAddedEvent, this, new OperatorPartChangedEventArgs(output));
        }
Ejemplo n.º 17
0
        public static void SetOperatorPartValue(OperatorPart opPart, double time, float value)
        {
            var animationOpPart = GetRegardingAnimationOpPart(opPart);

            if (animationOpPart != null)
            {
                var animationCurve = animationOpPart.Func as ICurve;
                Utils.AddKeyframeAtTime(animationCurve, time, value);
            }
            else
            {
                opPart.Func = Utilities.CreateValueFunction(new Float(value));
            }
        }
Ejemplo n.º 18
0
 public static string GetInputTextValue(OperatorPart opPart)
 {
     if (opPart.Connections.Count == 0)
     {
         string text      = "";
         var    textValue = ((opPart.Func as Utilities.ValueFunction).Value as Text);
         if (textValue != null)
         {
             text = textValue.Val;
         }
         return(text);
     }
     else
     {
         return(opPart.Connections[0].Eval(new OperatorPartContext()).Text);
     }
 }
Ejemplo n.º 19
0
 public static float GetInputFloatValue(OperatorPart opPart)
 {
     if (opPart.Connections.Count == 0)
     {
         float newValue   = 0;
         var   floatValue = ((opPart.Func as Utilities.ValueFunction).Value as Float);
         if (floatValue != null)
         {
             newValue = floatValue.Val;
         }
         return(newValue);
     }
     else
     {
         return(opPart.Connections[0].Eval(new OperatorPartContext()).Value);
     }
 }
Ejemplo n.º 20
0
            public void PostEvaluate(OperatorPart opPart)
            {
                if (_changedStates.Peek())
                {
                    if (opPart.Func != null)
                    {
                        opPart.Func.Changed = true;
                    }
                    return;
                }

                if (opPart.Func is IVariableAccessor)
                {
                    opPart.Func.Changed = true;
                    _changedStates.Pop();
                    _changedStates.Push(true);
                }
            }
Ejemplo n.º 21
0
            public void PostEvaluate(OperatorPart opPart)
            {
                if (_changedStates.Peek())
                {
                    if (opPart.Func != null)
                    {
                        opPart.Func.Changed = true;
                    }
                    return;
                }

                var variableAccessor = opPart.Func as IVariableAccessor;

                if (variableAccessor != null && variableAccessor.VariableName == _variableName)
                {
                    opPart.Func.Changed = true;
                    _changedStates.Pop();
                    _changedStates.Push(true);
                }
            }
Ejemplo n.º 22
0
        internal void RemoveInputInternal(OperatorPart input)
        {
            var inputOp  = input.Parent;
            var parentOp = inputOp.Parent;

            // remove possible connection to this input in parent op
            if (parentOp != null)
            {
                while (input.Connections.Count > 0)
                {
                    var sourceOpPart = input.Connections[0];
                    var sourceOp     = sourceOpPart.Parent;
                    var connection   = new Connection(sourceOp, sourceOpPart, this, input, 0);
                    parentOp.RemoveConnection(connection);
                }
            }

            Inputs.Remove(input);
            EventExt.Raise(InputRemovedEvent, this, new OperatorPartChangedEventArgs(input));
        }
Ejemplo n.º 23
0
            public void PostEvaluate(OperatorPart opPart)
            {
                if (_markedStates.Peek())
                {
                    opPart.SubTreeContainsInvalidatable = true;
                    return;
                }

                var isTimeAccessor     = opPart.Func is ITimeAccessor;
                var isAsyncDependend   = opPart.Func is IAsyncDependend;
                var isVariableAccessor = opPart.Func is IVariableAccessor;

                opPart.SubTreeContainsInvalidatable = isTimeAccessor || isAsyncDependend || isVariableAccessor;

                if (opPart.SubTreeContainsInvalidatable)
                {
                    _markedStates.Pop();
                    _markedStates.Push(true);
                }
            }
Ejemplo n.º 24
0
        public static bool ValidateResource(ref Resource resource, OperatorPart user, SharpDX.Direct3D11.Device device, Texture2DDescription textureDesc)
        {
            if (resource != null &&
                resource.Texture != null &&
                resource.Texture.Description.Equals(textureDesc) &&
                _usedResources.Contains(resource))
            {
                return(false); //resource has not changed and exists
            }

            InternalDispose(resource); // dispose previous resource (= move to available resources)

            List <Resource> matchingFreeResources = null;

            if (!_freeResources.TryGetValue(textureDesc, out matchingFreeResources))
            {
                var texture = new Texture2D(device, textureDesc);
                matchingFreeResources = new List <Resource>()
                {
                    new Resource()
                    {
                        Texture = texture, Valid = true
                    }
                };
            }
            var foundResource = matchingFreeResources[0];

            matchingFreeResources.Remove(foundResource);
            if (matchingFreeResources.Count == 0)
            {
                _freeResources.Remove(textureDesc);
            }

            foundResource.User = user;
            _usedResources.Add(foundResource);

            resource = foundResource;

            return(true); //new resource used, return true for changed
        }
Ejemplo n.º 25
0
        internal void RemoveOutputInternal(OperatorPart output)
        {
            var outputOp = this;
            var parentOp = outputOp.Parent;

            // remove possible connection from this output in parent op
            if (parentOp != null)
            {
                var connectionsToRemove = (from con in parentOp.Connections
                                           where con.SourceOp == outputOp
                                           where con.SourceOpPart == output
                                           select con).ToList();
                foreach (var connection in connectionsToRemove)
                {
                    parentOp.RemoveConnection(connection);
                }
            }

            Outputs.Remove(output);
            UpdateOutputIndices();
            EventExt.Raise(OutputRemovedEvent, this, new OperatorPartChangedEventArgs(output));
        }
Ejemplo n.º 26
0
            public void PostEvaluate(OperatorPart opPart)
            {
                if (_changedStates.Peek())
                {
                    if (opPart.Func != null)
                    {
                        opPart.Func.Changed = true;
                    }
                    return;
                }

                var isTimeAccessor     = opPart.Func is ITimeAccessor;
                var asyncDependend     = opPart.Func as IAsyncDependend;
                var isVariableAccessor = opPart.Func is IVariableAccessor;

                if (isTimeAccessor || (asyncDependend != null && asyncDependend.AsyncChanged) || isVariableAccessor)
                {
                    opPart.Func.Changed = true;
                    _changedStates.Pop();
                    _changedStates.Push(true);
                }
            }
Ejemplo n.º 27
0
 public OperatorPartChangedEventArgs(OperatorPart opPart)
 {
     OperatorPart = opPart;
 }
Ejemplo n.º 28
0
        public MetaOperatorPart GetMetaOperatorPart(OperatorPart opPart)
        {
            int index = InternalParts.IndexOf(opPart);

            return((index != -1) ? Definition.OperatorParts[index].Item2 : null);
        }
Ejemplo n.º 29
0
        public MetaOutput GetMetaOutput(OperatorPart input)
        {
            int index = Outputs.IndexOf(input);

            return((index != -1) ? Definition.Outputs[index] : null);
        }