Skip to content
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

Scenario filtering empty parameter fix #1218

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 54 additions & 48 deletions Revit_Core_Engine/Query/Passes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static bool Passes(this Parameter parameter, FilterByParameterBool reques
if (!CheckIfNotNull(parameter, request))
return false;

if (parameter.HasValue && parameter.StorageType == StorageType.Integer && parameter.Definition.ParameterType == ParameterType.YesNo)
if (parameter.StorageType == StorageType.Integer && parameter.Definition.ParameterType == ParameterType.YesNo)
pawelbaran marked this conversation as resolved.
Show resolved Hide resolved
{
int paramValue = parameter.AsInteger();
return (request.Value && paramValue == 1) || (!request.Value && paramValue == 0);
Expand Down Expand Up @@ -253,9 +253,10 @@ public static bool Passes(this Parameter parameter, FilterByParameterNumber requ
if (!CheckIfNotNull(parameter, request))
return false;


double paramValue = double.NaN;
if (parameter.HasValue)
{
double paramValue;
if (parameter.StorageType == StorageType.Double)
paramValue = parameter.AsDouble();
else if (parameter.StorageType == StorageType.Integer)
Expand All @@ -267,31 +268,34 @@ public static bool Passes(this Parameter parameter, FilterByParameterNumber requ
}
else
return false;
}

double comparisonValue = request.Value;
double comparisonTolerance = request.Tolerance;
double comparisonValue = request.Value;
double comparisonTolerance = request.Tolerance;

if (request.ConvertUnits)
{
comparisonValue = comparisonValue.FromSI(parameter.Definition.GetSpecTypeId());
comparisonTolerance = comparisonTolerance.FromSI(parameter.Definition.GetSpecTypeId());
}
if (request.ConvertUnits)
{
comparisonValue = comparisonValue.FromSI(parameter.Definition.GetSpecTypeId());
comparisonTolerance = comparisonTolerance.FromSI(parameter.Definition.GetSpecTypeId());
}

switch (request.NumberComparisonType)
{
case NumberComparisonType.Equal:
return Math.Abs(paramValue - comparisonValue) <= comparisonTolerance;
case NumberComparisonType.Greater:
return paramValue - comparisonValue > comparisonTolerance;
case NumberComparisonType.GreaterOrEqual:
return paramValue - comparisonValue > -comparisonTolerance;
case NumberComparisonType.Less:
return paramValue - comparisonValue < -comparisonTolerance;
case NumberComparisonType.LessOrEqual:
return paramValue - comparisonValue < comparisonTolerance;
case NumberComparisonType.NotEqual:
return Math.Abs(paramValue - comparisonValue) > comparisonTolerance;
}
switch (request.NumberComparisonType)
{
case NumberComparisonType.Equal:
return Math.Abs(paramValue - comparisonValue) <= comparisonTolerance || (double.IsNaN(paramValue) && double.IsNaN(comparisonValue));
case NumberComparisonType.Greater:
return paramValue - comparisonValue > comparisonTolerance;
case NumberComparisonType.GreaterOrEqual:
return paramValue - comparisonValue > -comparisonTolerance;
case NumberComparisonType.Less:
return paramValue - comparisonValue < -comparisonTolerance;
case NumberComparisonType.LessOrEqual:
return paramValue - comparisonValue < comparisonTolerance;
case NumberComparisonType.NotEqual:
if (double.IsNaN(paramValue))
return true;
return Math.Abs(paramValue - comparisonValue) > comparisonTolerance;

}

return false;
Expand All @@ -307,33 +311,35 @@ public static bool Passes(this Parameter parameter, FilterByParameterText reques
{
if (!CheckIfNotNull(parameter, request))
return false;

if (parameter.HasValue)

string paramValue;
if (parameter.StorageType == StorageType.String)
{
string paramValue;
if (parameter.StorageType == StorageType.String)
paramValue = parameter.AsString();
else if (parameter.StorageType == StorageType.ElementId || (parameter.StorageType == StorageType.Integer && parameter.Definition.ParameterType != ParameterType.YesNo))
paramValue = parameter.AsValueString();
else
return false;
paramValue = parameter.AsString();
if (paramValue == null)
paramValue = "";
}
else if (parameter.StorageType == StorageType.ElementId || (parameter.StorageType == StorageType.Integer && parameter.Definition.ParameterType != ParameterType.YesNo))
paramValue = parameter.AsValueString();
else
return false;

switch (request.TextComparisonType)
{
case TextComparisonType.Contains:
return paramValue.Contains(request.Value);
case TextComparisonType.ContainsNot:
return !paramValue.Contains(request.Value);
case TextComparisonType.EndsWith:
return paramValue.EndsWith(request.Value);
case TextComparisonType.Equal:
return paramValue == request.Value;
case TextComparisonType.NotEqual:
return paramValue != request.Value;
case TextComparisonType.StartsWith:
return paramValue.StartsWith(request.Value);
}
switch (request.TextComparisonType)
{
case TextComparisonType.Contains:
return paramValue.Contains(request.Value);
case TextComparisonType.ContainsNot:
return !paramValue.Contains(request.Value);
case TextComparisonType.EndsWith:
return paramValue.EndsWith(request.Value);
case TextComparisonType.Equal:
return paramValue == request.Value;
case TextComparisonType.NotEqual:
return paramValue != request.Value;
case TextComparisonType.StartsWith:
return paramValue.StartsWith(request.Value);
}


return false;
}
Expand Down