Exemplo n.º 1
0
        //--------------------------------------------- FROM RHINO TYPES

        public static GH_Curve CastFromPLine(Polyline crv)
        {
            GH_Curve outcv = new GH_Curve();

            outcv.CastFrom(crv);
            return(outcv);
        }
Exemplo n.º 2
0
        public static Curve CastToCurve(GH_Curve c)
        {
            Curve crv;

            c.CastTo <Curve>(out crv);
            return(crv);
        }
Exemplo n.º 3
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            GH_Colour CurrentCrvColor;

            base.DrawViewportMeshes(args);
            int Thickness = CrvThickness.Value < 0 ? Math.Abs(CrvThickness.Value) : CrvThickness.Value == 0 ? 2 : CrvThickness.Value;

            if (this.Hidden || this.Locked)
            {
                return;
            }

            if (this.Attributes.Selected)
            {
                CurrentCrvColor = new GH_Colour(Color.Green);
            }
            else
            {
                CurrentCrvColor = CrvColor;
            }

            for (int Index = 0; Index < CrvList.Count; Index++)
            {
                GH_Curve Crv = CrvList[Index];
                args.Display.DrawCurve(Crv.Value, CurrentCrvColor.Value, Thickness);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor from a Grasshopper curve
 /// </summary>
 /// <param name="a">Grasshopper curve</param>
 public RREdge(GH_Curve a)
 {
     this.or = false;
     this.sn = new RRNode(0, a.Value.PointAtStart);
     this.en = new RRNode(0, a.Value.PointAtEnd);
     this.cs = null;
 }
Exemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve         baseline = new GH_Curve();
            GH_String        layer    = new GH_String("");
            GH_Number        height   = new GH_Number();
            GH_String        style    = new GH_String("");
            List <Parameter> param    = new List <Parameter>();

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

            //DA.GetData<GH_String>("Family", ref family);
            DA.GetData <GH_String>("Layer", ref layer);
            DA.GetData <GH_String>("Style", ref style);
            DA.GetData <GH_Number>("Height", ref height);
            DA.GetData <GH_Curve>("Baseline", ref baseline);


            Wall w = new Wall(style.Value, layer.Value, param, baseline.ToGrevitCurve(), "", height.Value, true, false);

            SetGID(w);
            Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(baseline.Value, new Rhino.Geometry.Vector3d(0, 0, height.Value));
            SetPreview(w.GID, srf.ToBrep());
            DA.SetData("GrevitComponent", w);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts a polyline into a GH_Curve
        /// </summary>
        /// <param name="pline">The polyline to convert</param>
        /// <returns>The GH_Curve</returns>
        public static GH_Curve ConvertToGHCurve(Polyline pline)
        {
            GH_Curve ghl = new GH_Curve();
            bool     c   = GH_Convert.ToGHCurve(pline, GH_Conversion.Both, ref ghl);

            return(ghl);
        }
Exemplo n.º 7
0
        internal static IEnumerable <IGH_Goo> PromptEdge(string prompt)
        {
            IGH_Goo goo = null;

            try
            {
                var selectEdgeResult = theUI.SelectionManager.SelectTaggedObject(prompt, prompt, Selection.SelectionScope.WorkPart, Selection.SelectionAction.AllAndDisableSpecific, false, false, new Selection.MaskTriple[] { MaskTripleEx.Edge }, out var reference, out _);

                if (selectEdgeResult == Selection.Response.Ok)
                {
                    var edge = reference as Edge;

                    var extractedCurve = workPart.Features.CreateExtractGeometry(edge);

                    var nxCurve = extractedCurve.GetEntities()[0] as NXOpen.Curve;

                    nxCurve.RemoveParameters();

                    var curve = nxCurve.ToRhino();

                    goo = new GH_Curve(curve);
                }
            }
            catch (Exception) { }

            yield return(goo);
        }
Exemplo n.º 8
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 <IGH_GeometricGoo> geometry = new List <IGH_GeometricGoo>();
            Curve curve = null;

            if (!DA.GetDataList(0, geometry) || !DA.GetData(1, ref curve))
            {
                return;
            }
            ////////////////将于指定曲线线有关系的物件选出(Brep,Curve,Mesh)strict 选出完全重合,some 局部重合 ,all 相关联所有
            List <IGH_GeometricGoo> collect = new List <IGH_GeometricGoo>();
            List <int> indexes = new List <int>();

            for (int i = 0; i < geometry.Count; i++)
            {
                IGH_GeometricGoo obj = geometry[i];
                if (obj is GH_Curve)
                {
                    GH_Curve ghcurve = (GH_Curve)obj;
                    if (CurveAndCurve(ghcurve.Value, curve, strict, some, all))
                    {
                        indexes.Add(i);
                        collect.Add(obj);
                    }
                }
                else if (obj is GH_Brep)
                {
                    GH_Brep ghbrep = (GH_Brep)obj;
                    if (CurveAndBrep(ghbrep.Value, curve, strict, some, all))
                    {
                        indexes.Add(i);
                        collect.Add(obj);
                    }
                }
                else if (obj is GH_Surface)
                {
                    GH_Surface ghsurface = (GH_Surface)obj;
                    if (CurveAndBrep(ghsurface.Value, curve, strict, some, all))
                    {
                        indexes.Add(i);
                        collect.Add(obj);
                    }
                }
                else if (obj is GH_Mesh)
                {
                    GH_Mesh ghmesh = (GH_Mesh)obj;
                    if (CurveAndMesh(ghmesh.Value, curve, strict, some, all))
                    {
                        indexes.Add(i);
                        collect.Add(obj);
                    }
                }
            }
            DA.SetDataList(0, collect);
            DA.SetDataList(1, indexes);
        }
Exemplo n.º 9
0
        public bool ConvertToGH_Curve <T>(ref T target)
        {
            var crv = ToCurve();

            if (!(crv is null))
            {
                object obj = new GH_Curve(crv);
                target = (T)obj;
                return(true);
            }
            return(false);
        }
Exemplo n.º 10
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh)))
            {
                Mesh[] meshes = Value.GetMesh();
                Mesh   m      = new Mesh();
                for (int i = 0; i < meshes.Length; ++i)
                {
                    m.Append(meshes[i]);
                }
                object mesh = new GH_Mesh(m);

                target = (Q)mesh;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GlulamWorkpiece)))
            {
                object blank = Value;
                target = (Q)blank;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Brep)))
            {
                Brep[] breps = Value.GetBrep();
                Brep   b     = new Brep();
                for (int i = 0; i < breps.Length; ++i)
                {
                    b.Append(breps[i]);
                }
                object brep = new GH_Brep(b);
                target = (Q)brep;
                return(true);
            }
            //if (typeof(Q).IsAssignableFrom(typeof(GH_)))
            if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
            {
                Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
                //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q;
                object crv = new GH_Curve(crvs.FirstOrDefault());
                target = (Q)(crv);
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(List <GH_Curve>)))
            {
                Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray();
                //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q;
                object crv = crvs.Select(x => new GH_Curve(x)).ToList();
                target = (Q)(crv);
                return(true);
            }

            return(base.CastTo <Q>(ref target));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Extract nodes from a tree structure with a flat hierarchy and returns grouped as nodes. NOTE: will have duplicate lines, as untrimmed.
        /// </summary>
        /// <param name="skeleton"></param>
        /// <param name="trimLengthBase"></param>
        /// <param name="trimLengthTop"></param>
        /// <returns></returns>
        private GH_Structure <GH_Curve> ExtractNodes(GH_Structure <GH_Curve> skeleton, double trimLengthBase, double trimLengthTop)
        {
            GH_Structure <GH_Curve> nodes = new GH_Structure <GH_Curve>(); //3dimensional list to preserve data structure internally
            int nodeCount = 0;

            for (int i = 0; i < skeleton.PathCount; i++)
            {
                List <GH_Curve> tempMembers = new List <GH_Curve>();
                //add first member to tree

                GH_Curve member0 = skeleton.get_DataItem(new GH_Path(i), 0);
                tempMembers.Add(member0);

                for (int j = 0; j < skeleton.PathCount; j++)
                {
                    if (j != i) //if its not the same branch
                    {
                        //check whether last plane of branch i is the same as first plane of branch j

                        GH_Curve otherMember = skeleton.get_DataItem(new GH_Path(j), 0);
                        Vector3d distVector  = member0.Value.PointAtEnd - otherMember.Value.PointAtStart;
                        double   dist        = distVector.Length;
                        if (dist < 0.01)
                        {
                            //if same plane, add branch
                            tempMembers.Add(otherMember);
                        }
                    }
                }

                if (tempMembers.Count > 1) //if node is actually a node that is more than just a base
                {
                    //check if members have enough planes.
                    //e.g. if a member has only 1 plane, it is not enough to build a node.
                    bool isSufficient = true;
                    foreach (GH_Curve crv in tempMembers)
                    {
                        if (crv.Value.GetLength() < trimLengthTop)
                        {
                            isSufficient = false;
                            break;
                        }
                    }
                    if (isSufficient)
                    {
                        nodes.AppendRange(tempMembers, new GH_Path(nodeCount));
                        nodeCount++;
                    }
                }
            }
            return(nodes);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Solve method for ParVisCen
        /// </summary>
        public static GH_Point VisCen(GH_Curve ghcurve)
        {
            var c  = ghcurve.Value;
            var tt = DocumentTolerance();

            Polyline plx;

            if (!c.TryGetPolyline(out plx))
            {
                c.ToPolyline(100, 1, DocumentAngleTolerance(), tt, 0, tt, 0, 0, true).TryGetPolyline(out plx);
            }

            (Point3d, double)[] results = new (Point3d, double)[plx.Count];
Exemplo n.º 13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve curve = new GH_Curve();

            DA.GetData <GH_Curve>("Curve", ref curve);
            GH_String layer = new GH_String(string.Empty);

            DA.GetData <GH_String>("Layer", ref layer);

            Component c = curve.Value.ToNurbsCurve().ToGrevitCurve();

            c.TypeOrLayer = layer.ToString();
            SetGID(c);
            DA.SetData("GrevitComponent", c);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve curve = null;

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

            if (!curve.Value.TryGetPolyline(out var poly))
            {
                throw new ArgumentException("The given curve is not a polyline.");
            }

            DA.SetData(0, new GH_Mesh(Mesh.CreateFromClosedPolyline(poly)));
        }
Exemplo n.º 15
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object m_obj   = null;
            Mesh   m_mesh  = null;
            bool   m_faces = false;

            DA.GetData("Mesh", ref m_mesh);
            DA.GetData("Glulam", ref m_obj);
            DA.GetData("Faces", ref m_faces);

            Curve m_curve = null;

            while (true)
            {
                GH_Glulam m_ghglulam = m_obj as GH_Glulam;
                if (m_ghglulam != null)
                {
                    m_curve = m_ghglulam.Value.Centreline;
                    break;
                }

                GH_Curve m_ghcurve = m_obj as GH_Curve;
                if (m_ghcurve != null)
                {
                    m_curve = m_ghcurve.Value;
                    break;
                }

                Glulam m_glulam = m_obj as Glulam;
                if (m_glulam != null)
                {
                    m_curve = m_glulam.Centreline;
                    break;
                }

                m_curve = m_obj as Curve;
                if (m_curve != null)
                {
                    break;
                }
                throw new Exception("Input must be either Glulam or Curve!");
            }

            List <Vector3d> deviations = m_mesh.CalculateTangentVector(m_curve, m_faces);

            DA.SetDataList("Vectors", deviations);
        }
Exemplo n.º 16
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object m_obj   = null;
            Mesh   m_mesh  = null;
            double m_angle = Rhino.RhinoMath.ToRadians(5);

            DA.GetData("Angle", ref m_angle);
            DA.GetData("Mesh", ref m_mesh);
            DA.GetData("Glulam", ref m_obj);

            while (true)
            {
                GH_Glulam m_ghglulam = m_obj as GH_Glulam;
                if (m_ghglulam != null)
                {
                    m_mesh = m_ghglulam.Value.MapToCurveSpace(m_mesh);
                    break;
                }

                GH_Curve m_ghcurve = m_obj as GH_Curve;
                if (m_ghcurve != null)
                {
                    m_mesh = m_ghcurve.Value.MapToCurveSpace(m_mesh);
                    break;
                }

                Glulam m_glulam = m_obj as Glulam;
                if (m_glulam != null)
                {
                    m_mesh = m_glulam.MapToCurveSpace(m_mesh);
                    break;
                }

                Curve m_curve = m_obj as Curve;
                if (m_curve != null)
                {
                    m_mesh = m_curve.MapToCurveSpace(m_mesh);
                    break;
                }
                throw new Exception("Input must be either Glulam or Curve!");
            }

            var indices = m_mesh.CheckFibreCuttingAngle(m_angle);

            DA.SetDataList("Face Indices", indices);
            DA.SetData("debug", m_mesh);
        }
Exemplo n.º 17
0
        protected override void BeforeSolveInstance()
        {
            ClearOutput();
            curve    = false;
            line     = false;
            polyline = false;
            arc      = false;
            circle   = false;
            ellipse  = false;
            IGH_Structure dd        = Params.Input[0].VolatileData;
            double        tolerance = 0;

            foreach (IGH_Goo number in Params.Input[1].VolatileData.AllData(true))
            {
                GH_Number num = (GH_Number)number;
                tolerance = num.Value;
            }
            foreach (IGH_Goo geo in dd.AllData(true))
            {
                GH_Curve crv = (GH_Curve)geo;
                if (crv.Value.IsLinear(tolerance))
                {
                    line = true;
                }
                else if (crv.Value.IsPolyline())
                {
                    polyline = true;
                }
                else if (crv.Value.IsCircle(tolerance))
                {
                    circle = true;
                }
                else if (crv.Value.IsArc(tolerance))
                {
                    arc = true;
                }
                else if (crv.Value.IsEllipse(tolerance))
                {
                    ellipse = true;
                }
                else
                {
                    curve = true;
                }
            }
            AddOutput();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Build curves representation with 1D tree structure. branch = one curve
        /// </summary>
        /// <param name="inputPlanes"></param>
        /// <returns></returns>
        private GH_Structure <GH_Curve> BuildStructureAsCurves(GH_Structure <GH_Plane> inputPlanes)
        {
            GH_Structure <GH_Curve> curves = new GH_Structure <GH_Curve>();

            for (int i = 0; i < inputPlanes.PathCount; i++)
            {
                List <Point3d> cp = new List <Point3d>();
                foreach (GH_Plane plane in inputPlanes.get_Branch(i))
                {
                    cp.Add(plane.Value.Origin);
                }
                GH_Curve cv = new GH_Curve();
                cv.CastFrom(Curve.CreateInterpolatedCurve(cp, 3));
                curves.Append(cv, new GH_Path(i));
            }
            return(curves);
        }
        public override List <SpeckleObjectProperties> getObjectProperties(IEnumerable <object> objects)
        {
            var propertiesList = new List <SpeckleObjectProperties>();
            var simpleProps    = new List <ArchivableDictionary>();
            int k = 0;

            foreach (object o in objects)
            {
                CommonObject myObj = null;

                GH_Brep brep = o as GH_Brep;
                if (brep != null)
                {
                    myObj = brep.Value;
                }

                GH_Surface srf = o as GH_Surface;
                if (srf != null)
                {
                    myObj = srf.Value;
                }

                GH_Mesh mesh = o as GH_Mesh;
                if (mesh != null)
                {
                    myObj = mesh.Value;
                }

                GH_Curve crv = o as GH_Curve;
                if (crv != null)
                {
                    myObj = crv.Value;
                }

                if (myObj != null)
                {
                    if (myObj.UserDictionary.Keys.Length > 0)
                    {
                        propertiesList.Add(new SpeckleObjectProperties(k, myObj.UserDictionary));
                    }
                }

                k++;
            }
            return(propertiesList);
        }
Exemplo n.º 20
0
        private GH_Structure <IGH_Goo> SingleDataStructrue(object value)
        {
            if (value is string path)
            {
                if (File.Exists(path) && Path.GetExtension(path) == ".noahdata")
                {
                    byte[] array;
                    try
                    {
                        array = File.ReadAllBytes(path);
                    }
                    catch
                    {
                        return(null);
                    }

                    return(IO.DeserializeGrasshopperData(array));
                }
            }

            GH_Structure <IGH_Goo> m_data = new GH_Structure <IGH_Goo>();

            GH_Number castNumber = null;
            GH_String castString = null;
            GH_Curve  castCurve  = null;

            if (GH_Convert.ToGHCurve(value, GH_Conversion.Both, ref castCurve))
            {
                m_data.Append(new GH_ObjectWrapper(castCurve));
            }
            else if (GH_Convert.ToGHNumber(value, GH_Conversion.Both, ref castNumber))
            {
                m_data.Append(new GH_ObjectWrapper(castNumber));
            }
            else if (GH_Convert.ToGHString(value, GH_Conversion.Both, ref castString))
            {
                m_data.Append(new GH_ObjectWrapper(castString));
            }
            else
            {
                m_data.Append((IGH_Goo)value);
            }

            return(m_data);
        }
Exemplo n.º 21
0
        public static GH_Structure <GH_Curve> MakeTreeForWays(Dictionary <OSMTag, List <PolylineCurve> > foundWays)
        {
            var output = new GH_Structure <GH_Curve>();
            var i      = 0;

            foreach (var entry in foundWays)
            {
                for (int j = 0; j < entry.Value.Count; j++)
                {
                    GH_Path path = new GH_Path(i, j); // Need to ensure even an empty path exists to enable data matching
                    output.EnsurePath(path);          // Need to ensure even an empty path exists to enable data matching
                    GH_Curve lineForPath = new GH_Curve(entry.Value[j]);
                    output.Append(lineForPath, path);
                }
                i++;
            }

            return(output);
        }
Exemplo n.º 22
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            if (Locked || args.Document.PreviewMode == GH_PreviewMode.Disabled)
            {
                return;                                                                 //跳过锁定或非线框模式
            }
            List <GH_Colour> colour = ((GH_Structure <GH_Colour>)Params.Output[0].VolatileData).FlattenData();
            List <GH_Curve>  curve  = ((GH_Structure <GH_Curve>)Params.Input[0].VolatileData).FlattenData();

            for (int i = 0; i < colour.Count; i++)
            {
                GH_Curve cu  = curve[i];
                bool     set = Attributes.GetTopLevel.Selected;
                if (cu.IsValid)
                {
                    args.Display.DrawCurve(cu.Value, set ? args.WireColour_Selected : colour[i].Value);
                }
            }
        }
        internal static IEnumerable <IGH_Goo> PromptEdge(UIDocument doc, string prompt)
        {
            IGH_Goo goo = null;

            try
            {
                var reference = doc.Selection.PickObject(ObjectType.Edge, prompt);
                if (reference != null)
                {
                    var element = doc.Document.GetElement(reference);
                    var edge    = element.GetGeometryObjectFromReference(reference) as Edge;
                    var curve   = edge.AsCurve().ToCurve();
                    goo = new GH_Curve(curve);
                }
            }
            catch (Autodesk.Revit.Exceptions.OperationCanceledException) { }

            yield return(goo);
        }
Exemplo n.º 24
0
        public override void BakeGeometry(RhinoDoc doc, ObjectAttributes att, List <Guid> obj_ids)
        {
            List <GH_Colour> colour = ((GH_Structure <GH_Colour>)Params.Output[0].VolatileData).FlattenData();
            List <GH_Curve>  curve  = ((GH_Structure <GH_Curve>)Params.Input[0].VolatileData).FlattenData();

            for (var i = 0; i < curve.Count; i++)
            {
                GH_Curve c = curve[i];
                if (!c.IsValid)
                {
                    continue;
                }
                ObjectAttributes oa = att.Duplicate();
                oa.ColorSource = ObjectColorSource.ColorFromObject;
                oa.ObjectColor = colour[i].Value;
                Guid id = Guid.Empty;
                c.BakeGeometry(doc, oa, ref id);
                obj_ids.Add(id);
            }
        }
Exemplo n.º 25
0
        public static GH_Curve ProjectPolylineToTopo(Mesh topoMesh, Polyline pLine)
        {
            GH_Curve ghCurve = new GH_Curve();


            List <Point3d> projectedPts = new List <Point3d>();

            for (int j = 0; j < pLine.Count; j++)
            {
                Ray3d  ray = new Ray3d(pLine[j], moveDir);
                double t   = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, ray);
                if (t >= 0.0)
                {
                    projectedPts.Add(ray.PointAt(t));
                }
                else
                {
                    Ray3d  rayOpp = new Ray3d(pLine[j], -moveDir);
                    double tOpp   = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, rayOpp);
                    if (tOpp >= 0.0)
                    {
                        projectedPts.Add(rayOpp.PointAt(tOpp));
                    }
                    else
                    {
                        //return null;
                    }
                }
            }
            Polyline pLineOut = new Polyline(projectedPts);

            if (pLineOut.IsValid)
            {
                GH_Convert.ToGHCurve(pLineOut.ToNurbsCurve(), GH_Conversion.Primary, ref ghCurve);
                return(ghCurve);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 26
0
        public static bool CastCurveTo <Q>(Rhino.Geometry.Curve curve, out Q target)
        {
            if (curve != null)
            {
                // cast to GH_Curve (Caution: this loses all structural information)
                if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
                {
                    var gc = new GH_Curve(curve);
                    target = (Q)(object)gc;
                    return(true);
                }
                // cast to GH_Line (Caution: this loses all structural information)
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Line)))
                {
                    if (curve is Rhino.Geometry.LineCurve)
                    {
                        var gl = new GH_Line((curve as Rhino.Geometry.LineCurve).Line);
                        target = (Q)(object)gl;
                        return(true);
                    }
                }
                // cast to GH_Arc (Caution: this loses all structural information)
                else if (typeof(Q).IsAssignableFrom(typeof(GH_Arc)))
                {
                    if (curve is Rhino.Geometry.ArcCurve)
                    {
                        var ga = new GH_Arc((curve as Rhino.Geometry.ArcCurve).Arc);
                        target = (Q)(object)ga;
                        return(true);
                    }
                }
                else
                {
                    throw new Exception("Unable to cast to type: " + typeof(Q).ToString());
                }
            }

            target = default(Q);
            return(false);
        }
Exemplo n.º 27
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_GeometricGoo g = null;

            DA.GetData <IGH_GeometricGoo>(0, ref g);

            string geoType = g.TypeName;

            string name = null;

            DA.GetData(1, ref name);

            bool activate = false;

            DA.GetData(2, ref activate);

            Rhino.DocObjects.ObjectAttributes atts = new Rhino.DocObjects.ObjectAttributes();
            string newID = null;

            atts.Name = name;

            if (activate)
            {
                GH_Point p = g as GH_Point;
                if (p != null)
                {
                    GeometryBase geo = GH_Convert.ToGeometryBase(p);
                    newID = RhinoDoc.ActiveDoc.Objects.Add(geo, atts).ToString();
                }
                GH_Curve c = g as GH_Curve;
                if (c != null)
                {
                    GeometryBase geo = GH_Convert.ToGeometryBase(c);
                    newID = RhinoDoc.ActiveDoc.Objects.Add(geo, atts).ToString();
                }
            }

            DA.SetData(0, newID);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Path[0] = joint; Path[1] = member
        /// </summary>
        /// <param name="inputPlanes"></param>
        /// <returns></returns>
        private GH_Structure <GH_Curve> BuildStructureAsCurves()
        {
            GH_Structure <GH_Curve> curves = new GH_Structure <GH_Curve>();

            for (int i = 0; i < Utility.GetMainBranchCount(inputPlanes.Paths); i++)
            {
                int subBranchCount = Utility.GetSecondaryBranchCount(inputPlanes.Paths, i);
                for (int j = 0; j < subBranchCount; j++)
                {
                    GH_Path        path = new GH_Path(i, j);
                    List <Point3d> cp   = new List <Point3d>();
                    foreach (GH_Plane plane in inputPlanes.get_Branch(path))
                    {
                        cp.Add(plane.Value.Origin);
                    }
                    GH_Curve cv = new GH_Curve();
                    cv.CastFrom(Curve.CreateInterpolatedCurve(cp, 3));
                    curves.Append(cv, path);
                }
            }
            return(curves);
        }
Exemplo n.º 29
0
        public override bool CastTo <Q>(ref Q target)
        {
            if (typeof(Q).IsAssignableFrom(typeof(Feature)))
            {
                object blank = Value;
                target = (Q)blank;
                return(true);
            }
            else if (typeof(Q).IsAssignableFrom(typeof(GH_Brep)))
            {
                object blank = new GH_Brep(Value.ToBrep());

                target = (Q)blank;
                return(true);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
            {
                object cl = new GH_Curve(Value.ToNurbsCurve());
                target = (Q)cl;
                return(true);
            }
            return(base.CastTo <Q>(ref target));
        }
Exemplo n.º 30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve baseline = new GH_Curve();
            GH_String layer = new GH_String("");
            GH_Number height = new GH_Number();
            GH_String style = new GH_String("");
            List<Parameter> param = new List<Parameter>();
            if (!DA.GetDataList<Parameter>("Parameters", param)) param = new List<Parameter>();

            //DA.GetData<GH_String>("Family", ref family);
            DA.GetData<GH_String>("Layer", ref layer);
            DA.GetData<GH_String>("Style", ref style);
            DA.GetData<GH_Number>("Height", ref height);
            DA.GetData<GH_Curve>("Baseline", ref baseline);


            Wall w = new Wall(style.Value,layer.Value,param, baseline.ToGrevitCurve(),"",height.Value,true,false);

            SetGID(w);
            Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(baseline.Value, new Rhino.Geometry.Vector3d(0, 0, height.Value));
            SetPreview(w.GID, srf.ToBrep());
            DA.SetData("GrevitComponent",w);
        }
Exemplo n.º 31
0
        public static GH_Structure <GH_Curve> GetJoined(IList <Brep> inBreps)
        {
            GH_Structure <GH_Curve> joinedCurves = new GH_Structure <GH_Curve>();

            for (int i = 0; i < inBreps.Count; i++)
            {
                GH_Path      path        = new GH_Path(i);
                Brep         brep        = inBreps[i];
                List <Curve> curvesToAdd = new List <Curve>();
                curvesToAdd.AddRange(BrepBorderExtractor.GetJoined(brep));

                foreach (Curve curve in curvesToAdd)
                {
                    GH_Curve ghCurve = null;
                    if (GH_Convert.ToGHCurve(curve, GH_Conversion.Both, ref ghCurve))
                    {
                        joinedCurves.Append(ghCurve, path);
                    }
                }
            }

            return(joinedCurves);
        }
Exemplo n.º 32
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)
        {
            #region INPUTS
            // import silkwormSettings file
            List<string> silkwormSettings = new List<string>();
            if (!DA.GetDataList(0, silkwormSettings)) return;

            List<GH_ObjectWrapper> things = new List<GH_ObjectWrapper>();
            if (!DA.GetDataList(1, things)) return;

            // import Silkworm Movement
            #endregion

            SilkwormUtility sUtil = new SilkwormUtility();
            Dictionary<string, string> Settings = sUtil.convertSettings(silkwormSettings);

            #region Optional Variables
            int shell = -999;
            if (!DA.GetData(4, ref shell)) { }
            double layerheight = -999;
            if (!DA.GetData(3, ref layerheight)) { }
            //bool detect = false;
            //if (!DA.GetData(5, ref detect)) { }
            List<Plane> sliceplanes = new List<Plane>();
            if (!DA.GetDataList(2, sliceplanes)) { }

            if (shell == -999)
            {
                shell = int.Parse(Settings["perimeters"]);
            }
            if (layerheight == -999)
            {
                layerheight = double.Parse(Settings["layer_height"]);
            }
            if (sliceplanes.Count<1)
            {
                sliceplanes.Add(Plane.WorldXY);
            }

            #endregion

            List<Brep> Breps = new List<Brep>();

            List<Mesh> Meshes = new List<Mesh>();

            SilkwormSkein skein = new SilkwormSkein();

            #region Sort Types
            foreach (GH_ObjectWrapper obj in things)
            {
                if (obj.Value is GH_Brep)
                {
                    Brep brep = null;
                    GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both);

                    Breps.Add(brep);
                    continue;

                }

                if (obj.Value is GH_Mesh)
                {
                    Mesh mesh = null;
                    GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both);
                    Meshes.Add(mesh);

                    continue;
                }
            }
            #endregion

            if (Breps.Count>0)
            {

                skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight);
                skein.BrepSlice(false);

            }

            if (Meshes.Count > 0)
            {

                //TODO
            }

            //Reflect Errors and Warnings

                foreach (string message in skein.ErrorMessages)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);

                }
                foreach (string message in skein.WarningMessages)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);

                }

            List<Curve>[] openregions = skein.openRegions;

            List<Brep>[] rRegions = skein.Regions;
            List<Brep>[] rPerimeterR = skein.regionPerimeter;
            List<Brep>[]  rInfillR = skein.regionInfill;

            GH_Structure<GH_Brep> Regions = new GH_Structure<GH_Brep>();

            GH_Structure<GH_Curve> openRegions = new GH_Structure<GH_Curve>();

            #region Add Regions to GH_Structure

            if (rRegions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rRegions.Length; i++)
                {

                    if (rRegions[i] != null)
                        {
                    for (int j = 0; j < rRegions[i].Count; j++)
                    {

                            GH_Brep gShapes = new GH_Brep(rRegions[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 0), j);
                        }

                    }
                }
            }
            if (rPerimeterR.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rPerimeterR.Length; i++)
                {
            if (rPerimeterR[i] != null)
                        {
                    for (int j = 0; j < rPerimeterR[i].Count; j++)
                    {

                            GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 1), j);
                        }

                    }
                }
            }
            if (rInfillR.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < rInfillR.Length; i++)
                {
            if (rInfillR[i] != null)
                        {
                    for (int j = 0; j < rInfillR[i].Count; j++)
                    {

                            GH_Brep gShapes = new GH_Brep(rInfillR[i][j]);
                            Regions.Insert(gShapes, new GH_Path(i, 2), j);
                        }

                    }
                }
            }

            if (openregions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < openregions.Length; i++)
                {
            if (openregions[i] != null)
                        {
                    for (int j = 0; j < openregions[i].Count; j++)
                    {

                            GH_Curve gShapes = new GH_Curve(openregions[i][j]);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }

                    }
                }
            }
            //TODO
            //Add Overhang and Bridges

            #endregion

            #region Add Open Regions to GH_Structure
            if (openregions.GetUpperBound(0) > 1)
            {
                for (int i = 0; i < openregions.Length; i++)
                {

                    for (int j = 0; j < openregions[i].Count; j++)
                    {

                        if (openregions[i][j] != null)
                        {

                            SilkwormSegment segment = new SilkwormSegment(openregions[i][j]);
                            Curve curve = segment.Pline.ToNurbsCurve();
                            GH_Curve gShapes = new GH_Curve(curve);
                            openRegions.Insert(gShapes, new GH_Path(i), j);
                        }

                    }
                }
            }
            #endregion

            #region OUTPUT

            if (!DA.SetDataTree(0, Regions)) { return; }
            if (!DA.SetDataTree(1, openRegions)) { return; }

            #endregion
        }
Exemplo n.º 33
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)
        {
            #region INPUTS
            // import silkwormSettings file
            List<string> silkwormSettings = new List<string>();
            if (!DA.GetDataList(0, silkwormSettings)) return;

            List<Brep> things = new List<Brep>();
            if (!DA.GetDataList(1, things)) return;
            // import Silkworm Movement

            SilkwormUtility sUtil = new SilkwormUtility();
            Dictionary<string, string> Settings = sUtil.convertSettings(silkwormSettings);
            SilkwormCalculator calc = new SilkwormCalculator(Settings);

            #region Optional Inputs

            int infType = 0;
            if (!DA.GetData(2, ref infType)) { }

            List<double> spacing = new List<double>();
            if (!DA.GetDataList(3, spacing)) { }

            List<double> infDens = new List<double>();
            if (!DA.GetDataList(4, infDens)) { }
            List<double> infRot = new List<double>();
            if (!DA.GetDataList(5, infRot)) { }

            #endregion

            if (spacing.Count<1)
            {
                spacing.Add(0.66);
                //TODO Calculator

            }
            if (infDens.Count < 1)
            {
                infDens.Add(double.Parse(Settings["fill_density"]));

            }
            if (infRot.Count < 1)
            {
                infRot.Add(double.Parse(Settings["fill_angle"]));

            }
            #endregion

            SilkwormSkein skein = new SilkwormSkein(Settings, things);

            //Switch depending on which infill type is selected by input
            if (infType == 0)
            {
                //Match length of data
                if (spacing.Count != things.Count)
                {
                    List<double> newspacing = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newspacing.Add(spacing[0]);
                    }
                    spacing = newspacing;
                }

                skein.Skinner(spacing);
            }
            if (infType == 1)
            {
                //Match length of data
                if (infDens.Count != things.Count)
                {
                    List<double> newinfDens = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfDens.Add(infDens[0]);
                    }
                    spacing = newinfDens;
                }
                if (infRot.Count != things.Count)
                {
                    List<double> newinfRot = new List<double>();
                    for (int e = 0; e < things.Count; e++)
                    {
                        newinfRot.Add(infRot[0]);
                    }
                    spacing = newinfRot;
                }

                skein.Filler(infDens, infRot);
            }

            //Reflect Errors and Warnings

            foreach (string message in skein.ErrorMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message);

            }
            foreach (string message in skein.WarningMessages)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message);

            }

            //Output Holders
            List<Curve>[] plPerimeter = skein.curvePerimeter;
            List<Curve>[] plInfill = skein.curveInfill;

            GH_Structure<GH_Curve> InfillRegion = new GH_Structure<GH_Curve>();

            //Create GH_Structure
            #region Create Structure from Curves

            if (plPerimeter.Length > 0)
            {
                for (int i = 0; i < plPerimeter.Length; i++)
                {
                  if (plPerimeter[i] != null)
                        {
                    for (int j = 0; j < plPerimeter[i].Count; j++)
                    {

                            Curve aShape = plPerimeter[i][j].ToNurbsCurve();

                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 0), j);
                            //}
                        }
                    }
                }
            }
            if (plInfill.Length > 0)
            {
                for (int i = 0; i < plInfill.Length; i++)
                {
            if (plInfill[i] != null)
                        {
                    for (int j = 0; j < plInfill[i].Count; j++)
                    {

                            Curve aShape = plInfill[i][j].ToNurbsCurve();

                            GH_Curve gShapes = new GH_Curve(aShape);
                            InfillRegion.Insert(gShapes, new GH_Path(i, 1), j);
                        }
                    }
                }
            }

            #endregion

            //Output
            if (!DA.SetDataTree(0, InfillRegion)) { return; }
        }
Exemplo n.º 34
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.º 35
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve baseline = new GH_Curve();
            GH_Vector vector = new GH_Vector();
            GH_String family = new GH_String("");
            GH_String type = new GH_String("");
            List<Parameter> parameters = new List<Parameter>();
            if (!DA.GetDataList<Parameter>("Parameters", parameters)) parameters = new List<Parameter>();

            
            DA.GetData<GH_Vector>("Vector", ref vector);
            DA.GetData<GH_Curve>("Outline", ref baseline);

            if (baseline.Value.IsPolyline() && baseline.Value.IsClosed)
            {
                


                Rhino.Geometry.Polyline pline;
                if (baseline.Value.TryGetPolyline(out pline))
                {
                    PLine plineToExtrude = new PLine();
                    plineToExtrude.points = new List<Grevit.Types.Point>();
                    foreach (Rhino.Geometry.Point3d pkt in pline)
                    {
                        plineToExtrude.points.Add(pkt.ToGrevitPoint());
                    }
                    plineToExtrude.closed = pline.IsClosed;
                    plineToExtrude.GID = baseline.ReferenceID.ToString();


                    Grevit.Types.Point extrusionVector = new Grevit.Types.Point()
                    {
                        x = vector.Value.X,
                        y = vector.Value.Y,
                        z = vector.Value.Z
                    };

                    SimpleExtrusion extrusion = new SimpleExtrusion(family.Value, type.Value, parameters, plineToExtrude, extrusionVector);

                    Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(baseline.Value, vector.Value);
                    
                    SetGID(extrusion);
                    SetPreview(extrusion.GID, srf.ToBrep());

                    

                    DA.SetData("GrevitComponent",extrusion);
                }
            }
        }
Exemplo n.º 36
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.º 37
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Curve curve = new GH_Curve();
            DA.GetData<GH_Curve>("Curve", ref curve);
            GH_String layer = new GH_String(string.Empty);
            DA.GetData<GH_String>("Layer", ref layer);

            Component c = curve.Value.ToNurbsCurve().ToGrevitCurve();
            c.TypeOrLayer = layer.ToString();
            SetGID(c);
            DA.SetData("GrevitComponent", c);
        }
Exemplo n.º 38
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Types.Assembly assembly = new Types.Assembly();
            DA.GetData<Types.Assembly>("Material", ref assembly);

            GH_Curve curve = new GH_Curve();
            GH_Number radius = new GH_Number(0);
            GH_Number height = new GH_Number(0);
            GH_Number width = new GH_Number(0);
            Types.Profile profile = null;

            if (!DA.GetData<GH_Number>("Radius", ref radius)) radius.Value = 0;
            if (!DA.GetData<GH_Number>("Height", ref height)) height.Value = 0;
            if (!DA.GetData<GH_Number>("Width", ref width)) width.Value = 0;
            if (!DA.GetData<Types.Profile>("Profile", ref profile)) profile = null;
            DA.GetData<GH_Curve>("Curve", ref curve);

            double calculationVolume = 0;

            if (profile != null)
            {
                calculationVolume = curve.Value.GetLength() * profile.Area;
                drawColumn(curve.Value.PointAtStart, curve.Value.PointAtEnd, profile.Area);
            }
            else
            {
                if (radius.Value > 0)
                {
                    drawColumn(curve.Value.PointAtStart, curve.Value.PointAtEnd, radius.Value);
                    calculationVolume = curve.Value.GetLength() * radius.Value * radius.Value * Math.PI;
                }
                else
                {
                    drawColumn(curve.Value.PointAtStart, curve.Value.PointAtEnd, height.Value, width.Value);
                    calculationVolume = curve.Value.GetLength() * height.Value * width.Value;
                }
            }

            Types.Result result = new Types.Result()
            {
                GlobalWarmingPotential = new Types.UnitDouble<Types.LCA.CO2e>(assembly.GlobalWarmingPotential.Value * calculationVolume),
                Acidification = new Types.UnitDouble<Types.LCA.kgSO2>(assembly.Acidification.Value * calculationVolume),
                DepletionOfNonrenewbles = new Types.UnitDouble<Types.LCA.MJ>(assembly.DepletionOfNonrenewbles.Value * calculationVolume),
                DepletionOfOzoneLayer = new Types.UnitDouble<Types.LCA.kgCFC11>(assembly.DepletionOfOzoneLayer.Value * calculationVolume),
                Eutrophication = new Types.UnitDouble<Types.LCA.kgPhostphate>(assembly.Eutrophication.Value * calculationVolume),
                FormationTroposphericOzone = new Types.UnitDouble<Types.LCA.kgNOx>(assembly.FormationTroposphericOzone.Value * calculationVolume)
            };

            DA.SetData("LCA Result", result);
        }