Skip to content

Commit

Permalink
Cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dalefugier committed Feb 21, 2024
1 parent a416e67 commit e2b418d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions cpp/SampleCommands/cmdSampleMoveGrips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ static class CCommandSampleMoveGrips theSampleMoveGripsCommand;

CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandContext& context)
{
CRhinoDoc* doc = context.Document();
if (nullptr == doc)
return CRhinoCommand::failure;

// Select grips to move
CRhinoGetObject go;
go.SetCommandPrompt(L"Select grips to move");
go.SetGeometryFilter(CRhinoGetObject::grip_object);
go.GetObjects(1, 0);
if (go.CommandResult() != success)
return go.CommandResult();

// Fancy class for managing selected objects and grips
CRhinoXformObjectList list;
if (list.AddObjects(go, true) < 1)
return CRhinoCommand::failure;

// Point to move from
CRhinoGetPoint gp;
gp.SetCommandPrompt(L"Point to move from");
gp.GetPoint();
Expand All @@ -52,6 +51,7 @@ CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandCon

ON_3dPoint from = gp.Point();

// Point to move to
gp.SetCommandPrompt(L"Point to move to");
gp.SetBasePoint(from);
gp.DrawLineFromPoint(from, TRUE);
Expand All @@ -61,27 +61,25 @@ CRhinoCommand::result CCommandSampleMoveGrips::RunCommand(const CRhinoCommandCon

ON_3dPoint to = gp.Point();

// Create a translation transformation
ON_Xform xform = ON_Xform::TranslationTransformation(to - from);
if (xform.IsValid())
{
// Transform the grip objects
int i;
for (i = 0; i < list.m_grips.Count(); i++)
for (int i = 0; i < list.m_grips.Count(); i++)
{
CRhinoGripObject* grip = list.m_grips[i];
if (grip)
grip->MoveGrip(xform);
}

// Replace the old owner with a new one
for (i = 0; i < list.m_grip_owners.Count(); i++)
{
RhinoUpdateGripOwner(list.m_grip_owners[i], false, 0);
}

doc->Redraw();
for (int i = 0; i < list.m_grip_owners.Count(); i++)
RhinoUpdateGripOwner(list.m_grip_owners[i], false, nullptr);
}

context.m_doc.Redraw();

return CRhinoCommand::success;
}

Expand Down

0 comments on commit e2b418d

Please sign in to comment.