Skip to content

Commit

Permalink
GSAGH-538 - read-only access to properties extensively used for testi…
Browse files Browse the repository at this point in the history
…ng (#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]>
  • Loading branch information
SandeepArup and psarras authored Sep 27, 2024
1 parent 625bdad commit a928d8b
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 149 deletions.
12 changes: 6 additions & 6 deletions GH_UnitNumber/Components/ConvertUnitNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,25 @@ public override bool Read(GH_IReader reader) {
if (Params.Output.Count == 1) {
Params.RegisterOutputParam(param);
}

return flag;
}

public override void SetSelected(int i, int j) {
if (_unitDictionary != null) {
_selectedItems[i] = _dropDownItems[i][j];
_dropDownItems[0] = _unitDictionary.Keys.ToList();
_selectedItems[i] = DropDownItems[i][j];
DropDownItems[0] = _unitDictionary.Keys.ToList();
}
base.UpdateUI();
}

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

_dropDownItems = new List<List<string>>();
DropDownItems = new List<List<string>>();
_selectedItems = new List<string>();

_dropDownItems.Add(new List<string>(new string[] { " " }));
DropDownItems.Add(new List<string>(new string[] { " " }));
_selectedItems.Add(" ");

_isInitialised = true;
Expand Down Expand Up @@ -176,7 +176,7 @@ protected override void SolveInternal(IGH_DataAccess DA) {
_unitDictionary.Add(abbr, unit.Value);
}

_dropDownItems[0] = _unitDictionary.Keys.ToList();
DropDownItems[0] = _unitDictionary.Keys.ToList();
if (!_comingFromSave) {
IQuantity quantity = Quantity.From(0, inUnitNumber.Value.Unit);
string abbr = quantity.ToString().Replace("0", string.Empty).Trim();
Expand Down
12 changes: 6 additions & 6 deletions GH_UnitNumber/Components/CreateUnitNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CreateUnitNumber() : base("Create UnitNumber", "CreateUnit",
}

public override void SetSelected(int i, int j) {
_selectedItems[i] = _dropDownItems[i][j];
_selectedItems[i] = DropDownItems[i][j];

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

_dropDownItems = new List<List<string>>();
DropDownItems = new List<List<string>>();
_selectedItems = new List<string>();

_dropDownItems.Add(Enum.GetNames(typeof(EngineeringUnits)).ToList());
_selectedItems.Add(_dropDownItems[0][1]);
DropDownItems.Add(Enum.GetNames(typeof(EngineeringUnits)).ToList());
_selectedItems.Add(DropDownItems[0][1]);

_dropDownItems.Add(Enum.GetNames(typeof(LengthUnit)).ToList());
DropDownItems.Add(Enum.GetNames(typeof(LengthUnit)).ToList());
_selectedItems.Add(DefaultUnits.LengthUnitGeometry.ToString());

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

private void UpdateQuantityUnitTypeFromUnitString(EngineeringUnits unit) {
Expand Down
2 changes: 1 addition & 1 deletion GH_UnitNumber/GH_UnitNumber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryUrl>https://github.com/arup-group/OasysGH</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>UnitNumberLogo64.png</PackageIcon>
<Version>1.2.1</Version>
<Version>1.2.3</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<BaseOutputPath>bin\</BaseOutputPath>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
Expand Down
10 changes: 5 additions & 5 deletions GH_UnitNumberTests/Helpers/Dropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ internal class Dropdown {
internal static void ChangeDropDownDeserializeTest(
GH_OasysDropDownComponent comp) {
Assert.True(comp._isInitialised);
Assert.Equal(comp._dropDownItems.Count, comp._spacerDescriptions.Count);
Assert.Equal(comp.DropDownItems.Count, comp._spacerDescriptions.Count);

Assert.Equal(comp._dropDownItems.Count, comp._selectedItems.Count);
Assert.Equal(comp.DropDownItems.Count, comp._selectedItems.Count);

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

for (int j = 0; j < comp._dropDownItems[i].Count; j++) {
for (int j = 0; j < comp.DropDownItems[i].Count; j++) {
comp.SetSelected(i, j);
Deserialize.TestDeserialize(comp);
Assert.Equal(comp._selectedItems[i], comp._dropDownItems[i][j]);
Assert.Equal(comp._selectedItems[i], comp.DropDownItems[i][j]);
}
}
}
Expand Down
96 changes: 48 additions & 48 deletions OasysGH/Components/CreateOasysProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ public override void SetSelected(int i, int j) {
// input -1 to force update of catalogue sections to include/exclude superseeded
bool updateCat = false;
if (i == -1) {
_selectedItems[0] = "Catalogue";
SelectedItems[0] = "Catalogue";
updateCat = true;
i = 0;
} else {
// change selected item
_selectedItems[i] = _dropDownItems[i][j];
SelectedItems[i] = DropDownItems[i][j];
}

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

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

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

// update displayed selections to all
_selectedItems.Add(_catalogueNames[0]);
_selectedItems.Add(_typeNames[0]);
_selectedItems.Add(_sectionList[0]);
SelectedItems.Add(_catalogueNames[0]);
SelectedItems.Add(_typeNames[0]);
SelectedItems.Add(_sectionList[0]);

// call graphics update
Mode1Clicked();
}

// update dropdown lists
while (_dropDownItems.Count > 1)
_dropDownItems.RemoveAt(1);
while (DropDownItems.Count > 1)
DropDownItems.RemoveAt(1);

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

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

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

// update selections to display first item in new list
_selectedItems[2] = _typeNames[0];
_selectedItems[3] = _sectionList[0];
SelectedItems[2] = _typeNames[0];
SelectedItems[3] = _sectionList[0];
}
_dropDownItems.Add(_typeNames);
DropDownItems.Add(_typeNames);

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

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

// update selected section to be all
_selectedItems[3] = _sectionList[0];
SelectedItems[3] = _sectionList[0];
}
_dropDownItems.Add(_sectionList);
DropDownItems.Add(_sectionList);

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

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

if (_mode != FoldMode.Other) {
// remove all catalogue dropdowns
while (_dropDownItems.Count > 1)
_dropDownItems.RemoveAt(1);
while (DropDownItems.Count > 1)
DropDownItems.RemoveAt(1);

// add length measure dropdown list
_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
DropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));

// set selected length
_selectedItems[1] = _lengthUnit.ToString();
SelectedItems[1] = _lengthUnit.ToString();
}

if (i == 0) {
// update profile type if change is made to first dropdown menu
_type = profileTypes[_selectedItems[0]];
_type = profileTypes[SelectedItems[0]];
Mode2Clicked();
} else {
// change unit
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), _selectedItems[i]);
_lengthUnit = (LengthUnit)UnitsHelper.Parse(typeof(LengthUnit), SelectedItems[i]);

base.UpdateUI();
}
Expand Down Expand Up @@ -830,25 +830,25 @@ public override bool Write(GH_IWriter writer) {
}

protected internal override void InitialiseDropdowns() {
_spacerDescriptions = new List<string>(new string[] {
SpacerDescriptions = new List<string>(new string[] {
"Profile type",
"Measure",
"Type",
"Profile"
});

_dropDownItems = new List<List<string>>();
_selectedItems = new List<string>();
DropDownItems = new List<List<string>>();
SelectedItems = new List<string>();

// Profile type
_dropDownItems.Add(profileTypes.Keys.ToList());
_selectedItems.Add("Rectangle");
DropDownItems.Add(profileTypes.Keys.ToList());
SelectedItems.Add("Rectangle");

// Length
_dropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
_selectedItems.Add(Length.GetAbbreviation(_lengthUnit));
DropDownItems.Add(UnitsHelper.GetFilteredAbbreviations(EngineeringUnits.Length));
SelectedItems.Add(Length.GetAbbreviation(_lengthUnit));

_isInitialised = true;
IsInitialised = true;
}

protected virtual int GetNumberOfGenericInputs() {
Expand Down Expand Up @@ -982,11 +982,11 @@ protected List<IProfile> SolveInstanceForCatalogueProfile(IGH_DataAccess da) {
_typeIndex = -1;
UpdateSecionList();

_selectedItems[2] = "All";
_dropDownItems[2] = _typeNames;
SelectedItems[2] = "All";
DropDownItems[2] = _typeNames;

_selectedItems[3] = "All";
_dropDownItems[3] = _sectionList;
SelectedItems[3] = "All";
DropDownItems[3] = _sectionList;

base.UpdateUI();
}
Expand Down Expand Up @@ -1016,8 +1016,8 @@ protected List<IProfile> SolveInstanceForCatalogueProfile(IGH_DataAccess da) {

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

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

Mode1Clicked();

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

_type = profileTypes[_selectedItems[0]];
_type = profileTypes[SelectedItems[0]];
Mode2Clicked();
}

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

private void UpdateProfileDescriptions() {
if (_selectedItems[3] == "All") {
if (SelectedItems[3] == "All") {
_profileDescriptions = new List<string>();
foreach (string profile in _sectionList) {
if (profile == "All")
continue;
_profileDescriptions.Add("CAT " + profile);
}
} else
_profileDescriptions = new List<string>() { "CAT " + _selectedItems[3] };
_profileDescriptions = new List<string>() { "CAT " + SelectedItems[3] };
}

private void UpdateSecionList() {
Expand Down
Loading

0 comments on commit a928d8b

Please sign in to comment.