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