Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facade_Engine: ConvertOffsetDefinition #2285

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Facade_Engine/Facade_Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Physical_Engine">
<HintPath>C:\ProgramData\BHoM\Assemblies\Physical_Engine.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="Physical_oM">
<HintPath>C:\ProgramData\BHoM\Assemblies\Physical_oM.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -97,6 +102,7 @@
<Compile Include="Compute\ComponentAreas.cs" />
<Compile Include="Compute\EdgeAdjacencies.cs" />
<Compile Include="Compute\AdjacentElements.cs" />
<Compile Include="Modify\SetOffsetFromFacetoFaceDist.cs" />
<Compile Include="Modify\OffsetVariable.cs" />
<Compile Include="Query\AdjacencyId.cs" />
<Compile Include="Compute\UniqueAdjacencies.cs" />
Expand Down
88 changes: 88 additions & 0 deletions Facade_Engine/Modify/SetOffsetFromFacetoFaceDist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2021, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.Engine.Base;
using BH.oM.Geometry;
using BH.oM.Base;
using BH.Engine.Geometry;
using BH.Engine.Reflection;
using BH.oM.Reflection.Attributes;
using BH.oM.Reflection.Debugging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BH.oM.Facade.Elements;
using BH.oM.Facade.Fragments;
using BH.Engine.Physical;

namespace BH.Engine.Facade
{
public static partial class Modify
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Sets an opening offset based on a specified value defining the desired distance between the panel's exterior face and the openings exterior face.")]
[Input("panel", "A panel to base opening offset on. The panel must have a construction thickness.")]
[Input("opening", "An opening to set the offset on based on the specified value and provided panel. The opening must have a glazing thickness.")]
[Input("useroffset", "A user defined offset (exterior face of panel to exterior face of glazing).")]
[Output("opening", "The opening with the specified offset applied as a fragment.")]
public static Opening SetOffsetFromFacetoFaceDist(this Opening opening, Panel panel, double useroffset)
{
//TODO:
//Check for null case
if (panel == null || opening == null || useroffset == null)
return null;

//Retrieve panel width and opening glazing width
double panelwidth = panel.Construction.IThickness();
double glzwidth = opening.OpeningConstruction.IThickness();

//Check for existing offset on reference panel
double panelOffset = 0;
ConstructionOffset panelOffsetFragment = BH.Engine.Base.Query.FindFragment<ConstructionOffset>(panel);
if (panelOffsetFragment != null)
{
panelOffset = panelOffsetFragment.OffsetDistance;
}

//Calculate and return offset from defined panel centerline to glazing (opening) centerline
double offset = panelOffset + 0.5 * panelwidth - 0.5 * glzwidth - useroffset;

//Apply offset value to existing fragment (or new if not yet existing)
ConstructionOffset offsetFragment = BH.Engine.Base.Query.FindFragment<ConstructionOffset>(opening);
if (offsetFragment == null)
{
ConstructionOffset newOffsetFragment = new ConstructionOffset() { OffsetDistance = offset };
opening.Fragments.Add(newOffsetFragment);
}
else
{
offsetFragment.OffsetDistance = offset;
}

return opening;
}
}
}