aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-02 17:17:45 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2007-10-02 17:17:45 +0000
commit80828d43d4959122c549be8e44b26815bdb61519 (patch)
tree02edf84522e8bdfa095ec822ca25c6b9dcd34102 /src
parent21741980a3499e6d5ef44f27f2ae1d63a51152c7 (diff)
Further DirAx improvements
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@142 bf6ca9ba-c028-0410-8290-897cf20841d1
Diffstat (limited to 'src')
-rw-r--r--src/control.c1
-rw-r--r--src/dirax.c83
-rw-r--r--src/dirax.h1
-rw-r--r--src/displaywindow.c28
-rw-r--r--src/displaywindow.h1
5 files changed, 99 insertions, 15 deletions
diff --git a/src/control.c b/src/control.c
index 032700d..80cf7ce 100644
--- a/src/control.c
+++ b/src/control.c
@@ -54,6 +54,7 @@ ControlContext *control_ctx_new() {
ctx->y_centre = 0;
ctx->have_centres = 0;
ctx->cell = NULL;
+ ctx->dirax = NULL;
return ctx;
diff --git a/src/dirax.c b/src/dirax.c
index 4834ba3..12b68fe 100644
--- a/src/dirax.c
+++ b/src/dirax.c
@@ -106,59 +106,106 @@ static void dirax_sendline(const char *line, ControlContext *ctx) {
int i;
write(ctx->dirax_pty, line, strlen(line));
-
+
copy = strdup(line);
for ( i=0; i<strlen(copy); i++ ) {
if ( copy[i] == '\r' ) copy[i]='\0';
if ( copy[i] == '\n' ) copy[i]='\0';
}
- printf("sent '%s'", copy); /* No newline here */
+ printf("DX: Sent '%s'\n", copy); /* No newline here */
free(copy);
}
+/* Send a "user" command to DirAx, failing if DirAx is not idle */
+static void dirax_sendline_if_idle(const char *line, ControlContext *ctx) {
+
+ if ( ctx->dirax_step != 0 ) {
+ printf("DX: DirAx not idle\n");
+ return;
+ }
+
+ dirax_sendline(line, ctx);
+
+}
static void dirax_send_next(ControlContext *ctx) {
switch ( ctx->dirax_step ) {
- case 0 : {
+ case 1 : {
dirax_sendline("read dtr.drx\n", ctx);
ctx->dirax_step++;
break;
}
- case 1 : {
- dirax_sendline("dmax 50\n", ctx);
+ case 2 : {
+ dirax_sendline("dmax 10\n", ctx);
ctx->dirax_step++;
break;
}
- case 2 : {
- dirax_sendline("indexfit 2\n", ctx);
+ case 3 : {
+ dirax_sendline("indexfit 6\n", ctx);
ctx->dirax_step++;
break;
}
- case 3 : {
+ case 4 : {
dirax_sendline("levelfit 300\n", ctx);
ctx->dirax_step++;
break;
}
- case 4 : {
+ case 5 : {
dirax_sendline("go\n", ctx);
ctx->dirax_step++;
break;
}
- case 5 : {
+ case 6 : {
+ dirax_sendline("cell\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 7 : {
+ dirax_sendline("go\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 8 : {
+ dirax_sendline("cell\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 9 : {
+ dirax_sendline("go\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 10 : {
+ dirax_sendline("cell\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 11 : {
+ dirax_sendline("go\n", ctx);
+ ctx->dirax_step++;
+ break;
+ }
+
+ case 12 : {
dirax_sendline("cell\n", ctx);
ctx->dirax_step++;
break;
}
default: {
- printf("idle");
+ ctx->dirax_step = 0;
}
}
@@ -179,6 +226,7 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro
waitpid(ctx->dirax_pid, NULL, 0);
g_io_channel_shutdown(ctx->dirax, FALSE, NULL);
ctx->dirax = NULL;
+ displaywindow_update_dirax(ctx, ctx->dw);
return FALSE;
} else {
@@ -250,9 +298,8 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro
memmove(ctx->dirax_rbuffer+i, ctx->dirax_rbuffer+i+7, 7);
ctx->dirax_rbufpos -= 7;
- printf("DX: Got prompt: ");
+ printf("DX: Prompt\n");
dirax_send_next(ctx);
- printf("\n");
break;
@@ -287,6 +334,12 @@ static gboolean dirax_readable(GIOChannel *dirax, GIOCondition condition, Contro
}
+void dirax_stop(ControlContext *ctx) {
+
+ dirax_sendline_if_idle("end\n", ctx);
+
+}
+
void dirax_invoke(ControlContext *ctx) {
FILE *fh;
@@ -341,11 +394,13 @@ void dirax_invoke(ControlContext *ctx) {
opts = fcntl(ctx->dirax_pty, F_GETFL);
fcntl(ctx->dirax_pty, F_SETFL, opts | O_NONBLOCK);
- ctx->dirax_step = 0;
+ ctx->dirax_step = 1; /* This starts the "initialisation" procedure */
ctx->dirax_read_cell = 0;
ctx->dirax = g_io_channel_unix_new(ctx->dirax_pty);
g_io_add_watch(ctx->dirax, G_IO_IN | G_IO_HUP, (GIOFunc)dirax_readable, ctx);
+ displaywindow_update_dirax(ctx, ctx->dw);
+
return;
}
diff --git a/src/dirax.h b/src/dirax.h
index b06c6c9..c463561 100644
--- a/src/dirax.h
+++ b/src/dirax.h
@@ -21,6 +21,7 @@
#include "reflections.h"
extern void dirax_invoke(ControlContext *ctx);
+extern void dirax_stop(ControlContext *ctx);
extern ReflectionList *dirax_load(const char *filename);
extern int dirax_is_drxfile(const char *filename);
diff --git a/src/displaywindow.c b/src/displaywindow.c
index 1d3eb20..8899e0b 100644
--- a/src/displaywindow.c
+++ b/src/displaywindow.c
@@ -79,6 +79,10 @@ static void displaywindow_dirax(GtkWidget *widget, DisplayWindow *dw) {
dirax_invoke(dw->ctx);
}
+static void displaywindow_dirax_stop(GtkWidget *widget, DisplayWindow *dw) {
+ dirax_stop(dw->ctx);
+}
+
static void displaywindow_gl_set_ortho(DisplayWindow *dw, GLfloat w, GLfloat h) {
glMatrixMode(GL_PROJECTION);
@@ -173,7 +177,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw) {
{ "ViewAction", NULL, "_View", NULL, NULL, NULL },
{ "ToolsAction", NULL, "_Tools", NULL, NULL, NULL },
- { "DirAxAction", GTK_STOCK_EXECUTE, "Invoke _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) },
+ { "DirAxAction", GTK_STOCK_EXECUTE, "Start _DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax) },
+ { "StopDirAxAction", GTK_STOCK_CLOSE, "Stop DirAx", "<Ctrl>D", NULL, G_CALLBACK(displaywindow_dirax_stop) },
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About DTR...", NULL, NULL, G_CALLBACK(displaywindow_about) },
@@ -912,6 +917,8 @@ DisplayWindow *displaywindow_open(ControlContext *ctx) {
g_signal_connect(GTK_OBJECT(dw->drawing_area), "button_press_event", G_CALLBACK(displaywindow_gl_button_press), dw);
g_signal_connect(GTK_OBJECT(dw->drawing_area), "motion_notify_event", G_CALLBACK(displaywindow_gl_motion_notify), dw);
+ displaywindow_update_dirax(ctx, dw);
+
gtk_widget_show_all(dw->window);
return dw;
@@ -924,3 +931,22 @@ void displaywindow_update(DisplayWindow *dw) {
gdk_window_invalidate_rect(dw->drawing_area->window, &dw->drawing_area->allocation, FALSE);
}
+/* Update the disabling of the menu for DirAx functions */
+void displaywindow_update_dirax(ControlContext *ctx, DisplayWindow *dw) {
+
+ GtkWidget *start;
+ GtkWidget *stop;
+
+ start = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/dirax");
+ stop = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/tools/diraxstop");
+
+ if ( ctx->dirax ) {
+ gtk_widget_set_sensitive(GTK_WIDGET(start), FALSE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop), TRUE);
+ } else {
+ gtk_widget_set_sensitive(GTK_WIDGET(start), TRUE);
+ gtk_widget_set_sensitive(GTK_WIDGET(stop), FALSE);
+ }
+
+}
+
diff --git a/src/displaywindow.h b/src/displaywindow.h
index 8c4e388..6b4fb01 100644
--- a/src/displaywindow.h
+++ b/src/displaywindow.h
@@ -61,6 +61,7 @@ typedef struct dw_struct {
extern DisplayWindow *displaywindow_open(ControlContext *ctx);
extern void displaywindow_update(DisplayWindow *dw);
+extern void displaywindow_update_dirax(ControlContext *ctx, DisplayWindow *dw);
#endif /* DISPLAYWINDOW_H */