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) 46607a6623SBarry Smith ierr = PetscDrawInitializePackage();CHKERRQ(ierr); 475c6c1daeSBarry Smith #endif 485c6c1daeSBarry Smith *indraw = 0; 4967c2884eSBarry 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 154*1c9cd337SJed Brown ierr = PetscFunctionListFind(PetscDrawList,type,&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 1661c84c290SBarry Smith registered by PetscDrawRegister(). 1675c6c1daeSBarry Smith 1685c6c1daeSBarry Smith Not Collective 1695c6c1daeSBarry Smith 1705c6c1daeSBarry Smith Level: developer 1715c6c1daeSBarry Smith 1721c84c290SBarry Smith .seealso: PetscDrawRegister(), 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" 210607a6623SBarry Smith /*@C 2111c84c290SBarry Smith PetscDrawRegister - Adds a method to the graphics package. 2121c84c290SBarry Smith 2131c84c290SBarry Smith Not Collective 2141c84c290SBarry Smith 2151c84c290SBarry Smith Input Parameters: 2161c84c290SBarry Smith + name_solver - name of a new user-defined solver 2171c84c290SBarry Smith - routine_create - routine to create method context 2181c84c290SBarry Smith 2191c84c290SBarry Smith Level: developer 2201c84c290SBarry Smith 2211c84c290SBarry Smith Notes: 2221c84c290SBarry Smith PetscDrawRegister() may be called multiple times to add several user-defined solvers. 2231c84c290SBarry Smith 2241c84c290SBarry Smith Sample usage: 2251c84c290SBarry Smith .vb 226bdf89e91SBarry Smith PetscDrawRegister("my_draw_type", MyDrawCreate); 2271c84c290SBarry Smith .ve 2281c84c290SBarry Smith 2291c84c290SBarry Smith Then, your solver can be chosen with the procedural interface via 2301c84c290SBarry Smith $ PetscDrawSetType(ksp,"my_draw_type") 2311c84c290SBarry Smith or at runtime via the option 2321c84c290SBarry Smith $ -draw_type my_draw_type 2331c84c290SBarry Smith 2341c84c290SBarry Smith Concepts: graphics^registering new draw classes 2351c84c290SBarry Smith Concepts: PetscDraw^registering new draw classes 2361c84c290SBarry Smith 2371c84c290SBarry Smith .seealso: PetscDrawRegisterAll(), PetscDrawRegisterDestroy() 2381c84c290SBarry Smith @*/ 239bdf89e91SBarry Smith PetscErrorCode PetscDrawRegister(const char *sname,PetscErrorCode (*function)(PetscDraw)) 2405c6c1daeSBarry Smith { 2415c6c1daeSBarry Smith PetscErrorCode ierr; 2425c6c1daeSBarry Smith 2435c6c1daeSBarry Smith PetscFunctionBegin; 244bdf89e91SBarry Smith ierr = PetscFunctionListAdd(&PetscDrawList,sname,(void (*)(void))function);CHKERRQ(ierr); 2455c6c1daeSBarry Smith PetscFunctionReturn(0); 2465c6c1daeSBarry Smith } 2475c6c1daeSBarry Smith 2485c6c1daeSBarry Smith #undef __FUNCT__ 2495c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetFromOptions" 2505c6c1daeSBarry Smith /*@ 2515c6c1daeSBarry Smith PetscDrawSetFromOptions - Sets the graphics type from the options database. 2525c6c1daeSBarry Smith Defaults to a PETSc X windows graphics. 2535c6c1daeSBarry Smith 2545c6c1daeSBarry Smith Collective on PetscDraw 2555c6c1daeSBarry Smith 2565c6c1daeSBarry Smith Input Parameter: 2575c6c1daeSBarry Smith . draw - the graphics context 2585c6c1daeSBarry Smith 2595c6c1daeSBarry Smith Options Database Keys: 2605c6c1daeSBarry Smith + -nox - do not use X graphics (ignore graphics calls, but run program correctly) 2615c6c1daeSBarry Smith . -nox_warning - when X windows support is not installed this prevents the warning message 2625c6c1daeSBarry Smith from being printed 2637450148dSBarry Smith . -draw_pause <pause amount> -- -1 indicates wait for mouse input, -2 indicates pause when window is to be destroyed 2645c6c1daeSBarry Smith . -draw_save [optional filename] - (X windows only) saves each image before it is cleared to a file 265a4494fc1SBarry Smith . -draw_save_movie - converts image files to a movie at the end of the run. See PetscDrawSetSave() 266a4494fc1SBarry Smith - -draw_save_on_flush - saves an image on each flush in addition to each clear 2675c6c1daeSBarry Smith 2685c6c1daeSBarry Smith Level: intermediate 2695c6c1daeSBarry Smith 2705c6c1daeSBarry Smith Notes: 2715c6c1daeSBarry Smith Must be called after PetscDrawCreate() before the PetscDrawtor is used. 2725c6c1daeSBarry Smith 2735c6c1daeSBarry Smith Concepts: drawing^setting options 2745c6c1daeSBarry Smith Concepts: graphics^setting options 2755c6c1daeSBarry Smith 2765c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscDrawSetType(), PetscDrawSetSave() 2775c6c1daeSBarry Smith 2785c6c1daeSBarry Smith @*/ 2795c6c1daeSBarry Smith PetscErrorCode PetscDrawSetFromOptions(PetscDraw draw) 2805c6c1daeSBarry Smith { 2815c6c1daeSBarry Smith PetscErrorCode ierr; 2825c6c1daeSBarry Smith PetscBool flg,nox; 2835c6c1daeSBarry Smith char vtype[256]; 2845c6c1daeSBarry Smith const char *def; 2857450148dSBarry Smith PetscReal dpause; 2865c6c1daeSBarry Smith #if !defined(PETSC_USE_WINDOWS_GRAPHICS) && !defined(PETSC_HAVE_X) 2875c6c1daeSBarry Smith PetscBool warn; 2885c6c1daeSBarry Smith #endif 2895c6c1daeSBarry Smith 2905c6c1daeSBarry Smith PetscFunctionBegin; 2915c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 2925c6c1daeSBarry Smith 2935c6c1daeSBarry Smith if (!PetscDrawList) { 294607a6623SBarry Smith ierr = PetscDrawRegisterAll();CHKERRQ(ierr); 2955c6c1daeSBarry Smith } 2965c6c1daeSBarry Smith 297a297a907SKarl Rupp if (((PetscObject)draw)->type_name) def = ((PetscObject)draw)->type_name; 298a297a907SKarl Rupp else { 2990298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox",&nox);CHKERRQ(ierr); 3005c6c1daeSBarry Smith def = PETSC_DRAW_NULL; 3015c6c1daeSBarry Smith #if defined(PETSC_USE_WINDOWS_GRAPHICS) 3025c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_WIN32; 3035c6c1daeSBarry Smith #elif defined(PETSC_HAVE_X) 3045c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_X; 3055c6c1daeSBarry Smith #elif defined(PETSC_HAVE_GLUT) 3065c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_GLUT; 3075c6c1daeSBarry Smith #elif defined(PETSC_HAVE_OPENGLES) 3085c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_OPENGLES; 3095c6c1daeSBarry Smith #else 3100298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox_warning",&warn);CHKERRQ(ierr); 311a297a907SKarl Rupp if (!nox && !warn) (*PetscErrorPrintf)("PETSc installed without X windows, Microsoft Graphics, OpenGL ES, or GLUT/OpenGL on this machine\nproceeding without graphics\n"); 3125c6c1daeSBarry Smith #endif 3135c6c1daeSBarry Smith } 3145c6c1daeSBarry Smith ierr = PetscObjectOptionsBegin((PetscObject)draw);CHKERRQ(ierr); 3155c6c1daeSBarry Smith ierr = PetscOptionsList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);CHKERRQ(ierr); 3165c6c1daeSBarry Smith if (flg) { 3175c6c1daeSBarry Smith ierr = PetscDrawSetType(draw,vtype);CHKERRQ(ierr); 3185c6c1daeSBarry Smith } else if (!((PetscObject)draw)->type_name) { 3195c6c1daeSBarry Smith ierr = PetscDrawSetType(draw,def);CHKERRQ(ierr); 3205c6c1daeSBarry Smith } 3215c6c1daeSBarry Smith ierr = PetscOptionsName("-nox","Run without graphics","None",&nox);CHKERRQ(ierr); 3225c6c1daeSBarry Smith #if defined(PETSC_HAVE_X) 3235c6c1daeSBarry Smith { 3245c6c1daeSBarry Smith char filename[PETSC_MAX_PATH_LEN]; 3255c6c1daeSBarry Smith PetscBool save,movie = PETSC_FALSE; 3260298fd71SBarry Smith ierr = PetscOptionsBool("-draw_save_movie","Make a movie from the images saved (X Windows only)","PetscDrawSetSave",movie,&movie,NULL);CHKERRQ(ierr); 3275c6c1daeSBarry Smith ierr = PetscOptionsString("-draw_save","Save graphics to file (X Windows only)","PetscDrawSetSave",filename,filename,PETSC_MAX_PATH_LEN,&save);CHKERRQ(ierr); 3285c6c1daeSBarry Smith if (save) { 3295c6c1daeSBarry Smith ierr = PetscDrawSetSave(draw,filename,movie);CHKERRQ(ierr); 3305c6c1daeSBarry Smith } 331a4494fc1SBarry Smith ierr = PetscOptionsBool("-draw_save_on_flush","Save graphics to file (X Windows only) on each flush","PetscDrawSetSave",draw->saveonflush,&draw->saveonflush,NULL);CHKERRQ(ierr); 3325c6c1daeSBarry Smith } 3335c6c1daeSBarry Smith #endif 3347450148dSBarry Smith ierr = PetscOptionsGetReal(NULL,"-draw_pause",&dpause,&flg);CHKERRQ(ierr); 3357450148dSBarry Smith if (flg) draw->pause = dpause; 3365c6c1daeSBarry Smith 3375c6c1daeSBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3385c6c1daeSBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject)draw);CHKERRQ(ierr); 3395c6c1daeSBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 3405c6c1daeSBarry Smith PetscFunctionReturn(0); 3415c6c1daeSBarry Smith } 3425c6c1daeSBarry Smith 3435c6c1daeSBarry Smith #undef __FUNCT__ 3445c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetSave" 3455c6c1daeSBarry Smith /*@C 34699bbeb84SJed Brown PetscDrawSetSave - Saves images produced in a PetscDraw into a file as a Gif file using AfterImage 3475c6c1daeSBarry Smith 3485c6c1daeSBarry Smith Collective on PetscDraw 3495c6c1daeSBarry Smith 3505c6c1daeSBarry Smith Input Parameter: 3515c6c1daeSBarry Smith + draw - the graphics context 3520298fd71SBarry Smith . filename - name of the file, if NULL uses name of draw object 3535c6c1daeSBarry Smith - movie - produce a movie of all the images 3545c6c1daeSBarry Smith 3555c6c1daeSBarry Smith Options Database Command: 3565c6c1daeSBarry Smith + -draw_save <filename> 3575c6c1daeSBarry Smith - -draw_save_movie 3585c6c1daeSBarry Smith 3595c6c1daeSBarry Smith Level: intermediate 3605c6c1daeSBarry Smith 3615c6c1daeSBarry Smith Concepts: X windows^graphics 3625c6c1daeSBarry Smith 3635c6c1daeSBarry Smith Notes: You should call this BEFORE calling PetscDrawClear() and creating your image. 3645c6c1daeSBarry Smith 3655c6c1daeSBarry 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 3665c6c1daeSBarry Smith 3675c6c1daeSBarry Smith If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the 3685c6c1daeSBarry 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 3695c6c1daeSBarry Smith 3705c6c1daeSBarry Smith 37199bbeb84SJed Brown .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy() 3725c6c1daeSBarry Smith @*/ 3735c6c1daeSBarry Smith PetscErrorCode PetscDrawSetSave(PetscDraw draw,const char *filename,PetscBool movie) 3745c6c1daeSBarry Smith { 3755c6c1daeSBarry Smith PetscErrorCode ierr; 3765c6c1daeSBarry Smith 3775c6c1daeSBarry Smith PetscFunctionBegin; 3785c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 3795c6c1daeSBarry Smith ierr = PetscFree(draw->savefilename);CHKERRQ(ierr); 380a297a907SKarl Rupp 3815c6c1daeSBarry Smith draw->savefilemovie = movie; 3825c6c1daeSBarry Smith if (filename && filename[0]) { 3835c6c1daeSBarry Smith ierr = PetscStrallocpy(filename,&draw->savefilename);CHKERRQ(ierr); 3845c6c1daeSBarry Smith } else { 3855c6c1daeSBarry Smith const char *name; 3865c6c1daeSBarry Smith ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr); 3875c6c1daeSBarry Smith ierr = PetscStrallocpy(name,&draw->savefilename);CHKERRQ(ierr); 3885c6c1daeSBarry Smith } 3895c6c1daeSBarry Smith if (draw->ops->setsave) { 3905c6c1daeSBarry Smith ierr = (*draw->ops->setsave)(draw,filename);CHKERRQ(ierr); 3915c6c1daeSBarry Smith } 3925c6c1daeSBarry Smith PetscFunctionReturn(0); 3935c6c1daeSBarry Smith } 394