LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mouse curson freezes when trying to drag a curson on xy graph

Solved!
Go to solution

I am trying to build a star simulation VI, which will create a main star at the position of the curson, and with a mouse down event, it will create another star at the position of mouse clicking on the graph. However, the curson is only movable if I hit run and drag the cursor immediately; otherwise when I try to drag it my mouse cursor will freeze as a cross shape.

 

I think the data flow is fine and I even put on a wait VI. Any suggestions?

 

0 Kudos
Message 1 of 7
(3,380 Views)
Solution
Accepted by topic author DeliaZhang

You have an event strucure that is outside the loop and thus can run only once. When the event (mouse down) occurs the second time, the front panel locks (the event is configured to lock the front panel until the event completes, but the event cannot complete because it is not reachable via dataflow)

 

Get rid of the event structure.

Message 2 of 7
(3,367 Views)
Solution
Accepted by topic author DeliaZhang

Here's a quick draft that should give you some ideas. You probably want to improve the user intereaction though. (e.g. grabbing the cursor is also a mouse down event of course)

 

(note that using complex arrays significantly simplifies the code)

 

 

Message 3 of 7
(3,358 Views)

At first I put the event structure and for loop inside the wire loop and everything worked fine. Then I dragged them out because I only want the event structure to be executed once -- so the position of the star 1 can be only set once. Is there any pattern that can do this? So far I only know producer/consumer structure.

0 Kudos
Message 4 of 7
(3,309 Views)

Thank you! I learned so much from your code. I never thought of simplifying my code before and I can't believe it could be done like this.

My heart said a thousand times " Bravo!"

0 Kudos
Message 5 of 7
(3,307 Views)
You could place a case structure inside the even an wire a "first call" primitive to the selector. Seems a bit limiting. Maybe you could make the mouse down work only if shift is pressed?
0 Kudos
Message 6 of 7
(3,291 Views)

From your original code, it seems you wanted to have more than two stars. In this case you should make the code scalable so you don't need to change much if the number of stars needs to be increased in the future. Here's a quick draft showing how to do that.

 

At the moment, the various stars are placed with a combination of ctrl and shift when clicking, but you could easily just use a numeric control that selects the stars to be placed at the click location. You should probably add more properties to the stars cluster so each has a mass, size, and color, position, etc.

 

Also note that we no longer need a timeout case. The graph is only updated when something has changed. You could use it later to e.g. simulate orbits.

 

Download All
0 Kudos
Message 7 of 7
(3,253 Views)