Update a plot in LibPlotters

Engineering & Scientific library: http://zinnamturm.eu/downloadsIN.htm#Lib

Re: Update a plot in LibPlotters

Postby Robert » Mon Oct 05, 2015 4:57 pm

manumart1 wrote:The module LibPlotters (subsystem Lib from http://www.zinnamturm.eu/downloadsIN.htm#Lib) does not have Plotter.UpdateNow.
I modified module LibPlotters as you showed, but got an error:
So RestoreGraphic is missing. I changed it to Restore and compiled ok.
It now works ok, i.e. each line is drawn separately and immediately, instead of all at the same time when the program finished.

Yes, what I posted was suggestions, not finished code. If it works ok the way to clean it up is to observe that msg.graphicOnly is always FALSE, so you can remove the "IF msg.graphicOnly THEN" clauses, and even remove the graphicOnly fields entirely.

But... if the delay is too long, after 6 seconds the cursor becomes busy and the screen freezes

I often observe this problem. I think it is a general BlackBox problem with any long running Command, and not related to LibPlotters. I don't find it a time issue (6 seconds), but is caused when you do anything on the computer; move the mouse, hit the keyboard, top another programme ....
When the Command finishes the screen is then redrawn with the correct final result; it is only the intermediate results that can't be seen.

I also find that Chris's magic ProcessMessages can be very helpful - it can also be dangerous.

Regards
User avatar
Robert
 
Posts: 128
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Update a plot in LibPlotters

Postby Ivan Denisov » Mon Oct 05, 2015 9:03 pm

I recommend you never to use:
Code: Select all
WinApi.Sleep(2000);

Better use Services.Action!
User avatar
Ivan Denisov
 
Posts: 255
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Update a plot in LibPlotters

Postby Ivan Denisov » Mon Oct 05, 2015 9:39 pm

Please look at this example. It updates plotters 5 times without WinApi (and without UpdateNow).

Code: Select all
MODULE Test;

   IMPORT  Log, Plotters := LibPlotters, Vec := LibVectors, Ports, Services, Models;

   TYPE
      Animation = POINTER TO RECORD (Services.Action)
         j: INTEGER;
         p: Plotters.Plotter;
      END;

   PROCEDURE (a: Animation) Do ();
   VAR data: Vec.Vector; i: INTEGER; msg: Models.UpdateMsg;
   BEGIN
      Log.String("Iteration : "); Log.Int(a.j); Log.Ln();
      data := Vec.New(512);
      FOR i := 0 TO LEN(data) - 1 DO data[i] := a.j END;
      a.p.DrawVector(data, 0, 1, 0, 1, 0, Ports.blue);
      Models.Broadcast(a.p, msg);
      INC(a.j);
      IF a.j <= 5 THEN
         Services.DoLater(a, Services.Ticks() + Services.resolution);
      ELSE
         Services.RemoveAction(a)
      END
   END Do;

   PROCEDURE Run3* ();
    VAR
         p: Plotters.Plotter;
         a: Animation;
   BEGIN
      p  :=  Plotters.dir.NewPlotter ('Line plots');
      p.SetMargin (10, 5, 3, 3);
      p.Scale (0, 50, 0, 10);
      Plotters.OpenAux(p, 0, 0, TRUE, 'Test plot update');
      NEW(a);
      a.j := 1;
      a.p := p;
      Services.DoLater(a, Services.now);
   END Run3;

END Test.
User avatar
Ivan Denisov
 
Posts: 255
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Update a plot in LibPlotters

Postby Robert » Tue Oct 06, 2015 8:04 am

Ivan Denisov wrote:Better use Services.Action!
It updates plotters 5 times without WinApi (and without UpdateNow).

And it solves the freezing display problem!

But restructuring the code to use Actions is not always very convenient (maybe you want the update inside 2 nested loops, or inside some recursive structure). So sometimes it can be tempting not to use Actions.
User avatar
Robert
 
Posts: 128
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Update a plot in LibPlotters

Postby manumart1 » Tue Oct 06, 2015 6:24 pm

The program from Ivan works really well. The window can even be moved with the mouse while the program is running.

But the call to Services.RemoveAction(a) intrigues me. Is it necessary? I thought that the Action a was being consumed during the execution of Do.
Code: Select all
   PROCEDURE (a: Animation) Do ();
   ...
      IF a.j <= 5 THEN
         Services.DoLater(a, Services.Ticks() + Services.resolution);
      ELSE
         Services.RemoveAction(a)
      END
   END Do;
manumart1
 
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am

Re: Update a plot in LibPlotters

Postby Ivan Denisov » Wed Oct 07, 2015 2:14 am

Services.RemoveAction(a) is not necessary in this case. I think, that it can speed up garbage collection, removing pointer to this action from the Services module. However maybe it does not. Nothing bad will happen if you will call Services.RemoveAction(a), when you do not need the action.
User avatar
Ivan Denisov
 
Posts: 255
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Previous

Return to Lib

Who is online

Users browsing this forum: No registered users and 1 guest