public override Value Evaluate(FSharpList <Value> args)
        {
            FSharpList <Value> pts = ((Value.List)args[0]).Item;
            FamilySymbol       fs  = (FamilySymbol)((Value.Container)args[1]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                Element e;
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e))
                {
                    ac        = e as FamilyInstance;
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != pts.Count())
            {
                throw new Exception("The input list of points does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                ReferencePoint point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                XYZ            pt    = (XYZ)((Value.Container)pts.ElementAt(i)).Item;
                point.Position = pt;
                i++;
            }

            return(Value.NewContainer(ac));
        }
Example #2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            List <XYZ> xyzList = new List <XYZ>();

            FSharpList <Value> vals = ((Value.List)args[0]).Item;
            var doc = dynRevitSettings.Doc;

            for (int ii = 0; ii < vals.Count(); ii++)
            {
                var item = ((Value.Container)vals[ii]).Item;

                if (item is ReferencePoint)
                {
                    ReferencePoint refPoint = (ReferencePoint)item;
                    XYZ            thisXYZ  = refPoint.GetCoordinateSystem().Origin;
                    xyzList.Add(thisXYZ);
                }
                else if (item is XYZ)
                {
                    XYZ thisXYZ = (XYZ)item;
                    xyzList.Add(thisXYZ);
                }
            }

            if (xyzList.Count <= 1)
            {
                throw new Exception("Not enough reference points to make a curve.");
            }


            Type ArcType = typeof(Autodesk.Revit.DB.Arc);

            MethodInfo[] arcStaticMethods = ArcType.GetMethods(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            String nameOfMethodCreateByFit = "CreateByFit";
            Arc    result = null;

            foreach (MethodInfo m in arcStaticMethods)
            {
                if (m.Name == nameOfMethodCreateByFit)
                {
                    object[] argsM = new object[1];
                    argsM[0] = xyzList;

                    result = (Arc)m.Invoke(null, argsM);

                    break;
                }
            }

            return(Value.NewContainer(result));
        }
Example #3
0
        protected void Execute <T>(FSharpList <T> list, ISort sut)
            where T : IComparable,
        IComparable <T>
        {
            var expected = (from n in list
                            select n).ToArray().Sort();

            var sorted = sut.Sort(list);

            sorted.Should().NotBeEmpty()
            .And.HaveCount(list.Count())
            .And.ContainInOrder(expected);
        }
Example #4
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            _points    = ((Value.List)args[0]).Item;                      //point list
            _curves    = ((Value.List)args[1]).Item;                      //spring list
            _d         = ((Value.Number)args[2]).Item;                    //dampening
            _s         = ((Value.Number)args[3]).Item;                    //spring constant
            _r         = ((Value.Number)args[4]).Item;                    //rest length
            _use_rl    = Convert.ToBoolean(((Value.Number)args[5]).Item); //use rest length
            _rlf       = ((Value.Number)args[6]).Item;                    //rest length factor
            _m         = ((Value.Number)args[7]).Item;                    //nodal mass
            _g         = ((Value.Number)args[8]).Item;                    //gravity z component
            _threshold = ((Value.Number)args[9]).Item;                    //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            particleSystem.setConverged(false);
            particleSystem.setGravity(_g);
            particleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if (particleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != particleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            FSharpList <Value> forces = FSharpList <Value> .Empty;

            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                forces = FSharpList <Value> .Cons(Value.NewNumber(particleSystem.getSpring(i).getResidualForce()), forces);
            }
            forces.Reverse();

            FSharpList <Value> results = FSharpList <Value> .Empty;

            results = FSharpList <Value> .Cons(Value.NewList(forces), results);

            results = FSharpList <Value> .Cons(Value.NewContainer(particleSystem), results);

            //return Value.NewContainer(particleSystem);
            return(Value.NewList(results));
        }
Example #5
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var element = (Element)((Value.Container)args[0]).Item;
            var results = FSharpList <Value> .Empty;

            for (int i = args.Count() - 1; i > 0; i--)
            {
                var paramName = ((Value.String)args[i]).Item;
                var param     = element.get_Parameter(paramName);
                if (param != null)
                {
                    var pd = OutPortData[i - 1];
                    switch (param.StorageType)
                    {
                    case StorageType.Double:
                        outPuts[pd] = FScheme.Value.NewNumber(param.AsDouble());
                        break;

                    case StorageType.ElementId:
                        outPuts[pd] = FScheme.Value.NewContainer(param.AsElementId());
                        break;

                    case StorageType.Integer:
                        outPuts[pd] = FScheme.Value.NewNumber(param.AsInteger());
                        break;

                    case StorageType.String:
                        if (string.IsNullOrEmpty(param.AsString()))
                        {
                            outPuts[pd] = FScheme.Value.NewString(string.Empty);
                        }
                        else
                        {
                            outPuts[pd] = FScheme.Value.NewString(param.AsString());
                        }
                        break;

                    default:
                        if (string.IsNullOrEmpty(param.AsValueString()))
                        {
                            outPuts[pd] = FScheme.Value.NewString(string.Empty);
                        }
                        else
                        {
                            outPuts[pd] = FScheme.Value.NewString(param.AsValueString());
                        }
                        break;
                    }
                }
            }
        }
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            _points    = ((Value.List)args[0]).Item;                      //point list
            _curves    = ((Value.List)args[1]).Item;                      //spring list
            _d         = ((Value.Number)args[2]).Item;                    //dampening
            _s         = ((Value.Number)args[3]).Item;                    //spring constant
            _r         = ((Value.Number)args[4]).Item;                    //rest length
            _useRl     = Convert.ToBoolean(((Value.Number)args[5]).Item); //use rest length
            _rlf       = ((Value.Number)args[6]).Item;                    //rest length factor
            _m         = ((Value.Number)args[7]).Item;                    //nodal mass
            _g         = ((Value.Number)args[8]).Item;                    //gravity z component
            _threshold = ((Value.Number)args[9]).Item;                    //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            ParticleSystem.setConverged(false);
            ParticleSystem.setGravity(_g);
            ParticleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if (ParticleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != ParticleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            outPuts[_psPort]     = Value.NewContainer(ParticleSystem);
            outPuts[_forcesPort] = Value.NewList(Utils.SequenceToFSharpList(
                                                     ParticleSystem.Springs.Select(s => Value.NewNumber(s.getResidualForce()))));
        }
Example #7
0
        private void ResetSystem(FSharpList <Value> points, FSharpList <Value> curves)
        {
            if (points == null || curves == null)
            {
                return;
            }

            //particleSystem.Clear();
            particleSystem = null;
            particleSystem = new ParticleSystem();

            _fixPtCount = points.Count();

            particleSystem.setConverged(false);
            particleSystem.setGravity(_g);
            particleSystem.setThreshold(_threshold);

            CreateSpringsFromCurves(curves, points);

            DispatchOnUIThread(new Action(dynSettings.Controller.RequestClearDrawables));

            _reset = false;
        }
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            //if this element maintains a collcection of references
            //then clear the collection
            if (this is IClearable)
                (this as IClearable).ClearReferences();

            List<FSharpList<Value>> argSets = new List<FSharpList<Value>>();

            //create a zip of the incoming args and the port data
            //to be used for type comparison
            var portComparison = args.Zip(InPortData, (first, second) => new Tuple<Type, Type>(first.GetType(), second.PortType));

            //if any value is a list whose expectation is a single
            //do an auto map
            //TODO: figure out a better way to do this than using a lot
            //of specific excludes
            if (args.Count() > 0 &&
                portComparison.Any(x => x.Item1 == typeof(Value.List) &&
                x.Item2 != typeof(Value.List)) &&
                !(this.ArgumentLacing == LacingStrategy.Disabled))
            {
                //if the argument is of the expected type, then
                //leave it alone otherwise, wrap it in a list
                int j = 0;
                foreach (var arg in args)
                {
                    //incoming value is list and expecting single
                    if (portComparison.ElementAt(j).Item1 == typeof(Value.List) &&
                        portComparison.ElementAt(j).Item2 != typeof(Value.List))
                    {
                        //leave as list
                        argSets.Add(((Value.List)arg).Item);
                    }
                    //incoming value is list and expecting list
                    else
                    {
                        //wrap in list
                        argSets.Add(Utils.MakeFSharpList(arg));
                    }
                    j++;
                }

                IEnumerable<IEnumerable<Value>> lacedArgs = null;
                switch (this.ArgumentLacing)
                {
                    case LacingStrategy.First:
                        lacedArgs = argSets.SingleSet();
                        break;
                    case LacingStrategy.Shortest:
                        lacedArgs = argSets.ShortestSet();
                        break;
                    case LacingStrategy.Longest:
                        lacedArgs = argSets.LongestSet();
                        break;
                    case LacingStrategy.CrossProduct:
                        lacedArgs = argSets.CartesianProduct();
                        break;
                }

                //setup a list to hold the results
                //each output will have its own results collection
                List<FSharpList<Value>> results = new List<FSharpList<FScheme.Value>>();
                for(int i=0; i<OutPortData.Count(); i++)
                {
                    results.Add(FSharpList<Value>.Empty);
                }
                //FSharpList<Value> result = FSharpList<Value>.Empty;

                //run the evaluate method for each set of
                //arguments in the la result. do these
                //in reverse order so our cons comes out the right
                //way around
                for (int i = lacedArgs.Count() - 1; i >= 0; i--)
                {
                    var evalResult = Evaluate(Utils.MakeFSharpList(lacedArgs.ElementAt(i).ToArray()));

                    //if the list does not have the same number of items
                    //as the number of output ports, then throw a wobbly
                    if (!evalResult.IsList)
                        throw new Exception("Output value of the node is not a list.");

                    for (int k = 0; k < OutPortData.Count(); k++)
                    {
                        FSharpList<Value> lst = ((Value.List)evalResult).Item;
                        results[k] = FSharpList<Value>.Cons(lst[k], results[k]);
                    }
                    runCount++;
                }

                //the result of evaluation will be a list. we split that result
                //and send the results to the outputs
                for (int i = 0; i < OutPortData.Count(); i++)
                {
                    outPuts[OutPortData[i]] = Value.NewList(results[i]);
                }

            }
            else
            {
                Value evalResult = Evaluate(args);

                runCount++;

                if (!evalResult.IsList)
                        throw new Exception("Output value of the node is not a list.");

                FSharpList<Value> lst = ((Value.List)evalResult).Item;

                //the result of evaluation will be a list. we split that result
                //and send the results to the outputs
                for (int i = 0; i < OutPortData.Count(); i++)
                {
                    outPuts[OutPortData[i]] = lst[i];
                }
            }

            ValidateConnections();
        }
Example #9
0
        /// <summary>
        /// Builds a parameter list given a list of arguments and a list of parameter info
        /// </summary>
        /// <param name="args">A list of Values which will be distributed to the output lists</param>
        /// <param name="pi">An array of parameter info for the method</param>
        /// <param name="end">The end count</param>
        /// <param name="parameters">A parameters List to add to.</param>
        private static void BuildParameterList(FSharpList<Value> args, ParameterInfo[] pi, int end, List<List<object>> parameters)
        {
            //for a static method, the number of parameters
            //will equal the number of arguments on the node
            if (args.Count() == pi.Count())
            {
                //ARGUMENT LOOP
                for (int j = 0; j < end; j++)
                {
                    //create a list to hold each set of arguments
                    var currParams = new List<object>();

                    //PARAMETER LOOP
                    for (int i = 0; i < pi.Count(); i++)
                    {
                        var arg = args[i];

                        //if the value is a list, add the jth item converted
                        //or the last item if i exceeds the count of the list
                        if (arg.IsList)
                        {
                            var lst = (Value.List) arg;
                            var argItem = (j < lst.Item.Count() ? lst.Item[j]: lst.Item.Last());

                            currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType));
                        }
                        else
                            //if the value is not a list,
                            //just add the value
                            currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType));
                    }

                    parameters.Add(currParams);
                }
            }
            //for instance methods, the first argument will be the
            //item or list of items which will be the target of invocation
            //in this case, skip parsing the first argument
            else
            {
                //ARGUMENT LOOP
                for (int j = 0; j < end; j++)
                {
                    //create a list to hold each set of arguments
                    var currParams = new List<object>();

                    //PARAMETER LOOP
                    for (int i = 0; i < pi.Count(); i++)
                    {
                        var arg = args[i + 1];

                        //if the value is a list, add the jth item converted
                        //or the last item if i exceeds the count of the list
                        if (arg.IsList)
                        {
                            //var argItem = ((Value.List)arg).Item.Count() < end ? args.Last() : args[j];

                            var lst = (Value.List)arg;
                            var argItem = (j < lst.Item.Count() ? lst.Item[j] : lst.Item.Last());

                            currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType));
                        }
                        else
                            //if the value is not a list,
                            //just add the value
                            currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType));
                    }

                    parameters.Add(currParams);
                }
            }
        }
Example #10
0
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            _points = ((Value.List)args[0]).Item;//point list
            _curves = ((Value.List)args[1]).Item;//spring list
            _d = ((Value.Number)args[2]).Item;//dampening
            _s = ((Value.Number)args[3]).Item;//spring constant
            _r = ((Value.Number)args[4]).Item;//rest length
            _useRl = Convert.ToBoolean(((Value.Number)args[5]).Item);//use rest length
            _rlf = ((Value.Number)args[6]).Item;//rest length factor
            _m = ((Value.Number)args[7]).Item;//nodal mass
            _g = ((Value.Number)args[8]).Item;//gravity z component
            _threshold = ((Value.Number) args[9]).Item; //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            ParticleSystem.setConverged(false);
            ParticleSystem.setGravity(_g);
            ParticleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if(ParticleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != ParticleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            outPuts[_psPort] = Value.NewContainer(ParticleSystem);
            outPuts[_forcesPort] = Value.NewList(Utils.SequenceToFSharpList(
                ParticleSystem.Springs.Select(s => Value.NewNumber(s.getResidualForce()))));
        }
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            //THE OLD WAY
            //outPuts[OutPortData[0]] = Evaluate(args);

            //THE NEW WAY
            //if this element maintains a collcection of references
            //then clear the collection
            if (this is IClearable)
            {
                (this as IClearable).ClearReferences();
            }

            List <FSharpList <Value> > argSets = new List <FSharpList <Value> >();

            //create a zip of the incoming args and the port data
            //to be used for type comparison
            var portComparison       = args.Zip(InPortData, (first, second) => new Tuple <Type, Type>(first.GetType(), second.PortType));
            var listOfListComparison = args.Zip(InPortData, (first, second) => new Tuple <bool, Type>(Utils.IsListOfLists(first), second.PortType));

            //there are more than zero arguments
            //and there is either an argument which does not match its expections
            //OR an argument which requires a list and gets a list of lists
            //AND argument lacing is not disabled
            if (args.Count() > 0 &&
                (portComparison.Any(x => x.Item1 == typeof(Value.List) && x.Item2 != typeof(Value.List)) ||
                 listOfListComparison.Any(x => x.Item1 == true && x.Item2 == typeof(Value.List))) &&
                this.ArgumentLacing != LacingStrategy.Disabled)
            {
                //if the argument is of the expected type, then
                //leave it alone otherwise, wrap it in a list
                int j = 0;
                foreach (var arg in args)
                {
                    var portAtThis = portComparison.ElementAt(j);

                    //incoming value is list and expecting single
                    if (portAtThis.Item1 == typeof(Value.List) &&
                        portAtThis.Item2 != typeof(Value.List))
                    {
                        //leave as list
                        argSets.Add(((Value.List)arg).Item);
                    }
                    //incoming value is list and expecting list
                    else
                    {
                        //check if we have a list of lists, if so, then don't wrap
                        if (Utils.IsListOfLists(arg) && !acceptsListOfLists(arg))
                        {
                            //leave as list
                            argSets.Add(((Value.List)arg).Item);
                        }
                        else
                        {
                            //wrap in list
                            argSets.Add(Utils.MakeFSharpList(arg));
                        }
                    }
                    j++;
                }

                IEnumerable <IEnumerable <Value> > lacedArgs = null;
                switch (this.ArgumentLacing)
                {
                case LacingStrategy.First:
                    lacedArgs = argSets.SingleSet();
                    break;

                case LacingStrategy.Shortest:
                    lacedArgs = argSets.ShortestSet();
                    break;

                case LacingStrategy.Longest:
                    lacedArgs = argSets.LongestSet();
                    break;

                case LacingStrategy.CrossProduct:
                    lacedArgs = argSets.CartesianProduct();
                    break;
                }

                //setup an empty list to hold results
                FSharpList <Value> result = FSharpList <Value> .Empty;

                //run the evaluate method for each set of
                //arguments in the cartesian result. do these
                //in reverse order so our cons comes out the right
                //way around
                for (int i = lacedArgs.Count() - 1; i >= 0; i--)
                {
                    var evalResult = Evaluate(Utils.MakeFSharpList(lacedArgs.ElementAt(i).ToArray()));
                    result = FSharpList <Value> .Cons(evalResult, result);

                    runCount++;
                }

                outPuts[OutPortData[0]] = Value.NewList(result);
            }
            else
            {
                outPuts[OutPortData[0]] = Evaluate(args);
                runCount++;
            }
        }
Example #12
0
        protected internal virtual void __eval_internal(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            var argList = new List<string>();
            if (args.Count() > 0)
            {
                argList = args.Select(x => x.ToString()).ToList<string>();
            }
            var outPutsList = new List<string>();
            if(outPuts.Count() > 0)
            {
                outPutsList = outPuts.Keys.Select(x=>x.NickName).ToList<string>();
            }

            Debug.WriteLine(string.Format("__eval_internal : {0} : {1}",
                string.Join(",", argList),
                string.Join(",", outPutsList)));

            Evaluate(args, outPuts);
        }
Example #13
0
        private void ResetSystem(FSharpList<Value> points, FSharpList<Value> curves)
        {
            if (points == null || curves == null)
                return;

            //particleSystem.Clear();
            particleSystem = null;
            particleSystem = new ParticleSystem();

            _fixPtCount = points.Count();

            particleSystem.setConverged(false);
            particleSystem.setGravity(_g);
            particleSystem.setThreshold(_threshold);

            CreateSpringsFromCurves(curves, points);

            DispatchOnUIThread(new Action(dynSettings.Controller.RequestClearDrawables));

            _reset = false;
        }
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            //if this element maintains a collcection of references
            //then clear the collection
            if (this is IClearable)
            {
                (this as IClearable).ClearReferences();
            }

            List <FSharpList <Value> > argSets = new List <FSharpList <Value> >();

            //create a zip of the incoming args and the port data
            //to be used for type comparison
            var portComparison       = args.Zip(InPortData, (first, second) => new Tuple <Type, Type>(first.GetType(), second.PortType));
            var listOfListComparison = args.Zip(InPortData, (first, second) => new Tuple <bool, Type>(Utils.IsListOfLists(first), second.PortType));

            //there are more than zero arguments
            //and there is either an argument which does not match its expections
            //OR an argument which requires a list and gets a list of lists
            //AND argument lacing is not disabled
            if (args.Count() > 0 &&
                (portComparison.Any(x => x.Item1 == typeof(Value.List) && x.Item2 != typeof(Value.List)) ||
                 listOfListComparison.Any(x => x.Item1 == true && x.Item2 == typeof(Value.List))) &&
                this.ArgumentLacing != LacingStrategy.Disabled)
            {
                //if the argument is of the expected type, then
                //leave it alone otherwise, wrap it in a list
                int j = 0;
                foreach (var arg in args)
                {
                    //incoming value is list and expecting single
                    if (portComparison.ElementAt(j).Item1 == typeof(Value.List) &&
                        portComparison.ElementAt(j).Item2 != typeof(Value.List))
                    {
                        //leave as list
                        argSets.Add(((Value.List)arg).Item);
                    }
                    //incoming value is list and expecting list
                    else
                    {
                        //check if we have a list of lists, if so, then don't wrap
                        if (Utils.IsListOfLists(arg))
                        {
                            //leave as list
                            argSets.Add(((Value.List)arg).Item);
                        }
                        else
                        {
                            //wrap in list
                            argSets.Add(Utils.MakeFSharpList(arg));
                        }
                    }
                    j++;
                }

                IEnumerable <IEnumerable <Value> > lacedArgs = null;
                switch (this.ArgumentLacing)
                {
                case LacingStrategy.First:
                    lacedArgs = argSets.SingleSet();
                    break;

                case LacingStrategy.Shortest:
                    lacedArgs = argSets.ShortestSet();
                    break;

                case LacingStrategy.Longest:
                    lacedArgs = argSets.LongestSet();
                    break;

                case LacingStrategy.CrossProduct:
                    lacedArgs = argSets.CartesianProduct();
                    break;
                }

                //setup a list to hold the results
                //each output will have its own results collection
                List <FSharpList <Value> > results = new List <FSharpList <FScheme.Value> >();
                for (int i = 0; i < OutPortData.Count(); i++)
                {
                    results.Add(FSharpList <Value> .Empty);
                }
                //FSharpList<Value> result = FSharpList<Value>.Empty;

                //run the evaluate method for each set of
                //arguments in the la result. do these
                //in reverse order so our cons comes out the right
                //way around
                for (int i = lacedArgs.Count() - 1; i >= 0; i--)
                {
                    var evalResult = Evaluate(Utils.MakeFSharpList(lacedArgs.ElementAt(i).ToArray()));

                    //if the list does not have the same number of items
                    //as the number of output ports, then throw a wobbly
                    if (!evalResult.IsList)
                    {
                        throw new Exception("Output value of the node is not a list.");
                    }

                    for (int k = 0; k < OutPortData.Count(); k++)
                    {
                        FSharpList <Value> lst = ((Value.List)evalResult).Item;
                        results[k] = FSharpList <Value> .Cons(lst[k], results[k]);
                    }
                    runCount++;
                }

                //the result of evaluation will be a list. we split that result
                //and send the results to the outputs
                for (int i = 0; i < OutPortData.Count(); i++)
                {
                    outPuts[OutPortData[i]] = Value.NewList(results[i]);
                }
            }
            else
            {
                Value evalResult = Evaluate(args);

                runCount++;

                if (!evalResult.IsList)
                {
                    throw new Exception("Output value of the node is not a list.");
                }

                FSharpList <Value> lst = ((Value.List)evalResult).Item;

                //the result of evaluation will be a list. we split that result
                //and send the results to the outputs
                for (int i = 0; i < OutPortData.Count(); i++)
                {
                    outPuts[OutPortData[i]] = lst[i];
                }
            }

            ValidateConnections();
        }
Example #15
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            FSharpList <Value> pts = ((Value.List)args[0]).Item;
            var fs = (FamilySymbol)((Value.Container)args[1]).Item;

            FamilyInstance ac;

            var instData = new List <FamilyInstanceCreationData>();

            var sw = new Stopwatch();

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(Elements[0], out ac))
                {
                    sw.Start();
                    ac.Symbol = fs;
                    sw.Stop();
                    Debug.WriteLine(string.Format("{0} elapsed for updating family type on AC.", sw.Elapsed));
                    sw.Reset();
                }
                else
                {
                    sw.Start();
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                    sw.Stop();
                    Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed));
                    sw.Reset();
                }
            }
            else
            {
                sw.Start();
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
                sw.Stop();
                Debug.WriteLine(string.Format("{0} elapsed for creating an AC.", sw.Elapsed));
                sw.Reset();
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != pts.Count())
            {
                throw new Exception("The input list of points does not have the same number of values required by the adaptive component.");
            }

            sw.Start();
            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var pt    = (XYZ)((Value.Container)pts.ElementAt(i)).Item;
                point.Position = pt;
                i++;
            }
            sw.Stop();
            Debug.WriteLine(string.Format("{0} elapsed for updating placement points of the AC.", sw.Elapsed));
            sw.Reset();


            return(Value.NewContainer(ac));
        }
Example #16
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            _points = ((Value.List)args[0]).Item;//point list
            _curves = ((Value.List)args[1]).Item;//spring list
            _d = ((Value.Number)args[2]).Item;//dampening
            _s = ((Value.Number)args[3]).Item;//spring constant
            _r = ((Value.Number)args[4]).Item;//rest length
            _use_rl = Convert.ToBoolean(((Value.Number)args[5]).Item);//use rest length
            _rlf = ((Value.Number)args[6]).Item;//rest length factor
            _m = ((Value.Number)args[7]).Item;//nodal mass
            _g = ((Value.Number)args[8]).Item;//gravity z component
            _threshold = ((Value.Number) args[9]).Item; //convergence threshold

            //if we are in the evaluate, this has been
            //marked dirty and we should set it to unconverged
            //in case one of the inputs has changed.
            particleSystem.setConverged(false);
            particleSystem.setGravity(_g);
            particleSystem.setThreshold(_threshold);

            //if the particle system has a different layout, then
            //clear it instead of updating
            if(particleSystem.numberOfParticles() == 0 ||
                _fixPtCount != _points.Count() ||
                _curves.Count() != particleSystem.numberOfSprings() ||
                _reset)
            {
                ResetSystem(_points, _curves);
            }
            else
            {
                UpdateSystem();
            }

            FSharpList<Value> forces = FSharpList<Value>.Empty;
            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                forces = FSharpList<Value>.Cons(Value.NewNumber(particleSystem.getSpring(i).getResidualForce()), forces);
            }
            forces.Reverse();

            FSharpList<Value> results = FSharpList<Value>.Empty;
            results = FSharpList<Value>.Cons(Value.NewList(forces), results);
            results = FSharpList<Value>.Cons(Value.NewContainer(particleSystem), results);

            //return Value.NewContainer(particleSystem);
            return Value.NewList(results);
        }
Example #17
0
 public Blocks(FSharpList <FountainBlockElement> blocks)
 {
     Actions        = new List <Action>();
     Boneyards      = new List <Boneyard>();
     Centereds      = new List <Centered>();
     Characters     = new List <Character>();
     Dialogues      = new List <Dialogue>();
     DualDialogues  = new List <DualDialogue>();
     Lyrics         = new List <Lyrics>();
     PageBreaks     = new List <PageBreak>();
     Parentheticals = new List <Parenthetical>();
     SceneHeadings  = new List <SceneHeading>();
     Sections       = new List <Section>();
     Synopses       = new List <Synopses>();
     TitlePages     = new List <TitlePage>();
     Transitions    = new List <Transition>();
     FSharpBlocks   = blocks;
     for (int i = 0; i < blocks.Count(); i++)
     {
         FountainBlockElement b = blocks[i];
         if (b.IsAction)
         {
             Actions.Add(new Action(b));
         }
         if (b.IsBoneyard)
         {
             Boneyards.Add(new Boneyard(b));
         }
         if (b.IsCentered)
         {
             Centereds.Add(new Centered(b));
         }
         if (b.IsCharacter)
         {
             Characters.Add(new Character(b)); Character_Index.Add(i);
         }
         if (b.IsDialogue)
         {
             Dialogues.Add(new Dialogue(b)); Dialogue_Index.Add(i);
         }
         if (b.IsDualDialogue)
         {
             DualDialogue d = new DualDialogue(b);
             DualDialogues.Add(d);
             d.Blocks.Characters.ForEach(c => Characters.Add(c));
             d.Blocks.Dialogues.ForEach(c => Dialogues.Add(c));
         }
         if (b.IsLyrics)
         {
             Lyrics.Add(new Lyrics(b));
         }
         if (b.IsPageBreak)
         {
             PageBreaks.Add(new PageBreak(b));
         }
         if (b.IsParenthetical)
         {
             Parentheticals.Add(new Parenthetical(b));
         }
         if (b.IsSceneHeading)
         {
             SceneHeadings.Add(new SceneHeading(b)); SceneHeading_Index.Add(i);
         }
         if (b.IsSection)
         {
             Sections.Add(new Section(b));
         }
         if (b.IsSynopses)
         {
             Synopses.Add(new Synopses(b));
         }
         if (b.IsTitlePage)
         {
             TitlePages.Add(new TitlePage(b));
         }
         if (b.IsTransition)
         {
             Transitions.Add(new Transition(b));
         }
     }
 }
Example #18
0
        /// <summary>
        /// Builds a parameter list given a list of arguments and a list of parameter info
        /// </summary>
        /// <param name="args">A list of Values which will be distributed to the output lists</param>
        /// <param name="pi">An array of parameter info for the method</param>
        /// <param name="end">The end count</param>
        /// <param name="parameters">A parameters List to add to.</param>
        private static void BuildParameterList(FSharpList <Value> args, ParameterInfo[] pi, int end, List <List <object> > parameters)
        {
            //for a static method, the number of parameters
            //will equal the number of arguments on the node
            if (args.Count() == pi.Count())
            {
                //ARGUMENT LOOP
                for (int j = 0; j < end; j++)
                {
                    //create a list to hold each set of arguments
                    var currParams = new List <object>();

                    //PARAMETER LOOP
                    for (int i = 0; i < pi.Count(); i++)
                    {
                        var arg = args[i];

                        //if the value is a list, add the jth item converted
                        //or the last item if i exceeds the count of the list
                        if (arg.IsList)
                        {
                            var lst     = (Value.List)arg;
                            var argItem = (j < lst.Item.Count() ? lst.Item[j] : lst.Item.Last());

                            currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType));
                        }
                        else
                        {
                            //if the value is not a list,
                            //just add the value
                            currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType));
                        }
                    }

                    parameters.Add(currParams);
                }
            }
            //for instance methods, the first argument will be the
            //item or list of items which will be the target of invocation
            //in this case, skip parsing the first argument
            else
            {
                //ARGUMENT LOOP
                for (int j = 0; j < end; j++)
                {
                    //create a list to hold each set of arguments
                    var currParams = new List <object>();

                    //PARAMETER LOOP
                    for (int i = 0; i < pi.Count(); i++)
                    {
                        var arg = args[i + 1];

                        //if the value is a list, add the jth item converted
                        //or the last item if i exceeds the count of the list
                        if (arg.IsList)
                        {
                            //var argItem = ((Value.List)arg).Item.Count() < end ? args.Last() : args[j];

                            var lst     = (Value.List)arg;
                            var argItem = (j < lst.Item.Count() ? lst.Item[j] : lst.Item.Last());

                            currParams.Add(DynamoTypeConverter.ConvertInput(argItem, pi[i].ParameterType));
                        }
                        else
                        {
                            //if the value is not a list,
                            //just add the value
                            currParams.Add(DynamoTypeConverter.ConvertInput(arg, pi[i].ParameterType));
                        }
                    }

                    parameters.Add(currParams);
                }
            }
        }
Example #19
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (!args[0].IsList)
            {
                throw new Exception("A list of UVs is required to place the Adaptive Component.");
            }

            FSharpList <Value> uvs = ((Value.List)args[0]).Item;

            var faceRef = ((Value.Container)args[1]).Item as Reference;
            var f       = faceRef == null
                         ? (Face)((Value.Container)args[1]).Item
                         : (Face)dynRevitSettings.Doc.Document.GetElement(faceRef.ElementId).GetGeometryObjectFromReference(faceRef);

            var fs = (FamilySymbol)((Value.Container)args[2]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //mutate
                Element e;
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], typeof(FamilyInstance), out e))
                {
                    ac        = e as FamilyInstance;
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != uvs.Count())
            {
                throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var uv    = (UV)((Value.Container)uvs.ElementAt(i)).Item;
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var peref = dynRevitSettings.Revit.Application.Create.NewPointOnFace(f.Reference, uv);
                point.SetPointElementReference(peref);
                i++;
            }

            return(Value.NewContainer(ac));
        }
Example #20
0
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            var element = (Element)((Value.Container) args[0]).Item;
            var results = FSharpList<Value>.Empty;

            for(int i=args.Count()-1; i>0; i--)
            {
                var paramName = ((Value.String) args[i]).Item;
                var param = element.get_Parameter(paramName);
                if (param != null)
                {
                    var pd = OutPortData[i - 1];
                    switch (param.StorageType)
                    {
                        case StorageType.Double:
                            switch (param.Definition.ParameterType)
                            {
                                case ParameterType.Length:
                                    outPuts[pd] = Value.NewContainer(Units.Length.FromFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                                    break;
                                case ParameterType.Area:
                                    outPuts[pd] = Value.NewContainer(Units.Area.FromSquareFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                                    break;
                                case ParameterType.Volume:
                                    outPuts[pd] = Value.NewContainer(Units.Volume.FromCubicFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                                    break;
                                default:
                                    outPuts[pd] = Value.NewNumber(param.AsDouble());
                                    break;
                            }
                            break;
                        case StorageType.ElementId:
                            outPuts[pd] = FScheme.Value.NewContainer(param.AsElementId());
                            break;
                        case StorageType.Integer:
                            outPuts[pd] = FScheme.Value.NewNumber(param.AsInteger());
                            break;
                        case StorageType.String:
                            if (string.IsNullOrEmpty(param.AsString()))
                            {
                                outPuts[pd] = FScheme.Value.NewString(string.Empty);
                            }
                            else
                            {
                                outPuts[pd] = FScheme.Value.NewString(param.AsString());
                            }
                            break;
                        default:
                            if (string.IsNullOrEmpty(param.AsValueString()))
                            {
                                outPuts[pd] = FScheme.Value.NewString(string.Empty);
                            }
                            else
                            {
                                outPuts[pd] = FScheme.Value.NewString(param.AsValueString());
                            }
                            break;
                    }
                }
            }
        }
Example #21
0
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            //if this element maintains a collcection of references
            //then clear the collection
            if(this is IClearable)
                (this as IClearable).ClearReferences();

            List<FSharpList<Value>> argSets = new List<FSharpList<Value>>();

            //create a zip of the incoming args and the port data
            //to be used for type comparison
            var portComparison = args.Zip(InPortData,
                                          (first, second) => new Tuple<Type, Type>(first.GetType(), second.PortType));
            var listOfListComparison = args.Zip(InPortData, (first, second) => new Tuple<bool, Type>(Utils.IsListOfLists(first), second.PortType));

            //there are more than zero arguments
            //and there is either an argument which does not match its expections
            //OR an argument which requires a list and gets a list of lists
            //AND argument lacing is not disabled
            if (args.Count() > 0 &&
                (portComparison.Any(x => x.Item1 == typeof(Value.List) && x.Item2 != typeof(Value.List)) ||
                listOfListComparison.Any(x => x.Item1 == true && x.Item2 == typeof(Value.List))) &&
                this.ArgumentLacing != LacingStrategy.Disabled)
            {
                //if the argument is of the expected type, then
                //leave it alone otherwise, wrap it in a list
                int j = 0;
                foreach (var arg in args)
                {
                    //incoming value is list and expecting single
                    if (portComparison.ElementAt(j).Item1 == typeof (Value.List) &&
                        portComparison.ElementAt(j).Item2 != typeof (Value.List))
                    {
                        //leave as list
                        argSets.Add(((Value.List)arg).Item);
                    }
                    //incoming value is list and expecting list
                    else
                    {
                        //check if we have a list of lists, if so, then don't wrap
                        if (Utils.IsListOfLists(arg))
                            //leave as list
                            argSets.Add(((Value.List)arg).Item);
                        else
                            //wrap in list
                            argSets.Add(Utils.MakeFSharpList(arg));
                    }
                    j++;
                }

                IEnumerable<IEnumerable<Value>> lacedArgs = null;
                switch (this.ArgumentLacing)
                {
                    case LacingStrategy.First:
                        lacedArgs = argSets.SingleSet();
                        break;
                    case LacingStrategy.Shortest:
                        lacedArgs = argSets.ShortestSet();
                        break;
                    case LacingStrategy.Longest:
                        lacedArgs = argSets.LongestSet();
                        break;
                    case LacingStrategy.CrossProduct:
                        lacedArgs = argSets.CartesianProduct();
                        break;
                }

                //setup an empty list to hold results
                FSharpList<Value> result = FSharpList<Value>.Empty;

                //run the evaluate method for each set of
                //arguments in the cartesian result. do these
                //in reverse order so our cons comes out the right
                //way around
                for (int i = lacedArgs.Count() - 1; i >= 0; i--)
                {
                    var evalResult = Evaluate(Utils.MakeFSharpList(lacedArgs.ElementAt(i).ToArray()));
                    result = FSharpList<Value>.Cons(evalResult, result);
                }

                outPuts[OutPortData[0]] = Value.NewList(result);
            }
            else
            {
                outPuts[OutPortData[0]] = Evaluate(args);
            }

            ValidateConnections();

            if (dynSettings.Controller.UIDispatcher != null && this is IDrawable)
            {
                dynSettings.Controller.UIDispatcher.Invoke(new Action(() => (this as IDrawable).Draw()));
            }
        }
Example #22
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var element = (Element)((Value.Container)args[0]).Item;
            var results = FSharpList <Value> .Empty;

            for (int i = args.Count() - 1; i > 0; i--)
            {
                var paramName = ((Value.String)args[i]).Item;
                var param     = element.get_Parameter(paramName);
                if (param != null)
                {
                    var pd = OutPortData[i - 1];
                    switch (param.StorageType)
                    {
                    case StorageType.Double:
                        switch (param.Definition.ParameterType)
                        {
                        case ParameterType.Length:
                            outPuts[pd] = Value.NewContainer(Units.Length.FromFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                            break;

                        case ParameterType.Area:
                            outPuts[pd] = Value.NewContainer(Units.Area.FromSquareFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                            break;

                        case ParameterType.Volume:
                            outPuts[pd] = Value.NewContainer(Units.Volume.FromCubicFeet(param.AsDouble(), dynSettings.Controller.UnitsManager));
                            break;

                        default:
                            outPuts[pd] = Value.NewNumber(param.AsDouble());
                            break;
                        }
                        break;

                    case StorageType.ElementId:
                        outPuts[pd] = FScheme.Value.NewContainer(param.AsElementId());
                        break;

                    case StorageType.Integer:
                        outPuts[pd] = FScheme.Value.NewNumber(param.AsInteger());
                        break;

                    case StorageType.String:
                        if (string.IsNullOrEmpty(param.AsString()))
                        {
                            outPuts[pd] = FScheme.Value.NewString(string.Empty);
                        }
                        else
                        {
                            outPuts[pd] = FScheme.Value.NewString(param.AsString());
                        }
                        break;

                    default:
                        if (string.IsNullOrEmpty(param.AsValueString()))
                        {
                            outPuts[pd] = FScheme.Value.NewString(string.Empty);
                        }
                        else
                        {
                            outPuts[pd] = FScheme.Value.NewString(param.AsValueString());
                        }
                        break;
                    }
                }
            }
        }
Example #23
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            if (!args[0].IsList)
            {
                throw new Exception("A list of UVs is required to place the Adaptive Component.");
            }

            FSharpList <Value> parameters = ((Value.List)args[0]).Item;

            var curveRef = ((Value.Container)args[1]).Item as Reference;
            var c        = curveRef == null
                         ? (Curve)((Value.Container)args[1]).Item
                         : (Curve)dynRevitSettings.Doc.Document.GetElement(curveRef.ElementId).GetGeometryObjectFromReference(curveRef);

            var fs = (FamilySymbol)((Value.Container)args[2]).Item;

            FamilyInstance ac = null;

            //if the adapative component already exists, then move the points
            if (Elements.Any())
            {
                //...we attempt to fetch it from the document...
                if (dynUtils.TryGetElement(this.Elements[0], out ac))
                {
                    ac.Symbol = fs;
                }
                else
                {
                    //create
                    ac          = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                    Elements[0] = ac.Id;
                }
            }
            else
            {
                //create
                ac = AdaptiveComponentInstanceUtils.CreateAdaptiveComponentInstance(dynRevitSettings.Doc.Document, fs);
                Elements.Add(ac.Id);
            }

            if (ac == null)
            {
                throw new Exception("An adaptive component could not be found or created.");
            }

            IList <ElementId> placePointIds = new List <ElementId>();

            placePointIds = AdaptiveComponentInstanceUtils.GetInstancePlacementPointElementRefIds(ac);

            if (placePointIds.Count() != parameters.Count())
            {
                throw new Exception("The input list of UVs does not have the same number of values required by the adaptive component.");
            }

            // Set the position of each placement point
            int i = 0;

            foreach (ElementId id in placePointIds)
            {
                var t     = ((Value.Number)parameters.ElementAt(i)).Item;
                var point = dynRevitSettings.Doc.Document.GetElement(id) as ReferencePoint;
                var ploc  = new PointLocationOnCurve(PointOnCurveMeasurementType.NonNormalizedCurveParameter, t,
                                                     PointOnCurveMeasureFrom.Beginning);
                var peref = dynRevitSettings.Revit.Application.Create.NewPointOnEdge(c.Reference, ploc);
                point.SetPointElementReference(peref);
                i++;
            }

            return(Value.NewContainer(ac));
        }
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            //THE OLD WAY
            //outPuts[OutPortData[0]] = Evaluate(args);

            //THE NEW WAY
            //if this element maintains a collcection of references
            //then clear the collection
            if (this is IClearable)
                (this as IClearable).ClearReferences();

            List<FSharpList<Value>> argSets = new List<FSharpList<Value>>();

            //create a zip of the incoming args and the port data
            //to be used for type comparison
            var portComparison = args.Zip(InPortData, (first, second) => new Tuple<Type, Type>(first.GetType(), second.PortType));

            //if any value is a list whose expectation is a single
            //do an auto map
            //TODO: figure out a better way to do this than using a lot
            //of specific excludes
            if (args.Count() > 0 &&
                portComparison.Any(x => x.Item1 == typeof(Value.List) &&
                x.Item2 != typeof(Value.List)) &&
                !(this.ArgumentLacing == LacingStrategy.Disabled))
            {
                //if the argument is of the expected type, then
                //leave it alone otherwise, wrap it in a list
                int j = 0;
                foreach (var arg in args)
                {
                    //incoming value is list and expecting single
                    if (portComparison.ElementAt(j).Item1 == typeof(Value.List) &&
                        portComparison.ElementAt(j).Item2 != typeof(Value.List))
                    {
                        //leave as list
                        argSets.Add(((Value.List)arg).Item);
                    }
                    //incoming value is list and expecting list
                    else
                    {
                        //wrap in list
                        argSets.Add(Utils.MakeFSharpList(arg));
                    }
                    j++;
                }

                IEnumerable<IEnumerable<Value>> lacedArgs = null;
                switch (this.ArgumentLacing)
                {
                    case LacingStrategy.First:
                        lacedArgs = argSets.SingleSet();
                        break;
                    case LacingStrategy.Shortest:
                        lacedArgs = argSets.ShortestSet();
                        break;
                    case LacingStrategy.Longest:
                        lacedArgs = argSets.LongestSet();
                        break;
                    case LacingStrategy.CrossProduct:
                        lacedArgs = argSets.CartesianProduct();
                        break;
                }

                //setup an empty list to hold results
                FSharpList<Value> result = FSharpList<Value>.Empty;

                //run the evaluate method for each set of
                //arguments in the cartesian result. do these
                //in reverse order so our cons comes out the right
                //way around
                for (int i = lacedArgs.Count() - 1; i >= 0; i--)
                {
                    var evalResult = Evaluate(Utils.MakeFSharpList(lacedArgs.ElementAt(i).ToArray()));
                    result = FSharpList<Value>.Cons(evalResult, result);
                    runCount++;
                }

                outPuts[OutPortData[0]] = Value.NewList(result);
            }
            else
            {
                outPuts[OutPortData[0]] = Evaluate(args);
                runCount++;
            }
        }
Example #25
0
        public override void Evaluate(FSharpList<Value> args, Dictionary<PortData, Value> outPuts)
        {
            var element = (Element)((Value.Container) args[0]).Item;
            var results = FSharpList<Value>.Empty;

            for(int i=args.Count()-1; i>0; i--)
            {
                var paramName = ((Value.String) args[i]).Item;
                var param = element.get_Parameter(paramName);
                if (param != null)
                {
                    var pd = OutPortData[i - 1];
                    switch (param.StorageType)
                    {
                        case StorageType.Double:
                            outPuts[pd] = FScheme.Value.NewNumber(param.AsDouble());
                            break;
                        case StorageType.ElementId:
                            outPuts[pd] = FScheme.Value.NewContainer(param.AsElementId());
                            break;
                        case StorageType.Integer:
                            outPuts[pd] = FScheme.Value.NewNumber(param.AsInteger());
                            break;
                        case StorageType.String:
                            if (string.IsNullOrEmpty(param.AsString()))
                            {
                                outPuts[pd] = FScheme.Value.NewString(string.Empty);
                            }
                            else
                            {
                                outPuts[pd] = FScheme.Value.NewString(param.AsString());
                            }
                            break;
                        default:
                            if (string.IsNullOrEmpty(param.AsValueString()))
                            {
                                outPuts[pd] = FScheme.Value.NewString(string.Empty);
                            }
                            else
                            {
                                outPuts[pd] = FScheme.Value.NewString(param.AsValueString());
                            }
                            break;
                    }
                }
            }
        }