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