home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / gpc / fakefigs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-02  |  16.0 KB  |  508 lines

  1. /* $XConsortium: fakefigs.c,v 5.2 91/04/03 09:40:19 rws Exp $ */
  2. /***********************************************************
  3. Copyright(c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium at M.I.T.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Sun Microsystems,
  12. the X Consortium, and MIT not be used in advertising or publicity
  13. pertaining to distribution of the software without specific, written
  14. prior permission.
  15.  
  16. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
  18. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  19. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25.  
  26. /*--------------------------------------------------------------------*\
  27. |  Copyright (C) 1989,1990, 1991, National Computer Graphics Association
  28. |
  29. |  Permission is granted to any individual or institution to use, copy, or
  30. |  redistribute this software so long as it is not sold for profit, provided
  31. |  this copyright notice is retained.
  32. |
  33. |                         Developed for the
  34. |                National Computer Graphics Association
  35. |                         2722 Merrilee Drive
  36. |                         Fairfax, VA  22031
  37. |                           (703) 698-9600
  38. |
  39. |                                by
  40. |                 SimGraphics Engineering Corporation
  41. |                    1137 Huntington Drive  Unit A
  42. |                      South Pasadena, CA  91030
  43. |                           (213) 255-0900
  44. |---------------------------------------------------------------------
  45. |
  46. | Author        :    John M. Zulauf
  47. |
  48. | File          :    fakefigs.c
  49. | Date          :    Sun Jun 25 15:50:46 PDT 1989
  50. | Project       :    PLB
  51. | Description   :    Routines that emulate missing phigs+ calls.
  52. |                    Specifically, trimesh, quadmesh
  53. |                    --- And MUCH, MUCH More!!!!!!
  54. | Status        :    Version 1.0
  55. |
  56. |
  57. |    11/21/89    Paul Chek DEC:
  58. |                       - in fxrect change call to pfa to ppl 
  59. |    
  60. |    2/89        JMZ SimGEC: added pixmap functions
  61. |
  62. |       2/90            MFC Tektronix, Inc.: PEX-SI API implementation.
  63. |
  64. |       5/90            MFC Tektronix, Inc.: PEX-SI API Binding change.
  65. |
  66. |      12/90            MFC Tektronix, Inc.: PEX-SI PEX5R1 Release.
  67. |
  68. \*--------------------------------------------------------------------*/
  69.  
  70. /*--------------------------------------------------------------------*\
  71. |    Table of Contents
  72. |
  73. |    int fxtrd3( int *, int *, int *, float *, int *, float *, float *, float *, float *)
  74. |        :    Generate a polyhedron call for the given fxtrd3
  75. |    int fxqmd3( int *, int *, int *, float *, int *, int *, float *, float *, float *, float *)
  76. |        :    Generate a polyhedron call for the given fxqmd3
  77. |    int fxsattxal(int *, int *)
  78. |        :    A PHIGs like call that calls both psatal and pstxal
  79. |    int fxsattxp(int *, int *)
  80. |        :    A PHIGs like call that calls both psatp and pstxp
  81. |    int fxopns()
  82. |        :    Open a resevered structure to recieve the
  83. |    int fxclns()
  84. |        :    Closes the resevered structure that recieves the
  85. |    int fxsbfio(cmodel, c1, c2, c3)
  86. |        :    noop for BACKFACE_COLOR
  87. |    int fxsbfci(index)
  88. |        :    noop for BACKFACE_COLOR_INDEX
  89. |    int fxbfpr(&identify_flag, &cull_flag)
  90. |        :    Noop for back face processing
  91. |    fxbfp(&ambient,&diffuse,&specular,&color_model, specular_color, &highlight, &transparency);
  92. |        :    Noop for back face properties
  93. |    int fxsipi(index)
  94. |        :    noop for PATTERN_INDEX
  95. |    int fxnoop(size)
  96. |        :    Insert a PHIGS element that does nothing...
  97. |    int fxrect(xll, yll, xsize, ysize )
  98. |        :    Convert a FIGARO pxrect call into a pfa call
  99. |    int fxsbci(wk,index)
  100. |        :    Set the background to the color value at the
  101. |    int fxrfst(str_id)
  102. |        :    CALL a structure without doing a save/restore 
  103. |    int fxpaus()
  104. |        :    pause the workstation
  105. |    fxpixelup(int)
  106. |        :    Set the pixel update function to the given value
  107. |    fxpixmap3( vector3, int, int, int, *unsigned char, int, *char)
  108. |        :    Generate a one channel pixelmap PHIGS+ element
  109. |
  110. \*--------------------------------------------------------------------*/
  111.  
  112. /*--------------------------------------------------------------------*\
  113. |    Include Files
  114. \*--------------------------------------------------------------------*/
  115. #include <stdio.h>
  116. #include <X11/Xosdefs.h>
  117. #ifndef X_NOT_STDC_ENV
  118. #include <stdlib.h>
  119. #else
  120. char *malloc();
  121. #endif
  122. #if defined(macII) && !defined(__STDC__)  /* stdlib.h fails to define these */
  123. char *malloc();
  124. #endif /* macII */
  125. #ifdef HAVE_PIXELS
  126. #include "fig_enums.h"
  127. #endif
  128. #include "ph_map.h"
  129. #include "biftypes.h"
  130. #include "globals.h"
  131. #include "bifmacro.h"
  132.  
  133.  
  134. /*--------------------------------------------------------------------*\
  135. | Procedure     :    int fxsattxal(Ptxalign *)
  136. |---------------------------------------------------------------------
  137. | Description   :    A PHIGs like call that calls both psatal and pstxal
  138. |            NOTE: fxsattxal generates two PHIGs elements.
  139. |---------------------------------------------------------------------
  140. | Return        :    The return of the last PHIGs calls.
  141. \*--------------------------------------------------------------------*/
  142. int fxsattxal(align)
  143. Ptext_align *align;
  144.  
  145. {
  146.     /* NOTE: fxsattxal generates two PHIGs elements */
  147. #ifdef USING_PHIGS
  148.     pset_anno_align((Ptext_align *)align);
  149.     pset_text_align((Ptext_align *)align);
  150. #endif /* USING_PHIGS */
  151. } /* End fxsattxal() */
  152.  
  153.  
  154. /*--------------------------------------------------------------------*\
  155. | Procedure     :    void fxsattxp(int )
  156. |---------------------------------------------------------------------
  157. | Description   :    A PHIGs like call that calls both psatp and pstxp
  158. |            NOTE: fxsattxp generates two PHIGs elements.
  159. \*--------------------------------------------------------------------*/
  160. void fxsattxp(path)
  161. int path;
  162.  
  163. {
  164.     /* NOTE: fxsattxp generates two PHIGs elements */
  165. #ifdef USING_PHIGS
  166.     pset_anno_path((Ptext_path)path);
  167.     pset_text_path((Ptext_path)path);
  168. #endif /* USING_PHIGS */
  169. } /* End fxsattxp() */
  170.  
  171.  
  172. /*--------------------------------------------------------------------*\
  173. | Procedure     :    int fxopns()
  174. |---------------------------------------------------------------------
  175. | Description   :    Open a resevered structure to recieve the
  176. |            "immediate" mode BIF entities.
  177. |---------------------------------------------------------------------
  178. | Return        :    Error Code
  179. \*--------------------------------------------------------------------*/
  180. int fxopns()
  181.  
  182. {
  183. #ifdef USING_PHIGS
  184.     popen_struct((Pint)bench_setup.nrs_stid);
  185. #endif /* USING_PHIGS */
  186. } /* fxopns() */
  187.  
  188. /*--------------------------------------------------------------------*\
  189. | Procedure     :    int fxclns()
  190. |---------------------------------------------------------------------
  191. | Description   :    Closes the resevered structure that recieves the
  192. |            "immediate" mode BIF entities.
  193. |---------------------------------------------------------------------
  194. | Return        :    Error Code
  195. \*--------------------------------------------------------------------*/
  196. int fxclns()
  197.  
  198. {
  199. #ifdef USING_PHIGS
  200.     pclose_struct();
  201. #endif /* USING_PHIGS */
  202. } /* End fxclns() */
  203.  
  204. /*--------------------------------------------------------------------*\
  205. | Procedure     :    void fxsbfci(index)
  206. |---------------------------------------------------------------------
  207. | Description   :    noop for BACKFACE_COLOR_INDEX
  208. \*--------------------------------------------------------------------*/
  209. void fxsbfci(index)
  210. int index;
  211.  
  212. {
  213. } /* End fpsbfci() */
  214.  
  215. /*--------------------------------------------------------------------*\
  216. | Procedure     :    int fxsipi(index)
  217. |---------------------------------------------------------------------
  218. | Description   :    noop for PATTERN_INDEX
  219. |---------------------------------------------------------------------
  220. | Return        :    
  221. \*--------------------------------------------------------------------*/
  222. int fxsipi(index)
  223. int index;
  224.  
  225. {
  226.     return(0);
  227. } /* End fpsipi() */
  228.  
  229.  
  230. /*--------------------------------------------------------------------*\
  231. | Procedure     :    int fxnoop(size)
  232. |---------------------------------------------------------------------
  233. | Description   :    Insert a PHIGS element that does nothing...
  234. |        EXCEPTION: NOOP elements Don't exist on the GX4000
  235. |---------------------------------------------------------------------
  236. | Return        :    Error Code ( Not implemented )
  237. \*--------------------------------------------------------------------*/
  238. /*ARGSUSED*/
  239. fxnoop(size)
  240. int size;
  241. {
  242. } /* End fxnoop();
  243.  
  244. /*--------------------------------------------------------------------*\
  245. | Procedure     :    int fxrect(xll, yll, xsize, ysize )
  246. |---------------------------------------------------------------------
  247. | Description   :    Convert a FIGARO pxrect call into a pfa call
  248. |----------------------------------------------------------------------
  249. | Return        :    Error Code ( Not implemented )
  250. \*--------------------------------------------------------------------*/
  251. int fxrect(xll, yll, xsize, ysize )
  252. float xll, yll, xsize, ysize;
  253.  
  254. {
  255.     int numCoords;
  256.     Ppoint points[4];
  257.  
  258.     numCoords = 4;
  259.     points[0].x = (Pfloat)xll;
  260.     points[1].x = (Pfloat)(xll + xsize);
  261.     points[2].x = (Pfloat)(xll + xsize);
  262.     points[3].x = (Pfloat)xll;
  263.  
  264.     points[0].y = (Pfloat)yll;
  265.     points[1].y = (Pfloat)yll;
  266.     points[2].y = (Pfloat)(yll + ysize);
  267.     points[3].y = (Pfloat)(yll + ysize);
  268.  
  269. #ifdef USING_PHIGS
  270.     {
  271.         Ppoint_list fpoints;
  272.  
  273.         fpoints.num_points = (Pint)numCoords;
  274.         fpoints.points = (Ppoint *)points;
  275.         pfill_area(&fpoints);
  276.     }
  277. #endif
  278.  
  279. } /* End fxrect();
  280.  
  281. /*--------------------------------------------------------------------*\
  282. | Procedure     :    int fxsbci(wk,index)
  283. |---------------------------------------------------------------------
  284. | Description   :    Set the background to the color value at the
  285. |            given index.
  286. |---------------------------------------------------------------------
  287. | Return        :    Error Code ( Not implemented )
  288. \*--------------------------------------------------------------------*/
  289. /*ARGSUSED*/
  290. int fxsbci(wk,index)
  291. int *wk, *index;
  292. {
  293.     /*------------------------------------------------------------*\
  294.     |    WORKING: Need to do an inquire color rep and then
  295.     |    set color rep zero.
  296.     \*------------------------------------------------------------*/
  297. } /* End fxsbci();
  298.  
  299. /*--------------------------------------------------------------------*\
  300. | Procedure     :    int fxrfst(str_id)
  301. |---------------------------------------------------------------------
  302. | Description   :    CALL a structure without doing a save/restore 
  303. |            of the traverser state (obsolete)
  304. |---------------------------------------------------------------------
  305. | Return        :    
  306. \*--------------------------------------------------------------------*/
  307. int fxrfst(str_id)
  308. int str_id;
  309.  
  310. {
  311.     /*------------------------------------------------------------*\
  312.     |    PHIGs can't do this, so we'll approximate using
  313.     |    pexst.... but there is a better way.... 
  314.     \*------------------------------------------------------------*/
  315. #ifdef TEST_PRINT
  316. fflush(stderr);
  317. printf("fxrfst: executing %d\n",str_id);
  318. fflush(stdout);
  319. #endif /* TEST_PRINT */
  320.  
  321. #ifdef USING_PHIGS
  322.     pexec_struct((Pint)str_id);
  323. #endif
  324. }
  325.  
  326. /*--------------------------------------------------------------------*\
  327. | Procedure     :    int fxpaus()
  328. |---------------------------------------------------------------------
  329. | Description   :    pause the workstation
  330. |---------------------------------------------------------------------
  331. | Return        :    
  332. \*--------------------------------------------------------------------*/
  333. /*ARGSUSED*/
  334. int fxpaus(wk)
  335. int *wk;
  336.  
  337. {
  338.     /* WORKING: There should be a better form of pause avail. */
  339.     char buffy[255];
  340.     fflush(stdout);
  341.     fprintf(stderr,"Paused -- Press <Return> to continue.");
  342.     fflush(stderr);
  343.     gets(buffy);
  344. } /* End fxpaus() */
  345.  
  346.  
  347. /*--------------------------------------------------------------------*\
  348. | Procedure     :    fxpixelup(int)
  349. |---------------------------------------------------------------------
  350. | Description   :    Set the pixel update function to the given value
  351. |---------------------------------------------------------------------
  352. | Return        :    None:
  353. \*--------------------------------------------------------------------*/
  354. fxpixelup(pixelUpdate)
  355. int pixelUpdate;
  356.  
  357. {/* fxpixelup */
  358.     /* Pack data record parameters */
  359.     int    il;
  360.     int    ia[3];
  361.     int    rl;
  362.     float    ra[3];
  363.     int    sl;
  364.     int    lstr[1];  
  365.     char    str[80];
  366.     int    ldr;
  367.     int    ldrPixUp;
  368.     char    toPixUp[80];
  369.     int    mldr;
  370.     int    ierr;
  371.  
  372.     /*----------------------------------------------------*\
  373.     |    Pixel Update Function Data 
  374.     \*----------------------------------------------------*/
  375.     il      = 2;
  376.     ia[0]   = pixelUpdate;
  377.     ia[1]   = BIF_OFF;  /* 0 */
  378.     rl      = 0;
  379.     ra[0]   = 0.;
  380.     sl      = 0;
  381.     lstr[0] = 0; 
  382.     mldr    = 1;
  383.  
  384.     /* Build the data record to set the pixel function*/
  385. #ifdef USING_PHIGS
  386. #ifdef HAVEPIXELS
  387.     pprec(    &il, ia, &rl, ra,
  388.         &sl, lstr, str, &mldr, &ierr,
  389.         &ldrPixUp, toPixUp, 80, 80);
  390.  
  391. #ifdef PPRECCHECK
  392.     switch(ierr)
  393.     {
  394.     case 2001:
  395.         ERROR("fxpixelup: insufficient memory for pprec.");
  396.         break;
  397.     case 2003:
  398.         ERROR("fxpixelup: error encoding data record during pprec.");
  399.         break;
  400.     case 0:
  401.         break; /* no reported error */
  402.     default:
  403.         ERROR("fxpixelup: unknown phigs error in pprec.");
  404.         exit(-1);
  405.         break;
  406.     } /* end switch */
  407. #endif
  408.  
  409.     pgse(FIG_PIXFUNC,&ldrPixUp,toPixUp,80);
  410. #endif /* HAVEPIXELS */
  411. #endif
  412.  
  413.     return;
  414. }/* fxpixelup */
  415.  
  416. #ifdef EXTERNALNOTE
  417. Alliant Users!
  418. There is a problem with passing defined strings of characters from C to
  419. Fortran in that pprec uses the C strlen. strlen will assume a char 0 
  420. (NULL) to be the end of the string and terminate the data transfer. This
  421. means that the length of the data read in doees not match the length
  422. specified in br_mldr, and the pack operation is aborted. This problem is
  423. dealt with in version 2.0 and later. 
  424. #endif
  425. /*--------------------------------------------------------------------*\
  426. | Procedure     :    fxpixmap3( vector3, int, int, int,
  427. |                    *unsigned char, int, *char)
  428. |---------------------------------------------------------------------
  429. | Description   :    Generate a one channel pixelmap PHIGS+ element
  430. |---------------------------------------------------------------------
  431. | Return        :    
  432. \*--------------------------------------------------------------------*/
  433. fxpixmap3(upperLeft, numCol, numRow, channelID, pixelData,
  434.         wkSize,workSpace)
  435. vector3    upperLeft;
  436. int    numCol;
  437. int    numRow;
  438. int    channelID;
  439. unsigned char *pixelData;
  440. int    wkSize;        /* Size of workSpace in 80 byte records*/
  441. char    *workSpace;
  442.  
  443. {/* fxpixmap3 */
  444.     /* Pack data record parameters */
  445.     int    il;
  446.     int    ia[3];
  447.     int    rl;
  448.     float    ra[1];
  449.     int    sl;
  450.     int    lstr[1];  
  451.     int    ldr;
  452.     int    ldrPixUp;
  453.     char    *str;
  454.     int    mldr;
  455.     int    ierr;
  456.  
  457.     /*------------------------------------------------------------*\
  458.     |    Fill the  Data to pack the pixel map
  459.     \*------------------------------------------------------------*/
  460.     il      = 3;
  461.     ia[0]   = channelID;
  462.     ia[1]   = numCol;
  463.     ia[2]   = numRow;
  464.     ldr     = 0;
  465.     rl      = 0;
  466.     ra[0]   = 0.;
  467.     sl      = 1;
  468.     lstr[0] = numCol * numRow; 
  469.     str     = (char *)pixelData;
  470.     mldr    = wkSize;
  471.  
  472.     /*------------------------------------------------------------*\
  473.     |    Pack the pixmap data for the PHIGS+ call
  474.     \*------------------------------------------------------------*/
  475. #ifdef USING_PHIGS
  476. #ifdef HAVEPIXELS
  477.     pprec(    &il, ia, &rl, ra,
  478.         &sl, lstr, str, &mldr, &ierr,
  479.         &ldr, workSpace, 80, 80);
  480.  
  481. #ifdef PPRECCHECK
  482.     switch(ierr)
  483.     {
  484.     case 2001:
  485.         ERROR("fxpixmap3: insufficient memory for pprec.");
  486.         break;
  487.     case 2003:
  488.         ERROR("fxpixmap3: error encoding data record during pprec.");
  489.         break;
  490.     case 0:
  491.         break; /* no reported error */
  492.     default:
  493.         ERROR("fxpixmap3: unknown phigs error in pprec.");
  494.         exit(-1);
  495.         break;
  496.     } /* end switch */
  497. #endif
  498.  
  499.     /*------------------------------------------------------------*\
  500.     |    Load the pixmap into the open PHIGS+ structure
  501.     \*------------------------------------------------------------*/
  502.     ierr = pgdp3(Fi1, Fpass3f(upperLeft),FIG_WRITEIMAGE,
  503.              &ldr, workSpace, 80);
  504. #endif /* HAVEPIXELS */
  505. #endif
  506.  
  507. }/* fxpixmap3 */
  508.