///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            try
            {
                var myLayers = doc.Layers;
                this.doc = doc;

                Rhino.Display.RhinoView view = null;
                RhinoApp.WriteLine("Switching to Top View"); //switch to top view for the command to work
                view = doc.Views.Find("Top", false);         // en
                doc.Views.ActiveView = view;
                //display the option list to the user using the method
                displayMenuOption();
                if (!curveOpen)
                {
                    setLayerVisibility(doc, false);
                    Perimeter(doc);
                    return(Result.Success);
                }
                else
                {
                    Messages.showUnclosedCurves(unClosedPanels);
                    return(Result.Failure);
                }
            }
            catch (Exception e)
            {
                Messages.showMassdxfError(e);
                return(Result.Failure);
            }
        }
Example #2
0
    public static Rhino.Commands.Result ActiveViewport(Rhino.RhinoDoc doc)
    {
        Rhino.Display.RhinoView view = doc.Views.ActiveView;
        if (view == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Display.RhinoPageView pageview = view as Rhino.Display.RhinoPageView;
        if (pageview != null)
        {
            string layout_name = pageview.PageName;
            if (pageview.PageIsActive)
            {
                Rhino.RhinoApp.WriteLine("The layout {0} is active", layout_name);
            }
            else
            {
                string detail_name = pageview.ActiveViewport.Name;
                Rhino.RhinoApp.WriteLine("The detail {0} on layout {1} is active", detail_name, layout_name);
            }
        }
        else
        {
            string viewport_name = view.MainViewport.Name;
            Rhino.RhinoApp.WriteLine("The viewport {0} is active", viewport_name);
        }
        return(Rhino.Commands.Result.Success);
    }
    public static Rhino.Commands.Result AddClippingPlane(Rhino.RhinoDoc doc)
    {
        // Define the corners of the clipping plane
        Rhino.Geometry.Point3d[] corners;
        Rhino.Commands.Result    rc = Rhino.Input.RhinoGet.GetRectangle(out corners);
        if (rc != Rhino.Commands.Result.Success)
        {
            return(rc);
        }

        // Get the active view
        Rhino.Display.RhinoView view = doc.Views.ActiveView;
        if (view == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.Geometry.Point3d p0 = corners[0];
        Rhino.Geometry.Point3d p1 = corners[1];
        Rhino.Geometry.Point3d p3 = corners[3];

        // Create a plane from the corner points
        Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(p0, p1, p3);

        // Add a clipping plane object to the document
        Guid id = doc.Objects.AddClippingPlane(plane, p0.DistanceTo(p1), p0.DistanceTo(p3), view.ActiveViewportID);

        if (id != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
Example #4
0
 /// <summary>
 /// Call this function to render the scene in a view window. The function returns when rendering is complete (or cancelled).
 /// </summary>
 /// <param name="view">the view that the user selected a rectangle in.</param>
 /// <param name="rect">rectangle that the user selected.</param>
 /// <param name="inWindow">true to render directly into the view window.</param>
 /// <returns>A code that explains how rendering completed.</returns>
 /// //TODO - ViewInfo is wrong here
 public RenderReturnCode RenderWindow(Rhino.Display.RhinoView view, System.Drawing.Rectangle rect, bool inWindow)
 {
     m_ReturnCode = RenderReturnCode.InternalError;
     if (m_pSdkRender != IntPtr.Zero)
     {
         m_ReturnCode = (RenderReturnCode)UnsafeNativeMethods.Rdk_SdkRender_RenderWindow(m_pSdkRender, view.ConstPointer(), rect.Top, rect.Left, rect.Bottom, rect.Right, inWindow);
     }
     return(m_ReturnCode);
 }
Example #5
0
        /// <summary> btnBegin3d opens new perspective viewport for 3D drawing </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBegin3d_Click(object sender, EventArgs e)
        {
            IntPtr hwnd = RhinoApp.MainWindowHandle();

            view3 = mRhinoDoc.Views.ActiveView;
            Rhino.DocObjects.Tables.ViewTable viewTable = mRhinoDoc.Views;
            var newDisplaymode = Rhino.Display.DisplayModeDescription.FindByName("Ghosted");

            Rhino.Display.DisplayModeDescription.UpdateDisplayMode(newDisplaymode);
            view3 = viewTable.Add("squid2", Rhino.Display.DefinedViewportProjection.Perspective, System.Drawing.Rectangle.FromLTRB(1000, 300, 1700, 1000), true);
            view3.Redraw();
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Display.RhinoView view = doc.Views.ActiveView;
            if (null == view)
            {
                return(Result.Failure);
            }

            Rhino.Display.RhinoViewport          viewport           = view.ActiveViewport;
            Rhino.Display.DisplayModeDescription currentDisplayMode = viewport.DisplayMode;
            Rhino.RhinoApp.WriteLine("Viewport in {0} display.", currentDisplayMode.EnglishName);

            Rhino.Display.DisplayModeDescription[] displayModes = Rhino.Display.DisplayModeDescription.GetDisplayModes();

            Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
            go.SetCommandPrompt("Select new display mode");
            go.AcceptNothing(true);

            foreach (Rhino.Display.DisplayModeDescription displayMode in displayModes)
            {
                string displayName = FormatValidDisplayName(displayMode.EnglishName);
                go.AddOption(displayName);
            }

            Rhino.Input.GetResult rc = go.Get();
            switch (rc)
            {
            case Rhino.Input.GetResult.Option:
            {
                int optionIndex = go.Option().Index;
                if (optionIndex > 0 && optionIndex <= displayModes.Length)
                {
                    Rhino.Display.DisplayModeDescription newDisplayMode = displayModes[optionIndex - 1];
                    if (newDisplayMode.Id != currentDisplayMode.Id)
                    {
                        viewport.DisplayMode = newDisplayMode;
                        view.Redraw();
                        Rhino.RhinoApp.WriteLine("Viewport set to {0} display.", viewport.DisplayMode.EnglishName);
                    }
                }
            }
            break;

            case Rhino.Input.GetResult.Cancel:
                return(Result.Cancel);

            default:
                break;
            }

            return(Result.Success);
        }
Example #7
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)
        {
            Mesh         mesh   = null;
            List <Color> colors = new List <Color>();
            bool         active = false;


            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetDataList(1, colors))
            {
                return;
            }
            if (!DA.GetData(2, ref active))
            {
                return;
            }

            Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.Find("Perspective", false);
            {
                view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView; // assign active view
            }


            if (mesh.Normals.Count != mesh.Vertices.Count)
            {
                mesh.Normals.ComputeNormals();
            }

            if (mesh.VertexColors.Count != mesh.Vertices.Count)
            {
                mesh.VertexColors.CreateMonotoneMesh(Color.Black);
            }

            //Find Depth Range
            Point3d closestPt = mesh.ClosestPoint(view.MainViewport.CameraLocation);
            double  dd        = closestPt.DistanceTo(view.MainViewport.CameraLocation);
            double  dim       = mesh.GetBoundingBox(true).Diagonal.Length;

            DepthShade(mesh, view.MainViewport.CameraLocation, new Interval(dd, dd + dim), colors);

            DA.SetData(0, new GH_Mesh(mesh));


            if (active)
            {
                this.ExpireSolution(true);
            }
        }
Example #8
0
        public void SpreadObjects(double step, Boolean refresh)
        {
            if (myDisplayBool == null)
            {
            }
            else
            {
                Rhino.Display.RhinoView myViewport = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

                Rhino.Display.RhinoViewport viewport = myViewport.ActiveViewport;

                //viewport.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName("Wireframe");
                Rhino.Geometry.BoundingBox myGlobalBbox = new Rhino.Geometry.BoundingBox();
                myGlobalBbox = Rhino.Geometry.BoundingBox.Empty;
                List <Rhino.Geometry.Point3d> myCentroids = new List <Rhino.Geometry.Point3d>();
                //myCentroids.Clear();
                //Rhino.Geometry.Point3d explosionCenter;

                // First iteration: find initial object and initial bounding box center
                if (originalCentroids.Count == 0 || refresh == true)
                {
                    myCentroids.Clear();
                    foreach (Guid guid in allGuids)
                    {
                        RhinoObject foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(guid);
                        Rhino.Geometry.BoundingBox foundBbox = foundObject.Geometry.GetBoundingBox(true);
                        myGlobalBbox.Union(foundBbox);
                        myCentroids.Add(foundBbox.Center);
                        explosionCenter = myGlobalBbox.Center;
                    }
                    originalCentroids = myCentroids;
                }
                else
                {
                    for (int i = 0; i < allGuids.Count; i++)
                    {
                        RhinoObject             foundObject = Rhino.RhinoDoc.ActiveDoc.Objects.Find(allGuids[i]);
                        Rhino.Geometry.Vector3d trans       = explosionCenter - originalCentroids[i];

                        // Brings back to original position.
                        Rhino.Geometry.Vector3d backTrans = originalCentroids[i] - foundObject.Geometry.GetBoundingBox(true).Center;
                        trans.Unitize();
                        Rhino.RhinoDoc.ActiveDoc.Objects.Transform(foundObject, Rhino.Geometry.Transform.Translation(backTrans - Rhino.Geometry.Vector3d.Multiply(step, trans)), true);
                        Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
                    }
                }
            }
        }
Example #9
0
 protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 {
     Rhino.DocObjects.Tables.ViewTable viewTable = doc.Views;
     Rhino.Display.RhinoView[]         views     = viewTable.GetStandardRhinoViews();
     if (null != views)
     {
         int count = views.Length;
         for (int i = 0; i < count; i++)
         {
             Rhino.Display.RhinoView view = views[i];
             if (null != view)
             {
                 string name = view.MainViewport.Name;
                 Rhino.RhinoApp.WriteLine(string.Format("View {0} = {1}", i, name));
             }
         }
     }
     return(Result.Success);
 }
        private void ScreenShot(int i)
        {
            Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;
            if (view == null)
            {
                return;
            }

            string fileName = @"" + MyComponent.SSDir + MyComponent.SSFilename + "-" + i + ".png";
            Bitmap image    = view.CaptureToBitmap();

            if (image == null)
            {
                return;
            }

            image.Save(fileName);
            image = null;
        }
Example #11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ETABS2013.cOAPI ETABS    = null;
            string          loadcase = null;

            if (!DA.GetData(0, ref ETABS))
            {
                return;
            }
            if (!DA.GetData(1, ref loadcase))
            {
                return;
            }

            Rhino.RhinoDoc RhinoDoc = Rhino.RhinoDoc.ActiveDoc;

            Rhino.Display.RhinoView view    = RhinoDoc.Views.ActiveView;
            System.Drawing.Bitmap   picture = view.CaptureToBitmap();
            picture.Save("H:\\printad.bmp");
        }
Example #12
0
    public static Rhino.Commands.Result MoveCPlane(Rhino.RhinoDoc doc)
    {
        Rhino.Display.RhinoView view = doc.Views.ActiveView;
        if (view == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        Rhino.DocObjects.ConstructionPlane cplane = view.ActiveViewport.GetConstructionPlane();
        Point3d origin = cplane.Plane.Origin;

        MoveCPlanePoint gp = new MoveCPlanePoint(cplane);

        gp.SetCommandPrompt("CPlane origin");
        gp.SetBasePoint(origin, true);
        gp.DrawLineFromPoint(origin, true);
        gp.Get();

        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        Point3d  point = gp.Point();
        Vector3d v     = origin - point;

        if (v.IsTiny())
        {
            return(Rhino.Commands.Result.Nothing);
        }

        Plane pl = cplane.Plane;

        pl.Origin    = point;
        cplane.Plane = pl;
        view.ActiveViewport.SetConstructionPlane(cplane);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Example #13
0
        ///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            try
            {
                var myLayers = doc.Layers;
                this.doc = doc;

                Rhino.Display.RhinoView view = null;
                RhinoApp.WriteLine("Switching to Top View"); //switch to top view for the command to work
                view = doc.Views.Find("Top", false);         // en
                doc.Views.ActiveView = view;

                //Retrieve all label objects
                getLabels();
                resizeLabels();
                return(Result.Success);
            }
            catch (Exception e)
            {
                Messages.showMassdxfError(e);
                return(Result.Failure);
            }
        }
Example #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to expand");
            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                goList.Add(obj);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();

            Rhino.Display.RhinoView view = gp2.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();
                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Expantion factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec   = (centers[i] - scaleCenter) * (factor - 1);
                    var      xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1);
                    Vector3d planeNormal        = plane2D.Normal;
                    if (planeNormal[0] != 0)
                    {
                        vec.X = 0;
                    }
                    else if (planeNormal[1] != 0)
                    {
                        vec.Y = 0;
                    }
                    else if (planeNormal[2] != 0)
                    {
                        vec.Z = 0;
                    }
                    var xform = Rhino.Geometry.Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vecEach       = (centers[i] - scaleCenter);
                    double   vecEachLength = vecEach.Length * (factor - 1);
                    Vector3d vec           = (scaleRefPoint - scaleCenter);
                    double   angleVec      = Vector3d.VectorAngle(vecEach, vec);
                    int      pol           = 1;
                    if (angleVec > 1.57)
                    {
                        pol = -1;
                    }
                    vec.Unitize();
                    vec = vec * vecEachLength * pol;

                    var xform = Transform.Translation(vec);
                    doc.Objects.Transform(go.Object(i), xform, true);
                }
            }

            goList         = new List <Object>();
            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();

            doc.Views.Redraw();
            return(Result.Success);
        }
        /// <summary> btnBegin3d opens new perspective viewport for 3D drawing </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBegin3d_Click(object sender, EventArgs e)
        {
            IntPtr hwnd = RhinoApp.MainWindowHandle();

            view3 = mRhinoDoc.Views.ActiveView;
            Rhino.DocObjects.Tables.ViewTable viewTable = mRhinoDoc.Views;
            var newDisplaymode = Rhino.Display.DisplayModeDescription.FindByName("Ghosted");
            Rhino.Display.DisplayModeDescription.UpdateDisplayMode(newDisplaymode);
            view3 = viewTable.Add("squid2", Rhino.Display.DefinedViewportProjection.Perspective, System.Drawing.Rectangle.FromLTRB(1000, 300, 1700, 1000), true);
            view3.Redraw();
        }
        public bool RestoreAnimated(int index, Rhino.Display.RhinoView viewport, bool backgroundBitmap, int frames, int frameRate)
        {
            IntPtr pConstViewport = viewport.NonConstPointer();

            return(UnsafeNativeMethods.RHC_RhinoRestoreNamedView(m_doc.m_docId, index, pConstViewport, backgroundBitmap, frames, frameRate));
        }
 public bool RestoreAnimated(int index, Rhino.Display.RhinoView viewport, bool backgroundBitmap)
 {
     return(RestoreAnimated(index, viewport, backgroundBitmap, 100, 10));
 }
        /// <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)
        {
            string filename = "";

            DA.GetData("filename", ref filename);
            string viewport = "";

            DA.GetData("viewport", ref viewport);
            int width = 0;

            DA.GetData("width", ref width);
            int height = 0;

            DA.GetData("height", ref height);
            bool enabled = false;

            DA.GetData("enabled", ref enabled);

            Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;


            if (!enabled)
            {
                DA.SetData("file", null);
                DA.SetData("success", false);
                return;
            }

            try
            {
                // get the viewport named views
                Rhino.Display.RhinoView vp = doc.Views.Find(viewport, false);

                // get the bitmap in the right size
                Bitmap bitmap = Rhino.Display.DisplayPipeline.DrawToBitmap(vp.ActiveViewport, width, height);

                string ext = Path.GetExtension(filename).ToLower().Replace(".", "");


                System.Drawing.Imaging.ImageFormat imageFormat;

                switch (ext)
                {
                case "jpeg":
                case "jpg":
                    imageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
                    break;

                case "gif":
                    imageFormat = System.Drawing.Imaging.ImageFormat.Gif;
                    break;

                case "bmp":
                    imageFormat = System.Drawing.Imaging.ImageFormat.Bmp;
                    break;

                case "png":
                    imageFormat = System.Drawing.Imaging.ImageFormat.Png;
                    break;

                case "tif":
                case "tiff":
                    imageFormat = System.Drawing.Imaging.ImageFormat.Tiff;
                    break;

                default:
                    throw new Exception(String.Format("unknown image format: {0}", ext));
                }

                // save the bitmap
                bitmap.Save(filename, imageFormat);
                DA.SetData("file", filename);
                DA.SetData("success", System.IO.File.Exists(filename));
            }
            catch (Exception e)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                DA.SetData("file", null);
                DA.SetData("success", false);
            }
        }
Example #19
0
        static int OnReturnBoolGeneralCallback(int serial_number, int iVirtualFunction, IntPtr pObj, IntPtr pMat, IntPtr pMesh, IntPtr pView, int rectLeft, int rectTop, int rectRight, int rectBottom)
        {
            try
            {
                RenderPipeline pipe = RenderPipeline.FromSerialNumber(serial_number);
                if (pipe != null)
                {
                    switch ((VirtualFunctions)iVirtualFunction)
                    {
                    case VirtualFunctions.StartRendering:
                        return(pipe.OnRenderBegin() ? 1 : 0);

                    case VirtualFunctions.StartRenderingInWindow:
                    {
                        Rhino.Display.RhinoView  view = Rhino.Display.RhinoView.FromIntPtr(pView);
                        System.Drawing.Rectangle rect = System.Drawing.Rectangle.FromLTRB(rectLeft, rectTop, rectRight, rectBottom);
                        return(pipe.OnRenderWindowBegin(view, rect) ? 1 : 0);
                    }

                    case VirtualFunctions.StopRendering:
                        pipe.OnRenderEnd(new RenderEndEventArgs());
                        return(1);

                    case VirtualFunctions.NeedToProcessGeometryTable:
                        return(pipe.NeedToProcessGeometryTable() ? 1 : 0);

                    case VirtualFunctions.NeedToProcessLightTable:
                        return(pipe.NeedToProcessLightTable() ? 1 : 0);

                    case VirtualFunctions.RenderSceneWithNoMeshes:
                        return(pipe.RenderSceneWithNoMeshes() ? 1 : 0);

                    case VirtualFunctions.RenderPreCreateWindow:
                        return(pipe.RenderPreCreateWindow() ? 1:0);

                    case VirtualFunctions.RenderEnterModalLoop:
                        return(pipe.RenderEnterModalLoop() ? 1 : 0);

                    case VirtualFunctions.RenderExitModalLoop:
                        return(pipe.RenderExitModalLoop() ? 1 : 0);

                    case VirtualFunctions.RenderContinueModal:
                        return(pipe.ContinueModal() ? 1 : 0);

                    case VirtualFunctions.IgnoreRhinoObject:
                    {
                        if (pObj != IntPtr.Zero)
                        {
                            Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                            if (obj != null)
                            {
                                return(pipe.IgnoreRhinoObject(obj) ? 1 : 0);
                            }
                        }
                    }
                        return(0);

                    case VirtualFunctions.AddLightToScene:
                    {
                        if (pObj != IntPtr.Zero)
                        {
                            Rhino.DocObjects.LightObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj) as Rhino.DocObjects.LightObject;
                            if (obj != null)
                            {
                                return(pipe.AddLightToScene(obj) ? 1 : 0);
                            }
                        }
                    }
                        return(0);

                    case VirtualFunctions.AddRenderMeshToScene:
                    {
                        if (pObj != IntPtr.Zero && pMat != IntPtr.Zero && pMesh != IntPtr.Zero)
                        {
                            Rhino.DocObjects.RhinoObject obj = Rhino.DocObjects.RhinoObject.CreateRhinoObjectHelper(pObj);
                            Rhino.DocObjects.Material    mat = Rhino.DocObjects.Material.NewTemporaryMaterial(pMat);

                            //Steve....you need to look at this
                            Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(pMesh, obj);

                            return(pipe.AddRenderMeshToScene(obj, mat, mesh) ? 1:0);
                        }
                    }
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                Rhino.Runtime.HostUtils.ExceptionReport(ex);
            }

            Debug.Assert(false);
            return(0);
        }
Example #20
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 <Point3d> pProjected = new List <Point3d>();

            string view = string.Empty;

            DA.GetData <string>(0, ref view);
            viewportName = view;
            ///Get viewport boundary
            Rhino.Display.RhinoView[] rvList = Rhino.RhinoDoc.ActiveDoc.Views.GetViewList(true, false);
            Rhino.Display.RhinoView   rv     = Rhino.RhinoDoc.ActiveDoc.Views.Find(view, true);

            if (!rvList.Contains(rv))
            {
                rv = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Viewport name is not valid. Using active viewport " + rv.ActiveViewport.Name);
            }


            Rhino.Display.RhinoViewport vp = rv.MainViewport;
            Point3d[] pNear = rv.MainViewport.GetNearRect();
            Point3d[] pFar  = rv.MainViewport.GetFarRect();

            ///Project viewport boundary to a plane
            for (int i = 0; i < pNear.Length; i++)
            {
                Vector3d  tVec  = pFar[i] - pNear[i];
                Transform trans = Transform.ProjectAlong(Plane.WorldXY, tVec);
                pNear[i].Transform(trans);
                pProjected.Add(pNear[i]);
            }

            ///Create polyline from project viewport boundary
            Polyline pL = new Polyline();

            pL.Add(pProjected[2]);
            pL.Add(pProjected[3]);
            pL.Add(pProjected[1]);
            pL.Add(pProjected[0]);
            pL.Add(pProjected[2]);


            ///Calculate recommended zoom level from viewport size
            BoundingBox bb     = pL.BoundingBox;
            Vector3d    dia    = bb.Diagonal;
            Double      maxDim = Math.Max(dia.X, dia.Y) * Rhino.RhinoMath.UnitScale(Rhino.RhinoDoc.ActiveDoc.ModelUnitSystem, Rhino.UnitSystem.Meters);
            Double      maxPix = Math.Max(vp.Size.Height, vp.Size.Width);


            ///https://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map
            ///diameter of earth at equator is approx 40,000km
            ///resolution = (512px*distance)/40,075,000 meters * 2^zoom
            ///2^zoom = (resolution * 40,000,000) / (512px * distance)
            Double a = (maxPix * 40075000) / (512 * maxDim * 1.2);

            ///Solve for zoom
            ///https://stackoverflow.com/questions/4016213/whats-the-opposite-of-javascripts-math-pow
            Double z = Math.Log(a) / Math.Log(2);


            ///make sure zoom doesn't get too ridiculous levels
            DA.SetData(0, pL);
            DA.SetData(1, Math.Min(z, 21));
        }
    public static Rhino.Commands.Result AddBackgroundBitmap(Rhino.RhinoDoc doc)
    {
        Rhino.RhinoApp.WriteLine("hey");
        // Allow the user to select a bitmap file
        Rhino.UI.OpenFileDialog fd = new Rhino.UI.OpenFileDialog();
        fd.Filter = "Image Files (*.bmp;*.png;*.jpg)|*.bmp;*.png;*.jpg";
        if (!fd.ShowDialog())
        {
            return(Rhino.Commands.Result.Cancel);
        }

        // Verify the file that was selected
        System.Drawing.Image image;
        try
        {
            image = System.Drawing.Image.FromFile(fd.FileName);
        }
        catch (Exception)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Allow the user to pick the bitmap origin
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Bitmap Origin");
        gp.ConstrainToConstructionPlane(true);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Get the view that the point was picked in.
        // This will be the view that the bitmap appears in.
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }

        // Allow the user to specify the bitmap with in model units
        Rhino.Input.Custom.GetNumber gn = new Rhino.Input.Custom.GetNumber();
        gn.SetCommandPrompt("Bitmap width");
        gn.SetLowerLimit(1.0, false);
        gn.Get();
        if (gn.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gn.CommandResult());
        }

        // Cook up some scale factors
        double w            = gn.Number();
        double image_width  = image.Width;
        double image_height = image.Height;
        double h            = w * (image_height / image_width);

        Rhino.Geometry.Plane plane = view.ActiveViewport.ConstructionPlane();
        plane.Origin = gp.Point();
        view.ActiveViewport.SetTraceImage(fd.FileName, plane, w, h, false, false);
        view.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Example #22
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)
        {
            //Message = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.Name;

            bool capture = false;

            DA.GetData("Capture", ref capture);

            if (!capture)
            {
                Message = "";
                return;
            }
            string dir = "", Name = "";

            if (!DA.GetData(0, ref dir))
            {
                return;
            }
            if (!DA.GetData(1, ref Name))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(dir))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(Name))
            {
                return;
            }

            // Make sure the directory ends with a \
            if (dir.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
            {
                dir += System.IO.Path.DirectorySeparatorChar;
            }

            // Do not create directories, only use existing ones.
            if (!System.IO.Directory.Exists(dir))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Directory does not exist - use only existing directories");
                return;
            }

            //Add an incremental number to the name
            string[] nSplit = Name.Split('.');
            Name = nSplit[0] + "_{0}." + nSplit[1];

            // Assume index=0 for the first filename.
            string fileName = dir + string.Format(Name, 0.ToString("D3"));

            // Try to increment the index until we find a name which doesn't exist yet.
            if (System.IO.File.Exists(fileName))
            {
                for (int i = 1; i < int.MaxValue; i++)
                {
                    string localName = dir + string.Format(Name, i.ToString("D3"));
                    if (localName == fileName)
                    {
                        return;
                    }

                    if (!System.IO.File.Exists(localName))
                    {
                        fileName = localName;
                        break;
                    }
                }
            }
            string VP = "";

            DA.GetData(2, ref VP);
            if (string.IsNullOrWhiteSpace(VP))
            {
                VP = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.Name;
            }

            Message = VP;

            int[]  res = new int[1];
            Size   sz;
            string size = "";

            DA.GetData(3, ref size);
            double scale = 1.0;

            DA.GetData(4, ref scale);

            Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.Find(VP, false);

            if (!string.IsNullOrWhiteSpace(size))
            {
                res = size.Split(new[] { 'x' }).Select(x => (int)(Convert.ToInt32(x) * scale)).ToArray();
            }
            else
            {
                res    = new int[2];
                res[0] = (int)(view.Size.Width * scale);
                res[1] = (int)(view.Size.Height * scale);
            }

            sz = new Size(res[0], res[1]);

            Bitmap image;

            bool grid = false, axes = false, widget = false;

            DA.GetData(5, ref grid);
            DA.GetData(6, ref axes);
            DA.GetData(7, ref widget);

            if (res.Length == 1)
            {
                image = view.CaptureToBitmap(grid, widget, axes);
            }
            else
            {
                image = view.CaptureToBitmap(new Size(res[0], res[1]), grid, widget, axes);
            }

            image.Save(fileName);
            image.Dispose();
        }
Example #23
0
 protected virtual void OnMouseHover(Rhino.Display.RhinoView view)
 {
 }
Example #24
0
 protected virtual void OnMouseLeave(Rhino.Display.RhinoView view)
 {
 }
Example #25
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop;


            //pick objects to expand
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to scale");
            go.GeometryFilter = myTypes;
            //go.GroupSelect = true;
            go.SubObjectSelect = true;
            //go.EnableClearObjectsOnEntry(false);
            //go.EnableUnselectObjectsOnExit(false);
            //go.DeselectAllBeforePostSelect = false;
            go.GetMultiple(1, 0);

            //Compute center
            Point3d centersAdd = new Point3d();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bbObj       = go.Object(i).Geometry().GetBoundingBox(true);
                Point3d     bbObjCenter = bbObj.Center;
                centers.Add(bbObjCenter);
                centersAdd += bbObjCenter;

                Rhino.DocObjects.ObjRef objref = go.Object(i);
                // get selected surface object
                Rhino.DocObjects.RhinoObject obj = objref.Object();
                dynRef.Add(objref);
            }
            Point3d allCenter = centersAdd / centers.Count;

            //pick center
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Basepoint. Press Enter for automatic.");
            gp.AcceptNothing(true);
            var resgp = gp.Get();

            if (resgp == GetResult.Nothing)
            {
                scaleCenter = allCenter;
            }
            else
            {
                scaleCenter = gp.Point();
            }

            Rhino.Display.RhinoView view = gp.View();
            plane2D = view.ActiveViewport.ConstructionPlane();

            //Expansion factor
            GetPoint gp2 = new GetPoint();

            gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">");
            gp2.DrawLineFromPoint(scaleCenter, true);
            gp2.AcceptNumber(true, true);
            GetResult gr = gp2.Get();



            if (gr == GetResult.Number)
            {
                factor = gp2.Number();
            }
            if (gr == GetResult.Point)
            {
                scaleRefPoint = gp2.Point();
                Line line1     = new Line(scaleCenter, scaleRefPoint);
                Guid tempLine  = doc.Objects.AddLine(line1);
                Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint);
                if (scaleCenter == gp2.Point())
                {
                    return(Rhino.Commands.Result.Cancel);
                }
                GetPoint gp3 = new GetPoint();
                gp3.SetCommandPrompt("Secondt reference point");
                gp3.AddOptionList("ScaleDimension", dimensions, 0);
                gp3.DrawLineFromPoint(scaleCenter, true);
                gp3.DynamicDraw += RefObjDraw;

                while (true)
                {
                    GetResult res = gp3.Get();
                    if (res == GetResult.Option)
                    {
                        dimensionIndex = gp3.Option().CurrentListOptionIndex;
                        continue;
                    }
                    else if (res == GetResult.Point)
                    {
                        Point3d scaleRefPoint2 = gp3.Point();

                        factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint));
                        doc.Objects.Delete(tempLine, true);
                        doc.Objects.Delete(tempPoint, true);
                    }
                    break;
                }
            }
            RhinoApp.WriteLine("Scale factor: " + factor);

            //Compute translation

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    var xform  = Transform.Scale(centers[i], factor);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    plane2D.Origin = centers[i];
                    var xform  = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1);
                    var objref = go.Object(i);
                    var brep   = objref.Brep();
                    var index  = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    Vector3d vec        = (scaleRefPoint - scaleCenter);
                    Plane    scalePlane = new Plane(centers[i], vec);
                    var      xform      = Transform.Scale(scalePlane, 1, 1, factor);
                    var      objref     = go.Object(i);
                    var      brep       = objref.Brep();
                    var      index      = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true);
                        doc.Objects.Replace(objref.ObjectId, brep);
                    }
                    else
                    {
                        doc.Objects.Transform(go.Object(i), xform, true);
                    }
                }
            }

            centers        = new List <Point3d>();
            dimensionIndex = 0;
            plane2D        = new Plane();
            dynRef         = new List <Rhino.DocObjects.ObjRef>();

            doc.Views.Redraw();
            return(Result.Success);
        }
 /// <summary>
 /// Is called when the user calls the _RenderWindow command.
 /// </summary>
 /// <param name="doc">The document to be rendered.</param>
 /// <param name="mode">The run mode: interactive or scripted.</param>
 /// <param name="fastPreview">Whether the render is in preview-mode.</param>
 /// <param name="view">The view being rendered.</param>
 /// <param name="rect">The rendering rectangle.</param>
 /// <param name="inWindow">Whether rendering should appear in the window.</param>
 /// <returns>The result of the command.</returns>
 protected override Rhino.Commands.Result RenderWindow(RhinoDoc doc, Rhino.Commands.RunMode mode, bool fastPreview, Rhino.Display.RhinoView view, System.Drawing.Rectangle rect, bool inWindow)
 {
     return(Result.Success);
 }
Example #27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="view"></param>
 /// <param name="rectangle"></param>
 /// <returns></returns>
 protected abstract bool OnRenderWindowBegin(Rhino.Display.RhinoView view, System.Drawing.Rectangle rectangle);
    public static Rhino.Commands.Result OrientOnSrf(Rhino.RhinoDoc doc)
    {
        // Select objects to orient
        Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
        go.SetCommandPrompt("Select objects to orient");
        go.SubObjectSelect = false;
        go.GroupSelect     = true;
        go.GetMultiple(1, 0);
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        // Point to orient from
        Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint();
        gp.SetCommandPrompt("Point to orient from");
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Define source plane
        Rhino.Display.RhinoView view = gp.View();
        if (view == null)
        {
            view = doc.Views.ActiveView;
            if (view == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
        }
        Rhino.Geometry.Plane source_plane = view.ActiveViewport.ConstructionPlane();
        source_plane.Origin = gp.Point();

        // Surface to orient on
        Rhino.Input.Custom.GetObject gs = new Rhino.Input.Custom.GetObject();
        gs.SetCommandPrompt("Surface to orient on");
        gs.GeometryFilter              = Rhino.DocObjects.ObjectType.Surface;
        gs.SubObjectSelect             = true;
        gs.DeselectAllBeforePostSelect = false;
        gs.OneByOnePostSelect          = true;
        gs.Get();
        if (gs.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gs.CommandResult());
        }

        Rhino.DocObjects.ObjRef objref = gs.Object(0);
        // get selected surface object
        Rhino.DocObjects.RhinoObject obj = objref.Object();
        if (obj == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // get selected surface (face)
        Rhino.Geometry.Surface surface = objref.Surface();
        if (surface == null)
        {
            return(Rhino.Commands.Result.Failure);
        }
        // Unselect surface
        obj.Select(false);

        // Point on surface to orient to
        gp.SetCommandPrompt("Point on surface to orient to");
        gp.Constrain(surface, false);
        gp.Get();
        if (gp.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(gp.CommandResult());
        }

        // Do transformation
        Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
        double u, v;

        if (surface.ClosestPoint(gp.Point(), out u, out v))
        {
            Rhino.Geometry.Plane target_plane;
            if (surface.FrameAt(u, v, out target_plane))
            {
                // Build transformation
                Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.PlaneToPlane(source_plane, target_plane);

                // Do the transformation. In this example, we will copy the original objects
                const bool delete_original = false;
                for (int i = 0; i < go.ObjectCount; i++)
                {
                    doc.Objects.Transform(go.Object(i), xform, delete_original);
                }

                doc.Views.Redraw();
                rc = Rhino.Commands.Result.Success;
            }
        }
        return(rc);
    }
Example #29
0
 protected override bool OnRenderWindowBegin(Rhino.Display.RhinoView view, System.Drawing.Rectangle rect)
 {
     return(false);
 }