/// <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 <GeometryBase> G = new List <GeometryBase>(); if (!DA.GetDataList(0, G)) { return; } double inflate = 1.0; DA.GetData(1, ref inflate); bool go = false; DA.GetData(2, ref go); if (!go || G == null) { return; } //Get current viewport vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; // zoom to object bounding box BoundingBox bb, bTemp;// = G.GetBoundingBox(false); bb = G[0].GetBoundingBox(false); for (int i = 1; i < G.Count; i++) { bTemp = G[i].GetBoundingBox(false); bb.Union(bTemp); } bb.Inflate(bb.Diagonal.Length * inflate); vp.ZoomBoundingBox(bb); }
/// <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 run = false; if (!DA.GetData(0, ref run)) { return; } if (run) { //Get camera //Get current viewport vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; //save camera location and camera target DA.SetData(0, vp.CameraLocation); DA.SetData(1, vp.CameraTarget); DA.SetData(2, vp.Camera35mmLensLength); DA.SetData(3, vp.CameraUp); Plane fp, np; vp.GetFrustumNearPlane(out np); vp.GetFrustumFarPlane(out fp); DA.SetData(4, np); DA.SetData(5, fp); } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); var lines = Value.GetConnectionLines(); if (lines.Count == 1) { _infoPanel.Positions.Add((lines[0].From + lines[0].To) * 0.5); } else { _infoPanel.Positions.Add((lines[0].From + lines[0].To) * 0.5); _infoPanel.Positions.Add((lines[lines.Count - 1].From + lines[lines.Count - 1].To) * 0.5); _infoPanel.Positions.Add((lines[0].From + lines[lines.Count - 1].From) * 0.5); _infoPanel.Positions.Add((lines[0].To + lines[lines.Count - 1].To) * 0.5); } if (GroupId != 0) { _infoPanel.Content.Add("Grp: " + GroupId); } _infoPanel.Content.Add("Stf: " + Axial_stiffness + " / " + Rotational_stiffness + " / " + Transversal_stiffness); } _infoPanel.Draw(pipeline, viewport); } }
/// <summary> /// Transform calculator /// </summary> public bool CalculateTransform(Rhino.Display.RhinoViewport vp, double length, ref Rhino.Geometry.Transform xform) { bool rc = false; if (null == xform) { xform = new Rhino.Geometry.Transform(); } xform = Rhino.Geometry.Transform.Identity; if (length >= Rhino.RhinoMath.ZeroTolerance) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane()) { Origin = m_origin }; Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane); Rhino.Geometry.Transform scale_xform = Rhino.Geometry.Transform.Scale(plane, length, length, length); xform = scale_xform * rotate_xform; rc = xform.IsValid; if (rc) { m_length = length; } } return(rc); }
public Transform CalculateTransform(Rhino.Display.RhinoViewport viewport, double d) { Point3d basePoint; if (!TryGetBasePoint(out basePoint)) { return(Transform.Identity); } Plane plane = viewport.ConstructionPlane(); plane.Origin = basePoint; Vector3d v = RefPoint - basePoint; double len1 = v.Length; if (Math.Abs(len1) < 0.000001) { return(Transform.Identity); } v.Unitize(); v = v * d; double len2 = v.Length; if (Math.Abs(len2) < 0.000001) { return(Transform.Identity); } Scale = len2 / len1;; return(Transform.Scale(plane, Scale, Scale, Scale)); }
public override void DrawViewportWires(IGH_PreviewArgs args) { base.DrawViewportWires(args); if (texts.Count == 0) { return; } Plane plane; args.Viewport.GetFrustumFarPlane(out plane); for (int i = 0; i < texts.Count; i++) { string text = texts[i]; double size = sizes[i]; Point3d location = locations[i]; plane.Origin = location; // Figure out the size. This means measuring the visible size in the viewport AT the current location. double pixPerUnit; Rhino.Display.RhinoViewport viewport = args.Viewport; viewport.GetWorldToScreenScale(location, out pixPerUnit); size = size / pixPerUnit; Rhino.Display.Text3d drawText = new Rhino.Display.Text3d(text, plane, size); args.Display.Draw3dText(drawText, args.WireColour); drawText.Dispose(); } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); _infoPanel.Positions.Add(Value.Location); _infoPanel.Content.Add("LC: " + LoadCase); if (!Forces.IsTiny()) { _infoPanel.Content.Add("Force: " + Forces.Length); } if (!Moments.IsTiny()) { _infoPanel.Content.Add("Moment: " + Moments.Length); } if (!Displacement.IsTiny()) { _infoPanel.Content.Add("Displacement: " + Displacement.Length); } if (!DisplacementRotational.IsTiny()) { _infoPanel.Content.Add("Rot.Displacement: " + DisplacementRotational.Length); } } _infoPanel.Draw(pipeline, viewport); } }
public override Transform CalculateTransform(Rhino.Display.RhinoViewport viewport, Point3d point) { if (m_dc.InRelocate) { // don't move objects while relocating gumball return(m_dc.PreTransform); } return(m_dc.TotalTransform); }
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); }
/// <summary> /// Convert a Rhino.Display.Viewport to an RMA.Rhino.IRhinoViewport. /// </summary> /// <param name="source">A RhinoCommon viewport.</param> /// <returns> /// Rhino_DotNet IRhinoViewport object on success. This will be an independent copy. /// </returns> public static object ToIRhinoViewport(Rhino.Display.RhinoViewport source) { object rc = null; IntPtr pSource = source.ConstPointer(); Type rhType = GetRhinoDotNetType("RMA.Rhino.MRhinoViewport"); if (IntPtr.Zero != pSource && null != rhType) { System.Reflection.MethodInfo mi = rhType.GetMethod("WrapNativePointer", new Type[] { typeof(IntPtr), typeof(bool), typeof(bool) }); const bool isConst = true; const bool doDelete = false; rc = mi.Invoke(null, new object[] { pSource, isConst, doDelete }); } return(rc); }
/// <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) { Point3d location = new Point3d(); if (!DA.GetData(0, ref location)) { return; } Point3d target = new Point3d(); if (!DA.GetData(1, ref target)) { return; } double lens = 35; DA.GetData(2, ref lens); if (lens == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Lens cannot be zero"); } Vector3d up = Vector3d.ZAxis; DA.GetData(3, ref up); bool activate = false; DA.GetData(4, ref activate); if (!activate) { Message = ""; } else { Message = "active"; //Get current viewport vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; //Set new camera vp.SetCameraLocations(target, location); vp.CameraUp = up; vp.ChangeToPerspectiveProjection(true, lens); } }
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(); } } } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); _infoPanel.Positions.Add(Value.Location); if (Id != 0) { _infoPanel.Content.Add("Id: " + Id); } } _infoPanel.Draw(pipeline, viewport); } }
public override void DrawViewportWires(IGH_PreviewArgs args) { args.Viewport.GetFrustumFarPlane(out Plane plane); Rhino.Display.RhinoViewport viewport = args.Viewport; //X軸 for (int i = 0; i < _xline.Count; i++) { if (x_guideline == 1) { args.Display.DrawPatternedLine(_xline[i], Color.Black, 0x00001111, 1); double size = fontsize; Point3d point = _xline[i].From; plane.Origin = point; viewport.GetWorldToScreenScale(point, out double pixPerUnit); size /= pixPerUnit; Rhino.Display.Text3d drawText = new Rhino.Display.Text3d(_xlabel[i], plane, size); drawText.HorizontalAlignment = TextHorizontalAlignment.Center; drawText.VerticalAlignment = TextVerticalAlignment.Top; args.Display.Draw3dText(drawText, Color.Black); drawText.Dispose(); } } //Y軸 for (int i = 0; i < _yline.Count; i++) { if (y_guideline == 1) { args.Display.DrawPatternedLine(_yline[i], Color.Black, 0x00001111, 1); double size = fontsize; Point3d point = _yline[i].From; plane.Origin = point; viewport.GetWorldToScreenScale(point, out double pixPerUnit); size /= pixPerUnit; Rhino.Display.Text3d drawText = new Rhino.Display.Text3d(_ylabel[i], plane, size); drawText.HorizontalAlignment = TextHorizontalAlignment.Right; drawText.VerticalAlignment = TextVerticalAlignment.Middle; args.Display.Draw3dText(drawText, Color.Black); drawText.Dispose(); } } //Z軸 for (int i = 0; i < _zline.Count; i++) { if (z_guideline == 1) { args.Display.DrawPatternedLine(_zline[i], Color.Black, 0x00001111, 1); double size = fontsize; Point3d point = _zline[i].From; plane.Origin = point; viewport.GetWorldToScreenScale(point, out double pixPerUnit); size /= pixPerUnit; Rhino.Display.Text3d drawText = new Rhino.Display.Text3d(_zlabel[i], plane, size); drawText.HorizontalAlignment = TextHorizontalAlignment.Right; drawText.VerticalAlignment = TextVerticalAlignment.Middle; args.Display.Draw3dText(drawText, Color.Black); drawText.Dispose(); } } }///ここからGUIの作成*****************************************************************************************
/// <summary> /// Transform calculator /// </summary> public bool CalculateTransform(Rhino.Display.RhinoViewport vp, Rhino.Geometry.Point3d pt, ref Rhino.Geometry.Transform xform) { bool rc = false; if (null == xform) { xform = new Rhino.Geometry.Transform(); } xform = Rhino.Geometry.Transform.Identity; if (pt.IsValid) { Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(vp.ConstructionPlane()) { Origin = m_origin }; Rhino.Geometry.Vector3d xaxis = (pt - plane.Origin); double length = xaxis.Length; if (length >= Rhino.RhinoMath.ZeroTolerance) { Rhino.Geometry.Vector3d yaxis; yaxis = 0 != xaxis.IsParallelTo(plane.Normal) ? plane.YAxis : Rhino.Geometry.Vector3d.CrossProduct(plane.Normal, xaxis); plane = new Rhino.Geometry.Plane(plane.Origin, xaxis, yaxis); if (!plane.IsValid) { return(rc); } Rhino.Geometry.Transform rotate_xform = Rhino.Geometry.Transform.PlaneToPlane(Rhino.Geometry.Plane.WorldXY, plane); Rhino.Geometry.Transform scale_xform = Rhino.Geometry.Transform.Scale(plane, length, length, length); xform = scale_xform * rotate_xform; rc = xform.IsValid; if (rc) { m_length = length; } } } return(rc); }
public static Rhino.Commands.Result AddNamedView(Rhino.RhinoDoc doc) { Rhino.Display.RhinoView view; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetView("Select view to adjust", out view); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Point3d location; rc = Rhino.Input.RhinoGet.GetPoint("Camera Location", false, out location); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Look At Location"); gp.DrawLineFromPoint(location, false); gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } Rhino.Geometry.Point3d lookat = gp.Point(); string name = view.ActiveViewport.Name; rc = Rhino.Input.RhinoGet.GetString("Name", true, ref name); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Display.RhinoViewport vp = view.ActiveViewport; // save the current viewport projection vp.PushViewProjection(); vp.CameraUp = Rhino.Geometry.Vector3d.ZAxis; vp.SetCameraLocation(location, false); vp.SetCameraDirection(lookat - location, true); vp.Name = name; doc.NamedViews.Add(name, vp.Id); view.Redraw(); return(Rhino.Commands.Result.Success); }
/// <summary> /// Removes a viewport from the list of viewports that this clipping plane clips. /// </summary> /// <param name="viewport">The viewport to remove.</param> /// <param name="commit">Commit the change. When in doubt, set this parameter to true.</param> /// <returns>true if the viewport was removed, false if the viewport was not in the list.</returns> public bool RemoveClipViewport(Rhino.Display.RhinoViewport viewport, bool commit) { if (null == viewport) { throw new System.ArgumentNullException(nameof(viewport)); } bool rc = false; Rhino.Geometry.ClippingPlaneSurface geometry = ClippingPlaneGeometry; if (null != geometry) { rc = geometry.RemoveClipViewportId(viewport.Id); if (rc && commit) { CommitChanges(); } } return(rc); }
public bool SetActiveDetail(string detailName, bool compareCase) { bool rc = false; Rhino.DocObjects.DetailViewObject[] details = GetDetailViews(); if (details != null) { for (int i = 0; i < details.Length; i++) { Rhino.Display.RhinoViewport vp = details[i].Viewport; if (string.Equals(vp.Name, detailName, StringComparison.OrdinalIgnoreCase)) { details[i].IsActive = true; rc = true; break; } } } return(rc); }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); var amp = AreaMassProperties.Compute(Value); _infoPanel.Positions.Add(Value.ClosestPoint(amp.Centroid)); if (Id != 0) { _infoPanel.Content.Add("Id: " + Id); } if (GroupId != 0) { _infoPanel.Content.Add("Grp: " + GroupId); } } _infoPanel.Draw(pipeline, viewport); } }
void GetCameraInfo() { var doc = Rhino.RhinoDoc.ActiveDoc; if (doc != null) { Rhino.Display.RhinoViewport vp = doc.Views.ActiveView.ActiveViewport; CameraInfo cameraInfo = new CameraInfo { Name = cameraName, FocalLength = vp.Camera35mmLensLength, Position = new List <double> { vp.CameraLocation.X *scaleFactor, vp.CameraLocation.Y *scaleFactor, vp.CameraLocation.Z *scaleFactor }, Target = new List <double> { vp.CameraTarget.X *scaleFactor, vp.CameraTarget.Y *scaleFactor, vp.CameraTarget.Z *scaleFactor }, Aspect = vp.FrustumAspect }; Payload payload = new Payload { Action = "camera", Info = cameraInfo }; if (!prevCameraInfo.Equals(cameraInfo)) { string message = JsonConvert.SerializeObject(payload); socket.Send(message); prevCameraInfo.Name = cameraInfo.Name; prevCameraInfo.FocalLength = cameraInfo.FocalLength; prevCameraInfo.Aspect = cameraInfo.Aspect; prevCameraInfo.Position = cameraInfo.Position; prevCameraInfo.Target = cameraInfo.Target; } } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); _infoPanel.Positions.Add(Value.PointAtNormalizedLength(0.5)); _infoPanel.Content.Add("LC: " + LoadCase); if (!Forces.IsTiny()) { _infoPanel.Content.Add("Force: " + Forces.Length); } if (!Moments.IsTiny()) { _infoPanel.Content.Add("Moment: " + Moments.Length); } } _infoPanel.Draw(pipeline, viewport); } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); var amp = AreaMassProperties.Compute(Value); _infoPanel.Positions.Add(Value.ClosestPoint(amp.Centroid)); _infoPanel.Content.Add("LC: " + LoadCase); if (!Forces.IsTiny()) { _infoPanel.Content.Add("Force: " + Forces.Length); } if (!Moments.IsTiny()) { _infoPanel.Content.Add("Moment: " + Moments.Length); } } _infoPanel.Draw(pipeline, viewport); } }
/// <summary> /// Sets the viewport in rhino /// </summary> /// <param name="view">the name of the view</param> /// <param name="displayType">the display type, wireframe, shaded etc</param> public static void setViewport(String view, String displayType) { //-------Set viewport to specific view and maximize it & set display type-------- Rhino.DocObjects.Tables.NamedViewTable nvt = Rhino.RhinoDoc.ActiveDoc.NamedViews; Rhino.DocObjects.Tables.ViewTable vt = Rhino.RhinoDoc.ActiveDoc.Views; Rhino.Display.RhinoView[] rvs = vt.GetViewList(true, false); List <Rhino.Display.RhinoView> st = rvs.ToList(); List <String> viewList = new List <String>(); int viewCount = 0; foreach (Rhino.Display.RhinoView v in st) { if (v.ActiveViewport.Name == view) { Rhino.Display.RhinoViewport rvp = rvs[viewCount].ActiveViewport; rvs[viewCount].Maximized = true; } viewCount++; } var type = Rhino.Display.DisplayModeDescription.FindByName(displayType); Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.DisplayMode = type; }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); _infoPanel.Positions.Add(Value.PointAtNormalizedLength(0.5)); if (Id != 0) { _infoPanel.Content.Add("Id: " + Id); } if (GroupId != 0) { _infoPanel.Content.Add("Grp: " + GroupId); } if (SectionIdStart != 0) { _infoPanel.Content.Add("Sec: " + SectionIdStart + (SectionIdEnd == 0 || SectionIdStart == SectionIdEnd ? "" : "." + SectionIdEnd)); } } _infoPanel.Draw(pipeline, viewport); } }
private void drawInfoPanel(Rhino.Display.DisplayPipeline pipeline, Rhino.Display.RhinoViewport viewport) { if (DrawUtil.DrawInfo) { if (_infoPanel == null) { _infoPanel = new InfoPanel(); if (Value.IsACurve) { _infoPanel.Positions.Add(Value.CurveA.PointAtNormalizedLength(0.5)); } else { _infoPanel.Positions.Add(Value.PointA.Location); } if (GroupId != 0) { _infoPanel.Content.Add("Grp: " + GroupId); } _infoPanel.Content.Add("Stf: " + Axial_stiffness + " / " + Rotational_stiffness + " / " + Transversal_stiffness); } _infoPanel.Draw(pipeline, viewport); } }
public override Transform CalculateTransform(Rhino.Display.RhinoViewport viewport, Point3d point) { Point3d basePoint; if (!TryGetBasePoint(out basePoint)) { return(Transform.Identity); } double len2 = (point - basePoint).Length; double len1 = (RefPoint - basePoint).Length; if (Math.Abs(len1) < 0.000001 || Math.Abs(len2) < 0.000001) { return(Transform.Identity); } Scale = len2 / len1; Plane plane = viewport.ConstructionPlane(); plane.Origin = basePoint; return(Transform.Scale(plane, Scale, Scale, Scale)); }
/// <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)); }
/// <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 <GeometryBase> G = new List <GeometryBase>(); if (!DA.GetDataList(0, G)) { return; } //Plane P = new Plane(); //DA.GetData(1, ref P); double distMult = 0.0; DA.GetData(1, ref distMult); Interval lensRange = new Interval(); DA.GetData(2, ref lensRange); double lensPar = 0.0; DA.GetData(3, ref lensPar); double lens = lensRange.ParameterAt(lensPar); int direction = 0; DA.GetData(4, ref direction); direction = direction % 2; double adjustStart = 0.0; DA.GetData(5, ref adjustStart); double slideCamZ = 0.0, slideTarZ = 0.0; DA.GetData(6, ref slideCamZ); DA.GetData(7, ref slideTarZ); double animT = 0.0; DA.GetData(8, ref animT); bool activate = false; DA.GetData(9, ref activate); if (!activate) { Message = ""; return; } BoundingBox bb = new BoundingBox(); foreach (GeometryBase gg in G) { bb.Union(gg.GetBoundingBox(false)); } double d = Math.Max(bb.Diagonal.X, bb.Diagonal.Y) * 2; // compensate lens/distance double radius = d * distMult * (lens / ((lensRange[1] + lensRange[0]) * 0.5)); Point3d center = bb.Center; Point3d target = center; center.Z += slideCamZ; target.Z += slideTarZ; double sign = direction * 2 - 1; double angle = Math.PI * 2 * (adjustStart + animT) * sign; Point3d camera = center + new Point3d(Math.Cos(angle) * radius, Math.Sin(angle) * radius, 0.0); Message = string.Format("{0:f1}", lens); //Get current viewport vp = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport; //Set new camera vp.SetCameraLocations(target, camera); vp.CameraUp = Vector3d.ZAxis; vp.ChangeToPerspectiveProjection(true, lens); }
public static void ResetUI(RhinoDoc doc) { LayerColorChange(doc, Color.White); //Rhino.Render.RenderContent[] rendercontents = Rhino.Render.UI.UserInterfaceSection.FromWindow(RhinoApp.MainWindow()).GetContentList(); //for (int i = 0; i < rendercontents.Length; i++) //{ // RhinoApp.WriteLine(rendercontents[i].Name); //} //RhinoWindows.Forms.WindowsInterop. //System.Windows.WindowState asdf = System.Windows.WindowState.Maximized; //editregi("normal_start", "14474460"); //editregi("normal_end", "14474460"); //editregi("hot_start", "14474460"); //editregi("normal_border", "14474460"); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.NormalBorder, Color.LightGray); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.NormalEnd, Color.LightGray); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.NormalStart, Color.LightGray); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.HotStart, Color.LightGray); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.TextEnabled, Color.Black); Rhino.ApplicationSettings.AppearanceSettings.SetPaintColor(Rhino.ApplicationSettings.PaintColor.TextDisabled, Color.Gray); Rhino.ApplicationSettings.AppearanceSettings.CommandPromptBackgroundColor = Color.White; Rhino.ApplicationSettings.AppearanceSettings.CommandPromptTextColor = Color.Black; Rhino.ApplicationSettings.AppearanceSettings.ViewportBackgroundColor = Color.LightGray; Rhino.UI.ToolbarFileCollection collection = RhinoApp.ToolbarFiles; foreach (string i in asdfasdf) { collection.Open(i); } asdfasdf.Clear(); Rhino.ApplicationSettings.ModelAidSettings.DisplayControlPolygon = false; foreach (Guid i in closedpanel) { Rhino.UI.Panels.OpenPanel(i); } Rhino.UI.ToolbarFileCollection.SidebarIsVisible = true; Rhino.DocObjects.Tables.ViewTable viewinfo = doc.Views; foreach (Rhino.Display.RhinoView i in viewinfo) { Rhino.Display.RhinoViewport vp = i.ActiveViewport; if (vp.Name == "Perspective") { //currentview.Add(i); vp.ParentView.Maximized = false; vp.ConstructionGridVisible = true; Rhino.Display.DisplayModeDescription dm = vp.DisplayMode; if (dm.EnglishName != "Shaded") { Rhino.Display.DisplayModeDescription[] dms = Rhino.Display.DisplayModeDescription.GetDisplayModes(); for (int j = 0; j < dms.Length; j++) { string english_name = dms[j].EnglishName; english_name = english_name.Replace("_", ""); english_name = english_name.Replace(" ", ""); english_name = english_name.Replace("-", ""); english_name = english_name.Replace(",", ""); english_name = english_name.Replace(".", ""); if (english_name == "Shaded") { vp.DisplayMode = Rhino.Display.DisplayModeDescription.FindByName(dms[j].EnglishName); } } } } else { // i.Close(); } } isvisible = true; }
/// <summary> /// Get view dependent dimension scale /// </summary> /// <param name="doc"></param> /// <param name="dimstyle"></param> /// <param name="vport"></param> /// <returns></returns> /// <since>6.0</since> public static double GetDimensionScale(RhinoDoc doc, DimensionStyle dimstyle, Rhino.Display.RhinoViewport vport) { uint docsn = doc.RuntimeSerialNumber; IntPtr pvport = vport.ConstPointer(); IntPtr pdimstyle = dimstyle.ConstPointer(); double scale = UnsafeNativeMethods.ON_V6_Annotation_GetDimScale(docsn, pdimstyle, pvport); GC.KeepAlive(vport); // GC_KeepAlive: Nov. 1, 2018 GC.KeepAlive(dimstyle); // GC_KeepAlive: Nov. 1, 2018 return(scale); }