app_vobj.h

Go to the documentation of this file.
00001 /* Gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Copyright (C) 1999,2000,2001,2002,2003 Percy Zahl
00006  *
00007  * Authors: Percy Zahl <zahl@users.sf.net>
00008  * additional features: Andreas Klust <klust@users.sf.net>
00009  * WWW Home: http://gxsm.sf.net
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00024  */
00025 
00026 /* -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 8 c-style: "K&R" -*- */
00027 
00028 #ifndef APP_VOBJ_H
00029 #define APP_VOBJ_H
00030 
00031 #include <config.h>
00032 #include <libgnome/libgnome.h>
00033 
00034 #include <gdk/gdk.h>
00035 
00036 #include "xsmtypes.h"
00037 #include "gapp_service.h"
00038 #include "scan.h"
00039 
00040 #include "gxsm_app.h"
00041 #include "app_vinfo.h"
00042 
00043 class ProfileControl;
00044 
00045 typedef enum VOBJ_COORD_MODE { VOBJ_COORD_FROM_MOUSE, VOBJ_COORD_ABSOLUT, VOBJ_COORD_RELATIV };
00046 
00047 class VObject{
00048  public:
00049         VObject(GtkWidget *canvas, double *xy0, int npkt, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00050         virtual ~VObject();
00051 
00052         static gint item_event(GnomeCanvasItem *item, GdkEvent *event, VObject *vo);
00053 
00054         virtual void Update()=0;
00055         virtual void SetUpPos(VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE);
00056         virtual void SetUpScan();
00057         virtual void set_offset();
00058         virtual void properties();
00059         virtual void GoLocMax(int r=10);
00060         virtual void follow_on(){};
00061         virtual void follow_off(){};
00062         virtual int follow(){ return FALSE; };
00063         virtual void AddNode(){};
00064         virtual void DelNode(){};
00065         virtual void show_label(int flg = -1);
00066 
00067         GnomeCanvasItem* node_marker(GnomeCanvasItem* item, double *xy, int i);
00068 
00069         void Activate ();
00070         void lock_object (int l) { lock = l? 1:0; };
00071 
00072         void set_color_to_active (); // "blue"
00073         void set_color_to_inactive (); // "red"
00074         void set_color_to_hilit ();
00075 
00076         void set_marker_scale (double ms) { marker_scale=ms; };
00077         void set_label_offset (double *xy) { label_offset_xy[0]=xy[0]; label_offset_xy[1]=xy[1]; };
00078         
00079         // holds ScanEvent, non if NULL
00080         void set_scan_event (ScanEvent *se) { scan_event = se; };
00081         ScanEvent *get_scan_event () { return scan_event; };
00082 
00083         int GetRn(double *xyi, int n){ 
00084                 if(n<np && n>=0){
00085                         xyi[0] = xy[n<<1]; xyi[1] = xy[(n<<1)+1]; 
00086                         return FALSE;
00087                 }
00088                 else return TRUE;
00089         };
00090 
00091         double Dist(int i=0, int j=1){
00092                 double dx=xy[2*j  ]-xy[2*i  ];
00093                 double dy=xy[2*j+1]-xy[2*i+1];
00094                 return sqrt(dx*dx+dy*dy);
00095         }
00096 
00097         double Area(int i=0, int j=1){
00098                 double dx=xy[2*j  ]-xy[2*i  ];
00099                 double dy=xy[2*j+1]-xy[2*i+1];
00100                 return fabs(dx*dy);
00101         }
00102 
00103         double Phi(double dx, double dy){
00104                 double q23=0.;
00105                 if(dx<0.)
00106                         q23=180.;
00107                 if(fabs(dx)>1e-5)
00108                         return q23+180.*atan(dy/dx)/M_PI;
00109                 else return dy>0.?90.:-90.;
00110         }
00111 
00112         double Phi(int i=0, int j=1){
00113                 double dx=xy[2*j  ]-xy[2*i  ];
00114                 double dy=xy[2*j+1]-xy[2*i+1];
00115                 return Phi(dx, dy);
00116         }
00117 
00118         void save(std::ofstream &o){
00119                 o << "(VObject \"" << name << "\"" << std::endl
00120                   << "   (Label \"" << text << "\")" << std::endl
00121                   << "   (NPkte " << np << ")" << std::endl
00122                   << "   (Coords i X Y (XAng YAng)" << std::endl;
00123                 for(int i=0; i<np; ++i) {
00124                         double x,y;
00125                         x=xy[2*i]; y=xy[2*i+1];
00126                         o << "     (" << i << " " << x << " " << y;
00127                         vinfo->W2Angstroem (x,y);
00128                         o << " (" << x << " " << y << "))" << std::endl;
00129                 }
00130                 o << "))" << std::endl 
00131                   << std::endl;
00132         };
00133 
00134         void saveHPGL(std::ofstream &o){
00135                 double x,y;
00136                 int i;
00137                 for(i=0; i<np; ++i){
00138                         x=xy[2*i]; y=xy[2*i+1];
00139                         vinfo->W2Angstroem (x,y);
00140                         if(i == 0) 
00141                                 o << "PU " << x << "," << y << ";" << std::endl;
00142                         else
00143                                 o << "PD " << x << "," << y << ";" << std::endl;
00144                 }
00145                 if(i == 1) 
00146                         o << "PD " << x << "," << y << ";" << std::endl;
00147         };
00148         int obj_id (int newid=0) { if (newid) id = newid; return id; };
00149         gchar *obj_name () { return name; };
00150         gchar *obj_text ( const gchar *t=NULL ) { 
00151                 if (t) { 
00152                         if (text) g_free (text);
00153                         text = g_strdup (t);
00154                         return NULL; 
00155                 } else return text; 
00156         };
00157         int obj_num_points () { return np; };
00158         void obj_get_xy_i (int i, double &x, double &y) { 
00159                 if (i>=0) { // default (i=0...np) is Angstroems -- conveniance hack
00160                         if (i<np){ 
00161                                 x=xy[2*i]; y=xy[2*i+1]; 
00162                                 vinfo->W2Angstroem (x,y);
00163                         }
00164                 } else { // but -1, ... -np-1 is in pixels!
00165                         i = -i-1;
00166                         if (i<np){ 
00167                                 x=xy[2*i] * vinfo->GetQfac (); 
00168                                 y=xy[2*i+1] * vinfo->GetQfac (); 
00169                         }
00170                 } 
00171         };
00172 
00173         GtkWidget *canvas;
00174 
00175  protected:
00176         ProfileControl *profile;
00177         gchar *name;
00178         gchar *text;
00179 
00180         int np;
00181         double marker_scale;
00182         double label_offset_xy[2];
00183         double *xy;
00184         Point2D  *p2d;
00185         GnomeCanvasItem **abl;
00186         GnomeCanvasItem *label;
00187         GnomeCanvasItem *arrow_head;
00188         GtkWidget *popup;
00189         GtkWidget *statusbar;
00190         gint statusid;
00191         ViewInfo *vinfo;
00192 
00193         GnomeCanvasItem *touched_item;
00194         double touched_xy[2];
00195 
00196         ScanEvent *scan_event;
00197 
00198  private:
00199         int id;
00200         int lock;
00201 };
00202 
00203 
00204 class VObPoint : public VObject{
00205  public:
00206         VObPoint(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00207         virtual ~VObPoint();
00208         
00209         virtual void Update();
00210         virtual void follow_on();
00211         virtual void follow_off();
00212         virtual int follow_me(){ return follow; };
00213 
00214  private:
00215         void update_offset();
00216         int follow;
00217 };
00218 
00219 class VObLine : public VObject{
00220  public:
00221         VObLine(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00222         virtual ~VObLine();
00223 
00224         virtual void Update();
00225 
00226  private:
00227 };
00228 
00229 class VObPolyLine : public VObject{
00230  public:
00231         VObPolyLine(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00232         virtual ~VObPolyLine();
00233         virtual void AddNode();
00234         virtual void DelNode();
00235 
00236         virtual void Update();
00237 };
00238 
00239 class VObTrace : public VObject{
00240  public:
00241         VObTrace(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00242         virtual ~VObTrace();
00243         virtual void Change(double *xy0);
00244 
00245         virtual void Update();
00246         private:
00247         int trlen;
00248         GnomeCanvasPoints *pn;
00249 };
00250 
00251 class VObKsys : public VObject{
00252  public:
00253         VObKsys(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00254         virtual ~VObKsys();
00255 
00256         virtual void Update();
00257 
00258  private:
00259         void calc_grid();
00260         void update_grid();
00261         double *xygrid;
00262         GnomeCanvasPoints *pngrid; 
00263 };
00264 
00265 class VObParabel : public VObject{
00266  public:
00267         VObParabel(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00268         virtual ~VObParabel();
00269 
00270         virtual void Update();
00271 
00272  private:
00273 };
00274 
00275 class VObRectangle : public VObject{
00276  public:
00277         VObRectangle(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00278         virtual ~VObRectangle();
00279         virtual void Update();
00280 
00281 };
00282 
00283 class VObCircle : public VObject{
00284  public:
00285         VObCircle(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double Marker_scale=1.);
00286         virtual ~VObCircle();
00287 
00288         double Radius(){
00289                 return Dist();
00290         }
00291 
00292         virtual void Update();
00293 
00294         void Calc(){
00295                 double dx=fabs(xy[2]-xy[0]);
00296                 double dy=fabs(xy[3]-xy[1]);
00297                 double r=sqrt(dx*dx+dy*dy);
00298                 xyrec[0] = xy[0]-r;
00299                 xyrec[1] = xy[1]-r;
00300                 xyrec[2] = xy[0]+r;
00301                 xyrec[3] = xy[1]+r;
00302         };
00303 
00304         double xyrec[4];
00305 
00306 };
00307 
00308 class VObEvent : public VObject{
00309  public:
00310         VObEvent(GtkWidget *canvas, double *xy0, Point2D *P2d, int pflg=FALSE, VOBJ_COORD_MODE cmode=VOBJ_COORD_FROM_MOUSE, gchar *lab=NULL, double marker_scale=0.4);
00311         virtual ~VObEvent();
00312         
00313         virtual void Update();
00314 
00315  private:
00316 };
00317 
00318 #endif

Generated on Sat Apr 1 09:03:51 2006 for GXSM by  doxygen 1.4.6