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