Date: 2025-03-29T05:58:42+00:00

Actual source code: drawnull.c

      1: #include <petsc/private/drawimpl.h>

      3: static PetscErrorCode PetscDrawCoordinateToPixel_Null(PetscDraw draw, PetscReal x, PetscReal y, int *i, int *j)
      4: {
      5:   PetscFunctionBegin;
      6:   *i = *j = 0;
      7:   PetscFunctionReturn(PETSC_SUCCESS);
      8: }

     10: static PetscErrorCode PetscDrawPixelToCoordinate_Null(PetscDraw draw, int i, int j, PetscReal *x, PetscReal *y)
     11: {
     12:   PetscFunctionBegin;
     13:   *x = *y = 0;
     14:   PetscFunctionReturn(PETSC_SUCCESS);
     15: }

     17: static PetscErrorCode PetscDrawPoint_Null(PetscDraw draw, PetscReal x, PetscReal y, int c)
     18: {
     19:   PetscFunctionBegin;
     20:   PetscFunctionReturn(PETSC_SUCCESS);
     21: }

     23: static PetscErrorCode PetscDrawPointPixel_Null(PetscDraw draw, int x, int y, int c)
     24: {
     25:   PetscFunctionBegin;
     26:   PetscFunctionReturn(PETSC_SUCCESS);
     27: }

     29: static PetscErrorCode PetscDrawLineGetWidth_Null(PetscDraw draw, PetscReal *width)
     30: {
     31:   PetscFunctionBegin;
     32:   if (width) *width = (PetscReal)0.01;
     33:   PetscFunctionReturn(PETSC_SUCCESS);
     34: }

     36: static PetscErrorCode PetscDrawLine_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
     37: {
     38:   PetscFunctionBegin;
     39:   PetscFunctionReturn(PETSC_SUCCESS);
     40: }

     42: static PetscErrorCode PetscDrawArrow_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int cl)
     43: {
     44:   PetscFunctionBegin;
     45:   PetscFunctionReturn(PETSC_SUCCESS);
     46: }

     48: static PetscErrorCode PetscDrawRectangle_Null(PetscDraw draw, PetscReal xl, PetscReal yl, PetscReal xr, PetscReal yr, int c1, int c2, int c3, int c4)
     49: {
     50:   PetscFunctionBegin;
     51:   PetscFunctionReturn(PETSC_SUCCESS);
     52: }

     54: static PetscErrorCode PetscDrawEllipse_Null(PetscDraw Win, PetscReal x, PetscReal y, PetscReal a, PetscReal b, int c)
     55: {
     56:   PetscFunctionBegin;
     57:   PetscFunctionReturn(PETSC_SUCCESS);
     58: }

     60: static PetscErrorCode PetscDrawTriangle_Null(PetscDraw draw, PetscReal X1, PetscReal Y_1, PetscReal X2, PetscReal Y2, PetscReal X3, PetscReal Y3, int c1, int c2, int c3)
     61: {
     62:   PetscFunctionBegin;
     63:   PetscFunctionReturn(PETSC_SUCCESS);
     64: }

     66: static PetscErrorCode PetscDrawStringGetSize_Null(PetscDraw draw, PetscReal *x, PetscReal *y)
     67: {
     68:   PetscFunctionBegin;
     69:   if (x) *x = (PetscReal)0.01;
     70:   if (y) *y = (PetscReal)0.01;
     71:   PetscFunctionReturn(PETSC_SUCCESS);
     72: }

     74: static PetscErrorCode PetscDrawString_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[])
     75: {
     76:   PetscFunctionBegin;
     77:   PetscFunctionReturn(PETSC_SUCCESS);
     78: }

     80: static PetscErrorCode PetscDrawStringVertical_Null(PetscDraw draw, PetscReal x, PetscReal y, int c, const char chrs[])
     81: {
     82:   PetscFunctionBegin;
     83:   PetscFunctionReturn(PETSC_SUCCESS);
     84: }

     86: static PetscErrorCode PetscDrawStringBoxed_Null(PetscDraw draw, PetscReal sxl, PetscReal syl, int sc, int bc, const char text[], PetscReal *w, PetscReal *h)
     87: {
     88:   PetscFunctionBegin;
     89:   if (w) *w = 0.01;
     90:   if (h) *h = 0.01;
     91:   PetscFunctionReturn(PETSC_SUCCESS);
     92: }

     94: static PetscErrorCode PetscDrawGetSingleton_Null(PetscDraw draw, PetscDraw *sdraw)
     95: {
     96:   PetscFunctionBegin;
     97:   PetscCall(PetscDrawOpenNull(PETSC_COMM_SELF, sdraw));
     98:   PetscFunctionReturn(PETSC_SUCCESS);
     99: }

    101: static PetscErrorCode PetscDrawRestoreSingleton_Null(PetscDraw draw, PetscDraw *sdraw)
    102: {
    103:   PetscFunctionBegin;
    104:   PetscCall(PetscDrawDestroy(sdraw));
    105:   PetscFunctionReturn(PETSC_SUCCESS);
    106: }

    108: static struct _PetscDrawOps DvOps = {NULL, /* PetscDrawSetDoubleBuffer_Null */
    109:                                      NULL, /* PetscDrawFlush_Null */
    110:                                      PetscDrawLine_Null,
    111:                                      NULL, /* PetscDrawLineSetWidth_Null */
    112:                                      PetscDrawLineGetWidth_Null,
    113:                                      PetscDrawPoint_Null,
    114:                                      NULL, /* PetscDrawPointSetSize_Null */
    115:                                      PetscDrawString_Null,
    116:                                      PetscDrawStringVertical_Null,
    117:                                      NULL, /* PetscDrawStringSetSize_Null */
    118:                                      PetscDrawStringGetSize_Null,
    119:                                      NULL, /* PetscDrawSetViewport_Null */
    120:                                      NULL, /* PetscDrawClear_Null */
    121:                                      PetscDrawRectangle_Null,
    122:                                      PetscDrawTriangle_Null,
    123:                                      PetscDrawEllipse_Null,
    124:                                      NULL, /* PetscDrawGetMouseButton_Null */
    125:                                      NULL, /* PetscDrawPause_Null */
    126:                                      NULL, /* PetscDrawBeginPage_Null */
    127:                                      NULL, /* PetscDrawEndPage_Null */
    128:                                      NULL, /* PetscDrawGetPopup_Null */
    129:                                      NULL, /* PetscDrawSetTitle_Null */
    130:                                      NULL, /* PetscDrawCheckResizedWindow_Null */
    131:                                      NULL, /* PetscDrawResizeWindow_Null */
    132:                                      NULL, /* PetscDrawDestroy_Null */
    133:                                      NULL, /* PetscDrawView_Null */
    134:                                      PetscDrawGetSingleton_Null,
    135:                                      PetscDrawRestoreSingleton_Null,
    136:                                      NULL, /* PetscDrawSave_Null */
    137:                                      NULL, /* PetscDrawGetImage_Null */
    138:                                      NULL, /* PetscDrawSetCoordinates_Null */
    139:                                      PetscDrawArrow_Null,
    140:                                      PetscDrawCoordinateToPixel_Null,
    141:                                      PetscDrawPixelToCoordinate_Null,
    142:                                      PetscDrawPointPixel_Null,
    143:                                      PetscDrawStringBoxed_Null,
    144:                                      NULL /* PetscDrawSetVisible_Null */};

    146: /*MC
    147:      PETSC_DRAW_NULL - PETSc graphics device that ignores all draw commands

    149:    Level: beginner

    151:    Note:
    152:     A `PETSC_DRAW_NULL` is useful in places where `PetscDraw` routines are called but no graphics window, for example, is available.

    154: .seealso: `PetscDraw`, `PetscDrawOpenNull()`, `PETSC_DRAW_X`, `PetscDrawOpenNull()`, `PetscDrawIsNull()`
    155: M*/
    156: PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw);

    158: PETSC_EXTERN PetscErrorCode PetscDrawCreate_Null(PetscDraw draw)
    159: {
    160:   PetscFunctionBegin;
    161:   draw->pause   = 0;
    162:   draw->coor_xl = 0;
    163:   draw->coor_xr = 1;
    164:   draw->coor_yl = 0;
    165:   draw->coor_yr = 1;
    166:   draw->port_xl = 0;
    167:   draw->port_xr = 1;
    168:   draw->port_yl = 0;
    169:   draw->port_yr = 1;
    170:   PetscCall(PetscDrawDestroy(&draw->popup));

    172:   draw->ops[0] = DvOps;
    173:   draw->data   = NULL;
    174:   PetscFunctionReturn(PETSC_SUCCESS);
    175: }

    177: /*@
    178:   PetscDrawOpenNull - Opens a null drawing context. All draw commands to
    179:   it are ignored.

    181:   Input Parameter:
    182: . comm - MPI communicator

    184:   Output Parameter:
    185: . win - the drawing context

    187:   Level: advanced

    189: .seealso: `PetscDraw`, `PetscDrawIsNull()`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`
    190: @*/
    191: PetscErrorCode PetscDrawOpenNull(MPI_Comm comm, PetscDraw *win)
    192: {
    193:   PetscFunctionBegin;
    194:   PetscCall(PetscDrawCreate(comm, NULL, NULL, 0, 0, 1, 1, win));
    195:   PetscCall(PetscDrawSetType(*win, PETSC_DRAW_NULL));
    196:   PetscFunctionReturn(PETSC_SUCCESS);
    197: }

    199: /*@
    200:   PetscDrawIsNull - Returns `PETSC_TRUE` if draw is a null draw object.

    202:   Not Collective

    204:   Input Parameter:
    205: . draw - the draw context

    207:   Output Parameter:
    208: . yes - `PETSC_TRUE` if it is a null draw object; otherwise `PETSC_FALSE`

    210:   Level: advanced

    212: .seealso: `PetscDraw`, `PETSC_DRAW_NULL`, `PetscDrawOpenX()`
    213: @*/
    214: PetscErrorCode PetscDrawIsNull(PetscDraw draw, PetscBool *yes)
    215: {
    216:   PetscFunctionBegin;
    218:   PetscAssertPointer(yes, 2);
    219:   PetscCall(PetscObjectTypeCompare((PetscObject)draw, PETSC_DRAW_NULL, yes));
    220:   PetscFunctionReturn(PETSC_SUCCESS);
    221: }