home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Graphics / Graphics.zip / xfitsvew.zip / XFITSview / infobox.c < prev    next >
C/C++ Source or Header  |  1997-05-16  |  8KB  |  238 lines

  1. /* Information dialog box for XFITSview */
  2. /*-----------------------------------------------------------------------
  3. *  Copyright (C) 1996,1997
  4. *  Associated Universities, Inc. Washington DC, USA.
  5. *  This program is free software; you can redistribute it and/or
  6. *  modify it under the terms of the GNU General Public License as
  7. *  published by the Free Software Foundation; either version 2 of
  8. *  the License, or (at your option) any later version.
  9. *
  10. *  This program is distributed in the hope that it will be useful,
  11. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. *  GNU General Public License for more details.
  14. *-----------------------------------------------------------------------*/
  15.  
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <Xm/Xm.h> 
  19. #include <Xm/DialogS.h> 
  20. #include <Xm/Form.h>
  21. #include <Xm/Label.h>
  22. #include <Xm/PushB.h>
  23. #include "imagedisp.h"
  24. #include "infobox.h"
  25. #include "wpos.h"
  26.  
  27. /* is the info box active? */
  28. int InfoBoxActive = 0;
  29.  
  30. /* global structure for things to talk to each other */
  31. typedef struct {
  32.   Widget dialog;
  33.   Widget parent;
  34.   ImageDisplay *IDdata;
  35. } InfoBoxStuff;
  36. InfoBoxStuff Info;
  37.  
  38. void NextInfoLine (Widget form, Widget prev, Widget *line, 
  39.            char* string, int width)
  40. /* add label widget with string at end of form; */
  41. {
  42.   XmString     xlinestr = NULL;
  43.  
  44. /* convert to wierd X-Windows form */
  45.   xlinestr = XmStringCreateSimple (string);
  46.  
  47.   *line = XtVaCreateManagedWidget ("NextLine", xmLabelWidgetClass,
  48.                    form,
  49.                    XmNwidth,         width,
  50.                    XmNlabelString,   xlinestr,
  51.                    XmNtopAttachment, XmATTACH_WIDGET,
  52.                    XmNtopWidget,     prev,
  53.                    XmNleftAttachment,  XmATTACH_FORM,
  54.                    NULL);
  55.   if (xlinestr) XmStringFree(xlinestr);
  56. } /* end NextInfoLine */
  57.  
  58. /* button callbacks */
  59. void DismissButCB (Widget w, XtPointer clientData, XtPointer callData)
  60. /* Dismiss button hit */
  61. {
  62.   XtDestroyWidget (Info.dialog);
  63.   InfoBoxActive = 0; /* mark as inactive */
  64. } /* end DismissButCB */
  65.  
  66. void RefreshButCB (Widget w, XtPointer clientData, XtPointer callData)
  67. /* Refresh button hit */
  68. {
  69. /* some validity checks */
  70.   if (!Info.IDdata) return;
  71.   if (!image[CurImag].valid) return;
  72.  
  73. /* destroy old */
  74.   XtDestroyWidget (Info.dialog);
  75.   InfoBoxActive = 0; /* mark as inactive */
  76.  
  77. /* make new */
  78.   InfoBoxCB (Info.parent, (XtPointer)Info.IDdata, (XtPointer)NULL);
  79.  
  80. } /* end RefreshButCB */
  81.  
  82. void InfoBoxCB (Widget parent, XtPointer clientData, XtPointer callData)
  83. /* create dialog box for source information */
  84. {
  85.   Widget       form, line[15];
  86.   Widget       DismissButton, RefreshButton;
  87.   char         linestr[500], *axislab, coordst[50], cs[50];
  88.   float        incr;
  89.   int          loop, iLine, iMaxLine=14;
  90.   ImageDisplay *IDdata = (ImageDisplay*)clientData;
  91. /*  ImageData    *image = (ImageData*) IDdata->image;*/
  92.   int          width = 400; /* width of box */
  93.   XmString     label = NULL;
  94.  
  95. /* some validity checks */
  96.   if (!IDdata) return;
  97.   if (!image[CurImag].valid) return;
  98.  
  99. /* register info for use by refresh */
  100.   Info.IDdata = IDdata;
  101.   Info.parent = parent;
  102.  
  103.   /* don't make another one */
  104.   if (InfoBoxActive) {
  105.     if (XtIsRealized (Info.dialog))
  106.     XMapRaised (XtDisplay(Info.dialog), XtWindow(Info.dialog));
  107.     return;
  108.   }
  109.  
  110. /* mark as active */
  111.   InfoBoxActive = 1; 
  112.  
  113.   Info.dialog = XtVaCreatePopupShell("Source information", 
  114.                      xmDialogShellWidgetClass, 
  115.                      IDdata->shell, 
  116.                      XmNwidth,     width,
  117.                      XmNheight,    300,
  118.                      XmNdeleteResponse, XmDESTROY,
  119.                      NULL);
  120.  
  121. /* make Form widget to stick things on */
  122.   form = XtVaCreateManagedWidget ("InfoForm", xmFormWidgetClass,
  123.                   Info.dialog,
  124.                   XmNwidth,     width,
  125.                   XmNheight,    300,
  126.                   XmNx,           0,
  127.                   XmNy,           0,
  128.                   NULL);
  129. /* source info */ 
  130. /* file name */
  131.   sprintf(linestr, "Information about %s ",image[CurImag].FileName->sp);
  132.   label = XmStringCreateSimple (linestr);
  133.   line[0] = XtVaCreateManagedWidget ("FirstLine", xmLabelWidgetClass,
  134.                        form,
  135.                        XmNwidth,         width,
  136.                        XmNlabelString,   label,
  137.                        XmNtopAttachment, XmATTACH_FORM,
  138.                        XmNleftAttachment,  XmATTACH_FORM,
  139.                        NULL);
  140.   if (label) XmStringFree(label); label = NULL;
  141.   iLine = 0;
  142. /* object name, units */
  143.   sprintf(linestr, "object = %s  units = %s",
  144.       image[CurImag].object->sp, image[CurImag].units->sp);
  145.   NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  146.   iLine++;
  147.  
  148. /* max., min. values in plane */
  149.   sprintf(linestr, "max. value = %f    min value = %f ",
  150.       image[CurImag].data_max, image[CurImag].data_min);
  151.   NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  152.   iLine++;
  153.  
  154. /* observing date, coordinate equinox */
  155.   sprintf(linestr, "Observing date = %s  coordinate equinox= %6.1f",
  156.       image[CurImag].obsdate->sp, image[CurImag].Image->descript->equinox);
  157.   NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  158.   iLine++;
  159.  
  160. /* axis info label line */
  161.   sprintf(linestr," Axis  type     dim     value      ref. pix   inc.      rot.   ");
  162.   NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  163.   iLine++;
  164. /*    1 RA---SIN 1024  hh mm ss.sss     512.0  100.000     0.0 */
  165.  
  166. /* loop over axes */
  167.   for (loop=0;loop<image[CurImag].ndim;loop++)
  168.     {axislab =  image[CurImag].cname[loop]->sp;
  169.      if ((!strncmp (axislab, "RA", 2)) ||
  170.      (!strncmp (axislab, "LL  ", 4)))
  171. /* check useage of cs in ra2hms */
  172.        {ra2hms(image[CurImag].crval[loop], axislab, cs);
  173.     incr = image[CurImag].crinc[loop] * 3600.0; /* increment in arcsec. */
  174.     sprintf(linestr, "%4d %8.8s%5ld %13.13s%10.1f%9.3f%8.1f",
  175.         loop+1, axislab, image[CurImag].dim[loop],
  176.         cs+4, image[CurImag].crpix[loop],
  177.         incr, image[CurImag].crot[loop]);}
  178.      else  if ((!strncmp (axislab, "DEC", 3)) || 
  179.            (!strncmp (axislab, "GLON", 4)) ||
  180.            (!strncmp (axislab, "GLAT", 4)) ||
  181.            (!strncmp (axislab, "ELON", 4)) ||
  182.            (!strncmp (axislab, "ELAT", 4)) ||
  183.            (!strncmp (axislab, "MM  ", 4)))  
  184.        {dec2dms(image[CurImag].crval[loop], axislab, cs);
  185.     incr = image[CurImag].crinc[loop] * 3600.0; /* increment in arcsec. */
  186.     sprintf(linestr, "%4d %8.8s%5ld %13.13s%10.1f%9.3f%8.1f",
  187.         loop+1, axislab, image[CurImag].dim[loop],
  188.         cs+4, image[CurImag].crpix[loop],
  189.         incr, image[CurImag].crot[loop]);}
  190.      else   /* other axes */
  191.        {sprintf(linestr, "%4d %8.8s%5ld %13g%10.1f%9g%8.1f",
  192.         loop+1, axislab, image[CurImag].dim[loop],
  193.         image[CurImag].crval[loop], image[CurImag].crpix[loop],
  194.         image[CurImag].crinc[loop], image[CurImag].crot[loop]);} /* end type */
  195.      NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  196.      iLine++;
  197.      if (iLine>=iMaxLine) break;
  198.      
  199.    }  /* end of axis loop */
  200. /* tell coordinate type */
  201.   if (iLine<iMaxLine) {
  202.     if (image[CurImag].Image->descript->isDSS) {
  203.       sprintf (linestr, "Using DSS coordinates");
  204.       NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  205.       iLine++;
  206.     }
  207.     else if (image[CurImag].Image->descript->isIRAF) {
  208.       sprintf (linestr, "Using IRAF coordinates");
  209.       NextInfoLine (form, line[iLine], &line[iLine+1], linestr, width);
  210.       iLine++;
  211.     }
  212.   } /* end coordinate type label */
  213.  
  214. /* Dismiss button */
  215.   DismissButton = 
  216.     XtVaCreateManagedWidget ("Dismiss", xmPushButtonWidgetClass, 
  217.                  form, 
  218.                  XmNbottomAttachment, XmATTACH_FORM,
  219.                  XmNleftAttachment,  XmATTACH_FORM,
  220.                  NULL);
  221.   XtAddCallback (DismissButton, XmNactivateCallback, DismissButCB, 
  222.          (XtPointer)IDdata);
  223.   
  224. /* Refresh button */
  225.   RefreshButton = 
  226.     XtVaCreateManagedWidget ("Refresh", xmPushButtonWidgetClass, 
  227.                  form, 
  228.                  XmNbottomAttachment, XmATTACH_FORM,
  229.                  XmNrightAttachment, XmATTACH_FORM,
  230.                  NULL);
  231.   XtAddCallback (RefreshButton, XmNactivateCallback, RefreshButCB, 
  232.          (XtPointer)IDdata);
  233.  
  234. /* set it up */
  235.   XtManageChild (Info.dialog);
  236. } /* end OptionBox */
  237.  
  238.