예제 #1
0
CRhinoCommand::result CCommandSampleMeshDir::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetGeometryFilter( CRhinoObject::mesh_object | CRhinoObject::surface_object | CRhinoObject::polysrf_object | CRhinoObject::instance_reference );
  go.SetCommandPrompt( L"Select mesh, surface, or polysurface objects" );
  go.GetObjects(1,0);
  if( go.Result() != CRhinoGet::object )
    return CRhinoCommand::cancel;

  int i = 0;
  ON_SimpleArray<const CRhinoObject*> objects( go.ObjectCount() );
  for( i = 0; i < go.ObjectCount(); i++ )
    objects.Append( go.Object(i).Object() );

  ON_ClassArray<CRhinoObjRef> render_meshes;
  int count = RhinoGetRenderMeshes( objects, render_meshes, true, false );
  if( count > 0 )
  {
    CMeshDirDrawCallback callback;
    callback.m_mesh_list.Reserve( count );
    for( i = 0; i < render_meshes.Count(); i++ )
    {
      const ON_Mesh* mesh = render_meshes[i].Mesh();
      if( mesh )
        callback.m_mesh_list.AppendNew().SetMesh( mesh );
    }

    CRhinoGetOption go;
    go.SetCommandPrompt( L"Press Enter when done" );
    go.AcceptNothing();
    go.AddCommandOptionToggle( RHCMDOPTNAME(L"FaceNormals"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), m_draw_face_normals, &m_draw_face_normals );
    go.AddCommandOptionToggle( RHCMDOPTNAME(L"VertexNormals"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), m_draw_vertex_normals, &m_draw_vertex_normals );

    CRhinoGet::result res = CRhinoGet::nothing;
    for( ;; )
    {
      callback.m_draw_face_normals = m_draw_face_normals;
      callback.m_draw_vertex_normals = m_draw_vertex_normals;

      CRhinoView::AddDrawCallback( &callback );
      context.m_doc.Redraw( CRhinoView::regenerate_display_hint );

      res = go.GetOption();
      CRhinoView::RemoveDrawCallback( &callback );

      if( res == CRhinoGet::option )
        continue;
      break;
    }
  }

  context.m_doc.Redraw( CRhinoView::regenerate_display_hint );
  
  return CRhinoCommand::success;
}
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 );
}
CRhinoCommand::result CCommandZAnalysisOn::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select objects for Z analysis.");
  go.SetGeometryFilter( ON::brep_object | ON::mesh_object );
  go.GetObjects(1,0);
  if( CRhinoCommand::success != go.CommandResult() )
    return go.CommandResult();

  ON_MeshParameters mp = CRhinoAppRenderMeshSettings::DefaultQualityMeshParameters();
  context.m_doc.Properties().SetAnalysisMeshSettings( mp );

  int count = 0;
  for( int i = 0; i < go.ObjectCount(); i++ )
  {
    const CRhinoObject* rhino_object = go.Object(i).Object();
    if( 0 == rhino_object )
      continue;

    if( rhino_object->InAnalysisMode(theZAnalysisVAM.m_am_id) )
      continue;

    const_cast<CRhinoObject*>(rhino_object)->DestroyMeshes( ON::analysis_mesh, true );

    if( rhino_object->EnableAnalysisMode(theZAnalysisVAM.m_am_id, true) )
      count++;
  }

  RhinoApp().Print( L"%d objects were put into Z analysis mode", count );
  context.m_doc.Redraw();

	return CRhinoCommand::success;
}
CRhinoCommand::result CCommandTestHistoryExample::RunCommand( const CRhinoCommandContext& context )
{
  CRhinoCommand::result rc  = CRhinoCommand::failure; 

  CRhinoGetObject go;
  go.SetCommandPrompt(L"Pick two curves");
  go.SetGeometryFilter(CRhinoGetObject::curve_object);
  go.GetObjects(2,2);
  if( go.Result()== CRhinoGet::object && 
      go.ObjectCount()==2)
  {
    CRhinoObjRef CObj0 = go.Object(0);
    CRhinoObjRef CObj1 = go.Object(1);
    const ON_Curve* c0 = CObj0.Curve();
    const ON_Curve* c1 = CObj1.Curve();
    if( c0 && c1)
    {
      ON_Surface* pSrf = MakeBilinearSurface( *c0, *c1);
      ON_Brep brep;
      if(pSrf && brep.Create(pSrf))
      {
        CRhinoHistory history(*this);
        WriteHistory(history,  CObj0, CObj1);
        context.m_doc.AddBrepObject(brep,NULL,&history);
        rc  = CRhinoCommand::success; 
      }
    }

  }

  return rc;
}
CRhinoCommand::result CCommandSamplePrintGripLocations::RunCommand( const CRhinoCommandContext& context )
{
	CRhinoGetObject go;
  go.SetCommandPrompt( L"Select grips" );
  go.SetGeometryFilter( CRhinoGetObject::grip_object );
  go.GetObjects( 1, 0 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();

  const int object_count = go.ObjectCount();
  for( int i = 0; i < object_count; i++ )
  {
    const CRhinoGripObject* grip = CRhinoGripObject::Cast( go.Object(i).Object() );
    if( grip )
    {
      ON_3dPoint point = grip->GripLocation();

      ON_wString point_str;
      RhinoFormatPoint( point, point_str );

      RhinoApp().Print( L"Grip %d = %s\n", i, point_str );
    }
  }

  return CRhinoCommand::success;
}
CRhinoCommand::result CCommandSamplePrePostSelect::RunCommand( const CRhinoCommandContext& context )
{
  double dValue = m_dValue;
  int nValue = m_nValue;

  CRhinoGetObject go;
  go.SetGeometryFilter( CRhinoGetObject::curve_object );
  go.EnableGroupSelect( TRUE );
  go.EnableSubObjectSelect( FALSE );

  /*int d_option_index =*/ go.AddCommandOptionNumber( 
      RHCMDOPTNAME(L"Double"), &dValue, L"Double value", FALSE, 1.0, 99.9 );

  /*int n_option_index =*/ go.AddCommandOptionInteger( 
      RHCMDOPTNAME(L"Integer"), &nValue, L"Integer value", 1, 99 );

  bool bHavePreselectedObjects = false;

  for( ;; )
  {
    CRhinoGet::result res = go.GetObjects( 1, 0 );

    if( res == CRhinoGet::option )
    {
      go.EnablePreSelect( FALSE );
      go.EnableAlreadySelectedObjectSelect( true );
      go.EnableClearObjectsOnEntry( false );
      go.EnableDeselectAllBeforePostSelect( false );
      go.EnableUnselectObjectsOnExit( false );
      continue;
    }

    else if( res != CRhinoGet::object )
      return CRhinoCommand::cancel;

    if( go.ObjectsWerePreSelected() )
    {
      bHavePreselectedObjects = true;
      go.EnablePreSelect( FALSE );
      go.EnableAlreadySelectedObjectSelect( true );
      go.EnableClearObjectsOnEntry( false );
      go.EnableDeselectAllBeforePostSelect( false );
      go.EnableUnselectObjectsOnExit( false );
      continue;
    }

    break;
  }

  if( bHavePreselectedObjects )
  {
    // Normally, pre-selected objects will remain selected, when a
    // command finishes, and post-selected objects will be unselected.
    // This this way of picking, it is possible to have a combination
    // of pre-selected and post-selected. So, to make sure everything
    // "looks the same", lets unselect everything before finishing
    // the command.
    for( int i = 0; i < go.ObjectCount(); i++ )
    {
      const CRhinoObject* object = go.Object(i).Object();
      if( 0 != object )
        object->Select( false );
    }
    context.m_doc.Redraw();
  }

  int object_count = go.ObjectCount();
  m_dValue = dValue;
  m_nValue = nValue;

  RhinoApp().Print( L"Select object count = %d\n", object_count );
  RhinoApp().Print( L"Value of double = %f\n", m_dValue );
  RhinoApp().Print( L"Value of integer = %d\n", m_nValue );

  return CRhinoCommand::success;
}
예제 #7
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;
}
CRhinoCommand::result CCommandSampleOrientOnSrf::RunCommand( const CRhinoCommandContext& context )
{
  // Select objects to orient
	CRhinoGetObject go;
  go.SetCommandPrompt( L"Select objects to orient" );
  go.EnableSubObjectSelect( FALSE );
  go.EnableGroupSelect( TRUE );
  go.GetObjects( 1, 0 );
  if( go.CommandResult() != CRhinoCommand::success )
    return go.CommandResult();

  // Point to orient from
  CRhinoGetPoint gp;
  gp.SetCommandPrompt( L"Point to orient from" );
  gp.GetPoint();
  if( gp.CommandResult() != CRhinoCommand::success )
    return gp.CommandResult();

  // Define source plane
  CRhinoView* view = gp.View();
  if( 0 == view )
  {
    view = RhinoApp().ActiveView();
    if( 0 == view )
      return CRhinoCommand::failure;
  }
  ON_Plane source_plane( view->Viewport().ConstructionPlane().m_plane );
  source_plane.SetOrigin( gp.Point() );

  // Surface to orient on
  CRhinoGetObject gs;
  gs.SetCommandPrompt( L"Surface to orient on" );
  gs.SetGeometryFilter( CRhinoGetObject::surface_object );
  gs.EnableSubObjectSelect( TRUE );
  gs.EnableDeselectAllBeforePostSelect( false );
  gs.EnableOneByOnePostSelect();
  gs.GetObjects( 1, 1 );
  if( gs.CommandResult() != CRhinoCommand::success )
    return gs.CommandResult();

  const CRhinoObjRef& ref = gs.Object(0);
  // Get selected surface object
  const CRhinoObject* obj = ref.Object();
  if( 0 == obj )
    return CRhinoCommand::failure;
  // Get selected surface (face)
  const ON_BrepFace* face = ref.Face();
  if( 0 == face )
    return CRhinoCommand::failure;
  // Unselect surface
  obj->Select( false );

  // Point on surface to orient to
  gp.SetCommandPrompt( L"Point on surface to orient to" );
  gp.Constrain( *face );
  gp.GetPoint();
  if( gp.CommandResult() != CRhinoCommand::success )
    return gp.CommandResult();

  // Do transformation
  CRhinoCommand::result rc = CRhinoCommand::failure;
  double u = 0.0, v = 0.0;
  if( face->GetClosestPoint(gp.Point(), &u, &v) )
  {
    ON_Plane target_plane;
    if( face->FrameAt(u, v, target_plane) )
    {
      // If the face orientation is opposite
      // of natural surface orientation, then
      // flip the plane's zaxis.
      if( face->m_bRev )
        target_plane.CreateFromFrame( 
            target_plane.origin, 
            target_plane.xaxis, 
            -target_plane.zaxis 
            );

      // Build transformation
      ON_Xform xform;
      xform.Rotation( source_plane, target_plane );

      // Do the transformation. In this example,
      // we will copy the original objects
      bool bDeleteOriginal = false;
      int i;
      for( i = 0; i < go.ObjectCount(); i++ )
        context.m_doc.TransformObject( go.Object(i), xform, bDeleteOriginal );
      context.m_doc.Redraw();
      rc = CRhinoCommand::success;
    }
  }

	return rc;
}
예제 #10
0
CRhinoCommand::result CTraslRuota::RunCommand( const CRhinoCommandContext& context )
{
		Cscript1PlugIn& plugin = script1PlugIn();
		if( !plugin.IsDlgVisible() )
		{
			return CRhinoCommand::nothing;
		}

		/*GET A REFERENCE TO THE LAYER TABLE*/
	  CRhinoLayerTable& layer_table = context.m_doc.m_layer_table;
	  


	  ON_Layer currentLayer;
		  int numLayers = layer_table.LayerCount();
		 
		  for(int i = 0; i < numLayers; i++)
	{
			  
				  currentLayer = layer_table[i];
				  const CRhinoLayer& layer = layer_table[i];

				  currentLayer.SetVisible(true);
				  
				  layer_table.ModifyLayer(currentLayer, i);
				  layer_table.SetCurrentLayerIndex(i);
				  
			  
		  
		  
		  
		  
		  const CRhinoLayer& current_layer = layer_table.CurrentLayer();

		  int layer_index = layer_table.CurrentLayerIndex();
		  const CRhinoLayer& layer2 = layer_table[layer_index];

		  ON_SimpleArray<CRhinoObject*> obj_list;
		  int j, obj_count = context.m_doc.LookupObject( layer2, obj_list );
		  for( j = 0; j < obj_count; j++ )
		  {
				  CRhinoObject* obj = obj_list[j];
				  if( obj && obj->IsSelectable() )
					  obj->Select();
				  if( obj_count )
					context.m_doc.Redraw();
		  }
		  
	}  

		  context.m_doc.Redraw();

			//inizio rotazione
		  
		  double m_angle=(_wtof(plugin.m_dialog->ValoreRotazione));
		  ON_Plane plane = RhinoActiveCPlane();
		  
		CRhinoGetObject go1;
		  go1.GetObjects( 1, 0 );
		  int numero1 = go1.ObjectCount();
		for( int k = 0; k < go1.ObjectCount(); k++ )
		{
		 // Get an object reference
			const CRhinoObjRef& ref = go1.Object(k);
 
			// Get the real object
			const CRhinoObject* obj = ref.Object();
			if( !obj )
			continue;

			ON_Xform xform;
    xform.Rotation( m_angle * ON_PI / 180.0, plane.zaxis, plane.Origin() );
	context.m_doc.TransformObject( obj, xform, true, true, true );
	context.m_doc.Redraw();
		}

		//fine rotazione


			//inizio traslazione		 
		  CRhinoGetObject go;
		  int numero = go.ObjectCount();
		  go.GetObjects( 1, 0 );
		  
		for( int i = 0; i < go.ObjectCount(); i++ )
		{
		 // Get an object reference
			const CRhinoObjRef& ref = go.Object(i);
 
			// Get the real object
			const CRhinoObject* obj = ref.Object();
			if( !obj )
			continue;

			ON_Xform xform;
    xform.Rotation( m_angle * ON_PI / 180.0, plane.zaxis, plane.Origin() );
	//context.m_doc.TransformObject( obj, xform, true, true, true );
	context.m_doc.Redraw();
	xform.Translation((_wtof(plugin.m_dialog->ValoreTraslazione)),0,0);
	context.m_doc.TransformObject( obj, xform, true, true, true );
	context.m_doc.Redraw();
		}
			// fine traslazione

		
		 context.m_doc.Redraw();




return CRhinoCommand::success;


}
CRhinoCommand::result CCommandTestUVMesh::RunCommand( const CRhinoCommandContext& context )
{
  bool bDeleteInput = false;
  CRhinoGetObject go;
  go.SetCommandPrompt(L"Select untrimmed surface");
  go.AddCommandOptionInteger(RHCMDOPTNAME(L"U"), &m_U, 0, 2);
  go.AddCommandOptionInteger(RHCMDOPTNAME(L"V"), &m_V, 0, 2);
  go.AddCommandOptionToggle(RHCMDOPTNAME(L"DeleteInput"), RHCMDOPTVALUE(L"No"), RHCMDOPTVALUE(L"Yes"), bDeleteInput, &bDeleteInput);
  go.SetGeometryFilter(CRhinoGetObject::surface_object);
  go.SetGeometryAttributeFilter(CRhinoGetObject::untrimmed_surface);

  CRhinoGet::result rs = CRhinoGet::no_result;
  while (CRhinoGet::cancel != rs && CRhinoGet::nothing != rs && CRhinoGet::object != rs)
    rs = go.GetObjects(1,1);

  if (CRhinoGet::cancel == rs)
    return CRhinoCommand::cancel;
  if (0 == go.ObjectCount())
    return CRhinoCommand::failure;

  const CRhinoObject* pObj = go .Object(0).Object();
  if (0 == pObj)
    return CRhinoCommand::failure;

  const ON_BrepFace* pBrepFace = go.Object(0).Face();
  if (0 == pBrepFace)
    return CRhinoCommand::failure;

  const ON_Surface* pSurf = pBrepFace->SurfaceOf();
  if (0 == pSurf)
    return CRhinoCommand::failure;

  ON_SimpleArray<double>UArray(m_U+1);
  ON_SimpleArray<double>VArray(m_V+1);
  double UDist, VDist;
  UDist = (pSurf->Domain(0).m_t[1]-pSurf->Domain(0).m_t[0])/m_U;
  VDist = (pSurf->Domain(1).m_t[1]-pSurf->Domain(1).m_t[0])/m_V;
  int i;
  for (i=0; i <= m_U; i++)
    UArray.Append(pSurf->Domain(0).m_t[0] + i*UDist);
  for (i=0; i <= m_V; i++)
    VArray.Append(pSurf->Domain(1).m_t[0] + i*VDist);

  //If m_U or m_V are large then there can be a slight difference between
  //pSurf->Domain(0).m_t[0] + (m_U-1)*UDist and pSurf->Domain(0).m_t[1]
  //ON_MeshSurface requires it to be less than or equal to pSurf->Domain(0).m_t[1]
  //05/24/06 TimH Fix for RR21194
  double* d = UArray.Last();
  if (pSurf->Domain(0).m_t[1] < *d)
    *d = pSurf->Domain(0).m_t[1];
  d = VArray.Last();
  if (pSurf->Domain(1).m_t[1] < *d)
    *d = pSurf->Domain(1).m_t[1];

  ON_Mesh* pMeshOut = ON_MeshSurface(*pSurf, m_U+1, UArray.Array(), m_V+1, VArray.Array());

  if (0 == pMeshOut)
    return CRhinoCommand::failure;

  CRhinoMeshObject* pMeshObj = new CRhinoMeshObject(pObj->Attributes());
  if (0 == pMeshObj)
  {
    delete pMeshOut;
    return CRhinoCommand::failure;
  }
  pMeshObj->SetMesh(pMeshOut);

  if (true == bDeleteInput)
    context.m_doc.ReplaceObject(pObj, pMeshObj);
  else
    context.m_doc.AddObject(pMeshObj);

  context.m_doc.Redraw();
  return CRhinoCommand::success;
}