Exemple #1
0
        /// <summary>
        /// Update all the groups with the current materials in the database.
        /// </summary>
        public void UpdateAllMaterials()
        {
            List <string> updatedmaterials = new List <string>();

            foreach (CarboGroup gr in this.groupList)
            {
                try
                {
                    CarboMaterial cm = CarboDatabase.GetExcactMatch(gr.Material.Name);
                    if (cm != null)
                    {
                        if (cm.ECI != gr.ECI)
                        {
                            //The material has been changed, update required.
                            gr.Material = cm;

                            if (gr.AllElements.Count > 0)
                            {
                                gr.RefreshValuesFromElements();
                            }

                            gr.CalculateTotals();

                            updatedmaterials.Add(gr.MaterialName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemple #2
0
        public CarboProject()
        {
            //UserPaths
            PathUtils.CheckFileLocationsNew();

            CarboDatabase = new CarboDatabase();
            CarboDatabase = CarboDatabase.DeSerializeXML("");

            groupList      = new ObservableCollection <CarboGroup>();
            elementList    = new ObservableCollection <CarboElement>();
            carboLevelList = new List <CarboLevel>();

            Name        = "New Project";
            Number      = "000000";
            Category    = "A building";
            Description = "New Project";
            //C1 Global
            demoArea = 0;
            C1Global = 0;
            C1Factor = 3.40; // kg CO₂ per m2
            //A5 Global
            A5Global = 0;
            A5Factor = 1400; //kg CO₂ per vaue
            //Social
            SocialCost = 50;
            //Other
            justSaved = false;
            //Totals
            Value = 0;
            //New projects don't need to be saved
            justSaved = true;
        }
        /// <summary>
        /// Creates a copy of the class and all its materials
        /// </summary>
        /// <returns>CarboDatabase</returns>
        public CarboDatabase Copy()
        {
            CarboDatabase copy = new CarboDatabase();

            foreach (CarboMaterial cm in this.CarboMaterialList)
            {
                CarboMaterial newcarboMaterial = new CarboMaterial();
                newcarboMaterial.Copy(cm);
                copy.AddMaterial(newcarboMaterial);
            }

            return(copy);
        }
Exemple #4
0
        public CarboProject()
        {
            CarboDatabase = new CarboDatabase();
            CarboDatabase = CarboDatabase.DeSerializeXML("");

            groupList      = new ObservableCollection <CarboGroup>();
            elementList    = new ObservableCollection <CarboElement>();
            carboLevelList = new List <CarboLevel>();

            Name        = "New Project";
            Number      = "00000";
            Category    = "";
            Description = "New Project";
        }
Exemple #5
0
        /// <summary>
        /// After creating a mapping list, you can use this method to update all map all the groups in a project.
        /// </summary>
        public void mapAllMaterials()
        {
            if (carboMaterialMap != null)
            {
                if (carboMaterialMap.Count > 0)
                {
                    foreach (CarboGroup gr in this.groupList)
                    {
                        try
                        {
                            //MApping only works where elements are imported from Revit and the group contains elements
                            if (gr.AllElements != null && gr.AllElements.Count > 0)
                            {
                                //First see if a change is required;
                                //Find the map file of this group using a single element in the group;
                                CarboMapElement mapElement = GetMapItem(gr.AllElements[0].MaterialName, gr.Category);
                                if (mapElement != null)
                                {
                                    //Get the material from the mapping name;
                                    CarboMaterial cm = CarboDatabase.GetExcactMatch(mapElement.carboNAME);

                                    if (cm != null)
                                    {
                                        //see if the material need changing;
                                        if (cm.Name != gr.MaterialName)
                                        {
                                            //Only update if the mapping file suggest a change.
                                            gr.Material = cm;
                                            gr.RefreshValuesFromElements();
                                            gr.CalculateTotals();
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please setup your material map first.");
            }
        }
Exemple #6
0
        private void NewGroup(CarboElement ceNew)
        {
            try
            {
                ceNew.isUpdated = true;
                CarboGroup newGroup = new CarboGroup(ceNew);

                CarboMaterial closestGroupMaterial = CarboDatabase.getClosestMatch(ceNew.MaterialName);
                //cg.MaterialName = closestGroupMaterial.Name;
                newGroup.setMaterial(closestGroupMaterial);
                closestGroupMaterial.CalculateTotals();

                this.AddGroup(newGroup);
            }
            catch
            {
            }
        }
Exemple #7
0
        public void UpdateAllMaterials()
        {
            List <string> updatedmaterials = new List <string>();

            foreach (CarboGroup gr in this.groupList)
            {
                CarboMaterial cm = CarboDatabase.GetExcactMatch(gr.Material.Name);
                if (cm != null)
                {
                    if (cm.ECI != gr.ECI)
                    {
                        //The material has been changed, update required.
                        gr.Material = cm;
                        gr.RefreshValuesFromElements();
                        gr.CalculateTotals();
                        updatedmaterials.Add(gr.MaterialName);
                    }
                }
            }
        }
        /// <summary>
        /// Will update one database without the other, no elements will be deleted.
        /// </summary>
        /// <param name="userMaterials">The database the user wants to syncronize with</param>
        /// <returns></returns>
        public bool SyncMaterials(CarboDatabase userMaterials)
        {
            try
            {
                //Loop though all materials and update the current ones
                for (int i = userMaterials.CarboMaterialList.Count - 1; i >= 0; i--)
                {
                    CarboMaterial newcarboMaterial = userMaterials.CarboMaterialList[i];
                    bool          matchfound       = false;

                    //Find a match in current database
                    foreach (CarboMaterial carboMaterial in this.CarboMaterialList)
                    {
                        if (newcarboMaterial.Name == carboMaterial.Name)
                        {
                            //Copy all properties;
                            carboMaterial.Copy(newcarboMaterial);
                            matchfound = true;
                            //next'
                            break;
                        }
                    }

                    //If this part has been reached;
                    //the material doesn't exist in the database and a new material will be created:
                    if (matchfound == false)
                    {
                        AddMaterial(newcarboMaterial);
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.WriteToLog(ex.Message);
                return(false);
            }

            //success:
            return(true);
        }
Exemple #9
0
        public static ObservableCollection <CarboGroup> GroupElementsAdvanced(ObservableCollection <CarboElement> carboElementList,
                                                                              bool groupCategory,
                                                                              bool groupSubCategory,
                                                                              bool groupType,
                                                                              bool groupMaterial,
                                                                              bool groupSubStructure,
                                                                              bool groupDemolition,
                                                                              CarboDatabase materialData,
                                                                              string uniqueTypeNames = "")
        {
            ObservableCollection <CarboGroup> result = new ObservableCollection <CarboGroup>();

            foreach (CarboElement ce in carboElementList)
            {
                result = AddToCarboGroup(result, ce, groupCategory, groupSubCategory, groupType, groupMaterial, groupSubStructure, groupDemolition, uniqueTypeNames);
            }


            result = mapGroupMaterials(result, materialData);
            result = RefreshValues(result);
            return(result);
        }
Exemple #10
0
        public static ObservableCollection <CarboGroup> GroupElementsAdvanced(ObservableCollection <CarboElement> carboElementList,
                                                                              bool groupCategory,
                                                                              bool groupSubCategory,
                                                                              bool groupType,
                                                                              bool groupMaterial,
                                                                              bool groupSubStructure,
                                                                              bool groupDemolition,
                                                                              CarboDatabase materialData,
                                                                              string uniqueTypeNames = "")
        {
            ObservableCollection <CarboGroup> result = new ObservableCollection <CarboGroup>();

            //First we build groups based on the import settings
            foreach (CarboElement ce in carboElementList)
            {
                result = AddToCarboGroup(result, ce, groupCategory, groupSubCategory, groupType, groupMaterial, groupSubStructure, groupDemolition, uniqueTypeNames);
            }
            //Now we map the importedMaterialParameter to one in our own database;
            result = mapGroupMaterials(result, materialData);
            //Recalculate the entire thing
            result = RefreshValues(result);
            return(result);
        }
Exemple #11
0
 public static ObservableCollection <CarboGroup> mapGroupMaterials(ObservableCollection <CarboGroup> group, CarboDatabase materialData)
 {
     if (group.Count > 0)
     {
         foreach (CarboGroup cg in group)
         {
             //The materialname was given by the elements, the values now need to be matched with a own one.
             CarboMaterial closestGroupMaterial = materialData.getClosestMatch(cg.MaterialName);
             //cg.MaterialName = closestGroupMaterial.Name;
             cg.setMaterial(closestGroupMaterial);
             cg.CalculateTotals();
         }
     }
     return(group);
 }
Exemple #12
0
 public static ObservableCollection <CarboGroup> mapGroupMaterials(ObservableCollection <CarboGroup> group, CarboDatabase materialData)
 {
     if (group.Count > 0)
     {
         foreach (CarboGroup cg in group)
         {
             CarboMaterial closestGroupMaterial = materialData.getClosestMatch(cg.MaterialName);
             //cg.MaterialName = closestGroupMaterial.Name;
             cg.setMaterial(closestGroupMaterial);
             cg.CalculateTotals();
         }
     }
     return(group);
 }