Example #1
0
        public override void Evaluate(FSharpList <Value> args, Dictionary <PortData, Value> outPuts)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects;
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);

            var xyz = FSharpList <Value> .Empty;
            var u   = FSharpList <Value> .Empty;
            var v   = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    xyz = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xyz);

                    u = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), u);

                    v = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), v);

                    pts.Add(ir.XYZPoint);
                }
            }

            outPuts[_vPort]      = Value.NewList(v);
            outPuts[_uPort]      = Value.NewList(u);
            outPuts[_xyzPort]    = Value.NewList(xyz);
            outPuts[_resultPort] = Value.NewString(result.ToString());
        }
Example #2
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var crv1 = (Curve)((Value.Container)args[0]).Item;
            var crv2 = (Curve)((Value.Container)args[1]).Item;

            IntersectionResultArray xsects = new IntersectionResultArray();
            SetComparisonResult     result = crv1.Intersect(crv2, out xsects);
            var results = FSharpList <Value> .Empty;

            var xsect_results = FSharpList <Value> .Empty;

            if (xsects != null)
            {
                foreach (IntersectionResult ir in xsects)
                {
                    var xsect = FSharpList <Value> .Empty;
                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.U), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewNumber(ir.UVPoint.V), xsect);

                    xsect = FSharpList <Value> .Cons(Value.NewContainer(ir.XYZPoint), xsect);

                    xsect_results = FSharpList <Value> .Cons(Value.NewList(xsect), xsect_results);

                    pts.Add(ir.XYZPoint);
                }
            }
            results = FSharpList <Value> .Cons(Value.NewList(xsect_results), results);

            results = FSharpList <Value> .Cons(Value.NewString(result.ToString()), results);

            return(Value.NewList(results));
        }
Example #3
0
        private async Task <bool> TryCompileFSharpToStreamAsync(MemoryStream assemblyStream, IWorkSession session, IList <Diagnostic> diagnostics, CancellationToken cancellationToken)
        {
            var fsharp = session.FSharp();

            // GetLastParseResults are guaranteed to be available here as MirrorSharp's SlowUpdate does the parse
            var parsed = fsharp.GetLastParseResults();

            using (var virtualAssemblyFile = FSharpFileSystem.RegisterVirtualFile(assemblyStream)) {
                var compiled = await FSharpAsync.StartAsTask(fsharp.Checker.Compile(
                                                                 // ReSharper disable once PossibleNullReferenceException
                                                                 FSharpList <Ast.ParsedInput> .Cons(parsed.ParseTree.Value, FSharpList <Ast.ParsedInput> .Empty),
                                                                 "_", virtualAssemblyFile.Name,
                                                                 fsharp.AssemblyReferencePathsAsFSharpList,
                                                                 pdbFile: null,
                                                                 executable: false,
                                                                 noframework: true
                                                                 ), null, cancellationToken).ConfigureAwait(false);

                foreach (var error in compiled.Item1)
                {
                    // no reason to add warnings as check would have added them anyways
                    if (error.Severity.Tag == FSharpErrorSeverity.Tags.Error)
                    {
                        diagnostics.Add(fsharp.ConvertToDiagnostic(error));
                    }
                }
                return(virtualAssemblyFile.Stream.Length > 0);
            }
        }
Example #4
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var    domain = (DSCoreNodes.Domain2D)((FScheme.Value.Container)args[0]).Item;
            double ui     = ((FScheme.Value.Number)args[1]).Item;
            double vi     = ((FScheme.Value.Number)args[2]).Item;
            double us     = domain.USpan / ui;
            double vs     = domain.VSpan / vi;

            FSharpList <FScheme.Value> result = FSharpList <FScheme.Value> .Empty;

            for (int i = 0; i <= ui; i++)
            {
                double u = domain.Min.x() + i * us;

                for (int j = 0; j <= vi; j++)
                {
                    double v = domain.Min.y() + j * vs;

                    result = FSharpList <FScheme.Value> .Cons(
                        FScheme.Value.NewContainer(new UV(u, v)),
                        result
                        );
                }
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            if (SelectedIndex < 0)
            {
                throw new Exception("Please select a mesh node.");
            }

            var node_name = Items[SelectedIndex].Name;

            //             if (InPorts[0].IsConnected)
            //             {
            //                 // send the to the connected node
            //                 return FScheme.Value.NewString(node_name);
            //             }

            var result = FSharpList <FScheme.Value> .Empty;

            if (OutPorts[0].IsConnected)
            {
                // get the data from the connected node
                DynamoMaya.Contract.IService s        = MayaCommunication.openChannelToMaya();
                Point3DCollection            vertices = s.receiveVertexPositionsFromMaya(node_name);

                foreach (Point3D v in vertices)
                {
                    XYZ pt = new XYZ(v.X, v.Y, v.Z);
                    result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);
                }

                MayaCommunication.closeChannelToMaya(s);
            }

            return(FScheme.Value.NewList(ListModule.Reverse(result)));
        }
Example #6
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            ParticleSystem particleSystem = (ParticleSystem)((Value.Container)args[0]).Item;

            var result = FSharpList <Value> .Empty;

            ParticleSpring s;
            Particle       springEnd1;
            Particle       springEnd2;
            XYZ            springXYZ1;
            XYZ            springXYZ2;
            Line           springLine;

            //create a geometry curve from each spring
            for (int i = 0; i < particleSystem.numberOfSprings(); i++)
            {
                s          = particleSystem.getSpring(i);
                springEnd1 = s.getOneEnd();
                springEnd2 = s.getTheOtherEnd();

                springXYZ1 = springEnd1.getPosition();
                springXYZ2 = springEnd2.getPosition();
                springLine = dynRevitSettings.Doc.Application.Application.Create.NewLineBound(springXYZ1, springXYZ2);

                result = FSharpList <Value> .Cons(Value.NewContainer(springLine), result);
            }

            return(Value.NewList(result));
        }
Example #7
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input  = args[0];
            var result = FSharpList <Value> .Empty;

            if (input.IsList)
            {
                var ptList = (input as Value.List).Item;
                int length = ptList.Length;

                var verts = new List <Vertex3>();

                for (int i = 0; i < length; i++)
                {
                    var pt   = (XYZ)((Value.Container)ptList[i]).Item;
                    var vert = new Vertex3(pt.X, pt.Y, pt.Z);
                    verts.Add(vert);
                }

                // make triangulation
                var triResult = DelaunayTriangulation <Vertex3, Tetrahedron> .Create(verts);

                _tessellationLines.Clear();

                // make edges
                foreach (var cell in triResult.Cells)
                {
                    foreach (var face in cell.MakeFaces())
                    {
                        var start1 = cell.Vertices[face[0]].ToXYZ();
                        var end1   = cell.Vertices[face[1]].ToXYZ();

                        var start2 = cell.Vertices[face[1]].ToXYZ();
                        var end2   = cell.Vertices[face[2]].ToXYZ();

                        var start3 = cell.Vertices[face[2]].ToXYZ();
                        var end3   = cell.Vertices[face[0]].ToXYZ();

                        var l1 = this.UIDocument.Application.Application.Create.NewLineBound(start1, end1);
                        _tessellationLines.Add(l1);

                        var l2 = this.UIDocument.Application.Application.Create.NewLineBound(start2, end2);
                        _tessellationLines.Add(l2);

                        var l3 = this.UIDocument.Application.Application.Create.NewLineBound(start3, end3);
                        _tessellationLines.Add(l3);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l1), result);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l2), result);

                        result = FSharpList <Value> .Cons(Value.NewContainer(l3), result);
                    }
                }

                return(Value.NewList(result));
            }

            return(Value.NewList(result));
        }
        private void ActivateNewChunk()
        {
            chunks = FSharpList <T[]> .Cons(chunk, chunks);

            chunk    = new T[Math.Max(InitialSize, Math.Min(chunk.Length * 2, MaxChunkSize))];
            chunkPos = 0;
        }
Example #9
0
        public void XYZFromReferencePoint()
        {
            var model = dynSettings.Controller.DynamoModel;

            string samplePath = Path.Combine(_testPath, @".\XYZFromReferencePoint.dyn");
            string testPath   = Path.GetFullPath(samplePath);

            model.Open(testPath);
            ReferencePoint rp;

            using (_trans = new Transaction(dynRevitSettings.Doc.Document))
            {
                _trans.Start("Create a reference point.");

                rp = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ());

                _trans.Commit();
            }
            FSharpList <Value> args = FSharpList <Value> .Empty;

            args = FSharpList <Value> .Cons(Value.NewContainer(rp), args);

            //find the XYZFromReferencePoint node
            var node = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is dynXYZFromReferencePoint).First();

            Value v = ((dynNodeWithOneOutput)node).Evaluate(args);

            Assert.IsInstanceOf(typeof(XYZ), ((Value.Container)v).Item);
        }
Example #10
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var pts = (args[0] as Value.List).Item;

            if (pts.Length < 3)
            {
                throw new Exception("3 or more XYZs are necessary to form the best fit plane.");
            }

            var        ptList = dynBestFitLine.AsGenericList <XYZ>(pts);
            XYZ        meanPt;
            List <XYZ> orderedEigenvectors;

            dynBestFitLine.PrincipalComponentsAnalysis(ptList, out meanPt, out orderedEigenvectors);

            var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]);

            var results = FSharpList <Value> .Empty;

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

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

            return(Value.NewList(results));
        }
Example #11
0
    public static int main(string[] argv)
    {
        IDisposable disposable;

        using (Program.disposable()) {
            Console.WriteLine("Hello 1");
            disposable = Program.disposable();
        }
        using (disposable) {
            IEnumerable <int> seq = getSeq();
            foreach (int item in seq)
            {
                Console.WriteLine(item);
            }
            FSharpList <int> fSharpList = FSharpList <int> .Cons(1, FSharpList <int> .Empty);

            for (FSharpList <int> tailOrNull = fSharpList.TailOrNull; tailOrNull != null; tailOrNull = fSharpList.TailOrNull)
            {
                int headOrDefault = fSharpList.HeadOrDefault;
                Console.WriteLine(headOrDefault);
                fSharpList = tailOrNull;
            }
            int[] array = new int[1] {
                1
            };
            for (int headOrDefault = 0; headOrDefault < array.Length; headOrDefault++)
            {
                Console.WriteLine(array[headOrDefault]);
            }
            return(0);
        }
    }
Example #12
0
        public static FSharpList <RankedTree <a> > insertTree <a>(IComparer <a> comparer, RankedTree <a> t, FSharpList <RankedTree <a> > ts)
        {
            while (true)
            {
                FSharpList <RankedTree <a> > fsharpList1 = ts;
                if (fsharpList1.get_TailOrNull() != null)
                {
                    FSharpList <RankedTree <a> > fsharpList2 = fsharpList1;
                    FSharpList <RankedTree <a> > tailOrNull  = fsharpList2.get_TailOrNull();
                    RankedTree <a> headOrDefault             = fsharpList2.get_HeadOrDefault();
                    if (BinomialHeap.rank <a>(t) >= BinomialHeap.rank <a>(headOrDefault))
                    {
                        IComparer <a>  comparer1  = comparer;
                        RankedTree <a> rankedTree = BinomialHeap.link <a>(comparer, t, headOrDefault);
                        ts       = tailOrNull;
                        t        = rankedTree;
                        comparer = comparer1;
                    }
                    else
                    {
                        goto label_3;
                    }
                }
                else
                {
                    break;
                }
            }
            return(FSharpList <RankedTree <a> > .Cons(t, FSharpList <RankedTree <a> > .get_Empty()));

label_3:
            return(FSharpList <RankedTree <a> > .Cons(t, ts));
        }
Example #13
0
        void DispatchBlock()
        {
            try
            {
                _Hasher.Pause("dispatching block");

                MinerTrace.Information($"dispatching block with {_ValidatedTxs.Count()} txs");

                var txs = FSharpList <Types.Transaction> .Cons(_Coinbase, ListModule.OfSeq(_ValidatedTxs.Select(TransactionValidation.unpoint)));

                var block = new Types.Block(_Header, txs);


                var result = new HandleBlockAction(block).Publish().Result.BkResultEnum;

                if (result == BlockVerificationHelper.BkResultEnum.Accepted)
                {
                    if (OnMined != null)
                    {
                        OnMined(block);
                    }
                }
                else
                {
                    Reset();
                }

                MinerTrace.Information($"  block {block.header.blockNumber} is " + result);
            } catch (Exception e)
            {
                MinerTrace.Error("Dispatch block exception", e);
            }
        }
Example #14
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var input  = args[0];
            var result = FSharpList <Value> .Empty;

            if (input.IsList)
            {
                var uvList = (input as Value.List).Item;
                int length = uvList.Length;

                var verts = new List <Vertex2>();

                for (int i = 0; i < length; i++)
                {
                    UV      uv   = (UV)((Value.Container)uvList[i]).Item;
                    Vertex2 vert = new Vertex2(uv.U, uv.V);
                    verts.Add(vert);
                }

                var voronoiMesh = VoronoiMesh.Create <Vertex2, Cell2>(verts);

                _tessellationLines.Clear();

                object arg1 = ((Value.Container)args[1]).Item;
                var    f    = arg1 as Face;

                if (f != null)
                {
                    foreach (VoronoiEdge <Vertex2, Cell2> edge in voronoiMesh.Edges)
                    {
                        var from = edge.Source.Circumcenter;
                        var to   = edge.Target.Circumcenter;

                        var uv1 = new UV(from.X, from.Y);
                        var uv2 = new UV(to.X, to.Y);

                        if (!f.IsInside(uv1) || !f.IsInside(uv2))
                        {
                            continue;
                        }

                        var start = f.Evaluate(uv1);
                        var end   = f.Evaluate(uv2);

                        if (start.DistanceTo(end) > 0.1)
                        {
                            var l = this.UIDocument.Application.Application.Create.NewLineBound(start, end);
                            _tessellationLines.Add(l);

                            result = FSharpList <Value> .Cons(Value.NewContainer(l), result);
                        }
                    }
                }

                return(Value.NewList(result));
            }

            return(Value.NewList(result));
        }
 private FSharpList <T> CopyToList(FSharpList <T> result, T[] chunk, int length)
 {
     for (var i = length - 1; i >= 0; --i)
     {
         result = FSharpList <T> .Cons(chunk[i], result);
     }
     return(result);
 }
 public static Types.Transaction AddInput(this Types.Transaction tx, Types.Outpoint outpoint)
 {
     return(new Types.Transaction(tx.version,
                                  FSharpList <Types.Outpoint> .Cons(outpoint, tx.inputs),
                                  tx.witnesses,
                                  tx.outputs,
                                  tx.contract));
 }
Example #17
0
        public override void Evaluate(FSharpList <FScheme.Value> args, Dictionary <PortData, FScheme.Value> outPuts)
        {
            var origin    = (XYZ)((FScheme.Value.Container)args[0]).Item;
            var direction = (XYZ)((FScheme.Value.Container)args[1]).Item;
            var rayLimit  = ((FScheme.Value.Number)args[2]).Item;
            var view      = (View3D)((FScheme.Value.Container)args[3]).Item;

            XYZ startpt  = origin;
            int rayCount = 0;

            var bouncePts      = FSharpList <FScheme.Value> .Empty;
            var bounceElements = FSharpList <FScheme.Value> .Empty;

            bouncePts = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(origin), bouncePts);

            for (int ctr = 1; ctr <= rayLimit; ctr++)
            {
                var referenceIntersector = new ReferenceIntersector(view);
                IList <ReferenceWithContext> references = referenceIntersector.Find(startpt, direction);
                ReferenceWithContext         rClosest   = null;
                rClosest = FindClosestReference(references);
                if (rClosest == null)
                {
                    break;
                }
                else
                {
                    var reference        = rClosest.GetReference();
                    var referenceElement = dynRevitSettings.Doc.Document.GetElement(reference);
                    bounceElements = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(referenceElement), bounceElements);

                    var referenceObject = referenceElement.GetGeometryObjectFromReference(reference);
                    var endpt           = reference.GlobalPoint;
                    if (startpt.IsAlmostEqualTo(endpt))
                    {
                        break;
                    }
                    else
                    {
                        rayCount = rayCount + 1;
                        currFace = referenceObject as Face;
                        var endptUV    = reference.UVPoint;
                        var FaceNormal = currFace.ComputeDerivatives(endptUV).BasisZ;                          // face normal where ray hits
                        FaceNormal = rClosest.GetInstanceTransform().OfVector(FaceNormal);                     // transformation to get it in terms of document coordinates instead of the parent symbol
                        var directionMirrored = direction - 2 * direction.DotProduct(FaceNormal) * FaceNormal; //http://www.fvastro.org/presentations/ray_tracing.htm
                        direction = directionMirrored;                                                         // get ready to shoot the next ray
                        startpt   = endpt;

                        bouncePts = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(endpt), bouncePts);
                    }
                }
            }
            bouncePts.Reverse();
            bounceElements.Reverse();

            outPuts[intersections] = FScheme.Value.NewList(bouncePts);
            outPuts[elements]      = FScheme.Value.NewList(bounceElements);
        }
Example #18
0
        public void Match_non_empty()
        {
            var a = FSharpList <int> .Cons(5, FSharpList <int> .Empty);

            var s = a.Match(() => "empty",
                            (x, xs) => "head is " + x + ", tail is " + (xs.IsEmpty ? "empty" : "non-empty"));

            Assert.AreEqual("head is 5, tail is empty", s);
        }
Example #19
0
        public void Cons()
        {
            var a = FSharpList.Create(1, 2, 3);
            var b = a.Cons(0);
            var c = FSharpList.Cons(a, 0);

            Assert.AreEqual(FSharpList.Create(0, 1, 2, 3), b);
            Assert.AreEqual(FSharpList.Create(0, 1, 2, 3), c);
        }
Example #20
0
        //Function used to construct our expression. This is used to properly create a curried function call, which will be
        //able to support partial function application.
        protected Expression ToExpression(
            Expression function,
            IEnumerable <string> parameters,
            int expectedArgs,
            Dictionary <INode, string> symbols,
            Dictionary <INode, List <INode> > letEntries,
            HashSet <string> initializedIds,
            HashSet <string> conditionalIds)
        {
            //If no arguments have been supplied and if we are expecting arguments, simply return the function.
            if (arguments.Keys.Count == 0 && expectedArgs > 0)
            {
                return(function);
            }

            //If the number of expected arguments is greater than how many arguments have been supplied, we perform a partial
            //application, returning a function which takes the remaining arguments.
            if (arguments.Keys.Count < expectedArgs)
            {
                //Get all of the missing arguments.
                IEnumerable <string> missingArgs = parameters.Where(
                    input => !arguments.ContainsKey(input)
                    );
                //Return a function that...
                return(Utils.MakeAnon(
                           //...takes all of the missing arguments...
                           missingArgs.ToList(),
                           Expression.NewList_E(
                               FSharpList <Expression> .Cons(
                                   //...and calls this function...
                                   function,
                                   Utils.SequenceToFSharpList(
                                       //...with the arguments which were supplied.
                                       parameters.Select(
                                           input =>
                                           missingArgs.Contains(input)
                                    ? Expression.NewId(input)
                                    : arguments[input].compile(
                                               symbols, letEntries, initializedIds, conditionalIds)))))));
            }

            //If all the arguments were supplied, just return a standard function call expression.
            else
            {
                return(Expression.NewList_E(
                           FSharpList <Expression> .Cons(
                               function,
                               Utils.SequenceToFSharpList(
                                   parameters.Select(
                                       input => arguments[input].compile(
                                           symbols, letEntries, initializedIds, conditionalIds))
                                   )
                               )
                           ));
            }
        }
Example #21
0
        private OrderCreated BuildOrderCreated(Guid orderId, Guid basketId, int numberOfOrderLines, int pricePerProduct = 100)
        {
            var orderLines = FSharpList <OrderLine> .Empty;

            for (var i = 0; i < numberOfOrderLines; i++)
            {
                orderLines = FSharpList <OrderLine> .Cons(new OrderLine(Guid.NewGuid(), "Line " + i, pricePerProduct, pricePerProduct, 1), orderLines);
            }
            return(new OrderCreated(orderId, basketId, orderLines));
        }
Example #22
0
        private FSharpList <string> ToFSharpList(ImmutableArray <string> assemblyReferencePaths)
        {
            var list = FSharpList <string> .Empty;

            for (var i = assemblyReferencePaths.Length - 1; i >= 0; i--)
            {
                list = FSharpList <string> .Cons(assemblyReferencePaths[i], list);
            }
            return(list);
        }
Example #23
0
        /// <summary>
        /// Converts the given IEnumerable into an FSharp list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="seq"></param>
        /// <returns></returns>
        public static FSharpList <T> SequenceToFSharpList <T>(IEnumerable <T> seq)
        {
            FSharpList <T> result = FSharpList <T> .Empty;

            foreach (T element in seq.Reverse <T>())
            {
                result = FSharpList <T> .Cons(element, result);
            }
            return(result);
        }
Example #24
0
        /// <summary>
        /// Makes an FSharp list from all given arguments.
        /// </summary>
        public static FSharpList <T> MakeFSharpList <T>(params T[] ar)
        {
            FSharpList <T> foo = FSharpList <T> .Empty;

            for (int n = ar.Length - 1; n >= 0; n--)
            {
                foo = FSharpList <T> .Cons(ar[n], foo);
            }
            return(foo);
        }
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        public TriggerResult Execute()
        {
            if (Operators.DefaultArg(botTriggerParameters.GetParameter <bool>("execute"), false))
            {
                FSharpList <MyBotParameter> myBotParameters = FSharpList <MyBotParameter> .Cons(new MyBotParameter("OpenBetPosition.Stake", 2.0), FSharpList <MyBotParameter> .Empty);

                return(TriggerResult.NewExecuteActionBotOnSelectionWithParameters(selection, myBotParameters));
            }

            return(TriggerResult.EndExecution);
        }
 /// <summary>
 /// CreateFSharpList
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="input"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 private static FSharpList <T> CreateFSharpList <T>(IList <T> input, int index)
 {
     if (index >= input.Count)
     {
         return(FSharpList <T> .Empty);
     }
     else
     {
         return(FSharpList <T> .Cons(input[index], CreateFSharpList(input, index + 1)));
     }
 }
Example #27
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var symbol    = (FamilySymbol)((FScheme.Value.Container)args[0]).Item;
            var collector = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            collector.OfClass(typeof(FamilyInstance));
            var fis     = collector.ToElements().Where(x => x is FamilyInstance).Cast <FamilyInstance>().Where(x => x.Symbol.Name == symbol.Name);
            var results = fis.Aggregate(FSharpList <FScheme.Value> .Empty,
                                        (current, fi) => FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(fi), current));

            return(FScheme.Value.NewList(Utils.SequenceToFSharpList(results.Reverse())));
        }
Example #28
0
File: XYZ.cs Project: l2obin/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            double xi;                                 //, x0, xs;

            xi = ((FScheme.Value.Number)args[1]).Item; // Number
            xi = Math.Round(xi);
            if (xi < System.Double.Epsilon)
            {
                throw new Exception("The point count must be larger than 0.");
            }
            xi = xi - 1;

            //x0 = ((Value.Number)args[2]).Item;// Starting Coord
            //xs = ((Value.Number)args[3]).Item;// Spacing


            var result = FSharpList <FScheme.Value> .Empty;

            Curve crvRef = null;

            if (((FScheme.Value.Container)args[0]).Item is CurveElement)
            {
                var c = (CurveElement)((FScheme.Value.Container)args[0]).Item; // Curve
                crvRef = c.GeometryCurve;
            }
            else
            {
                crvRef = (Curve)((FScheme.Value.Container)args[0]).Item; // Curve
            }

            double t = 0;

            if (xi < System.Double.Epsilon)
            {
                var pt = !XyzOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);

                return(FScheme.Value.NewList(
                           ListModule.Reverse(result)
                           ));
            }

            for (int xCount = 0; xCount <= xi; xCount++)
            {
                t = xCount / xi; // create normalized curve param by dividing current number by total number
                var pt = !XyzOnCurveOrEdge.curveIsReallyUnbound(crvRef) ? crvRef.Evaluate(t, true) : crvRef.Evaluate(t * crvRef.Period, false);
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(pt), result);
            }

            return(FScheme.Value.NewList(
                       ListModule.Reverse(result)
                       ));
        }
Example #29
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 #30
0
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            Solid thisSolid  = (Solid)((FScheme.Value.Container)args[0]).Item;
            Line  selectLine = (Line)((FScheme.Value.Container)args[1]).Item;

            FaceArray faceArr  = thisSolid.Faces;
            var       thisEnum = faceArr.GetEnumerator();

            SortedList <double, Autodesk.Revit.DB.Face> intersectingFaces = new SortedList <double, Autodesk.Revit.DB.Face>();

            for (; thisEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face  thisFace    = (Autodesk.Revit.DB.Face)thisEnum.Current;
                IntersectionResultArray resultArray = null;

                SetComparisonResult resultIntersect = thisFace.Intersect(selectLine, out resultArray);
                if (resultIntersect != SetComparisonResult.Overlap)
                {
                    continue;
                }
                bool   first   = true;
                double linePar = -1.0;
                foreach (IntersectionResult ir in resultArray)
                {
                    double irPar = ir.Parameter;
                    if (first == true)
                    {
                        linePar = irPar;
                        first   = false;
                    }
                    else if (irPar < linePar)
                    {
                        linePar = irPar;
                    }
                }
                intersectingFaces.Add(linePar, thisFace);
            }

            var result = FSharpList <FScheme.Value> .Empty;

            var intersectingFacesEnum = intersectingFaces.Reverse().GetEnumerator();

            for (; intersectingFacesEnum.MoveNext();)
            {
                Autodesk.Revit.DB.Face faceObj = intersectingFacesEnum.Current.Value;
                result = FSharpList <FScheme.Value> .Cons(FScheme.Value.NewContainer(faceObj), result);
            }

            return(FScheme.Value.NewList(result));
        }