Beispiel #1
0
        public static string MapToSofiString(Rhino.UnitSystem us)
        {
            switch (us)
            {
            case Rhino.UnitSystem.Kilometers:
                return("km");

            case Rhino.UnitSystem.Meters:
                return("m");

            case Rhino.UnitSystem.Millimeters:
                return("mm");

            case Rhino.UnitSystem.Miles:
                return("mi");

            case Rhino.UnitSystem.Feet:
                return("ft");

            case Rhino.UnitSystem.Inches:
                return("in");

            case Rhino.UnitSystem.Yards:
                return("yd");
            }
            return(null);
        }
        /// <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)
        {
            Plane plane    = Plane.WorldXY;
            Curve perimCrv = null;

            coreCrvs     = new List <Curve>();
            rectangles   = new List <Rectangle3d>();
            obstacleCrvs = new List <Curve>();
            DA.GetData(IN_autoColor, ref autoColor);

            DA.GetData(IN_plane, ref plane);
            DA.GetData(IN_perimCrv, ref perimCrv);
            DA.GetDataList(IN_voxelRects, rectangles);
            DA.GetDataList(IN_obstacleCrvs, obstacleCrvs);
            bool coreReceived = DA.GetDataList(IN_coreCrvs, coreCrvs);

            _plan = new SmartPlan(perimCrv, coreCrvs, rectangles, obstacleCrvs, plane);

            Rhino.RhinoDoc   doc    = Rhino.RhinoDoc.ActiveDoc;
            Rhino.UnitSystem system = doc.ModelUnitSystem;
            _plan.projectUnits = system.ToString() == "Meters" ? 0 : 1;

            _plan.ComputeCovid();

            compromisedMetric = _plan.GetCovidMetric();

            DA.SetDataList(OUT_hit, compromisedMetric);
            DA.SetDataTree(OUT_lines, _plan.covidLines);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        ///

        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double inputValue = 1.0;

            double sourceUnit = 0;
            double targetUnit = 0;

            //what are you meausuring which translates in power 1 = length, 2 = area, 3 = volume
            int    unitType         = 1;
            String outMessage       = "";
            String sourceUnitName   = "";
            String targetUnitName   = "";
            String unitTypeConvName = "";
            String userUnitName     = "";


            Rhino.RhinoDoc   doc         = Rhino.RhinoDoc.ActiveDoc;
            Rhino.UnitSystem docUnits    = doc.ModelUnitSystem;
            Rhino.UnitSystem targetUnits = doc.ModelUnitSystem;



            // this is the number that have to use to convert from the document's units to the desired one)
            double conversionNumber = 1;

            bool success1 = DA.GetData(0, ref inputValue);
            bool success2 = DA.GetData(1, ref sourceUnit);
            bool success3 = DA.GetData(2, ref targetUnit);

            //a parameter to change between user model units =0 , or from model to user defined units = 1
            double conversionSwitch = 1;



            if (success1 && success2)
            {
                if (conversionSwitch == 1)
                {
                    conversionNumber = Rhino.RhinoMath.UnitScale(docUnits, targetUnits);
                }
                //convert from arbitrry units to Model units

                //unitType refers to length,area etc and is set by the drop down
                unitType = 1;//unitTp;

                double convertedValue = inputValue * Math.Pow(conversionNumber, unitType);

                outMessage = "You are calculating: " + unitTypeConvName + "You have converted FROM: " + sourceUnitName + " TO: " + targetUnitName;

                DA.SetData(0, convertedValue);
                DA.SetData(1, outMessage);
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Check again your inputs");
            }
        }
        /// <summary>
        /// Sets the detail viewport's projection so geometry is displayed at a certain scale.
        /// </summary>
        /// <param name="modelLength">Reference model length.</param>
        /// <param name="modelUnits">Units for model length.</param>
        /// <param name="pageLength">Length on page that the modelLength should equal.</param>
        /// <param name="pageUnits">Units for page length.</param>
        /// <returns>
        /// true on success. false if the DetailView projection is perspective or input values are incongruous.
        /// </returns>
        /// <example>
        /// <code source='examples\vbnet\ex_addlayout.vb' lang='vbnet'/>
        /// <code source='examples\cs\ex_addlayout.cs' lang='cs'/>
        /// <code source='examples\py\ex_addlayout.py' lang='py'/>
        /// </example>
        public bool SetScale(double modelLength, Rhino.UnitSystem modelUnits, double pageLength, Rhino.UnitSystem pageUnits)
        {
            // SetScale only works on parallel projections
            if (!IsParallelProjection)
            {
                return(false);
            }

            IntPtr pThis = NonConstPointer();

            return(UnsafeNativeMethods.ON_DetailView_SetScale(pThis, modelLength, (int)modelUnits, pageLength, (int)pageUnits));
        }
Beispiel #5
0
        public static Transform ToWGSxf()
        {
            EarthAnchorPoint eap = Rhino.RhinoDoc.ActiveDoc.EarthAnchorPoint;

            Rhino.UnitSystem us = new Rhino.UnitSystem();
            Transform        xf = eap.GetModelToEarthTransform(us);

            ///scale the transform to the model units
            Transform xfScaled = Transform.Multiply(xf, Transform.Scale(new Point3d(0.0, 0.0, 0.0), Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters)));

            return(xfScaled);
        }
Beispiel #6
0
        //////////////////////////////////////////////////////
        ///Basic Rhino transforms
        ///Using Rhino's EarthAnchorPoint to Transform.  GetModelToEarthTransform() translates to WGS84.
        ///https://github.com/gHowl/gHowlComponents/blob/master/gHowl/gHowl/GEO/XYZtoGeoComponent.cs
        ///https://github.com/mcneel/rhinocommon/blob/master/dotnet/opennurbs/opennurbs_3dm_settings.cs  search for "model_to_earth"

        public static Point3d ToWGS(Point3d xyz)
        {
            EarthAnchorPoint eap = new EarthAnchorPoint();

            eap = Rhino.RhinoDoc.ActiveDoc.EarthAnchorPoint;
            Rhino.UnitSystem us = new Rhino.UnitSystem();
            Transform        xf = eap.GetModelToEarthTransform(us);

            xyz = xyz * Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters);
            Point3d ptON = new Point3d(xyz.X, xyz.Y, xyz.Z);

            ptON = xf * ptON;

            ///TODO: Make translation of ptON here using SetCRS global variable (WGS84 -> CRS)

            return(ptON);
        }
Beispiel #7
0
        public static Transform ToXYZxf()
        {
            EarthAnchorPoint eap = new EarthAnchorPoint();

            eap = Rhino.RhinoDoc.ActiveDoc.EarthAnchorPoint;
            Rhino.UnitSystem us = new Rhino.UnitSystem();
            Transform        xf = eap.GetModelToEarthTransform(us);

            //scale the transform to the model units
            Transform xfScaled = Transform.Multiply(xf, Transform.Scale(new Point3d(0.0, 0.0, 0.0), Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters)));

            //http://www.grasshopper3d.com/forum/topics/matrix-datatype-in-rhinocommon
            //Thanks Andrew
            Transform Inversexf = new Transform();

            xfScaled.TryGetInverse(out Inversexf);
            return(Inversexf);
        }
Beispiel #8
0
        public static int MapToSofiUnitSet(Rhino.UnitSystem us)
        {
            switch (us)
            {
            case Rhino.UnitSystem.Millimeters:
                return(6);

            case Rhino.UnitSystem.Centimeters:
                return(1);

            case Rhino.UnitSystem.Meters:
                return(0);

            case Rhino.UnitSystem.Inches:
                return(9);
            }
            return(-1);
        }
Beispiel #9
0
        public static Point3d ToXYZ(Point3d wgs)
        {
            ///TODO: make translation of wgs here using SetCRS (CRS -> WGS84)

            EarthAnchorPoint eap = new EarthAnchorPoint();

            eap = Rhino.RhinoDoc.ActiveDoc.EarthAnchorPoint;
            Rhino.UnitSystem us = new Rhino.UnitSystem();
            Transform        xf = eap.GetModelToEarthTransform(us);

            //http://www.grasshopper3d.com/forum/topics/matrix-datatype-in-rhinocommon
            //Thanks Andrew
            Transform Inversexf = new Transform();

            xf.TryGetInverse(out Inversexf);

            wgs = Inversexf * wgs / Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters);
            return(wgs);
        }
Beispiel #10
0
        public static Unit_Length MapUnits(Rhino.UnitSystem rUnit)
        {
            switch (rUnit)
            {
            case Rhino.UnitSystem.Millimeters:
                return(Unit_Length.MilliMeters);

            case Rhino.UnitSystem.Meters:
                return(Unit_Length.Meters);

            case Rhino.UnitSystem.Kilometers:
                return(Unit_Length.KiloMeters);

            case Rhino.UnitSystem.Feet:
                return(Unit_Length.Feet);

            case Rhino.UnitSystem.Inches:
                return(Unit_Length.Inches);

            case Rhino.UnitSystem.None:
                return(Unit_Length.None);
            }
            return(Unit_Length.Meters);
        }
Beispiel #11
0
        /// <summary>
        /// Gets the unit system scaling factor from Rhino and returns a factor which when multiplied
        /// with the current Rhino units gives the corresponding length in SI units.
        /// General rule: divide when writing output to Rhino, multiply when recieving input from Rhino
        /// </summary>
        /// <returns></returns>
        public static double ScalingFactor()
        {
            Rhino.UnitSystem us = Rhino.RhinoDoc.ActiveDoc.PageUnitSystem;
            switch (us)
            {
            case Rhino.UnitSystem.None:
                break;

            case Rhino.UnitSystem.Angstroms:
                break;

            case Rhino.UnitSystem.Nanometers:
                break;

            case Rhino.UnitSystem.Microns:
                break;

            case Rhino.UnitSystem.Millimeters:
                return(0.001);

            case Rhino.UnitSystem.Centimeters:
                return(0.01);

            case Rhino.UnitSystem.Decimeters:
                return(0.1);

            case Rhino.UnitSystem.Meters:
                return(1);

            case Rhino.UnitSystem.Dekameters:
                break;

            case Rhino.UnitSystem.Hectometers:
                break;

            case Rhino.UnitSystem.Kilometers:
                return(1000);

            case Rhino.UnitSystem.Megameters:
                break;

            case Rhino.UnitSystem.Gigameters:
                break;

            case Rhino.UnitSystem.Microinches:
                break;

            case Rhino.UnitSystem.Mils:
                break;

            case Rhino.UnitSystem.Inches:
                break;

            case Rhino.UnitSystem.Feet:
                break;

            case Rhino.UnitSystem.Yards:
                break;

            case Rhino.UnitSystem.Miles:
                break;

            case Rhino.UnitSystem.PrinterPoint:
                break;

            case Rhino.UnitSystem.PrinterPica:
                break;

            case Rhino.UnitSystem.NauticalMile:
                break;

            case Rhino.UnitSystem.Astronomical:
                break;

            case Rhino.UnitSystem.Lightyears:
                break;

            case Rhino.UnitSystem.Parsecs:
                break;

            case Rhino.UnitSystem.CustomUnitSystem:
                break;

            default:
                break;
            }

            // If unimplemented
            throw new NotImplementedException("Rhino document using unknown unit system not implemented in software. Try using SI units");
        }
Beispiel #12
0
        public GHScale GetScale(Rhino.RhinoDoc rhinoDoc)
        {
            // Scale factor is based on assumption of feet based units.

            double scale = 1.0;

            Rhino.UnitSystem us    = rhinoDoc.ModelUnitSystem;
            string           units = us.ToString();

            scale = 1.0;
            switch (units)
            {
            case "None":
                scale = 1;
                break;

            case "Microns":
                scale = 1000000;
                break;

            case "Millimeters":
                scale = 1000;
                break;

            case "Centimeters":
                scale = 100;
                break;

            case "Meters":
                scale = 1;
                break;

            case "Kilometers":
                scale = 0.001;
                break;

            case "Microinches":
                scale = 39370100;
                break;

            case "Mils":
                scale = 39370.0787;
                break;

            case "Inches":
                scale = 39.3701;
                break;

            case "Feet":
                scale = 3.28084;
                break;

            case "Miles":
                scale = 0.000621371;
                break;

            case "Angstroms":
                scale = 10000000000;
                break;

            case "Nanometers":
                scale = 1000000000;
                break;

            case "Decimeters":
                scale = 10;
                break;

            case "Dekameters":
                scale = 0.1;
                break;

            case "Hectometers":
                scale = 0.01;
                break;

            case "Megameters":
                scale = 0.000001;
                break;

            case "Gigameters":
                scale = 0.000000001;
                break;

            case "Yards":
                scale = 1.09361;
                break;

            case "PrinterPoint":
                scale = 1;
                break;

            case "PrinterPica":
                scale = 1;
                break;

            case "NauticalMile":
                scale = 0.000539957;
                break;

            case "Astronomical":
                scale = 0.00000000000668458712;
                break;

            case "Lightyears":
                scale = 0.000000000000000105702341;
                break;

            case "Parsecs":
                scale = 0.0000000000000000324077929;
                break;

            default:
                break;
            }

            GHScale ghScale = new GHScale(units, scale);

            return(ghScale);
        }
Beispiel #13
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)
        {
            double inputValue    = 1.0;
            double targetUnitSys = 0;
            double convType      = 0;

            //get the model units from the rhino document
            Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;

            // create variables to hold the input and target unit system
            Rhino.UnitSystem docUnits    = doc.ModelUnitSystem;
            Rhino.UnitSystem targetUnits = doc.ModelUnitSystem;


            String outMessage       = "";
            String sourceUnitName   = docUnits.ToString();
            String targetUnitName   = "";
            String unitTypeConvName = "";
            String userUnitName     = "";

            double conversionNumber = 1;


            //create a a value for raising the number to an expoenet
            //what are you meausuring which translates in power 1 = length, 2 = area, 3 = volume

            //update baseed based on the selection of the menu
            double convExp = conversionExp;


            //read in the values from sliders/ other components
            bool success1 = DA.GetData(0, ref inputValue);
            bool success2 = DA.GetData(1, ref targetUnitSys);
            bool success3 = DA.GetData(2, ref convType);

            //initialize a value
            double convertedValue = 1;



            if (targetUnitSys == 0)
            {
            }
            else if (targetUnitSys == 1)
            {
                targetUnits = (Rhino.UnitSystem)UnitSystem.Microns;
            }
            else if (targetUnitSys == 2)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Millimeters;
            }
            else if (targetUnitSys == 3)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Centimeters;
            }
            else if (targetUnitSys == 4)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Meters;
            }
            else if (targetUnitSys == 5)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Kilometers;
            }
            else if (targetUnitSys == 6)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Microinches;
            }
            else if (targetUnitSys == 7)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Mils;
            }
            else if (targetUnitSys == 8)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Inches;
            }
            else if (targetUnitSys == 9)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Feet;
            }
            else if (targetUnitSys == 10)
            {
                //update the unit system
                targetUnits = (Rhino.UnitSystem)UnitSystem.Miles;
            }
            else
            {
                //give an error
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Check again your inputs");
            }

            // get the name of the target conversion system
            targetUnitName = targetUnits.ToString();

            // Don't worry about where the Absolute property comes from, we'll get to it soon.
            if (convType == 0)
            {
                //convert from Model Unit System to User Defined
                conversionNumber = Rhino.RhinoMath.UnitScale(docUnits, targetUnits);
                // write a message
                outMessage = "Conversion Done! The Document's Units System is: " + sourceUnitName + " /You are converting TO: " + targetUnitName + " / The unit conversion number is: " + conversionNumber;
                //convert the value
                convertedValue = Math.Pow(inputValue * conversionNumber, convExp);
            }
            else
            {
                // converting from User Defined to Model Units
                conversionNumber = Rhino.RhinoMath.UnitScale(targetUnits, docUnits);
                // write a message
                outMessage = "Conversion Done! The Document's Units System is: " + sourceUnitName + " /You are converting FROM: " + targetUnitName + " / The unit conversion number is: " + conversionNumber;
                //convert the value
                convertedValue = Math.Pow(inputValue * conversionNumber, convExp);
            }



            DA.SetData(0, convertedValue);
            DA.SetData(1, outMessage);
        }