示例#1
0
        /// <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 slot            = new Slot();
            var moduleNames     = new List <ModuleName>();
            var modulesProvided = false;

            if (!DA.GetData(0, ref slot))
            {
                return;
            }

            if (slot == null || !slot.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The slot is null or invalid.");
                return;
            }

            if (DA.GetDataList(1, moduleNames))
            {
                modulesProvided = true;
            }

            DA.SetDataList(0, new List <Point3d>()
            {
                slot.AbsoluteCenter
            });
            DA.SetDataList(1, new List <Plane>()
            {
                slot.BasePlane
            });
            DA.SetDataList(2, new List <Vector3d>()
            {
                slot.Diagonal
            });
            if (modulesProvided &&
                moduleNames != null &&
                slot.AllowsAnyModule &&
                slot.AllowedModuleNames.Count == 0)
            {
                DA.SetDataList(3, moduleNames);
            }
            else
            {
                DA.SetDataList(3, slot.AllowedModuleNames.Select(name => new ModuleName(name)));
            }
            if (modulesProvided &&
                moduleNames != null &&
                slot.AllowedModuleNames.Count >= moduleNames.Count &&
                moduleNames.All(name => slot.AllowedModuleNames.Contains(name.ToString())))
            {
                DA.SetDataList(4, new List <bool>()
                {
                    true
                });
            }
            else
            {
                DA.SetDataList(4, new List <bool>()
                {
                    slot.AllowsAnyModule
                });
            }
            DA.SetDataList(5, new List <bool>()
            {
                slot.IsContradictory
            });
            if (modulesProvided &&
                moduleNames != null &&
                (slot.AllowedModuleNames.Count > moduleNames.Count ||
                 !slot.AllowedModuleNames.All(name => moduleNames.Any(moduleName => moduleName.Name == name))
                ))
            {
                DA.SetData(6, false);
            }
            else
            {
                DA.SetData(6, slot.IsValid);
            }
        }