Actual source code: drawreg.c
1: #define PETSC_DLL
2: /*
3: Provides the registration process for PETSc PetscDraw routines
4: */
5: #include src/sys/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: PetscErrorCode PetscDrawCreate(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscDraw *indraw)
38: {
39: PetscDraw draw;
41: PetscInt dpause;
42: PetscTruth flag;
45: *indraw = 0;
46: PetscHeaderCreate(draw,_p_PetscDraw,struct _PetscDrawOps,PETSC_DRAW_COOKIE,-1,"Draw",comm,PetscDrawDestroy,0);
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",&dpause,&flag);
65: if (flag) draw->pause = (int) dpause;
66: *indraw = draw;
67: return(0);
68: }
69:
72: /*@C
73: PetscDrawSetType - Builds graphics object for a particular implementation
75: Collective on PetscDraw
77: Input Parameter:
78: + draw - the graphics context
79: - type - for example, PETSC_DRAW_X
81: Options Database Command:
82: . -draw_type <type> - Sets the type; use -help for a list
83: of available methods (for instance, x)
85: Level: intermediate
87: Notes:
88: See "petsc/include/petscdraw.h" for available methods (for instance,
89: PETSC_DRAW_X)
91: Concepts: drawing^X windows
92: Concepts: X windows^graphics
93: Concepts: drawing^postscript
94: Concepts: postscript^graphics
95: Concepts: drawing^Microsoft Windows
97: .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy()
98: @*/
99: PetscErrorCode PetscDrawSetType(PetscDraw draw,const PetscDrawType type)
100: {
101: PetscErrorCode ierr,(*r)(PetscDraw);
102: PetscTruth match;
103: PetscTruth flg=PETSC_FALSE;
109: PetscTypeCompare((PetscObject)draw,type,&match);
110: if (match) return(0);
112: /* User requests no graphics */
113: PetscOptionsHasName(PETSC_NULL,"-nox",&flg);
115: /*
116: This is not ideal, but it allows codes to continue to run if X graphics
117: was requested but is not installed on this machine. Mostly this is for
118: testing.
119: */
120: #if !defined(PETSC_HAVE_X11)
121: if (!flg) {
122: PetscStrcmp(type,PETSC_DRAW_X,&match);
123: if (match) {
124: PetscTruth dontwarn = PETSC_TRUE;
125: flg = PETSC_TRUE;
126: PetscOptionsHasName(PETSC_NULL,"-nox_warning",&dontwarn);
127: if (!dontwarn) {
128: (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n");
129: }
130: }
131: }
132: #endif
133: if (flg) {
134: type = PETSC_DRAW_NULL;
135: }
137: if (draw->data) {
138: /* destroy the old private PetscDraw context */
139: (*draw->ops->destroy)(draw);
140: draw->data = 0;
141: }
143: /* Get the function pointers for the graphics method requested */
144: if (!PetscDrawList) {
145: PetscDrawRegisterAll(PETSC_NULL);
146: }
147: PetscFListFind(draw->comm,PetscDrawList,type,(void (**)(void)) &r);
148: if (!r) SETERRQ1(PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscDraw type given: %s",type);
149: PetscObjectChangeTypeName((PetscObject)draw,type);
150: draw->data = 0;
151: (*r)(draw);
152: return(0);
153: }
157: /*@C
158: PetscDrawRegisterDestroy - Frees the list of PetscDraw methods that were
159: registered by PetscDrawRegisterDynamic().
161: Not Collective
163: Level: developer
165: .seealso: PetscDrawRegisterDynamic(), PetscDrawRegisterAll()
166: @*/
167: PetscErrorCode PetscDrawRegisterDestroy(void)
168: {
172: if (PetscDrawList) {
173: PetscFListDestroy(&PetscDrawList);
174: PetscDrawList = 0;
175: }
176: return(0);
177: }
181: /*@C
182: PetscDrawGetType - Gets the PetscDraw type as a string from the PetscDraw object.
184: Not Collective
186: Input Parameter:
187: . draw - Krylov context
189: Output Parameters:
190: . name - name of PetscDraw method
192: Level: advanced
194: @*/
195: PetscErrorCode PetscDrawGetType(PetscDraw draw,PetscDrawType *type)
196: {
198: *type = draw->type_name;
199: return(0);
200: }
204: PetscErrorCode PetscDrawRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(PetscDraw))
205: {
207: char fullname[PETSC_MAX_PATH_LEN];
210: PetscFListConcat(path,name,fullname);
211: PetscFListAdd(&PetscDrawList,sname,fullname,(void (*)(void))function);
212: return(0);
213: }
217: /*@C
218: PetscDrawSetFromOptions - Sets the graphics type from the options database.
219: Defaults to a PETSc X windows graphics.
221: Collective on PetscDraw
223: Input Parameter:
224: . draw - the graphics context
226: Options Database Keys:
227: + -nox - do not use X graphics (ignore graphics calls, but run program correctly)
228: - -nox_warning - when X windows support is not installed this prevents the warning message
229: from being printed
231: Level: intermediate
233: Notes:
234: Must be called after PetscDrawCreate() before the PetscDrawtor is used.
236: Concepts: drawing^setting options
237: Concepts: graphics^setting options
239: .seealso: PetscDrawCreate(), PetscDrawSetType()
241: @*/
242: PetscErrorCode PetscDrawSetFromOptions(PetscDraw draw)
243: {
245: PetscTruth flg,nox;
246: char vtype[256];
247: const char *def;
248: #if !defined(PETSC_HAVE_WINDOWS_H) && !defined(PETSC_HAVE_X11)
249: PetscTruth warn;
250: #endif
255: if (!PetscDrawList) {
256: PetscDrawRegisterAll(PETSC_NULL);
257: }
259: if (draw->type_name) {
260: def = draw->type_name;
261: } else {
262: PetscOptionsHasName(PETSC_NULL,"-nox",&nox);
263: def = PETSC_DRAW_NULL;
264: #if defined(PETSC_HAVE_WINDOWS_H) && !defined(PETSC_HAVE_X11)
265: if (!nox) def = PETSC_DRAW_WIN32;
266: #elif defined(PETSC_HAVE_X11)
267: if (!nox) def = PETSC_DRAW_X;
268: #else
269: PetscOptionsHasName(PETSC_NULL,"-nox_warning",&warn);
270: if (!nox && !warn) {
271: (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n");
272: }
273: #endif
274: }
275: PetscOptionsBegin(draw->comm,draw->prefix,"Graphics (PetscDraw) Options","Draw");
276: PetscOptionsList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);
277: if (flg) {
278: PetscDrawSetType(draw,vtype);
279: } else if (!draw->type_name) {
280: PetscDrawSetType(draw,def);
281: }
282: PetscOptionsName("-nox","Run without graphics","None",&nox);
283: PetscOptionsEnd();
284: return(0);
285: }