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