00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #ifndef __UNIX_
00043 #include <stdlib.h>
00044 #ifndef _Windows
00045 #include <graphics.h>
00046 #else
00047 #include <windows.h>
00048 #endif
00049 #endif
00050 #include "memvirtu.h"
00051 #include "lowparam.h"
00052 #include "lowsolid.h"
00053 #include "disdispl.h"
00054 #include "gphgraph.h"
00055 #include "animatio.h"
00056 #ifdef _Windows
00057 #include "../basicViewer/cBasicViewer.h"
00058 #endif
00059
00060 #ifdef __UNIX_
00061 extern GC XViewGraphContext;
00062 extern Display *XDisplay;
00063 extern unsigned int ViewWidth, ViewHeight;
00064 extern Window ViewWndw;
00065 #else
00066 #ifdef _Windows
00068 cBasicViewer *viewer;
00069
00071 HGDIOBJ *Brushes;
00072
00073 #define SOLID_LINE PS_SOLID
00074 #define DASHED_LINE PS_DASH
00075 #define ERROR 0
00076
00077 COLORREF BGI__Colors[16];
00078 #else
00079 int GraphDriver, GraphMode, GraphError;
00080 #endif
00081 int MaxColors;
00082 #endif
00083 int MaxX, MaxY;
00084
00085 void g_frame(void)
00086 {
00087 int xmin, ymin, xmax, ymax;
00088
00089 xmin = (int)(MaxX * (dwindbox[0]));
00090 ymin = (int)(MaxY * (1.0 - dwindbox[1]));
00091 xmax = (int)(MaxX * (dwindbox[0] + dwindbox[2]));
00092 ymax = (int)(MaxY * (1.0 - dwindbox[1] - dwindbox[2]));
00093 #ifdef __UNIX_
00094
00095 if (Draw)
00096 {
00097 GGMySetLineStyle(SOLID_LINE);
00098 GGMySetColor(framecol);
00099 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, xmin, ymin, xmax, ymin);
00100 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, xmax, ymin, xmax, ymax);
00101 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, xmax, ymax, xmin, ymax);
00102 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, xmin, ymax, xmin, ymin);
00103 }
00104 #else
00105
00106 if (Draw)
00107 {
00108 #ifdef _Windows
00109 POINT *polygon;
00110
00111 HDC hdc = viewer->BeginDraw();
00112 HGDIOBJ hPen = SelectObject(hdc, CreatePen(SOLID_LINE, 1, BGI__Colors[0]));
00113 polygon = new POINT[4];
00114 polygon[0].x = xmin;
00115 polygon[0].y = ymin;
00116 polygon[1].x = xmin;
00117 polygon[1].y = ymax;
00118 polygon[2].x = xmax;
00119 polygon[2].y = ymax;
00120 polygon[3].x = xmax;
00121 polygon[3].y = ymin;
00122 Polygon(hdc, polygon, 4);
00123 delete polygon;
00124 viewer->EndDraw();
00125 viewer->Update();
00126 DeleteObject(SelectObject(hdc, hPen));
00127 #else
00128 setlinestyle(SOLID_LINE, 0, NORM_WIDTH);
00129 setcolor(framecol);
00130 rectangle(xmin, ymin, xmax, ymax);
00131 #endif
00132 }
00133 #endif
00134 if (dspfwptr)
00135 {
00136 framenum += 4;
00137 fprintf(dspfwptr, "%2d %2d %10.6f %10.6f %10.6f %10.6f\n",
00138 framecol, SOLID_LINE, -1.0, -xyratio, -1.0, xyratio);
00139 fprintf(dspfwptr, "%2d %2d %10.6f %10.6f %10.6f %10.6f\n",
00140 framecol, SOLID_LINE, -1.0, xyratio, 1.0, xyratio);
00141 fprintf(dspfwptr, "%2d %2d %10.6f %10.6f %10.6f %10.6f\n",
00142 framecol, SOLID_LINE, 1.0, xyratio, 1.0, -xyratio);
00143 fprintf(dspfwptr, "%2d %2d %10.6f %10.6f %10.6f %10.6f\n",
00144 framecol, SOLID_LINE, 1.0, -xyratio, -1.0, -xyratio);
00145 }
00146 }
00147
00148 void g_tpoint(int lt, vect2 v)
00149 {
00150 int gdcsv[2];
00151
00152 if (lncolor != -1)
00153 {
00154 gdcpos(v, gdcsv);
00155 if (Draw)
00156 {
00157
00158
00159
00160 }
00161 }
00162 }
00163
00164 void g_iline(int lt, int *gdcsv, int *gdcev)
00165 {
00166 if (lncolor != -1)
00167 {
00168 #ifdef __UNIX_
00169
00170 if (Draw)
00171 {
00172 GGMySetLineStyle(lt);
00173 GGMySetColor(lncolor);
00174 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, gdcsv[0], gdcsv[1],
00175 gdcev[0], gdcev[1]);
00176 }
00177 #else
00178
00179 if (Draw)
00180 {
00181 #ifdef _Windows
00182 POINT *polygon;
00183 HGDIOBJ hPen;
00184
00185 HDC hdc = viewer->BeginDraw();
00186 switch (lt)
00187 {
00188 case DASHED_LINE:
00189 hPen = SelectObject(hdc, CreatePen(PS_DOT, 1, BGI__Colors[lncolor]));
00190 break;
00191
00192 case SOLID_LINE:
00193 hPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, BGI__Colors[lncolor]));
00194 break;
00195 }
00196 polygon = new POINT[2];
00197 polygon[0].x = gdcsv[0];
00198 polygon[0].y = gdcsv[1];
00199 polygon[1].x = gdcev[0];
00200 polygon[1].y = gdcev[1];
00201 Polygon(hdc, polygon, 2);
00202 delete polygon;
00203 viewer->EndDraw();
00204 viewer->Update();
00205 DeleteObject(SelectObject(hdc, hPen));
00206 #else
00207 setlinestyle(lt, 0, NORM_WIDTH);
00208 setcolor(lncolor);
00209 line(gdcsv[0], gdcsv[1], gdcev[0], gdcev[1]);
00210 #endif
00211 }
00212 #endif
00213 }
00214 }
00215
00216 void g_tline(int lt, vect2 sv, vect2 ev)
00217 {
00218 int gdcsv[2], gdcev[2];
00219
00220 if (lncolor != -1)
00221 {
00222 gdcpos(sv, gdcsv);
00223 gdcpos(ev, gdcev);
00224 #ifdef __UNIX_
00225
00226 if (Draw)
00227 {
00228 GGMySetLineStyle(lt);
00229 GGMySetColor(lncolor);
00230 XDrawLine(XDisplay, ViewWndw, XViewGraphContext, gdcsv[0], gdcsv[1],
00231 gdcev[0], gdcev[1]);
00232 }
00233 #else
00234
00235 if (Draw)
00236 {
00237 #ifdef _Windows
00238 POINT *polygon;
00239 HGDIOBJ hPen;
00240
00241 HDC hdc = viewer->BeginDraw();
00242 switch (lt)
00243 {
00244 case DASHED_LINE:
00245 hPen = SelectObject(hdc, CreatePen(PS_DOT, 1, BGI__Colors[lncolor]));
00246 break;
00247
00248 case SOLID_LINE:
00249 hPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, BGI__Colors[lncolor]));
00250 break;
00251 }
00252 polygon = new POINT[2];
00253 polygon[0].x = gdcsv[0];
00254 polygon[0].y = gdcsv[1];
00255 polygon[1].x = gdcev[0];
00256 polygon[1].y = gdcev[1];
00257 Polygon(hdc, polygon, 2);
00258 delete polygon;
00259 viewer->EndDraw();
00260 viewer->Update();
00261 DeleteObject(SelectObject(hdc, hPen));
00262 #else
00263 setlinestyle(lt, 0, NORM_WIDTH);
00264 setcolor(lncolor);
00265 line(gdcsv[0], gdcsv[1], gdcev[0], gdcev[1]);
00266 #endif
00267 }
00268 #endif
00269 if (dspfwptr)
00270 {
00271 framenum++;
00272 fprintf(dspfwptr, "%2d %2d %10.6f %10.6f %10.6f %10.6f\n",
00273 lncolor, lntype, sv[0], sv[1], ev[0], ev[1]);
00274 }
00275 }
00276 }
00277
00278 void h_line(void)
00279 {
00280 int col, typ;
00281 float x1, y1, x2, y2;
00282 vect2 sv, ev;
00283
00284 if (fscanf(dspfrptr, "%d %d %f %f %f %f", &col, &typ, &x1, &y1, &x2, &y2) == 6)
00285 {
00286 sv[0] = x1;
00287 sv[1] = y1;
00288 ev[0] = x2;
00289 ev[1] = y2;
00290 lncolor = col;
00291 g_tline(typ, sv, ev);
00292 }
00293 }
00294
00295 void g_open(void)
00296 {
00297 #ifdef __UNIX_
00298 GGInitGraph(argc, argv, FALSE, FALSE);
00299 MaxX = ViewWidth;
00300 MaxY = ViewHeight;
00301 #else
00302 #ifndef _Windows
00303 GraphMode = 1;
00304 GraphDriver = DETECT;
00305 initgraph(&GraphDriver, &GraphMode, "");
00306 if ((GraphError = graphresult()) != grOk)
00307 {
00308 printf("initgraph error: %s\n", grapherrormsg(GraphError));
00309 exit(1);
00310 }
00311 MaxX = getmaxx();
00312 MaxY = getmaxy();
00313 MaxColors = getmaxcolor() + 1;
00314 #else
00315 viewer = new cBasicViewer(700, 550, "USPDesigner ver. 1.3");
00316
00317 HDC hdc = viewer->BeginDraw();
00318 SelectObject(hdc, GetStockObject(BLACK_PEN));
00319 SelectObject(hdc, GetStockObject(HOLLOW_BRUSH));
00320 viewer->EndDraw();
00321 g_clear();
00322 viewer->Show();
00323
00324 MaxX = viewer->GetWidth();
00325 MaxY = viewer->GetHeight();
00326
00327 MaxColors = 50;
00328
00329 BGI__Colors[0] = RGB(0, 0, 0);
00330 BGI__Colors[1] = RGB(0, 0, 128);
00331 BGI__Colors[2] = RGB(0, 128, 0);
00332 BGI__Colors[3] = RGB(0, 128, 128);
00333 BGI__Colors[4] = RGB(128, 0, 0);
00334 BGI__Colors[5] = RGB(128, 0, 128);
00335 BGI__Colors[6] = RGB(128, 128, 0);
00336 BGI__Colors[7] = RGB(192, 192, 192);
00337 BGI__Colors[8] = RGB(128, 128, 128);
00338 BGI__Colors[9] = RGB(128, 128, 255);
00339 BGI__Colors[10] = RGB(128, 255, 128);
00340 BGI__Colors[11] = RGB(128, 255, 255);
00341 BGI__Colors[12] = RGB(255, 128, 128);
00342 BGI__Colors[13] = RGB(255, 128, 255);
00343 BGI__Colors[14] = RGB(255, 255, 0);
00344 BGI__Colors[15] = RGB(255, 255, 255);
00345 #endif
00346 #endif
00347 }
00348
00349 void g_filbox(int color, vect2 v0, vect2 v1)
00350 {
00351 int d0[2], d1[2];
00352
00353
00354
00355 #ifdef __UNIX_
00356 #else
00357 gdcpos(v0, d0);
00358 gdcpos(v1, d1);
00359 #ifdef _Windows
00360
00361 RECT r;
00362 r.top = d0[0];
00363 r.left = d0[1];
00364 r.bottom = d1[0];
00365 r.right = d1[1];
00366
00367 HDC hdc = viewer->BeginDraw();
00368 FillRect(hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
00369 viewer->EndDraw();
00370 viewer->Update();
00371 #else
00372 setfillpattern(EMPTY_FILL, color);
00373 bar(d0[0], d0[1], d1[0], d1[1]);
00374 #endif
00375 #endif
00376 }
00377
00378 void g_clear(void)
00379 {
00380 #ifdef __UNIX_
00381 GGClearViewArea();
00382 #else
00383 #ifdef _Windows
00384
00385 RECT r;
00386 r.top = 0;
00387 r.left = 0;
00388 r.bottom = viewer->GetHeight();
00389 r.right = viewer->GetWidth();
00390
00391 HDC hdc = viewer->BeginDraw();
00392 FillRect(hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
00393 viewer->EndDraw();
00394 viewer->Update();
00395 #else
00396 cleardevice();
00397 #endif
00398 #endif
00399 }
00400
00401 void g_pcolor(int color)
00402 {
00403 lncolor = color;
00404 }
00405
00406 void g_close(void)
00407 {
00408 #ifdef __UNIX_
00409 GGCloseGraph();
00410 #else
00411 #ifdef _Windows
00412 delete viewer;
00413 #else
00414 closegraph();
00415 #endif
00416 #endif
00417 }
00418
00419 void gdcpos(vect2 npos, int *dpos)
00420 {
00421 dpos[0] = (int)(MaxX * (dwindbox[0] + (npos[0] + 1.0) / 2.0 * dwindbox[2]));
00422 dpos[1] = (int)(MaxY * (1.0 - dwindbox[1] - (npos[1] + xyratio) / xyratio
00423 / 2.0 * dwindbox[2]));
00424 }