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;
12: #undef __FUNCT__
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: ierr = PetscStrallocpy(title,&draw->title);
49: ierr = 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:
69: #undef __FUNCT__
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,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) flg = PETSC_TRUE;
125: }
126: #endif
127: if (flg) {
128: type = PETSC_DRAW_NULL;
129: }
131: if (draw->data) {
132: /* destroy the old private PetscDraw context */
133: ierr = (*draw->ops->destroy)(draw);
134: draw->data = 0;
135: }
137: /* Get the function pointers for the graphics method requested */
138: if (!PetscDrawList) SETERRQ(1,"No draw implementations ierr");
140: PetscFListFind(draw->comm,PetscDrawList,type,(void (**)(void)) &r);
142: if (!r) SETERRQ1(1,"Unknown PetscDraw type given: %s",type);
144: PetscObjectChangeTypeName((PetscObject)draw,type);
146: draw->data = 0;
147: (*r)(draw);
149: return(0);
150: }
152: #undef __FUNCT__
154: /*@C
155: PetscDrawRegisterDestroy - Frees the list of PetscDraw methods that were
156: registered by PetscDrawRegisterDynamic().
158: Not Collective
160: Level: developer
162: .seealso: PetscDrawRegisterDynamic(), PetscDrawRegisterAll()
163: @*/
164: int PetscDrawRegisterDestroy(void)
165: {
169: if (PetscDrawList) {
170: PetscFListDestroy(&PetscDrawList);
171: PetscDrawList = 0;
172: }
173: return(0);
174: }
176: #undef __FUNCT__
178: /*@C
179: PetscDrawGetType - Gets the PetscDraw type as a string from the PetscDraw object.
181: Not Collective
183: Input Parameter:
184: . draw - Krylov context
186: Output Parameters:
187: . name - name of PetscDraw method
189: Level: advanced
191: @*/
192: int PetscDrawGetType(PetscDraw draw,PetscDrawType *type)
193: {
195: *type = draw->type_name;
196: return(0);
197: }
199: /*MC
200: PetscDrawRegisterDynamic - Adds a method to the Krylov subspace solver package.
202: Synopsis:
203: int PetscDrawRegisterDynamic(char *name_solver,char *path,char *name_create,int (*routine_create)(PetscDraw))
205: Not Collective
207: Input Parameters:
208: + name_solver - name of a new user-defined solver
209: . path - path (either absolute or relative) the library containing this solver
210: . name_create - name of routine to create method context
211: - routine_create - routine to create method context
213: Level: developer
215: Notes:
216: PetscDrawRegisterDynamic() may be called multiple times to add several user-defined solvers.
218: If dynamic libraries are used, then the fourth input argument (routine_create)
219: is ignored.
221: Sample usage:
222: .vb
223: PetscDrawRegisterDynamic("my_draw_type",/home/username/my_lib/lib/libO/solaris/mylib.a,
224: "MyDrawCreate",MyDrawCreate);
225: .ve
227: Then, your solver can be chosen with the procedural interface via
228: $ PetscDrawSetType(ksp,"my_draw_type")
229: or at runtime via the option
230: $ -draw_type my_draw_type
232: Concepts: graphics^registering new draw classes
233: Concepts: PetscDraw^registering new draw classes
235: .seealso: PetscDrawRegisterAll(), PetscDrawRegisterDestroy()
236: M*/
238: #undef __FUNCT__
240: int PetscDrawRegister(char *sname,char *path,char *name,int (*function)(PetscDraw))
241: {
242: int ierr;
243: char fullname[PETSC_MAX_PATH_LEN];
246: PetscFListConcat(path,name,fullname);
247: PetscFListAdd(&PetscDrawList,sname,fullname,(void (*)(void))function);
248: return(0);
249: }
251: #undef __FUNCT__
253: /*@C
254: PetscDrawSetFromOptions - Sets the graphics type from the options database.
255: Defaults to a PETSc X windows graphics.
257: Collective on PetscDraw
259: Input Parameter:
260: . draw - the graphics context
262: Options Database Keys:
263: + -nox - do not use X graphics (ignore graphics calls, but run program correctly)
264: - -nox_warning - when X windows support is not installed this prevents the warning message
265: from being printed
267: Level: intermediate
269: Notes:
270: Must be called after PetscDrawCreate() before the PetscDrawtor is used.
272: Concepts: drawing^setting options
273: Concepts: graphics^setting options
275: .seealso: PetscDrawCreate(), PetscDrawSetType()
277: @*/
278: int PetscDrawSetFromOptions(PetscDraw draw)
279: {
280: int ierr;
281: PetscTruth flg,nox;
282: char vtype[256],*def;
283: #if !defined(PARCH_Win32) && !defined(PETSC_HAVE_X11)
284: PetscTruth warn;
285: #endif
290: if (!PetscDrawList) SETERRQ(1,"No draw implementations registered");
291: if (draw->type_name) {
292: def = draw->type_name;
293: } else {
294: PetscOptionsHasName(PETSC_NULL,"-nox",&nox);
295: def = PETSC_DRAW_NULL;
296: #if defined(PARCH_win32)
297: if (!nox) def = PETSC_DRAW_WIN32;
298: #elif defined(PETSC_HAVE_X11)
299: if (!nox) def = PETSC_DRAW_X;
300: #else
301: PetscOptionsHasName(PETSC_NULL,"-nox_warning",&warn);
302: if (!nox && !warn) {
303: (*PetscErrorPrintf)("PETSc installed without X windows on this machinenproceeding without graphicsn");
304: }
305: #endif
306: }
307: PetscOptionsBegin(draw->comm,draw->prefix,"Graphics (PetscDraw) Options","Draw");
308: PetscOptionsList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);
309: if (flg) {
310: PetscDrawSetType(draw,vtype);
311: } else if (!draw->type_name) {
312: PetscDrawSetType(draw,def);
313: }
314: PetscOptionsName("-nox","Run without graphics","None",&nox);
315: PetscOptionsEnd();
316: return(0);
317: }