Move C Plane
Last changed: stevebaer-204.177.179.109

.
DeveloperC++, .NET
SummaryDemonstrates how to move the origin of a construction plane.

C++

  class CTestMoveCPlanePoint : public CRhinoGetPoint
  {
  public:
    CTestMoveCPlanePoint( const ON_3dmConstructionPlane& cplane );
    ~CTestMoveCPlanePoint() {}
    void SetConstructionPlane(const ON_3dmConstructionPlane& cplane);
    void OnMouseMove( CRhinoViewport& vp,
                      UINT flags,
                      const ON_3dPoint& pt,
                      const CPoint* pt2d );
    void DynamicDraw( HDC hdc,
                      CRhinoViewport& vp,
                      const ON_3dPoint& pt );
  private:
    ON_3dmConstructionPlane m_cplane;
  };


  CTestMoveCPlanePoint::CTestMoveCPlanePoint(const ON_3dmConstructionPlane& cplane)
  : m_cplane(cplane)
  {
  }


  void CTestMoveCPlanePoint::OnMouseMove( CRhinoViewport& vp, UINT flags,
                                          const ON_3dPoint& pt, const CPoint* pt2d )
  {
    m_cplane.m_plane.CreateFromFrame( pt, m_cplane.m_plane.xaxis, m_cplane.m_plane.yaxis );
    CRhinoGetPoint::OnMouseMove( vp, flags, pt, pt2d );
  }


  void CTestMoveCPlanePoint::DynamicDraw(HDC hdc, CRhinoViewport& vp, const ON_3dPoint& pt)
  {
    vp.DrawConstructionPlane( m_cplane, FALSE, TRUE );
    CRhinoGetPoint::DynamicDraw( hdc, vp, pt );
  }


  CRhinoCommand::result CCommandTest::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;


    CTestMoveCPlanePoint 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;
  }

VB.NET (Rhino 4)

  Private Class CTestMoveCPlanePoint
    Inherits MRhinoGetPoint
    Private m_cplane As On3dmConstructionPlane


    Public Sub New(ByVal cplane As IOn3dmConstructionPlane)
      m_cplane = New On3dmConstructionPlane(cplane)
    End Sub


    Public Sub SetConstructionPlane(ByVal cplane As IOn3dmConstructionPlane)
      m_cplane = New On3dmConstructionPlane(cplane)
    End Sub


    Public Overrides Sub OnMouseMove(ByVal vp As MRhinoViewport, _
                                     ByVal nFlags As UInteger, _
                                     ByVal point As IOn3dPoint, _
                                     ByVal view_wnd_point As System.Drawing.Point)
      m_cplane.m_plane.CreateFromFrame(point, m_cplane.m_plane.xaxis, m_cplane.m_plane.yaxis)
      MyBase.OnMouseMove(vp, nFlags, point, view_wnd_point)
    End Sub


    Public Overrides Sub DynamicDraw(ByVal hdc As System.IntPtr, _
                                     ByVal viewport As MRhinoViewport, _
                                     ByVal pt As IOn3dPoint)
      viewport.DrawConstructionPlane(m_cplane, False, True)
      MyBase.DynamicDraw(hdc, viewport, pt)
    End Sub
  End Class




  Public Overrides Function RunCommand(ByVal context As IRhinoCommandContext) _
    As IRhinoCommand.result


    Dim view As MRhinoView = RhUtil.RhinoApp.ActiveView
    If (view Is Nothing) Then Return IRhinoCommand.result.failure


    Dim cplane As New On3dmConstructionPlane(view.ActiveViewport().ConstructionPlane())
    Dim origin As New On3dPoint(cplane.m_plane.origin)
    Dim gp As New CTestMoveCPlanePoint(cplane)
    gp.SetCommandPrompt("CPlane origin")
    gp.SetBasePoint(origin)
    gp.DrawLineFromPoint(origin, True)
    gp.GetPoint()
    If (gp.CommandResult() <> IRhinoCommand.result.success) Then
      Return gp.CommandResult()
    End If


    Dim pt As On3dPoint = gp.Point()
    Dim v As On3dVector = origin - pt
    If (v.IsTiny()) Then Return IRhinoCommand.result.nothing


    cplane.m_plane.CreateFromFrame(pt, cplane.m_plane.xaxis, cplane.m_plane.yaxis)
    view.ActiveViewport().SetConstructionPlane(cplane)
    view.Redraw()
    Return IRhinoCommand.result.success
  End Function

C# (Rhino 4)

  private class CTestMoveCPlanePoint : MRhinoGetPoint
  {
    private On3dmConstructionPlane m_cplane;


    public CTestMoveCPlanePoint(IOn3dmConstructionPlane cplane)
    {
      m_cplane = new On3dmConstructionPlane(cplane);
    }


    public void SetConstructionPlane(IOn3dmConstructionPlane cplane)
    {
      m_cplane = new On3dmConstructionPlane(cplane);
    }


    public override void OnMouseMove(MRhinoViewport vp,
                                     uint nFlags,
                                     IOn3dPoint point,
                                     System.Drawing.Point view_wnd_point)
    {
      m_cplane.m_plane.CreateFromFrame(point,
                                       m_cplane.m_plane.xaxis,
                                       m_cplane.m_plane.yaxis);
      base.OnMouseMove(vp, nFlags, point, view_wnd_point);
    }


    public override void DynamicDraw(System.IntPtr hdc,
                                     MRhinoViewport viewport,
                                     IOn3dPoint pt)
    {
      viewport.DrawConstructionPlane(m_cplane, false, true);
      base.DynamicDraw(hdc, viewport, pt);
    }
  }




  public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  {
    MRhinoView view = RhUtil.RhinoApp().ActiveView();
    if( view == null )
      return IRhinoCommand.result.failure;


    On3dmConstructionPlane cplane = 
         new On3dmConstructionPlane(view.ActiveViewport().ConstructionPlane());
    On3dPoint origin = new On3dPoint(cplane.m_plane.origin);
    CTestMoveCPlanePoint gp = new CTestMoveCPlanePoint(cplane);
    gp.SetCommandPrompt("CPlane origin");
    gp.SetBasePoint(origin);
    gp.DrawLineFromPoint(origin, true);
    gp.GetPoint();
    if( gp.CommandResult() != IRhinoCommand.result.success )
      return gp.CommandResult();


    On3dPoint pt = gp.Point();
    On3dVector v = origin - pt;
    if(v.IsTiny())
      return IRhinoCommand.result.nothing;


    cplane.m_plane.CreateFromFrame(pt, cplane.m_plane.xaxis, cplane.m_plane.yaxis);
    view.ActiveViewport().SetConstructionPlane(cplane);
    view.Redraw();
    return IRhinoCommand.result.success;
  }