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: /*@
12: PetscDrawResizeWindow - Allows one to resize a window from a program.
14: Collective on PetscDraw
16: Input Parameter:
17: + draw - the window
18: - w,h - the new width and height of the window
20: Level: intermediate
22: .seealso: PetscDrawCheckResizedWindow()
23: @*/
24: PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h)
25: {
28: if (draw->ops->resizewindow) {
29: (*draw->ops->resizewindow)(draw,w,h);
30: }
31: return(0);
32: }
36: /*@
37: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
39: Collective on PetscDraw
41: Input Parameter:
42: . draw - the window
44: Level: advanced
46: .seealso: PetscDrawResizeWindow()
48: @*/
49: PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw)
50: {
53: if (draw->ops->checkresizedwindow) {
54: (*draw->ops->checkresizedwindow)(draw);
55: }
56: return(0);
57: }
61: /*@C
62: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
64: Not collective
66: Input Parameter:
67: . draw - the graphics context
69: Output Parameter:
70: . title - the title
72: Level: intermediate
74: .seealso: PetscDrawSetTitle()
75: @*/
76: PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title)
77: {
81: *title = draw->title;
82: return(0);
83: }
87: /*@C
88: PetscDrawSetTitle - Sets the title of a PetscDraw context.
90: Not collective (any processor or all may call this)
92: Input Parameters:
93: + draw - the graphics context
94: - title - the title
96: Level: intermediate
98: Note:
99: A copy of the string is made, so you may destroy the
100: title string after calling this routine.
102: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
103: @*/
104: PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[])
105: {
110: PetscStrfree(draw->title);
111: PetscStrallocpy(title,&draw->title);
112: if (draw->ops->settitle) {
113: (*draw->ops->settitle)(draw,title);
114: }
115: return(0);
116: }
120: /*@C
121: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
123: Not collective (any processor or all can call this)
125: Input Parameters:
126: + draw - the graphics context
127: - title - the title
129: Note:
130: A copy of the string is made, so you may destroy the
131: title string after calling this routine.
133: Level: advanced
135: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
136: @*/
137: PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[])
138: {
140: size_t len1,len2,len;
141: char *newtitle;
145: if (!title) return(0);
147: if (draw->title) {
148: PetscStrlen(title,&len1);
149: PetscStrlen(draw->title,&len2);
150: len = len1 + len2;
151: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
152: PetscStrcpy(newtitle,draw->title);
153: PetscStrcat(newtitle,title);
154: PetscFree(draw->title);
155: draw->title = newtitle;
156: } else {
157: PetscStrallocpy(title,&draw->title);
158: }
159: if (draw->ops->settitle) {
160: (*draw->ops->settitle)(draw,draw->title);
161: }
162: return(0);
163: }
167: /*@
168: PetscDrawDestroy - Deletes a draw context.
170: Collective on PetscDraw
172: Input Parameters:
173: . draw - the drawing context
175: Level: beginner
177: .seealso: PetscDrawCreate()
179: @*/
180: PetscErrorCode PetscDrawDestroy(PetscDraw draw)
181: {
185: if (--draw->refct > 0) return(0);
187: /* if memory was published then destroy it */
188: PetscObjectDepublish(draw);
190: if (draw->ops->destroy) {
191: (*draw->ops->destroy)(draw);
192: }
193: PetscStrfree(draw->title);
194: PetscStrfree(draw->display);
195: PetscHeaderDestroy(draw);
196: return(0);
197: }
201: /*@
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: }