Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

SfClass.h

00001 //
00002 // SfClass.h
00003 //
00004 // Basic Saphira class definitions
00005 
00006 //
00007 // Copyright 2000 by Kurt Konolige
00008 //
00009 // The author hereby grants to SRI permission to use this software.
00010 // The author also grants to SRI permission to distribute this software
00011 // to schools for non-commercial educational use only.
00012 //
00013 // The author hereby grants to other individuals or organizations
00014 // permission to use this software for non-commercial
00015 // educational use only.  This software may not be distributed to others
00016 // except by SRI, under the conditions above.
00017 //
00018 // Other than these cases, no part of this software may be used or
00019 // distributed without written permission of the author.
00020 //
00021 // Neither the author nor SRI make any representations about the 
00022 // suitability of this software for any purpose.  It is provided 
00023 // "as is" without express or implied warranty.
00024 //
00025 // Kurt Konolige
00026 // Senior Computer Scientist
00027 // SRI International
00028 // 333 Ravenswood Avenue
00029 // Menlo Park, CA 94025
00030 // E-mail:  konolige@ai.sri.com
00031 
00032 #ifndef SFCLASSES_H
00033 #define SFCLASSES_H
00034 
00035 #include <list>
00036 #include <map>
00037 
00038 
00039 //
00040 // enumerated lists
00041 //
00042 
00043 class SfList
00044 {
00045  public:
00046   SfList(int mxx, void **pp)
00047     { n = 0; p = pp; mx = mxx; };
00048   ~SfList() {};
00049   void reset()
00050     { n = 0; };
00051   void add(void *p);
00052   void addBeginning(void *p);
00053   void addUnique(void *p);
00054   int  remove(void *p);
00055   void **getObjs() 
00056     { return p; };
00057   int  getNum()
00058     { return n; };
00059 
00060  protected:
00061   int n;
00062   int mx;
00063   void **p;
00064 };
00065 
00066 
00067 
00068 // abstract drawable class, for mixing in
00069 // inheritance from this class means you can draw yourself
00070 
00071 class SfWin;                    // forward ref
00072 
00076 class SfDrawable
00077 {
00078 public:
00079   SfDrawable()                  // by default we draw
00080      { visible = true; }
00081   virtual void draw(SfWin *) {};
00083   bool visible;                 // should we draw?
00085   int color;                    // what color we are
00086 };
00087 
00088 
00089 
00090 
00091 #define MAXKEYFNS 10
00092 #define MAXBUTTONFNS 10
00093 
00094 
00099 class SfWin
00100 {
00101 public:
00102   SfWin();              // sets up key and button handler lists
00103   virtual ~SfWin() {};
00104   enum {
00105     FIRST, 
00106     LAST,  
00107     REMOVE 
00108   };
00110   virtual void Vector(double, double, double, double) {}; 
00112   virtual void Vector(double, double, double, double, ArPose *) {}; 
00114   virtual void Rectangle(double, double, double, double) {}; 
00115   // draws a rectangle relative to a pose; use NULL for the robot
00116   virtual void Rectangle(double, double, double, double, ArPose *) {}; 
00118   virtual void CRectangle(double, double, double, double) {}; 
00120   virtual void CRectangle(double, double, double, double, ArPose *) {}; 
00122   virtual void Point(double, double) {}; 
00124   virtual void Point(double, double, ArPose *) {}; 
00126   virtual void Polygon(int, double *, double *) {} 
00128   virtual void Circle(double x, double y, double r) {}; 
00130   virtual void Circle(double x, double y, double r, ArPose *) {}; 
00132   virtual void Text(char *str, double x, double y) {}; 
00134   virtual void Text(char *str, double x, double y, ArPose *) {}; 
00135   virtual void Add(SfDrawable *) {}; // adds a drawable to the display list
00136   virtual void Scale(double) {}; // scale in mm/pixel
00137   virtual void Resize(int, int) {}; // in pixels
00138   virtual void Center(double, double) {}; // center window here in rw coords
00141   virtual void PenColor(int) {}; 
00142   virtual void Transform(ArPose *) {}; // sets the transform for window display, go away
00143   virtual void Rotate(double) {}; // sets the rotation, in deg
00145   virtual void Coords(double *x, double *y, int i, int j) {}; 
00146 
00147 
00149   void AddKeyHandler(int (*fn)(int, int, SfWin *), int which = FIRST); 
00151   void AddButtonHandler(int (*fn)(int, int, int, int, SfWin *), int which = FIRST); 
00152 
00153  private:
00154   void **key_fn_buf[MAXKEYFNS];
00155   void **button_fn_buf[MAXBUTTONFNS];
00156 
00157  protected:
00158   SfList keyFnList;
00159   SfList buttonFnList;
00160 };
00161 
00162 // definitions of some graphics constants
00163 
00164 #include "FL/Enumerations.H"
00165 
00167 #define sfLeftButton   FL_BUTTON1
00168 
00169 #define sfMiddleButton FL_BUTTON2
00170 
00171 #define sfRightButton  FL_BUTTON3 
00172 
00173 #define sfShiftMask    FL_SHIFT
00174 #define sfControlMask  FL_CTRL
00175 #define sfAltMask      FL_ALT
00176 #define sfMetaMask     FL_META
00177 
00178 
00179 
00180 // Abstract frame class
00181 // Purpose of this class is to make frames available without
00182 //   specifying any implementation
00183 // E.g., could use FLTK, or a null implementation for no drawing
00184 
00185 class SfSensorDevice;
00186 class SfRangeDevice;
00187 
00188 class SfFr
00189 {
00190 public:
00191   virtual ~SfFr() {};
00192   virtual void AddSensor(SfSensorDevice *sd) {}; // adds this device to display list
00193   virtual void addRangeDevice(SfRangeDevice *) {}; // adds this device to display list
00194   static SfFr *Current(); // returns default frame
00195   static void Current(SfFr *f); // sets default frame
00196 protected:
00197   static SfFr *_current; // pointer to current default
00198 };
00199 
00201 #define SfFRAME SfFr::Current()
00202 
00203 
00204 
00205 
00206 //
00207 // Geometry definitions
00208 //
00209 
00211 class SfVector                  // represents a vector or rectangle in 2D
00212 {                               // dims in mm
00213 public:
00214   double x1, y1, x2, y2;
00216   SfVector()
00217     { x1 = y1 = x2 = y2 = 0; }
00219   SfVector(double xx1, double yy1, double xx2, double yy2)
00220     { x1 = xx1; y1 = yy1; x2 = xx2; y2 = yy2; }
00221       
00222 };
00223 
00224 
00225 
00227 class SfTime
00228 {
00229 public:
00231   SfTime();
00233   void Reset(); // sets to zero
00235   int TimeMS(); 
00237   int TimeUS(); 
00238 private:
00239   int time;                     // microsecond time
00240 };
00241 
00242 
00243 //
00244 // Activity interpreter uTask class
00245 // One instance is used as a schema
00246 // Other instances are running activities
00247 // Only used internally for the activity interpreter
00248 //
00249 
00250 class SfActTask
00251 {
00252 public:
00253   SfActTask(char *iname, int pri = 50, bool schema = false);
00254   ~SfActTask();
00255 
00256   void process();               // what we do
00257 
00258   SfActTask *dad;               // parent, NULL if none
00259   int timeout;                  // if we have a time limit
00260   int time;                     // time since we started
00261 
00262   interpact *ia;                // activity schema or instance
00263   void *actionNew;              // creates a new action
00264   ArAction *action;             // current action instance
00265   int nargs;                    // number of arguments
00266   int type;                     // sfACTIVITY or sfACTION
00267   int priority;                 // priority for sfACTION only
00268 
00269   bool trace;                   // are we tracing?
00270   int tracepc;                  // last pc traced
00271   int disp;                     // are we displaying?
00272   char *name;                   // name of activity
00273   char *schemaName;             // name of schema
00274   beh_params params;            // parameters of activity
00275   int processState;             // state of the process
00276 
00277 protected:
00278   ArFunctorC<SfActTask> myActCB;
00279 };
00280 
00281 
00283 void sfSuspendTask(SfActTask *p, int time);
00284 void sfFailTask(SfActTask *p);
00285 void sfSucceedTask(SfActTask *p);
00286 void sfInterruptTask(SfActTask *p);
00287 void sfResumeTask(SfActTask *p);
00288 void sfRemoveTask(SfActTask *p);
00289 
00291 bool sfTaskFinished(SfActTask *act);
00292 bool sfTaskFinished(char *iname);
00293 bool sfTaskSuspended(SfActTask *act);
00294 bool sfTaskSuspended(char *iname);
00295 extern "C" {
00296 int sfStartTask(char *schema, char *iname, int timeout, int priority, 
00297                          int suspend, ...);
00298 }
00299 
00300 //
00301 // Activity schema registration
00302 //
00303 
00304 class SfActRegister
00305 {
00306   friend class Sf;
00307 
00308  public:
00309   static void add(SfActTask *); // add an activity as a schema
00310   static void add(char *name, interpact *ia); // make a new activity schema
00311   static void add(char *name, int nargs, beh_params pp, void *fn); // make a new action schema
00312   static void remove(SfActTask *);  // remove an activity
00313   static void remove(char *name); // remove by name
00314   static SfActTask *find(char *name); // find schema by name
00315   static SfActTask *getAct(char *iname); // get currently running task by name
00316   static SfActTask *getAct(SfActTask *schema, char *iname); // make new instance of schema
00317   static SfActTask *removeAct(char *iname);// removes it from the activities list
00318   static void       removeAct(SfActTask *act); // removes it from the activities list
00319   static SfActTask *currentTask; // current executing activity, NULL if none
00320   static std::list<SfActTask *> *getActList() { return activities; };
00321 
00322  protected:
00323   static std::list<SfActTask *> *schemas;
00324   static std::list<SfActTask *> *activities;
00325 };
00326 
00327 
00328 
00329 #endif // SFCLASSES_H
00330 

Generated on Tue Nov 12 17:49:33 2002 for Saphira by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001