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 #include <petscviewer.h> 7 8 PetscClassId PETSC_DRAW_CLASSID; 9 10 static PetscBool PetscDrawPackageInitialized = PETSC_FALSE; 11 #undef __FUNCT__ 12 #define __FUNCT__ "PetscDrawFinalizePackage" 13 /*@C 14 PetscDrawFinalizePackage - This function destroys everything in the Petsc interface to the Draw package. It is 15 called from PetscFinalize(). 16 17 Level: developer 18 19 .keywords: Petsc, destroy, package, mathematica 20 .seealso: PetscFinalize() 21 @*/ 22 PetscErrorCode PetscDrawFinalizePackage(void) 23 { 24 PetscFunctionBegin; 25 PetscDrawPackageInitialized = PETSC_FALSE; 26 PetscDrawList = 0; 27 PetscFunctionReturn(0); 28 } 29 30 #undef __FUNCT__ 31 #define __FUNCT__ "PetscDrawInitializePackage" 32 /*@C 33 PetscInitializeDrawPackage - This function initializes everything in the PetscDraw package. It is called 34 from PetscDLLibraryRegister() when using dynamic libraries, and on the call to PetscInitialize() 35 when using static libraries. 36 37 Level: developer 38 39 .keywords: Petsc, initialize, package 40 .seealso: PetscInitialize() 41 @*/ 42 PetscErrorCode PetscDrawInitializePackage(void) 43 { 44 char logList[256]; 45 char *className; 46 PetscBool opt; 47 PetscErrorCode ierr; 48 49 PetscFunctionBegin; 50 if (PetscDrawPackageInitialized) PetscFunctionReturn(0); 51 PetscDrawPackageInitialized = PETSC_TRUE; 52 /* Register Classes */ 53 ierr = PetscClassIdRegister("Draw",&PETSC_DRAW_CLASSID);CHKERRQ(ierr); 54 ierr = PetscClassIdRegister("Axis",&PETSC_DRAWAXIS_CLASSID);CHKERRQ(ierr); 55 ierr = PetscClassIdRegister("Line Graph",&PETSC_DRAWLG_CLASSID);CHKERRQ(ierr); 56 ierr = PetscClassIdRegister("Histogram",&PETSC_DRAWHG_CLASSID);CHKERRQ(ierr); 57 ierr = PetscClassIdRegister("Scatter Plot",&PETSC_DRAWSP_CLASSID);CHKERRQ(ierr); 58 /* Register Constructors */ 59 ierr = PetscDrawRegisterAll();CHKERRQ(ierr); 60 /* Process info exclusions */ 61 ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 62 if (opt) { 63 ierr = PetscStrstr(logList, "draw", &className);CHKERRQ(ierr); 64 if (className) { 65 ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr); 66 } 67 } 68 /* Process summary exclusions */ 69 ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 70 if (opt) { 71 ierr = PetscStrstr(logList, "draw", &className);CHKERRQ(ierr); 72 if (className) { 73 ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr); 74 } 75 } 76 ierr = PetscRegisterFinalize(PetscDrawFinalizePackage);CHKERRQ(ierr); 77 PetscFunctionReturn(0); 78 } 79 80 #undef __FUNCT__ 81 #define __FUNCT__ "PetscDrawResizeWindow" 82 /*@ 83 PetscDrawResizeWindow - Allows one to resize a window from a program. 84 85 Collective on PetscDraw 86 87 Input Parameter: 88 + draw - the window 89 - w,h - the new width and height of the window 90 91 Level: intermediate 92 93 .seealso: PetscDrawCheckResizedWindow() 94 @*/ 95 PetscErrorCode PetscDrawResizeWindow(PetscDraw draw,int w,int h) 96 { 97 PetscErrorCode ierr; 98 99 PetscFunctionBegin; 100 if (draw->ops->resizewindow) { 101 ierr = (*draw->ops->resizewindow)(draw,w,h);CHKERRQ(ierr); 102 } 103 PetscFunctionReturn(0); 104 } 105 106 #undef __FUNCT__ 107 #define __FUNCT__ "PetscDrawCheckResizedWindow" 108 /*@ 109 PetscDrawCheckResizedWindow - Checks if the user has resized the window. 110 111 Collective on PetscDraw 112 113 Input Parameter: 114 . draw - the window 115 116 Level: advanced 117 118 .seealso: PetscDrawResizeWindow() 119 120 @*/ 121 PetscErrorCode PetscDrawCheckResizedWindow(PetscDraw draw) 122 { 123 PetscErrorCode ierr; 124 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: The title is positioned in the windowing system title bar for the window. Hence it will not be saved with -draw_save 172 in the image. 173 174 A copy of the string is made, so you may destroy the 175 title string after calling this routine. 176 177 You can use PetscDrawAxisSetLabels() to indicate a title within the window 178 179 .seealso: PetscDrawGetTitle(), PetscDrawAppendTitle() 180 @*/ 181 PetscErrorCode PetscDrawSetTitle(PetscDraw draw,const char title[]) 182 { 183 PetscErrorCode ierr; 184 185 PetscFunctionBegin; 186 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 187 PetscValidCharPointer(title,2); 188 ierr = PetscFree(draw->title);CHKERRQ(ierr); 189 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 190 if (draw->ops->settitle) { 191 ierr = (*draw->ops->settitle)(draw,title);CHKERRQ(ierr); 192 } 193 PetscFunctionReturn(0); 194 } 195 196 #undef __FUNCT__ 197 #define __FUNCT__ "PetscDrawAppendTitle" 198 /*@C 199 PetscDrawAppendTitle - Appends to the title of a PetscDraw context. 200 201 Not collective (any processor or all can call this) 202 203 Input Parameters: 204 + draw - the graphics context 205 - title - the title 206 207 Note: 208 A copy of the string is made, so you may destroy the 209 title string after calling this routine. 210 211 Level: advanced 212 213 .seealso: PetscDrawSetTitle(), PetscDrawGetTitle() 214 @*/ 215 PetscErrorCode PetscDrawAppendTitle(PetscDraw draw,const char title[]) 216 { 217 PetscErrorCode ierr; 218 size_t len1,len2,len; 219 char *newtitle; 220 221 PetscFunctionBegin; 222 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 223 if (!title) PetscFunctionReturn(0); 224 225 if (draw->title) { 226 ierr = PetscStrlen(title,&len1);CHKERRQ(ierr); 227 ierr = PetscStrlen(draw->title,&len2);CHKERRQ(ierr); 228 len = len1 + len2; 229 ierr = PetscMalloc((len + 1)*sizeof(char*),&newtitle);CHKERRQ(ierr); 230 ierr = PetscStrcpy(newtitle,draw->title);CHKERRQ(ierr); 231 ierr = PetscStrcat(newtitle,title);CHKERRQ(ierr); 232 ierr = PetscFree(draw->title);CHKERRQ(ierr); 233 234 draw->title = newtitle; 235 } else { 236 ierr = PetscStrallocpy(title,&draw->title);CHKERRQ(ierr); 237 } 238 if (draw->ops->settitle) { 239 ierr = (*draw->ops->settitle)(draw,draw->title);CHKERRQ(ierr); 240 } 241 PetscFunctionReturn(0); 242 } 243 244 #undef __FUNCT__ 245 #define __FUNCT__ "PetscDrawDestroy" 246 /*@ 247 PetscDrawDestroy - Deletes a draw context. 248 249 Collective on PetscDraw 250 251 Input Parameters: 252 . draw - the drawing context 253 254 Level: beginner 255 256 .seealso: PetscDrawCreate() 257 258 @*/ 259 PetscErrorCode PetscDrawDestroy(PetscDraw *draw) 260 { 261 PetscErrorCode ierr; 262 263 PetscFunctionBegin; 264 if (!*draw) PetscFunctionReturn(0); 265 PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,1); 266 if (--((PetscObject)(*draw))->refct > 0) PetscFunctionReturn(0); 267 268 if ((*draw)->pause == -2) { 269 (*draw)->pause = -1; 270 271 ierr = PetscDrawPause(*draw);CHKERRQ(ierr); 272 } 273 274 /* if memory was published then destroy it */ 275 ierr = PetscObjectAMSViewOff((PetscObject)*draw);CHKERRQ(ierr); 276 277 if ((*draw)->ops->destroy) { 278 ierr = (*(*draw)->ops->destroy)(*draw);CHKERRQ(ierr); 279 } 280 ierr = PetscFree((*draw)->title);CHKERRQ(ierr); 281 ierr = PetscFree((*draw)->display);CHKERRQ(ierr); 282 ierr = PetscFree((*draw)->savefilename);CHKERRQ(ierr); 283 ierr = PetscHeaderDestroy(draw);CHKERRQ(ierr); 284 PetscFunctionReturn(0); 285 } 286 287 #undef __FUNCT__ 288 #define __FUNCT__ "PetscDrawGetPopup" 289 /*@ 290 PetscDrawGetPopup - Creates a popup window associated with a PetscDraw window. 291 292 Collective on PetscDraw 293 294 Input Parameter: 295 . draw - the original window 296 297 Output Parameter: 298 . popup - the new popup window 299 300 Level: advanced 301 302 @*/ 303 PetscErrorCode PetscDrawGetPopup(PetscDraw draw,PetscDraw *popup) 304 { 305 PetscErrorCode ierr; 306 307 PetscFunctionBegin; 308 PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1); 309 PetscValidPointer(popup,2); 310 311 if (draw->popup) *popup = draw->popup; 312 else if (draw->ops->getpopup) { 313 ierr = (*draw->ops->getpopup)(draw,popup);CHKERRQ(ierr); 314 } else *popup = NULL; 315 PetscFunctionReturn(0); 316 } 317 318 #undef __FUNCT__ 319 #define __FUNCT__ "PetscDrawDestroy_Null" 320 PetscErrorCode PetscDrawDestroy_Null(PetscDraw draw) 321 { 322 PetscFunctionBegin; 323 PetscFunctionReturn(0); 324 } 325 326 #undef __FUNCT__ 327 #define __FUNCT__ "PetscDrawOpenNull" 328 /* 329 PetscDrawOpenNull - Opens a null drawing context. All draw commands to 330 it are ignored. 331 332 Output Parameter: 333 . win - the drawing context 334 335 Level: advanced 336 337 */ 338 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm,PetscDraw *win) 339 { 340 PetscErrorCode ierr; 341 342 PetscFunctionBegin; 343 ierr = PetscDrawCreate(comm,NULL,NULL,0,0,1,1,win);CHKERRQ(ierr); 344 ierr = PetscDrawSetType(*win,PETSC_DRAW_NULL);CHKERRQ(ierr); 345 PetscFunctionReturn(0); 346 } 347 348 #undef __FUNCT__ 349 #define __FUNCT__ "PetscDrawSetDisplay" 350 /*@ 351 PetscDrawSetDisplay - Sets the display where a PetscDraw object will be displayed 352 353 Input Parameter: 354 + draw - the drawing context 355 - display - the X windows display 356 357 Level: advanced 358 359 @*/ 360 PetscErrorCode PetscDrawSetDisplay(PetscDraw draw,const char display[]) 361 { 362 PetscErrorCode ierr; 363 364 PetscFunctionBegin; 365 ierr = PetscFree(draw->display);CHKERRQ(ierr); 366 ierr = PetscStrallocpy(display,&draw->display);CHKERRQ(ierr); 367 PetscFunctionReturn(0); 368 } 369 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 PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) 380 { 381 PetscErrorCode ierr; 382 383 PetscFunctionBegin; 384 ierr = PetscMemzero(draw->ops,sizeof(struct _PetscDrawOps));CHKERRQ(ierr); 385 386 draw->ops->destroy = PetscDrawDestroy_Null; 387 draw->ops->view = 0; 388 draw->pause = 0.0; 389 draw->coor_xl = 0.0; draw->coor_xr = 1.0; 390 draw->coor_yl = 0.0; draw->coor_yr = 1.0; 391 draw->port_xl = 0.0; draw->port_xr = 1.0; 392 draw->port_yl = 0.0; draw->port_yr = 1.0; 393 draw->popup = 0; 394 PetscFunctionReturn(0); 395 } 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(PetscObjectComm((PetscObject)draw),&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(PetscObjectComm((PetscObject)draw),&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