Beispiel #1
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView rhino_view = RhUtil.RhinoApp().ActiveView();

            if (null == rhino_view)
            {
                return(IRhinoCommand.result.failure);
            }

            On3dmView view = new On3dmView(rhino_view.ActiveViewport().View());

            view.m_wallpaper_image.Default();
            _saved_views.Push(view);

            int count = _saved_views.Count;

            if (1 == count)
            {
                RhUtil.RhinoApp().Print("The saved view stack has 1 entry.\n");
            }
            else
            {
                RhUtil.RhinoApp().Print(string.Format("The saved view stack has {0} entries.\n", count));
            }

            return(IRhinoCommand.result.success);
        }
Beispiel #2
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            MRhinoViewport             vp = view.ActiveViewport();
            MRhinoDisplayPipeline      dp = view.DisplayPipeline();
            MDisplayPipelineAttributes da = view.DisplayAttributes();

            // Prevent capturing of the frame buffer on every update
            MRhinoDisplayPipeline.EnableFrameBufferCapture(false);
            // Prevent the draw list from updating on every frame
            dp.FreezeDrawing(true);

            int    dir         = 0; // 0 = Right, 1 = Left, 2 = Down, and 3 = Up
            int    frame_count = 100;
            double delta_angle = 5.0 * (Math.PI / 180.0);

            for (int i = 0; i < frame_count; i++)
            {
                switch (dir)
                {
                case 0:
                    vp.LeftRightRotate(delta_angle);
                    break;

                case 1:
                    vp.LeftRightRotate(-delta_angle);
                    break;

                case 2:
                    vp.DownUpRotate(delta_angle);
                    break;

                case 3:
                    vp.DownUpRotate(-delta_angle);
                    break;
                }
                //dp.DrawFrameBuffer(da);
                view.Redraw();
                RhUtil.RhinoApp().Wait(0);
            }

            dp.FreezeDrawing(false);
            MRhinoDisplayPipeline.EnableFrameBufferCapture(true);

            view.Redraw();

            return(IRhinoCommand.result.success);
        }
        /// <summary>
        /// This method is called when the drag and drop operation is completed and
        /// the item being dragged was dropped on a valid, top level Rhino object.
        /// </summary>
        public override bool OnDropOnObject(IRhinoObjRef objRef, MRhinoView rhinoView, DataObject data, DragDropEffects dropEffect, Point point)
        {
            SampleCsDragData dragData = GetSampleCsDragData(data);
              if (null == dragData)
            return false;

              MessageBox.Show(
            RhUtil.RhinoApp().MainWnd(),
            "String \"" + dragData.DragString + "\" Dropped on object",
            "SampleCsDragDrop",
            MessageBoxButtons.OK,
            MessageBoxIcon.Information
            );

              return true;
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null != view)
            {
                // 1/2 of smallest subtended view angle
                double half_smallest_angle = 0.0;
                if (view.ActiveViewport().VP().GetCameraAngle(ref half_smallest_angle))
                {
                    string fov = string.Empty;
                    RhUtil.RhinoFormatNumber(half_smallest_angle * (180.0 / OnUtil.On_PI), ref fov);
                    RhUtil.RhinoApp().Print(string.Format("Field of view =  {0} degrees.\n", fov));
                }
            }
            return(IRhinoCommand.result.success);
        }
Beispiel #5
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null != view)
            {
                int left = 0, right = 0, bottom = 0, top = 0;
                view.ActiveViewport().VP().GetScreenPort(ref left, ref right, ref bottom, ref top);

                string name   = view.ActiveViewport().Name();
                int    width  = right - left;
                int    height = bottom - top;
                RhUtil.RhinoApp().Print(string.Format("Name = {0}: Width = {1}, Height = {2}\n", name, width, height));
            }

            return(IRhinoCommand.result.cancel);
        }
Beispiel #6
0
        /// <summary>
        /// This method is called when the drag and drop operation is completed and
        /// the item being dragged was dropped on a valid, top level Rhino object.
        /// </summary>
        public override bool OnDropOnObject(IRhinoObjRef objRef, MRhinoView rhinoView, DataObject data, DragDropEffects dropEffect, Point point)
        {
            SampleCsDragData dragData = GetSampleCsDragData(data);

            if (null == dragData)
            {
                return(false);
            }

            MessageBox.Show(
                RhUtil.RhinoApp().MainWnd(),
                "String \"" + dragData.DragString + "\" Dropped on object",
                "SampleCsDragDrop",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information
                );

            return(true);
        }
Beispiel #7
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (view == null)
            {
                return(IRhinoCommand.result.nothing);
            }

            MRhinoGetOption go = new MRhinoGetOption();

            go.SetCommandPrompt("Capture Method");
            go.SetCommandPromptDefault("ViewCapture");
            int viewcap   = go.AddCommandOption(new MRhinoCommandOptionName("ViewCapture"));
            int screencap = go.AddCommandOption(new MRhinoCommandOptionName("ScreenCapture"));

            go.GetOption();
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            System.Drawing.Bitmap bmp = null;

            if (go.Option().m_option_index == viewcap)
            {
                MRhinoDisplayPipeline pipeline = view.DisplayPipeline();
                int left = 0, right = 0, bot = 0, top = 0;
                view.MainViewport().VP().GetScreenPort(ref left, ref right, ref bot, ref top);
                int w = right - left;
                int h = bot - top;
                bmp = new System.Drawing.Bitmap(w, h);
                System.Drawing.Graphics    g    = System.Drawing.Graphics.FromImage(bmp);
                MDisplayPipelineAttributes attr = new MDisplayPipelineAttributes(pipeline.DisplayAttrs());
                bool rc = pipeline.DrawToDC(g, w, h, attr);
                g.Dispose();
                if (!rc)
                {
                    bmp = null;
                }
            }
            else
            {
                bmp = new System.Drawing.Bitmap(1, 1);
                bool rc = view.ScreenCaptureToBitmap(ref bmp, true, false);
                if (!rc)
                {
                    bmp = null;
                }
            }

            if (bmp != null)
            {
                string mydir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
                string path  = System.IO.Path.Combine(mydir, "capture.png");
                bmp.Save(path);
                return(IRhinoCommand.result.success);
            }

            return(IRhinoCommand.result.failure);
        }
Beispiel #8
0
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            MRhinoView rhino_view = RhUtil.RhinoApp().ActiveView();

            if (null == rhino_view)
            {
                return(IRhinoCommand.result.failure);
            }

            On3dmView saved_view = SampleCsSaveView.Instance.PopView();

            if (null == saved_view)
            {
                RhUtil.RhinoApp().Print("No saved views to restore.\n");
                return(IRhinoCommand.result.nothing);
            }

            MRhinoViewport viewport = rhino_view.ActiveViewport();

            int scr_left = 0, scr_right = 0, scr_bottom = 0, scr_top = 0;

            viewport.VP().GetScreenPort(ref scr_left, ref scr_right, ref scr_bottom, ref scr_top);

            On3dmView new_view = new On3dmView(saved_view);

            new_view.m_vp.SetScreenPort(scr_left, scr_right, scr_bottom, scr_top);

            double aspect = 0.0;

            if (new_view.m_vp.GetScreenPortAspect(ref aspect))
            {
                new_view.m_vp.SetFrustumAspect(aspect);
            }

            // Some optional parameters that you might want to control
            // when restoring a saved view
            bool bSavedViewSetsConstructionPlane = true;
            bool bSavedViewSetsProjection        = true;
            bool bSavedViewSetsTraceImage        = true;

            // Keep existing construction plane?
            if (!bSavedViewSetsConstructionPlane)
            {
                new_view.m_cplane = new On3dmConstructionPlane(viewport.ConstructionPlane());
            }

            // Keep existing projection?
            if (!bSavedViewSetsProjection)
            {
                new_view.m_vp.SetProjection(viewport.VP().Projection());
            }

            // Copy parameters from existing view that you might want to keep
            // from current view
            new_view.m_position        = new On3dmViewPosition(viewport.View().m_position);
            new_view.m_trace_image     = new On3dmViewTraceImage(viewport.View().m_trace_image);
            new_view.m_wallpaper_image = new On3dmWallpaperImage(viewport.View().m_wallpaper_image);
            new_view.m_clipping_planes = new ArrayOnClippingPlaneInfo(viewport.View().m_clipping_planes);
            new_view.m_display_mode    = viewport.DisplayMode();
            new_view.m_display_mode_id = viewport.View().m_display_mode_id;

            // Do the view restoration
            viewport.SetView(new_view);

            // Keep existing trace image?
            if (!bSavedViewSetsTraceImage)
            {
                viewport.SetTraceImage(saved_view.m_trace_image);
            }

            // Append the current view onto Rhino's view stack
            viewport.PushViewProjection();

            // Redraw
            rhino_view.Redraw();

            return(IRhinoCommand.result.success);
        }
        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            // Select a curve object
            MRhinoGetObject go = new MRhinoGetObject();

            go.SetCommandPrompt("Select curve");
            go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.curve_object);
            go.GetObjects(1, 1);
            if (go.CommandResult() != IRhinoCommand.result.success)
            {
                return(go.CommandResult());
            }

            // Validate the selection
            IRhinoObject obj = go.Object(0).Object();

            if (null == obj)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the active view
            MRhinoView view = RhUtil.RhinoApp().ActiveView();

            if (null == view)
            {
                return(IRhinoCommand.result.failure);
            }

            // Get the construction plane from the active view
            OnPlane plane = new OnPlane(view.ActiveViewport().ConstructionPlane().m_plane);

            // Create a construction plane aligned bounding box
            OnBoundingBox bbox = new OnBoundingBox();

            IRhinoObject[] objs = new IRhinoObject[1] {
                obj
            };
            bool rc = RhUtil.RhinoGetTightBoundingBox(objs, ref bbox, false, plane);

            if (rc == false)
            {
                return(IRhinoCommand.result.failure);
            }

            // Validate bounding box
            if (0 != bbox.IsDegenerate())
            {
                RhUtil.RhinoApp().Print("Curve's tight bounding box is degenerate.\n");
                return(IRhinoCommand.result.nothing);
            }

            // ON_BrepBox wants 8 points defining the box corners
            // arranged in this order:
            //
            //          v7______________v6
            //           |\             |\
            //           | \            | \
            //           |  \ _____________\ 
            //           |   v4         |   v5
            //           |   |          |   |
            //           |   |          |   |
            //          v3---|---------v2   |
            //           \   |          \   |
            //            \  |           \  |
            //             \ |            \ |
            //              \v0____________\v1
            //
            On3dPoint[] box_corners = new On3dPoint[8];
            box_corners[0] = bbox.Corner(0, 0, 0);
            box_corners[1] = bbox.Corner(1, 0, 0);
            box_corners[2] = bbox.Corner(1, 1, 0);
            box_corners[3] = bbox.Corner(0, 1, 0);
            box_corners[4] = bbox.Corner(0, 0, 1);
            box_corners[5] = bbox.Corner(1, 0, 1);
            box_corners[6] = bbox.Corner(1, 1, 1);
            box_corners[7] = bbox.Corner(0, 1, 1);

            // Transform points to the world-xy plane
            OnXform p2w = new OnXform();

            p2w.ChangeBasis(plane, OnUtil.On_xy_plane);
            for (int i = 0; i < 8; i++)
            {
                box_corners[i].Transform(p2w);
            }

            // Make a brep box
            OnBrep brep = OnUtil.ON_BrepBox(box_corners);

            if (null != brep)
            {
                context.m_doc.AddBrepObject(brep);
                context.m_doc.Redraw();
            }

            return(IRhinoCommand.result.success);
        }