summaryrefslogtreecommitdiff
path: root/plot
diff options
context:
space:
mode:
Diffstat (limited to 'plot')
-rw-r--r--plot/plot.c54
-rw-r--r--plot/plot.h4
-rw-r--r--plot/vrml.c5
-rw-r--r--plot/vrml.h4
4 files changed, 52 insertions, 15 deletions
diff --git a/plot/plot.c b/plot/plot.c
index e3cd5bf..d7b4799 100644
--- a/plot/plot.c
+++ b/plot/plot.c
@@ -120,7 +120,7 @@ static plot_info pd;
static int do_plot_imp(
int flags,
double xmin, double xmax, double ymin, double ymax, /* Bounding box */
- double ratio, /* Aspect ratio of window, X/Y */
+ double ratio, /* Aspect ratio of window, X/Y, 1.0 = nominal */
int dowait, /* > 0 wait for user to hit space key, < 0 delat dowait seconds. */
double *x1, double *x2,
double *yy[MXGPHS], char **ntext,
@@ -369,7 +369,7 @@ int n) { /* Number of values */
xmin = ymin = 1e6;
xmax = ymax = -1e6;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < nn; i++) {
if (xmin > x[i])
xmin = x[i];
if (xmax < x[i])
@@ -433,7 +433,7 @@ int m) {
xmin = ymin = 1e6;
xmax = ymax = -1e6;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < nn; i++) {
if (xmin > x[i])
xmin = x[i];
if (xmax < x[i])
@@ -892,6 +892,8 @@ static int do_plot_imp(
/* ------------------------------------------- */
/* Setup windows stuff */
{
+ ui_UsingGUI();
+
/* It would be nice to reduce number of globals. */
/* We don't clean up properly either - ie. don't delete thread etc. */
@@ -908,11 +910,14 @@ static int do_plot_imp(
}
while (plot_hwnd == NULL)
Sleep(50);
+
+ SetForegroundWindow(plot_hwnd); /* Raise */
}
plot_signal = 0;
- SetForegroundWindow(plot_hwnd);
+ if (dowait > 0)
+ SetForegroundWindow(plot_hwnd); /* Raise */
/* Force a repaint with the new data */
if (!InvalidateRgn(plot_hwnd,NULL,TRUE)) {
@@ -1321,6 +1326,14 @@ static void DoPlot(NSRect *rect, plot_info *pdp);
@end
+/* Function called back by main thread to trigger a drawRect */
+
+static void doSetNeedsDisplay(void *cntx) {
+ cntx_t *cx = (cntx_t *)cntx;
+
+ [cx->view setNeedsDisplay: YES ];
+}
+
// - - - - - - - - - - - - - - - - - - - - - - - - -
@interface PLWin : NSWindow {
@@ -1362,7 +1375,8 @@ static void DoPlot(NSRect *rect, plot_info *pdp);
@end
/* Create our window */
-static void create_my_win(cntx_t *cx) {
+static void create_my_win(void *cntx) {
+ cntx_t *cx = (cntx_t *)cntx;
NSRect wRect;
/* Create Window */
@@ -1491,6 +1505,8 @@ static int do_plot_imp(
pd.o = abs(o);
}
+ ui_UsingGUI();
+
/* If we may be in a different thread to the main thread or */
/* the application thread, establish our own pool. */
NSAutoreleasePool *tpool = nil;
@@ -1511,10 +1527,26 @@ static int do_plot_imp(
if ((plot_cx = (cntx_t *)calloc(sizeof(cntx_t), 1)) == NULL)
error("new_dispwin: Malloc failed (cntx_t)\n");
- create_my_win(plot_cx);
+ /* Prepare to wait for events */
+ ui_aboutToWait();
+
+ /* Run the window creation in the main thread and wait for it */
+ ui_runInMainThreadAndWait((void *)plot_cx, create_my_win);
+
+ /* Wait for events generated by window creation to complete */
+ ui_waitForEvents();
} else { /* Trigger an update */
- [plot_cx->view setNeedsDisplay: YES ];
+// [plot_cx->view setNeedsDisplay: YES ];
+
+ /* Prepare to wait for events */
+ ui_aboutToWait();
+
+ /* Run the window creation in the main thread and wait for it */
+ ui_runInMainThreadAndWait((void *)plot_cx, doSetNeedsDisplay);
+
+ /* Wait for any events generated by paint to complete */
+ ui_waitForEvents();
}
/* (Main thread will service events) */
@@ -1960,6 +1992,8 @@ static int do_plot_imp(
unsigned long myforeground,mybackground;
int done;
+ ui_UsingGUI();
+
/* open the display */
if (mydisplay == NULL) {
mydisplay = XOpenDisplay("");
@@ -2013,8 +2047,10 @@ static int do_plot_imp(
XSendEvent(mydisplay, mywindow, False, ExposureMask, (XEvent *)&ev);
} else {
- XMapRaised(mydisplay,mywindow);
- debugf(("Raised window\n"));
+ if (pd.dowait > 0) {
+ XMapRaised(mydisplay,mywindow);
+ debugf(("Raised window\n"));
+ }
}
/* Main event loop */
diff --git a/plot/plot.h b/plot/plot.h
index 89bf16b..b7d06f7 100644
--- a/plot/plot.h
+++ b/plot/plot.h
@@ -71,7 +71,7 @@ int do_plot10p(double *x, double *y1, double *y2, double *y3, double *y4, double
/* Plot a bunch of vectors + points + optional colored points & notation */
/* return 0 on success, -1 on error */
-/* Vectors are x1, y1 to x2, y2 with 'X' at x2, y3, */
+/* Vectors are x1, y1 to x2, y2 with 'X' at x2, y2, */
/* Colored annotated Crosss at x3, y3. */
int do_plot_vec(double xmin, double xmax, double ymin, double ymax,
double *x1, double *y1, double *x2, double *y2, int n,
@@ -81,7 +81,7 @@ int do_plot_vec(double xmin, double xmax, double ymin, double ymax,
/* Plot a bunch of vectors + points + optional colored points & notation */
/* + optional colored vectors */
/* return 0 on success, -1 on error */
-/* Vectors are x1, y1 to x2, y2 with annotated 'X' at x2, y3, */
+/* Vectors are x1, y1 to x2, y2 with annotated 'X' at x2, y2, */
/* Colored annotated Crosss at x3, y3. */
/* Colored vector from x4, y4 to x5, y5 */
int do_plot_vec2(double xmin, double xmax, double ymin, double ymax,
diff --git a/plot/vrml.c b/plot/vrml.c
index 0121c53..d56e62d 100644
--- a/plot/vrml.c
+++ b/plot/vrml.c
@@ -600,7 +600,9 @@ double cc[3] /* Surface color, cc == NULL or cc[0] < 0.0 */
if (set < 0 || set > 9)
error("vrml make_line_tri_quad set %d out of range",set);
- if (s->set[set].npoints > 0 && s->set[set].tqary[0].ix[2] < 0) /* First is a line */
+ if (s->set[set].npoints > 0
+ && s->set[set].ntrqu > 0
+ && s->set[set].tqary[0].ix[2] < 0) /* First is a line */
lines = 1; /* Assume all are lines */
if (cc != NULL && cc[0] >= 0.0) {
@@ -1745,7 +1747,6 @@ static int do_flush(vrml *s) {
fflush(s->fp);
rv = fclose(s->fp);
-
/* Check that there are the x3dom files with the output file */
if (s->fmt == fmt_x3dom) {
char *xl, *x3name;
diff --git a/plot/vrml.h b/plot/vrml.h
index ff44a6c..d3c86c3 100644
--- a/plot/vrml.h
+++ b/plot/vrml.h
@@ -225,10 +225,10 @@ char *vrml_format();
/* Create a vrml/x3d plot object. */
/* Filename will have appropriate extension added automatically. */
-vrml *new_vrml_vdist(char *name, int doaxes, vrml_space ispace, double vdist);
+vrml *new_vrml(char *name, int doaxes, vrml_space ispace);
/* Same as above but override default Z viewing distance */
-vrml *new_vrml(char *name, int doaxes, vrml_space ispace);
+vrml *new_vrml_vdist(char *name, int doaxes, vrml_space ispace, double vdist);
#define VRML_H