Actual source code: draw.c
1: /*$Id: draw.c,v 1.73 2001/03/23 23:20:08 balay Exp $*/
2: /*
3: Provides the calling sequences for all the basic PetscDraw routines.
4: */
5: #include src/sys/src/draw/drawimpl.h
7: int PETSC_DRAW_COOKIE;
9: /*@
10: PetscDrawResizeWindow - Allows one to resize a window from a program.
12: Collective on PetscDraw
14: Input Parameter:
15: + draw - the window
16: - w,h - the new width and height of the window
18: Level: intermediate
20: .seealso: PetscDrawCheckResizedWindow()
21: @*/
22: int PetscDrawResizeWindow(PetscDraw draw,int w,int h)
23: {
26: if (draw->ops->resizewindow) {
27: (*draw->ops->resizewindow)(draw,w,h);
28: }
29: return(0);
30: }
32: /*@
33: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
35: Collective on PetscDraw
37: Input Parameter:
38: . draw - the window
40: Level: advanced
42: .seealso: PetscDrawResizeWindow()
44: @*/
45: int PetscDrawCheckResizedWindow(PetscDraw draw)
46: {
49: if (draw->ops->checkresizedwindow) {
50: (*draw->ops->checkresizedwindow)(draw);
51: }
52: return(0);
53: }
55: /*@C
56: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
58: Not collective
60: Input Parameter:
61: . draw - the graphics context
63: Output Parameter:
64: . title - the title
66: Level: intermediate
68: .seealso: PetscDrawSetTitle()
69: @*/
70: int PetscDrawGetTitle(PetscDraw draw,char **title)
71: {
74: *title = draw->title;
75: return(0);
76: }
78: /*@C
79: PetscDrawSetTitle - Sets the title of a PetscDraw context.
81: Not collective (any processor or all may call this)
83: Input Parameters:
84: + draw - the graphics context
85: - title - the title
87: Level: intermediate
89: Note:
90: A copy of the string is made, so you may destroy the
91: title string after calling this routine.
93: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
94: @*/
95: int PetscDrawSetTitle(PetscDraw draw,char *title)
96: {
100: PetscStrfree(draw->title);
101: PetscStrallocpy(title,&draw->title);
102: if (draw->ops->settitle) {
103: (*draw->ops->settitle)(draw,title);
104: }
105: return(0);
106: }
108: /*@C
109: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
111: Not collective (any processor or all can call this)
113: Input Parameters:
114: + draw - the graphics context
115: - title - the title
117: Note:
118: A copy of the string is made, so you may destroy the
119: title string after calling this routine.
121: Level: advanced
123: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
124: @*/
125: int PetscDrawAppendTitle(PetscDraw draw,char *title)
126: {
127: int ierr,len1,len2,len;
128: char *newtitle;
132: if (!title) return(0);
134: if (draw->title) {
135: PetscStrlen(title,&len1);
136: PetscStrlen(draw->title,&len2);
137: len = len1 + len2;
138: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
139: PetscStrcpy(newtitle,draw->title);
140: PetscStrcat(newtitle,title);
141: PetscFree(draw->title);
142: draw->title = newtitle;
143: } else {
144: PetscStrallocpy(title,&draw->title);
145: }
146: if (draw->ops->settitle) {
147: (*draw->ops->settitle)(draw,draw->title);
148: }
149: return(0);
150: }
152: /*@C
153: PetscDrawDestroy - Deletes a draw context.
155: Collective on PetscDraw
157: Input Parameters:
158: . draw - the drawing context
160: Level: beginner
162: .seealso: PetscDrawCreate()
164: @*/
165: int PetscDrawDestroy(PetscDraw draw)
166: {
170: if (--draw->refct > 0) return(0);
172: /* if memory was published with AMS then destroy it */
173: PetscObjectDepublish(draw);
175: if (draw->ops->destroy) {
176: (*draw->ops->destroy)(draw);
177: }
178: PetscStrfree(draw->title);
179: PetscStrfree(draw->display);
180: PetscLogObjectDestroy(draw);
181: PetscHeaderDestroy(draw);
182: return(0);
183: }
185: /*@C
186: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
188: Collective on PetscDraw
190: Input Parameter:
191: . draw - the original window
193: Output Parameter:
194: . popup - the new popup window
196: Level: advanced
198: @*/
199: int PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
200: {
206: if (draw->popup) {
207: *popup = draw->popup;
208: } else if (draw->ops->getpopup) {
209: (*draw->ops->getpopup)(draw,popup);
210: } else {
211: *popup = PETSC_NULL;
212: }
213: return(0);
214: }
216: int PetscDrawDestroy_Null(PetscDraw draw)
217: {
219: return(0);
220: }
222: /*
223: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
224: it are ignored.
226: Output Parameter:
227: . win - the drawing context
229: Level: advanced
231: */
232: int PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
233: {
237: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
238: PetscDrawSetType(*win,PETSC_DRAW_NULL);
239: return(0);
240: }
242: /*@
243: PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed
245: Input Parameter:
246: + draw - the drawing context
247: - display - the X windows display
249: Level: advanced
251: @*/
252: int PetscDrawSetDisplay(PetscDraw draw,char *display)
253: {
257: ierr = PetscStrfree(draw->display);
258: ierr = PetscStrallocpy(display,&draw->display);
259: return(0);
260: }
262: EXTERN_C_BEGIN
263: /*
264: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
265: it are ignored.
267: Input Parameter:
268: . win - the drawing context
269: */
270: int PetscDrawCreate_Null(PetscDraw draw)
271: {
275: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
276: draw->ops->destroy = PetscDrawDestroy_Null;
277: draw->ops->view = 0;
278: draw->pause = 0;
279: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
280: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
281: draw->port_xl = 0.0; draw->port_xr = 1.0;
282: draw->port_yl = 0.0; draw->port_yr = 1.0;
283: draw->popup = 0;
285: return(0);
286: }
287: EXTERN_C_END
289: /*@C
290: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
291: by the one process.
293: Collective on PetscDraw
295: Input Parameter:
296: . draw - the original window
298: Output Parameter:
299: . sdraw - the singleton window
301: Level: advanced
303: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
305: @*/
306: int PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
307: {
308: int ierr,size;
314: MPI_Comm_size(draw->comm,&size);
315: if (size == 1) {
316: *sdraw = draw;
317: return(0);
318: }
320: if (draw->ops->getsingleton) {
321: (*draw->ops->getsingleton)(draw,sdraw);
322: } else {
323: SETERRQ1(1,"Cannot get singleton for this type %s of draw object",draw->type_name);
324: }
325: return(0);
326: }
328: /*@C
329: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
330: by the one process.
332: Collective on PetscDraw
334: Input Parameters:
335: + draw - the original window
336: - sdraw - the singleton window
338: Level: advanced
340: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
342: @*/
343: int PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
344: {
345: int ierr,size;
352: MPI_Comm_size(draw->comm,&size);
353: if (size == 1) {
354: return(0);
355: }
357: if (draw->ops->restoresingleton) {
358: (*draw->ops->restoresingleton)(draw,sdraw);
359: } else {
360: SETERRQ1(1,"Cannot restore singleton for this type %s of draw object",draw->type_name);
361: }
362: return(0);
363: }