Example #1
0
    /// <summary>
    /// Asks the user to select a Box in the viewport.
    /// </summary>
    /// <param name="box">If the result is Success, this parameter will be filled out.</param>
    /// <param name="mode">A particular "get box" mode, or <see cref="GetBoxMode.All"/>.</param>
    /// <param name="basePoint">Optional base point. Supply Point3d.Unset if you don't want to use this.</param>
    /// <param name="prompt1">Optional first prompt. Supply null to use the default prompt.</param>
    /// <param name="prompt2">Optional second prompt. Supply null to use the default prompt.</param>
    /// <param name="prompt3">Optional third prompt. Supply null to use the default prompt.</param>
    /// <returns>Commands.Result.Success if successful.</returns>
    public static Commands.Result GetBox(out Rhino.Geometry.Box box, GetBoxMode mode, Point3d basePoint, string prompt1, string prompt2, string prompt3)
    {
      Point3d[] corners = new Point3d[8];
      // 19 Feb 2010 S. Baer
      // On Win x64 builds the .NET framework appears to have problems if you don't initialize the array
      // before passing it off to unmanaged code.
      for (int i = 0; i < corners.Length; i++)
        corners[i] = new Point3d();
      Rhino.Commands.Result rc = (Rhino.Commands.Result)UnsafeNativeMethods.RHC_RhinoGetBox(corners, (int)mode, basePoint, prompt1, prompt2, prompt3);

      // David: This code is untested.
      box = new Box();

      if (rc == Rhino.Commands.Result.Success)
      {
        Vector3d x = corners[1] - corners[0];
        Vector3d y = corners[3] - corners[0];
        Vector3d z = corners[4] - corners[0];

        // Create a singular box.
        if (x.IsZero && y.IsZero && z.IsZero)
        {
          box = new Box(new Plane(corners[0], new Vector3d(0, 0, 1)), new Interval(), new Interval(), new Interval());
          return rc;
        }

        // Create a linear box.
        if (x.IsZero && y.IsZero)
        {
          box = new Box(new Plane(corners[0], z), new Interval(), new Interval(), new Interval(0, z.Length));
          return rc;
        }

        // Boxes were getting inverted if the "height" pick was on the negative side of the base plane.
        Plane base_plane = new Plane(corners[0], x, y);
        Point3d C0, C1;
        base_plane.RemapToPlaneSpace(corners[0], out C0);
        base_plane.RemapToPlaneSpace(corners[6], out C1);

        Interval ix = new Interval(C0.X, C1.X); ix.MakeIncreasing();
        Interval iy = new Interval(C0.Y, C1.Y); iy.MakeIncreasing();
        Interval iz = new Interval(C0.Z, C1.Z); iz.MakeIncreasing();

        box = new Box(base_plane, ix, iy, iz);
      }

      return rc;
    }
Example #2
0
    /// <summary>
    /// Gets a 3d rectangle made up of four points.
    /// </summary>
    /// <param name="mode">A get box mode.</param>
    /// <param name="firstPoint">The first corner used. Pass Point3d.Unset if you do not want to set this.</param>
    /// <param name="prompts">Optional prompts to display while getting points. May be null.</param>
    /// <param name="corners">Corners of the rectangle in counter-clockwise order will be assigned to this out parameter during this call.</param>
    /// <returns>Commands.Result.Success if successful.</returns>
    public static Commands.Result GetRectangle(GetBoxMode mode, Rhino.Geometry.Point3d firstPoint, System.Collections.Generic.IEnumerable<string> prompts, out Rhino.Geometry.Point3d[] corners)
    {
      corners = new Point3d[4];
      IntPtr ptr = UnsafeNativeMethods.CArgsRhinoGetPlane_New();
      UnsafeNativeMethods.CArgsRhinoGetPlane_SetMode(ptr, (int)mode);
      if (firstPoint.IsValid) UnsafeNativeMethods.CArgsRhinoGetPlane_SetFirstPoint(ptr, firstPoint);
      int i = 0;
      foreach (string s in prompts)
      {
        if( !string.IsNullOrEmpty(s) )
          UnsafeNativeMethods.CArgsRhinoGetPlane_SetPrompt(ptr, s, i++);
      }

      Commands.Result rc = (Rhino.Commands.Result)UnsafeNativeMethods.RHC_RhinoGetRectangle(corners, ptr);
      if (rc != Commands.Result.Success)
        corners = null;
      UnsafeNativeMethods.CArgsRhinoGetPlane_Delete(ptr);
      return rc;
    }