Actual source code: draw.c
1: /*
2: Provides the calling sequences for all the basic PetscDraw routines.
3: */
4: #include src/sys/src/draw/drawimpl.h
6: PetscCookie PETSC_DRAW_COOKIE = 0;
10: /*@
11: PetscDrawResizeWindow - Allows one to resize a window from a program.
13: Collective on PetscDraw
15: Input Parameter:
16: + draw - the window
17: - w,h - the new width and height of the window
19: Level: intermediate
21: .seealso: PetscDrawCheckResizedWindow()
22: @*/
23: PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h)
24: {
27: if (draw->ops->resizewindow) {
28: (*draw->ops->resizewindow)(draw,w,h);
29: }
30: return(0);
31: }
35: /*@
36: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
38: Collective on PetscDraw
40: Input Parameter:
41: . draw - the window
43: Level: advanced
45: .seealso: PetscDrawResizeWindow()
47: @*/
48: PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw)
49: {
52: if (draw->ops->checkresizedwindow) {
53: (*draw->ops->checkresizedwindow)(draw);
54: }
55: return(0);
56: }
60: /*@C
61: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
63: Not collective
65: Input Parameter:
66: . draw - the graphics context
68: Output Parameter:
69: . title - the title
71: Level: intermediate
73: .seealso: PetscDrawSetTitle()
74: @*/
75: PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title)
76: {
80: *title = draw->title;
81: return(0);
82: }
86: /*@C
87: PetscDrawSetTitle - Sets the title of a PetscDraw context.
89: Not collective (any processor or all may call this)
91: Input Parameters:
92: + draw - the graphics context
93: - title - the title
95: Level: intermediate
97: Note:
98: A copy of the string is made, so you may destroy the
99: title string after calling this routine.
101: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
102: @*/
103: PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[])
104: {
109: PetscStrfree(draw->title);
110: PetscStrallocpy(title,&draw->title);
111: if (draw->ops->settitle) {
112: (*draw->ops->settitle)(draw,title);
113: }
114: return(0);
115: }
119: /*@C
120: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
122: Not collective (any processor or all can call this)
124: Input Parameters:
125: + draw - the graphics context
126: - title - the title
128: Note:
129: A copy of the string is made, so you may destroy the
130: title string after calling this routine.
132: Level: advanced
134: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
135: @*/
136: PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[])
137: {
139: size_t len1,len2,len;
140: char *newtitle;
144: if (!title) return(0);
146: if (draw->title) {
147: PetscStrlen(title,&len1);
148: PetscStrlen(draw->title,&len2);
149: len = len1 + len2;
150: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
151: PetscStrcpy(newtitle,draw->title);
152: PetscStrcat(newtitle,title);
153: PetscFree(draw->title);
154: draw->title = newtitle;
155: } else {
156: PetscStrallocpy(title,&draw->title);
157: }
158: if (draw->ops->settitle) {
159: (*draw->ops->settitle)(draw,draw->title);
160: }
161: return(0);
162: }
166: /*@C
167: PetscDrawDestroy - Deletes a draw context.
169: Collective on PetscDraw
171: Input Parameters:
172: . draw - the drawing context
174: Level: beginner
176: .seealso: PetscDrawCreate()
178: @*/
179: PetscErrorCode PetscDrawDestroy(PetscDraw draw)
180: {
184: if (--draw->refct > 0) return(0);
186: /* if memory was published then destroy it */
187: PetscObjectDepublish(draw);
189: if (draw->ops->destroy) {
190: (*draw->ops->destroy)(draw);
191: }
192: PetscStrfree(draw->title);
193: PetscStrfree(draw->display);
194: PetscLogObjectDestroy(draw);
195: PetscHeaderDestroy(draw);
196: return(0);
197: }
201: /*@C
202: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
204: Collective on PetscDraw
206: Input Parameter:
207: . draw - the original window
209: Output Parameter:
210: . popup - the new popup window
212: Level: advanced
214: @*/
215: PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
216: {
222: if (draw->popup) {
223: *popup = draw->popup;
224: } else if (draw->ops->getpopup) {
225: (*draw->ops->getpopup)(draw,popup);
226: } else {
227: *popup = PETSC_NULL;
228: }
229: return(0);
230: }
234: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
235: {
237: return(0);
238: }
242: /*
243: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
244: it are ignored.
246: Output Parameter:
247: . win - the drawing context
249: Level: advanced
251: */
252: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
253: {
257: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
258: PetscDrawSetType(*win,PETSC_DRAW_NULL);
259: return(0);
260: }
264: /*@
265: PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed
267: Input Parameter:
268: + draw - the drawing context
269: - display - the X windows display
271: Level: advanced
273: @*/
274: PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,char *display)
275: {
279: PetscStrfree(draw->display);
280: PetscStrallocpy(display,&draw->display);
281: return(0);
282: }
287: /*
288: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
289: it are ignored.
291: Input Parameter:
292: . win - the drawing context
293: */
294: PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
295: {
299: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
300: draw->ops->destroy = PetscDrawDestroy_Null;
301: draw->ops->view = 0;
302: draw->pause = 0;
303: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
304: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
305: draw->port_xl = 0.0; draw->port_xr = 1.0;
306: draw->port_yl = 0.0; draw->port_yr = 1.0;
307: draw->popup = 0;
309: return(0);
310: }
315: /*@C
316: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
317: by the one process.
319: Collective on PetscDraw
321: Input Parameter:
322: . draw - the original window
324: Output Parameter:
325: . sdraw - the singleton window
327: Level: advanced
329: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
331: @*/
332: PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
333: {
335: PetscMPIInt size;
341: MPI_Comm_size(draw->comm,&size);
342: if (size == 1) {
343: *sdraw = draw;
344: } else {
345: if (draw->ops->getsingleton) {
346: (*draw->ops->getsingleton)(draw,sdraw);
347: } else {
348: SETERRQ1(PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",draw->type_name);
349: }
350: }
351: return(0);
352: }
356: /*@C
357: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
358: by the one process.
360: Collective on PetscDraw
362: Input Parameters:
363: + draw - the original window
364: - sdraw - the singleton window
366: Level: advanced
368: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
370: @*/
371: PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
372: {
374: PetscMPIInt size;
381: MPI_Comm_size(draw->comm,&size);
382: if (size != 1) {
383: if (draw->ops->restoresingleton) {
384: (*draw->ops->restoresingleton)(draw,sdraw);
385: } else {
386: SETERRQ1(PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",draw->type_name);
387: }
388: }
389: return(0);
390: }