Actual source code: drawreg.c
1: /*$Id: drawreg.c,v 1.45 2001/06/21 21:15:18 bsmith Exp $*/
2: /*
3: Provides the registration process for PETSc PetscDraw routines
4: */
5: #include src/sys/src/draw/drawimpl.h
7: /*
8: Contains the list of registered PetscDraw routines
9: */
10: PetscFList PetscDrawList = 0;
14: /*@C
15: PetscDrawCreate - Creates a graphics context.
17: Collective on MPI_Comm
19: Input Parameter:
20: + comm - MPI communicator
21: . display - X display when using X windows
22: . title - optional title added to top of window
23: . x,y - coordinates of lower left corner of window or PETSC_DECIDE
24: - w, h - width and height of window or PETSC_DECIDE or PETSC_DRAW_HALF_SIZE, PETSC_DRAW_FULL_SIZE,
25: or PETSC_DRAW_THIRD_SIZE or PETSC_DRAW_QUARTER_SIZE
27: Output Parameter:
28: . draw - location to put the PetscDraw context
30: Level: beginner
32: Concepts: graphics^creating context
33: Concepts: drawing^creating context
35: .seealso: PetscDrawSetFromOptions(), PetscDrawDestroy(), PetscDrawSetType()
36: @*/
37: int PetscDrawCreate(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscDraw *indraw)
38: {
39: PetscDraw draw;
40: int ierr;
43: *indraw = 0;
44: PetscHeaderCreate(draw,_p_PetscDraw,struct _PetscDrawOps,PETSC_DRAW_COOKIE,-1,"Draw",comm,PetscDrawDestroy,0);
45: PetscLogObjectCreate(draw);
46: draw->type = -1;
47: draw->data = 0;
48: PetscStrallocpy(title,&draw->title);
49: PetscStrallocpy(display,&draw->display);
50: draw->x = x;
51: draw->y = y;
52: draw->w = w;
53: draw->h = h;
54: draw->pause = 0;
55: draw->coor_xl = 0.0;
56: draw->coor_xr = 1.0;
57: draw->coor_yl = 0.0;
58: draw->coor_yr = 1.0;
59: draw->port_xl = 0.0;
60: draw->port_xr = 1.0;
61: draw->port_yl = 0.0;
62: draw->port_yr = 1.0;
63: draw->popup = 0;
64: PetscOptionsGetInt(PETSC_NULL,"-draw_pause",&draw->pause,PETSC_NULL);
65: *indraw = draw;
66: return(0);
67: }
68:
71: /*@C
72: PetscDrawSetType - Builds graphics object for a particular implementation
74: Collective on PetscDraw
76: Input Parameter:
77: + draw - the graphics context
78: - type - for example, PETSC_DRAW_X
80: Options Database Command:
81: . -draw_type <type> - Sets the type; use -help for a list
82: of available methods (for instance, x)
84: Level: intermediate
86: Notes:
87: See "petsc/include/petscdraw.h" for available methods (for instance,
88: PETSC_DRAW_X)
90: Concepts: drawing^X windows
91: Concepts: X windows^graphics
92: Concepts: drawing^postscript
93: Concepts: postscript^graphics
94: Concepts: drawing^Microsoft Windows
96: .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy()
97: @*/
98: int PetscDrawSetType(PetscDraw draw,const PetscDrawType type)
99: {
100: int ierr,(*r)(PetscDraw);
101: PetscTruth match;
102: PetscTruth flg=PETSC_FALSE;
108: PetscTypeCompare((PetscObject)draw,type,&match);
109: if (match) return(0);
111: #if defined(PETSC_HAVE_X11)
112: /* User requests no graphics */
113: PetscOptionsHasName(PETSC_NULL,"-nox",&flg);
114: #endif
116: /*
117: This is not ideal, but it allows codes to continue to run if X graphics
118: was requested but is not installed on this machine. Mostly this is for
119: testing.
120: */
121: #if !defined(PETSC_HAVE_X11)
122: {
123: PetscStrcmp(type,PETSC_DRAW_X,&match);
124: if (match) {
125: PetscTruth dontwarn = PETSC_TRUE;
126: flg = PETSC_TRUE;
127: PetscOptionsHasName(PETSC_NULL,"-nox_warning",&dontwarn);
128: if (!dontwarn) {
129: (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n");
130: }
131: }
132: }
133: #endif
134: if (flg) {
135: type = PETSC_DRAW_NULL;
136: }
138: if (draw->data) {
139: /* destroy the old private PetscDraw context */
140: (*draw->ops->destroy)(draw);
141: draw->data = 0;
142: }
144: /* Get the function pointers for the graphics method requested */
145: if (!PetscDrawList) SETERRQ(1,"No draw implementations ierr");
147: PetscFListFind(draw->comm,PetscDrawList,type,(void (**)(void)) &r);
149: if (!r) SETERRQ1(1,"Unknown PetscDraw type given: %s",type);
151: PetscObjectChangeTypeName((PetscObject)draw,type);
153: draw->data = 0;
154: (*r)(draw);
156: return(0);
157: }
161: /*@C
162: PetscDrawRegisterDestroy - Frees the list of PetscDraw methods that were
163: registered by PetscDrawRegisterDynamic().
165: Not Collective
167: Level: developer
169: .seealso: PetscDrawRegisterDynamic(), PetscDrawRegisterAll()
170: @*/
171: int PetscDrawRegisterDestroy(void)
172: {
176: if (PetscDrawList) {
177: PetscFListDestroy(&PetscDrawList);
178: PetscDrawList = 0;
179: }
180: return(0);
181: }
185: /*@C
186: PetscDrawGetType - Gets the PetscDraw type as a string from the PetscDraw object.
188: Not Collective
190: Input Parameter:
191: . draw - Krylov context
193: Output Parameters:
194: . name - name of PetscDraw method
196: Level: advanced
198: @*/
199: int PetscDrawGetType(PetscDraw draw,PetscDrawType *type)
200: {
202: *type = draw->type_name;
203: return(0);
204: }
208: int PetscDrawRegister(const char *sname,const char *path,const char *name,int (*function)(PetscDraw))
209: {
210: int ierr;
211: char fullname[PETSC_MAX_PATH_LEN];
214: PetscFListConcat(path,name,fullname);
215: PetscFListAdd(&PetscDrawList,sname,fullname,(void (*)(void))function);
216: return(0);
217: }
221: /*@C
222: PetscDrawSetFromOptions - Sets the graphics type from the options database.
223: Defaults to a PETSc X windows graphics.
225: Collective on PetscDraw
227: Input Parameter:
228: . draw - the graphics context
230: Options Database Keys:
231: + -nox - do not use X graphics (ignore graphics calls, but run program correctly)
232: - -nox_warning - when X windows support is not installed this prevents the warning message
233: from being printed
235: Level: intermediate
237: Notes:
238: Must be called after PetscDrawCreate() before the PetscDrawtor is used.
240: Concepts: drawing^setting options
241: Concepts: graphics^setting options
243: .seealso: PetscDrawCreate(), PetscDrawSetType()
245: @*/
246: int PetscDrawSetFromOptions(PetscDraw draw)
247: {
248: int ierr;
249: PetscTruth flg,nox;
250: char vtype[256];
251: const char *def;
252: #if !defined(PARCH_Win32) && !defined(PETSC_HAVE_X11)
253: PetscTruth warn;
254: #endif
259: if (!PetscDrawList) SETERRQ(1,"No draw implementations registered");
260: if (draw->type_name) {
261: def = draw->type_name;
262: } else {
263: PetscOptionsHasName(PETSC_NULL,"-nox",&nox);
264: def = PETSC_DRAW_NULL;
265: #if defined(PARCH_win32)
266: if (!nox) def = PETSC_DRAW_WIN32;
267: #elif defined(PETSC_HAVE_X11)
268: if (!nox) def = PETSC_DRAW_X;
269: #else
270: PetscOptionsHasName(PETSC_NULL,"-nox_warning",&warn);
271: if (!nox && !warn) {
272: (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n");
273: }
274: #endif
275: }
276: PetscOptionsBegin(draw->comm,draw->prefix,"Graphics (PetscDraw) Options","Draw");
277: PetscOptionsList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);
278: if (flg) {
279: PetscDrawSetType(draw,vtype);
280: } else if (!draw->type_name) {
281: PetscDrawSetType(draw,def);
282: }
283: PetscOptionsName("-nox","Run without graphics","None",&nox);
284: PetscOptionsEnd();
285: return(0);
286: }