home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d536 / chemesthetics.lha / Chemesthetics / Source / Source.LZH / eingabe.c < prev    next >
C/C++ Source or Header  |  1991-04-20  |  11KB  |  409 lines

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