CRhinoGetPoint::Get2dRectangle() and typed coordinates

I’m calling Get2dRectangle() to get an on-screen rectangle. If the rectangle is drawn with the mouse - everything is OK. However Rhino accepts typing the coordinates on the command line, instead of clicking with the mouse.

For example here I typed some coords for the two corners
image

and the result has nothing to do with the actual values:
image

If I call CRhinoGetRectangle::Corners() I actually get the second point correct in this case, and I see that m_preview_point holds the value. However I couldn’t find a way to access the first point’ coordinates

Does anyone has an idea how to get the typed coordinates ?

Hi @Nikolay,

The typed coordinates are transformed to screen coordinates by doing something similar to this:

var point3d = ...
var view = doc.Views.ActiveView;
if (null != view)
{
  var world_to_screen = view.ActiveViewport.GetTransform(
    CoordinateSystem.World, 
    CoordinateSystem.Screen
    );

  var point2d = point3d;
  point2d.Transform(world_to_screen);

  // TODO
}

To get a 3d point from a screen point, just create a screen-to-world transformation and transform the point.

– Dale

Hi Dale,

that transformation was the first thing I tried, and it didn’t work

here I typed 100,100 and 200,200 as inputs. Assume the rect’s corners are the top-left and bottom-right coordinates of the typed points and here is what I get:


I need to get whatever the user has typed - (100,100), (200,200), but got (-2145, -746), (-2423, -719)

It doesn’t really matter if I get the CRhinoGet’s View() or the document’s ActiveView() the result is the same.

Furthermore, the user may click for both points (then Rectangle2d() returns correct); may type the first point, click for the second point, vice versa, or type both (then Rectangle2d() returns wrong). Assuming there is a transformation that returns the correct numbers, how to know when to apply it and when to take the Rectangle2d() result directly ?

Furthermore 2, if the first coordinate is typed, the dynamic rectangle is not drawn on the screen when moving the mouse for the other corner. Is that a bug ?

I think I’ll try to write my own CRhinoGetPoint inherited class an capture the points somehow
Thanks

I made it work. Quite ugly, but it does exactly what I want.
p0 and p1 are screen coordinates of user points, entered either by typing or mouse clicking

RhinoApp().Print(L"Specify screen rectangle\n");
CArgsRhinoGetPlane args;
MyRhinoGetPoint gi(args);
gi.AcceptNothing();

ON_2iPoint p0, p1;
switch (gi.Get2dPoint())
{
	case CRhinoGet::point:
	{
		//Typed coordinates
		const ON_3dPoint p = gi.Point();
		p0 = ON_2iPoint(p.x, p.y);
		break;
	}
	case CRhinoGet::point2d:
	{
		//Mouse click coordinates
		p0 = gi.Point2d();
		break;
	}
	case CRhinoGet::cancel:
		return CRhinoCommand::cancel;
	default:
		return CRhinoCommand::failure;
}

//pick the second point only
//enable dynamic drawing of the rectangle frame
POINT screenStart = { p0.x, p1.y };
switch (gi.Get2dRectangle(gi.View(), &screenStart))
{
	case CRhinoGet::point:
	{
		//Typed coordinates
		const ON_3dPoint p = gi.Point();
		p1 = ON_2iPoint(p.x, p.y);
		break;
	}
	case CRhinoGet::rect2d:
	{
		//Mouse click coordinates
		p1 = gi.Point2d();
		break;
	}
	case CRhinoGet::cancel:
		return CRhinoCommand::cancel;
	default:
		return CRhinoCommand::failure;
}

using what you said i am trying to convert point2d in screen plane to Point3d

Point2d point2d = new Point2d() ;
var screen_to_world = view.ActiveViewport.GetTransform(
    CoordinateSystem.Screen,CoordinateSystem.World
    );

  Point3d point3d = point2d;
  point3d.Transform(world_to_screen);

how do i convert Point2d to Point3d for later operations? Thanks in Advance

Hi @Arjun_Sharma1,

I’m not sure I understand the question. If you want to save the point, the save it on some structure that will persist after the function returns. Or am I confused?

– Dale