예제 #1
0
        public void VectorAnalysisDataByPointsAndResults_BadArgs()
        {
            Assert.Throws <ArgumentNullException>(
                () =>
                VectorAnalysisData.ByPointsAndResults(
                    null,
                    TestResultNames(),
                    TestVectorResults()));

            Assert.Throws <ArgumentNullException>(
                () =>
                VectorAnalysisData.ByPointsAndResults(
                    TestPoints(),
                    null,
                    TestVectorResults()));

            Assert.Throws <ArgumentNullException>(
                () =>
                VectorAnalysisData.ByPointsAndResults(
                    TestPoints(),
                    TestResultNames(),
                    null));

            Assert.Throws <ArgumentException>(
                () =>
                VectorAnalysisData.ByPointsAndResults(
                    TestPoints(),
                    new [] { "cat", "foo" },
                    TestVectorResults()));
        }
예제 #2
0
        public void ByViewAndVectorAnalysisData_ValidArgs()
        {
            var samplePoints = new[]
            {
                Point.ByCoordinates(0, 2, 4),
                Point.ByCoordinates(0, 7, 4),
                Point.ByCoordinates(0, 19, 4)
            };

            var sampleValues = new[]
            {
                Vector.ByCoordinates(0, 2, 4),
                Vector.ByCoordinates(0, 7, 4),
                Vector.ByCoordinates(0, 19, 4)
            };

            var data = VectorAnalysisData.ByPointsAndResults(
                samplePoints,
                new List <string>()
            {
                "Test vector data."
            },
                new List <IList <Vector> >()
            {
                sampleValues
            });

            var doc  = Document.Current;
            var grid = VectorAnalysisDisplay.ByViewAndVectorAnalysisData(doc.ActiveView, new [] { data });

            Assert.NotNull(grid);
        }
예제 #3
0
        public void ByViewAndVectorAnalysisData_BadArgs()
        {
            var samplePoints = new[]
            {
                Point.ByCoordinates(0, 2, 4),
                Point.ByCoordinates(0, 7, 4),
                Point.ByCoordinates(0, 19, 4)
            };

            var sampleValues = new[]
            {
                Vector.ByCoordinates(0, 2, 4),
                Vector.ByCoordinates(0, 7, 4),
                Vector.ByCoordinates(0, 19, 4)
            };

            var data = VectorAnalysisData.ByPointsAndResults(
                samplePoints,
                new List <string>()
            {
                "Test vector data."
            },
                new List <IList <Vector> >()
            {
                sampleValues
            });

            var doc = Document.Current;

            Assert.Throws(typeof(System.ArgumentNullException), () => VectorAnalysisDisplay.ByViewAndVectorAnalysisData(null, new [] { data }));
            Assert.Throws(typeof(System.ArgumentNullException), () => VectorAnalysisDisplay.ByViewAndVectorAnalysisData(doc.ActiveView, null));
            Assert.Throws(typeof(System.Exception), () => VectorAnalysisDisplay.ByViewAndVectorAnalysisData(doc.ActiveView, new VectorAnalysisData[] {}));
        }
예제 #4
0
        public void VectorAnalysisDataByPoints_ValidArgs()
        {
            var vad = VectorAnalysisData.ByPoints(TestPoints());

            Assert.NotNull(vad);
            Assert.NotNull(vad.CalculationLocations);
            Assert.AreEqual(vad.CalculationLocations.Count(), 3);
        }
예제 #5
0
        public void VectorAnalysisDataByPointsAndResults_ValidArgs()
        {
            var vad = VectorAnalysisData.ByPointsAndResults(TestPoints(), TestResultNames(), TestVectorResults());

            Assert.NotNull(vad);
            Assert.NotNull(vad.CalculationLocations);
            Assert.NotNull(vad.Results);
            Assert.AreEqual(vad.Results.Count, 3);
        }
예제 #6
0
        /// <summary>
        /// Show a Vector Analysis Display in the Revit view.
        /// </summary>
        /// <param name="view">The view into which you want to draw the analysis results.</param>
        /// <param name="samplePoints">The locations at which you want to create analysis values.</param>
        /// <param name="samples">The analysis values at the given locations.</param>
        /// <param name="name">An optional analysis results name to show on the results legend.</param>
        /// <param name="description">An optional analysis results description to show on the results legend.</param>
        /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param>
        /// <returns>A VectorAnalysisDisplay object.</returns>
        public static VectorAnalysisDisplay ByViewPointsAndVectorValues(View view,
                                                                        Autodesk.DesignScript.Geometry.Point[] sampleLocations, Vector[] samples,
                                                                        string name = "", string description = "", Type unitType = null)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (sampleLocations == null)
            {
                throw new ArgumentNullException("samplePoints");
            }

            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }

            if (sampleLocations.Length != samples.Length)
            {
                throw new Exception("The number of sample points and number of samples must be the same");
            }

            if (string.IsNullOrEmpty(name))
            {
                name = Resource1.AnalysisResultsDefaultName;
            }

            if (string.IsNullOrEmpty(description))
            {
                description = Resource1.AnalysisResultsDefaultDescription;
            }

            var data = VectorAnalysisData.ByPointsAndResults(sampleLocations, new List <string> {
                "Dynamo Data"
            }, new List <IList <Vector> > {
                samples
            });

            return(new VectorAnalysisDisplay(view.InternalView, new List <VectorAnalysisData>()
            {
                data
            }, name, description, unitType));
        }
예제 #7
0
        /// <summary>
        /// Set the spatial field values for the current spatial field primitive.  The two
        /// input sequences should be of the same length.
        /// </summary>
        /// <param name="sampleLocations"></param>
        /// <param name="samples"></param>
        private void InternalSetSpatialFieldValues(int primitiveId, VectorAnalysisData data, string schemaName, string description, Type unitType)
        {
            var values = data.Results.Values;

            var height = values.First().Count();
            var width  = values.Count();

            // Transpose and convert the analysis values to a special Revit type
            var valList = new List <VectorAtPoint>();

            for (int i = 0; i < height; i++)
            {
                var lst = new List <XYZ>()
                {
                };

                for (int j = 0; j < width; j++)
                {
                    lst.Add(values.ElementAt(j).ElementAt(i).ToXyz());
                }
                valList.Add(new VectorAtPoint(lst));
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            var sampleValues = new FieldValues(valList);

            // Convert the sample points to a special Revit Type
            var samplePts = new FieldDomainPointsByXYZ(data.CalculationLocations.Select(p => p.ToXyz()).ToList());

            // Get the analysis results schema
            var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType);

            // Update the values
            SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex);

            TransactionManager.Instance.TransactionTaskDone();
        }
예제 #8
0
 public void VectorAnalysisdataByPoint_BadArgs()
 {
     Assert.Throws <ArgumentNullException>(() => VectorAnalysisData.ByPoints(null));
 }
예제 #9
0
        /// <summary>
        /// Set the spatial field values for the current spatial field primitive.  The two 
        /// input sequences should be of the same length.
        /// </summary>
        /// <param name="sampleLocations"></param>
        /// <param name="samples"></param>
        private void InternalSetSpatialFieldValues(int primitiveId, VectorAnalysisData data, string schemaName, string description, Type unitType)
        {
            var values = data.Results.Values;

            var height = values.First().Count();
            var width = values.Count();

            // Transpose and convert the analysis values to a special Revit type
            var valList = new List<VectorAtPoint>();
            for (int i = 0; i < height; i++)
            {
                var lst = new List<XYZ>() { };

                for (int j = 0; j < width; j++)
                {
                    lst.Add(values.ElementAt(j).ElementAt(i).ToXyz());
                }
                valList.Add(new VectorAtPoint(lst));
            }

            TransactionManager.Instance.EnsureInTransaction(Document);

            var sampleValues = new FieldValues(valList);

            // Convert the sample points to a special Revit Type
            var samplePts = new FieldDomainPointsByXYZ(data.CalculationLocations.Select(p=>p.ToXyz()).ToList());

            // Get the analysis results schema
            var schemaIndex = GetAnalysisResultSchemaIndex(schemaName, description, unitType);

            // Update the values
            SpatialFieldManager.UpdateSpatialFieldPrimitive(primitiveId, samplePts, sampleValues, schemaIndex);

            TransactionManager.Instance.TransactionTaskDone();
        }
예제 #10
0
        /// <summary>
        /// Show a Vector Analysis Display in the Revit view.
        /// </summary>
        /// <param name="view">The view into which you want to draw the analysis results.</param>
        /// <param name="data">A list of VectorAnalysisData objects.</param>
        /// <param name="name">An optional analysis results name to show on the results legend.</param>
        /// <param name="description">An optional analysis results description to show on the results legend.</param>
        /// <param name="unitType">An optional Unit type to provide conversions in the analysis results.</param>
        /// <returns>A VectorAnalysisDisplay object.</returns>
        public static VectorAnalysisDisplay ByViewAndVectorAnalysisData(View view,
                        VectorAnalysisData[] data,
            string name = "", string description = "", Type unitType = null)
        {

            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (!data.Any())
            {
                throw new Exception("There is no input data.");
            }

            if (string.IsNullOrEmpty(name))
            {
                name = Resource1.AnalysisResultsDefaultName;
            }

            if (string.IsNullOrEmpty(description))
            {
                description = Resource1.AnalysisResultsDefaultDescription;
            }

            return new VectorAnalysisDisplay(view.InternalView, data, name, description, unitType);
        }