Actual source code: draw.c

petsc-3.3-p7 2013-05-11
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <../src/sys/draw/drawimpl.h>  /*I "petscdraw.h" I*/

  7: PetscClassId PETSC_DRAW_CLASSID;

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

 16:   Level: developer

 18: .keywords: Petsc, destroy, package, mathematica
 19: .seealso: PetscFinalize()
 20: @*/
 21: PetscErrorCode  PetscDrawFinalizePackage(void)
 22: {
 24:   PetscDrawPackageInitialized = PETSC_FALSE;
 25:   PetscDrawList               = 0;
 26:   return(0);
 27: }

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

 36:   Input Parameter:
 37:   path - The dynamic library path, or PETSC_NULL

 39:   Level: developer

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

 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(path);
 62:   /* Process info exclusions */
 63:   PetscOptionsGetString(PETSC_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(PETSC_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: {
101:   if (draw->ops->resizewindow) {
102:     (*draw->ops->resizewindow)(draw,w,h);
103:   }
104:   return(0);
105: }

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

112:    Collective on PetscDraw

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

117:    Level: advanced

119: .seealso: PetscDrawResizeWindow()

121: @*/
122: PetscErrorCode  PetscDrawCheckResizedWindow(PetscDraw draw)
123: {
126:   if (draw->ops->checkresizedwindow) {
127:     (*draw->ops->checkresizedwindow)(draw);
128:   }
129:   return(0);
130: }

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

137:    Not collective

139:    Input Parameter:
140: .  draw - the graphics context

142:    Output Parameter:
143: .  title - the title

145:    Level: intermediate

147: .seealso: PetscDrawSetTitle()
148: @*/
149: PetscErrorCode  PetscDrawGetTitle(PetscDraw draw,char **title)
150: {
154:   *title = draw->title;
155:   return(0);
156: }

160: /*@C
161:    PetscDrawSetTitle - Sets the title of a PetscDraw context.

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

165:    Input Parameters:
166: +  draw - the graphics context
167: -  title - the title

169:    Level: intermediate

171:    Note:
172:    A copy of the string is made, so you may destroy the 
173:    title string after calling this routine.

175: .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle()
176: @*/
177: PetscErrorCode  PetscDrawSetTitle(PetscDraw draw,const char title[])
178: {
183:   PetscFree(draw->title);
184:   PetscStrallocpy(title,&draw->title);
185:   if (draw->ops->settitle) {
186:     (*draw->ops->settitle)(draw,title);
187:   }
188:   return(0);
189: }

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

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

198:    Input Parameters:
199: +  draw - the graphics context
200: -  title - the title

202:    Note:
203:    A copy of the string is made, so you may destroy the 
204:    title string after calling this routine.

206:    Level: advanced

208: .seealso: PetscDrawSetTitle(), PetscDrawGetTitle()
209: @*/
210: PetscErrorCode  PetscDrawAppendTitle(PetscDraw draw,const char title[])
211: {
213:   size_t len1,len2,len;
214:   char   *newtitle;

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

220:   if (draw->title) {
221:     PetscStrlen(title,&len1);
222:     PetscStrlen(draw->title,&len2);
223:     len  = len1 + len2;
224:     PetscMalloc((len + 1)*sizeof(char*),&newtitle);
225:     PetscStrcpy(newtitle,draw->title);
226:     PetscStrcat(newtitle,title);
227:     PetscFree(draw->title);
228:     draw->title = newtitle;
229:   } else {
230:     PetscStrallocpy(title,&draw->title);
231:   }
232:   if (draw->ops->settitle) {
233:     (*draw->ops->settitle)(draw,draw->title);
234:   }
235:   return(0);
236: }

240: /*@
241:    PetscDrawDestroy - Deletes a draw context.

243:    Collective on PetscDraw

245:    Input Parameters:
246: .  draw - the drawing context

248:    Level: beginner

250: .seealso: PetscDrawCreate()

252: @*/
253: PetscErrorCode  PetscDrawDestroy(PetscDraw *draw)
254: {
257:   if (!*draw) return(0);
259:   if (--((PetscObject)(*draw))->refct > 0) return(0);

261:   /* if memory was published then destroy it */
262:   PetscObjectDepublish(*draw);

264:   if ((*draw)->ops->destroy) {
265:     (*(*draw)->ops->destroy)(*draw);
266:   }
267:   PetscFree((*draw)->title);
268:   PetscFree((*draw)->display);
269:   PetscFree((*draw)->savefilename);
270:   PetscHeaderDestroy(draw);
271:   return(0);
272: }

276: /*@
277:    PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window.

279:    Collective on PetscDraw

281:    Input Parameter:
282: .  draw - the original window

284:    Output Parameter:
285: .  popup - the new popup window

287:    Level: advanced

289: @*/
290: PetscErrorCode  PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup)
291: {

297:   if (draw->popup) {
298:     *popup = draw->popup;
299:   } else if (draw->ops->getpopup) {
300:       (*draw->ops->getpopup)(draw,popup);
301:   } else {
302:     *popup = PETSC_NULL;
303:   }
304:   return(0);
305: }

309: PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw)
310: {
312:   return(0);
313: }

317: /*
318:   PetscDrawOpenNull - Opens a null drawing context. All draw commands to 
319:   it are ignored.

321:   Output Parameter:
322: . win - the drawing context

324:    Level: advanced

326: */
327: PetscErrorCode  PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win)
328: {

332:   PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);
333:   PetscDrawSetType(*win,PETSC_DRAW_NULL);
334:   return(0);
335: }

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

342:   Input Parameter:
343: + draw - the drawing context
344: - display - the X windows display

346:   Level: advanced

348: @*/
349: PetscErrorCode  PetscDrawSetDisplay(PetscDraw draw,char *display)
350: {

354:   PetscFree(draw->display);
355:   PetscStrallocpy(display,&draw->display);
356:   return(0);
357: }

359: EXTERN_C_BEGIN
362: /*
363:   PetscDrawCreate_Null - Opens a null drawing context. All draw commands to 
364:   it are ignored.

366:   Input Parameter:
367: . win - the drawing context
368: */
369: PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
370: {

374:   PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));
375:   draw->ops->destroy = PetscDrawDestroy_Null;
376:   draw->ops->view    = 0;
377:   draw->pause   = 0.0;
378:   draw->coor_xl = 0.0;  draw->coor_xr = 1.0;
379:   draw->coor_yl = 0.0;  draw->coor_yr = 1.0;
380:   draw->port_xl = 0.0;  draw->port_xr = 1.0;
381:   draw->port_yl = 0.0;  draw->port_yr = 1.0;
382:   draw->popup   = 0;

384:   return(0);
385: }
386: EXTERN_C_END

390: /*@C
391:    PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned 
392:         by the one process.

394:    Collective on PetscDraw

396:    Input Parameter:
397: .  draw - the original window

399:    Output Parameter:
400: .  sdraw - the singleton window

402:    Level: advanced

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

406: @*/
407: PetscErrorCode  PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw)
408: {
410:   PetscMPIInt    size;


416:   MPI_Comm_size(((PetscObject)draw)->comm,&size);
417:   if (size == 1) {
418:     *sdraw = draw;
419:   } else {
420:     if (draw->ops->getsingleton) {
421:       (*draw->ops->getsingleton)(draw,sdraw);
422:     } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name);
423:   }
424:   return(0);
425: }

429: /*@C
430:    PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned 
431:         by the one process.

433:    Collective on PetscDraw

435:    Input Parameters:
436: +  draw - the original window
437: -  sdraw - the singleton window

439:    Level: advanced

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

443: @*/
444: PetscErrorCode  PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw)
445: {
447:   PetscMPIInt    size;


454:   MPI_Comm_size(((PetscObject)draw)->comm,&size);
455:   if (size != 1) {
456:     if (draw->ops->restoresingleton) {
457:       (*draw->ops->restoresingleton)(draw,sdraw);
458:     } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name);
459:   }
460:   return(0);
461: }