CRhinoCommand::result CCommandSampleMeshFaceColor::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select mesh" );
  go.SetGeometryFilter( CRhinoGetObject::mesh_object );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();

  const CRhinoMeshObject* mesh_obj = CRhinoMeshObject::Cast( go.Object(0).Object() );
  if( 0 == mesh_obj )
    return CRhinoCommand::failure;

  CSampleMeshFaceColorConduit conduit( mesh_obj->m_runtime_object_serial_number );
  conduit.Enable();
  context.m_doc.Regen();

  CRhinoGetString gs;
  gs.SetCommandPrompt( L"Press <Enter> to continue" );
  gs.AcceptNothing();
  gs.GetString();

  conduit.Disable();
  context.m_doc.Regen();

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleSelectVisibleMeshFaces::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select mesh");
  go.SetGeometryFilter(ON::mesh_object);
  go.EnablePreSelect(false);
  go.EnableUnselectObjectsOnExit(false);
  go.GetObjects(1, 1);
  if (go.CommandResult() != CRhinoCommand::success)
    return go.CommandResult();

  CRhinoView* view = go.View();
  if (0 == view)
    return CRhinoCommand::failure;

  const CRhinoMeshObject* mesh_obj = CRhinoMeshObject::Cast(go.Object(0).Object());
  if (0 == mesh_obj)
    return CRhinoCommand::failure;

  ON_Mesh* mesh = const_cast<ON_Mesh*>(mesh_obj->Mesh());
  if (0 == mesh)
    return CRhinoCommand::failure;

  mesh_obj->Select(false);
  context.m_doc.Redraw();

  if (!mesh->HasFaceNormals())
    mesh->ComputeFaceNormals();

  ON_3fVector dir(view->ActiveViewport().VP().CameraZ());
  double min_angle = 0.0;
  double max_angle = 90.0 * (ON_PI/180);

  for (int fi = 0; fi < mesh->m_F.Count(); fi++)
  {
    const ON_3fVector& norm = mesh->m_FN[fi];
    double dot = ON_DotProduct(dir, norm) / (dir.Length() * norm.Length());
    double angle = acos(dot);
    if (min_angle <= angle && angle <= max_angle)
    {
      ON_COMPONENT_INDEX ci(ON_COMPONENT_INDEX::mesh_face, fi);
      mesh_obj->SelectSubObject(ci, true, true);
    }
  }
  context.m_doc.Redraw();

  CRhinoGetString gs;
  gs.SetCommandPrompt(L"Press <Enter> to continue");
  gs.AcceptNothing();
  gs.GetString();

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleWindowPick::RunCommand( const CRhinoCommandContext& context )
{
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select point cloud" );
    go.SetGeometryFilter( CRhinoGetObject::pointset_object );
    go.EnableSubObjectSelect( false );
    go.GetObjects( 1, 1 );
    if( go.CommandResult() != CRhinoCommand::success )
        return go.CommandResult();

    const CRhinoPointCloudObject* obj = CRhinoPointCloudObject::Cast( go.Object(0).Object() );
    if( 0 == obj )
        return CRhinoCommand::failure;

    const ON_PointCloud& cloud = obj->PointCloud();

    obj->Select( false );
    context.m_doc.Redraw();

    CRhinoGetPoint gp;
    gp.SetCommandPrompt( L"Drag a window to select point cloud points" );
    gp.ConstrainToTargetPlane();
    gp.AcceptNothing();
    gp.SetGetPointCursor( RhinoApp().m_default_cursor );
    gp.Get2dRectangle();
    if( gp.CommandResult() != CRhinoCommand::success )
        return gp.CommandResult();

    ON_SimpleArray<int> indices;
    const int index_count = RhWindowsSelectPointCloudPoints( gp.View(), cloud, gp.Rectangle2d(), indices );
    if( 0 == index_count )
        return CRhinoCommand::nothing;

    int i;
    for( i = 0; i < index_count; i++ )
        obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), true );
    context.m_doc.Redraw();

    CRhinoGetString gs;
    gs.SetCommandPrompt( L"Press <Enter> to continue" );
    gs.AcceptNothing();
    gs.GetString();

    for( i = 0; i < index_count; i++ )
        obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), false );
    context.m_doc.Redraw();

    return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleRegionPick::RunCommand( const CRhinoCommandContext& context )
{
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select point cloud" );
    go.SetGeometryFilter( CRhinoGetObject::pointset_object );
    go.EnableSubObjectSelect( false );
    go.GetObjects( 1, 1 );
    if( go.CommandResult() != CRhinoCommand::success )
        return go.CommandResult();

    const CRhinoPointCloudObject* obj = CRhinoPointCloudObject::Cast( go.Object(0).Object() );
    if( 0 == obj )
        return CRhinoCommand::failure;

    const ON_PointCloud& cloud = obj->PointCloud();

    obj->Select( false );
    context.m_doc.Redraw();

    CRhGetRegionPoints gp;
    gp.SetCommandPrompt( L"Click and drag, or repeatedly click to lasso point cloud points. Press Enter when done" );
    gp.AcceptNothing();
    gp.SetGetPointCursor( RhinoApp().m_default_cursor );
    gp.GetPoints();
    if( gp.Result() == CRhinoGet::point )
        return CRhinoCommand::cancel;

    ON_SimpleArray<int> indices;
    const int index_count = RhRegionSelectPointCloudPoints( gp.View(), cloud, gp.m_points, indices );
    if( 0 == index_count )
        return CRhinoCommand::nothing;

    int i;
    for( i = 0; i < index_count; i++ )
        obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), true );
    context.m_doc.Redraw();

    CRhinoGetString gs;
    gs.SetCommandPrompt( L"Press <Enter> to continue" );
    gs.AcceptNothing();
    gs.GetString();

    for( i = 0; i < index_count; i++ )
        obj->SelectSubObject( ON_COMPONENT_INDEX(ON_COMPONENT_INDEX::pointcloud_point, indices[i]), false );
    context.m_doc.Redraw();

    return CRhinoCommand::success;
}
Пример #5
0
CRhinoCommand::result CCommandNewName::RunCommand( const CRhinoCommandContext& context )
{
	// Select an object to modify
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select object to change name" );
  go.EnablePreSelect( TRUE );
  go.EnableSubObjectSelect( FALSE );
  go.GetObjects( 1, 1 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();
 
  // Get the object reference
  const CRhinoObjRef& objref = go.Object(0);
 
  // Get the object
  const CRhinoObject* obj = objref.Object();
  if( !obj )
    return CRhinoCommand::failure;
 
  // Make copy of object attributes. This objects
  // holds an object's user-defined name.
  ON_3dmObjectAttributes obj_attribs = obj->Attributes();
 
  // Prompt for new object name
  CRhinoGetString gs;
  gs.SetCommandPrompt( L"New object name" );
  gs.SetDefaultString( obj_attribs.m_name );
  gs.AcceptNothing( TRUE );
  gs.GetString();
  if( gs.CommandResult() != CRhinoCommand::success )
    return gs.CommandResult();
 
  // Get the string entered by the user
  ON_wString obj_name = gs.String();
  obj_name.TrimLeftAndRight();
 
  // Is name the same?
  if( obj_name.Compare(obj_attribs.m_name) == 0 )
    return CRhinoCommand::nothing;
 
  // Modify the attributes of the object
  obj_attribs.m_name = obj_name;
  context.m_doc.ModifyObjectAttributes( objref, obj_attribs );
 
  return CRhinoCommand::success;

}