Actual source code: drawnull.c
1: #include <petsc/private/drawimpl.h>
3: static PetscErrorCode PetscDrawCoordinateToPixel_Null(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
4: {
5: *i = *j = 0;
6: return 0;
7: }
9: static PetscErrorCode PetscDrawPixelToCoordinate_Null(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
10: {
11: *x = *y = 0;
12: return 0;
13: }
15: static PetscErrorCode PetscDrawPoint_Null(PetscDraw draw, PetscReal x, PetscReal y, int c)
16: {
17: return 0;
18: }
20: static PetscErrorCode PetscDrawPointPixel_Null(PetscDraw draw, int x, int y, int c)
21: {
22: return 0;
23: }
25: static PetscErrorCode PetscDrawLineGetWidth_Null(PetscDraw draw, PetscReal *width)
26: {
27: if (width) *width = 0.01;
28: return 0;
29: }
31: static PetscErrorCode PetscDrawLine_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
32: {
33: return 0;
34: }
36: static PetscErrorCode PetscDrawArrow_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
37: {
38: return 0;
39: }
41: static PetscErrorCode PetscDrawRectangle_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
42: {
43: return 0;
44: }
46: static PetscErrorCode PetscDrawEllipse_Null(PetscDraw Win, PetscReal x, PetscReal y, PetscReal a, PetscReal b, int c)
47: {
48: return 0;
49: }
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: {
53: return 0;
54: }
56: static PetscErrorCode PetscDrawStringGetSize_Null(PetscDraw draw, PetscReal *x, PetscReal *y)
57: {
58: if (x) *x = 0.01;
59: if (y) *y = 0.01;
60: return 0;
61: }
63: static PetscErrorCode PetscDrawString_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[])
64: {
65: return 0;
66: }
68: static PetscErrorCode PetscDrawStringVertical_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[])
69: {
70: return 0;
71: }
73: static PetscErrorCode PetscDrawStringBoxed_Null(PetscDraw draw, PetscReal sxl, PetscReal syl, int sc, int bc, const char text[], PetscReal *w, PetscReal *h)
74: {
75: if (w) *w = 0.01;
76: if (h) *h = 0.01;
77: return 0;
78: }
80: static PetscErrorCode PetscDrawGetSingleton_Null(PetscDraw draw, PetscDraw *sdraw)
81: {
82: PetscDrawOpenNull(PETSC_COMM_SELF, sdraw);
83: return 0;
84: }
86: static PetscErrorCode PetscDrawRestoreSingleton_Null(PetscDraw draw, PetscDraw *sdraw)
87: {
88: PetscDrawDestroy(sdraw);
89: return 0;
90: }
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};
129: /*MC
130: PETSC_DRAW_NULL - PETSc graphics device that ignores all draw commands
132: Level: beginner
134: Note:
135: A `PETSC_DRAW_NULL` is useful in places where `PetscDraw` routines are called but no graphics window, for example, is available.
137: .seealso: `PetscDraw`, `PetscDrawOpenNull()`, `PETSC_DRAW_X`, `PetscDrawOpenNull()`, `PetscDrawIsNull()`
138: M*/
139: PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw);
141: PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
142: {
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: PetscDrawDestroy(&draw->popup);
154: PetscMemcpy(draw->ops, &DvOps, sizeof(DvOps));
155: draw->data = NULL;
156: return 0;
157: }
159: /*@
160: PetscDrawOpenNull - Opens a null drawing context. All draw commands to
161: it are ignored.
163: Input Parameter:
164: . comm - MPI communicator
166: Output Parameter:
167: . draw - the drawing context
169: Level: advanced
171: .seealso: `PetscDraw`, `PetscDrawIsNull()`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`, `PetscDrawIsNull()`
172: @*/
173: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm, PetscDraw *win)
174: {
175: PetscDrawCreate(comm, NULL, NULL, 0, 0, 1, 1, win);
176: PetscDrawSetType(*win, PETSC_DRAW_NULL);
177: return 0;
178: }
180: /*@
181: PetscDrawIsNull - Returns `PETSC_TRUE` if draw is a null draw object.
183: Not collective
185: Input Parameter:
186: . draw - the draw context
188: Output Parameter:
189: . yes - `PETSC_TRUE` if it is a null draw object; otherwise `PETSC_FALSE`
191: Level: advanced
193: .seealso: `PetscDraw`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`, `PetscDrawIsNull()`
194: @*/
195: PetscErrorCode PetscDrawIsNull(PetscDraw draw, PetscBool *yes)
196: {
199: PetscObjectTypeCompare((PetscObject)draw, PETSC_DRAW_NULL, yes);
200: return 0;
201: }