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 = 0;
11: /*@C
12: PetscInitializeDrawPackage - This function initializes everything in the PetscDraw package. It is called
13: from PetscDLLibraryRegister() when using dynamic libraries, and on the call to PetscInitialize()
14: when using static libraries.
16: Input Parameter:
17: path - The dynamic library path, or PETSC_NULL
19: Level: developer
21: .keywords: Petsc, initialize, package
22: .seealso: PetscInitialize()
23: @*/
24: PetscErrorCode PetscDrawInitializePackage(const char path[])
25: {
26: static PetscTruth initialized = PETSC_FALSE;
27: char logList[256];
28: char *className;
29: PetscTruth opt;
30: PetscErrorCode ierr;
33: if (initialized) return(0);
34: initialized = PETSC_TRUE;
35: /* Register Classes */
36: PetscLogClassRegister(&PETSC_DRAW_COOKIE, "Draw");
37: PetscLogClassRegister(&DRAWAXIS_COOKIE, "Axis");
38: PetscLogClassRegister(&DRAWLG_COOKIE, "Line Graph");
39: PetscLogClassRegister(&DRAWHG_COOKIE, "Histogram");
40: PetscLogClassRegister(&DRAWSP_COOKIE, "Scatter Plot");
41: /* Register Constructors */
42: PetscDrawRegisterAll(path);
43: /* Process info exclusions */
44: PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);
45: if (opt) {
46: PetscStrstr(logList, "draw", &className);
47: if (className) {
48: PetscInfoDeactivateClass(0);
49: }
50: }
51: /* Process summary exclusions */
52: PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);
53: if (opt) {
54: PetscStrstr(logList, "draw", &className);
55: if (className) {
57: }
58: }
59: return(0);
60: }
64: /*@
65: PetscDrawResizeWindow - Allows one to resize a window from a program.
67: Collective on PetscDraw
69: Input Parameter:
70: + draw - the window
71: - w,h - the new width and height of the window
73: Level: intermediate
75: .seealso: PetscDrawCheckResizedWindow()
76: @*/
77: PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h)
78: {
81: if (draw->ops->resizewindow) {
82: (*draw->ops->resizewindow)(draw,w,h);
83: }
84: return(0);
85: }
89: /*@
90: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
92: Collective on PetscDraw
94: Input Parameter:
95: . draw - the window
97: Level: advanced
99: .seealso: PetscDrawResizeWindow()
101: @*/
102: PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw)
103: {
106: if (draw->ops->checkresizedwindow) {
107: (*draw->ops->checkresizedwindow)(draw);
108: }
109: return(0);
110: }
114: /*@C
115: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
117: Not collective
119: Input Parameter:
120: . draw - the graphics context
122: Output Parameter:
123: . title - the title
125: Level: intermediate
127: .seealso: PetscDrawSetTitle()
128: @*/
129: PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title)
130: {
134: *title = draw->title;
135: return(0);
136: }
140: /*@C
141: PetscDrawSetTitle - Sets the title of a PetscDraw context.
143: Not collective (any processor or all may call this)
145: Input Parameters:
146: + draw - the graphics context
147: - title - the title
149: Level: intermediate
151: Note:
152: A copy of the string is made, so you may destroy the
153: title string after calling this routine.
155: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
156: @*/
157: PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[])
158: {
163: PetscStrfree(draw->title);
164: PetscStrallocpy(title,&draw->title);
165: if (draw->ops->settitle) {
166: (*draw->ops->settitle)(draw,title);
167: }
168: return(0);
169: }
173: /*@C
174: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
176: Not collective (any processor or all can call this)
178: Input Parameters:
179: + draw - the graphics context
180: - title - the title
182: Note:
183: A copy of the string is made, so you may destroy the
184: title string after calling this routine.
186: Level: advanced
188: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
189: @*/
190: PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[])
191: {
193: size_t len1,len2,len;
194: char *newtitle;
198: if (!title) return(0);
200: if (draw->title) {
201: PetscStrlen(title,&len1);
202: PetscStrlen(draw->title,&len2);
203: len = len1 + len2;
204: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
205: PetscStrcpy(newtitle,draw->title);
206: PetscStrcat(newtitle,title);
207: PetscFree(draw->title);
208: draw->title = newtitle;
209: } else {
210: PetscStrallocpy(title,&draw->title);
211: }
212: if (draw->ops->settitle) {
213: (*draw->ops->settitle)(draw,draw->title);
214: }
215: return(0);
216: }
220: /*@
221: PetscDrawDestroy - Deletes a draw context.
223: Collective on PetscDraw
225: Input Parameters:
226: . draw - the drawing context
228: Level: beginner
230: .seealso: PetscDrawCreate()
232: @*/
233: PetscErrorCode PetscDrawDestroy(PetscDraw draw)
234: {
238: if (--draw->refct > 0) return(0);
240: /* if memory was published then destroy it */
241: PetscObjectDepublish(draw);
243: if (draw->ops->destroy) {
244: (*draw->ops->destroy)(draw);
245: }
246: PetscStrfree(draw->title);
247: PetscStrfree(draw->display);
248: PetscHeaderDestroy(draw);
249: return(0);
250: }
254: /*@
255: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
257: Collective on PetscDraw
259: Input Parameter:
260: . draw - the original window
262: Output Parameter:
263: . popup - the new popup window
265: Level: advanced
267: @*/
268: PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
269: {
275: if (draw->popup) {
276: *popup = draw->popup;
277: } else if (draw->ops->getpopup) {
278: (*draw->ops->getpopup)(draw,popup);
279: } else {
280: *popup = PETSC_NULL;
281: }
282: return(0);
283: }
287: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
288: {
290: return(0);
291: }
295: /*
296: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
297: it are ignored.
299: Output Parameter:
300: . win - the drawing context
302: Level: advanced
304: */
305: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
306: {
310: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
311: PetscDrawSetType(*win,PETSC_DRAW_NULL);
312: return(0);
313: }
317: /*@
318: PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed
320: Input Parameter:
321: + draw - the drawing context
322: - display - the X windows display
324: Level: advanced
326: @*/
327: PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,char *display)
328: {
332: PetscStrfree(draw->display);
333: PetscStrallocpy(display,&draw->display);
334: return(0);
335: }
340: /*
341: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
342: it are ignored.
344: Input Parameter:
345: . win - the drawing context
346: */
347: PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
348: {
352: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
353: draw->ops->destroy = PetscDrawDestroy_Null;
354: draw->ops->view = 0;
355: draw->pause = 0;
356: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
357: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
358: draw->port_xl = 0.0; draw->port_xr = 1.0;
359: draw->port_yl = 0.0; draw->port_yr = 1.0;
360: draw->popup = 0;
362: return(0);
363: }
368: /*@C
369: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
370: by the one process.
372: Collective on PetscDraw
374: Input Parameter:
375: . draw - the original window
377: Output Parameter:
378: . sdraw - the singleton window
380: Level: advanced
382: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
384: @*/
385: PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
386: {
388: PetscMPIInt size;
394: MPI_Comm_size(draw->comm,&size);
395: if (size == 1) {
396: *sdraw = draw;
397: } else {
398: if (draw->ops->getsingleton) {
399: (*draw->ops->getsingleton)(draw,sdraw);
400: } else {
401: SETERRQ1(PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",draw->type_name);
402: }
403: }
404: return(0);
405: }
409: /*@C
410: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
411: by the one process.
413: Collective on PetscDraw
415: Input Parameters:
416: + draw - the original window
417: - sdraw - the singleton window
419: Level: advanced
421: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
423: @*/
424: PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
425: {
427: PetscMPIInt size;
434: MPI_Comm_size(draw->comm,&size);
435: if (size != 1) {
436: if (draw->ops->restoresingleton) {
437: (*draw->ops->restoresingleton)(draw,sdraw);
438: } else {
439: SETERRQ1(PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",draw->type_name);
440: }
441: }
442: return(0);
443: }