CRhinoCommand::result CCommandSampleOrientOnCrv::GetPathCurve( const ON_Curve*& path_curve )
{
  CRhinoGetObject get;
  get.SetCommandPrompt( L"Select path curve" );
  get.SetGeometryFilter( CRhinoGetObject::curve_object );
  get.EnableDeselectAllBeforePostSelect( false );
  get.EnablePreSelect( FALSE );
  get.AcceptNothing();
  get.GetObjects( 1, 1 );

  CRhinoCommand::result rc = get.CommandResult();
  if( rc == CRhinoCommand::success )
  {
    CRhinoObjRef objRef = get.Object(0);
    path_curve = objRef.Curve();
    if( !path_curve )
      rc = CRhinoCommand::failure;
  }

  return rc;
}
CRhinoCommand::result CCommandSampleSelectPolylineSegment::RunCommand( const CRhinoCommandContext& context )
{
    CRhGetPolylineObject go;
    go.SetCommandPrompt( L"Select polyline" );
    go.GetObjects( 1, 1 );
    if( go.CommandResult() != CRhinoCommand::success )
        return go.CommandResult();

    const CRhinoObjRef object_ref = go.Object(0);

    const CRhinoObject* object = object_ref.Object();
    const ON_PolylineCurve* curve = ON_PolylineCurve::Cast( object_ref.Curve() );
    if( 0 == object || 0 == curve )
        return CRhinoCommand::failure;

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

    CRhGetPolylineSegment gp( curve );
    gp.SetCommandPrompt( L"Select polyline segment" );
    gp.GetPoint();
    if( gp.CommandResult() != CRhinoCommand::success )
        return gp.CommandResult();

    ON_3dPoint point = gp.Point();

    int index0 = -1;
    int index1 = -1;

    if( gp.CalculatePolylineSegment(point, index0, index1) )
    {
        ON_wString point_str;
        RhinoFormatPoint( point, point_str );
        RhinoApp().Print( L"Curve point = %s\n", point_str );
        RhinoApp().Print( L"Curve index0 = %d\n", index0 );
        RhinoApp().Print( L"Curve index1 = %d\n", index1 );
    }

    return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleQueryDiameterDimension::RunCommand( const CRhinoCommandContext& context )
{
    CRhGetDiameterDimensionObject go;
    go.SetCommandPrompt( L"Select diameter dimension" );
    go.SetGeometryFilter( CRhinoGetObject::annotation_object );
    go.GetObjects( 1, 1 );
    if( go.CommandResult() != CRhinoCommand::success )
        return go.CommandResult();

    const CRhinoObjRef object_ref = go.Object(0);

    // Get the Rhino object
    const CRhinoObject* object = object_ref.Object();
    if( 0 == object )
        return CRhinoCommand::failure;

    // The Rhino object class for a diameter dimension is a CRhinoAnnotationObject
    const CRhinoAnnotationObject* annotation_object = CRhinoAnnotationObject::Cast( object );
    if( 0 == annotation_object || annotation_object->Type() != ON::dtDimDiameter )
        return CRhinoCommand::failure;

    // Get the Rhino object's geometry. For CRhinoAnnotationObject, this is a ON_Annotation2 object
    const ON_Annotation2* annotation = annotation_object->Annotation();
    if( 0 == annotation )
        return CRhinoCommand::failure;

    // The geometry for a diameter dimension is a ON_RadialDimension2 object,
    // which is derived from ON_Annotation2.
    const ON_RadialDimension2* radial_dim = ON_RadialDimension2::Cast( annotation );
    if( 0 == radial_dim )
        return CRhinoCommand::failure;

    // Report some parameters
    ON_wString point0_str, point1_str;
    RhinoFormatPoint( radial_dim->Dim3dPoint(0), point0_str );
    RhinoFormatPoint( radial_dim->Dim3dPoint(1), point1_str );

    RhinoApp().Print( L"Center point: %s\n", point0_str );
    RhinoApp().Print( L"Arrowhead point: %s\n", point1_str );
    RhinoApp().Print( L"Dimension text: %s\n", annotation_object->TextString() );

    return CRhinoCommand::success;
}
Ejemplo n.º 4
0
CRhinoCommand::result CCommandTestAnimator::RunCommand( const CRhinoCommandContext& context )
{
    // Select objects to animate
    CRhinoGetObject go;
    go.SetCommandPrompt( L"Select objects to animate" );
    go.GetObjects( 1, 0 );
    if( go.CommandResult() != success )
        return go.CommandResult();

    // Select path curve
    CRhinoGetObject gc;
    gc.SetCommandPrompt( L"Select path curve" );
    gc.SetGeometryFilter( CRhinoGetObject::curve_object );
    gc.SetGeometryAttributeFilter( CRhinoGetObject::open_curve );
    gc.GetObjects( 1, 1 );
    if( gc.CommandResult() != success )
        return gc.CommandResult();

    const ON_Curve* crv = gc.Object(0).Curve();
    if( 0 == crv )
        return failure;

    // Create an array of normalized curve parameters
    ON_SimpleArray<double> t_array( m_max_steps );
    t_array.SetCount( m_max_steps );
    int i = 0;
    for( i = 0; i < m_max_steps; i++ )
    {
        double t = (double)i / ( (double)m_max_steps - 1 );
        t_array[i] = t;
    }

    // Get the real parameters along the curve
    if( !crv->GetNormalizedArcLengthPoints(m_max_steps, t_array.Array(), t_array.Array()) )
        return failure;

    // Create our dialog box with animatin slider...
    CTestAnimatorDlg dlg( CWnd::FromHandle(RhinoApp().MainWnd()) );
    dlg.m_max_steps = m_max_steps;
    dlg.m_start = crv->PointAtStart();

    // Get points along curve
    for( i = 0; i < m_max_steps; i++ )
    {
        ON_3dPoint pt = crv->PointAt( t_array[i] );
        dlg.m_points.Append( pt );
    }

    // Hide objects and add them to callback's object array
    for( i = 0; i < go.ObjectCount(); i++ )
    {
        CRhinoObjRef ref = go.Object(i);
        context.m_doc.HideObject( ref );
        dlg.m_conduit.m_objects.Append( ref.Object() );
    }

    // Do the dialog
    INT_PTR rc = dlg.DoModal();

    // If OK was pressed, transform the objects.
    // Otherwise, just unhide them.
    for( i = 0; i < go.ObjectCount(); i++ )
    {
        CRhinoObjRef ref = go.Object(i);
        context.m_doc.ShowObject( ref );
        if( rc == IDOK )
        {
            ON_Xform xform = dlg.m_conduit.m_xform;
            context.m_doc.TransformObject( ref, xform );
        }
    }

    context.m_doc.Redraw( CRhinoView::regenerate_display_hint );

    return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleConvertQuadsToTriangles::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Select meshes to convert" );
  go.SetGeometryFilter( CRhinoObject::mesh_object );
  if( go.GetObjects(1,0) != CRhinoGet::object )
    return CRhinoCommand::cancel;
  
  CRhinoGetOption gs;
  gs.AcceptNothing();
  gs.SetCommandPrompt( L"Delete input?" );
  gs.SetDefaultString( (m_delete_input)?L"Yes":L"No" );
  int n_index = gs.AddCommandOption( RHCMDOPTNAME(L"No") );
  int y_index = gs.AddCommandOption( RHCMDOPTNAME(L"Yes") );
  switch( gs.GetOption() )
  {
    case CRhinoGet::option:
      if( gs.Option()->m_option_index == n_index )
        m_delete_input = false;
      else
        m_delete_input = true;
      break;
    
    case CRhinoGet::string:
    case CRhinoGet::nothing:
      break;
    
    default:
      return CRhinoCommand::cancel;
  }
  
  int num_converted = 0;
  for( int i = 0; i < go.ObjectCount(); i++ )
  {
    CRhinoObjRef objref = go.Object(i);
    if( const CRhinoObject* pObject = objref.Object() )
    {
      if( const ON_Mesh* pMesh = ON_Mesh::Cast(pObject->Geometry()) )
      {
        ON_Mesh mesh(*pMesh);
        if( mesh.QuadCount() <= 0 )
          continue;
        
        if( !mesh.ConvertQuadsToTriangles() )
          continue;
        
        const CRhinoMeshObject* mesh_object = NULL;
        if( m_delete_input )
          mesh_object = context.m_doc.ReplaceObject( objref, mesh );
        else
          mesh_object = context.m_doc.AddMeshObject( mesh );
        
        if( mesh_object )
          num_converted++;
      }
    }
  }
  
  if( num_converted > 0 )
    context.m_doc.Redraw();
  
  RhinoApp().Print( L"%d meshes selected, %d meshes converted.\n", go.ObjectCount(), num_converted );
  
  return CRhinoCommand::success;
}