00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 #include "config.h"
00079 #include "gxsm/plugin.h"
00080 #include "glbvars.h"
00081 #include "xsmtypes.h"
00082
00083 #include "PanView.h"
00084
00085
00086 static void PanView_init (void);
00087 static void PanView_query (void);
00088 static void PanView_about (void);
00089 static void PanView_configure (void);
00090 static void PanView_cleanup (void);
00091
00092 PanView *Pan_Window = NULL;
00093 static void PanView_run(GtkWidget *w, void *data);
00094 gboolean refresh_function(GtkWidget *w, GdkEvent *event, void *data);
00095
00096 gboolean PanView_valid = FALSE;
00097
00098 #define PRE_AREA 0
00099
00100
00101
00102
00103
00104
00105
00106 GxsmPlugin PanView_pi = {
00107 NULL,
00108 NULL,
00109 0,
00110 NULL,
00111 "Pan View",
00112 NULL,
00113 "Visualisation of the scan position",
00114 "Kristan Temme, Thorsten Wagner",
00115 N_("_Windows/"),
00116 N_("Pan View"),
00117 NULL,
00118 "No further info",
00119 NULL,
00120 NULL,
00121 PanView_init,
00122 NULL,
00123 PanView_about,
00124 PanView_configure,
00125 PanView_run,
00126 PanView_cleanup
00127 };
00128
00129
00130
00131
00132 static const char *about_text = N_("A little scanning reference");
00133
00134
00135
00136
00137
00138
00139 GxsmPlugin *get_gxsm_plugin_info ( void ){
00140 PanView_pi.description = g_strdup_printf(N_("Gxsm pan view window %s"), VERSION);
00141 return &PanView_pi;
00142 }
00143
00144
00145
00146
00147
00148 static void PanView_init(void)
00149 {
00150 PI_DEBUG(DBG_L2, "PanView Plugin Init" );
00151 }
00152
00153
00154
00155
00156 static void PanView_about(void)
00157 {
00158 const gchar *authors[] = { PanView_pi.authors, NULL};
00159 gtk_widget_show(gnome_about_new ( PanView_pi.name,
00160 VERSION,
00161 N_("(C) 2003 the Free Software Foundation"),
00162 about_text,
00163 authors,
00164 NULL,NULL,NULL
00165 ));
00166 }
00167
00168
00169
00170 static void PanView_configure(void)
00171 {
00172 if(PanView_pi.app)
00173 PanView_pi.app->message("PanView Plugin Configuration");
00174
00175 if (Pan_Window){
00176 if (Pan_Window->finish ()){
00177 PanView_pi.app->message("PanView: Starting tip monitor");
00178 Pan_Window->start_tip_monitor ();
00179 } else {
00180 PanView_pi.app->message("PanView: Stopping tip monitor");
00181 Pan_Window->stop_tip_monitor ();
00182 }
00183 }
00184 }
00185
00186
00187
00188
00189 static void PanView_cleanup(void)
00190 {
00191 PanView_valid = FALSE;
00192
00193 PI_DEBUG(DBG_L2, "PanView_cleanup(void). Entering.\n");
00194 if (Pan_Window) {
00195 delete Pan_Window;
00196 }
00197 PI_DEBUG(DBG_L2, "PanView_cleanup(void). Exiting.\n");
00198 }
00199
00200 static void PanView_refresh_callback (gpointer data){
00201 if (Pan_Window)
00202 Pan_Window -> refresh ();
00203 }
00204
00205 static gint PanView_tip_refresh_callback (PanView *pv){
00206
00207 if (!PanView_valid) return FALSE;
00208
00209 if (pv){
00210 if (! pv -> finish ()){
00211 pv -> tip_refresh ();
00212 return TRUE;
00213 }
00214 pv -> finish (-999);
00215 }
00216 return FALSE;
00217 }
00218
00219
00220 static void PanView_run(GtkWidget *w, void *data)
00221 {
00222 if (!Pan_Window){
00223 Pan_Window = new PanView(PanView_pi.app->getApp());
00224 PanView_pi.app->ConnectPluginToSPMRangeEvent (PanView_refresh_callback);
00225 }
00226
00227 Pan_Window->run();
00228 Pan_Window->start_tip_monitor ();
00229
00230 PI_DEBUG(DBG_L2, "A new Pan Window was opened" );
00231 }
00232
00233 PanView :: PanView (GtkWidget *a) : GnomeAppService (a){
00234 int i,j;
00235
00236 finish (FALSE);
00237 timer_id = 0;
00238
00239 AppWidgetInit (N_("Pan View: scan area"));
00240
00241 GtkWidget *box = gtk_vbox_new (FALSE, 0);
00242 gtk_widget_show (box);
00243 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
00244
00245
00246
00247
00248 gtk_widget_push_visual(gdk_rgb_get_visual());
00249 gtk_widget_push_colormap(gdk_rgb_get_cmap());
00250
00251 canvas = gnome_canvas_new_aa();
00252
00253
00254 gtk_widget_pop_colormap();
00255 gtk_widget_pop_visual();
00256
00257 gtk_widget_set_size_request (canvas, 2*WINDOW_SIZE+15, 2*WINDOW_SIZE+7);
00258
00259 gtk_widget_show (canvas);
00260 gtk_container_add (GTK_CONTAINER (box), canvas);
00261
00262
00263
00264 update_expanded_scan_limits ();
00265
00266
00267 gnome_canvas_set_scroll_region( GNOME_CANVAS ( canvas ), TO_CANVAS_X(max_x), TO_CANVAS_Y(max_y),
00268 TO_CANVAS_X(min_x), TO_CANVAS_Y(min_y));
00269
00270
00271
00272 pan_area = gnome_canvas_item_new ( gnome_canvas_root (GNOME_CANVAS (canvas)),
00273 gnome_canvas_rect_get_type(),
00274 "x1", TO_CANVAS_X(max_x),
00275 "x2", TO_CANVAS_X(min_x),
00276 "y1", TO_CANVAS_Y(max_y),
00277 "y2", TO_CANVAS_Y(min_y),
00278 "fill_color","white",
00279 "outline_color","red",
00280 "width_units", 1.5,
00281 NULL );
00282
00283 pre_current_view = NULL;
00284 current_view = NULL;
00285 tip_marker = NULL;
00286 tip_marker_z = NULL;
00287
00288 PanView_valid = TRUE;
00289
00290 refresh ();
00291 tip_refresh ();
00292 }
00293
00294 PanView::~PanView (){
00295
00296 PanView_valid = FALSE;
00297
00298 g_print ("PanView :: ~PanView ()\n");
00299 g_print ("PanView :: ~PanView () -- stop_tip_monitor \n");
00300 stop_tip_monitor ();
00301 g_print ("PanView :: ~PanView () -- OK.\n");
00302 }
00303
00304 void PanView::run()
00305 {
00306 show ();
00307 }
00308
00309 void PanView::start_tip_monitor (){
00310 if (!timer_id){
00311 g_print ("PanView::start_tip_monitor \n");
00312 finish (FALSE);
00313 timer_id = gtk_timeout_add (150, (GtkFunction) PanView_tip_refresh_callback, this);
00314 }
00315 }
00316
00317 void PanView::stop_tip_monitor (){
00318 if (timer_id){
00319 g_print ("PanView::stop_tip_monitor \n");
00320 finish (TRUE);
00321
00322
00323
00324
00325 gtk_timeout_remove (timer_id);
00326 timer_id = 0;
00327 }
00328 tip_refresh ();
00329 g_print ("PanView::stop_tip_monitor OK.\n");
00330 }
00331
00332 void PanView::update_expanded_scan_limits (){
00333
00334
00335 max_x = xsmres.AnalogVMaxOut*gapp->xsm->Inst->VX();
00336 min_x = -xsmres.AnalogVMaxOut*gapp->xsm->Inst->VX();
00337 max_y = xsmres.AnalogVMaxOut*gapp->xsm->Inst->VY();
00338 min_y = -xsmres.AnalogVMaxOut*gapp->xsm->Inst->VY();
00339 max_z = xsmres.AnalogVMaxOut*gapp->xsm->Inst->VZ();
00340 min_z = -xsmres.AnalogVMaxOut*gapp->xsm->Inst->VZ();
00341
00342
00343
00344
00345 if (gapp->xsm->Inst->OffsetMode() == OFM_ANALOG_OFFSET_ADDING){
00346 max_x = xsmres.AnalogVMaxOut*gapp->xsm->Inst->VX0();
00347 min_x = -xsmres.AnalogVMaxOut*gapp->xsm->Inst->VX0();
00348 max_y = xsmres.AnalogVMaxOut*gapp->xsm->Inst->VY0();
00349 min_y = -xsmres.AnalogVMaxOut*gapp->xsm->Inst->VY0();
00350 }
00351 }
00352
00353 void PanView :: tip_refresh()
00354 {
00355
00356 GnomeCanvasPoints* tipmark_points = gnome_canvas_points_new (4);
00357 double rsz = max_x/15.;
00358 double asp = 1.67;
00359 double x,y,z;
00360 x=y=z=0.;
00361
00362 if (!PanView_valid) return;
00363
00364 if (IS_NOCARD){
00365 ;
00366 }
00367 else{
00368
00369 gapp->xsm->hardware->RTQuery ("zxy", z, x, y);
00370 }
00371
00372
00373 tipmark_points->coords[0] = TO_CANVAS_X (x-rsz/asp);
00374 tipmark_points->coords[1] = TO_CANVAS_Y (y+rsz);
00375 tipmark_points->coords[2] = TO_CANVAS_X (x+rsz/asp);
00376 tipmark_points->coords[3] = TO_CANVAS_Y (y-rsz);
00377 tipmark_points->coords[4] = TO_CANVAS_X (x-rsz/asp);
00378 tipmark_points->coords[5] = TO_CANVAS_Y (y-rsz);
00379 tipmark_points->coords[6] = TO_CANVAS_X (x+rsz/asp);
00380 tipmark_points->coords[7] = TO_CANVAS_Y (y+rsz);
00381
00382 if (tip_marker)
00383 gnome_canvas_item_set (tip_marker,
00384 "points", tipmark_points,
00385 "fill_color", finish () ? "red":"yellow",
00386 NULL);
00387 else
00388 tip_marker = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
00389 gnome_canvas_polygon_get_type (),
00390 "points", tipmark_points,
00391 "outline_color", "blue",
00392 "fill_color", finish () ? "red":"yellow",
00393 "width_units", 0.5,
00394 NULL);
00395
00396 gnome_canvas_item_raise_to_top (tip_marker);
00397
00398
00399 rsz = 1./15.;
00400 asp = 1.67;
00401 tipmark_points->coords[0] = TO_CANVAS_NORMAL_X (1.+rsz);
00402 tipmark_points->coords[1] = TO_CANVAS_NORMAL_Y (z/max_z-rsz/asp);
00403 tipmark_points->coords[2] = TO_CANVAS_NORMAL_X (1.-rsz);
00404 tipmark_points->coords[3] = TO_CANVAS_NORMAL_Y (z/max_z+rsz/asp);
00405 tipmark_points->coords[4] = TO_CANVAS_NORMAL_X (1.-rsz);
00406 tipmark_points->coords[5] = TO_CANVAS_NORMAL_Y (z/max_z-rsz/asp);
00407 tipmark_points->coords[6] = TO_CANVAS_NORMAL_X (1.+rsz);
00408 tipmark_points->coords[7] = TO_CANVAS_NORMAL_Y (z/max_z+rsz/asp);
00409
00410
00411 if (tip_marker_z)
00412 gnome_canvas_item_set (tip_marker_z,
00413 "points", tipmark_points,
00414 "fill_color", fabs(z/max_z) < 0.8 ? "green":"red",
00415 NULL);
00416 else
00417 tip_marker_z = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
00418 gnome_canvas_polygon_get_type (),
00419 "points", tipmark_points,
00420 "outline_color", "green",
00421 "fill_color", fabs(z/max_z) < 0.8 ? "green":"red",
00422 "width_units", 0.5,
00423 NULL);
00424
00425 gnome_canvas_points_free (tipmark_points);
00426 gnome_canvas_item_raise_to_top (tip_marker_z);
00427 }
00428
00429 void PanView :: refresh()
00430 {
00431 static int prev_error = FALSE;
00432 int error = FALSE;
00433 double max_corn[4][2];
00434 double x_offset;
00435 double y_offset;
00436 double alpha;
00437
00438 int i,j;
00439
00440 if (!PanView_valid) return;
00441
00442
00443 update_expanded_scan_limits ();
00444
00445 PI_DEBUG (DBG_L2, min_x<<"<X<"<<max_x );
00446 PI_DEBUG (DBG_L2, min_y<<"<Y<"<<max_y );
00447
00448
00449 if (IS_SPALEED_CTRL||xsmres.ScanOrgCenter){
00450 point[0][0] = -0.5*gapp->xsm->data.s.nx*gapp->xsm->data.s.dx/xsmres.XPiezoAV;
00451 point[0][1] = +0.5*gapp->xsm->data.s.ny*gapp->xsm->data.s.dy/xsmres.YPiezoAV;
00452
00453 point[1][0] = -1*point[0][0]; point[1][1] = +1*point[0][1];
00454 point[2][0] = -1*point[0][0]; point[2][1] = -1*point[0][1];
00455 point[3][0] = +1*point[0][0]; point[3][1] = -1*point[0][1];
00456 }
00457 else{
00458 point[0][0] =-0.5*gapp->xsm->data.s.nx*gapp->xsm->data.s.dx/xsmres.XPiezoAV; point[0][1] = 0;
00459 point[1][0] = -1*point[0][0]; point[1][1] = 0;
00460 point[2][0] = -1*point[0][0]; point[2][1] = -gapp->xsm->data.s.ny*gapp->xsm->data.s.dy/xsmres.YPiezoAV;
00461 point[3][0] = +1*point[0][0]; point[3][1] = +1*point[2][1];
00462 }
00463 PI_DEBUG (DBG_L2, "Original coordinates: \t"<<
00464 point[0][0]<<","<<point[0][1]<<"\t"<<
00465 point[1][0]<<","<<point[1][1]<<"\t"<<
00466 point[2][0]<<","<<point[2][1]<<"\t"<<
00467 point[3][0]<<","<<point[3][1] );
00468
00469
00470 y_offset = gapp->xsm->data.s.y0/xsmres.YPiezoAV;
00471 x_offset = gapp->xsm->data.s.x0/xsmres.XPiezoAV;
00472 alpha = gapp->xsm->data.s.alpha;
00473
00474 #if PRE_AREA
00475
00476 double w = 2*gapp->xsm->data.s.dx*gapp->xsm->data.hardpars.LS_nx_pre/xsmres.XPiezoAV;
00477 pre_point[0][0] = point[0][0]-w; pre_point[0][1] = point [0][1];
00478 pre_point[1][0] = point[1][0]+w; pre_point[1][1] = point [1][1];
00479 pre_point[2][0] = point[2][0]+w; pre_point[2][1] = point [2][1];
00480 pre_point[3][0] = point[3][0]-w; pre_point[3][1] = point [3][1];
00481 #endif
00482
00483
00484 for(i=0;i<4;i++){
00485 transform(max_corn[i], point[i], -alpha, y_offset, x_offset);
00486 #if PRE_AREA
00487 transform(max_corn[i],pre_point[i],-alpha,y_offset,x_offset);
00488 #endif
00489 }
00490
00491
00492 for(i=0; i < 4 && !error;i++){
00493 if(max_corn[i][0] >= max_x || max_corn[i][0] <= min_x)
00494 error = TRUE;
00495
00496 if(max_corn[i][1] >= max_y || max_corn[i][1] <= min_y)
00497 error = TRUE;
00498
00499 }
00500
00501 if(max_corn[0][0] == corn_oo && max_corn[3][1] == corn_ii)
00502 error = FALSE;
00503
00504 corn_oo = max_corn[0][0];
00505 corn_ii = max_corn[3][1];
00506
00507
00508 #if PRE_AREA
00509
00510
00511 pre_scanarea_points = gnome_canvas_points_new (4);
00512 for(i=0,j=0;i < 4;i++){
00513 pre_scanarea_points->coords[j] = TO_CANVAS_X(max_corn[i][0]);
00514 pre_scanarea_points->coords[j+1] = TO_CANVAS_Y(max_corn[i][1]);
00515 j+=2;
00516 }
00517
00518 if (pre_current_view)
00519 gnome_canvas_item_set (pre_current_view,
00520 "points", pre_scanarea_points,
00521 "outline_color", "black",
00522 "fill_color","white",
00523 NULL );
00524 else
00525 pre_current_view = gnome_canvas_item_new( gnome_canvas_root (GNOME_CANVAS (canvas)),
00526 gnome_canvas_polygon_get_type(),
00527 "points", pre_scanarea_points,
00528 "fill_color", "white",
00529 "outline_color", "black",
00530 "width_units", 1.5,
00531 NULL );
00532
00533 gnome_canvas_points_free (pre_scanarea_points);
00534 #endif
00535
00536
00537 for(i=0;i<4;i++)
00538 transform(max_corn[i],point[i],-alpha,y_offset,x_offset);
00539
00540 PI_DEBUG (DBG_L2, "Transformed coordinates: \t"<<
00541 max_corn[0][0]<<","<<max_corn[0][1]<<"\t"<<
00542 max_corn[1][0]<<","<<max_corn[1][1]<<"\t"<<
00543 max_corn[2][0]<<","<<max_corn[2][1]<<"\t"<<
00544 max_corn[3][0]<<","<<max_corn[3][1] );
00545
00546
00547 GnomeCanvasPoints *scanarea_points = gnome_canvas_points_new (4);
00548 for(i=0,j=0;i < 4;i++){
00549 scanarea_points->coords[j] = TO_CANVAS_X(max_corn[i][0]);
00550 scanarea_points->coords[j+1] = TO_CANVAS_Y(max_corn[i][1]);
00551 j+=2;
00552 }
00553
00554 if (current_view)
00555 gnome_canvas_item_set(current_view,
00556 "points", scanarea_points,
00557 "outline_color", (error)?"red":"black",
00558 "fill_color",(error)?"red":"black",
00559 NULL );
00560 else
00561 current_view = gnome_canvas_item_new( gnome_canvas_root (GNOME_CANVAS (canvas)),
00562 gnome_canvas_polygon_get_type(),
00563 "points", scanarea_points,
00564 "fill_color", "black",
00565 "outline_color", "black",
00566 "width_units", 1.5,
00567 NULL);
00568
00569 gnome_canvas_points_free (scanarea_points);
00570
00571 if(error && !prev_error){
00572 prev_error = error;
00573 warning ("Scanning area is out of limits!");
00574 PI_DEBUG(DBG_L2, "Error: Scanning area is out of limits!" );
00575 }
00576 prev_error = error;
00577 }
00578
00579 void PanView :: transform(double *dest, double *src, double rot, double y_off, double x_off)
00580 {
00581 double D[2][2];
00582 int i,j;
00583
00584 D[0][0] = cos(TO_RAD(rot));
00585 D[1][1] = cos(TO_RAD(rot));
00586 D[0][1] = -sin(TO_RAD(rot));
00587 D[1][0] = sin(TO_RAD(rot));
00588
00589 dest[0] = 0;
00590 dest[1] = 0;
00591
00592 for(i=0; i<2 ; i++)
00593 for(j=0;j<2;j++)
00594 dest[i] += D[i][j]*src[j];
00595
00596 dest[0] += x_off;
00597 dest[1] += y_off;
00598 return;
00599 }
00600
00602