Skip to content

Commit

Permalink
Fix/collect (#48)
Browse files Browse the repository at this point in the history
Fixes bug in Collect component.
Now unwraps all typed rules first, collects all disallowed (unwrapped + originally explicit) rules and removes them from the list of allowed rules.
  • Loading branch information
janper authored May 29, 2021
1 parent 4dd6375 commit f17a0f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
38 changes: 21 additions & 17 deletions Components/RulesCollect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ protected override void SolveInstance(IGH_DataAccess DA) {

var allowedExplicit = allowedOriginalClean
.Where(rule => rule.IsExplicit)
.Select(rule => rule.Explicit);
.Select(rule => rule.Explicit)
.ToList();
var allowedTyped = allowedOriginalClean
.Where(rule => rule.IsTyped)
.Select(rule => rule.Typed);
Expand All @@ -123,7 +124,8 @@ protected override void SolveInstance(IGH_DataAccess DA) {

var disallowedExplicit = disallowedOriginalClean
.Where(rule => rule.IsExplicit)
.Select(rule => rule.Explicit);
.Select(rule => rule.Explicit)
.ToList();
var disallowedTyped = disallowedOriginalClean
.Where(rule => rule.IsTyped)
.Select(rule => rule.Typed);
Expand All @@ -150,52 +152,54 @@ protected override void SolveInstance(IGH_DataAccess DA) {
}
}

var finalTyped = new List<RuleTyped>();
var finalExplicit = new List<RuleExplicit>();

// unwrap disallowed typed rules and add them to disallowedExplicit
foreach (var entry in allTypedByType) {
var type = entry.Key;
var rules = entry.Value;
if (disallowedTypedByType.ContainsKey(type)) {
var rulesExplicit = rules.SelectMany(rule => rule.ToRulesExplicit(rules, modulesClean));
var disallowedRules = disallowedTypedByType[type];
foreach (var rule in rulesExplicit) {
if (!disallowedRules.Any(disallowedRule =>
if (disallowedRules.Any(disallowedRule =>
(disallowedRule.ModuleName == rule.SourceModuleName
&& disallowedRule.ConnectorIndex == rule.SourceConnectorIndex)
|| (disallowedRule.ModuleName == rule.TargetModuleName
&& disallowedRule.ConnectorIndex == rule.TargetConnectorIndex))
&& !disallowedExplicit.Any(disallowedRule => disallowedRule.Equals(rule))) {
finalExplicit.Add(rule);
&& disallowedRule.ConnectorIndex == rule.TargetConnectorIndex))) {
disallowedExplicit.Add(rule);
}
}
} else {
finalTyped.AddRange(rules);
}
}

// unwrap all typed rules
foreach (var rule in allTypedRules) {
var rulesExplicit = rule.ToRulesExplicit(allTypedRules, modulesClean);
allowedExplicit.AddRange(rulesExplicit);
}

var finalExplicit = new List<RuleExplicit>();

foreach (var rule in allowedExplicit) {
if (!disallowedExplicit.Any(disallowedRule => disallowedRule.Equals(rule))) {
finalExplicit.Add(rule);
}
}

var outRules = finalExplicit
var outputRules = finalExplicit
.Where(rule => !(rule.SourceModuleName == Config.OUTER_MODULE_NAME && rule.TargetModuleName == Config.OUTER_MODULE_NAME))
.Select(explicitRule => new Rule(explicitRule))
.Concat(finalTyped.Select(ruleTyped => new Rule(ruleTyped)))
.Distinct()
.Select(explicitRule => new Rule(explicitRule))
.ToList();

outRules.Sort();
outputRules.Sort();

foreach (var rule in outRules) {
foreach (var rule in outputRules) {
if (!rule.IsValid) {
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, rule.IsValidWhyNot);
}
}

DA.SetDataList(0, outRules);
DA.SetDataList(0, outputRules);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.4.4")]
[assembly: AssemblyFileVersion("1.2.4.4")]
[assembly: AssemblyVersion("1.2.4.5")]
[assembly: AssemblyFileVersion("1.2.4.5")]
Binary file modified bin/Monoceros.pdb
Binary file not shown.

0 comments on commit f17a0f5

Please sign in to comment.