xref: /petsc/src/sys/classes/draw/interface/dmarker.c (revision ff87db43c5082475ccdd828c5a732608447f441c)
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 const char *const PetscDrawMarkerTypes[] = {"CROSS", "POINT", "PLUS", "CIRCLE", "PetscDrawMarkerType", "PETSC_DRAW_MARKER_", NULL};
7 
8 /*@
9    PetscDrawMarker - draws a marker onto a drawable.
10 
11    Not collective
12 
13    Input Parameters:
14 +  draw - the drawing context
15 .  xl,yl - the coordinates of the marker
16 -  cl - the color of the marker
17 
18    Level: beginner
19 
20 .seealso: `PetscDraw`, `PetscDrawPoint()`, `PetscDrawString()`, `PetscDrawSetMarkerType()`, `PetscDrawGetMarkerType()`
21 @*/
22 PetscErrorCode PetscDrawMarker(PetscDraw draw, PetscReal xl, PetscReal yl, int cl) {
23   PetscFunctionBegin;
24   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
25   if (draw->markertype == PETSC_DRAW_MARKER_CROSS) {
26     if (draw->ops->coordinatetopixel && draw->ops->pointpixel) {
27       int i, j, k;
28       PetscUseTypeMethod(draw, coordinatetopixel, xl, yl, &i, &j);
29       for (k = -2; k <= 2; k++) {
30         PetscCall((*draw->ops->pointpixel)(draw, i + k, j + k, cl));
31         PetscCall((*draw->ops->pointpixel)(draw, i + k, j - k, cl));
32       }
33     } else PetscUseTypeMethod(draw, string, xl, yl, cl, "x");
34   } else if (draw->markertype == PETSC_DRAW_MARKER_PLUS) {
35     if (draw->ops->coordinatetopixel && draw->ops->pointpixel) {
36       int i, j, k;
37       PetscUseTypeMethod(draw, coordinatetopixel, xl, yl, &i, &j);
38       for (k = -2; k <= 2; k++) {
39         PetscCall((*draw->ops->pointpixel)(draw, i, j + k, cl));
40         PetscCall((*draw->ops->pointpixel)(draw, i + k, j, cl));
41       }
42     } else PetscUseTypeMethod(draw, string, xl, yl, cl, "+");
43   } else if (draw->markertype == PETSC_DRAW_MARKER_CIRCLE) {
44     if (draw->ops->coordinatetopixel && draw->ops->pointpixel) {
45       int i, j, k;
46       PetscUseTypeMethod(draw, coordinatetopixel, xl, yl, &i, &j);
47       for (k = -1; k <= 1; k++) {
48         PetscCall((*draw->ops->pointpixel)(draw, i + 2, j + k, cl));
49         PetscCall((*draw->ops->pointpixel)(draw, i - 2, j + k, cl));
50         PetscCall((*draw->ops->pointpixel)(draw, i + k, j + 2, cl));
51         PetscCall((*draw->ops->pointpixel)(draw, i + k, j - 2, cl));
52       }
53     } else PetscUseTypeMethod(draw, string, xl, yl, cl, "+");
54   } else PetscUseTypeMethod(draw, point, xl, yl, cl);
55   PetscFunctionReturn(0);
56 }
57 
58 /*@
59    PetscDrawSetMarkerType - sets the type of marker to display with `PetscDrawMarker()`
60 
61    Not collective
62 
63    Input Parameters:
64 +  draw - the drawing context
65 -  mtype - either `PETSC_DRAW_MARKER_CROSS` (default) or `PETSC_DRAW_MARKER_POINT`
66 
67    Options Database Key:
68 .  -draw_marker_type - x or point
69 
70    Level: beginner
71 
72 .seealso: `PetscDraw`, `PetscDrawPoint()`, `PetscDrawMarker()`, `PetscDrawGetMarkerType()`, `PetscDrawMarkerType`
73 @*/
74 PetscErrorCode PetscDrawSetMarkerType(PetscDraw draw, PetscDrawMarkerType mtype) {
75   PetscFunctionBegin;
76   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
77   draw->markertype = mtype;
78   PetscFunctionReturn(0);
79 }
80 
81 /*@
82    PetscDrawGetMarkerType - gets the type of marker to display with `PetscDrawMarker()`
83 
84    Not collective
85 
86    Input Parameters:
87 +  draw - the drawing context
88 -  mtype - either `PETSC_DRAW_MARKER_CROSS` (default) or `PETSC_DRAW_MARKER_POINT`
89 
90    Level: beginner
91 
92 .seealso: `PetscDraw`, `PetscDrawPoint()`, `PetscDrawMarker()`, `PetscDrawSetMarkerType()`, `PetscDrawMarkerType`
93 @*/
94 PetscErrorCode PetscDrawGetMarkerType(PetscDraw draw, PetscDrawMarkerType *mtype) {
95   PetscFunctionBegin;
96   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID, 1);
97   *mtype = draw->markertype;
98   PetscFunctionReturn(0);
99 }
100