Actual source code: dline.c


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

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

 10:    Not collective

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

 15:    Output Parameters:
 16: .   xl,yl,xr,yr - coordinates of lower left and upper right corners of bounding box

 18:    Level: intermediate

 20: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawSetCurrentPoint()
 21: @*/
 22: PetscErrorCode  PetscDrawGetBoundingBox(PetscDraw draw,PetscReal *xl,PetscReal *yl,PetscReal *xr,PetscReal *yr)
 23: {
 30:   if (xl) *xl = draw->boundbox_xl;
 31:   if (yl) *yl = draw->boundbox_yl;
 32:   if (xr) *xr = draw->boundbox_xr;
 33:   if (yr) *yr = draw->boundbox_yr;
 34:   return(0);
 35: }

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

 40:    Not collective

 42:    Input Parameter:
 43: .  draw - the drawing context

 45:    Output Parameters:
 46: .   x,y - the current point

 48:    Level: intermediate

 50: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawSetCurrentPoint()
 51: @*/
 52: PetscErrorCode  PetscDrawGetCurrentPoint(PetscDraw draw,PetscReal *x,PetscReal *y)
 53: {
 58:   *x = draw->currentpoint_x[draw->currentpoint];
 59:   *y = draw->currentpoint_y[draw->currentpoint];
 60:   return(0);
 61: }

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

 66:    Not collective

 68:    Input Parameters:
 69: +  draw - the drawing context
 70: -  x,y - the location of the current point

 72:    Level: intermediate

 74: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawGetCurrentPoint()
 75: @*/
 76: PetscErrorCode  PetscDrawSetCurrentPoint(PetscDraw draw,PetscReal x,PetscReal y)
 77: {
 80:   draw->currentpoint_x[draw->currentpoint] = x;
 81:   draw->currentpoint_y[draw->currentpoint] = y;
 82:   return(0);
 83: }

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

 88:    Not collective

 90:    Input Parameters:
 91: +  draw - the drawing context
 92: -  x,y - the location of the current point

 94:    Level: intermediate

 96: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawPopCurrentPoint(), PetscDrawGetCurrentPoint()
 97: @*/
 98: PetscErrorCode  PetscDrawPushCurrentPoint(PetscDraw draw,PetscReal x,PetscReal y)
 99: {
102:   if (draw->currentpoint > 19) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You have pushed too many current points");
103:   draw->currentpoint_x[++draw->currentpoint] = x;
104:   draw->currentpoint_y[draw->currentpoint]   = y;
105:   return(0);
106: }

108: /*@
109:    PetscDrawPopCurrentPoint - Pops a current draw point (discarding it)

111:    Not collective

113:    Input Parameter:
114: .  draw - the drawing context

116:    Level: intermediate

118: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawSetCurrentPoint(), PetscDrawGetCurrentPoint()
119: @*/
120: PetscErrorCode  PetscDrawPopCurrentPoint(PetscDraw draw)
121: {
124:   if (draw->currentpoint-- == 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You have popped too many current points");
125:   return(0);
126: }

128: /*@
129:    PetscDrawLine - PetscDraws a line onto a drawable.

131:    Not collective

133:    Input Parameters:
134: +  draw - the drawing context
135: .  xl,yl,xr,yr - the coordinates of the line endpoints
136: -  cl - the colors of the endpoints

138:    Level: beginner

140: .seealso: PetscDrawArrow(), PetscDrawLineSetWidth(), PetscDrawLineGetWidth(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(),
141:           PetscDrawMarker(), PetscDrawPoint()

143: @*/
144: PetscErrorCode  PetscDrawLine(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
145: {

150:   if (!draw->ops->line) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing lines",((PetscObject)draw)->type_name);
151:   (*draw->ops->line)(draw,xl,yl,xr,yr,cl);
152:   return(0);
153: }

155: /*@
156:    PetscDrawArrow - PetscDraws a line with arrow head at end if the line is long enough

158:    Not collective

160:    Input Parameters:
161: +  draw - the drawing context
162: .  xl,yl,xr,yr - the coordinates of the line endpoints
163: -  cl - the colors of the endpoints

165:    Level: beginner

167: .seealso: PetscDrawLine(), PetscDrawLineSetWidth(), PetscDrawLineGetWidth(), PetscDrawRectangle(), PetscDrawTriangle(), PetscDrawEllipse(),
168:           PetscDrawMarker(), PetscDrawPoint()

170: @*/
171: PetscErrorCode  PetscDrawArrow(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
172: {

177:   if (!draw->ops->arrow) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"This draw type %s does not support drawing arrows",((PetscObject)draw)->type_name);
178:   (*draw->ops->arrow)(draw,xl,yl,xr,yr,cl);
179:   return(0);
180: }

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

187:    Not collective

189:    Input Parameters:
190: +  draw - the drawing context
191: -  width - the width in user coordinates

193:    Level: advanced

195: .seealso:  PetscDrawLineGetWidth(), PetscDrawLine(), PetscDrawArrow()
196: @*/
197: PetscErrorCode  PetscDrawLineSetWidth(PetscDraw draw,PetscReal width)
198: {

203:   if (draw->ops->linesetwidth) {
204:     (*draw->ops->linesetwidth)(draw,width);
205:   }
206:   return(0);
207: }

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.

214:    Not collective

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

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

222:    Level: advanced

224:    Notes:
225:    Not currently implemented.

227: .seealso:  PetscDrawLineSetWidth(), PetscDrawLine(), PetscDrawArrow()
228: @*/
229: PetscErrorCode  PetscDrawLineGetWidth(PetscDraw draw,PetscReal *width)
230: {

236:   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);
237:   (*draw->ops->linegetwidth)(draw,width);
238:   return(0);
239: }