Ejemplo n.º 1
0
CRhinoCommand::result CCommandExposeSdk::RunCommand( const CRhinoCommandContext& context )
{
  // CCommandExposeSdk::RunCommand() is called when the user runs the "ExposeSdk"
  // command or the "ExposeSdk" command is run by a history operation.

  // TODO: Add command code here.

  // Rhino command that display a dialog box interface should also support
  // a command-line, or scriptable interface.

  ON_wString wStr;
  wStr.Format( L"The \"%s\" command is under construction.\n", EnglishCommandName() );
  if( context.IsInteractive() )
    RhinoMessageBox( wStr, PlugIn()->PlugInName(), MB_OK );
  else
	  RhinoApp().Print( wStr );

  // TODO: Return one of the following values:
  //   CRhinoCommand::success:  The command worked.
  //   CRhinoCommand::failure:  The command failed because of invalid input, inability
  //                            to compute the desired result, or some other reason
  //                            computation reason.
  //   CRhinoCommand::cancel:   The user interactively canceled the command 
  //                            (by pressing ESCAPE, clicking a CANCEL button, etc.)
  //                            in a Get operation, dialog, time consuming computation, etc.

  return CRhinoCommand::success;
}
Ejemplo n.º 2
0
CRhinoCommand::result CCommandSamplePolyline::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoCommand::result rc = CRhinoCommand::nothing;
  ON_Polyline pline;

  if( context.IsInteractive() )
  {
    // Our way...
	  CGetPolylinePoints gp;
    int count = gp.GetPoints();
    if( count > 1 )
    {
      pline = gp.m_point_array;
      if( pline.IsValid() )
        rc = CRhinoCommand::success;
    }
  }
  else
  {
    // The Rhino way...
    CArgsRhinoGetPolyline args;
    args.SetFirstPointPrompt( L"Start of polyline" );
    args.SetSecondPointPrompt( L"Next point of polyline" );
    rc = RhinoGetPolyline( args, pline );
  }

  if( rc == CRhinoCommand::success )
  {
    context.m_doc.AddCurveObject( pline );
    context.m_doc.Redraw();
  }

	return rc;
}
Ejemplo n.º 3
0
CRhinoCommand::result CCommandSampleOpenIges::RunCommand( const CRhinoCommandContext& context )
{
  ON_wString filename;

  if( context.IsInteractive() )
  {
    DWORD dwFlags = OFN_ENABLESIZING | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
    const wchar_t* szFilter = L"IGES Files (*.igs;*.iges)|*.igs; *.iges||";
    CWnd* pParentWnd = CWnd::FromHandle( RhinoApp().MainWnd() );

#if defined(WIN64)
    CFileDialog dialog( TRUE, L"igs", 0, dwFlags, szFilter, pParentWnd, 0, TRUE );
#else
    CFileDialog dialog( TRUE, L"igs", 0, dwFlags, szFilter, pParentWnd );
#endif
    INT_PTR rc = dialog.DoModal();
    if( rc != IDOK )
      return CRhinoCommand::cancel;

    filename = dialog.GetPathName();
  }
  else
  {
    CRhinoGetString gs;
    gs.SetCommandPrompt( L"IGES file to open" );
    gs.GetString();
    if( gs.CommandResult() != CRhinoCommand::success )
      return gs.CommandResult();

    filename = gs.String();
  }

  filename.TrimLeftAndRight();
  if( filename.IsEmpty() )
    return CRhinoCommand::nothing;

  if( !CRhinoFileUtilities::FileExists(filename) )
  {
    RhinoApp().Print( L"File \"%s\" not found.\n", filename );
    return CRhinoCommand::failure;
  }

  // Note, setting the document modified flag to false will prevent the
  // "Do you want to save this file..." mesasge from displaying when you
  // open a file (if the current document has been modified in any way).
  // But, you will (also) loose any modifications to the current document.
  // So, use the following line of code carefully.
  context.m_doc.SetModifiedFlag( FALSE );

  ON_wString script;
  script.Format( L"_-Open \"%s\" _Enter _Enter _Enter", filename );

  RhinoApp().RunScript( script, 0 );

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleDimLinear::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoLinearDimension* pDim = 0;
 
  CArgsRhinoDimLinear args;
  args.SetFirstPointPrompt( L"First dimension point" );
  args.SetSecondPointPrompt( L"Second dimension point" );
  args.SetDragPointPrompt( L"Dimension location" );
  args.SetIsInteractive( context.IsInteractive() ? true : false );
 
  CRhinoCommand::result rc = RhinoGetDimLinear( args, pDim, 0 );
 
  if( rc == CRhinoCommand::success && 0 != pDim )
  {
    context.m_doc.AddObject( pDim, FALSE );
    context.m_doc.Redraw();
  } 
 
  return rc;
}
CRhinoCommand::result CCommandSampleTabbedDockBar::RunCommand( const CRhinoCommandContext& context )
{
  ON_UUID tabId = CSampleTabbedDockBarDialog::ID();

  if( context.IsInteractive() )
  {
    CRhinoTabbedDockBarDialog::OpenDockbarTab( tabId );
  }
  else
  {
    bool bVisible = CRhinoTabbedDockBarDialog::IsTabVisible( tabId );
 
    ON_wString str;
    str.Format( L"%s is %s. New value", LocalCommandName(), bVisible ? L"visible" : L"hidden" );
 
    CRhinoGetOption go;
    go.SetCommandPrompt( str );
    int h_option = go.AddCommandOption( RHCMDOPTNAME(L"Hide") );
    int s_option = go.AddCommandOption( RHCMDOPTNAME(L"Show") );
    int t_option = go.AddCommandOption( RHCMDOPTNAME(L"Toggle") );
    go.GetOption();
    if( go.CommandResult() != CRhinoCommand::success )
      return go.CommandResult();
 
    const CRhinoCommandOption* option = go.Option();
    if( 0 == option )
      return CRhinoCommand::failure;
 
    int option_index = option->m_option_index;

    if( h_option == option_index && bVisible )
      CRhinoTabbedDockBarDialog::ShowDockbarTab( tabId, false );
    else if( s_option == option_index && !bVisible  )
      CRhinoTabbedDockBarDialog::ShowDockbarTab( tabId, true );
    else if( t_option == option_index )
      CRhinoTabbedDockBarDialog::ShowDockbarTab( tabId, !bVisible );
  }

  return CRhinoCommand::success;
}
Ejemplo n.º 6
0
CRhinoCommand::result CCommandscript1::RunCommand( const CRhinoCommandContext& context )
{
  // CCommandscript1::RunCommand() is called when the user runs the "script1"
  // command or the "script1" command is run by a history operation.

  // TODO: Add command code here.

  // Rhino command that display a dialog box interface should also support
  // a command-line, or scriptable interface.

  Cscript1PlugIn& plugin = script1PlugIn();

  bool bVisible = plugin.IsDlgVisible();

  if( context.IsInteractive() )
  {
    if( false == bVisible )
		plugin.DisplayDlg(); // tolto come parametro context.m_doc
  }

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleImportMeshes::RunCommand( const CRhinoCommandContext& context )
{
  CWnd* pMainWnd = CWnd::FromHandle(RhinoApp().MainWnd());
  if (0 == pMainWnd)
    return CRhinoCommand::failure;
 
  CRhinoGetFileDialog gf;
  gf.SetScriptMode(context.IsInteractive() ? FALSE : TRUE);
  BOOL rc = gf.DisplayFileDialog(CRhinoGetFileDialog::open_rhino_only_dialog, 0, pMainWnd);
  if (!rc)
    return CRhinoCommand::cancel;
 
  ON_wString filename = gf.FileName();
  filename.TrimLeftAndRight();
  if (filename.IsEmpty())
    return CRhinoCommand::nothing;

  if (!CRhinoFileUtilities::FileExists(filename))
  {
    RhinoApp().Print(L"File not found\n");
    return CRhinoCommand::failure;
  }

  FILE* archive_fp = ON::OpenFile(filename, L"rb");
  if (0 == archive_fp)
  {
    RhinoApp().Print(L"Unable to open file\n");
    return CRhinoCommand::failure;
  }

  ON_BinaryFile archive(ON::read3dm, archive_fp);

  ONX_Model model;
  rc = model.Read(archive) ? TRUE : FALSE;

  ON::CloseFile( archive_fp );

  if (!rc)
  {
    RhinoApp().Print(L"Error reading file\n");
    return CRhinoCommand::failure;
  }

  int num_imported = 0;
  for (int i = 0; i < model.m_object_table.Count(); i++)
  {
    const ONX_Model_Object& model_object = model.m_object_table[i];
    const ON_Mesh* mesh = ON_Mesh::Cast(model_object.m_object);
    if (0 != mesh)
    {
      // CRhinoDoc::AddMeshObject makes a copy of the input mesh
      context.m_doc.AddMeshObject(*mesh);
      num_imported++;
    }
  }

  if (0 == num_imported)
    RhinoApp().Print(L"No meshes imported\n");
  else if (1 == num_imported)
    RhinoApp().Print(L"1 mesh imported\n");
  else
    RhinoApp().Print(L"%d meshes imported\n", num_imported);

  context.m_doc.Redraw();

  return CRhinoCommand::success;
}