changed reading hint
[gromacs/adressmacs.git] / src / ngmx / filter.c
blob7b74c9ff9f8d09143991611db2b55cd640cbd762
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_filter_c = "$Id$";
31 #include <string.h>
32 #include "sysstuff.h"
33 #include "futil.h"
34 #include "smalloc.h"
35 #include "macros.h"
36 #include "rdgroup.h"
37 #include "xdlghi.h"
38 #include "dialogs.h"
39 #include "index.h"
41 t_filter *init_filter(t_atoms *atoms, char *fn)
43 t_filter *f;
45 snew(f,1);
46 if (fn != NULL)
47 f->grps=init_index(fn,&f->grpnames);
48 else {
49 snew(f->grps,1);
50 snew(f->grps->index,1);
51 analyse(atoms,f->grps,&f->grpnames,FALSE,FALSE);
53 snew(f->bShow,f->grps->nr);
55 return f;
58 static void FilterCB(t_x11 *x11,int dlg_mess,int item_id,
59 char *set,void *data)
61 int nset;
62 t_filter *f;
63 t_gmx *gmx;
64 t_dlg *dlg;
66 gmx=(t_gmx *)data;
67 dlg=gmx->dlgs[edFilter];
68 f=gmx->filter;
70 #ifdef DEBUG
71 printf("item_id: %d, set: %s\n",item_id,set);
72 #endif
73 switch (dlg_mess) {
74 case DLG_SET:
75 if (set)
76 if (sscanf(set,"%d",&nset)==1)
77 f->bShow[nset]=!f->bShow[nset];
78 break;
79 case DLG_EXIT:
80 HideDlg(dlg);
81 write_gmx(x11,gmx,IDDOFILTER);
82 break;
86 t_dlg *select_filter(t_x11 *x11,t_gmx *gmx)
88 static char *title="Group";
89 static char *dummy="\"FALSE\"";
90 static char *ok="\"Ok\"";
91 FILE *tmp;
92 t_dlg *dlg;
93 char tmpfile[L_tmpnam];
94 int i,j,k,len,tlen,ht,ncol,nrow,x0;
96 len=strlen(title);
97 for(i=0; (i<(int)gmx->filter->grps->nr); i++)
98 len=max(len,(int)strlen(gmx->filter->grpnames[i]));
99 len+=2;
101 ncol=1+(gmx->filter->grps->nr / 15);
102 nrow=gmx->filter->grps->nr/ncol;
103 if (nrow*ncol < gmx->filter->grps->nr)
104 nrow++;
105 if (ncol > 1) {
106 ht=1+(nrow+1)*2+3;
108 else {
109 ht=1+(gmx->filter->grps->nr+1)*2+3;
111 tmpnam(tmpfile);
112 #ifdef DEBUG
113 fprintf(stderr,"file: %s\n",tmpfile);
114 #endif
115 tmp=fopen(tmpfile,"w");
116 tlen=1+ncol*(1+len);
117 fprintf(tmp,"grid %d %d {\n\n",tlen,ht);
119 for(k=j=0,x0=1; (j<ncol); j++,x0+=len+1) {
120 fprintf(tmp,"group \"%s-%d\" %d 1 %d %d {\n",title,j+1,x0,len,ht-5);
121 for(i=0; (i<nrow) && (k<gmx->filter->grps->nr); i++,k++)
122 fprintf(tmp,"checkbox \"%s\" \"%d\" %s %s %s\n",
123 gmx->filter->grpnames[k],k,dummy,dummy,dummy);
124 fprintf(tmp,"}\n\n");
126 fprintf(tmp,"simple 1 %d %d 2 {\n",ht-3,tlen-2);
127 fprintf(tmp,"defbutton %s %s %s %s %s\n",ok,ok,dummy,dummy,dummy);
128 fprintf(tmp,"}\n\n}\n");
129 fclose(tmp);
131 dlg=ReadDlg(x11,gmx->wd->self,title,x11->fg,x11->bg,tmpfile,
132 0,0,TRUE,FALSE,FilterCB,gmx);
134 remove(tmpfile);
136 return dlg;