1 2 /* 3 Provides the calling sequences for all the basic PetscDraw routines. 4 */ 5 #include <petsc-private/drawimpl.h> /*I "petscdraw.h" I*/ 6 7 PetscClassId PETSC_DRAW_CLASSID; 8 9 static PetscBool PetscDrawPackageInitialized = PETSC_FALSE; 10 #undef __FUNCT__ 11 #define __FUNCT__ "PetscDrawFinalizePackage" 12 /*@C 13 PetscDrawFinalizePackage - This function destroys everything in the Petsc interface to the Draw package. It is 14 called from PetscFinalize(). 15 16 Level: developer 17 18 .keywords: Petsc, destroy, package, mathematica 19 .seealso: PetscFinalize() 20 @*/ 21 PetscErrorCode PetscDrawFinalizePackage(void) 22 { 23 PetscFunctionBegin; 24 PetscDrawPackageInitialized = PETSC_FALSE; 25 PetscDrawList = 0; 26 PetscFunctionReturn(0); 27 } 28 29 #undef __FUNCT__ 30 #define __FUNCT__ "PetscDrawInitializePackage" 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. 35 36 Input Parameter: 37 path - The dynamic library path, or PETSC_NULL 38 39 Level: developer 40 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; 50 51 PetscFunctionBegin; 52 if (PetscDrawPackageInitialized) PetscFunctionReturn(0); 53 PetscDrawPackageInitialized = PETSC_TRUE; 54 /* Register Classes */ 55 ierr = PetscClassIdRegister("Draw",&PETSC_DRAW_CLASSID);CHKERRQ(ierr); 56 ierr = PetscClassIdRegister("Axis",&PETSC_DRAWAXIS_CLASSID);CHKERRQ(ierr); 57 ierr = PetscClassIdRegister("Line Graph",&PETSC_DRAWLG_CLASSID);CHKERRQ(ierr); 58 ierr = PetscClassIdRegister("Histogram",&PETSC_DRAWHG_CLASSID);CHKERRQ(ierr); 59 ierr = PetscClassIdRegister("Scatter Plot",&PETSC_DRAWSP_CLASSID);CHKERRQ(ierr); 60 /* Register Constructors */ 61 ierr = PetscDrawRegisterAll(path);CHKERRQ(ierr); 62 /* Process info exclusions */ 63 ierr = PetscOptionsGetString(PETSC_NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 64 if (opt) { 65 ierr = PetscStrstr(logList, "draw", &className);CHKERRQ(ierr); 66 if (className) { 67 ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr); 68 } 69 } 70 /* Process summary exclusions */ 71 ierr = PetscOptionsGetString(PETSC_NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 72 if (opt) { 73 ierr = PetscStrstr(logList, "draw", &className);CHKERRQ(ierr); 74 if (className) { 75 ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr); 76 } 77 } 78 ierr = PetscRegisterFinalize(PetscDrawFinalizePackage);CHKERRQ(ierr); 79 PetscFunctionReturn(0); 80 } 81 82 #undef __FUNCT__ 83 #define __FUNCT__ "PetscDrawResizeWindow" 84 /*@ 85 PetscDrawResizeWindow - Allows one to resize a window from a program. 86 87 Collective on PetscDraw 88 89 Input Parameter: 90 + draw - the window 91 - w,h - the new width and height of the window 92 93 Level: intermediate 94 95 .seealso: PetscDrawCheckResizedWindow() 96 @*/ 97 PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h) 98 { 99 PetscErrorCode ierr; 100 PetscFunctionBegin; 101 if (draw->ops->resizewindow) { 102 ierr = (*draw->ops->resizewindow)(draw,w,h);CHKERRQ(ierr); 103 } 104 PetscFunctionReturn(0); 105 } 106 107 #undef __FUNCT__ 108 #define __FUNCT__ "PetscDrawCheckResizedWindow" 109 /*@ 110 PetscDrawCheckResizedWindow - Checks if the user has resized the window. 111 112 Collective on PetscDraw 113 114 Input Parameter: 115 . draw - the window 116 117 Level: advanced 118 119 .seealso: PetscDrawResizeWindow() 120 121 @*/ 122 PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw) 123 { 124 PetscErrorCode ierr; 125 PetscFunctionBegin; 126 if (draw->ops->checkresizedwindow) { 127 ierr = (*draw->ops->checkresizedwindow)(draw);CHKERRQ(ierr); 128 } 129 PetscFunctionReturn(0); 130 } 131 132 #undef __FUNCT__ 133 #define __FUNCT__ "PetscDrawGetTitle" 134 /*@C 135 PetscDrawGetTitle - Gets pointer to title of a PetscDraw context. 136 137 Not collective 138 139 Input Parameter: 140 . draw - the graphics context 141 142 Output Parameter: 143 . title - the title 144 145 Level: intermediate 146 147 .seealso: PetscDrawSetTitle() 148 @*/ 149 PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title) 150 { 151 PetscFunctionBegin; 152 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 153 PetscValidPointer(title,2); 154 *title = draw->title; 155 PetscFunctionReturn(0); 156 } 157 158 #undef __FUNCT__ 159 #define __FUNCT__ "PetscDrawSetTitle" 160 /*@C 161 PetscDrawSetTitle - Sets the title of a PetscDraw context. 162 163 Not collective (any processor or all may call this) 164 165 Input Parameters: 166 + draw - the graphics context 167 - title - the title 168 169 Level: intermediate 170 171 Note: 172 A copy of the string is made, so you may destroy the 173 title string after calling this routine. 174 175 .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle() 176 @*/ 177 PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[]) 178 { 179 PetscErrorCode ierr; 180 PetscFunctionBegin; 181 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 182 PetscValidCharPointer(title,2); 183 ierr = PetscFree(draw->title);CHKERRQ(ierr); 184 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 185 if (draw->ops->settitle) { 186 ierr = (*draw->ops->settitle)(draw,title);CHKERRQ(ierr); 187 } 188 PetscFunctionReturn(0); 189 } 190 191 #undef __FUNCT__ 192 #define __FUNCT__ "PetscDrawAppendTitle" 193 /*@C 194 PetscDrawAppendTitle - Appends to the title of a PetscDraw context. 195 196 Not collective (any processor or all can call this) 197 198 Input Parameters: 199 + draw - the graphics context 200 - title - the title 201 202 Note: 203 A copy of the string is made, so you may destroy the 204 title string after calling this routine. 205 206 Level: advanced 207 208 .seealso: PetscDrawSetTitle(), PetscDrawGetTitle() 209 @*/ 210 PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[]) 211 { 212 PetscErrorCode ierr; 213 size_t len1,len2,len; 214 char *newtitle; 215 216 PetscFunctionBegin; 217 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 218 if (!title) PetscFunctionReturn(0); 219 220 if (draw->title) { 221 ierr = PetscStrlen(title,&len1);CHKERRQ(ierr); 222 ierr = PetscStrlen(draw->title,&len2);CHKERRQ(ierr); 223 len = len1 + len2; 224 ierr = PetscMalloc((len + 1)*sizeof(char*),&newtitle);CHKERRQ(ierr); 225 ierr = PetscStrcpy(newtitle,draw->title);CHKERRQ(ierr); 226 ierr = PetscStrcat(newtitle,title);CHKERRQ(ierr); 227 ierr = PetscFree(draw->title);CHKERRQ(ierr); 228 draw->title = newtitle; 229 } else { 230 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 231 } 232 if (draw->ops->settitle) { 233 ierr = (*draw->ops->settitle)(draw,draw->title);CHKERRQ(ierr); 234 } 235 PetscFunctionReturn(0); 236 } 237 238 #undef __FUNCT__ 239 #define __FUNCT__ "PetscDrawDestroy" 240 /*@ 241 PetscDrawDestroy - Deletes a draw context. 242 243 Collective on PetscDraw 244 245 Input Parameters: 246 . draw - the drawing context 247 248 Level: beginner 249 250 .seealso: PetscDrawCreate() 251 252 @*/ 253 PetscErrorCode PetscDrawDestroy(PetscDraw *draw) 254 { 255 PetscErrorCode ierr; 256 PetscFunctionBegin; 257 if (!*draw) PetscFunctionReturn(0); 258 PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,1); 259 if (--((PetscObject)(*draw))->refct > 0) PetscFunctionReturn(0); 260 261 if ((*draw)->pause == -2) { 262 (*draw)->pause = -1; 263 ierr = PetscDrawPause(*draw);CHKERRQ(ierr); 264 } 265 266 /* if memory was published then destroy it */ 267 ierr = PetscObjectDepublish(*draw);CHKERRQ(ierr); 268 269 if ((*draw)->ops->destroy) { 270 ierr = (*(*draw)->ops->destroy)(*draw);CHKERRQ(ierr); 271 } 272 ierr = PetscFree((*draw)->title);CHKERRQ(ierr); 273 ierr = PetscFree((*draw)->display);CHKERRQ(ierr); 274 ierr = PetscFree((*draw)->savefilename);CHKERRQ(ierr); 275 ierr = PetscHeaderDestroy(draw);CHKERRQ(ierr); 276 PetscFunctionReturn(0); 277 } 278 279 #undef __FUNCT__ 280 #define __FUNCT__ "PetscDrawGetPopup" 281 /*@ 282 PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window. 283 284 Collective on PetscDraw 285 286 Input Parameter: 287 . draw - the original window 288 289 Output Parameter: 290 . popup - the new popup window 291 292 Level: advanced 293 294 @*/ 295 PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup) 296 { 297 PetscErrorCode ierr; 298 PetscFunctionBegin; 299 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 300 PetscValidPointer(popup,2); 301 302 if (draw->popup) { 303 *popup = draw->popup; 304 } else if (draw->ops->getpopup) { 305 ierr = (*draw->ops->getpopup)(draw,popup);CHKERRQ(ierr); 306 } else { 307 *popup = PETSC_NULL; 308 } 309 PetscFunctionReturn(0); 310 } 311 312 #undef __FUNCT__ 313 #define __FUNCT__ "PetscDrawDestroy_Null" 314 PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw) 315 { 316 PetscFunctionBegin; 317 PetscFunctionReturn(0); 318 } 319 320 #undef __FUNCT__ 321 #define __FUNCT__ "PetscDrawOpenNull" 322 /* 323 PetscDrawOpenNull - Opens a null drawing context. All draw commands to 324 it are ignored. 325 326 Output Parameter: 327 . win - the drawing context 328 329 Level: advanced 330 331 */ 332 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win) 333 { 334 PetscErrorCode ierr; 335 336 PetscFunctionBegin; 337 ierr = PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);CHKERRQ(ierr); 338 ierr = PetscDrawSetType(*win,PETSC_DRAW_NULL);CHKERRQ(ierr); 339 PetscFunctionReturn(0); 340 } 341 342 #undef __FUNCT__ 343 #define __FUNCT__ "PetscDrawSetDisplay" 344 /*@ 345 PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed 346 347 Input Parameter: 348 + draw - the drawing context 349 - display - the X windows display 350 351 Level: advanced 352 353 @*/ 354 PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,const char display[]) 355 { 356 PetscErrorCode ierr; 357 358 PetscFunctionBegin; 359 ierr = PetscFree(draw->display);CHKERRQ(ierr); 360 ierr = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr); 361 PetscFunctionReturn(0); 362 } 363 364 EXTERN_C_BEGIN 365 #undef __FUNCT__ 366 #define __FUNCT__ "PetscDrawCreate_Null" 367 /* 368 PetscDrawCreate_Null - Opens a null drawing context. All draw commands to 369 it are ignored. 370 371 Input Parameter: 372 . win - the drawing context 373 */ 374 PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) 375 { 376 PetscErrorCode ierr; 377 378 PetscFunctionBegin; 379 ierr = PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));CHKERRQ(ierr); 380 draw->ops->destroy = PetscDrawDestroy_Null; 381 draw->ops->view = 0; 382 draw->pause = 0.0; 383 draw->coor_xl = 0.0; draw->coor_xr = 1.0; 384 draw->coor_yl = 0.0; draw->coor_yr = 1.0; 385 draw->port_xl = 0.0; draw->port_xr = 1.0; 386 draw->port_yl = 0.0; draw->port_yr = 1.0; 387 draw->popup = 0; 388 389 PetscFunctionReturn(0); 390 } 391 EXTERN_C_END 392 393 #undef __FUNCT__ 394 #define __FUNCT__ "PetscDrawGetSingleton" 395 /*@C 396 PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned 397 by the one process. 398 399 Collective on PetscDraw 400 401 Input Parameter: 402 . draw - the original window 403 404 Output Parameter: 405 . sdraw - the singleton window 406 407 Level: advanced 408 409 .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton() 410 411 @*/ 412 PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw) 413 { 414 PetscErrorCode ierr; 415 PetscMPIInt size; 416 417 PetscFunctionBegin; 418 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 419 PetscValidPointer(sdraw,2); 420 421 ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size);CHKERRQ(ierr); 422 if (size == 1) { 423 *sdraw = draw; 424 } else { 425 if (draw->ops->getsingleton) { 426 ierr = (*draw->ops->getsingleton)(draw,sdraw);CHKERRQ(ierr); 427 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name); 428 } 429 PetscFunctionReturn(0); 430 } 431 432 #undef __FUNCT__ 433 #define __FUNCT__ "PetscDrawRestoreSingleton" 434 /*@C 435 PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned 436 by the one process. 437 438 Collective on PetscDraw 439 440 Input Parameters: 441 + draw - the original window 442 - sdraw - the singleton window 443 444 Level: advanced 445 446 .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton() 447 448 @*/ 449 PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw) 450 { 451 PetscErrorCode ierr; 452 PetscMPIInt size; 453 454 PetscFunctionBegin; 455 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 456 PetscValidPointer(sdraw,2); 457 PetscValidHeaderSpecific(*sdraw,PETSC_DRAW_CLASSID,2); 458 459 ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size);CHKERRQ(ierr); 460 if (size != 1) { 461 if (draw->ops->restoresingleton) { 462 ierr = (*draw->ops->restoresingleton)(draw,sdraw);CHKERRQ(ierr); 463 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name); 464 } 465 PetscFunctionReturn(0); 466 } 467 468 469 470 471 472 473 474