Пример #1
0
        //CONSTRUCTOR
        public Design(RadicalComponent component)
        {
            //Access the component
            this.MyComponent = component;

            this.Variables   = new List <IVariable>();
            this.Geometries  = new List <IDesignGeometry>();
            this.Constraints = new List <Constraint>();

            // ADD VARIABLES
            //Sliders
            foreach (IGH_Param param in MyComponent.Params.Input[2].Sources)
            {
                SliderVariable s = new SliderVariable(param);
                if (s.CurrentValue == 0)
                {
                    if (s.Max >= 0.001)
                    {
                        s.UpdateValue(0.001);
                    }
                    else
                    {
                        s.UpdateValue(-0.001);
                    }
                }
                this.Variables.Add(new SliderVariable(param));
            }
            Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false, Grasshopper.Kernel.GH_SolutionMode.Silent);

            //Surfaces
            for (int i = 0; i < MyComponent.Params.Input[3].Sources.Count; i++)
            {
                IGH_Param    param = MyComponent.Params.Input[3].Sources[i];
                NurbsSurface surf  = MyComponent.SrfVariables[i];
                Geometries.Add(new DesignSurface(param, surf));
            }
            //Curves
            for (int i = 0; i < MyComponent.Params.Input[4].Sources.Count; i++)
            {
                IGH_Param  param = MyComponent.Params.Input[4].Sources[i];
                NurbsCurve curv  = MyComponent.CrvVariables[i];
                this.Geometries.Add(new DesignCurve(param, curv));
            }

            // Add geometries to variables list
            // not the cleanest way to do it, review code structure
            if (Geometries.Any())
            {
                this.Variables.AddRange(Geometries.Select(x => x.Variables).SelectMany(x => x).ToList());
            }

            // ADD CONSTRAINTS
            for (int i = 0; i < component.Constraints.Count; i++)
            {
                this.Constraints.Add(new Constraint(MyComponent, Constraint.ConstraintType.morethan, i));
            }

            MyComponent.numVars = this.Variables.Where(var => var.IsActive).Count();
        }
Пример #2
0
 public Constraint(RadicalComponent mycomponent, ConstraintType constraintType, int constraintindex,
                   double limit = 0, bool active = true)
 {
     MyComponent          = mycomponent;
     this.ConstraintIndex = constraintindex;
     this.MyType          = constraintType;
     this.LimitValue      = limit;
     this.IsActive        = active;
 }
 public DSOptimizationComponentAttributes(IGH_Component component) : base(component)
 {
     MyComponent = (RadicalComponent)component;
 }