Actual source code: draw.c

petsc-3.5.4 2015-05-23
Report Typos and Errors
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc-private/drawimpl.h>  /*I "petscdraw.h" I*/
  6: #include <petscviewer.h>

  8: PetscClassId PETSC_DRAW_CLASSID;

 10: static PetscBool PetscDrawPackageInitialized = PETSC_FALSE;
 13: /*@C
 14:   PetscDrawFinalizePackage - This function destroys everything in the Petsc interface to the Draw package. It is
 15:   called from PetscFinalize().

 17:   Level: developer

 19: .keywords: Petsc, destroy, package, mathematica
 20: .seealso: PetscFinalize()
 21: @*/
 22: PetscErrorCode  PetscDrawFinalizePackage(void)
 23: {

 27:   PetscFunctionListDestroy(&PetscDrawList);
 28:   PetscDrawPackageInitialized = PETSC_FALSE;
 29:   return(0);
 30: }

 34: /*@C
 35:   PetscInitializeDrawPackage - This function initializes everything in the PetscDraw package. It is called
 36:   from PetscDLLibraryRegister() when using dynamic libraries, and on the call to PetscInitialize()
 37:   when using static libraries.

 39:   Level: developer

 41: .keywords: Petsc, initialize, package
 42: .seealso: PetscInitialize()
 43: @*/
 44: PetscErrorCode  PetscDrawInitializePackage(void)
 45: {
 46:   char           logList[256];
 47:   char           *className;
 48:   PetscBool      opt;

 52:   if (PetscDrawPackageInitialized) return(0);
 53:   PetscDrawPackageInitialized = PETSC_TRUE;
 54:   /* Register Classes */
 55:   PetscClassIdRegister("Draw",&PETSC_DRAW_CLASSID);
 56:   PetscClassIdRegister("Axis",&PETSC_DRAWAXIS_CLASSID);
 57:   PetscClassIdRegister("Line Graph",&PETSC_DRAWLG_CLASSID);
 58:   PetscClassIdRegister("Histogram",&PETSC_DRAWHG_CLASSID);
 59:   PetscClassIdRegister("Scatter Plot",&PETSC_DRAWSP_CLASSID);
 60:   /* Register Constructors */
 61:   PetscDrawRegisterAll();
 62:   /* Process info exclusions */
 63:   PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);
 64:   if (opt) {
 65:     PetscStrstr(logList, "draw", &className);
 66:     if (className) {
 67:       PetscInfoDeactivateClass(0);
 68:     }
 69:   }
 70:   /* Process summary exclusions */
 71:   PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);
 72:   if (opt) {
 73:     PetscStrstr(logList, "draw", &className);
 74:     if (className) {
 75:       PetscLogEventDeactivateClass(0);
 76:     }
 77:   }
 78:   PetscRegisterFinalize(PetscDrawFinalizePackage);
 79:   return(0);
 80: }

 84: /*@
 85:    PetscDrawResizeWindow - Allows one to resize a window from a program.

 87:    Collective on PetscDraw

 89:    Input Parameter:
 90: +  draw - the window
 91: -  w,h - the new width and height of the window

 93:    Level: intermediate

 95: .seealso: PetscDrawCheckResizedWindow()
 96: @*/
 97: PetscErrorCode  PetscDrawResizeWindow(PetscDraw draw,int w,int h)
 98: {

102:   if (draw->ops->resizewindow) {
103:     (*draw->ops->resizewindow)(draw,w,h);
104:   }
105:   return(0);
106: }

110: /*@
111:    PetscDrawCheckResizedWindow - Checks if the user has resized the window.

113:    Collective on PetscDraw

115:    Input Parameter:
116: .  draw - the window

118:    Level: advanced

120: .seealso: PetscDrawResizeWindow()

122: @*/
123: PetscErrorCode  PetscDrawCheckResizedWindow(PetscDraw draw)
124: {

128:   if (draw->ops->checkresizedwindow) {
129:     (*draw->ops->checkresizedwindow)(draw);
130:   }
131:   return(0);
132: }

136: /*@C
137:    PetscDrawGetTitle - Gets pointer to title of a PetscDraw context.

139:    Not collective

141:    Input Parameter:
142: .  draw - the graphics context

144:    Output Parameter:
145: .  title - the title

147:    Level: intermediate

149: .seealso: PetscDrawSetTitle()
150: @*/
151: PetscErrorCode  PetscDrawGetTitle(PetscDraw draw,char **title)
152: {
156:   *title = draw->title;
157:   return(0);
158: }

162: /*@C
163:    PetscDrawSetTitle - Sets the title of a PetscDraw context.

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

167:    Input Parameters:
168: +  draw - the graphics context
169: -  title - the title

171:    Level: intermediate

173:    Note: The title is positioned in the windowing system title bar for the window. Hence it will not be saved with -draw_save 
174:    in the image.

176:    A copy of the string is made, so you may destroy the
177:    title string after calling this routine.

179:    You can use PetscDrawAxisSetLabels() to indicate a title within the window 

181: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
182: @*/
183: PetscErrorCode  PetscDrawSetTitle(PetscDraw draw,const char title[])
184: {

190:   PetscFree(draw->title);
191:   PetscStrallocpy(title,&draw->title);
192:   if (draw->ops->settitle) {
193:     (*draw->ops->settitle)(draw,title);
194:   }
195:   return(0);
196: }

200: /*@C
201:    PetscDrawAppendTitle - Appends to the title of a PetscDraw context.

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

205:    Input Parameters:
206: +  draw - the graphics context
207: -  title - the title

209:    Note:
210:    A copy of the string is made, so you may destroy the
211:    title string after calling this routine.

213:    Level: advanced

215: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
216: @*/
217: PetscErrorCode  PetscDrawAppendTitle(PetscDraw draw,const char title[])
218: {
220:   size_t         len1,len2,len;
221:   char           *newtitle;

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

227:   if (draw->title) {
228:     PetscStrlen(title,&len1);
229:     PetscStrlen(draw->title,&len2);
230:     len  = len1 + len2;
231:     PetscMalloc1((len + 1),&newtitle);
232:     PetscStrcpy(newtitle,draw->title);
233:     PetscStrcat(newtitle,title);
234:     PetscFree(draw->title);

236:     draw->title = newtitle;
237:   } else {
238:     PetscStrallocpy(title,&draw->title);
239:   }
240:   if (draw->ops->settitle) {
241:     (*draw->ops->settitle)(draw,draw->title);
242:   }
243:   return(0);
244: }

248: /*@
249:    PetscDrawDestroy - Deletes a draw context.

251:    Collective on PetscDraw

253:    Input Parameters:
254: .  draw - the drawing context

256:    Level: beginner

258: .seealso: PetscDrawCreate()

260: @*/
261: PetscErrorCode  PetscDrawDestroy(PetscDraw *draw)
262: {

266:   if (!*draw) return(0);
268:   if (--((PetscObject)(*draw))->refct > 0) return(0);

270:   if ((*draw)->pause == -2) {
271:     (*draw)->pause = -1;

273:     PetscDrawPause(*draw);
274:   }

276:   /* if memory was published then destroy it */
277:   PetscObjectSAWsViewOff((PetscObject)*draw);

279:   if ((*draw)->ops->destroy) {
280:     (*(*draw)->ops->destroy)(*draw);
281:   }
282:   PetscFree((*draw)->title);
283:   PetscFree((*draw)->display);
284:   PetscFree((*draw)->savefilename);
285:   PetscFree((*draw)->savefinalfilename);
286:   PetscHeaderDestroy(draw);
287:   return(0);
288: }

292: /*@
293:    PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.

295:    Collective on PetscDraw

297:    Input Parameter:
298: .  draw - the original window

300:    Output Parameter:
301: .  popup - the new popup window

303:    Level: advanced

305: @*/
306: PetscErrorCode  PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
307: {


314:   if (draw->popup) *popup = draw->popup;
315:   else if (draw->ops->getpopup) {
316:     (*draw->ops->getpopup)(draw,popup);
317:     if (*popup) {
318:       PetscObjectSetOptionsPrefix((PetscObject)*popup,"popup_");
319:       PetscDrawSetFromOptions(*popup);
320:     }
321:   } else *popup = NULL;
322:   return(0);
323: }

327: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
328: {
330:   return(0);
331: }

335: /*
336:   PetscDrawOpenNull - Opens a null drawing context. All draw commands to
337:   it are ignored.

339:   Output Parameter:
340: . win - the drawing context

342:    Level: advanced

344: */
345: PetscErrorCode  PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
346: {

350:   PetscDrawCreate(comm,NULL,NULL,0,0,1,1,win);
351:   PetscDrawSetType(*win,PETSC_DRAW_NULL);
352:   return(0);
353: }

357: /*@
358:   PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed

360:   Input Parameter:
361: + draw - the drawing context
362: - display - the X windows display

364:   Level: advanced

366: @*/
367: PetscErrorCode  PetscDrawSetDisplay(PetscDraw draw,const char display[])
368: {

372:   PetscFree(draw->display);
373:   PetscStrallocpy(display,&draw->display);
374:   return(0);
375: }

379: /*
380:   PetscDrawCreate_Null - Opens a null drawing context. All draw commands to
381:   it are ignored.

383:   Input Parameter:
384: . win - the drawing context
385: */
386: PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
387: {

391:   PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));

393:   draw->ops->destroy = PetscDrawDestroy_Null;
394:   draw->ops->view    = 0;
395:   draw->pause        = 0.0;
396:   draw->coor_xl      = 0.0;  draw->coor_xr = 1.0;
397:   draw->coor_yl      = 0.0;  draw->coor_yr = 1.0;
398:   draw->port_xl      = 0.0;  draw->port_xr = 1.0;
399:   draw->port_yl      = 0.0;  draw->port_yr = 1.0;
400:   draw->popup        = 0;
401:   return(0);
402: }

406: /*@C
407:    PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned
408:         by the one process.

410:    Collective on PetscDraw

412:    Input Parameter:
413: .  draw - the original window

415:    Output Parameter:
416: .  sdraw - the singleton window

418:    Level: advanced

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

422: @*/
423: PetscErrorCode  PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
424: {
426:   PetscMPIInt    size;


432:   MPI_Comm_size(PetscObjectComm((PetscObject)draw),&size);
433:   if (size == 1) *sdraw = draw;
434:   else {
435:     if (draw->ops->getsingleton) {
436:       (*draw->ops->getsingleton)(draw,sdraw);
437:     } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name);
438:   }
439:   return(0);
440: }

444: /*@C
445:    PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned
446:         by the one process.

448:    Collective on PetscDraw

450:    Input Parameters:
451: +  draw - the original window
452: -  sdraw - the singleton window

454:    Level: advanced

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

458: @*/
459: PetscErrorCode  PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
460: {
462:   PetscMPIInt    size;


469:   MPI_Comm_size(PetscObjectComm((PetscObject)draw),&size);
470:   if (size != 1) {
471:     if (draw->ops->restoresingleton) {
472:       (*draw->ops->restoresingleton)(draw,sdraw);
473:     } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name);
474:   }
475:   return(0);
476: }