Exemplo n.º 1
0
        private static double GetValueFromSpaceSyntax(SpaceSyntax spaceSyntax, int column, int row)
        {
            foreach (CellIndex cellIndex in spaceSyntax.CellIndices)
            {
                if (cellIndex.X == column && cellIndex.Y == row)
                {
                    return(cellIndex.Value);
                }
            }

            return(spaceSyntax.MinValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method creates points from the space syntax meta data and maps the cell
        /// indices value to those points.
        /// Note: If the provided face was aquired by user selection, the face.Reference is null,
        /// and the Reference, which is returned by the selection must be passed to this method.
        /// </summary>
        /// <param name="doc">the document of the active view</param>
        /// <param name="spaceSyntax">the object parsed from xml</param>
        /// <param name="face">the face of the a floor on which it i</param>
        /// <param name="faceReference">the reference to the face</param>
        /// <returns>whether the computation succeeded or was</returns>
        public static void CreateSpaceSyntaxAnalysisResult(Document doc, SpaceSyntax spaceSyntax, Face face, Reference faceReference)
        {
            SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView);

            if (sfm == null)
            {
                sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView, 1);
            }

            var uvPts      = new List <UV>();
            var doubleList = new List <double>();
            var valList    = new List <ValueAtPoint>();

            // we map u to x and v to y
            var localOriginInGlobalVector = face.Evaluate(new UV(0.0, 0.0));
            var matrixAInverted           = CalculateMatrixForGlobalToLocalCoordinateSystem(face);

            double deltaX = Math.Abs(spaceSyntax.MinX - spaceSyntax.MaxX) / spaceSyntax.DomainColumns;
            double deltaY = Math.Abs(spaceSyntax.MinY - spaceSyntax.MaxY) / spaceSyntax.DomainRows;

            double minX = spaceSyntax.MinX + deltaX / 2.0;
            double minY = spaceSyntax.MinY + deltaY / 2.0;

            for (double y = minY, i = 1.0; y < spaceSyntax.MaxY; y += deltaY, i += 1.0)
            {
                for (double x = minX, j = 1.0; x < spaceSyntax.MaxX; x += deltaX, j += 1.0)
                {
                    var globalPoint = new XYZ(x, y, 0.0); // z-coordinate is irrelevant, since the UV space is parallel
                    var localUV     = GlobalToLocalCoordinate(matrixAInverted, localOriginInGlobalVector, globalPoint);

                    if (face.IsInside(localUV))
                    {
                        uvPts.Add(localUV);
                        doubleList.Add(GetValueFromSpaceSyntax(spaceSyntax, (int)j, (int)i));
                        valList.Add(new ValueAtPoint(doubleList));
                        doubleList.Clear();
                    }
                }
            }

            var points = new FieldDomainPointsByUV(uvPts);
            var values = new FieldValues(valList);
            int index  = sfm.AddSpatialFieldPrimitive(faceReference);

            var resultSchema = CreateResultSchemaWithUnitNames();

            sfm.UpdateSpatialFieldPrimitive(index, points, values, sfm.RegisterResult(resultSchema));
        }
Exemplo n.º 3
0
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiApp = commandData.Application;
        Document      doc   = uiApp.ActiveUIDocument.Document;
        Application   app   = commandData.Application.Application;

        // internal agreement: abuse KeyValuePair to pass plugin operation state and objects
        KeyValuePair <Result, SpaceSyntax> kvSpaceSyntax = FileOpenService.PromtUserForSpaceSyntaxXml();

        if (kvSpaceSyntax.Key != Result.Succeeded)
        {
            return(kvSpaceSyntax.Key);
        }
        SpaceSyntax spaceSyntax = kvSpaceSyntax.Value;

        KeyValuePair <Result, Level> kvSelectedLevel = new KeyValuePair <Result, Level>(Result.Failed, null);

        if (!string.IsNullOrEmpty(spaceSyntax.ScenarioName))
        {
            kvSelectedLevel = RevitUtils.AttemptToGetLevelByScenarioName(doc, spaceSyntax.ScenarioName);
        }

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            kvSelectedLevel = UserLevelSelectService.LetUserPickLevelFromDialog(doc);
        }

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            return(kvSelectedLevel.Key);
        }
        Level level = kvSelectedLevel.Value;

        KeyValuePair <Result, PlanarFace> kvTopFace = RevitUtils.GetTopFaceFromLevel(app, level);

        if (kvSelectedLevel.Key != Result.Succeeded)
        {
            return(kvSelectedLevel.Key);
        }
        PlanarFace topFace = kvTopFace.Value;

        Result result = RevitVisualizationService.CreateSpaceSyntaxAnalysisResult(doc, spaceSyntax, topFace);

        return(result);
    }
Exemplo n.º 4
0
        public static Result CreateSpaceSyntaxAnalysisResult(Document doc, SpaceSyntax spaceSyntax, Face face)
        {
            // A (default) AnalysisDisplayStyle must exist, otherwise Revit does not know how to display/interpret anything
            ActivateAnalysisDisplayStyle(doc);

            using (var transaction = new Transaction(doc, "SpaceSyntax Visualization"))
            {
                transaction.Start();
                try
                {
                    CreateSpaceSyntaxAnalysisResult(doc, spaceSyntax, face, face.Reference);
                    transaction.Commit();
                    return(Result.Succeeded);
                }
                catch (Exception e)
                {
                    PromtService.ShowErrorToUser(e.ToString());
                    transaction.RollBack();
                    return(Result.Failed);
                }
            }
        }