Exemple #1
0
        private void HideExistingAnalysis()
        {
            SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView);

            if (sfm != null)
            {
                IList <int> regIndices = sfm.GetRegisteredResults();
                foreach (int i in regIndices)
                {
                    AnalysisResultSchema result = sfm.GetResultSchema(i);
                    result.IsVisible = false;
                    sfm.SetResultSchema(i, result);
                }
            }
        }
Exemple #2
0
        public bool AnalysisByElements()
        {
            bool result = false;

            try
            {
                if (areaDictionary.Count > 0)
                {
                    int  resultIndex = FindIndexOfResult(sfm);
                    bool firstLoop   = true;
                    foreach (int areaId in areaDictionary.Keys)
                    {
                        AreaProperties ap      = areaDictionary[areaId];
                        List <double>  dblList = new List <double>(); //double values to be displayed on the face.
                        Face           face    = ap.BaseFace;
                        dblList.Add(ap.FAR);

                        if (dblList.Count != sfm.NumberOfMeasurements)
                        {
                            continue;
                        }

                        int                  index   = sfm.AddSpatialFieldPrimitive(face, Transform.Identity);
                        IList <UV>           uvPts   = new List <UV>();
                        IList <ValueAtPoint> valList = new List <ValueAtPoint>();
                        BoundingBoxUV        bb      = face.GetBoundingBox();
                        UV faceCenter = (bb.Min + bb.Max) / 2; //only collect a center point.

                        uvPts.Add(faceCenter);
                        valList.Add(new ValueAtPoint(dblList));
                        //dblList.Clear();

                        FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts);
                        FieldValues           values       = new FieldValues(valList);

                        AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                        resultSchema.SetUnits(unitNames, multipliers);
                        if (unitNames.Contains(settings.Units))
                        {
                            resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                        }

                        if (overwriteResult)
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }
                        else if (firstLoop)
                        {
                            resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                        }
                        else
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }

                        sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                    }
                    SetCurrentStyle();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
Exemple #3
0
        public bool AnalysisByElements()
        {
            bool result = false;

            try
            {
                if (radianceDictionary.Count > 0)
                {
                    int                  resultIndex = FindIndexOfResult(sfm);
                    bool                 firstLoop   = true;
                    int                  index       = sfm.AddSpatialFieldPrimitive();//not associated with any geometry
                    IList <XYZ>          xyzPoints   = new List <XYZ>();
                    IList <ValueAtPoint> valList     = new List <ValueAtPoint>();

                    foreach (int keyIndex in radianceDictionary.Keys)
                    {
                        RadianceResult rr      = radianceDictionary[keyIndex];
                        List <double>  dblList = new List <double>(); //double values to be displayed on the face.

                        dblList.Add(rr.Value1);
                        dblList.Add(rr.Value2);
                        dblList.Add(rr.Value3);

                        if (dblList.Count != sfm.NumberOfMeasurements)
                        {
                            continue;
                        }

                        xyzPoints.Add(rr.PointXYZ);
                        valList.Add(new ValueAtPoint(dblList));
                        //dblList.Clear();
                    }
                    FieldDomainPointsByXYZ domainPoints = new FieldDomainPointsByXYZ(xyzPoints);
                    FieldValues            values       = new FieldValues(valList);

                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                    resultSchema.SetUnits(unitNames, multipliers);
                    if (unitNames.Contains(settings.Units))
                    {
                        resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                    }

                    if (overwriteResult)
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }
                    else if (firstLoop)
                    {
                        resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                    }
                    else
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }

                    sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);

                    SetCurrentStyle();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visulaize the FAR data. \n" + ex.Message, "FARCalculator : AnalysisByElements", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
Exemple #4
0
        //Display on the floor
        private bool MeasureDistanceOnFloor()
        {
            bool result = false;

            try
            {
                //find walls located inside the selected rooms
                FindWallFacesOnFloor();

                //Find point of view from the sphere element
                if (null != sphere)
                {
                    LocationPoint location = sphere.Location as LocationPoint;
                    XYZ           pointXYZ = location.Point;

                    int  resultIndex = FindIndexOfResult(sfm);
                    bool firstLoop   = true;
                    foreach (int floorId in floorFaces.Keys)
                    {
                        Face floorFace = floorFaces[floorId];
                        XYZ  vectorZ   = new XYZ(0, 0, 1);
#if RELEASE2013
                        Transform transform = Transform.get_Translation(vectorZ);
#else
                        Transform transform = Transform.CreateTranslation(vectorZ);
#endif

                        int index = sfm.AddSpatialFieldPrimitive(floorFace, transform);

                        List <double>        doubleList = new List <double>();
                        IList <UV>           uvPoints   = new List <UV>();
                        IList <ValueAtPoint> valList    = new List <ValueAtPoint>();
                        BoundingBoxUV        bb         = floorFace.GetBoundingBox();
                        for (double u = bb.Min.U; u < bb.Max.U; u = u + (bb.Max.U - bb.Min.U) / 30)
                        {
                            for (double v = bb.Min.V; v < bb.Max.V; v = v + (bb.Max.V - bb.Min.V) / 30)
                            {
                                UV uvPoint = new UV(u, v);
                                uvPoints.Add(uvPoint);
                                XYZ faceXYZ = floorFace.Evaluate(uvPoint);
#if RELEASE2013
                                Line line = doc.Application.Create.NewLine(pointXYZ, faceXYZ, true);
#else
                                Line line = Line.CreateBound(pointXYZ, faceXYZ);
#endif
                                double dblValue = 1;

                                IntersectionResultArray resultArray;
                                foreach (int wallId in wallFaces.Keys)
                                {
                                    Face wallFace = wallFaces[wallId];
                                    SetComparisonResult compResult = wallFace.Intersect(line, out resultArray);
                                    //if intersects with walls the level of visibility will have negative values
                                    if (compResult == SetComparisonResult.Overlap && null != resultArray)
                                    {
                                        if (dblValue > 0)
                                        {
                                            dblValue = 0 - resultArray.Size;
                                        }
                                        else
                                        {
                                            dblValue = dblValue - resultArray.Size;
                                        }
                                    }
                                }

                                doubleList.Add(dblValue);
                                valList.Add(new ValueAtPoint(doubleList));
                                doubleList.Clear();
                            }
                            progressBar.PerformStep();
                        }

                        FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPoints);
                        FieldValues           values       = new FieldValues(valList);

                        AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                        resultSchema.SetUnits(unitNames, multipliers);
                        if (unitNames.Contains(settings.Units))
                        {
                            resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                        }

                        if (overwriteResult)
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }
                        else if (firstLoop)
                        {
                            resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                        }
                        else
                        {
                            sfm.SetResultSchema(resultIndex, resultSchema);
                        }

                        sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to measure distance from the point element to the points on floor face.\n" + ex.Message, "FieldOfViewAnalysis:MeasureDistanceOnFloor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }
        private bool AnalysisByFaces(SpatialFieldManager sfm)
        {
            bool result = false;

            progressBar.Maximum = settings.SelectedElements.Count;
            try
            {
                Options options = new Options();
                options.ComputeReferences = true;

                Dictionary <ElementId, Dictionary <Reference, Face> > selectedFaces = new Dictionary <ElementId, Dictionary <Reference, Face> >();
                selectedFaces = settings.SelectedFaces;

                Dictionary <Face, Dictionary <Reference, List <double> /*paramValues*/> > faceDictionary = new Dictionary <Face, Dictionary <Reference, List <double> /*paramValues*/> >();
                foreach (Element element in settings.SelectedElements)
                {
                    ElementId elementId = element.Id;
                    if (!selectedFaces.ContainsKey(elementId))
                    {
                        continue;
                    }

                    List <double> valueLists = new List <double>();
                    foreach (string paramName in settings.Configurations.Keys)
                    {
#if RELEASE2015 || RELEASE2016 || RELEASE2017
                        Parameter param = element.LookupParameter(paramName);
#else
                        Parameter param = element.get_Parameter(paramName);
#endif

                        if (param != null)
                        {
                            double value = param.AsDouble();
                            valueLists.Add(value);
                        }
                        else
                        {
                            valueLists.Add(0);
                        }
                    }

                    foreach (Reference reference in selectedFaces[elementId].Keys)
                    {
                        if (null != selectedFaces[elementId][reference] && valueLists.Count == settings.NumberOfMeasurement)
                        {
                            Face face = selectedFaces[elementId][reference];
                            faceDictionary.Add(face, new Dictionary <Reference, List <double> >());
                            faceDictionary[face].Add(reference, valueLists);
                            //break;
                        }
                    }
                    progressBar.PerformStep();
                }

                int  resultIndex = FindIndexOfResult(sfm);
                bool firstLoop   = true;
                foreach (Face face in faceDictionary.Keys)
                {
                    Reference     reference = faceDictionary[face].Keys.First();
                    List <double> dblList   = new List <double>();//double values to be displayed on the face.
                    dblList = faceDictionary[face][reference];
                    int                  index   = sfm.AddSpatialFieldPrimitive(reference);
                    IList <UV>           uvPts   = new List <UV>();
                    IList <ValueAtPoint> valList = new List <ValueAtPoint>();
                    BoundingBoxUV        bb      = face.GetBoundingBox();
                    UV faceCenter = (bb.Min + bb.Max) / 2; //only collect a center point.

                    uvPts.Add(faceCenter);
                    valList.Add(new ValueAtPoint(dblList));
                    //dblList.Clear();

                    FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts);
                    FieldValues           values       = new FieldValues(valList);

                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(settings.LegendTitle, settings.LegendDescription);
                    resultSchema.SetUnits(unitNames, multipliers);
                    if (unitNames.Contains(settings.Units))
                    {
                        resultSchema.CurrentUnits = unitNames.IndexOf(settings.Units);
                    }

                    if (overwriteResult)
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }
                    else if (firstLoop)
                    {
                        resultIndex = sfm.RegisterResult(resultSchema); firstLoop = false;
                    }
                    else
                    {
                        sfm.SetResultSchema(resultIndex, resultSchema);
                    }

                    sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                }
                SetCurrentStyle();
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to analyze elements. \n" + ex.Message, "AnalysisDataManager : ElementAnalysis", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }
        public bool VisualizeData()
        {
            bool result = false;

            try
            {
                string    viewIdValue       = RegistryKeyManager.GetRegistryKeyValue("RevitOutgoingViewId");
                ElementId viewId            = new ElementId(int.Parse(viewIdValue));
                Autodesk.Revit.DB.View view = m_doc.GetElement(viewId) as Autodesk.Revit.DB.View;
                if (null != view)
                {
                    SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(view);
                    if (null == sfm)
                    {
                        sfm = SpatialFieldManager.CreateSpatialFieldManager(view, 1);
                    }
                    AnalysisResultSchema resultSchema = new AnalysisResultSchema(analysisType.ToString(), "Imported from DIVA");

                    int resultIndex = -1;

                    //check order
                    DataContainer      tempContainer = dataDictionary[0];
                    XYZ                node          = new XYZ(tempContainer.Node.XValue, tempContainer.Node.YValue, tempContainer.Node.ZValue);
                    IntersectionResult intersection  = displayingFaces[0].Project(node);
                    if (null == intersection)
                    {
                        displayingFaces.Reverse();
                    }                                                        //reverse the order of faces

                    foreach (int keyIndex in dataDictionary.Keys)
                    {
                        DataContainer container = dataDictionary[keyIndex];
                        Face          face      = displayingFaces[keyIndex];
                        List <double> dblList   = new List <double>();
                        dblList.Add(container.ResultValue);

                        XYZ                  vectorZ   = new XYZ(0, 0, -1);
                        Transform            transform = Transform.CreateTranslation(vectorZ);
                        int                  index     = sfm.AddSpatialFieldPrimitive(face, transform);
                        IList <UV>           uvPts     = new List <UV>();
                        IList <ValueAtPoint> valList   = new List <ValueAtPoint>();

                        XYZ nodePoint = new XYZ(container.Node.XValue, container.Node.YValue, container.Node.ZValue);
                        IntersectionResult intersect = face.Project(nodePoint);
                        if (null != intersect)
                        {
                            UV nodeUV = intersect.UVPoint;
                            uvPts.Add(nodeUV);
                            valList.Add(new ValueAtPoint(dblList));

                            FieldDomainPointsByUV domainPoints = new FieldDomainPointsByUV(uvPts);
                            FieldValues           values       = new FieldValues(valList);

                            FieldValues vals = new FieldValues(valList);

                            if (resultIndex == -1)
                            {
                                resultIndex = sfm.RegisterResult(resultSchema);
                            }
                            else
                            {
                                sfm.SetResultSchema(resultIndex, resultSchema);
                            }

                            sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                        }

                        result = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to visualize the result data.\n" + ex.Message, "Analysis Data Manager - Visualize Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                result = false;
            }
            return(result);
        }