1 #include <petsc/private/drawimpl.h> /*I "petscdraw.h" I*/ 2 3 static PetscErrorCode PetscDrawCoordinateToPixel_Null(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j) { 4 PetscFunctionBegin; 5 *i = *j = 0; 6 PetscFunctionReturn(0); 7 } 8 9 static PetscErrorCode PetscDrawPixelToCoordinate_Null(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y) { 10 PetscFunctionBegin; 11 *x = *y = 0; 12 PetscFunctionReturn(0); 13 } 14 15 static PetscErrorCode PetscDrawPoint_Null(PetscDraw draw, PetscReal x, PetscReal y, int c) { 16 PetscFunctionBegin; 17 PetscFunctionReturn(0); 18 } 19 20 static PetscErrorCode PetscDrawPointPixel_Null(PetscDraw draw, int x, int y, int c) { 21 PetscFunctionBegin; 22 PetscFunctionReturn(0); 23 } 24 25 static PetscErrorCode PetscDrawLineGetWidth_Null(PetscDraw draw, PetscReal *width) { 26 PetscFunctionBegin; 27 if (width) *width = 0.01; 28 PetscFunctionReturn(0); 29 } 30 31 static PetscErrorCode PetscDrawLine_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl) { 32 PetscFunctionBegin; 33 PetscFunctionReturn(0); 34 } 35 36 static PetscErrorCode PetscDrawArrow_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl) { 37 PetscFunctionBegin; 38 PetscFunctionReturn(0); 39 } 40 41 static PetscErrorCode PetscDrawRectangle_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4) { 42 PetscFunctionBegin; 43 PetscFunctionReturn(0); 44 } 45 46 static PetscErrorCode PetscDrawEllipse_Null(PetscDraw Win, PetscReal x, PetscReal y, PetscReal a, PetscReal b, int c) { 47 PetscFunctionBegin; 48 PetscFunctionReturn(0); 49 } 50 51 static PetscErrorCode PetscDrawTriangle_Null(PetscDraw draw, PetscReal X1, PetscReal Y_1, PetscReal X2, PetscReal Y2, PetscReal X3, PetscReal Y3, int c1, int c2, int c3) { 52 PetscFunctionBegin; 53 PetscFunctionReturn(0); 54 } 55 56 static PetscErrorCode PetscDrawStringGetSize_Null(PetscDraw draw, PetscReal *x, PetscReal *y) { 57 PetscFunctionBegin; 58 if (x) *x = 0.01; 59 if (y) *y = 0.01; 60 PetscFunctionReturn(0); 61 } 62 63 static PetscErrorCode PetscDrawString_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[]) { 64 PetscFunctionBegin; 65 PetscFunctionReturn(0); 66 } 67 68 static PetscErrorCode PetscDrawStringVertical_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[]) { 69 PetscFunctionBegin; 70 PetscFunctionReturn(0); 71 } 72 73 static PetscErrorCode PetscDrawStringBoxed_Null(PetscDraw draw, PetscReal sxl, PetscReal syl, int sc, int bc, const char text[], PetscReal *w, PetscReal *h) { 74 PetscFunctionBegin; 75 if (w) *w = 0.01; 76 if (h) *h = 0.01; 77 PetscFunctionReturn(0); 78 } 79 80 static PetscErrorCode PetscDrawGetSingleton_Null(PetscDraw draw, PetscDraw *sdraw) { 81 PetscFunctionBegin; 82 PetscCall(PetscDrawOpenNull(PETSC_COMM_SELF, sdraw)); 83 PetscFunctionReturn(0); 84 } 85 86 static PetscErrorCode PetscDrawRestoreSingleton_Null(PetscDraw draw, PetscDraw *sdraw) { 87 PetscFunctionBegin; 88 PetscCall(PetscDrawDestroy(sdraw)); 89 PetscFunctionReturn(0); 90 } 91 92 static struct _PetscDrawOps DvOps = {NULL, /* PetscDrawSetDoubleBuffer_Null */ 93 NULL, /* PetscDrawFlush_Null */ 94 PetscDrawLine_Null, 95 NULL, /* PetscDrawLineSetWidth_Null */ 96 PetscDrawLineGetWidth_Null, 97 PetscDrawPoint_Null, 98 NULL, /* PetscDrawPointSetSize_Null */ 99 PetscDrawString_Null, 100 PetscDrawStringVertical_Null, 101 NULL, /* PetscDrawStringSetSize_Null */ 102 PetscDrawStringGetSize_Null, 103 NULL, /* PetscDrawSetViewport_Null */ 104 NULL, /* PetscDrawClear_Null */ 105 PetscDrawRectangle_Null, 106 PetscDrawTriangle_Null, 107 PetscDrawEllipse_Null, 108 NULL, /* PetscDrawGetMouseButton_Null */ 109 NULL, /* PetscDrawPause_Null */ 110 NULL, /* PetscDrawBeginPage_Null */ 111 NULL, /* PetscDrawEndPage_Null */ 112 NULL, /* PetscDrawGetPopup_Null */ 113 NULL, /* PetscDrawSetTitle_Null */ 114 NULL, /* PetscDrawCheckResizedWindow_Null */ 115 NULL, /* PetscDrawResizeWindow_Null */ 116 NULL, /* PetscDrawDestroy_Null */ 117 NULL, /* PetscDrawView_Null */ 118 PetscDrawGetSingleton_Null, 119 PetscDrawRestoreSingleton_Null, 120 NULL, /* PetscDrawSave_Null */ 121 NULL, /* PetscDrawGetImage_Null */ 122 NULL, /* PetscDrawSetCoordinates_Null */ 123 PetscDrawArrow_Null, 124 PetscDrawCoordinateToPixel_Null, 125 PetscDrawPixelToCoordinate_Null, 126 PetscDrawPointPixel_Null, 127 PetscDrawStringBoxed_Null}; 128 129 /*MC 130 PETSC_DRAW_NULL - PETSc graphics device that ignores all draw commands 131 132 Level: beginner 133 134 Note: 135 A `PETSC_DRAW_NULL` is useful in places where `PetscDraw` routines are called but no graphics window, for example, is available. 136 137 .seealso: `PetscDraw`, `PetscDrawOpenNull()`, `PETSC_DRAW_X`, `PetscDrawOpenNull()`, `PetscDrawIsNull()` 138 M*/ 139 PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw); 140 141 PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) { 142 PetscFunctionBegin; 143 draw->pause = 0; 144 draw->coor_xl = 0; 145 draw->coor_xr = 1; 146 draw->coor_yl = 0; 147 draw->coor_yr = 1; 148 draw->port_xl = 0; 149 draw->port_xr = 1; 150 draw->port_yl = 0; 151 draw->port_yr = 1; 152 PetscCall(PetscDrawDestroy(&draw->popup)); 153 154 PetscCall(PetscMemcpy(draw->ops, &DvOps, sizeof(DvOps))); 155 draw->data = NULL; 156 PetscFunctionReturn(0); 157 } 158 159 /*@ 160 PetscDrawOpenNull - Opens a null drawing context. All draw commands to 161 it are ignored. 162 163 Input Parameter: 164 . comm - MPI communicator 165 166 Output Parameter: 167 . draw - the drawing context 168 169 Level: advanced 170 171 .seealso: `PetscDraw`, `PetscDrawIsNull()`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`, `PetscDrawIsNull()` 172 @*/ 173 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm, PetscDraw *win) { 174 PetscFunctionBegin; 175 PetscCall(PetscDrawCreate(comm, NULL, NULL, 0, 0, 1, 1, win)); 176 PetscCall(PetscDrawSetType(*win, PETSC_DRAW_NULL)); 177 PetscFunctionReturn(0); 178 } 179 180 /*@ 181 PetscDrawIsNull - Returns `PETSC_TRUE` if draw is a null draw object. 182 183 Not collective 184 185 Input Parameter: 186 . draw - the draw context 187 188 Output Parameter: 189 . yes - `PETSC_TRUE` if it is a null draw object; otherwise `PETSC_FALSE` 190 191 Level: advanced 192 193 .seealso: `PetscDraw`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`, `PetscDrawIsNull()` 194 @*/ 195 PetscErrorCode PetscDrawIsNull(PetscDraw draw, PetscBool *yes) { 196 PetscFunctionBegin; 197 PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1); 198 PetscValidBoolPointer(yes, 2); 199 PetscCall(PetscObjectTypeCompare((PetscObject)draw, PETSC_DRAW_NULL, yes)); 200 PetscFunctionReturn(0); 201 } 202