I am creating a custom Move command which asks for a CRhinoGetObjet using the point_object filter.
Then I want to ask the user for a new point position, which has to be inputted as x,y,z coordinates.
I don’t want to accept mouse click as input.
I don’t want the mouse crosshair to be transformed to a cross, like it does with the CRhinoGetPoint::GetPoint(and which can handle relative coordinates and other formats).
Basically I want what the CRhinoGetNumber::GetNumber does. However this only accepts numbers and I want to accept all the coordinate formats listed on this page Entering Numbers | Rhino 3-D modeling
My current code:
CRhinoCommand::result RunCommand(const CRhinoCommandContext &context) {
CRhinoGetObject point{};
point.SetCommandPrompt(L"Select a point");
point.SetGeometryFilter(CRhinoGetObject::point_object);
const CRhinoGet::result result = point.GetObjects(1, 1);
const CRhinoCommand::result command_result = point.CommandResult();
if (command_result != CRhinoCommand::result::success) {
RhinoApp().Print(L"Command failed. Bad selection?\n");
}
if (result != CRhinoGet::object) {
RhinoApp().Print(L"This was not a point.\n");
}
CRhinoGetNumber try_new_pos {};
try_new_pos.SetCommandPrompt(L"Input new coordinates");
// This will fail because x,y,z format from user is not CRhinoGet::number
if (not (try_new_pos.GetNumber() == CRhinoGet::number)) {
RhinoApp().Print("Not a number, exiting.\n");
return CRhinoCommand::result::failure;
}
double new_pos = try_new_pos.Number();
const CRhinoObject *old_point = point.Object(0).Object();
CRhinoPointObject *new_point = new CRhinoPointObject();
if (new_point == nullptr) {
RhinoApp().Print("Memory allocation failed\n");
return CRhinoCommand::result::failure;
}
ON_3dPoint p {new_pos}; // This fails of course. new_pos typed as @5,0,0
*new_point = p;
if (!context.m_doc.ReplaceObject(CRhinoObjRef {old_point}, new_point, true)) {
RhinoApp().Print("Rhino failed to modify the point\n");
delete new_point;
return CRhinoCommand::result::failure;
}
context.Document()->Redraw();
return CRhinoCommand::success;
}