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*/ 6111ee811SBarry Smith #include <petscviewer.h> /*I "petscviewer.h" I*/ 7111ee811SBarry Smith #if defined(PETSC_HAVE_SAWS) 8111ee811SBarry Smith #include <petscviewersaws.h> 9111ee811SBarry Smith #endif 105c6c1daeSBarry Smith 115c6c1daeSBarry Smith /* 125c6c1daeSBarry Smith Contains the list of registered PetscDraw routines 135c6c1daeSBarry Smith */ 14140e18c1SBarry Smith PetscFunctionList PetscDrawList = 0; 155c6c1daeSBarry Smith 160076e027SBarry Smith #undef __FUNCT__ 170076e027SBarry Smith #define __FUNCT__ "PetscDrawView" 180076e027SBarry Smith /*@C 190076e027SBarry Smith PetscDrawView - Prints the PetscDraw data structure. 200076e027SBarry Smith 210076e027SBarry Smith Collective on PetscDraw 220076e027SBarry Smith 230076e027SBarry Smith Input Parameters: 240076e027SBarry Smith + indraw - the PetscDraw context 250076e027SBarry Smith - viewer - visualization context 260076e027SBarry Smith 27236f5a4dSBarry Smith See PetscDrawSetFromOptions() for options database keys 280076e027SBarry Smith 290076e027SBarry Smith Note: 300076e027SBarry Smith The available visualization contexts include 310076e027SBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 320076e027SBarry Smith - PETSC_VIEWER_STDOUT_WORLD - synchronized standard 330076e027SBarry Smith output where only the first processor opens 340076e027SBarry Smith the file. All other processors send their 350076e027SBarry Smith data to the first processor to print. 360076e027SBarry Smith 370076e027SBarry Smith The user can open an alternative visualization context with 380076e027SBarry Smith PetscViewerASCIIOpen() - output to a specified file. 390076e027SBarry Smith 400076e027SBarry Smith Level: beginner 410076e027SBarry Smith 420076e027SBarry Smith .keywords: PetscDraw, view 430076e027SBarry Smith 440076e027SBarry Smith .seealso: PCView(), PetscViewerASCIIOpen() 450076e027SBarry Smith @*/ 460076e027SBarry Smith PetscErrorCode PetscDrawView(PetscDraw indraw,PetscViewer viewer) 470076e027SBarry Smith { 480076e027SBarry Smith PetscErrorCode ierr; 490076e027SBarry Smith PetscBool isdraw; 50e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 51536b137fSBarry Smith PetscBool issaws; 520076e027SBarry Smith #endif 530076e027SBarry Smith 540076e027SBarry Smith PetscFunctionBegin; 550076e027SBarry Smith PetscValidHeaderSpecific(indraw,PETSC_DRAW_CLASSID,1); 560076e027SBarry Smith if (!viewer) viewer = PETSC_VIEWER_STDOUT_(PetscObjectComm((PetscObject)indraw)); 570076e027SBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 580076e027SBarry Smith PetscCheckSameComm(indraw,1,viewer,2); 590076e027SBarry Smith 6098c3331eSBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)indraw,viewer);CHKERRQ(ierr); 610076e027SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); 62e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 63536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 640076e027SBarry Smith #endif 650076e027SBarry Smith if (isdraw) { 660076e027SBarry Smith PetscDraw draw; 670076e027SBarry Smith char str[36]; 680076e027SBarry Smith PetscReal x,y,bottom,h; 690076e027SBarry Smith 700076e027SBarry Smith ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); 710076e027SBarry Smith ierr = PetscDrawGetCurrentPoint(draw,&x,&y);CHKERRQ(ierr); 720076e027SBarry Smith ierr = PetscStrcpy(str,"PetscDraw: ");CHKERRQ(ierr); 730076e027SBarry Smith ierr = PetscStrcat(str,((PetscObject)indraw)->type_name);CHKERRQ(ierr); 74*51fa3d41SBarry Smith ierr = PetscDrawStringBoxed(draw,x,y,PETSC_DRAW_RED,PETSC_DRAW_BLACK,str,NULL,&h);CHKERRQ(ierr); 750076e027SBarry Smith bottom = y - h; 760076e027SBarry Smith ierr = PetscDrawPushCurrentPoint(draw,x,bottom);CHKERRQ(ierr); 77e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 78536b137fSBarry Smith } else if (issaws) { 79d45a07a7SBarry Smith PetscMPIInt rank; 80d45a07a7SBarry Smith 81d45a07a7SBarry Smith ierr = PetscObjectName((PetscObject)indraw);CHKERRQ(ierr); 82d45a07a7SBarry Smith ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr); 83d45a07a7SBarry Smith if (!((PetscObject)indraw)->amsmem && !rank) { 84e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)indraw,viewer);CHKERRQ(ierr); 850076e027SBarry Smith } 860076e027SBarry Smith #endif 870076e027SBarry Smith } else if (indraw->ops->view) { 880076e027SBarry Smith ierr = (*indraw->ops->view)(indraw,viewer);CHKERRQ(ierr); 890076e027SBarry Smith } 900076e027SBarry Smith PetscFunctionReturn(0); 910076e027SBarry Smith } 920076e027SBarry Smith 935c6c1daeSBarry Smith #undef __FUNCT__ 945c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawCreate" 955c6c1daeSBarry Smith /*@C 965c6c1daeSBarry Smith PetscDrawCreate - Creates a graphics context. 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith Collective on MPI_Comm 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith Input Parameter: 1015c6c1daeSBarry Smith + comm - MPI communicator 1025c6c1daeSBarry Smith . display - X display when using X windows 1035c6c1daeSBarry Smith . title - optional title added to top of window 1045c6c1daeSBarry Smith . x,y - coordinates of lower left corner of window or PETSC_DECIDE 1055c6c1daeSBarry Smith - w, h - width and height of window or PETSC_DECIDE or PETSC_DRAW_HALF_SIZE, PETSC_DRAW_FULL_SIZE, 1065c6c1daeSBarry Smith or PETSC_DRAW_THIRD_SIZE or PETSC_DRAW_QUARTER_SIZE 1075c6c1daeSBarry Smith 1085c6c1daeSBarry Smith Output Parameter: 1095c6c1daeSBarry Smith . draw - location to put the PetscDraw context 1105c6c1daeSBarry Smith 1115c6c1daeSBarry Smith Level: beginner 1125c6c1daeSBarry Smith 1135c6c1daeSBarry Smith Concepts: graphics^creating context 1145c6c1daeSBarry Smith Concepts: drawing^creating context 1155c6c1daeSBarry Smith 1165c6c1daeSBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawDestroy(), PetscDrawSetType() 1175c6c1daeSBarry Smith @*/ 1185c6c1daeSBarry Smith PetscErrorCode PetscDrawCreate(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscDraw *indraw) 1195c6c1daeSBarry Smith { 1205c6c1daeSBarry Smith PetscDraw draw; 1215c6c1daeSBarry Smith PetscErrorCode ierr; 1225c6c1daeSBarry Smith PetscReal dpause; 1235c6c1daeSBarry Smith PetscBool flag; 1245c6c1daeSBarry Smith 1255c6c1daeSBarry Smith PetscFunctionBegin; 126607a6623SBarry Smith ierr = PetscDrawInitializePackage();CHKERRQ(ierr); 1275c6c1daeSBarry Smith *indraw = 0; 1280076e027SBarry Smith ierr = PetscHeaderCreate(draw,_p_PetscDraw,struct _PetscDrawOps,PETSC_DRAW_CLASSID,"Draw","Graphics","Draw",comm,PetscDrawDestroy,PetscDrawView);CHKERRQ(ierr); 129a297a907SKarl Rupp 1305c6c1daeSBarry Smith draw->data = 0; 1315c6c1daeSBarry Smith ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 1325c6c1daeSBarry Smith ierr = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr); 1335c6c1daeSBarry Smith draw->x = x; 1345c6c1daeSBarry Smith draw->y = y; 1355c6c1daeSBarry Smith draw->w = w; 1365c6c1daeSBarry Smith draw->h = h; 1375c6c1daeSBarry Smith draw->pause = 0.0; 1385c6c1daeSBarry Smith draw->coor_xl = 0.0; 1395c6c1daeSBarry Smith draw->coor_xr = 1.0; 1405c6c1daeSBarry Smith draw->coor_yl = 0.0; 1415c6c1daeSBarry Smith draw->coor_yr = 1.0; 1425c6c1daeSBarry Smith draw->port_xl = 0.0; 1435c6c1daeSBarry Smith draw->port_xr = 1.0; 1445c6c1daeSBarry Smith draw->port_yl = 0.0; 1455c6c1daeSBarry Smith draw->port_yr = 1.0; 1465c6c1daeSBarry Smith draw->popup = 0; 147a297a907SKarl Rupp 1480298fd71SBarry Smith ierr = PetscOptionsGetReal(NULL,"-draw_pause",&dpause,&flag);CHKERRQ(ierr); 1495c6c1daeSBarry Smith if (flag) draw->pause = dpause; 1500298fd71SBarry Smith draw->savefilename = NULL; 1515c6c1daeSBarry Smith draw->savefilemovie = PETSC_FALSE; 1525c6c1daeSBarry Smith draw->savefilecount = -1; 153a297a907SKarl Rupp 1545c6c1daeSBarry Smith ierr = PetscDrawSetCurrentPoint(draw,.5,.9);CHKERRQ(ierr); 155a297a907SKarl Rupp 1565c6c1daeSBarry Smith draw->boundbox_xl = .5; 1575c6c1daeSBarry Smith draw->boundbox_xr = .5; 1585c6c1daeSBarry Smith draw->boundbox_yl = .9; 1595c6c1daeSBarry Smith draw->boundbox_yr = .9; 1605c6c1daeSBarry Smith 1615c6c1daeSBarry Smith *indraw = draw; 1625c6c1daeSBarry Smith PetscFunctionReturn(0); 1635c6c1daeSBarry Smith } 1645c6c1daeSBarry Smith 1655c6c1daeSBarry Smith #undef __FUNCT__ 1665c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetType" 1675c6c1daeSBarry Smith /*@C 1685c6c1daeSBarry Smith PetscDrawSetType - Builds graphics object for a particular implementation 1695c6c1daeSBarry Smith 1705c6c1daeSBarry Smith Collective on PetscDraw 1715c6c1daeSBarry Smith 1725c6c1daeSBarry Smith Input Parameter: 1735c6c1daeSBarry Smith + draw - the graphics context 1745c6c1daeSBarry Smith - type - for example, PETSC_DRAW_X 1755c6c1daeSBarry Smith 1765c6c1daeSBarry Smith Options Database Command: 177236f5a4dSBarry Smith . -draw_type <type> - Sets the type; use -help for a list of available methods (for instance, x) 178236f5a4dSBarry Smith 179236f5a4dSBarry Smith See PetscDrawSetFromOptions for additional options database keys 1805c6c1daeSBarry Smith 1815c6c1daeSBarry Smith Level: intermediate 1825c6c1daeSBarry Smith 1835c6c1daeSBarry Smith Notes: 1845c6c1daeSBarry Smith See "petsc/include/petscdraw.h" for available methods (for instance, 1855c6c1daeSBarry Smith PETSC_DRAW_X) 1865c6c1daeSBarry Smith 1875c6c1daeSBarry Smith Concepts: drawing^X windows 1885c6c1daeSBarry Smith Concepts: X windows^graphics 1895c6c1daeSBarry Smith Concepts: drawing^Microsoft Windows 1905c6c1daeSBarry Smith 1915c6c1daeSBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy() 1925c6c1daeSBarry Smith @*/ 1935c6c1daeSBarry Smith PetscErrorCode PetscDrawSetType(PetscDraw draw,PetscDrawType type) 1945c6c1daeSBarry Smith { 1955c6c1daeSBarry Smith PetscErrorCode ierr,(*r)(PetscDraw); 1965c6c1daeSBarry Smith PetscBool match; 1975c6c1daeSBarry Smith PetscBool flg=PETSC_FALSE; 1985c6c1daeSBarry Smith 1995c6c1daeSBarry Smith PetscFunctionBegin; 2005c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 2015c6c1daeSBarry Smith PetscValidCharPointer(type,2); 2025c6c1daeSBarry Smith 2035c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)draw,type,&match);CHKERRQ(ierr); 2045c6c1daeSBarry Smith if (match) PetscFunctionReturn(0); 2055c6c1daeSBarry Smith 2065c6c1daeSBarry Smith /* User requests no graphics */ 2070298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox",&flg);CHKERRQ(ierr); 2085c6c1daeSBarry Smith 2095c6c1daeSBarry Smith /* 2105c6c1daeSBarry Smith This is not ideal, but it allows codes to continue to run if X graphics 2115c6c1daeSBarry Smith was requested but is not installed on this machine. Mostly this is for 2125c6c1daeSBarry Smith testing. 2135c6c1daeSBarry Smith */ 2145c6c1daeSBarry Smith #if !defined(PETSC_HAVE_X) 2155c6c1daeSBarry Smith if (!flg) { 2165c6c1daeSBarry Smith ierr = PetscStrcmp(type,PETSC_DRAW_X,&match);CHKERRQ(ierr); 2175c6c1daeSBarry Smith if (match) { 2185c6c1daeSBarry Smith PetscBool dontwarn = PETSC_TRUE; 2195c6c1daeSBarry Smith flg = PETSC_TRUE; 2200298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox_warning",&dontwarn);CHKERRQ(ierr); 221a297a907SKarl Rupp if (!dontwarn) (*PetscErrorPrintf)("PETSc installed without X windows on this machine\nproceeding without graphics\n"); 2225c6c1daeSBarry Smith } 2235c6c1daeSBarry Smith } 2245c6c1daeSBarry Smith #endif 225a297a907SKarl Rupp if (flg) type = PETSC_DRAW_NULL; 2265c6c1daeSBarry Smith 2271c9cd337SJed Brown ierr = PetscFunctionListFind(PetscDrawList,type,&r);CHKERRQ(ierr); 2285c6c1daeSBarry Smith if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscDraw type given: %s",type); 22969c83917SLisandro Dalcin if (draw->data) {ierr = (*draw->ops->destroy)(draw);CHKERRQ(ierr);} 23069c83917SLisandro Dalcin draw->ops->destroy = NULL; 23169c83917SLisandro Dalcin draw->data = NULL; 2325c6c1daeSBarry Smith ierr = PetscObjectChangeTypeName((PetscObject)draw,type);CHKERRQ(ierr); 2335c6c1daeSBarry Smith ierr = (*r)(draw);CHKERRQ(ierr); 2345c6c1daeSBarry Smith PetscFunctionReturn(0); 2355c6c1daeSBarry Smith } 2365c6c1daeSBarry Smith 2375c6c1daeSBarry Smith #undef __FUNCT__ 2385c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawGetType" 2395c6c1daeSBarry Smith /*@C 2405c6c1daeSBarry Smith PetscDrawGetType - Gets the PetscDraw type as a string from the PetscDraw object. 2415c6c1daeSBarry Smith 2425c6c1daeSBarry Smith Not Collective 2435c6c1daeSBarry Smith 2445c6c1daeSBarry Smith Input Parameter: 2455c6c1daeSBarry Smith . draw - Krylov context 2465c6c1daeSBarry Smith 2475c6c1daeSBarry Smith Output Parameters: 2485c6c1daeSBarry Smith . name - name of PetscDraw method 2495c6c1daeSBarry Smith 2505c6c1daeSBarry Smith Level: advanced 2515c6c1daeSBarry Smith 2525c6c1daeSBarry Smith @*/ 2535c6c1daeSBarry Smith PetscErrorCode PetscDrawGetType(PetscDraw draw,PetscDrawType *type) 2545c6c1daeSBarry Smith { 2555c6c1daeSBarry Smith PetscFunctionBegin; 2565c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 2575c6c1daeSBarry Smith PetscValidPointer(type,2); 2585c6c1daeSBarry Smith *type = ((PetscObject)draw)->type_name; 2595c6c1daeSBarry Smith PetscFunctionReturn(0); 2605c6c1daeSBarry Smith } 2615c6c1daeSBarry Smith 2625c6c1daeSBarry Smith #undef __FUNCT__ 2635c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawRegister" 264607a6623SBarry Smith /*@C 2651c84c290SBarry Smith PetscDrawRegister - Adds a method to the graphics package. 2661c84c290SBarry Smith 2671c84c290SBarry Smith Not Collective 2681c84c290SBarry Smith 2691c84c290SBarry Smith Input Parameters: 2700076e027SBarry Smith + name_solver - name of a new user-defined graphics class 2711c84c290SBarry Smith - routine_create - routine to create method context 2721c84c290SBarry Smith 2731c84c290SBarry Smith Level: developer 2741c84c290SBarry Smith 2751c84c290SBarry Smith Notes: 2760076e027SBarry Smith PetscDrawRegister() may be called multiple times to add several user-defined graphics classes 2771c84c290SBarry Smith 2781c84c290SBarry Smith Sample usage: 2791c84c290SBarry Smith .vb 280bdf89e91SBarry Smith PetscDrawRegister("my_draw_type", MyDrawCreate); 2811c84c290SBarry Smith .ve 2821c84c290SBarry Smith 2830076e027SBarry Smith Then, your specific graphics package can be chosen with the procedural interface via 2841c84c290SBarry Smith $ PetscDrawSetType(ksp,"my_draw_type") 2851c84c290SBarry Smith or at runtime via the option 2861c84c290SBarry Smith $ -draw_type my_draw_type 2871c84c290SBarry Smith 2881c84c290SBarry Smith Concepts: graphics^registering new draw classes 2891c84c290SBarry Smith Concepts: PetscDraw^registering new draw classes 2901c84c290SBarry Smith 2911c84c290SBarry Smith .seealso: PetscDrawRegisterAll(), PetscDrawRegisterDestroy() 2921c84c290SBarry Smith @*/ 293bdf89e91SBarry Smith PetscErrorCode PetscDrawRegister(const char *sname,PetscErrorCode (*function)(PetscDraw)) 2945c6c1daeSBarry Smith { 2955c6c1daeSBarry Smith PetscErrorCode ierr; 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith PetscFunctionBegin; 298a240a19fSJed Brown ierr = PetscFunctionListAdd(&PetscDrawList,sname,function);CHKERRQ(ierr); 2995c6c1daeSBarry Smith PetscFunctionReturn(0); 3005c6c1daeSBarry Smith } 3015c6c1daeSBarry Smith 3025c6c1daeSBarry Smith #undef __FUNCT__ 3035c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetFromOptions" 3045c6c1daeSBarry Smith /*@ 3055c6c1daeSBarry Smith PetscDrawSetFromOptions - Sets the graphics type from the options database. 3065c6c1daeSBarry Smith Defaults to a PETSc X windows graphics. 3075c6c1daeSBarry Smith 3085c6c1daeSBarry Smith Collective on PetscDraw 3095c6c1daeSBarry Smith 3105c6c1daeSBarry Smith Input Parameter: 3115c6c1daeSBarry Smith . draw - the graphics context 3125c6c1daeSBarry Smith 3135c6c1daeSBarry Smith Options Database Keys: 3145c6c1daeSBarry Smith + -nox - do not use X graphics (ignore graphics calls, but run program correctly) 3151cda70a7SBarry Smith . -nox_warning - when X windows support is not installed this prevents the warning message from being printed 3167450148dSBarry Smith . -draw_pause <pause amount> -- -1 indicates wait for mouse input, -2 indicates pause when window is to be destroyed 3175c6c1daeSBarry Smith . -draw_save [optional filename] - (X windows only) saves each image before it is cleared to a file 318287de1a7SBarry Smith . -draw_save_final_image [optional filename] - (X windows only) saves the final image displayed in a window 319a4494fc1SBarry Smith . -draw_save_movie - converts image files to a movie at the end of the run. See PetscDrawSetSave() 3208b7fcac6SBarry Smith . -draw_save_on_flush - saves an image on each flush in addition to each clear 3218b7fcac6SBarry Smith - -draw_save_single_file - saves each new image in the same file, normally each new image is saved in a new file with filename_%d 3225c6c1daeSBarry Smith 3235c6c1daeSBarry Smith Level: intermediate 3245c6c1daeSBarry Smith 3255c6c1daeSBarry Smith Notes: 32699749f0dSBarry Smith Must be called after PetscDrawCreate() before the PetscDraw is used. 3275c6c1daeSBarry Smith 3285c6c1daeSBarry Smith Concepts: drawing^setting options 3295c6c1daeSBarry Smith Concepts: graphics^setting options 3305c6c1daeSBarry Smith 331287de1a7SBarry Smith .seealso: PetscDrawCreate(), PetscDrawSetType(), PetscDrawSetSave(), PetscDrawSetSaveFinalImage() 3325c6c1daeSBarry Smith 3335c6c1daeSBarry Smith @*/ 3345c6c1daeSBarry Smith PetscErrorCode PetscDrawSetFromOptions(PetscDraw draw) 3355c6c1daeSBarry Smith { 3365c6c1daeSBarry Smith PetscErrorCode ierr; 3375c6c1daeSBarry Smith PetscBool flg,nox; 3385c6c1daeSBarry Smith char vtype[256]; 3395c6c1daeSBarry Smith const char *def; 3407450148dSBarry Smith PetscReal dpause; 3415c6c1daeSBarry Smith #if !defined(PETSC_USE_WINDOWS_GRAPHICS) && !defined(PETSC_HAVE_X) 3425c6c1daeSBarry Smith PetscBool warn; 3435c6c1daeSBarry Smith #endif 3445c6c1daeSBarry Smith 3455c6c1daeSBarry Smith PetscFunctionBegin; 3465c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 3475c6c1daeSBarry Smith 3485c6c1daeSBarry Smith if (!PetscDrawList) { 349607a6623SBarry Smith ierr = PetscDrawRegisterAll();CHKERRQ(ierr); 3505c6c1daeSBarry Smith } 3515c6c1daeSBarry Smith 352a297a907SKarl Rupp if (((PetscObject)draw)->type_name) def = ((PetscObject)draw)->type_name; 353a297a907SKarl Rupp else { 3540298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox",&nox);CHKERRQ(ierr); 3555c6c1daeSBarry Smith def = PETSC_DRAW_NULL; 3565c6c1daeSBarry Smith #if defined(PETSC_USE_WINDOWS_GRAPHICS) 3575c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_WIN32; 3585c6c1daeSBarry Smith #elif defined(PETSC_HAVE_X) 3595c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_X; 3605c6c1daeSBarry Smith #elif defined(PETSC_HAVE_GLUT) 3615c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_GLUT; 3625c6c1daeSBarry Smith #elif defined(PETSC_HAVE_OPENGLES) 3635c6c1daeSBarry Smith if (!nox) def = PETSC_DRAW_OPENGLES; 3645c6c1daeSBarry Smith #else 3650298fd71SBarry Smith ierr = PetscOptionsHasName(NULL,"-nox_warning",&warn);CHKERRQ(ierr); 366a297a907SKarl Rupp if (!nox && !warn) (*PetscErrorPrintf)("PETSc installed without X windows, Microsoft Graphics, OpenGL ES, or GLUT/OpenGL on this machine\nproceeding without graphics\n"); 3675c6c1daeSBarry Smith #endif 3685c6c1daeSBarry Smith } 3695c6c1daeSBarry Smith ierr = PetscObjectOptionsBegin((PetscObject)draw);CHKERRQ(ierr); 370a264d7a6SBarry Smith ierr = PetscOptionsFList("-draw_type","Type of graphical output","PetscDrawSetType",PetscDrawList,def,vtype,256,&flg);CHKERRQ(ierr); 3715c6c1daeSBarry Smith if (flg) { 3725c6c1daeSBarry Smith ierr = PetscDrawSetType(draw,vtype);CHKERRQ(ierr); 3735c6c1daeSBarry Smith } else if (!((PetscObject)draw)->type_name) { 3745c6c1daeSBarry Smith ierr = PetscDrawSetType(draw,def);CHKERRQ(ierr); 3755c6c1daeSBarry Smith } 3765c6c1daeSBarry Smith ierr = PetscOptionsName("-nox","Run without graphics","None",&nox);CHKERRQ(ierr); 3775c6c1daeSBarry Smith #if defined(PETSC_HAVE_X) 3785c6c1daeSBarry Smith { 3795c6c1daeSBarry Smith char filename[PETSC_MAX_PATH_LEN]; 3805c6c1daeSBarry Smith PetscBool save,movie = PETSC_FALSE; 3810298fd71SBarry Smith ierr = PetscOptionsBool("-draw_save_movie","Make a movie from the images saved (X Windows only)","PetscDrawSetSave",movie,&movie,NULL);CHKERRQ(ierr); 3828b7fcac6SBarry Smith ierr = PetscOptionsBool("-draw_save_single_file","Each new image replaces previous image in file","PetscDrawSetSave",draw->savesinglefile,&draw->savesinglefile,NULL);CHKERRQ(ierr); 3835c6c1daeSBarry Smith ierr = PetscOptionsString("-draw_save","Save graphics to file (X Windows only)","PetscDrawSetSave",filename,filename,PETSC_MAX_PATH_LEN,&save);CHKERRQ(ierr); 3845c6c1daeSBarry Smith if (save) { 3855c6c1daeSBarry Smith ierr = PetscDrawSetSave(draw,filename,movie);CHKERRQ(ierr); 3865c6c1daeSBarry Smith } 387287de1a7SBarry Smith ierr = PetscOptionsString("-draw_save_final_image","Save graphics to file (X Windows only)","PetscDrawSetSaveFinalImage",filename,filename,PETSC_MAX_PATH_LEN,&save);CHKERRQ(ierr); 388287de1a7SBarry Smith if (save) { 389287de1a7SBarry Smith ierr = PetscDrawSetSaveFinalImage(draw,filename);CHKERRQ(ierr); 390287de1a7SBarry Smith } 391a4494fc1SBarry 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); 3925c6c1daeSBarry Smith } 3935c6c1daeSBarry Smith #endif 3947450148dSBarry Smith ierr = PetscOptionsGetReal(NULL,"-draw_pause",&dpause,&flg);CHKERRQ(ierr); 3957450148dSBarry Smith if (flg) draw->pause = dpause; 3965c6c1daeSBarry Smith 3975c6c1daeSBarry Smith /* process any options handlers added with PetscObjectAddOptionsHandler() */ 3985c6c1daeSBarry Smith ierr = PetscObjectProcessOptionsHandlers((PetscObject)draw);CHKERRQ(ierr); 399ce1779c8SBarry Smith 400ce1779c8SBarry Smith ierr = PetscDrawViewFromOptions(draw,NULL,"-draw_view");CHKERRQ(ierr); 4015c6c1daeSBarry Smith ierr = PetscOptionsEnd();CHKERRQ(ierr); 4025c6c1daeSBarry Smith PetscFunctionReturn(0); 4035c6c1daeSBarry Smith } 4045c6c1daeSBarry Smith 4055c6c1daeSBarry Smith #undef __FUNCT__ 4065c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetSave" 4075c6c1daeSBarry Smith /*@C 40899bbeb84SJed Brown PetscDrawSetSave - Saves images produced in a PetscDraw into a file as a Gif file using AfterImage 4095c6c1daeSBarry Smith 4105c6c1daeSBarry Smith Collective on PetscDraw 4115c6c1daeSBarry Smith 4125c6c1daeSBarry Smith Input Parameter: 4135c6c1daeSBarry Smith + draw - the graphics context 41476f01e85SBarry Smith . filename - name of the file, if .ext then uses name of draw object plus .ext using .ext to determine the image type, if NULL use .Gif image type 4155c6c1daeSBarry Smith - movie - produce a movie of all the images 4165c6c1daeSBarry Smith 4175c6c1daeSBarry Smith Options Database Command: 41876f01e85SBarry Smith + -draw_save <filename> - filename could be name.ext or .ext (where .ext determines the type of graphics file to save, for example .Gif) 419236f5a4dSBarry Smith . -draw_save_movie 420236f5a4dSBarry Smith . -draw_save_final_image [optional filename] - (X windows only) saves the final image displayed in a window 421236f5a4dSBarry Smith . -draw_save_on_flush - saves an image on each flush in addition to each clear 422236f5a4dSBarry Smith - -draw_save_single_file - saves each new image in the same file, normally each new image is saved in a new file with filename_%d 4235c6c1daeSBarry Smith 4245c6c1daeSBarry Smith Level: intermediate 4255c6c1daeSBarry Smith 4265c6c1daeSBarry Smith Concepts: X windows^graphics 4275c6c1daeSBarry Smith 4285c6c1daeSBarry Smith Notes: You should call this BEFORE calling PetscDrawClear() and creating your image. 4295c6c1daeSBarry Smith 4305c6c1daeSBarry 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 4315c6c1daeSBarry Smith 43276f01e85SBarry Smith The .ext formats that are supported depend on what formats AfterImage was configured with; on the Apple Mac both .Gif and .Jpeg are supported. 43376f01e85SBarry Smith 4345c6c1daeSBarry Smith If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the 4355c6c1daeSBarry 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 4365c6c1daeSBarry Smith 4375c6c1daeSBarry Smith 438287de1a7SBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSetSaveFinalImage() 4395c6c1daeSBarry Smith @*/ 4405c6c1daeSBarry Smith PetscErrorCode PetscDrawSetSave(PetscDraw draw,const char *filename,PetscBool movie) 4415c6c1daeSBarry Smith { 4425c6c1daeSBarry Smith PetscErrorCode ierr; 44376f01e85SBarry Smith char *ext; 4445c6c1daeSBarry Smith 4455c6c1daeSBarry Smith PetscFunctionBegin; 4465c6c1daeSBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 4475c6c1daeSBarry Smith ierr = PetscFree(draw->savefilename);CHKERRQ(ierr); 448a297a907SKarl Rupp 44976f01e85SBarry Smith /* determine extension of filename */ 45076f01e85SBarry Smith if (filename && filename[0]) { 45176f01e85SBarry Smith ierr = PetscStrchr(filename,'.',&ext);CHKERRQ(ierr); 45276f01e85SBarry Smith if (!ext) SETERRQ1(PetscObjectComm((PetscObject)draw),PETSC_ERR_ARG_INCOMP,"Filename %s should end with graphics extension (for example .Gif)",filename); 45376f01e85SBarry Smith } else { 45476f01e85SBarry Smith ext = (char *)".Gif"; 45576f01e85SBarry Smith } 45676f01e85SBarry Smith if (ext == filename) filename = NULL; 45776f01e85SBarry Smith ierr = PetscStrallocpy(ext,&draw->savefilenameext);CHKERRQ(ierr); 45876f01e85SBarry Smith 4595c6c1daeSBarry Smith draw->savefilemovie = movie; 4605c6c1daeSBarry Smith if (filename && filename[0]) { 46176f01e85SBarry Smith size_t l1,l2; 46276f01e85SBarry Smith ierr = PetscStrlen(filename,&l1);CHKERRQ(ierr); 46376f01e85SBarry Smith ierr = PetscStrlen(ext,&l2);CHKERRQ(ierr); 46476f01e85SBarry Smith ierr = PetscMalloc1(l1-l2+1,&draw->savefilename);CHKERRQ(ierr); 46576f01e85SBarry Smith ierr = PetscStrncpy(draw->savefilename,filename,l1-l2+1);CHKERRQ(ierr); 4665c6c1daeSBarry Smith } else { 4675c6c1daeSBarry Smith const char *name; 46876f01e85SBarry Smith 4695c6c1daeSBarry Smith ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr); 4705c6c1daeSBarry Smith ierr = PetscStrallocpy(name,&draw->savefilename);CHKERRQ(ierr); 4715c6c1daeSBarry Smith } 47276f01e85SBarry Smith ierr = PetscInfo2(NULL,"Will save images to file %s%s\n",draw->savefilename,draw->savefilenameext);CHKERRQ(ierr); 4735c6c1daeSBarry Smith if (draw->ops->setsave) { 474287de1a7SBarry Smith ierr = (*draw->ops->setsave)(draw,draw->savefilename);CHKERRQ(ierr); 475287de1a7SBarry Smith } 476287de1a7SBarry Smith PetscFunctionReturn(0); 477287de1a7SBarry Smith } 478287de1a7SBarry Smith 479287de1a7SBarry Smith #undef __FUNCT__ 480287de1a7SBarry Smith #define __FUNCT__ "PetscDrawSetSaveFinalImage" 481287de1a7SBarry Smith /*@C 482287de1a7SBarry Smith PetscDrawSetSaveFinalImage - Saves the finale image produced in a PetscDraw into a file as a Gif file using AfterImage 483287de1a7SBarry Smith 484287de1a7SBarry Smith Collective on PetscDraw 485287de1a7SBarry Smith 486287de1a7SBarry Smith Input Parameter: 487287de1a7SBarry Smith + draw - the graphics context 488287de1a7SBarry Smith - filename - name of the file, if NULL uses name of draw object 489287de1a7SBarry Smith 490287de1a7SBarry Smith Options Database Command: 491287de1a7SBarry Smith . -draw_save_final_image <filename> 492287de1a7SBarry Smith 493287de1a7SBarry Smith Level: intermediate 494287de1a7SBarry Smith 495287de1a7SBarry Smith Concepts: X windows^graphics 496287de1a7SBarry Smith 497287de1a7SBarry Smith Notes: You should call this BEFORE calling PetscDrawClear() and creating your image. 498287de1a7SBarry Smith 499287de1a7SBarry 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 500287de1a7SBarry Smith 501287de1a7SBarry Smith If X windows generates an error message about X_CreateWindow() failing then Afterimage was installed without X windows. Reinstall Afterimage using the 502287de1a7SBarry 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 503287de1a7SBarry Smith 504287de1a7SBarry Smith 505287de1a7SBarry Smith .seealso: PetscDrawSetFromOptions(), PetscDrawCreate(), PetscDrawDestroy(), PetscDrawSetSave() 506287de1a7SBarry Smith @*/ 507287de1a7SBarry Smith PetscErrorCode PetscDrawSetSaveFinalImage(PetscDraw draw,const char *filename) 508287de1a7SBarry Smith { 509287de1a7SBarry Smith PetscErrorCode ierr; 510287de1a7SBarry Smith 511287de1a7SBarry Smith PetscFunctionBegin; 512287de1a7SBarry Smith PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 513287de1a7SBarry Smith ierr = PetscFree(draw->savefinalfilename);CHKERRQ(ierr); 514287de1a7SBarry Smith 515287de1a7SBarry Smith if (filename && filename[0]) { 516287de1a7SBarry Smith ierr = PetscStrallocpy(filename,&draw->savefinalfilename);CHKERRQ(ierr); 517287de1a7SBarry Smith } else { 518287de1a7SBarry Smith const char *name; 519287de1a7SBarry Smith ierr = PetscObjectGetName((PetscObject)draw,&name);CHKERRQ(ierr); 520287de1a7SBarry Smith ierr = PetscStrallocpy(name,&draw->savefinalfilename);CHKERRQ(ierr); 5215c6c1daeSBarry Smith } 5225c6c1daeSBarry Smith PetscFunctionReturn(0); 5235c6c1daeSBarry Smith } 524