private bool ConstructLineFromExplicitRule( List <Module> modules, RuleExplicit ruleExplicit, out Line line, out Axis axis ) { line = default; axis = default; var sourceModule = modules .FirstOrDefault(module => module.Name == ruleExplicit.SourceModuleName); if (sourceModule == null) { return(false); } var sourceConnector = sourceModule .Connectors .ElementAtOrDefault(ruleExplicit.SourceConnectorIndex); if (sourceConnector.Equals(default(ModuleConnector))) { return(false); } var targetModule = modules .FirstOrDefault(module => module.Name == ruleExplicit.TargetModuleName); if (targetModule == null) { return(false); } var targetConnector = targetModule .Connectors .ElementAtOrDefault(ruleExplicit.TargetConnectorIndex); if (targetConnector.Equals(default(ModuleConnector))) { return(false); } if (targetConnector.Direction.IsOpposite(sourceConnector.Direction)) { line = new Line(sourceConnector.AnchorPlane.Origin, targetConnector.AnchorPlane.Origin); axis = sourceConnector.Direction.Axis; return(true); } else { return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="Rule"/> class. It will /// contain only <see cref="Explicit"/>. /// </summary> /// <param name="sourceModuleName">The source module name.</param> /// <param name="sourceConnectorIndex">The source connector index. /// </param> /// <param name="targetModuleName">The target module name.</param> /// <param name="targetConnectorIndex">The target connector index. /// </param> public Rule( string sourceModuleName, uint sourceConnectorIndex, string targetModuleName, uint targetConnectorIndex ) { Explicit = new RuleExplicit(sourceModuleName, sourceConnectorIndex, targetModuleName, targetConnectorIndex); }
private bool ConstructArrowFromOutRule( List <Module> modules, RuleExplicit ruleExplicit, out Line line, out Axis axis ) { line = default; axis = default; if (ruleExplicit.TargetModuleName != Config.OUTER_MODULE_NAME) { return(false); } var sourceModule = modules .FirstOrDefault(module => module.Name == ruleExplicit.SourceModuleName); if (sourceModule == null) { return(false); } var sourceConnector = sourceModule .Connectors .ElementAtOrDefault(ruleExplicit.SourceConnectorIndex); if (sourceConnector.Equals(default(ModuleConnector))) { return(false); } axis = sourceConnector.Direction.Axis; var targetPoint = sourceConnector.AnchorPlane.Origin + sourceConnector.Direction.ToVector() * sourceModule.PartDiagonal[(int)axis] / 4; line = new Line(sourceConnector.AnchorPlane.Origin, targetPoint); return(true); }
/// <summary> /// Wrap input geometry into module cages. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from /// input parameters and to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { var modulesRaw = new List <Module>(); var slotsRaw = new List <Slot>(); if (!DA.GetDataList(0, slotsRaw)) { return; } if (!DA.GetDataList(1, modulesRaw)) { return; } var slotsClean = new List <Slot>(); var warnNonDeterministic = false; foreach (var slot in slotsRaw) { if (slot == null || !slot.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Slot is null or invalid and will be skipped."); continue; } if (!slot.IsDeterministic) { warnNonDeterministic = true; } slotsClean.Add(slot); } if (warnNonDeterministic) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "One or more Slots are non-deterministic."); } var modulesClean = new List <Module>(); foreach (var module in modulesRaw) { if (module == null || !module.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Module is null or invalid."); continue; } if (module.Geometry.Count + module.ReferencedGeometry.Count == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Module \"" + module.Name + "\" contains " + "no geometry and therefore will be skipped."); continue; } modulesClean.Add(module); } if (!modulesClean.Any()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No valid Modules collected."); return; } if (!slotsClean.Any()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No valid Slots collected."); return; } var rulesOut = new List <Rule>(); foreach (var slot in slotsClean) { foreach (var slotOther in slotsClean) { if (slot.RelativeCenter.IsNeighbor(slotOther.RelativeCenter)) { var neighborVector = (slotOther.RelativeCenter - slot.RelativeCenter).ToVector3d(); if (Direction.FromVector(neighborVector, out var direction) && direction.Orientation == Orientation.Positive) { foreach (var currentPart in slot.AllowedPartNames) { foreach (var otherPart in slotOther.AllowedPartNames) { if (modulesClean.Any(module => module.ContainsPart(currentPart)) && modulesClean.Any(module => module.ContainsPart(otherPart))) { var ruleForSolver = new RuleForSolver(direction.Axis, currentPart, otherPart); if (RuleExplicit.FromRuleForSolver(ruleForSolver, modulesClean, out var ruleExplicit)) { var rule = new Rule(ruleExplicit); if (!rulesOut.Contains(rule)) { rulesOut.Add(rule); } } } } } } } } } rulesOut.Sort(); DA.SetDataList(0, rulesOut); }
/// <summary> /// Initializes a new instance of the <see cref="Rule"/> class. It will /// contain only <see cref="Explicit"/>. /// </summary> /// <param name="ruleExplicit">The <see cref="RuleExplicit"/> to be /// wrapped into the <see cref="Rule"/>.</param> public Rule( RuleExplicit ruleExplicit ) { Explicit = ruleExplicit; }