Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define _WRITE2D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdio.h>
40
#include <stdlib.h>
41
42
#include "header2.h"
43
#include "write.h"
44
45
#include "all_2d.H1"
46
#include "pixmap.h"
47
#include "Gfun.H1"
48
49
50
#define numBits (8*sizeof(int))
51
52
int
53
writeViewport(int thingsToWrite)
54
{
55
56
FILE *viewDataFile;
57
char viewDirName[80],
58
viewBitmapFilename[80],viewDataFilename[80],command[80];
59
int i,j,k,ii;
60
pointListStruct *aList;
61
pointStruct *aPoint;
62
XWindowAttributes vwInfo;
63
64
XGetWindowAttributes(dsply,viewport->titleWindow,&vwInfo);
65
sprintf(viewDirName,"%s%s",filename,".VIEW");
66
sprintf(command,"%s%s%s","rm -r ",viewDirName," > /dev/null 2>&1");
67
system(command);
68
sprintf(command,"%s%s%s","mkdir ",viewDirName," > /dev/null 2>&1");
69
if (system(command)) {
70
fprintf(stderr," Error: Cannot create %s\n",viewDirName);
71
return(-1);
72
} else {
73
/*** Create the data file ***/
74
sprintf(viewDataFilename,"%s%s",viewDirName,"/data");
75
if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
76
fprintf(stderr," Error: Cannot create %s\n",viewDataFilename);
77
perror("fopen");
78
return(-1);
79
} else {
80
/*** write out the view2DStruct stuff ***/
81
fprintf(viewDataFile,"%d\n",view2DType);
82
fprintf(viewDataFile,"%s\n",viewport->title);
83
fprintf(viewDataFile,"%d %d %d %d\n",vwInfo.x,vwInfo.y,
84
vwInfo.width,vwInfo.height);
85
for (i=0; i<maxGraphs; i++) {
86
fprintf(viewDataFile,"%d\n",graphArray[i].key);
87
fprintf(viewDataFile,"%g %g\n",
88
graphStateArray[i].scaleX,graphStateArray[i].scaleY);
89
fprintf(viewDataFile,"%g %g\n",
90
graphStateArray[i].deltaX,graphStateArray[i].deltaY);
91
fprintf(viewDataFile,"%g %g\n",
92
graphStateArray[i].centerX,graphStateArray[i].centerY);
93
fprintf(viewDataFile,"%d %d %d %d %d %d %d\n",
94
graphStateArray[i].pointsOn,graphStateArray[i].connectOn,
95
graphStateArray[i].splineOn,
96
graphStateArray[i].axesOn, graphStateArray[i].axesColor,
97
graphStateArray[i].unitsOn, graphStateArray[i].unitsColor);
98
fprintf(viewDataFile,"%d %d\n",
99
graphStateArray[i].showing,graphStateArray[i].selected);
100
}
101
fclose(viewDataFile);
102
for (i=0; i<maxGraphs; i++) {
103
if (graphArray[i].key) {
104
sprintf(viewDataFilename,"%s%s%d",viewDirName,"/graph",i);
105
if ((viewDataFile = fopen(viewDataFilename,"w")) == NULL) {
106
fprintf(stderr," Error: Cannot create %s\n",viewDataFilename);
107
perror("fopen");
108
return(-1);
109
} else {
110
fprintf(viewDataFile,"%g %g %g %g\n",
111
graphArray[i].xmin,graphArray[i].ymin,
112
graphArray[i].xmax,graphArray[i].ymax);
113
fprintf(viewDataFile,"%g %g\n",
114
graphArray[i].xNorm,graphArray[i].yNorm);
115
fprintf(viewDataFile,"%g %g\n",
116
graphArray[i].originX,graphArray[i].originY);
117
fprintf(viewDataFile,"%g %g\n",
118
graphArray[i].spadUnitX,graphArray[i].spadUnitY);
119
fprintf(viewDataFile,"%g %g\n",
120
graphArray[i].unitX,graphArray[i].unitY);
121
fprintf(viewDataFile,"%d\n",graphArray[i].numberOfLists);
122
for (j=0,aList=graphArray[i].listOfListsOfPoints;
123
j<graphArray[i].numberOfLists;
124
j++, aList++) {
125
fprintf(viewDataFile,"%d\n",aList->numberOfPoints);
126
fprintf(viewDataFile,"%d %d %d\n",
127
aList->pointColor,aList->lineColor,aList->pointSize);
128
for (k=0,aPoint=aList->listOfPoints;
129
k<aList->numberOfPoints;
130
k++,aPoint++)
131
fprintf(viewDataFile,"%g %g %g %g\n",
132
aPoint->x,aPoint->y,aPoint->hue,aPoint->shade);
133
} /* for j, aList */
134
fclose(viewDataFile);
135
} /* else graph i */
136
} /* if */
137
} /* for */
138
} /* else */
139
140
/* write out special files */
141
for (ii=1; ii<numBits; ii++) { /* write.h is one-based */
142
if (thingsToWrite & (1<<ii)) {
143
switch (ii) {
144
case Pixmap:
145
/*** Create the pixmap (bitmaps need leaf name) ***/
146
sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.xpm");
147
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
148
write_pixmap_file(dsply,scrn,viewBitmapFilename,
149
viewport->titleWindow,0,0,vwInfo.width,
150
vwInfo.height+titleHeight);
151
break;
152
case Bitmap:
153
/*** Create the bitmap (bitmaps need leaf name) ***/
154
sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.bm");
155
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
156
XWriteBitmapFile(dsply,viewBitmapFilename,
157
viewport->titleWindow,vwInfo.width,
158
vwInfo.height+vwInfo.border_width+20,-1,-1);
159
break;
160
case Image:
161
/*** Create the pixmap (bitmaps need leaf name) ***/
162
sprintf(viewBitmapFilename,"%s%s",viewDirName,"/image.xpm");
163
XResizeWindow(dsply,viewport->titleWindow,300,300+titleHeight);
164
XResizeWindow(dsply,viewport->viewWindow,300,300);
165
XGetWindowAttributes(dsply,viewport->viewWindow,&vwInfo);
166
drawViewport(Xoption);
167
writeTitle();
168
write_pixmap_file(dsply,scrn,viewBitmapFilename,
169
viewport->titleWindow,0,0,vwInfo.width,
170
vwInfo.height+titleHeight);
171
/*** Create the bitmap (bitmaps need leaf name) ***/
172
mono = 1;
173
drawViewport(Xoption);
174
writeTitle();
175
sprintf(viewBitmapFilename,"%s%s%s",viewDirName,"/","image.bm");
176
XWriteBitmapFile(dsply,viewBitmapFilename,
177
viewport->titleWindow,vwInfo.width,
178
vwInfo.height+vwInfo.border_width+20,-1,-1);
179
mono = 0;
180
break;
181
182
case Postscript:
183
/*** Create postscript output for viewport (in axiom2D.ps) ***/
184
sprintf(PSfilename,"%s%s",viewDirName,"/axiom2D.ps");
185
if (PSInit(viewport->viewWindow,viewport->titleWindow) == psError)
186
return (-1);
187
drawViewport(PSoption); /* write new script file in /tmp */
188
if (PSCreateFile(viewBorderWidth,viewport->viewWindow,
189
viewport->titleWindow, viewport->title) == psError)
190
return(-1); /* concat script & proc into axiom2D.ps */
191
break;
192
193
} /* switch on ii */
194
} /* if thingsToWrite >> ii */
195
} /* for ii */
196
197
return(0);
198
} /* else create directory okay */
199
200
}
201
202