Exemple #1
0
CRhinoCommand::result CCommandVRaptor::RunCommand( const CRhinoCommandContext& context )
{
  // CCommandVRaptor::RunCommand() is called when the user runs the "VRaptor"
  // command or the "VRaptor" 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 raptor is slumbering.\n", EnglishCommandName() );
	  RhinoApp().Print( wStr );

  wStr.Format( L"another one.\n", EnglishCommandName() );
	  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;
}
Exemple #2
0
void ON_RadialDimension::SetTextToDefault() 
{ 
  ON_wString s; 
  if( Type() == ON::dtDimDiameter) 
    s.Format( L"%c<>", ON_Annotation::diametersym); 
  else 
    s.Format( L"%c<>", ON_Annotation::radiussym); 
  SetUserText( s); 
}
void CSamplePickObjectsDialog::OnBnClickedPick()
{
  // If our dialog contains controls that had values we cared about,
  // you will want to call UpdateData() before hiding the dialog.
  //UpdateData( TRUE );

  // Hide this dialog
  PushPickButton( TRUE );

  // Pick some objects
  CRhinoGetObject go;
  go.SetCommandPrompt( L"Pick objects" );
  go.GetObjects( 1, 0 );
  if( go.CommandResult() == CRhinoCommand::success )
  {
    int count = go.ObjectCount();
    ON_wString str;
    if( 1 == count )
      str = L"1 object picked.";
    else
      str.Format( L"%d objects picked.", count );
      m_message.SetWindowText( str );
  }

  // Hide this dialog
  PushPickButton( FALSE );

  // If our dialog contains controls that had values we cared about,
  // you will want to call UpdateData() before showing the dialog.
  //UpdateData( FALSE );
}
Exemple #4
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;
}
static void SyncVR( CRhinoView* lView, CRhinoView* rView) // not calling continuously. much else to add; re:conduits ... pull from example. werk till it werks. then OVRintegration
{
	VR().HMDPoseUpdate();
	if (lView && rView) 
	{ // first we will make it sync the two views as in example

		ON_wString inIf;
		inIf.Format(L"inIf\n");
		RhinoApp().Print( inIf );

		const ON_3dmView& v0 = lView->Viewport().View(); // get Open Nurbs view from 1st CRhinoView* object
		const ON_Viewport& vp0 = lView->Viewport().VP(); // get ON viewport from 1st CRhinoView* object 

		ON_3dmView& v1 = rView->Viewport().m_v; // non-const; ? this important? otherwise same structure as above
		ON_Viewport& vp1 = rView->Viewport().m_v.m_vp; // m_v is settings, m_vp is projection information
		
		vp1.SetProjection( vp0.Projection() ); // so using Viewport().View() to pull from and Viewport().m_v to write to. cannot write to function, yah, duh, all these Things() are functions which return values. not things themselves.
		vp1.SetCameraLocation( vp0.CameraLocation() );
		vp1.SetCameraDirection( vp0.CameraDirection() );
		vp1.SetCameraUp( vp0.CameraUp() ); // breakpoint triggered here
		// v1.SetTargetPoint( v0.TargetPoint() ); // ok so all these assignments make sense

		double fl, fr, ft, fb, fn, ff, fa; // ok dealing with frustrums now: 'Bounding Box' for rendering images. Apparently needs to be kept in sync as well
		vp1.GetFrustumAspect( fa ); // vp1 may be an error -> vp0 . this from example
		vp0.GetFrustum( &fl, &fr, &fb, &ft, &fn, &ff ); // & denotes pointer, I think, or 'disembodied' reference. so the double can be written to?
		vp1.SetFrustum( fl, fr, fb, ft, fn, ff );
		vp1.SetFrustumAspect( fa );

		lView->Viewport().SetTarget( rView->Viewport().Target() ); // this is confusing, though... we have been setting left to right otherwise? ? AND it works both ways!
	}

} // need to setup so this calls everytime at beginning of pipeline
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 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;
}
CRhinoCommand::result CCommandSampleDimStyleTextHeight::RunCommand( const CRhinoCommandContext& context )
{
  // Get the current dimstyle
  const CRhinoDimStyle& dimstyle = context.m_doc.m_dimstyle_table.CurrentDimStyle();

  ON_wString prompt;
  prompt.Format( L"New text height for \"%s\" dimension style", dimstyle.Name() );

  // Prompt for a new text height value
  CRhinoGetNumber gn;
  gn.SetCommandPrompt( prompt );
  gn.SetDefaultNumber( dimstyle.TextHeight() );
  gn.SetLowerLimit( 0.0, TRUE );
  gn.AcceptNothing();
  gn.GetNumber();
  if( gn.CommandResult() != CRhinoCommand::success )
    return gn.CommandResult();

  // New text height value
  double height = gn.Number();

  // Validate new value
  if( height != dimstyle.TextHeight() && ON_IsValid(height) && height > ON_SQRT_EPSILON )
  {
    int style_index = dimstyle.Index();

    // Copy everything from the dimension's dimstyle
    ON_DimStyle modified_dimstyle( context.m_doc.m_dimstyle_table[style_index] );

    // Modify the text height
    modified_dimstyle.SetTextHeight( height );

    // Modify the dimension style
    if( context.m_doc.m_dimstyle_table.ModifyDimStyle(modified_dimstyle, style_index) )
      context.m_doc.Redraw();
  }

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSampleMenuToggle::RunCommand( const CRhinoCommandContext& context )
{
  BOOL bVisible = SampleMenuPlugIn().IsSampleMenuVisible();
 
  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 )
    SampleMenuPlugIn().HideSampleMenu();
  else if( s_option == option_index && !bVisible  )
    SampleMenuPlugIn().ShowSampleMenu();
  else if( t_option == option_index )
  {
    if( bVisible )
      SampleMenuPlugIn().HideSampleMenu();
    else
      SampleMenuPlugIn().ShowSampleMenu();
  }

  return CRhinoCommand::success;
}
Exemple #10
0
void ON_AngularDimension::SetTextToDefault() 
{ 
  ON_wString s; 
  s.Format( L"<>%c", ON_Annotation::degreesym); 
  SetUserText( s); 
}
BOOL CSampleExportMeshPlugIn::WriteFile( const wchar_t* filename, int index, CRhinoDoc& doc, const CRhinoFileWriteOptions& options )
{
  // Description:
  //   Rhino calls WriteFile() to write document geometry to an external file.
  // Parameters:
  //   filename [in] The name of file to write.
  //   index [in] The index of file extension added to list in AddToFileType().
  //   doc [in] The current Rhino document.
  //   options [in] File write options.
  // Remarks:
  //   The plug-in is responsible for opening the file and writing to it.
  // Return TRUE if successful, otherwise return FALSE.

  // TODO: Add file export code here.

  // Are we saving or exporting?
  bool bExport = options.Mode( CRhinoFileWriteOptions::SelectedMode );
  // Are we in interactive or scripted mode?
  bool bScript = options.Mode( CRhinoFileWriteOptions::BatchMode );

  ON_SimpleArray<const CRhinoObject*> objects( 256 );

  // Get objects to save/export
  CRhinoObjectIterator it( doc, CRhinoObjectIterator::undeleted_objects );
  if( bExport )
  {
    it.EnableSelectedFilter();
    it.EnableVisibleFilter();
  }

  // Do the iteration...
  const CRhinoObject* obj = 0;
  for( obj = it.First(); obj; obj = it.Next() )
    objects.Append( obj );

  ON_ClassArray<CRhinoObjectMesh> meshes( objects.Count() );
  ON_MeshParameters mesh_parameters = m_mesh_parameters;
  int mesh_ui_style = ( bScript ) ? 2 : m_mesh_ui_style;

  // Get the meshes to save/export
  CRhinoCommand::result res = RhinoMeshObjects( objects, mesh_parameters, mesh_ui_style, meshes );
  if( res == CRhinoCommand::success )
  {
    if( mesh_ui_style >= 0 && mesh_ui_style <= 1 )
      m_mesh_ui_style = mesh_ui_style;
    m_mesh_parameters = mesh_parameters;
  }
  else 
  {
    if( bExport )
      RhinoApp().Print( L"\nNo meshes to export.\n" );
    else
      RhinoApp().Print( L"\nNo meshes to save.\n" );
    return FALSE;
  }

  // Write the mesh file
  FILE* fp = 0;
  errno_t err = _wfopen_s( &fp, filename, L"w" );
  bool rc = ( 0 == err || 0 != fp );
  if( !rc )
  {
    RhinoApp().Print( L"\nUnable to open \"%s\" for writing.\n", filename );
    return FALSE;
  }

  // Write mesh count
  ON_wString s;
  s.Format( L"meshcount=%d\n", meshes.Count() );
  rc = ( fputws(s, fp) >= 0 );

  int i, j;
  for( i = 0; rc && i < meshes.Count(); i++ )
  {
    const CRhinoObjectMesh& obj_mesh = meshes[i];
    const ON_Mesh* mesh = obj_mesh.m_mesh;
    rc = ( 0 != mesh );

    // Write mesh number
    if( rc )
    {
      s.Format( L"mesh=%d\n", i );
      rc = ( fputws(s, fp) >= 0 );
    }

    // Write mesh vertex count
    if( rc )
    {
      s.Format( L"vertexcount=%d\n", mesh->m_V.Count() );
      rc = ( fputws(s, fp) >= 0 );
    }

    // Write mesh face count
    if( rc )
    {
      s.Format( L"facecount=%d\n", mesh->m_F.Count() );
      rc = ( fputws(s, fp) >= 0 );
    }

    // Write mesh vertices
    if( rc )
    {
      for( j = 0; rc && j < mesh->m_V.Count(); j++ )
      {
        const ON_3fPoint& p = mesh->m_V[j];
        s.Format( L"vertex=(%.16f,%.16f,%.16f)\n", p.x, p.y, p.z );
        rc = ( fputws(s, fp) >= 0 );
      }
    }

    // Write mesh faces
    if( rc )
    {
      for( j = 0; rc && j < mesh->m_F.Count(); j++ )
      {
        const ON_MeshFace& f = mesh->m_F[j];
        s.Format( L"face=(%d,%d,%d,%d)\n", f.vi[0], f.vi[1], f.vi[2], f.vi[3] );
        rc = ( fputws(s, fp) >= 0 );
      }
    }
  }

  fclose( fp );
  
  return ( rc ) ? TRUE : FALSE;
}
BOOL ON_UserStringList::GetDescription( ON_wString& description )
{
  description.Format("User text (%d entries)",m_e.Count());
  return true;
}
Exemple #13
0
ON_BOOL32 ON_HatchExtra::GetDescription( ON_wString& description)
{
  description.Format( "Userdata extension of ON_Hatch (contains basepoint)");
  return true;
}
Exemple #14
0
CRhinoCommand::result CCommandVRCreateViews::RunCommand( const CRhinoCommandContext& context )
{
	AFX_MANAGE_STATE( ::RhinoApp().RhinoModuleState() ); // dunno, from example

	ON_wString wStr;
	wStr.Format( L"READY SET\n", EnglishCommandName() );
	RhinoApp().Print( wStr );

	ON_SimpleArray<CRhinoView*> viewList; // don't know what is up with* this*
	ON_SimpleArray<ON_UUID> viewportIds;
	CRhinoView* lView = 0;
	CRhinoView* rView = 0;
	ON_SimpleArray<CRhinoView*> lrViews; // will contain our vr views
	int i = 0; // also use this in loops
	int lr = 0; // use to track 1st and 2nd find

	// builds a list of (current) viewport IDs
	context.m_doc.GetViewList( viewList, true, false );
	for ( i = 0; i < viewList.Count(); i ++)
	{
		CRhinoView* tempView = viewList[i]; // pull view out -> this is redeclared here, in sample, but not in second loop
		if (tempView)
			viewportIds.Append( tempView->ActiveViewportID() );
	}
	viewList.Empty(); // empty bc we are going to re-build later when new views

	context.m_doc.NewView( ON_3dmView() );
	context.m_doc.NewView( ON_3dmView() ); // we will build two

	// find viewport UUID just created
	context.m_doc.GetViewList( viewList, true, false);
	for (i = 0; i < viewList.Count(); i++)
	{
		CRhinoView* tempView = viewList[i];
		if (tempView)
		{
			int rc = viewportIds.Search( tempView->ActiveViewportID() ); // returns index of 1st element which satisfies search. returns -1 when no such item found
			if (rc < 0 ) // if current tempView did not exist prior to this running
			{
				if (lr > 0) // and if lr already found 1
				{
					rView = tempView; // right is 2nd view we find 
					break;
				// so this breaks when we find, and lView is left as the viewList[i] where we found the new viewport, whose ID was not in our list.
				// and we are left with lView being = viewList[i] at new view
				}
				if (lr == 0)
				{
					lView = tempView; // left is 1st view
					lr = 1;
				}
			}

			else
				tempView = 0; // reset lView to null and re-loop
		}
	}

	lrViews.Append(lView);
	lrViews.Append(rView);

	// init points
	ON_3dPoint locationL = ON_3dPoint(100.0,100.0,100.0);
	ON_3dPoint locationR = ON_3dPoint(100.0,165.1,100.0);
	ON_3dPoint targetSetup = ON_3dPoint(0,0,0);

	if (lView && rView)
	{
		for (int i = 0; i < 2; i++)
		{
			// 			RhinoApp().ActiveView()->
			ON_3dmView onView = lrViews[i]->ActiveViewport().View();

			if(i == 0)
				onView.m_name = L"lView";
				//lrViews[i]->MoveWindow(0,0,VR().resolution.w/2,VR().resolution.h, true);
			if(i == 1)
				onView.m_name = L"rView";
				//lrViews[i]->MoveWindow(960,0,VR().resolution.w/2,VR().resolution.h, true);
			lrViews[i]->ActiveViewport().SetView(onView);
			lrViews[i]->ActiveViewport().m_v.m_vp.ChangeToPerspectiveProjection(50,true,35);
			lrViews[i]->ActiveViewport().m_v.m_vp.SetCameraLocation(locationL);
			lrViews[i]->FloatRhinoView(true);
			lrViews[i]->Redraw();
		}
	}

	VR().lView = lView;
	VR().rView = rView;

	ON_wString SYNC;
	SYNC.Format(L"SYNCVRBEGIN\n" );
	RhinoApp().Print( SYNC );

	if (vrConduit.IsEnabled()
	&& ::IsWindow( vrConduit.m_hWnd1 )
	&& ::IsWindow( vrConduit.m_hWnd2 ) ) // if is already enabled ?
	{
		vrConduit.m_pView1 = 0;
		vrConduit.m_pView2 = 0;
		vrConduit.Disable();
	}
	else
	{
		vrConduit.m_pView1 = lView;
		vrConduit.m_pView2 = rView;
		vrConduit.m_hWnd1 = vrConduit.m_pView1->m_hWnd;
		vrConduit.m_hWnd2 = vrConduit.m_pView2->m_hWnd;

		SyncVR(lView, rView); // ok it runs once. we should also set them up perspective & looking at 0,0

		vrConduit.Bind( *lView );
		vrConduit.Bind( *rView );

		lView->Redraw();
		rView->Redraw();
		
		vrConduit.Enable();
	}

	// but do not update names immediately; have to refresh somehow

	// now re-name update positions outside of loop: continuously
	// bring in OVR Tracking and assign to VR Viewports
	// then, orbit?

	return CRhinoCommand::success;
}