gxsm_main.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 #include <new>
00027 #include <cstring>
00028 
00029 #include <locale.h>
00030 #include <libintl.h>
00031 
00032 #include <config.h>
00033 #include <libgnome/libgnome.h>
00034 #include <libgnome/gnome-init.h>
00035 
00036 #include <gtk/gtkgl.h>
00037 
00038 #include "gxsm_app.h"
00039 #include "gxsm_resoucetable.h"
00040 #include "action_id.h"
00041 
00042 /* do not change this line manually! CVS is updateing this automatically! */
00043 char xxsmmaincvsrev[]="$Header: /cvsroot/gxsm/Gxsm-2.0/src/gxsm_main.C,v 1.21 2005/04/23 15:36:26 zahl Exp $";
00044 char *cvsmainrev=NULL, *cvsmaindate=NULL;
00045 
00046 
00047 XSMRESOURCES xsmres;
00048 
00049 App *gapp = NULL;
00050 int restarted = 0;
00051 int debug_level = 0;
00052 int pi_debug_level = 0;
00053 int force_gconf_defaults = 0;
00054 
00055 /* True if parsing determined that all the work is already done.  */
00056 int just_exit = 0;
00057 
00058 /* Popt Options -- define Cmd Options here */
00059 static const struct poptOption options[] = {
00060         { "Hardware-Card", 'h', POPT_ARG_STRING, &xsmres.HardwareTypeCmd, 0,
00061           N_("Hardware Card: no | ... (depends on available HwI plugins)"), N_("default")},
00062         { "User-Unit", 'u', POPT_ARG_STRING, &xsmres.UnitCmd, 0,
00063           N_("XYZ Unit: AA | nm | um | mm | BZ | sec | V | 1 "), N_("default")},
00064         { "disable-plugins", '\0', POPT_ARG_NONE, &xsmres.disableplugins, 0,
00065           N_("Disable default plugin loading on startup"), 0},
00066         { "force-configure", '\0', POPT_ARG_NONE, &xsmres.force_config, 0,
00067           N_("Force to reconfigure Gxsm on startup"), 0},
00068         { "force-rebuild-gconf-defaults", '\0', POPT_ARG_NONE, &force_gconf_defaults, 0,
00069           N_("Forces to restore all GXSM gconf defaults on startup"), 0},
00070         { "debug-level", '\0', POPT_ARG_INT, &debug_level, 0,
00071           N_("Set Gxsm debug level. 0: no debug output on console, 1: normal, 2: more verbose, ...5 increased verbosity"), 0},
00072         { "pi-debug-level", '\0', POPT_ARG_INT, &pi_debug_level, 0,
00073           N_("Set Gxsm-PlugIn debug level. 0: no debug output on console, 1: normal, 2: more verbose, ...5 increased verbosity"), 0},
00074         {NULL, '\0', 0, NULL, 0} // end the list
00075 };
00076 
00077 
00078 int main(int argc, char *argv[])
00079 {
00080 #ifdef G_THREADS_ENABLED 
00081         // init glib thread support
00082         XSM_DEBUG(DBG_L1, "glib thread init.");
00083         g_thread_init (NULL);
00084         gdk_threads_init ();                   // Called to initialize internal mutex "gdk_threads_mutex".
00085         gdk_threads_enter ();                  // protect GTK/GDK calls from now!
00086 #else
00087         XSM_DEBUG(DBG_L1, "sorry, no glib thread support, needed for scanning.");
00088 #endif
00089 
00090 #ifdef ENABLE_NLS
00091         XSM_DEBUG(DBG_L1, "NLS is enabled.");
00092         /* Initialize the i18n stuff */
00093         bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
00094         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
00095         textdomain(GETTEXT_PACKAGE);
00096 #endif
00097 
00098         XSM_DEBUG(DBG_L1, "Gnome program init");
00099         GnomeProgram *my_app = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, 
00100                                                    GNOME_PARAM_POPT_TABLE, options, 
00101                                                    GNOME_PARAM_NONE);
00102 
00103         gtk_gl_init (&argc, &argv);
00104 
00105         std::cout << "GXSM-DebugLevel/PI-DebugLevel/ForceGDefaults: " 
00106                   << debug_level << "/" 
00107                   << pi_debug_level << "/" 
00108                   << force_gconf_defaults 
00109                   << std::endl;
00110 
00111         XSM_DEBUG(DBG_L1, "Setup dynamic preferences");
00112         gxsm_init_dynamic_res ();
00113 
00114         XSM_DEBUG(DBG_L1, "GXSM run druids check");
00115         // Check for new user, present druids
00116         gxsm_check_new_user_config ();
00117 
00118         // no GxsmApplication right now, set NULL.
00119         gapp = NULL;
00120         
00121         XSM_DEBUG(DBG_L1, "GXSM CVS versioning");
00122         // Fingure out CVS Version and Date of xsm_main.C
00123         char *cvsv;
00124         cvsv=strchr(xxsmmaincvsrev,',')+2; *cvsv='V'; cvsmaindate=strchr(cvsv,' ')+1; *strchr(cvsv,' ')=0; 
00125         if((cvsv-xxsmmaincvsrev) > 10){ cvsv -= 8; strcpy(cvsv,"Version "); cvsv[8]=' '; }
00126         cvsmainrev=cvsv;
00127         *strchr(strchr(strchr(cvsmaindate,' ')+1,' ')+1,' ')=0;
00128         XSM_DEBUG(DBG_L1, "GXSM init, CVS " << cvsmainrev << ", date: " << cvsmaindate);
00129         XSM_DEBUG(DBG_L1, "GXSM / PlugIn debug level is: " << debug_level << " / " << pi_debug_level);
00130 
00131         XSM_DEBUG(DBG_L1, "GXSM: create application");
00132         // Now create GxsmApplication (gapp):
00133         // this starts at App::App() and fires up the applicationīs initialisiation
00134         gapp = new App (restarted); 
00135 
00136         XSM_DEBUG(DBG_L1, "GXSM: build GUI");
00137         gapp->build_gxsm ();
00138         
00139         // reparse all args, i.e. load scans, if not loadable, ignore:
00140         // do not know how to skip already by popt parsed args?!?!? FixMe!!!
00141 
00142         XSM_DEBUG(DBG_L2, "GXSM: parsing all arguments...");
00143         if (++argv){
00144                         int re_use=0;
00145                         for (; *argv; argv++) {
00146                                         XSM_DEBUG(DBG_L2, "Attempt to load/import <" << *argv << ">");
00147                                         if (re_use)
00148                                                         re_use = gapp->xsm->load(*argv);
00149                                         else
00150                                                         if(!gapp->xsm->ActivateFreeChannel())
00151                                                                         // if no success, reuse this active scan next!
00152                                                                         re_use = gapp->xsm->load(*argv);
00153                         }
00154                         if (re_use)
00155                                         gapp->xsm->SetMode(-1, ID_CH_M_OFF, TRUE); // kill unused scan
00156         }
00157         XSM_DEBUG(DBG_L2, "All files processed.");
00158         XSM_DEBUG(DBG_L2, "Entering gtk_main loop.");
00159 
00160         gtk_main();  // enter Gtk message loop
00161 
00162         gdk_flush ();
00163         gdk_threads_leave ();
00164         
00165         XSM_DEBUG(DBG_L2, "GXSM is exiting now.");
00166 
00167         // gtk_main_quit() was called to exit.
00168         // now cleanup GxsmApplication (gapp): done by App::~App()
00169         delete gapp;
00170         gdk_flush ();
00171 
00172 //      gdk_threads_leave ();
00173 
00174         gapp = NULL;
00175         my_app = NULL;
00176 
00177         XSM_DEBUG(DBG_L2, "by.");
00178 
00179         gtk_exit (0);
00180         return 0;
00181 }
00182 

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