예제 #1
0
        public DataTree <Plane> GetNexorPlanes()
        {
            DataTree <Plane> dt = new DataTree <Plane>();



            foreach (var n in this._nexors)
            {
                if (n.isNexor != 0)
                {
                    var path = new Grasshopper.Kernel.Data.GH_Path(n.idNested[0], n.idNested[1]);



                    dt.AddRange(n.foPl, path);
                    dt.Add(n.ePl, path);
                    dt.Add(n.fcPl_foPl, path);
                    dt.AddRange(n.fcPl, path);

                    dt.Add(n.ePl90Offset, path);



                    dt.Add(n.endPl0, path);
                    dt.Add(n.endPl1, path);
                }
            }
            return(dt);
        }
예제 #2
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 <string> _buildingFiles       = new List <string>();
            List <string> _buildingBinaryFiles = new List <string>();
            int           _val_  = 0;
            bool          runIt_ = false;

            DA.GetDataList(0, _buildingFiles);
            DA.GetDataList(1, _buildingBinaryFiles);
            DA.GetData(2, ref _val_);
            DA.GetData(3, ref runIt_);

            // Unwrap variables
            List <FacadeVariable> variables = BuildingFacadeOutputMapping();

            if (runIt_)
            {
                DataTree <string>         fileNameTree = new DataTree <string>();
                DataTree <FacadeVariable> variableTree = new DataTree <FacadeVariable>();
                DataTree <double>         dataTree     = new DataTree <double>();

                // Warning!
                if (_val_ >= variables.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Variable is out of range, check description of the input.");
                    return;
                }

                for (int i = 0; i < _buildingFiles.Count; i++)
                {
                    GHD.GH_Path pth = new GHD.GH_Path(i);
                    try
                    {
                        string edxName = Path.GetFileNameWithoutExtension(_buildingFiles[i]);
                        string edtName = Path.GetFileNameWithoutExtension(_buildingBinaryFiles[i]);

                        if (edxName == edtName)
                        {
                            List <double> results = BuildingOutput.ParseBinBuilding(_buildingFiles[i], _buildingBinaryFiles[i], (int)variables[_val_], Direction);

                            fileNameTree.Add(Path.GetFileName(_buildingFiles[i]), pth);
                            variableTree.Add(variables[_val_], pth);
                            dataTree.AddRange(results, pth);
                        }
                    }
                    catch
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Something is wrong in output dynamic folder.\nPlease, make sure EDT length is equals to EDX length.");
                        continue;
                    }
                }

                DA.SetDataTree(0, fileNameTree);
                DA.SetDataTree(1, variableTree);
                DA.SetDataTree(2, dataTree);
            }
        }
        /// <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 <string> _buildingFiles = new List <string>();
            int           _val_          = 0;
            bool          runIt_         = false;

            DA.GetDataList(0, _buildingFiles);
            DA.GetData(1, ref _val_);
            DA.GetData(2, ref runIt_);


            // Unwrap variables
            var variables = BuildingOutputTypeMapping();


            if (runIt_)
            {
                DataTree <string>             valueTree        = new DataTree <string>();
                DataTree <string>             dateTree         = new DataTree <string>();
                DataTree <string>             timeTree         = new DataTree <string>();
                DataTree <BuldingDatVariable> variableNameTree = new DataTree <BuldingDatVariable>();

                // Warning!
                if (_val_ >= variables.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Variable is out of range, check description of the input.");
                    return;
                }

                //TO DO: Generic class for csv method
                for (int i = 0; i < _buildingFiles.Count; i++)
                {
                    GHD.GH_Path pth = new GHD.GH_Path(i);

                    valueTree.AddRange(ReceptorOutput.GetValueFromCsv(_buildingFiles[i], (int)variables[_val_]), pth);
                    dateTree.AddRange(ReceptorOutput.GetValueFromCsv(_buildingFiles[i], (int)BuldingDatVariable.Date), pth);
                    timeTree.AddRange(ReceptorOutput.GetValueFromCsv(_buildingFiles[i], (int)BuldingDatVariable.Time), pth);
                    variableNameTree.Add(variables[_val_], pth);
                }

                DA.SetDataTree(0, variableNameTree);
                DA.SetDataTree(1, dateTree);
                DA.SetDataTree(2, timeTree);
                DA.SetDataTree(3, valueTree);
            }
        }
예제 #4
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)
        {
            // INPUT
            // declaration
            string        _XML     = String.Empty;
            List <string> _tagName = new List <string>();

            DA.GetData(0, ref _XML);
            DA.GetDataList(1, _tagName);

            // actions
            XmlDocument xmlDoc = new XmlDocument();
            //declare tree
            DataTree <string> intTree = new DataTree <string>();

            xmlDoc.LoadXml(_XML);

            if (_tagName != null)
            {
                try
                {
                    //set up tree
                    for (int i = 0; i < _tagName.Count; i++)
                    {
                        GHD.GH_Path pth = new GHD.GH_Path(i);

                        var innerTextData = xmlDoc.GetElementsByTagName(_tagName[i])[0].InnerText;
                        intTree.Add(innerTextData, pth);
                    }

                    // output
                    DA.SetDataTree(0, intTree);
                }
                catch
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide a valid keyword.");
                    return;
                }
            }
        }
예제 #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)
        {
            List <string> gridFiles       = new List <string>();
            List <string> gridBinaryFiles = new List <string>();
            string        type            = GridOutputFolderType.ATMOSPHERE;
            int           var             = 0;
            int           loc             = 0;
            bool          runIt           = false;

            DA.GetDataList(0, gridFiles);
            DA.GetDataList(1, gridBinaryFiles);
            DA.GetData(2, ref type);
            DA.GetData(3, ref var);
            DA.GetData(4, ref loc);
            DA.GetData(5, ref runIt);

            GetNameOfPlaneInput();
            ChangeVariableDescription(type);


            if (runIt)
            {
                var    variables        = GetVariable();
                int    selectedVariable = 0;
                object varName          = null;
                string report           = String.Empty;

                switch (type)
                {
                case GridOutputFolderType.ATMOSPHERE:
                    var atmosphere = variables[0] as List <AtmosphereOutput>;
                    // Warning
                    if (var >= atmosphere.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Atmosphere variable is out of range, check description of the input.");
                        return;
                    }
                    selectedVariable = (int)(atmosphere)[var];
                    varName          = atmosphere[var];
                    break;

                case GridOutputFolderType.POLLUTANTS:
                    var pollutant = variables[1] as List <PollutantsOutput>;
                    // Warning
                    if (var >= pollutant.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Pollutants variable is out of range, check description of the input.");
                        return;
                    }
                    selectedVariable = (int)(pollutant)[var];
                    varName          = pollutant[var];
                    break;

                case GridOutputFolderType.RADIATION:
                    var radiation = variables[2] as List <RadiationOutput>;
                    // Warning
                    if (var >= radiation.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Radiation variable is out of range, check description of the input.");
                        return;
                    }
                    selectedVariable = (int)(radiation)[var];
                    varName          = radiation[var];
                    break;

                case GridOutputFolderType.SOIL:
                    var soil = variables[3] as List <SoilOutput>;
                    // Warning
                    if (var >= soil.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Soil variable is out of range, check description of the input.");
                        return;
                    }
                    selectedVariable = (int)(soil)[var];
                    varName          = soil[var];
                    break;

                case GridOutputFolderType.SURFACE:
                    var surface = variables[4] as List <SurfaceOutput>;
                    // Warning
                    if (var >= surface.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Soil variable is out of range, check description of the input.");
                        return;
                    }
                    FlatResults();
                    loc = 0;
                    selectedVariable = (int)(surface)[var];
                    varName          = surface[var];
                    break;

                case GridOutputFolderType.SOLAR_ACCESS:
                    var solar = variables[5] as List <SolarAccessOutput>;
                    // Warning
                    if (var >= solar.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Solar access variable is out of range, check description of the input.");
                        return;
                    }
                    FlatResults();
                    selectedVariable = (int)(solar)[var];
                    varName          = solar[var];
                    break;

                case GridOutputFolderType.VEGETATIONS:
                    var vegetation = variables[6] as List <VegetationOutput>;
                    // Warning
                    if (var >= vegetation.Count)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Vegetation variable is out of range, check description of the input.");
                        return;
                    }
                    selectedVariable = (int)(vegetation)[var];
                    varName          = vegetation[var];
                    break;
                }

                DataTree <string> fileNameTree = new DataTree <string>();
                DataTree <object> variableTree = new DataTree <object>();
                DataTree <double> dataTree     = new DataTree <double>();

                for (int i = 0; i < gridFiles.Count; i++)
                {
                    GHD.GH_Path pth = new GHD.GH_Path(i);
                    try
                    {
                        string edxName = Path.GetFileNameWithoutExtension(gridFiles[i]);
                        string edtName = Path.GetFileNameWithoutExtension(gridBinaryFiles[i]);

                        if (edxName == edtName)
                        {
                            List <double> results = GridOutput.ParseBinGrid(gridFiles[i], gridBinaryFiles[i], selectedVariable, loc, Direction);


                            if (results == null)
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Location of plane is out of range.");
                                return;
                            }

                            report = GridOutput.GetReport(gridFiles[i]);
                            DA.SetData(0, report);
                            Vector3d vector = GridOutput.GetVectorPlaneFromEdx(gridFiles[i], Direction, loc);
                            DA.SetData(1, vector);

                            fileNameTree.Add(Path.GetFileName(gridFiles[i]), pth);
                            variableTree.Add(varName, pth);
                            dataTree.AddRange(results, pth);
                        }
                        else
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please, check output folder you are reading. EDT file name and EDX file name should be the same.");
                        }
                    }
                    catch
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Something is wrong in output dynamic folder.\nPlease, make sure EDT length is equals to EDX length.");
                        continue;
                    }
                }

                DA.SetDataTree(2, fileNameTree);
                DA.SetDataTree(3, variableTree);
                DA.SetDataTree(4, dataTree);
            }
        }
예제 #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)
        {
            List <string> _receptorPath         = new List <string>();
            int           _receptorHeightIndex_ = 0;
            int           _val_  = 0;
            bool          runIt_ = false;

            DA.GetDataList(0, _receptorPath);
            DA.GetData(1, ref _receptorHeightIndex_);
            DA.GetData(2, ref _val_);
            DA.GetData(3, ref runIt_);

            // Unwrap variables
            var variables = ReceptorOutputTypeMapping(_value);

            if (_value == ReceptorFileType.SOIL)
            {
                Params.Input[1].Name        = "_receptorHeightIndex_";
                Params.Input[1].NickName    = "_receptorHeightIndex_";
                Params.Input[1].Description = "Use this index to a get value at different height. Value depends on your model.";
                Params.Input[2].Name        = "_soilVariable_";
                Params.Input[2].NickName    = "_soilVariable_";
                Params.Input[2].Description = "Connect a number:\n0 = Temperature °C\n1= VolumeWaterContent m3/m-3\n2 = TemperatureDiffusifity *10e6";

                Params.Output[0].Description = "Negative height (cm).";
            }
            else if (_value == ReceptorFileType.FLUX)
            {
                Params.Input[1].Name        = "-";
                Params.Input[1].NickName    = "-";
                Params.Input[1].Description = "-";
                _receptorHeightIndex_       = 0;

                Params.Output[0].Description = "Height of measure (m).";

                Params.Input[2].Name        = "_fluxVariable_";
                Params.Input[2].NickName    = "_fluxVariable_";
                Params.Input[2].Description = "Connect a number:\n0 = SurfaceTemperature °C\n" +
                                              "1 = ChangeSurfaceTemperature °C/h\n" +
                                              "2 = SurfaceHumidity g/kg\n" +
                                              "3 = HorizontalWindSpeedaboveSurface m/s\n" +
                                              "4 = VerticalComponentWindSpeedaboveSurfaceZ m/s\n" +
                                              "5 = AirTemperatureofGridPoint °C\n" +
                                              "6 = SensibleHeatFlux W/m²\n" +
                                              "7 = LatentHeatFlux W/m²\n" +
                                              "8 = SoilHeatFlux W/m²\n" +
                                              "9 = MasSExchangeCoefficient m²/s\n" +
                                              "10 = TurbulentExchangeCoefficient m²/s\n" +
                                              "11 = MaxDirectShortwaverRadiation W/m²\n" +
                                              "12 = MaxDiffuseShortwaveRadiation W/m²\n" +
                                              "13 = MaxReflectedShortwaveRadiation W/m²\n" +
                                              "14 = LongwaveRadiationBudgetSrf W/m²";
            }
            else
            {
                Params.Input[1].Name        = "_receptorHeightIndex_";
                Params.Input[1].NickName    = "_receptorHeightIndex_";
                Params.Input[1].Description = "Use this index to a get value at different height. Value depends on your model..";
                Params.Input[2].Name        = "_atmosphereVariable_";
                Params.Input[2].NickName    = "_atmosphereVariable_";

                Params.Output[0].Description = "Height of measure (m).";

                Params.Input[2].Description = "Connect a number:\n0 = WindSpeed m/s\n" +
                                              "1 = WindDirection °\n" +
                                              "2 = AirTemperature °C\n" +
                                              "3 = DiffTemperature °C/h\n" +
                                              "4 = SpecificHumidity g/kg\n" +
                                              "5 = RelativeHumidity %\n" +
                                              "6 = VerticalExchangeCoefficient m²/s\n" +
                                              "7 = VerticalKmNormed -\n" +
                                              "8 = HorizontalExchangeCoefficient m²/s\n" +
                                              "9 = TurbulentKineticEnergy m²/s²\n" +
                                              "10 = DissipationTKE m³/s²\n" +
                                              "11 = MeanRadiantTemperature °C\n" +
                                              "12 = LeafAreaDensity m²/m³\n" +
                                              "13 = LeafFoliageTemperature °C\n" +
                                              "14 = SensibleHeatFluxFromLeaf W/m²2\n" +
                                              "15 = LatentHeatFluxFromLeaf W/m²2\n" +
                                              "16 = StomataResistance m/s\n" +
                                              "17 = CO2 mg/m³\n" +
                                              "18 = CO2Flux mg/(kg*s)\n" +
                                              "19 = ShortwaveDirectRadiation W/m²\n" +
                                              "20 = ShortwaveDiffuseRadiation W/m²\n" +
                                              "21 = PressurePerturbation Pa\n" +
                                              "22 = MassConcentration mg/m³\n" +
                                              "23 = MechanicalProductionTKE -\n" +
                                              "24 = AirTemperatureChangeLongwave K/h\n" +
                                              "25 = SkyViewFactorBuilding\n -" +
                                              "26 = SkyViewFactorBuildingLeaf -";
            }

            if (runIt_)
            {
                DataTree <string> valueTree = new DataTree <string>();
                DataTree <string> dateTree  = new DataTree <string>();
                DataTree <string> timeTree  = new DataTree <string>();

                // Warning!
                if (_val_ >= variables.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Variable is out of range, check description of the input.");
                    return;
                }

                double receptorHeight = 0;

                for (int i = 0; i < _receptorPath.Count; i++)
                {
                    IEnumerable <string> files          = ReceptorOutput.GetAllReceptorFiles(_receptorPath[i], _value);
                    List <string>        selectedValues = new List <string>();

                    GHD.GH_Path pth = new GHD.GH_Path(i);

                    if (_value != ReceptorFileType.FLUX)
                    {
                        foreach (string f in files)
                        {
                            // Warning
                            if (_receptorHeightIndex_ >= ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Z).Count)
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Z Index does not exist.");
                                return;
                            }

                            string val = ReceptorOutput.GetValueFromCsv(f, variables[_val_])[_receptorHeightIndex_];

                            if (val == SOIL_NULL)
                            {
                                val = ZERO;
                            }
                            selectedValues.Add(val);
                            dateTree.Add(ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Date)[_receptorHeightIndex_], pth);
                            timeTree.Add(ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Time)[_receptorHeightIndex_], pth);

                            receptorHeight = Convert.ToDouble(ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Z)[_receptorHeightIndex_]);
                        }

                        valueTree.AddRange(selectedValues, pth);
                    }
                    else
                    {
                        foreach (string f in files)
                        {
                            valueTree.AddRange(ReceptorOutput.GetValueFromCsv(f, variables[_val_]), pth);
                            dateTree.AddRange(ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Date), pth);
                            timeTree.AddRange(ReceptorOutput.GetValueFromCsv(f, (int)ReceptorAtmosphereVariable.Time), pth);
                        }
                    }
                }

                DA.SetData(0, receptorHeight);
                DA.SetDataTree(1, dateTree);
                DA.SetDataTree(2, timeTree);
                DA.SetDataTree(3, valueTree);
            }
        }
예제 #7
0
        //Main Methods

        public DataTree <Polyline> Beams2(NGonsCore.MeshProps p)
        {
            DataTree <Polyline> dt = new DataTree <Polyline>();

            try
            {
                //Edge and End Planes
                Dictionary <int, int> E = p.M._EAll();//mesh edge - ngon edge
                for (int i = 0; i < p.M._countF(); i++)
                {
                    int[] fe = p.M._fe(i);


                    for (int j = 0; j < p.M._countE(i); j++)
                    {
                        if (this[i, j].isNexor != 0)
                        {
                            int e = E[fe[j]];//get ngon Edge by local meshedge
                            this[i, j].ePl90       = p.ePl90[e].ChangeOrigin(this[i, j].line.Center());
                            this[i, j].ePl         = p.ePl[e].ChangeOrigin(this[i, j].line.Center());
                            this[i, j].ePl90Offset = this[i, j].ePl90.MovePlanebyAxis(depth);

                            int[] o     = p.M._OppositeFE(i, j);
                            int   i_    = (o[0] != -1) ? o[0] : i;
                            int   j_    = (o[1] != -1) ? o[1] : j;
                            int   naked = (o[0] != -1) ? 1 : -1;


                            Plane ePl0 = this[i, j].ePl;
                            Plane ePl1 = new Plane(this[i, j].ePl.Origin, this[i, j].ePl.YAxis, this[i, j].ePl.ZAxis);
                            Plane cPl  = p.fPl[i];
                            Plane oPl  = p.fPl[i_];

                            Point3d originC = PlaneUtil.PlanePlanePlane(ePl0, ePl1, cPl);
                            Point3d originO = PlaneUtil.PlanePlanePlane(ePl0, ePl1, oPl);

                            //Plane correspoding to current face plane
                            Plane    fcPl   = p.fePl[i][j].ChangeOrigin(originC);
                            Plane    fcPl90 = p.fePl90[i][j].ChangeOrigin(originC);
                            Vector3d v0     = -fcPl.ZAxis * offset0 * scale;
                            Vector3d v1     = -fcPl.YAxis * plateThickness;

                            Plane fcPl0 = fcPl90;
                            //this[i, j].fcPl.Add(fcPl90);
                            this[i, j].fcPl.Add(fcPl.Translation(v0 * extend));
                            this[i, j].fcPl.Add(fcPl90.Translation(v0 + v1));
                            this[i, j].fcPl.Add(this[i, j].ePl.Translation(v0 * 2));

                            if (i == 10)
                            {
                                //Line line = new Line(originO.zy);
                                //this[i, j].fcPl.Bake();
                            }

                            //Plane corresponding to opposite plane
                            Plane foPl   = p.fePl[i_][j_].ChangeOrigin(originO);
                            Plane foPl90 = p.fePl90[i_][j_].ChangeOrigin(originO);
                            v0 = -foPl.ZAxis * offset0 * scale * naked;//for naked opposite - do i need to flip?
                            v1 = -foPl.YAxis * plateThickness;



                            this[i, j].foPl.Add(this[i, j].ePl.Translation(v0 * 2));
                            this[i, j].foPl.Add(foPl90.Translation(v0 + v1));
                            this[i, j].foPl.Add(foPl.Translation(v0 * extend));
                            //this[i, j].foPl.Add(foPl90);
                            Plane foPl3 = foPl90;


                            //Average plane for chamfer middle part of the beam

                            Line l1 = PlaneUtil.PlanePlane(fcPl90, this[i, j].fcPl[0]);
                            Line l0 = PlaneUtil.PlanePlane(this[i, j].foPl[2], foPl90);

                            this[i, j].fcPl_foPl = new Plane((l0.Center() + l1.Center()) * 0.5, l0.Direction, l0.Center() - l1.Center());



                            //End Planes - next edge opposite
                            int   ne = E[fe.Next(j)];                                                                                                                                                          //get next ngon edge
                            int[] no = p.M._OppositeFE(i, (j + 1).Wrap(p.M._countE(i)));                                                                                                                       //get next opposite edge
                            this[i, j].endPl0 = (no[0] != -1) ? this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[no[0], no[1]].line.Center()) : this[i, j].endPl0 = p.ePl[ne].ChangeOrigin(this[i, j].line.To); //change origin because planes are located at mesh edge
                            this[i, j].endPl0 = this[i, j].endPl0.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center());                                                                                      //move towards the center

                            //End Planes - prev edge opposite
                            int   pe = E[fe.Prev(j)];                                                                                                                    //get previous ngon edge
                            int[] po = p.M._OppositeFE(i, (j - 1).Wrap(p.M._countE(i)));                                                                                 ////get prev opposite edge
                            this[i, j].endPl1 = (po[0] != -1) ? p.ePl[pe].ChangeOrigin(this[po[0], po[1]].line.Center()) : p.ePl[pe].ChangeOrigin(this[i, j].line.From); //change origin because planes are located at mesh edge
                            this[i, j].endPl1 = this[i, j].endPl1.MovePlanebyAxis(offset0 * 2, this[i, j].line.Center());                                                //move towards the center
                        }//is nexor
                    }//for j
                }//for i



                //Nodes profiles
                for (int i = 0; i < p.M._countF(); i++)
                {
                    int[] fe = p.M._fe(i);
                    for (int j = 0; j < p.M._countE(i); j++)
                    {
                        if (this[i, j].isNexor != 0)
                        {
                            List <Polyline> cutters0 = new List <Polyline>();



                            List <Plane> sidePlanes = new List <Plane>();
                            sidePlanes.AddRange(this[i, j].fcPl);
                            sidePlanes.Add(this[i, j].ePl90Offset);
                            sidePlanes.AddRange(this[i, j].foPl);
                            sidePlanes.Add(this[i, j].fcPl_foPl);

                            if ((!p.M.IsNaked(fe[j])))//
                            {
                                //End Planes - next edge opposite
                                int[] op = p.M._OppositeFE(i, j, -1);
                                int[] on = p.M._OppositeFE(i, j, 1);



                                int[] no = p.M._OppositeFE(i, (j + 1).Wrap(fe.Length)); //for end parts
                                int[] po = p.M._OppositeFE(i, (j - 1).Wrap(fe.Length)); //for end parts


                                //First profile
                                Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes);

                                //Plane sectionPlaneP0 = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].ePl : this[op[0], op[1]].fcPl[0];
                                if (op[0] != -1)
                                {
                                    p0 = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes);
                                }



                                List <Plane> sidePlanes1A = new List <Plane>();
                                sidePlanes1A.AddRange(this[i, j].fcPl);
                                sidePlanes1A.Add(this[i, j].ePl90Offset);
                                sidePlanes1A.Add(this[i, j].foPl[0]);
                                sidePlanes1A.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness));
                                sidePlanes1A.Add(this[i, j].fcPl_foPl);

                                Plane sectionPlaneP3A_ = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].foPl[0] : this[op[0], op[1]].foPl[0];
                                Plane sectionPlaneP3A  = p.M.IsNaked(fe.Next(j)) ? this[i, (j + 1).Wrap(fe.Length)].fcPl[2] : this[op[0], op[1]].foPl[0];

                                if (p.M.IsNaked(fe.Next(j)) && (p.M.TopologyEdges.EdgeLine(fe.Next(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Next(j)).From.Z < z))
                                {
                                    sectionPlaneP3A_  = ground;
                                    this[i, j].endPl0 = ground;
                                }


                                List <Plane> sidePlanes1BExtended = new List <Plane>();
                                sidePlanes1BExtended.Add(this[i, j].fcPl[0]);
                                sidePlanes1BExtended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true));
                                sidePlanes1BExtended.Add(this[i, j].foPl[0]);

                                sidePlanes1BExtended.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness));
                                sidePlanes1BExtended.Add(this[i, j].fcPl_foPl);

                                Polyline p2A  = PolylineUtil.PolylineFromPlanes(this[op[0], op[1]].fcPl[0], sidePlanes1A);
                                Polyline p3A  = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1A);//Top Removal - Inner
                                Polyline p3A_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A_, sidePlanes1A);

                                Polyline p3A_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3A, sidePlanes1BExtended); //1
                                cutters0.Add(p3A_Extended);


                                this[i, j].profiles.Add(p2A);
                                this[i, j].profiles.Add(p3A_);


                                if (p.M.IsNaked(fe.Next(j)))
                                {
                                    this[i, j].endPl0 = sectionPlaneP3A_;
                                }


                                if (no[0] != -1)//i == 20 && j == 1 &&
                                {
                                    List <Plane> sidePlanes2 = new List <Plane>();
                                    sidePlanes2.AddRange(this[i, j].fcPl);
                                    sidePlanes2.Add(this[i, j].ePl90Offset);
                                    sidePlanes2.Add(this[i, j].foPl[0]);
                                    sidePlanes2.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness));
                                    sidePlanes2.Add(this[i, j].fcPl_foPl);

                                    List <Plane> sidePlanes2Extended = new List <Plane>();
                                    sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false));
                                    sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true));
                                    sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false));
                                    sidePlanes2Extended.Add(this[no[0], no[1]].foPl[1].MovePlanebyAxis(plateThickness));
                                    sidePlanes2Extended.Add(this[i, j].fcPl_foPl);



                                    Polyline p4A          = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0, sidePlanes2);                                                                   //Top Removal - End
                                    Polyline p4A_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl0.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End - 0
                                    cutters0.Insert(0, p4A_Extended);



                                    this[i, j].profiles.Add(p3A);
                                    this[i, j].profiles.Add(p4A);
                                }



                                //Second profile
                                Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes);

                                //Plane sectionPlaneP1 = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].ePl : this[on[0], on[1]].fcPl[0];
                                if (on[0] != -1)
                                {
                                    p1 = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes);
                                }


                                List <Plane> sidePlanes1B = new List <Plane>();
                                sidePlanes1B.AddRange(this[i, j].fcPl);
                                sidePlanes1B.Add(this[i, j].ePl90Offset);
                                sidePlanes1B.Add(this[i, j].foPl[0]);
                                sidePlanes1B.Add(this[i, j].foPl[1].MovePlanebyAxis(plateThickness));
                                sidePlanes1B.Add(this[i, j].fcPl_foPl);



                                Plane sectionPlaneP3B_ = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].foPl[0] : this[on[0], on[1]].foPl[0];
                                Plane sectionPlaneP3B  = p.M.IsNaked(fe.Prev(j)) ? this[i, (j - 1).Wrap(fe.Length)].fcPl[2] : this[on[0], on[1]].foPl[0];
                                if (p.M.IsNaked(fe.Prev(j)) && (p.M.TopologyEdges.EdgeLine(fe.Prev(j)).To.Z < z || p.M.TopologyEdges.EdgeLine(fe.Prev(j)).From.Z < z))
                                {
                                    sectionPlaneP3B_  = ground;
                                    this[i, j].endPl1 = ground;
                                    //p.M.TopologyEdges.EdgeLine(fe[j]).Center().Bake();
                                }

                                Polyline p2B  = PolylineUtil.PolylineFromPlanes(this[on[0], on[1]].fcPl[0], sidePlanes1B);
                                Polyline p3B  = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1B);//Top Removal - Inner
                                Polyline p3B_ = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B_, sidePlanes1B);

                                Polyline p3B_Extended = PolylineUtil.PolylineFromPlanes(sectionPlaneP3B, sidePlanes1BExtended);//Top Removal - Inner2
                                cutters0.Add(p3B_Extended);


                                this[i, j].profiles.Add(p2B);
                                this[i, j].profiles.Add(p3B_);



                                if (p.M.IsNaked(fe.Prev(j)))
                                {
                                    this[i, j].endPl1 = sectionPlaneP3B_;
                                }



                                if (po[0] != -1)//i == 20 && j == 1 &&
                                {
                                    List <Plane> sidePlanes2 = new List <Plane>();
                                    sidePlanes2.AddRange(this[i, j].fcPl);
                                    sidePlanes2.Add(this[i, j].ePl90Offset);
                                    sidePlanes2.Add(this[i, j].foPl[0]);
                                    sidePlanes2.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness));
                                    sidePlanes2.Add(this[i, j].fcPl_foPl);

                                    List <Plane> sidePlanes2Extended = new List <Plane>();
                                    sidePlanes2Extended.Add(this[i, j].fcPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false));
                                    sidePlanes2Extended.Add(this[i, j].ePl90Offset.MovePlanebyAxis(this.depth * 2, this[i, j].line.Center(), 2, true));
                                    sidePlanes2Extended.Add(this[i, j].foPl[0].MovePlanebyAxis(this.plateThickness, this[i, j].line.Center(), 2, false));
                                    sidePlanes2Extended.Add(this[po[0], po[1]].foPl[1].MovePlanebyAxis(plateThickness));
                                    sidePlanes2Extended.Add(this[i, j].fcPl_foPl);


                                    Polyline p4B          = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1, sidePlanes2);                                                                   //Top Removal - End
                                    Polyline p4B_Extended = PolylineUtil.PolylineFromPlanes(this[i, j].endPl1.MovePlanebyAxis(0.00, this[i, j].line.Center(), 2, false), sidePlanes2Extended); //Top Removal - End //3
                                    cutters0.Add(p4B_Extended);
                                    //p4B_Extended.Bake();
                                    //p2.Bake();
                                    //p3.Bake();
                                    //p4.Bake();


                                    this[i, j].profiles.Add(p4B);
                                    this[i, j].profiles.Add(p3B);
                                }



                                this[i, j].profiles.Add(p0);
                                this[i, j].profiles.Add(p1);
                                //End profile
                            }
                            else if (this[i, j].isNexor == 1)
                            {
                                List <Plane> sidePlanesNaked = new List <Plane>();
                                sidePlanesNaked.AddRange(this[i, j].fcPl);
                                sidePlanesNaked.Add(this[i, j].ePl90Offset);
                                sidePlanesNaked.Add(this[i, j].foPl[0]);
                                sidePlanesNaked.Add(this[i, j].fcPl_foPl);

                                Plane planeA = (this[i, j].endPl0.Origin.Z < z) ? ground : this[i, j].endPl0;
                                Plane planeB = (this[i, j].endPl1.Origin.Z < z) ? ground : this[i, j].endPl1;

                                if (this[i, j].endPl0.Origin.Z < z)
                                {
                                    this[i, j].endPl0 = ground;
                                }
                                if (this[i, j].endPl1.Origin.Z < z)
                                {
                                    this[i, j].endPl1 = ground;
                                }



                                Polyline p0 = PolylineUtil.PolylineFromPlanes(planeA, sidePlanesNaked);
                                Polyline p1 = PolylineUtil.PolylineFromPlanes(planeB, sidePlanesNaked);

                                this[i, j].profiles.Add(p0);
                                this[i, j].profiles.Add(p1);
                            }
                            else if (this[i, j].isNexor == -1)
                            {
                                List <Plane> sidePlanesNaked = new List <Plane>();

                                sidePlanesNaked.Add(this[i, j].ePl90Offset);
                                sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[2]);
                                sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[1]);
                                sidePlanesNaked.Add(this[i, (j + 1).Wrap(fe.Length)].fcPl[0]);
                                sidePlanesNaked.Add(this[i, j].fcPl_foPl);
                                sidePlanesNaked.AddRange(this[i, (j - 1).Wrap(fe.Length)].fcPl);


                                this[i, j].endPl0 = this[i, (j + 1).Wrap(fe.Length)].fcPl[0];
                                this[i, j].endPl1 = this[i, (j - 1).Wrap(fe.Length)].fcPl[0];



                                Polyline p0 = PolylineUtil.PolylineFromPlanes(this[i, j].fcPl[0], sidePlanesNaked);
                                Polyline p1 = PolylineUtil.PolylineFromPlanes(this[i, j].foPl[0], sidePlanesNaked);
                                //p0.Bake();
                                //p1.Bake();
                                this[i, j].profiles.Add(p0);
                                this[i, j].profiles.Add(p1);
                                //p0.Bake();
                                //p1.Bake();
                            }

                            this[i, j].CNC_Cuts.AddRange(cutters0, new Grasshopper.Kernel.Data.GH_Path(i, j));
                        }
                    }
                }



                foreach (var n in this._nexors)
                {
                    if (n.isNexor != 0)
                    {
                        var path = new Grasshopper.Kernel.Data.GH_Path(n.idNested[0], n.idNested[1]);
                        if (n.profiles.Count > 0)
                        {
                            dt.AddRange(n.profiles, path);
                        }
                    }
                }
            } catch (Exception e)
            {
                Rhino.RhinoApp.WriteLine(e.ToString());
            }
            return(dt);
        }
예제 #8
0
        public DataTree <Polyline> Cuts()
        {
            DataTree <Polyline> dt = new DataTree <Polyline>();



            //Create end cuts
            for (int i = 0; i < this._nexors.Count; i++)
            {
                if (this._nexors[i].isNexor != 0)
                {
                    var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2);

                    //1. Get bisector planes
                    List <Plane> sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].fcPl[2],
                        this._nexors[i].endPl0,
                        this._nexors[i].foPl[0],
                        this._nexors[i].endPl1
                    };

                    Polyline outline     = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes);
                    Plane[]  bisectors   = outline.PolylineBisectors();
                    Plane    higherPlane = (this._nexors[i].fcPl[1].Origin.DistanceToSquared(this._nexors[i].ePl90Offset.Origin) > this._nexors[i].foPl[1].Origin.DistanceToSquared(this._nexors[i].ePl90Offset.Origin)) ? this._nexors[i].fcPl[1] : this._nexors[i].foPl[1];
                    higherPlane = higherPlane.MovePlanebyAxis(this.plateThickness * 3);
                    Plane    lowerPlane = this._nexors[i].ePl90Offset.MovePlanebyAxis(-this.plateThickness * 3);
                    Polyline outline1   = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes);
                    Plane[]  bisectors1 = outline1.PolylineBisectors();

                    for (int j = 0; j < bisectors.Length; j++)
                    {
                        bisectors[j] = new Plane(
                            (bisectors[j].Origin + bisectors1[j].Origin) * 0.5,
                            (bisectors[j].XAxis + bisectors1[j].XAxis) * 0.5,
                            bisectors[j].Origin - bisectors1[j].Origin
                            );
                    }


                    //Create V-Shape cuts
                    Point3d nexorCenter = this._nexors[i].line.Center();


                    sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].endPl0.MovePlanebyAxis(0.2, nexorCenter),
                        this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, nexorCenter, 2, false),
                        bisectors[0],
                        this._nexors[i].endPl0,
                        bisectors[1],
                        this._nexors[i].foPl[0].MovePlanebyAxis(0.1, nexorCenter, 2, false)
                        ,
                    };
                    Polyline endCuts0A = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true);
                    Polyline endCuts0B = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true);
                    sidePlanes[0] = sidePlanes[0].MovePlanebyAxis(-0.2 * 2, nexorCenter, 2, false);
                    Polyline endCuts0A_ = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true);
                    Polyline endCuts0B_ = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true);

                    //endCuts0A_.Bake();
                    //endCuts0B_.Bake();

                    sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].endPl1.MovePlanebyAxis(0.2, nexorCenter),
                        this._nexors[i].foPl[0].MovePlanebyAxis(0.1, nexorCenter, 2, false),
                        bisectors[2],
                        this._nexors[i].endPl1,
                        bisectors[3],
                        this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, nexorCenter, 2, false)
                    };

                    Polyline endCuts1A = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true);
                    Polyline endCuts1B = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true);
                    sidePlanes[0] = sidePlanes[0].MovePlanebyAxis(-0.2 * 2, nexorCenter, 2, false);
                    Polyline endCuts1A_ = PolylineUtil.PolylineFromPlanes(lowerPlane, sidePlanes, true);
                    Polyline endCuts1B_ = PolylineUtil.PolylineFromPlanes(higherPlane, sidePlanes, true);


                    //endCuts1A_.Bake();
                    //endCuts1B_.Bake();



                    this._nexors[i].CNCendBladeSawCuts0.Add(endCuts0A_);
                    this._nexors[i].CNCendBladeSawCuts0.Add(endCuts0B_);
                    this._nexors[i].CNCendBladeSawCuts1.Add(endCuts1A_);
                    this._nexors[i].CNCendBladeSawCuts1.Add(endCuts1B_);


                    this._nexors[i].CNCendBladeSawCuts0Negative.Add(endCuts0A);
                    this._nexors[i].CNCendBladeSawCuts0Negative.Add(endCuts0B);
                    this._nexors[i].CNCendBladeSawCuts1Negative.Add(endCuts1A);
                    this._nexors[i].CNCendBladeSawCuts1Negative.Add(endCuts1B);


                    dt.AddRange(this._nexors[i].CNCendBladeSawCuts0, path);
                    dt.AddRange(this._nexors[i].CNCendBladeSawCuts1, path);



                    //if (this._nexors[i].isNexor == -1)
                    //{
                    //    endCuts0A.Bake();
                    //    endCuts0B.Bake();
                    //    endCuts1A.Bake();
                    //    endCuts1B.Bake();
                    //}
                }
            }


            //Collect neighbour cuts
            for (int i = 0; i < this._nexors.Count; i++)
            {
                var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2);

                int[] adjE0S = this._nexors[i].adjE0S;
                int[] adjE1S = this._nexors[i].adjE1S;

                if (this._nexors[i].isNexor == 1)
                {
                    if (adjE0S[0] != -1)
                    {
                        dt.AddRange(this[adjE0S[0], adjE0S[1]].CNCendBladeSawCuts0Negative, path);
                    }
                    if (adjE1S[0] != -1)
                    {
                        dt.AddRange(this[adjE1S[0], adjE1S[1]].CNCendBladeSawCuts1Negative, path);
                    }

                    //Bottom cut
                    Point3d      c          = this._nexors[i].line.Center();
                    List <Plane> sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].endPl0.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, c, 2, false), this._nexors[i].endPl1.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].foPl[0].MovePlanebyAxis(0.1, c, 2, false)
                    };
                    Polyline bottomCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes);
                    Polyline bottomCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset.MovePlanebyAxis(0.1, c, 2, false), sidePlanes);
                    //dt.Add(bottomCut0,path);
                    //dt.Add(bottomCut1, path);

                    dt.AddRange(this._nexors[i].CNCtopProfileCuts, path);
                    //bottomCut0.Bake();
                    //bottomCut1.Bake();
                }

                if (this._nexors[i].isNexor == -1)
                {
                    dt.AddRange(this._nexors[i].CNCendBladeSawCuts0Negative, new Grasshopper.Kernel.Data.GH_Path(adjE0S[0], adjE0S[1]));
                    dt.AddRange(this._nexors[i].CNCendBladeSawCuts1Negative, new Grasshopper.Kernel.Data.GH_Path(adjE1S[0], adjE1S[1]));

                    //Bottom cut
                    Point3d      c          = this._nexors[i].line.Center();
                    List <Plane> sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].endPl0.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].fcPl[2].MovePlanebyAxis(0.1, c, 2, false), this._nexors[i].endPl1.MovePlanebyAxis(0.2, c, 2, false), this._nexors[i].foPl[0].MovePlanebyAxis(0.1, c, 2, false)
                    };
                    Polyline bottomCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset, sidePlanes);
                    Polyline bottomCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].ePl90Offset.MovePlanebyAxis(0.1, c, 2, false), sidePlanes);
                    //dt.Add(bottomCut0, path);
                    //dt.Add(bottomCut1, path);


                    dt.AddRange(this._nexors[i].CNCtopProfileCuts, path);

                    //instead of path ?????????????????????

                    //Rhino.RhinoApp.WriteLine(String.Format("adj {0} - {1}, {2}-{3} , {4}-{5}",
                    //    adjE0S[0],
                    //    adjE0S[1],
                    //    adjE1S[0],
                    //    adjE1S[1],
                    //    this._nexors[i].idNested [0],
                    //    this._nexors[i].idNested[1]
                    //    ));
                    //Rhino.RhinoDoc.ActiveDoc.Objects.AddBrep(this._nexors[i].pipe.breploft);
                }
            }



            for (int i = 0; i < this._nexors.Count; i++)
            {
                if (this._nexors[i].isNexor != 0)
                {
                    var path = new Grasshopper.Kernel.Data.GH_Path(this.id_[i].Item1, this.id_[i].Item2);


                    Point3d c = this._nexors[i].pipe.line.Center();


                    List <Plane> sidePlanes = new List <Plane>()
                    {
                        this._nexors[i].fcPl[0].MovePlanebyAxis(0.01, c, 2, false),
                        this._nexors[i].endPl0.MovePlanebyAxis(0.01, c, 2, false),
                        this._nexors[i].foPl[2].MovePlanebyAxis(0.01, c, 2, false),
                        this._nexors[i].endPl1.MovePlanebyAxis(0.01, c, 2, false),
                    };

                    Polyline angledCut0 = PolylineUtil.PolylineFromPlanes(this._nexors[i].fcPl_foPl, sidePlanes);
                    Polyline angledCut1 = PolylineUtil.PolylineFromPlanes(this._nexors[i].fcPl_foPl.MovePlanebyAxis(0.1, c, 2, false), sidePlanes);


                    //dt.Add(angledCut0, path);
                    //dt.Add(angledCut1, path);
                    //bottomCut0.Bake();
                    //bottomCut1.Bake();
                }
            }


            return(dt);
        }