Actual source code: dline.c

petsc-3.5.0 2014-06-30
Report Typos and Errors
  2: /*
  3:        Provides the calling sequences for all the basic PetscDraw routines.
  4: */
  5: #include <petsc-private/drawimpl.h>  /*I "petscdraw.h" I*/

  9: /*@
 10:    PetscDrawGetBoundingBox - Gets the bounding box of all PetscDrawBoxedString() commands

 12:    Not collective

 14:    Input Parameter:
 15: .  draw - the drawing context

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

 20:    Level: intermediate

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

 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: {
 56:   *x = draw->currentpoint_x[draw->currentpoint];
 57:   *y = draw->currentpoint_y[draw->currentpoint];
 58:   return(0);
 59: }

 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: }

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

 90:    Not collective

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

 96:    Level: intermediate

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

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

115:    Not collective

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

120:    Level: intermediate

122: .seealso:  PetscDrawPushCurrentPoint(), PetscDrawSetCurrentPoint(), PetscDrawGetCurrentPoint()
123: @*/
124: PetscErrorCode  PetscDrawPopCurrentPoint(PetscDraw draw)
125: {
128:   if (draw->currentpoint-- == 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"You have popped too many current points");
129:   return(0);
130: }

134: /*@
135:    PetscDrawLine - PetscDraws a line onto a drawable.

137:    Not collective

139:    Input Parameters:
140: +  draw - the drawing context
141: .  xl,yl,xr,yr - the coordinates of the line endpoints
142: -  cl - the colors of the endpoints

144:    Level: beginner

146:    Concepts: line^drawing
147:    Concepts: drawing^line

149: @*/
150: PetscErrorCode  PetscDrawLine(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
151: {
153:   PetscBool      isdrawnull;

157:   PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isdrawnull);
158:   if (isdrawnull) return(0);
159:   if (!draw->ops->line) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_SUP,"No support for drawing lines");
160:   (*draw->ops->line)(draw,xl,yl,xr,yr,cl);
161:   return(0);
162: }

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

169:    Not collective

171:    Input Parameters:
172: +  draw - the drawing context
173: .  xl,yl,xr,yr - the coordinates of the line endpoints
174: -  cl - the colors of the endpoints

176:    Level: beginner

178:    Concepts: line^drawing
179:    Concepts: drawing^line

181: @*/
182: PetscErrorCode  PetscDrawArrow(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr,int cl)
183: {
185:   PetscBool      isdrawnull;

189:   PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isdrawnull);
190:   if (isdrawnull) return(0);
191:   if (!draw->ops->arrow) SETERRQ(PetscObjectComm((PetscObject)draw),PETSC_ERR_SUP,"No support for drawing arrows");
192:   (*draw->ops->arrow)(draw,xl,yl,xr,yr,cl);
193:   return(0);
194: }