Exemplo n.º 1
0
        public bool AddMaterial(CarboMaterial newMaterial)
        {
            bool result = false;
            bool exists = false;
            int  id     = getUniqueId();

            newMaterial.Id = id;

            foreach (CarboMaterial cm in CarboMaterialList)
            {
                if (cm.Name == newMaterial.Name)
                {
                    exists = true;
                    break;
                }
            }

            if (exists == false)
            {
                CarboMaterialList.Add(newMaterial);
                result = true;
            }
            else
            {
                result = false;
            }

            return(result);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        public void UpdateMaterial(CarboGroup TargetGroup, CarboMaterial NewMaterial)
        {
            if (NewMaterial != null)
            {
                foreach (CarboGroup cg in groupList)
                {
                    // Update selected group per se.
                    //
                    if (cg.Id == TargetGroup.Id)
                    {
                        cg.MaterialName = NewMaterial.Name;
                        cg.Material     = NewMaterial;
                    }

                    //Update all idential materials
                    if (cg.Material.Id == NewMaterial.Id)
                    {
                        cg.MaterialName = NewMaterial.Name;
                        cg.Material     = NewMaterial;
                    }
                }
            }

            justSaved = false;
        }
Exemplo n.º 4
0
        public CarboGroup(CarboElement carboElement)
        {
            Id           = -999;
            MaterialName = carboElement.MaterialName;
            Category     = carboElement.Category;
            SubCategory  = carboElement.SubCategory;

            Description = "";

            Volume  = carboElement.Volume;
            Density = 0;
            Mass    = 0;

            //EEI = 0;
            ECI = 0;
            //EE = 0;
            EC = 0;

            PerCent  = 0;
            Material = new CarboMaterial();
            Material = carboElement.Material;

            AllElements = new List <CarboElement>();

            AllElements.Add(carboElement);
            isDemolished   = carboElement.isDemolished;
            isSubstructure = carboElement.isSubstructure;
        }
Exemplo n.º 5
0
 public void setMaterial(CarboMaterial carboMaterial)
 {
     //this.Material = carboMaterial;
     MaterialName = carboMaterial.Name;
     Density      = carboMaterial.Density;
     ECI          = carboMaterial.ECI;
 }
Exemplo n.º 6
0
        internal List <CarboMaterial> getUsedmaterials()
        {
            List <CarboMaterial> result = new List <CarboMaterial>();

            foreach (CarboGroup group in getGroupList)
            {
                //get material from group
                CarboMaterial material = group.Material;
                bool          isunique = true;

                foreach (CarboMaterial mat in result)
                {
                    if (material.Name == mat.Name)
                    {
                        isunique = false;
                        break;
                    }
                }
                if (isunique == true)
                {
                    result.Add(material);
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        internal void setMaterial(CarboMaterial material)
        {
            this.MaterialName = material.Name;
            this.Material     = material;
            this.Density      = material.Density;

            CalculateTotals();
        }
Exemplo n.º 8
0
 internal void Calculate(CarboMaterial material)
 {
     if (material != null)
     {
         ///This calculation can be made;
         ECI  = material.ECI;
         EC   = material.ECI * (material.Density * Volume);
         Mass = material.Density * Volume;
     }
 }
Exemplo n.º 9
0
        public CarboMaterial getClosestMatch(string materialToLookup)
        {
            int score     = 0;
            int highscore = -50;
            int basescore = materialToLookup.Length;

            CarboMaterial result = new CarboMaterial();

            string[] wordsInMaterialToLookup = materialToLookup.Split(' ');


            foreach (CarboMaterial cm in this.CarboMaterialList)
            {
                score = 0;

                //Direct Hit == LOADS OF POINTS;

                if (cm.Name.ToLower() == materialToLookup.ToLower())
                {
                    score += (basescore * 3);
                }

                // string materialname = cm.Name;
                int dist = Utils.CalcLevenshteinDistance(materialToLookup, cm.Name);
                score += (basescore - dist);

                //Get additional score points;

                //See if any of the words have a direct match in the lookup;
                foreach (string word in wordsInMaterialToLookup)
                {
                    string lowerWord = word.ToLower();

                    //Thif the material contains a word from the carbolist; get points
                    bool contains = cm.Name.IndexOf(lowerWord, StringComparison.OrdinalIgnoreCase) >= 0;

                    if (contains == true)
                    {
                        score += basescore * 2;
                    }
                }

                //Make a decision of this is better than current best;
                if (score > highscore)
                {
                    highscore = score;
                    result    = cm;
                }
            }
            Utils.WriteToLog("LookedupMaterial: " + materialToLookup + " Score: " + highscore + " -> " + result.Name);
            return(result);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
 public CarboElement()
 {
     Id           = -999;
     Name         = "";
     MaterialName = "Other";
     Category     = "Other";
     SubCategory  = "";
     Volume       = 0;
     Level        = 0;
     isDemolished = false;
     isExisting   = false;
     Material     = new CarboMaterial();
 }
Exemplo n.º 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);
 }
Exemplo n.º 13
0
        internal void Copy(CarboMaterial cmNew)
        {
            var type = typeof(CarboMaterial);

            foreach (var sourceProperty in type.GetProperties())
            {
                var targetProperty = type.GetProperty(sourceProperty.Name);
                targetProperty.SetValue(this, sourceProperty.GetValue(cmNew, null), null);
            }
            foreach (var sourceField in type.GetFields())
            {
                var targetField = type.GetField(sourceField.Name);
                targetField.SetValue(this, sourceField.GetValue(cmNew));
            }
        }
Exemplo n.º 14
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);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Excact Match
        /// </summary>
        /// <param name="materialName"></param>
        /// <returns></returns>
        public CarboMaterial GetExcactMatch(string materialName)
        {
            CarboMaterial result = null;

            foreach (CarboMaterial cm in this.CarboMaterialList)
            {
                // string materialname = cm.Name;
                if (cm.Name == materialName)
                {
                    result = cm;
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 16
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.");
            }
        }
Exemplo n.º 17
0
        public CarboGroup(CarboElement carboElement)
        {
            Id           = -999;
            MaterialName = carboElement.MaterialName;
            Category     = carboElement.Category;
            SubCategory  = carboElement.SubCategory;

            Description = "";

            Volume  = carboElement.Volume;
            Density = 0;
            Mass    = 0;

            //EEI = 0;
            ECI = 0;
            //EE = 0;
            EC = 0;

            //Correction Formula
            Correction            = "";
            CorrectionDescription = "";
            //Waste
            Waste            = 0;
            WasteDescription = "";
            //Additional
            Additional            = 0;
            AdditionalDescription = "";
            //B4
            B4Factor            = 1;
            ComponentLifePeriod = 50;
            AssetLifePeriod     = 50;
            B4Description       = "";

            PerCent = 0;

            //get the material

            Material = new CarboMaterial();
            //Material = carboElement.Material; removed from CarboElement

            AllElements = new List <CarboElement>();

            AllElements.Add(carboElement);
            isDemolished   = carboElement.isDemolished;
            isSubstructure = carboElement.isSubstructure;
        }
Exemplo n.º 18
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
            {
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Approx Match
        /// </summary>
        /// <param name="materialToLookup"></param>
        /// <returns></returns>
        public CarboMaterial getClosestMatch(CarboMaterial materialToLookup)
        {
            CarboMaterial result   = new CarboMaterial();
            int           basedist = 100;

            foreach (CarboMaterial cm in this.CarboMaterialList)
            {
                // string materialname = cm.Name;
                int dist = Utils.CalcLevenshteinDistance(materialToLookup.Name, cm.Name);

                if (dist < basedist)
                {
                    basedist = dist;
                    result   = cm;
                }
            }
            return(result);
        }
Exemplo n.º 20
0
        public CarboGroup(int id, string materialName, string category, string description, double volume, double density, double mass, double eei, double eci, double ee, double ec)
        {
            Id           = id;
            MaterialName = materialName;
            Category     = category;
            Description  = description;

            Volume  = volume;
            Density = density;
            Mass    = mass;

            //EEI = eei;
            ECI = eci;
            //EE = ee;
            EC = ec;

            PerCent     = 0;
            Material    = new CarboMaterial();
            AllElements = new List <CarboElement>();
        }
Exemplo n.º 21
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);
                    }
                }
            }
        }
Exemplo n.º 22
0
        /// <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);
        }
Exemplo n.º 23
0
        public CarboGroup()
        {
            Id           = -999;
            MaterialName = "";
            Category     = "";
            SubCategory  = "";
            Description  = "";
            Correction   = "";

            Volume  = 0;
            Density = 0;
            Mass    = 0;

            ECI = 0;
            EC  = 0;

            PerCent     = 0;
            Material    = new CarboMaterial();
            AllElements = new List <CarboElement>();

            isDemolished   = false;
            isSubstructure = false;
        }
Exemplo n.º 24
0
        public CarboGroup()
        {
            Id           = -999;
            MaterialName = "";
            Category     = "";
            SubCategory  = "";
            Description  = "";

            Volume  = 0;
            Density = 0;
            Mass    = 0;

            ECI = 0;
            EC  = 0;

            //Correction Formula
            Correction            = "";
            CorrectionDescription = "";
            //Waste
            Waste            = 0;
            WasteDescription = "";
            //Additional
            Additional            = 0;
            AdditionalDescription = "";
            //B4
            B4Factor            = 1;
            ComponentLifePeriod = 50;
            AssetLifePeriod     = 50;
            B4Description       = "";

            PerCent     = 0;
            Material    = new CarboMaterial();
            AllElements = new List <CarboElement>();

            isDemolished   = false;
            isSubstructure = false;
        }
Exemplo n.º 25
0
        public CarboGroup(int id, string materialName, string category, string description, double volume, double density, double mass, double eei, double eci, double ee, double ec)
        {
            Id           = id;
            MaterialName = materialName;
            Category     = category;
            Description  = description;

            Volume  = volume;
            Density = density;
            Mass    = mass;

            //EEI = eei;
            ECI = eci;
            //EE = ee;
            EC = ec;

            //Correction Formula
            Correction            = "";
            CorrectionDescription = "";
            //Waste
            Waste            = 0;
            WasteDescription = "";
            //Additional
            Additional            = 0;
            AdditionalDescription = "";
            //B4
            B4Factor            = 1;
            ComponentLifePeriod = 50;
            AssetLifePeriod     = 50;
            B4Description       = "";

            PerCent = 0;

            Material    = new CarboMaterial();
            AllElements = new List <CarboElement>();
        }
Exemplo n.º 26
0
 public void setMaterial(CarboMaterial carboMaterial)
 {
     this.Material = carboMaterial;
     MaterialName  = carboMaterial.Name;
 }
Exemplo n.º 27
0
        private static ObservableCollection <CarboGroup> AddToCarboGroup(ObservableCollection <CarboGroup> carboGroupList, CarboElement carboElement, CarboMaterial mappedMaterial)
        {
            int idbase = 1000;

            //Try Add
            foreach (CarboGroup cg in carboGroupList)
            {
                if (cg.Category == carboElement.Category)
                {
                    if (cg.MaterialName == mappedMaterial.Name)
                    {
                        cg.AllElements.Add(carboElement);
                        return(carboGroupList);
                    }
                }
            }
            //NoCategoryWasFound: make new group
            int id = carboGroupList.Count;

            CarboGroup newGroup = new CarboGroup(carboElement);

            newGroup.Id           = idbase;
            newGroup.Material     = mappedMaterial;
            newGroup.MaterialName = mappedMaterial.Name;
            newGroup.Density      = mappedMaterial.Density;
            //newGroup.ECI = mappedMaterial.ECI;
            //newGroup.EEI = mappedMaterial.EEI;
            //newGroup.Volume = carboElement.Volume;

            carboGroupList.Add(newGroup);
            return(carboGroupList);
        }