xref: /petsc/src/sys/classes/draw/interface/dline.c (revision 3872ee93fc6fc5dd06e57f8e7b2853c37bc1be92)
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 /*@
8    PetscDrawGetBoundingBox - Gets the bounding box of all `PetscDrawStringBoxed()` commands
9 
10    Not Collective
11 
12    Input Parameter:
13 .  draw - the drawing context
14 
15    Output Parameters:
16 +   xl - horizontal coordinate of lower left corner of bounding box
17 .   yl - vertical coordinate of lower left corner of bounding box
18 .   xr - horizontal coordinate of upper right corner of bounding box
19 -   yr - vertical coordinate of upper right corner of bounding box
20 
21    Level: intermediate
22 
23 .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawSetCurrentPoint()`
24 @*/
25 PetscErrorCode PetscDrawGetBoundingBox(PetscDraw draw, PetscReal *xl, PetscReal *yl, PetscReal *xr, PetscReal *yr)
26 {
27   PetscFunctionBegin;
28   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
29   if (xl) PetscValidRealPointer(xl, 2);
30   if (yl) PetscValidRealPointer(yl, 3);
31   if (xr) PetscValidRealPointer(xr, 4);
32   if (yr) PetscValidRealPointer(yr, 5);
33   if (xl) *xl = draw->boundbox_xl;
34   if (yl) *yl = draw->boundbox_yl;
35   if (xr) *xr = draw->boundbox_xr;
36   if (yr) *yr = draw->boundbox_yr;
37   PetscFunctionReturn(PETSC_SUCCESS);
38 }
39 
40 /*@
41    PetscDrawGetCurrentPoint - Gets the current draw point, some codes use this point to determine where to draw next
42 
43    Not Collective
44 
45    Input Parameter:
46 .  draw - the drawing context
47 
48    Output Parameters:
49 +   x - horizontal coordinate of the current point
50 -   y - vertical coordinate of the current point
51 
52    Level: intermediate
53 
54 .seealso: `PetscDraw`, `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(PETSC_SUCCESS);
65 }
66 
67 /*@
68    PetscDrawSetCurrentPoint - Sets the current draw point, some codes use this point to determine where to draw next
69 
70    Not Collective
71 
72    Input Parameters:
73 +  draw - the drawing context
74 .   x - horizontal coordinate of the current point
75 -   y - vertical coordinate of the current point
76 
77    Level: intermediate
78 
79 .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawGetCurrentPoint()`
80 @*/
81 PetscErrorCode PetscDrawSetCurrentPoint(PetscDraw draw, PetscReal x, PetscReal y)
82 {
83   PetscFunctionBegin;
84   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
85   draw->currentpoint_x[draw->currentpoint] = x;
86   draw->currentpoint_y[draw->currentpoint] = y;
87   PetscFunctionReturn(PETSC_SUCCESS);
88 }
89 
90 /*@
91    PetscDrawPushCurrentPoint - Pushes a new current draw point, retaining the old one, some codes use this point to determine where to draw next
92 
93    Not Collective
94 
95    Input Parameters:
96 +  draw - the drawing context
97 .   x - horizontal coordinate of the current point
98 -   y - vertical coordinate of the current point
99 
100    Level: intermediate
101 
102 .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawGetCurrentPoint()`
103 @*/
104 PetscErrorCode PetscDrawPushCurrentPoint(PetscDraw draw, PetscReal x, PetscReal y)
105 {
106   PetscFunctionBegin;
107   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
108   PetscCheck(draw->currentpoint <= 19, PETSC_COMM_SELF, PETSC_ERR_SUP, "You have pushed too many current points");
109   draw->currentpoint_x[++draw->currentpoint] = x;
110   draw->currentpoint_y[draw->currentpoint]   = y;
111   PetscFunctionReturn(PETSC_SUCCESS);
112 }
113 
114 /*@
115    PetscDrawPopCurrentPoint - Pops a current draw point (discarding it)
116 
117    Not Collective
118 
119    Input Parameter:
120 .  draw - the drawing context
121 
122    Level: intermediate
123 
124 .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawSetCurrentPoint()`, `PetscDrawGetCurrentPoint()`
125 @*/
126 PetscErrorCode PetscDrawPopCurrentPoint(PetscDraw draw)
127 {
128   PetscFunctionBegin;
129   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
130   PetscCheck(draw->currentpoint-- > 0, PETSC_COMM_SELF, PETSC_ERR_SUP, "You have popped too many current points");
131   PetscFunctionReturn(PETSC_SUCCESS);
132 }
133 
134 /*@
135    PetscDrawLine - draws a line onto a drawable.
136 
137    Not Collective
138 
139    Input Parameters:
140 +  draw - the drawing context
141 .  xl - horizontal coordinate of first end point
142 .  yl - vertical coordinate of first end point
143 .  xr - horizontal coordinate of second end point
144 .  yr - vertical coordinate of second end point
145 -  cl - the colors of the endpoints
146 
147    Level: beginner
148 
149 .seealso: `PetscDraw`, `PetscDrawArrow()`, `PetscDrawLineSetWidth()`, `PetscDrawLineGetWidth()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
150           `PetscDrawMarker()`, `PetscDrawPoint()`
151 @*/
152 PetscErrorCode PetscDrawLine(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
153 {
154   PetscFunctionBegin;
155   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
156   PetscUseTypeMethod(draw, line, xl, yl, xr, yr, cl);
157   PetscFunctionReturn(PETSC_SUCCESS);
158 }
159 
160 /*@
161    PetscDrawArrow - draws a line with arrow head at end if the line is long enough
162 
163    Not Collective
164 
165    Input Parameters:
166 +  draw - the drawing context
167 .  xl - horizontal coordinate of first end point
168 .  yl - vertical coordinate of first end point
169 .  xr - horizontal coordinate of second end point
170 .  yr - vertical coordinate of second end point
171 -  cl - the colors of the endpoints
172 
173    Level: beginner
174 
175 .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawLineSetWidth()`, `PetscDrawLineGetWidth()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
176           `PetscDrawMarker()`, `PetscDrawPoint()`
177 @*/
178 PetscErrorCode PetscDrawArrow(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
179 {
180   PetscFunctionBegin;
181   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
182   PetscUseTypeMethod(draw, arrow, xl, yl, xr, yr, cl);
183   PetscFunctionReturn(PETSC_SUCCESS);
184 }
185 
186 /*@
187    PetscDrawLineSetWidth - Sets the line width for future draws.  The width is
188    relative to the user coordinates of the window; 0.0 denotes the natural
189    width; 1.0 denotes the entire viewport.
190 
191    Not Collective
192 
193    Input Parameters:
194 +  draw - the drawing context
195 -  width - the width in user coordinates
196 
197    Level: advanced
198 
199 .seealso: `PetscDraw`, `PetscDrawLineGetWidth()`, `PetscDrawLine()`, `PetscDrawArrow()`
200 @*/
201 PetscErrorCode PetscDrawLineSetWidth(PetscDraw draw, PetscReal width)
202 {
203   PetscFunctionBegin;
204   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
205   PetscTryTypeMethod(draw, linesetwidth, width);
206   PetscFunctionReturn(PETSC_SUCCESS);
207 }
208 
209 /*@
210    PetscDrawLineGetWidth - Gets the line width for future draws.  The width is
211    relative to the user coordinates of the window; 0.0 denotes the natural
212    width; 1.0 denotes the interior viewport.
213 
214    Not Collective
215 
216    Input Parameter:
217 .  draw - the drawing context
218 
219    Output Parameter:
220 .  width - the width in user coordinates
221 
222    Level: advanced
223 
224    Note:
225    Not currently implemented.
226 
227 .seealso: `PetscDraw`, `PetscDrawLineSetWidth()`, `PetscDrawLine()`, `PetscDrawArrow()`
228 @*/
229 PetscErrorCode PetscDrawLineGetWidth(PetscDraw draw, PetscReal *width)
230 {
231   PetscFunctionBegin;
232   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
233   PetscValidRealPointer(width, 2);
234   PetscUseTypeMethod(draw, linegetwidth, width);
235   PetscFunctionReturn(PETSC_SUCCESS);
236 }
237