Esempio n. 1
0
        public CreateModelViewModel(CreateModelModel model, bool dragonfly)
        {
            DispatcherHelper.Initialize();

            Model               = model;
            Dragonfly           = dragonfly;
            Title               = Dragonfly ? "Dragonfly - Create Model" : "Honeybee - Create Model";
            Settings            = AppSettings.Instance;
            ContextShades       = Model.GetContextShades().ToObservableCollection();
            BldgConstructionSet = new ConstructionSet(Settings.StoredSettings.EnergyModelSettings.BldgConstructionSet);
            BldgProgramType     = new ProgramType(Settings.StoredSettings.EnergyModelSettings.BldgProgramType);

            var color = dragonfly
                ? Color.FromRgb(0, 166, 81)
                : Color.FromRgb(245, 179, 76);

            BorderBrush = new SolidColorBrush(color);

            SpatialObjects = new ListCollectionView(SpatialObjectsModels);
            SpatialObjects.GroupDescriptions.Clear();
            SpatialObjects.GroupDescriptions.Add(new PropertyGroupDescription("Level", new LevelToNameConverter()));
            SpatialObjects.Filter = FilterDataGrid;

            Close                         = new RelayCommand <Window>(OnClose);
            Help                          = new RelayCommand(OnHelp);
            ClearFilters                  = new RelayCommand(OnClearFilters);
            FilterChanged                 = new RelayCommand(OnFilterChanged);
            PickSpatialObjects            = new RelayCommand(OnPickSpatialObjects);
            OpenPopup                     = new RelayCommand <Popup>(OnOpenPopup);
            ClosePopup                    = new RelayCommand <Popup>(OnClosePopup);
            CloseBldgConstructionSetPopup = new RelayCommand <Popup>(OnCloseBldgConstructionSetPopup);
            CloseProgramTypePopup         = new RelayCommand <Popup>(OnCloseProgramTypePopup);
            CloseBuildingProgramTypePopup = new RelayCommand <Popup>(OnCloseBuildingProgramTypePopup);
            ResetConstructionSet          = new RelayCommand(OnResetConstructionSet);
            ResetProgramType              = new RelayCommand(OnResetProgramType);
            ShowBoundaryConditions        = new RelayCommand <SpatialObjectWrapper>(OnShowBoundaryConditions);
            ShowDetails                   = new RelayCommand <SpatialObjectWrapper>(OnShowDetails);
            ExportModel                   = new RelayCommand(OnExportModel);
            RunSimulation                 = new RelayCommand(OnRunSimulation);
            AddPlanting                   = new RelayCommand(OnAddPlanting);
            AddFaces                      = new RelayCommand(OnAddFaces);
            ClearShades                   = new RelayCommand(OnClearShades);
            ShowLog                       = new RelayCommand(OnShowLog);
        }
Esempio n. 2
0
        private void OnClosePopup(Popup popup)
        {
            popup.IsOpen = false;

            foreach (SpatialObjectWrapper so in SpatialObjects)
            {
                if (!so.IsSelected)
                {
                    continue;
                }

                so.Room2D.Properties.Energy.ConstructionSet.Vintage          = ConstructionSetTemp.Vintage;
                so.Room2D.Properties.Energy.ConstructionSet.ClimateZone      = ConstructionSetTemp.ClimateZone;
                so.Room2D.Properties.Energy.ConstructionSet.ConstructionType = ConstructionSetTemp.ConstructionType;
                so.IsConstructionSetOverriden = true;
            }

            ConstructionSetTemp = new ConstructionSet();
        }
Esempio n. 3
0
        public static Log Log(this HoneybeeSchema.AnyOf <ConstructionSetAbridged, ConstructionSet> constructionSet)
        {
            if (constructionSet == null)
            {
                return(null);
            }

            if (constructionSet.Obj is IIDdBase)
            {
                return(Log((IIDdBase)constructionSet.Obj));
            }

            if (constructionSet.Obj is ConstructionSet)
            {
                ConstructionSet constructionSet_Temp = (ConstructionSet)constructionSet.Obj;
                //TODO: Implement identifier Log for construction in constructionSet
            }

            return(null);
        }
Esempio n. 4
0
        //private HB.ConstructionSet GetDefaultConstructionSet()
        //{
        //    var args = new List<string> { "Default Generic Construction Set", "--none-defaults", "False" };
        //    var jsonConstructionSets = RunHoneybeeEnergyCommand2("construction-set-by-id", args);
        //    JsonConverter[] converters =
        //    {
        //        new HB.AnyOfJsonConverter()
        //    };

        //    return JsonConvert.DeserializeObject<HB.ConstructionSet>(jsonConstructionSets, converters);
        //}

        private List <HB.ConstructionSet> GetConstructionSets(IEnumerable <Room2D> rooms, ConstructionSet bConstructionSet)
        {
            var cSets = rooms
                        .GroupBy(x => x.Properties.Energy.ConstructionSet.Identifier)
                        .Select(x => x.Key)
                        .ToList();

            if (!cSets.Contains(bConstructionSet.Identifier))
            {
                cSets.Add(bConstructionSet.Identifier);
            }

            var jsonConstructionSets = RunHoneybeeEnergyCommand("construction-sets-by-id", cSets);

            JsonConverter[] converters =
            {
                new HB.AnyOfJsonConverter()
            };

            return(JsonConvert.DeserializeObject <List <HB.ConstructionSet> >(jsonConstructionSets, converters));
        }
Esempio n. 5
0
        public string SerializeRoom2D(
            List <Room2D> rooms,
            ProgramType bProgramType,
            ConstructionSet bConstructionSet,
            bool dragonfly,
            List <Shade> shades)
        {
            try
            {
                var modelFilePath = string.Empty;

                var hbProgramTypes     = GetProgramTypeSet(rooms, bProgramType);
                var hbConstructionSets = GetConstructionSets(rooms, bConstructionSet);
                var properties         = new ModelProperties {
                    Energy = new ModelEnergyProperties()
                };

                hbProgramTypes.ForEach(x => properties.Energy.ProgramTypes.Add(x));
                hbConstructionSets.ForEach(x => properties.Energy.ConstructionSets.Add(x));

                var contextShades = shades ?? GetContextShades();

                if (dragonfly)
                {
                    var stories = rooms
                                  .GroupBy(x => x.LevelName)
                                  .Select(x => new Story(x.Key, x.ToList(), new StoryPropertiesAbridged
                    {
                        Energy = new StoryEnergyPropertiesAbridged
                        {
                            ConstructionSet = bConstructionSet?.Identifier
                        }
                    }))
                                  .ToList();

                    var building = new Building("Building 1", stories,
                                                new BuildingPropertiesAbridged
                    {
                        Energy = new BuildingEnergyPropertiesAbridged
                        {
                            ConstructionSet = bConstructionSet?.Identifier
                        }
                    });

                    var model = new Model("Model 1", new List <Building> {
                        building
                    }, new ModelProperties(), contextShades)
                    {
                        Units     = HB.Units.Feet,
                        Tolerance = 0.0001d
                    };
                    var dfModel = model.ToDragonfly();
                    dfModel.Properties = properties.ToDragonfly();

                    var json = JsonConvert.SerializeObject(dfModel, Formatting.Indented, new HB.AnyOfJsonConverter());
                    if (string.IsNullOrWhiteSpace(json))
                    {
                        return(modelFilePath);
                    }

                    var simulationDir = AppSettings.Instance.StoredSettings.SimulationSettings.SimulationFolder;
                    var filePath      = Path.Combine(simulationDir, "Dragonfly.json");
                    if (string.IsNullOrWhiteSpace(simulationDir))
                    {
                        return(modelFilePath);
                    }

                    if (!Directory.Exists(simulationDir))
                    {
                        Directory.CreateDirectory(simulationDir);
                    }

                    if (File.Exists(filePath))
                    {
                        FileUtils.TryDeleteFile(filePath);
                    }

                    File.WriteAllText(filePath, json);
                    modelFilePath = filePath;

                    return(modelFilePath);
                }
                else
                {
                    var model = new Model("Model 1", new List <HB.Room>(), new ModelProperties(), contextShades)
                    {
                        Units     = HB.Units.Feet,
                        Tolerance = 0.0001d
                    };

                    var hbRooms = rooms.Select(x =>
                    {
                        var hb = x.ToHoneybee();
                        hb.Properties.Energy.ConstructionSet = x.Properties.Energy.ConstructionSet.Identifier;
                        hb.Properties.Energy.ProgramType     = x.Properties.Energy.ProgramType.Identifier;
                        return(hb);
                    }).ToList();

                    model.Rooms = hbRooms;

                    var hbModel = model.ToHoneybee();
                    hbModel.Properties = properties.ToHoneybee();

                    var json = JsonConvert.SerializeObject(hbModel, Formatting.Indented, new HB.AnyOfJsonConverter());
                    if (string.IsNullOrWhiteSpace(json))
                    {
                        return(modelFilePath);
                    }

                    var simulationDir = AppSettings.Instance.StoredSettings.SimulationSettings.SimulationFolder;
                    var filePath      = Path.Combine(simulationDir, "Honeybee.json");
                    if (string.IsNullOrWhiteSpace(simulationDir))
                    {
                        return(modelFilePath);
                    }

                    if (!Directory.Exists(simulationDir))
                    {
                        Directory.CreateDirectory(simulationDir);
                    }

                    if (File.Exists(filePath))
                    {
                        FileUtils.TryDeleteFile(filePath);
                    }

                    File.WriteAllText(filePath, json);
                    modelFilePath = filePath;

                    return(modelFilePath);
                }
            }
            catch (Exception e)
            {
                _logger.Fatal(e);
                return(string.Empty);
            }
        }