xref: /petsc/src/sys/classes/draw/interface/drawreg.c (revision 67c2884ef72a42a4f3a1babc25bcfa28f347172e)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith /*
35c6c1daeSBarry Smith        Provides the registration process for PETSc PetscDraw routines
45c6c1daeSBarry Smith */
55c6c1daeSBarry Smith #include <petsc-private/drawimpl.h>  /*I "petscdraw.h" I*/
65c6c1daeSBarry Smith 
75c6c1daeSBarry Smith /*
85c6c1daeSBarry Smith    Contains the list of registered PetscDraw routines
95c6c1daeSBarry Smith */
10140e18c1SBarry Smith PetscFunctionList PetscDrawList = 0;
115c6c1daeSBarry Smith 
125c6c1daeSBarry Smith #undef __FUNCT__
135c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawCreate"
145c6c1daeSBarry Smith /*@C
155c6c1daeSBarry Smith    PetscDrawCreate - Creates a graphics context.
165c6c1daeSBarry Smith 
175c6c1daeSBarry Smith    Collective on MPI_Comm
185c6c1daeSBarry Smith 
195c6c1daeSBarry Smith    Input Parameter:
205c6c1daeSBarry Smith +  comm - MPI communicator
215c6c1daeSBarry Smith .  display - X display when using X windows
225c6c1daeSBarry Smith .  title - optional title added to top of window
235c6c1daeSBarry Smith .  x,y - coordinates of lower left corner of window or PETSC_DECIDE
245c6c1daeSBarry Smith -  w, h - width and height of window or PETSC_DECIDE or PETSC_DRAW_HALF_SIZE, PETSC_DRAW_FULL_SIZE,
255c6c1daeSBarry Smith           or PETSC_DRAW_THIRD_SIZE or PETSC_DRAW_QUARTER_SIZE
265c6c1daeSBarry Smith 
275c6c1daeSBarry Smith    Output Parameter:
285c6c1daeSBarry Smith .  draw - location to put the PetscDraw context
295c6c1daeSBarry Smith 
305c6c1daeSBarry Smith    Level: beginner
315c6c1daeSBarry Smith 
325c6c1daeSBarry Smith    Concepts: graphics^creating context
335c6c1daeSBarry Smith    Concepts: drawing^creating context
345c6c1daeSBarry Smith 
355c6c1daeSBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawDestroy(), PetscDrawSetType()
365c6c1daeSBarry Smith @*/
375c6c1daeSBarry Smith PetscErrorCode  PetscDrawCreate(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscDraw *indraw)
385c6c1daeSBarry Smith {
395c6c1daeSBarry Smith   PetscDraw      draw;
405c6c1daeSBarry Smith   PetscErrorCode ierr;
415c6c1daeSBarry Smith   PetscReal      dpause;
425c6c1daeSBarry Smith   PetscBool      flag;
435c6c1daeSBarry Smith 
445c6c1daeSBarry Smith   PetscFunctionBegin;
45519f805aSKarl Rupp #if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
460298fd71SBarry Smith   ierr = PetscDrawInitializePackage(NULL);CHKERRQ(ierr);
475c6c1daeSBarry Smith #endif
485c6c1daeSBarry Smith   *indraw = 0;
49*67c2884eSBarry Smith   ierr = PetscHeaderCreate(draw,_p_PetscDraw,struct _PetscDrawOps,PETSC_DRAW_CLASSID,"Draw","Graphics","Draw",comm,PetscDrawDestroy,0);CHKERRQ(ierr);
50a297a907SKarl Rupp 
515c6c1daeSBarry Smith   draw->data    = 0;
525c6c1daeSBarry Smith   ierr          = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr);
535c6c1daeSBarry Smith   ierr          = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr);
545c6c1daeSBarry Smith   draw->x       = x;
555c6c1daeSBarry Smith   draw->y       = y;
565c6c1daeSBarry Smith   draw->w       = w;
575c6c1daeSBarry Smith   draw->h       = h;
585c6c1daeSBarry Smith   draw->pause   = 0.0;
595c6c1daeSBarry Smith   draw->coor_xl = 0.0;
605c6c1daeSBarry Smith   draw->coor_xr = 1.0;
615c6c1daeSBarry Smith   draw->coor_yl = 0.0;
625c6c1daeSBarry Smith   draw->coor_yr = 1.0;
635c6c1daeSBarry Smith   draw->port_xl = 0.0;
645c6c1daeSBarry Smith   draw->port_xr = 1.0;
655c6c1daeSBarry Smith   draw->port_yl = 0.0;
665c6c1daeSBarry Smith   draw->port_yr = 1.0;
675c6c1daeSBarry Smith   draw->popup   = 0;
68a297a907SKarl Rupp 
690298fd71SBarry Smith   ierr = PetscOptionsGetReal(NULL,"-draw_pause",&dpause,&flag);CHKERRQ(ierr);
705c6c1daeSBarry Smith   if (flag) draw->pause = dpause;
710298fd71SBarry Smith   draw->savefilename  = NULL;
725c6c1daeSBarry Smith   draw->savefilemovie = PETSC_FALSE;
735c6c1daeSBarry Smith   draw->savefilecount = -1;
74a297a907SKarl Rupp 
755c6c1daeSBarry Smith   ierr = PetscDrawSetCurrentPoint(draw,.5,.9);CHKERRQ(ierr);
76a297a907SKarl Rupp 
775c6c1daeSBarry Smith   draw->boundbox_xl  = .5;
785c6c1daeSBarry Smith   draw->boundbox_xr  = .5;
795c6c1daeSBarry Smith   draw->boundbox_yl  = .9;
805c6c1daeSBarry Smith   draw->boundbox_yr  = .9;
815c6c1daeSBarry Smith 
825c6c1daeSBarry Smith   *indraw = draw;
835c6c1daeSBarry Smith   PetscFunctionReturn(0);
845c6c1daeSBarry Smith }
855c6c1daeSBarry Smith 
865c6c1daeSBarry Smith #undef __FUNCT__
875c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetType"
885c6c1daeSBarry Smith /*@C
895c6c1daeSBarry Smith    PetscDrawSetType - Builds graphics object for a particular implementation
905c6c1daeSBarry Smith 
915c6c1daeSBarry Smith    Collective on PetscDraw
925c6c1daeSBarry Smith 
935c6c1daeSBarry Smith    Input Parameter:
945c6c1daeSBarry Smith +  draw      - the graphics context
955c6c1daeSBarry Smith -  type      - for example, PETSC_DRAW_X
965c6c1daeSBarry Smith 
975c6c1daeSBarry Smith    Options Database Command:
985c6c1daeSBarry Smith .  -draw_type  <type> - Sets the type; use -help for a list
995c6c1daeSBarry Smith     of available methods (for instance, x)
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith    Level: intermediate
1025c6c1daeSBarry Smith 
1035c6c1daeSBarry Smith    Notes:
1045c6c1daeSBarry Smith    See "petsc/include/petscdraw.h" for available methods (for instance,
1055c6c1daeSBarry Smith    PETSC_DRAW_X)
1065c6c1daeSBarry Smith 
1075c6c1daeSBarry Smith    Concepts: drawing^X windows
1085c6c1daeSBarry Smith    Concepts: X windows^graphics
1095c6c1daeSBarry Smith    Concepts: drawing^Microsoft Windows
1105c6c1daeSBarry Smith 
1115c6c1daeSBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy()
1125c6c1daeSBarry Smith @*/
1135c6c1daeSBarry Smith PetscErrorCode  PetscDrawSetType(PetscDraw draw,PetscDrawType type)
1145c6c1daeSBarry Smith {
1155c6c1daeSBarry Smith   PetscErrorCode ierr,(*r)(PetscDraw);
1165c6c1daeSBarry Smith   PetscBool      match;
1175c6c1daeSBarry Smith   PetscBool      flg=PETSC_FALSE;
1185c6c1daeSBarry Smith 
1195c6c1daeSBarry Smith   PetscFunctionBegin;
1205c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
1215c6c1daeSBarry Smith   PetscValidCharPointer(type,2);
1225c6c1daeSBarry Smith 
1235c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)draw,type,&match);CHKERRQ(ierr);
1245c6c1daeSBarry Smith   if (match) PetscFunctionReturn(0);
1255c6c1daeSBarry Smith 
1265c6c1daeSBarry Smith   /*  User requests no graphics */
1270298fd71SBarry Smith   ierr = PetscOptionsHasName(NULL,"-nox",&flg);CHKERRQ(ierr);
1285c6c1daeSBarry Smith 
1295c6c1daeSBarry Smith   /*
1305c6c1daeSBarry Smith      This is not ideal, but it allows codes to continue to run if X graphics
1315c6c1daeSBarry Smith    was requested but is not installed on this machine. Mostly this is for
1325c6c1daeSBarry Smith    testing.
1335c6c1daeSBarry Smith    */
1345c6c1daeSBarry Smith #if !defined(PETSC_HAVE_X)
1355c6c1daeSBarry Smith   if (!flg) {
1365c6c1daeSBarry Smith     ierr = PetscStrcmp(type,PETSC_DRAW_X,&match);CHKERRQ(ierr);
1375c6c1daeSBarry Smith     if (match) {
1385c6c1daeSBarry Smith       PetscBool dontwarn = PETSC_TRUE;
1395c6c1daeSBarry Smith       flg  = PETSC_TRUE;
1400298fd71SBarry Smith       ierr = PetscOptionsHasName(NULL,"-nox_warning",&dontwarn);CHKERRQ(ierr);
141a297a907SKarl Rupp       if (!dontwarn) (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n");
1425c6c1daeSBarry Smith     }
1435c6c1daeSBarry Smith   }
1445c6c1daeSBarry Smith #endif
145a297a907SKarl Rupp   if (flg) type = PETSC_DRAW_NULL;
1465c6c1daeSBarry Smith 
1475c6c1daeSBarry Smith   if (draw->data) {
1485c6c1daeSBarry Smith     /* destroy the old private PetscDraw context */
1495c6c1daeSBarry Smith     ierr               = (*draw->ops->destroy)(draw);CHKERRQ(ierr);
1500298fd71SBarry Smith     draw->ops->destroy = NULL;
1515c6c1daeSBarry Smith     draw->data         = 0;
1525c6c1daeSBarry Smith   }
1535c6c1daeSBarry Smith 
154140e18c1SBarry Smith   ierr =  PetscFunctionListFind(((PetscObject)draw)->comm,PetscDrawList,type,PETSC_TRUE,(void (**)(void)) &r);CHKERRQ(ierr);
1555c6c1daeSBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscDraw type given: %s",type);
1565c6c1daeSBarry Smith   ierr       = PetscObjectChangeTypeName((PetscObject)draw,type);CHKERRQ(ierr);
1575c6c1daeSBarry Smith   draw->data = 0;
1585c6c1daeSBarry Smith   ierr       = (*r)(draw);CHKERRQ(ierr);
1595c6c1daeSBarry Smith   PetscFunctionReturn(0);
1605c6c1daeSBarry Smith }
1615c6c1daeSBarry Smith 
1625c6c1daeSBarry Smith #undef __FUNCT__
1635c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawRegisterDestroy"
1645c6c1daeSBarry Smith /*@C
1655c6c1daeSBarry Smith    PetscDrawRegisterDestroy - Frees the list of PetscDraw methods that were
1665c6c1daeSBarry Smith    registered by PetscDrawRegisterDynamic().
1675c6c1daeSBarry Smith 
1685c6c1daeSBarry Smith    Not Collective
1695c6c1daeSBarry Smith 
1705c6c1daeSBarry Smith    Level: developer
1715c6c1daeSBarry Smith 
1725c6c1daeSBarry Smith .seealso: PetscDrawRegisterDynamic(), PetscDrawRegisterAll()
1735c6c1daeSBarry Smith @*/
1745c6c1daeSBarry Smith PetscErrorCode  PetscDrawRegisterDestroy(void)
1755c6c1daeSBarry Smith {
1765c6c1daeSBarry Smith   PetscErrorCode ierr;
1775c6c1daeSBarry Smith 
1785c6c1daeSBarry Smith   PetscFunctionBegin;
179140e18c1SBarry Smith   ierr = PetscFunctionListDestroy(&PetscDrawList);CHKERRQ(ierr);
1805c6c1daeSBarry Smith   PetscFunctionReturn(0);
1815c6c1daeSBarry Smith }
1825c6c1daeSBarry Smith 
1835c6c1daeSBarry Smith #undef __FUNCT__
1845c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawGetType"
1855c6c1daeSBarry Smith /*@C
1865c6c1daeSBarry Smith    PetscDrawGetType - Gets the PetscDraw type as a string from the PetscDraw object.
1875c6c1daeSBarry Smith 
1885c6c1daeSBarry Smith    Not Collective
1895c6c1daeSBarry Smith 
1905c6c1daeSBarry Smith    Input Parameter:
1915c6c1daeSBarry Smith .  draw - Krylov context
1925c6c1daeSBarry Smith 
1935c6c1daeSBarry Smith    Output Parameters:
1945c6c1daeSBarry Smith .  name - name of PetscDraw method
1955c6c1daeSBarry Smith 
1965c6c1daeSBarry Smith    Level: advanced
1975c6c1daeSBarry Smith 
1985c6c1daeSBarry Smith @*/
1995c6c1daeSBarry Smith PetscErrorCode  PetscDrawGetType(PetscDraw draw,PetscDrawType *type)
2005c6c1daeSBarry Smith {
2015c6c1daeSBarry Smith   PetscFunctionBegin;
2025c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
2035c6c1daeSBarry Smith   PetscValidPointer(type,2);
2045c6c1daeSBarry Smith   *type = ((PetscObject)draw)->type_name;
2055c6c1daeSBarry Smith   PetscFunctionReturn(0);
2065c6c1daeSBarry Smith }
2075c6c1daeSBarry Smith 
2085c6c1daeSBarry Smith #undef __FUNCT__
2095c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawRegister"
2105c6c1daeSBarry Smith PetscErrorCode  PetscDrawRegister(const char *sname,const char *path,const char *name,PetscErrorCode (*function)(PetscDraw))
2115c6c1daeSBarry Smith {
2125c6c1daeSBarry Smith   PetscErrorCode ierr;
2135c6c1daeSBarry Smith   char           fullname[PETSC_MAX_PATH_LEN];
2145c6c1daeSBarry Smith 
2155c6c1daeSBarry Smith   PetscFunctionBegin;
216140e18c1SBarry Smith   ierr = PetscFunctionListConcat(path,name,fullname);CHKERRQ(ierr);
217140e18c1SBarry Smith   ierr = PetscFunctionListAdd(PETSC_COMM_WORLD,&PetscDrawList,sname,fullname,(void (*)(void))function);CHKERRQ(ierr);
2185c6c1daeSBarry Smith   PetscFunctionReturn(0);
2195c6c1daeSBarry Smith }
2205c6c1daeSBarry Smith 
2215c6c1daeSBarry Smith #undef __FUNCT__
2225c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetFromOptions"
2235c6c1daeSBarry Smith /*@
2245c6c1daeSBarry Smith    PetscDrawSetFromOptions - Sets the graphics type from the options database.
2255c6c1daeSBarry Smith       Defaults to a PETSc X windows graphics.
2265c6c1daeSBarry Smith 
2275c6c1daeSBarry Smith    Collective on PetscDraw
2285c6c1daeSBarry Smith 
2295c6c1daeSBarry Smith    Input Parameter:
2305c6c1daeSBarry Smith .     draw - the graphics context
2315c6c1daeSBarry Smith 
2325c6c1daeSBarry Smith    Options Database Keys:
2335c6c1daeSBarry Smith +   -nox - do not use X graphics (ignore graphics calls, but run program correctly)
2345c6c1daeSBarry Smith .   -nox_warning - when X windows support is not installed this prevents the warning message
2355c6c1daeSBarry Smith                    from being printed
2365c6c1daeSBarry Smith .   -draw_save [optional filename] - (X windows only) saves each image before it is cleared to a file
2375c6c1daeSBarry Smith -   -draw_save_movie - converts image files to a movie  at the end of the run. See PetscDrawSetSave()
2385c6c1daeSBarry Smith 
2395c6c1daeSBarry Smith    Level: intermediate
2405c6c1daeSBarry Smith 
2415c6c1daeSBarry Smith    Notes:
2425c6c1daeSBarry Smith     Must be called after PetscDrawCreate() before the PetscDrawtor is used.
2435c6c1daeSBarry Smith 
2445c6c1daeSBarry Smith     Concepts: drawing^setting options
2455c6c1daeSBarry Smith     Concepts: graphics^setting options
2465c6c1daeSBarry Smith 
2475c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscDrawSetType(), PetscDrawSetSave()
2485c6c1daeSBarry Smith 
2495c6c1daeSBarry Smith @*/
2505c6c1daeSBarry Smith PetscErrorCode  PetscDrawSetFromOptions(PetscDraw draw)
2515c6c1daeSBarry Smith {
2525c6c1daeSBarry Smith   PetscErrorCode ierr;
2535c6c1daeSBarry Smith   PetscBool      flg,nox;
2545c6c1daeSBarry Smith   char           vtype[256];
2555c6c1daeSBarry Smith   const char     *def;
2565c6c1daeSBarry Smith #if !defined(PETSC_USE_WINDOWS_GRAPHICS) && !defined(PETSC_HAVE_X)
2575c6c1daeSBarry Smith   PetscBool      warn;
2585c6c1daeSBarry Smith #endif
2595c6c1daeSBarry Smith 
2605c6c1daeSBarry Smith   PetscFunctionBegin;
2615c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
2625c6c1daeSBarry Smith 
2635c6c1daeSBarry Smith   if (!PetscDrawList) {
2640298fd71SBarry Smith     ierr = PetscDrawRegisterAll(NULL);CHKERRQ(ierr);
2655c6c1daeSBarry Smith   }
2665c6c1daeSBarry Smith 
267a297a907SKarl Rupp   if (((PetscObject)draw)->type_name) def = ((PetscObject)draw)->type_name;
268a297a907SKarl Rupp   else {
2690298fd71SBarry Smith     ierr = PetscOptionsHasName(NULL,"-nox",&nox);CHKERRQ(ierr);
2705c6c1daeSBarry Smith     def  = PETSC_DRAW_NULL;
2715c6c1daeSBarry Smith #if defined(PETSC_USE_WINDOWS_GRAPHICS)
2725c6c1daeSBarry Smith     if (!nox) def = PETSC_DRAW_WIN32;
2735c6c1daeSBarry Smith #elif defined(PETSC_HAVE_X)
2745c6c1daeSBarry Smith     if (!nox) def = PETSC_DRAW_X;
2755c6c1daeSBarry Smith #elif defined(PETSC_HAVE_GLUT)
2765c6c1daeSBarry Smith     if (!nox) def = PETSC_DRAW_GLUT;
2775c6c1daeSBarry Smith #elif defined(PETSC_HAVE_OPENGLES)
2785c6c1daeSBarry Smith     if (!nox) def = PETSC_DRAW_OPENGLES;
2795c6c1daeSBarry Smith #else
2800298fd71SBarry Smith     ierr = PetscOptionsHasName(NULL,"-nox_warning",&warn);CHKERRQ(ierr);
281a297a907SKarl Rupp     if (!nox && !warn) (*PetscErrorPrintf)("PETSc installed without X windows, Microsoft Graphics, OpenGL ES, or GLUT/OpenGL on this machine\nproceeding without graphics\n");
2825c6c1daeSBarry Smith #endif
2835c6c1daeSBarry Smith   }
2845c6c1daeSBarry Smith   ierr = PetscObjectOptionsBegin((PetscObject)draw);CHKERRQ(ierr);
2855c6c1daeSBarry Smith   ierr = PetscOptionsList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);CHKERRQ(ierr);
2865c6c1daeSBarry Smith   if (flg) {
2875c6c1daeSBarry Smith     ierr = PetscDrawSetType(draw,vtype);CHKERRQ(ierr);
2885c6c1daeSBarry Smith   } else if (!((PetscObject)draw)->type_name) {
2895c6c1daeSBarry Smith     ierr = PetscDrawSetType(draw,def);CHKERRQ(ierr);
2905c6c1daeSBarry Smith   }
2915c6c1daeSBarry Smith   ierr = PetscOptionsName("-nox","Run without graphics","None",&nox);CHKERRQ(ierr);
2925c6c1daeSBarry Smith #if defined(PETSC_HAVE_X)
2935c6c1daeSBarry Smith   {
2945c6c1daeSBarry Smith     char      filename[PETSC_MAX_PATH_LEN];
2955c6c1daeSBarry Smith     PetscBool save,movie = PETSC_FALSE;
2960298fd71SBarry Smith     ierr = PetscOptionsBool("-draw_save_movie","Make a movie from the images saved (X Windows only)","PetscDrawSetSave",movie,&movie,NULL);CHKERRQ(ierr);
2975c6c1daeSBarry Smith     ierr = PetscOptionsString("-draw_save","Save graphics to file (X Windows only)","PetscDrawSetSave",filename,filename,PETSC_MAX_PATH_LEN,&save);CHKERRQ(ierr);
2985c6c1daeSBarry Smith     if (save) {
2995c6c1daeSBarry Smith       ierr = PetscDrawSetSave(draw,filename,movie);CHKERRQ(ierr);
3005c6c1daeSBarry Smith     }
3015c6c1daeSBarry Smith   }
3025c6c1daeSBarry Smith #endif
3035c6c1daeSBarry Smith 
3045c6c1daeSBarry Smith   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3055c6c1daeSBarry Smith   ierr = PetscObjectProcessOptionsHandlers((PetscObject)draw);CHKERRQ(ierr);
3065c6c1daeSBarry Smith   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3075c6c1daeSBarry Smith   PetscFunctionReturn(0);
3085c6c1daeSBarry Smith }
3095c6c1daeSBarry Smith 
3105c6c1daeSBarry Smith #undef __FUNCT__
3115c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetSave"
3125c6c1daeSBarry Smith /*@C
3135c6c1daeSBarry Smith    PetscDrawSave - Saves images produced in a PetscDraw into a file as a Gif file using AfterImage
3145c6c1daeSBarry Smith 
3155c6c1daeSBarry Smith    Collective on PetscDraw
3165c6c1daeSBarry Smith 
3175c6c1daeSBarry Smith    Input Parameter:
3185c6c1daeSBarry Smith +  draw      - the graphics context
3190298fd71SBarry Smith .  filename  - name of the file, if NULL uses name of draw object
3205c6c1daeSBarry Smith -  movie - produce a movie of all the images
3215c6c1daeSBarry Smith 
3225c6c1daeSBarry Smith    Options Database Command:
3235c6c1daeSBarry Smith +  -draw_save  <filename>
3245c6c1daeSBarry Smith -  -draw_save_movie
3255c6c1daeSBarry Smith 
3265c6c1daeSBarry Smith    Level: intermediate
3275c6c1daeSBarry Smith 
3285c6c1daeSBarry Smith    Concepts: X windows^graphics
3295c6c1daeSBarry Smith 
3305c6c1daeSBarry Smith    Notes: You should call this BEFORE calling PetscDrawClear() and creating your image.
3315c6c1daeSBarry Smith 
3325c6c1daeSBarry Smith    Requires that PETSc be configured with the option --with-afterimage to save the images and ffmpeg must be in your path to make the movie
3335c6c1daeSBarry Smith 
3345c6c1daeSBarry Smith    If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the
3355c6c1daeSBarry Smith    ./configure flags --x-includes=/pathtoXincludes --x-libraries=/pathtoXlibraries   For example under Mac OS X Mountain Lion --x-includes=/opt/X11/include -x-libraries=/opt/X11/lib
3365c6c1daeSBarry Smith 
3375c6c1daeSBarry Smith 
3385c6c1daeSBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSave()
3395c6c1daeSBarry Smith @*/
3405c6c1daeSBarry Smith PetscErrorCode  PetscDrawSetSave(PetscDraw draw,const char *filename,PetscBool movie)
3415c6c1daeSBarry Smith {
3425c6c1daeSBarry Smith   PetscErrorCode ierr;
3435c6c1daeSBarry Smith 
3445c6c1daeSBarry Smith   PetscFunctionBegin;
3455c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
3465c6c1daeSBarry Smith   ierr = PetscFree(draw->savefilename);CHKERRQ(ierr);
347a297a907SKarl Rupp 
3485c6c1daeSBarry Smith   draw->savefilemovie = movie;
3495c6c1daeSBarry Smith   if (filename && filename[0]) {
3505c6c1daeSBarry Smith     ierr = PetscStrallocpy(filename,&draw->savefilename);CHKERRQ(ierr);
3515c6c1daeSBarry Smith   } else {
3525c6c1daeSBarry Smith     const char *name;
3535c6c1daeSBarry Smith     ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr);
3545c6c1daeSBarry Smith     ierr = PetscStrallocpy(name,&draw->savefilename);CHKERRQ(ierr);
3555c6c1daeSBarry Smith   }
3565c6c1daeSBarry Smith   if (draw->ops->setsave) {
3575c6c1daeSBarry Smith     ierr = (*draw->ops->setsave)(draw,filename);CHKERRQ(ierr);
3585c6c1daeSBarry Smith   }
3595c6c1daeSBarry Smith   PetscFunctionReturn(0);
3605c6c1daeSBarry Smith }
361