home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- Program name: Topology Drawer demo program.
-
- Author: Gareth Williams
-
- Description: Demonstrates the topology drawer module.
-
- Modification history : (Version), (Date), (Name), (Description).
-
- 1.0, 1st June 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- #define WS1 1
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathnames */
- #define SCRIPTNAME "../scripts/lamp.scr"
- #define STORENAME "../data/topology.lyt"
- #define OPENWSNAME "../scripts/openws.scr"
-
- /*
- #ifdef VMS
- #define SCRIPTNAME "[-.scripts]lamp.scr"
- #define STORENAME "[-.data]topology.lyt"
- #endif
- */
-
- static char *colwrd[] =
- {
- "BLACK", "WHITE", "GREEN",
- "BLUE", "CYAN", "GREY", "RED"
- };
-
- static Pfloat devx, devy, devz;
- static ptkboolean docolour = FALSE;
-
- /*--------------------------------------------------------------------------*/
-
- static void options(C(void))
- {
- char commandstr[20], writestr[50];
- Pint lencom, lenstr, err;
- ptkboolean topquit;
- Plimit echoarea;
-
- topquit = FALSE;
- do
- {
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- ptk_readstring(WS1, "boxtopology",
- "Input command (default = boxtopology) >", &echoarea,
- 20, commandstr, &lencom);
- if (strncmp(commandstr, "boxtopology", lencom) == 0)
- {
- ptk_settopologytype(ptk_stringtoint("topologyid", "topology"),
- PTKEBOXTOPOLOGY);
- ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
- predraw_all_structs(WS1, PFLAG_ALWAYS);
- }
- else if (strncmp(commandstr, "structnettopology", lencom) == 0)
- {
- ptk_settopologytype(ptk_stringtoint("topologyid", "topology"),
- PTKESTRUCTNETTOPOLOGY);
- ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
- predraw_all_structs(WS1, PFLAG_ALWAYS);
- }
- else if (strncmp(commandstr, "structtopology", lencom) == 0)
- {
- ptk_settopologytype(ptk_stringtoint("topologyid", "topology"),
- PTKESTRUCTTOPOLOGY);
- ptk_posttopology(WS1, ptk_stringtoint("topologyid", "topology"), 0.0);
- predraw_all_structs(WS1, PFLAG_ALWAYS);
- }
- else if (strncmp(commandstr, "tidysingle", lencom) == 0)
- {
- Ppick_data pickrec;
- Ploc_data locrec;
-
- #ifdef HP
- locrec.pets.pet_r1.loc_colr_ind = 1;
- pickrec.pets.pet_r1.highl_colr_ind = 0;
- pickrec.pets.pet_r1.x_dim = 0.01;
- pickrec.pets.pet_r1.y_dim = 0.01;
- pickrec.pets.pet_r1.z_dim = 0.01;
- #endif
- ptk_tidytopology(WS1, ptk_stringtoint("topologyid", "topology"),
- PTKESINGLE, 1, 1, &pickrec, 1, 1, &locrec);
- }
- else if (strncmp(commandstr, "tidygroup", lencom) == 0)
- {
- Ppick_data pickrec;
- Ploc_data locrec;
-
- #ifdef HP
- locrec.pets.pet_r1.loc_colr_ind = 1;
- pickrec.pets.pet_r1.highl_colr_ind = 0;
- pickrec.pets.pet_r1.x_dim = 0.01;
- pickrec.pets.pet_r1.y_dim = 0.01;
- pickrec.pets.pet_r1.z_dim = 0.01;
- #endif
- ptk_tidytopology(WS1, ptk_stringtoint("topologyid", "topology"),
- PTKEGROUP, 1, 1, &pickrec, 1, 1, &locrec);
- }
- else if (strncmp(commandstr, "store", lencom) == 0)
- {
- FILE *fileptr;
-
- fileptr = fopen(STORENAME, "w+");
- rewind(fileptr);
- printf("storing layout in %s...\n", STORENAME);
- ptk_storetopologylayout(fileptr,
- ptk_stringtoint("topologyid", "topology"));
- fclose(fileptr);
- }
- else if (strncmp(commandstr, "restore", lencom) == 0)
- {
- FILE *fileptr;
-
- fileptr = fopen(STORENAME, "r");
- rewind(fileptr);
- printf("restoring layout from %s...\n", STORENAME);
- ptk_restoretopologylayout(fileptr,
- ptk_stringtoint("topologyid", "topology"));
- fclose(fileptr);
- }
- else if (strncmp(commandstr, "hardcopy", lencom) == 0)
- {
- Pint stid, lenname;
- char filename[80];
-
- ptk_readstring(WS1, "topology",
- "Input filename (default = topology) >", &echoarea,
- 80, filename, &lenname);
- /* Implementation dependent code, open a hardcopy workstation */
- #ifdef SUN
- popen_ws(2, filename, phigs_ws_type_cgm_out);
- ptk_inqtopologystructid(ptk_stringtoint("topologyid", "topology"),
- &stid, &err);
- ppost_struct(2, stid, 0.0);
- pupd_ws(2, PFLAG_PERFORM);
- pclose_ws(2);
- #endif
- }
- else
- if (strncmp(commandstr, "help", lencom) == 0)
- {
- printf("toptest options\n");
- printf("----------------\n");
- printf("boxtopology - display default topology type\n");
- printf("structtopology - display structtopology type\n");
- printf("structnettopology - display structnettopology type\n");
- printf("tidysingle - set position of single topology node\n");
- printf("tidygroup - set position of topology node group\n");
- printf("store - store topology layout\n");
- printf("restore - restore topology layout\n");
- printf("hardcopy - post topology to hardcopy workstation\n");
- printf("quit - exit toptest\n");
- }
- else if (strncmp(commandstr, "quit", lencom) == 0)
- {
- topquit = TRUE;
- }
- else
- {
- printf("Command unknown\n");
- }
- pupd_ws(WS1, PFLAG_PERFORM);
- } while (topquit == FALSE);
- }
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- FILE *f;
- char dummystr[10];
- Pint dummylen, err, minid, maxid, wst, topid;
- Pint white, black, grey, green, blue, textfont;
-
- printf("Demonstrating the topology drawer module of the PHIGS Toolkit...\n");
-
- /* Implementation dependent code, open PHIGS and workstation */
- #ifdef SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
-
- /* create the workstation type (either tool or canvas)
-
- wst = phigs_ws_type_create( phigs_ws_type_x_tool,
- PHIGS_TOOL_LABEL, "SunPHIGS Tool Workstation",
- 0);
- if ( !wst )
- {
- pclose_phigs();
- exit(1);
- }
-
- popen_ws(WS1, (void *)NULL, wst);
- {
- Pws_st ws_state;
-
- pinq_ws_st(&ws_state);
- if (ws_state != PWS_ST_WSOP)
- exit(3);
- }
- */
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
-
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
-
- #ifdef SUN
- #ifndef SUNMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef HP
- #ifndef HPMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef PEXSI
- #ifndef PEXSIMONO
- docolour = TRUE;
- #endif
- #endif
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
- minid = 0;
- maxid = 30;
- ptk_inithashtables();
- ptk_createhashtable("structureid", 1, 500);
- ptk_createhashtable("label", minid, maxid);
- ptk_createhashtable("topologyid", minid, maxid);
- ptk_createhashtable("name", minid, maxid);
- ptk_createhashtable("colourindex", 1, 8);
-
- /* set colours */
- if (docolour)
- {
- ptk_setupcolourtable(WS1, 7, colwrd);
- green = ptk_stringtoint("colourindex", "green");
- grey = ptk_stringtoint("colourindex", "grey");
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- blue = ptk_stringtoint("colourindex", "blue");
-
- /* Implementation dependent code, choose a nice font */
- #ifdef SUN
- textfont = PFONT_TRIPLEX;
- #endif
- #ifndef SUN
- textfont = 1;
- #endif
- ptk_setbackgroundcolourind(WS1, grey);
- }
-
- if (ptk_readphinterscript(SCRIPTNAME, NULL, NULL))
- {
- topid = ptk_stringtoint("topologyid", "topology");
- ptk_createtopology(topid, ptk_stringtoint("structureid", "lamp"), &err);
- if (docolour)
- ptk_settopologyattrs(topid, textfont, white, black, white, green,
- white, green);
- ptk_posttopology(WS1, topid, 0.0);
- predraw_all_structs(WS1, PFLAG_ALWAYS);
- options();
- }
- pclose_ws(1);
- pclose_phigs();
- exit(0);
- }
-
- /*--------------------------------------------------------------------------*/
-
- /* end of toptest.c */
-