casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ProgressMeter.h
Go to the documentation of this file.
00001 //# ProgressMeter.h: Visual indication of a tasks progress.
00002 //# Copyright (C) 1997,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: ProgressMeter.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00028 
00029 #ifndef CASA_PROGRESSMETER_H
00030 #define CASA_PROGRESSMETER_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <time.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class String;
00040 
00041 // <summary>
00042 // Visual indication of a tasks progress.
00043 // </summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00048 // </reviewed>
00049 
00050 // <synopsis>
00051 // This class is used to provide a visual indication to the user of the progress
00052 // of his task. If the process is not connected to the DO system, calls to the
00053 // progress meter are NO-OP's, so you can safely use this class in general
00054 // library code and it won't cause problems for processes which are not
00055 // attached to the distributed object system. It also won't cause any extra
00056 // stuff to be linked in to your executable in this case.
00057 //
00058 // The progress meter will usually be removed from the screen once the maximum
00059 // value is set, so you should not reuse the ProgressMeter after that has
00060 // happened. It is harmless, but it will not result in any visual feedback for
00061 // the user.
00062 //
00063 // While the "min" is usually less than "max", if in fact it is greater than
00064 // "max" the progress meter will count down correctly.
00065 // </synopsis>
00066 //
00067 // <example>
00068 // <srcblock>
00069 // void calculate(uInt n) {
00070 //   Int skip = n / 200;
00071 //   ProgressMeter meter(0, n, "Title", "Subtitle", "", "", True, skip);
00072 //   for (uInt i=0; i<n; i++) {
00073 //       ... calculate ...
00074 //       meter.update(i);
00075 //   }
00076 // }
00077 // </srcblock>
00078 // </example>
00079 //
00080 // <motivation>
00081 // Give the user visual indication of a long-running tasks progress.
00082 // </motivation>
00083 //
00084 // <todo asof="1997/03/03">
00085 //   <li> When the upper bound isn't known, it might be useful to have a busy
00086 //        bar that just moves back and forth to show that activity is happening.
00087 //   <li> We should probably have some way to suppress progress bars for tasks
00088 //        that are only going to take a few seconds.
00089 // </todo>
00090 
00091 class ProgressMeter
00092 {
00093 public:
00094     // Makes a null progress meter, i.e. no updates to the screen are
00095     // generated.
00096     ProgressMeter();
00097 
00098     // Create a progress meter with the given min and max values and labels.
00099     // if <src>estimateTime</src> is <src>True</src>, an estimate of the
00100     // time remaining will be made for the user. This estimate assumes that
00101     // the remaining portion will compute at the same rate as the portion
00102     // completed so far, so the time should not be estimated for processes
00103     // which are non-linear.
00104     //
00105     // Any labels which are set to the empty string will have sensible defaults
00106     // supplied. In particular, <src>minlabel</src> and <src>maxlabel</src>
00107     // will be set to the display the minimum and maximum values.
00108     //
00109     // Normally the progress bar will be updated with every call to
00110     // <src>update()</src>. If however you will be sending many events
00111     // then you might want to update the GUI every <src>updateEvery</src>'th
00112     // event for efficiency. Generally there's no point updating more than
00113     // a couple of hundred times since the eye can't distinguish differences
00114     // in the progress bar position at that level. If updateEvery is <=0, it
00115     // is set to 1 for you.
00116     ProgressMeter(Double min, Double max, 
00117                   const String &title, const String &subtitle,
00118                   const String &minlabel, const String &maxlabel,
00119                   Bool estimateTime = True, Int updateEvery=1);
00120 
00121     ProgressMeter(Double min, Double max, const String &title);
00122     // The destruction of the meter will cause an update to be sent with the
00123     // maximum value. This will usually cause the GUI window to be removed
00124     // from the screen. Thus the progress meter should generally live as long
00125     // as the calculation it is tracking.
00126     ~ProgressMeter();
00127 
00128     void update(Double value, Bool force=False);
00129     void _update(Double value, Bool force=False);
00130     void busy();
00131     void done();
00132 
00133     // Display the min and max values of the progress meter.
00134     // <group>
00135     Double min() const;
00136     Double max() const;
00137     // </group>
00138 
00139     friend class ObjectController;
00140     static const char* PROGRESSFILE;
00141 private:
00142     Int id_p;
00143     Double min_p, max_p;
00144     Int update_every_p, update_count_p;
00145        // Time the progress meter began
00146     time_t startTime; 
00147     Bool   showProgress;
00148     
00149     // These are set by ObjectController for executables that have the tasking
00150     // system in them, otherwise they are null and this class just does no-ops.
00151     static Int (*creation_function_p)(Double, Double, 
00152                               const String &, const String &,
00153                               const String &, const String &,
00154                               Bool);
00155     static void (*update_function_p)(Int, Double);
00156     static void (*show_function_p)(Int, Double);
00157     static void (*busy_function_p)(Int);
00158     static void (*done_function_p)(Int);
00159 
00160     // Undefined and inaccessible
00161     ProgressMeter(const ProgressMeter &);
00162     ProgressMeter &operator=(const ProgressMeter &);
00163 };
00164 
00165 
00166 } //# NAMESPACE CASA - END
00167 
00168 #endif
00169 
00170