File: raytrace.c

package info (click to toggle)
viewmol 2.4.1-13
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,212 kB
  • ctags: 2,054
  • sloc: ansic: 30,727; python: 1,849; sh: 921; awk: 433; makefile: 205
file content (108 lines) | stat: -rw-r--r-- 3,743 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
*                                                                              *
*                                   Viewmol                                    *
*                                                                              *
*                             R A Y T R A C E . C                              *
*                                                                              *
*                 Copyright (c) Joerg-R. Hill, October 2003                    *
*                                                                              *
********************************************************************************
*
* $Id: raytrace.c,v 1.6 2003/11/07 11:13:07 jrh Exp $
* $Log: raytrace.c,v $
* Revision 1.6  2003/11/07 11:13:07  jrh
* Release 2.4
*
*
* Revision 1.5  2000/12/10 15:14:42  jrh
* Release 2.3
*
* Revision 1.4  1999/05/24 01:27:05  jrh
* Release 2.2.1
*
* Revision 1.3  1999/02/07 21:55:23  jrh
* Release 2.2
*
* Revision 1.2  1998/01/26 00:49:09  jrh
* Release 2.1
*
* Revision 1.1  1996/12/10  18:43:29  jrh
* Initial revision
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<X11/Intrinsic.h>
#include<Xm/Xm.h>
#include "viewmol.h"
#include "dialog.h"

extern char *getStringResource(Widget, char *);
extern void GetMessageBoxButton(Widget, XtPointer, caddr_t);
extern char *selectFile(char *, char *, int);
extern int messgb(Widget, int, char *, struct PushButtonRow *, int);
extern char *saveVectorFile(int, char *, int);
extern int runProg(char *, int, char *, char *, char *, pid_t *);
extern int checkFile(char **);

extern Widget topShell;
extern struct WINDOW windows[];
extern pid_t raypid;
extern char raytracer[], displayImage[];

void raytrace(Widget widget, caddr_t data1, caddr_t data2)
{
  static struct PushButtonRow buttons1[] = {{"continue", GetMessageBoxButton, (XtPointer)0, NULL},
                                            {"cancel", GetMessageBoxButton, (XtPointer)1, NULL}};
  static struct PushButtonRow buttons2[] = {{"doRaytracing", GetMessageBoxButton, (XtPointer)0, NULL},
                                            {"stopRaytracing", GetMessageBoxButton, (XtPointer)1, NULL}};
  static struct PushButtonRow buttons3[] = {{"continue", GetMessageBoxButton, (XtPointer)0, NULL}};
  static char *rayfile="vm_image.ray";
  Dimension width, height;
  pid_t pid;
  char line[MAXLENLINE];
  char pngfile[MAXLENLINE], *dot;

  if ((rayfile=selectFile("*", rayfile, TRUE)) == NULL) return;
  saveVectorFile(VIEWER, rayfile, RAYTRACER);
  strcpy(pngfile, rayfile);
  if ((dot=strrchr(pngfile,'.')) != NULL)
    strcpy(dot, ".png");
  else
    strcat(pngfile, ".png");
  if (!access(pngfile, F_OK))
  {
    dot=getStringResource(topShell, "FileExists");
    sprintf(line, dot, pngfile);
    if (messgb(topShell, 1, line, buttons1, 2) == 1) return;
  }

  if (*raytracer != '\0')
  {
    if (*displayImage == '\0')
    {
      dot=getStringResource(topShell, "noDisplay");
      if (messgb(topShell, 3, dot, buttons2, 2) == 1) return;
    }
    if ((raypid=fork()) == (pid_t)0)
    {
	XtVaGetValues(windows[VIEWER].widget, XmNwidth, &width, XmNheight, &height, NULL);
      sprintf(line, raytracer, rayfile, pngfile, width, height);
      runProg(line, TRUE, NULL, NULL, "/dev/null", &pid);
/*    runProg(raytracer, TRUE, rayfile, pngfile, "/dev/null", &pid);*/
      if (*displayImage != '\0')
      {
        sprintf(line, displayImage, pngfile);
        runProg(line, FALSE, NULL, NULL, "/dev/null", &pid);
      }
      exit(0);
    }
  }
  else
  {
    dot=getStringResource(topShell, "noRayshade");
    messgb(topShell, 3, dot, buttons3, 1);
  }
}