For example, something simple, I imagine a circle (of fixed size, always parallel to the camera) to position defined by a Point3d, so that by rotating the camera this object rotates too (his center is the point3d), but without be a selectable or manipulatable object… So the thing is to interact with that circle, throwing mouse events or whatever, like a button for example.
It’s understandable? I can explain better if required…
The question is, is there some class in RhinoCommon for something like this? If not, is there any logical reason why that can not be done?
Thanks for you reply Luis.
This code seems to do the work, but some things must be fixed.
I think the code can be much improved, if someone wants I’d be grateful.
Its made in a VB component of grasshopper.
Private Sub RunScript(ByVal x As Boolean, ByVal ID As Guid, ByRef A As Object)
If x Then
C = New CustomIO(ID)
c.Enabled = True
rhinodoc.ActiveDoc.Views.Redraw()
Else
If (C IsNot Nothing) Then c.Enabled = False
End If
End Sub
'<Custom additional code>
Public C As customIO
Class CustomIO
Inherits Rhino.Display.DisplayConduit
Private Radius As Integer = 30
Private PointID As guid
Private mc As Rhino.UI.mousecallback
Private cts As system.Drawing.Point
Public Clicked As Boolean
Sub New(ID As guid)
PointID = ID
Clicked = False
End Sub
Protected Overrides Sub DrawOverlay (e As Rhino.Display.DrawEventArgs)
'Get point.
Dim rh As rhinoobject = e.RhinoDoc.Objects.Find(PointID)
'Set plane parallel to camera.
Dim pln As New plane
Rhino.RhinoDoc.ActiveDoc.Views.ActiveView.ActiveViewport.GetCameraFrame(pln)
Dim pt As Rhino.Geometry.point = DirectCast(rh.Geometry, Rhino.Geometry.point)
pln.Origin = pt.Location
'MouseHover.
Dim proy As Point3d = pt.Location
proy.Transform(transform.PlanarProjection(pln))
Dim wtc As point2d = e.Viewport.WorldToClient(proy)
cts = e.Viewport.ClientToScreen(wtc)
'MouseClick.
If (mc Is Nothing) Then
mc = New mymouseCallback(Me)
mc.Enabled = True
End If
'Set radius in world.
cts.X += radius
Dim stc As system.Drawing.Point = e.Viewport.ScreenToClient(cts)
Dim ctw As line = e.Viewport.ClientToWorld(stc)
Dim lp As New Double
rhino.Geometry.Intersect.Intersection.LinePlane(ctw, pln, lp)
Dim rad As Double = pln.Origin.DistanceTo(ctw.PointAt(lp))
'Draw circle shape.
Dim circle As New circle(pln, Rad)
Dim brp As brep = brep.CreatePlanarBreps(circle.ToNurbsCurve())(0)
Dim col As color = color.DarkViolet
If (clicked) Then
col = color.BurlyWood
Else
col = color.DarkViolet
End If
Dim mat As New rhino.Display.DisplayMaterial(col)
e.Display.DrawBrepShaded(brp, mat)
End Sub
Public Function MouseHover As Boolean
Dim cursor As System.Drawing.Point = system.Windows.Forms.Cursor.Position
Return math.Sqrt(((cts.X - cursor.X) ^ 2) + ((cts.Y - cursor.Y) ^ 2)) <= Radius
End Function
End Class
Public Class MyMouseCallback
Inherits Rhino.UI.MouseCallback
Private _CustomIO As CustomIO
Sub New(CIO As customIO)
_CustomIO = CIO
End Sub
Protected Overrides Sub OnMouseDown(e As Rhino.UI.MouseCallbackEventArgs)
MyBase.OnMouseDown(e)
If (_CustomIO.MouseHover) Then
_CustomIO.Clicked = Not _CustomIO.Clicked
RhinoApp.WriteLine("HECHO" & Date.now().ToString())
rhinodoc.ActiveDoc.Views.ActiveView.Redraw()
End If
End Sub
End Class
'</Custom additional code>
End Class