~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/mono/mono_tool.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* mono_tool.c
  2  *
  3  * Modification: 16-Sep-99 by IH, DICOM button added
  4  * 
  5  * most basic tv_screen level code for managing mono resources and data
  6  * structures.
  7  * 
  8  * deals with file based i/o as well as display selection
  9  * 
 10  */
 11 
 12 #include <stdio.h>
 13 #include <sys/param.h>
 14 #include <string.h>
 15 #include <tina/sys.h>
 16 #include <tina/sysfuncs.h>
 17 #include <tina/math.h>
 18 #include <tina/mathfuncs.h>
 19 #include <tina/vision.h>
 20 #include <tina/visionfuncs.h>
 21 #include <tina/file.h>
 22 #include <tina/filefuncs.h>
 23 #include <tina/file_gen.h>
 24 #include <tina/tv.h>
 25 #include <tina/tvfuncs.h>
 26 #include <tina/toolsfuncs.h>
 27 #include <tina/tw_Xfuncs.h>
 28 
 29 /* EXTERNS  */
 30 extern void tw_show_tool();
 31 extern void *tw_tool();
 32 
 33 /*
 34 #define AIFF_FILE  0
 35 #define PGM_FILE   1
 36 #define RAD_FILE   2
 37 #define EDGE_FILE  3
 38 #define POLY_FILE  4
 39 #define CAMERA     5
 40 #define WISP       6
 41 #define RAS        7
 42 #define GIF        8
 43 #define RAW_FILE   9
 44 */
 45 
 46 
 47 /* STATIC GLOBALS */
 48 static char directory_name[MAXPATHLEN];
 49 static char base_name[MAXPATHLEN];
 50 static char file_name[MAXPATHLEN];
 51 static void *pdir=NULL, *pfile=NULL;
 52 static int file_type = 0;
 53 static void *pframe;
 54 static int fnum = 0;
 55 
 56 /* CALLBACK FUNCTIONS */
 57 
 58 static void    mono_draw(Tv *tv)
 59 {
 60     if(tv!=NULL)
 61     {
 62         tv_free_background(tv);
 63         tv_repaint(tv);
 64     }
 65 }
 66 
 67 static void tv_proc(void)
 68 {
 69     mono_tv_set(mono_tv_make());
 70     tv_set_next(mono_tv());
 71 }
 72 
 73 
 74 /* Push / Pop callbacks */
 75 static void push_proc(void)
 76 {
 77     Imrect *im;
 78 
 79     im = im_copy(mono_image());
 80     stack_push((void *) im, IMRECT, im_free);
 81     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
 82     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
 83     image_choice_reset();
 84 }
 85 
 86 static void pop_proc(void)
 87 {
 88     int     type;
 89 
 90     if (stack_check_types(IMRECT, NULL) == false)
 91         if (stack_check_types(EDGERECT, NULL) == false)
 92             error("pop_proc: wrong type on stack", warning);
 93         else
 94             mono_edges_set((Imrect *) stack_pop(&type)); 
 95     else
 96         mono_image_set((Imrect *) stack_pop(&type));
 97     mono_draw(mono_tv_get());
 98     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
 99     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
100     image_choice_reset();
101 }
102 
103 /* Mouse function callbacks */
104 static void mono_mouse_proc(Tv_mouse(*func) ( /* ??? */ ))
105 {
106     tv_set_mouse(mono_tv(), (*func) ());
107     (void) tv_set_activity(mono_tv(), MOUSE);
108 }
109 
110 /* Mono check callback */
111 #define IMAGE_MASK  1
112 #define EDGE_MASK   2
113 #define CORNER_MASK 4
114 #define STRING_MASK 8
115 #define POLY_MASK   16
116 #define OTHER_MASK  32
117 
118 static void mono_check_proc(int val)
119 {
120     mono_image_on((Bool) (val & IMAGE_MASK));
121     mono_edges_on((Bool) (val & EDGE_MASK));
122     mono_corners_on((Bool) (val & CORNER_MASK));
123     mono_strings_on((Bool) (val & STRING_MASK));
124     mono_poly_on((Bool) (val & POLY_MASK));
125 }
126 
127 /* Choice item callbacks */
128 
129 /* File choice callback */
130 static void file_choice_proc(int val)
131 {
132     file_type = val;
133 }
134 
135 /* input / output callbacks */
136 static void input_proc(void)
137 {
138     char  *pfname[1];
139     
140     parse_fname(base_name, file_name, fnum);
141     *pfname = file_name;
142     if (strchr(file_name, '*') && !fname_resolve(directory_name, file_name, pfname))
143     {
144        error("mono input: no such file or filename", warning);
145        return;
146     }
147     mono_input(directory_name, *pfname, file_type);
148     mono_draw(mono_tv_get());
149 }
150 
151 static void output_proc(void)
152 {
153     parse_fname(base_name, file_name, fnum);
154     if (strchr(file_name, '*'))
155     {
156       error("mono output: cannot output to wildcard name", warning);
157       return;
158     }
159     mono_output(directory_name, file_name, file_type);
160 }
161 
162 
163 /* Tv list choice proc */
164 /* ARGSUSED quieten lint */
165 static void tv_choice_proc(int val)
166 {
167     tv_set_next(mono_tv());
168 }
169 
170 static void inc_fnum_proc(void)
171 {
172   fnum++;
173   tw_iglobal_reset(pframe);
174 }
175 
176 static void dec_fnum_proc(void)
177 {
178   fnum--;
179   tw_iglobal_reset(pframe);
180 }
181 
182 void scan_files(char *dir, char *file)
183 {
184    int i=0;
185    FILE *fp;
186    char temp[MAXPATHLEN], last[MAXPATHLEN];
187 
188    (void) strip_spaces(file);
189    (void) strip_spaces(dir);
190 
191    if (strcmp(file,"")==0)
192    {
193      sprintf(temp,"ls -d %s* > dirconts.tmp \n",dir);
194      system(temp);
195      if ((fp = fopen("dirconts.tmp", "r")) != NULL)
196      {
197        while (freadline(fp, temp)!=EOF)
198        {
199            format("%s \n",temp);
200            strcpy(last,temp);
201            i++;
202        }
203        fclose(fp);
204        if (i==1) strcpy(dir,last);
205      }
206    }
207    else
208    {
209      sprintf(temp,"ls %s* > dirconts.tmp \n",dir);
210      system(temp);
211      if ((fp = fopen("dirconts.tmp", "r")) != NULL)
212      {
213        while (freadline(fp, temp)!=EOF)
214        {
215            if (strncmp(temp,file, strlen(file))==0)
216            {
217              format("%s \n",temp);
218              strcpy(last,temp);
219              i++;
220            }
221        }
222        fclose(fp);
223        if (i==1) strcpy(file,last);
224      }
225    }
226    system("rm dirconts.tmp");
227 }
228 
229 static void scan_proc(void)
230 {
231    scan_files(directory_name, base_name);
232    tw_sglobal_reset(pdir);
233    tw_sglobal_reset(pfile);
234 }
235 
236 
237 /* Tool creation */
238 void    mono_tool(int x, int y)
239 {
240     Tv_mouse null_mouse();
241     Tv_mouse pos_mouse();
242     Tv_mouse mono_grey_mouse();
243     Tv_mouse pixel_mouse();
244 
245     static void *tv_screen = NULL;
246 
247     if (tv_screen)
248     {
249         tw_show_tool(tv_screen);
250         return;
251     }
252     /* Initialise pathname from environment variable (or #define) */
253     (void) environ_pathname_get(directory_name, base_name,
254                                 "TINA_IMAGE_DEFAULT",
255                                 TINA_IMAGE_DEFAULT_PATHNAME);
256     /* (void) strcat(base_name, ".l");  perhaps not */
257 
258     tv_proc();
259 
260     tv_screen = tw_tool("Mono Tool", x, y);
261 
262 
263     tw_choice("Tv : ", tv_choice_proc, 0, "mono", NULL);
264 
265     tw_menubar("Mouse: ",
266                "mono",
267                "null", mono_mouse_proc, null_mouse,
268                "pos", mono_mouse_proc, pos_mouse,
269                "grey", mono_mouse_proc, mono_grey_mouse,
270                "pixel", mono_mouse_proc, pixel_mouse,
271                NULL,
272                NULL);
273 
274     tw_label("                   ");
275     tw_help_button("mono_tool");
276 
277     tw_newrow();
278 
279     tw_check("Mono:       ", mono_check_proc, 1,
280              "image", "edges", "corner", "strings", "geom",
281              NULL);
282 
283     tw_newrow();
284 
285     tw_choice("File:", file_choice_proc, 0,
286               "AIFF", "PGM", "RAD", "EDGE", "POLY", "CAM", "WISP",
287               "RAS", "GIF", "DICOM", NULL);
288 
289     tw_newrow();
290 
291     tw_button("input", input_proc, NULL);
292     tw_button("output", output_proc, NULL);
293     pframe = (void *)tw_iglobal(" Frame Number (#):", &fnum, 5);
294     tw_button("<", dec_fnum_proc, NULL);
295     tw_button(">", inc_fnum_proc, NULL);
296 
297     tw_newrow();
298 
299     pdir = (void *) tw_sglobal("Directory Name:", directory_name, 32);
300     tw_button("scan", scan_proc, NULL);
301 
302     tw_newrow();
303 
304     pfile = (void *) tw_sglobal("Base Name:     ", base_name, 32);
305 
306     tw_newrow();
307 
308     tw_button("push", push_proc, NULL);
309     tw_button("pop", pop_proc, NULL);
310 
311     tw_end_tool();
312 }
313 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.