Пример #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 void TransformSceneInPlace(Func <IMesh, IMesh> meshTransform = null, Func <VimSceneNode, VimSceneNode> nodeTransform = null)
 {
     if (meshTransform != null)
     {
         Geometries = Geometries.Select(meshTransform).EvaluateInParallel();
     }
     if (nodeTransform != null)
     {
         VimNodes = VimNodes.Select(nodeTransform).EvaluateInParallel();
     }
 }
Пример #3
0
        public override Geometry Clone()
        {
            var result = CreateNew();

            foreach (var item in Geometries.Select(x => x.Clone()))
            {
                result.Geometries.Add(item);
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Сохранение файла
        /// </summary>
        public void SaveChanges()
        {
            if (Geometries == null || Geometries.Count == 0)
            {
                return;
            }

            var saveFileDialog = new SaveFileDialog()
            {
                Filter = "Text files (*.txt)|*.txt"
            };

            var stringsToSave = Geometries.Select(geom
                                                  => geom.GetStringToSave());

            if (saveFileDialog.ShowDialog() == true)
            {
                File.WriteAllLines(saveFileDialog.FileName, stringsToSave);
            }
        }
Пример #5
0
 public override Geometry CurveToLine(double tolerance)
 {
     return(new MultiLineString(Geometries.Select(g => g.CurveToLine(tolerance) as LineString)));
 }
Пример #6
0
 public override Geometry CurveToLine(double tolerance)
 {
     return(new MultiPolygon(Geometries.Select(g => g.CurveToLine(tolerance) as Polygon)));
 }
Пример #7
0
 public override int GetHashCode(SpatialEqualityOptions options)
 {
     return(Geometries
            .Select(x => x.GetHashCode(options))
            .Aggregate(0, (current, result) => (current * 397) ^ result));
 }
 public override string ToShortWKT2D() => string.Join(", ", Geometries.Select(p => $"({p.ToShortWKT2D()})"));