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