Changeset 1428


Ignore:
Timestamp:
Apr 30, 2009 9:20:06 AM (15 years ago)
Author:
gah
Message:

fix image hardcopy transfer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/pymolproxy/pymolproxy.c

    r1351 r1428  
    5252 */
    5353
     54#include <assert.h>
     55#include <ctype.h>
     56#include <errno.h>
     57#include <fcntl.h>
     58#include <getopt.h>
     59#include <net/if.h>
     60#include <netinet/in.h>
     61#include <poll.h>
     62#include <signal.h>
    5463#include <stdio.h>
    55 #include <time.h>
    56 #include <assert.h>
    57 #include <unistd.h>
    5864#include <stdlib.h>
    5965#include <string.h>
    60 #include <signal.h>
     66#include <sys/ioctl.h>
     67#include <sys/select.h>
     68#include <sys/socket.h>
    6169#include <sys/stat.h>
    62 #include <sys/types.h>
    63 #include <sys/socket.h>
    64 #include <sys/wait.h>
    65 #include <sys/select.h>
    66 #include <poll.h>
    6770#include <sys/time.h>
    6871#include <sys/times.h>
    69 #include <fcntl.h>
    70 #include <netinet/in.h>
    71 #include <getopt.h>
    72 #include <errno.h>
    73 #include <sys/ioctl.h>
    74 #include <net/if.h>
     72#include <sys/types.h>
     73#include <sys/wait.h>
     74#include <time.h>
     75#include <unistd.h>
    7576#include <tcl.h>
    7677
     
    354355        return proxyPtr->status;
    355356    }
    356     trace("Entering Expect(match=%s, maxSize=%d)\n", match, maxSize);
     357    trace("Entering Expect(want=%s, maxSize=%d)\n", match, maxSize);
    357358    c = match[0];
    358359    length = strlen(match);
     
    370371                memcpy(out, line, nBytes);
    371372                clear_error(proxyPtr);
    372                 trace("Leaving Expect: match is (%.*s)\n", nBytes, out);
     373                trace("Leaving Expect: got (%.*s)\n", nBytes, out);
    373374                return BUFFER_OK;
    374375            }
     
    636637Pymol(PymolProxy *proxyPtr, char *format, ...)
    637638{
     639    va_list ap;
     640    char buffer[BUFSIZ];
     641    char expect[BUFSIZ];
     642    int result;
     643    ssize_t nWritten;
     644    size_t length;
     645    char *p;
    638646
    639647    if (proxyPtr->error) {
    640648        return TCL_ERROR;
    641649    }
    642     {
    643         va_list ap;
    644         char cmd[BUFSIZ];
    645         ssize_t nWritten;
    646         size_t length;
    647 
    648         va_start(ap, format);
    649         vsnprintf(cmd, BUFSIZ-1, format, ap);
    650         va_end(ap);
    651        
    652         trace("to-pymol>(%s)", cmd);
    653        
    654         /* Write the command out to the server. */
    655         length = strlen(cmd);
    656         nWritten = write(proxyPtr->serverInput, cmd, length);
    657         if (nWritten != length) {
    658             trace("short write to pymol (wrote=%d, should have been %d)",
    659                   nWritten, length);
    660         }
    661     }
    662     {
    663         char out[BUFSIZ];
    664         int result;
    665 
    666         /* Now wait for the "PyMOL>" prompt. */
    667         result = Expect(proxyPtr, "PyMOL>", out, BUFSIZ);
    668         if (result == BUFFER_ERROR) {
    669             trace("timeout reading data (buffer=%s)", out);
    670             proxyPtr->error = 1;
    671             proxyPtr->status = TCL_ERROR;
    672             return proxyPtr->status;
    673         }
    674         return  proxyPtr->status;
    675     }
     650   
     651    va_start(ap, format);
     652    vsnprintf(buffer, BUFSIZ-1, format, ap);
     653    va_end(ap);
     654   
     655    trace("to-pymol>(%s)", buffer);
     656   
     657    /* Write the command out to the server. */
     658    length = strlen(buffer);
     659    nWritten = write(proxyPtr->serverInput, buffer, length);
     660    if (nWritten != length) {
     661        trace("short write to pymol (wrote=%d, should have been %d)",
     662              nWritten, length);
     663    }
     664
     665    for (p = buffer; *p != '\0'; p++) {
     666        if (isspace(*p)) {
     667            *p = '\0';
     668            break;
     669        }
     670    }
     671    sprintf(expect, "PyMOL>%s", buffer);
     672    /* Now wait for the "PyMOL>" prompt. */
     673    result = Expect(proxyPtr, expect, buffer, BUFSIZ);
     674    if (result == BUFFER_ERROR) {
     675        trace("timeout reading data (buffer=%s)", buffer);
     676        proxyPtr->error = 1;
     677        proxyPtr->status = TCL_ERROR;
     678        return proxyPtr->status;
     679    }
     680    return  proxyPtr->status;
    676681}
    677682
     
    843848    PymolProxy *proxyPtr = clientData;
    844849    Image *imgPtr;
    845     int nScanned;
    846850    size_t length;
    847 #ifdef notdef
    848     float samples = 10.0;
    849     ssize_t nWritten;
    850 #endif
    851851    clear_error(proxyPtr);
    852852
     
    859859    Pymol(proxyPtr,"refresh\n");
    860860    Pymol(proxyPtr,"bmp -\n");
    861     if (Expect(proxyPtr, "image follows: ", buffer, BUFSIZ) != BUFFER_OK) {
     861    if (Expect(proxyPtr, "bmp image follows: ", buffer, BUFSIZ) != BUFFER_OK) {
    862862        trace("can't find image follows line (%s)", buffer);
    863863    }
    864     nScanned = sscanf(buffer, "image follows: %d\n", &nBytes);
    865     if (nScanned != 1) {
    866         trace("can't scan image follows buffer (%s)", buffer);
     864    if (sscanf(buffer, "bmp image follows: %d\n", &nBytes) != 1) {
     865        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
     866                         (char *)NULL);
    867867        return TCL_ERROR;
    868 
    869     }
    870 #ifdef notdef
    871     nWritten = write(3,&samples,sizeof(samples));
    872 #endif
     868    }
    873869    sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId,
    874870            proxyPtr->frame, proxyPtr->rockOffset);
     
    12781274    Image *imgPtr;
    12791275
    1280 #ifdef notdef
    1281     float samples = 10.0;
    1282     ssize_t nWritten;
    1283 #endif
    12841276    clear_error(proxyPtr);
    12851277
     
    12941286    Pymol(proxyPtr,"png -\n");
    12951287
    1296     Expect(proxyPtr, "image follows: ", buffer, 800);
    1297 
    1298     sscanf(buffer, "image follows: %d\n", &nBytes);
    1299  
    1300 #ifdef notdef
    1301     nWritten = write(3, &samples, sizeof(samples));
    1302 #endif
    1303     if (nBytes == 0) {
    1304     }
     1288    Expect(proxyPtr, "png image follows: ", buffer, 800);
     1289
     1290    if (sscanf(buffer, "png image follows: %d\n", &nBytes) != 1) {
     1291        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
     1292                         (char *)NULL);
     1293        return TCL_ERROR;
     1294    }
    13051295    sprintf(buffer, "nv>image %d %d %d %d\n", nBytes, proxyPtr->cacheId,
    13061296            proxyPtr->frame, proxyPtr->rockOffset);
     
    13121302        return  TCL_ERROR;
    13131303    }
    1314 #ifdef notdef
    1315     Expect(proxyPtr, " ScenePNG", buffer,800);
    1316 #endif
     1304    Expect(proxyPtr, " ScenePNG", buffer, 800);
     1305
    13171306    stats.nFrames++;
    13181307    stats.nBytes += nBytes;
     
    13521341        return TCL_ERROR;
    13531342    }
    1354 
    13551343    /* Force pymol to update the current scene. */
    1356     Pymol(proxyPtr,"refresh\n");
    1357     Pymol(proxyPtr,"ray %d,%d\n", width, height);
    1358     Pymol(proxyPtr,"png -\n");
    1359 
    1360     Expect(proxyPtr, "image follows: ", buffer, 800);
    1361 
    1362     sscanf(buffer, "image follows: %d\n", &nBytes);
    1363  
    1364 #ifdef notdef
    1365     nWritten = write(3, &samples, sizeof(samples));
    1366 #endif
    1367     if (nBytes == 0) {
     1344    Pymol(proxyPtr,"refresh ; ray %d,%d ; png -, dpi=300\n", width, height);
     1345    Expect(proxyPtr, "png image follows: ", buffer, 800);
     1346
     1347    if (sscanf(buffer, "png image follows: %d\n", &nBytes) != 1) {
     1348        Tcl_AppendResult(interp, "can't get # bytes from \"", buffer, "\"",
     1349                         (char *)NULL);
     1350        return TCL_ERROR;
    13681351    }
    13691352    sprintf(buffer, "nv>image %d print \"%s\" %d\n", nBytes, token,
     
    13761359        return  TCL_ERROR;
    13771360    }
    1378 #ifdef notdef
    1379     Expect(proxyPtr, " ScenePNG", buffer,800);
    1380 #endif
     1361    Expect(proxyPtr, " ScenePNG", buffer, 800);
     1362
    13811363    stats.nFrames++;
    13821364    stats.nBytes += nBytes;
Note: See TracChangeset for help on using the changeset viewer.