Actual source code: draw.c
2: /*
3: Provides the calling sequences for all the basic PetscDraw routines.
4: */
5: #include <../src/sys/draw/drawimpl.h> /*I "petscdraw.h" I*/
7: PetscClassId PETSC_DRAW_CLASSID;
9: static PetscBool PetscDrawPackageInitialized = PETSC_FALSE;
12: /*@C
13: PetscDrawFinalizePackage - This function destroys everything in the Petsc interface to the Draw package. It is
14: called from PetscFinalize().
16: Level: developer
18: .keywords: Petsc, destroy, package, mathematica
19: .seealso: PetscFinalize()
20: @*/
21: PetscErrorCode PetscDrawFinalizePackage(void)
22: {
24: PetscDrawPackageInitialized = PETSC_FALSE;
25: PetscDrawList = 0;
26: return(0);
27: }
31: /*@C
32: PetscInitializeDrawPackage - This function initializes everything in the PetscDraw package. It is called
33: from PetscDLLibraryRegister() when using dynamic libraries, and on the call to PetscInitialize()
34: when using static libraries.
36: Input Parameter:
37: path - The dynamic library path, or PETSC_NULL
39: Level: developer
41: .keywords: Petsc, initialize, package
42: .seealso: PetscInitialize()
43: @*/
44: PetscErrorCode PetscDrawInitializePackage(const char path[])
45: {
46: char logList[256];
47: char *className;
48: PetscBool opt;
49: PetscErrorCode ierr;
52: if (PetscDrawPackageInitialized) return(0);
53: PetscDrawPackageInitialized = PETSC_TRUE;
54: /* Register Classes */
55: PetscClassIdRegister("Draw",&PETSC_DRAW_CLASSID);
56: PetscClassIdRegister("Axis",&DRAWAXIS_CLASSID);
57: PetscClassIdRegister("Line Graph",&DRAWLG_CLASSID);
58: PetscClassIdRegister("Histogram",&DRAWHG_CLASSID);
59: PetscClassIdRegister("Scatter Plot",&DRAWSP_CLASSID);
60: /* Register Constructors */
61: PetscDrawRegisterAll(path);
62: /* Process info exclusions */
63: PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);
64: if (opt) {
65: PetscStrstr(logList, "draw", &className);
66: if (className) {
67: PetscInfoDeactivateClass(0);
68: }
69: }
70: /* Process summary exclusions */
71: PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);
72: if (opt) {
73: PetscStrstr(logList, "draw", &className);
74: if (className) {
75: PetscLogEventDeactivateClass(0);
76: }
77: }
78: PetscRegisterFinalize(PetscDrawFinalizePackage);
79: return(0);
80: }
84: /*@
85: PetscDrawResizeWindow - Allows one to resize a window from a program.
87: Collective on PetscDraw
89: Input Parameter:
90: + draw - the window
91: - w,h - the new width and height of the window
93: Level: intermediate
95: .seealso: PetscDrawCheckResizedWindow()
96: @*/
97: PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h)
98: {
101: if (draw->ops->resizewindow) {
102: (*draw->ops->resizewindow)(draw,w,h);
103: }
104: return(0);
105: }
109: /*@
110: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
112: Collective on PetscDraw
114: Input Parameter:
115: . draw - the window
117: Level: advanced
119: .seealso: PetscDrawResizeWindow()
121: @*/
122: PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw)
123: {
126: if (draw->ops->checkresizedwindow) {
127: (*draw->ops->checkresizedwindow)(draw);
128: }
129: return(0);
130: }
134: /*@C
135: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
137: Not collective
139: Input Parameter:
140: . draw - the graphics context
142: Output Parameter:
143: . title - the title
145: Level: intermediate
147: .seealso: PetscDrawSetTitle()
148: @*/
149: PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title)
150: {
154: *title = draw->title;
155: return(0);
156: }
160: /*@C
161: PetscDrawSetTitle - Sets the title of a PetscDraw context.
163: Not collective (any processor or all may call this)
165: Input Parameters:
166: + draw - the graphics context
167: - title - the title
169: Level: intermediate
171: Note:
172: A copy of the string is made, so you may destroy the
173: title string after calling this routine.
175: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
176: @*/
177: PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[])
178: {
183: PetscFree(draw->title);
184: PetscStrallocpy(title,&draw->title);
185: if (draw->ops->settitle) {
186: (*draw->ops->settitle)(draw,title);
187: }
188: return(0);
189: }
193: /*@C
194: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
196: Not collective (any processor or all can call this)
198: Input Parameters:
199: + draw - the graphics context
200: - title - the title
202: Note:
203: A copy of the string is made, so you may destroy the
204: title string after calling this routine.
206: Level: advanced
208: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
209: @*/
210: PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[])
211: {
213: size_t len1,len2,len;
214: char *newtitle;
218: if (!title) return(0);
220: if (draw->title) {
221: PetscStrlen(title,&len1);
222: PetscStrlen(draw->title,&len2);
223: len = len1 + len2;
224: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
225: PetscStrcpy(newtitle,draw->title);
226: PetscStrcat(newtitle,title);
227: PetscFree(draw->title);
228: draw->title = newtitle;
229: } else {
230: PetscStrallocpy(title,&draw->title);
231: }
232: if (draw->ops->settitle) {
233: (*draw->ops->settitle)(draw,draw->title);
234: }
235: return(0);
236: }
240: /*@
241: PetscDrawDestroy - Deletes a draw context.
243: Collective on PetscDraw
245: Input Parameters:
246: . draw - the drawing context
248: Level: beginner
250: .seealso: PetscDrawCreate()
252: @*/
253: PetscErrorCode PetscDrawDestroy(PetscDraw *draw)
254: {
257: if (!*draw) return(0);
259: if (--((PetscObject)(*draw))->refct > 0) return(0);
261: /* if memory was published then destroy it */
262: PetscObjectDepublish(*draw);
264: if ((*draw)->ops->destroy) {
265: (*(*draw)->ops->destroy)(*draw);
266: }
267: PetscFree((*draw)->title);
268: PetscFree((*draw)->display);
269: PetscHeaderDestroy(draw);
270: return(0);
271: }
275: /*@
276: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
278: Collective on PetscDraw
280: Input Parameter:
281: . draw - the original window
283: Output Parameter:
284: . popup - the new popup window
286: Level: advanced
288: @*/
289: PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
290: {
296: if (draw->popup) {
297: *popup = draw->popup;
298: } else if (draw->ops->getpopup) {
299: (*draw->ops->getpopup)(draw,popup);
300: } else {
301: *popup = PETSC_NULL;
302: }
303: return(0);
304: }
308: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
309: {
311: return(0);
312: }
316: /*
317: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
318: it are ignored.
320: Output Parameter:
321: . win - the drawing context
323: Level: advanced
325: */
326: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
327: {
331: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
332: PetscDrawSetType(*win,PETSC_DRAW_NULL);
333: return(0);
334: }
338: /*@
339: PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed
341: Input Parameter:
342: + draw - the drawing context
343: - display - the X windows display
345: Level: advanced
347: @*/
348: PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,char *display)
349: {
353: PetscFree(draw->display);
354: PetscStrallocpy(display,&draw->display);
355: return(0);
356: }
361: /*
362: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
363: it are ignored.
365: Input Parameter:
366: . win - the drawing context
367: */
368: PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
369: {
373: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
374: draw->ops->destroy = PetscDrawDestroy_Null;
375: draw->ops->view = 0;
376: draw->pause = 0.0;
377: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
378: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
379: draw->port_xl = 0.0; draw->port_xr = 1.0;
380: draw->port_yl = 0.0; draw->port_yr = 1.0;
381: draw->popup = 0;
383: return(0);
384: }
389: /*@C
390: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
391: by the one process.
393: Collective on PetscDraw
395: Input Parameter:
396: . draw - the original window
398: Output Parameter:
399: . sdraw - the singleton window
401: Level: advanced
403: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
405: @*/
406: PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
407: {
409: PetscMPIInt size;
415: MPI_Comm_size(((PetscObject)draw)->comm,&size);
416: if (size == 1) {
417: *sdraw = draw;
418: } else {
419: if (draw->ops->getsingleton) {
420: (*draw->ops->getsingleton)(draw,sdraw);
421: } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name);
422: }
423: return(0);
424: }
428: /*@C
429: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
430: by the one process.
432: Collective on PetscDraw
434: Input Parameters:
435: + draw - the original window
436: - sdraw - the singleton window
438: Level: advanced
440: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
442: @*/
443: PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
444: {
446: PetscMPIInt size;
453: MPI_Comm_size(((PetscObject)draw)->comm,&size);
454: if (size != 1) {
455: if (draw->ops->restoresingleton) {
456: (*draw->ops->restoresingleton)(draw,sdraw);
457: } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name);
458: }
459: return(0);
460: }