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 = FindVisibility(rData, progressBar); 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); }
private void buttonCancel_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = System.Windows.MessageBox.Show("Would you like to stop processing the View Analysis?", "Cancellation - View Analysis", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { AbortFlag.SetAbortFlag(true); } }
public MainWindow(UIApplication uiapp, List <Room> rooms) { m_app = uiapp; m_doc = m_app.ActiveUIDocument.Document; selectedRooms = rooms; AbortFlag.SetAbortFlag(false); InitializeComponent(); DisplaySettings(); this.Title = "LEED EQc 8.2 - View Analysis v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
private RoomData FindVisibility(RoomData rd, ProgressBar progressBar) { RoomData updatedData = new RoomData(rd); try { LogicalOrFilter orFilter = new LogicalOrFilter(categoryFilters); ReferenceIntersector intersector = null; intersector = new ReferenceIntersector(orFilter, FindReferenceTarget.Face, m_view); intersector.FindReferencesInRevitLinks = true; Face face = rd.RoomFace; BoundingBoxUV bb = face.GetBoundingBox(); IList <UV> uvPoints = new List <UV>(); IList <ValueAtPoint> valList = new List <ValueAtPoint>(); List <PointData> pointDataList = new List <PointData>(); double interval = analysisSettings.Interval; List <double> uList = new List <double>(); List <double> vList = new List <double>(); GetUVArray(bb, interval, out uList, out vList); progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = uList.Count * vList.Count; UpdateProgressDelegate updateProgressDelegate = new UpdateProgressDelegate(progressBar.SetValue); List <XYZ> exteriorPoints = new List <XYZ>(); List <XYZ> interiorPoints = new List <XYZ>(); bool sorted = SortViewPoints(rd.BoundarySegments, out exteriorPoints, out interiorPoints); int visibleCount = 0; double progressValue = 0; foreach (double u in uList) //start from in the middle of grid { foreach (double v in vList) { if (AbortFlag.GetAbortFlag()) { return(updatedData); } Dispatcher.CurrentDispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue }); UV uvPoint = new UV(u, v); if (face.IsInside(uvPoint)) { XYZ evalPoint = face.Evaluate(uvPoint); XYZ xyzPoint = new XYZ(evalPoint.X, evalPoint.Y, evalPoint.Z + offsetHeight); //4.2 inches above from the floor double pointValue = 0; List <XYZ> viewPoints = new List <XYZ>(); if (exteriorPoints.Count > 0) { exteriorPoints = exteriorPoints.OrderBy(o => o.DistanceTo(xyzPoint)).ToList(); viewPoints.AddRange(exteriorPoints); } if (interiorPoints.Count > 0) { interiorPoints = interiorPoints.OrderBy(o => o.DistanceTo(xyzPoint)).ToList(); viewPoints.AddRange(interiorPoints); } if (viewPoints.Count > 0) { bool visible = CheckVisibilityByMaterial(intersector, xyzPoint, viewPoints); if (visible) { pointValue = 1; visibleCount++; } else { pointValue = 0; } } PointData pData = new PointData(uvPoint, xyzPoint, pointValue); pointDataList.Add(pData); uvPoints.Add(pData.UVPoint); valList.Add(pData.ValueAtPoint); } progressValue++; } } rd.PointDataList = pointDataList; double ratio = (double)visibleCount / (double)uvPoints.Count; rd.VisiblityRatio = ratio; rd.AreaWithViews = rd.RoomArea * ratio; rd.SetResultParameterValue(LEEDParameters.LEED_AreaWithViews.ToString(), rd.AreaWithViews); //visualize Transform transform = Transform.CreateTranslation(new XYZ(0, 0, offsetHeight)); int index = m_sfm.AddSpatialFieldPrimitive(face, 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); }
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); }