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