GetPoint override OnMouseDown failed

I oveeride OnMouseMove and OnMouseDown in GetPoint class, OnMouseMove is Ok,But OnMouseDown is failed.Why?

system:win8 64 vs2013 Rhino5 sr11 32-bit 5.11.50226.17195, 2015/2/26

Code:

class crv : GetPoint
{
    protected override void OnMouseMove(GetPointMouseEventArgs e)
    {
        RhinoApp.WriteLine("mousemove");//it is ok
        base.OnMouseMove(e);
    }
    protected override void OnMouseDown(GetPointMouseEventArgs e)
    {
        RhinoApp.WriteLine("mousedown");//But here not work,not being called,Why?
        base.OnMouseDown(e);
    }

}

    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
        
        crv cc = new crv();
        while (true)
        {
            cc.Get();
            if (cc.CommandResult() == Result.Cancel)
                break;
        }
        return Result.Success;
    }

You probably want to call the overload of Get that takes a bool specifying that you want the get to complete on mouse up instead of mouse down.

cc.Get(true);

Thank you!

Now, OnMouseDown is working,LeftButtonDown have capture,But MiddleButtonDown not have capture.why?
@stevebaer

I don’t understand your question, sorry.

@stevebaer

 class crv : GetPoint
{
    //press middle button can not trigger the event.
    protected override void OnMouseDown(GetPointMouseEventArgs e)
    {
        if(e.LeftButtonDown)//Press left button,  it  is working.
          RhinoApp.WriteLine("LeftButtonDown");
        if(e.MiddleButtonDown)//Press middle button. not working. no response
          RhinoApp.WriteLine("MiddleButtonDown");
        base.OnMouseDown(e);
    }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    crv cc = new crv();
    while (true)
    {
        cc.Get(true);
        if (cc.CommandResult() == Result.Cancel)
            break;
    }
    return Result.Success;
}

I don’t believe the GetPoint classes pay attention to middle mouse down events.

@stevebaer
I tried again,still fails,i upload the code,please check what is wrong.

MyProject2.zip (24.2 KB)

I don’t have the time at the moment to look at this project, but if you are still trying to get called during a middle mouse down I don’t believe the middle mouse event is caught by the getpoint class.

This topic suit my question. Why GetPoint.MouseDown is fired only once? I want to suspend MouseUp using inherited MouseCallback but it works only once, later it’s never called.

Or maybe someone could explain why when i call GetPoint.Get() when i completly change command for eg during my command i will run _Box command my Get() exits not before _Box but after _Box ? Is worth also mentioning that i set `EnableTransparentCommands’ to false.

I’d like also to ask why if I cancel OnMouseDown it doesn’t raise later OnMouseUp at all ? It raises OnMouseDown in override im canceling the event and it raises MouseMove nicely but it later doesn’t raise OnMouseUp at all…

Hi @D-W,

Please review the comments for GetPoint.MouseDown and let me know if you have any questions.

My apologies, but I am really having a hard time trying to figure out what you are describing. Can you please clarify or provide some sample code that isn’t working for you?

Thanks,

– Dale

Hi @dale,

ok maybe it will be better if i’ll describe behavior which i would expect here. I need a getter more or less like in _Sketch command but without quitting it after LMB release - i believe it will be GetPoint.Get(true) with registering points during MouseMove. To prevent LMB release quiting i wanted to use overridden MouseCallback.

Second thing which i want to do during this Get() is to detect LMB + CTRL + DRAG and RMB + ALT + Drag to provide an interactive change of param during it:

  1. Need to override default RMB + ALT + Drag behavior
  2. Need to prevent RMB from quitting Get() in OnMouseUp
  3. LMB + CTRL + DRAG shouldn’t be an issue here if i’ll prevent OnMouseUp LMB quitting the method.

Above doesn’t change a thing that command like _Box does run on top if im in Get() currently - this is just tricky since it applies also MouseCallback overrides at least for a single run.

private class MouseCallbackOverride : MouseCallback
        {
            private bool isDoingSth;

            protected override void OnMouseDown(MouseCallbackEventArgs e)
            {
                if (e.Button == MouseButtons.Right && Keyboard.IsKeyDown(Key.LeftAlt))
                {
                    e.Cancel = true;
                    isDoingSth = true;
                }
            }

            protected override void OnMouseUp(MouseCallbackEventArgs e)
            {
                if (isDoingSth)
                {
                    e.Cancel = true;
                    isDoingSth = false;
                }
            }

            protected override void OnMouseMove(MouseCallbackEventArgs e)
            {
                if (isDoingSth)
                {
                    DoStuff();
                }
            }
        }

And ofc before using:

var mo = new MouseCallbackOverride();
mo.Enabled = true;

using(GetPoint gp = new GetPoint())
{
    var result = gp.Get(true);
    ...
}

mo.Enabled = false;

OnMouseUp isn’t raised at all here. I set a breakpoint which never occurs. Oh and when im in this Get(true) and user will run for eg. _Box i’m not hitting mo.Enabled = false before the _Box getter kicks in.


@dale would you mind to share how the e.Cancel should be used to not impact OnMouseUp functionality? I decided to do this from ground up and create my own getter absolutely not relying on Rhino.Input stuff but it looks like still if i call e.Cancel = true during OnMouseDown it will never fire OnMouseUp - any possible workarounds or sth ?

SampleCsSketch.cs

GetPoint will only a single point, either when the mouse goes down - GetPoint.Get() - or when the mouse comes back up GetPoint.Get(true). If you need to pick multiple points, then you can create a loop in your code and call GetPoint.Getmultiple times.

I don’t believe it is possible to override Rhino’s default mouse behavior. However, you certainly try to implement your own mouse handling using either the MouseCallback class, which you know about. This looks like what you are trying to do.

I don’t understand this question. But the use of e.Cancel is pretty clearly documented in the MouseCallback comments.

Sorry for not being very helpful. I find your questions somewhat fragmented and hard to following. Feel free to clarify what you want to do, and why, and I’ll try my best to understand and then help.

Thanks,

– Dale

Thanks for example!

That’s exactly what i’m doing - ofc it is just esthetics but i presonally don’t like command prompt leaves line each run.

Look when RMB click happens it goes in a ‘chain’ ( at least i think so ) - OnMouseDown -> OnMouseUp

Whenever i put e.Cancel = true in OnMouseDown then OnMouseUp will never fire if i’ll delete e.Cancel = true from OnMouseDown then OnMouseUp is fired always.