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 232 draw->title = newtitle; 233 } else { 234 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 235 } 236 if (draw->ops->settitle) { 237 ierr = (*draw->ops->settitle)(draw,draw->title);CHKERRQ(ierr); 238 } 239 PetscFunctionReturn(0); 240 } 241 242 #undef __FUNCT__ 243 #define __FUNCT__ "PetscDrawDestroy" 244 /*@ 245 PetscDrawDestroy - Deletes a draw context. 246 247 Collective on PetscDraw 248 249 Input Parameters: 250 . draw - the drawing context 251 252 Level: beginner 253 254 .seealso: PetscDrawCreate() 255 256 @*/ 257 PetscErrorCode PetscDrawDestroy(PetscDraw *draw) 258 { 259 PetscErrorCode ierr; 260 261 PetscFunctionBegin; 262 if (!*draw) PetscFunctionReturn(0); 263 PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,1); 264 if (--((PetscObject)(*draw))->refct > 0) PetscFunctionReturn(0); 265 266 if ((*draw)->pause == -2) { 267 (*draw)->pause = -1; 268 269 ierr = PetscDrawPause(*draw);CHKERRQ(ierr); 270 } 271 272 /* if memory was published then destroy it */ 273 ierr = PetscObjectDepublish(*draw);CHKERRQ(ierr); 274 275 if ((*draw)->ops->destroy) { 276 ierr = (*(*draw)->ops->destroy)(*draw);CHKERRQ(ierr); 277 } 278 ierr = PetscFree((*draw)->title);CHKERRQ(ierr); 279 ierr = PetscFree((*draw)->display);CHKERRQ(ierr); 280 ierr = PetscFree((*draw)->savefilename);CHKERRQ(ierr); 281 ierr = PetscHeaderDestroy(draw);CHKERRQ(ierr); 282 PetscFunctionReturn(0); 283 } 284 285 #undef __FUNCT__ 286 #define __FUNCT__ "PetscDrawGetPopup" 287 /*@ 288 PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window. 289 290 Collective on PetscDraw 291 292 Input Parameter: 293 . draw - the original window 294 295 Output Parameter: 296 . popup - the new popup window 297 298 Level: advanced 299 300 @*/ 301 PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup) 302 { 303 PetscErrorCode ierr; 304 305 PetscFunctionBegin; 306 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 307 PetscValidPointer(popup,2); 308 309 if (draw->popup) *popup = draw->popup; 310 else if (draw->ops->getpopup) { 311 ierr = (*draw->ops->getpopup)(draw,popup);CHKERRQ(ierr); 312 } else *popup = PETSC_NULL; 313 PetscFunctionReturn(0); 314 } 315 316 #undef __FUNCT__ 317 #define __FUNCT__ "PetscDrawDestroy_Null" 318 PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw) 319 { 320 PetscFunctionBegin; 321 PetscFunctionReturn(0); 322 } 323 324 #undef __FUNCT__ 325 #define __FUNCT__ "PetscDrawOpenNull" 326 /* 327 PetscDrawOpenNull - Opens a null drawing context. All draw commands to 328 it are ignored. 329 330 Output Parameter: 331 . win - the drawing context 332 333 Level: advanced 334 335 */ 336 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win) 337 { 338 PetscErrorCode ierr; 339 340 PetscFunctionBegin; 341 ierr = PetscDrawCreate(comm,PETSC_NULL,PETSC_NULL,0,0,1,1,win);CHKERRQ(ierr); 342 ierr = PetscDrawSetType(*win,PETSC_DRAW_NULL);CHKERRQ(ierr); 343 PetscFunctionReturn(0); 344 } 345 346 #undef __FUNCT__ 347 #define __FUNCT__ "PetscDrawSetDisplay" 348 /*@ 349 PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed 350 351 Input Parameter: 352 + draw - the drawing context 353 - display - the X windows display 354 355 Level: advanced 356 357 @*/ 358 PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,const char display[]) 359 { 360 PetscErrorCode ierr; 361 362 PetscFunctionBegin; 363 ierr = PetscFree(draw->display);CHKERRQ(ierr); 364 ierr = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr); 365 PetscFunctionReturn(0); 366 } 367 368 EXTERN_C_BEGIN 369 #undef __FUNCT__ 370 #define __FUNCT__ "PetscDrawCreate_Null" 371 /* 372 PetscDrawCreate_Null - Opens a null drawing context. All draw commands to 373 it are ignored. 374 375 Input Parameter: 376 . win - the drawing context 377 */ 378 PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) 379 { 380 PetscErrorCode ierr; 381 382 PetscFunctionBegin; 383 ierr = PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));CHKERRQ(ierr); 384 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) *sdraw = draw; 427 else { 428 if (draw->ops->getsingleton) { 429 ierr = (*draw->ops->getsingleton)(draw,sdraw);CHKERRQ(ierr); 430 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot get singleton for this type %s of draw object",((PetscObject)draw)->type_name); 431 } 432 PetscFunctionReturn(0); 433 } 434 435 #undef __FUNCT__ 436 #define __FUNCT__ "PetscDrawRestoreSingleton" 437 /*@C 438 PetscDrawRestoreSingleton - Remove access to a PetscDraw object as if it were owned 439 by the one process. 440 441 Collective on PetscDraw 442 443 Input Parameters: 444 + draw - the original window 445 - sdraw - the singleton window 446 447 Level: advanced 448 449 .seealso: PetscDrawGetSingleton(), PetscViewerGetSingleton(), PetscViewerRestoreSingleton() 450 451 @*/ 452 PetscErrorCode PetscDrawRestoreSingleton(PetscDraw draw,PetscDraw *sdraw) 453 { 454 PetscErrorCode ierr; 455 PetscMPIInt size; 456 457 PetscFunctionBegin; 458 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 459 PetscValidPointer(sdraw,2); 460 PetscValidHeaderSpecific(*sdraw,PETSC_DRAW_CLASSID,2); 461 462 ierr = MPI_Comm_size(((PetscObject)draw)->comm,&size);CHKERRQ(ierr); 463 if (size != 1) { 464 if (draw->ops->restoresingleton) { 465 ierr = (*draw->ops->restoresingleton)(draw,sdraw);CHKERRQ(ierr); 466 } else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Cannot restore singleton for this type %s of draw object",((PetscObject)draw)->type_name); 467 } 468 PetscFunctionReturn(0); 469 } 470 471 472 473 474 475 476 477