private CarboProject openNewProject() { CarboProject result = null; try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|Carbo Life Project File (*.xml)| *.xml|All files (*.*)|*.*"; var path = openFileDialog.ShowDialog(); if (openFileDialog.FileName != "") { CarboProject buffer = new CarboProject(); result = buffer.DeSerializeXML(openFileDialog.FileName); result.Audit(); result.CalculateProject(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } return(result); }
/// <summary> /// Start A new Project /// </summary> private void mnu_newProject_Click(object sender, RoutedEventArgs e) { bool fileSaved = false; //This bit is a verification code, to make sure the user is given the opportunity to save teh work before continuing: if (carboLifeProject.justSaved == false) { MessageBoxResult result = MessageBox.Show("Do you want to save your project first?", "Warning", MessageBoxButton.YesNoCancel); if (result == MessageBoxResult.Yes) { if (carboLifeProject.filePath == "") { fileSaved = SaveFileAs(); } else { fileSaved = SaveFile(carboLifeProject.filePath); } } else if (result == MessageBoxResult.No) { //The user didnt want to save fileSaved = true; } else { //the user cancels fileSaved = false; } } else { //The file was already saved fileSaved = true; } // //the file is either saved, or used didnt want to save: if (fileSaved == true) { try { carboLifeProject = new CarboProject(); carboLifeProject.Audit(); carboLifeProject.CalculateProject(); carboLifeProject.justSaved = false; tab_Main.Visibility = Visibility.Hidden; tab_Main.Visibility = Visibility.Visible; } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void SaveSettings() { CarboLifeProject.Name = txt_ProjectName.Text; CarboLifeProject.Number = txt_Number.Text; CarboLifeProject.Category = txt_Category.Text; CarboLifeProject.Description = txt_Desctiption.Text; CarboLifeProject.Area = CarboLifeAPI.Utils.ConvertMeToDouble(txt_Area.Text); CarboLifeProject.Value = CarboLifeAPI.Utils.ConvertMeToDouble(txt_Value.Text); CarboLifeProject.CalculateProject(); }
private void SaveSettings() { CarboLifeProject.Name = txt_ProjectName.Text; CarboLifeProject.Number = txt_Number.Text; CarboLifeProject.Category = txt_Category.Text; CarboLifeProject.Description = txt_Desctiption.Text; CarboLifeProject.SocialCost = CarboLifeAPI.Utils.ConvertMeToDouble(txt_SocialCost.Text); CarboLifeProject.Area = CarboLifeAPI.Utils.ConvertMeToDouble(txt_Area.Text); CarboLifeProject.SocialCost = CarboLifeAPI.Utils.ConvertMeToDouble(txt_SocialCost.Text); //A5 CarboLifeProject.Value = CarboLifeAPI.Utils.ConvertMeToDouble(txt_Value.Text); CarboLifeProject.A5Factor = CarboLifeAPI.Utils.ConvertMeToDouble(txt_ValueA5Fact.Text); //C1 CarboLifeProject.demoArea = CarboLifeAPI.Utils.ConvertMeToDouble(txt_DemoArea.Text); CarboLifeProject.C1Factor = CarboLifeAPI.Utils.ConvertMeToDouble(txt_DemoC1Fact.Text); CarboLifeProject.CalculateProject(); }
private void Btn_Calculate_Click(object sender, RoutedEventArgs e) { CarboLifeProject.CalculateProject(); refreshData(); }
public static CarboProject CreateIntensityHeatMap(CarboProject carboProject, System.Drawing.Color minOutColour, System.Drawing.Color maxOutColour, System.Drawing.Color minRangeColour, System.Drawing.Color midRangeColour, System.Drawing.Color maxRangeColour, double standardNr = 2) { carboProject.clearHeatmapAndValues(); carboProject.CalculateProject(); List <CarboElement> bufferList = carboProject.getTemporaryElementListWithTotals(); List <double> valuelist = new List <double>(); //List<double> valueRangelist = new List<double>(); //Get a List<double> for only the calculated values. foreach (CarboElement carboElement in bufferList) { valuelist.Add(carboElement.ECI_Total); } double mean = valuelist.Average(); double standardDev = CalculateStandardDeviation(valuelist); double max = mean + (standardDev * standardNr); double min = mean - (standardDev * standardNr); double maxRange = 0; double minRange = 0; bool first = true; foreach (double value in valuelist) { if (value >= min && value <= max) { if (first == true) { maxRange = value; minRange = value; first = false; } //valueRangelist.Add(value); if (value > maxRange) { maxRange = value; } if (value < minRange) { minRange = value; } } else { double v = value; } } string text = "Setting Values:" + Environment.NewLine + "mean: " + mean + Environment.NewLine + "standard dev: " + standardDev + Environment.NewLine + "max: " + max + Environment.NewLine + "min: " + min + Environment.NewLine + Environment.NewLine + "maxRange: " + maxRange + Environment.NewLine + "minRange: " + minRange + Environment.NewLine; //MessageBox.Show(text); //This should be embedded in a single iteration //maxRange = valueRangelist.Max(); // minRange = valueRangelist.Min(); //Possibly split the range to min and maxes. //See how big the extreems are... // foreach (CarboGroup grp in carboProject.getGroupList) { List <CarboElement> elements = grp.AllElements; foreach (CarboElement cel in elements) { //See if this elements falls within the range. double ECI = cel.ECI_Total; if (ECI > maxRange) //Over the max { // Apply Max Colour (Purple for now) cel.r = maxOutColour.R; cel.g = maxOutColour.G; cel.b = maxOutColour.B; } else if (ECI < minRange) { // Apply Min Colour cel.r = minOutColour.R; cel.g = minOutColour.G; cel.b = minOutColour.B; } else { //Within range, calculate value. System.Drawing.Color groupColour = Utils.GetBlendedColor(maxRange, minRange, ECI, minRangeColour, midRangeColour, maxRangeColour); cel.r = groupColour.R; cel.g = groupColour.G; cel.b = groupColour.B; } } } return(carboProject); }
public static CarboProject CreateByGroupHeatMap(CarboProject carboProject, Color minOutColour, Color maxOutColour, Color minRangeColour, Color midRangeColour, Color maxRangeColour, double standardNr = 2) { carboProject.clearHeatmapAndValues(); carboProject.CalculateProject(); //List<CarboElement> bufferList = carboProject.getTemporaryElementListWithTotals(); List <double> valuelist = new List <double>(); List <double> valueRangelist = new List <double>(); //Get a List<double> for the group totals foreach (CarboGroup grp in carboProject.getGroupList) { valuelist.Add(grp.EC); } double mean = valuelist.Average(); double standardDev = CalculateStandardDeviation(valuelist); double max = mean + (standardDev * standardNr); double min = mean - (standardDev * standardNr); double maxRange = 0; double minRange = 0; bool first = true; foreach (double value in valuelist) { if (value >= min && value <= max) { if (first == true) { maxRange = value; minRange = value; first = false; } //valueRangelist.Add(value); if (value > maxRange) { maxRange = value; } if (value < minRange) { minRange = value; } } } string text = "Setting Values:" + Environment.NewLine + "mean: " + mean + Environment.NewLine + "standard dev: " + standardDev + Environment.NewLine + "max: " + max + Environment.NewLine + "min: " + min + Environment.NewLine + Environment.NewLine + "maxRange: " + maxRange + Environment.NewLine + "minRange: " + minRange + Environment.NewLine; //MessageBox.Show(text); foreach (CarboGroup grp in carboProject.getGroupList) { List <CarboElement> elements = grp.AllElements; //See if this elements falls within the range. double EC = grp.EC; if (EC > maxRange) //Over the max { // Apply Max Colour foreach (CarboElement cel in elements) { cel.r = maxOutColour.R; cel.g = maxOutColour.G; cel.b = maxOutColour.B; } } else if (EC < minRange) { // Apply Min Colour foreach (CarboElement cel in elements) { cel.r = minOutColour.R; cel.g = minOutColour.G; cel.b = minOutColour.B; } } else { //Within range, calculate value. System.Drawing.Color groupColour = Utils.GetBlendedColor(maxRange, minRange, EC, minRangeColour, midRangeColour, maxRangeColour); foreach (CarboElement cel in elements) { cel.r = groupColour.R; cel.g = groupColour.G; cel.b = groupColour.B; } } } return(carboProject); }
public static void ImportElements(UIApplication app, CarboRevitImportSettings settings, string updatePath) { UIDocument uidoc = app.ActiveUIDocument; Document doc = uidoc.Document; string MyAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location; string MyAssemblyDir = Path.GetDirectoryName(MyAssemblyPath); bool updateFile = false; if (File.Exists(updatePath)) { updateFile = true; } //Create a new project CarboProject myProject = new CarboProject(); myProject.Name = doc.ProjectInformation.Name.Trim(); myProject.Number = doc.ProjectInformation.Number; ICollection <ElementId> selectionList = uidoc.Selection.GetElementIds(); double area = 0; #region buildQuantitiestable if (selectionList.Count == 0) { //No elements are selected, all elements will be parsed View activeView = doc.ActiveView; FilteredElementCollector coll = new FilteredElementCollector(app.ActiveUIDocument.Document, activeView.Id); coll.WherePasses(new LogicalOrFilter(new ElementIsElementTypeFilter(false), new ElementIsElementTypeFilter(true))); //Now cast them as elements into a container IList <Element> collection = coll.ToElements(); string name = ""; List <string> IdsNotFound = new List <string>(); foreach (Element el in collection) { name = el.Id.ToString(); try { if (CarboRevitUtils.isElementReal(el) == true) { ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); if (carboElement != null) { myProject.AddElement(carboElement); } } //See if is floor(then count area) area += getFloorarea(el); } } catch { IdsNotFound.Add(name); //TaskDialog.Show("Error", ex.Message); } } if (IdsNotFound.Count > 0) { string message = "One or more elements weren't processed, most likely because they didn't contain any volume the element ids of these elements are: "; foreach (string id in IdsNotFound) { message += "\n" + id; } MessageBox.Show(message, "Warning", MessageBoxButton.OK); } } else { try { foreach (ElementId elid in selectionList) { Element el = doc.GetElement(elid); ICollection <ElementId> MaterialIds = el.GetMaterialIds(false); if (CarboRevitUtils.isElementReal(el) == true) { foreach (ElementId materialIds in MaterialIds) { CarboElement carboElement = CarboRevitUtils.getNewCarboElement(doc, el, materialIds, settings); if (carboElement != null) { myProject.AddElement(carboElement); } } //See if is floor(then count area) area += getFloorarea(el); } } } catch (Exception ex) { TaskDialog.Show("Error", ex.Message); } } #endregion //All element have been mapped, here the code will be split between an update or a new one. if (myProject.getAllElements.Count > 0) { CarboProject projectToOpen = new CarboProject(); if (updateFile == false) { //Create groups from all the individual elements myProject.CreateGroups(); projectToOpen = myProject; } else //upadte an existing file: { CarboProject projectToUpdate = new CarboProject(); CarboProject buffer = new CarboProject(); projectToUpdate = buffer.DeSerializeXML(updatePath); projectToUpdate.Audit(); projectToUpdate.UpdateProject(myProject); projectToUpdate.CalculateProject(); projectToOpen = projectToUpdate; } double areaMSqr = Math.Round((area * (0.3048 * 0.3048)), 2); projectToOpen.Area = areaMSqr; CarboLifeMainWindow carboCalcProgram = new CarboLifeMainWindow(projectToOpen); carboCalcProgram.IsRevit = true; AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); carboCalcProgram.ShowDialog(); //Create a visual if (carboCalcProgram.createHeatmap == true) { CreateHeatMap(app, carboCalcProgram.carboLifeProject); } } else { MessageBox.Show("No elements could be found to be calculated, please make sure you have a 3D view active and the building volume is clearly visible ", "Warning", MessageBoxButton.OK); } //When assembly cant be find bind to current System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { System.Reflection.Assembly ayResult = null; string sShortAssemblyName = args.Name.Split(',')[0]; System.Reflection.Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (System.Reflection.Assembly ayAssembly in ayAssemblies) { if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) { ayResult = ayAssembly; break; } } return(ayResult); } }
private void Calculate() { CarboLifeProject.CalculateProject(); refreshData(); }