-
Notifications
You must be signed in to change notification settings - Fork 10
Allow Multiple Logic Requests #474
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
Open
GCRA101
wants to merge
17
commits into
develop
Choose a base branch
from
ETABS_Toolkit-#465-AllowMultipleLogicRequests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2813222
Add Read Method for pulling IRequests
GCRA101 5c7f07b
Add Read Method for both FilterRequests and ILogicalRequests
GCRA101 0306993
Add Reflection-based Dynamic Comparer class to allow to intersect Has…
GCRA101 1a75a9a
Fix bug
GCRA101 3460fdf
Turn HashSet into List to allow for use of .Equals method from Dynami…
GCRA101 afebaa6
Fix minor issues
GCRA101 8674e64
Add code to read from LogicalNotRequests
GCRA101 c3fad84
Add comments highlighting use of GENERIC TYPES, HASH TABLES, STREAMS,…
GCRA101 06eee2b
Remove outstanding lines of code
GCRA101 15a93c5
Improve Hash function for the DynamicCompararer
GCRA101 a0a0911
Improve the Dynamic Comparer methods .Equals() and .GetHashCode() and…
GCRA101 2ee2250
Add comments
GCRA101 53c41c9
Update _Read.cs
GCRA101 7174aee
Turn DynamicComparer private class into public class in Types namespace
GCRA101 31623c0
Add copyright header to DynamicComparer class
GCRA101 ee7d8ae
Repaste Copyright header in DynamicComparer
GCRA101 e482ce6
Revert Execute.cs to original
GCRA101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * This file is part of the Buildings and Habitats object Model (BHoM) | ||
| * Copyright (c) 2015 - 2021, the respective contributors. All rights reserved. | ||
| * | ||
|
Check failure on line 4 in Etabs_Adapter/Types/DynamicComparer.cs
|
||
| * 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.oM.Adapters.ETABS; | ||
| using BH.oM.Base; | ||
| using BH.oM.Spatial.SettingOut; | ||
| using BH.oM.Structure.Constraints; | ||
| using BH.oM.Structure.Elements; | ||
| using BH.oM.Structure.Loads; | ||
| using BH.oM.Structure.MaterialFragments; | ||
| using BH.oM.Structure.SectionProperties; | ||
| using BH.oM.Structure.SurfaceProperties; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace BH.Adapter.ETABS.Types | ||
| { | ||
| public class DynamicComparer : IEqualityComparer<IBHoMObject> | ||
| { | ||
|
|
||
| // Use of STREAMS and REFLECTIONS | ||
|
|
||
| // 1. Equality based on ETABS obj Id or Name | ||
| public bool Equals(IBHoMObject obj1, IBHoMObject obj2) | ||
| { | ||
| if (obj1 == null || obj2 == null) return false; | ||
| if (obj1.GetType() != obj2.GetType()) return false; | ||
|
|
||
|
|
||
| Type objType = obj1.GetType(); | ||
|
|
||
| // For physical objects, use Id as it is never null | ||
| if (objType == typeof(Node) || objType == typeof(Bar) || objType == typeof(Panel) || objType == typeof(RigidLink) || objType == typeof(FEMesh)) | ||
| return GetEtabsId(obj1).Id.ToString() == GetEtabsId(obj2).Id.ToString(); | ||
| // For all other items, use Name as it is never null | ||
| if (objType == typeof(ISectionProperty) || objType == typeof(IMaterialFragment) || objType == typeof(ISurfaceProperty) || | ||
| objType == typeof(Loadcase) || objType == typeof(LoadCombination) || objType == typeof(ILoad) || objType == typeof(LinkConstraint) || | ||
| objType == typeof(Level) || objType == typeof(Grid)) | ||
| return obj1.Name.ToString() == obj2.Name.ToString(); | ||
|
|
||
| return false; | ||
|
|
||
| } | ||
|
|
||
| // 2. HashCode based on Hash function of ETABS obj Id+Label or Type+Name | ||
| public int GetHashCode(IBHoMObject obj) | ||
| { | ||
| Type objType = obj.GetType(); | ||
|
|
||
| // For physical objects, use Id and Label as they are never null | ||
| if (objType == typeof(Node) || objType == typeof(Bar) || objType == typeof(Panel) || objType == typeof(RigidLink) || objType == typeof(FEMesh)) | ||
| return (GetEtabsId(obj).Id.ToString() + GetEtabsId(obj).Label.ToString()).GetHashCode(); | ||
| // For all other items, use Name as Id/Label can be null | ||
| else if (objType == typeof(ISectionProperty) || objType == typeof(IMaterialFragment) || objType == typeof(ISurfaceProperty) || | ||
| objType == typeof(Loadcase) || objType == typeof(LoadCombination) || objType == typeof(ILoad) || objType == typeof(LinkConstraint) || | ||
| objType == typeof(Level) || objType == typeof(Grid)) | ||
| return (obj.GetType().ToString() + obj.Name.ToString()).GetHashCode(); | ||
|
|
||
| return 0; | ||
|
|
||
| } | ||
|
|
||
| // 3. Get ETABS Id using REFLECTION - **REFLECTION** | ||
| private ETABSId GetEtabsId(IBHoMObject obj) | ||
| { | ||
| // 1. Get the object Type | ||
| Type objsType = obj.GetType(); | ||
| // 2. Get the Property Fragments - via REFLECTION | ||
| PropertyInfo fragmentsProperty = objsType.GetProperty("Fragments"); | ||
| // 3. Downcast the Fragments Property to FragmentSet Class - via REFLECTION | ||
| FragmentSet fragments = (FragmentSet)fragmentsProperty.GetValue(obj); | ||
| // 4. Get the ETABSId object contained in the FragmentSet - via STREAMS | ||
| ETABSId etabsId = (ETABSId)(fragments.ToList().Find(frag => frag.GetType() == typeof(ETABSId))); | ||
| // 5. Return the Etabs Id of the object | ||
| return etabsId; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have all these comparers defined in the Adapter - can we not make sure of that rather than rewriting it here:
ETABS_Toolkit/Etabs_Adapter/Types/Comparer.cs
Lines 57 to 62 in edc11e0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterjamesnugent, thanks for the comment.
It would be great to reuse it yeah.
Only thing is that there are some objects that are not dealt with by the Adapter Comparer (e.g. Level, FEMesh,LoadCase...) - see screenshot below.
Can we add them in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I don't think that's an issue adding them to the
Comparer.cs- most of them will beNameOrDescriptionComparer()anyway.Can you add to the test script, trying to push two objects with the same name for each type you add (just to test that we are not breaking anything).