Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

afni_ttren.c

Go to the documentation of this file.
00001 #undef MAIN
00002 #include "afni.h"
00003 #include <Xm/XmAll.h>
00004 
00005 #define NUM_AV_FIRST 20  /* number of colormenus to create on first pass */
00006 
00007 /*-- internal data structure --*/
00008 
00009 typedef struct {
00010    int  reg_num , av_invert ;
00011    MCW_arrowval *reg_av[TTO_COUNT] ;  /* colormenus */
00012    char  *reg_label[TTO_COUNT] ;      /* labels for menus */
00013    short  reg_tto[TTO_COUNT]   ;      /* index into afni.h TTO_list */
00014    short  reg_ttbrik[TTO_COUNT] ;     /* which sub-brick in TTatlas+tlrc */
00015    short  reg_ttval[TTO_COUNT]  ;     /* what value in TTatlas+tlrc */
00016    short  reg_ttovc[TTO_COUNT]  ;     /* saved value of colormenu */
00017 
00018    Widget shell , scrollw , workwin ;
00019    MCW_arrowval *meth_av , *hemi_av ;
00020 
00021    Three_D_View * im3d ;
00022    MCW_DC *dc ;
00023 } TTRR_controls ;
00024 
00025 static TTRR_controls *ttc = NULL ;
00026 
00027 /*-- prototypes for internal functions --*/
00028 
00029 static void TTRR_action_CB       ( Widget, XtPointer, XtPointer ) ;
00030 static void TTRR_delete_window_CB( Widget, XtPointer, XtPointer ) ;
00031 static void TTRR_av_CB           ( MCW_arrowval * , XtPointer   ) ;
00032 
00033 static void TTRR_load_file( char * ) ;                             /* 08 Aug 2002 */
00034 static void TTRR_save_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
00035 static void TTRR_load_CB  ( Widget , XtPointer , MCW_choose_cbs * ) ;
00036 
00037 /*----------------------------------------------------------------------------
00038   Routine to create widgets for the TT atlas rendering controls
00039 ------------------------------------------------------------------------------*/
00040 
00041 /***** definitions for the action area controls *****/
00042 
00043 #define TTRR_clear_label  "Clear"
00044 #define TTRR_load_label   "Load"
00045 #define TTRR_save_label   "Save"
00046 #define TTRR_redraw_label "Redraw"
00047 #define TTRR_done_label   "Done"
00048 #define TTRR_help_label   "Help"
00049 
00050 #define TTRR_clear_hint  "Set all colors to 'none'"
00051 #define TTRR_load_hint   "Load colors from a file"
00052 #define TTRR_save_hint   "Save colors to a file"
00053 #define TTRR_redraw_hint "Redraw using current colors"
00054 #define TTRR_done_hint   "Close this window"
00055 
00056 #define NUM_TTRR_ACT 6
00057 
00058 static MCW_action_item TTRR_act[] = {
00059  { TTRR_clear_label , TTRR_action_CB, NULL,NULL, TTRR_clear_hint , 0 } ,
00060  { TTRR_load_label  , TTRR_action_CB, NULL,NULL, TTRR_load_hint  , 0 } ,
00061  { TTRR_save_label  , TTRR_action_CB, NULL,NULL, TTRR_save_hint  , 0 } ,
00062  { TTRR_redraw_label, TTRR_action_CB, NULL,NULL, TTRR_redraw_hint,-1 } ,
00063  { TTRR_done_label  , TTRR_action_CB, NULL,NULL, TTRR_done_hint  , 1 } ,
00064  { TTRR_help_label  , TTRR_action_CB, NULL,NULL, NULL            , 0 }
00065 } ;
00066 
00067 #define NMETHOD     5
00068 #define METHOD_OFF "Off"
00069 #define METHOD_GAF "Gyral/Area/Func"
00070 #define METHOD_AGF "Area/Gyral/Func"
00071 #define METHOD_FGA "Func/Gyral/Area"
00072 #define METHOD_FAG "Func/Area/Gyral"
00073 
00074 static char *METHOD_strings[NMETHOD] = {
00075   METHOD_OFF ,  METHOD_GAF ,  METHOD_AGF ,  METHOD_FGA ,  METHOD_FAG
00076 } ;
00077 
00078 #define NHEMI       3
00079 #define HEMI_LEFT   "Left only"
00080 #define HEMI_RIGHT  "Right only"
00081 #define HEMI_BOTH   "Both"
00082 
00083 static char *HEMI_strings[NHEMI] = { HEMI_LEFT , HEMI_RIGHT , HEMI_BOTH } ;
00084 
00085 static char helpstring[] =
00086   "The purpose of these controls is to enable display of the brain\n"
00087   "regions defined by the Talairach Daemon database (generously\n"
00088   "contributed by Jack Lancaster and Peter Fox of RIC UTHSCSA).\n"
00089   "\n"
00090   "In the database, some voxels have 2 labels - a larger scale\n"
00091   "'gyral' name and a finer scale 'area' name; these are marked\n"
00092   "with [G] and [A] in the region list.\n"
00093   "In the database there are\n"
00094   "    1,205,737 voxels with at least one label\n"
00095   "      709,953 voxels with only a 'gyral' label\n"
00096   "       15,898 voxels with only a 'area' label\n"
00097   "      479,886 voxels with both types of labels\n"
00098   "For example, the Parahippocampal Gyrus and the Hippocampus (area)\n"
00099   "have a great deal of overlap.\n"
00100   "\n"
00101   "Method:\n"
00102   "  To enable display of the selected regions, you must choose the\n"
00103   "  Method to be something other than 'Off'.  The other Method choices\n"
00104   "  determine the order in which color overlays take place; for example,\n"
00105   "  'Gyral/Area/Func' means that a 'gyral' color, if present in a voxel,\n"
00106   "  will overlay on top of any 'area' color there, which would in turn\n"
00107   "  overlay on top of any functional color there.  At this time, there\n"
00108   "  is no way to blend the colors from overlapping results.\n"
00109   "\n"
00110   "Hemisphere(s):\n"
00111   "  Use this to control which side(s) of the brain will have brain\n"
00112   "  region overlays.  At this time, this option only affects the volume\n"
00113   "  rendering and has no effect on the 2D image viewers, in which\n"
00114   "  regions from both hemispheres will be rendered, regardless.\n"
00115   "\n"
00116   "The regional controls are to set the overlay colors; if a region's\n"
00117   "color is set to 'none', then it will not be overlaid.\n"
00118   "\n"
00119   "* To change all overlay colors to 'none', use the Clear button.\n"
00120   "* To save the color settings to a file, use the Save button.\n"
00121   "* To read saved color settings from a file, use the Load button.\n"
00122   "* Set environment variable AFNI_TTRR_SETUP to the name of a Save\n"
00123   "    color file, and it will be loaded when you first create this\n"
00124   "    control panel.  See README.environment for more details.\n"
00125   "* The Done button closes the control panel, but doesn't change colors.\n"
00126   "\n"
00127   "NOTES:\n"
00128   " * At this time, the Redraw button has no functionality;\n"
00129   "     after you change the color settings in this window, you must\n"
00130   "     force an image redisplay to see the changes.  In the 2D image\n"
00131   "     viewers, you can do this by turning 'See TT Atlas Regions'\n"
00132   "     off and on;  in the volume renderer, you must press the 'Reload'\n"
00133   "     button to force the proper redisplay ('Draw' isn't enough).\n"
00134   " * The region rendering only works if the dataset being drawn in the\n"
00135   "     2D image viewers and/or Render Dataset plugin is in the +tlrc\n"
00136   "     coordinates sytem, and is at 1 mm resolution.\n"
00137   " * The regions used here are derived from the axial slices in the\n"
00138   "     Talairach-Tournoux Atlas.  Since these slices are several mm\n"
00139   "     apart, the resolution of the regions in the I-S direction is\n"
00140   "     fairly crude.  This means that the regions look 'blocky' in\n"
00141   "     sagittal and coronal 2D images, but look smoother in axial images.\n"
00142   " * The Atlas is only useful as a ROUGH guide to determining where you\n"
00143   "     are in any individual brain.  Do not rely exclusively on the Atlas\n"
00144   "     for brain region labeling: you must use your knowledge, skills,\n"
00145   "     and abilities as well.\n"
00146   "\n"
00147   "-- RWCox - July 2001\n"
00148 ;
00149 
00150 /*----------------------------------------------------------------------------*/
00151 
00152 static void TTRR_setup_widgets( MCW_DC * dc )
00153 {
00154    XmString xstr ;
00155    char lbuf[256] , *ept ;
00156    Widget toprc , bar , actar , frame , separator , label ;
00157    int ww,hh,bww , ii ;
00158 
00159 ENTRY("TTRR_setup_widgets") ;
00160 
00161    /**** sanity checks ****/
00162 
00163    if( dc == NULL || ttc != NULL ) EXRETURN ;
00164 
00165    SHOW_AFNI_PAUSE ;
00166 
00167    /**** create output structure ****/
00168 
00169    ttc = myXtNew(TTRR_controls) ; /* will live forever */
00170 
00171    ttc->dc = dc ;
00172 
00173    ttc->av_invert = AFNI_yesenv( "AFNI_TTRR_INVERT" ) ;
00174 
00175    /**** create Shell that can be opened up later ****/
00176 
00177    ttc->shell =
00178       XtVaAppCreateShell(
00179            "AFNI" , "AFNI" , topLevelShellWidgetClass , dc->display ,
00180 
00181            XmNtitle             , "TT Atlas Rendering" , /* top of window */
00182            XmNiconName          , "TT Atlas"           , /* label on icon */
00183 #if 0
00184            XmNmappedWhenManaged , False ,                /* must map it manually */
00185 #endif
00186            XmNdeleteResponse    , XmDO_NOTHING ,         /* deletion handled below */
00187            XmNallowShellResize  , False ,                /* let code resize shell? */
00188            XmNinitialResourcesPersistent , False ,
00189       NULL ) ;
00190 
00191    DC_yokify( ttc->shell , dc ) ;
00192 
00193    if( afni48_good )
00194       XtVaSetValues( ttc->shell ,
00195                         XmNiconPixmap , afni48_pixmap ,
00196                      NULL ) ;
00197 
00198    XmAddWMProtocolCallback(           /* make "Close" window menu work */
00199            ttc->shell ,
00200            XmInternAtom( dc->display , "WM_DELETE_WINDOW" , False ) ,
00201            TTRR_delete_window_CB , (XtPointer) ttc ) ;
00202 
00203    /**** create Form to hold all widgets ****/
00204 
00205    toprc = XtVaCreateWidget(
00206              "AFNI" , xmFormWidgetClass , ttc->shell ,
00207                  XmNborderWidth , 0 ,
00208                  XmNborderColor , 0 ,
00209                   XmNtraversalOn , False ,
00210                  XmNinitialResourcesPersistent , False ,
00211              NULL ) ;
00212 
00213    /**** Label to inform the cretinous user what he's looking at ****/
00214 
00215    xstr = XmStringCreateLtoR("-- Control Talairach Daemon display colors --" ,
00216                              XmFONTLIST_DEFAULT_TAG ) ;
00217    label = XtVaCreateManagedWidget(
00218              "AFNI" , xmLabelWidgetClass ,  toprc ,
00219                 XmNlabelString , xstr ,
00220                 XmNalignment  , XmALIGNMENT_CENTER ,
00221 
00222                 XmNleftAttachment , XmATTACH_FORM ,
00223                 XmNrightAttachment, XmATTACH_FORM ,
00224                 XmNtopAttachment  , XmATTACH_FORM ,
00225                 XmNtopOffset      , 3 ,
00226                 XmNinitialResourcesPersistent , False ,
00227              NULL ) ;
00228    XmStringFree( xstr ) ;
00229 
00230    MCW_widget_geom( label , &ww , &hh , NULL , NULL ) ; /* temporary */
00231    XtVaSetValues( ttc->shell ,
00232                       XmNminWidth  , ww+3  ,
00233                       XmNminHeight , 11*hh ,
00234                   NULL ) ;
00235 
00236    separator = XtVaCreateManagedWidget(
00237                  "AFNI" , xmSeparatorWidgetClass , toprc ,
00238                     XmNseparatorType  , XmSHADOW_ETCHED_IN ,
00239                     XmNshadowThickness, 2 ,
00240                     XmNleftAttachment , XmATTACH_FORM ,
00241                     XmNrightAttachment, XmATTACH_FORM ,
00242                     XmNtopAttachment  , XmATTACH_WIDGET ,
00243                     XmNtopWidget      , label ,
00244                     XmNtopOffset      , 1 ,
00245                  NULL ) ;
00246 
00247    /**** create an action area to hold user control buttons ****/
00248 
00249    for( ii=0 ; ii < NUM_TTRR_ACT ; ii++ )
00250       TTRR_act[ii].data = (XtPointer) ttc ;
00251 
00252    actar = MCW_action_area( toprc , TTRR_act , NUM_TTRR_ACT ) ;
00253 
00254    XtVaSetValues( actar ,
00255                      XmNleftAttachment , XmATTACH_FORM ,
00256                      XmNrightAttachment, XmATTACH_FORM ,
00257                      XmNtopAttachment  , XmATTACH_WIDGET ,
00258                      XmNtopWidget      , separator ,
00259                      XmNtopOffset      , 3 ,
00260                   NULL ) ;
00261 
00262    separator = XtVaCreateManagedWidget(
00263                  "AFNI" , xmSeparatorWidgetClass , toprc ,
00264                     XmNseparatorType  , XmSHADOW_ETCHED_IN ,
00265                     XmNshadowThickness, 2 ,
00266                     XmNleftAttachment , XmATTACH_FORM ,
00267                     XmNrightAttachment, XmATTACH_FORM ,
00268                     XmNtopAttachment  , XmATTACH_WIDGET ,
00269                     XmNtopWidget      , actar ,
00270                     XmNtopOffset      , 1 ,
00271                  NULL ) ;
00272 
00273    /**** a couple of buttons to control operational settings ****/
00274 
00275    ttc->meth_av = new_MCW_optmenu( toprc , "Method" ,
00276                                    0 , NMETHOD-1 , NMETHOD-1 , 0 ,
00277                                    NULL,NULL ,
00278                                    MCW_av_substring_CB, METHOD_strings ) ;
00279 
00280    XtVaSetValues( ttc->meth_av->wrowcol ,
00281                     XmNleftAttachment , XmATTACH_FORM ,
00282                     XmNtopAttachment  , XmATTACH_WIDGET ,
00283                     XmNtopWidget      , separator ,
00284                     XmNtopOffset      , 3 ,
00285                     XmNleftOffset     , 3 ,
00286                  NULL ) ;
00287 
00288    ttc->hemi_av = new_MCW_optmenu( toprc , "Hemisphere(s)" ,
00289                                    0 , NHEMI-1 , NHEMI-1 , 0 ,
00290                                    NULL,NULL ,
00291                                    MCW_av_substring_CB, HEMI_strings ) ;
00292 
00293    XtVaSetValues( ttc->hemi_av->wrowcol ,
00294                     XmNrightAttachment, XmATTACH_FORM ,
00295                     XmNtopAttachment  , XmATTACH_WIDGET ,
00296                     XmNtopWidget      , separator ,
00297                     XmNtopOffset      , 3 ,
00298                     XmNrightOffset    , 3 ,
00299                  NULL ) ;
00300 
00301    separator = XtVaCreateManagedWidget(
00302                  "AFNI" , xmSeparatorWidgetClass , toprc ,
00303                     XmNseparatorType  , XmSHADOW_ETCHED_IN ,
00304                     XmNshadowThickness, 2 ,
00305                     XmNleftAttachment , XmATTACH_FORM ,
00306                     XmNrightAttachment, XmATTACH_FORM ,
00307                     XmNtopAttachment  , XmATTACH_WIDGET ,
00308                     XmNtopWidget      , ttc->meth_av->wrowcol ,
00309                     XmNtopOffset      , 1 ,
00310                  NULL ) ;
00311 
00312    /**** create a Scrolled Window and Form to hold colormenus ****/
00313 
00314    ttc->scrollw =
00315       XtVaCreateWidget(
00316         "AFNI" , xmScrolledWindowWidgetClass ,  toprc ,
00317            XmNscrollingPolicy , XmAUTOMATIC ,
00318            XmNwidth  , ww+2*hh ,                /* temporary */
00319            XmNheight ,    3*hh ,                /* ditto     */
00320            XmNleftAttachment  , XmATTACH_FORM ,
00321            XmNrightAttachment , XmATTACH_FORM ,
00322            XmNtopAttachment   , XmATTACH_WIDGET ,
00323            XmNbottomAttachment, XmATTACH_FORM ,
00324            XmNtopWidget       , separator ,
00325            XmNtopOffset       , 3 ,
00326            XmNtraversalOn , False ,
00327            XmNinitialResourcesPersistent , False ,
00328         NULL ) ;
00329 
00330    frame =
00331       XtVaCreateWidget(
00332         "AFNI" , xmFrameWidgetClass , ttc->scrollw ,
00333             XmNshadowType , XmSHADOW_ETCHED_IN ,
00334             XmNshadowThickness , 5 ,
00335             XmNtraversalOn , False ,
00336             XmNinitialResourcesPersistent , False ,
00337          NULL ) ;
00338 
00339    ttc->workwin =
00340          XtVaCreateWidget(
00341            "AFNI" , xmFormWidgetClass , frame ,
00342               XmNborderWidth , 0 ,
00343               XmNborderColor , 0 ,
00344               XmNtraversalOn , False ,
00345               XmNinitialResourcesPersistent , False ,
00346            NULL ) ;
00347 
00348    /** compute information about regions **/
00349 
00350    ttc->reg_num = 0 ;
00351    for( ii=0 ; ii < TTO_COUNT ; ii++ ){
00352 
00353       if( strncmp(TTO_list[ii].name,"Left  ",6) != 0 ) continue ; /* skip */
00354       if( TTO_list[ii].tdval == 0 )                    continue ; /* skip */
00355 
00356            if( TTO_list[ii].tdlev == 2 ) strcpy(lbuf,"[G] ") ;
00357       else if( TTO_list[ii].tdlev == 4 ) strcpy(lbuf,"[A] ") ;
00358       else                               continue ;               /* skip */
00359 
00360       strcat(lbuf,TTO_list[ii].name+6) ;
00361 
00362       ttc->reg_label [ttc->reg_num] = strdup(lbuf) ;
00363       ttc->reg_tto   [ttc->reg_num] = ii ;
00364       ttc->reg_ttbrik[ttc->reg_num] = (TTO_list[ii].tdlev==2) ? 0 : 1 ;
00365       ttc->reg_ttval [ttc->reg_num] = TTO_list[ii].tdval ;
00366       ttc->reg_ttovc [ttc->reg_num] = 0 ;
00367 
00368       /* only create a few colormenu widgets first,
00369          because XtRealizeWidget() is so slow with many widgets,
00370          and the impatient user is likely to be unhappy with us  */
00371 
00372       if( ttc->reg_num < NUM_AV_FIRST ){
00373          ttc->reg_av[ttc->reg_num] =
00374             new_MCW_colormenu(
00375                ttc->workwin ,                 /* parent */
00376                ttc->reg_label[ttc->reg_num] , /* label  */
00377                dc ,                           /* display context */
00378                0 ,                            /* first color */
00379                dc->ovc->ncol_ov - 1 ,         /* last color */
00380                0 ,                            /* initial color */
00381                TTRR_av_CB,NULL                /* callback func,data */
00382             ) ;
00383 
00384          XtVaSetValues( ttc->reg_av[ttc->reg_num]->wrowcol ,
00385                          XmNleftAttachment   , XmATTACH_FORM ,
00386                          XmNtopAttachment    , (ttc->reg_num==0)
00387                                                 ? XmATTACH_FORM     /* 1st row */
00388                                                 : XmATTACH_WIDGET , /* 2nd+ row */
00389                          XmNtopWidget        , (ttc->reg_num==0)
00390                                                 ? NULL
00391                                                 : ttc->reg_av[ttc->reg_num-1]->wrowcol ,
00392                          XmNrightAttachment  , XmATTACH_FORM ,
00393                         NULL ) ;
00394       }
00395 
00396       ttc->reg_num++ ;
00397    }
00398 
00399    /* manage the managers */
00400 
00401    XtManageChild( ttc->workwin ) ;
00402    XtManageChild( frame ) ;
00403    XtManageChild( ttc->scrollw ) ;
00404    XtManageChild( toprc ) ;
00405    XtRealizeWidget( ttc->shell ) ;
00406 
00407    WATCH_cursorize( ttc->shell ) ;
00408    XmUpdateDisplay( ttc->shell ) ;
00409 
00410    /*** set size ***/
00411 
00412 #define LUCK   5  /* we all need some */
00413 #define CMMAX 17  /* vertical size = CMMAX colormenus high */
00414 
00415    MCW_widget_geom( ttc->reg_av[0]->wrowcol , &ww , &hh , NULL,NULL ) ;
00416 
00417    XtVaGetValues( ttc->scrollw , XmNverticalScrollBar , &bar , NULL ) ;
00418    MCW_widget_geom( bar , &bww , NULL,NULL,NULL ) ;
00419 
00420    hh  = CMMAX*hh + LUCK ;
00421    ww += bww + 5*LUCK ;
00422 
00423    /* but make sure window is at least wide
00424       enough for the Method and Hemisphere(s) widgets */
00425 
00426    MCW_widget_geom( ttc->meth_av->wrowcol , &ii  , NULL,NULL,NULL ) ;
00427    MCW_widget_geom( ttc->hemi_av->wrowcol , &bww , NULL,NULL,NULL ) ;
00428    bww += ii + LUCK ;
00429    if( ww < bww ) ww = bww ;
00430 
00431    XtVaSetValues( ttc->shell , XmNwidth , ww , XmNheight , hh , NULL ) ;
00432    XmUpdateDisplay( ttc->shell ) ;
00433 
00434    /*** create rest of colormenu widgets now
00435         -- this provides some visual feedback, and keeps the user happy ***/
00436 
00437    for( ii=NUM_AV_FIRST ; ii < ttc->reg_num ; ii++ ){
00438       ttc->reg_av[ii] =
00439          new_MCW_colormenu(
00440             ttc->workwin ,                 /* parent */
00441             ttc->reg_label[ii] ,           /* label  */
00442             dc ,                           /* display context */
00443             0 ,                            /* first color */
00444             dc->ovc->ncol_ov - 1 ,         /* last color */
00445             0 ,                            /* initial color */
00446             NULL,NULL                      /* callback func,data */
00447          ) ;
00448 
00449       XtVaSetValues( ttc->reg_av[ii]->wrowcol ,
00450                       XmNleftAttachment   , XmATTACH_FORM ,
00451                       XmNtopAttachment    , XmATTACH_WIDGET ,
00452                       XmNtopWidget        , ttc->reg_av[ii-1]->wrowcol ,
00453                       XmNrightAttachment  , XmATTACH_FORM ,
00454                      NULL ) ;
00455 
00456       XtRealizeWidget( ttc->reg_av[ii]->wrowcol ) ;
00457 
00458       if( ii%NUM_AV_FIRST == 0 )          /* show something occasionally */
00459          XmUpdateDisplay( ttc->shell ) ;
00460    }
00461 
00462    PLUTO_cursorize( ttc->shell ) ;
00463 
00464    /* 08 Aug 2002: read initial colors */
00465 
00466    ept = getenv( "AFNI_TTRR_SETUP" ) ;
00467    if( ept != NULL ) TTRR_load_file( ept ) ;
00468 
00469    /*** done!!! ***/
00470 
00471    SHOW_AFNI_READY ; EXRETURN ;
00472 }
00473 
00474 /*-----------------------------------------------------------------------
00475    Called to actually see the damn thing
00476 -------------------------------------------------------------------------*/
00477 
00478 void TTRR_popup( Three_D_View * im3d )
00479 {
00480 ENTRY("TTRR_popup") ;
00481 
00482    if( ttc == NULL ) TTRR_setup_widgets( im3d->dc ) ;
00483 
00484    ttc->im3d = im3d ;
00485    XtMapWidget( ttc->shell ) ;
00486 
00487    EXRETURN ;
00488 }
00489 
00490 /*------------------------------------------------------------------------
00491    What happens when a colormenu item is selected
00492 --------------------------------------------------------------------------*/
00493 
00494 static void TTRR_av_CB( MCW_arrowval * av , XtPointer cd )
00495 {
00496    if( !ttc->av_invert || av == NULL || av->ival == av->old_ival ) return ;
00497 
00498    if( av->ival == 0 ||
00499        (av->ival != 0 && av->old_ival == 0) ) MCW_invert_widget(av->wrowcol);
00500 
00501    return ;
00502 }
00503 
00504 /*------------------------------------------------------------------------
00505    What happens when an action button is pressed
00506 --------------------------------------------------------------------------*/
00507 
00508 static void TTRR_action_CB( Widget w , XtPointer cd , XtPointer cbs )
00509 {
00510    char * wname = XtName(w) ;
00511    int ii ;
00512 
00513 ENTRY("TTRR_action_CB") ;
00514 
00515    if( strcmp(wname,TTRR_help_label) == 0 ){
00516 
00517       new_MCW_textwin( w , helpstring , TEXT_READONLY ) ;
00518 
00519    } else if( strcmp(wname,TTRR_done_label) == 0 ){
00520 
00521       TTRR_delete_window_CB(NULL,NULL,NULL) ;
00522 
00523    } else if( strcmp(wname,TTRR_clear_label) == 0 ){
00524 
00525       /* restore colormenus to 'none' status */
00526 
00527       for( ii=0 ; ii < ttc->reg_num ; ii++ ){
00528          if( ttc->reg_av[ii]->ival != 0 ){
00529             AV_assign_ival( ttc->reg_av[ii] , 0 ) ;
00530 
00531             if( ttc->av_invert && ttc->reg_av[ii]->old_ival != 0 )
00532                MCW_invert_widget(ttc->reg_av[ii]->wrowcol);
00533          }
00534       }
00535 
00536    } else if( strcmp(wname,TTRR_redraw_label) == 0 ){
00537 
00538       BEEPIT ;
00539 
00540    } else if( strcmp(wname,TTRR_load_label) == 0 ){
00541 
00542       MCW_choose_string( w , "Filename to load" , NULL ,
00543                              TTRR_load_CB , NULL ) ;
00544 
00545    } else if( strcmp(wname,TTRR_save_label) == 0 ){
00546 
00547       MCW_choose_string( w , "Filename to save" , NULL ,
00548                              TTRR_save_CB , NULL ) ;
00549    }
00550 
00551    EXRETURN ;
00552 }
00553 
00554 /*------------------------------------------------------------------------
00555    What happens when the user selects "Close" from the window
00556    menu in a plugin interface menu window
00557 --------------------------------------------------------------------------*/
00558 
00559 static void TTRR_delete_window_CB( Widget w , XtPointer cd , XtPointer cbs )
00560 {
00561 ENTRY("TTRR_delete_window_CB") ;
00562 
00563    if( ttc != NULL ){
00564       XtUnmapWidget(ttc->shell) ;   /* just hide the window */
00565       XmUpdateDisplay(ttc->shell) ; /* (it's too hard to re-create) */
00566    }
00567    EXRETURN ;
00568 }
00569 
00570 /*------------------------------------------------------------------------
00571    Return the current state of the TT atlas colors in a static
00572    struct (i.e., do NOT free() this!).
00573 --------------------------------------------------------------------------*/
00574 
00575 static TTRR_params *ttp = NULL ;
00576 
00577 TTRR_params * TTRR_get_params(void)
00578 {
00579    int ii,jj ;
00580 
00581 ENTRY("TTRR_get_params") ;
00582 
00583    if( ttc == NULL ) RETURN(NULL) ;  /* report nothing */
00584 
00585    if( ttc->meth_av->ival == TTRR_METH_OFF ) RETURN(NULL) ;
00586 
00587    /* 1st time in: make reporting struct */
00588 
00589    if( ttp == NULL ){
00590       ttp = myXtNew(TTRR_params) ;
00591       ttp->ttbrik = (byte *) malloc(sizeof(byte)*ttc->reg_num) ;
00592       ttp->ttval  = (byte *) malloc(sizeof(byte)*ttc->reg_num) ;
00593       ttp->ttovc  = (byte *) malloc(sizeof(byte)*ttc->reg_num) ;
00594    }
00595 
00596    /* set method codes */
00597 
00598    ttp->meth = ttc->meth_av->ival ;
00599    ttp->hemi = ttc->hemi_av->ival ;  /* hemisphere */
00600 
00601    /* make list of all 'on' regions */
00602 
00603    for( ii=jj=0 ; ii < ttc->reg_num ; ii++ ){
00604       ttc->reg_ttovc[ii] = ttc->reg_av[ii]->ival ;
00605       if( ttc->reg_ttovc[ii] > 0 ){
00606          ttp->ttbrik[jj] = (byte) ttc->reg_ttbrik[ii] ;
00607          ttp->ttval [jj] = (byte) ttc->reg_ttval [ii] ;
00608          ttp->ttovc [jj] = (byte) ttc->reg_ttovc [ii] ;
00609          jj++ ;
00610       }
00611    }
00612 
00613    ttp->num = jj ;  /* number of 'on' regions */
00614    RETURN(ttp) ;
00615 }
00616 
00617 /*----------------------------------------------------------------------*/
00618 
00619 static void TTRR_load_file( char * fname )  /* 08 Aug 2002 */
00620 {
00621   FILE *fp = fopen(fname,"r") ;
00622 
00623 #define NLBUF 1024
00624   if( fp != NULL ){
00625     char lbuf[NLBUF], **stok , *name, *color, *ept ;
00626     int ns , ic , ii ;
00627 
00628     while(1){
00629       ept = fgets( lbuf , NLBUF , fp ) ;              /* get line */
00630       if( ept == NULL ) break ;                    /* end of file */
00631       stok = NULL ;
00632       ns = breakup_string( lbuf , &stok ) ;        /* break it up */
00633       if( ns <= 0 || stok == NULL ) continue ;            /* skip */
00634       if( ns == 1 ){ freeup_strings(ns,stok); continue; } /* skip */
00635       if( stok[0][0] == '#' ||
00636           (stok[0][0] == '/' && stok[0][1] == '/') )
00637                    { freeup_strings(ns,stok); continue; } /* skip */
00638       name = stok[0] ;                             /* region name */
00639       if( ns == 2 ) color = stok[1] ;       /* overlay color name */
00640       else          color = stok[2] ;
00641       ic = DC_find_overlay_color( ttc->dc , color ) ;
00642       if( ic < 0 ){ freeup_strings(ns,stok); continue; } /* skip */
00643 
00644       /* find region name in list; assign color to menu */
00645 
00646       for( ii=0 ; ii < ttc->reg_num ; ii++ ){
00647         if( ig_strstr( ttc->reg_label[ii], name, "._ " ) != NULL ){
00648           AV_assign_ival( ttc->reg_av[ii] , ic ) ;
00649         }
00650       }
00651 
00652       freeup_strings(ns,stok) ;
00653     }
00654 
00655     fclose(fp) ;  /* done with file */
00656   }
00657 
00658   return ;
00659 }
00660 
00661 /*------------------------------------------------------------------*/
00662 
00663 
00664 static void TTRR_load_CB( Widget w , XtPointer cd , MCW_choose_cbs * cbs )
00665 {
00666    if( cbs->reason != mcwCR_string ||
00667        cbs->cval == NULL           || strlen(cbs->cval) == 0 ){
00668 
00669       PLUTO_beep() ; return ;
00670    }
00671 
00672    if( !THD_is_file(cbs->cval) ){ PLUTO_beep(); return; }
00673 
00674    TTRR_load_file( cbs->cval ) ; return ;
00675 }
00676 
00677 /*------------------------------------------------------------------*/
00678 
00679 static void TTRR_save_CB( Widget w , XtPointer cd , MCW_choose_cbs * cbs )
00680 {
00681    int ii , qq , jj ;
00682    FILE *fp ;
00683    char name[128] , *color ;
00684 
00685    if( cbs->reason != mcwCR_string ||
00686        cbs->cval == NULL           || strlen(cbs->cval) == 0 ){
00687 
00688       PLUTO_beep() ; return ;
00689    }
00690 
00691    fp = fopen( cbs->cval , "w" ) ;
00692    if( fp == NULL ){ PLUTO_beep(); return; }
00693 
00694    for( ii=0 ; ii < ttc->reg_num ; ii++ ){
00695      color = ttc->dc->ovc->label_ov[ttc->reg_av[ii]->ival] ;
00696      qq = (ttc->reg_label[ii][0] == '[') ? 4 : 0 ;
00697      strcpy(name,ttc->reg_label[ii]+qq) ;
00698      qq = strlen(name) ;
00699      for( jj=0 ; jj < qq ; jj++ ){
00700             if( name[jj] == '.'   ) name[jj] = ' ' ;
00701        else if( name[jj] == ' '   ) name[jj] = '_' ;
00702      }
00703      fprintf(fp, "%s = %s\n",name,color) ;
00704    }
00705    fclose(fp) ; return ;
00706 }
 

Powered by Plone

This site conforms to the following standards: