Actual source code: draw.c
1: #define PETSC_DLL
2: /*
3: Provides the calling sequences for all the basic PetscDraw routines.
4: */
5: #include ../src/sys/draw/drawimpl.h
7: PetscCookie PETSC_DRAW_COOKIE;
9: static PetscTruth PetscDrawPackageInitialized = PETSC_FALSE;
12: /*@C
13: PetscDrawFinalizePackage - This function destroys everything in the Petsc interface to the charactoristics 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: PetscTruth opt;
49: PetscErrorCode ierr;
52: if (PetscDrawPackageInitialized) return(0);
53: PetscDrawPackageInitialized = PETSC_TRUE;
54: /* Register Classes */
55: PetscCookieRegister("Draw",&PETSC_DRAW_COOKIE);
56: PetscCookieRegister("Axis",&DRAWAXIS_COOKIE);
57: PetscCookieRegister("Line Graph",&DRAWLG_COOKIE);
58: PetscCookieRegister("Histogram",&DRAWHG_COOKIE);
59: PetscCookieRegister("Scatter Plot",&DRAWSP_COOKIE);
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: PetscStrfree(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: {
258: if (--((PetscObject)draw)->refct > 0) return(0);
260: /* if memory was published then destroy it */
261: PetscObjectDepublish(draw);
263: if (draw->ops->destroy) {
264: (*draw->ops->destroy)(draw);
265: }
266: PetscStrfree(draw->title);
267: PetscStrfree(draw->display);
268: PetscHeaderDestroy(draw);
269: return(0);
270: }
274: /*@
275: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
277: Collective on PetscDraw
279: Input Parameter:
280: . draw - the original window
282: Output Parameter:
283: . popup - the new popup window
285: Level: advanced
287: @*/
288: PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
289: {
295: if (draw->popup) {
296: *popup = draw->popup;
297: } else if (draw->ops->getpopup) {
298: (*draw->ops->getpopup)(draw,popup);
299: } else {
300: *popup = PETSC_NULL;
301: }
302: return(0);
303: }
307: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
308: {
310: return(0);
311: }
315: /*
316: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
317: it are ignored.
319: Output Parameter:
320: . win - the drawing context
322: Level: advanced
324: */
325: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
326: {
330: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
331: PetscDrawSetType(*win,PETSC_DRAW_NULL);
332: return(0);
333: }
337: /*@
338: PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed
340: Input Parameter:
341: + draw - the drawing context
342: - display - the X windows display
344: Level: advanced
346: @*/
347: PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,char *display)
348: {
352: PetscStrfree(draw->display);
353: PetscStrallocpy(display,&draw->display);
354: return(0);
355: }
360: /*
361: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
362: it are ignored.
364: Input Parameter:
365: . win - the drawing context
366: */
367: PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
368: {
372: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
373: draw->ops->destroy = PetscDrawDestroy_Null;
374: draw->ops->view = 0;
375: draw->pause = 0.0;
376: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
377: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
378: draw->port_xl = 0.0; draw->port_xr = 1.0;
379: draw->port_yl = 0.0; draw->port_yr = 1.0;
380: draw->popup = 0;
382: return(0);
383: }
388: /*@C
389: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
390: by the one process.
392: Collective on PetscDraw
394: Input Parameter:
395: . draw - the original window
397: Output Parameter:
398: . sdraw - the singleton window
400: Level: advanced
402: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
404: @*/
405: PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
406: {
408: PetscMPIInt size;
414: MPI_Comm_size(((PetscObject)draw)->comm,&size);
415: if (size == 1) {
416: *sdraw = draw;
417: } else {
418: if (draw->ops->getsingleton) {
419: (*draw->ops->getsingleton)(draw,sdraw);
420: } else {
421: SETERRQ1(PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name);
422: }
423: }
424: return(0);
425: }
429: /*@C
430: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
431: by the one process.
433: Collective on PetscDraw
435: Input Parameters:
436: + draw - the original window
437: - sdraw - the singleton window
439: Level: advanced
441: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
443: @*/
444: PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
445: {
447: PetscMPIInt size;
454: MPI_Comm_size(((PetscObject)draw)->comm,&size);
455: if (size != 1) {
456: if (draw->ops->restoresingleton) {
457: (*draw->ops->restoresingleton)(draw,sdraw);
458: } else {
459: SETERRQ1(PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name);
460: }
461: }
462: return(0);
463: }