app_channelselector.C

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 #include <locale.h>
00029 #include <libintl.h>
00030 
00031 #include "gxsm_app.h"
00032 
00033 #include "unit.h"
00034 #include "pcs.h"
00035 #include "xsmtypes.h"
00036 #include "action_id.h"
00037 #include "glbvars.h"
00038 
00039 /* Channel Menu */
00040 
00041 static char* choice_ChView[] =
00042 { 
00043         "No",
00044     "Grey 2D",
00045     "Surface 3D",
00046     "Profile 1D",
00047     0
00048 };
00049 
00050 static char* choice_ChMode[] =
00051 { 
00052     "Off",
00053     "Active",
00054     "On",
00055     "Math",
00056     "X",
00057     0
00058 };
00059 
00060 static char* choice_ChSDir[] =
00061 { 
00062     "->",
00063     "<-",
00064     "2>",
00065     "<2",
00066     0
00067 };
00068 
00069 
00070 typedef union ChIndex {
00071   struct { char ch, x, y, z; } s;
00072   long   l;
00073 };
00074 
00075 ChannelSelector::ChannelSelector (int ChAnz){
00076   GtkWidget* chtab;
00077   GtkWidget* wid;
00078   GtkWidget* menu;
00079   GtkWidget* menuitem;
00080   char txt[32];
00081   ChIndex chi;
00082   int i,j,k,l;
00083 
00084   chi.l=0L;
00085 
00086   AppWidgetInit(CHANNELSELECTOR_TITLE);
00087 
00088   chtab = gtk_table_new (4, 1+ChAnz, FALSE);
00089   gtk_widget_show (chtab);
00090   gtk_container_add (GTK_CONTAINER (vbox), chtab);
00091 
00092   wid = gtk_label_new ("Ch.");
00093   gtk_widget_show (wid);
00094   gtk_table_attach (GTK_TABLE (chtab), wid, 0, 1, 0, 1,
00095                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00096                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00097                     FALSE, FALSE);
00098 
00099   wid = gtk_label_new ("View");
00100   gtk_widget_show (wid);
00101   gtk_table_attach (GTK_TABLE (chtab), wid, 1, 2, 0, 1,
00102                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00103                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00104                     FALSE, FALSE);
00105 
00106   wid = gtk_label_new ("Mode");
00107   gtk_widget_show (wid);
00108   gtk_table_attach (GTK_TABLE (chtab), wid, 2, 3, 0, 1,
00109                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00110                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00111                     FALSE, FALSE);
00112 
00113   wid = gtk_label_new ("Dir");
00114   gtk_widget_show (wid);
00115   gtk_table_attach (GTK_TABLE (chtab), wid, 3, 4, 0, 1,
00116                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00117                     (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00118                     FALSE, FALSE);
00119 
00120   ChSDirWidget = new GtkWidget*[ChAnz];
00121   ChModeWidget = new GtkWidget*[ChAnz];
00122   ChViewWidget = new GtkWidget*[ChAnz];
00123       
00124   for(i=1; i<=ChAnz; i++){
00125     sprintf(txt,"% 2d", i);
00126 
00127     wid = gtk_label_new (txt);
00128     gtk_widget_show (wid);
00129     gtk_object_set_data  (GTK_OBJECT (wid), "ChNo", (void*)(i));
00130     gapp->configure_drop_on_widget(wid);
00131 
00132     gtk_table_attach (GTK_TABLE (chtab), wid, 0, 1, i, i+1,
00133                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00134                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00135                       FALSE, FALSE);
00136 
00137     /* View */
00138     wid = gtk_option_menu_new ();
00139     ChViewWidget[i-1] = wid;
00140 
00141     gtk_widget_show (wid);
00142     gtk_object_set_data  (GTK_OBJECT (wid), "ChNo", (void*)(i));
00143     gapp->configure_drop_on_widget(wid);
00144 
00145     gtk_table_attach (GTK_TABLE (chtab), wid, 1, 2, i, i+1,
00146                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00147                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00148                       FALSE, FALSE);
00149     menu = gtk_menu_new ();
00150 
00151     // Add Channel View Modes
00152     for(j=0; choice_ChView[j]; j++){
00153       menuitem = gtk_menu_item_new_with_label (choice_ChView[j]);
00154       chi.s.ch = i-1;
00155       chi.s.x  = j;
00156       gtk_widget_show (menuitem);
00157       gtk_menu_append (GTK_MENU (menu), menuitem);
00158       /* connect with signal-handler if selected */
00159       gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
00160                           GTK_SIGNAL_FUNC (ChannelSelector::choice_ChView_callback),
00161                           (void*)chi.l);
00162     }
00163     gtk_option_menu_set_menu (GTK_OPTION_MENU (wid), menu);
00164     gtk_option_menu_set_history (GTK_OPTION_MENU (wid), 1);
00165 
00166 
00167     /* Mode */
00168     wid = gtk_option_menu_new ();
00169     ChModeWidget[i-1] = wid;
00170 
00171     gtk_widget_show (wid);
00172     gtk_object_set_data  (GTK_OBJECT (wid), "ChNo", (void*)(i));
00173     gapp->configure_drop_on_widget(wid);
00174 
00175     gtk_table_attach (GTK_TABLE (chtab), wid, 2, 3, i, i+1,
00176                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00177                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
00178                       FALSE, FALSE);
00179 
00180     menu = gtk_menu_new ();
00181     // Add Default Channel Modes
00182     for(j=0; choice_ChMode[j]; j++){
00183       menuitem = gtk_menu_item_new_with_label (choice_ChMode[j]);
00184       chi.s.ch = i-1;
00185       chi.s.x  = j;
00186       gtk_widget_show (menuitem);
00187       gtk_menu_append (GTK_MENU (menu), menuitem);
00188       gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
00189                          GTK_SIGNAL_FUNC (ChannelSelector::choice_ChMode_callback),
00190                          (void*)chi.l);
00191     }
00192     // Add PID Srcs
00193     for(l=ID_CH_M_LAST-1, k=0; k<PIDCHMAX; k++, j++){
00194       if(strcmp(xsmres.pidsrc[k], "-")){
00195         GString *txt = g_string_new(xsmres.pidsrc[k]);
00196         gchar **g2;
00197         chi.s.ch = i-1;
00198         chi.s.x  = l;
00199         g2=g_strsplit(txt->str,",",2);
00200         if(g2[1])
00201           xsmres.piddefault=l+1;
00202         menuitem = gtk_menu_item_new_with_label (g2[0]);
00203         g_string_free(txt, TRUE);
00204         g_strfreev(g2);
00205         xsmres.pidchno[k]=l+1;
00206         gtk_widget_show (menuitem);
00207         gtk_menu_append (GTK_MENU (menu), menuitem);
00208         gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
00209                            GTK_SIGNAL_FUNC (ChannelSelector::choice_ChMode_callback),
00210                            (void*)chi.l);
00211         ++l;
00212       }
00213       else
00214         xsmres.pidchno[k]=999;
00215     }
00216     // Add DAQChannels
00217     for(k=0; k<DAQCHMAX; k++, j++){
00218       if(strcmp(xsmres.daqsrc[k], "-")){
00219         GString *txt = g_string_new(xsmres.daqsrc[k]);
00220         gchar **g2;
00221         chi.s.ch = i-1;
00222         chi.s.x  = l;
00223         g2=g_strsplit(txt->str,",",2);
00224         if(g2[1])
00225           xsmres.daqdefault=l+1;
00226         menuitem = gtk_menu_item_new_with_label (g2[0]);
00227         xsmres.daqchno[k]=l+1;
00228         g_string_free(txt, TRUE);
00229         g_strfreev(g2);
00230         gtk_widget_show (menuitem);
00231         gtk_menu_append (GTK_MENU (menu), menuitem);
00232         gtk_signal_connect(GTK_OBJECT (menuitem), "activate",
00233                            GTK_SIGNAL_FUNC (ChannelSelector::choice_ChMode_callback),
00234                            (void*)chi.l);
00235         ++l;
00236       }
00237       else
00238         xsmres.daqchno[k]=999;
00239     }
00240     gtk_option_menu_set_menu (GTK_OPTION_MENU (wid), menu);
00241     gtk_option_menu_set_history (GTK_OPTION_MENU (wid), 0);
00242 
00243     /* Add Scan Directions */
00244     wid = gtk_option_menu_new ();
00245     ChViewWidget[i-1] = wid;
00246 
00247     gtk_widget_show (wid);
00248     gtk_object_set_data  (GTK_OBJECT (wid), "ChNo", (void*)(i));
00249     gapp->configure_drop_on_widget(wid);
00250 
00251     gtk_table_attach (GTK_TABLE (chtab), wid, 3, 4, i, i+1,
00252                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00253                       (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 
00254                       FALSE, FALSE);
00255     menu = gtk_menu_new ();
00256 
00257     for(int j=0; choice_ChSDir[j]; j++){
00258       menuitem = gtk_menu_item_new_with_label (choice_ChSDir[j]);
00259       chi.s.ch = i-1;
00260       chi.s.x  = j;
00261       gtk_widget_show (menuitem);
00262       gtk_menu_append (GTK_MENU (menu), menuitem);
00263       /* connect with signal-handler if selected */
00264       gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
00265                           GTK_SIGNAL_FUNC (ChannelSelector::choice_ChSDir_callback),
00266                           (void*)chi.l);
00267     }
00268     gtk_option_menu_set_menu (GTK_OPTION_MENU (wid), menu);
00269     gtk_option_menu_set_history (GTK_OPTION_MENU (wid), 0);
00270   }
00271 }
00272 
00273 void ChannelSelector::choice_ChSDir_callback (GtkWidget *widget, void *data){
00274   ChIndex chi;
00275   chi.l=(long)data;
00276   gapp->xsm->SetSDir(chi.s.ch, chi.s.x);
00277   return;
00278 }
00279 
00280 void ChannelSelector::choice_ChView_callback (GtkWidget *widget, void *data){
00281   ChIndex chi;
00282   chi.l=(long)data;
00283   gapp->xsm->SetView(chi.s.ch, chi.s.x);
00284   return;
00285 }
00286 
00287 void ChannelSelector::choice_ChMode_callback (GtkWidget *widget, void *data){
00288   ChIndex chi;
00289   chi.l=(long)data;
00290   gapp->xsm->SetMode(chi.s.ch, chi.s.x+1);
00291   return;
00292 }
00293 
00294 void ChannelSelector::SetSDir(int Channel, int SDir){
00295   gtk_option_menu_set_history (GTK_OPTION_MENU (ChSDirWidget[Channel]), SDir);
00296 }
00297 
00298 void ChannelSelector::SetMode(int Channel, int Mode){
00299   gtk_option_menu_set_history (GTK_OPTION_MENU (ChModeWidget[Channel]), Mode-1);
00300 }
00301 
00302 void ChannelSelector::SetView(int Channel, int View){
00303   gtk_option_menu_set_history (GTK_OPTION_MENU (ChViewWidget[Channel]), View);
00304 }

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