Esempio n. 1
0
        private void updateSelectionFromTemplate(Simulation simulation, OutputSelections templateOutputSelections)
        {
            var settings = simulation.OutputSelections;

            settings.Clear();

            //Cache all quantities by path key
            var quantityCache = new Cache <string, List <IQuantity> >();

            foreach (var quantity in simulation.All <IQuantity>())
            {
                var key = _keyPathMapper.MapFrom(quantity);
                if (!quantityCache.Contains(key))
                {
                    quantityCache[key] = new List <IQuantity>();
                }

                quantityCache[key].Add(quantity);
            }

            //find them from the template and select them
            foreach (var selectedQuantity in templateOutputSelections)
            {
                var key = _keyPathMapper.MapFrom(selectedQuantity);
                if (!quantityCache.Contains(key))
                {
                    continue;
                }
                var selectedQuantityType = selectedQuantity.QuantityType;

                //we only select quantity that have the exact same type
                quantityCache[key].Where(q => q.QuantityType == selectedQuantityType)
                .Each(q => settings.AddOutput(selectionFrom(q)));
            }
        }
 private string pathFrom(string quantityPath, QuantityType quantityType)
 {
     return(_keyPathMapper.MapFrom(quantityPath, quantityType, removeFirstEntry: true).Path);
 }