コード例 #1
0
 public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
 {
     DA.GetDataTree(0, out speckleObjects);
     speckleObjects.Graft(GH_GraftMode.GraftAll);
     this.Params = Params;
     (Parent as ExpandSpeckleObjectAsync).outputList = GetOutputList();
 }
コード例 #2
0
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            Parent.ClearRuntimeMessages();
            DA.GetDataTree(0, out speckleObjects);
            speckleObjects.Graft(GH_GraftMode.GraftAll);
            var names = Params.Output.Select(p => p.Name);

            Console.WriteLine("Previous names:{0}", string.Join(", ", names));
            this.Params = Params;
        }
コード例 #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (!hasSetData)
            {
                // First run: Save the tree and expire solution to force an update in the output params.

                // Get the data or abort.
                if (!DA.GetDataTree(0, out speckleObjects))
                {
                    return;
                }

                if (!speckleObjects.Any())
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The provided input has no data.");
                    return;
                }
                // Ensure only one object per path.
                speckleObjects.Graft(GH_GraftMode.GraftAll);

                // Update the output list
                outputList = GetOutputList();

                // Once data has been set, expire solution to update output params.
                hasSetData = true;
                ExpireSolution(true);
            }
            else
            {
                // Second run: Parameter output should have been updated in `beforeSolveInstance` with latest state.

                // Build the output dictionary
                var outputDict = CreateOutputDictionary();

                // Assign outputs.
                foreach (var key in outputDict.Keys)
                {
                    DA.SetDataTree(Params.IndexOfOutputParam(key), outputDict[key]);
                }

                // Reset state
                hasSetData     = false;
                speckleObjects = null;
            }
        }
コード例 #4
0
 public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
 {
     DA.GetDataTree(0, out speckleObjects);
     speckleObjects.Graft(GH_GraftMode.GraftAll);
     this.Params = Params;
 }
コード例 #5
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)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region get Input From GH Canvas
            GH_Structure <GH_Curve> inCurves = new GH_Structure <GH_Curve>();
            bool areCurvesOK = DA.GetDataTree(0, out inCurves);
            inputChecker.StopIfConversionIsFailed(areCurvesOK);
            GH_Structure <GH_Curve> ghCurves = new GH_Structure <GH_Curve>();
            ghCurves = inCurves.Duplicate();
            ghCurves.Graft(GH_GraftMode.GraftAll);
            ghCurves.Simplify(GH_SimplificationMode.CollapseAllOverlaps);

            GH_Structure <GH_Number> inDistances = new GH_Structure <GH_Number>();
            bool areDistancesOk = DA.GetDataTree(1, out inDistances);
            inputChecker.StopIfConversionIsFailed(areDistancesOk);
            GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>();
            ghDistances = ValuesAllocator.NumsDSFromCurves(ghCurves, inDistances, ghDistances);

            GH_Structure <GH_Plane> inPlanes = new GH_Structure <GH_Plane>();
            bool arePlanesOk = DA.GetDataTree(2, out inPlanes);
            inputChecker.StopIfConversionIsFailed(arePlanesOk);
            GH_Structure <GH_Plane> ghPlanes = new GH_Structure <GH_Plane>();
            ghPlanes = ValuesAllocator.PlanesDSFromCurves(ghCurves, inPlanes, ghPlanes);

            GH_Structure <GH_Integer> inCorners = new GH_Structure <GH_Integer>();
            bool areCornerssOk = DA.GetDataTree(3, out inCorners);
            inputChecker.StopIfConversionIsFailed(areCornerssOk);
            GH_Structure <GH_Integer> ghCorners = new GH_Structure <GH_Integer>();
            ghCorners = ValuesAllocator.IntegerDSFromCurves(ghCurves, inCorners, ghCorners);
            #endregion

            GH_Structure <GH_Curve> ghCurveOffset = new GH_Structure <GH_Curve>();
            double docTollerance = DocumentTolerance();

            int pathIndex = 0;
            foreach (GH_Path ghPath in ghCurves.Paths)
            {
                for (int i = 0; i < ghCurves.get_Branch(ghPath).Count; i++)
                {
                    CurveOffsetCornerStyle cornerStyle = CurveOffsetCornerStyle.None;
                    int cornerStyleInInt = ghCorners.get_DataItem(ghPath, i).Value;
                    GetCornerStyleFromInt(ref cornerStyleInInt, ref cornerStyle);

                    Curve  crv   = ghCurves.get_DataItem(ghPath, i).Value;
                    Plane  plane = ghPlanes.get_DataItem(ghPath, i).Value;
                    double dist  = ghDistances.get_DataItem(ghPath, i).Value;

                    List <Curve> resultingCurves = new List <Curve>();

                    resultingCurves.AddRange(crv.Offset(plane, dist, docTollerance, cornerStyle));
                    resultingCurves.AddRange(crv.Offset(plane, dist *= -1, docTollerance, cornerStyle));
                    foreach (Curve resultingCrv in resultingCurves)
                    {
                        GH_Curve ghResultingCrv = null;
                        if (GH_Convert.ToGHCurve(resultingCrv, GH_Conversion.Both, ref ghResultingCrv))
                        {
                            ghCurveOffset.Append(ghResultingCrv, ghPath);
                        }
                    }
                }
                pathIndex++;
            }

            DA.SetDataTree(0, ghCurveOffset);
        }
コード例 #6
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)
        {
            InputChecker inputChecker = new InputChecker(this);

            #region GetIputFromCanvas
            GH_Structure <GH_Brep> inGhBreps = new GH_Structure <GH_Brep>();
            bool areBrepsOk = DA.GetDataTree(0, out inGhBreps);
            inputChecker.StopIfConversionIsFailed(areBrepsOk);
            inGhBreps.Graft(GH_GraftMode.GraftAll);
            inGhBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps);

            GH_Structure <GH_Number> inGhDistances = new GH_Structure <GH_Number>();
            bool areDistancesOk = DA.GetDataTree(1, out inGhDistances);
            inputChecker.StopIfConversionIsFailed(areDistancesOk);
            GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>();
            ghDistances = ValuesAllocator.NumbersDSFromBreps(inGhBreps, inGhDistances, ghDistances);

            GH_Structure <GH_Boolean> inGhBothSides = new GH_Structure <GH_Boolean>();
            bool areBoolBothSidesOk = DA.GetDataTree(2, out inGhBothSides);
            inputChecker.StopIfConversionIsFailed(areBoolBothSidesOk);
            GH_Structure <GH_Boolean> ghBothSides = new GH_Structure <GH_Boolean>();
            ghBothSides = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhBothSides, ghBothSides);

            GH_Structure <GH_Boolean> inGhFlipNormals = new GH_Structure <GH_Boolean>();
            bool areBoolFlipNormalsOk = DA.GetDataTree(3, out inGhFlipNormals);
            inputChecker.StopIfConversionIsFailed(areBoolFlipNormalsOk);
            GH_Structure <GH_Boolean> ghFlipNormals = new GH_Structure <GH_Boolean>();
            ghFlipNormals = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhFlipNormals, ghFlipNormals);

            bool useParallel = false;
            DA.GetData <bool>(4, ref useParallel);

            double docTollerance = DocumentTolerance();
            #endregion

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

            if (useParallel)
            {
                this.Message = Constants.Constants.PARALLEL_MESSAGE;
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING);

                int processorCount = Environment.ProcessorCount - 1;
                //WORK IN PARALLEL
                ConcurrentDictionary <GH_Path, Brep> solidBrepsPA = new ConcurrentDictionary <GH_Path, Brep>();
                Parallel.ForEach(inGhBreps.Paths, new ParallelOptions {
                    MaxDegreeOfParallelism = processorCount
                },
                                 path =>
                {
                    Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value;
                    bool flipTheNormal  = ghFlipNormals.get_DataItem(path, 0).Value;
                    bool bothSide       = ghBothSides.get_DataItem(path, 0).Value;
                    double distance     = ghDistances.get_DataItem(path, 0).Value;
                    if (flipTheNormal)
                    {
                        distance *= -1;
                    }
                    foreach (var brepFace in brepToSolidify.Faces)
                    {
                        solidBrepsPA[path] = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true);
                    }
                });
                foreach (KeyValuePair <GH_Path, Brep> keyValueBrep in solidBrepsPA)
                {
                    GH_Brep ghBrep = null;
                    if (GH_Convert.ToGHBrep(keyValueBrep.Value, GH_Conversion.Both, ref ghBrep))
                    {
                        ghSolidBreps.Append(ghBrep, keyValueBrep.Key);
                    }
                    else
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Conversion Failed");
                        return;
                    }
                }
            }//End Parallel Computation
            else
            {
                this.Message = Constants.Constants.SERIAL_MESSAGE;

                foreach (GH_Path path in inGhBreps.Paths)
                {
                    Brep   brepToSolidify = inGhBreps.get_DataItem(path, 0).Value;
                    bool   flipTheNormal  = ghFlipNormals.get_DataItem(path, 0).Value;
                    bool   bothSide       = ghBothSides.get_DataItem(path, 0).Value;
                    double distance       = ghDistances.get_DataItem(path, 0).Value;
                    if (flipTheNormal)
                    {
                        distance *= -1;
                    }
                    foreach (var brepFace in brepToSolidify.Faces)
                    {
                        Brep    solidBrep = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true);
                        GH_Brep ghBrep    = null;
                        if (GH_Convert.ToGHBrep(solidBrep, GH_Conversion.Both, ref ghBrep))
                        {
                            ghSolidBreps.Append(ghBrep, path);
                        }
                        else
                        {
                            this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion Failed");
                            return;
                        }
                    }
                }
            }//End Serial Computation

            #region SendDataToCanvas
            ghSolidBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps);
            DA.SetDataTree(0, ghSolidBreps);
            #endregion
        }//end SolveInstance