예제 #1
0
        public void GeneratePreViewObjectsI(GH_Structure <IGH_GeometricGoo> inGeoTree)
        {
            string key = "Leopard(" + this.InstanceGuid + ")";

            RhinoDoc.ActiveDoc.Layers.Add("Leopard_Preview", System.Drawing.Color.Maroon);
            int layer = RhinoDoc.ActiveDoc.Layers.Find("Leopard_Preview", true);

            Rhino.DocObjects.RhinoObject[] obj = RhinoDoc.ActiveDoc.Objects.FindByUserString(key, "*", true);

            if (obj.Length == 0) //if no preview item
            {
                int count = 0;
                foreach (IGH_GeometricGoo goo in inGeoTree.AllData(false))
                {
                    Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
                    att.SetUserString(key, count.ToString());
                    att.LayerIndex = layer;
                    count++;
                    if (goo is IGH_BakeAwareData)
                    {
                        IGH_BakeAwareData data = (IGH_BakeAwareData)goo;
                        Guid guid;
                        data.BakeGeometry(RhinoDoc.ActiveDoc, att, out guid);
                    }
                }
            }
        }
예제 #2
0
        public void GeneratePreViewMeshVertices(GH_Structure <IGH_GeometricGoo> inGeoTree)
        {
            string key = "Leopard(" + this.InstanceGuid + ")";

            RhinoDoc.ActiveDoc.Layers.Add("Leopard_Preview", System.Drawing.Color.Maroon);
            int layer = RhinoDoc.ActiveDoc.Layers.Find("Leopard_Preview", true);

            Rhino.DocObjects.RhinoObject[] obj = RhinoDoc.ActiveDoc.Objects.FindByUserString(key, "*", true);

            if (obj.Length == 0) //if no preview item
            {
                int count = 0;
                foreach (IGH_GeometricGoo goo in inGeoTree.AllData(false))
                {
                    PlanktonMesh pMesh = new PlanktonMesh();
                    Mesh         mesh;
                    if (!goo.CastTo <Mesh>(out mesh))
                    {
                        RhinoApp.WriteLine("input invalid");
                    }

                    pMesh = mesh.ToPlanktonMesh();

                    PlanktonXYZ[]  xyz       = pMesh.Vertices.GetPositions();
                    List <Point3d> oVertices = new List <Point3d>();

                    for (int i = 0; i < xyz.Length; i++)
                    {
                        oVertices.Add(xyz[i].ToPoint3d());
                    }

                    count++;

                    int vCount = 0;

                    foreach (Point3d p in oVertices)
                    {
                        string keyV = "Leopard(" + this.InstanceGuid + vCount + ")";


                        Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
                        att.SetUserString(keyV, count.ToString());
                        att.LayerIndex = layer;

                        GH_Point point = new GH_Point(p);

                        if (goo is IGH_BakeAwareData)
                        {
                            IGH_BakeAwareData data = (IGH_BakeAwareData)point;
                            Guid guid;
                            data.BakeGeometry(RhinoDoc.ActiveDoc, att, out guid);
                        }

                        vCount++;
                    }
                }
            }
        }
예제 #3
0
        protected override bool Prompt_ManageCollection(GH_Structure <T> values)
        {
            foreach (var item in values.AllData(true))
            {
                if (item.IsValid)
                {
                    continue;
                }

                if (item is Types.IGH_ElementId elementId)
                {
                    if (elementId.IsReferencedElement)
                    {
                        elementId.LoadElement();
                    }
                }
            }

            return(base.Prompt_ManageCollection(values));
        }
        private List <string> GetOutputList(GH_Structure <GH_SpeckleBase> speckleObjects)
        {
            // Get the full list of output parameters
            var fullProps = new List <string>();

            foreach (var ghGoo in speckleObjects.AllData(true))
            {
                var b = (ghGoo as GH_SpeckleBase)?.Value;
                b?.GetMemberNames().ToList().ForEach(prop =>
                {
                    if (!fullProps.Contains(prop))
                    {
                        fullProps.Add(prop);
                    }
                });
            }

            fullProps.Sort();
            return(fullProps);
        }
        private void createCombinedDat(GH_Structure <IGH_Goo> data, string projectName)
        {
            // var modelInfoList = new List<SofistikModel>();
            // var stringList = new List<string>();
            var cadInpList = new List <string>();

            foreach (var goo in data.AllData(true))
            {
                if (goo is GH_SofistikModel)
                {
                    // modelInfoList.Add((goo as GH_SofistikModel).Value);
                    cadInpList.Add((goo as GH_SofistikModel).Value.CadInp);
                }
                else if (goo is GH_String)
                {
                    // stringList.Add((goo as GH_String).Value);
                    cadInpList.Add((goo as GH_String).Value);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data conversion failed from " + goo.TypeName + " to GH_String.");
                }
            }

            // modelInfoList.Sort();

            // foreach (var modelInfo in modelInfoList)
            //    cadInpList.Add(modelInfo.CadInp);
            // foreach (var s in stringList)
            //    cadInpList.Add(s);

            _combinedDat = "#DEFINE PROJECT = " + projectName + "\n";
            foreach (var cadInp in cadInpList)
            {
                _combinedDat += cadInp + "\n";
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (!_needBake || !GhDrawingContext.LinkedDocument.IsActive)
            {
                return;
            }
            _needBake = false;

            var geometry = new GH_Structure <IGH_GeometricGoo>();

            if (!DA.GetDataTree("Geometry", out geometry))
            {
                return;
            }

            var objIds = BakeGhGeometry(geometry.AllData(true));
            var res    = new List <Types.BcEntity>();

            foreach (_OdDb.ObjectId objId in objIds)
            {
                res.Add(new Types.BcEntity(new _OdDb.FullSubentityPath(new _OdDb.ObjectId[] { objId }, new _OdDb.SubentityId()), GhDrawingContext.LinkedDocument.Name));
            }
            DA.SetDataList("BuildingElement", res);
        }
예제 #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            try {
                //Retrieve parameters

                GH_Structure <GH_Curve> c0 = new GH_Structure <GH_Curve>();
                GH_Structure <GH_Curve> c1 = new GH_Structure <GH_Curve>();
                Mesh   mesh0         = new Mesh();
                Mesh   mesh1         = new Mesh();
                int    sideDivisions = 2;
                double planeWidth    = 0.01;
                int    divisions     = 2;
                bool   cornerType    = true;
                double parallel      = 0.0;
                bool   screws        = true;

                DA.GetDataTree <GH_Curve>(0, out c0);
                DA.GetDataTree <GH_Curve>(1, out c1);
                DA.GetData(2, ref mesh0);
                DA.GetData(3, ref mesh1);
                DA.GetData(4, ref sideDivisions);
                DA.GetData(5, ref planeWidth);
                DA.GetData(6, ref divisions);
                DA.GetData(7, ref cornerType);
                DA.GetData(8, ref parallel);
                DA.GetData(9, ref screws);


                //Use curves as input
                if (c0.DataCount > 0 && (c0.DataCount == c1.DataCount))
                {
                    List <Polyline> outlines0 = new List <Polyline>();
                    List <Polyline> outlines1 = new List <Polyline>();

                    var c0Enumerator = c0.GetEnumerator();
                    var c1Enumerator = c1.GetEnumerator();

                    while (c0Enumerator.MoveNext() && c1Enumerator.MoveNext())
                    {
                        Object curve0 = c0Enumerator.Current;
                        Object curve1 = c1Enumerator.Current;
                    }


                    int n = c0.DataCount;


                    foreach (GH_Curve ghc in c0.AllData(true))
                    {
                        ghc.Value.TryGetPolyline(out Polyline p);
                        outlines0.Add(p);
                    }

                    foreach (GH_Curve ghc in c1.AllData(true))
                    {
                        ghc.Value.TryGetPolyline(out Polyline p);
                        outlines1.Add(p);
                    }


                    //2.0 Setup theBox class

                    TheBox[] boxes = new TheBox[n];

                    Plane[][]      sidePlanes    = new Plane[n][];
                    Plane[][]      topPlanes     = new Plane[n][];
                    Polyline[][][] midOutlines0  = new Polyline[n][][];
                    Polyline[][][] sideOutlines0 = new Polyline[n][][];

                    Polyline[][][] sideOutlines1 = new Polyline[n][][];
                    Plane[][][]    edgePlanes    = new Plane[n][][];

                    for (int i = 0; i < n; i++)
                    {
                        boxes[i] = new TheBox(outlines0[i], outlines1[i], planeWidth, new List <double> {
                            0.25, 0.75
                        }, cornerType, parallel, divisions, i);

                        boxes[i].ConstructPlanes();
                        sidePlanes[i] = boxes[i].sidePlanes;
                        topPlanes[i]  = boxes[i].topPlanes;

                        boxes[i].ConstructOutlines();
                        sideOutlines0[i] = boxes[i].sideOutlines0;
                        sideOutlines1[i] = boxes[i].sideOutlines1;
                        midOutlines0[i]  = boxes[i].midOutlines0;

                        if (sideDivisions > 1)
                        {
                            boxes[i].ConstructJointsEdgeJoints(sideDivisions, -20);
                            edgePlanes[i] = boxes[i].sidePlanesR90SideJoints;
                        }
                    }

                    DA.SetDataTree(1, NGonsCore.GrasshopperUtil.IE2(sidePlanes));
                    DA.SetDataTree(2, NGonsCore.GrasshopperUtil.IE2(topPlanes));
                    DA.SetDataTree(3, NGonsCore.GrasshopperUtil.IE3(sideOutlines0));
                    DA.SetDataTree(4, NGonsCore.GrasshopperUtil.IE3(sideOutlines1));
                    DA.SetDataTree(5, NGonsCore.GrasshopperUtil.IE3(midOutlines0));
                    DA.SetDataTree(6, NGonsCore.GrasshopperUtil.IE3(edgePlanes));


                    //Use meshes as input with its adjacency
                }
                else if (mesh0.Ngons.Count == mesh1.Ngons.Count)
                {
                    int n = mesh0.Ngons.Count;

                    Mesh[] meshBoxes = mesh0.ProjectPairsMesh(mesh1, 1);
                    DA.SetDataList(0, meshBoxes);

                    //1.0 Get top and side polylines from boxes
                    Polyline[][] meshBoxesOutlinesTop  = new Polyline[n][];
                    Polyline[][] meshBoxesOutlinesSide = new Polyline[n][];

                    for (int i = 0; i < n; i++)
                    {
                        Polyline[] outlines = meshBoxes[i].GetPolylines();
                        meshBoxesOutlinesSide[i] = new Polyline[outlines.Length - 2];
                        Array.Copy(outlines, meshBoxesOutlinesSide[i], outlines.Length - 2);
                        meshBoxesOutlinesTop[i] = new Polyline[2] {
                            outlines[outlines.Length - 1], outlines[outlines.Length - 2]
                        };
                    }

                    //2.0 Setup theBox class

                    TheBox[] boxes = new TheBox[n];

                    Plane[][] sidePlanes = new Plane[n][];
                    Plane[][] topPlanes  = new Plane[n][];

                    Polyline[][][] midOutlines0  = new Polyline[n][][];
                    Polyline[][][] sideOutlines0 = new Polyline[n][][];

                    Polyline[][][]      misOutlinesJoints   = new Polyline[n][][];       //Repesent mid panels with finger joints
                    List <Polyline>[][] sideOutlinesJoints0 = new List <Polyline> [n][]; //n - number of sides
                    List <Polyline>[][] sideOutlinesJoints1 = new List <Polyline> [n][]; //n - number of sides

                    for (int i = 0; i < n; i++)
                    {
                        boxes[i] = new TheBox(meshBoxesOutlinesTop[i][0], meshBoxesOutlinesTop[i][1], planeWidth, new List <double> {
                            0.5
                        }, cornerType, parallel, divisions + 1, i);

                        boxes[i].ConstructPlanes();
                        boxes[i].ConstructOutlines();
                        boxes[i].ConstructJoints();
                        boxes[i].ConstructJointsLines();

                        sidePlanes[i] = boxes[i].sidePlanes;
                        topPlanes[i]  = boxes[i].topPlanes;

                        sideOutlines0[i] = boxes[i].sideOutlines0;
                        midOutlines0[i]  = boxes[i].midOutlines0;

                        misOutlinesJoints[i]   = boxes[i].misOutlinesJoints;
                        sideOutlinesJoints0[i] = boxes[i].sideOutlinesJoints0;
                        sideOutlinesJoints1[i] = boxes[i].sideOutlinesJoints1;
                    }

                    //3.0 Setup neighbours
                    if (screws)
                    {
                        int[][]       e         = mesh0.GetNGonsTopoBoundaries();
                        HashSet <int> allE      = mesh0.GetAllNGonEdges(e);
                        int[]         allEArray = allE.ToArray();
                        int[][]       eNgons    = mesh0.GetNgonsConnectedToNGonsEdges(allE);
                        int[][]       ne        = mesh0.GetNGonFacesEdges(e);

                        List <Line>[][] screws_ = new List <Line> [n][];//n - number of sides

                        //Loop through ngons
                        for (int i = 0; i < n; i++)
                        {
                            screws_[i] = new List <Line> [ne[i].Length];

                            //Loop through negon edges
                            for (int j = 0; j < ne[i].Length; j++)
                            {
                                screws_[i][j] = new List <Line>();

                                //if not naked
                                if (mesh0.TopologyEdges.GetConnectedFaces(ne[i][j]).Length > 1)
                                {
                                    //Get currnet ngon line

                                    // int prev = NGonsCore.MathUtil.Wrap(j-1,ne[i].Length);

                                    Line ln0  = boxes[i].jointLines[j][0];
                                    Line ln0_ = boxes[i].jointLines[j][1];

                                    ////Get neighbour ngon line
                                    //First get edge ngons
                                    int   eID          = Array.IndexOf(allEArray, ne[i][j]);
                                    int[] currentNGons = eNgons[eID];
                                    int   neiN         = (currentNGons[0] == i) ? currentNGons[1] : currentNGons[0];//neighbour ngon


                                    //Local edge id of neighbour polygon
                                    int neiEID = Array.IndexOf(ne[neiN], ne[i][j]);
                                    //int prevNei = NGonsCore.MathUtil.Wrap(j+1,ne[neiN].Length);
                                    Line ln1  = boxes[neiN].jointLines[neiEID][0];
                                    Line ln1_ = boxes[neiN].jointLines[neiEID][1];

                                    // Polyline polyline = new Polyline(){boxes[i].c0,ln0.PointAt(0.5),boxes[neiN].c0 };
                                    //Polyline polyline = new Polyline(){ln0.PointAt(0.5),0.5*(ln0.PointAt(0.5)+ln1.PointAt(0.5)) };

                                    Point3d[] intp0  = NGonsCore.PointUtil.InterpolatePoints(ln0.PointAt(0.2), ln0.PointAt(0.8), 0);
                                    Point3d[] intp1  = NGonsCore.PointUtil.InterpolatePoints(ln1.PointAt(0.8), ln1.PointAt(0.2), 0);
                                    Point3d[] intp0_ = NGonsCore.PointUtil.InterpolatePoints(ln0_.PointAt(0.2), ln0_.PointAt(0.8), 0);
                                    Point3d[] intp1_ = NGonsCore.PointUtil.InterpolatePoints(ln1_.PointAt(0.8), ln1_.PointAt(0.2), 0);


                                    for (int k = 0; k < intp0.Length; k++)
                                    {
                                        Vector3d vec = intp0[k] - intp1[k];
                                        vec.Unitize();
                                        vec *= 0.01;
                                        Line joint = new Line(intp0[k] + vec, 0.5 * (intp0[k] + intp1[k]));
                                        screws_[i][j].Add(joint);
                                    }

                                    for (int k = 0; k < intp0.Length; k++)
                                    {
                                        Vector3d vec = intp0_[k] - intp1_[k];
                                        vec.Unitize();
                                        vec *= 0.01;
                                        Line joint = new Line(intp0_[k] + vec, 0.5 * (intp0_[k] + intp1_[k]));
                                        screws_[i][j].Add(joint);
                                    }
                                }
                            }
                        }
                        DA.SetDataTree(6, NGonsCore.GrasshopperUtil.IE3(screws_, 0));
                    }//if screws

                    DA.SetDataTree(1, NGonsCore.GrasshopperUtil.IE2(sidePlanes, 0));
                    DA.SetDataTree(2, NGonsCore.GrasshopperUtil.IE2(topPlanes, 0));
                    DA.SetDataTree(3, NGonsCore.GrasshopperUtil.IE3(misOutlinesJoints, 0));
                    DA.SetDataTree(4, NGonsCore.GrasshopperUtil.IE3(sideOutlinesJoints0, 0));
                    DA.SetDataTree(5, NGonsCore.GrasshopperUtil.IE3(sideOutlinesJoints1, 0));
                }
            }catch (Exception e) {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
        }
예제 #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //bool inputLock = false;
            string key = "Leopard(" + this.InstanceGuid + ")";
            GH_Structure <IGH_GeometricGoo> inGeoTree;

            if (!DA.GetDataTree <IGH_GeometricGoo>(0, out inGeoTree))
            {
                return;
            }

            //clear all stored selection
            if (resetStoredPath)
            {
                storedPath.Clear();
            }

            //delete the preview baked objects
            if (!freezePreviewObjects)
            {
                RemovePreviewObjects();
            }

            //generate the preview baked objects
            if (!inputLock && (generatePreview || !freezePreviewObjects))
            {
                GeneratePreViewObjectsI(inGeoTree);                                                          // && !freezePreviewObjects)
            }
            //happens when unlock
            //if (addSelection)
            //    SelectStoredPathObj(storedPath);

            GH_Structure <GH_String> pathTree = new GH_Structure <GH_String>(); //a tree that the data stored is its path

            for (int i = 0; i < inGeoTree.PathCount; i++)
            {
                string path = inGeoTree.Paths[i].ToString();
                for (int j = 0; j < inGeoTree.Branches[i].Count; j++)
                {
                    string str = path + "(" + j.ToString() + ")";
                    pathTree.Append(new GH_String(str));
                }
            }
            List <string> pathOrder = new List <string>();

            foreach (GH_String s in pathTree.AllData(false))
            {
                pathOrder.Add(s.ToString());
            }

            GH_Structure <GH_Integer> orderTree = new GH_Structure <GH_Integer>(); //a tree that the data is the order of each data, this tree is reference for sorting

            for (int i = 0; i < pathOrder.Count; i++)
            {
                string[] pathSeg;
                string   indSeg;
                GH_Path.SplitPathLikeString(pathOrder[i], out pathSeg, out indSeg);
                int[] pInd  = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str));
                int   index = System.Convert.ToInt32(indSeg);
                orderTree.Insert(new GH_Integer(i), new GH_Path(pInd), index);
            }

            GH_Structure <IGH_Goo>    outGeoTree   = new GH_Structure <IGH_Goo>();
            List <IGH_Goo>            outGeoList   = new List <IGH_Goo>();
            GH_Structure <IGH_Goo>    outPathTree  = new GH_Structure <IGH_Goo>();
            List <IGH_Goo>            outPathList  = new List <IGH_Goo>();
            GH_Structure <IGH_Goo>    outIndTree   = new GH_Structure <IGH_Goo>();
            List <IGH_Goo>            outIndList   = new List <IGH_Goo>();
            GH_Structure <GH_Integer> outOrderTree = new GH_Structure <GH_Integer>();
            List <GH_Integer>         outOrderList = new List <GH_Integer>();

            for (int i = 0; i < storedPath.Count; i++)
            {
                string   p = pathOrder[System.Convert.ToInt32(storedPath[i])];
                string[] pathSeg;
                string   indSeg;

                if (GH_Path.SplitPathLikeString(p, out pathSeg, out indSeg))
                {
                    int[]   pInd  = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str));
                    GH_Path path  = new GH_Path(pInd);
                    int     index = System.Convert.ToInt32(indSeg);
                    if (maintainPath)
                    {
                        outGeoTree.Append((IGH_GeometricGoo)inGeoTree.get_Branch(path)[index], path);
                        outPathTree.Append(new GH_String(path.ToString()), path);
                        outIndTree.Append(new GH_Integer(index), path);
                        outOrderTree.Append((GH_Integer)(orderTree.get_Branch(path)[index]), path);
                    }
                    else
                    {
                        outGeoList.Add((IGH_GeometricGoo)inGeoTree.get_Branch(path)[index]);
                        outPathList.Add(new GH_String(path.ToString()));
                        outIndList.Add(new GH_Integer(index));
                        outOrderList.Add((GH_Integer)orderTree.get_Branch(path)[index]);
                    }
                }
            }
            if (maintainPath)
            {
                if (this.sortByIndex)
                {
                    outGeoTree = SortTreeByIndex(outGeoTree, outOrderTree);
                    outIndTree = SortTreeByIndex(outIndTree, outOrderTree);
                }
                DA.SetDataTree(0, outGeoTree);
                DA.SetDataTree(1, outPathTree);
                DA.SetDataTree(2, outIndTree);
                DA.SetDataTree(3, outOrderTree);
            }
            else
            {
                if (this.sortByIndex)
                {
                    List <IGH_Goo> gooCopy = outGeoList;
                    outGeoList.Sort(new SelectCompareGoo(gooCopy, outOrderList));
                    gooCopy = outPathList;
                    outPathList.Sort(new SelectCompareGoo(gooCopy, outOrderList));
                    gooCopy = outIndList;
                    outIndList.Sort(new SelectCompareGoo(gooCopy, outOrderList));
                }
                DA.SetDataList(0, outGeoList);
                DA.SetDataList(1, outPathList);
                DA.SetDataList(2, outIndList);
                DA.SetDataTree(3, outOrderTree);
            }
        }
예제 #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //bool inputLock = false;
            string key = "Leopard(" + this.InstanceGuid + ")";

            GH_Structure <IGH_GeometricGoo> inGeoTree;

            if (!DA.GetDataTree <IGH_GeometricGoo>(0, out inGeoTree))
            {
                return;
            }

            GH_Structure <IGH_GeometricGoo> ptsGoo = new GH_Structure <IGH_GeometricGoo>();

            for (int i = 0; i < inGeoTree.PathCount; i++)
            {
                for (int j = 0; j < inGeoTree.Branches[i].Count; j++)
                {
                    Mesh mesh;
                    if (!inGeoTree.Branches[i][j].CastTo <Mesh>(out mesh))
                    {
                        continue;
                    }
                    else
                    {
                        GH_Path    path    = inGeoTree.get_Path(i);
                        List <int> newPath = new List <int>();
                        for (int p = 0; p < path.Indices.Length; p++)
                        {
                            newPath.Add(path.Indices[p]);
                        }

                        PlanktonMesh          pMesh = mesh.ToPlanktonMesh();
                        IEnumerable <Point3d> pts   = pMesh.GetPositions();

                        foreach (Point3d p in pts)
                        {
                            if (inGeoTree.PathCount == 1)
                            {
                                ptsGoo.Append(GH_Convert.ToGeometricGoo(p), inGeoTree.get_Path(i));
                            }
                            else
                            {
                                ptsGoo.Append(GH_Convert.ToGeometricGoo(p), new GH_Path(newPath.ToArray()));
                            }
                        }
                    }
                }
            }

            //ptsGoo.Simplify(GH_SimplificationMode.CollapseLeadingOverlaps);

            //clear all stored selection
            if (resetStoredPath)
            {
                storedPath.Clear();
            }

            //delete the preview baked objects
            if (!freezePreviewObjects)
            {
                RemovePreviewObjects();
            }

            //generate the preview baked objects
            if (!inputLock && (generatePreview || !freezePreviewObjects))
            {
                GeneratePreViewObjectsI(ptsGoo);                                                          // && !freezePreviewObjects)
            }
            //happens when unlock
            //if (addSelection)
            //    SelectStoredPathObj(storedPath);


            GH_Structure <GH_String> pathTree = new GH_Structure <GH_String>(); //a tree that the data stored is its path

            for (int i = 0; i < ptsGoo.PathCount; i++)
            {
                string path = ptsGoo.Paths[i].ToString();
                for (int j = 0; j < ptsGoo.Branches[i].Count; j++)
                {
                    string str = path + "(" + j.ToString() + ")";
                    pathTree.Append(new GH_String(str));
                }
            }
            List <string> pathOrder = new List <string>();

            foreach (GH_String s in pathTree.AllData(false))
            {
                pathOrder.Add(s.ToString());
            }

            GH_Structure <GH_Integer> orderTree = new GH_Structure <GH_Integer>(); //a tree that the data is the order of each data, this tree is reference for sorting

            for (int i = 0; i < pathOrder.Count; i++)
            {
                string[] pathSeg;
                string   indSeg;
                GH_Path.SplitPathLikeString(pathOrder[i], out pathSeg, out indSeg);
                int[] pInd  = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str));
                int   index = System.Convert.ToInt32(indSeg);
                orderTree.Insert(new GH_Integer(i), new GH_Path(pInd), index);
            }

            GH_Structure <IGH_Goo>    outGeoTree   = new GH_Structure <IGH_Goo>();
            GH_Structure <IGH_Goo>    outIndTree   = new GH_Structure <IGH_Goo>();
            GH_Structure <GH_Integer> outOrderTree = new GH_Structure <GH_Integer>();

            for (int i = 0; i < storedPath.Count; i++)
            {
                string   p = pathOrder[System.Convert.ToInt32(storedPath[i])];
                string[] pathSeg;
                string   indSeg;

                if (GH_Path.SplitPathLikeString(p, out pathSeg, out indSeg))
                {
                    int[]   pInd  = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str));
                    GH_Path path  = new GH_Path(pInd);
                    int     index = System.Convert.ToInt32(indSeg);

                    outGeoTree.Append((IGH_GeometricGoo)ptsGoo.get_Branch(path)[index], path);
                    outIndTree.Append(new GH_Integer(index), path);
                    outOrderTree.Append((GH_Integer)(orderTree.get_Branch(path)[index]), path);
                }
            }

            if (this.sortByIndex)
            {
                outGeoTree = SortTreeByIndex(outGeoTree, outOrderTree);
                outIndTree = SortTreeByIndex(outIndTree, outOrderTree);
            }
            DA.SetDataTree(0, outGeoTree);
            DA.SetDataTree(1, outIndTree);
        }
예제 #10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //declare input variables to load into

            AuthToken authToken = new AuthToken();
            string sheetName = "";
            string worksheet = "";
            bool rowsColumns = false;

            GH_Structure<GH_String> addresses = new GH_Structure<GH_String>();
            GH_Structure<GH_String> data = new GH_Structure<GH_String>();
            bool write = false;

            //declare output variables
            GH_Structure<GH_String> addressesOut = new GH_Structure<GH_String>();

            //get data from inputs
            if (!DA.GetData<AuthToken>("Token", ref authToken))
            {
                return; //exit if no token given
            }
            if (!authToken.IsValid)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The provided authentication token appears to be invalid. Try re-running the Google Authenticator component.");
                return; //exit if token invalid
            }

            if (!DA.GetData<string>("Name", ref sheetName))
            {
                return; //exit if no name given
            }
            DA.GetData<string>("Worksheet", ref worksheet);

            DA.GetData<bool>("Organize by Rows or Columns", ref rowsColumns);
            DA.GetDataTree<GH_String>("Address", out addresses);
            DA.GetDataTree<GH_String>("Data", out data);
            DA.GetData<bool>("Write", ref write);

            if (!write) return; //exit if write is not true

            //check each specified address for validity
            foreach (GH_String address in addresses.AllData(true))
            {
                if (!GDriveUtil.isValidAddress(address.ToString()))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error,"Not all addresses are specified in a valid format.");
                    return;
                }
            }

            //setup auth and factory
            //set up oAuth parameters
            OAuth2Parameters parameters = GDriveUtil.GetParameters(authToken);
            SpreadsheetsService service = GDriveUtil.GetSpreadsheetsService(parameters);

            //find spreadsheet by name
            SpreadsheetEntry spreadsheet = GDriveUtil.findSpreadsheetByName(sheetName, service);
            if (spreadsheet == null) //if the spreadsheet is not found
            {
                if (createNewSpreadsheets) //if the user has elected to create new spreadsheets
                {
                   List<string> worksheets = new List<string>();
                   if (!String.IsNullOrEmpty(worksheet))
                   {
                       worksheets.Add(worksheet); //create a 1-item list with the worksheet name
                   }
                    spreadsheet = CreateSpreadsheet.createNewSpreadsheet(this, authToken, sheetName, worksheets, false); //create the spreadsheet
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified spreadsheet not found.");
                    return;
                }
            }
            //find worksheet by name
            WorksheetEntry worksheetEntry = GDriveUtil.findWorksheetByName(worksheet, spreadsheet);
            if (worksheetEntry == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified worksheet not found.");
                return;
            }

            uint maxRow = 0;
            uint maxCol = 0;
            // set up dictionary<Cell address, cell input>
            // associate each input value with a corresponding address
            Dictionary<string, string> writeMap = constructWriteMap(addresses, data, rowsColumns, ref maxRow, ref maxCol, ref addressesOut);

                //expand worksheet if necessary
                if (worksheetEntry.Rows < maxRow)
                {

                        worksheetEntry.Rows = maxRow;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                if (worksheetEntry.Cols < maxCol)
                {

                        worksheetEntry.Cols = maxCol;
                        worksheetEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                        worksheetEntry.Update();

                }

                //set bounds of cell query
                CellQuery cellQuery = new CellQuery(worksheetEntry.CellFeedLink);
                cellQuery.MinimumColumn = 0;
                cellQuery.MinimumRow = 0;
                cellQuery.MaximumColumn = maxCol;
                cellQuery.MaximumRow = maxRow;
                cellQuery.ReturnEmpty = ReturnEmptyCells.yes;

                //retrieve cellfeed
                CellFeed cellFeed = service.Query(cellQuery);

                //convert cell entries to dictionary
               Dictionary<string,AtomEntry> cellDict = cellFeed.Entries.ToDictionary(k => k.Title.Text);

                CellFeed batchRequest = new CellFeed(cellQuery.Uri, service);

                //set up batchrequest
                foreach (KeyValuePair<string, string> entry in writeMap)
                {
                    AtomEntry atomEntry;
                    cellDict.TryGetValue(entry.Key, out atomEntry);
                    CellEntry batchEntry = atomEntry as CellEntry;
                    batchEntry.InputValue = entry.Value;
                    batchEntry.Etag = "*"; //required for compatibility with "new" google sheets (see:  http://stackoverflow.com/questions/22719170/updating-cell-in-google-spreadsheets-returns-error-missing-resource-version-id)
                    batchEntry.BatchData = new GDataBatchEntryData(GDataBatchOperationType.update);

                    batchRequest.Entries.Add(batchEntry);
                }
                CellFeed batchResponse = (CellFeed)service.Batch(batchRequest, new Uri(cellFeed.Batch));

                // Check the results
                bool isSuccess = true;
                foreach (CellEntry entry in batchResponse.Entries)
                {
                    string batchId = entry.BatchData.Id;
                    if (entry.BatchData.Status.Code != 200)
                    {
                        isSuccess = false;
                        GDataBatchStatus status = entry.BatchData.Status;
                    }
                }

                if (!isSuccess)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Update operations failed");
                }

            //output addresses
            DA.SetDataTree(0, addressesOut); //write addressesOut to first output parameter
        }
예제 #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Retrieve parameters

            GH_Structure <GH_Curve> c0 = new GH_Structure <GH_Curve>();
            GH_Structure <GH_Curve> c1 = new GH_Structure <GH_Curve>();
            Mesh   mesh0      = new Mesh();
            Mesh   mesh1      = new Mesh();
            double planeWidth = 0.01;
            int    divisions  = 2;
            bool   cornerType = true;
            double parallel   = 0.0;
            bool   screws     = true;

            DA.GetDataTree <GH_Curve>(0, out c0);
            DA.GetDataTree <GH_Curve>(1, out c1);
            DA.GetData(2, ref mesh0);
            DA.GetData(3, ref mesh1);
            DA.GetData(4, ref planeWidth);
            DA.GetData(5, ref divisions);
            DA.GetData(6, ref cornerType);
            DA.GetData(7, ref parallel);
            DA.GetData(8, ref screws);


            //Use curves as input
            if (c0.DataCount > 0 && (c0.DataCount == c1.DataCount))
            {
                List <Polyline> outlines0 = new List <Polyline>();
                List <Polyline> outlines1 = new List <Polyline>();

                var c0Enumerator = c0.GetEnumerator();
                var c1Enumerator = c1.GetEnumerator();

                while (c0Enumerator.MoveNext() && c1Enumerator.MoveNext())
                {
                    Object curve0 = c0Enumerator.Current;
                    Object curve1 = c1Enumerator.Current;
                }


                int n = c0.DataCount;


                foreach (GH_Curve ghc in c0.AllData(true))
                {
                    ghc.Value.TryGetPolyline(out Polyline p);
                    outlines0.Add(p);
                }

                foreach (GH_Curve ghc in c1.AllData(true))
                {
                    ghc.Value.TryGetPolyline(out Polyline p);
                    outlines1.Add(p);
                }


                //2.0 Setup theBox class

                TheBox[] boxes = new TheBox[n];

                Plane[][]      sidePlanes    = new Plane[n][];
                Plane[][]      topPlanes     = new Plane[n][];
                Polyline[][][] midOutlines0  = new Polyline[n][][];
                Polyline[][][] sideOutlines0 = new Polyline[n][][];

                for (int i = 0; i < n; i++)
                {
                    boxes[i] = new TheBox(outlines0[i], outlines1[i], planeWidth, new List <double> {
                        0.5
                    }, cornerType, parallel, divisions, i);

                    boxes[i].ConstructPlanes();
                    sidePlanes[i] = boxes[i].sidePlanes;
                    topPlanes[i]  = boxes[i].topPlanes;

                    boxes[i].ConstructOutlines();
                    sideOutlines0[i] = boxes[i].sideOutlines0;
                    midOutlines0[i]  = boxes[i].midOutlines0;
                }

                DA.SetDataTree(1, NGonsCore.GrasshopperUtil.IE2(sidePlanes));
                DA.SetDataTree(2, NGonsCore.GrasshopperUtil.IE2(topPlanes));
                DA.SetDataTree(3, NGonsCore.GrasshopperUtil.IE3(sideOutlines0));
                DA.SetDataTree(4, NGonsCore.GrasshopperUtil.IE3(midOutlines0));


                //Use meshes as input with its adjacency
            }
            else
            {
                //mesh0.Append(mesh1);

                Mesh[] meshBoxes = mesh0.ProjectPairsMesh(mesh1, 1);
                DA.SetDataList(0, meshBoxes);

                int n = meshBoxes.Length;
            }
        }
예제 #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //Input
            crvs.Clear();
            wid.Clear();
            col.Clear();
            bbox = new BoundingBox();

            // private void RunScript(Curve C, double R, int S, int t, int E, bool F, List<Interval> I, ref object A) {

            GH_Structure <GH_Curve> curve = NGonsCore.Clipper.DataAccessHelper.FetchTree <GH_Curve>(DA, "Curve");


            bool flag = false;


            foreach (GH_Curve c in curve.AllData(true))
            {
                crvs.Add(c.Value);
                bbox.Union(c.Boundingbox);
                flag = true;
            }
            if (flag)
            {
                GH_Structure <GH_Integer> width  = NGonsCore.Clipper.DataAccessHelper.FetchTree <GH_Integer>(DA, "Width");
                GH_Structure <GH_Colour>  colour = NGonsCore.Clipper.DataAccessHelper.FetchTree <GH_Colour>(DA, "Colour");



                //Width
                List <int> widthFlat = new List <int>(width.DataCount);
                foreach (var w in width.AllData(true))
                {
                    int val;
                    w.CastTo(out val);
                    widthFlat.Add(val);
                }

                if (widthFlat.Count == 0)
                {
                    widthFlat.Add(2);
                }

                for (int i = 0; i < this.crvs.Count; i++)
                {
                    this.wid.Add(widthFlat[i % widthFlat.Count]);
                }


                //Color
                List <System.Drawing.Color> colorFlat = new List <System.Drawing.Color>(colour.DataCount);
                foreach (var w in colour.AllData(true))
                {
                    System.Drawing.Color val;
                    w.CastTo(out val);
                    colorFlat.Add(val);
                }

                if (colorFlat.Count == 0)
                {
                    colorFlat.Add(System.Drawing.Color.Black);
                }

                for (int i = 0; i < this.crvs.Count; i++)
                {
                    this.col.Add(colorFlat[i % colorFlat.Count]);
                }
            }
            else
            {
                crvs.Clear();
                wid.Clear();
                col.Clear();
                bbox = new BoundingBox();
            }
        }