Skip to content

Commit a928d8b

Browse files
SandeepAruppsarras
andauthored
GSAGH-538 - read-only access to properties extensively used for testing (#117)
* GSAGH-538 - read-only access to properties extensively used for testing * GSAGH-538 - increase version number to 1.2.3 * feat: converted fields to properties with public get modifier * feat: added try catch on finding Rhino Version * Revert "feat: converted fields to properties with public get modifier" This reverts commit 1796913. * feat: public getters and private and internal setters, but kept the fields * feat: updated tests to avoid rare bug with uninstalled versions * feat: force check of version * feat: check dir not file --------- Co-authored-by: spsarras <[email protected]>
1 parent 625bdad commit a928d8b

15 files changed

+182
-149
lines changed

GH_UnitNumber/Components/ConvertUnitNumber.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,25 @@ public override bool Read(GH_IReader reader) {
122122
if (Params.Output.Count == 1) {
123123
Params.RegisterOutputParam(param);
124124
}
125-
125+
126126
return flag;
127127
}
128128

129129
public override void SetSelected(int i, int j) {
130130
if (_unitDictionary != null) {
131-
_selectedItems[i] = _dropDownItems[i][j];
132-
_dropDownItems[0] = _unitDictionary.Keys.ToList();
131+
_selectedItems[i] = DropDownItems[i][j];
132+
DropDownItems[0] = _unitDictionary.Keys.ToList();
133133
}
134134
base.UpdateUI();
135135
}
136136

137137
protected override void InitialiseDropdowns() {
138138
_spacerDescriptions = new List<string>(new string[] { "Select output unit" });
139139

140-
_dropDownItems = new List<List<string>>();
140+
DropDownItems = new List<List<string>>();
141141
_selectedItems = new List<string>();
142142

143-
_dropDownItems.Add(new List<string>(new string[] { " " }));
143+
DropDownItems.Add(new List<string>(new string[] { " " }));
144144
_selectedItems.Add(" ");
145145

146146
_isInitialised = true;
@@ -176,7 +176,7 @@ protected override void SolveInternal(IGH_DataAccess DA) {
176176
_unitDictionary.Add(abbr, unit.Value);
177177
}
178178

179-
_dropDownItems[0] = _unitDictionary.Keys.ToList();
179+
DropDownItems[0] = _unitDictionary.Keys.ToList();
180180
if (!_comingFromSave) {
181181
IQuantity quantity = Quantity.From(0, inUnitNumber.Value.Unit);
182182
string abbr = quantity.ToString().Replace("0", string.Empty).Trim();

GH_UnitNumber/Components/CreateUnitNumber.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public CreateUnitNumber() : base("Create UnitNumber", "CreateUnit",
3030
}
3131

3232
public override void SetSelected(int i, int j) {
33-
_selectedItems[i] = _dropDownItems[i][j];
33+
_selectedItems[i] = DropDownItems[i][j];
3434

3535
// if change is made to first (unit type) list we have to update lists
3636
if (i == 0) {
@@ -166,13 +166,13 @@ public override void VariableParameterMaintenance() {
166166
protected override void InitialiseDropdowns() {
167167
_spacerDescriptions = new List<string>(new string[] { "Unit type", "Measure" });
168168

169-
_dropDownItems = new List<List<string>>();
169+
DropDownItems = new List<List<string>>();
170170
_selectedItems = new List<string>();
171171

172-
_dropDownItems.Add(Enum.GetNames(typeof(EngineeringUnits)).ToList());
173-
_selectedItems.Add(_dropDownItems[0][1]);
172+
DropDownItems.Add(Enum.GetNames(typeof(EngineeringUnits)).ToList());
173+
_selectedItems.Add(DropDownItems[0][1]);
174174

175-
_dropDownItems.Add(Enum.GetNames(typeof(LengthUnit)).ToList());
175+
DropDownItems.Add(Enum.GetNames(typeof(LengthUnit)).ToList());
176176
_selectedItems.Add(DefaultUnits.LengthUnitGeometry.ToString());
177177

178178
_quantity = new Length(0, DefaultUnits.LengthUnitGeometry);
@@ -326,7 +326,7 @@ private void UpdateMeasureDictionary() {
326326
_measureDictionary = new Dictionary<string, Enum>();
327327
foreach (UnitInfo unitype in _quantity.QuantityInfo.UnitInfos)
328328
_measureDictionary.Add(unitype.Name, unitype.Value);
329-
_dropDownItems[1] = _measureDictionary.Keys.ToList();
329+
DropDownItems[1] = _measureDictionary.Keys.ToList();
330330
}
331331

332332
private void UpdateQuantityUnitTypeFromUnitString(EngineeringUnits unit) {

GH_UnitNumber/GH_UnitNumber.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<RepositoryUrl>https://github.com/arup-group/OasysGH</RepositoryUrl>
1111
<PackageReadmeFile>README.md</PackageReadmeFile>
1212
<PackageIcon>UnitNumberLogo64.png</PackageIcon>
13-
<Version>1.2.1</Version>
13+
<Version>1.2.3</Version>
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1515
<BaseOutputPath>bin\</BaseOutputPath>
1616
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>

GH_UnitNumberTests/Helpers/Dropdown.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ internal class Dropdown {
66
internal static void ChangeDropDownDeserializeTest(
77
GH_OasysDropDownComponent comp) {
88
Assert.True(comp._isInitialised);
9-
Assert.Equal(comp._dropDownItems.Count, comp._spacerDescriptions.Count);
9+
Assert.Equal(comp.DropDownItems.Count, comp._spacerDescriptions.Count);
1010

11-
Assert.Equal(comp._dropDownItems.Count, comp._selectedItems.Count);
11+
Assert.Equal(comp.DropDownItems.Count, comp._selectedItems.Count);
1212

13-
for (int i = 0; i < comp._dropDownItems.Count; i++) {
13+
for (int i = 0; i < comp.DropDownItems.Count; i++) {
1414
comp.SetSelected(i, 0);
1515

16-
for (int j = 0; j < comp._dropDownItems[i].Count; j++) {
16+
for (int j = 0; j < comp.DropDownItems[i].Count; j++) {
1717
comp.SetSelected(i, j);
1818
Deserialize.TestDeserialize(comp);
19-
Assert.Equal(comp._selectedItems[i], comp._dropDownItems[i][j]);
19+
Assert.Equal(comp._selectedItems[i], comp.DropDownItems[i][j]);
2020
}
2121
}
2222
}

OasysGH/Components/CreateOasysProfile.cs

+48-48
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,23 @@ public override void SetSelected(int i, int j) {
147147
// input -1 to force update of catalogue sections to include/exclude superseeded
148148
bool updateCat = false;
149149
if (i == -1) {
150-
_selectedItems[0] = "Catalogue";
150+
SelectedItems[0] = "Catalogue";
151151
updateCat = true;
152152
i = 0;
153153
} else {
154154
// change selected item
155-
_selectedItems[i] = _dropDownItems[i][j];
155+
SelectedItems[i] = DropDownItems[i][j];
156156
}
157157

158-
if (_selectedItems[0] == "Catalogue") {
158+
if (SelectedItems[0] == "Catalogue") {
159159
// update spacer description to match catalogue dropdowns
160-
_spacerDescriptions[1] = "Catalogue";
160+
SpacerDescriptions[1] = "Catalogue";
161161

162162
// if FoldMode is not currently catalogue state, then we update all lists
163163
if (_mode != FoldMode.Catalogue | updateCat) {
164164
// remove any existing selections
165-
while (_selectedItems.Count > 1)
166-
_selectedItems.RemoveAt(1);
165+
while (SelectedItems.Count > 1)
166+
SelectedItems.RemoveAt(1);
167167

168168
// set catalogue selection to all
169169
_catalogueIndex = -1;
@@ -177,27 +177,27 @@ public override void SetSelected(int i, int j) {
177177
_sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(_typeNumbers, DataSource, _inclSS);
178178

179179
// update displayed selections to all
180-
_selectedItems.Add(_catalogueNames[0]);
181-
_selectedItems.Add(_typeNames[0]);
182-
_selectedItems.Add(_sectionList[0]);
180+
SelectedItems.Add(_catalogueNames[0]);
181+
SelectedItems.Add(_typeNames[0]);
182+
SelectedItems.Add(_sectionList[0]);
183183

184184
// call graphics update
185185
Mode1Clicked();
186186
}
187187

188188
// update dropdown lists
189-
while (_dropDownItems.Count > 1)
190-
_dropDownItems.RemoveAt(1);
189+
while (DropDownItems.Count > 1)
190+
DropDownItems.RemoveAt(1);
191191

192192
// add catalogues (they will always be the same so no need to rerun sql call)
193-
_dropDownItems.Add(_catalogueNames);
193+
DropDownItems.Add(_catalogueNames);
194194

195195
// type list
196196
// if second list (i.e. catalogue list) is changed, update types list to account for that catalogue
197197
if (i == 1) {
198198
// update catalogue index with the selected catalogue
199199
_catalogueIndex = _catalogueNumbers[j];
200-
_selectedItems[1] = _catalogueNames[j];
200+
SelectedItems[1] = _catalogueNames[j];
201201

202202
// update typelist with selected input catalogue
203203
_typeData = SqlReader.Instance.GetTypesDataFromSQLite(_catalogueIndex, DataSource, _inclSS);
@@ -216,17 +216,17 @@ public override void SetSelected(int i, int j) {
216216
_sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(types, DataSource, _inclSS);
217217

218218
// update selections to display first item in new list
219-
_selectedItems[2] = _typeNames[0];
220-
_selectedItems[3] = _sectionList[0];
219+
SelectedItems[2] = _typeNames[0];
220+
SelectedItems[3] = _sectionList[0];
221221
}
222-
_dropDownItems.Add(_typeNames);
222+
DropDownItems.Add(_typeNames);
223223

224224
// section list
225225
// if third list (i.e. types list) is changed, update sections list to account for these section types
226226
if (i == 2) {
227227
// update catalogue index with the selected catalogue
228228
_typeIndex = _typeNumbers[j];
229-
_selectedItems[2] = _typeNames[j];
229+
SelectedItems[2] = _typeNames[j];
230230

231231
// create type list
232232
List<int> types;
@@ -241,15 +241,15 @@ public override void SetSelected(int i, int j) {
241241
_sectionList = SqlReader.Instance.GetSectionsDataFromSQLite(types, DataSource, _inclSS);
242242

243243
// update selected section to be all
244-
_selectedItems[3] = _sectionList[0];
244+
SelectedItems[3] = _sectionList[0];
245245
}
246-
_dropDownItems.Add(_sectionList);
246+
DropDownItems.Add(_sectionList);
247247

248248
// selected profile
249249
// if fourth list (i.e. section list) is changed, updated the sections list to only be that single profile
250250
if (i == 3) {
251251
// update displayed selected
252-
_selectedItems[3] = _sectionList[j];
252+
SelectedItems[3] = _sectionList[j];
253253
}
254254

255255
if (_search == "")
@@ -258,27 +258,27 @@ public override void SetSelected(int i, int j) {
258258
base.UpdateUI();
259259
} else {
260260
// update spacer description to match none-catalogue dropdowns
261-
_spacerDescriptions[1] = "Measure";// = new List<string>(new string[]
261+
SpacerDescriptions[1] = "Measure";// = new List<string>(new string[]
262262

263263
if (_mode != FoldMode.Other) {
264264
// remove all catalogue dropdowns
265-
while (_dropDownItems.Count > 1)
266-
_dropDownItems.RemoveAt(1);
265+
while (DropDownItems.Count > 1)
266+
DropDownItems.RemoveAt(1);
267267

268268
// add length measure dropdown list
269-
_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
269+
DropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
270270

271271
// set selected length
272-
_selectedItems[1] = _lengthUnit.ToString();
272+
SelectedItems[1] = _lengthUnit.ToString();
273273
}
274274

275275
if (i == 0) {
276276
// update profile type if change is made to first dropdown menu
277-
_type = profileTypes[_selectedItems[0]];
277+
_type = profileTypes[SelectedItems[0]];
278278
Mode2Clicked();
279279
} else {
280280
// change unit
281-
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[i]);
281+
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), SelectedItems[i]);
282282

283283
base.UpdateUI();
284284
}
@@ -830,25 +830,25 @@ public override bool Write(GH_IWriter writer) {
830830
}
831831

832832
protected internal override void InitialiseDropdowns() {
833-
_spacerDescriptions = new List<string>(new string[] {
833+
SpacerDescriptions = new List<string>(new string[] {
834834
"Profile type",
835835
"Measure",
836836
"Type",
837837
"Profile"
838838
});
839839

840-
_dropDownItems = new List<List<string>>();
841-
_selectedItems = new List<string>();
840+
DropDownItems = new List<List<string>>();
841+
SelectedItems = new List<string>();
842842

843843
// Profile type
844-
_dropDownItems.Add(profileTypes.Keys.ToList());
845-
_selectedItems.Add("Rectangle");
844+
DropDownItems.Add(profileTypes.Keys.ToList());
845+
SelectedItems.Add("Rectangle");
846846

847847
// Length
848-
_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
849-
_selectedItems.Add(Length.GetAbbreviation(_lengthUnit));
848+
DropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
849+
SelectedItems.Add(Length.GetAbbreviation(_lengthUnit));
850850

851-
_isInitialised = true;
851+
IsInitialised = true;
852852
}
853853

854854
protected virtual int GetNumberOfGenericInputs() {
@@ -982,11 +982,11 @@ protected List<IProfile> SolveInstanceForCatalogueProfile(IGH_DataAccess da) {
982982
_typeIndex = -1;
983983
UpdateSecionList();
984984

985-
_selectedItems[2] = "All";
986-
_dropDownItems[2] = _typeNames;
985+
SelectedItems[2] = "All";
986+
DropDownItems[2] = _typeNames;
987987

988-
_selectedItems[3] = "All";
989-
_dropDownItems[3] = _sectionList;
988+
SelectedItems[3] = "All";
989+
DropDownItems[3] = _sectionList;
990990

991991
base.UpdateUI();
992992
}
@@ -1016,8 +1016,8 @@ protected List<IProfile> SolveInstanceForCatalogueProfile(IGH_DataAccess da) {
10161016

10171017
// filter by search pattern
10181018
var filteredlist = new List<string>();
1019-
if (_selectedItems[3] != "All") {
1020-
if (!MatchAndAdd(_selectedItems[3], _search, ref filteredlist, tryHard)) {
1019+
if (SelectedItems[3] != "All") {
1020+
if (!MatchAndAdd(SelectedItems[3], _search, ref filteredlist, tryHard)) {
10211021
_profileDescriptions = new List<string>();
10221022
AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No profile found that matches selected profile and search!");
10231023
}
@@ -1362,9 +1362,9 @@ protected virtual void UpdateParameters() {
13621362
}
13631363

13641364
protected override void UpdateUIFromSelectedItems() {
1365-
if (_selectedItems[0] == "Catalogue") {
1365+
if (SelectedItems[0] == "Catalogue") {
13661366
// update spacer description to match catalogue dropdowns
1367-
_spacerDescriptions = new List<string>(new string[]
1367+
SpacerDescriptions = new List<string>(new string[]
13681368
{
13691369
"Profile type", "Catalogue", "Type", "Profile"
13701370
});
@@ -1375,15 +1375,15 @@ protected override void UpdateUIFromSelectedItems() {
13751375

13761376
Mode1Clicked();
13771377

1378-
_profileDescriptions = new List<string>() { "CAT " + _selectedItems[3] };
1378+
_profileDescriptions = new List<string>() { "CAT " + SelectedItems[3] };
13791379
} else {
13801380
// update spacer description to match none-catalogue dropdowns
1381-
_spacerDescriptions = new List<string>(new string[]
1381+
SpacerDescriptions = new List<string>(new string[]
13821382
{
13831383
"Profile type", "Measure", "Type", "Profile"
13841384
});
13851385

1386-
_type = profileTypes[_selectedItems[0]];
1386+
_type = profileTypes[SelectedItems[0]];
13871387
Mode2Clicked();
13881388
}
13891389

@@ -1415,15 +1415,15 @@ private static bool MatchAndAdd(string item, string pattern, ref List<string> li
14151415
}
14161416

14171417
private void UpdateProfileDescriptions() {
1418-
if (_selectedItems[3] == "All") {
1418+
if (SelectedItems[3] == "All") {
14191419
_profileDescriptions = new List<string>();
14201420
foreach (string profile in _sectionList) {
14211421
if (profile == "All")
14221422
continue;
14231423
_profileDescriptions.Add("CAT " + profile);
14241424
}
14251425
} else
1426-
_profileDescriptions = new List<string>() { "CAT " + _selectedItems[3] };
1426+
_profileDescriptions = new List<string>() { "CAT " + SelectedItems[3] };
14271427
}
14281428

14291429
private void UpdateSecionList() {

0 commit comments

Comments
 (0)