/// <summary>
        /// Creates the layout.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="panelParas">The panel paras.</param>
        /// <returns></returns>
        public Result createSummary(RhinoDoc doc, List <FoldedPerforationPanel> panel, double openAreaDifference)
        {
            // Add Summary layout

            if (panel == null)
            {
                panel = new List <FoldedPerforationPanel>();
            }


            RhinoView currentView = doc.Views.ActiveView;
            var       pageview    = doc.Views.AddPageView("Summary", 210, 297);
            Point2d   bottomLeft  = new Point2d(10, 70);
            Point2d   topRight    = new Point2d(200, 287);

            if (pageview != null)
            {
                pageview.SetPageAsActive();
                doc.Views.ActiveView = pageview;

                drawBlock(doc, panel, openAreaDifference);
            }

            // Show all objects
            RhinoApp.RunScript("_-Show _Enter", true);

            doc.Views.DefaultViewLayout();

            doc.Views.ActiveView = currentView;

            return(Result.Success);
        }
Beispiel #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)
        {
            bool createClippingPlane = false;

            if (!DA.GetData(0, ref createClippingPlane))
            {
                return;
            }

            Plane referencePlane = new Plane();
            bool  success        = DA.GetData(1, ref referencePlane);

            Guid id = Guid.Empty;

            if (success && createClippingPlane)
            {
                //define active document
                RhinoDoc activeDoc = RhinoDoc.ActiveDoc;

                //Get the active view
                RhinoView currentView = activeDoc.Views.ActiveView;

                //Viewport where use the clipping plane
                Guid currentViewId = currentView.ActiveViewportID;


                //add clipping Plane
                id = activeDoc.Objects.AddClippingPlane(referencePlane, 1, 1, currentViewId);
            }

            DA.SetData(0, id);
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoView view = doc.Views.ActiveView;

            if (null == view)
            {
                return(Result.Failure);
            }

            string name = null;
            Result rc   = RhinoGet.GetString("Named view to restore", false, ref name);

            if (rc != Result.Success || string.IsNullOrEmpty(name))
            {
                return(Result.Cancel);
            }

            int index = doc.NamedViews.FindByName(name);

            if (index < 0 || index >= doc.NamedViews.Count)
            {
                RhinoApp.WriteLine("Named view not found");
                return(Result.Nothing);
            }

            //doc.NamedViews.Restore(index, view, false);
            doc.NamedViews.RestoreAnimated(index, view, false);
            view.Redraw();

            return(Result.Success);
        }
Beispiel #4
0
        private List <ObjRef> ssget_point(RhinoDoc doc, RhinoView view, Point3d point)
        {
            var world_to_screen = view.ActiveViewport.GetTransform(CoordinateSystem.World, CoordinateSystem.Screen);

            point.Transform(world_to_screen);

            var pick_context = new PickContext();

            pick_context.View              = view;
            pick_context.PickStyle         = PickStyle.PointPick;
            pick_context.PickGroupsEnabled = true;

            var xform = view.ActiveViewport.GetPickTransform(Convert.ToInt32(point.X), Convert.ToInt32(point.Y));

            pick_context.SetPickTransform(xform);
            double depth, distance;

            foreach (var rhino_object in doc.Objects)
            {
                //rhino_object.OnPicked(pick_context, )
            }
            if (pick_context.PickFrustumTest(point, out depth, out distance))
            {
                pick_context.UpdateClippingPlanes();
            }
            return(null);
        }
Beispiel #5
0
 public void ApplySettings(RhinoView view)
 {
     view.ActiveViewport.CameraUp = Up;
     view.ActiveViewport.SetCameraLocation(Location, false);
     view.ActiveViewport.SetCameraDirection(Direction, false);
     view.ActiveViewport.SetCameraTarget(Target, false);
 }
Beispiel #6
0
 public CameraSettings(RhinoView view)
 {
     Location  = view.ActiveViewport.CameraLocation;
     Target    = view.ActiveViewport.CameraTarget;
     Direction = Target - Location;
     Up        = view.ActiveViewport.CameraUp;
 }
Beispiel #7
0
        protected void MaintainViewPort(int Width, int Height, double Reduce)
        {
            int width  = (int)((float)Width / Reduce);
            int height = (int)((float)Height / Reduce);
            int x      = Convert.ToInt32(Math.Round((double)Screen.PrimaryScreen.Bounds.Width - width));
            int y      = 200;


            if (Rhino.RhinoDoc.ActiveDoc.Views.Find("Whale", true) == null)
            {
                RhinoView      = Rhino.RhinoDoc.ActiveDoc.Views.Add("Whale", DefinedViewportProjection.Perspective, new Rectangle(x, y, width, height), true);
                RhinoView.Size = new Size(width, height);
                RhinoView.ActiveViewport.DisplayMode = DisplayModeDescription.GetDisplayMode(DisplayModeDescription.RenderedId);
                IntPtr parent = GetControl.GetParent(RhinoView.Handle);
                GetControl.SetWindowPos(parent, -1, 0, 0, 0, 0, 3);
            }
            else
            {
                RhinoView = Rhino.RhinoDoc.ActiveDoc.Views.Find("Whale", true);
                int viewWidth = RhinoView.Size.Width;
                Reduce         = (float)Width / (float)viewWidth;
                RhinoView.Size = new Size(viewWidth, viewWidth * height / width);
                RhinoView.Redraw();
            }
        }
        public static bool ActivateGlContext()
        {
            if (OpenGL.wglGetCurrentContext() != IntPtr.Zero)
            {
                return(true);
            }

            if (IntPtr.Zero == _hglrc)
            {
                return(false);
            }
            RhinoView view = RhinoView.FromRuntimeSerialNumber(_viewSerialNumber);

            if (null == view)
            {
                _hglrc            = IntPtr.Zero;
                _viewSerialNumber = 0;
                return(false);
            }
            var hwnd = view.Handle;
            var hdc  = OpenGL.GetDC(hwnd);

            OpenGL.wglMakeCurrent(hdc, _hglrc);
            return(true);
        }
        private RhinoViewport camera; //ビューポートのカメラの設定

        ////////////////
        //constructors//
          ////////////////


        public ChangeCoordinates(
            int _size,
            RhinoView _view
            )
        {
            size = _size;
            view = _view;

            camera = new RhinoViewport(view.ActiveViewport);//ビューポートのカメラの設定を格納
        }
        public static string CaptureImage(string pathToFile, string fileName, bool transparent, bool activate)
        {
            string result = "Failure";

            if (activate == false)
            {
                return("Not Activated");
            }
            else if (pathToFile == "")
            {
                return("Path does not exist");
            }
            else if (!System.IO.Directory.Exists(pathToFile))
            {
                return("Path does not exist");
            }


            RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

            if (null == view)
            {
                return(result);
            }

            var view_capture = new ViewCapture
            {
                Width                 = view.ActiveViewport.Size.Width,
                Height                = view.ActiveViewport.Size.Height,
                ScaleScreenItems      = false,
                DrawAxes              = false,
                DrawGrid              = false,
                DrawGridAxes          = false,
                TransparentBackground = transparent,
            };

            System.Drawing.Bitmap bitmap = view_capture.CaptureToBitmap(view);

            if (null != bitmap)
            {
                if (!pathToFile.EndsWith("\\"))
                {
                    pathToFile = pathToFile + "\\";
                }

                var filename = pathToFile + fileName + ".png";
                bitmap.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
                return("Success");
            }
            return(result);
        }
Beispiel #11
0
        public string ViewToNative(View3D view)
        {
            Rhino.RhinoApp.InvokeOnUiThread((Action) delegate {
                RhinoView _view        = Doc.Views.ActiveView;
                RhinoViewport viewport = _view.ActiveViewport;
                viewport.SetProjection(DefinedViewportProjection.Perspective, null, false);
                var origin  = PointToNative(view.origin).Location;
                var forward = new Vector3d(view.forwardDirection.x, view.forwardDirection.y, view.forwardDirection.z);

                if (view.target != null)
                {
                    viewport.SetCameraLocations(PointToNative(view.target).Location, origin); // this changes viewport.CameraUp. works for axon from revit if after, for perspective from revit if before
                }
                else
                {
                    viewport.SetCameraLocation(origin, true);
                    viewport.SetCameraDirection(forward, true);
                }
                viewport.CameraUp = new Vector3d(view.upDirection.x, view.upDirection.y, view.upDirection.z);

                viewport.Name = view.name;

                /* TODO: debug this and see if it helps better match views from revit
                 * // set bounding box
                 * var box = BoxToNative(view.boundingBox);
                 * BoundingBox boundingBox = new BoundingBox(box.X.Min, box.Y.Min, box.Z.Min, box.X.Max, box.Y.Max, box.Z.Max);
                 * viewport.SetClippingPlanes(boundingBox);
                 */

                // set rhino view props if available
                SetViewParams(viewport, view);

                if (view.isOrthogonal)
                {
                    viewport.ChangeToParallelProjection(true);
                }

                var commitInfo = GetCommitInfo();
                var viewName   = $"{commitInfo } - {view.name}";

                Doc.NamedViews.Add(viewName, viewport.Id);
            });

            //ConversionErrors.Add(sdfasdfaf);

            return("baked");
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoView view = doc.Views.ActiveView;

            if (null == view)
            {
                return(Result.Failure);
            }

            const string           englishName = @"Shaded";
            DisplayModeDescription display_mode_description = DisplayModeDescription.FindByName(englishName);

            if (null != display_mode_description)
            {
                view.ActiveViewport.DisplayMode = display_mode_description;
                view.Redraw();
            }

            return(Result.Success);
        }
Beispiel #13
0
        public static bool ActivateGlContext()
        {
            if (!OpenGL.IsAvailable)
            {
                return(false);
            }

            // just assume GL context is active for now
            if (Rhino.Runtime.HostUtils.RunningOnOSX)
            {
                return(true);
            }

            if (OpenGL.wglGetCurrentContext() != IntPtr.Zero)
            {
                return(true);
            }

            if (IntPtr.Zero == _hglrc)
            {
                return(false);
            }

            RhinoView view = RhinoView.FromRuntimeSerialNumber(_viewSerialNumber);

            if (null == view)
            {
                _hglrc            = IntPtr.Zero;
                _viewSerialNumber = 0;
                return(false);
            }
            var hwnd = view.Handle;
            var hdc  = OpenGL.GetDC(hwnd);

            OpenGL.wglMakeCurrent(hdc, _hglrc);
            return(true);
        }
Beispiel #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Locals
            Plane     plane;
            Point3d   base_point = Point3d.Unset;
            Point3d   ref_point  = Point3d.Unset;
            GetResult res        = GetResult.Nothing;
            Result    rc         = Result.Nothing;


            // Select objects to rotate
            TransformObjectList list = new TransformObjectList();

            rc = SelectObjects("Select objects to rotate", list);
            if (rc != Result.Success)
            {
                return(rc);
            }

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Center of rotation");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            RhinoView view = gp.View();

            if (null == view)
            {
                return(Result.Failure);
            }

            base_point   = gp.Point();
            plane        = view.ActiveViewport.ConstructionPlane();
            plane.Origin = base_point;


            // Angle or first reference point
            GetReferencePoint gr = new GetReferencePoint(base_point);

            gr.SetCommandPrompt("Angle or first reference point");
            res = gr.Get();
            if (res == GetResult.Point)
            {
                view = gr.View();
                rc   = (null != view) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    plane        = view.ActiveViewport.ConstructionPlane();
                    plane.Origin = base_point;
                    ref_point    = plane.ClosestPoint(gr.Point());
                    if (base_point.DistanceTo(ref_point) <= RhinoMath.ZeroTolerance)
                    {
                        rc = Result.Nothing;
                    }
                }
                if (rc != Result.Success)
                {
                    return(rc);
                }
            }
            else if (res == GetResult.Number)
            {
                Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gr.Number()), plane.Normal, base_point);
                rc = (xform.IsValid) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    TransformObjects(list, xform, false, false);
                    doc.Views.Redraw();
                }
                return(rc);
            }
            else
            {
                return(Result.Cancel);
            }


            // Second reference point
            GetRotationTransform gx = new GetRotationTransform(plane, base_point, ref_point);

            gx.SetCommandPrompt("Second reference point");
            gx.AddTransformObjects(list);
            res = gx.GetXform();
            if (res == GetResult.Point)
            {
                view = gx.View();
                rc   = (null != view) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
                    rc = (xform.IsValid) ? Result.Success : Result.Failure;
                    if (rc == Result.Success)
                    {
                        TransformObjects(list, xform, false, false);
                        doc.Views.Redraw();
                    }
                }
            }
            else if (res == GetResult.Number)
            {
                Transform xform = Transform.Rotation(Rhino.RhinoMath.ToRadians(gx.Number()), plane.Normal, base_point);
                rc = (xform.IsValid) ? Result.Success : Result.Failure;
                if (rc == Result.Success)
                {
                    TransformObjects(list, xform, false, false);
                    doc.Views.Redraw();
                }
            }
            else
            {
                rc = Result.Cancel;
            }

            return(rc);
        }
Beispiel #15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Base of cylinder");
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d   center = gp.Point();
            Plane     plane  = Plane.WorldXY;
            RhinoView view   = gp.View();

            if (null != view)
            {
                plane = view.ActiveViewport.ConstructionPlane();
            }
            plane.Origin = center;

            var cylinder = new SampleCsGumballCylinder(plane, m_radius, m_height);

            var radius_go = new GumballObject();
            var height_go = new GumballObject();

            var radius_dc = new GumballDisplayConduit();
            var height_dc = new GumballDisplayConduit();

            var radius_gas = RadiusGumballAppearanceSettings();
            var height_gas = HeightGumballAppearanceSettings();

            while (true)
            {
                radius_go.SetFromPlane(cylinder.RadiusPlane);
                height_go.SetFromPlane(cylinder.HeightPlane);

                radius_dc.SetBaseGumball(radius_go, radius_gas);
                height_dc.SetBaseGumball(height_go, height_gas);

                radius_dc.Enabled = true;
                height_dc.Enabled = true;

                var gx = new SampleCsGumballCylinderGetPoint(cylinder, radius_dc, height_dc);
                gx.SetCommandPrompt("Drag gumball. Press Enter when done");
                gx.AcceptNothing(true);
                gx.MoveGumball();

                radius_dc.Enabled = false;
                height_dc.Enabled = false;

                if (gx.CommandResult() != Result.Success)
                {
                    break;
                }

                var res = gx.Result();
                if (res == GetResult.Point)
                {
                    var radius = cylinder.Radius;
                    var height = cylinder.Height;
                    cylinder = new SampleCsGumballCylinder(plane, radius, height);
                    continue;
                }
                if (res == GetResult.Nothing)
                {
                    m_radius = cylinder.Radius;
                    m_height = cylinder.Height;
                    cylinder = new SampleCsGumballCylinder(plane, m_radius, m_height);
                    var brep = cylinder.ToBrep;
                    if (null != brep)
                    {
                        doc.Objects.AddBrep(brep);
                    }
                }

                break;
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
 protected override Result RenderWindow(RhinoDoc doc, RunMode mode, bool fastPreview, RhinoView view, Rectangle rect, bool inWindow)
 {
     return(Result.Success);
 }
 protected override bool OnRenderWindowBegin(RhinoView view, Rectangle rectangle)
 {
     return(false);
 }
 /// <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 Result RenderWindow(RhinoDoc doc, RunMode mode, bool fastPreview, RhinoView view,
                                        Rectangle rect, bool inWindow)
 {
     //throw new NotImplementedException();
     return(Result.Success);
 }
Beispiel #19
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Result    rc  = Result.Nothing;
            GetResult res = GetResult.Nothing;

            // Select objects to rotate
            TransformObjectList list = new TransformObjectList();

            rc = SelectObjects("Select objects to transform", list);
            if (rc != Result.Success)
            {
                return(rc);
            }

            OptionToggle opt_xset = new OptionToggle(true, "No", "Yes");
            OptionToggle opt_yset = new OptionToggle(true, "No", "Yes");
            OptionToggle opt_zset = new OptionToggle(true, "No", "Yes");

            // Second reference point
            GetSetPointTransform gx = new GetSetPointTransform(true, true, true);

            gx.SetCommandPrompt("Location for points");
            gx.AddTransformObjects(list);
            for (;;)
            {
                gx.ClearCommandOptions();
                gx.AddOptionToggle("XSet", ref opt_xset);
                gx.AddOptionToggle("YSet", ref opt_yset);
                gx.AddOptionToggle("ZSet", ref opt_zset);

                res = gx.GetXform();

                if (res == GetResult.Point)
                {
                    RhinoView view = gx.View();
                    rc = (null != view) ? Result.Success : Result.Failure;
                    if (rc == Result.Success)
                    {
                        Transform xform = gx.CalculateTransform(view.ActiveViewport, gx.Point());
                        rc = (xform.IsValid) ? Result.Success : Result.Failure;
                        if (rc == Result.Success)
                        {
                            TransformObjects(list, xform, false, false);
                            doc.Views.Redraw();
                        }
                    }
                }
                else if (res == GetResult.Option)
                {
                    gx.SetX = opt_xset.CurrentValue;
                    gx.SetY = opt_yset.CurrentValue;
                    gx.SetZ = opt_zset.CurrentValue;
                    continue;
                }
                else
                {
                    rc = Result.Cancel;
                }

                break;
            }

            return(rc);
        }
        /// <summary>
        /// Creates the layout.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="panel">The panel.</param>
        /// <param name="panelParas">The panel paras.</param>
        /// <returns></returns>
        public Result createLayout(RhinoDoc doc, FoldedPerforationPanel panel, PanelParameters panelParas)
        {
            if (panelParas == null)
            {
                panelParas = new PanelParameters();
            }

            if (panel == null)
            {
                panel = new FoldedPerforationPanel();
            }

            // Get all selected Objects
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.EnablePressEnterWhenDonePrompt(false);

            go.SetCommandPrompt("Select items for the new layout:");

            // Disable the scaling
            RhinoApp.RunScript("_-DocumentProperties AnnotationStyles ModelSpaceScaling=Disabled LayoutSpaceScaling=Disabled _Enter _Enter", true);

            GetResult result = go.GetMultiple(1, -1);

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

            RhinoApp.WriteLine("Total Objects Selected: {0}", go.ObjectCount);

            string  labelName = panel.PartName;
            string  area      = string.Format("{0:0.00}", panel.Area);
            Point2d minPoint  = new Point2d(0, 0);
            Point2d maxPoint  = new Point2d(0, 0);

            // Loop through all the objects to find Text
            for (int i = 0; i < go.ObjectCount; i++)
            {
                BoundingBox bBox = go.Object(i).Object().Geometry.GetBoundingBox(true);

                if (bBox.Min.X < minPoint.X)
                {
                    minPoint.X = bBox.Min.X;
                }

                if (bBox.Min.Y < minPoint.Y)
                {
                    minPoint.Y = bBox.Min.Y;
                }

                if (bBox.Max.X > maxPoint.X)
                {
                    maxPoint.X = bBox.Max.X;
                }

                if (bBox.Max.Y > maxPoint.Y)
                {
                    maxPoint.Y = bBox.Max.Y;
                }
            }

            // If the selected items has no label, return failure
            if (labelName == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            // Hide all the non selected objects
            foreach (var obj in doc.Objects)
            {
                if (obj.IsSelected(true) == 0)
                {
                    doc.Objects.Hide(obj, false);
                }
            }

            // Add layout
            doc.PageUnitSystem = Rhino.UnitSystem.Millimeters;


            RhinoView currentView = doc.Views.ActiveView;
            var       pageview    = doc.Views.AddPageView(string.Format("{0}", labelName), 210, 297);
            Point2d   bottomLeft  = new Point2d(10, 70);
            Point2d   topRight    = new Point2d(200, 287);

            if (pageview != null)
            {
                pageview.SetPageAsActive();

                var detail = pageview.AddDetailView("Panel", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                // Show all objects
                RhinoApp.RunScript("_-Show _Enter", true);

                if (detail != null)
                {
                    pageview.SetActiveDetail(detail.Id);

                    doc.Views.ActiveView = pageview;

                    //doc.Views.Redraw();
                    // Select all the objects
                    for (int i = 0; i < go.ObjectCount; i++)
                    {
                        RhinoObject rhinoObject = go.Object(i).Object();

                        rhinoObject.Select(true);
                    }

                    // Hide all the non selected objects
                    var filter = new ObjectEnumeratorSettings
                    {
                        NormalObjects    = true,
                        LockedObjects    = false,
                        HiddenObjects    = false,
                        ActiveObjects    = true,
                        ReferenceObjects = true
                    };

                    var rh_objects = doc.Objects.FindByFilter(filter);

                    pageview.SetPageAsActive();

                    //doc.Views.Redraw();

                    foreach (var rh_obj in rh_objects)
                    {
                        var select = 0 == rh_obj.IsSelected(false) && rh_obj.IsSelectable();
                        rh_obj.Select(select);
                    }

                    RhinoApp.RunScript("_-HideInDetail Enter", true);

                    detail.IsActive = false;
                }

                bottomLeft = new Point2d(10, 40);
                topRight   = new Point2d(135, 70);

                detail = pageview.AddDetailView("Sample", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(50, 160, 0), true);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(4.5, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                //  doc.Views.Redraw();


                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                RhinoApp.WriteLine("Name = {0}: Width = {1}, Height = {2}",
                                   detail.Viewport.Name, detail.Viewport.Size.Width, detail.Viewport.Size.Height);
                detail.CommitViewportChanges();
                //  doc.Views.Redraw();

                detail.IsActive = false;

                bottomLeft = new Point2d(5, 5);
                topRight   = new Point2d(205, 35);
                detail     = pageview.AddDetailView("Block", bottomLeft, topRight, Rhino.Display.DefinedViewportProjection.Top);

                //  doc.Views.Redraw();

                detail.IsActive = true;
                pageview.SetActiveDetail(detail.Id);

                detail.Viewport.SetCameraLocation(new Point3d(105, 520, 0), true);
                detail.CommitViewportChanges();

                //  doc.Views.Redraw();

                detail.DetailGeometry.IsProjectionLocked = true;
                detail.DetailGeometry.SetScale(1, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
                detail.CommitChanges();

                detail.IsActive = false;
                //  doc.Views.Redraw();

                drawBlock(doc, labelName, area, panel.PanelNumber, panelParas);

                //  doc.Views.Redraw();
            }

            // Show all objects
            RhinoApp.RunScript("_-Show _Enter", true);

            doc.Views.DefaultViewLayout();

            doc.Views.ActiveView = currentView;

            return(Result.Success);
        }
 protected override bool OnDropOnObject(ObjRef objRef, RhinoView rhinoView, DataObject dataObject, DragDropEffects dropEffect, Point point)
 {
     RhinoApp.WriteLine($"SampleCsDropTarget.OnDropOnObject({DropString(dataObject)})");
     return(true);
 }
Beispiel #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)
        {
            string view_name = "";

            DA.GetData <string>(0, ref view_name);

            string server_msg = "";

            DA.GetData <string>(1, ref server_msg);

            string post = "{\"id\": \"" + screenshot_id + "\"}";

            //if (!active)
            if (Equals(server_msg, "100"))
            {
                string url = "http://127.0.0.1:5000/api/v1.0/ss-register-id";

                Tuple <bool, string> result = Helpers.PostToServer(url, post);
                string message = result.Item2;

                if (!result.Item1)
                {
                    Helpers.Print(DA, "Error:" + message);
                    throw new Exception(message);
                }
                else
                {
                    var serializer = new JavaScriptSerializer();
                    var json       = serializer.Deserialize <ScreenshotMSG>(message);

                    Helpers.Print(DA, json.status);
                    addFileWatcher(DA, json.path);
                }
            }

            if (active)
            {
                RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

                if (view_name == "")
                {
                    Helpers.Print(DA, "Using active viewport " + view.MainViewport.Name);
                }
                else
                {
                    ViewTable   view_table = Rhino.RhinoDoc.ActiveDoc.Views;
                    RhinoView[] views      = view_table.GetViewList(true, false);

                    bool exists = false;

                    for (int i = 0; i < views.Length; i++)
                    {
                        view = views[i];
                        string vp_name = view.MainViewport.Name;

                        if (string.Equals(vp_name, view_name))
                        {
                            Helpers.Print(DA, "Viewport " + view_name + " found");
                            exists = true;
                            break;
                        }
                    }

                    if (exists)
                    {
                    }
                    else
                    {
                        Helpers.Print(DA, "New viewport " + view_name + " created");
                        Rectangle rec      = new Rectangle(0, 0, 800, 600);
                        RhinoView new_view = view_table.Add(view_name, Rhino.Display.DefinedViewportProjection.Perspective, rec, true);
                        new_view.MainViewport.WorldAxesVisible        = false;
                        new_view.MainViewport.ConstructionGridVisible = false;
                        new_view.MainViewport.ConstructionAxesVisible = false;
                        new_view.MainViewport.DisplayMode             = DisplayModeDescription.FindByName("shaded");

                        view = new_view;
                    }


                    Bitmap bitmap = view.CaptureToBitmap(false, false, false);

                    string url = "http://127.0.0.1:5000/api/v1.0/ss-get-path";

                    Tuple <bool, string> result = Helpers.PostToServer(url, post);
                    string message = result.Item2;

                    if (!result.Item1)
                    {
                        Helpers.Print(DA, "Error:" + message);
                        throw new Exception(message);
                    }
                    else
                    {
                        var serializer = new JavaScriptSerializer();
                        var json       = serializer.Deserialize <ScreenshotMSG>(message);

                        if (string.Equals(json.status, "success"))
                        {
                            string[] components = { json.path, "png" };
                            string   path       = string.Join(".", components);

                            Helpers.Print(DA, "Screenshot captured to: " + path);
                            bitmap.Save(path);
                        }
                        else
                        {
                            Helpers.Print(DA, json.status);
                        }
                    }

                    Helpers.PingServer("http://127.0.0.1:5000/api/v1.0/ss-done");
                }
                //else
                //{
                //    Helpers.Print(DA, screenshot_id + " active.");
                //}

                active = false;
            }
        }