home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / demo / toptest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-01  |  8.5 KB  |  305 lines

  1. /*--------------------------------------------------------------------------- 
  2.  
  3.  Program name: Topology Drawer demo program.
  4.  
  5.  Author: Gareth Williams
  6.  
  7.  Description: Demonstrates the topology drawer module.
  8.  
  9.  Modification history : (Version), (Date), (Name), (Description).
  10.  
  11.  1.0, 1st June 1991, G. Williams, First Version.
  12.  
  13.  2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
  14.  
  15.  SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
  16.  
  17. ----------------------------------------------------------------------------*/
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21. #include <phigs.h>
  22. #include "ptk.h"
  23.  
  24. #define WS1 1
  25.  
  26. /* Operating system dependent code, UNIX/VMS pathnames */
  27. /* UNIX pathnames */
  28. #define SCRIPTNAME "../scripts/lamp.scr"
  29. #define STORENAME "../data/topology.lyt"
  30. #define OPENWSNAME "../scripts/openws.scr"
  31.  
  32. /*
  33. #ifdef VMS
  34. #define SCRIPTNAME "[-.scripts]lamp.scr"
  35. #define STORENAME "[-.data]topology.lyt"
  36. #endif
  37. */
  38.  
  39. static char *colwrd[] = 
  40.      {
  41.          "BLACK", "WHITE", "GREEN", 
  42.          "BLUE", "CYAN", "GREY", "RED" 
  43.      };
  44.  
  45. static Pfloat devx, devy, devz;
  46. static ptkboolean docolour = FALSE;
  47.  
  48. /*--------------------------------------------------------------------------*/
  49.  
  50. static void options(C(void))
  51. {
  52.   char commandstr[20], writestr[50];
  53.   Pint lencom, lenstr, err;
  54.   ptkboolean topquit;
  55.   Plimit echoarea;
  56.  
  57.   topquit = FALSE;
  58.   do
  59.   {
  60.     echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
  61.     ptk_readstring(WS1, "boxtopology", 
  62.                    "Input command (default = boxtopology) >", &echoarea,
  63.                    20, commandstr, &lencom);
  64.     if (strncmp(commandstr, "boxtopology", lencom) == 0)
  65.     {
  66.       ptk_settopologytype(ptk_stringtoint("topologyid", "topology"), 
  67.                    PTKEBOXTOPOLOGY);
  68.       ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
  69.       predraw_all_structs(WS1, PFLAG_ALWAYS);    
  70.     }
  71.     else if (strncmp(commandstr, "structnettopology", lencom) == 0)
  72.     {
  73.       ptk_settopologytype(ptk_stringtoint("topologyid", "topology"), 
  74.                    PTKESTRUCTNETTOPOLOGY);
  75.       ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
  76.       predraw_all_structs(WS1, PFLAG_ALWAYS);    
  77.     }
  78.     else if (strncmp(commandstr, "structtopology", lencom) == 0)
  79.     {
  80.       ptk_settopologytype(ptk_stringtoint("topologyid", "topology"), 
  81.                    PTKESTRUCTTOPOLOGY);
  82.       ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
  83.       predraw_all_structs(WS1, PFLAG_ALWAYS);    
  84.     }
  85.     else if (strncmp(commandstr, "tidysingle", lencom) == 0)
  86.     {
  87.       Ppick_data pickrec;
  88.       Ploc_data locrec;
  89.  
  90. #ifdef HP
  91.       locrec.pets.pet_r1.loc_colr_ind = 1;
  92.       pickrec.pets.pet_r1.highl_colr_ind = 0;
  93.       pickrec.pets.pet_r1.x_dim = 0.01;
  94.       pickrec.pets.pet_r1.y_dim = 0.01;
  95.       pickrec.pets.pet_r1.z_dim = 0.01;
  96. #endif
  97.       ptk_tidytopology(WS1, ptk_stringtoint("topologyid", "topology"),
  98.                        PTKESINGLE, 1, 1, &pickrec, 1, 1, &locrec);
  99.     }    
  100.     else if (strncmp(commandstr, "tidygroup", lencom) == 0)
  101.     {
  102.       Ppick_data pickrec;
  103.       Ploc_data locrec;
  104.  
  105. #ifdef HP
  106.       locrec.pets.pet_r1.loc_colr_ind = 1;
  107.       pickrec.pets.pet_r1.highl_colr_ind = 0;
  108.       pickrec.pets.pet_r1.x_dim = 0.01;
  109.       pickrec.pets.pet_r1.y_dim = 0.01;
  110.       pickrec.pets.pet_r1.z_dim = 0.01;
  111. #endif
  112.       ptk_tidytopology(WS1, ptk_stringtoint("topologyid", "topology"),
  113.                        PTKEGROUP, 1, 1, &pickrec, 1, 1, &locrec);
  114.     }    
  115.     else if (strncmp(commandstr, "store", lencom) == 0)
  116.     {
  117.       FILE *fileptr;
  118.  
  119.       fileptr = fopen(STORENAME, "w+");
  120.       rewind(fileptr);
  121.       printf("storing layout in %s...\n", STORENAME);
  122.       ptk_storetopologylayout(fileptr, 
  123.                               ptk_stringtoint("topologyid", "topology"));
  124.       fclose(fileptr);
  125.     }    
  126.     else if (strncmp(commandstr, "restore", lencom) == 0)
  127.     {
  128.       FILE *fileptr;
  129.  
  130.       fileptr = fopen(STORENAME, "r");
  131.       rewind(fileptr);
  132.       printf("restoring layout from %s...\n", STORENAME);
  133.       ptk_restoretopologylayout(fileptr, 
  134.                               ptk_stringtoint("topologyid", "topology"));
  135.       fclose(fileptr);
  136.     }    
  137.     else if (strncmp(commandstr, "hardcopy", lencom) == 0)
  138.     {
  139.       Pint stid, lenname;
  140.       char filename[80];
  141.  
  142.       ptk_readstring(WS1, "topology", 
  143.                    "Input filename (default = topology) >", &echoarea,
  144.                    80, filename, &lenname);
  145.       /* Implementation dependent code, open a hardcopy workstation */
  146. #ifdef SUN
  147.       popen_ws(2, filename, phigs_ws_type_cgm_out);
  148.       ptk_inqtopologystructid(ptk_stringtoint("topologyid", "topology"),
  149.                               &stid, &err);
  150.       ppost_struct(2, stid, 0.0);
  151.       pupd_ws(2, PFLAG_PERFORM);
  152.       pclose_ws(2);
  153. #endif
  154.     }    
  155.     else
  156.     if (strncmp(commandstr, "help", lencom) == 0)
  157.     {
  158.       printf("toptest options\n");
  159.       printf("----------------\n");
  160.       printf("boxtopology - display default topology type\n");
  161.       printf("structtopology - display structtopology type\n");
  162.       printf("structnettopology - display structnettopology type\n");
  163.       printf("tidysingle - set position of single topology node\n");
  164.       printf("tidygroup - set position of topology node group\n");
  165.       printf("store - store topology layout\n");
  166.       printf("restore - restore topology layout\n");
  167.       printf("hardcopy - post topology to hardcopy workstation\n");
  168.       printf("quit - exit toptest\n");
  169.     }    
  170.     else if (strncmp(commandstr, "quit", lencom) == 0)
  171.     {
  172.       topquit = TRUE;
  173.     }    
  174.     else
  175.     {
  176.       printf("Command unknown\n");    
  177.     }
  178.     pupd_ws(WS1, PFLAG_PERFORM);
  179.   } while (topquit == FALSE);
  180. }
  181.  
  182. /*--------------------------------------------------------------------------*/
  183.  
  184. main()
  185. {
  186.   FILE *f;
  187.   char dummystr[10];
  188.   Pint dummylen, err, minid, maxid, wst, topid;
  189.   Pint white, black, grey, green, blue, textfont;
  190.  
  191.   printf("Demonstrating the topology drawer module of the PHIGS Toolkit...\n");
  192.  
  193.   /* Implementation dependent code, open PHIGS and workstation */
  194. #ifdef SUN
  195.   printf("Opening SunPHIGS...\n");
  196.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  197.   
  198.   /* open the workstation */
  199.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  200.   
  201. /* create the workstation type (either tool or canvas) 
  202.  
  203.   wst = phigs_ws_type_create( phigs_ws_type_x_tool,
  204.     PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
  205.     0);
  206.   if ( !wst ) 
  207.   {
  208.     pclose_phigs();
  209.     exit(1);
  210.   }
  211.  
  212.   popen_ws(WS1, (void *)NULL, wst);
  213.   {
  214.     Pws_st    ws_state;
  215.     
  216.     pinq_ws_st(&ws_state);
  217.     if (ws_state != PWS_ST_WSOP)
  218.       exit(3);
  219.   }
  220. */
  221. #endif
  222. #ifdef PEXSI
  223.   printf("Opening PEX-SI PHIGS...\n");
  224.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  225.  
  226.   /* open the workstation */
  227.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  228. #endif
  229. #ifdef HP
  230.   printf("Opening HP PHIGS...\n");
  231.   popen_phigs(stderr, PDEF_MEM_SIZE);
  232.  
  233.   /* open the workstation */
  234.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  235. #endif
  236.  
  237.   ptk_inqmaxdevicecoords(WS1, &devx, &devy);
  238.   devz = 0.0;
  239.  
  240. #ifdef SUN
  241. #ifndef SUNMONO
  242.   docolour = TRUE;
  243. #endif
  244. #endif
  245. #ifdef HP
  246. #ifndef HPMONO
  247.   docolour = TRUE;
  248. #endif
  249. #endif
  250. #ifdef PEXSI
  251. #ifndef PEXSIMONO
  252.   docolour = TRUE;
  253. #endif
  254. #endif
  255.  
  256.   pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
  257.   minid = 0;
  258.   maxid = 30;
  259.   ptk_inithashtables();
  260.   ptk_createhashtable("structureid", 1, 500);
  261.   ptk_createhashtable("label", minid, maxid);
  262.   ptk_createhashtable("topologyid", minid, maxid);
  263.   ptk_createhashtable("name", minid, maxid);
  264.   ptk_createhashtable("colourindex", 1, 8);
  265.  
  266.    /* set colours */
  267.    if (docolour)
  268.    {
  269.      ptk_setupcolourtable(WS1, 7, colwrd);
  270.      green = ptk_stringtoint("colourindex", "green");
  271.      grey = ptk_stringtoint("colourindex", "grey");
  272.      white = ptk_stringtoint("colourindex", "white");
  273.      black = ptk_stringtoint("colourindex", "black");
  274.      blue = ptk_stringtoint("colourindex", "blue");
  275.    
  276.      /* Implementation dependent code, choose a nice font */
  277. #ifdef SUN
  278.      textfont = PFONT_TRIPLEX;
  279. #endif
  280. #ifndef SUN
  281.      textfont = 1;
  282. #endif
  283.      ptk_setbackgroundcolourind(WS1, grey);
  284.   }
  285.  
  286.   if (ptk_readphinterscript(SCRIPTNAME, NULL, NULL))
  287.   {
  288.     topid = ptk_stringtoint("topologyid", "topology");
  289.     ptk_createtopology(topid, ptk_stringtoint("structureid", "lamp"), &err);
  290.     if (docolour)
  291.       ptk_settopologyattrs(topid, textfont, white, black, white, green,
  292.                            white, green);
  293.     ptk_posttopology(WS1, topid, 0.0);
  294.     predraw_all_structs(WS1, PFLAG_ALWAYS);    
  295.     options();
  296.   }
  297.   pclose_ws(1);
  298.   pclose_phigs();
  299.   exit(0);
  300. }
  301.  
  302. /*--------------------------------------------------------------------------*/
  303.  
  304. /* end of toptest.c */
  305.