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 101 PetscFunctionBegin; 102 if (draw->ops->resizewindow) { 103 ierr = (*draw->ops->resizewindow)(draw,w,h);CHKERRQ(ierr); 104 } 105 PetscFunctionReturn(0); 106 } 107 108 #undef __FUNCT__ 109 #define __FUNCT__ "PetscDrawCheckResizedWindow" 110 /*@ 111 PetscDrawCheckResizedWindow - Checks if the user has resized the window. 112 113 Collective on PetscDraw 114 115 Input Parameter: 116 . draw - the window 117 118 Level: advanced 119 120 .seealso: PetscDrawResizeWindow() 121 122 @*/ 123 PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw) 124 { 125 PetscErrorCode ierr; 126 127 PetscFunctionBegin; 128 if (draw->ops->checkresizedwindow) { 129 ierr = (*draw->ops->checkresizedwindow)(draw);CHKERRQ(ierr); 130 } 131 PetscFunctionReturn(0); 132 } 133 134 #undef __FUNCT__ 135 #define __FUNCT__ "PetscDrawGetTitle" 136 /*@C 137 PetscDrawGetTitle - Gets pointer to title of a PetscDraw context. 138 139 Not collective 140 141 Input Parameter: 142 . draw - the graphics context 143 144 Output Parameter: 145 . title - the title 146 147 Level: intermediate 148 149 .seealso: PetscDrawSetTitle() 150 @*/ 151 PetscErrorCode PetscDrawGetTitle(PetscDraw draw,char **title) 152 { 153 PetscFunctionBegin; 154 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 155 PetscValidPointer(title,2); 156 *title = draw->title; 157 PetscFunctionReturn(0); 158 } 159 160 #undef __FUNCT__ 161 #define __FUNCT__ "PetscDrawSetTitle" 162 /*@C 163 PetscDrawSetTitle - Sets the title of a PetscDraw context. 164 165 Not collective (any processor or all may call this) 166 167 Input Parameters: 168 + draw - the graphics context 169 - title - the title 170 171 Level: intermediate 172 173 Note: 174 A copy of the string is made, so you may destroy the 175 title string after calling this routine. 176 177 .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle() 178 @*/ 179 PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[]) 180 { 181 PetscErrorCode ierr; 182 183 PetscFunctionBegin; 184 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 185 PetscValidCharPointer(title,2); 186 ierr = PetscFree(draw->title);CHKERRQ(ierr); 187 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 188 if (draw->ops->settitle) { 189 ierr = (*draw->ops->settitle)(draw,title);CHKERRQ(ierr); 190 } 191 PetscFunctionReturn(0); 192 } 193 194 #undef __FUNCT__ 195 #define __FUNCT__ "PetscDrawAppendTitle" 196 /*@C 197 PetscDrawAppendTitle - Appends to the title of a PetscDraw context. 198 199 Not collective (any processor or all can call this) 200 201 Input Parameters: 202 + draw - the graphics context 203 - title - the title 204 205 Note: 206 A copy of the string is made, so you may destroy the 207 title string after calling this routine. 208 209 Level: advanced 210 211 .seealso: PetscDrawSetTitle(), PetscDrawGetTitle() 212 @*/ 213 PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[]) 214 { 215 PetscErrorCode ierr; 216 size_t len1,len2,len; 217 char *newtitle; 218 219 PetscFunctionBegin; 220 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 221 if (!title) PetscFunctionReturn(0); 222 223 if (draw->title) { 224 ierr = PetscStrlen(title,&len1);CHKERRQ(ierr); 225 ierr = PetscStrlen(draw->title,&len2);CHKERRQ(ierr); 226 len = len1 + len2; 227 ierr = PetscMalloc((len + 1)*sizeof(char*),&newtitle);CHKERRQ(ierr); 228 ierr = PetscStrcpy(newtitle,draw->title);CHKERRQ(ierr); 229 ierr = PetscStrcat(newtitle,title);CHKERRQ(ierr); 230 ierr = PetscFree(draw->title);CHKERRQ(ierr); 231 draw->title = newtitle; 232 } else { 233 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 234 } 235 if (draw->ops->settitle) { 236 ierr = (*draw->ops->settitle)(draw,draw->title);CHKERRQ(ierr); 237 } 238 PetscFunctionReturn(0); 239 } 240 241 #undef __FUNCT__ 242 #define __FUNCT__ "PetscDrawDestroy" 243 /*@ 244 PetscDrawDestroy - Deletes a draw context. 245 246 Collective on PetscDraw 247 248 Input Parameters: 249 . draw - the drawing context 250 251 Level: beginner 252 253 .seealso: PetscDrawCreate() 254 255 @*/ 256 PetscErrorCode PetscDrawDestroy(PetscDraw *draw) 257 { 258 PetscErrorCode ierr; 259 260 PetscFunctionBegin; 261 if (!*draw) PetscFunctionReturn(0); 262 PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,1); 263 if (--((PetscObject)(*draw))->refct > 0) PetscFunctionReturn(0); 264 265 if ((*draw)->pause == -2) { 266 (*draw)->pause = -1; 267 ierr = PetscDrawPause(*draw);CHKERRQ(ierr); 268 } 269 270 /* if memory was published then destroy it */ 271 ierr = PetscObjectDepublish(*draw);CHKERRQ(ierr); 272 273 if ((*draw)->ops->destroy) { 274 ierr = (*(*draw)->ops->destroy)(*draw);CHKERRQ(ierr); 275 } 276 ierr = PetscFree((*draw)->title);CHKERRQ(ierr); 277 ierr = PetscFree((*draw)->display);CHKERRQ(ierr); 278 ierr = PetscFree((*draw)->savefilename);CHKERRQ(ierr); 279 ierr = PetscHeaderDestroy(draw);CHKERRQ(ierr); 280 PetscFunctionReturn(0); 281 } 282 283 #undef __FUNCT__ 284 #define __FUNCT__ "PetscDrawGetPopup" 285 /*@ 286 PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window. 287 288 Collective on PetscDraw 289 290 Input Parameter: 291 . draw - the original window 292 293 Output Parameter: 294 . popup - the new popup window 295 296 Level: advanced 297 298 @*/ 299 PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup) 300 { 301 PetscErrorCode ierr; 302 303 PetscFunctionBegin; 304 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 305 PetscValidPointer(popup,2); 306 307 if (draw->popup) { 308 *popup = draw->popup; 309 } else if (draw->ops->getpopup) { 310 ierr = (*draw->ops->getpopup)(draw,popup);CHKERRQ(ierr); 311 } else { 312 *popup = PETSC_NULL; 313 } 314 PetscFunctionReturn(0); 315 } 316 317 #undef __FUNCT__ 318 #define __FUNCT__ "PetscDrawDestroy_Null" 319 PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw) 320 { 321 PetscFunctionBegin; 322 PetscFunctionReturn(0); 323 } 324 325 #undef __FUNCT__ 326 #define __FUNCT__ "PetscDrawOpenNull" 327 /* 328 PetscDrawOpenNull - Opens a null drawing context. All draw commands to 329 it are ignored. 330 331 Output Parameter: 332 . win - the drawing context 333 334 Level: advanced 335 336 */ 337 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win) 338 { 339 PetscErrorCode ierr; 340 341 PetscFunctionBegin; 342 ierr = PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);CHKERRQ(ierr); 343 ierr = PetscDrawSetType(*win,PETSC_DRAW_NULL);CHKERRQ(ierr); 344 PetscFunctionReturn(0); 345 } 346 347 #undef __FUNCT__ 348 #define __FUNCT__ "PetscDrawSetDisplay" 349 /*@ 350 PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed 351 352 Input Parameter: 353 + draw - the drawing context 354 - display - the X windows display 355 356 Level: advanced 357 358 @*/ 359 PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,const char display[]) 360 { 361 PetscErrorCode ierr; 362 363 PetscFunctionBegin; 364 ierr = PetscFree(draw->display);CHKERRQ(ierr); 365 ierr = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr); 366 PetscFunctionReturn(0); 367 } 368 369 EXTERN_C_BEGIN 370 #undef __FUNCT__ 371 #define __FUNCT__ "PetscDrawCreate_Null" 372 /* 373 PetscDrawCreate_Null - Opens a null drawing context. All draw commands to 374 it are ignored. 375 376 Input Parameter: 377 . win - the drawing context 378 */ 379 PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) 380 { 381 PetscErrorCode ierr; 382 383 PetscFunctionBegin; 384 ierr = PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));CHKERRQ(ierr); 385 draw->ops->destroy = PetscDrawDestroy_Null; 386 draw->ops->view = 0; 387 draw->pause = 0.0; 388 draw->coor_xl = 0.0; draw->coor_xr = 1.0; 389 draw->coor_yl = 0.0; draw->coor_yr = 1.0; 390 draw->port_xl = 0.0; draw->port_xr = 1.0; 391 draw->port_yl = 0.0; draw->port_yr = 1.0; 392 draw->popup = 0; 393 PetscFunctionReturn(0); 394 } 395 EXTERN_C_END 396 397 #undef __FUNCT__ 398 #define __FUNCT__ "PetscDrawGetSingleton" 399 /*@C 400 PetscDrawGetSingleton - Gain access to a PetscDraw object as if it were owned 401 by the one process. 402 403 Collective on PetscDraw 404 405 Input Parameter: 406 . draw - the original window 407 408 Output Parameter: 409 . sdraw - the singleton window 410 411 Level: advanced 412 413 .seealso: PetscDrawRestoreSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton() 414 415 @*/ 416 PetscErrorCode PetscDrawGetSingleton(PetscDraw draw,PetscDraw *sdraw) 417 { 418 PetscErrorCode ierr; 419 PetscMPIInt size; 420 421 PetscFunctionBegin; 422 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 423 PetscValidPointer(sdraw,2); 424 425 ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size);CHKERRQ(ierr); 426 if (size == 1) { 427 *sdraw = draw; 428 } else { 429 if (draw->ops->getsingleton) { 430 ierr = (*draw->ops->getsingleton)(draw,sdraw);CHKERRQ(ierr); 431 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name); 432 } 433 PetscFunctionReturn(0); 434 } 435 436 #undef __FUNCT__ 437 #define __FUNCT__ "PetscDrawRestoreSingleton" 438 /*@C 439 PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned 440 by the one process. 441 442 Collective on PetscDraw 443 444 Input Parameters: 445 + draw - the original window 446 - sdraw - the singleton window 447 448 Level: advanced 449 450 .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton() 451 452 @*/ 453 PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw) 454 { 455 PetscErrorCode ierr; 456 PetscMPIInt size; 457 458 PetscFunctionBegin; 459 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 460 PetscValidPointer(sdraw,2); 461 PetscValidHeaderSpecific(*sdraw,PETSC_DRAW_CLASSID,2); 462 463 ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size);CHKERRQ(ierr); 464 if (size != 1) { 465 if (draw->ops->restoresingleton) { 466 ierr = (*draw->ops->restoresingleton)(draw,sdraw);CHKERRQ(ierr); 467 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name); 468 } 469 PetscFunctionReturn(0); 470 } 471 472 473 474 475 476 477 478