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 = 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: int 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: int 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: int 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: int 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: int PetscDrawAppendTitle(PetscDraw draw,const char title[])
138: {
139:   int  ierr,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: int PetscDrawDestroy(PetscDraw draw)
180: {
184:   if (--draw->refct > 0) return(0);

186:   /* if memory was published with AMS 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: int 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: int 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: int 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: int PetscDrawSetDisplay(PetscDraw draw,char *display)
275: {

279:   PetscStrfree(draw->display);
280:   PetscStrallocpy(display,&draw->display);
281:   return(0);
282: }

284: EXTERN_C_BEGIN
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: int 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: }
311: EXTERN_C_END

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: int PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
333: {
334:   int ierr,size;


340:   MPI_Comm_size(draw->comm,&size);
341:   if (size == 1) {
342:     *sdraw = draw;
343:     return(0);
344:   }

346:   if (draw->ops->getsingleton) {
347:     (*draw->ops->getsingleton)(draw,sdraw);
348:   } else {
349:     SETERRQ1(1,"Cannot get singleton for this type %s of draw object",draw->type_name);
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: int PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
372: {
373:   int ierr,size;


380:   MPI_Comm_size(draw->comm,&size);
381:   if (size == 1) {
382:      return(0);
383:   }

385:   if (draw->ops->restoresingleton) {
386:     (*draw->ops->restoresingleton)(draw,sdraw);
387:   } else {
388:     SETERRQ1(1,"Cannot restore singleton for this type %s of draw object",draw->type_name);
389:   }
390:   return(0);
391: }