home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / IRIT / DRAWFN3S.ZIP / SETPARAM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-06  |  6.5 KB  |  175 lines

  1. /*****************************************************************************
  2. *   Routines to    set and    handle the scaling of the drawing, and other params.:*
  3. *                                         *
  4. * Written by:  Gershon Elber                   Ver 0.1,    Apr. 1988    *
  5. *****************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <graphics.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include "GraphGnG.h"
  13. #include "Expr2TrG.h"
  14. #include "GenMat.h"
  15. #include "Program.h"
  16.  
  17. static void UpdateParamFlags(struct MenuItem SetParamMenu[],
  18.     double UMin, double UMax, double VMin, double VMax,
  19.     int NumOfSamples, int NumOfIsoLines, int DblBuffer);
  20.  
  21. /*****************************************************************************
  22. *   Main routine of the    SetScale module    - set the Menu and call    the         *
  23. * requested routines.                                 *
  24. *****************************************************************************/
  25. void DoSetParam(int *NumOfSamples, int *NumOfIsoLines,
  26.     double *UMin, double *UMax, double *VMin, double *VMax,
  27.     int *DblBuffer,
  28.     struct IsoLine *IsoLinesU[MAX_ISO_LINES],
  29.     struct IsoLine *IsoLinesV[MAX_ISO_LINES])
  30. {
  31.     static struct MenuItem SetParamMenu[] = {         /* Set Parameters Menu. */
  32.     YELLOW,    "Set Parameters",
  33.     MAGENTA, "Set UMin=         ",
  34.     MAGENTA, "Set UMax=         ",
  35.     MAGENTA, "Set VMin=         ",
  36.     MAGENTA, "Set VMax=         ",
  37.     GREEN, "Set Samples=      ",  /* Set number of samples per iso line. */
  38.     GREEN, "Set IsoLines=      ",/* Set number of iso lines per function.*/
  39.     MAGENTA, "Double Buffer ON ",
  40.     CYAN,    "Help",
  41.     BLUE,    "Exit"
  42.     };
  43.     int    select, OldSamples, OldIsoLines;
  44.     char s[LINE_LEN];
  45.     double Rtemp;
  46.  
  47.     while (TRUE) {
  48.     UpdateParamFlags(SetParamMenu, *UMin, *UMax, *VMin, *VMax,
  49.                 *NumOfSamples, *NumOfIsoLines, *DblBuffer);
  50.     GGMenuDraw(9, SetParamMenu, TRUE);               /* Draw Menu. */
  51.     select = GGMenuPick();
  52.     switch (select)    {
  53.         case 1:                        /* Set UMin. */
  54.         sprintf(s, "%lf", *UMin);
  55.         GetLine(stdin, TRUE, "Enter New UMin:", s);
  56.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp < *UMax))
  57.             *UMin = Rtemp;
  58.         else GGPutErrorMsg("Wrong Format/Range");
  59.         break;
  60.         case 2:                        /* Set UMax. */
  61.         sprintf(s, "%lf", *UMax);
  62.         GetLine(stdin, TRUE, "Enter New UMax:", s);
  63.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp > *UMin))
  64.             *UMax = Rtemp;
  65.         else GGPutErrorMsg("Wrong Format/Range");
  66.         break;
  67.         case 3:                        /* Set VMin. */
  68.         sprintf(s, "%lf", *VMin);
  69.         GetLine(stdin, TRUE, "Enter New VMin:", s);
  70.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp < *VMax))
  71.             *VMin = Rtemp;
  72.         else GGPutErrorMsg("Wrong Format/Range");
  73.         break;
  74.         case 4:                        /* Set VMax. */
  75.         sprintf(s, "%lf", *VMax);
  76.         GetLine(stdin, TRUE, "Enter New VMax:", s);
  77.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp > *VMin))
  78.             *VMax = Rtemp;
  79.         else GGPutErrorMsg("Wrong Format/Range");
  80.         break;
  81.         case 5:              /* Set number of samples per function. */
  82.         OldSamples = *NumOfSamples;
  83.         OldIsoLines = *NumOfIsoLines;
  84.         sprintf(s, "%d", *NumOfSamples);
  85.         GetLine(stdin, TRUE, "New NumOfSamples:", s);
  86.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp >= 2) &&
  87.                         (Rtemp <= MAX_SAMPLES)) {
  88.             *NumOfSamples = (int) Rtemp;
  89.             UpdateDataStruct(OldSamples, OldIsoLines, NumOfSamples,
  90.                        NumOfIsoLines, IsoLinesU, IsoLinesV);
  91.         }
  92.         else GGPutErrorMsg("Wrong Format/Range");
  93.         break;
  94.         case 6:              /* Set number of samples per function. */
  95.         OldSamples = *NumOfSamples;
  96.         OldIsoLines = *NumOfIsoLines;
  97.         sprintf(s, "%d", *NumOfIsoLines);
  98.         GetLine(stdin, TRUE, "New NumOfIsoLines:", s);
  99.         if ((sscanf(s, "%lf", &Rtemp) == 1) && (Rtemp >= 2) &&
  100.             (Rtemp <= MAX_ISO_LINES)) {
  101.             *NumOfIsoLines = (int) Rtemp;
  102.             UpdateDataStruct(OldSamples, OldIsoLines, NumOfSamples,
  103.                        NumOfIsoLines, IsoLinesU, IsoLinesV);
  104.         }
  105.         else GGPutErrorMsg("Wrong Format/Range");
  106.         break;
  107.         case 7:                /* Toggles double buffering. */
  108.         *DblBuffer = !*DblBuffer;
  109.         break;
  110.         case 8:                            /* Help. */
  111.         GGPrintHelpMenu("DrawFn3D.hlp", "SETPARAM");
  112.         break;
  113.         case 9:                            /* Exit. */
  114.         GGClearMenuArea();
  115.         return;
  116.     }
  117.     }
  118. }
  119.  
  120. /*****************************************************************************
  121. *   Routine to update the EditMenu status according to flags :             *
  122. *****************************************************************************/
  123. static void UpdateParamFlags(struct MenuItem SetParamMenu[],
  124.     double UMin, double UMax, double VMin, double VMax,
  125.     int NumOfSamples, int NumOfIsoLines, int DblBuffer)
  126. {
  127.     sprintf(SetParamMenu[1].string, "Set UMin=%7lg", UMin);
  128.     sprintf(SetParamMenu[2].string, "Set UMax=%7lg", UMax);
  129.     sprintf(SetParamMenu[3].string, "Set VMin=%7lg", VMin);
  130.     sprintf(SetParamMenu[4].string, "Set VMax=%7lg", VMax);
  131.  
  132.     sprintf(SetParamMenu[5].string, "Set Samples=%4d", NumOfSamples);
  133.     sprintf(SetParamMenu[6].string, "Set IsoLines=%4d", NumOfIsoLines);
  134.  
  135.     if (DblBuffer) sprintf(SetParamMenu[7].string, "Double Buffer ON");
  136.     else       sprintf(SetParamMenu[7].string, "Double Buffer OFF");
  137. }
  138.  
  139. /*****************************************************************************
  140. *   Routine to update the main data structure IsoLineX/Y for new config. :   *
  141. *****************************************************************************/
  142. void UpdateDataStruct(int OldSamples, int OldIsoLines,
  143.     int *NumOfSamples, int *NumOfIsoLines,
  144.     struct IsoLine *IsoLinesU[MAX_ISO_LINES],
  145.     struct IsoLine *IsoLinesV[MAX_ISO_LINES])
  146. {
  147.     int    i, j;
  148.  
  149.     for    (i=0; i<OldIsoLines; i++) {             /* Free old allocation. */
  150.     free(IsoLinesU[i]);
  151.     free(IsoLinesV[i]);
  152.     }
  153.  
  154.     for    (i=0; i<*NumOfIsoLines;    i++) {         /* Allocate new data structure. */
  155.     IsoLinesU[i] = (IsoLine    *) malloc(3 * sizeof(float) * (*NumOfSamples));
  156.     IsoLinesV[i] = (IsoLine    *) malloc(3 * sizeof(float) * (*NumOfSamples));
  157.     if (IsoLinesV[i] == (IsoLine *)    NULL) {           /* Not enough memory! */
  158.         GGPutErrorMsg("Not enough memory.");
  159.         for    (j=0; j<=i; j++) {         /* Free the new allocation. */
  160.         free(IsoLinesU[j]);
  161.         free(IsoLinesV[j]);
  162.         }
  163.         *NumOfIsoLines = OldIsoLines;              /* Restore it! */
  164.         *NumOfSamples = OldSamples;
  165.         for    (j=0; j<*NumOfIsoLines;    j++) {          /* Allocate as it was. */
  166.            IsoLinesU[j] = (IsoLine *)
  167.                    malloc(3 * sizeof(float) * (*NumOfSamples));
  168.            IsoLinesV[j] = (IsoLine *)
  169.                    malloc(3 * sizeof(float) * (*NumOfSamples));
  170.         }
  171.         return;                /* Nothing to do any more... */
  172.     }
  173.     }
  174. }
  175.