/// <summary> /// Refresh after change in unknown combo box /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UnknownGwpTypeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox gwpComboBox = sender as ComboBox; string selectedGwp = gwpComboBox.SelectedItem as string; GwpData gwpData = gwpComboBox.DataContext as GwpData; GwpNameValue gwpNameValue = gwpData.AllGwpList.First(x => x.Name == selectedGwp); gwpData.GwpSelected = gwpNameValue; gwpData.Gwp = gwpNameValue.Value; RefreshPlot(); }
/// <summary> /// Get saved GwpData selected from json /// </summary> /// <param name="gwpData"></param> /// <param name="savedGwpJson"></param> /// <returns></returns> private GwpData GetSavedGwpSetting(GwpData gwpData, string savedGwpJson) { GwpData onlySavedPropertiesGwp = null; List <GwpData> savedGwps = Newtonsoft.Json.JsonConvert.DeserializeObject <List <GwpData> >(savedGwpJson); if (savedGwps != null) { var foundGwp = savedGwps.Where(x => x.Category == gwpData.Category && x.MaterialName == gwpData.MaterialName); if (foundGwp.Count() > 0) { onlySavedPropertiesGwp = foundGwp.First(); } } return(onlySavedPropertiesGwp); }
/// <summary> /// Bring up detail element list UI on double click of data grid row /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RowDoubleClick(object sender, MouseButtonEventArgs e) { DataGridRow row = sender as DataGridRow; if (row != null) { GwpData gwpData = row.Item as GwpData; if (gwpData != null) { var revitElements = a_RevitReader.RevitElementData.FindAll(x => x.Category == gwpData.Category && x.MaterialName == gwpData.MaterialName); revitElements = revitElements.OrderBy(x => x.Name).ThenBy(y => y.AssociatedLevel).ToList(); string label = "Elements: " + gwpData.Category.ToString() + " - " + gwpData.MaterialName; DataGridUI dataGridUI = new DataGridUI(revitElements, label); dataGridUI.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; dataGridUI.ShowDialog(); } Totals total = row.Item as Totals; if (total != null) { var revitElements = a_RevitReader.RevitElementData.FindAll(x => x.Material.ToString() == total.Name); if (total.Name == "Total") { revitElements = a_RevitReader.RevitElementData; } else if (total.Name == "Rebar") { revitElements = a_RevitReader.RevitElementData.FindAll(x => x.Material.ToString() == MaterialType.Concrete.ToString()); } revitElements = revitElements.OrderBy(x => x.Material.ToString()).ThenBy(y => y.MaterialName).ThenBy(z => z.Category.ToString()).ToList(); string label = "Elements: " + total.Name; DataGridUI dataGridUI = new DataGridUI(revitElements, label); dataGridUI.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; dataGridUI.ShowDialog(); } } }
/// <summary> /// Calculate EC based on selected GwpData /// </summary> private void ParseByCategoryAndLevel() { a_categoryPlotData.Clear(); a_levelPlotData.Clear(); a_totalArea = 0.0; Dictionary <string, double> rebarECByCatDict = new Dictionary <string, double>(); Dictionary <string, Tuple <string, double> > rebarECByLevelDict = new Dictionary <string, Tuple <string, double> >(); foreach (var revitElement in a_RevitReader.RevitElementData) { if (revitElement.Area > 0) { a_totalArea += revitElement.Area; } double unknownEC = 0.0, steelEC = 0.0, concreteEC = 0.0, timberEC = 0.0; switch (revitElement.Material) { case MaterialType.Steel: var steelGwpList = a_SteelGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (steelGwpList.Count() == 1) { GwpData gwpData = steelGwpList.First(); steelEC = gwpData.Gwp * (revitElement.Weight / 2000); revitElement.GwpType = gwpData.Gwp == gwpData.GwpSelected.Value ? gwpData.GwpSelected.Name : "User Input"; revitElement.Gwp = gwpData.Gwp; revitElement.EmbodiedCarbon = steelEC; } break; case MaterialType.Concrete: var concreteGwpList = a_ConcreteGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (concreteGwpList.Count() == 1) { // Concrete GwpData gwpData = concreteGwpList.First(); concreteEC = gwpData.Gwp * (revitElement.Volume / 27); revitElement.GwpType = gwpData.Gwp == gwpData.GwpSelected.Value ? gwpData.GwpSelected.Name : "User Input"; revitElement.Gwp = gwpData.Gwp; revitElement.EmbodiedCarbon = concreteEC; // Element Rebar Estimate revitElement.RebarMultiplier = gwpData.RebarWeightMultiplier; if (revitElement.Category == RevitCategory.Floor) { revitElement.RebarWeight = gwpData.RebarWeightMultiplier * revitElement.Area; } else { revitElement.RebarWeight = gwpData.RebarWeightMultiplier * revitElement.Volume / 27; } revitElement.RebarGwp = gwpData.RebarGwp; revitElement.RebarEmbodiedCarbon = gwpData.RebarGwp * (revitElement.RebarWeight / 2000); // Category and Level Rebar Estimate if (rebarECByCatDict.ContainsKey(revitElement.Category.ToString()) == false) { double rebarECValue = gwpData.RebarGwp * (gwpData.RebarWeight / 2000); rebarECByCatDict.Add(revitElement.Category.ToString(), rebarECValue); foreach (var levelRatio in gwpData.rebarLevelRatio) { rebarECByLevelDict.Add(revitElement.Category.ToString() + levelRatio.Key, Tuple.Create(levelRatio.Key, levelRatio.Value * rebarECValue)); } } } break; case MaterialType.Timber: var timberGwpList = a_TimberGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (timberGwpList.Count() == 1) { GwpData gwpData = timberGwpList.First(); timberEC = gwpData.Gwp * (revitElement.Volume / 27); revitElement.GwpType = gwpData.Gwp == gwpData.GwpSelected.Value ? gwpData.GwpSelected.Name : "User Input"; revitElement.Gwp = gwpData.Gwp; revitElement.EmbodiedCarbon = timberEC; } break; case MaterialType.Unknown: var unknownGwpList = a_UnknownGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (unknownGwpList.Count() == 1) { GwpData gwpData = unknownGwpList.First(); if (gwpData.GwpSelected.GwpType == MultiplierType.Volume) { unknownEC = gwpData.Gwp * (revitElement.Volume / 27); } else { unknownEC = gwpData.Gwp * (revitElement.Weight / 2000); } revitElement.GwpType = gwpData.Gwp == gwpData.GwpSelected.Value ? gwpData.GwpSelected.Name : "User Input"; revitElement.Gwp = gwpData.Gwp; revitElement.EmbodiedCarbon = unknownEC; } break; default: break; } // Category var foundCatData = a_categoryPlotData.Where(c => c.Label == revitElement.Category.ToString()); PlotData categoryPlotData = null; if (foundCatData.Count() == 0) { categoryPlotData = new PlotData(revitElement.Category.ToString(), steelEC, concreteEC, timberEC, unknownEC, 0, 0); a_categoryPlotData.Add(categoryPlotData); } else if (foundCatData.Count() > 0) { categoryPlotData = foundCatData.First(); categoryPlotData.Steel += steelEC; categoryPlotData.Concrete += concreteEC; categoryPlotData.Timber += timberEC; categoryPlotData.Unknown += unknownEC; } // Level var foundLevelData = a_levelPlotData.Where(c => c.Label == revitElement.AssociatedLevel); PlotData levelPlotData = null; if (foundLevelData.Count() == 0) { levelPlotData = new PlotData(revitElement.AssociatedLevel, steelEC, concreteEC, timberEC, unknownEC, 0, revitElement.AssociatedElevation); a_levelPlotData.Add(levelPlotData); } else if (foundLevelData.Count() > 0) { levelPlotData = foundLevelData.First(); levelPlotData.Steel += steelEC; levelPlotData.Concrete += concreteEC; levelPlotData.Timber += timberEC; levelPlotData.Unknown += unknownEC; } } // Category Rebar foreach (var catData in a_categoryPlotData) { double rebarEC = 0.0; if (rebarECByCatDict.TryGetValue(catData.Label, out rebarEC)) { catData.Rebar = rebarEC; } } // Level Rebar foreach (var levelRebarEC in rebarECByLevelDict) { var foundLevelData = a_levelPlotData.Where(c => c.Label == levelRebarEC.Value.Item1); if (foundLevelData.Count() > 0) { PlotData levelPlotData = foundLevelData.First(); levelPlotData.Rebar += levelRebarEC.Value.Item2; } } // Sort Level by elevation a_levelPlotData = new Collection <PlotData>(a_levelPlotData.OrderBy(x => x.Elevation).ToList()); // Calculate Totals a_TotalsList = new List <Totals>() { new Totals(MaterialType.Steel.ToString(), Math.Round(a_categoryPlotData.Sum(x => x.Steel))), new Totals(MaterialType.Concrete.ToString(), Math.Round(a_categoryPlotData.Sum(x => x.Concrete))), new Totals(MaterialType.Timber.ToString(), Math.Round(a_categoryPlotData.Sum(x => x.Timber))), new Totals(MaterialType.Rebar.ToString(), Math.Round(a_categoryPlotData.Sum(x => x.Rebar))), new Totals(MaterialType.Unknown.ToString(), Math.Round(a_categoryPlotData.Sum(x => x.Unknown))), new Totals("Total", Math.Round(a_categoryPlotData.Sum(x => x.Total))), }; TotalDataGrid.ItemsSource = a_TotalsList; // Set Beacon Color SetBeaconColor(); }
/// <summary> /// Group RevitElements into GwpData by Category and Material Name /// </summary> /// <param name="setConcrete">Process Concrete?</param> /// <param name="setSteel">Process Steel?</param> /// <param name="setTimber">Process Timber?</param> /// <param name="setUnknown">Process Unknown?</param> private void BuildGwpData(bool setConcrete, bool setSteel, bool setTimber, bool setUnknown) { foreach (var revitElement in a_RevitReader.RevitElementData) { switch (revitElement.Material) { case MaterialType.Concrete: if (setConcrete) { var gwpConcreteDataList = a_ConcreteGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (gwpConcreteDataList.Count() == 0) { GwpData gwpData = new GwpData(revitElement.Category, revitElement.MaterialName); if (revitElement.Category == RevitCategory.Floor) { gwpData.RebarEstimateBasis += revitElement.Area; } else { gwpData.RebarEstimateBasis += revitElement.Volume / 27; } gwpData.rebarLevelBreakdown.Add(revitElement.AssociatedLevel, gwpData.RebarEstimateBasis); gwpData.PopulateConcreteGwpList(); switch (revitElement.Category) { case RevitCategory.Framing: gwpData.RebarWeightMultiplier = 200; gwpData.GwpSelectedIndex = gwpData.ConcreteGwpList.FindIndex(x => x.Name == "6000-00-FA/SL"); gwpData.GwpSelected = gwpData.ConcreteGwpList.First(x => x.Name == "6000-00-FA/SL"); gwpData.Gwp = gwpData.GwpSelected.Value; break; case RevitCategory.Column: gwpData.RebarWeightMultiplier = 150; gwpData.GwpSelectedIndex = gwpData.ConcreteGwpList.FindIndex(x => x.Name == "8000-00-FA/SL"); gwpData.GwpSelected = gwpData.ConcreteGwpList.First(x => x.Name == "8000-00-FA/SL"); gwpData.Gwp = gwpData.GwpSelected.Value; break; case RevitCategory.Floor: gwpData.RebarWeightMultiplier = 6; gwpData.GwpSelectedIndex = gwpData.ConcreteGwpList.FindIndex(x => x.Name == "6000-00-FA/SL"); gwpData.GwpSelected = gwpData.ConcreteGwpList.First(x => x.Name == "6000-00-FA/SL"); gwpData.Gwp = gwpData.GwpSelected.Value; break; case RevitCategory.Wall: gwpData.RebarWeightMultiplier = 250; gwpData.GwpSelectedIndex = gwpData.ConcreteGwpList.FindIndex(x => x.Name == "8000-00-FA/SL"); gwpData.GwpSelected = gwpData.ConcreteGwpList.First(x => x.Name == "8000-00-FA/SL"); gwpData.Gwp = gwpData.GwpSelected.Value; break; case RevitCategory.Foundation: gwpData.RebarWeightMultiplier = 200; gwpData.GwpSelectedIndex = gwpData.ConcreteGwpList.FindIndex(x => x.Name == "4000-00-FA/SL"); gwpData.GwpSelected = gwpData.ConcreteGwpList.First(x => x.Name == "4000-00-FA/SL"); gwpData.Gwp = gwpData.GwpSelected.Value; break; default: gwpData.RebarWeightMultiplier = 0.0; break; } GwpData savedGwpData = GetSavedGwpSetting(gwpData, Settings.Default.SavedGwpsConcrete); if (savedGwpData != null) { gwpData.GwpSelectedIndex = savedGwpData.GwpSelectedIndex; gwpData.Gwp = savedGwpData.Gwp; gwpData.RebarWeightMultiplier = savedGwpData.RebarWeightMultiplier; gwpData.RebarWeight = savedGwpData.RebarWeight; gwpData.RebarGwp = savedGwpData.RebarGwp; } gwpData.Volume += revitElement.Volume; gwpData.Density = revitElement.Density; a_ConcreteGwpDataList.Add(gwpData); } else { var gwpConcreteData = gwpConcreteDataList.First(); gwpConcreteData.Volume += revitElement.Volume; double localRebarEstimateBasis = 0.0; if (revitElement.Category == RevitCategory.Floor) { localRebarEstimateBasis = revitElement.Area; gwpConcreteData.RebarEstimateBasis += revitElement.Area; } else { localRebarEstimateBasis = revitElement.Volume / 27; gwpConcreteData.RebarEstimateBasis += revitElement.Volume / 27; } double rebarEstimateValue; if (gwpConcreteData.rebarLevelBreakdown.TryGetValue(revitElement.AssociatedLevel, out rebarEstimateValue)) { rebarEstimateValue += localRebarEstimateBasis; gwpConcreteData.rebarLevelBreakdown.Remove(revitElement.AssociatedLevel); gwpConcreteData.rebarLevelBreakdown.Add(revitElement.AssociatedLevel, rebarEstimateValue); } else { gwpConcreteData.rebarLevelBreakdown.Add(revitElement.AssociatedLevel, localRebarEstimateBasis); } } } break; case MaterialType.Steel: if (setSteel) { var gwpSteelDataList = a_SteelGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (gwpSteelDataList.Count() == 0) { GwpData gwpData = new GwpData(revitElement.Category, revitElement.MaterialName); gwpData.PopulateSteelGwpList(); if (revitElement.MaterialName.ToUpper().Contains("A992")) { gwpData.GwpSelectedIndex = gwpData.SteelGwpList.FindIndex(x => x.Name == "Primary Steel"); gwpData.GwpSelected = gwpData.SteelGwpList.First(x => x.Name == "Primary Steel"); gwpData.Gwp = gwpData.GwpSelected.Value; } else if (revitElement.MaterialName.ToUpper().Contains("A500")) { gwpData.GwpSelectedIndex = gwpData.SteelGwpList.FindIndex(x => x.Name == "HSS Steel"); gwpData.GwpSelected = gwpData.SteelGwpList.First(x => x.Name == "HSS Steel"); gwpData.Gwp = gwpData.GwpSelected.Value; } GwpData savedGwpData = GetSavedGwpSetting(gwpData, Settings.Default.SavedGwpsSteel); if (savedGwpData != null) { gwpData.GwpSelectedIndex = savedGwpData.GwpSelectedIndex; gwpData.Gwp = savedGwpData.Gwp; } gwpData.Volume += revitElement.Volume; gwpData.Density = revitElement.Density; a_SteelGwpDataList.Add(gwpData); } else { GwpData foundGwpData = gwpSteelDataList.First(); foundGwpData.Volume += revitElement.Volume; } } break; case MaterialType.Timber: if (setTimber) { var gwpTimberDataList = a_TimberGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (gwpTimberDataList.Count() == 0) { GwpData gwpData = new GwpData(revitElement.Category, revitElement.MaterialName); gwpData.PopulateTimberGwpList(); if (revitElement.MaterialName.ToUpper().Contains("SOFTWOOD") && revitElement.MaterialName.ToUpper().Contains("LUMBER")) { gwpData.GwpSelectedIndex = gwpData.TimberGwpList.FindIndex(x => x.Name == "Softwood Lumber"); gwpData.GwpSelected = gwpData.TimberGwpList.First(x => x.Name == "Softwood Lumber"); gwpData.Gwp = gwpData.GwpSelected.Value; } else if (revitElement.MaterialName.ToUpper().Contains("SOFTWOOD") && revitElement.MaterialName.ToUpper().Contains("PLYWOOD")) { gwpData.GwpSelectedIndex = gwpData.TimberGwpList.FindIndex(x => x.Name == "Softwood Plywood"); gwpData.GwpSelected = gwpData.TimberGwpList.First(x => x.Name == "Softwood Plywood"); gwpData.Gwp = gwpData.GwpSelected.Value; } else if (revitElement.MaterialName.ToUpper().Contains("STRAND")) { gwpData.GwpSelectedIndex = gwpData.TimberGwpList.FindIndex(x => x.Name == "Oriented Strand Board"); gwpData.GwpSelected = gwpData.TimberGwpList.First(x => x.Name == "Oriented Strand Board"); gwpData.Gwp = gwpData.GwpSelected.Value; } else if (revitElement.MaterialName.ToUpper().Contains("GLULAM")) { gwpData.GwpSelectedIndex = gwpData.TimberGwpList.FindIndex(x => x.Name == "Glulam"); gwpData.GwpSelected = gwpData.TimberGwpList.First(x => x.Name == "Glulam"); gwpData.Gwp = gwpData.GwpSelected.Value; } else if (revitElement.MaterialName.ToUpper().Contains("LVL") || revitElement.MaterialName.ToUpper().Contains("LAMINATED VENEER LUMBER")) { gwpData.GwpSelectedIndex = gwpData.TimberGwpList.FindIndex(x => x.Name == "Laminated Veneer Lumber"); gwpData.GwpSelected = gwpData.TimberGwpList.First(x => x.Name == "Laminated Veneer Lumber"); gwpData.Gwp = gwpData.GwpSelected.Value; } GwpData savedGwpData = GetSavedGwpSetting(gwpData, Settings.Default.SavedGwpsTimber); if (savedGwpData != null) { gwpData.GwpSelectedIndex = savedGwpData.GwpSelectedIndex; gwpData.Gwp = savedGwpData.Gwp; } gwpData.Volume += revitElement.Volume; gwpData.Density = revitElement.Density; a_TimberGwpDataList.Add(gwpData); } else { GwpData foundGwpData = gwpTimberDataList.First(); foundGwpData.Volume += revitElement.Volume; } } break; case MaterialType.Unknown: if (setUnknown) { var gwpUnknownDataList = a_UnknownGwpDataList.Where(x => x.Category == revitElement.Category && x.MaterialName == revitElement.MaterialName); if (gwpUnknownDataList.Count() == 0) { GwpData gwpData = new GwpData(revitElement.Category, revitElement.MaterialName); gwpData.PopulateAllGwpList(); GwpData savedGwpData = GetSavedGwpSetting(gwpData, Settings.Default.SavedGwpsUnknown); if (savedGwpData != null) { gwpData.GwpSelectedIndex = savedGwpData.GwpSelectedIndex; gwpData.Gwp = savedGwpData.Gwp; } gwpData.Volume += revitElement.Volume; gwpData.Density = revitElement.Density; a_UnknownGwpDataList.Add(gwpData); } else { GwpData foundGwpData = gwpUnknownDataList.First(); foundGwpData.Volume += revitElement.Volume; } } break; default: break; } } // Set unknown tab to Bold if not zero count. Only on initial time when all sets are true. if (a_UnknownGwpDataList.Count > 0 && setSteel && setConcrete && setTimber && setUnknown) { UnknownTab.FontWeight = FontWeights.Bold; UnknownTab.IsSelected = true; } }