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-2008, Gabriel Dos Reis.
5
All right 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 _GRAPH2D_C
37
#include "openaxiom-c-macros.h"
38
39
#include <stdio.h>
40
#include <unistd.h>
41
#include <stdlib.h>
42
43
#include "header2.h"
44
45
#include "all_2d.H1"
46
#include "util.H1"
47
48
49
void
50
getGraphFromViewman(int i)
51
{
52
/** This routine should be called right after a read of the graph key
53
was made from the viewport manager (or defined in some other way). **/
54
55
int j,k,xPointsNeeded;
56
pointListStruct *llPtr;
57
pointStruct *p;
58
59
readViewman(&(graphArray[i].xmin),floatSize);
60
readViewman(&(graphArray[i].xmax),floatSize);
61
readViewman(&(graphArray[i].ymin),floatSize);
62
readViewman(&(graphArray[i].ymax),floatSize);
63
readViewman(&(graphArray[i].xNorm),floatSize);
64
readViewman(&(graphArray[i].yNorm),floatSize);
65
readViewman(&(graphArray[i].spadUnitX),floatSize);
66
readViewman(&(graphArray[i].spadUnitY),floatSize);
67
readViewman(&(graphArray[i].unitX),floatSize);
68
readViewman(&(graphArray[i].unitY),floatSize);
69
readViewman(&(graphArray[i].originX),floatSize);
70
readViewman(&(graphArray[i].originY),floatSize);
71
readViewman(&(graphArray[i].numberOfLists),intSize);
72
73
if (!(llPtr = (pointListStruct *)malloc(graphArray[i].numberOfLists * sizeof(pointListStruct)))) {
74
fprintf(stderr,"VIEW2D: Fatal Error>> Ran out of memory trying to receive a graph.\n");
75
exitWithAck(RootWindow(dsply,scrn),Window,-1);
76
}
77
graphArray[i].listOfListsOfPoints = llPtr;
78
79
xPointsNeeded = 0;
80
for (j=0; j<graphArray[i].numberOfLists; j++) {
81
readViewman(&(llPtr->numberOfPoints),intSize);
82
if (!(p = (pointStruct *)malloc(llPtr->numberOfPoints * sizeof(pointStruct)))) {
83
fprintf(stderr,"VIEW2D: (pointStruct) ran out of memory trying to create a new graph.\n");
84
exitWithAck(RootWindow(dsply,scrn),Window,-1);
85
}
86
llPtr->listOfPoints = p; /** point to current point list **/
87
for (k=0; k<llPtr->numberOfPoints; k++) {
88
readViewman(&(p->x),floatSize);
89
readViewman(&(p->y),floatSize);
90
readViewman(&(p->hue),floatSize);
91
readViewman(&(p->shade),floatSize);
92
p++;
93
} /* for k in list of points */
94
readViewman(&(llPtr->pointColor),intSize);
95
readViewman(&(llPtr->lineColor),intSize);
96
readViewman(&(llPtr->pointSize),intSize);
97
98
xPointsNeeded += llPtr->numberOfPoints;
99
llPtr++;
100
} /* for j in list of lists of points */
101
102
/* read in graph state for the existing graph (override default values) */
103
readViewman(&(graphStateArray[i].scaleX),floatSize);
104
readViewman(&(graphStateArray[i].scaleY),floatSize);
105
readViewman(&(graphStateArray[i].deltaX),floatSize);
106
readViewman(&(graphStateArray[i].deltaY),floatSize);
107
readViewman(&(graphStateArray[i].pointsOn),intSize);
108
readViewman(&(graphStateArray[i].connectOn),intSize);
109
readViewman(&(graphStateArray[i].splineOn),intSize);
110
readViewman(&(graphStateArray[i].axesOn),intSize);
111
readViewman(&(graphStateArray[i].axesColor),intSize);
112
readViewman(&(graphStateArray[i].unitsOn),intSize);
113
readViewman(&(graphStateArray[i].unitsColor),intSize);
114
readViewman(&(graphStateArray[i].showing),intSize);
115
graphStateArray[i].selected = yes;
116
graphStateBackupArray[i] = graphStateArray[i];
117
118
graphStateArray[i].deltaX = graphStateArray[0].deltaX;
119
graphStateArray[i].deltaY = graphStateArray[0].deltaY;
120
graphStateArray[i].scaleX = graphStateArray[0].scaleX;
121
graphStateArray[i].scaleY = graphStateArray[0].scaleY;
122
123
/* allocate memory for xPoints (used in drawViewport) */
124
if (!(xPointsArray[i].xPoint = (XPoint *)malloc(xPointsNeeded * sizeof(XPoint)))) {
125
fprintf(stderr,"VIEW2D: (XPoint) Ran out of memory (malloc) trying to create a new graph.\n");
126
exitWithAck(RootWindow(dsply,scrn),Window,-1);
127
}
128
if (!(xPointsArray[i].x10Point = (Vertex *)malloc(xPointsNeeded * sizeof(Vertex)))) {
129
fprintf(stderr,
130
"VIEW2D: (X10Point) Ran out of memory (malloc) trying to create a new graph.\n");
131
exitWithAck(RootWindow(dsply,scrn),Window,-1);
132
}
133
if (!(xPointsArray[i].arc = (XArc *)malloc(xPointsNeeded * sizeof(XArc)))) {
134
fprintf(stderr,"VIEW2D: (XArc) Ran out of memory (malloc) trying to create a new graph.\n");
135
exitWithAck(RootWindow(dsply,scrn),Window,-1);
136
}
137
138
} /* getGraphFromViewman */
139
140
141
142
void
143
freeGraph(int i)
144
{
145
int j;
146
pointListStruct *llPtr;
147
148
if (graphArray[i].key) {
149
graphArray[i].key = 0; /* 0 means no graph */
150
for (j=0,llPtr=graphArray[i].listOfListsOfPoints;
151
j<graphArray[i].numberOfLists; j++,llPtr++)
152
free(llPtr->listOfPoints);
153
free(graphArray[i].listOfListsOfPoints);
154
free(xPointsArray[i].xPoint);
155
} else {
156
}
157
158
}
159
160