Exemplo n.º 1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Colour  inColor     = null;
            GH_Colour  inAmbient   = null;
            GH_Colour  inEmissive  = null;
            GH_Number  inOpacity   = null;
            GH_Boolean inSmooth    = null;
            String     outMaterial = null;

            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            if (inColor == null)
            {
                return;
            }
            DA.GetData(1, ref inAmbient);
            DA.GetData(2, ref inEmissive);
            DA.GetData(3, ref inOpacity);
            if (inOpacity.Value > 1 || inOpacity.Value < 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1.  Check your 'O' input.");
                inOpacity.Value = 1.0;
            }
            DA.GetData(4, ref inSmooth);

            outMaterial = ConstructLambertMaterial(inColor, inAmbient, inEmissive, inOpacity.Value, inSmooth.Value);

            Material material = new Material(outMaterial, va3cMaterialType.Mesh);

            DA.SetData(0, material);
        }
Exemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_String path = new GH_String();

            DA.GetData <GH_String>(0, ref path);

            GH_Boolean mesh = new GH_Boolean(true);

            if (!DA.GetData <GH_Boolean>(1, ref mesh))
            {
                mesh = new GH_Boolean(true);
            }

            List <GH_Brep>   surfaces  = new List <GH_Brep>();
            List <GH_String> layers    = new List <GH_String>();
            List <Instance>  Instances = new List <Instance>();
            List <GH_Curve>  curves    = new List <GH_Curve>();
            List <GH_Mesh>   meshes    = new List <GH_Mesh>();

            SketchUp skp = new SketchUp();

            if (skp.LoadModel(path.Value, mesh.Value))
            {
                foreach (Surface srf in skp.Surfaces)
                {
                    foreach (var brep in srf.ToRhinoGeo())
                    {
                        surfaces.Add(new GH_Brep(brep));
                    }

                    if (srf.FaceMesh != null)
                    {
                        meshes.Add(new GH_Mesh(srf.FaceMesh.ToRhinoGeo()));
                    }
                }

                foreach (Layer l in skp.Layers)
                {
                    layers.Add(new GH_String(l.Name));
                }

                foreach (Instance i in skp.Instances)
                {
                    Instances.Add(i);
                }

                foreach (Edge c in skp.Edges)
                {
                    curves.Add(new GH_Curve(c.ToRhinoGeo().ToNurbsCurve()));
                }
            }

            DA.SetDataList(0, surfaces);
            DA.SetDataList(1, layers);
            DA.SetDataList(2, Instances);
            DA.SetDataList(3, curves);
            DA.SetDataList(4, meshes);
        }
Exemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Surface surface    = new GH_Surface();
            GH_String  lvlbtm     = new GH_String("");
            GH_String  style      = new GH_String("");
            GH_String  layer      = new GH_String("");
            GH_Number  taperAng   = new GH_Number(0);
            GH_Number  height     = new GH_Number();
            GH_Point   stop       = new GH_Point();
            GH_Point   sbtm       = new GH_Point();
            GH_Boolean structural = new GH_Boolean(true);

            List <Parameter> param = new List <Parameter>();

            if (!DA.GetDataList <Parameter>("Parameters", param))
            {
                param = new List <Parameter>();
            }
            DA.GetData <GH_Surface>("Surface", ref surface);

            DA.GetData <GH_String>("Layer", ref layer);
            //DA.GetData<GH_String>("Style", ref style);
            DA.GetData <GH_Number>("taperAngle", ref taperAng);
            DA.GetData <GH_Number>("height", ref height);

            Slab s = new Slab();

            s.FamilyOrStyle   = style.Value;
            s.TypeOrLayer     = layer.Value;
            s.levelbottom     = lvlbtm.Value;
            s.structural      = structural.Value;
            s.surface         = new Profile();
            s.surface.profile = new List <Loop>();
            Loop loop = new Loop()
            {
                outline = new List <Component>()
            };

            foreach (Rhino.Geometry.BrepEdge be in surface.Value.Edges)
            {
                loop.outline.Add(be.ToNurbsCurve().ToGrevitCurve());
            }
            s.surface.profile.Add(loop);


            s.height     = height.Value;
            s.parameters = param;
            //s.top = ComponentUtilities.GHPoint2Point(stop);
            //s.bottom = ComponentUtilities.GHPoint2Point(sbtm);
            s.slope = taperAng.Value;
            s.GID   = this.InstanceGuid.ToString();


            //SetPreview(s.GID, surface.Value);
            DA.SetData("GrevitComponent", s);
        }
Exemplo n.º 4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Program program      = null;
            GH_Number  sliderTimeGH = null;
            GH_Boolean isNormalized = null;

            if (!DA.GetData(0, ref program))
            {
                return;
            }
            if (!DA.GetData(1, ref sliderTimeGH))
            {
                return;
            }
            if (!DA.GetData(2, ref isNormalized))
            {
                return;
            }


            sliderTime = (isNormalized.Value) ? sliderTimeGH.Value * program.Value.Duration : sliderTimeGH.Value;
            if (!form.Visible)
            {
                time = sliderTime;
            }

            program.Value.Animate(time, false);
            var currentTarget = program.Value.CurrentSimulationTarget;

            var errors = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Errors);
            var meshes = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Meshes);
            var joints = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Joints);
            var planes = currentTarget.ProgramTargets.SelectMany(x => x.Kinematics.Planes);

            if (errors.Count() > 0)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Errors in solution");
            }

            DA.SetDataList(0, meshes?.Select(x => new GH_Mesh(x)));
            DA.SetDataList(1, joints);
            DA.SetDataList(2, planes.Select(x => new GH_Plane(x)));
            DA.SetData(3, currentTarget.Index);
            DA.SetData(4, program.Value.CurrentSimulationTime);
            DA.SetData(5, new GH_Program(program.Value));
            DA.SetDataList(6, errors);

            if (form.Visible && form.play.Checked.Value)
            {
                var      currentTime = DateTime.Now;
                TimeSpan delta       = currentTime - lastTime;
                time    += delta.TotalSeconds * speed;
                lastTime = currentTime;
                this.ExpireSolution(true);
            }
        }
Exemplo n.º 5
0
        /*******************************************/

        public static bool CastToGoo(object value, ref IGH_QuickCast target)
        {
            try
            {
                if (value is bool)
                {
                    target = new GH_Boolean((bool)value);
                }
                else if (value is Color)
                {
                    target = new GH_Colour((Color)value);
                }
                else if (value is Complex)
                {
                    target = new GH_ComplexNumber((Complex)value);
                }
                else if (value is int)
                {
                    target = new GH_Integer((int)value);
                }
                else if (value is Interval)
                {
                    target = new GH_Interval((Interval)value);
                }
                else if (value is Matrix)
                {
                    target = new GH_Matrix((Matrix)value);
                }
                else if (value is double || value is float)
                {
                    target = new GH_Number((double)value);
                }
                else if (value is Point3d)
                {
                    target = new GH_Point((Point3d)value);
                }
                else if (value is string)
                {
                    target = new GH_String(value.ToString());
                }
                else if (value is Vector3d)
                {
                    target = new GH_Vector((Vector3d)value);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Boolean ghBolX = new GH_Boolean();

            if (DA.GetData(0, ref ghBolX))
            {
                GH_Convert.ToBoolean(ghBolX, out x, GH_Conversion.Both); //use Grasshopper to convert, these methods covers many cases and are consistent
            }
            GH_Boolean ghBolY = new GH_Boolean();

            if (DA.GetData(1, ref ghBolY))
            {
                GH_Convert.ToBoolean(ghBolY, out y, GH_Conversion.Both);
            }
            GH_Boolean ghBolZ = new GH_Boolean();

            if (DA.GetData(2, ref ghBolZ))
            {
                GH_Convert.ToBoolean(ghBolZ, out z, GH_Conversion.Both);
            }
            GH_Boolean ghBolXX = new GH_Boolean();

            if (DA.GetData(3, ref ghBolXX))
            {
                GH_Convert.ToBoolean(ghBolXX, out xx, GH_Conversion.Both);
            }
            GH_Boolean ghBolYY = new GH_Boolean();

            if (DA.GetData(4, ref ghBolYY))
            {
                GH_Convert.ToBoolean(ghBolYY, out yy, GH_Conversion.Both);
            }
            GH_Boolean ghBolZZ = new GH_Boolean();

            if (DA.GetData(5, ref ghBolZZ))
            {
                GH_Convert.ToBoolean(ghBolZZ, out zz, GH_Conversion.Both);
            }
            GsaBool6 bool6 = new GsaBool6
            {
                X  = x,
                Y  = y,
                Z  = z,
                XX = xx,
                YY = yy,
                ZZ = zz
            };

            DA.SetData(0, new GsaBool6Goo(bool6.Duplicate())); // output as Goo-type for consistency.
        }
Exemplo n.º 7
0
        public override Boolean Equals(Object that)
        {
            if (that == null)
            {
                return(false);
            }
            if (that.GetType() != this.GetType())
            {
                return(false);
            }

            //FIXME: use a reflection to get the Value property of the GH_Goo
            //if a value property is missing, it seems that we could not compare Goos (or different method should be used)

            // GH_Goo.Equals(GH_Goo) compare the GUIDs which are different in the common case
            // that's why we need to compare GH_Goo inner values
            // unfortunately the Value property is not generic for GH_Goo
            // only some GH_Goo have value assigned
            GH_CellState thatState = (GH_CellState)that;

            if (value.GetType() == GH_TypeLib.t_gh_colour)
            {
                GH_Colour thisGH_Colour = (GH_Colour)value;
                GH_Colour thatGH_Colour = (GH_Colour)thatState.value;

                return(thisGH_Colour.Value.Equals(thatGH_Colour.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_bool)
            {
                GH_Boolean thisGH_Boolean = (GH_Boolean)this.value;
                GH_Boolean thatGH_Boolean = (GH_Boolean)thatState.value;
                return(thisGH_Boolean.Value.Equals(thatGH_Boolean.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_int)
            {
                GH_Integer thisGH_Integer = (GH_Integer)this.value;
                GH_Integer thatGH_Integer = (GH_Integer)thatState.value;
                return(thisGH_Integer.Value.Equals(thatGH_Integer.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_string)
            {
                GH_String thisGH_String = (GH_String)this.value;
                GH_String thatGH_String = (GH_String)thatState.value;
                return(thisGH_String.Value.Equals(thatGH_String.Value));
            }

            throw new NotSupportedException("Could not compare GH_Goo type: " + value.GetType());
        }
Exemplo n.º 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <GH_ObjectWrapper> lines = new List <GH_ObjectWrapper>();
            List <GH_Guid>          cakes = new List <GH_Guid>();
            GH_String  layername          = new GH_String("");
            GH_Boolean bake = new GH_Boolean(false);

            DA.GetData <GH_String>("layer", ref layername);
            DA.GetData <GH_Boolean>("bake", ref bake);



            if (!DA.GetDataList <GH_ObjectWrapper>("dough", lines))
            {
                lines = new List <GH_ObjectWrapper>();
            }


            if (lines.Count > 0 && bake.Value)
            {
                foreach (GH_ObjectWrapper line in lines)
                {
                    int layerindex = 0;
                    Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();



                    foreach (Rhino.DocObjects.Layer layer in Rhino.RhinoDoc.ActiveDoc.Layers)
                    {
                        if (layer.Name == layername.Value)
                        {
                            layerindex = layer.LayerIndex;
                        }
                    }
                    att.LayerIndex = layerindex;

                    Guid g = Guid.Empty;
                    line.BakeGeometry(Rhino.RhinoDoc.ActiveDoc, att, ref g);
                    if (g != Guid.Empty)
                    {
                        cakes.Add(new GH_Guid(g));
                    }
                }

                DA.SetDataList("cake", cakes);
            }
        }
Exemplo n.º 9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var points = new List <GH_Point>();
            var h      = new GH_Number();
            var k      = new GH_Number();
            var e      = new GH_Boolean();

            if (DA.GetDataList(0, points) && points == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled.");
                return;
            }

            if (points.Count == 0)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Singularity point list must not be empty. Operation canceled.");
                return;
            }

            if (DA.GetData(1, ref h) && h == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid h value. Operation canceled.");
                return;
            }

            if (DA.GetData(2, ref k) && k == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid k value. Operation canceled.");
                return;
            }

            if (DA.GetData(3, ref e) && e == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid e value. Operation canceled.");
                return;
            }

            var dynamic = new GravityDynamic();

            dynamic.Param["SP"] = points;
            dynamic.Param["h"]  = h.Value;
            dynamic.Param["k"]  = k.Value;
            dynamic.Param["e"]  = e.Value;

            DA.SetData(0, new GH_ObjectWrapper(dynamic));
        }
Exemplo n.º 10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Boolean       assoc  = new GH_Boolean(false);
            GH_String        name   = new GH_String();
            GH_String        layer  = new GH_String("");
            GH_String        style  = new GH_String("");
            GH_String        number = new GH_String();
            List <Parameter> param  = new List <Parameter>();
            List <GH_Point>  points = new List <GH_Point>();

            if (!DA.GetDataList <Parameter>("Parameters", param))
            {
                param = new List <Parameter>();
            }

            if (!DA.GetDataList <GH_Point>("Points", points))
            {
                points = new List <GH_Point>();
            }

            DA.GetData <GH_String>("Name", ref name);
            DA.GetData <GH_Boolean>("Assoc", ref assoc);
            DA.GetData <GH_String>("Number", ref number);
            DA.GetData <GH_String>("Style", ref style);
            DA.GetData <GH_String>("Layer", ref layer);


            Room ac = new Room(name.Value, number.Value, "", param);

            IEnumerable <GH_Point> nodups = points.Distinct(new GH_PointComparer());

            ac.points = new List <Grevit.Types.Point>();
            foreach (var p in nodups)
            {
                ac.points.Add(p.ToGrevitPoint());
            }

            ac.associative   = assoc.Value;
            ac.FamilyOrStyle = style.Value;
            ac.TypeOrLayer   = layer.Value;
            ac.GID           = this.InstanceGuid.ToString();

            DA.SetData("GrevitComponent", ac);
        }
Exemplo n.º 11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var reset = new GH_Boolean();

            if (DA.GetData(0, ref reset) && reset == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid reset input. Operation canceled.");
                return;
            }

            if (reset.Value)
            {
                counter = 0;
            }
            else
            {
                counter++;
            }

            DA.SetData(0, counter);
        }
Exemplo n.º 12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <Curve> _CurveList       = new List <Curve>();
            List <Curve> ProcessCurve     = new List <Curve>();
            List <Curve> _OutputCurveList = new List <Curve>();
            GH_Point     ReferencePoint   = default(GH_Point);
            GH_Boolean   IsReverse        = default(GH_Boolean);

            if (!DA.GetDataList <Curve>(0, _CurveList))
            {
                return;
            }
            if (!DA.GetData(1, ref ReferencePoint))
            {
                return;
            }
            if (!DA.GetData(2, ref IsReverse))
            {
                return;
            }

            ProcessCurve = _CurveList.Select(item => item.DuplicateCurve()).ToList();

            for (int Index = 0; Index < ProcessCurve.Count; Index++)
            {
                Curve CrvItem = _CurveList[Index];
                if (CrvItem.PointAtStart.DistanceTo(ReferencePoint.Value) > CrvItem.PointAtEnd.DistanceTo(ReferencePoint.Value))
                {
                    CrvItem.Reverse();
                }
                if (IsReverse.Value)
                {
                    CrvItem.Reverse();
                }
                _OutputCurveList.Add(CrvItem);
            }
            DA.SetDataList(0, _OutputCurveList);
        }
Exemplo n.º 13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve baseline = new GH_Curve();
            GH_String level = new GH_String("none");
            GH_Number height = new GH_Number();
            GH_Number offset = new GH_Number();
            GH_Boolean join = new GH_Boolean(true);
            GH_Boolean flip = new GH_Boolean(false);
            GH_String family = new GH_String("");
            GH_String type = new GH_String("none");

            List<Parameter> parameters = new List<Parameter>();
            if (!DA.GetDataList<Parameter>("Parameters", parameters)) parameters = new List<Parameter>();

            DA.GetData<GH_Boolean>("Join", ref join);
            DA.GetData<GH_String>("Type", ref type);
            DA.GetData<GH_String>("Levelbottom", ref level);
            DA.GetData<GH_Number>("Height", ref height);
            DA.GetData<GH_Curve>("Baseline", ref baseline);
            DA.GetData<GH_Boolean>("Flip", ref flip);


            Wall wall = new Wall(family.Value, type.Value, parameters, baseline.ToGrevitCurve(), level.Value,height.Value,join.Value,flip.Value );
            
            Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(baseline.Value, new Rhino.Geometry.Vector3d(0, 0, height.Value));

            SetGID(wall);
            SetPreview(wall.GID, srf.ToBrep());
            
            DA.SetData("GrevitComponent", wall);
        }
Exemplo n.º 14
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve line = new GH_Curve();
            DA.GetData<GH_Curve>("Curve", ref line);
            GH_Boolean isModelLine = new GH_Boolean(false);
            GH_Boolean isDetailLine = new GH_Boolean(false);
            GH_Boolean isRoomBoundary = new GH_Boolean(false);
            DA.GetData<GH_Boolean>("isModelLine", ref isModelLine);
            DA.GetData<GH_Boolean>("isDetailLine", ref isDetailLine);
            DA.GetData<GH_Boolean>("isRoomBoundary", ref isRoomBoundary);

            RevitLine revitLine = new RevitLine();
            revitLine.curve = line.Value.ToNurbsCurve().ToGrevitCurve();

            SetGID(revitLine);
            revitLine.isModelCurve = isModelLine.Value;
            revitLine.isDetailCurve = isDetailLine.Value;
            revitLine.isRoomBounding = isRoomBoundary.Value;

            DA.SetData("GrevitComponent", revitLine);
        }
Exemplo n.º 15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_String name = new GH_String();
            GH_Number elevation = new GH_Number();
            GH_Boolean view = new GH_Boolean();

            DA.GetData<GH_String>("Name", ref name);
            DA.GetData<GH_Boolean>("View", ref view);
            DA.GetData<GH_Number>("Elevation", ref elevation);

            Level level = new Level(name.Value, elevation.Value, view.Value);
            level.GID = this.InstanceGuid.ToString();
            DA.SetData("GrevitComponent", level);
        }
Exemplo n.º 16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string serializedData = this.GetValue("assembly", "");

            if (serializedData != "")
            {
                this.assembly = (Types.Assembly)Serialization.Utilities.Deserialize(serializedData, typeof(Types.Assembly));
            }

            GH_String path = new GH_String("");
            DA.GetData<GH_String>("Path", ref path);
            GH_Boolean percentual = new GH_Boolean(false);
            if (!DA.GetData<GH_Boolean>("Percentual", ref percentual)) percentual.Value = false;

            this.isPercentual = percentual.Value;
            this.alternativeDataSourcePath = path.Value;

            //if (assembly != null) this.SetValue("assembly", Serialization.Utilities.Serialize(this.assembly));

            DA.SetData("Material", assembly);
        }
Exemplo n.º 17
0
        /*******************************************/

        public static bool CastToGoo(object value, ref GH_Boolean target)
        {
            return(GH_Convert.ToGHBoolean(value, GH_Conversion.Both, ref target));
        }
Exemplo n.º 18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var respawn  = new GH_Boolean();
            var newSpawn = new GH_Integer();
            var rndSpawn = new GH_Integer();

            var avgRadius = new GH_Number();
            var bounds    = new GH_Brep();
            var snapTol   = new GH_Number();
            var snapAngle = new GH_Number();
            var surface   = new GH_Surface();
            var lineCont  = new GH_Boolean();

            if (DA.GetData(0, ref respawn) && respawn == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid respawn value. Operation canceled.");
                return;
            }

            if (DA.GetData(1, ref newSpawn) && newSpawn == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid new spawn value. Operation canceled.");
                return;
            }

            if (DA.GetData(2, ref rndSpawn) && rndSpawn == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid new spawn randomizing value. Operation canceled.");
                return;
            }

            if (DA.GetData(3, ref avgRadius) && avgRadius == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid interpolation radius value. Operation canceled.");
                return;
            }

            if (DA.GetData(4, ref bounds) && bounds == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid bounding box. Operation canceled.");
                return;
            }

            if (DA.GetData(5, ref snapTol) && snapTol == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid snap tolerance. Operation canceled.");
                return;
            }

            if (DA.GetData(6, ref snapAngle) && snapAngle == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid snapping angle. Operation canceled.");
                return;
            }

            if (DA.GetData(7, ref surface) && surface == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid surface constraint. Operation canceled.");
                return;
            }

            if (DA.GetData(8, ref lineCont) && lineCont == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid line continuity value. Operation canceled.");
                return;
            }

            DynamicSettings settings = new DynamicSettings();

            settings.respawn   = respawn.Value;
            settings.newSpawn  = newSpawn.Value;
            settings.rndSpawn  = rndSpawn.Value;
            settings.avgRadius = avgRadius.Value;
            settings.bounds    = bounds;
            settings.snapTol   = snapTol.Value;
            settings.snapAngle = snapAngle.Value;
            settings.surface   = surface;
            settings.lineCont  = lineCont.Value;

            var output = new GH_ObjectWrapper(settings);

            DA.SetData(0, output);
        }
Exemplo n.º 19
0
        public static Response Grasshopper(NancyContext ctx)
        {
            // load grasshopper file
            var archive = new GH_Archive();
            // TODO: stream to string
            var body = ctx.Request.Body.ToString();

            string json = string.Empty;

            using (var reader = new StreamReader(ctx.Request.Body))
            {
                json = reader.ReadToEnd();
            }

            //GrasshopperInput input = Newtonsoft.Json.JsonConvert.DeserializeObject<GrasshopperInput>(json);
            //JsonSerializerSettings settings = new JsonSerializerSettings();
            //settings.ContractResolver = new DictionaryAsArrayResolver();
            Schema input = JsonConvert.DeserializeObject <Schema>(json);

            string grasshopperXml = string.Empty;

            if (input.Algo != null)
            {
                // If request contains markup
                byte[] byteArray = Convert.FromBase64String(input.Algo);
                grasshopperXml = System.Text.Encoding.UTF8.GetString(byteArray);
            }
            else
            {
                // If request contains pointer
                string pointer = input.Pointer;
                grasshopperXml = GetGhxFromPointer(pointer);
            }
            if (!archive.Deserialize_Xml(grasshopperXml))
            {
                throw new Exception();
            }

            var definition = new GH_Document();

            if (!archive.ExtractObject(definition, "Definition"))
            {
                throw new Exception();
            }

            // Set input params
            foreach (var obj in definition.Objects)
            {
                var group = obj as GH_Group;
                if (group == null)
                {
                    continue;
                }

                if (group.NickName.Contains("RH_IN"))
                {
                    // It is a RestHopper input group!
                    GHTypeCodes code  = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]);
                    var         param = group.Objects()[0];
                    //GH_Param<IGH_Goo> goo = obj as GH_Param<IGH_Goo>;

                    // SetData
                    foreach (Resthopper.IO.DataTree <ResthopperObject> tree in input.Values)
                    {
                        string paramname = tree.ParamName;
                        if (group.NickName == paramname)
                        {
                            switch (code)
                            {
                            case GHTypeCodes.Boolean:
                                //PopulateParam<GH_Boolean>(goo, tree);
                                Param_Boolean boolParam = param as Param_Boolean;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Boolean> objectList = new List <GH_Boolean>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                                        GH_Boolean       data    = new GH_Boolean(boolean);
                                        boolParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Point:
                                //PopulateParam<GH_Point>(goo, tree);
                                Param_Point ptParam = param as Param_Point;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Point> objectList = new List <GH_Point>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject       restobj = entree.Value[i];
                                        Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                                        GH_Point data = new GH_Point(rPt);
                                        ptParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Vector:
                                //PopulateParam<GH_Vector>(goo, tree);
                                Param_Vector vectorParam = param as Param_Vector;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Vector> objectList = new List <GH_Vector>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject        restobj  = entree.Value[i];
                                        Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                                        GH_Vector data = new GH_Vector(rhVector);
                                        vectorParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Integer:
                                //PopulateParam<GH_Integer>(goo, tree);
                                Param_Integer integerParam = param as Param_Integer;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Integer> objectList = new List <GH_Integer>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                                        GH_Integer data          = new GH_Integer(rhinoInt);
                                        integerParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Number:
                                //PopulateParam<GH_Number>(goo, tree);
                                Param_Number numberParam = param as Param_Number;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Number> objectList = new List <GH_Number>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                                        GH_Number        data     = new GH_Number(rhNumber);
                                        numberParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Text:
                                //PopulateParam<GH_String>(goo, tree);
                                Param_String stringParam = param as Param_String;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_String> objectList = new List <GH_String>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                                        GH_String        data     = new GH_String(rhString);
                                        stringParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Line:
                                //PopulateParam<GH_Line>(goo, tree);
                                Param_Line lineParam = param as Param_Line;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Line> objectList = new List <GH_Line>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                                        GH_Line             data    = new GH_Line(rhLine);
                                        lineParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Curve:
                                //PopulateParam<GH_Curve>(goo, tree);
                                Param_Curve curveParam = param as Param_Curve;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Curve> objectList = new List <GH_Curve>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        GH_Curve         ghCurve;
                                        try
                                        {
                                            Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                            Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                            ghCurve = new GH_Curve(c);
                                        }
                                        catch
                                        {
                                            Rhino.Geometry.NurbsCurve data = JsonConvert.DeserializeObject <Rhino.Geometry.NurbsCurve>(restobj.Data);
                                            Rhino.Geometry.Curve      c    = new Rhino.Geometry.NurbsCurve(data);
                                            ghCurve = new GH_Curve(c);
                                        }
                                        curveParam.AddVolatileData(path, i, ghCurve);
                                    }
                                }
                                break;

                            case GHTypeCodes.Circle:
                                //PopulateParam<GH_Circle>(goo, tree);
                                Param_Circle circleParam = param as Param_Circle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Circle> objectList = new List <GH_Circle>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject      restobj  = entree.Value[i];
                                        Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                                        GH_Circle             data     = new GH_Circle(rhCircle);
                                        circleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.PLane:
                                //PopulateParam<GH_Plane>(goo, tree);
                                Param_Plane planeParam = param as Param_Plane;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Plane> objectList = new List <GH_Plane>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject     restobj = entree.Value[i];
                                        Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                                        GH_Plane             data    = new GH_Plane(rhPlane);
                                        planeParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Rectangle:
                                //PopulateParam<GH_Rectangle>(goo, tree);
                                Param_Rectangle rectangleParam = param as Param_Rectangle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path             path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Rectangle> objectList = new List <GH_Rectangle>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject           restobj     = entree.Value[i];
                                        Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                                        GH_Rectangle data = new GH_Rectangle(rhRectangle);
                                        rectangleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Box:
                                //PopulateParam<GH_Box>(goo, tree);
                                Param_Box boxParam = param as Param_Box;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path       path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Box> objectList = new List <GH_Box>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject   restobj = entree.Value[i];
                                        Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                                        GH_Box             data    = new GH_Box(rhBox);
                                        boxParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Surface:
                                //PopulateParam<GH_Surface>(goo, tree);
                                Param_Surface surfaceParam = param as Param_Surface;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Surface> objectList = new List <GH_Surface>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject       restobj   = entree.Value[i];
                                        Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                                        GH_Surface             data      = new GH_Surface(rhSurface);
                                        surfaceParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Brep:
                                //PopulateParam<GH_Brep>(goo, tree);
                                Param_Brep brepParam = param as Param_Brep;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Brep> objectList = new List <GH_Brep>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                                        GH_Brep             data    = new GH_Brep(rhBrep);
                                        brepParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Mesh:
                                //PopulateParam<GH_Mesh>(goo, tree);
                                Param_Mesh meshParam = param as Param_Mesh;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Mesh> objectList = new List <GH_Mesh>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                                        GH_Mesh             data    = new GH_Mesh(rhMesh);
                                        meshParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Slider:
                                //PopulateParam<GH_Number>(goo, tree);
                                GH_NumberSlider sliderParam = param as GH_NumberSlider;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Number> objectList = new List <GH_Number>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                                        GH_Number        data     = new GH_Number(rhNumber);
                                        sliderParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.BooleanToggle:
                                //PopulateParam<GH_Boolean>(goo, tree);
                                GH_BooleanToggle toggleParam = param as GH_BooleanToggle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Boolean> objectList = new List <GH_Boolean>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj   = entree.Value[i];
                                        bool             rhBoolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                                        GH_Boolean       data      = new GH_Boolean(rhBoolean);
                                        toggleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Panel:
                                //PopulateParam<GH_String>(goo, tree);
                                GH_Panel panelParam = param as GH_Panel;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Panel> objectList = new List <GH_Panel>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                                        GH_String        data     = new GH_String(rhString);
                                        panelParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            Schema OutputSchema = new Schema();

            OutputSchema.Algo = Utils.Base64Encode(string.Empty);

            // Parse output params
            foreach (var obj in definition.Objects)
            {
                var group = obj as GH_Group;
                if (group == null)
                {
                    continue;
                }

                if (group.NickName.Contains("RH_OUT"))
                {
                    // It is a RestHopper output group!
                    GHTypeCodes code  = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]);
                    var         param = group.Objects()[0] as IGH_Param;
                    if (param == null)
                    {
                        continue;
                    }

                    try
                    {
                        param.CollectData();
                        param.ComputeData();
                    }
                    catch (Exception)
                    {
                        param.Phase = GH_SolutionPhase.Failed;
                        // TODO: throw something better
                        throw;
                    }

                    // Get data
                    Resthopper.IO.DataTree <ResthopperObject> OutputTree = new Resthopper.IO.DataTree <ResthopperObject>();
                    OutputTree.ParamName = group.NickName;

                    var volatileData = param.VolatileData;
                    for (int p = 0; p < volatileData.PathCount; p++)
                    {
                        List <ResthopperObject> ResthopperObjectList = new List <ResthopperObject>();
                        foreach (var goo in volatileData.get_Branch(p))
                        {
                            if (goo == null)
                            {
                                continue;
                            }
                            else if (goo.GetType() == typeof(GH_Boolean))
                            {
                                GH_Boolean ghValue = goo as GH_Boolean;
                                bool       rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <bool>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Point))
                            {
                                GH_Point ghValue = goo as GH_Point;
                                Point3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Point3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Vector))
                            {
                                GH_Vector ghValue = goo as GH_Vector;
                                Vector3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Vector3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Integer))
                            {
                                GH_Integer ghValue = goo as GH_Integer;
                                int        rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <int>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Number))
                            {
                                GH_Number ghValue = goo as GH_Number;
                                double    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <double>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_String))
                            {
                                GH_String ghValue = goo as GH_String;
                                string    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <string>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Line))
                            {
                                GH_Line ghValue = goo as GH_Line;
                                Line    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Line>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Curve))
                            {
                                GH_Curve ghValue = goo as GH_Curve;
                                Curve    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Curve>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Circle))
                            {
                                GH_Circle ghValue = goo as GH_Circle;
                                Circle    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Circle>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Plane))
                            {
                                GH_Plane ghValue = goo as GH_Plane;
                                Plane    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Plane>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Rectangle))
                            {
                                GH_Rectangle ghValue = goo as GH_Rectangle;
                                Rectangle3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Rectangle3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Box))
                            {
                                GH_Box ghValue = goo as GH_Box;
                                Box    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Box>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Surface))
                            {
                                GH_Surface ghValue = goo as GH_Surface;
                                Brep       rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Brep))
                            {
                                GH_Brep ghValue = goo as GH_Brep;
                                Brep    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Mesh))
                            {
                                GH_Mesh ghValue = goo as GH_Mesh;
                                Mesh    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Mesh>(rhValue));
                            }
                        }

                        GhPath path = new GhPath(new int[] { p });
                        OutputTree.Add(path.ToString(), ResthopperObjectList);
                    }

                    OutputSchema.Values.Add(OutputTree);
                }
            }


            if (OutputSchema.Values.Count < 1)
            {
                throw new System.Exceptions.PayAttentionException("Looks like you've missed something..."); // TODO
            }
            string returnJson = JsonConvert.SerializeObject(OutputSchema);

            return(returnJson);
        }
Exemplo n.º 20
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaBeamLoad beamLoad = new GsaBeamLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            beamLoad.BeamLoad.Case = lc;

            // 1 element/beam list
            string    beamList = ""; //pick an initial name that is sure not to be used...
            GH_String gh_bl    = new GH_String();

            if (DA.GetData(1, ref gh_bl))
            {
                GH_Convert.ToString(gh_bl, out beamList, GH_Conversion.Both);
            }
            //var isNumeric = int.TryParse(beamList, out int n);
            //if (isNumeric)
            //    beamList = "PB" + n;
            beamLoad.BeamLoad.Elements = beamList;

            // 2 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(2, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    beamLoad.BeamLoad.Name = name;
                }
            }

            // 3 axis
            int axis = 0;

            beamLoad.BeamLoad.AxisProperty = 0; //Note there is currently a bug/undocumented in GsaAPI that cannot translate an integer into axis type (Global, Local or edformed local)
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(3, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    beamLoad.BeamLoad.AxisProperty = axis;
                }
            }

            // 4 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(4, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper().Trim();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }
            if (dir == "XX")
            {
                direc = Direction.XX;
            }
            if (dir == "YY")
            {
                direc = Direction.YY;
            }
            if (dir == "ZZ")
            {
                direc = Direction.ZZ;
            }

            beamLoad.BeamLoad.Direction = direc;

            // 5 projection
            bool       prj    = false;
            GH_Boolean gh_prj = new GH_Boolean();

            if (DA.GetData(5, ref gh_prj))
            {
                GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both);
            }
            beamLoad.BeamLoad.IsProjected = prj;

            // 6 value (1)
            double load1 = 0;

            if (DA.GetData(6, ref load1))
            {
                if (direc == Direction.Z)
                {
                    load1 *= -1000; //convert to kN
                }
                else
                {
                    load1 *= 1000;
                }
            }


            switch (_mode)
            {
            case FoldMode.Point:
                if (_mode == FoldMode.Point)
                {
                    beamLoad.BeamLoad.Type = BeamLoadType.POINT;

                    // 7 pos (1)
                    double pos = 0;
                    if (DA.GetData(7, ref pos))
                    {
                        pos *= -1;
                    }

                    // set position and value
                    beamLoad.BeamLoad.SetValue(0, load1);
                    beamLoad.BeamLoad.SetPosition(0, pos);
                }
                break;

            case FoldMode.Uniform:
                if (_mode == FoldMode.Uniform)
                {
                    beamLoad.BeamLoad.Type = BeamLoadType.UNIFORM;
                    // set value
                    beamLoad.BeamLoad.SetValue(0, load1);
                }
                break;

            case FoldMode.Linear:
                if (_mode == FoldMode.Linear)
                {
                    beamLoad.BeamLoad.Type = BeamLoadType.LINEAR;

                    // 6 value (2)
                    double load2 = 0;
                    if (DA.GetData(7, ref load2))
                    {
                        if (direc == Direction.Z)
                        {
                            load2 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load2 *= 1000;
                        }
                    }

                    // set value
                    beamLoad.BeamLoad.SetValue(0, load1);
                    beamLoad.BeamLoad.SetValue(1, load2);
                }
                break;

            case FoldMode.Patch:
                if (_mode == FoldMode.Patch)
                {
                    beamLoad.BeamLoad.Type = BeamLoadType.PATCH;

                    // 7 pos (1)
                    double pos1 = 0;
                    if (DA.GetData(7, ref pos1))
                    {
                        pos1 *= -1;
                    }

                    // 9 pos (2)
                    double pos2 = 1;
                    if (DA.GetData(9, ref pos2))
                    {
                        pos2 *= -1;
                    }

                    // 8 value (2)
                    double load2 = 0;
                    if (DA.GetData(8, ref load2))
                    {
                        if (direc == Direction.Z)
                        {
                            load2 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load2 *= 1000;
                        }
                    }

                    // set value
                    beamLoad.BeamLoad.SetValue(0, load1);
                    beamLoad.BeamLoad.SetValue(1, load2);
                    beamLoad.BeamLoad.SetPosition(0, pos1);
                    beamLoad.BeamLoad.SetPosition(1, pos2);
                }
                break;

            case FoldMode.Trilinear:
                if (_mode == FoldMode.Trilinear)
                {
                    beamLoad.BeamLoad.Type = BeamLoadType.TRILINEAR;

                    // 7 pos (1)
                    double pos1 = 0;
                    if (DA.GetData(7, ref pos1))
                    {
                        pos1 *= -1;
                    }

                    // 9 pos (2)
                    double pos2 = 1;
                    if (DA.GetData(9, ref pos2))
                    {
                        pos2 *= -1;
                    }

                    // 8 value (2)
                    double load2 = 0;
                    if (DA.GetData(8, ref load2))
                    {
                        if (direc == Direction.Z)
                        {
                            load2 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load2 *= 1000;
                        }
                    }

                    // set value
                    beamLoad.BeamLoad.SetValue(0, load1);
                    beamLoad.BeamLoad.SetValue(1, load2);
                    beamLoad.BeamLoad.SetPosition(0, pos1);
                    beamLoad.BeamLoad.SetPosition(1, pos2);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GsaLoad gsaLoad = new GsaLoad(beamLoad);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Linear Configuration Control
            if (typeof(LinearConfigurationControl).IsAssignableFrom(source.GetType()))
            {
                Value = source as LinearConfigurationControl;
                return(true);
            }

            //Cast from Boolean
            if (typeof(GH_Boolean).IsAssignableFrom(source.GetType()))
            {
                GH_Boolean ghBoolean = source as GH_Boolean;
                Value = new LinearConfigurationControl(ghBoolean.Value);
                return(true);
            }

            //Cast from Action
            if (typeof(Action).IsAssignableFrom(source.GetType()))
            {
                if (source is LinearConfigurationControl action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Action).IsAssignableFrom(source.GetType()))
            {
                GH_Action actionGoo = source as GH_Action;
                if (actionGoo.Value is LinearConfigurationControl action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Instruction
            if (typeof(IInstruction).IsAssignableFrom(source.GetType()))
            {
                if (source is LinearConfigurationControl instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            //Cast from Instruction Goo
            if (typeof(GH_Instruction).IsAssignableFrom(source.GetType()))
            {
                GH_Instruction instructionGoo = source as GH_Instruction;
                if (instructionGoo.Value is LinearConfigurationControl instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaFaceLoad faceLoad = new GsaFaceLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            faceLoad.FaceLoad.Case = lc;

            // 1 element/beam list
            string    elemList = "";
            GH_String gh_el    = new GH_String();

            if (DA.GetData(1, ref gh_el))
            {
                GH_Convert.ToString(gh_el, out elemList, GH_Conversion.Both);
            }
            //var isNumeric = int.TryParse(elemList, out int n);
            //if (isNumeric)
            //    elemList = "PA" + n;

            faceLoad.FaceLoad.Elements = elemList;

            // 2 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(2, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    faceLoad.FaceLoad.Name = name;
                }
            }

            // 3 axis
            int axis = -1;

            faceLoad.FaceLoad.AxisProperty = 0; //Note there is currently a bug/undocumented in GsaAPI that cannot translate an integer into axis type (Global, Local or edformed local)
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(3, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    faceLoad.FaceLoad.AxisProperty = axis;
                }
            }

            // 4 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(4, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper().Trim();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }

            faceLoad.FaceLoad.Direction = direc;

            switch (_mode)
            {
            case FoldMode.Uniform:
                if (_mode == FoldMode.Uniform)
                {
                    faceLoad.FaceLoad.Type = FaceLoadType.CONSTANT;

                    //projection
                    bool       prj    = false;
                    GH_Boolean gh_prj = new GH_Boolean();
                    if (DA.GetData(5, ref gh_prj))
                    {
                        GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both);
                    }
                    faceLoad.FaceLoad.IsProjected = prj;


                    double load1 = 0;
                    if (DA.GetData(6, ref load1))
                    {
                        if (direc == Direction.Z)
                        {
                            load1 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load1 *= 1000;
                        }
                    }

                    // set position and value
                    faceLoad.FaceLoad.SetValue(0, load1);
                }
                break;

            case FoldMode.Variable:
                if (_mode == FoldMode.Variable)
                {
                    faceLoad.FaceLoad.Type = FaceLoadType.GENERAL;

                    //projection
                    bool       prj    = false;
                    GH_Boolean gh_prj = new GH_Boolean();
                    if (DA.GetData(5, ref gh_prj))
                    {
                        GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both);
                    }
                    faceLoad.FaceLoad.IsProjected = prj;

                    double load1 = 0;
                    if (DA.GetData(6, ref load1))
                    {
                        if (direc == Direction.Z)
                        {
                            load1 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load1 *= 1000;
                        }
                    }
                    double load2 = 0;
                    if (DA.GetData(7, ref load2))
                    {
                        if (direc == Direction.Z)
                        {
                            load2 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load2 *= 1000;
                        }
                    }
                    double load3 = 0;
                    if (DA.GetData(8, ref load3))
                    {
                        if (direc == Direction.Z)
                        {
                            load3 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load3 *= 1000;
                        }
                    }
                    double load4 = 0;
                    if (DA.GetData(9, ref load4))
                    {
                        if (direc == Direction.Z)
                        {
                            load4 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load4 *= 1000;
                        }
                    }

                    // set value
                    faceLoad.FaceLoad.SetValue(0, load1);
                    faceLoad.FaceLoad.SetValue(1, load2);
                    faceLoad.FaceLoad.SetValue(2, load3);
                    faceLoad.FaceLoad.SetValue(3, load4);
                }
                break;

            case FoldMode.Point:
                if (_mode == FoldMode.Point)
                {
                    faceLoad.FaceLoad.Type = FaceLoadType.POINT;

                    //projection
                    bool       prj    = false;
                    GH_Boolean gh_prj = new GH_Boolean();
                    if (DA.GetData(5, ref gh_prj))
                    {
                        GH_Convert.ToBoolean(gh_prj, out prj, GH_Conversion.Both);
                    }
                    faceLoad.FaceLoad.IsProjected = prj;

                    double load1 = 0;
                    if (DA.GetData(6, ref load1))
                    {
                        if (direc == Direction.Z)
                        {
                            load1 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load1 *= 1000;
                        }
                    }
                    double r = 0;
                    DA.GetData(7, ref r);

                    double s = 0;
                    DA.GetData(8, ref s);

                    // set position and value
                    faceLoad.FaceLoad.SetValue(0, load1);
                    //faceLoad.Position.X = r; //note Vector2 currently only get in GsaAPI
                    //faceLoad.Position.Y = s;
                }
                break;

            case FoldMode.Edge:
                if (_mode == FoldMode.Edge)
                {
                    //faceLoad.Type = BeamLoadType.EDGE; GsaAPI implementation missing

                    // get data
                    int edge = 1;
                    DA.GetData(5, ref edge);

                    double load1 = 0;
                    if (DA.GetData(6, ref load1))
                    {
                        if (direc == Direction.Z)
                        {
                            load1 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load1 *= 1000;
                        }
                    }

                    double load2 = 0;
                    if (DA.GetData(7, ref load2))
                    {
                        if (direc == Direction.Z)
                        {
                            load2 *= -1000;     //convert to kN
                        }
                        else
                        {
                            load2 *= 1000;
                        }
                    }

                    // set value
                    faceLoad.FaceLoad.SetValue(0, load1);
                    faceLoad.FaceLoad.SetValue(1, load2);
                    //faceLoad.Edge = edge; //note implementation of edge-load is not yet supported in GsaAPI

                    faceLoad = null;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GsaLoad gsaLoad = new GsaLoad(faceLoad);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }
Exemplo n.º 23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            this.Components = new List <object>();
            DA.GetDataList <object>("Components", this.Components);
            GH_Boolean update = new GH_Boolean(true);
            GH_Boolean erase  = new GH_Boolean(false);

            this.Ip      = new GH_String("127.0.0.1");
            this.Port    = new GH_Integer(8002);
            this.Timeout = new GH_Integer(10000);
            DA.GetData <GH_Boolean>("Update", ref update);
            DA.GetData <GH_String>("IP", ref this.Ip);
            DA.GetData <GH_Integer>("Port", ref this.Port);
            DA.GetData <GH_Integer>("TimeOut", ref this.Timeout);
            GH_Boolean send = new GH_Boolean();

            DA.GetData <GH_Boolean>("Send", ref send);
            DA.GetData <GH_Boolean>("Erase", ref erase);
            this.Erase  = erase.Value;
            this.Update = update.Value;
            GH_Number scale = new GH_Number(3.28084);

            DA.GetData <GH_Number>("Scale", ref scale);
            this.Scale = scale.Value;

            if (send.Value)
            {
                this.Icon = Properties.Resources.paper_airplane_red;
                this.DestroyIconCache();
                Grasshopper.Instances.RedrawAll();

                bool   retry        = true;
                string responseData = "";

                try
                {
                    while (retry)
                    {
                        using (TcpClient tcpClient = new TcpClient())
                        {
                            tcpClient.Connect(IPAddress.Parse(Ip.Value), Port.Value);
                            tcpClient.NoDelay        = true;
                            tcpClient.ReceiveTimeout = Timeout.Value;
                            tcpClient.SendTimeout    = Timeout.Value;

                            using (NetworkStream stream = tcpClient.GetStream())
                            {
                                using (StreamWriter writer = new StreamWriter(stream, new UTF8Encoding(false)))
                                {
                                    writer.AutoFlush = true;
                                    using (StreamReader reader = new StreamReader(stream))
                                    {
                                        string line = ComponentsToString(this.Components);
                                        writer.WriteLine(line);

                                        string response = reader.ReadLine();
                                        if (response == line)
                                        {
                                            retry = false;
                                        }
                                        responseData = reader.ReadLine();
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message);
                }

                try
                {
                    if (responseData != "")
                    {
                        revitFamilyCollection = (RevitFamilyCollection)Grevit.Serialization.Utilities.Deserialize(responseData, typeof(RevitFamilyCollection));
                    }
                }
                catch (Exception ex)
                {
                }

                this.Icon = Properties.Resources.paper_airplane_green;
                this.DestroyIconCache();
                Grasshopper.Instances.RedrawAll();
            }

            DA.SetDataList("Categories", revitFamilyCollection.Categories);
        }
Exemplo n.º 24
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var props = new ArchivableDictionary();

            for (int i = 0; i < Params.Input.Count; i++)
            {
                var key = Params.Input[i].NickName;

                object value = null;
                DA.GetData(i, ref value);

                if (value != null)
                {
                    GH_Number nmb = value as GH_Number;
                    if (nmb != null)
                    {
                        props.Set(key, nmb.Value);
                    }

                    if (value is double)
                    {
                        props.Set(key, (double)value);
                    }

                    if (value is int)
                    {
                        props.Set(key, (double)value);
                    }

                    GH_String str = value as GH_String;
                    if (str != null)
                    {
                        props.Set(key, str.Value);
                    }

                    if (value is string)
                    {
                        props.Set(key, (string)value);
                    }

                    GH_Boolean bol = value as GH_Boolean;
                    if (bol != null)
                    {
                        props.Set(key, bol.Value);
                    }

                    GH_ObjectWrapper temp = value as GH_ObjectWrapper;
                    if (temp != null)
                    {
                        ArchivableDictionary dict = ((GH_ObjectWrapper)value).Value as ArchivableDictionary;
                        if (dict != null)
                        {
                            props.Set(key, dict);
                        }
                    }

                    if (!props.ContainsKey(key))
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, key + " could not be set. Strings, numbers, booleans and ArchivableDictionary are the only supported types.");
                    }
                }
            }

            DA.SetData(0, props);
        }
Exemplo n.º 25
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember3d gsaMember3d = new GsaMember3d();

            if (DA.GetData(0, ref gsaMember3d))
            {
                if (gsaMember3d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member3D input is null");
                }
                GsaMember3d mem = gsaMember3d.Duplicate();

                // #### inputs ####

                // 1 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(1, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 2 geometry
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaMember3d tempMem = new GsaMember3d();
                    Brep        brep    = new Brep();
                    Mesh        mesh    = new Mesh();
                    if (GH_Convert.ToBrep(gh_typ.Value, ref brep, GH_Conversion.Both))
                    {
                        tempMem = new GsaMember3d(brep);
                    }
                    else if (GH_Convert.ToMesh(gh_typ.Value, ref mesh, GH_Conversion.Both))
                    {
                        tempMem = new GsaMember3d(mesh);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input to a 3D Member");
                        return;
                    }
                    mem.SolidMesh = tempMem.SolidMesh;
                }

                // 3 prop3d -- to be implemented GsaAPI
                gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(3, ref gh_typ))
                {
                    if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                    {
                        mem.Member.Property = idd;
                    }
                    //GsaProp3d prop3d = new GsaProp3d();
                    //if (gh_typ.Value is GsaProp3dGoo)
                    //    gh_typ.CastTo(ref prop3d);
                    //else
                    //{
                    //    if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                    //        prop3d.ID = idd;
                    //    else
                    //    {
                    //        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 3D Property of reference integer");
                    //        return;
                    //    }
                    //}
                    //mem.Property = prop3d;
                }

                // 4 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(4, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 5 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(5, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 6 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(6, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 7 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(7, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 8 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(8, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 9 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(9, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####

                DA.SetData(0, new GsaMember3dGoo(mem));
                DA.SetData(1, mem.ID);
                DA.SetData(2, mem.SolidMesh);

                //DA.SetData(3, mem.Property);

                DA.SetData(4, mem.Member.MeshSize);
                //DA.SetData(5, mem.Member.MeshWithOthers);

                DA.SetData(6, mem.Member.Name);
                DA.SetData(7, mem.Member.Group);
                DA.SetData(8, mem.Member.Colour);
                DA.SetData(9, mem.Member.IsDummy);
            }
        }
        /// <summary>
        /// Determines object type and calls the appropriate conversion call.
        /// </summary>
        /// <param name="o">Object to convert.</param>
        /// <param name="getEncoded">If set to true, will return a base64 encoded value of more complex objects (ie, breps).</param>
        /// <returns></returns>
        private static SpeckleObject fromGhRhObject(object o, bool getEncoded = false, bool getAbstract = true)
        {
            GH_Interval int1d = o as GH_Interval;

            if (int1d != null)
            {
                return(GhRhConveter.fromInterval(int1d.Value));
            }
            if (o is Interval)
            {
                return(GhRhConveter.fromInterval((Interval)o));
            }

            GH_Interval2D int2d = o as GH_Interval2D;

            if (int2d != null)
            {
                return(GhRhConveter.fromInterval2d(int2d.Value));
            }
            if (o is UVInterval)
            {
                return(GhRhConveter.fromInterval2d((UVInterval)o));
            }

            // basic stuff
            GH_Number num = o as GH_Number;

            if (num != null)
            {
                return(SpeckleConverter.fromNumber(num.Value));
            }
            if (o is double || o is int)
            {
                return(SpeckleConverter.fromNumber((double)o));
            }

            GH_Boolean bul = o as GH_Boolean;

            if (bul != null)
            {
                return(SpeckleConverter.fromBoolean(bul.Value));
            }
            if (o is Boolean)
            {
                return(GhRhConveter.fromBoolean((bool)o));
            }

            GH_String str = o as GH_String;

            if (str != null)
            {
                return(SpeckleConverter.fromString(str.Value));
            }
            if (o is string)
            {
                return(SpeckleConverter.fromString((string)o));
            }

            // simple geometry
            GH_Point point = o as GH_Point;

            if (point != null)
            {
                return(GhRhConveter.fromPoint(point.Value));
            }
            if (o is Point3d)
            {
                return(GhRhConveter.fromPoint((Point3d)o));
            }
            // added because when we assign user data to points they get converted to points.
            // the above comment does makes sense. check the sdk.
            if (o is Rhino.Geometry.Point)
            {
                return(GhRhConveter.fromPoint(((Rhino.Geometry.Point)o).Location));
            }

            GH_Vector vector = o as GH_Vector;

            if (vector != null)
            {
                return(GhRhConveter.fromVector(vector.Value));
            }
            if (o is Vector3d)
            {
                return(GhRhConveter.fromVector((Vector3d)o));
            }

            GH_Plane plane = o as GH_Plane;

            if (plane != null)
            {
                return(GhRhConveter.fromPlane(plane.Value));
            }
            if (o is Plane)
            {
                return(GhRhConveter.fromPlane((Plane)o));
            }

            GH_Line line = o as GH_Line;

            if (line != null)
            {
                return(GhRhConveter.fromLine(line.Value));
            }
            if (o is Line)
            {
                return(GhRhConveter.fromLine((Line)o));
            }

            GH_Arc arc = o as GH_Arc;

            if (arc != null)
            {
                return(GhRhConveter.fromArc(arc.Value));
            }
            if (o is Arc)
            {
                return(GhRhConveter.fromArc((Arc)o));
            }

            GH_Circle circle = o as GH_Circle;

            if (circle != null)
            {
                return(GhRhConveter.fromCircle(circle.Value));
            }
            if (o is Circle)
            {
                return(GhRhConveter.fromCircle((Circle)o));
            }

            GH_Rectangle rectangle = o as GH_Rectangle;

            if (rectangle != null)
            {
                return(GhRhConveter.fromRectangle(rectangle.Value));
            }
            if (o is Rectangle3d)
            {
                return(GhRhConveter.fromRectangle((Rectangle3d)o));
            }

            GH_Box box = o as GH_Box;

            if (box != null)
            {
                return(GhRhConveter.fromBox(box.Value));
            }
            if (o is Box)
            {
                return(GhRhConveter.fromBox((Box)o));
            }

            // getting complex
            GH_Curve curve = o as GH_Curve;

            if (curve != null)
            {
                Polyline poly;
                if (curve.Value.TryGetPolyline(out poly))
                {
                    return(GhRhConveter.fromPolyline(poly));
                }
                return(GhRhConveter.fromCurve(curve.Value, getEncoded, getAbstract));
            }

            if (o is Polyline)
            {
                return(GhRhConveter.fromPolyline((Polyline)o));
            }
            if (o is Curve)
            {
                return(GhRhConveter.fromCurve((Curve)o, getEncoded, getAbstract));
            }

            GH_Surface surface = o as GH_Surface;

            if (surface != null)
            {
                return(GhRhConveter.fromBrep(surface.Value, getEncoded, getAbstract));
            }

            GH_Brep brep = o as GH_Brep;

            if (brep != null)
            {
                return(GhRhConveter.fromBrep(brep.Value, getEncoded, getAbstract));
            }

            if (o is Brep)
            {
                return(GhRhConveter.fromBrep((Brep)o, getEncoded, getAbstract));
            }

            GH_Mesh mesh = o as GH_Mesh;

            if (mesh != null)
            {
                return(GhRhConveter.fromMesh(mesh.Value));
            }
            if (o is Mesh)
            {
                return(GhRhConveter.fromMesh((Mesh)o));
            }

            return(new SpeckleObject()
            {
                hash = "404", value = "Type not supported", type = "404"
            });
        }
Exemplo n.º 27
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare variables
            List <string> keys   = new List <string>();
            List <object> values = new List <object>();

            // Reference the inputs
            if (!DA.GetDataList(0, keys))
            {
                return;
            }
            if (!DA.GetDataList(1, values))
            {
                return;
            }

            // Make sure same number of keys and values
            if (keys.Count != values.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "There must must be the same number of keys and values per object.");
            }

            // Create a dictionary
            IDictionary <string, object> properties = new ExpandoObject();

            for (int i = 0; i < keys.Count; i++)
            {
                if (values[i] is GH_Boolean)
                {
                    GH_Boolean n     = (GH_Boolean)values[i];
                    bool       value = n.Value;
                    properties[keys[i]] = value;
                }
                else if (values[i] is GH_Number)
                {
                    GH_Number n     = (GH_Number)values[i];
                    double    value = n.Value;
                    properties[keys[i]] = value;
                }
                else if (values[i] is GH_Integer)
                {
                    GH_Integer n     = (GH_Integer)values[i];
                    int        value = n.Value;
                    properties[keys[i]] = value;
                }
                else if (values[i] is GH_String)
                {
                    GH_String n     = (GH_String)values[i];
                    string    value = n.Value;
                    properties[keys[i]] = value;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Item of type [{values[i].GetType()}] is not supported. Only support GH_Bool, GH_Number, GH_Integer, and GH_String.");
                }
            }

            // Wrap in a custom class
            UserData userData = new UserData(properties);

            // Set output references
            DA.SetData(0, userData);
        }
Exemplo n.º 28
0
        public void SetInputs(List <DataTree <ResthopperObject> > values)
        {
            foreach (var tree in values)
            {
                if (!_input.TryGetValue(tree.ParamName, out var inputGroup))
                {
                    continue;
                }

                if (inputGroup.AlreadySet(tree))
                {
                    LogDebug("Skipping input tree... same input");
                    continue;
                }

                inputGroup.CacheTree(tree);

                IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter;
                if (contextualParameter != null)
                {
                    switch (ParamTypeName(inputGroup.Param))
                    {
                    case "Number":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            double[] doubles = new double[entree.Value.Count];
                            for (int i = 0; i < doubles.Length; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                doubles[i] = JsonConvert.DeserializeObject <double>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(doubles);
                            break;
                        }
                    }
                    break;

                    case "Integer":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            int[] integers = new int[entree.Value.Count];
                            for (int i = 0; i < integers.Length; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                integers[i] = JsonConvert.DeserializeObject <int>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(integers);
                            break;
                        }
                    }
                    break;

                    case "Point":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            Point3d[] points = new Point3d[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                points[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(points);
                            break;
                        }
                    }
                    break;

                    case "Line":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            Line[] lines = new Line[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                lines[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(lines);
                            break;
                        }
                    }
                    break;

                    case "Text":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            string[] strings = new string[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                strings[i] = restobj.Data.Trim(new char[] { '"' });
                            }
                            contextualParameter.AssignContextualData(strings);
                            break;
                        }
                    }
                    break;

                    case "Geometry":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            GeometryBase[] geometries = new GeometryBase[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase;
                            }
                            contextualParameter.AssignContextualData(geometries);
                            break;
                        }
                    }
                    break;
                    }
                    continue;
                }

                inputGroup.Param.VolatileData.Clear();
                inputGroup.Param.ExpireSolution(false); // mark param as expired but don't recompute just yet!

                if (inputGroup.Param is Param_Point)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj = entree.Value[i];
                            Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            GH_Point data = new GH_Point(rPt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Vector)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject        restobj  = entree.Value[i];
                            Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                            GH_Vector data = new GH_Vector(rhVector);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Integer)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                            GH_Integer data          = new GH_Integer(rhinoInt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Number)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_String)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = restobj.Data;
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Line)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            GH_Line             data    = new GH_Line(rhLine);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Curve)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            GH_Curve         ghCurve;
                            try
                            {
                                Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                ghCurve = new GH_Curve(c);
                            }
                            catch
                            {
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                var c    = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict);
                                ghCurve = new GH_Curve(c);
                            }
                            inputGroup.Param.AddVolatileData(path, i, ghCurve);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Circle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject      restobj  = entree.Value[i];
                            Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                            GH_Circle             data     = new GH_Circle(rhCircle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Plane)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject     restobj = entree.Value[i];
                            Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                            GH_Plane             data    = new GH_Plane(rhPlane);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Rectangle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject           restobj     = entree.Value[i];
                            Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                            GH_Rectangle data = new GH_Rectangle(rhRectangle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Box)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject   restobj = entree.Value[i];
                            Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                            GH_Box             data    = new GH_Box(rhBox);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Surface)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj   = entree.Value[i];
                            Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                            GH_Surface             data      = new GH_Surface(rhSurface);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Brep)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                            GH_Brep             data    = new GH_Brep(rhBrep);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Mesh)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                            GH_Mesh             data    = new GH_Mesh(rhMesh);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_NumberSlider)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                            GH_Boolean       data    = new GH_Boolean(boolean);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_Panel)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }
            }
        }
Exemplo n.º 29
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // inputs
            var points          = new List <GH_Point>();
            var vectors         = new List <GH_Vector>();
            var startPoints     = new List <GH_Point>();
            var lifeTime        = new GH_Integer();
            var settings        = new GH_ObjectWrapper();
            var reset           = new GH_Boolean();
            var dynamicsWrapped = new List <GH_ObjectWrapper>();
            var dynamics        = new List <IDynamic>();

            if (DA.GetDataList(0, points) && points == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled.");
                return;
            }

            if (DA.GetDataList(1, vectors) && vectors == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled.");
                return;
            }

            if (vectors.Count != points.Count && vectors.Count != 0)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length (or empty). Operation canceled.");
                return;
            }

            if (DA.GetDataList(2, startPoints) && startPoints == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling points. Operation canceled.");
                return;
            }

            if (DA.GetData(3, ref lifeTime) && lifeTime == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid lifetime input. Operation canceled.");
                return;
            }

            if (DA.GetDataList(4, dynamicsWrapped) && dynamicsWrapped == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid dynamics list. Operation canceled.");
                return;
            }
            dynamics = (from d in dynamicsWrapped select d.Value as IDynamic).ToList();
            Algos.SortDynamicsByPriority(dynamics);

            // if vectors list is empty we'll populate it with empty vectors to match each point
            if (vectors.Count == 0)
            {
                for (int i = 0; i < points.Count; i++)
                {
                    vectors.Add(new GH_Vector());
                }
            }

            // spm parameters component is optional, we use its defaults if it is not available
            var spm_settings = new DynamicSettings();

            if (DA.GetData(5, ref settings))
            {
                // if getdata succeeded but the settings var is null we had bad input
                if (settings == null)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid settings input. Operation canceled.");
                    return;
                }

                // otherwise cast from gh_objectwrapper and continue
                spm_settings = (DynamicSettings)settings.Value;
            }

            if (DA.GetData(6, ref reset) && reset == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid reset input. Operation canceled.");
                return;
            }

            if (emitter == null || reset.Value)
            {
                emitter = new Emitter(startPoints, lifeTime.Value, spm_settings);
                DA.SetDataList(0, startPoints);

                var zv = new List <GH_Vector>(startPoints.Count);
                for (int i = 0; i < startPoints.Count; i++)
                {
                    zv.Add(new GH_Vector());
                }

                Algos.ClearDynamics(dynamics);

                DA.SetDataList(1, zv);
                return;
            }

            // emitter updates dynamics
            emitter.Update(dynamics, points, vectors, spm_settings);

            DA.SetDataList(0, emitter.Points);
            DA.SetDataList(1, emitter.Vectors);
        }
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Auto Axis Config
            if (typeof(AutoAxisConfig).IsAssignableFrom(source.GetType()))
            {
                Value = source as AutoAxisConfig;
                return(true);
            }

            //Cast from Boolean
            if (typeof(GH_Boolean).IsAssignableFrom(source.GetType()))
            {
                GH_Boolean ghBoolean = source as GH_Boolean;
                Value = new AutoAxisConfig(ghBoolean.Value);
                return(true);
            }

            //Cast from Action
            if (typeof(RobotComponents.Actions.Action).IsAssignableFrom(source.GetType()))
            {
                if (source is AutoAxisConfig action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Action).IsAssignableFrom(source.GetType()))
            {
                GH_Action actionGoo = source as GH_Action;
                if (actionGoo.Value is AutoAxisConfig action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Instruction
            if (typeof(IInstruction).IsAssignableFrom(source.GetType()))
            {
                if (source is AutoAxisConfig instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }

            //Cast from Instruction Goo
            if (typeof(GH_Instruction).IsAssignableFrom(source.GetType()))
            {
                GH_Instruction instructionGoo = source as GH_Instruction;
                if (instructionGoo.Value is AutoAxisConfig instruction)
                {
                    Value = instruction;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 31
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Surface surface = new GH_Surface();
            GH_String level = new GH_String();
            GH_String family = new GH_String("");
            GH_String type = new GH_String("");

            GH_Boolean structural = new GH_Boolean(false); 
            GH_Number slope = new GH_Number(0.0);
            List<Parameter> parameters = new List<Parameter>();
            if (!DA.GetDataList<Parameter>("Parameters", parameters)) parameters = new List<Parameter>();
            DA.GetData<GH_Surface>("Surface", ref surface);

            GH_Point slopeTopPoint = new GH_Point(surface.Value.Edges[0].PointAtStart);
            GH_Point slopeBottomPoint = new GH_Point(surface.Value.Edges[0].PointAtEnd);

            //DA.GetData<GH_String>("Family", ref family);
            //DA.GetData<GH_String>("Type", ref type);
            DA.GetData<GH_String>("Levelbottom", ref level);
            DA.GetData<GH_Boolean>("Structural", ref structural);
            DA.GetData<GH_Point>("SlopeTopPoint", ref slopeTopPoint);
            DA.GetData<GH_Point>("SlopeBottomPoint", ref slopeBottomPoint);
            DA.GetData<GH_Number>("Slope", ref slope);

            

            Slab slab = new Slab();
            slab.FamilyOrStyle = family.Value;
            slab.TypeOrLayer = type.Value;
            slab.levelbottom = level.Value;
            slab.structural = structural.Value;
            slab.surface = new Profile();
            slab.surface.profile = new List<Loop>();
            
            Loop loop = new Loop();
            loop.outline = new List<Component>();

            foreach (Rhino.Geometry.BrepEdge be in surface.Value.Edges)
            {
                loop.outline.Add(be.ToNurbsCurve().ToGrevitCurve());
            }

            slab.surface.profile.Add(loop);

            slab.parameters = parameters;
            slab.top = slopeTopPoint.ToGrevitPoint();
            slab.bottom = slopeBottomPoint.ToGrevitPoint();
            slab.slope = slope.Value;
            slab.GID = this.InstanceGuid.ToString();



            DA.SetData("GrevitComponent", slab);
        }
Exemplo n.º 32
0
        //////////////////////////////  CastTo  ////////////////////////////////////

        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(string)))
            {
                object s = Value.ToString();
                target = (Q)s;
                return(true);
            }
            if (Value.IntegerQ())
            {
                if (typeof(Q).IsAssignableFrom(typeof(Int32)))
                {
                    object i = (int)Value;
                    target = (Q)i;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(Int64)))
                {
                    object i = Value.AsInt64();
                    target = (Q)i;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Integer)))
                {
                    object ptr = new GH_Integer((int)Value.AsInt64());
                    target = (Q)ptr;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(Double)))
                {
                    object d = Value.AsDouble();
                    target = (Q)d;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Number)))
                {
                    object d = new GH_Number(Value.AsDouble());
                    target = (Q)d;
                    return(true);
                }
            }
            if (Value.NumberQ())
            {
                if (typeof(Q).IsAssignableFrom(typeof(Double)))
                {
                    object d = Value.AsDouble();
                    target = (Q)d;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Number)))
                {
                    object d = new GH_Number(Value.AsDouble());
                    target = (Q)d;
                    return(true);
                }
            }
            if (Value.StringQ() || Value.SymbolQ())
            {
                if (typeof(Q).IsAssignableFrom(typeof(string)))
                {
                    object s = Value.ToString();
                    target = (Q)s;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(GH_String)))
                {
                    object s = new GH_String(Value.ToString());
                    target = (Q)s;
                    return(true);
                }
            }
            if (Value.TrueQ() || Value.SymbolQ() && Value.ToString() == "False")
            {
                if (typeof(Q).IsAssignableFrom(typeof(bool)))
                {
                    object s = Value.TrueQ() ? true : false;
                    target = (Q)s;
                    return(true);
                }
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Boolean)))
                {
                    object s = new GH_Boolean(Value.TrueQ() ? true : false);
                    target = (Q)s;
                    return(true);
                }
            }
            // Try to convert to an array.
            // TODO. This is not yet implemented. Any why am Idoing Array? Shouldn't this be List or GH_Structure?
            object dataArray = null;

            try
            {
                if (Value.Head.Equals(SYM_LIST))
                {
                    int[] dims = Value.Dimensions;
                    if (dims.Length == 1)
                    {
                        try
                        {
                            dataArray = Value.AsArray(ExpressionType.Integer, 1);
                        }
                        catch (Exception)
                        {
                            dataArray = Value.AsArray(ExpressionType.Real, 1);
                        }
                        if (dataArray != null)
                        {
                            target = (Q)dataArray;
                            return(true);
                        }
                    }
                    else if (dims.Length == 2)
                    {
                        // TODO
                    }
                }
            }
            catch (Exception)
            {
            }
            // TODO: More types, like ComplexNumber.

            return(false);
        }
Exemplo n.º 33
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // inputs
            var points      = new List <GH_Point>();
            var vectors     = new List <GH_Vector>();
            var startPoints = new List <GH_Point>();
            var reset       = new GH_Boolean();

            var settings = new GH_ObjectWrapper();

            if (DA.GetDataList(0, points) && points == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid points list. Operation canceled.");
                return;
            }

            if (DA.GetDataList(1, vectors) && vectors == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid vector list. Operation canceled.");
                return;
            }

            if (vectors.Count != points.Count)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Vector list size mismatch with points list, they must be equal in length. Operation canceled.");
                return;
            }

            if (DA.GetDataList(2, startPoints) && startPoints == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid travelling points. Operation canceled.");
                return;
            }

            // spm parameters component is optional, we use its defaults if it is not available
            SPM_Parameters spm_settings = new SPM_Parameters();

            if (DA.GetData(3, ref settings))
            {
                // if getdata succeeded but the settings var is null we had bad input
                if (settings == null)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid settings input. Operation canceled.");
                    return;
                }

                // otherwise cast from gh_objectwrapper and continue
                spm_settings = (SPM_Parameters)settings.Value;
            }

            if (DA.GetData(4, ref reset) && reset == null)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid reset input. Operation canceled.");
                return;
            }

            if (startBasis == null || reset.Value)
            {
                var count = startPoints.Count;

                startBasis = new Basis[count];
                lastVecs   = new GH_Vector[count];

                xy = new double[count];
                yz = new double[count];
                xz = new double[count];

                for (int i = 0; i < count; i++)
                {
                    startBasis[i] = new Basis(startPoints[i]);
                    lastVecs[i]   = new GH_Vector();
                    xy[i]         = 0;
                    yz[i]         = 0;
                    xz[i]         = 0;
                }
            }

            if (moving == null || reset.Value)
            {
                moving = startPoints;
                return;
            }

            int steps = spm_settings.steps;

            if (steps == 0)
            {
                steps = 1;
            }

            var bases = new List <Basis>();

            for (int i = 0; i < points.Count; i++)
            {
                bases.Add(new Basis(points[i], vectors[i]));
            }

            // find each next point based on an averaging formula and iterate

            for (int i = 0; i < startPoints.Count; i++)
            {
                for (int j = 0; j < steps; j++)
                {
                    bool add = false;

                    var outBasis = new Basis();

                    bool working = Algos.SampleForNextPoint(bases, moving[i].Value, startBasis[i], lastVecs[i], spm_settings, out outBasis, out add);

                    if (spm_settings.stop && spm_settings.windAngle != 0.0d)
                    {
                        if (!lastVecs[i].Value.IsZero)
                        {
                            double cxy = xy[i];
                            double cyz = yz[i];
                            double cxz = xz[i];

                            if (Algos.IsWoundPast(outBasis.Vector.Value, lastVecs[i].Value, spm_settings.windAngle, ref cxy, ref cyz, ref cxz))
                            {
                                break;
                            }

                            xy[i] = cxy;
                            yz[i] = cyz;
                            xz[i] = cxz;
                        }
                    }

                    lastVecs[i] = outBasis.Vector;

                    if (working && startBasis[i].Vector.Value.IsZero)
                    {
                        startBasis[i].Vector.Value = moving[i].Value - startBasis[i].Point.Value;
                    }

                    if (add)
                    {
                        moving[i] = outBasis.Point;
                    }

                    if (!working)
                    {
                        moving[i] = startPoints[i];
                    }
                }
            }

            DA.SetDataList(0, moving);
        }
        public void SetInputs(List <DataTree <ResthopperObject> > values)
        {
            foreach (var tree in values)
            {
                if (!_input.TryGetValue(tree.ParamName, out var inputGroup))
                {
                    continue;
                }

                if (inputGroup.AlreadySet(tree))
                {
                    Console.WriteLine("Skipping input tree... same input");
                    continue;
                }

                inputGroup.CacheTree(tree);
                inputGroup.Param.VolatileData.Clear();
                inputGroup.Param.ExpireSolution(true);

                if (inputGroup.Param is Param_Point)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj = entree.Value[i];
                            Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            GH_Point data = new GH_Point(rPt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Vector)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject        restobj  = entree.Value[i];
                            Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                            GH_Vector data = new GH_Vector(rhVector);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Integer)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                            GH_Integer data          = new GH_Integer(rhinoInt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Number)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_String)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = restobj.Data;
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Line)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            GH_Line             data    = new GH_Line(rhLine);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Curve)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            GH_Curve         ghCurve;
                            try
                            {
                                Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                ghCurve = new GH_Curve(c);
                            }
                            catch
                            {
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                var c    = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict);
                                ghCurve = new GH_Curve(c);
                            }
                            inputGroup.Param.AddVolatileData(path, i, ghCurve);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Circle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject      restobj  = entree.Value[i];
                            Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                            GH_Circle             data     = new GH_Circle(rhCircle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Plane)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject     restobj = entree.Value[i];
                            Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                            GH_Plane             data    = new GH_Plane(rhPlane);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Rectangle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject           restobj     = entree.Value[i];
                            Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                            GH_Rectangle data = new GH_Rectangle(rhRectangle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Box)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject   restobj = entree.Value[i];
                            Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                            GH_Box             data    = new GH_Box(rhBox);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Surface)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj   = entree.Value[i];
                            Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                            GH_Surface             data      = new GH_Surface(rhSurface);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Brep)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                            GH_Brep             data    = new GH_Brep(rhBrep);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Mesh)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                            GH_Mesh             data    = new GH_Mesh(rhMesh);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_NumberSlider)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                            GH_Boolean       data    = new GH_Boolean(boolean);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_Panel)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }
            }
        }
Exemplo n.º 35
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Boolean assoc = new GH_Boolean(false);
            GH_String name = new GH_String();
            GH_String layer = new GH_String("");
            GH_String style = new GH_String("");
            GH_String number = new GH_String();
            List<Parameter> param = new List<Parameter>();
            List<GH_Point> points = new List<GH_Point>();
            if (!DA.GetDataList<Parameter>("Parameters", param)) param = new List<Parameter>();

            if (!DA.GetDataList<GH_Point>("Points", points)) points = new List<GH_Point>();

            DA.GetData<GH_String>("Name", ref name);
            DA.GetData<GH_Boolean>("Assoc", ref assoc);
            DA.GetData<GH_String>("Number", ref number);
            DA.GetData<GH_String>("Style", ref style);
            DA.GetData<GH_String>("Layer", ref layer);

            Room ac = new Room(name.Value,number.Value,"",param);

            IEnumerable<GH_Point> nodups = points.Distinct(new GH_PointComparer());
            ac.points = new List<Grevit.Types.Point>();
            foreach (var p in nodups)
            {
                ac.points.Add(p.ToGrevitPoint());
            }

            ac.associative = assoc.Value;
            ac.FamilyOrStyle = style.Value;
            ac.TypeOrLayer = layer.Value;
            ac.GID = this.InstanceGuid.ToString();

            DA.SetData("GrevitComponent", ac);
        }
Exemplo n.º 36
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Surface surface = new GH_Surface();
            GH_String lvlbtm = new GH_String("");
            GH_String style = new GH_String("");
            GH_String layer = new GH_String("");
            GH_Number taperAng = new GH_Number(0);
            GH_Number height = new GH_Number();
            GH_Point stop = new GH_Point();
            GH_Point sbtm = new GH_Point();
            GH_Boolean structural = new GH_Boolean(true);

            List<Parameter> param = new List<Parameter>();
            if (!DA.GetDataList<Parameter>("Parameters", param)) param = new List<Parameter>();
            DA.GetData<GH_Surface>("Surface", ref surface);

            DA.GetData<GH_String>("Layer", ref layer);
            //DA.GetData<GH_String>("Style", ref style);
            DA.GetData<GH_Number>("taperAngle", ref taperAng);
            DA.GetData<GH_Number>("height", ref height);

            Slab s = new Slab();
            s.FamilyOrStyle = style.Value;
            s.TypeOrLayer = layer.Value;
            s.levelbottom = lvlbtm.Value;
            s.structural = structural.Value;
            s.surface = new Surface();
            s.surface.outline = new List<Component>();

            foreach (Rhino.Geometry.BrepEdge be in surface.Value.Edges)
            {
                s.surface.outline.Add(be.ToNurbsCurve().ToGrevitCurve());
            }

            s.height = height.Value;
            s.parameters = param;
            //s.top = ComponentUtilities.GHPoint2Point(stop);
            //s.bottom = ComponentUtilities.GHPoint2Point(sbtm);
            s.slope = taperAng.Value;
            s.GID = this.InstanceGuid.ToString();

            //SetPreview(s.GID, surface.Value);
            DA.SetData("GrevitComponent", s);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridLineLoad gridlineload = new GsaGridLineLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            gridlineload.GridLineLoad.Case = lc;

            // Do plane input first as to see if we need to project polyline onto grid plane
            // 2 Plane
            Plane pln      = Plane.WorldXY;
            bool  planeSet = false;
            GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface();
            GH_ObjectWrapper    gh_typ    = new GH_ObjectWrapper();

            if (DA.GetData(2, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    grdplnsrf = temppln.Duplicate();
                    pln       = grdplnsrf.Plane;
                    planeSet  = true;
                }
                else if (gh_typ.Value is Plane)
                {
                    gh_typ.CastTo(ref pln);
                    grdplnsrf = new GsaGridPlaneSurface(pln);
                    planeSet  = true;
                }
                else
                {
                    int id = 0;
                    if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                    {
                        gridlineload.GridLineLoad.GridSurface = id;
                        gridlineload.GridPlaneSurface         = null;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " +
                                          System.Environment.NewLine + "If no input here then the line's best-fit plane will be used");
                        return;
                    }
                }
            }

            // we wait setting the gridplanesurface until we have run the polyline input

            // 1 Polyline
            Polyline ln     = new Polyline();
            GH_Curve gh_crv = new GH_Curve();

            if (DA.GetData(1, ref gh_crv))
            {
                Curve crv = null;
                GH_Convert.ToCurve(gh_crv, ref crv, GH_Conversion.Both);

                //convert to polyline
                if (crv.TryGetPolyline(out ln))
                {
                    // get control points
                    List <Point3d> ctrl_pts = ln.ToList();

                    // plane
                    if (!planeSet)
                    {
                        // create best-fit plane from pts
                        pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts);

                        // create grid plane surface from best fit plane
                        grdplnsrf = new GsaGridPlaneSurface(pln, true);
                    }
                    else
                    {
                        // project original curve onto grid plane
                        crv = Curve.ProjectToPlane(crv, pln);

                        // convert to polyline again
                        crv.TryGetPolyline(out ln);

                        //get control points again
                        ctrl_pts = ln.ToList();
                    }

                    // string to write polyline description to
                    string desc = "";

                    // loop through all points
                    for (int i = 0; i < ctrl_pts.Count; i++)
                    {
                        if (i > 0)
                        {
                            desc += " ";
                        }

                        // get control points in local plane coordinates
                        Point3d temppt = new Point3d();
                        pln.RemapToPlaneSpace(ctrl_pts[i], out temppt);

                        // write point to string
                        // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m)
                        desc += "(" + temppt.X + "," + temppt.Y + ")";
                    }
                    // add units to the end
                    desc += "(" + Units.LengthLarge + ")";

                    // set polyline in grid line load
                    gridlineload.GridLineLoad.Type = GridLineLoad.PolyLineType.EXPLICIT_POLYLINE;
                    gridlineload.GridLineLoad.PolyLineDefinition = desc;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Curve to Polyline");
                }
            }

            // now we can set the gridplanesurface:
            if (gridlineload.GridPlaneSurface != null)
            {
                if (gridlineload.GridPlaneSurface.GridSurfaceID == 0)
                {
                    gridlineload.GridPlaneSurface = grdplnsrf;
                }
            }

            // 3 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(3, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }

            gridlineload.GridLineLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridlineload.GridLineLoad.AxisProperty = 0;
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(4, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    gridlineload.GridLineLoad.AxisProperty = axis;
                }
            }

            // 5 Projected
            bool       proj    = false;
            GH_Boolean gh_proj = new GH_Boolean();

            if (DA.GetData(5, ref gh_proj))
            {
                if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both))
                {
                    gridlineload.GridLineLoad.IsProjected = proj;
                }
            }

            // 6 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(6, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    gridlineload.GridLineLoad.Name = name;
                }
            }

            // 7 load value
            double load1 = 0;

            if (DA.GetData(7, ref load1))
            {
                load1 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtStart = load1;

            // 8 load value
            double load2 = load1;

            if (DA.GetData(8, ref load2))
            {
                load2 *= -1000; //convert to kN
            }
            gridlineload.GridLineLoad.ValueAtEnd = load2;

            // convert to goo
            GsaLoad gsaLoad = new GsaLoad(gridlineload);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }