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: EXTERN_C_BEGIN
243: /*
244: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
245: it are ignored.
247: Input Parameter:
248: . win - the drawing context
249: */
250: int PetscDrawCreate_Null(PetscDraw draw)
251: {
255: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
256: draw->ops->destroy = PetscDrawDestroy_Null;
257: draw->ops->view = 0;
258: draw->pause = 0;
259: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
260: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
261: draw->port_xl = 0.0; draw->port_xr = 1.0;
262: draw->port_yl = 0.0; draw->port_yr = 1.0;
263: draw->popup = 0;
265: return(0);
266: }
267: EXTERN_C_END
269: /*@C
270: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
271: by the one process.
273: Collective on PetscDraw
275: Input Parameter:
276: . draw - the original window
278: Output Parameter:
279: . sdraw - the singleton window
281: Level: advanced
283: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
285: @*/
286: int PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
287: {
288: int ierr,size;
294: MPI_Comm_size(draw->comm,&size);
295: if (size == 1) {
296: *sdraw = draw;
297: return(0);
298: }
300: if (draw->ops->getsingleton) {
301: (*draw->ops->getsingleton)(draw,sdraw);
302: } else {
303: SETERRQ1(1,"Cannot get singleton for this type %s of draw object",draw->type_name);
304: }
305: return(0);
306: }
308: /*@C
309: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
310: by the one process.
312: Collective on PetscDraw
314: Input Parameters:
315: + draw - the original window
316: - sdraw - the singleton window
318: Level: advanced
320: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
322: @*/
323: int PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
324: {
325: int ierr,size;
332: MPI_Comm_size(draw->comm,&size);
333: if (size == 1) {
334: return(0);
335: }
337: if (draw->ops->restoresingleton) {
338: (*draw->ops->restoresingleton)(draw,sdraw);
339: } else {
340: SETERRQ1(1,"Cannot restore singleton for this type %s of draw object",draw->type_name);
341: }
342: return(0);
343: }