-
Notifications
You must be signed in to change notification settings - Fork 4
Add update load combination to adapter push #565
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
base: develop
Are you sure you want to change the base?
Changes from 8 commits
d67a0fd
f50a1a8
76a6e23
bfb1008
ed3ac69
3a19af3
ff4fa73
51c170a
204ade8
1ced695
c9e9b24
8b43266
f2e3614
0e0d306
05ec678
3bde84e
72779ff
77a8ff3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||||||||
| * along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>. | ||||||||||||
| */ | ||||||||||||
|
|
||||||||||||
| using System; | ||||||||||||
| using System.Collections.Generic; | ||||||||||||
| using BH.oM.Base; | ||||||||||||
| using BH.oM.Structure.Elements; | ||||||||||||
|
|
@@ -29,6 +30,7 @@ | |||||||||||
| using BH.oM.Structure.Loads; | ||||||||||||
| using BH.oM.Physical.Materials; | ||||||||||||
| using BH.oM.Adapter; | ||||||||||||
| using BH.Engine.Base; | ||||||||||||
| using RobotOM; | ||||||||||||
|
|
||||||||||||
| namespace BH.Adapter.Robot | ||||||||||||
|
|
@@ -42,7 +44,63 @@ public partial class RobotAdapter | |||||||||||
| protected bool Update(IEnumerable<LoadCombination> loadCombinations) | ||||||||||||
| { | ||||||||||||
| bool success = true; | ||||||||||||
| success = ICreate(loadCombinations); | ||||||||||||
|
|
||||||||||||
| m_RobotApplication.Project.Structure.Cases.BeginMultiOperation(); | ||||||||||||
|
|
||||||||||||
| foreach (LoadCombination lComb in loadCombinations) | ||||||||||||
| { | ||||||||||||
| //Check combination itself is not null | ||||||||||||
| if (!CheckNotNull(lComb)) | ||||||||||||
| continue; | ||||||||||||
|
|
||||||||||||
| // Use the Number property directly and try to get the combination | ||||||||||||
| int combinationId = lComb.Number; | ||||||||||||
|
|
||||||||||||
| // Get the existing combination from Robot (following pattern from Loadcases Update method) | ||||||||||||
| RobotCaseCombination rCaseCombination = m_RobotApplication.Project.Structure.Cases.Get(combinationId) as RobotCaseCombination; | ||||||||||||
| if (rCaseCombination == null) | ||||||||||||
| { | ||||||||||||
| Engine.Base.Compute.RecordWarning("Load combination with number " + combinationId.ToString() + " does not exist in Robot. Load combination could not be updated!"); | ||||||||||||
| success = false; | ||||||||||||
| continue; | ||||||||||||
|
Comment on lines
+78
to
+80
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggest we return an error here and exit the method given you cannot do anything with a null rCaseCombination. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Update the combination name if provided | ||||||||||||
| if (!string.IsNullOrWhiteSpace(lComb.Name)) | ||||||||||||
| rCaseCombination.Name = lComb.Name; | ||||||||||||
|
|
||||||||||||
| // Clear existing case factors by deleting them individually | ||||||||||||
| // Note: Robot API requires deleting case factors in reverse order to avoid index shifting | ||||||||||||
| for (int i = rCaseCombination.CaseFactors.Count; i >= 1; i--) | ||||||||||||
| { | ||||||||||||
| rCaseCombination.CaseFactors.Delete(i); | ||||||||||||
| } | ||||||||||||
|
Comment on lines
+89
to
+92
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not put this inside the if statement below? That way you don't clear all the factors of a |
||||||||||||
|
|
||||||||||||
| // Add new case factors from the BHoM LoadCombination | ||||||||||||
| if (lComb.LoadCases != null && lComb.LoadCases.Count > 0) | ||||||||||||
| { | ||||||||||||
| for (int i = 0; i < lComb.LoadCases.Count; i++) | ||||||||||||
| { | ||||||||||||
| //Check tuple as well as case not null | ||||||||||||
| if (CheckNotNull(lComb.LoadCases[i], oM.Base.Debugging.EventType.Error, typeof(LoadCombination)) && | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you add a I would also add using |
||||||||||||
| CheckNotNull(lComb.LoadCases[i].Item2, oM.Base.Debugging.EventType.Error, typeof(LoadCombination))) | ||||||||||||
| { | ||||||||||||
| System.Tuple<double, ICase> loadcase = lComb.LoadCases[i]; | ||||||||||||
| rCaseCombination.CaseFactors.New(lComb.LoadCases[i].Item2.Number, lComb.LoadCases[i].Item1); | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| else | ||||||||||||
| { | ||||||||||||
| Engine.Base.Compute.RecordWarning("Load combination with number " + combinationId.ToString() + " has no load cases. The combination has been cleared of all case factors."); | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Then we don't delete the factors. |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Set the adapter ID to maintain the connection between BHoM and Robot objects | ||||||||||||
| this.SetAdapterId(lComb, lComb.Number); | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this line needed? You have already updated the object id when it didn't match the load combination number? |
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| m_RobotApplication.Project.Structure.Cases.EndMultiOperation(); | ||||||||||||
|
|
||||||||||||
| return success; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
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.
If it's
nulldon't we want to return a error stating as such - and then returning false?