home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / chemesthetics_427.lzh / Chemesthetics / Source / Source.LZH / eingabe.c < prev    next >
C/C++ Source or Header  |  1990-12-06  |  9KB  |  328 lines

  1. #include <intuition/intuitionbase.h>
  2. #include <libraries/mathffp.h>
  3. #include "messages.h"
  4. #include "chem_defs.h"
  5. #include "eingabe.h"
  6.  
  7. int      PropBlock = 0xFFFF, PropSchritte = 1;
  8. T_A      alt;                   /* enthaelt Original-Werte, nicht gedreht etc. */
  9.  
  10. extern int atomanz, drehx, drehy, drehz, ref, geladene_Atome;
  11. extern double mattheit, matthm1, abstand, vergr, zf, VERGRFAKTOR;
  12. extern T_A a;
  13. extern VEKTOR l, b;
  14. extern USHORT GadgetID;
  15. extern BOOL reflexion;
  16. extern char Dateiname[];
  17. extern struct Atom *GAtom[];
  18. extern struct Screen *FirstScreen;
  19.  
  20. struct Window *Window2, *OpenWindow();
  21.  
  22. void      uebertragen(), anzeigen(), FlushStrGadget(), Prepare();
  23. double      atof();
  24.  
  25. int      Eingabe()
  26. {
  27.   register int i, j;
  28.   int        ende = 0, anfang = 1, nummer = atomanz + 1, pos, mx, my, rwert,
  29.         atomanz_alt, a_name;
  30.   char        dummy[81];
  31.   T_A        kopie;
  32.  
  33.   EingabeFenster.Screen = FirstScreen;
  34.   if (!(Window2 = (struct Window *) OpenWindow(&EingabeFenster)))
  35.     return;
  36.   Print(Window2, Dateiname, 7, 0, -1, 20);      /* zentriert ! */
  37.   Print(Window2, "Atom                         X      Y      Z    Radius",
  38.     9, 0, 62, 127);
  39.   Box(Window2, 1, 6, 4, 35, 608, 86);
  40.   sprintf(dummy, "%s    %s               %s               %s             ",
  41.       MAGNF, TURN, LIGHT, REFLEX);
  42.   Print(Window2, dummy, 13, 2, 4, 158);
  43.   atomanz_alt = atomanz;           /* Sichern, falls Abbr. gedrueckt wird */
  44.   for (i = 1; i <= atomanz; i++)
  45.   {
  46.     a[i] = alt[i];               /* Original-Werte zurückschreiben */
  47.     kopie[i] = a[i];               /* Sicherheitskopie des Molekuels
  48.                       anlegen */
  49.   }
  50.   uebertragen();
  51.   if (atomanz > 10)
  52.   {
  53.     PropBlock = (int) (0xFFFF / (float) (atomanz / 10.0));
  54.     PropSchritte = (int) (0xFFFF / (atomanz - 10));
  55.     ModifyProp(&Prop, Window2, NULL, AUTOKNOB | FREEVERT, 0, 0, 0, PropBlock);
  56.   }
  57.   while (!ende)
  58.   {
  59.     switch (Nachricht(Window2))
  60.     {
  61.       case CLOSEWINDOW:
  62.     rwert = 0;
  63.     ende++;
  64.     break;
  65.       case GADGETUP:
  66.     switch (GadgetID)
  67.     {
  68.       case 1:               /* PropGadget */
  69.         if (atomanz > 9)
  70.         {
  71.           anfang = PropSInfo.VertPot / PropSchritte + 1;
  72.           if (anfang > atomanz - 9)
  73.         anfang = atomanz - 9;
  74.           anzeigen(anfang);
  75.         }
  76.         break;
  77.       case 2:               /* Pfeil nach oben */
  78.         if (anfang > 1)
  79.         {
  80.           anfang--;
  81.           anzeigen(anfang);
  82.           ModifyProp(&Prop, Window2, NULL, AUTOKNOB | FREEVERT,
  83.               0, PropSInfo.VertPot - PropSchritte, 0, PropBlock);
  84.         }
  85.         break;
  86.       case 3:               /* Pfeil nach unten */
  87.         if (anfang < atomanz - 9)
  88.         {
  89.           anfang++;
  90.           anzeigen(anfang);
  91.           ModifyProp(&Prop, Window2, NULL, AUTOKNOB | FREEVERT,
  92.               0, PropSInfo.VertPot + PropSchritte, 0, PropBlock);
  93.         }
  94.         break;
  95.  
  96.       case 4:               /* Vergroesserung */
  97.         ActivateGadget(&DrehX, Window2, NULL);
  98.         break;
  99.       case 5:
  100.         ActivateGadget(&DrehY, Window2, NULL);
  101.         break;
  102.       case 6:
  103.         ActivateGadget(&DrehZ, Window2, NULL);
  104.         break;
  105.       case 7:
  106.         ActivateGadget(&LichtX, Window2, NULL);
  107.         break;
  108.       case 8:
  109.         ActivateGadget(&LichtY, Window2, NULL);
  110.         break;
  111.       case 9:
  112.         ActivateGadget(&LichtZ, Window2, NULL);
  113.         break;
  114.       case 10:
  115.         ActivateGadget(&Reflex, Window2, NULL);
  116.         break;
  117.       case 11:
  118.         break;
  119.       case 12:
  120.         strcpy(a[nummer].name, AtomSIBuff);
  121.         ActivateGadget(&PosX, Window2, NULL);
  122.         break;
  123.       case 13:
  124.         a[nummer].x = PosXSInfo.LongInt;
  125.         ActivateGadget(&PosY, Window2, NULL);
  126.         break;
  127.       case 14:
  128.         a[nummer].y = PosYSInfo.LongInt;
  129.         ActivateGadget(&PosZ, Window2, NULL);
  130.         break;
  131.       case 15:
  132.         a[nummer].z = PosZSInfo.LongInt;
  133.         ActivateGadget(&Radius, Window2, NULL);
  134.         break;
  135.       case 16:
  136.         a[nummer].r = RadiusSInfo.LongInt;
  137.         if (Neu.Flags & SELECTED)  /* nur wenn wirklich neues Atom */
  138.         {
  139.           atomanz++;
  140.           if (atomanz > 10)
  141.           {
  142.         PropBlock = (int) (0xFFFF / (float) (atomanz / 10.0));
  143.         PropSchritte = (int) (0xFFFF / (atomanz - 9));
  144.         ModifyProp(&Prop, Window2, NULL, AUTOKNOB | FREEVERT,
  145.                0, anfang * PropSchritte, 0, PropBlock);
  146.           }
  147.           nummer++;
  148.         }
  149.         anzeigen(anfang);
  150.         FlushStrGadget(&AtomSInfo);
  151.         FlushStrGadget(&PosXSInfo);
  152.         FlushStrGadget(&PosYSInfo);
  153.         FlushStrGadget(&PosZSInfo);
  154.         FlushStrGadget(&RadiusSInfo);
  155.         RefreshGList(&Atom, Window2, NULL, 5);
  156.         if (Neu.Flags & SELECTED)
  157.         {
  158.           sprintf(dummy, "%3d", nummer);
  159.           Print(Window2, dummy, 1, 0, 8, 137);
  160.           ActivateGadget(&Atom, Window2, NULL);
  161.         }
  162.         break;
  163.       case 17:               /* OK */
  164.         zf = atof(VergrSIBuff);
  165.         if (zf == 0.0)
  166.           MessageReq(Window2, MAGNF_FACTOR, 8, 10, 12);
  167.         if (zf == 0.0)
  168.           break;
  169.         drehx = DrehXSInfo.LongInt;
  170.         drehy = DrehYSInfo.LongInt;
  171.         drehz = DrehZSInfo.LongInt;
  172.         l.x = atof(LichtXSIBuff);
  173.         l.y = atof(LichtYSIBuff);
  174.         l.z = atof(LichtZSIBuff);
  175.         ref = ReflexSInfo.LongInt;
  176.         for (i = 1; i <= atomanz; i++)
  177.           alt[i] = a[i];           /* Original-Werte aufbewahren fuer
  178.                       erneutes Editieren */
  179.         rwert = 1;
  180.         ende++;
  181.         break;
  182.       case 18:               /* Abbruch */
  183.         atomanz = atomanz_alt;     /* "alte" Anzahl zurueckholen */
  184.         for (i = 1; i <= atomanz; i++)
  185.           a[i] = kopie[i];           /* Sicherheitskopie zurueckholen */
  186.         rwert = 0;
  187.         ende++;
  188.         break;
  189.       case 19:               /* Edit oder Anfügen ? */
  190.         if (Neu.Flags & SELECTED)
  191.         {
  192.           nummer = atomanz + 1;
  193.           sprintf(dummy, "%3d", nummer);
  194.           Print(Window2, dummy, 1, 0, 8, 137);
  195.           ActivateGadget(&Atom, Window2, NULL);
  196.         }
  197.         break;
  198.     }
  199.     break;
  200.       case MOUSEBUTTONS:
  201.     mx = Window2->MouseX;
  202.     my = Window2->MouseY;
  203.     pos = (my - 38) / 8;
  204.     if (pos >= 0 && pos < 10 && mx < 618)
  205.     {
  206.       pos = pos + anfang;
  207.       strcpy(AtomSIBuff, a[pos].name);
  208.       sprintf(PosXSIBuff, "%d", a[pos].x);
  209.       sprintf(PosYSIBuff, "%d", a[pos].y);
  210.       sprintf(PosZSIBuff, "%d", a[pos].z);
  211.       sprintf(RadiusSIBuff, "%d", a[pos].r);
  212.       RefreshGList(&Atom, Window2, NULL, 5);
  213.       nummer = pos;            /* Aktuelle Atom-Nummer aufs aus-
  214.                       gewaehlte Atom setzen */
  215.       sprintf(dummy, "%3d", nummer);
  216.       Print(Window2, dummy, 1, 0, 8, 136);
  217.       a_name = 105;            /* auf ??? setzen, falls nichts ge-
  218.                       funden wird */
  219.       for (j = 1; j <= geladene_Atome; j++)
  220.       {
  221.         if (strcmp(a[pos].name, GAtom[j]->Kurzz) == NULL)
  222.         {
  223.           a_name = j;
  224.           break;
  225.         }
  226.       }
  227.       sprintf(dummy, "%-20s", GAtom[a_name]->Name);
  228.       Print(Window2, dummy, 1, 0, 96, 136);
  229.     }
  230.     break;
  231.     }
  232.   }
  233.   CloseWindowSafely(Window2, NULL);
  234.   Window2 = NULL;
  235.   return rwert;
  236. }
  237.  
  238. void      uebertragen()
  239. {
  240.   int        i;
  241.   char        dummy[80];
  242.  
  243.   anzeigen(1);                         /* Start immer bei 1 */
  244.   sprintf(dummy, "%3.1lf", zf);
  245.   strncpy(VergrSIBuff, dummy, VergrSInfo.MaxChars);
  246.   VergrSInfo.NumChars = strlen(VergrSIBuff);
  247.   DrehXSInfo.LongInt = drehx;
  248.   sprintf(DrehXSIBuff, "%d", drehx);
  249.   DrehYSInfo.LongInt = drehy;
  250.   sprintf(DrehYSIBuff, "%d", drehy);
  251.   DrehZSInfo.LongInt = drehz;
  252.   sprintf(DrehZSIBuff, "%d", drehz);
  253.   sprintf(dummy, "%7.0f", l.x);
  254.   strncpy(LichtXSIBuff, dummy, LichtXSInfo.MaxChars);
  255.   LichtXSInfo.NumChars = strlen(LichtXSIBuff);
  256.   sprintf(dummy, "%7.0f", l.y);
  257.   strncpy(LichtYSIBuff, dummy, LichtYSInfo.MaxChars);
  258.   LichtYSInfo.NumChars = strlen(LichtYSIBuff);
  259.   sprintf(dummy, "%7.0f", l.z);
  260.   strncpy(LichtZSIBuff, dummy, LichtZSInfo.MaxChars);
  261.   LichtZSInfo.NumChars = strlen(LichtZSIBuff);
  262.   ReflexSInfo.LongInt = ref;
  263.   sprintf(ReflexSIBuff, "%d", ref);
  264.   RefreshGList(&Vergr, Window2, NULL, 8);
  265. }
  266.  
  267. void      anzeigen(anfang)
  268. int      anfang;
  269. {
  270.   register int i, j;
  271.   int        y = 0, nummer;
  272.   char        dummy[80];
  273.  
  274.   for (i = anfang; i <= anfang + 9; i++)
  275.   {
  276.     nummer = 105;
  277.     for (j = 1; j <= geladene_Atome; j++)
  278.     {
  279.       if (strcmp(a[i].name, GAtom[j]->Kurzz) == 0)
  280.       {
  281.     nummer = j;
  282.     break;
  283.       }
  284.     }
  285.     sprintf(dummy, "%3d)   %3s %-20s %6d %6d %6d  %4d                ",
  286.       i, a[i].name, GAtom[nummer]->Name, a[i].x, a[i].y, a[i].z, a[i].r);
  287.     Print(Window2, dummy, 3, 5, 8, 44 + y * 8);
  288.     y++;
  289.   }
  290. }
  291.  
  292. void      FlushStrGadget(StrInfo)
  293. struct StringInfo *StrInfo;
  294. {
  295.   strcpy(StrInfo->Buffer, "");
  296.   StrInfo->NumChars = 0;
  297.   StrInfo->BufferPos = 0;
  298. }
  299.  
  300. void      Prepare()                    /* Werte vorbereiten zum Zeichnen */
  301. {
  302.   int        n;
  303.  
  304.   atomedrehen('x', (double) drehx);
  305.   atomedrehen('y', (double) drehy);
  306.   atomedrehen('z', (double) drehz);
  307.   vergr = VERGRFAKTOR;
  308.   vergr *= zf;
  309.   abstand = BILDSCHIRMABSTAND / zf;
  310.   b.x = 0.0;
  311.   b.y = -abstand;
  312.   b.z = 0.0;
  313.   for (n = 1; n <= atomanz; n++)       /*Vergroeßerung der Kalotten*/
  314.     a[n].r = round(ATOMVERGRFAKT * a[n].r);
  315.   reflexion = TRUE;
  316.   if (ref < 1)
  317.     reflexion = FALSE;
  318.   else
  319.   {
  320.     if (ref > 100)
  321.       ref = 100;
  322.     mattheit = (double) ref / 100.0;
  323.     matthm1 = 1.0 / mattheit - 1.0;
  324.   }
  325.   atomeordnen();
  326.   atomezentrieren();
  327. }
  328.