NanoPlott.C

Go to the documentation of this file.
00001 /* Gnome gxsm - Gnome X Scanning Microscopy
00002  * universal STM/AFM/SARLS/SPALEED/... controlling and
00003  * data analysis software
00004  * 
00005  * Gxsm Plugin Name: NanoPlott.C
00006  * ========================================
00007  * 
00008  * Copyright (C) 1999 The Free Software Foundation
00009  *
00010  * Authors: Percy Zahl <zahl@fkp.uni-hannover.de>
00011  * additional features: Andreas Klust <klust@fkp.uni-hannover.de>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00026  */
00027 
00028 /* Please do not change the Begin/End lines of this comment section!
00029  * this is a LaTeX style section used for auto generation of the PlugIn Manual 
00030  * Chapter. Add a complete PlugIn documentation inbetween the Begin/End marks!
00031  * All "% PlugInXXX" commentary tags are mandatory
00032  * All "% OptPlugInXXX" tags are optional
00033  * --------------------------------------------------------------------------------
00034 % BeginPlugInDocuSection
00035 % PlugInDocuCaption: Nano HPLG plotter
00036 % PlugInName: NanoPlott
00037 % PlugInAuthor: Percy Zahl
00038 % PlugInAuthorEmail: zahl@users.sf.net
00039 % PlugInMenuPath: Windows/Nano Plotter
00040 
00041 % PlugInDescription
00042 This is a tool to use your tip for writing or manipulating by moving
00043 the tip (i.e. the scan-piezo) along an arbitrary programmable
00044 path. There are two DSP-parameter sets for bias, feedback and scan
00045 settings which can be used for to assign two ''writing'' modes called
00046 PU (pen up) and PD (pen down). The path is read from a plotter-file in
00047 a very simple HPGL-plotter language style. This file can be
00048 created by hand (editor) or from line or polyline object(s) drawn in a
00049 scan.
00050 
00051 \GxsmScreenShot{NanoPlott}{The Nano-Plott window.}
00052 
00053 % PlugInUsage
00054 Set desired parameters for Pen Up and Pen Down, put in the path/file
00055 to your plottfile (.plt) and press start\dots You can translate and
00056 scale you plot data using the parameters Offset and Scale. Make sure
00057 the plot file name is correct in can be found from current working
00058 directory or use an absolute path.
00059 
00060 % OptPlugInObjects
00061 Poly line objects are used for display only -- not for input of path!
00062 
00063 % OptPlugInDest
00064 The plotted path is shown on the active scan using poly line objects.
00065 
00066 %% OptPlugInConfig
00067 %
00068 
00069 % OptPlugInFiles
00070 Create a simple HPGL plott file for input. You can do this with Gxsm
00071 itself: place a bunch of PolyLine objects and use \GxsmPopup{Grey
00072 2D}{File/Save Objects} to create a HPGL file, enter therefore a file
00073 with a \filename{.plt} extension! Use this as input for the
00074 NanoPlotter.
00075 
00076 % OptPlugInKnownBugs
00077 Not 100\% tested, beta state.
00078 
00079 % OptPlugInNotes
00080 The PCI32-DSP vector scan generator is only able to move in horizontal,
00081 vertical or diagonal direction. This limitation dose not apply to the SRanger DSP code.
00082 
00083 % OptPlugInHints
00084 Use \GxsmEmph{hp2xx} for preview of your HPGL files, available for debian!
00085 
00086 Example file to draw a line from 0$\:$\AA, 0$\:$\AA to 0$\:$\AA, 5000$\:$\AA:\\
00087 \ \\
00088 PU 0.0,0.0;\\
00089 PD 0.0,5000.0;\\
00090                                                                               
00091 
00092 
00093 % OptPlugInSubSection: Disclaimer
00094 This tool may ruin your tip and sample, so take care!
00095 
00096 % EndPlugInDocuSection
00097  * -------------------------------------------------------------------------------- 
00098  */
00099 
00100 #include <gtk/gtk.h>
00101 #include "config.h"
00102 #include "gxsm/plugin.h"
00103 
00104 #include "gxsm/unit.h"
00105 #include "gxsm/pcs.h"
00106 #include "gxsm/app_remote.h"
00107 #include "gxsm/xsmtypes.h"
00108 #include "gxsm/glbvars.h"
00109 
00110 #include "include/dsp-pci32/xsm/xsmcmd.h"
00111 
00112 
00113 static void NanoPlott_about( void );
00114 static void NanoPlott_query( void );
00115 static void NanoPlott_cleanup( void );
00116 
00117 static void NanoPlott_show_callback( GtkWidget*, void* );
00118 static void NanoPlott_StartScan_callback( gpointer );
00119 
00120 GxsmPlugin NanoPlott_pi = {
00121   NULL,
00122   NULL,
00123   0,
00124   NULL,
00125   "NanoPlott",
00126   "+ALL +SRanger:SPMHARD +SRangerTest:SPMHARD +Innovative_DSP:SPMHARD +Innovative_DSP:SPAHARD",
00127 //  "-LAN_RHK:SPMHARD", //"+spmHARD +STM +AFM",
00128   NULL,
00129   "Percy Zahl",
00130   N_("_Windows/"),
00131   N_("Nano Plotter"),
00132   N_("open the Nano Plotter Control"),
00133   "Nano Plotter Control",
00134   NULL,
00135   NULL,
00136   NULL,
00137   NanoPlott_query,
00138   NanoPlott_about,
00139   NULL,
00140   NULL,
00141   NanoPlott_cleanup
00142 };
00143 
00144 static const char *about_text = N_("Gxsm NanoPlotter Plugin:\n"
00145                                    "This plugin runs a control window to "
00146                                    "do simple HPGL 'Nano Plotting'.\n\n"
00147                                    "Supported Commands are PU (PenUp) and PD (PenDown)\n"
00148                                    "to given coordinates X,Y.\n"
00149                                    "Syntax PenUp movement:   'PU X,Z;'\n"
00150                                    "Syntax PenDown movement: 'PD X,Z;'\n\n"
00151                                    "Example Plot File of a 'square plott':\n"
00152                                    "PU 0,0;\n"
00153                                    "PD 100,0;\n"
00154                                    "PD 100,100;\n"
00155                                    "PD 0,100;\n"
00156                                    "PD 0,0;\n"
00157         );
00158 
00159 
00160 typedef struct{
00161         double bias;
00162         double current;
00163         double setpoint;
00164         double cp, ci;
00165         double speed;
00166 } DSP_Remote;
00167 
00168 
00169 
00170 GxsmPlugin *get_gxsm_plugin_info ( void ){ 
00171   NanoPlott_pi.description = g_strdup_printf(N_("Gxsm NanoPlott plugin %s"), VERSION);
00172   return &NanoPlott_pi; 
00173 }
00174 
00175 class NanoPlottControl : public AppBase{
00176 public:
00177         NanoPlottControl();
00178         virtual ~NanoPlottControl();
00179         
00180         void update();
00181         void savestate();
00182         static void ExecCmd(int cmd);
00183         static void RunPlott(GtkWidget *widget, NanoPlottControl *npc);
00184         static void StopPlott(GtkWidget *widget, NanoPlottControl *npc);
00185         
00186         void SetNewParam(DSP_Remote *dsp);
00187         void Transform(double &x, double &y);
00188         void GoToPosition(double x, double y);
00189 
00190 private:
00191         gchar *PlotFile;
00192         double Xorg, Yorg, XScale, YScale;
00193         int    repeat, count;
00194         UnitObj *Unity, *Volt, *Current, *Force, *Speed;
00195         DSP_Remote dsp_move;
00196         DSP_Remote dsp_plot;
00197 };
00198 
00199 NanoPlottControl *NanoPlottClass = NULL;
00200 
00201 static void NanoPlott_query(void)
00202 {
00203   static GnomeUIInfo menuinfo[] = { 
00204     { GNOME_APP_UI_ITEM, 
00205       NanoPlott_pi.menuentry, NanoPlott_pi.help,
00206       (gpointer) NanoPlott_show_callback, NULL,
00207       NULL, GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_BLANK, 
00208       0, GDK_CONTROL_MASK, NULL },
00209 
00210     GNOMEUIINFO_END
00211   };
00212 
00213   gnome_app_insert_menus
00214     ( GNOME_APP(NanoPlott_pi.app->getApp()), 
00215       NanoPlott_pi.menupath, menuinfo );
00216 
00217   // new ...
00218   NanoPlottClass = new NanoPlottControl;
00219 
00220   NanoPlottClass->SetResName ("WindowNanoPlottControl", "false", xsmres.geomsave);
00221 
00222   NanoPlott_pi.app->ConnectPluginToStartScanEvent
00223     ( NanoPlott_StartScan_callback );
00224 
00225   NanoPlott_pi.status = g_strconcat(N_("Plugin query has attached "),
00226                                      NanoPlott_pi.name, 
00227                                      N_(": NanoPlott is created."),
00228                                      NULL);
00229 }
00230 
00231 static void NanoPlott_about(void)
00232 {
00233   const gchar *authors[] = { "Percy Zahl", NULL};
00234   gtk_widget_show(gnome_about_new ( NanoPlott_pi.name,
00235                                     VERSION,
00236                                     N_("(C) 2001 the Free Software Foundation"),
00237                                     about_text,
00238                                     authors,
00239                                     NULL, NULL, NULL
00240                                     ));
00241 }
00242 
00243 static void NanoPlott_cleanup( void ){
00244   PI_DEBUG (DBG_L2, "NanoPlott Plugin Cleanup" );
00245   gchar *mp = g_strconcat(NanoPlott_pi.menupath, NanoPlott_pi.menuentry, NULL);
00246   gnome_app_remove_menus (GNOME_APP( NanoPlott_pi.app->getApp() ), mp, 1);
00247   g_free(mp);
00248 
00249   // delete ...
00250   if( NanoPlottClass )
00251     delete NanoPlottClass ;
00252 
00253   g_free( NanoPlott_pi.status );
00254 }
00255 
00256 static void NanoPlott_show_callback( GtkWidget* widget, void* data){
00257   if( NanoPlottClass )
00258     NanoPlottClass->show();
00259 }
00260 
00261 static void NanoPlott_StartScan_callback( gpointer ){
00262   NanoPlottClass->update();
00263 }
00264 
00265 
00266 NanoPlottControl::NanoPlottControl ()
00267 {
00268   GtkWidget *box, *hbox;
00269   GtkWidget *frame_param;
00270   GtkWidget *vbox_param, *hbox_param;
00271   GtkWidget *input, *rep_input;
00272 
00273   GSList *EC_list=NULL;
00274   GSList **RemoteEntryList = new GSList *;
00275   *RemoteEntryList = NULL;
00276 
00277   Gtk_EntryControl *ec;
00278 
00279 #define UTF8_DEGREE    "\302\260"
00280 #define UTF8_MU        "\302\265"
00281 #define UTF8_ANGSTROEM "\303\205"
00282 
00283   Unity    = new UnitObj(" "," ");
00284   Volt     = new UnitObj("V","V");
00285   Current  = new UnitObj("nA","nA");
00286   Force    = new UnitObj("nN","nN");
00287   Speed    = new UnitObj(UTF8_ANGSTROEM"/s","A/s");
00288 
00289 
00290   XsmRescourceManager xrm("PluginNanoPlottControl");
00291   xrm.Get("NanoPlott.Xorg", &Xorg, "0.");
00292   xrm.Get("NanoPlott.Yorg", &Yorg, "0.");
00293   xrm.Get("NanoPlott.XScale", &XScale, "1.");
00294   xrm.Get("NanoPlott.YScale", &YScale, "1.");
00295   xrm.Get("NanoPlott.Repeat", &repeat, "1");
00296 
00297   // ** User Params
00298   xrm.Get("NanoPlott.move_bias", &dsp_move.bias, "2.");
00299   xrm.Get("NanoPlott.move_current", &dsp_move.current, "1.");
00300   xrm.Get("NanoPlott.move_setpoint", &dsp_move.setpoint, "1.");
00301   xrm.Get("NanoPlott.move_cp", &dsp_move.cp, "0.1");
00302   xrm.Get("NanoPlott.move_ci", &dsp_move.ci, "0.1");
00303   xrm.Get("NanoPlott.move_speed", &dsp_move.speed, "100.");
00304 
00305   xrm.Get("NanoPlott.plot_bias", &dsp_plot.bias, "2.");
00306   xrm.Get("NanoPlott.plot_current", &dsp_plot.current, "1.");
00307   xrm.Get("NanoPlott.plot_setpoint", &dsp_plot.setpoint, "1.");
00308   xrm.Get("NanoPlott.plot_cp", &dsp_plot.cp, "0.1");
00309   xrm.Get("NanoPlott.plot_ci", &dsp_plot.ci, "0.1");
00310   xrm.Get("NanoPlott.plot_speed", &dsp_plot.speed, "100.");
00311 
00312   xrm.Get("NanoPlott.PlotFile", &PlotFile, "myplottfile");
00313 
00314   count = -1;
00315 
00316   AppWidgetInit("Nano Plott");
00317 
00318   box = gtk_vbox_new (FALSE, 0);
00319   gtk_widget_show (box);
00320   gtk_box_pack_start (GTK_BOX (vbox), box, TRUE, TRUE, 0);
00321 
00322   hbox = gtk_hbox_new (FALSE, 0);
00323   gtk_widget_show (hbox);
00324   gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
00325 
00326   // ========================================
00327 #define MYGTK_INPUT(L)  mygtk_create_input(L, vbox_param, hbox_param, 50, 70);
00328 
00329   frame_param = gtk_frame_new (N_("Settings for Move: PU X,Y;"));
00330   gtk_widget_show (frame_param);
00331   gtk_container_add (GTK_CONTAINER (hbox), frame_param);
00332 
00333   vbox_param = gtk_vbox_new (FALSE, 0);
00334   gtk_widget_show (vbox_param);
00335   gtk_container_add (GTK_CONTAINER (frame_param), vbox_param);
00336 
00337   input = MYGTK_INPUT("U");
00338   ec = new Gtk_EntryControl (Volt, MLD_WERT_NICHT_OK, &dsp_move.bias, -10., 10., "5g", input);
00339   EC_list = g_slist_prepend( EC_list, ec);
00340 
00341   if (IS_AFM_CTRL){ // AFM (linear)
00342           input = MYGTK_INPUT("SP");
00343           ec = new Gtk_EntryControl (Force, MLD_WERT_NICHT_OK, &dsp_move.setpoint, -10000., 10000., "5g", input);
00344           EC_list = g_slist_prepend( EC_list, ec);
00345   } else {
00346           input = MYGTK_INPUT("I");
00347           ec = new Gtk_EntryControl (Current, MLD_WERT_NICHT_OK, &dsp_move.current, 0.001, 50., "5g", input);
00348           EC_list = g_slist_prepend( EC_list, ec);
00349   }
00350 
00351   input = MYGTK_INPUT("CP");
00352   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &dsp_move.cp, -10., 10., "5g", input);
00353   EC_list = g_slist_prepend( EC_list, ec);
00354 
00355   input = MYGTK_INPUT("CI");
00356   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &dsp_move.ci, -10., 10., "5g", input);
00357   EC_list = g_slist_prepend( EC_list, ec);
00358 
00359   input = MYGTK_INPUT("Speed");
00360   ec = new Gtk_EntryControl (Speed, MLD_WERT_NICHT_OK, &dsp_move.speed, 1., 100000., "4.0f", input);
00361   EC_list = g_slist_prepend( EC_list, ec);
00362 
00363   // ========================================
00364   frame_param = gtk_frame_new (N_("Settings for Plot: PD X,Y;"));
00365   gtk_widget_show (frame_param);
00366   gtk_container_add (GTK_CONTAINER (hbox), frame_param);
00367 
00368   vbox_param = gtk_vbox_new (FALSE, 0);
00369   gtk_widget_show (vbox_param);
00370   gtk_container_add (GTK_CONTAINER (frame_param), vbox_param);
00371 
00372   input = MYGTK_INPUT("U");
00373   ec = new Gtk_EntryControl (Volt, MLD_WERT_NICHT_OK, &dsp_plot.bias, -10., 10., "5g", input);
00374   EC_list = g_slist_prepend( EC_list, ec);
00375 
00376   if (IS_AFM_CTRL){ // AFM (linear)
00377           input = MYGTK_INPUT("SP");
00378           ec = new Gtk_EntryControl (Force, MLD_WERT_NICHT_OK, &dsp_plot.setpoint, -10000., 10000., "5g", input);
00379           EC_list = g_slist_prepend( EC_list, ec);
00380   } else {
00381           input = MYGTK_INPUT("I");
00382           ec = new Gtk_EntryControl (Current, MLD_WERT_NICHT_OK, &dsp_plot.current, 0.001, 50., "5g", input);
00383           EC_list = g_slist_prepend( EC_list, ec);
00384   }
00385 
00386   input = MYGTK_INPUT("CP");
00387   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &dsp_plot.cp, -10., 10., "5g", input);
00388   EC_list = g_slist_prepend( EC_list, ec);
00389 
00390   input = MYGTK_INPUT("CI");
00391   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &dsp_plot.ci, -10., 10., "5g", input);
00392   EC_list = g_slist_prepend( EC_list, ec);
00393 
00394   input = MYGTK_INPUT("Speed");
00395   ec = new Gtk_EntryControl (Speed, MLD_WERT_NICHT_OK, &dsp_plot.speed, 1., 100000., "4.0f", input);
00396   EC_list = g_slist_prepend( EC_list, ec);
00397 
00398 
00399   // ========================================
00400   frame_param = gtk_frame_new (N_("Nano Plot Settings"));
00401   gtk_widget_show (frame_param);
00402   gtk_container_add (GTK_CONTAINER (vbox), frame_param);
00403 
00404   vbox_param = gtk_vbox_new (FALSE, 0);
00405   gtk_widget_show (vbox_param);
00406   gtk_container_add (GTK_CONTAINER (frame_param), vbox_param);
00407 
00408 
00409 // Plott Offset, Scale
00410   input = mygtk_create_input("Offset XY", vbox_param, hbox_param);
00411   ec = new Gtk_EntryControl 
00412           (NanoPlott_pi.app->xsm->X_Unit, MLD_WERT_NICHT_OK, &Xorg,
00413            NanoPlott_pi.app->xsm->XOffsetMin(), NanoPlott_pi.app->xsm->XOffsetMax(), 
00414            NanoPlott_pi.app->xsm->AktUnit->prec1, input);
00415   EC_list = g_slist_prepend( EC_list, ec);
00416 
00417   input = mygtk_add_input(hbox_param);
00418   ec = new Gtk_EntryControl 
00419           (NanoPlott_pi.app->xsm->Y_Unit, MLD_WERT_NICHT_OK, &Yorg,
00420            NanoPlott_pi.app->xsm->YOffsetMin(), NanoPlott_pi.app->xsm->YOffsetMax(), 
00421            NanoPlott_pi.app->xsm->AktUnit->prec1, input);
00422   EC_list = g_slist_prepend( EC_list, ec);
00423         
00424   input = mygtk_create_input("Scale XY", vbox_param, hbox_param);
00425   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &XScale, -1e8, 1e8, "5g", input);
00426   EC_list = g_slist_prepend( EC_list, ec);
00427   input = mygtk_add_input(hbox_param);
00428   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &YScale, -1e8, 1e8, "5g", input);
00429   EC_list = g_slist_prepend( EC_list, ec);
00430 
00431   input = mygtk_create_input("Repeat #", vbox_param, hbox_param);
00432   ec = new Gtk_EntryControl (Unity, MLD_WERT_NICHT_OK, &repeat, 1, 99999, "5.0f", input);
00433   EC_list = g_slist_prepend( EC_list, ec);
00434   rep_input = input;
00435 
00436 // PlotFile
00437 //  input = mygtk_create_input("PlotFile", vbox_param, hbox_param);
00438 //  gtk_object_set_data( GTK_OBJECT (vbox), "PlotFileEntry", input);
00439 //  gtk_entry_set_text ( GTK_ENTRY (input), PlotFile);
00440 
00441   hbox_param = gtk_hbox_new (FALSE, 0);
00442   gtk_widget_show (hbox_param);
00443   gtk_box_pack_start (GTK_BOX (vbox_param), hbox_param, TRUE, TRUE, 0);
00444   input = gnome_file_entry_new( NULL, "Choose a plot-file (.plt)");
00445   gtk_object_set_data( GTK_OBJECT (vbox), "PlotFileEntry", input);
00446   gnome_file_entry_set_default_path( GNOME_FILE_ENTRY ( input ), PlotFile);
00447   gnome_file_entry_set_filename (GNOME_FILE_ENTRY (input), PlotFile);
00448   gtk_box_pack_start (GTK_BOX (hbox_param), input, TRUE, TRUE, 0);
00449   gtk_widget_show(input);
00450 
00451 
00452   hbox_param = gtk_hbox_new (FALSE, 0);
00453   gtk_widget_show (hbox_param);
00454   gtk_box_pack_start (GTK_BOX (vbox_param), hbox_param, TRUE, TRUE, 0);
00455 
00456 // Run Button
00457   GtkWidget *button = gtk_button_new_with_label("Start Plot");
00458   gtk_widget_show (button);
00459   gtk_box_pack_start (GTK_BOX (hbox_param), button, TRUE, TRUE, 0);
00460   gtk_object_set_data( GTK_OBJECT (button), "PlotFileEntry", input);
00461   gtk_object_set_data( GTK_OBJECT (button), "RepeatEntry", rep_input);
00462   gtk_signal_connect ( GTK_OBJECT (button), "pressed",
00463                        GTK_SIGNAL_FUNC (NanoPlottControl::RunPlott),
00464                        this);
00465 
00466   button = gtk_button_new_with_label("Stop");
00467   gtk_widget_show (button);
00468   gtk_box_pack_start (GTK_BOX (hbox_param), button, TRUE, TRUE, 0);
00469   gtk_object_set_data( GTK_OBJECT (button), "PlotFileEntry", input);
00470   gtk_signal_connect ( GTK_OBJECT (button), "pressed",
00471                        GTK_SIGNAL_FUNC (NanoPlottControl::StopPlott),
00472                        this);
00473 // CmdList
00474 
00475   // save List away...
00476   gtk_object_set_data( GTK_OBJECT (widget), "NANOPLOTT_EC_list", EC_list);
00477 
00478 }
00479 
00480 NanoPlottControl::~NanoPlottControl (){
00481 
00482         savestate ();
00483 
00484         delete Unity;
00485         delete Volt;
00486         delete Current;
00487         delete Force;
00488         delete Speed;
00489 }
00490 
00491 
00492 void NanoPlottControl::savestate (){
00493         XsmRescourceManager xrm("PluginNanoPlottControl");
00494         xrm.Put("NanoPlott.Xorg", Xorg);
00495         xrm.Put("NanoPlott.Yorg", Yorg);
00496         xrm.Put("NanoPlott.XScale", XScale);
00497         xrm.Put("NanoPlott.YScale", YScale);
00498         xrm.Put("NanoPlott.Repeat", repeat);
00499 
00500         // ** User Params
00501         xrm.Put("NanoPlott.move_bias", dsp_move.bias);
00502         xrm.Put("NanoPlott.move_current", dsp_move.current);
00503         xrm.Put("NanoPlott.move_setpoint", dsp_move.setpoint);
00504         xrm.Put("NanoPlott.move_cp", dsp_move.cp);
00505         xrm.Put("NanoPlott.move_ci", dsp_move.ci);
00506         xrm.Put("NanoPlott.move_speed", dsp_move.speed);
00507         
00508         xrm.Put("NanoPlott.plot_bias", dsp_plot.bias);
00509         xrm.Put("NanoPlott.plot_current", dsp_plot.current);
00510         xrm.Put("NanoPlott.plot_setpoint", dsp_plot.setpoint);
00511         xrm.Put("NanoPlott.plot_cp", dsp_plot.cp);
00512         xrm.Put("NanoPlott.plot_ci", dsp_plot.ci);
00513         xrm.Put("NanoPlott.plot_speed", dsp_plot.speed);
00514 
00515         xrm.Put("NanoPlott.PlotFile", PlotFile);
00516 }
00517 
00518 
00519 void NanoPlottControl::update(){
00520   g_slist_foreach((GSList*)gtk_object_get_data( GTK_OBJECT (widget), "NANOPLOTT_EC_list"),
00521                   (GFunc) App::update_ec, NULL);
00522 }
00523 
00524 void NanoPlottControl::StopPlott(GtkWidget *widget, NanoPlottControl *npc){
00525         npc->savestate ();
00526         npc->count = npc->repeat;
00527 
00528 //      gtk_entry_set_text (
00529 //              GTK_ENTRY (gtk_object_get_data ( 
00530 //                                 GTK_OBJECT (widget),
00531 //                                 "PlotFileEntry"
00532 //                                 )),
00533 //              npc->PlotFile
00534 //              );
00535 
00536         npc->update ();
00537 }
00538 
00539 void NanoPlottControl::RunPlott(GtkWidget *widget, NanoPlottControl *npc){
00540         if (npc->count != -1) return;
00541         gtk_widget_set_sensitive (widget, FALSE);
00542 
00543 #define MAXPOLYNODES 8
00544 //      G_FREE_STRDUP (
00545 //              npc->PlotFile, 
00546 //              gtk_entry_get_text (
00547 //                      GTK_ENTRY (gtk_object_get_data ( 
00548 //                                         GTK_OBJECT (widget),
00549 //                                         "PlotFileEntry"
00550 //                                         ))
00551 //                      )
00552 //              );
00553         if (npc->PlotFile)
00554                 g_free (npc->PlotFile);
00555         npc->PlotFile = g_strdup( gnome_file_entry_get_full_path (GNOME_FILE_ENTRY (gtk_object_get_data (GTK_OBJECT (widget), "PlotFileEntry")), TRUE));
00556         PI_DEBUG (DBG_L2, npc->PlotFile );
00557 
00558         npc->count = 0;
00559         do {
00560                 PI_DEBUG (DBG_L2, "----------- Start Plotting ----------" );
00561                 std::ifstream hp;
00562                 hp.open (npc->PlotFile, std::ios::in);
00563                 int k=0;
00564                 double xy[1+2*MAXPOLYNODES];
00565                 double x0,y0;
00566                 x0=0.; y0=0.;
00567                 
00568                 gchar *mld = g_strdup_printf ("Running: %d/%d: %5.1f%% done", npc->count, npc->repeat, 100.*npc->count/npc->repeat);
00569                 gtk_entry_set_text (GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (widget), "RepeatEntry")), mld);
00570                 g_free (mld);
00571                 while(gtk_events_pending()) gtk_main_iteration();
00572 
00573                 while (hp.good()){
00574                         gchar cmd[64];
00575                         hp.getline (cmd, 64);
00576                         PI_DEBUG (DBG_L2, "$>" << cmd );
00577                         if (!strncmp(cmd, "PU", 2)){
00578                                 double x,y;
00579                                 strtok(cmd, " ,;");
00580                                 x = atof (strtok(NULL, " ,;"));
00581                                 y = atof (strtok(NULL, " ,;"));
00582                                 npc->SetNewParam (&npc->dsp_move);
00583                                 npc->Transform (x, y);
00584                                 npc->GoToPosition (x, y);
00585 
00586                                 while(gtk_events_pending()) gtk_main_iteration();
00587 
00588                                 PI_DEBUG (DBG_L2, "Pen Up: (" << x << "," << y << ")" );
00589                                 x0=x; y0=y;
00590                                 if(k){ 
00591                                         if (NanoPlott_pi.app->xsm->ActiveScan)
00592                                                 if (NanoPlott_pi.app->xsm->ActiveScan->view && npc->count == 0)
00593                                                         NanoPlott_pi.app->xsm->ActiveScan->view->add_object (0, (gpointer) xy);
00594                                         k=0;
00595                                 }
00596                         }
00597                         if (!strncmp(cmd, "PD", 2)){
00598                                 double x,y;
00599                                 if(!k) { 
00600                                         xy[0] = (double)(k+1);
00601                                         xy[1 + 2*k    ] = x0;
00602                                         xy[1 + 2*k + 1] = y0;
00603                                         ++k;
00604                                 }
00605                                 strtok(cmd, " ,;");
00606                                 x = atof (strtok(NULL, " ,;"));
00607                                 y = atof (strtok(NULL, " ,;"));
00608                                 npc->SetNewParam (&npc->dsp_plot);
00609                                 npc->Transform (x, y);
00610                                 npc->GoToPosition (x, y);
00611 
00612                                 while(gtk_events_pending()) gtk_main_iteration();
00613 
00614                                 PI_DEBUG (DBG_L2, "Pen Down: (" << x << "," << y << ")" );
00615                                 // x,y in Pixel via nx,ny,user(rx,ry)
00616                                 if(k<MAXPOLYNODES){
00617                                         x0=x; y0=y;
00618                                         xy[0] = (double)(k+1);
00619                                         xy[1 + 2*k    ] = x;
00620                                         xy[1 + 2*k + 1] = y;
00621                                         ++k;
00622                                 }else{
00623                                         // add polyobj. and start new one 
00624                                         // "appending" at last pos.
00625                                         if (NanoPlott_pi.app->xsm->ActiveScan)
00626                                                 if (NanoPlott_pi.app->xsm->ActiveScan->view && npc->count == 0)
00627                                                         NanoPlott_pi.app->xsm->ActiveScan->view->add_object (0, (gpointer) xy);
00628                                         k=0;
00629                                         xy[0] = (double)(k+1);
00630                                         xy[1 + 2*k    ] = x0;
00631                                         xy[1 + 2*k + 1] = y0;
00632                                         ++k;
00633                                         xy[0] = (double)(k+1);
00634                                         xy[1 + 2*k    ] = x;
00635                                         xy[1 + 2*k + 1] = y;
00636                                         ++k;
00637                                 }
00638                         }
00639                 }
00640                 if(k){ 
00641                         if (NanoPlott_pi.app->xsm->ActiveScan)
00642                                 if (NanoPlott_pi.app->xsm->ActiveScan->view && npc->count == 0)
00643                                         NanoPlott_pi.app->xsm->ActiveScan->view->add_object (0, (gpointer) xy);
00644                 }
00645                 hp.close();
00646                 PI_DEBUG (DBG_L2, "-----------  End Plotting  ----------" );
00647 
00648                 ++npc->count;
00649         } while (npc->count < npc->repeat);
00650 
00651         PI_DEBUG (DBG_L2, "Restoring FB Parameters" );
00652 
00653 // **=== restore missing ===
00654 // **===        npc->SetNewParam (&NanoPlott_pi.app->xsm->data.hardpars);
00655 
00656         gtk_widget_set_sensitive (widget, TRUE);
00657         npc->count = -1;
00658 
00659         npc->update ();
00660 }
00661 
00662 
00663 /* stolen from app_remote.C & pyremote.C */
00664 static void check_remote_ec(Gtk_EntryControl* ec, gpointer arglist){
00665     ec->CheckRemoteCmd((gchar **)arglist);
00666 }
00667 
00668 static void set_via_remote (gchar *arg, double value){
00669         gchar *args[] = { "set", NULL, NULL };
00670         args[1] = arg;
00671         args[2] = g_strdup_printf ("%g", value);
00672         g_slist_foreach (gapp->RemoteEntryList, (GFunc) check_remote_ec, (gpointer)args);
00673         g_free (args[2]);
00674 }
00675 
00676 void NanoPlottControl::SetNewParam(DSP_Remote *dsp){
00677         set_via_remote ("DSP_Bias", dsp->bias);
00678         set_via_remote ("DSP_Current", dsp->current);
00679         set_via_remote ("DSP_SetPoint", dsp->setpoint);
00680         set_via_remote ("DSP_CP", dsp->cp);
00681         set_via_remote ("DSP_CI", dsp->ci);
00682         set_via_remote ("DSP_MoveSpd", dsp->speed);
00683 }
00684 
00685 void NanoPlottControl::Transform(double &x, double &y){
00686         x *= XScale; x += Xorg;
00687         y *= YScale; y += Yorg;
00688 }
00689 
00690 void NanoPlottControl::GoToPosition(double x, double y){
00691         NanoPlott_pi.app->xsm->hardware->SetOffset(
00692                 R2INT(NanoPlott_pi.app->xsm->Inst->X0A2Dig(x)),
00693                 R2INT(NanoPlott_pi.app->xsm->Inst->Y0A2Dig(y)));
00694 }

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