Example #1
0
        public static AnalyticalModel ToSAM_AnalyticalModel(this TBD.Building building)
        {
            if (building == null)
            {
                return(null);
            }

            ProfileLibrary profileLibrary = building.ToSAM_ProfileLibrary();

            Core.MaterialLibrary materialLibrary = building.ToSAM_MaterialLibrary();

            Core.Location location = new Core.Location(building.name, building.longitude, building.latitude, 0);
            location.SetValue(Core.LocationParameter.TimeZone, Core.Query.Description(Core.Query.UTC(building.timeZone)));

            Core.Address address = new Core.Address(null, null, null, Core.CountryCode.Undefined);

            return(new AnalyticalModel(building.name, null, location, address, ToSAM(building), materialLibrary, profileLibrary));
        }
Example #2
0
        public async Task <Core.Location> GoogleApiDingens(Core.Location location)
        {
            try
            {
                var response = await Client.GetAsync($"/maps/api/geocode/json?address={location.Street_number}+{location.Street_name}+{location.City}+&key=AIzaSyB_0wHwmbg5aMjbUxMvT3SxjlE_aSnYlp4");

                response.EnsureSuccessStatusCode();

                var result = await response.Content.ReadAsStringAsync();

                GoogleGeoecodingApi obj = JsonConvert.DeserializeObject <GoogleGeoecodingApi>(result);
                location.Lat = obj.Results.FirstOrDefault().Geometry.Location.Lat;
                location.Lng = obj.Results.FirstOrDefault().Geometry.Location.Lng;
                return(location);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Example #3
0
        public MapPageRenderer()
        {
            Subscribe(Messages.LOCATION_CHANGED, obj =>
                {
                    _location = obj as Core.Location;

                    LatLng location = new LatLng(_location.Latitude, _location.Longitude);
                    CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                    builder.Target(location);
                    builder.Zoom(18);
                    CameraPosition cameraPosition = builder.Build();
                    CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                    var activity = this.Context as Activity;
                    MapFragment mapFrag = (MapFragment)activity.FragmentManager.FindFragmentById(Resource.Id.map);
                    _map = mapFrag.Map;
                    _map?.MoveCamera(cameraUpdate);

                    var textview = _view.FindViewById<Android.Widget.TextView>(Resource.Id.textView);
                    textview.Text = $"{_location.Latitude} , {_location.Longitude}";
                });
        }
Example #4
0
        public MapPageRenderer()
        {
            Subscribe(Messages.LOCATION_CHANGED, obj =>
            {
                _location = obj as Core.Location;

                LatLng location = new LatLng(_location.Latitude, _location.Longitude);
                CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                builder.Target(location);
                builder.Zoom(18);
                CameraPosition cameraPosition = builder.Build();
                CameraUpdate cameraUpdate     = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                var activity        = this.Context as Activity;
                MapFragment mapFrag = (MapFragment)activity.FragmentManager.FindFragmentById(Resource.Id.map);
                _map = mapFrag.Map;
                _map?.MoveCamera(cameraUpdate);

                var textview  = _view.FindViewById <Android.Widget.TextView>(Resource.Id.textView);
                textview.Text = $"{_location.Latitude} , {_location.Longitude}";
            });
        }
Example #5
0
 public LocationResponse(int status, string message, Core.Location data)
 {
     Status  = status;
     Message = message;
     Data    = data;
 }
Example #6
0
        public static AnalyticalModel ToSAM_AnalyticalModel(this Document document, ConvertSettings convertSettings)
        {
            if (document == null)
            {
                return(null);
            }

            ProjectInfo projectInfo = document.ProjectInformation;

            AnalyticalModel result = convertSettings?.GetObject <AnalyticalModel>(projectInfo?.Id);

            if (result != null)
            {
                return(result);
            }

            Core.Location location = Core.Revit.Query.Location(document);
            Address       address  = null;

            if (projectInfo != null)
            {
                address = new Address(Guid.NewGuid(), projectInfo.BuildingName, projectInfo.Address, null, null, CountryCode.Undefined);
            }

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            EnergyAnalysisDetailModelOptions energyAnalysisDetailModelOptions = new EnergyAnalysisDetailModelOptions();

            energyAnalysisDetailModelOptions.Tier                   = EnergyAnalysisDetailModelTier.SecondLevelBoundaries;
            energyAnalysisDetailModelOptions.EnergyModelType        = EnergyModelType.SpatialElement;
            energyAnalysisDetailModelOptions.ExportMullions         = true;
            energyAnalysisDetailModelOptions.IncludeShadingSurfaces = true;
            energyAnalysisDetailModelOptions.SimplifyCurtainSystems = false;

            EnergyDataSettings energyDataSettings = EnergyDataSettings.GetFromDocument(document);

            energyDataSettings.ExportComplexity = gbXMLExportComplexity.ComplexWithMullionsAndShadingSurfaces;
            energyDataSettings.ExportDefaults   = false;
#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, DisplayUnitType.DUT_METERS);
#else
            energyDataSettings.SliverSpaceTolerance = UnitUtils.ConvertToInternalUnits(0.005, UnitTypeId.Meters);
#endif
            energyDataSettings.AnalysisType = AnalysisMode.BuildingElements;
            energyDataSettings.EnergyModel  = false;

            //Reseting Project Base Point
            IEnumerable <Element> elements = new FilteredElementCollector(document).OfCategory(BuiltInCategory.OST_ProjectBasePoint);
            foreach (Element element in elements)
            {
                if (element.Pinned)
                {
                    element.Pinned = false;
                }

                Parameter parameter = null;

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_EASTWEST_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }

                parameter = element.get_Parameter(BuiltInParameter.BASEPOINT_ANGLETON_PARAM);
                if (parameter != null && !parameter.IsReadOnly)
                {
                    parameter.Set(0.0);
                }
            }

            //AnalyticalSpaces
            EnergyAnalysisDetailModel   energyAnalysisDetailModel         = EnergyAnalysisDetailModel.Create(document, energyAnalysisDetailModelOptions);
            IList <EnergyAnalysisSpace> energyAnalysisSpaces              = energyAnalysisDetailModel.GetAnalyticalSpaces();
            Dictionary <string, Tuple <Panel, List <Space> > > dictionary = new Dictionary <string, Tuple <Panel, List <Space> > >();
            foreach (EnergyAnalysisSpace energyAnalysisSpace in energyAnalysisSpaces)
            {
                try
                {
                    if (energyAnalysisSpace.Area <= Core.Tolerance.MacroDistance)
                    {
                        continue;
                    }

                    Space space = energyAnalysisSpace.ToSAM(convertSettings);
                    if (space == null)
                    {
                        continue;
                    }

                    Shell shell = Geometry.Revit.Convert.ToSAM(energyAnalysisSpace.GetClosedShell());
                    if (shell == null)
                    {
                        continue;
                    }

                    adjacencyCluster.AddObject(space);

                    foreach (EnergyAnalysisSurface energyAnalysisSurface in energyAnalysisSpace.GetAnalyticalSurfaces())
                    {
                        Tuple <Panel, List <Space> > tuple;
                        if (!dictionary.TryGetValue(energyAnalysisSurface.SurfaceName, out tuple))
                        {
                            Panel panel = energyAnalysisSurface.ToSAM(convertSettings, shell);
                            if (panel == null)
                            {
                                continue;
                            }

                            tuple = new Tuple <Panel, List <Space> >(panel, new List <Space>());
                            dictionary[energyAnalysisSurface.SurfaceName] = tuple;
                        }

                        tuple.Item2.Add(space);
                    }
                }
                catch
                {
                }
            }

            #region Additional Checks (WIP)
            //Additional Check for wrongly recoginzed internal panels (WIP)
            List <Tuple <string, Panel, Space, Face3D> > tuples_External = new List <Tuple <string, Panel, Space, Face3D> >();
            foreach (KeyValuePair <string, Tuple <Panel, List <Space> > > keyValuePair in dictionary)
            {
                Tuple <Panel, List <Space> > tuple = keyValuePair.Value;
                if (tuple.Item1 != null && tuple.Item2 != null && tuple.Item2.Count == 1)
                {
                    Face3D face3D = tuple.Item1.GetFace3D();
                    if (face3D != null)
                    {
                        tuples_External.Add(new Tuple <string, Panel, Space, Face3D>(keyValuePair.Key, tuple.Item1, tuple.Item2[0], face3D));
                    }
                }
            }

            while (tuples_External.Count > 0)
            {
                Tuple <string, Panel, Space, Face3D> tuple = tuples_External[0];
                tuples_External.RemoveAt(0);

                Point3D point3D = tuple.Item4.InternalPoint3D();
                if (point3D == null)
                {
                    continue;
                }

                List <Tuple <string, Panel, Space, Face3D> > tuples_Overlap = tuples_External.FindAll(x => x.Item4.Inside(point3D));
                if (tuples_Overlap.Count != 1)
                {
                    continue;
                }

                tuples_Overlap.Add(tuple);

                tuples_Overlap.Sort((x, y) => y.Item4.GetArea().CompareTo(x.Item4.GetArea()));

                tuple = tuples_Overlap[0];
                Tuple <string, Panel, Space, Face3D> tuple_Overlap = tuples_Overlap[1];

                dictionary[tuple.Item1].Item2.Add(tuple_Overlap.Item3);
                dictionary[tuple_Overlap.Item1] = new Tuple <Panel, List <Space> >(Analytical.Create.Panel(dictionary[tuple_Overlap.Item1].Item1, PanelType.Shade), null);
                int index = tuples_External.IndexOf(tuple_Overlap);
                if (index != -1)
                {
                    tuples_External.RemoveAt(index);
                }
            }
            #endregion

            foreach (Tuple <Panel, List <Space> > tuple in dictionary.Values)
            {
                Panel panel = tuple.Item1;

                adjacencyCluster.AddObject(panel);
                tuple.Item2?.ForEach(x => adjacencyCluster.AddRelation(x, panel));
            }

            //AnalyticalShadingSurfaces
            IList <EnergyAnalysisSurface> analyticalShadingSurfaces = energyAnalysisDetailModel.GetAnalyticalShadingSurfaces();
            foreach (EnergyAnalysisSurface energyAnalysisSurface in analyticalShadingSurfaces)
            {
                try
                {
                    Panel panel = energyAnalysisSurface.ToSAM(convertSettings);
                    if (panel == null)
                    {
                        continue;
                    }

                    panel = Analytical.Create.Panel(panel, PanelType.Shade);

                    adjacencyCluster.AddObject(panel);
                }
                catch
                {
                }
            }

            adjacencyCluster.MapZones();

            IEnumerable <IMaterial> materials       = Analytical.Query.Materials(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <MaterialLibrary>(AnalyticalSettingParameter.DefaultMaterialLibrary));
            MaterialLibrary         materialLibrary = Core.Create.MaterialLibrary("Default Material Library", materials);

            IEnumerable <Profile> profiles       = Analytical.Query.Profiles(adjacencyCluster, Analytical.ActiveSetting.Setting.GetValue <ProfileLibrary>(AnalyticalSettingParameter.DefaultProfileLibrary));
            ProfileLibrary        profileLibrary = new ProfileLibrary("Default Profile Library", profiles);

            result = new AnalyticalModel(document.Title, null, location, address, adjacencyCluster, materialLibrary, profileLibrary);
            result.UpdateParameterSets(document.ProjectInformation, ActiveSetting.Setting.GetValue <TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            convertSettings?.Add(projectInfo.Id, result);

            return(result);
        }
        public static AnalyticalModel ToSAM(this Campus campus, double silverSpacing = Tolerance.MacroDistance, double tolerance = Tolerance.MicroDistance)
        {
            Address address = campus.Location.ToSAM_Address();

            Core.Location location = campus.Location.ToSAM(tolerance);

            AdjacencyCluster adjacencyCluster = new AdjacencyCluster();

            Dictionary <string, Space> dictionary_Space = new Dictionary <string, Space>();

            Building[] buildings = campus.Buildings;
            if (buildings != null)
            {
                foreach (Building building in buildings)
                {
                    gbXMLSerializer.Space[] spaces = building.Spaces;
                    if (spaces != null)
                    {
                        foreach (gbXMLSerializer.Space space_gbXML in spaces)
                        {
                            if (space_gbXML == null)
                            {
                                continue;
                            }

                            Space space_SAM = space_gbXML.ToSAM(silverSpacing, tolerance);
                            if (space_SAM == null)
                            {
                                continue;
                            }

                            dictionary_Space[space_gbXML.id] = space_SAM;

                            adjacencyCluster.AddObject(space_SAM);
                        }
                    }
                }
            }

            Surface[] surfaces = campus.Surface;
            if (surfaces != null)
            {
                foreach (Surface surface in surfaces)
                {
                    if (surface == null)
                    {
                        continue;
                    }

                    Panel panel = surface.ToSAM(tolerance);
                    if (panel == null)
                    {
                        continue;
                    }

                    adjacencyCluster.AddObject(panel);

                    AdjacentSpaceId[] adjacentSpaceIds = surface.AdjacentSpaceId;
                    if (adjacentSpaceIds == null || adjacentSpaceIds.Length == 0)
                    {
                        continue;
                    }

                    foreach (AdjacentSpaceId adjacentSpaceId in adjacentSpaceIds)
                    {
                        string id = adjacentSpaceId?.spaceIdRef;
                        if (string.IsNullOrWhiteSpace(id))
                        {
                            continue;
                        }

                        Space space = null;

                        if (!dictionary_Space.TryGetValue(id, out space))
                        {
                            continue;
                        }

                        adjacencyCluster.AddRelation(panel, space);
                    }
                }
            }

            AnalyticalModel result = new AnalyticalModel(string.Empty, string.Empty, location, address, adjacencyCluster);

            return(result);
        }