xref: /petsc/src/sys/classes/draw/impls/null/drawnull.c (revision 58d68138c660dfb4e9f5b03334792cd4f2ffd7cc)
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 .seealso: `PetscDrawOpenNull()`, `PetscDrawIsNull()`
135 M*/
136 PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw);
137 
138 PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw) {
139   PetscFunctionBegin;
140   draw->pause   = 0;
141   draw->coor_xl = 0;
142   draw->coor_xr = 1;
143   draw->coor_yl = 0;
144   draw->coor_yr = 1;
145   draw->port_xl = 0;
146   draw->port_xr = 1;
147   draw->port_yl = 0;
148   draw->port_yr = 1;
149   PetscCall(PetscDrawDestroy(&draw->popup));
150 
151   PetscCall(PetscMemcpy(draw->ops, &DvOps, sizeof(DvOps)));
152   draw->data = NULL;
153   PetscFunctionReturn(0);
154 }
155 
156 /*@
157    PetscDrawOpenNull - Opens a null drawing context. All draw commands to
158    it are ignored.
159 
160    Input Parameter:
161 .  comm - MPI communicator
162 
163    Output Parameter:
164 .  draw - the drawing context
165 
166    Level: advanced
167 @*/
168 PetscErrorCode PetscDrawOpenNull(MPI_Comm comm, PetscDraw *win) {
169   PetscFunctionBegin;
170   PetscCall(PetscDrawCreate(comm, NULL, NULL, 0, 0, 1, 1, win));
171   PetscCall(PetscDrawSetType(*win, PETSC_DRAW_NULL));
172   PetscFunctionReturn(0);
173 }
174 
175 /*@
176    PetscDrawIsNull - Returns PETSC_TRUE if draw is a null draw object.
177 
178    Not collective
179 
180    Input Parameter:
181 .  draw - the draw context
182 
183    Output Parameter:
184 .  yes - PETSC_TRUE if it is a null draw object; otherwise PETSC_FALSE
185 
186    Level: advanced
187 @*/
188 PetscErrorCode PetscDrawIsNull(PetscDraw draw, PetscBool *yes) {
189   PetscFunctionBegin;
190   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
191   PetscValidBoolPointer(yes, 2);
192   PetscCall(PetscObjectTypeCompare((PetscObject)draw, PETSC_DRAW_NULL, yes));
193   PetscFunctionReturn(0);
194 }
195