Actual source code: dline.c

  1: /*
  2:        Provides the calling sequences for all the basic PetscDraw routines.
  3: */
  4: #include <petsc/private/drawimpl.h>

  6: /*@
  7:   PetscDrawGetBoundingBox - Gets the bounding box of all `PetscDrawStringBoxed()` commands

  9:   Not Collective

 11:   Input Parameter:
 12: . draw - the drawing context

 14:   Output Parameters:
 15: + xl - horizontal coordinate of lower left corner of bounding box
 16: . yl - vertical coordinate of lower left corner of bounding box
 17: . xr - horizontal coordinate of upper right corner of bounding box
 18: - yr - vertical coordinate of upper right corner of bounding box

 20:   Level: intermediate

 22: .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawSetCurrentPoint()`
 23: @*/
 24: PetscErrorCode PetscDrawGetBoundingBox(PetscDraw draw, PetscReal *xl, PetscReal *yl, PetscReal *xr, PetscReal *yr)
 25: {
 26:   PetscFunctionBegin;
 28:   if (xl) PetscAssertPointer(xl, 2);
 29:   if (yl) PetscAssertPointer(yl, 3);
 30:   if (xr) PetscAssertPointer(xr, 4);
 31:   if (yr) PetscAssertPointer(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(PETSC_SUCCESS);
 37: }

 39: /*@
 40:   PetscDrawGetCurrentPoint - Gets the current draw point, some codes use this point to determine where to draw next

 42:   Not Collective

 44:   Input Parameter:
 45: . draw - the drawing context

 47:   Output Parameters:
 48: + x - horizontal coordinate of the current point
 49: - y - vertical coordinate of the current point

 51:   Level: intermediate

 53: .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawSetCurrentPoint()`
 54: @*/
 55: PetscErrorCode PetscDrawGetCurrentPoint(PetscDraw draw, PetscReal *x, PetscReal *y)
 56: {
 57:   PetscFunctionBegin;
 59:   PetscAssertPointer(x, 2);
 60:   PetscAssertPointer(y, 3);
 61:   *x = draw->currentpoint_x[draw->currentpoint];
 62:   *y = draw->currentpoint_y[draw->currentpoint];
 63:   PetscFunctionReturn(PETSC_SUCCESS);
 64: }

 66: /*@
 67:   PetscDrawSetCurrentPoint - Sets the current draw point, some codes use this point to determine where to draw next

 69:   Not Collective

 71:   Input Parameters:
 72: + draw - the drawing context
 73: . x    - horizontal coordinate of the current point
 74: - y    - vertical coordinate of the current point

 76:   Level: intermediate

 78: .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawPopCurrentPoint()`, `PetscDrawGetCurrentPoint()`
 79: @*/
 80: PetscErrorCode PetscDrawSetCurrentPoint(PetscDraw draw, PetscReal x, PetscReal y)
 81: {
 82:   PetscFunctionBegin;
 84:   draw->currentpoint_x[draw->currentpoint] = x;
 85:   draw->currentpoint_y[draw->currentpoint] = y;
 86:   PetscFunctionReturn(PETSC_SUCCESS);
 87: }

 89: /*@
 90:   PetscDrawPushCurrentPoint - Pushes a new current draw point, retaining the old one, some codes use this point to determine where to draw next

 92:   Not Collective

 94:   Input Parameters:
 95: + draw - the drawing context
 96: . x    - horizontal coordinate of the current point
 97: - y    - vertical coordinate of the current point

 99:   Level: intermediate

101: .seealso: `PetscDraw`, `PetscDrawPopCurrentPoint()`, `PetscDrawGetCurrentPoint()`
102: @*/
103: PetscErrorCode PetscDrawPushCurrentPoint(PetscDraw draw, PetscReal x, PetscReal y)
104: {
105:   PetscFunctionBegin;
107:   PetscCheck(draw->currentpoint <= 19, PETSC_COMM_SELF, PETSC_ERR_SUP, "You have pushed too many current points");
108:   draw->currentpoint_x[++draw->currentpoint] = x;
109:   draw->currentpoint_y[draw->currentpoint]   = y;
110:   PetscFunctionReturn(PETSC_SUCCESS);
111: }

113: /*@
114:   PetscDrawPopCurrentPoint - Pops a current draw point (discarding it)

116:   Not Collective

118:   Input Parameter:
119: . draw - the drawing context

121:   Level: intermediate

123: .seealso: `PetscDraw`, `PetscDrawPushCurrentPoint()`, `PetscDrawSetCurrentPoint()`, `PetscDrawGetCurrentPoint()`
124: @*/
125: PetscErrorCode PetscDrawPopCurrentPoint(PetscDraw draw)
126: {
127:   PetscFunctionBegin;
129:   PetscCheck(draw->currentpoint-- > 0, PETSC_COMM_SELF, PETSC_ERR_SUP, "You have popped too many current points");
130:   PetscFunctionReturn(PETSC_SUCCESS);
131: }

133: /*@
134:   PetscDrawLine - draws a line onto a drawable.

136:   Not Collective

138:   Input Parameters:
139: + draw - the drawing context
140: . xl   - horizontal coordinate of first end point
141: . yl   - vertical coordinate of first end point
142: . xr   - horizontal coordinate of second end point
143: . yr   - vertical coordinate of second end point
144: - cl   - the colors of the endpoints

146:   Level: beginner

148: .seealso: `PetscDraw`, `PetscDrawArrow()`, `PetscDrawLineSetWidth()`, `PetscDrawLineGetWidth()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
149:           `PetscDrawMarker()`, `PetscDrawPoint()`
150: @*/
151: PetscErrorCode PetscDrawLine(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
152: {
153:   PetscFunctionBegin;
155:   PetscUseTypeMethod(draw, line, xl, yl, xr, yr, cl);
156:   PetscFunctionReturn(PETSC_SUCCESS);
157: }

159: /*@
160:   PetscDrawArrow - draws a line with arrow head at end if the line is long enough

162:   Not Collective

164:   Input Parameters:
165: + draw - the drawing context
166: . xl   - horizontal coordinate of first end point
167: . yl   - vertical coordinate of first end point
168: . xr   - horizontal coordinate of second end point
169: . yr   - vertical coordinate of second end point
170: - cl   - the colors of the endpoints

172:   Level: beginner

174: .seealso: `PetscDraw`, `PetscDrawLine()`, `PetscDrawLineSetWidth()`, `PetscDrawLineGetWidth()`, `PetscDrawRectangle()`, `PetscDrawTriangle()`, `PetscDrawEllipse()`,
175:           `PetscDrawMarker()`, `PetscDrawPoint()`
176: @*/
177: PetscErrorCode PetscDrawArrow(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
178: {
179:   PetscFunctionBegin;
181:   PetscUseTypeMethod(draw, arrow, xl, yl, xr, yr, cl);
182:   PetscFunctionReturn(PETSC_SUCCESS);
183: }

185: /*@
186:   PetscDrawLineSetWidth - Sets the line width for future draws.  The width is
187:   relative to the user coordinates of the window; 0.0 denotes the natural
188:   width; 1.0 denotes the entire viewport.

190:   Not Collective

192:   Input Parameters:
193: + draw  - the drawing context
194: - width - the width in user coordinates

196:   Level: advanced

198: .seealso: `PetscDraw`, `PetscDrawLineGetWidth()`, `PetscDrawLine()`, `PetscDrawArrow()`
199: @*/
200: PetscErrorCode PetscDrawLineSetWidth(PetscDraw draw, PetscReal width)
201: {
202:   PetscFunctionBegin;
204:   PetscTryTypeMethod(draw, linesetwidth, width);
205:   PetscFunctionReturn(PETSC_SUCCESS);
206: }

208: /*@
209:   PetscDrawLineGetWidth - Gets the line width for future draws.  The width is
210:   relative to the user coordinates of the window; 0.0 denotes the natural
211:   width; 1.0 denotes the interior viewport.

213:   Not Collective

215:   Input Parameter:
216: . draw - the drawing context

218:   Output Parameter:
219: . width - the width in user coordinates

221:   Level: advanced

223:   Note:
224:   Not currently implemented.

226: .seealso: `PetscDraw`, `PetscDrawLineSetWidth()`, `PetscDrawLine()`, `PetscDrawArrow()`
227: @*/
228: PetscErrorCode PetscDrawLineGetWidth(PetscDraw draw, PetscReal *width)
229: {
230:   PetscFunctionBegin;
232:   PetscAssertPointer(width, 2);
233:   PetscUseTypeMethod(draw, linegetwidth, width);
234:   PetscFunctionReturn(PETSC_SUCCESS);
235: }