xref: /petsc/src/sys/classes/draw/interface/dline.c (revision 9be3f403e6dfdc4afd0fa2e761af1e0cdbb5f7f2)
1 
2 /*
3        Provides the calling sequences for all the basic PetscDraw routines.
4 */
5 #include <petsc/private/drawimpl.h>  /*I "petscdraw.h" I*/
6 
7 #undef __FUNCT__
8 #define __FUNCT__ "PetscDrawGetBoundingBox"
9 /*@
10    PetscDrawGetBoundingBox - Gets the bounding box of all PetscDrawStringBoxed() commands
11 
12    Not collective
13 
14    Input Parameter:
15 .  draw - the drawing context
16 
17    Output Parameters:
18 .   xl,yl,xr,yr - coordinates of lower left and upper right corners of bounding box
19 
20    Level: intermediate
21 
22 .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawSetCurrentPoint()
23 @*/
24 PetscErrorCode  PetscDrawGetBoundingBox(PetscDraw draw,PetscReal *xl,PetscReal *yl,PetscReal *xr,PetscReal *yr)
25 {
26   PetscFunctionBegin;
27   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
28   if (xl) PetscValidRealPointer(xl,2);
29   if (yl) PetscValidRealPointer(yl,3);
30   if (xr) PetscValidRealPointer(xr,4);
31   if (yr) PetscValidRealPointer(yr,5);
32   if (xl) *xl = draw->boundbox_xl;
33   if (yl) *yl = draw->boundbox_yl;
34   if (xr) *xr = draw->boundbox_xr;
35   if (yr) *yr = draw->boundbox_yr;
36   PetscFunctionReturn(0);
37 }
38 
39 #undef __FUNCT__
40 #define __FUNCT__ "PetscDrawGetCurrentPoint"
41 /*@
42    PetscDrawGetCurrentPoint - Gets the current draw point, some codes use this point to determine where to draw next
43 
44    Not collective
45 
46    Input Parameter:
47 .  draw - the drawing context
48 
49    Output Parameters:
50 .   x,y - the current point
51 
52    Level: intermediate
53 
54 .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawSetCurrentPoint()
55 @*/
56 PetscErrorCode  PetscDrawGetCurrentPoint(PetscDraw draw,PetscReal *x,PetscReal *y)
57 {
58   PetscFunctionBegin;
59   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
60   PetscValidRealPointer(x,2);
61   PetscValidRealPointer(y,3);
62   *x = draw->currentpoint_x[draw->currentpoint];
63   *y = draw->currentpoint_y[draw->currentpoint];
64   PetscFunctionReturn(0);
65 }
66 
67 #undef __FUNCT__
68 #define __FUNCT__ "PetscDrawSetCurrentPoint"
69 /*@
70    PetscDrawSetCurrentPoint - Sets the current draw point, some codes use this point to determine where to draw next
71 
72    Not collective
73 
74    Input Parameters:
75 +  draw - the drawing context
76 -  x,y - the location of the current point
77 
78    Level: intermediate
79 
80 .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawGetCurrentPoint()
81 @*/
82 PetscErrorCode  PetscDrawSetCurrentPoint(PetscDraw draw,PetscReal x,PetscReal y)
83 {
84   PetscFunctionBegin;
85   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
86   draw->currentpoint_x[draw->currentpoint] = x;
87   draw->currentpoint_y[draw->currentpoint] = y;
88   PetscFunctionReturn(0);
89 }
90 
91 #undef __FUNCT__
92 #define __FUNCT__ "PetscDrawPushCurrentPoint"
93 /*@
94    PetscDrawPushCurrentPoint - Pushes a new current draw point, retaining the old one, some codes use this point to determine where to draw next
95 
96    Not collective
97 
98    Input Parameters:
99 +  draw - the drawing context
100 -  x,y - the location of the current point
101 
102    Level: intermediate
103 
104 .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawGetCurrentPoint()
105 @*/
106 PetscErrorCode  PetscDrawPushCurrentPoint(PetscDraw draw,PetscReal x,PetscReal y)
107 {
108   PetscFunctionBegin;
109   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
110   if (draw->currentpoint > 19) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You have pushed too many current points");
111   draw->currentpoint_x[++draw->currentpoint] = x;
112   draw->currentpoint_y[draw->currentpoint]   = y;
113   PetscFunctionReturn(0);
114 }
115 
116 #undef __FUNCT__
117 #define __FUNCT__ "PetscDrawPopCurrentPoint"
118 /*@
119    PetscDrawPopCurrentPoint - Pops a current draw point (discarding it)
120 
121    Not collective
122 
123    Input Parameter:
124 .  draw - the drawing context
125 
126    Level: intermediate
127 
128 .seealso:  PetscDrawPushCurrentPoint(), PetscDrawSetCurrentPoint(), PetscDrawGetCurrentPoint()
129 @*/
130 PetscErrorCode  PetscDrawPopCurrentPoint(PetscDraw draw)
131 {
132   PetscFunctionBegin;
133   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
134   if (draw->currentpoint-- == 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You have popped too many current points");
135   PetscFunctionReturn(0);
136 }
137 
138 #undef __FUNCT__
139 #define __FUNCT__ "PetscDrawLine"
140 /*@
141    PetscDrawLine - PetscDraws a line onto a drawable.
142 
143    Not collective
144 
145    Input Parameters:
146 +  draw - the drawing context
147 .  xl,yl,xr,yr - the coordinates of the line endpoints
148 -  cl - the colors of the endpoints
149 
150    Level: beginner
151 
152    Concepts: line^drawing
153    Concepts: drawing^line
154 
155 @*/
156 PetscErrorCode  PetscDrawLine(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
157 {
158   PetscErrorCode ierr;
159 
160   PetscFunctionBegin;
161   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
162   if (!draw->ops->line) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing lines",((PetscObject)draw)->type_name);
163   ierr = (*draw->ops->line)(draw,xl,yl,xr,yr,cl);CHKERRQ(ierr);
164   PetscFunctionReturn(0);
165 }
166 
167 #undef __FUNCT__
168 #define __FUNCT__ "PetscDrawArrow"
169 /*@
170    PetscDrawArrow - PetscDraws a line with arrow head at end if the line is long enough
171 
172    Not collective
173 
174    Input Parameters:
175 +  draw - the drawing context
176 .  xl,yl,xr,yr - the coordinates of the line endpoints
177 -  cl - the colors of the endpoints
178 
179    Level: beginner
180 
181    Concepts: line^drawing
182    Concepts: drawing^line
183 
184 @*/
185 PetscErrorCode  PetscDrawArrow(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
186 {
187   PetscErrorCode ierr;
188 
189   PetscFunctionBegin;
190   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
191   if (!draw->ops->arrow) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing arrows",((PetscObject)draw)->type_name);
192   ierr = (*draw->ops->arrow)(draw,xl,yl,xr,yr,cl);CHKERRQ(ierr);
193   PetscFunctionReturn(0);
194 }
195 
196 #undef __FUNCT__
197 #define __FUNCT__ "PetscDrawLineSetWidth"
198 /*@
199    PetscDrawLineSetWidth - Sets the line width for future draws.  The width is
200    relative to the user coordinates of the window; 0.0 denotes the natural
201    width; 1.0 denotes the entire viewport.
202 
203    Not collective
204 
205    Input Parameters:
206 +  draw - the drawing context
207 -  width - the width in user coordinates
208 
209    Level: advanced
210 
211    Concepts: line^width
212 
213 .seealso:  PetscDrawLineGetWidth()
214 @*/
215 PetscErrorCode  PetscDrawLineSetWidth(PetscDraw draw,PetscReal width)
216 {
217   PetscErrorCode ierr;
218 
219   PetscFunctionBegin;
220   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
221   if (draw->ops->linesetwidth) {
222     ierr = (*draw->ops->linesetwidth)(draw,width);CHKERRQ(ierr);
223   }
224   PetscFunctionReturn(0);
225 }
226 
227 #undef __FUNCT__
228 #define __FUNCT__ "PetscDrawLineGetWidth"
229 /*@
230    PetscDrawLineGetWidth - Gets the line width for future draws.  The width is
231    relative to the user coordinates of the window; 0.0 denotes the natural
232    width; 1.0 denotes the interior viewport.
233 
234    Not collective
235 
236    Input Parameter:
237 .  draw - the drawing context
238 
239    Output Parameter:
240 .  width - the width in user coordinates
241 
242    Level: advanced
243 
244    Notes:
245    Not currently implemented.
246 
247    Concepts: line^width
248 
249 .seealso:  PetscDrawLineSetWidth()
250 @*/
251 PetscErrorCode  PetscDrawLineGetWidth(PetscDraw draw,PetscReal *width)
252 {
253   PetscErrorCode ierr;
254 
255   PetscFunctionBegin;
256   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
257   PetscValidScalarPointer(width,2);
258   if (!draw->ops->linegetwidth) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support getting line width",((PetscObject)draw)->type_name);
259   ierr = (*draw->ops->linegetwidth)(draw,width);CHKERRQ(ierr);
260   PetscFunctionReturn(0);
261 }
262 
263