private RoomData FindVisibilityByPointData(RoomData rd, AnalysisData aData, ProgressBar progressBar)
        {
            RoomData updatedData = new RoomData(rd);

            try
            {
                updatedData.RoomFace = FMEDataUtil.CreateFacebyFMEData(aData.RoomFace);
                if (null != updatedData.RoomFace)
                {
                    updatedData.PointDataList = FMEDataUtil.ConvertToPointDataList(updatedData.RoomFace, aData.PointValues);

                    IList <UV>           uvPoints = new List <UV>();
                    IList <ValueAtPoint> valList  = new List <ValueAtPoint>();

                    progressBar.Value   = 0;
                    progressBar.Minimum = 0;
                    progressBar.Maximum = updatedData.PointDataList.Count;
                    UpdateProgressDelegate updateProgressDelegate = new UpdateProgressDelegate(progressBar.SetValue);

                    int    visibleCount  = 0;
                    double progressValue = 0;
                    foreach (PointData ptData in updatedData.PointDataList)
                    {
                        if (AbortFlag.GetAbortFlag())
                        {
                            return(updatedData);
                        }
                        Dispatcher.CurrentDispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue });

                        if (null != ptData.UVPoint && null != ptData.ValueAtPoint)
                        {
                            uvPoints.Add(ptData.UVPoint);
                            valList.Add(ptData.ValueAtPoint);
                            if (ptData.PointValue > 0)
                            {
                                visibleCount++;
                            }
                        }
                        progressValue++;
                    }

                    double ratio = (double)visibleCount / (double)uvPoints.Count;
                    updatedData.VisiblityRatio = ratio;
                    updatedData.AreaWithViews  = rd.RoomArea * ratio;
                    updatedData.SetResultParameterValue(LEEDParameters.LEED_AreaWithViews.ToString(), rd.AreaWithViews);

                    //visualize
                    Transform transform = Transform.CreateTranslation(new XYZ(0, 0, offsetHeight));
                    int       index     = m_sfm.AddSpatialFieldPrimitive(updatedData.RoomFace, transform);

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

                    m_sfm.UpdateSpatialFieldPrimitive(index, domainPoints, values, resultIndex);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find visibility.\n" + ex.Message, "Find Visibility", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(updatedData);
        }
示例#2
0
        private bool SaveResultData(Dictionary <int, RoomData> roomDictionary)
        {
            bool saved = false;

            try
            {
                if (!string.IsNullOrEmpty(settings.DataFileName))
                {
                    analysisDataCollection = new AnalysisDataCollection();

                    foreach (int roomId in roomDictionary.Keys)
                    {
                        RoomData roomData = roomDictionary[roomId];
                        int      index    = analysisDataCollection.AnalysisDataList.FindIndex(o => o.RoomId == roomId);
                        if (settings.OverwriteData)
                        {
                            if (index > -1)
                            {
                                analysisDataCollection.AnalysisDataList.RemoveAt(index);
                            }
                            AnalysisData aData = new AnalysisData();
                            aData.RoomId      = roomData.RoomId;
                            aData.RoomArea    = roomData.RoomArea;
                            aData.VisibleArea = roomData.AreaWithViews;
                            aData.RoomFace    = FMEDataUtil.ConvertRevitFaceToFMEArea(roomData.RoomFace);
                            aData.PointValues = FMEDataUtil.ConvertToFMEPointList(roomData.PointDataList);
                            analysisDataCollection.AnalysisDataList.Add(aData);
                        }
                        else if (index == -1)
                        {
                            //add new room data only if it doesn't exist
                            AnalysisData aData = new AnalysisData();
                            aData.RoomId      = roomData.RoomId;
                            aData.RoomArea    = roomData.RoomArea;
                            aData.VisibleArea = roomData.AreaWithViews;
                            aData.RoomFace    = FMEDataUtil.ConvertRevitFaceToFMEArea(roomData.RoomFace);
                            aData.PointValues = FMEDataUtil.ConvertToFMEPointList(roomData.PointDataList);
                            analysisDataCollection.AnalysisDataList.Add(aData);
                        }
                    }

                    if (analysisDataCollection.AnalysisDataList.Count > 0)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(AnalysisDataCollection));
                        StreamWriter  writer     = new StreamWriter(settings.DataFileName);
                        serializer.Serialize(writer, analysisDataCollection);
                        writer.Close();
                        saved = true;
                    }
                }
                else
                {
                    saved = true;
                }
            }
            catch (Exception ex)
            {
                saved = false;
                System.Windows.MessageBox.Show("Failed to save analysis data.\n" + ex.Message, "Save Result Data", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(saved);
        }
        public bool RunViewAnalysis(ProgressBar progressBar, TextBlock statusLable)
        {
            bool result = true;

            using (TransactionGroup tg = new TransactionGroup(m_doc))
            {
                tg.Start("Run View Analysis");
                try
                {
                    UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue);

                    List <int> keys         = roomDictionary.Keys.ToList();
                    int        finishedRoom = 0;
                    foreach (int roomId in keys)
                    {
                        if (AbortFlag.GetAbortFlag())
                        {
                            return(false);
                        }

                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Find Visibility");
                            try
                            {
                                RoomData rData    = roomDictionary[roomId];
                                string   roomInfo = rData.RoomObj.Name + " (" + finishedRoom + " of " + keys.Count + ")";
                                Dispatcher.CurrentDispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, roomInfo });
                                progressBar.Visibility = System.Windows.Visibility.Visible;

                                RoomData updatedData = null;
                                int      index       = dataCollection.AnalysisDataList.FindIndex(o => o.RoomId == rData.RoomId);
                                if (index == -1 || overwriteData)
                                {
                                    updatedData = FindVisibility(rData, progressBar);
                                }
                                else
                                {
                                    AnalysisData aData = dataCollection.AnalysisDataList[index];
                                    updatedData = FindVisibilityByPointData(rData, aData, progressBar);
                                }

                                if (null != updatedData)
                                {
                                    roomDictionary.Remove(roomId);
                                    roomDictionary.Add(roomId, updatedData);
                                }

                                finishedRoom++;
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                result = false;
                                string message = ex.Message;
                            }
                        }
                    }

                    tg.Assimilate();
                }
                catch (Exception ex)
                {
                    result = false;
                    MessageBox.Show("Failed to run view analysis.\n" + ex.Message, "Run View Analysis", MessageBoxButton.OK, MessageBoxImage.Warning);
                    tg.RollBack();
                }
            }
            return(result);
        }