Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed May 7, 2024
1 parent 2a07649 commit ac82da2
Showing 1 changed file with 24 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param
{
return target switch
{
nameof(TableView.GetAvailableParameterCategories) => ResolveAvailableParameterCategories(),
// nameof(TableView.GetAvailableParameterCategories) => ResolveAvailableParameterCategories(), disabled, long computation time
nameof(TableView.GetAvailableParameters) => ResolveAvailableParameters(),
nameof(TableView.GetCalculatedValueName) => ResolveCalculatedValueName(),
nameof(TableView.GetCalculatedValueText) => ResolveCalculatedValueText(),
Expand All @@ -40,33 +40,6 @@ public ResolveSet Resolve(Document context, string target, ParameterInfo[] param
_ => null
};

ResolveSet ResolveAvailableParameterCategories()
{
if (tableView is not ViewSchedule && tableView is not PanelScheduleView)
return ResolveSet.Append("This view is not a schedule view");

TableData tableData = null;
if (tableView is ViewSchedule viewSchedule)
tableData = viewSchedule.GetTableData();
else if (tableView is PanelScheduleView panelScheduleView)
tableData = panelScheduleView.GetTableData();

var sectionTypes = Enum.GetValues(typeof(SectionType));
var resolveSummary = new ResolveSet();
foreach (SectionType sectionType in sectionTypes)
{
var tableSectionData = tableData!.GetSectionData(sectionType);
if (tableSectionData is null) continue;
for (var i = tableSectionData.FirstRowNumber; i < tableSectionData.LastRowNumber; i++)
{
resolveSummary.AppendVariant(tableView.GetAvailableParameterCategories(sectionType, i),
$"{sectionType}: Row {i}");
}
}

return resolveSummary;
}

ResolveSet ResolveAvailableParameters()
{
var categories = context.Settings.Categories;
Expand All @@ -82,26 +55,25 @@ ResolveSet ResolveAvailableParameters()

ResolveSet ResolveCalculatedValueName()
{
if (tableView is not ViewSchedule && tableView is not PanelScheduleView)
return ResolveSet.Append("This view is not a schedule view");

TableData tableData = null;
if (tableView is ViewSchedule viewSchedule)
tableData = viewSchedule.GetTableData();
else if (tableView is PanelScheduleView panelScheduleView)
tableData = panelScheduleView.GetTableData();
var tableData = tableView switch
{
ViewSchedule viewSchedule => viewSchedule.GetTableData(),
PanelScheduleView panelScheduleView => panelScheduleView.GetTableData(),
_ => throw new NotSupportedException($"{tableView.GetType().FullName} is not supported in the current API version")
};

var sectionTypes = Enum.GetValues(typeof(SectionType));
var resolveSummary = new ResolveSet();
foreach (SectionType sectionType in sectionTypes)
{
var tableSectionData = tableData!.GetSectionData(sectionType);
if (tableSectionData is null) continue;

for (var i = tableSectionData.FirstRowNumber; i < tableSectionData.LastRowNumber; i++)
for (var j = tableSectionData.FirstColumnNumber; j < tableSectionData.LastColumnNumber; j++)
{
var result = tableView.GetCalculatedValueName(sectionType, i, j);
resolveSummary.AppendVariant(result, $"{sectionType}, Row {i}, Column {j}: {result}");
resolveSummary.AppendVariant(result, $"{sectionType}, row {i}, column {j}: {result}");
}
}

Expand All @@ -110,26 +82,25 @@ ResolveSet ResolveCalculatedValueName()

ResolveSet ResolveCalculatedValueText()
{
if (tableView is not ViewSchedule && tableView is not PanelScheduleView)
return ResolveSet.Append("This view is not a schedule view");

TableData tableData = null;
if (tableView is ViewSchedule viewSchedule)
tableData = viewSchedule.GetTableData();
else if (tableView is PanelScheduleView panelScheduleView)
tableData = panelScheduleView.GetTableData();
var tableData = tableView switch
{
ViewSchedule viewSchedule => viewSchedule.GetTableData(),
PanelScheduleView panelScheduleView => panelScheduleView.GetTableData(),
_ => throw new NotSupportedException($"{tableView.GetType().FullName} is not supported in the current API version")

Check notice on line 89 in source/RevitLookup/Core/ComponentModel/Descriptors/TableViewDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert 'if' statement into 'switch'

Convert 'if' statement into 'switch'
};

var sectionTypes = Enum.GetValues(typeof(SectionType));
var resolveSummary = new ResolveSet();
foreach (SectionType sectionType in sectionTypes)
{
var tableSectionData = tableData!.GetSectionData(sectionType);
if (tableSectionData is null) continue;

for (var i = tableSectionData.FirstRowNumber; i < tableSectionData.LastRowNumber; i++)
for (var j = tableSectionData.FirstColumnNumber; j < tableSectionData.LastColumnNumber; j++)
{
var result = tableView.GetCalculatedValueText(sectionType, i, j);
resolveSummary.AppendVariant(result, $"{sectionType}, Row {i}, Column {j}: {result}");
resolveSummary.AppendVariant(result, $"{sectionType}, row {i}, column {j}: {result}");
}
}

Expand All @@ -138,14 +109,12 @@ ResolveSet ResolveCalculatedValueText()

ResolveSet ResolveCellText()
{
if (tableView is not ViewSchedule && tableView is not PanelScheduleView)
return ResolveSet.Append("This view is not a schedule view");

TableData tableData = null;
if (tableView is ViewSchedule viewSchedule)
tableData = viewSchedule.GetTableData();
else if (tableView is PanelScheduleView panelScheduleView)
tableData = panelScheduleView.GetTableData();
var tableData = tableView switch
{
ViewSchedule viewSchedule => viewSchedule.GetTableData(),
PanelScheduleView panelScheduleView => panelScheduleView.GetTableData(),
_ => throw new NotSupportedException($"{tableView.GetType().FullName} is not supported in the current API version")
};

Check notice on line 117 in source/RevitLookup/Core/ComponentModel/Descriptors/TableViewDescriptor.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert 'if' statement into 'switch'

Convert 'if' statement into 'switch'

var sectionTypes = Enum.GetValues(typeof(SectionType));
var resolveSummary = new ResolveSet();
Expand All @@ -157,7 +126,7 @@ ResolveSet ResolveCellText()
for (var j = tableSectionData.FirstColumnNumber; j < tableSectionData.LastColumnNumber; j++)
{
var result = tableView.GetCellText(sectionType, i, j);
resolveSummary.AppendVariant(result, $"{sectionType}, Row {i}, Column {j}: {result}");
resolveSummary.AppendVariant(result, $"{sectionType}, row {i}, column {j}: {result}");
}
}

Expand Down

0 comments on commit ac82da2

Please sign in to comment.