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: #undef __FUNCT__  
 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: }

 34: #undef __FUNCT__  
 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: }

 59: #undef __FUNCT__  
 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: {
 80:   *title = draw->title;
 81:   return(0);
 82: }

 84: #undef __FUNCT__  
 86: /*@C
 87:    PetscDrawSetTitle - Sets the title of a PetscDraw context.

 89:    Not collective (any processor or all may call this)

 91:    Input Parameters:
 92: +  draw - the graphics context
 93: -  title - the title

 95:    Level: intermediate

 97:    Note:
 98:    A copy of the string is made, so you may destroy the 
 99:    title string after calling this routine.

101: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
102: @*/
103: int PetscDrawSetTitle(PetscDraw draw,char *title)
104: {
108:   PetscStrfree(draw->title);
109:   PetscStrallocpy(title,&draw->title);
110:   if (draw->ops->settitle) {
111:     (*draw->ops->settitle)(draw,title);
112:   }
113:   return(0);
114: }

116: #undef __FUNCT__  
118: /*@C
119:    PetscDrawAppendTitle - Appends to the title of a PetscDraw context.

121:    Not collective (any processor or all can call this)

123:    Input Parameters:
124: +  draw - the graphics context
125: -  title - the title

127:    Note:
128:    A copy of the string is made, so you may destroy the 
129:    title string after calling this routine.

131:    Level: advanced

133: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
134: @*/
135: int PetscDrawAppendTitle(PetscDraw draw,char *title)
136: {
137:   int  ierr,len1,len2,len;
138:   char *newtitle;

142:   if (!title) return(0);

144:   if (draw->title) {
145:     PetscStrlen(title,&len1);
146:     PetscStrlen(draw->title,&len2);
147:     len  = len1 + len2;
148:     PetscMalloc((len + 1)*sizeof(char*),&newtitle);
149:     PetscStrcpy(newtitle,draw->title);
150:     PetscStrcat(newtitle,title);
151:     PetscFree(draw->title);
152:     draw->title = newtitle;
153:   } else {
154:     PetscStrallocpy(title,&draw->title);
155:   }
156:   if (draw->ops->settitle) {
157:     (*draw->ops->settitle)(draw,draw->title);
158:   }
159:   return(0);
160: }

162: #undef __FUNCT__  
164: /*@C
165:    PetscDrawDestroy - Deletes a draw context.

167:    Collective on PetscDraw

169:    Input Parameters:
170: .  draw - the drawing context

172:    Level: beginner

174: .seealso: PetscDrawCreate()

176: @*/
177: int PetscDrawDestroy(PetscDraw draw)
178: {
182:   if (--draw->refct > 0) return(0);

184:   /* if memory was published with AMS then destroy it */
185:   PetscObjectDepublish(draw);

187:   if (draw->ops->destroy) {
188:     (*draw->ops->destroy)(draw);
189:   }
190:   PetscStrfree(draw->title);
191:   PetscStrfree(draw->display);
192:   PetscLogObjectDestroy(draw);
193:   PetscHeaderDestroy(draw);
194:   return(0);
195: }

197: #undef __FUNCT__  
199: /*@C
200:    PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.

202:    Collective on PetscDraw

204:    Input Parameter:
205: .  draw - the original window

207:    Output Parameter:
208: .  popup - the new popup window

210:    Level: advanced

212: @*/
213: int PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
214: {

220:   if (draw->popup) {
221:     *popup = draw->popup;
222:   } else if (draw->ops->getpopup) {
223:       (*draw->ops->getpopup)(draw,popup);
224:   } else {
225:     *popup = PETSC_NULL;
226:   }
227:   return(0);
228: }

230: #undef __FUNCT__  
232: int PetscDrawDestroy_Null(PetscDraw draw)
233: {
235:   return(0);
236: }

238: #undef __FUNCT__  
240: /*
241:   PetscDrawOpenNull - Opens a null drawing context. All draw commands to 
242:   it are ignored.

244:   Output Parameter:
245: . win - the drawing context

247:    Level: advanced

249: */
250: int PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
251: {

255:   PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
256:   PetscDrawSetType(*win,PETSC_DRAW_NULL);
257:   return(0);
258: }

260: #undef __FUNCT__  
262: /*@
263:   PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed

265:   Input Parameter:
266: + draw - the drawing context
267: - display - the X windows display

269:   Level: advanced

271: @*/
272: int PetscDrawSetDisplay(PetscDraw draw,char *display)
273: {

277:   ierr          = PetscStrfree(draw->display);
278:   ierr          = PetscStrallocpy(display,&draw->display);
279:   return(0);
280: }

282: EXTERN_C_BEGIN
283: #undef __FUNCT__  
285: /*
286:   PetscDrawCreate_Null - Opens a null drawing context. All draw commands to 
287:   it are ignored.

289:   Input Parameter:
290: . win - the drawing context
291: */
292: int PetscDrawCreate_Null(PetscDraw draw)
293: {

297:   PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
298:   draw->ops->destroy = PetscDrawDestroy_Null;
299:   draw->ops->view    = 0;
300:   draw->pause   = 0;
301:   draw->coor_xl = 0.0;  draw->coor_xr = 1.0;
302:   draw->coor_yl = 0.0;  draw->coor_yr = 1.0;
303:   draw->port_xl = 0.0;  draw->port_xr = 1.0;
304:   draw->port_yl = 0.0;  draw->port_yr = 1.0;
305:   draw->popup   = 0;

307:   return(0);
308: }
309: EXTERN_C_END

311: #undef __FUNCT__  
313: /*@C
314:    PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned 
315:         by the one process.

317:    Collective on PetscDraw

319:    Input Parameter:
320: .  draw - the original window

322:    Output Parameter:
323: .  sdraw - the singleton window

325:    Level: advanced

327: .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()

329: @*/
330: int PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
331: {
332:   int ierr,size;


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

344:   if (draw->ops->getsingleton) {
345:     (*draw->ops->getsingleton)(draw,sdraw);
346:   } else {
347:     SETERRQ1(1,"Cannot get singleton for this type %s of draw object",draw->type_name);
348:   }
349:   return(0);
350: }

352: #undef __FUNCT__  
354: /*@C
355:    PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned 
356:         by the one process.

358:    Collective on PetscDraw

360:    Input Parameters:
361: +  draw - the original window
362: -  sdraw - the singleton window

364:    Level: advanced

366: .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton()

368: @*/
369: int PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
370: {
371:   int ierr,size;


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

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