Plot sometimes does not react to mouse input in windows forms

133 views Asked by At

I'm using an ILPlotcube with line- and point-plots inside a windows forms window. Somehow the mouse control of the PlotCube, like zooming and dragging does not work anymore. For example: i can't zoom into the plot by drawing a rectangle over the region i want to see. The mouse doesn't seem to be recognized anymore.

Basically the code looks like this:

public void init() {
    Thread backgroundThread = new Thread(
        new ThreadStart(() =>
        {
            makePlot();
        }));
    backgroundThread.Start();
}

makePlot() looks like this:

public void makePlot()
{
   ILPlotCube plotCube = _ilPanel.Scene.First<ILPlotCube>();

   if (plotCube == null) {

      plotCube = new ILPlotCube {
         new ILLinePlot(tosingle(_data1), "plot1", lineColor: Color.Blue),
         new ILLinePlot(tosingle(_data2), "plot2", lineColor: Color.Red),
         new ILLegend("data1","data2")
       };
       _ilPanel.Scene = new ILScene { plotCube };
   }
   else
   { 
      plotCube.First<ILLinePlot>(tag: "plot1").Line.Positions.Update(tosingle(_data1);
      plotCube.First<ILLinePlot>(tag: "plot2").Line.Positions.Update(tosingle(_data2);
   }

   _ilPanel.Scene.Configure();

   _ilPanel.Invoke((MethodInvoker)delegate { _ilPanel.Refresh(); });
}

I call init() in Form1_Load() not in ilPanel1_Load()

Actually there is an other thing. The Class Reference says ILLinePlot has a Method "Update" to update the positions of the plotted line. But Visual Studio tells me ILLinePlot doesn't have such a member Function. Instead i'm using

   linePlot.Line.Positions.Update  

Also if i don't call Configure() on the Scene Element it won't plot the legend but if i do, the whole Plotting takes much more time.

2

There are 2 answers

1
Haymo Kutschbach On

It is hard to guess without some code. But I suppose there are multiple plot cubes in your scene. And they probably use the same screen area (probably the whole panel area?). Mouse events will fire on the topmost camera object or one of its children, if configured that way. Possibly the plot cube lays "behind" some other camera object which catches all the events. You can find out by registering an event handler on the root node and print out all mouse down events:

ilPanel1.Scene.MouseDown += (_s, _e) => { Debug.WriteLine(_e.Target); };

This will give the node below the mouse which was selected as target for the mouse event during the mouse down action. In order for the (correct) plotcube to properly receive the mouse events for zoom / rotate/ pan operations there should be either the plotcube node (plotcube derives from ILCamera) or one of its children found as target.

Another easy way to inspect the scene and detect all camera nodes contained is to create a breakpoint at the very end of your setup method (mostly this will be ilPanel1_Load(..). Once you stopped in the debugger, execute the following code in the Immediate window:

ilPanel1.Scene.Find<ILCamera>()

Count = 2
[0]: "Camera: #2 - Polar r:10 φ:0° ρ:0° - Pos X:0 Y:0 Z:10 - Lookat X:0 Y:0 Z:0 - Top X:0 Y:1 Z:0"
[1]: "ILPlotCube #30 'PlotCube' Children:[2]"

How many plot cubes do you count?

0
Robert On

I got it to work after i switched

ilpanel.Scene = new ILScene { plotCube }

to

ilpanel.Scene.Add( plotCube )