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: /*@
8: PetscDrawResizeWindow - Allows one to resize a window from a program.
10: Collective on PetscDraw
12: Input Parameter:
13: + draw - the window
14: - w,h - the new width and height of the window
16: Level: intermediate
18: .seealso: PetscDrawCheckResizedWindow()
19: @*/
20: int PetscDrawResizeWindow(PetscDraw draw,int w,int h)
21: {
24: if (draw->ops->resizewindow) {
25: (*draw->ops->resizewindow)(draw,w,h);
26: }
27: return(0);
28: }
30: /*@
31: PetscDrawCheckResizedWindow - Checks if the user has resized the window.
33: Collective on PetscDraw
35: Input Parameter:
36: . draw - the window
38: Level: advanced
40: .seealso: PetscDrawResizeWindow()
42: @*/
43: int PetscDrawCheckResizedWindow(PetscDraw draw)
44: {
47: if (draw->ops->checkresizedwindow) {
48: (*draw->ops->checkresizedwindow)(draw);
49: }
50: return(0);
51: }
53: /*@C
54: PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.
56: Not collective
58: Input Parameter:
59: . draw - the graphics context
61: Output Parameter:
62: . title - the title
64: Level: intermediate
66: .seealso: PetscDrawSetTitle()
67: @*/
68: int PetscDrawGetTitle(PetscDraw draw,char **title)
69: {
72: *title = draw->title;
73: return(0);
74: }
76: /*@C
77: PetscDrawSetTitle - Sets the title of a PetscDraw context.
79: Not collective (any processor or all may call this)
81: Input Parameters:
82: + draw - the graphics context
83: - title - the title
85: Level: intermediate
87: Note:
88: A copy of the string is made, so you may destroy the
89: title string after calling this routine.
91: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
92: @*/
93: int PetscDrawSetTitle(PetscDraw draw,char *title)
94: {
98: PetscStrfree(draw->title);
99: PetscStrallocpy(title,&draw->title);
100: if (draw->ops->settitle) {
101: (*draw->ops->settitle)(draw,title);
102: }
103: return(0);
104: }
106: /*@C
107: PetscDrawAppendTitle - Appends to the title of a PetscDraw context.
109: Not collective (any processor or all can call this)
111: Input Parameters:
112: + draw - the graphics context
113: - title - the title
115: Note:
116: A copy of the string is made, so you may destroy the
117: title string after calling this routine.
119: Level: advanced
121: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
122: @*/
123: int PetscDrawAppendTitle(PetscDraw draw,char *title)
124: {
125: int ierr,len1,len2,len;
126: char *newtitle;
130: if (!title) return(0);
132: if (draw->title) {
133: PetscStrlen(title,&len1);
134: PetscStrlen(draw->title,&len2);
135: len = len1 + len2;
136: PetscMalloc((len + 1)*sizeof(char*),&newtitle);
137: PetscStrcpy(newtitle,draw->title);
138: PetscStrcat(newtitle,title);
139: PetscFree(draw->title);
140: draw->title = newtitle;
141: } else {
142: PetscStrallocpy(title,&draw->title);
143: }
144: if (draw->ops->settitle) {
145: (*draw->ops->settitle)(draw,draw->title);
146: }
147: return(0);
148: }
150: /*@C
151: PetscDrawDestroy - Deletes a draw context.
153: Collective on PetscDraw
155: Input Parameters:
156: . draw - the drawing context
158: Level: beginner
160: .seealso: PetscDrawCreate()
162: @*/
163: int PetscDrawDestroy(PetscDraw draw)
164: {
168: if (--draw->refct > 0) return(0);
170: /* if memory was published with AMS then destroy it */
171: PetscObjectDepublish(draw);
173: if (draw->ops->destroy) {
174: (*draw->ops->destroy)(draw);
175: }
176: PetscStrfree(draw->title);
177: PetscStrfree(draw->display);
178: PetscLogObjectDestroy(draw);
179: PetscHeaderDestroy(draw);
180: return(0);
181: }
183: /*@C
184: PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.
186: Collective on PetscDraw
188: Input Parameter:
189: . draw - the original window
191: Output Parameter:
192: . popup - the new popup window
194: Level: advanced
196: @*/
197: int PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
198: {
204: if (draw->popup) {
205: *popup = draw->popup;
206: } else if (draw->ops->getpopup) {
207: (*draw->ops->getpopup)(draw,popup);
208: } else {
209: *popup = PETSC_NULL;
210: }
211: return(0);
212: }
214: int PetscDrawDestroy_Null(PetscDraw draw)
215: {
217: return(0);
218: }
220: /*
221: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
222: it are ignored.
224: Output Parameter:
225: . win - the drawing context
227: Level: advanced
229: */
230: int PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
231: {
235: PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
236: PetscDrawSetType(*win,PETSC_DRAW_NULL);
237: return(0);
238: }
240: EXTERN_C_BEGIN
241: /*
242: PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
243: it are ignored.
245: Input Parameter:
246: . win - the drawing context
247: */
248: int PetscDrawCreate_Null(PetscDraw draw)
249: {
253: PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
254: draw->ops->destroy = PetscDrawDestroy_Null;
255: draw->ops->view = 0;
256: draw->pause = 0;
257: draw->coor_xl = 0.0; draw->coor_xr = 1.0;
258: draw->coor_yl = 0.0; draw->coor_yr = 1.0;
259: draw->port_xl = 0.0; draw->port_xr = 1.0;
260: draw->port_yl = 0.0; draw->port_yr = 1.0;
261: draw->popup = 0;
263: return(0);
264: }
265: EXTERN_C_END
267: /*@C
268: PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
269: by the one process.
271: Collective on PetscDraw
273: Input Parameter:
274: . draw - the original window
276: Output Parameter:
277: . sdraw - the singleton window
279: Level: advanced
281: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
283: @*/
284: int PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
285: {
286: int ierr,size;
292: MPI_Comm_size(draw->comm,&size);
293: if (size == 1) {
294: *sdraw = draw;
295: return(0);
296: }
298: if (draw->ops->getsingleton) {
299: (*draw->ops->getsingleton)(draw,sdraw);
300: } else {
301: SETERRQ1(1,"Cannot get singleton for this type %s of draw object",draw->type_name);
302: }
303: return(0);
304: }
306: /*@C
307: PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
308: by the one process.
310: Collective on PetscDraw
312: Input Parameters:
313: + draw - the original window
314: - sdraw - the singleton window
316: Level: advanced
318: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()
320: @*/
321: int PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
322: {
323: int ierr,size;
330: MPI_Comm_size(draw->comm,&size);
331: if (size == 1) {
332: return(0);
333: }
335: if (draw->ops->restoresingleton) {
336: (*draw->ops->restoresingleton)(draw,sdraw);
337: } else {
338: SETERRQ1(1,"Cannot restore singleton for this type %s of draw object",draw->type_name);
339: }
340: return(0);
341: }