home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************
- * *
- * Filename : PltL3.c *
- * *
- *****************************************************************
- * *
- * Comment : Level 3 der Plotlibrary. Alle Funktionen für die *
- * Plotterausgabe. *
- * *
- * Funktionen *
- * ========== *
- * *
- * PlOpenGraphics() öffnet das Graphiksystem *
- * PlCloseGraphics() schliesst das Graphiksystem *
- * PlClearGraphics() löscht den Bildschirm *
- * PlGetMaxX() max. horiz. Auflösung *
- * PlGetMaxY() max. vert. Auflösung *
- * PlDrawText() schreibt eine Text *
- * PlSetLineStyle() setzt Linienattribute *
- * PlGetTextSize() holt Textgrösse *
- * PlSetTextSize() setzt 8*8 Text *
- * PlGetFgColor() holt Stiftfarbe *
- * PlSetFgColor() setzt Stiftfarbe *
- * PlGetBackColor() holt Hintergrundefarbe *
- * PlSetBackColor() setzt Hintergrundfarbe *
- * PlDrawLine() zeichnet eine Line *
- * PlDrawPolyLine() zeichnet Kurvenzug *
- * PlFillPolyLine() zeichnet Polygon *
- * PlSetFillStyle() setzt Füllmuster *
- * PlDrawRectangle() zeichnet ein Rechteck *
- * PlGetMaxColor() holt max. verfügbare Farbenanzahl *
- * PlRotate() dreht die Plotausgabe *
- * PlTrans() Minitransformation für Plotter *
- * *
- * Rev : V1.0 *
- * *
- * History : V1.0 erstellen dieses Files 04/12/89 *
- * *
- * Doc : Plotlibrary User's Guide *
- * *
- * Bugs : keine bekannten *
- * *
- * Autor : Oesch Silvano *
- * *
- * Datum : 04/12/89 *
- * *
- ****************************************************************/
-
- /****************************************************************
- * *
- * Plotlibrary Includedateien *
- * *
- ****************************************************************/
-
- #include "Plot.h"
- #include "PltL3.h"
-
- /****************************************************************
- * *
- * globale statische Variablen *
- * *
- *****************************************************************
- * *
- * Die meisten der unten aufgeführten Variablen werden in einer *
- * späteren Erweiterung ausgelagert in eine Datei die dann beim *
- * öffnen der Graphik nachgeladen wird. Dieses nachladen *
- * ermöglicht eine weitere unterstützung verschiedener Plotter *
- * welche nicht unbedingt HPGL verstehen. Weiter können so auch *
- * verschiedene Blattgrössen definiert werden. *
- * *
- ****************************************************************/
-
- static int apen;
- static FILE *plotfile = NULL;
-
- static float zoll = 2.541,
- hz = 7.4,
- lz = 10.5,
- xz,yz,xpz,ypz;
-
- static int steps = 1024,
- pens = 6,
- xp,yp,xop,yop;
-
- static char HpPU[]="PU"; /* alle benötigten HPGL */
- static char HpPD[]="PD"; /* Befehle auf einen Blick */
- static char HpPA[]="PA";
- static char HpIP[]="IP";
- static char HpSC[]="SC";
- static char HpSP[]="SP";
- static char HpEA[]="EA";
- static char HpRO[]="RO";
- static char HpDF[]="DF";
- static char HpIN[]="IN";
- static char HpIW[]="IW";
- static char HpPG[]="PG";
- static char HpSI[]="SI";
- static char HpLB[]="LB";
- static char HpLT[]="LT";
- static char HpCS[]="CS";
-
- static char defname[]="Plot.plt";
-
- /****************************************************************
- * *
- * externe Variablen *
- * *
- ****************************************************************/
-
- extern struct Plot *plot;
- extern int plerr;
-
- /****************************************************************
- * *
- * Function : PlOpenGraphics() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int returnset *
- * != FALSE alle klar *
- * == FALSE Fehler *
- * *
- *****************************************************************
- * *
- * Comment : Hier werden alle Plotterwerte initialisiert und *
- * die Ausgabedatei geöffnet. Bei einer späteren *
- * Erweiterung wird zusätzlich ein Plottertreiber *
- * nachgeladen. *
- * *
- ****************************************************************/
-
- int PlOpenGraphics()
- {
-
- int returnset; /* allg Rückgabewert */
- float mem; /* temp. Speicher */
- char *filename; /* Dateinamen */
-
- xz = plot->xlength/zoll; /* berechnen der Ausgabe- */
- yz = plot->ylength/zoll; /* grössen sowie der */
- xpz = plot->xout/zoll; /* Ausgabepunkte */
- ypz = plot->yout/zoll;
-
- if (plot->pldisp & ROTATE) /* Wenn gedreht */
- swap(lz,hz,mem); /* vertausche länge mit */
- /* der höhe */
-
- if ((xz+xpz > lz) or /* liegt noch alles in den */
- (yz+ypz > hz)) /* Papiergrenzen */
- { /* Nein, Fehler */
- seterror(PLSIZE);
- setreturn(FALSE);
- }
- else /* Ja */
- {
-
- xp = (int)(xz*steps); /* berechne Punkte */
- yp = (int)(yz*steps);
- xop = (int)(xpz*steps);
- yop = (int)((hz-yz-ypz)*steps);
-
- if (plot->pldisp & ROTATE) /* Vertauschte Werte */
- swap(lz,hz,mem); /* rücksetzten */
- if (plot->outname) /* Wenn Namen gegeben */
- filename = plot->outname; /* nimm diesen */
- else /* sonst */
- filename = defname; /* nimm default */
-
- plotfile = fopen(filename,"w"); /* öffne Datei */
- if (plotfile) /* alles klar ? */
- { /* initialisiere Plotter */
- fprintf(plotfile,"%s;\n",HpDF);
- if (plot->pldisp & ROTATE) /* Drehen ? */
- PlRotate(90);
- fprintf(plotfile,"%s 2;\n",HpCS);
- setreturn(TRUE); /* alles klar */
- }
- else /* setzte Fehler */
- {
- seterror(PLOPER);
- setreturn(FALSE);
- }
- }
- return(returnset); /* und zurück */
- }
-
- /****************************************************************
- * *
- * Function : PlCloseGraphics() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : setzt Papiervorschub und schliesst das Datenfile *
- * *
- ****************************************************************/
-
- void PlCloseGraphics()
- {
- if (plotfile) /* nur wenn geöffnet */
- {
- fprintf(plotfile,"%s;\n",HpPG); /* Seitenvorschub */
- fclose(plotfile); /* Datei schliessen */
- }
- }
-
- /****************************************************************
- * *
- * Function : PlGetMaxColor() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int maxcolor max setzbares Farbregister *
- * *
- *****************************************************************
- * *
- * Comment : gibt die Anzahl verschiedener Farbstifte zurück. *
- * *
- ****************************************************************/
-
- int PlGetMaxColor()
- {
- return(pens); /* max. Farbstifte */
- }
-
- /****************************************************************
- * *
- * Function : PlGetMaxX() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int maxx max. horizontaler setzbarer Punkt *
- * *
- *****************************************************************
- * *
- * Comment : gibt die max. horizontale Auflösung des Plotters *
- * zurück. *
- * *
- ****************************************************************/
-
- int PlGetMaxX()
- {
- return(xp); /* horiz. Punkte */
- }
-
- /****************************************************************
- * *
- * Function : PlGetMaxY() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int maxy max. vertikaler setzbarer Punkt *
- * *
- *****************************************************************
- * *
- * Comment : gibt die max. verzikale Auflösung des Plotters *
- * zurück. *
- * *
- ****************************************************************/
-
- int PlGetMaxY()
- {
- return(yp); /* vert. Punkte */
- }
-
- /****************************************************************
- * *
- * Function : PlSetTextSize() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : setzt die Textgrösse auf 80*40 Zeichen und Linien *
- * *
- ****************************************************************/
-
- void PlSetTextSize()
- {
-
- fprintf(plotfile,"%s %f %f;\n",
- HpSI,
- plot->xlength/118.5,
- plot->ylength/60.0);
- }
-
- /****************************************************************
- * *
- * Function : PlClearGraphics() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : löscht das Papier Ha, Ha, Ha !! *
- * Muss vorhanden sein wegen Kompatibilität. *
- * *
- ****************************************************************/
-
- void PlClearGraphics()
- {
- }
-
- /****************************************************************
- * *
- * Function : PlDrawText() *
- * *
- *****************************************************************
- * *
- * Input : x,y,string *
- * int x Koordinatenpunkt für untere *
- * int y linke Ecke des Textes *
- * char *string Text *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : schreibt einen Text an den Punkt(x/y) in der *
- * aktuellen Farbe *
- * *
- ****************************************************************/
-
- void PlDrawText(x,y,string)
- int x,y;
- char *string;
- {
-
- PlTrans(&x,&y); /* translaten */
- fprintf(plotfile,"%s %d %d;", /* positionieren */
- HpPU,x,y);
- fprintf(plotfile,"%s%s\x03;\n", /* Text ausgeben */
- HpLB,string);
- }
-
- /****************************************************************
- * *
- * Function : PlGetFgColor() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int color aktuelle Farbe *
- * *
- *****************************************************************
- * *
- * Comment : gibt die aktuelle Stiftfarbe zurück welche in *
- * der Variablen apen gespeichert ist. *
- * *
- ****************************************************************/
-
- int PlGetFgColor()
- {
- return(apen); /* aktuelle Farbe */
- }
-
- /****************************************************************
- * *
- * Function : PlSetFgColor() *
- * *
- *****************************************************************
- * *
- * Input : int color neue Farbe *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : setzt eine neue Stiftfarbe und speichert diese *
- * in der Variablen apen. *
- * *
- ****************************************************************/
-
- void PlSetFgColor(color)
- int color;
- {
-
- apen = color; /* speichern */
- fprintf(plotfile,"%s %d;", /* und setzten */
- HpSP,color);
-
- }
-
- /****************************************************************
- * *
- * Function : PlGetBackColor() *
- * *
- *****************************************************************
- * *
- * Input : void *
- * *
- * Output : int color *
- * *
- *****************************************************************
- * *
- * Comment : Immer Weiss, hat keine Bedeutung nur für *
- * Kompatiblität. *
- * *
- ****************************************************************/
-
- int PlGetBackColor()
- {
- return(TRUE);
- }
-
- /****************************************************************
- * *
- * Function : PlSetBackColor() *
- * *
- *****************************************************************
- * *
- * Input : int color neue Hintergrundfarbe *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Nur für Kompatibilität. Zuweisung damit Compiler *
- * keine Warnings ausgeben. *
- * *
- ****************************************************************/
-
- void PlSetBackColor(color)
- int color;
- {
- color = color; /* gegen Warnings */
- }
-
- /****************************************************************
- * *
- * Function : PlDrawLine() *
- * *
- *****************************************************************
- * *
- * Input : x1,y1,x2,y2 *
- * int x1 Startkoordinate(x1/y1) *
- * int y1 *
- * int x2 Endkoordinate(x2,y2) *
- * int y2 *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : zeichnet eine absolute Line in der aktuellen *
- * Stiftfarbe. *
- * *
- ****************************************************************/
-
- void PlDrawLine(x1,y1,x2,y2)
- int x1,
- y1,
- x2,
- y2;
- {
-
- PlTrans(&x1,&y1); /* translate */
- PlTrans(&x2,&y2); /* translate */
- fprintf(plotfile,"%s %d %d;%s %d %d;\n",
- HpPU,x1,y1, /* und zeichnen */
- HpPD,x2,y2);
- }
-
- /****************************************************************
- * *
- * Function : PlDrawPolyLine() *
- * *
- *****************************************************************
- * *
- * Input : counter,array *
- * int counter Anzahl Koordinatenpunkte *
- * GPT *array Array der Koordinatenpunkte *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Zeichnet eine folge von Linien auf den Plotter *
- * in den aktuellen Farben. Die Fläche wird nicht *
- * ausgefüllt. *
- * *
- ****************************************************************/
-
- void PlDrawPolyLine(counter,array)
- int counter;
- GPT *array;
- {
-
- PlFillPolyLine(counter,array); /* Aufruf von Fill */
-
- }
-
-
- /****************************************************************
- * *
- * Function : PlFillPolyLine() *
- * *
- *****************************************************************
- * *
- * Input : counter,array *
- * int counter Anzahl Koordinatenpunkte *
- * GPT *array Array der Koordinatenpunkte *
- * *
- * Output : int returnset Rückgabewert *
- * *
- *****************************************************************
- * *
- * Comment : Zeichnet eine folge von Linien auf den Plotter *
- * in den aktuellen Farben. Die Fläche wird nicht *
- * ausgefüllt. *
- * *
- ****************************************************************/
-
- int PlFillPolyLine(counter,array)
- int counter;
- GPT *array;
- {
- int i,x1,y1;
-
- x1 = *array++; /* Startpunkt zuweisen */
- y1 = *array++;
- PlTrans(&x1,&y1); /* translaten */
- fprintf(plotfile,"%s %d %d;%s;\n",
- HpPU,x1,y1,HpPD);
- for (i=1;i<counter;i++) /* alle restlichen Punkte */
- {
- x1 = *array++; /* zuweisen und */
- y1 = *array++;
- PlTrans(&x1,&y1); /* translaten */
- fprintf(plotfile,"%s %d %d;\n", /* schreiben */
- HpPA,x1,y1);
- }
- fprintf(plotfile,"%s;\n",HpPU);
- return(TRUE); /* ohne Worte */
- }
-
- /****************************************************************
- * *
- * Function : PlSetFillStyle() *
- * *
- *****************************************************************
- * *
- * Input : int style Füllmuster *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Ein Plotter kann kein Polygon ausfüllen, desshalb *
- * nur wegen Kompatibilität. *
- * *
- ****************************************************************/
-
- void PlSetFillStyle(style)
- int style;
- {
- style = style;
- }
-
- /****************************************************************
- * *
- * Function : PlDrawRectangle() *
- * *
- *****************************************************************
- * *
- * Input : x1,y1,x2,y2 *
- * int x1 linke *
- * int y1 obere Ecke *
- * int x2 rechte *
- * int y2 untere Ecke *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Zeichnet ein Rechteck in der aktuellen Farbe *
- * *
- ****************************************************************/
-
- void PlDrawRectangle(x1,y1,x2,y2)
- int x1,
- y1,
- x2,
- y2;
- {
-
- PlTrans(&x1,&y1); /* translaten */
- PlTrans(&x2,&y2);
- /* und schreiben */
- fprintf(plotfile,"%s %d %d;%s %d %d;\n",
- HpPU,x1,y1,HpEA,x2,y2);
- }
-
- /****************************************************************
- * *
- * Function : PlGetTextSize() *
- * *
- *****************************************************************
- * *
- * Input : axis Breite oder Höhe *
- * *
- * Output : int size Grösse in Punkten *
- * *
- *****************************************************************
- * *
- * Comment : gibt die Textgrösse für die entsprechende Achse *
- * zurück. *
- * *
- ****************************************************************/
-
- int PlGetTextSize(axis)
- int axis;
- {
- if (axis == XSIZE) /* X-Achse ? */
- return(xp/79); /* Ja */
- else /* sonst Y-Achse */
- return(yp/47);
- }
-
- /****************************************************************
- * *
- * Function : PlSetLineStyle() *
- * *
- *****************************************************************
- * *
- * Input : int typ Liniendarstellung *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : setzt den entsprechenden Linientyp. *
- * *
- ****************************************************************/
-
- void PlSetLineStyle(typ)
- int typ;
- {
-
- static int style[] = /* Verhältnisdefinition */
- {
- 2,1,
- 2,2,
- 2,4,
- 2,6
- };
-
- if (typ == SOL_LINE) /* ausgezogene Linie */
- fprintf(plotfile,"%s;",HpLT); /* setzte diese */
- else /* sonst */
- {
- typ--; /* für array */
- fprintf(plotfile,"%s %d %f;\n", /* setzte Linientyp */
- HpLT,
- style[typ*2],
- style[typ*2+1]/2.0);
- }
- }
-
- /****************************************************************
- * *
- * Function : PlRotate() *
- * *
- *****************************************************************
- * *
- * Input : int phi Winkel in Grad *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Dreht die Ausgabe um 90 Grad. *
- * *
- ****************************************************************/
-
- static void PlRotate(phi)
- int phi;
- {
- fprintf(plotfile,"%s %d;\n", /* schreibe Winkel */
- HpRO,phi);
- }
-
- /****************************************************************
- * *
- * Function : PlTrans() *
- * *
- *****************************************************************
- * *
- * Input : x,y *
- * int x Zeiger auf Koordinatenpunkt *
- * int y *
- * *
- * Output : void *
- * *
- *****************************************************************
- * *
- * Comment : Verschiebt und spiegelt die Plotausgabe zusätzlich *
- * genüber der normalen Ausgabe. *
- * *
- ****************************************************************/
-
- static void PlTrans(x,y)
- int *x,*y;
- {
- *x = *x+xop; /* einfache Rechenoperation */
- *y = -*y+yp+yop;
- }
-
-