pcs.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 __PCS_H
00029 #define __PCS_H
00030 
00031 #include <fstream>
00032 
00033 #include <gnome.h>
00034 
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <math.h>
00038 #include <string.h>
00039 
00040 #include "gxsm_conf.h"
00041 #include "unit.h"
00042 
00043 #ifndef MLD_WERT_NICHT_OK
00044 #define MLD_WERT_NICHT_OK        "Value out of Range !"
00045 #define MLD_VALID_RANGE          "Valid Range: "
00046 #endif
00047 
00048 extern GtkTooltips *remote_pcs_tips;
00049 
00050 class Param_Control;
00051 
00052 // Objekt für Parameter Ein/Ausgabeüberwachung und Formatierung
00053 class Param_Control{
00054  public:
00055         Param_Control(UnitObj *U, char *W, double *V, double VMi, double VMa, char *p);
00056         Param_Control(UnitObj *U, char *W, unsigned long *V, double VMi, double VMa, char *p);
00057         Param_Control(UnitObj *U, char *W, int *V, double VMi, double VMa, char *p);
00058         Param_Control(UnitObj *U, char *W, short *V, double VMi, double VMa, char *p);
00059         virtual ~Param_Control();
00060 
00061         void Init(){
00062                 set_exclude ();
00063                 ChangeNoticeFkt = NULL;
00064                 FktData = NULL;
00065                 refname=NULL;
00066                 info=NULL;
00067         };
00068         void setMax(double VMa, double Vmax_warn =  1e111);
00069         void setMin(double VMi, double Vmin_warn = -1e111);
00070         void set_exclude(double V_ex_lo = 1e111, double V_ex_hi = 1e111);
00071         void set_info (gchar* Info);
00072         virtual void update_limits() {};
00073         void changeUnit(UnitObj *U){ unit = U; };
00074         void changeUnit_hold_usr_value(UnitObj *U){ 
00075                 double valusr = unit->Base2Usr(Get_dValue());
00076                 unit = U;
00077                 Set_FromUsrValue(valusr);
00078         };
00079         void Val(double *V);
00080         void Val(unsigned long *V);
00081         void Val(short *V);
00082         void Val(int *V);
00083         void Prec(char *p);
00084         void Get_UsrString(char *txt);
00085         gchar *Get_UsrString();
00086         double Get_dValue();
00087         void Set_FromValue(double nVal);
00088         void Set_FromUsrValue(double nVal){ Set_FromValue(unit->Usr2Base(nVal)); };
00089         double Convert2Base (double x) { return unit->Usr2Base(x); };
00090         double Convert2Usr (double x) { return unit->Base2Usr(x); };
00091 
00092         virtual gint ShowMessage(char *txt, char *options=NULL, gint default_choice=0);
00093         virtual void Put_Value();
00094         virtual void Set_Parameter(double value=0., int flg=FALSE, int usr2base=FALSE);
00095         virtual gpointer GetEntryData(const gchar *txtid){ return NULL; };
00096 
00097         virtual void Set_ChangeNoticeFkt(void (*NewChangeNoticeFkt)(Param_Control* pcs, gpointer data), gpointer data){
00098                 ChangeNoticeFkt = NewChangeNoticeFkt;
00099                 FktData = data;
00100         }
00101 
00102  protected:
00103         UnitObj *unit;
00104         gchar *warning;
00105         void (*ChangeNoticeFkt)(Param_Control* pcs, gpointer data);
00106         gpointer FktData;
00107         double vMin, vMax;
00108         double vMin_warn, vMax_warn;
00109         double v_ex_lo, v_ex_hi;
00110         gchar *refname;
00111         gchar *prec;
00112         gchar *info;
00113 
00114  private:
00115         double *Dval;
00116         unsigned long *ULval;
00117         int    *Ival;
00118         short  *Sval;
00119 };
00120 
00121 class Gtk_EntryControl : public Param_Control{
00122  public:
00123         Gtk_EntryControl(UnitObj *U, char *W, double *V, double VMi, double VMa, char *p, GtkWidget *w,
00124                          double AdjStep=0., double AdjPage=0., double AdjProg=0.):
00125                 Param_Control(U, W, V, VMi, VMa, p){
00126                 entry=w;
00127                 InitRegisterCb(AdjStep, AdjPage, AdjProg);
00128         };
00129         Gtk_EntryControl(UnitObj *U, char *W, unsigned long *V, double VMi, double VMa, char *p, GtkWidget *w,
00130                          double AdjStep=0., double AdjPage=0., double AdjProg=0.):
00131                 Param_Control(U, W, V, VMi, VMa, p){
00132                 entry=w;
00133                 InitRegisterCb(AdjStep, AdjPage, AdjProg);
00134         };
00135         Gtk_EntryControl(UnitObj *U, char *W, int *V, double VMi, double VMa, char *p, GtkWidget *w,
00136                          double AdjStep=0., double AdjPage=0., double AdjProg=0.):
00137                 Param_Control(U, W, V, VMi, VMa, p){
00138                 entry=w;
00139                 InitRegisterCb(AdjStep, AdjPage, AdjProg);
00140         };
00141         Gtk_EntryControl(UnitObj *U, char *W, short *V, double VMi, double VMa, char *p, GtkWidget *w,
00142                          double AdjStep=0., double AdjPage=0., double AdjProg=0.):
00143                 Param_Control(U, W, V, VMi, VMa, p){
00144                 entry=w;
00145                 InitRegisterCb(AdjStep, AdjPage, AdjProg);
00146         };
00147         virtual ~Gtk_EntryControl(){
00148                 //    gtk_signal_handlers_destroy( GTK_OBJECT( entry ) );
00149                 adjustment_callback (NULL, NULL); // cleanup static timer if allocated
00150         };
00151 
00152         static gint update_callback(GtkEditable *editable, void *data){
00153                 ((Gtk_EntryControl *)gtk_object_get_data( GTK_OBJECT (editable), "Gtk_EntryControl"))->Set_Parameter();
00154                 return FALSE;
00155         };
00156 
00157         void pcs_adjustment_configure ();
00158         void get_pcs_configuartion ();
00159         void put_pcs_configuartion ();
00160 
00161         static void adjustment_callback (GtkAdjustment *adj, Gtk_EntryControl *gpcs);
00162 
00163         virtual gint ShowMessage(char *txt, char *options=NULL, gint default_choice=0);
00164 
00165         GtkObject *GetAdjustment(){ return adj; };
00166 
00167         void Show(gint flg){ 
00168                 if(flg){ gtk_widget_show(entry); enable_client=TRUE; }
00169                 else{ enable_client=FALSE; gtk_widget_hide(entry); }
00170         };
00171         void Thaw(){ 
00172                 gtk_entry_set_editable(GTK_ENTRY(entry), TRUE); 
00173                 gtk_widget_set_sensitive (entry, TRUE);
00174         };
00175         void Freeze(){ 
00176                 gtk_widget_set_sensitive (entry, FALSE);
00177                 gtk_entry_set_editable(GTK_ENTRY(entry), FALSE); 
00178         };
00179         virtual gpointer GetEntryData(const gchar *txtid){ 
00180                 return gtk_object_get_data( GTK_OBJECT (entry), txtid);
00181         };
00182 
00183         GSList *AddEntry2RemoteList(gchar *RefName, GSList *remotelist);
00184         void disable_remote_pcs_tips (){ gtk_tooltips_disable (remote_pcs_tips); };
00185         void enable_remote_pcs_tips (){ gtk_tooltips_enable (remote_pcs_tips); };
00186 
00187         int CheckRemoteCmd(gchar **arglist){
00188                 if(refname && arglist[1] && arglist[2])
00189                         if(! strcmp(arglist[1], refname)){
00190                                 Set_Parameter(atof(arglist[2]), TRUE, TRUE);
00191                                 return TRUE;
00192                         }
00193                 return FALSE;
00194         };
00195 
00196         virtual void Put_Value(){
00197                 char txt[64];
00198                 Get_UsrString(txt);
00199                 gtk_entry_set_text (GTK_ENTRY (entry), txt);
00200                 if(adj)
00201                         gtk_adjustment_set_value(GTK_ADJUSTMENT(adj), unit->Usr2Base(atof(txt)));
00202         };
00203         virtual void Set_Parameter(double Value=0., int flg=FALSE, int usr2base=FALSE){
00204                 GtkWidget *c;
00205                 double value;
00206                 if(flg){
00207                         if(usr2base)
00208                                 value=unit->Usr2Base(Value);
00209                         else
00210                                 value=Value;
00211                 }
00212                 else{
00213                         const gchar *ctxt = gtk_entry_get_text (GTK_ENTRY (entry));
00214                         if(!strcmp(ctxt, "19710403") ||
00215                            !strcmp(ctxt, "3.4.1971")){
00216                                 ShowMessage ("Wieso? -- Geht doch!");
00217                                 Put_Value();
00218                                 return;
00219                         }
00220                         if(!strcmp(ctxt, "180960") ||
00221                            !strcmp(ctxt, "2091964")){
00222                                 ShowMessage ("Hallo Meister!");
00223                                 Put_Value();
00224                                 return;
00225                         }
00226                         value=unit->Usr2Base(atof(ctxt));
00227                         if(adj)
00228                                 gtk_adjustment_set_value(GTK_ADJUSTMENT(adj), value);
00229                 }
00230                 Set_FromValue(value);
00231                 // check for interconnections
00232                 if((c=(GtkWidget*)gtk_object_get_data( GTK_OBJECT (entry), "HasClient")) && enable_client)
00233                         ((Gtk_EntryControl *)gtk_object_get_data( GTK_OBJECT (c), "Gtk_EntryControl"))->Set_FromValue(value);
00234                 if(ChangeNoticeFkt)
00235                         (*ChangeNoticeFkt)(this, FktData);
00236         };
00237 
00238  private:
00239         void InitRegisterCb(double AdjStep, double AdjPage, double AdjProg);
00240 
00241         GtkWidget *entry;
00242         GtkObject *adj;
00243         gint enable_client;
00244 
00245         double page10, page, step, progressive;
00246         gint show_adj:1;
00247         gint show_scale:1;
00248         gint show_extra:1;
00249 
00250 };
00251 
00252 
00253 #endif
00254 
00255 
00256 
00257 

Generated on Sat Apr 1 09:04:02 2006 for GXSM by  doxygen 1.4.6