コード例 #1
0
CRhinoCommand::result CCommandSampleMoveCPlane::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoView* view = ::RhinoApp().ActiveView();
  if( !view )
    return CRhinoCommand::failure;

  ON_3dmConstructionPlane cplane = view->Viewport().ConstructionPlane();
  ON_3dPoint origin = cplane.m_plane.origin;

  CSampleMoveCPlanePoint gp( cplane );
  gp.SetCommandPrompt( L"CPlane origin" );
  gp.SetBasePoint( origin );
  gp.DrawLineFromPoint( origin, TRUE );
  gp.GetPoint();

  if( gp.CommandResult() != CRhinoCommand::success )
    return gp.CommandResult();

  ON_3dPoint pt = gp.Point();
  ON_3dVector v = origin - pt;
  if( v.IsTiny() )
    return CRhinoCommand::nothing;

  cplane.m_plane.CreateFromFrame( pt, cplane.m_plane.xaxis, cplane.m_plane.yaxis );
  view->Viewport().SetConstructionPlane( cplane );
  view->Redraw();

	return CRhinoCommand::success;
}
コード例 #2
0
CRhinoCommand::result CCommandSamplePan::RunCommand( const CRhinoCommandContext& context )
{
  const CRhinoAppViewSettings& view_settings = RhinoApp().AppSettings().ViewSettings();
  double d = view_settings.m_pan_increment;
  if (view_settings.m_pan_reverse_keyboard)
    d = -d;

  CRhinoGetOption go;
  go.SetCommandPrompt(L"Select pan option");
  go.AcceptNothing();

  const int down_option_index  = go.AddCommandOption(RHCMDOPTNAME(L"Down"));
  const int left_option_index  = go.AddCommandOption(RHCMDOPTNAME(L"Left"));
  const int right_option_index = go.AddCommandOption(RHCMDOPTNAME(L"Right"));
  const int up_option_index    = go.AddCommandOption(RHCMDOPTNAME( L"Up"));
  const int in_option_index    = go.AddCommandOption(RHCMDOPTNAME(L"In"));
  const int out_option_index   = go.AddCommandOption(RHCMDOPTNAME(L"Out"));

  for(;;)
  {
    CRhinoGet::result res = go.GetOption();

    if (res != CRhinoGet::option)
      break;

    CRhinoView* view = go.View(); 
    const CRhinoCommandOption* option = go.Option();

    if (0 != view && 0 != option && 0.0 != d)
    {
      CRhinoViewport* viewport = &(view->ActiveViewport());
      if (0 != viewport && viewport->View().m_bLockedProjection)
        viewport = &(view->MainViewport());

      if (0 != viewport)
      {
        if (down_option_index == option->m_option_index)
          viewport->DownUpDolly(-d);
        else if (up_option_index == option->m_option_index)
          viewport->DownUpDolly(d);
        else if (left_option_index == option->m_option_index)
          viewport->LeftRightDolly(-d);
        else if (right_option_index == option->m_option_index)
          viewport->LeftRightDolly(d);
        else if (in_option_index == option->m_option_index)
          viewport->InOutDolly(d);
        else if (out_option_index == option->m_option_index)
          viewport->InOutDolly(-d);
      }

      view->Redraw();
      RhinoApp().SetActiveView(view);
    }
  }  
  
  return CRhinoCommand::success;
}
コード例 #3
0
CRhinoCommand::result CCommandSampleZoomRotateWindow::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetPoint gp;
  gp.SetCommandPrompt( L"Drag a window to zoom" );
  gp.SetGetPointCursor( RhinoApp().m_default_cursor );
  gp.ConstrainToTargetPlane();
  gp.AcceptNothing();
  switch( gp.Get2dRectangle() )
  {
  case CRhinoGet::rect2d:
    break;
  default:
    return CRhinoCommand::cancel;
  }

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

  CRhinoViewport& vport = view->ActiveViewport();

  if( !vport.VP().IsParallelProjection() )
  {
    RhinoApp().Print( L"This sample only works in parallel-projected views.\n" );
    return CRhinoCommand::nothing;
  }

  ON_3dPoint target_point = vport.Target();
  CRect pick_rect = gp.Rectangle2d();
  ON_Viewport vp_out;

  if( DollyWindow(vport, pick_rect, target_point, vp_out) )
  {
    vport.m_v.SetTargetPoint( target_point );
    vp_out.SetTargetPoint( target_point );
    vport.SetVP( vp_out, false );
    view->Redraw();
  }

  return CRhinoCommand::success;
}
コード例 #4
0
ファイル: cmdVRCreateViews.cpp プロジェクト: jakeread/vraptor
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;
}